From 5636655d0f0afb0d509cd86ad479773f5854630e Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Wed, 16 Feb 2022 18:48:33 -0500 Subject: [PATCH] New `deprecated_suggestion` feature, use in tests --- compiler/rustc_attr/src/builtin.rs | 18 +++++++++++++----- compiler/rustc_feature/src/active.rs | 2 ++ compiler/rustc_span/src/symbol.rs | 1 + library/core/src/lib.rs | 1 + library/std/src/lib.rs | 1 + .../feature-gate-deprecated_suggestion.rs | 6 ++++++ .../feature-gate-deprecated_suggestion.stderr | 11 +++++++++++ src/test/ui/deprecation/suggestion.fixed | 1 + src/test/ui/deprecation/suggestion.rs | 1 + src/test/ui/deprecation/suggestion.stderr | 6 +++--- 10 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/deprecation/feature-gate-deprecated_suggestion.rs create mode 100644 src/test/ui/deprecation/feature-gate-deprecated_suggestion.stderr diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index e965cc4f385..9a750d9f40f 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -741,7 +741,19 @@ fn find_deprecation_generic<'a, I>(sess: &Session, attrs_iter: I) -> Option<(Dep 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; } @@ -778,10 +790,6 @@ fn find_deprecation_generic<'a, I>(sess: &Session, attrs_iter: I) -> Option<(Dep } } - 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); diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1f7dc769512..d39847f7b97 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -368,6 +368,8 @@ pub fn set(&self, features: &mut Features, span: Span) { (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(...))]`. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9d452131fa6..793e7286e96 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -562,6 +562,7 @@ delay_span_bug_from_inside_query, deny, deprecated, + deprecated_suggestion, deref, deref_method, deref_mut, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index e7896b2cb66..34b09129964 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -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)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 10fec8e1152..4040db38be7 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -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)] diff --git a/src/test/ui/deprecation/feature-gate-deprecated_suggestion.rs b/src/test/ui/deprecation/feature-gate-deprecated_suggestion.rs new file mode 100644 index 00000000000..a2d0023e3f4 --- /dev/null +++ b/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 {} diff --git a/src/test/ui/deprecation/feature-gate-deprecated_suggestion.stderr b/src/test/ui/deprecation/feature-gate-deprecated_suggestion.stderr new file mode 100644 index 00000000000..3b995fed75c --- /dev/null +++ b/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 + diff --git a/src/test/ui/deprecation/suggestion.fixed b/src/test/ui/deprecation/suggestion.fixed index 7d662227881..6c2718a0296 100644 --- a/src/test/ui/deprecation/suggestion.fixed +++ b/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")] diff --git a/src/test/ui/deprecation/suggestion.rs b/src/test/ui/deprecation/suggestion.rs index b34dc0eb83a..d512d3227b8 100644 --- a/src/test/ui/deprecation/suggestion.rs +++ b/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")] diff --git a/src/test/ui/deprecation/suggestion.stderr b/src/test/ui/deprecation/suggestion.stderr index 7d78b222244..8d1e108345f 100644 --- a/src/test/ui/deprecation/suggestion.stderr +++ b/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`