Skip to content

Commit 313a668

Browse files
authored
Rollup merge of #94635 - jhpratt:merge-deprecated-attrs, r=davidtwco
Merge `#[deprecated]` and `#[rustc_deprecated]` The first commit makes "reason" an alias for "note" in `#[rustc_deprecated]`, while still prohibiting it in `#[deprecated]`. The second commit changes "suggestion" to not just be a feature of `#[rustc_deprecated]`. This is placed behind the new `deprecated_suggestion` feature. This needs a tracking issue; let me know if this PR will be approved and I can create one. The third commit is what permits `#[deprecated]` to be used when `#![feature(staged_api)]` is enabled. This isn't yet used in stdlib (only tests), as it would require duplicating all deprecation attributes until a bootstrap occurs. I intend to submit a follow-up PR that replaces all uses and removes the remaining `#[rustc_deprecated]` code after the next bootstrap. `@rustbot` label +T-libs-api +C-feature-request +A-attributes +S-waiting-on-review
2 parents 7473750 + 38478ea commit 313a668

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+217
-380
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-7
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
437437
)
438438
.emit();
439439
}
440-
} else {
441-
if attr.has_name(sym::deprecated) {
442-
self.sess
443-
.struct_span_err(attr.span, "`#[deprecated]` cannot be used in staged API")
444-
.span_label(attr.span, "use `#[rustc_deprecated]` instead")
445-
.emit();
446-
}
447440
}
448441
}
449442

compiler/rustc_attr/src/builtin.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ where
664664
{
665665
let mut depr: Option<(Deprecation, Span)> = None;
666666
let diagnostic = &sess.parse_sess.span_diagnostic;
667+
let is_rustc = sess.features_untracked().staged_api;
667668

668669
'outer: for attr in attrs_iter {
669670
if !(attr.has_name(sym::deprecated) || attr.has_name(sym::rustc_deprecated)) {
@@ -728,17 +729,31 @@ where
728729
continue 'outer;
729730
}
730731
}
731-
sym::note if attr.has_name(sym::deprecated) => {
732+
sym::note => {
732733
if !get(mi, &mut note) {
733734
continue 'outer;
734735
}
735736
}
737+
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
738+
// error specific to the renaming would be a good idea as well.
736739
sym::reason if attr.has_name(sym::rustc_deprecated) => {
737740
if !get(mi, &mut note) {
738741
continue 'outer;
739742
}
740743
}
741-
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+
742757
if !get(mi, &mut suggestion) {
743758
continue 'outer;
744759
}
@@ -752,7 +767,7 @@ where
752767
if attr.has_name(sym::deprecated) {
753768
&["since", "note"]
754769
} else {
755-
&["since", "reason", "suggestion"]
770+
&["since", "note", "suggestion"]
756771
},
757772
),
758773
);
@@ -775,24 +790,22 @@ where
775790
}
776791
}
777792

778-
if suggestion.is_some() && attr.has_name(sym::deprecated) {
779-
unreachable!("only allowed on rustc_deprecated")
780-
}
781-
782-
if attr.has_name(sym::rustc_deprecated) {
793+
if is_rustc {
783794
if since.is_none() {
784795
handle_errors(&sess.parse_sess, attr.span, AttrError::MissingSince);
785796
continue;
786797
}
787798

788799
if note.is_none() {
789-
struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'").emit();
800+
struct_span_err!(diagnostic, attr.span, E0543, "missing 'note'").emit();
790801
continue;
791802
}
792803
}
793804

794-
let is_since_rustc_version = attr.has_name(sym::rustc_deprecated);
795-
depr = Some((Deprecation { since, note, suggestion, is_since_rustc_version }, attr.span));
805+
depr = Some((
806+
Deprecation { since, note, suggestion, is_since_rustc_version: is_rustc },
807+
attr.span,
808+
));
796809
}
797810

798811
depr

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ declare_features! (
362362
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
363363
/// Allows default type parameters to influence type inference.
364364
(active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
365+
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
366+
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
365367
/// Allows `#[derive(Default)]` and `#[default]` on enums.
366368
(active, derive_default_enum, "1.56.0", Some(86985), None),
367369
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
461461
// DuplicatesOk since it has its own validation
462462
ungated!(
463463
rustc_deprecated, Normal,
464-
template!(List: r#"since = "version", reason = "...""#), DuplicatesOk // See E0550
464+
template!(List: r#"since = "version", note = "...""#), DuplicatesOk // See E0550
465465
),
466466
// DuplicatesOk since it has its own validation
467467
ungated!(

compiler/rustc_passes/src/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
202202
self.tcx.sess,
203203
*span,
204204
E0549,
205-
"rustc_deprecated attribute must be paired with \
205+
"deprecated attribute must be paired with \
206206
either stable or unstable attribute"
207207
)
208208
.emit();

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
@@ -167,6 +167,7 @@
167167
#![feature(const_refs_to_cell)]
168168
#![feature(decl_macro)]
169169
#![feature(derive_default_enum)]
170+
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
170171
#![feature(doc_cfg)]
171172
#![feature(doc_notable_trait)]
172173
#![feature(rustdoc_internals)]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
#![feature(doc_cfg)]
264264
#![feature(doc_cfg_hide)]
265265
#![feature(rustdoc_internals)]
266+
#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))]
266267
#![feature(doc_masked)]
267268
#![feature(doc_notable_trait)]
268269
#![feature(dropck_eyepatch)]

src/test/ui/deprecation/deprecation-in-staged-api.rs

-4
This file was deleted.

src/test/ui/deprecation/deprecation-in-staged-api.stderr

-8
This file was deleted.
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/rustc_deprecation-in-future.rs renamed to src/test/ui/deprecation/staged-deprecation-in-future.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#![stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
66

7-
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
7+
#[deprecated(since = "99.99.99", note = "effectively never")]
88
#[stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
99
pub struct S1;
1010

11-
#[rustc_deprecated(since = "TBD", reason = "literally never")]
11+
#[deprecated(since = "TBD", note = "literally never")]
1212
#[stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
1313
pub struct S2;
1414

src/test/ui/deprecation/rustc_deprecation-in-future.stderr renamed to src/test/ui/deprecation/staged-deprecation-in-future.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: use of unit struct `S1` that will be deprecated in future version 99.99.99: effectively never
2-
--> $DIR/rustc_deprecation-in-future.rs:16:13
2+
--> $DIR/staged-deprecation-in-future.rs:16:13
33
|
44
LL | let _ = S1;
55
| ^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/rustc_deprecation-in-future.rs:1:9
8+
--> $DIR/staged-deprecation-in-future.rs:1:9
99
|
1010
LL | #![deny(deprecated_in_future)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: use of unit struct `S2` that will be deprecated in a future Rust version: literally never
14-
--> $DIR/rustc_deprecation-in-future.rs:17:13
14+
--> $DIR/staged-deprecation-in-future.rs:17:13
1515
|
1616
LL | let _ = S2;
1717
| ^^

src/test/ui/deprecation/suggestion.fixed

+5-4
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

@@ -10,9 +11,9 @@
1011
struct Foo;
1112

1213
impl Foo {
13-
#[rustc_deprecated(
14+
#[deprecated(
1415
since = "1.0.0",
15-
reason = "replaced by `replacement`",
16+
note = "replaced by `replacement`",
1617
suggestion = "replacement",
1718
)]
1819
#[stable(since = "1.0.0", feature = "test")]
@@ -22,9 +23,9 @@ impl Foo {
2223
}
2324

2425
mod bar {
25-
#[rustc_deprecated(
26+
#[deprecated(
2627
since = "1.0.0",
27-
reason = "replaced by `replacement`",
28+
note = "replaced by `replacement`",
2829
suggestion = "replacement",
2930
)]
3031
#[stable(since = "1.0.0", feature = "test")]

src/test/ui/deprecation/suggestion.rs

+5-4
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

@@ -10,9 +11,9 @@
1011
struct Foo;
1112

1213
impl Foo {
13-
#[rustc_deprecated(
14+
#[deprecated(
1415
since = "1.0.0",
15-
reason = "replaced by `replacement`",
16+
note = "replaced by `replacement`",
1617
suggestion = "replacement",
1718
)]
1819
#[stable(since = "1.0.0", feature = "test")]
@@ -22,9 +23,9 @@ impl Foo {
2223
}
2324

2425
mod bar {
25-
#[rustc_deprecated(
26+
#[deprecated(
2627
since = "1.0.0",
27-
reason = "replaced by `replacement`",
28+
note = "replaced by `replacement`",
2829
suggestion = "replacement",
2930
)]
3031
#[stable(since = "1.0.0", feature = "test")]

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`

src/test/ui/feature-gates/issue-43106-gating-of-rustc_deprecated.rs

-43
This file was deleted.

0 commit comments

Comments
 (0)