Skip to content

Commit a603e2a

Browse files
authored
Rollup merge of rust-lang#58202 - varkor:deprecated-future-external, r=GuillaumeGomez
Ignore future deprecations in #[deprecated] The future deprecation warnings should only apply to `#[rustc_deprecated]` as they take into account rustc's version. Fixes rust-lang#57952. I've also slightly modified rustdoc's display of future deprecation notices to make it more consistent, so I'm assigning a rustdoc team member for review to make sure this is okay. r? @GuillaumeGomez
2 parents 9cb5831 + b5fa870 commit a603e2a

10 files changed

+134
-92
lines changed

src/librustc/middle/stability.rs

+1-27
Original file line numberDiff line numberDiff line change
@@ -593,37 +593,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
593593
// Deprecated attributes apply in-crate and cross-crate.
594594
if let Some(id) = id {
595595
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
596-
// If the deprecation is scheduled for a future Rust
597-
// version, then we should display no warning message.
598-
let deprecated_in_future_version = if let Some(sym) = depr_entry.attr.since {
599-
let since = sym.as_str();
600-
if !deprecation_in_effect(&since) {
601-
Some(since)
602-
} else {
603-
None
604-
}
605-
} else {
606-
None
607-
};
608-
609596
let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id));
610597
let skip = self.lookup_deprecation_entry(parent_def_id)
611598
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
612599

613-
if let Some(since) = deprecated_in_future_version {
614-
let path = self.item_path_str(def_id);
615-
let message = format!("use of item '{}' \
616-
that will be deprecated in future version {}",
617-
path,
618-
since);
619-
620-
lint_deprecated(def_id,
621-
id,
622-
depr_entry.attr.note,
623-
None,
624-
&message,
625-
lint::builtin::DEPRECATED_IN_FUTURE);
626-
} else if !skip {
600+
if !skip {
627601
let path = self.item_path_str(def_id);
628602
let message = format!("use of deprecated item '{}'", path);
629603
lint_deprecated(def_id,

src/librustdoc/html/render.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,17 @@ fn stability_tags(item: &clean::Item) -> String {
28232823

28242824
// The trailing space after each tag is to space it properly against the rest of the docs.
28252825
if item.deprecation().is_some() {
2826-
tags += &tag_html("deprecated", "Deprecated");
2826+
let mut message = "Deprecated";
2827+
if let Some(ref stab) = item.stability {
2828+
if let Some(ref depr) = stab.deprecation {
2829+
if let Some(ref since) = depr.since {
2830+
if !stability::deprecation_in_effect(&since) {
2831+
message = "Deprecation planned";
2832+
}
2833+
}
2834+
}
2835+
}
2836+
tags += &tag_html("deprecated", message);
28272837
}
28282838

28292839
if let Some(stab) = item
@@ -2851,16 +2861,23 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
28512861
let mut stability = vec![];
28522862
let error_codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
28532863

2854-
if let Some(Deprecation { since, note }) = &item.deprecation() {
2864+
if let Some(Deprecation { note, since }) = &item.deprecation() {
2865+
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
2866+
// but only display the future-deprecation messages for #[rustc_deprecated].
28552867
let mut message = if let Some(since) = since {
2856-
if stability::deprecation_in_effect(since) {
2857-
format!("Deprecated since {}", Escape(since))
2858-
} else {
2859-
format!("Deprecating in {}", Escape(since))
2860-
}
2868+
format!("Deprecated since {}", Escape(since))
28612869
} else {
28622870
String::from("Deprecated")
28632871
};
2872+
if let Some(ref stab) = item.stability {
2873+
if let Some(ref depr) = stab.deprecation {
2874+
if let Some(ref since) = depr.since {
2875+
if !stability::deprecation_in_effect(&since) {
2876+
message = format!("Deprecating in {}", Escape(&since));
2877+
}
2878+
}
2879+
}
2880+
}
28642881

28652882
if let Some(note) = note {
28662883
let mut ids = cx.id_map.borrow_mut();

src/test/rustdoc/deprecated-future.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![feature(deprecated)]
22

3+
// @has deprecated_future/index.html '//*[@class="stab deprecated"]' \
4+
// 'Deprecated'
35
// @has deprecated_future/struct.S.html '//*[@class="stab deprecated"]' \
4-
// 'Deprecating in 99.99.99: effectively never'
6+
// 'Deprecated since 99.99.99: effectively never'
57
#[deprecated(since = "99.99.99", note = "effectively never")]
68
pub struct S;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(staged_api)]
2+
3+
#![stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
4+
5+
// @has rustc_deprecated_future/index.html '//*[@class="stab deprecated"]' \
6+
// 'Deprecation planned'
7+
// @has rustc_deprecated_future/struct.S.html '//*[@class="stab deprecated"]' \
8+
// 'Deprecating in 99.99.99: effectively never'
9+
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
10+
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
11+
pub struct S;
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// ignore-tidy-linelength
22

3+
// run-pass
4+
35
#![deny(deprecated_in_future)]
46

57
#[deprecated(since = "99.99.99", note = "text")]
68
pub fn deprecated_future() {}
79

810
fn test() {
9-
deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
11+
deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
1012
}
1113

1214
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
error: use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
2-
--> $DIR/deprecation-in-future.rs:9:5
1+
warning: use of deprecated item 'deprecated_future': text
2+
--> $DIR/deprecation-in-future.rs:11:5
33
|
4-
LL | deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
4+
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
55
| ^^^^^^^^^^^^^^^^^
66
|
7-
note: lint level defined here
8-
--> $DIR/deprecation-in-future.rs:3:9
9-
|
10-
LL | #![deny(deprecated_in_future)]
11-
| ^^^^^^^^^^^^^^^^^^^^
12-
13-
error: aborting due to previous error
7+
= note: #[warn(deprecated)] on by default
148

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ mod this_crate {
261261
<Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
262262
<Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
263263

264-
deprecated_future(); // Fine; no error.
265-
deprecated_future_text(); // Fine; no error.
264+
// Future deprecations are only permitted for rustc_deprecated.
265+
deprecated_future(); //~ ERROR use of deprecated item
266+
deprecated_future_text(); //~ ERROR use of deprecated item
266267

267268
let _ = DeprecatedStruct {
268269
//~^ ERROR use of deprecated item 'this_crate::DeprecatedStruct': text

0 commit comments

Comments
 (0)