Skip to content

Commit c92c9fd

Browse files
bors[bot]m-ou-se
andauthored
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`: https://github.com/rust-analyzer/rust-analyzer/blob/56a7bf7ede12f6bec194265ea4a95911c9e469bd/crates/hir_def/src/nameres/path_resolution.rs#L132 Co-authored-by: Mara Bos <[email protected]>
2 parents 56a7bf7 + 273d2f9 commit c92c9fd

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

crates/base_db/src/input.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ pub struct CrateData {
190190
pub proc_macro: Vec<ProcMacro>,
191191
}
192192

193-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
193+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
194194
pub enum Edition {
195-
Edition2018,
196195
Edition2015,
196+
Edition2018,
197+
Edition2021,
197198
}
198199

199200
#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -393,6 +394,7 @@ impl FromStr for Edition {
393394
let res = match s {
394395
"2015" => Edition::Edition2015,
395396
"2018" => Edition::Edition2018,
397+
"2021" => Edition::Edition2021,
396398
_ => return Err(ParseEditionError { invalid_input: s.to_string() }),
397399
};
398400
Ok(res)
@@ -404,6 +406,7 @@ impl fmt::Display for Edition {
404406
f.write_str(match self {
405407
Edition::Edition2015 => "2015",
406408
Edition::Edition2018 => "2018",
409+
Edition::Edition2021 => "2021",
407410
})
408411
}
409412
}

crates/ide/src/runnables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl TestAttr {
230230

231231
const RUSTDOC_FENCE: &str = "```";
232232
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] =
233-
&["", "rust", "should_panic", "edition2015", "edition2018"];
233+
&["", "rust", "should_panic", "edition2015", "edition2018", "edition2021"];
234234

235235
fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
236236
attrs.docs().map_or(false, |doc| {

crates/ide/src/syntax_highlighting/injection.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,17 @@ pub(super) fn highlight_injection(
5454
type RangesMap = BTreeMap<TextSize, TextSize>;
5555

5656
const RUSTDOC_FENCE: &'static str = "```";
57-
const RUSTDOC_FENCE_TOKENS: &[&'static str] =
58-
&["", "rust", "should_panic", "ignore", "no_run", "compile_fail", "edition2015", "edition2018"];
57+
const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
58+
"",
59+
"rust",
60+
"should_panic",
61+
"ignore",
62+
"no_run",
63+
"compile_fail",
64+
"edition2015",
65+
"edition2018",
66+
"edition2021",
67+
];
5968

6069
/// Extracts Rust code from documentation comments as well as a mapping from
6170
/// the extracted source code back to the original source ranges.

crates/project_model/src/project_json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,16 @@ enum EditionData {
139139
Edition2015,
140140
#[serde(rename = "2018")]
141141
Edition2018,
142+
#[serde(rename = "2021")]
143+
Edition2021,
142144
}
143145

144146
impl From<EditionData> for Edition {
145147
fn from(data: EditionData) -> Self {
146148
match data {
147149
EditionData::Edition2015 => Edition::Edition2015,
148150
EditionData::Edition2018 => Edition::Edition2018,
151+
EditionData::Edition2021 => Edition::Edition2021,
149152
}
150153
}
151154
}

crates/rust-analyzer/src/markdown.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
//! Transforms markdown
22
33
const RUSTDOC_FENCE: &str = "```";
4-
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC: &[&str] =
5-
&["", "rust", "should_panic", "ignore", "no_run", "compile_fail", "edition2015", "edition2018"];
4+
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC: &[&str] = &[
5+
"",
6+
"rust",
7+
"should_panic",
8+
"ignore",
9+
"no_run",
10+
"compile_fail",
11+
"edition2015",
12+
"edition2018",
13+
"edition2021",
14+
];
615

716
pub(crate) fn format_docs(src: &str) -> String {
817
let mut processed_lines = Vec::new();

docs/user/manual.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ interface Crate {
339339
/// Path to the root module of the crate.
340340
root_module: string;
341341
/// Edition of the crate.
342-
edition: "2015" | "2018";
342+
edition: "2015" | "2018" | "2021";
343343
/// Dependencies
344344
deps: Dep[];
345345
/// Should this crate be treated as a member of current "workspace".

0 commit comments

Comments
 (0)