Skip to content

Commit 5636655

Browse files
committed
New deprecated_suggestion feature, use in tests
1 parent 6efc8e3 commit 5636655

File tree

10 files changed

+40
-8
lines changed

10 files changed

+40
-8
lines changed

compiler/rustc_attr/src/builtin.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,19 @@ where
741741
continue 'outer;
742742
}
743743
}
744-
sym::suggestion if attr.has_name(sym::rustc_deprecated) => {
744+
sym::suggestion => {
745+
if !sess.features_untracked().deprecated_suggestion {
746+
let mut diag = sess.struct_span_err(
747+
mi.span,
748+
"suggestions on deprecated items are unstable",
749+
);
750+
if sess.is_nightly_build() {
751+
diag.help("add `#![feature(deprecated_suggestion)]` to the crate root");
752+
}
753+
// FIXME(jhpratt) change this to an actual tracking issue
754+
diag.note("see #XXX for more details").emit();
755+
}
756+
745757
if !get(mi, &mut suggestion) {
746758
continue 'outer;
747759
}
@@ -778,10 +790,6 @@ where
778790
}
779791
}
780792

781-
if suggestion.is_some() && attr.has_name(sym::deprecated) {
782-
unreachable!("only allowed on rustc_deprecated")
783-
}
784-
785793
if attr.has_name(sym::rustc_deprecated) {
786794
if since.is_none() {
787795
handle_errors(&sess.parse_sess, attr.span, AttrError::MissingSince);

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ declare_features! (
368368
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
369369
/// Allows default type parameters to influence type inference.
370370
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
371+
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
372+
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
371373
/// Allows `#[derive(Default)]` and `#[default]` on enums.
372374
(active, derive_default_enum, "1.56.0", Some(86985), None),
373375
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ symbols! {
562562
delay_span_bug_from_inside_query,
563563
deny,
564564
deprecated,
565+
deprecated_suggestion,
565566
deref,
566567
deref_method,
567568
deref_mut,

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
#![feature(const_refs_to_cell)]
167167
#![feature(decl_macro)]
168168
#![feature(derive_default_enum)]
169+
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
169170
#![feature(doc_cfg)]
170171
#![feature(doc_notable_trait)]
171172
#![feature(rustdoc_internals)]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
#![feature(doc_cfg)]
271271
#![feature(doc_cfg_hide)]
272272
#![feature(rustdoc_internals)]
273+
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
273274
#![feature(doc_masked)]
274275
#![feature(doc_notable_trait)]
275276
#![feature(dropck_eyepatch)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// compile-flags: --crate-type=lib
2+
3+
#![no_implicit_prelude]
4+
5+
#[deprecated(suggestion = "foo")] //~ ERROR suggestions on deprecated items are unstable
6+
struct Foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: suggestions on deprecated items are unstable
2+
--> $DIR/feature-gate-deprecated_suggestion.rs:5:14
3+
|
4+
LL | #[deprecated(suggestion = "foo")]
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(deprecated_suggestion)]` to the crate root
8+
= note: see #XXX for more details
9+
10+
error: aborting due to previous error
11+

src/test/ui/deprecation/suggestion.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![feature(staged_api)]
4+
#![feature(deprecated_suggestion)]
45

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

src/test/ui/deprecation/suggestion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![feature(staged_api)]
4+
#![feature(deprecated_suggestion)]
45

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

src/test/ui/deprecation/suggestion.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: use of deprecated function `bar::deprecated`: replaced by `replacement`
2-
--> $DIR/suggestion.rs:41:10
2+
--> $DIR/suggestion.rs:42:10
33
|
44
LL | bar::deprecated();
55
| ^^^^^^^^^^ help: replace the use of the deprecated function: `replacement`
66
|
77
note: the lint level is defined here
8-
--> $DIR/suggestion.rs:7:9
8+
--> $DIR/suggestion.rs:8:9
99
|
1010
LL | #![deny(deprecated)]
1111
| ^^^^^^^^^^
1212

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

0 commit comments

Comments
 (0)