Skip to content

Commit 25cc4a8

Browse files
committed
Auto merge of #45707 - Ryman:deprecated-item-name, r=nikomatsakis
rustc: add item name to deprecated lint warning It can sometimes be difficult to know what is actually deprecated when you have `foo.bar()` and `bar` comes from a trait in another crate.
2 parents a35a3ab + 725ddb4 commit 25cc4a8

File tree

6 files changed

+315
-230
lines changed

6 files changed

+315
-230
lines changed

src/librustc/middle/stability.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
516516
return;
517517
}
518518

519-
let lint_deprecated = |note: Option<Symbol>| {
519+
let lint_deprecated = |def_id: DefId, note: Option<Symbol>| {
520+
let path = self.item_path_str(def_id);
521+
520522
let msg = if let Some(note) = note {
521-
format!("use of deprecated item: {}", note)
523+
format!("use of deprecated item '{}': {}", path, note)
522524
} else {
523-
format!("use of deprecated item")
525+
format!("use of deprecated item '{}'", path)
524526
};
525527

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

540542
if !skip {
541-
lint_deprecated(depr_entry.attr.note);
543+
lint_deprecated(def_id, depr_entry.attr.note);
542544
}
543545
}
544546

@@ -557,7 +559,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
557559
if let Some(&Stability{rustc_depr: Some(attr::RustcDeprecation { reason, .. }), ..})
558560
= stability {
559561
if id != ast::DUMMY_NODE_ID {
560-
lint_deprecated(Some(reason));
562+
lint_deprecated(def_id, Some(reason));
561563
}
562564
}
563565

src/librustc/ty/item_path.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
151151
}
152152
}
153153

154-
cur_path.push(self.def_key(cur_def)
155-
.disambiguated_data.data.get_opt_name().unwrap_or_else(||
156-
Symbol::intern("<unnamed>").as_str()));
154+
let mut cur_def_key = self.def_key(cur_def);
155+
156+
// For a UnitStruct or TupleStruct we want the name of its parent rather than <unnamed>.
157+
if let DefPathData::StructCtor = cur_def_key.disambiguated_data.data {
158+
let parent = DefId {
159+
krate: cur_def.krate,
160+
index: cur_def_key.parent.expect("DefPathData::StructCtor missing a parent"),
161+
};
162+
163+
cur_def_key = self.def_key(parent);
164+
}
165+
166+
let data = cur_def_key.disambiguated_data.data;
167+
let symbol =
168+
data.get_opt_name().unwrap_or_else(|| Symbol::intern("<unnamed>").as_str());
169+
cur_path.push(symbol);
170+
157171
match visible_parent_map.get(&cur_def) {
158172
Some(&def) => cur_def = def,
159173
None => return false,

src/test/compile-fail/auxiliary/deprecation-lint.rs

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ pub enum Enum {
5252
#[deprecated(since = "1.0.0", note = "text")]
5353
pub struct DeprecatedTupleStruct(pub isize);
5454

55+
pub mod nested {
56+
#[deprecated(since = "1.0.0", note = "text")]
57+
pub struct DeprecatedStruct {
58+
pub i: isize
59+
}
60+
61+
#[deprecated(since = "1.0.0", note = "text")]
62+
pub struct DeprecatedUnitStruct;
63+
64+
pub enum Enum {
65+
#[deprecated(since = "1.0.0", note = "text")]
66+
DeprecatedVariant,
67+
}
68+
69+
#[deprecated(since = "1.0.0", note = "text")]
70+
pub struct DeprecatedTupleStruct(pub isize);
71+
}
72+
5573
pub struct Stable {
5674
#[deprecated(since = "1.0.0", note = "text")]
5775
pub override2: u8,

0 commit comments

Comments
 (0)