Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19355 from Veykril/push-nzknrnouutnp
internal: Render root syntax contexts more clearly
Lukas Wirth 2025-03-17
parent f443ba0 · parent a06aadb · commit 23e8d13
-rw-r--r--crates/edition/src/lib.rs9
-rw-r--r--crates/hir-def/src/item_tree/tests.rs2
-rw-r--r--crates/hir-def/src/macro_expansion_tests/mbe.rs22
-rw-r--r--crates/hir-def/src/macro_expansion_tests/proc_macros.rs6
-rw-r--r--crates/hir-expand/src/builtin/quote.rs4
-rw-r--r--crates/hir-expand/src/proc_macro.rs6
-rw-r--r--crates/intern/src/symbol.rs14
-rw-r--r--crates/mbe/src/tests.rs160
-rw-r--r--crates/proc-macro-srv/src/tests/mod.rs130
-rw-r--r--crates/span/src/hygiene.rs8
10 files changed, 182 insertions, 179 deletions
diff --git a/crates/edition/src/lib.rs b/crates/edition/src/lib.rs
index a2269bf54d..04e65fc378 100644
--- a/crates/edition/src/lib.rs
+++ b/crates/edition/src/lib.rs
@@ -41,6 +41,15 @@ impl Edition {
self >= Edition::Edition2018
}
+ pub fn number(&self) -> usize {
+ match self {
+ Edition::Edition2015 => 2015,
+ Edition::Edition2018 => 2018,
+ Edition::Edition2021 => 2021,
+ Edition::Edition2024 => 2024,
+ }
+ }
+
pub fn iter() -> impl Iterator<Item = Edition> {
[Edition::Edition2015, Edition::Edition2018, Edition::Edition2021, Edition::Edition2024]
.iter()
diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs
index 47d374a2be..0651a5ed55 100644
--- a/crates/hir-def/src/item_tree/tests.rs
+++ b/crates/hir-def/src/item_tree/tests.rs
@@ -270,7 +270,7 @@ m!();
// AstId: 2
pub macro m2 { ... }
- // AstId: 3, SyntaxContextId: 4294967037, ExpandTo: Items
+ // AstId: 3, SyntaxContextId: ROOT2021, ExpandTo: Items
m!(...);
"#]],
);
diff --git a/crates/hir-def/src/macro_expansion_tests/mbe.rs b/crates/hir-def/src/macro_expansion_tests/mbe.rs
index 66e344d724..bf0902a7e5 100644
--- a/crates/hir-def/src/macro_expansion_tests/mbe.rs
+++ b/crates/hir-def/src/macro_expansion_tests/mbe.rs
@@ -35,7 +35,7 @@ macro_rules! f {
};
}
-struct#0:[email protected]#20480# MyTraitMap2#0:[email protected]#4294967037# {#0:[email protected]#20480#
+struct#0:[email protected]#20480# MyTraitMap2#0:[email protected]#ROOT2021# {#0:[email protected]#20480#
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#
}#0:[email protected]#20480#
"#]],
@@ -75,12 +75,12 @@ macro_rules! f {
};
}
-fn#0:[email protected]#4294967037# main#0:[email protected]#4294967037#(#0:[email protected]#4294967037#)#0:[email protected]#4294967037# {#0:[email protected]#4294967037#
- 1#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
- 1.0#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
- (#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#
- let#0:[email protected]#4294967037# x#0:[email protected]#4294967037# =#0:[email protected]#4294967037# 1#0:[email protected]#4294967037#;#0:[email protected]#4294967037#
-}#0:[email protected]#4294967037#
+fn#0:[email protected]#ROOT2021# main#0:[email protected]#ROOT2021#(#0:[email protected]#ROOT2021#)#0:[email protected]#ROOT2021# {#0:[email protected]#ROOT2021#
+ 1#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
+ 1.0#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
+ (#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#
+ let#0:[email protected]#ROOT2021# x#0:[email protected]#ROOT2021# =#0:[email protected]#ROOT2021# 1#0:[email protected]#ROOT2021#;#0:[email protected]#ROOT2021#
+}#0:[email protected]#ROOT2021#
"#]],
@@ -171,7 +171,7 @@ fn main(foo: ()) {
}
fn main(foo: ()) {
- /* error: unresolved macro unresolved */"helloworld!"#0:[email protected]#4294967037#;
+ /* error: unresolved macro unresolved */"helloworld!"#0:[email protected]#ROOT2021#;
}
}
@@ -197,7 +197,7 @@ macro_rules! mk_struct {
#[macro_use]
mod foo;
-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#
+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#
"#]],
);
}
@@ -424,8 +424,8 @@ macro_rules! m {
($($i:ident),*) => ( impl Bar { $(fn $i() {})* } );
}
impl#\20480# Bar#\20480# {#\20480#
- fn#\20480# foo#\4294967037#(#\20480#)#\20480# {#\20480#}#\20480#
- fn#\20480# bar#\4294967037#(#\20480#)#\20480# {#\20480#}#\20480#
+ fn#\20480# foo#\ROOT2021#(#\20480#)#\20480# {#\20480#}#\20480#
+ fn#\20480# bar#\ROOT2021#(#\20480#)#\20480# {#\20480#}#\20480#
}#\20480#
"#]],
);
diff --git a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
index 650807fb4a..3009b72499 100644
--- a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
+++ b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
@@ -181,9 +181,9 @@ fn foo(&self) {
self.0. 1;
}
-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#
- 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#
-}#0:[email protected]#4294967037#"#]],
+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#
+ 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#
+}#0:[email protected]#ROOT2021#"#]],
);
}
diff --git a/crates/hir-expand/src/builtin/quote.rs b/crates/hir-expand/src/builtin/quote.rs
index 859f6f7b14..7e159d999d 100644
--- a/crates/hir-expand/src/builtin/quote.rs
+++ b/crates/hir-expand/src/builtin/quote.rs
@@ -277,8 +277,8 @@ mod tests {
assert_eq!(quoted.to_string(), "hello");
let t = format!("{quoted:#?}");
expect![[r#"
- SUBTREE $$ 937550:[email protected]#4294967037 937550:[email protected]#4294967037
- IDENT hello 937550:[email protected]#4294967037"#]]
+ SUBTREE $$ 937550:[email protected]#ROOT2021 937550:[email protected]#ROOT2021
+ IDENT hello 937550:[email protected]#ROOT2021"#]]
.assert_eq(&t);
}
diff --git a/crates/hir-expand/src/proc_macro.rs b/crates/hir-expand/src/proc_macro.rs
index 9dcd5ef1ef..ceb6972a50 100644
--- a/crates/hir-expand/src/proc_macro.rs
+++ b/crates/hir-expand/src/proc_macro.rs
@@ -78,8 +78,10 @@ impl ProcMacrosBuilder {
if let Ok(proc_macros) = &mut proc_macro {
// Sort proc macros to improve incrementality when only their order has changed (ideally the build system
// will not change their order, but just to be sure).
- proc_macros
- .sort_unstable_by_key(|proc_macro| (proc_macro.name.clone(), proc_macro.kind));
+ proc_macros.sort_unstable_by(|proc_macro, proc_macro2| {
+ (proc_macro.name.as_str(), proc_macro.kind)
+ .cmp(&(proc_macro2.name.as_str(), proc_macro2.kind))
+ });
}
self.0.insert(
proc_macros_crate,
diff --git a/crates/intern/src/symbol.rs b/crates/intern/src/symbol.rs
index f02fb6d14f..22490e416a 100644
--- a/crates/intern/src/symbol.rs
+++ b/crates/intern/src/symbol.rs
@@ -42,18 +42,6 @@ struct TaggedArcPtr {
unsafe impl Send for TaggedArcPtr {}
unsafe impl Sync for TaggedArcPtr {}
-impl Ord for TaggedArcPtr {
- fn cmp(&self, other: &Self) -> std::cmp::Ordering {
- self.as_str().cmp(other.as_str())
- }
-}
-
-impl PartialOrd for TaggedArcPtr {
- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- Some(self.cmp(other))
- }
-}
-
impl TaggedArcPtr {
const BOOL_BITS: usize = true as usize;
@@ -125,7 +113,7 @@ impl TaggedArcPtr {
}
}
-#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[derive(PartialEq, Eq, Hash)]
pub struct Symbol {
repr: TaggedArcPtr,
}
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs
index 7d9538a4b4..763ec14052 100644
--- a/crates/mbe/src/tests.rs
+++ b/crates/mbe/src/tests.rs
@@ -109,8 +109,8 @@ fn unbalanced_brace() {
"#,
r#""#,
expect![[r#"
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- SUBTREE {} 0:[email protected]#4294967037 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ SUBTREE {} 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
{}"#]],
);
@@ -132,25 +132,25 @@ fn token_mapping_smoke_test() {
struct MyTraitMap2
"#,
expect![[r#"
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- IDENT struct 0:[email protected]#4294967037
- IDENT MyTraitMap2 1:[email protected]#4294967037
- SUBTREE {} 0:[email protected]#4294967037 0:[email protected]#4294967037
- IDENT map 0:[email protected]#4294967037
- PUNCH : [alone] 0:[email protected]#4294967037
- PUNCH : [joint] 0:[email protected]#4294967037
- PUNCH : [alone] 0:[email protected]#4294967037
- IDENT std 0:[email protected]#4294967037
- PUNCH : [joint] 0:[email protected]#4294967037
- PUNCH : [alone] 0:[email protected]#4294967037
- IDENT collections 0:[email protected]#4294967037
- PUNCH : [joint] 0:[email protected]#4294967037
- PUNCH : [alone] 0:[email protected]#4294967037
- IDENT HashSet 0:[email protected]#4294967037
- PUNCH < [alone] 0:[email protected]#4294967037
- SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
- PUNCH > [joint] 0:[email protected]#4294967037
- PUNCH , [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ IDENT struct 0:[email protected]#ROOT2021
+ IDENT MyTraitMap2 1:[email protected]#ROOT2021
+ SUBTREE {} 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ IDENT map 0:[email protected]#ROOT2021
+ PUNCH : [alone] 0:[email protected]#ROOT2021
+ PUNCH : [joint] 0:[email protected]#ROOT2021
+ PUNCH : [alone] 0:[email protected]#ROOT2021
+ IDENT std 0:[email protected]#ROOT2021
+ PUNCH : [joint] 0:[email protected]#ROOT2021
+ PUNCH : [alone] 0:[email protected]#ROOT2021
+ IDENT collections 0:[email protected]#ROOT2021
+ PUNCH : [joint] 0:[email protected]#ROOT2021
+ PUNCH : [alone] 0:[email protected]#ROOT2021
+ IDENT HashSet 0:[email protected]#ROOT2021
+ PUNCH < [alone] 0:[email protected]#ROOT2021
+ SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ PUNCH > [joint] 0:[email protected]#ROOT2021
+ PUNCH , [alone] 0:[email protected]#ROOT2021
struct MyTraitMap2 {
map: ::std::collections::HashSet<()>,
@@ -179,28 +179,28 @@ fn main() {
}
"#,
expect![[r#"
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- IDENT fn 1:[email protected]#4294967037
- IDENT main 1:[email protected]#4294967037
- SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
- SUBTREE {} 1:[email protected]#4294967037 1:[email protected]#4294967037
- LITERAL Integer 1 1:[email protected]#4294967037
- PUNCH ; [alone] 1:[email protected]#4294967037
- LITERAL Float 1.0 1:[email protected]#4294967037
- PUNCH ; [alone] 1:[email protected]#4294967037
- SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
- SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
- LITERAL Integer 1 1:[email protected]#4294967037
- PUNCH , [alone] 1:[email protected]#4294967037
- PUNCH , [alone] 1:[email protected]#4294967037
- PUNCH . [alone] 1:[email protected]#4294967037
- LITERAL Float 0.0 1:[email protected]#4294967037
- PUNCH ; [alone] 1:[email protected]#4294967037
- IDENT let 1:[email protected]#4294967037
- IDENT x 1:[email protected]#4294967037
- PUNCH = [alone] 1:[email protected]#4294967037
- LITERAL Integer 1 1:[email protected]#4294967037
- PUNCH ; [alone] 1:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ IDENT fn 1:[email protected]#ROOT2021
+ IDENT main 1:[email protected]#ROOT2021
+ SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ SUBTREE {} 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ LITERAL Integer 1 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 1:[email protected]#ROOT2021
+ LITERAL Float 1.0 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 1:[email protected]#ROOT2021
+ SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ LITERAL Integer 1 1:[email protected]#ROOT2021
+ PUNCH , [alone] 1:[email protected]#ROOT2021
+ PUNCH , [alone] 1:[email protected]#ROOT2021
+ PUNCH . [alone] 1:[email protected]#ROOT2021
+ LITERAL Float 0.0 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 1:[email protected]#ROOT2021
+ IDENT let 1:[email protected]#ROOT2021
+ IDENT x 1:[email protected]#ROOT2021
+ PUNCH = [alone] 1:[email protected]#ROOT2021
+ LITERAL Integer 1 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 1:[email protected]#ROOT2021
fn main(){
1;
@@ -226,14 +226,14 @@ fn expr_2021() {
const { 1 },
"#,
expect![[r#"
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- IDENT _ 1:[email protected]#4294967037
- PUNCH ; [joint] 0:[email protected]#4294967037
- SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
- IDENT const 1:[email protected]#4294967037
- SUBTREE {} 1:[email protected]#4294967037 1:[email protected]#4294967037
- LITERAL Integer 1 1:[email protected]#4294967037
- PUNCH ; [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ IDENT _ 1:[email protected]#ROOT2021
+ PUNCH ; [joint] 0:[email protected]#ROOT2021
+ SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ IDENT const 1:[email protected]#ROOT2021
+ SUBTREE {} 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ LITERAL Integer 1 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 0:[email protected]#ROOT2021
_;
(const {
@@ -254,13 +254,13 @@ fn expr_2021() {
expect![[r#"
ExpandError {
inner: (
- 1:[email protected]#4294967037,
+ 1:[email protected]#ROOT2021,
NoMatchingRule,
),
}
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- PUNCH ; [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 0:[email protected]#ROOT2021
;"#]],
);
@@ -278,13 +278,13 @@ fn expr_2021() {
expect![[r#"
ExpandError {
inner: (
- 1:[email protected]#4294967037,
+ 1:[email protected]#ROOT2021,
NoMatchingRule,
),
}
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- PUNCH ; [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 0:[email protected]#ROOT2021
;"#]],
);
@@ -304,26 +304,26 @@ fn expr_2021() {
break 'foo bar,
"#,
expect![[r#"
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- LITERAL Integer 4 1:[email protected]#4294967037
- PUNCH ; [joint] 0:[email protected]#4294967037
- LITERAL Str literal 1:[email protected]#4294967037
- PUNCH ; [joint] 0:[email protected]#4294967037
- SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
- IDENT funcall 1:[email protected]#4294967037
- SUBTREE () 1:[email protected]#4294967037 1:[email protected]#4294967037
- PUNCH ; [joint] 0:[email protected]#4294967037
- SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
- IDENT future 1:[email protected]#4294967037
- PUNCH . [alone] 1:[email protected]#4294967037
- IDENT await 1:[email protected]#4294967037
- PUNCH ; [joint] 0:[email protected]#4294967037
- SUBTREE () 0:[email protected]#4294967037 0:[email protected]#4294967037
- IDENT break 1:[email protected]#4294967037
- PUNCH ' [joint] 1:[email protected]#4294967037
- IDENT foo 1:[email protected]#4294967037
- IDENT bar 1:[email protected]#4294967037
- PUNCH ; [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ LITERAL Integer 4 1:[email protected]#ROOT2021
+ PUNCH ; [joint] 0:[email protected]#ROOT2021
+ LITERAL Str literal 1:[email protected]#ROOT2021
+ PUNCH ; [joint] 0:[email protected]#ROOT2021
+ SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ IDENT funcall 1:[email protected]#ROOT2021
+ SUBTREE () 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ PUNCH ; [joint] 0:[email protected]#ROOT2021
+ SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ IDENT future 1:[email protected]#ROOT2021
+ PUNCH . [alone] 1:[email protected]#ROOT2021
+ IDENT await 1:[email protected]#ROOT2021
+ PUNCH ; [joint] 0:[email protected]#ROOT2021
+ SUBTREE () 0:[email protected]#ROOT2021 0:[email protected]#ROOT2021
+ IDENT break 1:[email protected]#ROOT2021
+ PUNCH ' [joint] 1:[email protected]#ROOT2021
+ IDENT foo 1:[email protected]#ROOT2021
+ IDENT bar 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 0:[email protected]#ROOT2021
4;
"literal";
@@ -345,13 +345,13 @@ fn expr_2021() {
expect![[r#"
ExpandError {
inner: (
- 1:[email protected]#4294967037,
+ 1:[email protected]#ROOT2021,
NoMatchingRule,
),
}
- SUBTREE $$ 1:[email protected]#4294967037 1:[email protected]#4294967037
- PUNCH ; [alone] 0:[email protected]#4294967037
+ SUBTREE $$ 1:[email protected]#ROOT2021 1:[email protected]#ROOT2021
+ PUNCH ; [alone] 0:[email protected]#ROOT2021
;"#]],
);
diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs
index 716d351271..b2ffa4ca80 100644
--- a/crates/proc-macro-srv/src/tests/mod.rs
+++ b/crates/proc-macro-srv/src/tests/mod.rs
@@ -12,7 +12,7 @@ fn test_derive_empty() {
"DeriveEmpty",
r#"struct S;"#,
expect!["SUBTREE $$ 1 1"],
- expect!["SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037"],
+ expect!["SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021"],
);
}
@@ -29,12 +29,12 @@ fn test_derive_error() {
LITERAL Str #[derive(DeriveError)] struct S ; 1
PUNCH ; [alone] 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT compile_error 42:[email protected]#4294967037
- PUNCH ! [alone] 42:[email protected]#4294967037
- SUBTREE () 42:[email protected]#4294967037 42:[email protected]#4294967037
- LITERAL Str #[derive(DeriveError)] struct S ; 42:[email protected]#4294967037
- PUNCH ; [alone] 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT compile_error 42:[email protected]#ROOT2021
+ PUNCH ! [alone] 42:[email protected]#ROOT2021
+ SUBTREE () 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ LITERAL Str #[derive(DeriveError)] struct S ; 42:[email protected]#ROOT2021
+ PUNCH ; [alone] 42:[email protected]#ROOT2021"#]],
);
}
@@ -53,14 +53,14 @@ fn test_fn_like_macro_noop() {
PUNCH , [alone] 1
SUBTREE [] 1 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT ident 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Integer 0 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Integer 1 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- SUBTREE [] 42:[email protected]#4294967037 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT ident 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Integer 0 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Integer 1 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ SUBTREE [] 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021"#]],
);
}
@@ -75,10 +75,10 @@ fn test_fn_like_macro_clone_ident_subtree() {
PUNCH , [alone] 1
SUBTREE [] 1 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT ident 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- SUBTREE [] 42:[email protected]#4294967037 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT ident 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ SUBTREE [] 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021"#]],
);
}
@@ -91,8 +91,8 @@ fn test_fn_like_macro_clone_raw_ident() {
SUBTREE $$ 1 1
IDENT r#async 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT r#async 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT r#async 42:[email protected]#ROOT2021"#]],
);
}
@@ -105,8 +105,8 @@ fn test_fn_like_fn_like_span_join() {
SUBTREE $$ 1 1
IDENT r#joined 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT r#joined 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT r#joined 42:[email protected]#ROOT2021"#]],
);
}
@@ -121,10 +121,10 @@ fn test_fn_like_fn_like_span_ops() {
IDENT resolved_at_def_site 1
IDENT start_span 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT set_def_site 41:[email protected]#4294967037
- IDENT resolved_at_def_site 42:[email protected]#4294967037
- IDENT start_span 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT set_def_site 41:[email protected]#ROOT2021
+ IDENT resolved_at_def_site 42:[email protected]#ROOT2021
+ IDENT start_span 42:[email protected]#ROOT2021"#]],
);
}
@@ -143,14 +143,14 @@ fn test_fn_like_mk_literals() {
LITERAL Integer 123i64 1
LITERAL Integer 123 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- LITERAL ByteStr byte_string 42:[email protected]#4294967037
- LITERAL Char c 42:[email protected]#4294967037
- LITERAL Str string 42:[email protected]#4294967037
- LITERAL Float 3.14f64 42:[email protected]#4294967037
- LITERAL Float 3.14 42:[email protected]#4294967037
- LITERAL Integer 123i64 42:[email protected]#4294967037
- LITERAL Integer 123 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ LITERAL ByteStr byte_string 42:[email protected]#ROOT2021
+ LITERAL Char c 42:[email protected]#ROOT2021
+ LITERAL Str string 42:[email protected]#ROOT2021
+ LITERAL Float 3.14f64 42:[email protected]#ROOT2021
+ LITERAL Float 3.14 42:[email protected]#ROOT2021
+ LITERAL Integer 123i64 42:[email protected]#ROOT2021
+ LITERAL Integer 123 42:[email protected]#ROOT2021"#]],
);
}
@@ -164,9 +164,9 @@ fn test_fn_like_mk_idents() {
IDENT standard 1
IDENT r#raw 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT standard 42:[email protected]#4294967037
- IDENT r#raw 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT standard 42:[email protected]#ROOT2021
+ IDENT r#raw 42:[email protected]#ROOT2021"#]],
);
}
@@ -198,27 +198,27 @@ fn test_fn_like_macro_clone_literals() {
PUNCH , [alone] 1
LITERAL CStr null 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- LITERAL Integer 1u16 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Integer 2_u32 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- PUNCH - [alone] 42:[email protected]#4294967037
- LITERAL Integer 4i64 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Float 3.14f32 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Str hello bridge 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Str suffixedsuffix 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL StrRaw(2) raw 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Char a 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL Byte b 42:[email protected]#4294967037
- PUNCH , [alone] 42:[email protected]#4294967037
- LITERAL CStr null 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ LITERAL Integer 1u16 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Integer 2_u32 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ PUNCH - [alone] 42:[email protected]#ROOT2021
+ LITERAL Integer 4i64 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Float 3.14f32 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Str hello bridge 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Str suffixedsuffix 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL StrRaw(2) raw 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Char a 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL Byte b 42:[email protected]#ROOT2021
+ PUNCH , [alone] 42:[email protected]#ROOT2021
+ LITERAL CStr null 42:[email protected]#ROOT2021"#]],
);
}
@@ -239,12 +239,12 @@ fn test_attr_macro() {
LITERAL Str #[attr_error(some arguments)] mod m {} 1
PUNCH ; [alone] 1"#]],
expect![[r#"
- SUBTREE $$ 42:[email protected]#4294967037 42:[email protected]#4294967037
- IDENT compile_error 42:[email protected]#4294967037
- PUNCH ! [alone] 42:[email protected]#4294967037
- SUBTREE () 42:[email protected]#4294967037 42:[email protected]#4294967037
- LITERAL Str #[attr_error(some arguments)] mod m {} 42:[email protected]#4294967037
- PUNCH ; [alone] 42:[email protected]#4294967037"#]],
+ SUBTREE $$ 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ IDENT compile_error 42:[email protected]#ROOT2021
+ PUNCH ! [alone] 42:[email protected]#ROOT2021
+ SUBTREE () 42:[email protected]#ROOT2021 42:[email protected]#ROOT2021
+ LITERAL Str #[attr_error(some arguments)] mod m {} 42:[email protected]#ROOT2021
+ PUNCH ; [alone] 42:[email protected]#ROOT2021"#]],
);
}
diff --git a/crates/span/src/hygiene.rs b/crates/span/src/hygiene.rs
index 7cb1676a29..9ecd188a3c 100644
--- a/crates/span/src/hygiene.rs
+++ b/crates/span/src/hygiene.rs
@@ -353,14 +353,18 @@ impl Transparency {
impl fmt::Display for SyntaxContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.0.as_u32())
+ if self.is_root() {
+ write!(f, "ROOT{}", Edition::from_u32(SyntaxContext::MAX_ID - self.0.as_u32()).number())
+ } else {
+ write!(f, "{}", self.0.as_u32())
+ }
}
}
impl std::fmt::Debug for SyntaxContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if f.alternate() {
- write!(f, "{}", self.0.as_u32())
+ fmt::Display::fmt(self, f)
} else {
f.debug_tuple("SyntaxContext").field(&self.0).finish()
}