Skip to content

Commit

Permalink
rustc: add item name to deprecated lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryman committed Nov 2, 2017
1 parent 8b22e70 commit 725ddb4
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 230 deletions.
12 changes: 7 additions & 5 deletions src/librustc/middle/stability.rs
Expand Up @@ -516,11 +516,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return;
}

let lint_deprecated = |note: Option<Symbol>| {
let lint_deprecated = |def_id: DefId, note: Option<Symbol>| {
let path = self.item_path_str(def_id);

let msg = if let Some(note) = note {
format!("use of deprecated item: {}", note)
format!("use of deprecated item '{}': {}", path, note)
} else {
format!("use of deprecated item")
format!("use of deprecated item '{}'", path)
};

self.lint_node(lint::builtin::DEPRECATED, id, span, &msg);
Expand All @@ -538,7 +540,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
};

if !skip {
lint_deprecated(depr_entry.attr.note);
lint_deprecated(def_id, depr_entry.attr.note);
}
}

Expand All @@ -557,7 +559,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
if let Some(&Stability{rustc_depr: Some(attr::RustcDeprecation { reason, .. }), ..})
= stability {
if id != ast::DUMMY_NODE_ID {
lint_deprecated(Some(reason));
lint_deprecated(def_id, Some(reason));
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/librustc/ty/item_path.rs
Expand Up @@ -151,9 +151,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

cur_path.push(self.def_key(cur_def)
.disambiguated_data.data.get_opt_name().unwrap_or_else(||
Symbol::intern("<unnamed>").as_str()));
let mut cur_def_key = self.def_key(cur_def);

// For a UnitStruct or TupleStruct we want the name of its parent rather than <unnamed>.
if let DefPathData::StructCtor = cur_def_key.disambiguated_data.data {
let parent = DefId {
krate: cur_def.krate,
index: cur_def_key.parent.expect("DefPathData::StructCtor missing a parent"),
};

cur_def_key = self.def_key(parent);
}

let data = cur_def_key.disambiguated_data.data;
let symbol =
data.get_opt_name().unwrap_or_else(|| Symbol::intern("<unnamed>").as_str());
cur_path.push(symbol);

match visible_parent_map.get(&cur_def) {
Some(&def) => cur_def = def,
None => return false,
Expand Down
18 changes: 18 additions & 0 deletions src/test/compile-fail/auxiliary/deprecation-lint.rs
Expand Up @@ -52,6 +52,24 @@ pub enum Enum {
#[deprecated(since = "1.0.0", note = "text")]
pub struct DeprecatedTupleStruct(pub isize);

pub mod nested {
#[deprecated(since = "1.0.0", note = "text")]
pub struct DeprecatedStruct {
pub i: isize
}

#[deprecated(since = "1.0.0", note = "text")]
pub struct DeprecatedUnitStruct;

pub enum Enum {
#[deprecated(since = "1.0.0", note = "text")]
DeprecatedVariant,
}

#[deprecated(since = "1.0.0", note = "text")]
pub struct DeprecatedTupleStruct(pub isize);
}

pub struct Stable {
#[deprecated(since = "1.0.0", note = "text")]
pub override2: u8,
Expand Down

0 comments on commit 725ddb4

Please sign in to comment.