Skip to content

Commit 8a2fe75

Browse files
committed
Auto merge of rust-lang#95960 - jhpratt:remove-rustc_deprecated, r=compiler-errors
Remove `#[rustc_deprecated]` This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires rust-lang#95958, which includes converting `stdarch`. I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2 parents db5b365 + dac487a commit 8a2fe75

Some content is hidden

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

98 files changed

+406
-437
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ where
679679
continue;
680680
}
681681

682-
if let Some((_, span)) = &depr {
683-
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
684-
.span_label(attr.span, "repeated deprecation attribute")
685-
.span_label(*span, "first deprecation attribute")
682+
// FIXME(jhpratt) remove this eventually
683+
if attr.has_name(sym::rustc_deprecated) {
684+
diagnostic
685+
.struct_span_err(attr.span, "`#[rustc_deprecated]` has been removed")
686+
.help("use `#[deprecated]` instead")
686687
.emit();
687-
break;
688688
}
689689

690690
let Some(meta) = attr.meta() else {
@@ -742,12 +742,24 @@ where
742742
continue 'outer;
743743
}
744744
}
745-
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
746-
// error specific to the renaming would be a good idea as well.
745+
// FIXME(jhpratt) remove this eventually
747746
sym::reason if attr.has_name(sym::rustc_deprecated) => {
748747
if !get(mi, &mut note) {
749748
continue 'outer;
750749
}
750+
751+
let mut diag = diagnostic
752+
.struct_span_err(mi.span, "`reason` has been renamed");
753+
match note {
754+
Some(note) => diag.span_suggestion(
755+
mi.span,
756+
"use `note` instead",
757+
format!("note = \"{note}\""),
758+
Applicability::MachineApplicable,
759+
),
760+
None => diag.span_help(mi.span, "use `note` instead"),
761+
};
762+
diag.emit();
751763
}
752764
sym::suggestion => {
753765
if !sess.features_untracked().deprecated_suggestion {

compiler/rustc_error_codes/src/error_codes/E0539.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Erroneous code example:
66
#![feature(staged_api)]
77
#![stable(since = "1.0.0", feature = "test")]
88
9-
#[rustc_deprecated(reason)] // error!
9+
#[deprecated(note)] // error!
1010
#[unstable(feature = "deprecated_fn", issue = "123")]
1111
fn deprecated() {}
1212
@@ -30,7 +30,7 @@ To fix these issues you need to give required key-value pairs.
3030
#![feature(staged_api)]
3131
#![stable(since = "1.0.0", feature = "test")]
3232
33-
#[rustc_deprecated(since = "1.39.0", reason = "reason")] // ok!
33+
#[deprecated(since = "1.39.0", note = "reason")] // ok!
3434
#[unstable(feature = "deprecated_fn", issue = "123")]
3535
fn deprecated() {}
3636

compiler/rustc_error_codes/src/error_codes/E0542.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn _stable_fn() {}
1313
const fn _stable_const_fn() {}
1414
1515
#[stable(feature = "_deprecated_fn", since = "0.1.0")]
16-
#[rustc_deprecated(
17-
reason = "explanation for deprecation"
16+
#[deprecated(
17+
note = "explanation for deprecation"
1818
)] // invalid
1919
fn _deprecated_fn() {}
2020
```
@@ -32,9 +32,9 @@ fn _stable_fn() {}
3232
const fn _stable_const_fn() {}
3333
3434
#[stable(feature = "_deprecated_fn", since = "0.1.0")]
35-
#[rustc_deprecated(
35+
#[deprecated(
3636
since = "1.0.0",
37-
reason = "explanation for deprecation"
37+
note = "explanation for deprecation"
3838
)] // ok!
3939
fn _deprecated_fn() {}
4040
```

compiler/rustc_error_codes/src/error_codes/E0543.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The `reason` value is missing in a stability attribute.
1+
The `note` value is missing in a stability attribute.
22

33
Erroneous code example:
44

@@ -7,22 +7,22 @@ Erroneous code example:
77
#![stable(since = "1.0.0", feature = "test")]
88
99
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
10-
#[rustc_deprecated(
10+
#[deprecated(
1111
since = "1.0.0"
1212
)] // invalid
1313
fn _deprecated_fn() {}
1414
```
1515

16-
To fix this issue, you need to provide the `reason` field. Example:
16+
To fix this issue, you need to provide the `note` field. Example:
1717

1818
```
1919
#![feature(staged_api)]
2020
#![stable(since = "1.0.0", feature = "test")]
2121
2222
#[stable(since = "0.1.0", feature = "_deprecated_fn")]
23-
#[rustc_deprecated(
23+
#[deprecated(
2424
since = "1.0.0",
25-
reason = "explanation for deprecation"
25+
note = "explanation for deprecation"
2626
)] // ok!
2727
fn _deprecated_fn() {}
2828
```

compiler/rustc_error_codes/src/error_codes/E0549.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
A `rustc_deprecated` attribute wasn't paired with a `stable`/`unstable`
2-
attribute.
1+
A `deprecated` attribute wasn't paired with a `stable`/`unstable` attribute with
2+
`#![feature(staged_api)]` enabled.
33

44
Erroneous code example:
55

66
```compile_fail,E0549
77
#![feature(staged_api)]
88
#![stable(since = "1.0.0", feature = "test")]
99
10-
#[rustc_deprecated(
10+
#[deprecated(
1111
since = "1.0.1",
12-
reason = "explanation for deprecation"
12+
note = "explanation for deprecation"
1313
)] // invalid
1414
fn _deprecated_fn() {}
1515
```
@@ -22,9 +22,9 @@ Example:
2222
#![stable(since = "1.0.0", feature = "test")]
2323
2424
#[stable(since = "1.0.0", feature = "test")]
25-
#[rustc_deprecated(
25+
#[deprecated(
2626
since = "1.0.1",
27-
reason = "explanation for deprecation"
27+
note = "explanation for deprecation"
2828
)] // ok!
2929
fn _deprecated_fn() {}
3030
```

compiler/rustc_error_codes/src/error_codes/E0550.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler
2+
13
More than one `deprecated` attribute has been put on an item.
24

35
Erroneous code example:
46

5-
```compile_fail,E0550
7+
```compile_fail
68
#[deprecated(note = "because why not?")]
79
#[deprecated(note = "right?")] // error!
810
fn the_banished() {}

compiler/rustc_error_codes/src/error_codes/E0734.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ A stability attribute has been used outside of the standard library.
33
Erroneous code example:
44

55
```compile_fail,E0734
6-
#[rustc_deprecated(since = "b", reason = "text")] // invalid
76
#[stable(feature = "a", since = "b")] // invalid
87
#[unstable(feature = "b", issue = "none")] // invalid
98
fn foo(){}

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
304304
List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
305305
NameValueStr: "reason"
306306
),
307-
// This has special duplicate handling in E0550 to handle duplicates with rustc_deprecated
308-
DuplicatesOk
307+
ErrorFollowing
309308
),
310309

311310
// Crate properties:
@@ -469,10 +468,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
469468
// ==========================================================================
470469

471470
ungated!(feature, CrateLevel, template!(List: "name1, name2, ..."), DuplicatesOk),
472-
// DuplicatesOk since it has its own validation
471+
// FIXME(jhpratt) remove this eventually
473472
ungated!(
474473
rustc_deprecated, Normal,
475-
template!(List: r#"since = "version", note = "...""#), DuplicatesOk // See E0550
474+
template!(List: r#"since = "version", note = "...""#), ErrorFollowing
476475
),
477476
// DuplicatesOk since it has its own validation
478477
ungated!(

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,13 +2201,12 @@ declare_lint! {
22012201
/// used by user code.
22022202
///
22032203
/// This lint is only enabled in the standard library. It works with the
2204-
/// use of `#[rustc_deprecated]` with a `since` field of a version in the
2205-
/// future. This allows something to be marked as deprecated in a future
2206-
/// version, and then this lint will ensure that the item is no longer
2207-
/// used in the standard library. See the [stability documentation] for
2208-
/// more details.
2204+
/// use of `#[deprecated]` with a `since` field of a version in the future.
2205+
/// This allows something to be marked as deprecated in a future version,
2206+
/// and then this lint will ensure that the item is no longer used in the
2207+
/// standard library. See the [stability documentation] for more details.
22092208
///
2210-
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
2209+
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
22112210
pub DEPRECATED_IN_FUTURE,
22122211
Allow,
22132212
"detects use of items that will be deprecated in a future version",

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
118118
}
119119

120120
if !is_since_rustc_version {
121-
// The `since` field doesn't have semantic purpose in the stable `deprecated`
122-
// attribute, only in `rustc_deprecated`.
121+
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
123122
return true;
124123
}
125124

@@ -336,7 +335,7 @@ impl<'tcx> TyCtxt<'tcx> {
336335
// topmost deprecation. For example, if a struct is deprecated,
337336
// the use of a field won't be linted.
338337
//
339-
// #[rustc_deprecated] however wants to emit down the whole
338+
// With #![staged_api], we want to emit down the whole
340339
// hierarchy.
341340
let depr_attr = &depr_entry.attr;
342341
if !skip || depr_attr.is_since_rustc_version {

0 commit comments

Comments
 (0)