Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore future deprecations in #[deprecated] #58202

Merged
merged 7 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,37 +598,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// Deprecated attributes apply in-crate and cross-crate.
if let Some(id) = id {
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
// If the deprecation is scheduled for a future Rust
// version, then we should display no warning message.
let deprecated_in_future_version = if let Some(sym) = depr_entry.attr.since {
let since = sym.as_str();
if !deprecation_in_effect(&since) {
Some(since)
} else {
None
}
} else {
None
};

let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id));
let skip = self.lookup_deprecation_entry(parent_def_id)
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));

if let Some(since) = deprecated_in_future_version {
let path = self.item_path_str(def_id);
let message = format!("use of item '{}' \
that will be deprecated in future version {}",
path,
since);

lint_deprecated(def_id,
id,
depr_entry.attr.note,
None,
&message,
lint::builtin::DEPRECATED_IN_FUTURE);
} else if !skip {
if !skip {
let path = self.item_path_str(def_id);
let message = format!("use of deprecated item '{}'", path);
lint_deprecated(def_id,
Expand Down
31 changes: 24 additions & 7 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,17 @@ fn stability_tags(item: &clean::Item) -> String {

// The trailing space after each tag is to space it properly against the rest of the docs.
if item.deprecation().is_some() {
tags += &tag_html("deprecated", "Deprecated");
let mut message = "Deprecated";
if let Some(ref stab) = item.stability {
if let Some(ref depr) = stab.deprecation {
if let Some(ref since) = depr.since {
if !stability::deprecation_in_effect(&since) {
message = "Deprecation planned";
}
}
}
}
tags += &tag_html("deprecated", message);
}

if let Some(stab) = item
Expand Down Expand Up @@ -2845,16 +2855,23 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
let mut stability = vec![];
let error_codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());

if let Some(Deprecation { since, note }) = &item.deprecation() {
if let Some(Deprecation { note, since }) = &item.deprecation() {
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
// but only display the future-deprecation messages for #[rustc_deprecated].
let mut message = if let Some(since) = since {
if stability::deprecation_in_effect(since) {
format!("Deprecated since {}", Escape(since))
} else {
format!("Deprecating in {}", Escape(since))
}
format!("Deprecated since {}", Escape(since))
} else {
String::from("Deprecated")
};
if let Some(ref stab) = item.stability {
if let Some(ref depr) = stab.deprecation {
if let Some(ref since) = depr.since {
if !stability::deprecation_in_effect(&since) {
message = format!("Deprecating in {}", Escape(&since));
}
}
}
}

if let Some(note) = note {
let mut ids = cx.id_map.borrow_mut();
Expand Down
4 changes: 3 additions & 1 deletion src/test/rustdoc/deprecated-future.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![feature(deprecated)]

// @has deprecated_future/index.html '//*[@class="stab deprecated"]' \
// 'Deprecated'
// @has deprecated_future/struct.S.html '//*[@class="stab deprecated"]' \
// 'Deprecating in 99.99.99: effectively never'
// 'Deprecated since 99.99.99: effectively never'
#[deprecated(since = "99.99.99", note = "effectively never")]
pub struct S;
11 changes: 11 additions & 0 deletions src/test/rustdoc/rustc_deprecated-future.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![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.S.html '//*[@class="stab deprecated"]' \
// 'Deprecating in 99.99.99: effectively never'
#[rustc_deprecated(since = "99.99.99", reason = "effectively never")]
#[stable(feature = "rustc_deprecated-future-test", since = "1.0.0")]
pub struct S;
4 changes: 3 additions & 1 deletion src/test/ui/deprecation/deprecation-in-future.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// ignore-tidy-linelength

// run-pass

#![deny(deprecated_in_future)]

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

fn test() {
deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
varkor marked this conversation as resolved.
Show resolved Hide resolved
}

fn main() {}
14 changes: 4 additions & 10 deletions src/test/ui/deprecation/deprecation-in-future.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error: use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
--> $DIR/deprecation-in-future.rs:9:5
warning: use of deprecated item 'deprecated_future': text
--> $DIR/deprecation-in-future.rs:11:5
|
LL | deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
LL | deprecated_future(); // ok; deprecated_in_future only applies to rustc_deprecated
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/deprecation-in-future.rs:3:9
|
LL | #![deny(deprecated_in_future)]
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
= note: #[warn(deprecated)] on by default

5 changes: 3 additions & 2 deletions src/test/ui/deprecation/deprecation-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ mod this_crate {
<Foo>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text
<Foo as Trait>::trait_deprecated_text(&foo); //~ ERROR use of deprecated item 'this_crate::Trait::trait_deprecated_text': text

deprecated_future(); // Fine; no error.
deprecated_future_text(); // Fine; no error.
// Future deprecations are only permitted for rustc_deprecated.
deprecated_future(); //~ ERROR use of deprecated item
deprecated_future_text(); //~ ERROR use of deprecated item

let _ = DeprecatedStruct {
//~^ ERROR use of deprecated item 'this_crate::DeprecatedStruct': text
Expand Down
Loading