Skip to content

Commit 4848b1b

Browse files
authored
Merge pull request rust-lang#19355 from Veykril/push-nzknrnouutnp
internal: Render root syntax contexts more clearly
2 parents d89aefd + 68d08a5 commit 4848b1b

File tree

10 files changed

+182
-179
lines changed

10 files changed

+182
-179
lines changed

src/tools/rust-analyzer/crates/edition/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ impl Edition {
4141
self >= Edition::Edition2018
4242
}
4343

44+
pub fn number(&self) -> usize {
45+
match self {
46+
Edition::Edition2015 => 2015,
47+
Edition::Edition2018 => 2018,
48+
Edition::Edition2021 => 2021,
49+
Edition::Edition2024 => 2024,
50+
}
51+
}
52+
4453
pub fn iter() -> impl Iterator<Item = Edition> {
4554
[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024]
4655
.iter()

src/tools/rust-analyzer/crates/hir-def/src/item_tree/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ m!();
270270
// AstId: 2
271271
pub macro m2 { ... }
272272
273-
// AstId: 3, SyntaxContextId: 4294967037, ExpandTo: Items
273+
// AstId: 3, SyntaxContextId: ROOT2021, ExpandTo: Items
274274
m!(...);
275275
"#]],
276276
);

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! f {
3535
};
3636
}
3737
38-
struct#0:1@58..64#20480# MyTraitMap2#0:2@31..42#4294967037# {#0:1@72..73#20480#
38+
struct#0:1@58..64#20480# MyTraitMap2#0:2@31..42#ROOT2021# {#0:1@72..73#20480#
3939
map#0:1@86..89#20480#:#0:1@89..90#20480# #0:1@89..90#20480#::#0:1@91..93#20480#std#0:1@93..96#20480#::#0:1@96..98#20480#collections#0:1@98..109#20480#::#0:1@109..111#20480#HashSet#0:1@111..118#20480#<#0:1@118..119#20480#(#0:1@119..120#20480#)#0:1@120..121#20480#>#0:1@121..122#20480#,#0:1@122..123#20480#
4040
}#0:1@132..133#20480#
4141
"#]],
@@ -75,12 +75,12 @@ macro_rules! f {
7575
};
7676
}
7777
78-
fn#0:2@30..32#4294967037# main#0:2@33..37#4294967037#(#0:2@37..38#4294967037#)#0:2@38..39#4294967037# {#0:2@40..41#4294967037#
79-
1#0:2@50..51#4294967037#;#0:2@51..52#4294967037#
80-
1.0#0:2@61..64#4294967037#;#0:2@64..65#4294967037#
81-
(#0:2@74..75#4294967037#(#0:2@75..76#4294967037#1#0:2@76..77#4294967037#,#0:2@77..78#4294967037# )#0:2@78..79#4294967037#,#0:2@79..80#4294967037# )#0:2@80..81#4294967037#.#0:2@81..82#4294967037#0#0:2@82..85#4294967037#.#0:2@82..85#4294967037#0#0:2@82..85#4294967037#;#0:2@85..86#4294967037#
82-
let#0:2@95..98#4294967037# x#0:2@99..100#4294967037# =#0:2@101..102#4294967037# 1#0:2@103..104#4294967037#;#0:2@104..105#4294967037#
83-
}#0:2@110..111#4294967037#
78+
fn#0:2@30..32#ROOT2021# main#0:2@33..37#ROOT2021#(#0:2@37..38#ROOT2021#)#0:2@38..39#ROOT2021# {#0:2@40..41#ROOT2021#
79+
1#0:2@50..51#ROOT2021#;#0:2@51..52#ROOT2021#
80+
1.0#0:2@61..64#ROOT2021#;#0:2@64..65#ROOT2021#
81+
(#0:2@74..75#ROOT2021#(#0:2@75..76#ROOT2021#1#0:2@76..77#ROOT2021#,#0:2@77..78#ROOT2021# )#0:2@78..79#ROOT2021#,#0:2@79..80#ROOT2021# )#0:2@80..81#ROOT2021#.#0:2@81..82#ROOT2021#0#0:2@82..85#ROOT2021#.#0:2@82..85#ROOT2021#0#0:2@82..85#ROOT2021#;#0:2@85..86#ROOT2021#
82+
let#0:2@95..98#ROOT2021# x#0:2@99..100#ROOT2021# =#0:2@101..102#ROOT2021# 1#0:2@103..104#ROOT2021#;#0:2@104..105#ROOT2021#
83+
}#0:2@110..111#ROOT2021#
8484
8585
8686
"#]],
@@ -171,7 +171,7 @@ fn main(foo: ()) {
171171
}
172172
173173
fn main(foo: ()) {
174-
/* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#4294967037#;
174+
/* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#ROOT2021#;
175175
}
176176
}
177177
@@ -197,7 +197,7 @@ macro_rules! mk_struct {
197197
#[macro_use]
198198
mod foo;
199199
200-
struct#1:1@59..65#20480# Foo#0:2@32..35#4294967037#(#1:1@70..71#20480#u32#0:2@41..44#4294967037#)#1:1@74..75#20480#;#1:1@75..76#20480#
200+
struct#1:1@59..65#20480# Foo#0:2@32..35#ROOT2021#(#1:1@70..71#20480#u32#0:2@41..44#ROOT2021#)#1:1@74..75#20480#;#1:1@75..76#20480#
201201
"#]],
202202
);
203203
}
@@ -424,8 +424,8 @@ macro_rules! m {
424424
($($i:ident),*) => ( impl Bar { $(fn $i() {})* } );
425425
}
426426
impl#\20480# Bar#\20480# {#\20480#
427-
fn#\20480# foo#\4294967037#(#\20480#)#\20480# {#\20480#}#\20480#
428-
fn#\20480# bar#\4294967037#(#\20480#)#\20480# {#\20480#}#\20480#
427+
fn#\20480# foo#\ROOT2021#(#\20480#)#\20480# {#\20480#}#\20480#
428+
fn#\20480# bar#\ROOT2021#(#\20480#)#\20480# {#\20480#}#\20480#
429429
}#\20480#
430430
"#]],
431431
);

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/proc_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ fn foo(&self) {
181181
self.0. 1;
182182
}
183183
184-
fn#0:1@45..47#4294967037# foo#0:1@48..51#4294967037#(#0:1@51..52#4294967037#&#0:1@52..53#4294967037#self#0:1@53..57#4294967037# )#0:1@57..58#4294967037# {#0:1@59..60#4294967037#
185-
self#0:1@65..69#4294967037# .#0:1@69..70#4294967037#0#0:1@70..71#4294967037#.#0:1@71..72#4294967037#1#0:1@73..74#4294967037#;#0:1@74..75#4294967037#
186-
}#0:1@76..77#4294967037#"#]],
184+
fn#0:1@45..47#ROOT2021# foo#0:1@48..51#ROOT2021#(#0:1@51..52#ROOT2021#&#0:1@52..53#ROOT2021#self#0:1@53..57#ROOT2021# )#0:1@57..58#ROOT2021# {#0:1@59..60#ROOT2021#
185+
self#0:1@65..69#ROOT2021# .#0:1@69..70#ROOT2021#0#0:1@70..71#ROOT2021#.#0:1@71..72#ROOT2021#1#0:1@73..74#ROOT2021#;#0:1@74..75#ROOT2021#
186+
}#0:1@76..77#ROOT2021#"#]],
187187
);
188188
}
189189

src/tools/rust-analyzer/crates/hir-expand/src/builtin/quote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ mod tests {
277277
assert_eq!(quoted.to_string(), "hello");
278278
let t = format!("{quoted:#?}");
279279
expect![[r#"
280-
SUBTREE $$ 937550:0@0..0#4294967037 937550:0@0..0#4294967037
281-
IDENT hello 937550:0@0..0#4294967037"#]]
280+
SUBTREE $$ 937550:0@0..0#ROOT2021 937550:0@0..0#ROOT2021
281+
IDENT hello 937550:0@0..0#ROOT2021"#]]
282282
.assert_eq(&t);
283283
}
284284

src/tools/rust-analyzer/crates/hir-expand/src/proc_macro.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ impl ProcMacrosBuilder {
7878
if let Ok(proc_macros) = &mut proc_macro {
7979
// Sort proc macros to improve incrementality when only their order has changed (ideally the build system
8080
// will not change their order, but just to be sure).
81-
proc_macros
82-
.sort_unstable_by_key(|proc_macro| (proc_macro.name.clone(), proc_macro.kind));
81+
proc_macros.sort_unstable_by(|proc_macro, proc_macro2| {
82+
(proc_macro.name.as_str(), proc_macro.kind)
83+
.cmp(&(proc_macro2.name.as_str(), proc_macro2.kind))
84+
});
8385
}
8486
self.0.insert(
8587
proc_macros_crate,

src/tools/rust-analyzer/crates/intern/src/symbol.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ struct TaggedArcPtr {
4242
unsafe impl Send for TaggedArcPtr {}
4343
unsafe impl Sync for TaggedArcPtr {}
4444

45-
impl Ord for TaggedArcPtr {
46-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
47-
self.as_str().cmp(other.as_str())
48-
}
49-
}
50-
51-
impl PartialOrd for TaggedArcPtr {
52-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
53-
Some(self.cmp(other))
54-
}
55-
}
56-
5745
impl TaggedArcPtr {
5846
const BOOL_BITS: usize = true as usize;
5947

@@ -125,7 +113,7 @@ impl TaggedArcPtr {
125113
}
126114
}
127115

128-
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
116+
#[derive(PartialEq, Eq, Hash)]
129117
pub struct Symbol {
130118
repr: TaggedArcPtr,
131119
}

src/tools/rust-analyzer/crates/mbe/src/tests.rs

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ fn unbalanced_brace() {
109109
"#,
110110
r#""#,
111111
expect![[r#"
112-
SUBTREE $$ 1:0@0..0#4294967037 1:0@0..0#4294967037
113-
SUBTREE {} 0:0@9..10#4294967037 0:0@11..12#4294967037
112+
SUBTREE $$ 1:0@0..0#ROOT2021 1:0@0..0#ROOT2021
113+
SUBTREE {} 0:0@9..10#ROOT2021 0:0@11..12#ROOT2021
114114
115115
{}"#]],
116116
);
@@ -132,25 +132,25 @@ fn token_mapping_smoke_test() {
132132
struct MyTraitMap2
133133
"#,
134134
expect![[r#"
135-
SUBTREE $$ 1:0@0..20#4294967037 1:0@0..20#4294967037
136-
IDENT struct 0:0@34..40#4294967037
137-
IDENT MyTraitMap2 1:0@8..19#4294967037
138-
SUBTREE {} 0:0@48..49#4294967037 0:0@100..101#4294967037
139-
IDENT map 0:0@58..61#4294967037
140-
PUNCH : [alone] 0:0@61..62#4294967037
141-
PUNCH : [joint] 0:0@63..64#4294967037
142-
PUNCH : [alone] 0:0@64..65#4294967037
143-
IDENT std 0:0@65..68#4294967037
144-
PUNCH : [joint] 0:0@68..69#4294967037
145-
PUNCH : [alone] 0:0@69..70#4294967037
146-
IDENT collections 0:0@70..81#4294967037
147-
PUNCH : [joint] 0:0@81..82#4294967037
148-
PUNCH : [alone] 0:0@82..83#4294967037
149-
IDENT HashSet 0:0@83..90#4294967037
150-
PUNCH < [alone] 0:0@90..91#4294967037
151-
SUBTREE () 0:0@91..92#4294967037 0:0@92..93#4294967037
152-
PUNCH > [joint] 0:0@93..94#4294967037
153-
PUNCH , [alone] 0:0@94..95#4294967037
135+
SUBTREE $$ 1:0@0..20#ROOT2021 1:0@0..20#ROOT2021
136+
IDENT struct 0:0@34..40#ROOT2021
137+
IDENT MyTraitMap2 1:0@8..19#ROOT2021
138+
SUBTREE {} 0:0@48..49#ROOT2021 0:0@100..101#ROOT2021
139+
IDENT map 0:0@58..61#ROOT2021
140+
PUNCH : [alone] 0:0@61..62#ROOT2021
141+
PUNCH : [joint] 0:0@63..64#ROOT2021
142+
PUNCH : [alone] 0:0@64..65#ROOT2021
143+
IDENT std 0:0@65..68#ROOT2021
144+
PUNCH : [joint] 0:0@68..69#ROOT2021
145+
PUNCH : [alone] 0:0@69..70#ROOT2021
146+
IDENT collections 0:0@70..81#ROOT2021
147+
PUNCH : [joint] 0:0@81..82#ROOT2021
148+
PUNCH : [alone] 0:0@82..83#ROOT2021
149+
IDENT HashSet 0:0@83..90#ROOT2021
150+
PUNCH < [alone] 0:0@90..91#ROOT2021
151+
SUBTREE () 0:0@91..92#ROOT2021 0:0@92..93#ROOT2021
152+
PUNCH > [joint] 0:0@93..94#ROOT2021
153+
PUNCH , [alone] 0:0@94..95#ROOT2021
154154
155155
struct MyTraitMap2 {
156156
map: ::std::collections::HashSet<()>,
@@ -179,28 +179,28 @@ fn main() {
179179
}
180180
"#,
181181
expect![[r#"
182-
SUBTREE $$ 1:0@0..63#4294967037 1:0@0..63#4294967037
183-
IDENT fn 1:0@1..3#4294967037
184-
IDENT main 1:0@4..8#4294967037
185-
SUBTREE () 1:0@8..9#4294967037 1:0@9..10#4294967037
186-
SUBTREE {} 1:0@11..12#4294967037 1:0@61..62#4294967037
187-
LITERAL Integer 1 1:0@17..18#4294967037
188-
PUNCH ; [alone] 1:0@18..19#4294967037
189-
LITERAL Float 1.0 1:0@24..27#4294967037
190-
PUNCH ; [alone] 1:0@27..28#4294967037
191-
SUBTREE () 1:0@33..34#4294967037 1:0@39..40#4294967037
192-
SUBTREE () 1:0@34..35#4294967037 1:0@37..38#4294967037
193-
LITERAL Integer 1 1:0@35..36#4294967037
194-
PUNCH , [alone] 1:0@36..37#4294967037
195-
PUNCH , [alone] 1:0@38..39#4294967037
196-
PUNCH . [alone] 1:0@40..41#4294967037
197-
LITERAL Float 0.0 1:0@41..44#4294967037
198-
PUNCH ; [alone] 1:0@44..45#4294967037
199-
IDENT let 1:0@50..53#4294967037
200-
IDENT x 1:0@54..55#4294967037
201-
PUNCH = [alone] 1:0@56..57#4294967037
202-
LITERAL Integer 1 1:0@58..59#4294967037
203-
PUNCH ; [alone] 1:0@59..60#4294967037
182+
SUBTREE $$ 1:0@0..63#ROOT2021 1:0@0..63#ROOT2021
183+
IDENT fn 1:0@1..3#ROOT2021
184+
IDENT main 1:0@4..8#ROOT2021
185+
SUBTREE () 1:0@8..9#ROOT2021 1:0@9..10#ROOT2021
186+
SUBTREE {} 1:0@11..12#ROOT2021 1:0@61..62#ROOT2021
187+
LITERAL Integer 1 1:0@17..18#ROOT2021
188+
PUNCH ; [alone] 1:0@18..19#ROOT2021
189+
LITERAL Float 1.0 1:0@24..27#ROOT2021
190+
PUNCH ; [alone] 1:0@27..28#ROOT2021
191+
SUBTREE () 1:0@33..34#ROOT2021 1:0@39..40#ROOT2021
192+
SUBTREE () 1:0@34..35#ROOT2021 1:0@37..38#ROOT2021
193+
LITERAL Integer 1 1:0@35..36#ROOT2021
194+
PUNCH , [alone] 1:0@36..37#ROOT2021
195+
PUNCH , [alone] 1:0@38..39#ROOT2021
196+
PUNCH . [alone] 1:0@40..41#ROOT2021
197+
LITERAL Float 0.0 1:0@41..44#ROOT2021
198+
PUNCH ; [alone] 1:0@44..45#ROOT2021
199+
IDENT let 1:0@50..53#ROOT2021
200+
IDENT x 1:0@54..55#ROOT2021
201+
PUNCH = [alone] 1:0@56..57#ROOT2021
202+
LITERAL Integer 1 1:0@58..59#ROOT2021
203+
PUNCH ; [alone] 1:0@59..60#ROOT2021
204204
205205
fn main(){
206206
1;
@@ -226,14 +226,14 @@ fn expr_2021() {
226226
const { 1 },
227227
"#,
228228
expect![[r#"
229-
SUBTREE $$ 1:0@0..25#4294967037 1:0@0..25#4294967037
230-
IDENT _ 1:0@5..6#4294967037
231-
PUNCH ; [joint] 0:0@36..37#4294967037
232-
SUBTREE () 0:0@34..35#4294967037 0:0@34..35#4294967037
233-
IDENT const 1:0@12..17#4294967037
234-
SUBTREE {} 1:0@18..19#4294967037 1:0@22..23#4294967037
235-
LITERAL Integer 1 1:0@20..21#4294967037
236-
PUNCH ; [alone] 0:0@39..40#4294967037
229+
SUBTREE $$ 1:0@0..25#ROOT2021 1:0@0..25#ROOT2021
230+
IDENT _ 1:0@5..6#ROOT2021
231+
PUNCH ; [joint] 0:0@36..37#ROOT2021
232+
SUBTREE () 0:0@34..35#ROOT2021 0:0@34..35#ROOT2021
233+
IDENT const 1:0@12..17#ROOT2021
234+
SUBTREE {} 1:0@18..19#ROOT2021 1:0@22..23#ROOT2021
235+
LITERAL Integer 1 1:0@20..21#ROOT2021
236+
PUNCH ; [alone] 0:0@39..40#ROOT2021
237237
238238
_;
239239
(const {
@@ -254,13 +254,13 @@ fn expr_2021() {
254254
expect![[r#"
255255
ExpandError {
256256
inner: (
257-
1:0@5..6#4294967037,
257+
1:0@5..6#ROOT2021,
258258
NoMatchingRule,
259259
),
260260
}
261261
262-
SUBTREE $$ 1:0@0..8#4294967037 1:0@0..8#4294967037
263-
PUNCH ; [alone] 0:0@39..40#4294967037
262+
SUBTREE $$ 1:0@0..8#ROOT2021 1:0@0..8#ROOT2021
263+
PUNCH ; [alone] 0:0@39..40#ROOT2021
264264
265265
;"#]],
266266
);
@@ -278,13 +278,13 @@ fn expr_2021() {
278278
expect![[r#"
279279
ExpandError {
280280
inner: (
281-
1:0@5..10#4294967037,
281+
1:0@5..10#ROOT2021,
282282
NoMatchingRule,
283283
),
284284
}
285285
286-
SUBTREE $$ 1:0@0..18#4294967037 1:0@0..18#4294967037
287-
PUNCH ; [alone] 0:0@39..40#4294967037
286+
SUBTREE $$ 1:0@0..18#ROOT2021 1:0@0..18#ROOT2021
287+
PUNCH ; [alone] 0:0@39..40#ROOT2021
288288
289289
;"#]],
290290
);
@@ -304,26 +304,26 @@ fn expr_2021() {
304304
break 'foo bar,
305305
"#,
306306
expect![[r#"
307-
SUBTREE $$ 1:0@0..76#4294967037 1:0@0..76#4294967037
308-
LITERAL Integer 4 1:0@5..6#4294967037
309-
PUNCH ; [joint] 0:0@41..42#4294967037
310-
LITERAL Str literal 1:0@12..21#4294967037
311-
PUNCH ; [joint] 0:0@41..42#4294967037
312-
SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037
313-
IDENT funcall 1:0@27..34#4294967037
314-
SUBTREE () 1:0@34..35#4294967037 1:0@35..36#4294967037
315-
PUNCH ; [joint] 0:0@41..42#4294967037
316-
SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037
317-
IDENT future 1:0@42..48#4294967037
318-
PUNCH . [alone] 1:0@48..49#4294967037
319-
IDENT await 1:0@49..54#4294967037
320-
PUNCH ; [joint] 0:0@41..42#4294967037
321-
SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037
322-
IDENT break 1:0@60..65#4294967037
323-
PUNCH ' [joint] 1:0@66..67#4294967037
324-
IDENT foo 1:0@67..70#4294967037
325-
IDENT bar 1:0@71..74#4294967037
326-
PUNCH ; [alone] 0:0@44..45#4294967037
307+
SUBTREE $$ 1:0@0..76#ROOT2021 1:0@0..76#ROOT2021
308+
LITERAL Integer 4 1:0@5..6#ROOT2021
309+
PUNCH ; [joint] 0:0@41..42#ROOT2021
310+
LITERAL Str literal 1:0@12..21#ROOT2021
311+
PUNCH ; [joint] 0:0@41..42#ROOT2021
312+
SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021
313+
IDENT funcall 1:0@27..34#ROOT2021
314+
SUBTREE () 1:0@34..35#ROOT2021 1:0@35..36#ROOT2021
315+
PUNCH ; [joint] 0:0@41..42#ROOT2021
316+
SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021
317+
IDENT future 1:0@42..48#ROOT2021
318+
PUNCH . [alone] 1:0@48..49#ROOT2021
319+
IDENT await 1:0@49..54#ROOT2021
320+
PUNCH ; [joint] 0:0@41..42#ROOT2021
321+
SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021
322+
IDENT break 1:0@60..65#ROOT2021
323+
PUNCH ' [joint] 1:0@66..67#ROOT2021
324+
IDENT foo 1:0@67..70#ROOT2021
325+
IDENT bar 1:0@71..74#ROOT2021
326+
PUNCH ; [alone] 0:0@44..45#ROOT2021
327327
328328
4;
329329
"literal";
@@ -345,13 +345,13 @@ fn expr_2021() {
345345
expect![[r#"
346346
ExpandError {
347347
inner: (
348-
1:0@5..6#4294967037,
348+
1:0@5..6#ROOT2021,
349349
NoMatchingRule,
350350
),
351351
}
352352
353-
SUBTREE $$ 1:0@0..8#4294967037 1:0@0..8#4294967037
354-
PUNCH ; [alone] 0:0@44..45#4294967037
353+
SUBTREE $$ 1:0@0..8#ROOT2021 1:0@0..8#ROOT2021
354+
PUNCH ; [alone] 0:0@44..45#ROOT2021
355355
356356
;"#]],
357357
);

0 commit comments

Comments
 (0)