From c28b80c321d34e143074e5bac03b24b8545f2cb7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 14 Mar 2025 13:54:17 +0100 Subject: [PATCH 1/2] internal: `Symbol` is not `PartialOrd` --- crates/hir-expand/src/proc_macro.rs | 6 ++++-- crates/intern/src/symbol.rs | 14 +------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/crates/hir-expand/src/proc_macro.rs b/crates/hir-expand/src/proc_macro.rs index 9dcd5ef1ef03..ceb6972a50c3 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 f02fb6d14f17..22490e416a30 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 { - 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, } From a06aadb9f087a32dbd3523ccdcf766081ae28707 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 14 Mar 2025 13:54:17 +0100 Subject: [PATCH 2/2] internal: Render root syntax contexts more clearly --- crates/edition/src/lib.rs | 9 + crates/hir-def/src/item_tree/tests.rs | 2 +- .../hir-def/src/macro_expansion_tests/mbe.rs | 22 +-- .../src/macro_expansion_tests/proc_macros.rs | 6 +- crates/hir-expand/src/builtin/quote.rs | 4 +- crates/mbe/src/tests.rs | 160 +++++++++--------- crates/proc-macro-srv/src/tests/mod.rs | 130 +++++++------- crates/span/src/hygiene.rs | 8 +- 8 files changed, 177 insertions(+), 164 deletions(-) diff --git a/crates/edition/src/lib.rs b/crates/edition/src/lib.rs index a2269bf54d43..04e65fc378fc 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 { [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 47d374a2beee..0651a5ed5524 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 66e344d72452..bf0902a7e59d 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:1@58..64#20480# MyTraitMap2#0:2@31..42#4294967037# {#0:1@72..73#20480# +struct#0:1@58..64#20480# MyTraitMap2#0:2@31..42#ROOT2021# {#0:1@72..73#20480# 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# }#0:1@132..133#20480# "#]], @@ -75,12 +75,12 @@ macro_rules! f { }; } -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# - 1#0:2@50..51#4294967037#;#0:2@51..52#4294967037# - 1.0#0:2@61..64#4294967037#;#0:2@64..65#4294967037# - (#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# - 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# -}#0:2@110..111#4294967037# +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# + 1#0:2@50..51#ROOT2021#;#0:2@51..52#ROOT2021# + 1.0#0:2@61..64#ROOT2021#;#0:2@64..65#ROOT2021# + (#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# + 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# +}#0:2@110..111#ROOT2021# "#]], @@ -171,7 +171,7 @@ fn main(foo: ()) { } fn main(foo: ()) { - /* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#4294967037#; + /* error: unresolved macro unresolved */"helloworld!"#0:3@236..321#ROOT2021#; } } @@ -197,7 +197,7 @@ macro_rules! mk_struct { #[macro_use] mod foo; -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# +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# "#]], ); } @@ -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 650807fb4acf..3009b7249965 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:1@45..47#4294967037# foo#0:1@48..51#4294967037#(#0:1@51..52#4294967037#�:1@52..53#4294967037#self#0:1@53..57#4294967037# )#0:1@57..58#4294967037# {#0:1@59..60#4294967037# - 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# -}#0:1@76..77#4294967037#"#]], +fn#0:1@45..47#ROOT2021# foo#0:1@48..51#ROOT2021#(#0:1@51..52#ROOT2021#�:1@52..53#ROOT2021#self#0:1@53..57#ROOT2021# )#0:1@57..58#ROOT2021# {#0:1@59..60#ROOT2021# + 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# +}#0:1@76..77#ROOT2021#"#]], ); } diff --git a/crates/hir-expand/src/builtin/quote.rs b/crates/hir-expand/src/builtin/quote.rs index 859f6f7b1449..7e159d999ddf 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:0@0..0#4294967037 937550:0@0..0#4294967037 - IDENT hello 937550:0@0..0#4294967037"#]] + SUBTREE $$ 937550:0@0..0#ROOT2021 937550:0@0..0#ROOT2021 + IDENT hello 937550:0@0..0#ROOT2021"#]] .assert_eq(&t); } diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 7d9538a4b4dd..763ec1405260 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:0@0..0#4294967037 1:0@0..0#4294967037 - SUBTREE {} 0:0@9..10#4294967037 0:0@11..12#4294967037 + SUBTREE $$ 1:0@0..0#ROOT2021 1:0@0..0#ROOT2021 + SUBTREE {} 0:0@9..10#ROOT2021 0:0@11..12#ROOT2021 {}"#]], ); @@ -132,25 +132,25 @@ fn token_mapping_smoke_test() { struct MyTraitMap2 "#, expect![[r#" - SUBTREE $$ 1:0@0..20#4294967037 1:0@0..20#4294967037 - IDENT struct 0:0@34..40#4294967037 - IDENT MyTraitMap2 1:0@8..19#4294967037 - SUBTREE {} 0:0@48..49#4294967037 0:0@100..101#4294967037 - IDENT map 0:0@58..61#4294967037 - PUNCH : [alone] 0:0@61..62#4294967037 - PUNCH : [joint] 0:0@63..64#4294967037 - PUNCH : [alone] 0:0@64..65#4294967037 - IDENT std 0:0@65..68#4294967037 - PUNCH : [joint] 0:0@68..69#4294967037 - PUNCH : [alone] 0:0@69..70#4294967037 - IDENT collections 0:0@70..81#4294967037 - PUNCH : [joint] 0:0@81..82#4294967037 - PUNCH : [alone] 0:0@82..83#4294967037 - IDENT HashSet 0:0@83..90#4294967037 - PUNCH < [alone] 0:0@90..91#4294967037 - SUBTREE () 0:0@91..92#4294967037 0:0@92..93#4294967037 - PUNCH > [joint] 0:0@93..94#4294967037 - PUNCH , [alone] 0:0@94..95#4294967037 + SUBTREE $$ 1:0@0..20#ROOT2021 1:0@0..20#ROOT2021 + IDENT struct 0:0@34..40#ROOT2021 + IDENT MyTraitMap2 1:0@8..19#ROOT2021 + SUBTREE {} 0:0@48..49#ROOT2021 0:0@100..101#ROOT2021 + IDENT map 0:0@58..61#ROOT2021 + PUNCH : [alone] 0:0@61..62#ROOT2021 + PUNCH : [joint] 0:0@63..64#ROOT2021 + PUNCH : [alone] 0:0@64..65#ROOT2021 + IDENT std 0:0@65..68#ROOT2021 + PUNCH : [joint] 0:0@68..69#ROOT2021 + PUNCH : [alone] 0:0@69..70#ROOT2021 + IDENT collections 0:0@70..81#ROOT2021 + PUNCH : [joint] 0:0@81..82#ROOT2021 + PUNCH : [alone] 0:0@82..83#ROOT2021 + IDENT HashSet 0:0@83..90#ROOT2021 + PUNCH < [alone] 0:0@90..91#ROOT2021 + SUBTREE () 0:0@91..92#ROOT2021 0:0@92..93#ROOT2021 + PUNCH > [joint] 0:0@93..94#ROOT2021 + PUNCH , [alone] 0:0@94..95#ROOT2021 struct MyTraitMap2 { map: ::std::collections::HashSet<()>, @@ -179,28 +179,28 @@ fn main() { } "#, expect![[r#" - SUBTREE $$ 1:0@0..63#4294967037 1:0@0..63#4294967037 - IDENT fn 1:0@1..3#4294967037 - IDENT main 1:0@4..8#4294967037 - SUBTREE () 1:0@8..9#4294967037 1:0@9..10#4294967037 - SUBTREE {} 1:0@11..12#4294967037 1:0@61..62#4294967037 - LITERAL Integer 1 1:0@17..18#4294967037 - PUNCH ; [alone] 1:0@18..19#4294967037 - LITERAL Float 1.0 1:0@24..27#4294967037 - PUNCH ; [alone] 1:0@27..28#4294967037 - SUBTREE () 1:0@33..34#4294967037 1:0@39..40#4294967037 - SUBTREE () 1:0@34..35#4294967037 1:0@37..38#4294967037 - LITERAL Integer 1 1:0@35..36#4294967037 - PUNCH , [alone] 1:0@36..37#4294967037 - PUNCH , [alone] 1:0@38..39#4294967037 - PUNCH . [alone] 1:0@40..41#4294967037 - LITERAL Float 0.0 1:0@41..44#4294967037 - PUNCH ; [alone] 1:0@44..45#4294967037 - IDENT let 1:0@50..53#4294967037 - IDENT x 1:0@54..55#4294967037 - PUNCH = [alone] 1:0@56..57#4294967037 - LITERAL Integer 1 1:0@58..59#4294967037 - PUNCH ; [alone] 1:0@59..60#4294967037 + SUBTREE $$ 1:0@0..63#ROOT2021 1:0@0..63#ROOT2021 + IDENT fn 1:0@1..3#ROOT2021 + IDENT main 1:0@4..8#ROOT2021 + SUBTREE () 1:0@8..9#ROOT2021 1:0@9..10#ROOT2021 + SUBTREE {} 1:0@11..12#ROOT2021 1:0@61..62#ROOT2021 + LITERAL Integer 1 1:0@17..18#ROOT2021 + PUNCH ; [alone] 1:0@18..19#ROOT2021 + LITERAL Float 1.0 1:0@24..27#ROOT2021 + PUNCH ; [alone] 1:0@27..28#ROOT2021 + SUBTREE () 1:0@33..34#ROOT2021 1:0@39..40#ROOT2021 + SUBTREE () 1:0@34..35#ROOT2021 1:0@37..38#ROOT2021 + LITERAL Integer 1 1:0@35..36#ROOT2021 + PUNCH , [alone] 1:0@36..37#ROOT2021 + PUNCH , [alone] 1:0@38..39#ROOT2021 + PUNCH . [alone] 1:0@40..41#ROOT2021 + LITERAL Float 0.0 1:0@41..44#ROOT2021 + PUNCH ; [alone] 1:0@44..45#ROOT2021 + IDENT let 1:0@50..53#ROOT2021 + IDENT x 1:0@54..55#ROOT2021 + PUNCH = [alone] 1:0@56..57#ROOT2021 + LITERAL Integer 1 1:0@58..59#ROOT2021 + PUNCH ; [alone] 1:0@59..60#ROOT2021 fn main(){ 1; @@ -226,14 +226,14 @@ fn expr_2021() { const { 1 }, "#, expect![[r#" - SUBTREE $$ 1:0@0..25#4294967037 1:0@0..25#4294967037 - IDENT _ 1:0@5..6#4294967037 - PUNCH ; [joint] 0:0@36..37#4294967037 - SUBTREE () 0:0@34..35#4294967037 0:0@34..35#4294967037 - IDENT const 1:0@12..17#4294967037 - SUBTREE {} 1:0@18..19#4294967037 1:0@22..23#4294967037 - LITERAL Integer 1 1:0@20..21#4294967037 - PUNCH ; [alone] 0:0@39..40#4294967037 + SUBTREE $$ 1:0@0..25#ROOT2021 1:0@0..25#ROOT2021 + IDENT _ 1:0@5..6#ROOT2021 + PUNCH ; [joint] 0:0@36..37#ROOT2021 + SUBTREE () 0:0@34..35#ROOT2021 0:0@34..35#ROOT2021 + IDENT const 1:0@12..17#ROOT2021 + SUBTREE {} 1:0@18..19#ROOT2021 1:0@22..23#ROOT2021 + LITERAL Integer 1 1:0@20..21#ROOT2021 + PUNCH ; [alone] 0:0@39..40#ROOT2021 _; (const { @@ -254,13 +254,13 @@ fn expr_2021() { expect![[r#" ExpandError { inner: ( - 1:0@5..6#4294967037, + 1:0@5..6#ROOT2021, NoMatchingRule, ), } - SUBTREE $$ 1:0@0..8#4294967037 1:0@0..8#4294967037 - PUNCH ; [alone] 0:0@39..40#4294967037 + SUBTREE $$ 1:0@0..8#ROOT2021 1:0@0..8#ROOT2021 + PUNCH ; [alone] 0:0@39..40#ROOT2021 ;"#]], ); @@ -278,13 +278,13 @@ fn expr_2021() { expect![[r#" ExpandError { inner: ( - 1:0@5..10#4294967037, + 1:0@5..10#ROOT2021, NoMatchingRule, ), } - SUBTREE $$ 1:0@0..18#4294967037 1:0@0..18#4294967037 - PUNCH ; [alone] 0:0@39..40#4294967037 + SUBTREE $$ 1:0@0..18#ROOT2021 1:0@0..18#ROOT2021 + PUNCH ; [alone] 0:0@39..40#ROOT2021 ;"#]], ); @@ -304,26 +304,26 @@ fn expr_2021() { break 'foo bar, "#, expect![[r#" - SUBTREE $$ 1:0@0..76#4294967037 1:0@0..76#4294967037 - LITERAL Integer 4 1:0@5..6#4294967037 - PUNCH ; [joint] 0:0@41..42#4294967037 - LITERAL Str literal 1:0@12..21#4294967037 - PUNCH ; [joint] 0:0@41..42#4294967037 - SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037 - IDENT funcall 1:0@27..34#4294967037 - SUBTREE () 1:0@34..35#4294967037 1:0@35..36#4294967037 - PUNCH ; [joint] 0:0@41..42#4294967037 - SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037 - IDENT future 1:0@42..48#4294967037 - PUNCH . [alone] 1:0@48..49#4294967037 - IDENT await 1:0@49..54#4294967037 - PUNCH ; [joint] 0:0@41..42#4294967037 - SUBTREE () 0:0@39..40#4294967037 0:0@39..40#4294967037 - IDENT break 1:0@60..65#4294967037 - PUNCH ' [joint] 1:0@66..67#4294967037 - IDENT foo 1:0@67..70#4294967037 - IDENT bar 1:0@71..74#4294967037 - PUNCH ; [alone] 0:0@44..45#4294967037 + SUBTREE $$ 1:0@0..76#ROOT2021 1:0@0..76#ROOT2021 + LITERAL Integer 4 1:0@5..6#ROOT2021 + PUNCH ; [joint] 0:0@41..42#ROOT2021 + LITERAL Str literal 1:0@12..21#ROOT2021 + PUNCH ; [joint] 0:0@41..42#ROOT2021 + SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021 + IDENT funcall 1:0@27..34#ROOT2021 + SUBTREE () 1:0@34..35#ROOT2021 1:0@35..36#ROOT2021 + PUNCH ; [joint] 0:0@41..42#ROOT2021 + SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021 + IDENT future 1:0@42..48#ROOT2021 + PUNCH . [alone] 1:0@48..49#ROOT2021 + IDENT await 1:0@49..54#ROOT2021 + PUNCH ; [joint] 0:0@41..42#ROOT2021 + SUBTREE () 0:0@39..40#ROOT2021 0:0@39..40#ROOT2021 + IDENT break 1:0@60..65#ROOT2021 + PUNCH ' [joint] 1:0@66..67#ROOT2021 + IDENT foo 1:0@67..70#ROOT2021 + IDENT bar 1:0@71..74#ROOT2021 + PUNCH ; [alone] 0:0@44..45#ROOT2021 4; "literal"; @@ -345,13 +345,13 @@ fn expr_2021() { expect![[r#" ExpandError { inner: ( - 1:0@5..6#4294967037, + 1:0@5..6#ROOT2021, NoMatchingRule, ), } - SUBTREE $$ 1:0@0..8#4294967037 1:0@0..8#4294967037 - PUNCH ; [alone] 0:0@44..45#4294967037 + SUBTREE $$ 1:0@0..8#ROOT2021 1:0@0..8#ROOT2021 + PUNCH ; [alone] 0:0@44..45#ROOT2021 ;"#]], ); diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs index 716d351271ef..b2ffa4ca80ad 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:2@0..100#4294967037 42:2@0..100#4294967037"], + expect!["SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021"], ); } @@ -29,12 +29,12 @@ fn test_derive_error() { LITERAL Str #[derive(DeriveError)] struct S ; 1 PUNCH ; [alone] 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT compile_error 42:2@0..100#4294967037 - PUNCH ! [alone] 42:2@0..100#4294967037 - SUBTREE () 42:2@0..100#4294967037 42:2@0..100#4294967037 - LITERAL Str #[derive(DeriveError)] struct S ; 42:2@0..100#4294967037 - PUNCH ; [alone] 42:2@0..100#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT compile_error 42:2@0..100#ROOT2021 + PUNCH ! [alone] 42:2@0..100#ROOT2021 + SUBTREE () 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + LITERAL Str #[derive(DeriveError)] struct S ; 42:2@0..100#ROOT2021 + PUNCH ; [alone] 42:2@0..100#ROOT2021"#]], ); } @@ -53,14 +53,14 @@ fn test_fn_like_macro_noop() { PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT ident 42:2@0..5#4294967037 - PUNCH , [alone] 42:2@5..6#4294967037 - LITERAL Integer 0 42:2@7..8#4294967037 - PUNCH , [alone] 42:2@8..9#4294967037 - LITERAL Integer 1 42:2@10..11#4294967037 - PUNCH , [alone] 42:2@11..12#4294967037 - SUBTREE [] 42:2@13..14#4294967037 42:2@14..15#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT ident 42:2@0..5#ROOT2021 + PUNCH , [alone] 42:2@5..6#ROOT2021 + LITERAL Integer 0 42:2@7..8#ROOT2021 + PUNCH , [alone] 42:2@8..9#ROOT2021 + LITERAL Integer 1 42:2@10..11#ROOT2021 + PUNCH , [alone] 42:2@11..12#ROOT2021 + SUBTREE [] 42:2@13..14#ROOT2021 42:2@14..15#ROOT2021"#]], ); } @@ -75,10 +75,10 @@ fn test_fn_like_macro_clone_ident_subtree() { PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT ident 42:2@0..5#4294967037 - PUNCH , [alone] 42:2@5..6#4294967037 - SUBTREE [] 42:2@7..8#4294967037 42:2@7..8#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT ident 42:2@0..5#ROOT2021 + PUNCH , [alone] 42:2@5..6#ROOT2021 + SUBTREE [] 42:2@7..8#ROOT2021 42:2@7..8#ROOT2021"#]], ); } @@ -91,8 +91,8 @@ fn test_fn_like_macro_clone_raw_ident() { SUBTREE $$ 1 1 IDENT r#async 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT r#async 42:2@0..7#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT r#async 42:2@0..7#ROOT2021"#]], ); } @@ -105,8 +105,8 @@ fn test_fn_like_fn_like_span_join() { SUBTREE $$ 1 1 IDENT r#joined 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT r#joined 42:2@0..11#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT r#joined 42:2@0..11#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:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT set_def_site 41:1@0..150#4294967037 - IDENT resolved_at_def_site 42:2@13..33#4294967037 - IDENT start_span 42:2@34..34#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT set_def_site 41:1@0..150#ROOT2021 + IDENT resolved_at_def_site 42:2@13..33#ROOT2021 + IDENT start_span 42:2@34..34#ROOT2021"#]], ); } @@ -143,14 +143,14 @@ fn test_fn_like_mk_literals() { LITERAL Integer 123i64 1 LITERAL Integer 123 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - LITERAL ByteStr byte_string 42:2@0..100#4294967037 - LITERAL Char c 42:2@0..100#4294967037 - LITERAL Str string 42:2@0..100#4294967037 - LITERAL Float 3.14f64 42:2@0..100#4294967037 - LITERAL Float 3.14 42:2@0..100#4294967037 - LITERAL Integer 123i64 42:2@0..100#4294967037 - LITERAL Integer 123 42:2@0..100#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + LITERAL ByteStr byte_string 42:2@0..100#ROOT2021 + LITERAL Char c 42:2@0..100#ROOT2021 + LITERAL Str string 42:2@0..100#ROOT2021 + LITERAL Float 3.14f64 42:2@0..100#ROOT2021 + LITERAL Float 3.14 42:2@0..100#ROOT2021 + LITERAL Integer 123i64 42:2@0..100#ROOT2021 + LITERAL Integer 123 42:2@0..100#ROOT2021"#]], ); } @@ -164,9 +164,9 @@ fn test_fn_like_mk_idents() { IDENT standard 1 IDENT r#raw 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT standard 42:2@0..100#4294967037 - IDENT r#raw 42:2@0..100#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT standard 42:2@0..100#ROOT2021 + IDENT r#raw 42:2@0..100#ROOT2021"#]], ); } @@ -198,27 +198,27 @@ fn test_fn_like_macro_clone_literals() { PUNCH , [alone] 1 LITERAL CStr null 1"#]], expect![[r#" - SUBTREE $$ 42:2@0..100#4294967037 42:2@0..100#4294967037 - LITERAL Integer 1u16 42:2@0..4#4294967037 - PUNCH , [alone] 42:2@4..5#4294967037 - LITERAL Integer 2_u32 42:2@6..11#4294967037 - PUNCH , [alone] 42:2@11..12#4294967037 - PUNCH - [alone] 42:2@13..14#4294967037 - LITERAL Integer 4i64 42:2@14..18#4294967037 - PUNCH , [alone] 42:2@18..19#4294967037 - LITERAL Float 3.14f32 42:2@20..27#4294967037 - PUNCH , [alone] 42:2@27..28#4294967037 - LITERAL Str hello bridge 42:2@29..43#4294967037 - PUNCH , [alone] 42:2@43..44#4294967037 - LITERAL Str suffixedsuffix 42:2@45..61#4294967037 - PUNCH , [alone] 42:2@61..62#4294967037 - LITERAL StrRaw(2) raw 42:2@63..73#4294967037 - PUNCH , [alone] 42:2@73..74#4294967037 - LITERAL Char a 42:2@75..78#4294967037 - PUNCH , [alone] 42:2@78..79#4294967037 - LITERAL Byte b 42:2@80..84#4294967037 - PUNCH , [alone] 42:2@84..85#4294967037 - LITERAL CStr null 42:2@86..93#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + LITERAL Integer 1u16 42:2@0..4#ROOT2021 + PUNCH , [alone] 42:2@4..5#ROOT2021 + LITERAL Integer 2_u32 42:2@6..11#ROOT2021 + PUNCH , [alone] 42:2@11..12#ROOT2021 + PUNCH - [alone] 42:2@13..14#ROOT2021 + LITERAL Integer 4i64 42:2@14..18#ROOT2021 + PUNCH , [alone] 42:2@18..19#ROOT2021 + LITERAL Float 3.14f32 42:2@20..27#ROOT2021 + PUNCH , [alone] 42:2@27..28#ROOT2021 + LITERAL Str hello bridge 42:2@29..43#ROOT2021 + PUNCH , [alone] 42:2@43..44#ROOT2021 + LITERAL Str suffixedsuffix 42:2@45..61#ROOT2021 + PUNCH , [alone] 42:2@61..62#ROOT2021 + LITERAL StrRaw(2) raw 42:2@63..73#ROOT2021 + PUNCH , [alone] 42:2@73..74#ROOT2021 + LITERAL Char a 42:2@75..78#ROOT2021 + PUNCH , [alone] 42:2@78..79#ROOT2021 + LITERAL Byte b 42:2@80..84#ROOT2021 + PUNCH , [alone] 42:2@84..85#ROOT2021 + LITERAL CStr null 42:2@86..93#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:2@0..100#4294967037 42:2@0..100#4294967037 - IDENT compile_error 42:2@0..100#4294967037 - PUNCH ! [alone] 42:2@0..100#4294967037 - SUBTREE () 42:2@0..100#4294967037 42:2@0..100#4294967037 - LITERAL Str #[attr_error(some arguments)] mod m {} 42:2@0..100#4294967037 - PUNCH ; [alone] 42:2@0..100#4294967037"#]], + SUBTREE $$ 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + IDENT compile_error 42:2@0..100#ROOT2021 + PUNCH ! [alone] 42:2@0..100#ROOT2021 + SUBTREE () 42:2@0..100#ROOT2021 42:2@0..100#ROOT2021 + LITERAL Str #[attr_error(some arguments)] mod m {} 42:2@0..100#ROOT2021 + PUNCH ; [alone] 42:2@0..100#ROOT2021"#]], ); } diff --git a/crates/span/src/hygiene.rs b/crates/span/src/hygiene.rs index 7cb1676a29de..9ecd188a3cc3 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() }