-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #16450 - Urhengulas:edition-aware-parser, r=Veykril
internal: Prepare parser interface for editions
- Loading branch information
Showing
24 changed files
with
140 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,6 +303,7 @@ pub mod known { | |
rust_2015, | ||
rust_2018, | ||
rust_2021, | ||
rust_2024, | ||
v1, | ||
new_display, | ||
new_debug, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! 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)] | ||
pub enum Edition { | ||
Edition2015, | ||
Edition2018, | ||
Edition2021, | ||
Edition2024, | ||
} | ||
|
||
impl Edition { | ||
pub const CURRENT: Edition = Edition::Edition2021; | ||
pub const DEFAULT: Edition = Edition::Edition2015; | ||
} | ||
|
||
#[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", | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.