Skip to content

Commit

Permalink
ignore deprecation for items deprecated by the same attribute
Browse files Browse the repository at this point in the history
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 rust-lang#35128
closes rust-lang#16490
  • Loading branch information
TimNN committed Aug 4, 2016
1 parent b4c6a39 commit c17501f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ struct Checker<'a, 'tcx: 'a> {

impl<'a, 'tcx> Checker<'a, 'tcx> {
fn check(&mut self, id: DefId, span: Span,
stab: &Option<&Stability>, _depr: &Option<Deprecation>) {
stab: &Option<&Stability>, _depr: &Option<DeprecationEntry>) {
if !is_staged_api(self.tcx, id) {
return;
}
Expand Down Expand Up @@ -511,7 +511,7 @@ pub fn check_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
warn_about_defns: bool,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
match item.node {
hir::ItemExternCrate(_) => {
// compiler-generated `extern crate` items have a dummy span.
Expand Down Expand Up @@ -550,7 +550,7 @@ pub fn check_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn check_expr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, e: &hir::Expr,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
let span;
let id = match e.node {
hir::ExprMethodCall(i, _, _) => {
Expand Down Expand Up @@ -614,7 +614,7 @@ pub fn check_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
path: &hir::Path, id: ast::NodeId,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
// Paths in import prefixes may have no resolution.
match tcx.expect_def_or_none(id) {
Some(Def::PrimTy(..)) => {}
Expand All @@ -630,7 +630,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
item: &hir::PathListItem,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
match tcx.expect_def(item.node.id()) {
Def::PrimTy(..) => {}
def => {
Expand All @@ -642,7 +642,7 @@ pub fn check_path_list_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn check_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &hir::Pat,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
debug!("check_pat(pat = {:?})", pat);
if is_internal(tcx, pat.span) { return; }

Expand Down Expand Up @@ -673,7 +673,7 @@ fn maybe_do_stability_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: DefId, span: Span,
cb: &mut FnMut(DefId, Span,
&Option<&Stability>,
&Option<Deprecation>)) {
&Option<DeprecationEntry>)) {
if is_internal(tcx, span) {
debug!("maybe_do_stability_check: \
skipping span={:?} since it is internal", span);
Expand All @@ -682,7 +682,7 @@ fn maybe_do_stability_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let (stability, deprecation) = if is_staged_api(tcx, id) {
(tcx.lookup_stability(id), None)
} else {
(None, tcx.lookup_deprecation(id))
(None, tcx.lookup_deprecation_entry(id))
};
debug!("maybe_do_stability_check: \
inspecting id={:?} span={:?} of stability={:?}", id, span, stability);
Expand Down
13 changes: 10 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,20 @@ impl Deprecated {
}

fn lint(&self, cx: &LateContext, _id: DefId, span: Span,
stability: &Option<&attr::Stability>, deprecation: &Option<attr::Deprecation>) {
stability: &Option<&attr::Stability>,
deprecation: &Option<stability::DeprecationEntry>) {
// Deprecated attributes apply in-crate and cross-crate.
if let Some(&attr::Stability{rustc_depr: Some(attr::RustcDeprecation{ref reason, ..}), ..})
= *stability {
output(cx, DEPRECATED, span, Some(&reason))
} else if let Some(attr::Deprecation{ref note, ..}) = *deprecation {
output(cx, DEPRECATED, span, note.as_ref().map(|x| &**x))
} else if let Some(ref depr_entry) = *deprecation {
if let Some(parent_depr) = cx.tcx.lookup_deprecation_entry(self.parent_def(cx)) {
if parent_depr.same_origin(depr_entry) {
return;
}
}

output(cx, DEPRECATED, span, depr_entry.attr.note.as_ref().map(|x| &**x))
}

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

0 comments on commit c17501f

Please sign in to comment.