Error on #[rustc_deprecated]
This commit is contained in:
parent
4fbe73e0b7
commit
e46f8b23dd
11 changed files with 85 additions and 34 deletions
|
@ -687,6 +687,14 @@ where
|
||||||
break;
|
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 {
|
let Some(meta) = attr.meta() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -742,12 +750,24 @@ where
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME(jhpratt) remove this after a bootstrap occurs. Emitting an
|
// FIXME(jhpratt) remove this eventually
|
||||||
// error specific to the renaming would be a good idea as well.
|
|
||||||
sym::reason if attr.has_name(sym::rustc_deprecated) => {
|
sym::reason if attr.has_name(sym::rustc_deprecated) => {
|
||||||
if !get(mi, &mut note) {
|
if !get(mi, &mut note) {
|
||||||
continue 'outer;
|
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 => {
|
sym::suggestion => {
|
||||||
if !sess.features_untracked().deprecated_suggestion {
|
if !sess.features_untracked().deprecated_suggestion {
|
||||||
|
|
|
@ -2201,11 +2201,10 @@ declare_lint! {
|
||||||
/// used by user code.
|
/// used by user code.
|
||||||
///
|
///
|
||||||
/// This lint is only enabled in the standard library. It works with the
|
/// 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
|
/// use of `#[deprecated]` with a `since` field of a version in the future.
|
||||||
/// future. This allows something to be marked as deprecated in a future
|
/// This allows something to be marked as deprecated in a future version,
|
||||||
/// version, and then this lint will ensure that the item is no longer
|
/// and then this lint will ensure that the item is no longer used in the
|
||||||
/// used in the standard library. See the [stability documentation] for
|
/// standard library. See the [stability documentation] for more details.
|
||||||
/// more details.
|
|
||||||
///
|
///
|
||||||
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
|
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
|
||||||
pub DEPRECATED_IN_FUTURE,
|
pub DEPRECATED_IN_FUTURE,
|
||||||
|
|
|
@ -118,8 +118,7 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_since_rustc_version {
|
if !is_since_rustc_version {
|
||||||
// The `since` field doesn't have semantic purpose in the stable `deprecated`
|
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
|
||||||
// attribute, only in `rustc_deprecated`.
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +335,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// topmost deprecation. For example, if a struct is deprecated,
|
// topmost deprecation. For example, if a struct is deprecated,
|
||||||
// the use of a field won't be linted.
|
// 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.
|
// hierarchy.
|
||||||
let depr_attr = &depr_entry.attr;
|
let depr_attr = &depr_entry.attr;
|
||||||
if !skip || depr_attr.is_since_rustc_version {
|
if !skip || depr_attr.is_since_rustc_version {
|
||||||
|
|
|
@ -659,8 +659,8 @@ fn short_item_info(
|
||||||
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
|
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
|
||||||
item.deprecation(cx.tcx())
|
item.deprecation(cx.tcx())
|
||||||
{
|
{
|
||||||
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
|
// We display deprecation messages for #[deprecated], but only display
|
||||||
// but only display the future-deprecation messages for #[rustc_deprecated].
|
// the future-deprecation messages for rustc versions.
|
||||||
let mut message = if let Some(since) = since {
|
let mut message = if let Some(since) = since {
|
||||||
let since = since.as_str();
|
let since = since.as_str();
|
||||||
if !stability::deprecation_in_effect(&depr) {
|
if !stability::deprecation_in_effect(&depr) {
|
||||||
|
|
18
src/test/rustdoc/deprecated-future-staged-api.rs
Normal file
18
src/test/rustdoc/deprecated-future-staged-api.rs
Normal 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;
|
|
@ -2,7 +2,6 @@
|
||||||
// build-aux-docs
|
// build-aux-docs
|
||||||
|
|
||||||
#![feature(macro_test)]
|
#![feature(macro_test)]
|
||||||
|
|
||||||
#![crate_name = "foo"]
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
extern crate macros;
|
extern crate macros;
|
||||||
|
@ -16,5 +15,5 @@ extern crate macros;
|
||||||
// @has - '//*[@class="docblock"]' 'docs for my_macro'
|
// @has - '//*[@class="docblock"]' 'docs for my_macro'
|
||||||
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text'
|
// @has - '//*[@class="stab deprecated"]' 'Deprecated since 1.2.3: text'
|
||||||
// @has - '//*[@class="stab unstable"]' 'macro_test'
|
// @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;
|
pub use macros::my_macro;
|
||||||
|
|
|
@ -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;
|
|
|
@ -1,7 +1,7 @@
|
||||||
warning: use of deprecated function `deprecated_future`: text
|
warning: use of deprecated function `deprecated_future`: text
|
||||||
--> $DIR/deprecation-in-future.rs:9:5
|
--> $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
|
= note: `#[warn(deprecated)]` on by default
|
||||||
|
|
|
@ -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>::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
|
<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(); //~ ERROR use of deprecated function
|
||||||
deprecated_future_text(); //~ ERROR use of deprecated function
|
deprecated_future_text(); //~ ERROR use of deprecated function
|
||||||
|
|
||||||
|
|
13
src/test/ui/deprecation/rustc_deprecated.rs
Normal file
13
src/test/ui/deprecation/rustc_deprecated.rs
Normal 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() {}
|
21
src/test/ui/deprecation/rustc_deprecated.stderr
Normal file
21
src/test/ui/deprecation/rustc_deprecated.stderr
Normal 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue