Allow since="TBD"
for rustc_deprecated
This commit is contained in:
parent
2ba7ca2bbb
commit
1e1ca28f39
8 changed files with 111 additions and 69 deletions
|
@ -132,37 +132,37 @@ pub fn report_unstable(
|
||||||
/// Checks whether an item marked with `deprecated(since="X")` is currently
|
/// Checks whether an item marked with `deprecated(since="X")` is currently
|
||||||
/// deprecated (i.e., whether X is not greater than the current rustc version).
|
/// deprecated (i.e., whether X is not greater than the current rustc version).
|
||||||
pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool {
|
pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool {
|
||||||
let since = if let Some(since) = since {
|
|
||||||
if is_since_rustc_version {
|
|
||||||
since
|
|
||||||
} else {
|
|
||||||
// We assume that the deprecation is in effect if it's not a
|
|
||||||
// rustc version.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If since attribute is not set, then we're definitely in effect.
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
fn parse_version(ver: &str) -> Vec<u32> {
|
fn parse_version(ver: &str) -> Vec<u32> {
|
||||||
// We ignore non-integer components of the version (e.g., "nightly").
|
// We ignore non-integer components of the version (e.g., "nightly").
|
||||||
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
|
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(rustc) = option_env!("CFG_RELEASE") {
|
if !is_since_rustc_version {
|
||||||
let since: Vec<u32> = parse_version(&since);
|
// The `since` field doesn't have semantic purpose in the stable `deprecated`
|
||||||
let rustc: Vec<u32> = parse_version(rustc);
|
// attribute, only in `rustc_deprecated`.
|
||||||
// We simply treat invalid `since` attributes as relating to a previous
|
return true;
|
||||||
// Rust version, thus always displaying the warning.
|
|
||||||
if since.len() != 3 {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
since <= rustc
|
|
||||||
} else {
|
|
||||||
// By default, a deprecation warning applies to
|
|
||||||
// the current version of the compiler.
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(since) = since {
|
||||||
|
if since == "TBD" {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(rustc) = option_env!("CFG_RELEASE") {
|
||||||
|
let since: Vec<u32> = parse_version(&since);
|
||||||
|
let rustc: Vec<u32> = parse_version(rustc);
|
||||||
|
// We simply treat invalid `since` attributes as relating to a previous
|
||||||
|
// Rust version, thus always displaying the warning.
|
||||||
|
if since.len() != 3 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return since <= rustc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Assume deprecation is in effect if "since" field is missing
|
||||||
|
// or if we can't determine the current Rust version.
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deprecation_suggestion(
|
pub fn deprecation_suggestion(
|
||||||
|
@ -182,19 +182,24 @@ pub fn deprecation_suggestion(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
|
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
|
||||||
let (message, lint) = if deprecation_in_effect(
|
let since = depr.since.map(Symbol::as_str);
|
||||||
depr.is_since_rustc_version,
|
let (message, lint) = if deprecation_in_effect(depr.is_since_rustc_version, since.as_deref()) {
|
||||||
depr.since.map(Symbol::as_str).as_deref(),
|
|
||||||
) {
|
|
||||||
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
|
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
format!(
|
if since.as_deref() == Some("TBD") {
|
||||||
"use of {} `{}` that will be deprecated in future version {}",
|
format!(
|
||||||
kind,
|
"use of {} `{}` that will be deprecated in a future Rust version",
|
||||||
path,
|
kind, path
|
||||||
depr.since.unwrap()
|
)
|
||||||
),
|
} else {
|
||||||
|
format!(
|
||||||
|
"use of {} `{}` that will be deprecated in future version {}",
|
||||||
|
kind,
|
||||||
|
path,
|
||||||
|
since.unwrap()
|
||||||
|
)
|
||||||
|
},
|
||||||
DEPRECATED_IN_FUTURE,
|
DEPRECATED_IN_FUTURE,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -182,28 +182,32 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
for (dep_v, stab_v) in
|
for (dep_v, stab_v) in
|
||||||
dep_since.as_str().split('.').zip(stab_since.as_str().split('.'))
|
dep_since.as_str().split('.').zip(stab_since.as_str().split('.'))
|
||||||
{
|
{
|
||||||
if let (Ok(dep_v), Ok(stab_v)) = (dep_v.parse::<u64>(), stab_v.parse()) {
|
match stab_v.parse::<u64>() {
|
||||||
match dep_v.cmp(&stab_v) {
|
Err(_) => {
|
||||||
Ordering::Less => {
|
self.tcx.sess.span_err(item_sp, "Invalid stability version found");
|
||||||
self.tcx.sess.span_err(
|
break;
|
||||||
item_sp,
|
}
|
||||||
"An API can't be stabilized \
|
Ok(stab_vp) => match dep_v.parse::<u64>() {
|
||||||
after it is deprecated",
|
Ok(dep_vp) => match dep_vp.cmp(&stab_vp) {
|
||||||
);
|
Ordering::Less => {
|
||||||
|
self.tcx.sess.span_err(
|
||||||
|
item_sp,
|
||||||
|
"An API can't be stabilized after it is deprecated",
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Ordering::Equal => continue,
|
||||||
|
Ordering::Greater => break,
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
if dep_v != "TBD" {
|
||||||
|
self.tcx
|
||||||
|
.sess
|
||||||
|
.span_err(item_sp, "Invalid deprecation version found");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ordering::Equal => continue,
|
},
|
||||||
Ordering::Greater => break,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Act like it isn't less because the question is now nonsensical,
|
|
||||||
// and this makes us not do anything else interesting.
|
|
||||||
self.tcx.sess.span_err(
|
|
||||||
item_sp,
|
|
||||||
"Invalid stability or deprecation \
|
|
||||||
version found",
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2279,7 +2279,11 @@ fn short_item_info(item: &clean::Item, cx: &Context, parent: Option<&clean::Item
|
||||||
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(is_since_rustc_version, Some(since)) {
|
if !stability::deprecation_in_effect(is_since_rustc_version, Some(since)) {
|
||||||
format!("Deprecating in {}", Escape(since))
|
if *since == "TBD" {
|
||||||
|
format!("Deprecating in a future Rust version")
|
||||||
|
} else {
|
||||||
|
format!("Deprecating in {}", Escape(since))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
format!("Deprecated since {}", Escape(since))
|
format!("Deprecated since {}", Escape(since))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,16 @@
|
||||||
|
|
||||||
// @has rustc_deprecated_future/index.html '//*[@class="stab deprecated"]' \
|
// @has rustc_deprecated_future/index.html '//*[@class="stab deprecated"]' \
|
||||||
// 'Deprecation planned'
|
// 'Deprecation planned'
|
||||||
// @has rustc_deprecated_future/struct.S.html '//*[@class="stab deprecated"]' \
|
// @has rustc_deprecated_future/struct.S1.html '//*[@class="stab deprecated"]' \
|
||||||
// 'Deprecating in 99.99.99: effectively never'
|
// 'Deprecating in 99.99.99: effectively never'
|
||||||
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
|
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
|
||||||
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
|
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
|
||||||
pub struct S;
|
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'
|
||||||
|
#[rustc_deprecated(since = "TBD", reason = "literally never")]
|
||||||
|
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
|
||||||
|
pub struct S2;
|
||||||
|
|
|
@ -8,8 +8,13 @@
|
||||||
|
|
||||||
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
|
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
|
||||||
#[stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
|
#[stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
|
||||||
pub struct S;
|
pub struct S1;
|
||||||
|
|
||||||
|
#[rustc_deprecated(since = "TBD", reason = "literally never")]
|
||||||
|
#[stable(feature = "rustc_deprecation-in-future-test", since = "1.0.0")]
|
||||||
|
pub struct S2;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = S; //~ ERROR use of unit struct `S` that will be deprecated in future version 99.99.99: effectively never
|
let _ = S1; //~ ERROR use of unit struct `S1` that will be deprecated in future version 99.99.99: effectively never
|
||||||
|
let _ = S2; //~ ERROR use of unit struct `S2` that will be deprecated in a future Rust version: literally never
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error: use of unit struct `S` that will be deprecated in future version 99.99.99: effectively never
|
error: use of unit struct `S1` that will be deprecated in future version 99.99.99: effectively never
|
||||||
--> $DIR/rustc_deprecation-in-future.rs:14:13
|
--> $DIR/rustc_deprecation-in-future.rs:18:13
|
||||||
|
|
|
|
||||||
LL | let _ = S;
|
LL | let _ = S1;
|
||||||
| ^
|
| ^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/rustc_deprecation-in-future.rs:3:9
|
--> $DIR/rustc_deprecation-in-future.rs:3:9
|
||||||
|
@ -10,5 +10,11 @@ note: the lint level is defined here
|
||||||
LL | #![deny(deprecated_in_future)]
|
LL | #![deny(deprecated_in_future)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: use of unit struct `S2` that will be deprecated in a future Rust version: literally never
|
||||||
|
--> $DIR/rustc_deprecation-in-future.rs:19:13
|
||||||
|
|
|
||||||
|
LL | let _ = S2;
|
||||||
|
| ^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,11 @@ fn multiple3() { }
|
||||||
#[rustc_const_unstable(feature = "c", issue = "none")]
|
#[rustc_const_unstable(feature = "c", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "d", issue = "none")] //~ ERROR multiple stability levels
|
#[rustc_const_unstable(feature = "d", issue = "none")] //~ ERROR multiple stability levels
|
||||||
pub const fn multiple4() { }
|
pub const fn multiple4() { }
|
||||||
//~^ ERROR Invalid stability or deprecation version found
|
//~^ ERROR Invalid stability version found
|
||||||
|
|
||||||
|
#[stable(feature = "a", since = "1.0.0")]
|
||||||
|
#[rustc_deprecated(since = "invalid", reason = "text")]
|
||||||
|
fn invalid_deprecation_version() {} //~ ERROR Invalid deprecation version found
|
||||||
|
|
||||||
#[rustc_deprecated(since = "a", reason = "text")]
|
#[rustc_deprecated(since = "a", reason = "text")]
|
||||||
fn deprecated_without_unstable_or_stable() { }
|
fn deprecated_without_unstable_or_stable() { }
|
||||||
|
|
|
@ -96,19 +96,25 @@ error[E0544]: multiple stability levels
|
||||||
LL | #[rustc_const_unstable(feature = "d", issue = "none")]
|
LL | #[rustc_const_unstable(feature = "d", issue = "none")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: Invalid stability or deprecation version found
|
error: Invalid stability version found
|
||||||
--> $DIR/stability-attribute-sanity.rs:65:1
|
--> $DIR/stability-attribute-sanity.rs:65:1
|
||||||
|
|
|
|
||||||
LL | pub const fn multiple4() { }
|
LL | pub const fn multiple4() { }
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: Invalid deprecation version found
|
||||||
|
--> $DIR/stability-attribute-sanity.rs:70:1
|
||||||
|
|
|
||||||
|
LL | fn invalid_deprecation_version() {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0549]: rustc_deprecated attribute must be paired with either stable or unstable attribute
|
error[E0549]: rustc_deprecated attribute must be paired with either stable or unstable attribute
|
||||||
--> $DIR/stability-attribute-sanity.rs:68:1
|
--> $DIR/stability-attribute-sanity.rs:72:1
|
||||||
|
|
|
|
||||||
LL | #[rustc_deprecated(since = "a", reason = "text")]
|
LL | #[rustc_deprecated(since = "a", reason = "text")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 18 previous errors
|
error: aborting due to 19 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0539, E0541, E0546, E0550.
|
Some errors have detailed explanations: E0539, E0541, E0546, E0550.
|
||||||
For more information about an error, try `rustc --explain E0539`.
|
For more information about an error, try `rustc --explain E0539`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue