Skip to content

Commit 5e02212

Browse files
committed
Note the version and PR of removed features when using it
Signed-off-by: xizheyin <[email protected]>
1 parent 8ddc69e commit 5e02212

18 files changed

+71
-21
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ expand_feature_not_allowed =
6262
expand_feature_removed =
6363
feature has been removed
6464
.label = feature has been removed
65+
.note = removed in {$removed_rustc_version} (you are using {$current_rustc_version}){$pull_note}
6566
.reason = {$reason}
6667
6768
expand_glob_delegation_outside_impls =

compiler/rustc_expand/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,20 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
8181

8282
// If the enabled feature has been removed, issue an error.
8383
if let Some(f) = REMOVED_LANG_FEATURES.iter().find(|f| name == f.feature.name) {
84+
let pull_note = if let Some(pull) = f.pull {
85+
format!(
86+
"; see <https://github.com/rust-lang/rust/pull/{}> for more information",
87+
pull
88+
)
89+
} else {
90+
"".to_owned()
91+
};
8492
sess.dcx().emit_err(FeatureRemoved {
8593
span: mi.span(),
8694
reason: f.reason.map(|reason| FeatureRemovedReason { reason }),
95+
removed_rustc_version: f.feature.since,
96+
current_rustc_version: sess.cfg_version,
97+
pull_note,
8798
});
8899
continue;
89100
}

compiler/rustc_expand/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ pub(crate) struct HelperAttributeNameInvalid {
154154

155155
#[derive(Diagnostic)]
156156
#[diag(expand_feature_removed, code = E0557)]
157+
#[note]
157158
pub(crate) struct FeatureRemoved<'a> {
158159
#[primary_span]
159160
#[label]
160161
pub span: Span,
161162
#[subdiagnostic]
162163
pub reason: Option<FeatureRemovedReason<'a>>,
164+
pub removed_rustc_version: &'a str,
165+
pub current_rustc_version: &'a str,
166+
pub pull_note: String,
163167
}
164168

165169
#[derive(Subdiagnostic)]

compiler/rustc_feature/src/removed.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
//! List of the removed feature gates.
22
3+
use std::num::{NonZero, NonZeroU32};
4+
35
use rustc_span::sym;
46

57
use super::{Feature, to_nonzero};
68

79
pub struct RemovedFeature {
810
pub feature: Feature,
911
pub reason: Option<&'static str>,
12+
pub pull: Option<NonZero<u32>>,
13+
}
14+
15+
macro_rules! opt_nonzero_u32 {
16+
() => {
17+
None
18+
};
19+
($val:expr) => {
20+
Some(NonZeroU32::new($val).unwrap())
21+
};
1022
}
1123

1224
macro_rules! declare_features {
1325
($(
14-
$(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, $reason:expr),
26+
$(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, $reason:expr $(, $pull:expr)?),
1527
)+) => {
1628
/// Formerly unstable features that have now been removed.
1729
pub static REMOVED_LANG_FEATURES: &[RemovedFeature] = &[
@@ -21,7 +33,8 @@ macro_rules! declare_features {
2133
since: $ver,
2234
issue: to_nonzero($issue),
2335
},
24-
reason: $reason
36+
reason: $reason,
37+
pull: opt_nonzero_u32!($($pull)?),
2538
}),+
2639
];
2740
};
@@ -120,7 +133,7 @@ declare_features! (
120133
Some("subsumed by `::foo::bar` paths")),
121134
/// Allows `#[doc(include = "some-file")]`.
122135
(removed, external_doc, "1.54.0", Some(44732),
123-
Some("use #[doc = include_str!(\"filename\")] instead, which handles macro invocations")),
136+
Some("use #[doc = include_str!(\"filename\")] instead, which handles macro invocations"), 85457),
124137
/// Allows using `#[ffi_returns_twice]` on foreign functions.
125138
(removed, ffi_returns_twice, "1.78.0", Some(58314),
126139
Some("being investigated by the ffi-unwind project group")),

tests/ui/deprecation/deprecated_no_stack_check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
2+
13
#![deny(warnings)]
24
#![feature(no_stack_check)]
35
//~^ ERROR: feature has been removed [E0557]

tests/ui/deprecation/deprecated_no_stack_check.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/deprecated_no_stack_check.rs:2:12
2+
--> $DIR/deprecated_no_stack_check.rs:4:12
33
|
44
LL | #![feature(no_stack_check)]
55
| ^^^^^^^^^^^^^^ feature has been removed
6+
|
7+
= note: removed in 1.0.0 (you are using $RUSTC_VERSION)
68

79
error: aborting due to 1 previous error
810

tests/ui/feature-gates/feature-gate-coverage-attribute.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
2+
13
#![crate_type = "lib"]
24
#![feature(no_coverage)] //~ ERROR feature has been removed [E0557]
35

tests/ui/feature-gates/feature-gate-coverage-attribute.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/feature-gate-coverage-attribute.rs:2:12
2+
--> $DIR/feature-gate-coverage-attribute.rs:4:12
33
|
44
LL | #![feature(no_coverage)]
55
| ^^^^^^^^^^^ feature has been removed
66
|
7+
= note: removed in 1.74.0 (you are using $RUSTC_VERSION)
78
= note: renamed to `coverage_attribute`
89

910
error[E0658]: the `#[coverage]` attribute is an experimental feature
10-
--> $DIR/feature-gate-coverage-attribute.rs:10:1
11+
--> $DIR/feature-gate-coverage-attribute.rs:12:1
1112
|
1213
LL | #[coverage(off)]
1314
| ^^^^^^^^^^^^^^^^

tests/ui/feature-gates/gated-bad-feature.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
12
#![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
23
//~^ ERROR malformed `feature`
34
//~| ERROR malformed `feature`

tests/ui/feature-gates/gated-bad-feature.stderr

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
error[E0556]: malformed `feature` attribute input
2-
--> $DIR/gated-bad-feature.rs:1:25
2+
--> $DIR/gated-bad-feature.rs:2:25
33
|
44
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
55
| ^^^^^^^^ help: expected just one word: `foo`
66

77
error[E0556]: malformed `feature` attribute input
8-
--> $DIR/gated-bad-feature.rs:1:35
8+
--> $DIR/gated-bad-feature.rs:2:35
99
|
1010
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
1111
| ^^^^^^^^^^^ help: expected just one word: `foo`
1212

1313
error[E0557]: feature has been removed
14-
--> $DIR/gated-bad-feature.rs:8:12
14+
--> $DIR/gated-bad-feature.rs:9:12
1515
|
1616
LL | #![feature(test_removed_feature)]
1717
| ^^^^^^^^^^^^^^^^^^^^ feature has been removed
18+
|
19+
= note: removed in 1.0.0 (you are using $RUSTC_VERSION)
1820

1921
error: malformed `feature` attribute input
20-
--> $DIR/gated-bad-feature.rs:6:1
22+
--> $DIR/gated-bad-feature.rs:7:1
2123
|
2224
LL | #![feature]
2325
| ^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name2, ...)]`
2426

2527
error: malformed `feature` attribute input
26-
--> $DIR/gated-bad-feature.rs:7:1
28+
--> $DIR/gated-bad-feature.rs:8:1
2729
|
2830
LL | #![feature = "foo"]
2931
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name2, ...)]`
3032

3133
error[E0635]: unknown feature `foo_bar_baz`
32-
--> $DIR/gated-bad-feature.rs:1:12
34+
--> $DIR/gated-bad-feature.rs:2:12
3335
|
3436
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
3537
| ^^^^^^^^^^^
3638

3739
error[E0635]: unknown feature `foo`
38-
--> $DIR/gated-bad-feature.rs:1:48
40+
--> $DIR/gated-bad-feature.rs:2:48
3941
|
4042
LL | #![feature(foo_bar_baz, foo(bar), foo = "baz", foo)]
4143
| ^^^

tests/ui/feature-gates/removed-features-note-version-and-pr-issue-141619.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
2+
13
#![feature(external_doc)] //~ ERROR feature has been removed
24
#![doc(include("README.md"))] //~ ERROR unknown `doc` attribute `include`
35

tests/ui/feature-gates/removed-features-note-version-and-pr-issue-141619.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:1:12
2+
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:3:12
33
|
44
LL | #![feature(external_doc)]
55
| ^^^^^^^^^^^^ feature has been removed
66
|
7+
= note: removed in 1.54.0 (you are using $RUSTC_VERSION); see <https://github.com/rust-lang/rust/pull/85457> for more information
78
= note: use #[doc = include_str!("filename")] instead, which handles macro invocations
89

910
error: unknown `doc` attribute `include`
10-
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:2:8
11+
--> $DIR/removed-features-note-version-and-pr-issue-141619.rs:4:8
1112
|
1213
LL | #![doc(include("README.md"))]
1314
| ^^^^^^^^^^^^^^^^^^^^

tests/ui/macros/macro-reexport-removed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ aux-build:two_macros.rs
2+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
23

34
#![feature(macro_reexport)] //~ ERROR feature has been removed
45

tests/ui/macros/macro-reexport-removed.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/macro-reexport-removed.rs:3:12
2+
--> $DIR/macro-reexport-removed.rs:4:12
33
|
44
LL | #![feature(macro_reexport)]
55
| ^^^^^^^^^^^^^^ feature has been removed
66
|
7+
= note: removed in 1.0.0 (you are using $RUSTC_VERSION)
78
= note: subsumed by `pub use`
89

910
error: cannot find attribute `macro_reexport` in this scope
10-
--> $DIR/macro-reexport-removed.rs:5:3
11+
--> $DIR/macro-reexport-removed.rs:6:3
1112
|
1213
LL | #[macro_reexport(macro_one)]
1314
| ^^^^^^^^^^^^^^ help: a built-in attribute with a similar name exists: `macro_export`

tests/ui/rustdoc/renamed-features-rustdoc_internals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
2+
13
#![feature(doc_keyword)] //~ ERROR
24
#![feature(doc_primitive)] //~ ERROR
35
#![crate_type = "lib"]

tests/ui/rustdoc/renamed-features-rustdoc_internals.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/renamed-features-rustdoc_internals.rs:1:12
2+
--> $DIR/renamed-features-rustdoc_internals.rs:3:12
33
|
44
LL | #![feature(doc_keyword)]
55
| ^^^^^^^^^^^ feature has been removed
66
|
7+
= note: removed in 1.28.0 (you are using $RUSTC_VERSION)
78
= note: merged into `#![feature(rustdoc_internals)]`
89

910
error[E0557]: feature has been removed
10-
--> $DIR/renamed-features-rustdoc_internals.rs:2:12
11+
--> $DIR/renamed-features-rustdoc_internals.rs:4:12
1112
|
1213
LL | #![feature(doc_primitive)]
1314
| ^^^^^^^^^^^^^ feature has been removed
1415
|
16+
= note: removed in 1.56.0 (you are using $RUSTC_VERSION)
1517
= note: merged into `#![feature(rustdoc_internals)]`
1618

1719
error: aborting due to 2 previous errors

tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Regression test for issue #125877.
77

88
//@ compile-flags: -Znext-solver
9+
//@ normalize-stderr: "you are using [0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?( \([0-9a-fA-F]+ [0-9]{4}-[0-9]{2}-[0-9]{2}\))?" -> "you are using $$RUSTC_VERSION"
910

1011
#![feature(const_trait_impl, effects)]
1112
//~^ ERROR feature has been removed

tests/ui/traits/const-traits/const-trait-impl-parameter-mismatch.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
error[E0557]: feature has been removed
2-
--> $DIR/const-trait-impl-parameter-mismatch.rs:10:30
2+
--> $DIR/const-trait-impl-parameter-mismatch.rs:11:30
33
|
44
LL | #![feature(const_trait_impl, effects)]
55
| ^^^^^^^ feature has been removed
66
|
7+
= note: removed in 1.84.0 (you are using $RUSTC_VERSION)
78
= note: removed, redundant with `#![feature(const_trait_impl)]`
89

910
error[E0049]: associated function `compute` has 0 type parameters but its trait declaration has 1 type parameter
10-
--> $DIR/const-trait-impl-parameter-mismatch.rs:19:16
11+
--> $DIR/const-trait-impl-parameter-mismatch.rs:20:16
1112
|
1213
LL | fn compute<T: ~const Aux>() -> u32;
1314
| - expected 1 type parameter

0 commit comments

Comments
 (0)