Skip to content

Commit 8141873

Browse files
committed
Auto merge of #74785 - euclio:deprecation-kinds, r=petrochenkov
report kind of deprecated item in message This is important for fields, which are incorrectly referred to as "items".
2 parents e18b563 + 0b32008 commit 8141873

39 files changed

+748
-742
lines changed

src/librustc_lint/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ pub trait LintContext: Sized {
573573
}
574574
}
575575
BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
576-
stability::deprecation_suggestion(&mut db, suggestion, span)
576+
stability::deprecation_suggestion(&mut db, "macro", suggestion, span)
577577
}
578578
BuiltinLintDiagnostics::UnusedDocComment(span) => {
579579
db.span_label(span, "rustdoc does not generate documentation for macro invocations");

src/librustc_middle/middle/stability.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,31 @@ pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>)
166166

167167
pub fn deprecation_suggestion(
168168
diag: &mut DiagnosticBuilder<'_>,
169+
kind: &str,
169170
suggestion: Option<Symbol>,
170171
span: Span,
171172
) {
172173
if let Some(suggestion) = suggestion {
173174
diag.span_suggestion(
174175
span,
175-
"replace the use of the deprecated item",
176+
&format!("replace the use of the deprecated {}", kind),
176177
suggestion.to_string(),
177178
Applicability::MachineApplicable,
178179
);
179180
}
180181
}
181182

182-
pub fn deprecation_message(depr: &Deprecation, path: &str) -> (String, &'static Lint) {
183+
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
183184
let (message, lint) = if deprecation_in_effect(
184185
depr.is_since_rustc_version,
185186
depr.since.map(Symbol::as_str).as_deref(),
186187
) {
187-
(format!("use of deprecated item '{}'", path), DEPRECATED)
188+
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
188189
} else {
189190
(
190191
format!(
191-
"use of item '{}' that will be deprecated in future version {}",
192+
"use of {} `{}` that will be deprecated in future version {}",
193+
kind,
192194
path,
193195
depr.since.unwrap()
194196
),
@@ -224,6 +226,7 @@ fn late_report_deprecation(
224226
lint: &'static Lint,
225227
span: Span,
226228
hir_id: HirId,
229+
def_id: DefId,
227230
) {
228231
if span.in_derive_expansion() {
229232
return;
@@ -232,7 +235,8 @@ fn late_report_deprecation(
232235
tcx.struct_span_lint_hir(lint, hir_id, span, |lint| {
233236
let mut diag = lint.build(message);
234237
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
235-
deprecation_suggestion(&mut diag, suggestion, span);
238+
let kind = tcx.def_kind(def_id).descr(def_id);
239+
deprecation_suggestion(&mut diag, kind, suggestion, span);
236240
}
237241
diag.emit()
238242
});
@@ -304,15 +308,17 @@ impl<'tcx> TyCtxt<'tcx> {
304308
// #[rustc_deprecated] however wants to emit down the whole
305309
// hierarchy.
306310
if !skip || depr_entry.attr.is_since_rustc_version {
307-
let (message, lint) =
308-
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
311+
let path = &self.def_path_str(def_id);
312+
let kind = self.def_kind(def_id).descr(def_id);
313+
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
309314
late_report_deprecation(
310315
self,
311316
&message,
312317
depr_entry.attr.suggestion,
313318
lint,
314319
span,
315320
id,
321+
def_id,
316322
);
317323
}
318324
};

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl<'a> Resolver<'a> {
10201020
}
10211021
if let Some(depr) = &ext.deprecation {
10221022
let path = pprust::path_to_string(&path);
1023-
let (message, lint) = stability::deprecation_message(depr, &path);
1023+
let (message, lint) = stability::deprecation_message(depr, "macro", &path);
10241024
stability::early_report_deprecation(
10251025
&mut self.lint_buffer,
10261026
&message,

src/test/ui/conditional-compilation/cfg-attr-multi-true.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#[cfg_attr(all(), deprecated, must_use)]
1010
struct MustUseDeprecated {}
1111

12-
impl MustUseDeprecated { //~ warning: use of deprecated item
13-
fn new() -> MustUseDeprecated { //~ warning: use of deprecated item
14-
MustUseDeprecated {} //~ warning: use of deprecated item
12+
impl MustUseDeprecated { //~ warning: use of deprecated
13+
fn new() -> MustUseDeprecated { //~ warning: use of deprecated
14+
MustUseDeprecated {} //~ warning: use of deprecated
1515
}
1616
}
1717

1818
fn main() {
19-
MustUseDeprecated::new(); //~ warning: use of deprecated item
19+
MustUseDeprecated::new(); //~ warning: use of deprecated
2020
//~| warning: unused `MustUseDeprecated` that must be used
2121
}

src/test/ui/conditional-compilation/cfg-attr-multi-true.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
warning: use of deprecated item 'MustUseDeprecated'
1+
warning: use of deprecated struct `MustUseDeprecated`
22
--> $DIR/cfg-attr-multi-true.rs:12:6
33
|
44
LL | impl MustUseDeprecated {
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(deprecated)]` on by default
88

9-
warning: use of deprecated item 'MustUseDeprecated'
9+
warning: use of deprecated struct `MustUseDeprecated`
1010
--> $DIR/cfg-attr-multi-true.rs:19:5
1111
|
1212
LL | MustUseDeprecated::new();
1313
| ^^^^^^^^^^^^^^^^^^^^^^
1414

15-
warning: use of deprecated item 'MustUseDeprecated'
15+
warning: use of deprecated struct `MustUseDeprecated`
1616
--> $DIR/cfg-attr-multi-true.rs:13:17
1717
|
1818
LL | fn new() -> MustUseDeprecated {
1919
| ^^^^^^^^^^^^^^^^^
2020

21-
warning: use of deprecated item 'MustUseDeprecated'
21+
warning: use of deprecated struct `MustUseDeprecated`
2222
--> $DIR/cfg-attr-multi-true.rs:14:9
2323
|
2424
LL | MustUseDeprecated {}

src/test/ui/deprecation/atomic_initializers.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};
66

77
#[allow(dead_code)]
88
static FOO: AtomicIsize = AtomicIsize::new(0);
9-
//~^ WARN use of deprecated item
9+
//~^ WARN use of deprecated constant
1010

1111
fn main() {}

src/test/ui/deprecation/atomic_initializers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};
66

77
#[allow(dead_code)]
88
static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
9-
//~^ WARN use of deprecated item
9+
//~^ WARN use of deprecated constant
1010

1111
fn main() {}

src/test/ui/deprecation/atomic_initializers.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
warning: use of deprecated item 'std::sync::atomic::ATOMIC_ISIZE_INIT': the `new` function is now preferred
1+
warning: use of deprecated constant `std::sync::atomic::ATOMIC_ISIZE_INIT`: the `new` function is now preferred
22
--> $DIR/atomic_initializers.rs:8:27
33
|
44
LL | static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
5-
| ^^^^^^^^^^^^^^^^^ help: replace the use of the deprecated item: `AtomicIsize::new(0)`
5+
| ^^^^^^^^^^^^^^^^^ help: replace the use of the deprecated constant: `AtomicIsize::new(0)`
66
|
77
= note: `#[warn(deprecated)]` on by default
88

src/test/ui/deprecation/deprecation-in-future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn deprecated_future() {}
77

88
fn test() {
99
deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
10-
//~^ WARNING use of deprecated item 'deprecated_future': text [deprecated]
10+
//~^ WARNING use of deprecated function `deprecated_future`: text [deprecated]
1111
}
1212

1313
fn main() {}

src/test/ui/deprecation/deprecation-in-future.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: use of deprecated item 'deprecated_future': text
1+
warning: use of deprecated function `deprecated_future`: text
22
--> $DIR/deprecation-in-future.rs:9:5
33
|
44
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated

src/test/ui/deprecation/deprecation-lint-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// aux-build:deprecation-lint.rs
2-
// error-pattern: use of deprecated item
2+
// error-pattern: use of deprecated function
33

44
#![deny(deprecated)]
55

src/test/ui/deprecation/deprecation-lint-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: use of deprecated item 'deprecation_lint::deprecated': text
1+
error: use of deprecated function `deprecation_lint::deprecated`: text
22
--> $DIR/deprecation-lint-2.rs:12:5
33
|
44
LL | macro_test!();

src/test/ui/deprecation/deprecation-lint-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// aux-build:deprecation-lint.rs
2-
// error-pattern: use of deprecated item
2+
// error-pattern: use of deprecated function
33

44
#![deny(deprecated)]
55
#![allow(warnings)]

src/test/ui/deprecation/deprecation-lint-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: use of deprecated item 'deprecation_lint::deprecated_text': text
1+
error: use of deprecated function `deprecation_lint::deprecated_text`: text
22
--> $DIR/deprecation-lint-3.rs:13:5
33
|
44
LL | macro_test_arg_nested!(deprecated_text);

src/test/ui/deprecation/deprecation-lint-nested.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ mod loud {
5252
#[deprecated]
5353
const DEPRECATED_CONST: u8 = 1;
5454

55-
struct Foo(DeprecatedType); //~ ERROR use of deprecated item
55+
struct Foo(DeprecatedType); //~ ERROR use of deprecated type alias
5656

57-
impl DeprecatedTrait for Foo {} //~ ERROR use of deprecated item
57+
impl DeprecatedTrait for Foo {} //~ ERROR use of deprecated trait
5858

5959
impl Foo {
60-
fn bar<T: DeprecatedTrait>() { //~ ERROR use of deprecated item
61-
deprecated_fn(); //~ ERROR use of deprecated item
60+
fn bar<T: DeprecatedTrait>() { //~ ERROR use of deprecated trait
61+
deprecated_fn(); //~ ERROR use of deprecated function
6262
}
6363
}
6464

6565
fn foo() -> u8 {
66-
DEPRECATED_STATIC + //~ ERROR use of deprecated item
67-
DEPRECATED_CONST //~ ERROR use of deprecated item
66+
DEPRECATED_STATIC + //~ ERROR use of deprecated static
67+
DEPRECATED_CONST //~ ERROR use of deprecated const
6868
}
6969
}
7070

src/test/ui/deprecation/deprecation-lint-nested.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: use of deprecated item 'loud::DeprecatedType'
1+
error: use of deprecated type alias `loud::DeprecatedType`
22
--> $DIR/deprecation-lint-nested.rs:55:16
33
|
44
LL | struct Foo(DeprecatedType);
@@ -10,31 +10,31 @@ note: the lint level is defined here
1010
LL | #![deny(deprecated)]
1111
| ^^^^^^^^^^
1212

13-
error: use of deprecated item 'loud::DeprecatedTrait'
13+
error: use of deprecated trait `loud::DeprecatedTrait`
1414
--> $DIR/deprecation-lint-nested.rs:57:10
1515
|
1616
LL | impl DeprecatedTrait for Foo {}
1717
| ^^^^^^^^^^^^^^^
1818

19-
error: use of deprecated item 'loud::DEPRECATED_STATIC'
19+
error: use of deprecated static `loud::DEPRECATED_STATIC`
2020
--> $DIR/deprecation-lint-nested.rs:66:9
2121
|
2222
LL | DEPRECATED_STATIC +
2323
| ^^^^^^^^^^^^^^^^^
2424

25-
error: use of deprecated item 'loud::DEPRECATED_CONST'
25+
error: use of deprecated constant `loud::DEPRECATED_CONST`
2626
--> $DIR/deprecation-lint-nested.rs:67:9
2727
|
2828
LL | DEPRECATED_CONST
2929
| ^^^^^^^^^^^^^^^^
3030

31-
error: use of deprecated item 'loud::DeprecatedTrait'
31+
error: use of deprecated trait `loud::DeprecatedTrait`
3232
--> $DIR/deprecation-lint-nested.rs:60:19
3333
|
3434
LL | fn bar<T: DeprecatedTrait>() {
3535
| ^^^^^^^^^^^^^^^
3636

37-
error: use of deprecated item 'loud::deprecated_fn'
37+
error: use of deprecated function `loud::deprecated_fn`
3838
--> $DIR/deprecation-lint-nested.rs:61:13
3939
|
4040
LL | deprecated_fn();

0 commit comments

Comments
 (0)