Skip to content

report kind of deprecated item in message #74785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub trait LintContext: Sized {
}
}
BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
stability::deprecation_suggestion(&mut db, suggestion, span)
stability::deprecation_suggestion(&mut db, "macro", suggestion, span)
}
BuiltinLintDiagnostics::UnusedDocComment(span) => {
db.span_label(span, "rustdoc does not generate documentation for macro invocations");
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_middle/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,31 @@ pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>)

pub fn deprecation_suggestion(
diag: &mut DiagnosticBuilder<'_>,
kind: &str,
suggestion: Option<Symbol>,
span: Span,
) {
if let Some(suggestion) = suggestion {
diag.span_suggestion(
span,
"replace the use of the deprecated item",
&format!("replace the use of the deprecated {}", kind),
suggestion.to_string(),
Applicability::MachineApplicable,
);
}
}

pub fn deprecation_message(depr: &Deprecation, path: &str) -> (String, &'static Lint) {
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
let (message, lint) = if deprecation_in_effect(
depr.is_since_rustc_version,
depr.since.map(Symbol::as_str).as_deref(),
) {
(format!("use of deprecated item '{}'", path), DEPRECATED)
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
} else {
(
format!(
"use of item '{}' that will be deprecated in future version {}",
"use of {} `{}` that will be deprecated in future version {}",
kind,
path,
depr.since.unwrap()
),
Expand Down Expand Up @@ -224,6 +226,7 @@ fn late_report_deprecation(
lint: &'static Lint,
span: Span,
hir_id: HirId,
def_id: DefId,
) {
if span.in_derive_expansion() {
return;
Expand All @@ -232,7 +235,8 @@ fn late_report_deprecation(
tcx.struct_span_lint_hir(lint, hir_id, span, |lint| {
let mut diag = lint.build(message);
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
deprecation_suggestion(&mut diag, suggestion, span);
let kind = tcx.def_kind(def_id).descr(def_id);
deprecation_suggestion(&mut diag, kind, suggestion, span);
}
diag.emit()
});
Expand Down Expand Up @@ -304,15 +308,17 @@ impl<'tcx> TyCtxt<'tcx> {
// #[rustc_deprecated] however wants to emit down the whole
// hierarchy.
if !skip || depr_entry.attr.is_since_rustc_version {
let (message, lint) =
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
let path = &self.def_path_str(def_id);
let kind = self.def_kind(def_id).descr(def_id);
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
late_report_deprecation(
self,
&message,
depr_entry.attr.suggestion,
lint,
span,
id,
def_id,
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ impl<'a> Resolver<'a> {
}
if let Some(depr) = &ext.deprecation {
let path = pprust::path_to_string(&path);
let (message, lint) = stability::deprecation_message(depr, &path);
let (message, lint) = stability::deprecation_message(depr, "macro", &path);
stability::early_report_deprecation(
&mut self.lint_buffer,
&message,
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/conditional-compilation/cfg-attr-multi-true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#[cfg_attr(all(), deprecated, must_use)]
struct MustUseDeprecated {}

impl MustUseDeprecated { //~ warning: use of deprecated item
fn new() -> MustUseDeprecated { //~ warning: use of deprecated item
MustUseDeprecated {} //~ warning: use of deprecated item
impl MustUseDeprecated { //~ warning: use of deprecated
fn new() -> MustUseDeprecated { //~ warning: use of deprecated
MustUseDeprecated {} //~ warning: use of deprecated
}
}

fn main() {
MustUseDeprecated::new(); //~ warning: use of deprecated item
MustUseDeprecated::new(); //~ warning: use of deprecated
//~| warning: unused `MustUseDeprecated` that must be used
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
warning: use of deprecated item 'MustUseDeprecated'
warning: use of deprecated struct `MustUseDeprecated`
--> $DIR/cfg-attr-multi-true.rs:12:6
|
LL | impl MustUseDeprecated {
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default

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

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

warning: use of deprecated item 'MustUseDeprecated'
warning: use of deprecated struct `MustUseDeprecated`
--> $DIR/cfg-attr-multi-true.rs:14:9
|
LL | MustUseDeprecated {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/atomic_initializers.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};

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

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/atomic_initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};

#[allow(dead_code)]
static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
//~^ WARN use of deprecated item
//~^ WARN use of deprecated constant

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/deprecation/atomic_initializers.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
warning: use of deprecated item 'std::sync::atomic::ATOMIC_ISIZE_INIT': the `new` function is now preferred
warning: use of deprecated constant `std::sync::atomic::ATOMIC_ISIZE_INIT`: the `new` function is now preferred
--> $DIR/atomic_initializers.rs:8:27
|
LL | static FOO: AtomicIsize = ATOMIC_ISIZE_INIT;
| ^^^^^^^^^^^^^^^^^ help: replace the use of the deprecated item: `AtomicIsize::new(0)`
| ^^^^^^^^^^^^^^^^^ help: replace the use of the deprecated constant: `AtomicIsize::new(0)`
|
= note: `#[warn(deprecated)]` on by default

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-in-future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn deprecated_future() {}

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

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-in-future.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: use of deprecated item 'deprecated_future': text
warning: use of deprecated function `deprecated_future`: text
--> $DIR/deprecation-in-future.rs:9:5
|
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-lint-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// aux-build:deprecation-lint.rs
// error-pattern: use of deprecated item
// error-pattern: use of deprecated function

#![deny(deprecated)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-lint-2.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: use of deprecated item 'deprecation_lint::deprecated': text
error: use of deprecated function `deprecation_lint::deprecated`: text
--> $DIR/deprecation-lint-2.rs:12:5
|
LL | macro_test!();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-lint-3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// aux-build:deprecation-lint.rs
// error-pattern: use of deprecated item
// error-pattern: use of deprecated function

#![deny(deprecated)]
#![allow(warnings)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-lint-3.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: use of deprecated item 'deprecation_lint::deprecated_text': text
error: use of deprecated function `deprecation_lint::deprecated_text`: text
--> $DIR/deprecation-lint-3.rs:13:5
|
LL | macro_test_arg_nested!(deprecated_text);
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/deprecation/deprecation-lint-nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ mod loud {
#[deprecated]
const DEPRECATED_CONST: u8 = 1;

struct Foo(DeprecatedType); //~ ERROR use of deprecated item
struct Foo(DeprecatedType); //~ ERROR use of deprecated type alias

impl DeprecatedTrait for Foo {} //~ ERROR use of deprecated item
impl DeprecatedTrait for Foo {} //~ ERROR use of deprecated trait

impl Foo {
fn bar<T: DeprecatedTrait>() { //~ ERROR use of deprecated item
deprecated_fn(); //~ ERROR use of deprecated item
fn bar<T: DeprecatedTrait>() { //~ ERROR use of deprecated trait
deprecated_fn(); //~ ERROR use of deprecated function
}
}

fn foo() -> u8 {
DEPRECATED_STATIC + //~ ERROR use of deprecated item
DEPRECATED_CONST //~ ERROR use of deprecated item
DEPRECATED_STATIC + //~ ERROR use of deprecated static
DEPRECATED_CONST //~ ERROR use of deprecated const
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/deprecation/deprecation-lint-nested.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: use of deprecated item 'loud::DeprecatedType'
error: use of deprecated type alias `loud::DeprecatedType`
--> $DIR/deprecation-lint-nested.rs:55:16
|
LL | struct Foo(DeprecatedType);
Expand All @@ -10,31 +10,31 @@ note: the lint level is defined here
LL | #![deny(deprecated)]
| ^^^^^^^^^^

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

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

error: use of deprecated item 'loud::DEPRECATED_CONST'
error: use of deprecated constant `loud::DEPRECATED_CONST`
--> $DIR/deprecation-lint-nested.rs:67:9
|
LL | DEPRECATED_CONST
| ^^^^^^^^^^^^^^^^

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

error: use of deprecated item 'loud::deprecated_fn'
error: use of deprecated function `loud::deprecated_fn`
--> $DIR/deprecation-lint-nested.rs:61:13
|
LL | deprecated_fn();
Expand Down
Loading