Skip to content

respect CARGO_PKG_RUST_VERSION when issuing deprecation warnings #98893

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

Closed
Closed
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
17 changes: 11 additions & 6 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,19 @@ pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
return false;
}

let since: Vec<u32> = 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<u32> = parse_version(&since);
let rustc: Vec<u32> = 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;
}
};
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/deprecation/respect-rust-version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-pass
// rustc-env:CARGO_PKG_RUST_VERSION=1.28.0

fn main() {
let _ = std::env::home_dir();
}