Skip to content
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

shrinking the deprecated span #86320

Merged
merged 3 commits into from
Jul 12, 2021
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
9 changes: 5 additions & 4 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,19 @@ fn late_report_deprecation(
suggestion: Option<Symbol>,
lint: &'static Lint,
span: Span,
method_span: Option<Span>,
Copy link
Member Author

@Rustin170506 Rustin170506 Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's not a suitable name for now. But I'm not quite sure what to rename it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

hir_id: HirId,
def_id: DefId,
) {
if span.in_derive_expansion() {
return;
}

tcx.struct_span_lint_hir(lint, hir_id, span, |lint| {
let method_span = method_span.unwrap_or(span);
tcx.struct_span_lint_hir(lint, hir_id, method_span, |lint| {
let mut diag = lint.build(message);
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
let kind = tcx.def_kind(def_id).descr(def_id);
deprecation_suggestion(&mut diag, kind, suggestion, span);
deprecation_suggestion(&mut diag, kind, suggestion, method_span);
}
diag.emit()
});
Expand Down Expand Up @@ -306,13 +307,13 @@ impl<'tcx> TyCtxt<'tcx> {
let path = &with_no_trimmed_paths(|| 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);
let span = method_span.unwrap_or(span);
late_report_deprecation(
self,
&message,
depr_entry.attr.suggestion,
lint,
span,
method_span,
id,
def_id,
);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ impl Visitor<'tcx> for Checker<'tcx> {

fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
if let Some(def_id) = path.res.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span, None)
let method_span = path.segments.last().map(|s| s.ident.span);
self.tcx.check_stability(def_id, Some(id), path.span, method_span)
}
intravisit::walk_path(self, path)
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/deprecation/deprecation-lint-3.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
error: use of deprecated function `deprecation_lint::deprecated_text`: text
--> $DIR/deprecation-lint-3.rs:13:5
--> $DIR/deprecation-lint-3.rs:13:28
|
LL | macro_test_arg_nested!(deprecated_text);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/deprecation-lint-3.rs:4:9
|
LL | #![deny(deprecated)]
| ^^^^^^^^^^
= note: this error originates in the macro `macro_test_arg_nested` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

108 changes: 54 additions & 54 deletions src/test/ui/deprecation/deprecation-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ LL | #![deny(deprecated)]
| ^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:21:9
--> $DIR/deprecation-lint.rs:21:16
|
LL | Trait::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:23:9
--> $DIR/deprecation-lint.rs:23:25
|
LL | <Foo as Trait>::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated function `deprecation_lint::deprecated_text`: text
--> $DIR/deprecation-lint.rs:25:9
Expand All @@ -29,16 +29,16 @@ LL | deprecated_text();
| ^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:30:9
--> $DIR/deprecation-lint.rs:30:16
|
LL | ... Trait::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:32:9
--> $DIR/deprecation-lint.rs:32:25
|
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated struct `deprecation_lint::DeprecatedStruct`: text
--> $DIR/deprecation-lint.rs:34:17
Expand All @@ -53,10 +53,10 @@ LL | let _ = DeprecatedUnitStruct;
| ^^^^^^^^^^^^^^^^^^^^

error: use of deprecated variant `deprecation_lint::Enum::DeprecatedVariant`: text
--> $DIR/deprecation-lint.rs:40:17
--> $DIR/deprecation-lint.rs:40:23
|
LL | let _ = Enum::DeprecatedVariant;
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^

error: use of deprecated struct `deprecation_lint::DeprecatedTupleStruct`: text
--> $DIR/deprecation-lint.rs:42:17
Expand All @@ -65,28 +65,28 @@ LL | let _ = DeprecatedTupleStruct (1);
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated struct `deprecation_lint::nested::DeprecatedStruct`: text
--> $DIR/deprecation-lint.rs:44:17
--> $DIR/deprecation-lint.rs:44:25
|
LL | let _ = nested::DeprecatedStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated struct `deprecation_lint::nested::DeprecatedUnitStruct`: text
--> $DIR/deprecation-lint.rs:48:17
--> $DIR/deprecation-lint.rs:48:25
|
LL | let _ = nested::DeprecatedUnitStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^

error: use of deprecated variant `deprecation_lint::nested::Enum::DeprecatedVariant`: text
--> $DIR/deprecation-lint.rs:50:17
--> $DIR/deprecation-lint.rs:50:31
|
LL | ... let _ = nested::Enum::DeprecatedVariant;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^

error: use of deprecated struct `deprecation_lint::nested::DeprecatedTupleStruct`: text
--> $DIR/deprecation-lint.rs:52:17
--> $DIR/deprecation-lint.rs:52:25
|
LL | ... let _ = nested::DeprecatedTupleStruct (1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated function `deprecation_lint::deprecated_text`: text
--> $DIR/deprecation-lint.rs:59:25
Expand All @@ -101,28 +101,28 @@ LL | macro_test_arg!(macro_test_arg!(deprecated_text()));
| ^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:65:9
--> $DIR/deprecation-lint.rs:65:16
|
LL | Trait::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:67:9
--> $DIR/deprecation-lint.rs:67:25
|
LL | <Foo as Trait>::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:69:9
--> $DIR/deprecation-lint.rs:69:16
|
LL | ... Trait::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:71:9
--> $DIR/deprecation-lint.rs:71:25
|
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
--> $DIR/deprecation-lint.rs:81:10
Expand Down Expand Up @@ -173,10 +173,10 @@ LL | let Deprecated2
| ^^^^^^^^^^^

error: use of deprecated function `deprecation_lint::deprecated_mod::deprecated`: text
--> $DIR/deprecation-lint.rs:162:9
--> $DIR/deprecation-lint.rs:162:25
|
LL | deprecated_mod::deprecated();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^

error: use of deprecated function `this_crate::deprecated`: text
--> $DIR/deprecation-lint.rs:245:9
Expand All @@ -185,16 +185,16 @@ LL | deprecated();
| ^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:250:9
--> $DIR/deprecation-lint.rs:250:16
|
LL | Trait::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:252:9
--> $DIR/deprecation-lint.rs:252:25
|
LL | <Foo as Trait>::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated function `this_crate::deprecated_text`: text
--> $DIR/deprecation-lint.rs:254:9
Expand All @@ -203,16 +203,16 @@ LL | deprecated_text();
| ^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:259:9
--> $DIR/deprecation-lint.rs:259:16
|
LL | Trait::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:261:9
--> $DIR/deprecation-lint.rs:261:25
|
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated function `this_crate::deprecated_future`: text
--> $DIR/deprecation-lint.rs:264:9
Expand All @@ -239,10 +239,10 @@ LL | let _ = DeprecatedUnitStruct;
| ^^^^^^^^^^^^^^^^^^^^

error: use of deprecated unit variant `this_crate::Enum::DeprecatedVariant`: text
--> $DIR/deprecation-lint.rs:274:17
--> $DIR/deprecation-lint.rs:274:23
|
LL | let _ = Enum::DeprecatedVariant;
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^

error: use of deprecated tuple struct `this_crate::DeprecatedTupleStruct`: text
--> $DIR/deprecation-lint.rs:276:17
Expand All @@ -251,52 +251,52 @@ LL | let _ = DeprecatedTupleStruct (1);
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated struct `this_crate::nested::DeprecatedStruct`: text
--> $DIR/deprecation-lint.rs:278:17
--> $DIR/deprecation-lint.rs:278:25
|
LL | let _ = nested::DeprecatedStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated unit struct `this_crate::nested::DeprecatedUnitStruct`: text
--> $DIR/deprecation-lint.rs:283:17
--> $DIR/deprecation-lint.rs:283:25
|
LL | let _ = nested::DeprecatedUnitStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^

error: use of deprecated unit variant `this_crate::nested::Enum::DeprecatedVariant`: text
--> $DIR/deprecation-lint.rs:285:17
--> $DIR/deprecation-lint.rs:285:31
|
LL | ... let _ = nested::Enum::DeprecatedVariant;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^

error: use of deprecated tuple struct `this_crate::nested::DeprecatedTupleStruct`: text
--> $DIR/deprecation-lint.rs:287:17
--> $DIR/deprecation-lint.rs:287:25
|
LL | ... let _ = nested::DeprecatedTupleStruct (1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:292:9
--> $DIR/deprecation-lint.rs:292:16
|
LL | Trait::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:294:9
--> $DIR/deprecation-lint.rs:294:25
|
LL | <Foo as Trait>::trait_deprecated(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:296:9
--> $DIR/deprecation-lint.rs:296:16
|
LL | Trait::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
--> $DIR/deprecation-lint.rs:298:9
--> $DIR/deprecation-lint.rs:298:25
|
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^

error: use of deprecated function `this_crate::test_fn_closure_body::{closure#0}::bar`
--> $DIR/deprecation-lint.rs:316:13
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/deprecation/suggestion.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@ impl Foo {
fn replacement(&self) {}
}

mod bar {
#[rustc_deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
pub fn deprecated() {}

pub fn replacement() {}
}

fn main() {
let foo = Foo;

foo.replacement(); //~ ERROR use of deprecated

bar::replacement(); //~ ERROR use of deprecated
}
14 changes: 14 additions & 0 deletions src/test/ui/deprecation/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@ impl Foo {
fn replacement(&self) {}
}

mod bar {
#[rustc_deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
pub fn deprecated() {}

pub fn replacement() {}
}

fn main() {
let foo = Foo;

foo.deprecated(); //~ ERROR use of deprecated

bar::deprecated(); //~ ERROR use of deprecated
}
Loading