Skip to content

Commit 23e8d13

Browse files
authored
Merge pull request #19355 from Veykril/push-nzknrnouutnp
internal: Render root syntax contexts more clearly
2 parents f443ba0 + a06aadb commit 23e8d13

File tree

10 files changed

+182
-179
lines changed

10 files changed

+182
-179
lines changed

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()

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
);

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:[email protected]#20480# MyTraitMap2#0:[email protected]#4294967037# {#0:[email protected]#20480#
38+
struct#0:[email protected]#20480# MyTraitMap2#0:[email protected]#ROOT2021# {#0:[email protected]#20480#
3939
map#0:[email protected]#20480#:#0:[email protected]#20480# #0:[email protected]#20480#::#0:[email protected]#20480#std#0:[email protected]#20480#::#0:[email protected]#20480#collections#0:[email protected]#20480#::#0:[email protected]#20480#HashSet#0:[email protected]#20480#<#0:[email protected]#20480#(#0:[email protected]#20480#)#0:[email protected]#20480#>#0:[email protected]#20480#,#0:[email protected]#20480#
4040
4141
"#]],
@@ -75,12 +75,12 @@ macro_rules! f {
7575
};
7676
}
7777
78-
fn#0:[email protected]#4294967037# main#0:[email protected]#4294967037#(#0:[email protected]#4294967037#)#0:[email protected]#4294967037# {#0:[email protected]#4294967037#
79-
1#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
80-
1.0#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
81-
(#0:[email protected]#4294967037#(#0:[email protected]#4294967037#1#0:[email protected]#4294967037#,#0:[email protected]#4294967037# )#0:[email protected]#4294967037#,#0:[email protected]#4294967037# )#0:[email protected]#4294967037#.#0:[email protected]#4294967037#0#0:[email protected]#4294967037#.#0:[email protected]#4294967037#0#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
82-
let#0:[email protected]#4294967037# x#0:[email protected]#4294967037# =#0:[email protected]#4294967037# 1#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
83-
}#0:[email protected]#4294967037#
78+
fn#0:[email protected]#ROOT2021# main#0:[email protected]#ROOT2021#(#0:[email protected]#ROOT2021#)#0:[email protected]#ROOT2021# {#0:[email protected]#ROOT2021#
79+
1#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
80+
1.0#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
81+
(#0:[email protected]#ROOT2021#(#0:[email protected]#ROOT2021#1#0:[email protected]#ROOT2021#,#0:[email protected]#ROOT2021# )#0:[email protected]#ROOT2021#,#0:[email protected]#ROOT2021# )#0:[email protected]#ROOT2021#.#0:[email protected]#ROOT2021#0#0:[email protected]#ROOT2021#.#0:[email protected]#ROOT2021#0#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
82+
let#0:[email protected]#ROOT2021# x#0:[email protected]#ROOT2021# =#0:[email protected]#ROOT2021# 1#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
83+
}#0:[email protected]#ROOT2021#
8484
8585
8686
"#]],
@@ -171,7 +171,7 @@ fn main(foo: ()) {
171171
}
172172
173173
fn main(foo: ()) {
174-
/* error: unresolved macro unresolved */"helloworld!"#0:[email protected]#4294967037#;
174+
/* error: unresolved macro unresolved */"helloworld!"#0:[email protected]#ROOT2021#;
175175
}
176176
}
177177
@@ -197,7 +197,7 @@ macro_rules! mk_struct {
197197
#[macro_use]
198198
mod foo;
199199
200-
struct#1:[email protected]#20480# Foo#0:[email protected]#4294967037#(#1:[email protected]#20480#u32#0:[email protected]#4294967037#)#1:[email protected]#20480#;#1:[email protected]#20480#
200+
struct#1:[email protected]#20480# Foo#0:[email protected]#ROOT2021#(#1:[email protected]#20480#u32#0:[email protected]#ROOT2021#)#1:[email protected]#20480#;#1:[email protected]#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
);

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:[email protected]#4294967037# foo#0:[email protected]#4294967037#(#0:[email protected]#4294967037#&#0:[email protected]#4294967037#self#0:[email protected]#4294967037# )#0:[email protected]#4294967037# {#0:[email protected]#4294967037#
185-
self#0:[email protected]#4294967037# .#0:[email protected]#4294967037#0#0:[email protected]#4294967037#.#0:[email protected]#4294967037#1#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
186-
}#0:[email protected]#4294967037#"#]],
184+
fn#0:[email protected]#ROOT2021# foo#0:[email protected]#ROOT2021#(#0:[email protected]#ROOT2021#&#0:[email protected]#ROOT2021#self#0:[email protected]#ROOT2021# )#0:[email protected]#ROOT2021# {#0:[email protected]#ROOT2021#
185+
self#0:[email protected]#ROOT2021# .#0:[email protected]#ROOT2021#0#0:[email protected]#ROOT2021#.#0:[email protected]#ROOT2021#1#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
186+
}#0:[email protected]#ROOT2021#"#]],
187187
);
188188
}
189189

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:[email protected]#4294967037 937550:[email protected]#4294967037
281-
IDENT hello 937550:[email protected]#4294967037"#]]
280+
SUBTREE $$ 937550:[email protected]#ROOT2021 937550:[email protected]#ROOT2021
281+
IDENT hello 937550:[email protected]#ROOT2021"#]]
282282
.assert_eq(&t);
283283
}
284284

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,

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
}

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:[email protected]#4294967037 1:[email protected]#4294967037
113-
SUBTREE {} 0:[email protected]#4294967037 0:[email protected]#4294967037
112+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
113+
SUBTREE {} 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
114114
115115
{}"#]],
116116
);
@@ -132,25 +132,25 @@ fn token_mapping_smoke_test() {
132132
struct MyTraitMap2
133133
"#,
134134
expect![[r#"
135-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
136-
IDENT struct 0:[email protected]#4294967037
137-
IDENT MyTraitMap2 1:[email protected]#4294967037
138-
SUBTREE {} 0:[email protected]#4294967037 0:[email protected]#4294967037
139-
IDENT map 0:[email protected]#4294967037
140-
PUNCH : [alone] 0:[email protected]#4294967037
141-
PUNCH : [joint] 0:[email protected]#4294967037
142-
PUNCH : [alone] 0:[email protected]#4294967037
143-
IDENT std 0:[email protected]#4294967037
144-
PUNCH : [joint] 0:[email protected]#4294967037
145-
PUNCH : [alone] 0:[email protected]#4294967037
146-
IDENT collections 0:[email protected]#4294967037
147-
PUNCH : [joint] 0:[email protected]#4294967037
148-
PUNCH : [alone] 0:[email protected]#4294967037
149-
IDENT HashSet 0:[email protected]#4294967037
150-
PUNCH < [alone] 0:[email protected]#4294967037
151-
SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
152-
PUNCH > [joint] 0:[email protected]#4294967037
153-
PUNCH , [alone] 0:[email protected]#4294967037
135+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
136+
IDENT struct 0:[email protected]#ROOT2021
137+
IDENT MyTraitMap2 1:[email protected]#ROOT2021
138+
SUBTREE {} 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
139+
IDENT map 0:[email protected]#ROOT2021
140+
PUNCH : [alone] 0:[email protected]#ROOT2021
141+
PUNCH : [joint] 0:[email protected]#ROOT2021
142+
PUNCH : [alone] 0:[email protected]#ROOT2021
143+
IDENT std 0:[email protected]#ROOT2021
144+
PUNCH : [joint] 0:[email protected]#ROOT2021
145+
PUNCH : [alone] 0:[email protected]#ROOT2021
146+
IDENT collections 0:[email protected]#ROOT2021
147+
PUNCH : [joint] 0:[email protected]#ROOT2021
148+
PUNCH : [alone] 0:[email protected]#ROOT2021
149+
IDENT HashSet 0:[email protected]#ROOT2021
150+
PUNCH < [alone] 0:[email protected]#ROOT2021
151+
SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
152+
PUNCH > [joint] 0:[email protected]#ROOT2021
153+
PUNCH , [alone] 0:[email protected]#ROOT2021
154154
155155
struct MyTraitMap2 {
156156
map: ::std::collections::HashSet<()>,
@@ -179,28 +179,28 @@ fn main() {
179179
}
180180
"#,
181181
expect![[r#"
182-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
183-
IDENT fn 1:[email protected]#4294967037
184-
IDENT main 1:[email protected]#4294967037
185-
SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
186-
SUBTREE {} 1:[email protected]#4294967037 1:[email protected]#4294967037
187-
LITERAL Integer 1 1:[email protected]#4294967037
188-
PUNCH ; [alone] 1:[email protected]#4294967037
189-
LITERAL Float 1.0 1:[email protected]#4294967037
190-
PUNCH ; [alone] 1:[email protected]#4294967037
191-
SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
192-
SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
193-
LITERAL Integer 1 1:[email protected]#4294967037
194-
PUNCH , [alone] 1:[email protected]#4294967037
195-
PUNCH , [alone] 1:[email protected]#4294967037
196-
PUNCH . [alone] 1:[email protected]#4294967037
197-
LITERAL Float 0.0 1:[email protected]#4294967037
198-
PUNCH ; [alone] 1:[email protected]#4294967037
199-
IDENT let 1:[email protected]#4294967037
200-
IDENT x 1:[email protected]#4294967037
201-
PUNCH = [alone] 1:[email protected]#4294967037
202-
LITERAL Integer 1 1:[email protected]#4294967037
203-
PUNCH ; [alone] 1:[email protected]#4294967037
182+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
183+
IDENT fn 1:[email protected]#ROOT2021
184+
IDENT main 1:[email protected]#ROOT2021
185+
SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
186+
SUBTREE {} 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
187+
LITERAL Integer 1 1:[email protected]#ROOT2021
188+
PUNCH ; [alone] 1:[email protected]#ROOT2021
189+
LITERAL Float 1.0 1:[email protected]#ROOT2021
190+
PUNCH ; [alone] 1:[email protected]#ROOT2021
191+
SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
192+
SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
193+
LITERAL Integer 1 1:[email protected]#ROOT2021
194+
PUNCH , [alone] 1:[email protected]#ROOT2021
195+
PUNCH , [alone] 1:[email protected]#ROOT2021
196+
PUNCH . [alone] 1:[email protected]#ROOT2021
197+
LITERAL Float 0.0 1:[email protected]#ROOT2021
198+
PUNCH ; [alone] 1:[email protected]#ROOT2021
199+
IDENT let 1:[email protected]#ROOT2021
200+
IDENT x 1:[email protected]#ROOT2021
201+
PUNCH = [alone] 1:[email protected]#ROOT2021
202+
LITERAL Integer 1 1:[email protected]#ROOT2021
203+
PUNCH ; [alone] 1:[email protected]#ROOT2021
204204
205205
fn main(){
206206
1;
@@ -226,14 +226,14 @@ fn expr_2021() {
226226
const { 1 },
227227
"#,
228228
expect![[r#"
229-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
230-
IDENT _ 1:[email protected]#4294967037
231-
PUNCH ; [joint] 0:[email protected]#4294967037
232-
SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
233-
IDENT const 1:[email protected]#4294967037
234-
SUBTREE {} 1:[email protected]#4294967037 1:[email protected]#4294967037
235-
LITERAL Integer 1 1:[email protected]#4294967037
236-
PUNCH ; [alone] 0:[email protected]#4294967037
229+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
230+
IDENT _ 1:[email protected]#ROOT2021
231+
PUNCH ; [joint] 0:[email protected]#ROOT2021
232+
SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
233+
IDENT const 1:[email protected]#ROOT2021
234+
SUBTREE {} 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
235+
LITERAL Integer 1 1:[email protected]#ROOT2021
236+
PUNCH ; [alone] 0:[email protected]#ROOT2021
237237
238238
_;
239239
(const {
@@ -254,13 +254,13 @@ fn expr_2021() {
254254
expect![[r#"
255255
ExpandError {
256256
inner: (
257-
1:[email protected]#4294967037,
257+
1:[email protected]#ROOT2021,
258258
NoMatchingRule,
259259
),
260260
}
261261
262-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
263-
PUNCH ; [alone] 0:[email protected]#4294967037
262+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
263+
PUNCH ; [alone] 0:[email protected]#ROOT2021
264264
265265
;"#]],
266266
);
@@ -278,13 +278,13 @@ fn expr_2021() {
278278
expect![[r#"
279279
ExpandError {
280280
inner: (
281-
1:[email protected]#4294967037,
281+
1:[email protected]#ROOT2021,
282282
NoMatchingRule,
283283
),
284284
}
285285
286-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
287-
PUNCH ; [alone] 0:[email protected]#4294967037
286+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
287+
PUNCH ; [alone] 0:[email protected]#ROOT2021
288288
289289
;"#]],
290290
);
@@ -304,26 +304,26 @@ fn expr_2021() {
304304
break 'foo bar,
305305
"#,
306306
expect![[r#"
307-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
308-
LITERAL Integer 4 1:[email protected]#4294967037
309-
PUNCH ; [joint] 0:[email protected]#4294967037
310-
LITERAL Str literal 1:[email protected]#4294967037
311-
PUNCH ; [joint] 0:[email protected]#4294967037
312-
SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
313-
IDENT funcall 1:[email protected]#4294967037
314-
SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
315-
PUNCH ; [joint] 0:[email protected]#4294967037
316-
SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
317-
IDENT future 1:[email protected]#4294967037
318-
PUNCH . [alone] 1:[email protected]#4294967037
319-
IDENT await 1:[email protected]#4294967037
320-
PUNCH ; [joint] 0:[email protected]#4294967037
321-
SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
322-
IDENT break 1:[email protected]#4294967037
323-
PUNCH ' [joint] 1:[email protected]#4294967037
324-
IDENT foo 1:[email protected]#4294967037
325-
IDENT bar 1:[email protected]#4294967037
326-
PUNCH ; [alone] 0:[email protected]#4294967037
307+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
308+
LITERAL Integer 4 1:[email protected]#ROOT2021
309+
PUNCH ; [joint] 0:[email protected]#ROOT2021
310+
LITERAL Str literal 1:[email protected]#ROOT2021
311+
PUNCH ; [joint] 0:[email protected]#ROOT2021
312+
SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
313+
IDENT funcall 1:[email protected]#ROOT2021
314+
SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
315+
PUNCH ; [joint] 0:[email protected]#ROOT2021
316+
SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
317+
IDENT future 1:[email protected]#ROOT2021
318+
PUNCH . [alone] 1:[email protected]#ROOT2021
319+
IDENT await 1:[email protected]#ROOT2021
320+
PUNCH ; [joint] 0:[email protected]#ROOT2021
321+
SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
322+
IDENT break 1:[email protected]#ROOT2021
323+
PUNCH ' [joint] 1:[email protected]#ROOT2021
324+
IDENT foo 1:[email protected]#ROOT2021
325+
IDENT bar 1:[email protected]#ROOT2021
326+
PUNCH ; [alone] 0:[email protected]#ROOT2021
327327
328328
4;
329329
"literal";
@@ -345,13 +345,13 @@ fn expr_2021() {
345345
expect![[r#"
346346
ExpandError {
347347
inner: (
348-
1:[email protected]#4294967037,
348+
1:[email protected]#ROOT2021,
349349
NoMatchingRule,
350350
),
351351
}
352352
353-
SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
354-
PUNCH ; [alone] 0:[email protected]#4294967037
353+
SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
354+
PUNCH ; [alone] 0:[email protected]#ROOT2021
355355
356356
;"#]],
357357
);

0 commit comments

Comments
 (0)