diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 802b7852bace1..7da4124adcdd2 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -126,14 +126,19 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool { return false; } + let since: Vec = parse_version(&since); + // We simply treat invalid `since` attributes as relating to a previous + // Rust version, thus always displaying the warning. + if since.len() != 3 { + return true; + } + + if let Ok(cargo_rust_version) = std::env::var("CARGO_PKG_RUST_VERSION") && !cargo_rust_version.is_empty() { + let parsed = parse_version(&cargo_rust_version); + return since <= parsed; + } if let Some(rustc) = option_env!("CFG_RELEASE") { - let since: Vec = parse_version(&since); let rustc: Vec = parse_version(rustc); - // We simply treat invalid `since` attributes as relating to a previous - // Rust version, thus always displaying the warning. - if since.len() != 3 { - return true; - } return since <= rustc; } }; diff --git a/src/test/ui/deprecation/respect-rust-version.rs b/src/test/ui/deprecation/respect-rust-version.rs new file mode 100644 index 0000000000000..d4f4d41cf692c --- /dev/null +++ b/src/test/ui/deprecation/respect-rust-version.rs @@ -0,0 +1,6 @@ +// check-pass +// rustc-env:CARGO_PKG_RUST_VERSION=1.28.0 + +fn main() { + let _ = std::env::home_dir(); +}