mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Merge #7123
7123: Add support for Rust 2021. r=lnicola a=m-ou-se
This adds `2021` in all places where rust-analyzer already knew about `2015` and `2018`.
The only edition-specific behaviour I could find in the source code was gated on a direct comparison with `Edition2015`, so `Edition2021` should (correctly) behave the same as `Edition2018`:
56a7bf7ede/crates/hir_def/src/nameres/path_resolution.rs (L132)
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
This commit is contained in:
commit
c92c9fdc52
6 changed files with 32 additions and 8 deletions
|
@ -190,10 +190,11 @@ pub struct CrateData {
|
||||||
pub proc_macro: Vec<ProcMacro>,
|
pub proc_macro: Vec<ProcMacro>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum Edition {
|
pub enum Edition {
|
||||||
Edition2018,
|
|
||||||
Edition2015,
|
Edition2015,
|
||||||
|
Edition2018,
|
||||||
|
Edition2021,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -393,6 +394,7 @@ impl FromStr for Edition {
|
||||||
let res = match s {
|
let res = match s {
|
||||||
"2015" => Edition::Edition2015,
|
"2015" => Edition::Edition2015,
|
||||||
"2018" => Edition::Edition2018,
|
"2018" => Edition::Edition2018,
|
||||||
|
"2021" => Edition::Edition2021,
|
||||||
_ => return Err(ParseEditionError { invalid_input: s.to_string() }),
|
_ => return Err(ParseEditionError { invalid_input: s.to_string() }),
|
||||||
};
|
};
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
@ -404,6 +406,7 @@ impl fmt::Display for Edition {
|
||||||
f.write_str(match self {
|
f.write_str(match self {
|
||||||
Edition::Edition2015 => "2015",
|
Edition::Edition2015 => "2015",
|
||||||
Edition::Edition2018 => "2018",
|
Edition::Edition2018 => "2018",
|
||||||
|
Edition::Edition2021 => "2021",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,7 @@ impl TestAttr {
|
||||||
|
|
||||||
const RUSTDOC_FENCE: &str = "```";
|
const RUSTDOC_FENCE: &str = "```";
|
||||||
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] =
|
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] =
|
||||||
&["", "rust", "should_panic", "edition2015", "edition2018"];
|
&["", "rust", "should_panic", "edition2015", "edition2018", "edition2021"];
|
||||||
|
|
||||||
fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
|
fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
|
||||||
attrs.docs().map_or(false, |doc| {
|
attrs.docs().map_or(false, |doc| {
|
||||||
|
|
|
@ -54,8 +54,17 @@ pub(super) fn highlight_injection(
|
||||||
type RangesMap = BTreeMap<TextSize, TextSize>;
|
type RangesMap = BTreeMap<TextSize, TextSize>;
|
||||||
|
|
||||||
const RUSTDOC_FENCE: &'static str = "```";
|
const RUSTDOC_FENCE: &'static str = "```";
|
||||||
const RUSTDOC_FENCE_TOKENS: &[&'static str] =
|
const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
|
||||||
&["", "rust", "should_panic", "ignore", "no_run", "compile_fail", "edition2015", "edition2018"];
|
"",
|
||||||
|
"rust",
|
||||||
|
"should_panic",
|
||||||
|
"ignore",
|
||||||
|
"no_run",
|
||||||
|
"compile_fail",
|
||||||
|
"edition2015",
|
||||||
|
"edition2018",
|
||||||
|
"edition2021",
|
||||||
|
];
|
||||||
|
|
||||||
/// Extracts Rust code from documentation comments as well as a mapping from
|
/// Extracts Rust code from documentation comments as well as a mapping from
|
||||||
/// the extracted source code back to the original source ranges.
|
/// the extracted source code back to the original source ranges.
|
||||||
|
|
|
@ -139,6 +139,8 @@ enum EditionData {
|
||||||
Edition2015,
|
Edition2015,
|
||||||
#[serde(rename = "2018")]
|
#[serde(rename = "2018")]
|
||||||
Edition2018,
|
Edition2018,
|
||||||
|
#[serde(rename = "2021")]
|
||||||
|
Edition2021,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<EditionData> for Edition {
|
impl From<EditionData> for Edition {
|
||||||
|
@ -146,6 +148,7 @@ impl From<EditionData> for Edition {
|
||||||
match data {
|
match data {
|
||||||
EditionData::Edition2015 => Edition::Edition2015,
|
EditionData::Edition2015 => Edition::Edition2015,
|
||||||
EditionData::Edition2018 => Edition::Edition2018,
|
EditionData::Edition2018 => Edition::Edition2018,
|
||||||
|
EditionData::Edition2021 => Edition::Edition2021,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
//! Transforms markdown
|
//! Transforms markdown
|
||||||
|
|
||||||
const RUSTDOC_FENCE: &str = "```";
|
const RUSTDOC_FENCE: &str = "```";
|
||||||
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC: &[&str] =
|
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC: &[&str] = &[
|
||||||
&["", "rust", "should_panic", "ignore", "no_run", "compile_fail", "edition2015", "edition2018"];
|
"",
|
||||||
|
"rust",
|
||||||
|
"should_panic",
|
||||||
|
"ignore",
|
||||||
|
"no_run",
|
||||||
|
"compile_fail",
|
||||||
|
"edition2015",
|
||||||
|
"edition2018",
|
||||||
|
"edition2021",
|
||||||
|
];
|
||||||
|
|
||||||
pub(crate) fn format_docs(src: &str) -> String {
|
pub(crate) fn format_docs(src: &str) -> String {
|
||||||
let mut processed_lines = Vec::new();
|
let mut processed_lines = Vec::new();
|
||||||
|
|
|
@ -339,7 +339,7 @@ interface Crate {
|
||||||
/// Path to the root module of the crate.
|
/// Path to the root module of the crate.
|
||||||
root_module: string;
|
root_module: string;
|
||||||
/// Edition of the crate.
|
/// Edition of the crate.
|
||||||
edition: "2015" | "2018";
|
edition: "2015" | "2018" | "2021";
|
||||||
/// Dependencies
|
/// Dependencies
|
||||||
deps: Dep[];
|
deps: Dep[];
|
||||||
/// Should this crate be treated as a member of current "workspace".
|
/// Should this crate be treated as a member of current "workspace".
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue