Skip to content

Commit c08902b

Browse files
committed
Prevent deprecation warning for items deprecated in the future
1 parent ab8b961 commit c08902b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/librustc/middle/stability.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,41 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
559559
// Deprecated attributes apply in-crate and cross-crate.
560560
if let Some(id) = id {
561561
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
562+
fn deprecation_in_effect(since: Option<&str>, rustc: Option<&str>) -> bool {
563+
fn parse_version(ver: &str) -> Vec<u32> {
564+
// We ignore non-integer components of the version (e.g. "nightly").
565+
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
566+
}
567+
568+
if since.is_none() || rustc.is_none() {
569+
// By default, a deprecation warning applies to
570+
// the current version of the compiler.
571+
true
572+
} else {
573+
let since: Vec<u32> = parse_version(since.unwrap());
574+
let rustc: Vec<u32> = parse_version(rustc.unwrap());
575+
// We simply treat invalid `since` attributes as relating to a previous
576+
// Rust version, thus always displaying the warning.
577+
if since.len() != 3 {
578+
return true;
579+
}
580+
since <= rustc
581+
}
582+
}
583+
584+
// If the deprecation is scheduled for a future Rust
585+
// version, then we should display no warning message.
586+
let deprecated_in_future_version = if let Some(sym) = depr_entry.attr.since {
587+
let since = sym.as_str();
588+
!deprecation_in_effect(Some(since.as_ref()), option_env!("CFG_RELEASE"))
589+
} else {
590+
false
591+
};
592+
562593
let parent_def_id = self.hir.local_def_id(self.hir.get_parent(id));
563-
let skip = self.lookup_deprecation_entry(parent_def_id)
564-
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
594+
let skip = deprecated_in_future_version ||
595+
self.lookup_deprecation_entry(parent_def_id)
596+
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
565597
if !skip {
566598
lint_deprecated(def_id, id, depr_entry.attr.note);
567599
}

0 commit comments

Comments
 (0)