Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e46f8b2

Browse files
committed
Error on #[rustc_deprecated]
1 parent 4fbe73e commit e46f8b2

File tree

11 files changed

+85
-34
lines changed

11 files changed

+85
-34
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ where
687687
break;
688688
}
689689

690+
// FIXME(jhpratt) remove this eventually
691+
if attr.has_name(sym::rustc_deprecated) {
692+
diagnostic
693+
.struct_span_err(attr.span, "`#[rustc_deprecated]` has been removed")
694+
.help("use `#[deprecated]` instead")
695+
.emit();
696+
}
697+
690698
let Some(meta) = attr.meta() else {
691699
continue;
692700
};
@@ -742,12 +750,24 @@ where
742750
continue 'outer;
743751
}
744752
}
745-
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
746-
// error specific to the renaming would be a good idea as well.
753+
// FIXME(jhpratt) remove this eventually
747754
sym::reason if attr.has_name(sym::rustc_deprecated) => {
748755
if !get(mi, &mut note) {
749756
continue 'outer;
750757
}
758+
759+
let mut diag = diagnostic
760+
.struct_span_err(mi.span, "`reason` has been renamed");
761+
match note {
762+
Some(note) => diag.span_suggestion(
763+
mi.span,
764+
"use `note` instead",
765+
format!("note = \"{note}\""),
766+
Applicability::MachineApplicable,
767+
),
768+
None => diag.span_help(mi.span, "use `note` instead"),
769+
};
770+
diag.emit();
751771
}
752772
sym::suggestion => {
753773
if !sess.features_untracked().deprecated_suggestion {

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,11 +2201,10 @@ 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
///
22102209
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
22112210
pub DEPRECATED_IN_FUTURE,

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 {

src/librustdoc/html/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ fn short_item_info(
659659
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
660660
item.deprecation(cx.tcx())
661661
{
662-
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
663-
// but only display the future-deprecation messages for #[rustc_deprecated].
662+
// We display deprecation messages for #[deprecated], but only display
663+
// the future-deprecation messages for rustc versions.
664664
let mut message = if let Some(since) = since {
665665
let since = since.as_str();
666666
if !stability::deprecation_in_effect(&depr) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(staged_api)]
2+
#![stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
3+
4+
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \
5+
// 'Deprecation planned'
6+
// @has deprecated_future_staged_api/struct.S1.html '//*[@class="stab deprecated"]' \
7+
// 'Deprecating in 99.99.99: effectively never'
8+
#[deprecated(since = "99.99.99", note = "effectively never")]
9+
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
10+
pub struct S1;
11+
12+
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \
13+
// 'Deprecation planned'
14+
// @has deprecated_future_staged_api/struct.S2.html '//*[@class="stab deprecated"]' \
15+
// 'Deprecating in a future Rust version: literally never'
16+
#[deprecated(since = "TBD", note = "literally never")]
17+
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
18+
pub struct S2;

src/test/rustdoc/inline_cross/macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// build-aux-docs
33

44
#![feature(macro_test)]
5-
65
#![crate_name = "foo"]
76

87
extern crate macros;
@@ -16,5 +15,5 @@ extern crate macros;
1615
// @has - '//*[@class="docblock"]' 'docs for my_macro'
1716
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text'
1817
// @has - '//*[@class="stab unstable"]' 'macro_test'
19-
// @has - '//a/@href' '../src/macros/macros.rs.html#9-11'
18+
// @has - '//a/@href' '../src/macros/macros.rs.html#8-10'
2019
pub use macros::my_macro;

src/test/rustdoc/rustc_deprecated-future.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/test/ui/deprecation/deprecation-in-future.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
warning: use of deprecated function `deprecated_future`: text
22
--> $DIR/deprecation-in-future.rs:9:5
33
|
4-
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
4+
LL | deprecated_future(); // ok; deprecated_in_future only applies with `#![feature(staged_api)]`
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(deprecated)]` on by default

src/test/ui/deprecation/deprecation-lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ mod this_crate {
260260
<Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
261261
<Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
262262

263-
// Future deprecations are only permitted for rustc_deprecated.
263+
// Future deprecations are only permitted with `#![feature(staged_api)]`
264264
deprecated_future(); //~ ERROR use of deprecated function
265265
deprecated_future_text(); //~ ERROR use of deprecated function
266266

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: --crate-type=lib
2+
3+
#![feature(staged_api)]
4+
#![stable(since = "1.0.0", feature = "rust1")]
5+
6+
#[rustc_deprecated( //~ ERROR `#[rustc_deprecated]` has been removed
7+
//~^ HELP use `#[deprecated]` instead
8+
since = "1.100.0",
9+
reason = "text" //~ ERROR `reason` has been renamed
10+
//~^ HELP use `note` instead
11+
)]
12+
#[stable(feature = "rust1", since = "1.0.0")]
13+
fn foo() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: `#[rustc_deprecated]` has been removed
2+
--> $DIR/rustc_deprecated.rs:6:1
3+
|
4+
LL | / #[rustc_deprecated(
5+
LL | |
6+
LL | | since = "1.100.0",
7+
LL | | reason = "text"
8+
LL | |
9+
LL | | )]
10+
| |__^
11+
|
12+
= help: use `#[deprecated]` instead
13+
14+
error: `reason` has been renamed
15+
--> $DIR/rustc_deprecated.rs:9:5
16+
|
17+
LL | reason = "text"
18+
| ^^^^^^^^^^^^^^^ help: use `note` instead: `note = "text"`
19+
20+
error: aborting due to 2 previous errors
21+

0 commit comments

Comments
 (0)