Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63e20b0

Browse files
authoredDec 14, 2018
Rollup merge of rust-lang#56203 - aheart:master, r=varkor
Add lint for items deprecated in future Resolves rust-lang#55892
2 parents e44527a + f8c03b6 commit 63e20b0

File tree

4 files changed

+89
-15
lines changed

4 files changed

+89
-15
lines changed
 

‎src/librustc/lint/builtin.rs

+8
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ pub mod parser {
365365
}
366366
}
367367

368+
declare_lint! {
369+
pub DEPRECATED_IN_FUTURE,
370+
Allow,
371+
"detects use of items that will be deprecated in a future version",
372+
report_in_external_macro: true
373+
}
374+
368375
/// Does nothing as a lint pass, but registers some `Lint`s
369376
/// that are used by other parts of the compiler.
370377
#[derive(Copy, Clone)]
@@ -427,6 +434,7 @@ impl LintPass for HardwiredLints {
427434
MACRO_USE_EXTERN_CRATE,
428435
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
429436
parser::QUESTION_MARK_MACRO_SEP,
437+
DEPRECATED_IN_FUTURE,
430438
)
431439
}
432440
}

‎src/librustc/middle/stability.rs

+55-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
pub use self::StabilityLevel::*;
1515

16-
use lint;
16+
use lint::{self, Lint};
1717
use hir::{self, Item, Generics, StructField, Variant, HirId};
1818
use hir::def::Def;
1919
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
@@ -562,18 +562,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
562562
return EvalResult::Allow;
563563
}
564564

565-
let lint_deprecated = |def_id: DefId, id: NodeId, note: Option<Symbol>| {
566-
let path = self.item_path_str(def_id);
567-
565+
let lint_deprecated = |def_id: DefId,
566+
id: NodeId,
567+
note: Option<Symbol>,
568+
message: &str,
569+
lint: &'static Lint| {
568570
let msg = if let Some(note) = note {
569-
format!("use of deprecated item '{}': {}", path, note)
571+
format!("{}: {}", message, note)
570572
} else {
571-
format!("use of deprecated item '{}'", path)
573+
format!("{}", message)
572574
};
573575

574-
self.lint_node(lint::builtin::DEPRECATED, id, span, &msg);
576+
self.lint_node(lint, id, span, &msg);
575577
if id == ast::DUMMY_NODE_ID {
576-
span_bug!(span, "emitted a deprecated lint with dummy node id: {:?}", def_id);
578+
span_bug!(span, "emitted a {} lint with dummy node id: {:?}", lint.name, def_id);
577579
}
578580
};
579581

@@ -584,17 +586,39 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
584586
// version, then we should display no warning message.
585587
let deprecated_in_future_version = if let Some(sym) = depr_entry.attr.since {
586588
let since = sym.as_str();
587-
!deprecation_in_effect(&since)
589+
if !deprecation_in_effect(&since) {
590+
Some(since)
591+
} else {
592+
None
593+
}
588594
} else {
589-
false
595+
None
590596
};
591597

592598
let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id));
593-
let skip = deprecated_in_future_version ||
594-
self.lookup_deprecation_entry(parent_def_id)
599+
let skip = self.lookup_deprecation_entry(parent_def_id)
595600
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
596-
if !skip {
597-
lint_deprecated(def_id, id, depr_entry.attr.note);
601+
602+
if let Some(since) = deprecated_in_future_version {
603+
let path = self.item_path_str(def_id);
604+
let message = format!("use of item '{}' \
605+
that will be deprecated in future version {}",
606+
path,
607+
since);
608+
609+
lint_deprecated(def_id,
610+
id,
611+
depr_entry.attr.note,
612+
&message,
613+
lint::builtin::DEPRECATED_IN_FUTURE);
614+
} else if !skip {
615+
let path = self.item_path_str(def_id);
616+
let message = format!("use of deprecated item '{}'", path);
617+
lint_deprecated(def_id,
618+
id,
619+
depr_entry.attr.note,
620+
&message,
621+
lint::builtin::DEPRECATED);
598622
}
599623
};
600624
}
@@ -614,8 +638,24 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
614638
if let Some(&Stability{rustc_depr: Some(attr::RustcDeprecation { reason, since }), ..})
615639
= stability {
616640
if let Some(id) = id {
641+
let path = self.item_path_str(def_id);
617642
if deprecation_in_effect(&since.as_str()) {
618-
lint_deprecated(def_id, id, Some(reason));
643+
let message = format!("use of deprecated item '{}'", path);
644+
lint_deprecated(def_id,
645+
id,
646+
Some(reason),
647+
&message,
648+
lint::builtin::DEPRECATED);
649+
} else {
650+
let message = format!("use of item '{}' \
651+
that will be deprecated in future version {}",
652+
path,
653+
since);
654+
lint_deprecated(def_id,
655+
id,
656+
Some(reason),
657+
&message,
658+
lint::builtin::DEPRECATED_IN_FUTURE);
619659
}
620660
}
621661
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ignore-tidy-linelength
2+
3+
#![deny(deprecated_in_future)]
4+
5+
#[deprecated(since = "99.99.99", note = "text")]
6+
pub fn deprecated_future() {}
7+
8+
fn test() {
9+
deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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
3+
|
4+
LL | deprecated_future(); //~ ERROR use of item 'deprecated_future' that will be deprecated in future version 99.99.99: text
5+
| ^^^^^^^^^^^^^^^^^
6+
|
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
14+

0 commit comments

Comments
 (0)
Please sign in to comment.