Rollup merge of #140348 - ehuss:lint-docs-edition, r=compiler-errors

Update lint-docs to default to Rust 2024

This updates the lint-docs tool to default to the 2024 edition. The lint docs are supposed to illustrate the code with the latest edition, and I just forgot to update this in https://github.com/rust-lang/rust/pull/133349.

Some docs needed to add the `edition` attribute since they were assuming a particular edition, but were missing the explicit annotation.

This also includes a commit to simplify the edition handling in lint-docs.
This commit is contained in:
Matthias Krüger 2025-04-27 16:09:00 +02:00 committed by GitHub
commit c006eb7010
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 18 deletions

View File

@ -948,7 +948,7 @@ declare_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail,edition2021
/// #[no_mangle] /// #[no_mangle]
/// const FOO: i32 = 5; /// const FOO: i32 = 5;
/// ``` /// ```

View File

@ -41,7 +41,7 @@ declare_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail,edition2021
/// # #![deny(impl_trait_overcaptures)] /// # #![deny(impl_trait_overcaptures)]
/// # use std::fmt::Display; /// # use std::fmt::Display;
/// let mut x = vec![]; /// let mut x = vec![];

View File

@ -1424,7 +1424,7 @@ declare_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail,edition2021
/// macro_rules! foo { /// macro_rules! foo {
/// () => {}; /// () => {};
/// ($name) => { }; /// ($name) => { };
@ -4128,7 +4128,7 @@ declare_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail,edition2021
/// #![deny(dependency_on_unit_never_type_fallback)] /// #![deny(dependency_on_unit_never_type_fallback)]
/// fn main() { /// fn main() {
/// if true { /// if true {

View File

@ -444,21 +444,15 @@ impl<'a> LintExtractor<'a> {
fs::write(&tempfile, source) fs::write(&tempfile, source)
.map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?; .map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
let mut cmd = Command::new(self.rustc_path); let mut cmd = Command::new(self.rustc_path);
if options.contains(&"edition2024") { let edition = options
cmd.arg("--edition=2024"); .iter()
cmd.arg("-Zunstable-options"); .filter_map(|opt| opt.strip_prefix("edition"))
} else if options.contains(&"edition2021") { .next()
cmd.arg("--edition=2021");
} else if options.contains(&"edition2018") {
cmd.arg("--edition=2018");
} else if options.contains(&"edition2015") {
cmd.arg("--edition=2015");
} else if options.contains(&"edition") {
panic!("lint-docs: unknown edition");
} else {
// defaults to latest edition // defaults to latest edition
cmd.arg("--edition=2021"); .unwrap_or("2024");
} cmd.arg(format!("--edition={edition}"));
// Just in case this is an unstable edition.
cmd.arg("-Zunstable-options");
cmd.arg("--error-format=json"); cmd.arg("--error-format=json");
cmd.arg("--target").arg(self.rustc_target); cmd.arg("--target").arg(self.rustc_target);
if let Some(target_linker) = self.rustc_linker { if let Some(target_linker) = self.rustc_linker {