From 2166bcf7d64f2973a51754d0d004d6112c78ff69 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 24 May 2024 18:24:16 -0300 Subject: [PATCH] Add "better" edition handling on lint-docs tool --- compiler/rustc_lint/src/async_fn_in_trait.rs | 6 +++--- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_lint/src/deref_into_dyn_supertrait.rs | 2 +- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_lint_defs/src/builtin.rs | 6 +++--- src/tools/lint-docs/src/lib.rs | 10 +++++++--- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_lint/src/async_fn_in_trait.rs b/compiler/rustc_lint/src/async_fn_in_trait.rs index 40778542c75c9..f9d03881b8f08 100644 --- a/compiler/rustc_lint/src/async_fn_in_trait.rs +++ b/compiler/rustc_lint/src/async_fn_in_trait.rs @@ -11,7 +11,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,edition2018 /// pub trait Trait { /// async fn method(&self); /// } @@ -32,7 +32,7 @@ declare_lint! { /// /// For example, this code is invalid: /// - /// ```rust,compile_fail + /// ```rust,edition2018,compile_fail /// pub trait Trait { /// async fn method(&self) {} /// } @@ -49,7 +49,7 @@ declare_lint! { /// /// For example, instead of: /// - /// ```rust + /// ```rust,edition2018 /// pub trait Trait { /// async fn method(&self) {} /// } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6b9f9d1531ea1..11449ef8ec625 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1290,7 +1290,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,edition2018 /// #[track_caller] /// async fn foo() {} /// ``` diff --git a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs index b671dfaa0d1b0..35668178f4c9b 100644 --- a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs +++ b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs @@ -19,7 +19,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust,compile_fail + /// ```rust,edition2018,compile_fail /// #![deny(deref_into_dyn_supertrait)] /// #![allow(dead_code)] /// diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index f9f766f832af7..613109abaa38a 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1899,7 +1899,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust,compile_fail + /// ```rust,edition2018,compile_fail /// # use core::sync::atomic::{AtomicU8, Ordering}; /// let atom = AtomicU8::new(0); /// let value = atom.load(Ordering::Release); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 5369454577249..bc1384d5d20cf 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -428,7 +428,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,edition2018 /// #![feature(must_not_suspend)] /// #![warn(must_not_suspend)] /// @@ -1195,7 +1195,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust,compile_fail + /// ```rust,edition2018,compile_fail /// extern crate core; /// pub use core as reexported_core; /// ``` @@ -4514,7 +4514,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust,compile_fail + /// ```rust,edition2018,compile_fail /// #![deny(ambiguous_glob_imports)] /// pub fn foo() -> u32 { /// use sub::*; diff --git a/src/tools/lint-docs/src/lib.rs b/src/tools/lint-docs/src/lib.rs index 22ab576b07762..473522a45bfff 100644 --- a/src/tools/lint-docs/src/lib.rs +++ b/src/tools/lint-docs/src/lib.rs @@ -441,10 +441,14 @@ impl<'a> LintExtractor<'a> { fs::write(&tempfile, source) .map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?; let mut cmd = Command::new(self.rustc_path); - if options.contains(&"edition2015") { - cmd.arg("--edition=2015"); - } else { + if options.contains(&"edition2024") { + cmd.arg("--edition=2024"); + } else if options.contains(&"edition2021") { + cmd.arg("--edition=2021"); + } else if options.contains(&"edition2018") { cmd.arg("--edition=2018"); + } else { + cmd.arg("--edition=2015"); } cmd.arg("--error-format=json"); cmd.arg("--target").arg(self.rustc_target);