Skip to content

Commit c17501f

Browse files
committed
ignore deprecation for items deprecated by the same attribute
Whenever a node whould be reported as deprecated: - check if the parent item is also deprecated - if it is and both were deprecated by the same attribute - skip the deprecation warning fixes #35128 closes #16490
1 parent b4c6a39 commit c17501f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/librustc/middle/stability.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ struct Checker<'a, 'tcx: 'a> {
386386

387387
impl<'a, 'tcx> Checker<'a, 'tcx> {
388388
fn check(&mut self, id: DefId, span: Span,
389-
stab: &Option<&Stability>, _depr: &Option<Deprecation>) {
389+
stab: &Option<&Stability>, _depr: &Option<DeprecationEntry>) {
390390
if !is_staged_api(self.tcx, id) {
391391
return;
392392
}
@@ -511,7 +511,7 @@ pub fn check_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
511511
warn_about_defns: bool,
512512
cb: &mut FnMut(DefId, Span,
513513
&Option<&Stability>,
514-
&Option<Deprecation>)) {
514+
&Option<DeprecationEntry>)) {
515515
match item.node {
516516
hir::ItemExternCrate(_) => {
517517
// compiler-generated `extern crate` items have a dummy span.
@@ -550,7 +550,7 @@ pub fn check_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
550550
pub fn check_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, e: &hir::Expr,
551551
cb: &mut FnMut(DefId, Span,
552552
&Option<&Stability>,
553-
&Option<Deprecation>)) {
553+
&Option<DeprecationEntry>)) {
554554
let span;
555555
let id = match e.node {
556556
hir::ExprMethodCall(i, _, _) => {
@@ -614,7 +614,7 @@ pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
614614
path: &hir::Path, id: ast::NodeId,
615615
cb: &mut FnMut(DefId, Span,
616616
&Option<&Stability>,
617-
&Option<Deprecation>)) {
617+
&Option<DeprecationEntry>)) {
618618
// Paths in import prefixes may have no resolution.
619619
match tcx.expect_def_or_none(id) {
620620
Some(Def::PrimTy(..)) => {}
@@ -630,7 +630,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
630630
item: &hir::PathListItem,
631631
cb: &mut FnMut(DefId, Span,
632632
&Option<&Stability>,
633-
&Option<Deprecation>)) {
633+
&Option<DeprecationEntry>)) {
634634
match tcx.expect_def(item.node.id()) {
635635
Def::PrimTy(..) => {}
636636
def => {
@@ -642,7 +642,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
642642
pub fn check_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &hir::Pat,
643643
cb: &mut FnMut(DefId, Span,
644644
&Option<&Stability>,
645-
&Option<Deprecation>)) {
645+
&Option<DeprecationEntry>)) {
646646
debug!("check_pat(pat = {:?})", pat);
647647
if is_internal(tcx, pat.span) { return; }
648648

@@ -673,7 +673,7 @@ fn maybe_do_stability_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
673673
id: DefId, span: Span,
674674
cb: &mut FnMut(DefId, Span,
675675
&Option<&Stability>,
676-
&Option<Deprecation>)) {
676+
&Option<DeprecationEntry>)) {
677677
if is_internal(tcx, span) {
678678
debug!("maybe_do_stability_check: \
679679
skipping span={:?} since it is internal", span);
@@ -682,7 +682,7 @@ fn maybe_do_stability_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
682682
let (stability, deprecation) = if is_staged_api(tcx, id) {
683683
(tcx.lookup_stability(id), None)
684684
} else {
685-
(None, tcx.lookup_deprecation(id))
685+
(None, tcx.lookup_deprecation_entry(id))
686686
};
687687
debug!("maybe_do_stability_check: \
688688
inspecting id={:?} span={:?} of stability={:?}", id, span, stability);

src/librustc_lint/builtin.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,20 @@ impl Deprecated {
583583
}
584584

585585
fn lint(&self, cx: &LateContext, _id: DefId, span: Span,
586-
stability: &Option<&attr::Stability>, deprecation: &Option<attr::Deprecation>) {
586+
stability: &Option<&attr::Stability>,
587+
deprecation: &Option<stability::DeprecationEntry>) {
587588
// Deprecated attributes apply in-crate and cross-crate.
588589
if let Some(&attr::Stability{rustc_depr: Some(attr::RustcDeprecation{ref reason, ..}), ..})
589590
= *stability {
590591
output(cx, DEPRECATED, span, Some(&reason))
591-
} else if let Some(attr::Deprecation{ref note, ..}) = *deprecation {
592-
output(cx, DEPRECATED, span, note.as_ref().map(|x| &**x))
592+
} else if let Some(ref depr_entry) = *deprecation {
593+
if let Some(parent_depr) = cx.tcx.lookup_deprecation_entry(self.parent_def(cx)) {
594+
if parent_depr.same_origin(depr_entry) {
595+
return;
596+
}
597+
}
598+
599+
output(cx, DEPRECATED, span, depr_entry.attr.note.as_ref().map(|x| &**x))
593600
}
594601

595602
fn output(cx: &LateContext, lint: &'static Lint, span: Span, note: Option<&str>) {

0 commit comments

Comments
 (0)