Skip to content

Commit

Permalink
Do not apply future deprecation warning for #[deprecated]
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Feb 11, 2019
1 parent 652ae3f commit 3737d4d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 84 deletions.
28 changes: 1 addition & 27 deletions src/librustc/middle/stability.rs
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
4 changes: 3 additions & 1 deletion src/test/ui/deprecation/deprecation-in-future.rs
@@ -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
}

fn main() {}
14 changes: 4 additions & 10 deletions src/test/ui/deprecation/deprecation-in-future.stderr
@@ -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
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

0 comments on commit 3737d4d

Please sign in to comment.