Skip to content

Commit

Permalink
Rollup merge of #94635 - jhpratt:merge-deprecated-attrs, r=davidtwco
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matthiaskrgr authored Mar 10, 2022
2 parents 7473750 + 38478ea commit 313a668
Show file tree
Hide file tree
Showing 42 changed files with 217 additions and 380 deletions.
7 changes: 0 additions & 7 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
)
.emit();
}
} else {
if attr.has_name(sym::deprecated) {
self.sess
.struct_span_err(attr.span, "`#[deprecated]` cannot be used in staged API")
.span_label(attr.span, "use `#[rustc_deprecated]` instead")
.emit();
}
}
}

Expand Down
35 changes: 24 additions & 11 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ where
{
let mut depr: Option<(Deprecation, Span)> = None;
let diagnostic = &sess.parse_sess.span_diagnostic;
let is_rustc = sess.features_untracked().staged_api;

'outer: for attr in attrs_iter {
if !(attr.has_name(sym::deprecated) || attr.has_name(sym::rustc_deprecated)) {
Expand Down Expand Up @@ -728,17 +729,31 @@ where
continue 'outer;
}
}
sym::note if attr.has_name(sym::deprecated) => {
sym::note => {
if !get(mi, &mut note) {
continue 'outer;
}
}
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
// error specific to the renaming would be a good idea as well.
sym::reason if attr.has_name(sym::rustc_deprecated) => {
if !get(mi, &mut note) {
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 All @@ -752,7 +767,7 @@ where
if attr.has_name(sym::deprecated) {
&["since", "note"]
} else {
&["since", "reason", "suggestion"]
&["since", "note", "suggestion"]
},
),
);
Expand All @@ -775,24 +790,22 @@ where
}
}

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

if attr.has_name(sym::rustc_deprecated) {
if is_rustc {
if since.is_none() {
handle_errors(&sess.parse_sess, attr.span, AttrError::MissingSince);
continue;
}

if note.is_none() {
struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'").emit();
struct_span_err!(diagnostic, attr.span, E0543, "missing 'note'").emit();
continue;
}
}

let is_since_rustc_version = attr.has_name(sym::rustc_deprecated);
depr = Some((Deprecation { since, note, suggestion, is_since_rustc_version }, attr.span));
depr = Some((
Deprecation { since, note, suggestion, is_since_rustc_version: is_rustc },
attr.span,
));
}

depr
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,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
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// DuplicatesOk since it has its own validation
ungated!(
rustc_deprecated, Normal,
template!(List: r#"since = "version", reason = "...""#), DuplicatesOk // See E0550
template!(List: r#"since = "version", note = "...""#), DuplicatesOk // See E0550
),
// DuplicatesOk since it has its own validation
ungated!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
self.tcx.sess,
*span,
E0549,
"rustc_deprecated attribute must be paired with \
"deprecated attribute must be paired with \
either stable or unstable attribute"
)
.emit();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,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
4 changes: 0 additions & 4 deletions src/test/ui/deprecation/deprecation-in-staged-api.rs

This file was deleted.

8 changes: 0 additions & 8 deletions src/test/ui/deprecation/deprecation-in-staged-api.stderr

This file was deleted.

6 changes: 6 additions & 0 deletions src/test/ui/deprecation/feature-gate-deprecated_suggestion.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: use of unit struct `S1` that will be deprecated in future version 99.99.99: effectively never
--> $DIR/rustc_deprecation-in-future.rs:16:13
--> $DIR/staged-deprecation-in-future.rs:16:13
|
LL | let _ = S1;
| ^^
|
note: the lint level is defined here
--> $DIR/rustc_deprecation-in-future.rs:1:9
--> $DIR/staged-deprecation-in-future.rs:1:9
|
LL | #![deny(deprecated_in_future)]
| ^^^^^^^^^^^^^^^^^^^^

error: use of unit struct `S2` that will be deprecated in a future Rust version: literally never
--> $DIR/rustc_deprecation-in-future.rs:17:13
--> $DIR/staged-deprecation-in-future.rs:17:13
|
LL | let _ = S2;
| ^^
Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/deprecation/suggestion.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-rustfix

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

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

Expand All @@ -10,9 +11,9 @@
struct Foo;

impl Foo {
#[rustc_deprecated(
#[deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
note = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
Expand All @@ -22,9 +23,9 @@ impl Foo {
}

mod bar {
#[rustc_deprecated(
#[deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
note = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/deprecation/suggestion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-rustfix

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

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

Expand All @@ -10,9 +11,9 @@
struct Foo;

impl Foo {
#[rustc_deprecated(
#[deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
note = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
Expand All @@ -22,9 +23,9 @@ impl Foo {
}

mod bar {
#[rustc_deprecated(
#[deprecated(
since = "1.0.0",
reason = "replaced by `replacement`",
note = "replaced by `replacement`",
suggestion = "replacement",
)]
#[stable(since = "1.0.0", feature = "test")]
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/deprecation/suggestion.stderr
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Loading

0 comments on commit 313a668

Please sign in to comment.