Skip to content

Commit

Permalink
New deprecated_suggestion feature, use in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Mar 9, 2022
1 parent 6efc8e3 commit 5636655
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
18 changes: 13 additions & 5 deletions compiler/rustc_attr/src/builtin.rs
Expand Up @@ -741,7 +741,19 @@ where
continue 'outer;
}
}
sym::suggestion if attr.has_name(sym::rustc_deprecated) => {
sym::suggestion => {
if !sess.features_untracked().deprecated_suggestion {
let mut diag = sess.struct_span_err(
mi.span,
"suggestions on deprecated items are unstable",
);
if sess.is_nightly_build() {
diag.help("add `#![feature(deprecated_suggestion)]` to the crate root");
}
// FIXME(jhpratt) change this to an actual tracking issue
diag.note("see #XXX for more details").emit();
}

if !get(mi, &mut suggestion) {
continue 'outer;
}
Expand Down Expand Up @@ -778,10 +790,6 @@ where
}
}

if suggestion.is_some() && attr.has_name(sym::deprecated) {
unreachable!("only allowed on rustc_deprecated")
}

if attr.has_name(sym::rustc_deprecated) {
if since.is_none() {
handle_errors(&sess.parse_sess, attr.span, AttrError::MissingSince);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -368,6 +368,8 @@ declare_features! (
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
/// Allows default type parameters to influence type inference.
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
/// Allows `#[derive(Default)]` and `#[default]` on enums.
(active, derive_default_enum, "1.56.0", Some(86985), None),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Expand Up @@ -562,6 +562,7 @@ symbols! {
delay_span_bug_from_inside_query,
deny,
deprecated,
deprecated_suggestion,
deref,
deref_method,
deref_mut,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Expand Up @@ -166,6 +166,7 @@
#![feature(const_refs_to_cell)]
#![feature(decl_macro)]
#![feature(derive_default_enum)]
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
#![feature(doc_cfg)]
#![feature(doc_notable_trait)]
#![feature(rustdoc_internals)]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Expand Up @@ -270,6 +270,7 @@
#![feature(doc_cfg)]
#![feature(doc_cfg_hide)]
#![feature(rustdoc_internals)]
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
#![feature(doc_masked)]
#![feature(doc_notable_trait)]
#![feature(dropck_eyepatch)]
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/deprecation/feature-gate-deprecated_suggestion.rs
@@ -0,0 +1,6 @@
// compile-flags: --crate-type=lib

#![no_implicit_prelude]

#[deprecated(suggestion = "foo")] //~ ERROR suggestions on deprecated items are unstable
struct Foo {}
11 changes: 11 additions & 0 deletions src/test/ui/deprecation/feature-gate-deprecated_suggestion.stderr
@@ -0,0 +1,11 @@
error: suggestions on deprecated items are unstable
--> $DIR/feature-gate-deprecated_suggestion.rs:5:14
|
LL | #[deprecated(suggestion = "foo")]
| ^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(deprecated_suggestion)]` to the crate root
= note: see #XXX for more details

error: aborting due to previous error

1 change: 1 addition & 0 deletions src/test/ui/deprecation/suggestion.fixed
@@ -1,6 +1,7 @@
// run-rustfix

#![feature(staged_api)]
#![feature(deprecated_suggestion)]

#![stable(since = "1.0.0", feature = "test")]

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/deprecation/suggestion.rs
@@ -1,6 +1,7 @@
// run-rustfix

#![feature(staged_api)]
#![feature(deprecated_suggestion)]

#![stable(since = "1.0.0", feature = "test")]

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/deprecation/suggestion.stderr
@@ -1,17 +1,17 @@
error: use of deprecated function `bar::deprecated`: replaced by `replacement`
--> $DIR/suggestion.rs:41:10
--> $DIR/suggestion.rs:42:10
|
LL | bar::deprecated();
| ^^^^^^^^^^ help: replace the use of the deprecated function: `replacement`
|
note: the lint level is defined here
--> $DIR/suggestion.rs:7:9
--> $DIR/suggestion.rs:8:9
|
LL | #![deny(deprecated)]
| ^^^^^^^^^^

error: use of deprecated associated function `Foo::deprecated`: replaced by `replacement`
--> $DIR/suggestion.rs:39:9
--> $DIR/suggestion.rs:40:9
|
LL | foo.deprecated();
| ^^^^^^^^^^ help: replace the use of the deprecated associated function: `replacement`
Expand Down

0 comments on commit 5636655

Please sign in to comment.