diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-11-02 23:51:03 +0200 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-12-11 20:48:41 +0200 |
| commit | 2950325f37fda0629fba99e751104b6faeb73ddb (patch) | |
| tree | 42ac6cb5541fef980af8090a0c29e94948b524cf /src/tools/rust-analyzer/crates/parser | |
| parent | a18e38e6e23255e095dd3be763e7fa29bc5d4cbe (diff) | |
Properly handle different defaults for severity of lints
Previously all lints were assumed to be `#[warn]`, and we had a hand-coded list of `#[allow]` exceptions. Now the severity is autogenerated from rustdoc output. Also support lints that change status between editions, and the `warnings` lint group.
Diffstat (limited to 'src/tools/rust-analyzer/crates/parser')
| -rw-r--r-- | src/tools/rust-analyzer/crates/parser/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/parser/src/edition.rs | 77 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/parser/src/lib.rs | 4 |
3 files changed, 4 insertions, 79 deletions
diff --git a/src/tools/rust-analyzer/crates/parser/Cargo.toml b/src/tools/rust-analyzer/crates/parser/Cargo.toml index d5255665b46..3629d275c0c 100644 --- a/src/tools/rust-analyzer/crates/parser/Cargo.toml +++ b/src/tools/rust-analyzer/crates/parser/Cargo.toml @@ -18,6 +18,8 @@ ra-ap-rustc_lexer.workspace = true limit.workspace = true tracing = { workspace = true, optional = true } +edition.workspace = true + [dev-dependencies] expect-test = "1.4.0" diff --git a/src/tools/rust-analyzer/crates/parser/src/edition.rs b/src/tools/rust-analyzer/crates/parser/src/edition.rs deleted file mode 100644 index 702b16252d4..00000000000 --- a/src/tools/rust-analyzer/crates/parser/src/edition.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! The edition of the Rust language used in a crate. -// Ideally this would be defined in the span crate, but the dependency chain is all over the place -// wrt to span, parser and syntax. -use std::fmt; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(u8)] -pub enum Edition { - Edition2015, - Edition2018, - Edition2021, - Edition2024, -} - -impl Edition { - pub const DEFAULT: Edition = Edition::Edition2015; - pub const LATEST: Edition = Edition::Edition2024; - pub const CURRENT: Edition = Edition::Edition2021; - /// The current latest stable edition, note this is usually not the right choice in code. - pub const CURRENT_FIXME: Edition = Edition::Edition2021; - - pub fn at_least_2024(self) -> bool { - self >= Edition::Edition2024 - } - - pub fn at_least_2021(self) -> bool { - self >= Edition::Edition2021 - } - - pub fn at_least_2018(self) -> bool { - self >= Edition::Edition2018 - } - - pub fn iter() -> impl Iterator<Item = Edition> { - [Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024] - .iter() - .copied() - } -} - -#[derive(Debug)] -pub struct ParseEditionError { - invalid_input: String, -} - -impl std::error::Error for ParseEditionError {} -impl fmt::Display for ParseEditionError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "invalid edition: {:?}", self.invalid_input) - } -} - -impl std::str::FromStr for Edition { - type Err = ParseEditionError; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - let res = match s { - "2015" => Edition::Edition2015, - "2018" => Edition::Edition2018, - "2021" => Edition::Edition2021, - "2024" => Edition::Edition2024, - _ => return Err(ParseEditionError { invalid_input: s.to_owned() }), - }; - Ok(res) - } -} - -impl fmt::Display for Edition { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match self { - Edition::Edition2015 => "2015", - Edition::Edition2018 => "2018", - Edition::Edition2021 => "2021", - Edition::Edition2024 => "2024", - }) - } -} diff --git a/src/tools/rust-analyzer/crates/parser/src/lib.rs b/src/tools/rust-analyzer/crates/parser/src/lib.rs index 679492066a3..e461492cc6f 100644 --- a/src/tools/rust-analyzer/crates/parser/src/lib.rs +++ b/src/tools/rust-analyzer/crates/parser/src/lib.rs @@ -25,7 +25,6 @@ extern crate ra_ap_rustc_lexer as rustc_lexer; #[cfg(feature = "in-rust-tree")] extern crate rustc_lexer; -mod edition; mod event; mod grammar; mod input; @@ -41,8 +40,9 @@ mod tests; pub(crate) use token_set::TokenSet; +pub use edition::Edition; + pub use crate::{ - edition::Edition, input::Input, lexed_str::LexedStr, output::{Output, Step}, |
