Error on #[rustc_deprecated]

This commit is contained in:
Jacob Pratt 2022-04-07 23:44:55 -04:00
parent 4fbe73e0b7
commit e46f8b23dd
No known key found for this signature in database
GPG key ID: B80E19E4662B5AA4
11 changed files with 85 additions and 34 deletions

View file

@ -687,6 +687,14 @@ where
break;
}
// FIXME(jhpratt) remove this eventually
if attr.has_name(sym::rustc_deprecated) {
diagnostic
.struct_span_err(attr.span, "`#[rustc_deprecated]` has been removed")
.help("use `#[deprecated]` instead")
.emit();
}
let Some(meta) = attr.meta() else {
continue;
};
@ -742,12 +750,24 @@ where
continue 'outer;
}
}
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
// error specific to the renaming would be a good idea as well.
// FIXME(jhpratt) remove this eventually
sym::reason if attr.has_name(sym::rustc_deprecated) => {
if !get(mi, &mut note) {
continue 'outer;
}
let mut diag = diagnostic
.struct_span_err(mi.span, "`reason` has been renamed");
match note {
Some(note) => diag.span_suggestion(
mi.span,
"use `note` instead",
format!("note = \"{note}\""),
Applicability::MachineApplicable,
),
None => diag.span_help(mi.span, "use `note` instead"),
};
diag.emit();
}
sym::suggestion => {
if !sess.features_untracked().deprecated_suggestion {

View file

@ -2201,11 +2201,10 @@ declare_lint! {
/// used by user code.
///
/// This lint is only enabled in the standard library. It works with the
/// use of `#[rustc_deprecated]` with a `since` field of a version in the
/// future. This allows something to be marked as deprecated in a future
/// version, and then this lint will ensure that the item is no longer
/// used in the standard library. See the [stability documentation] for
/// more details.
/// use of `#[deprecated]` with a `since` field of a version in the future.
/// This allows something to be marked as deprecated in a future version,
/// and then this lint will ensure that the item is no longer used in the
/// standard library. See the [stability documentation] for more details.
///
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
pub DEPRECATED_IN_FUTURE,

View file

@ -118,8 +118,7 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
}
if !is_since_rustc_version {
// The `since` field doesn't have semantic purpose in the stable `deprecated`
// attribute, only in `rustc_deprecated`.
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
return true;
}
@ -336,7 +335,7 @@ impl<'tcx> TyCtxt<'tcx> {
// topmost deprecation. For example, if a struct is deprecated,
// the use of a field won't be linted.
//
// #[rustc_deprecated] however wants to emit down the whole
// With #![staged_api], we want to emit down the whole
// hierarchy.
let depr_attr = &depr_entry.attr;
if !skip || depr_attr.is_since_rustc_version {

View file

@ -659,8 +659,8 @@ fn short_item_info(
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
item.deprecation(cx.tcx())
{
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
// but only display the future-deprecation messages for #[rustc_deprecated].
// We display deprecation messages for #[deprecated], but only display
// the future-deprecation messages for rustc versions.
let mut message = if let Some(since) = since {
let since = since.as_str();
if !stability::deprecation_in_effect(&depr) {

View file

@ -0,0 +1,18 @@
#![feature(staged_api)]
#![stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \
// 'Deprecation planned'
// @has deprecated_future_staged_api/struct.S1.html '//*[@class="stab deprecated"]' \
// 'Deprecating in 99.99.99: effectively never'
#[deprecated(since = "99.99.99", note = "effectively never")]
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
pub struct S1;
// @has deprecated_future_staged_api/index.html '//*[@class="stab deprecated"]' \
// 'Deprecation planned'
// @has deprecated_future_staged_api/struct.S2.html '//*[@class="stab deprecated"]' \
// 'Deprecating in a future Rust version: literally never'
#[deprecated(since = "TBD", note = "literally never")]
#[stable(feature = "deprecated-future-staged-api", since = "1.0.0")]
pub struct S2;

View file

@ -2,7 +2,6 @@
// build-aux-docs
#![feature(macro_test)]
#![crate_name = "foo"]
extern crate macros;
@ -16,5 +15,5 @@ extern crate macros;
// @has - '//*[@class="docblock"]' 'docs for my_macro'
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text'
// @has - '//*[@class="stab unstable"]' 'macro_test'
// @has - '//a/@href' '../src/macros/macros.rs.html#9-11'
// @has - '//a/@href' '../src/macros/macros.rs.html#8-10'
pub use macros::my_macro;

View file

@ -1,18 +0,0 @@
#![feature(staged_api)]
#![stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
// @has rustc_deprecated_future/index.html '//*[@class="stab deprecated"]' \
// 'Deprecation planned'
// @has rustc_deprecated_future/struct.S1.html '//*[@class="stab deprecated"]' \
// 'Deprecating in 99.99.99: effectively never'
#[deprecated(since = "99.99.99", note = "effectively never")]
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
pub struct S1;
// @has rustc_deprecated_future/index.html '//*[@class="stab deprecated"]' \
// 'Deprecation planned'
// @has rustc_deprecated_future/struct.S2.html '//*[@class="stab deprecated"]' \
// 'Deprecating in a future Rust version: literally never'
#[deprecated(since = "TBD", note = "literally never")]
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
pub struct S2;

View file

@ -1,7 +1,7 @@
warning: use of deprecated function `deprecated_future`: text
--> $DIR/deprecation-in-future.rs:9:5
|
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
LL | deprecated_future(); // ok; deprecated_in_future only applies with `#![feature(staged_api)]`
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default

View file

@ -260,7 +260,7 @@ mod this_crate {
<Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
<Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
// Future deprecations are only permitted for rustc_deprecated.
// Future deprecations are only permitted with `#![feature(staged_api)]`
deprecated_future(); //~ ERROR use of deprecated function
deprecated_future_text(); //~ ERROR use of deprecated function

View file

@ -0,0 +1,13 @@
// compile-flags: --crate-type=lib
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "rust1")]
#[rustc_deprecated( //~ ERROR `#[rustc_deprecated]` has been removed
//~^ HELP use `#[deprecated]` instead
since = "1.100.0",
reason = "text" //~ ERROR `reason` has been renamed
//~^ HELP use `note` instead
)]
#[stable(feature = "rust1", since = "1.0.0")]
fn foo() {}

View file

@ -0,0 +1,21 @@
error: `#[rustc_deprecated]` has been removed
--> $DIR/rustc_deprecated.rs:6:1
|
LL | / #[rustc_deprecated(
LL | |
LL | | since = "1.100.0",
LL | | reason = "text"
LL | |
LL | | )]
| |__^
|
= help: use `#[deprecated]` instead
error: `reason` has been renamed
--> $DIR/rustc_deprecated.rs:9:5
|
LL | reason = "text"
| ^^^^^^^^^^^^^^^ help: use `note` instead: `note = "text"`
error: aborting due to 2 previous errors