From e6270bd378cb8eef0321cbe3d2d7877c664cc612 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 10 Jan 2025 10:45:44 +0100 Subject: [PATCH] internal: Add Definition::Crate This is its own thing so it should be handled specifically where possible --- crates/hir/src/attrs.rs | 10 ++ crates/hir/src/display.rs | 33 ++++-- crates/ide-db/src/defs.rs | 21 +++- crates/ide-db/src/documentation.rs | 2 +- crates/ide-db/src/rename.rs | 1 + crates/ide/src/doc_links.rs | 2 + crates/ide/src/hover/tests.rs | 2 +- crates/ide/src/moniker.rs | 2 +- crates/ide/src/navigation_target.rs | 7 ++ .../ide/src/syntax_highlighting/highlight.rs | 3 + crates/ide/src/syntax_highlighting/inject.rs | 4 +- .../test_data/highlight_block_mod_items.html | 6 +- .../test_data/highlight_const.html | 6 +- .../test_data/highlight_doctest.html | 6 +- .../test_data/highlight_extern_crate.html | 2 +- .../test_data/highlight_issue_18089.html | 4 +- .../test_data/highlight_keywords_2015.html | 16 +-- .../test_data/highlight_keywords_2018.html | 16 +-- .../test_data/highlight_keywords_2021.html | 16 +-- .../test_data/highlight_keywords_2024.html | 16 +-- .../test_data/highlight_macros.html | 20 ++-- .../test_data/highlight_strings.html | 110 +++++++++--------- .../test_data/highlight_unsafe.html | 12 +- 23 files changed, 184 insertions(+), 133 deletions(-) diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index a23fdf1b3934..6e434addace4 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -90,6 +90,16 @@ impl HasAttrs for AssocItem { } } +impl HasAttrs for crate::Crate { + fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner { + let def = AttrDefId::ModuleId(self.root_module().id); + AttrsWithOwner::new(db.upcast(), def) + } + fn attr_id(self) -> AttrDefId { + AttrDefId::ModuleId(self.root_module().id) + } +} + /// Resolves the item `link` points to in the scope of `def`. pub fn resolve_doc_path_on( db: &dyn HirDatabase, diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index e09ded32fbdf..b29c91694d37 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -23,10 +23,10 @@ use hir_ty::{ use itertools::Itertools; use crate::{ - Adt, AsAssocItem, AssocItem, AssocItemContainer, Const, ConstParam, Enum, ExternCrateDecl, - Field, Function, GenericParam, HasCrate, HasVisibility, Impl, LifetimeParam, Macro, Module, - SelfParam, Static, Struct, Trait, TraitAlias, TraitRef, TupleField, TyBuilder, Type, TypeAlias, - TypeOrConstParam, TypeParam, Union, Variant, + Adt, AsAssocItem, AssocItem, AssocItemContainer, Const, ConstParam, Crate, Enum, + ExternCrateDecl, Field, Function, GenericParam, HasCrate, HasVisibility, Impl, LifetimeParam, + Macro, Module, SelfParam, Static, Struct, Trait, TraitAlias, TraitRef, TupleField, TyBuilder, + Type, TypeAlias, TypeOrConstParam, TypeParam, Union, Variant, }; impl HirDisplay for Function { @@ -846,14 +846,27 @@ impl HirDisplay for TypeAlias { impl HirDisplay for Module { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { - // FIXME: Module doesn't have visibility saved in data. + match self.parent(f.db) { + Some(m) => write_visibility(m.id, self.visibility(f.db), f)?, + None => { + return match self.krate(f.db).display_name(f.db) { + Some(name) => write!(f, "extern crate {name}"), + None => f.write_str("extern crate {unknown}"), + } + } + } match self.name(f.db) { Some(name) => write!(f, "mod {}", name.display(f.db.upcast(), f.edition())), - None if self.is_crate_root() => match self.krate(f.db).display_name(f.db) { - Some(name) => write!(f, "extern crate {name}"), - None => f.write_str("extern crate {unknown}"), - }, - None => f.write_str("mod {unnamed}"), + None => f.write_str("mod {unknown}"), + } + } +} + +impl HirDisplay for Crate { + fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { + match self.display_name(f.db) { + Some(name) => write!(f, "extern crate {name}"), + None => f.write_str("extern crate {unknown}"), } } } diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 2d30bb412735..a5587507f134 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -32,6 +32,7 @@ pub enum Definition { Field(Field), TupleField(TupleField), Module(Module), + Crate(Crate), Function(Function), Adt(Adt), Variant(Variant), @@ -62,14 +63,19 @@ impl Definition { pub fn krate(&self, db: &RootDatabase) -> Option { Some(match self { Definition::Module(m) => m.krate(), + &Definition::Crate(it) => it, _ => self.module(db)?.krate(), }) } + /// Returns the module this definition resides in. + /// + /// As such, for modules themselves this will return the parent module. pub fn module(&self, db: &RootDatabase) -> Option { let module = match self { Definition::Macro(it) => it.module(db), Definition::Module(it) => it.parent(db)?, + Definition::Crate(_) => return None, Definition::Field(it) => it.parent_def(db).module(db), Definition::Function(it) => it.module(db), Definition::Adt(it) => it.module(db), @@ -108,6 +114,7 @@ impl Definition { match self { Definition::Macro(it) => Some(it.module(db).into()), Definition::Module(it) => it.parent(db).map(Definition::Module), + Definition::Crate(_) => None, Definition::Field(it) => Some(it.parent_def(db).into()), Definition::Function(it) => container_to_definition(it.container(db)), Definition::Adt(it) => Some(it.module(db).into()), @@ -137,6 +144,7 @@ impl Definition { let vis = match self { Definition::Field(sf) => sf.visibility(db), Definition::Module(it) => it.visibility(db), + Definition::Crate(_) => return None, Definition::Function(it) => it.visibility(db), Definition::Adt(it) => it.visibility(db), Definition::Const(it) => it.visibility(db), @@ -146,8 +154,8 @@ impl Definition { Definition::TypeAlias(it) => it.visibility(db), Definition::Variant(it) => it.visibility(db), Definition::ExternCrateDecl(it) => it.visibility(db), + Definition::Macro(it) => it.visibility(db), Definition::BuiltinType(_) | Definition::TupleField(_) => Visibility::Public, - Definition::Macro(_) => return None, Definition::BuiltinAttr(_) | Definition::BuiltinLifetime(_) | Definition::ToolModule(_) @@ -167,6 +175,9 @@ impl Definition { Definition::Macro(it) => it.name(db), Definition::Field(it) => it.name(db), Definition::Module(it) => it.name(db)?, + Definition::Crate(it) => { + Name::new_symbol_root(it.display_name(db)?.crate_name().symbol().clone()) + } Definition::Function(it) => it.name(db), Definition::Adt(it) => it.name(db), Definition::Variant(it) => it.name(db), @@ -202,6 +213,7 @@ impl Definition { Definition::Macro(it) => it.docs(db), Definition::Field(it) => it.docs(db), Definition::Module(it) => it.docs(db), + Definition::Crate(it) => it.docs(db), Definition::Function(it) => it.docs(db), Definition::Adt(it) => it.docs(db), Definition::Variant(it) => it.docs(db), @@ -282,6 +294,7 @@ impl Definition { Definition::Field(it) => it.display(db, edition).to_string(), Definition::TupleField(it) => it.display(db, edition).to_string(), Definition::Module(it) => it.display(db, edition).to_string(), + Definition::Crate(it) => it.display(db, edition).to_string(), Definition::Function(it) => it.display(db, edition).to_string(), Definition::Adt(it) => it.display(db, edition).to_string(), Definition::Variant(it) => it.display(db, edition).to_string(), @@ -415,7 +428,7 @@ impl IdentClass { } IdentClass::NameRefClass(NameRefClass::ExternCrateShorthand { decl, krate }) => { res.push((Definition::ExternCrateDecl(decl), None)); - res.push((Definition::Module(krate.root_module()), None)); + res.push((Definition::Crate(krate), None)); } IdentClass::Operator( OperatorClass::Await(func) @@ -456,7 +469,7 @@ impl IdentClass { } IdentClass::NameRefClass(NameRefClass::ExternCrateShorthand { decl, krate }) => { res.push(Definition::ExternCrateDecl(decl)); - res.push(Definition::Module(krate.root_module())); + res.push(Definition::Crate(krate)); } IdentClass::Operator(_) => (), } @@ -800,7 +813,7 @@ impl NameRefClass { let extern_crate = sema.to_def(&extern_crate_ast)?; let krate = extern_crate.resolved_crate(sema.db)?; Some(if extern_crate_ast.rename().is_some() { - NameRefClass::Definition(Definition::Module(krate.root_module()), None) + NameRefClass::Definition(Definition::Crate(krate), None) } else { NameRefClass::ExternCrateShorthand { krate, decl: extern_crate } }) diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index a0ef0f90a65b..b83efcd02f77 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -178,7 +178,7 @@ macro_rules! impl_has_docs { impl_has_docs![ Variant, Field, Static, Const, Trait, TraitAlias, TypeAlias, Macro, Function, Adt, Module, - Impl, + Impl, Crate, ]; macro_rules! impl_has_docs_enum { diff --git a/crates/ide-db/src/rename.rs b/crates/ide-db/src/rename.rs index 1d1679c3ff88..42efbd68e33d 100644 --- a/crates/ide-db/src/rename.rs +++ b/crates/ide-db/src/rename.rs @@ -134,6 +134,7 @@ impl Definition { FieldSource::Pos(_) => None, } } + Definition::Crate(_) => None, Definition::Module(module) => { let src = module.declaration_source(sema.db)?; let name = src.value.name()?; diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 72fcac54177f..bc9843f3f35a 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -199,6 +199,7 @@ pub(crate) fn resolve_doc_path_for_def( ) -> Option { match def { Definition::Module(it) => it.resolve_doc_path(db, link, ns), + Definition::Crate(it) => it.resolve_doc_path(db, link, ns), Definition::Function(it) => it.resolve_doc_path(db, link, ns), Definition::Adt(it) => it.resolve_doc_path(db, link, ns), Definition::Variant(it) => it.resolve_doc_path(db, link, ns), @@ -594,6 +595,7 @@ fn filename_and_frag_for_def( Adt::Enum(e) => format!("enum.{}.html", e.name(db).unescaped().display(db.upcast())), Adt::Union(u) => format!("union.{}.html", u.name(db).unescaped().display(db.upcast())), }, + Definition::Crate(_) => String::from("index.html"), Definition::Module(m) => match m.name(db) { // `#[doc(keyword = "...")]` is internal used only by rust compiler Some(name) => { diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 2e7637e46773..7f3644c08d72 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -6112,7 +6112,7 @@ use foo::bar::{self$0}; ``` ```rust - mod bar + pub mod bar ``` --- diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs index 052466725fa1..51f280961884 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -191,7 +191,7 @@ pub(crate) fn def_to_kind(db: &RootDatabase, def: Definition) -> SymbolInformati MacroKind::ProcMacro => Macro, }, Definition::Field(..) | Definition::TupleField(..) => Field, - Definition::Module(..) => Module, + Definition::Module(..) | Definition::Crate(..) => Module, Definition::Function(it) => { if it.as_assoc_item(db).is_some() { if it.has_self_param(db) { diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs index 9259243db85d..f6c15345982c 100644 --- a/crates/ide/src/navigation_target.rs +++ b/crates/ide/src/navigation_target.rs @@ -225,6 +225,7 @@ impl TryToNav for Definition { Definition::Local(it) => Some(it.to_nav(db)), Definition::Label(it) => it.try_to_nav(db), Definition::Module(it) => Some(it.to_nav(db)), + Definition::Crate(it) => Some(it.to_nav(db)), Definition::Macro(it) => it.try_to_nav(db), Definition::Field(it) => it.try_to_nav(db), Definition::SelfType(it) => it.try_to_nav(db), @@ -398,6 +399,12 @@ impl ToNav for hir::Module { } } +impl ToNav for hir::Crate { + fn to_nav(&self, db: &RootDatabase) -> UpmappingResult { + self.root_module().to_nav(db) + } +} + impl TryToNav for hir::Impl { fn try_to_nav(&self, db: &RootDatabase) -> Option> { let InFile { file_id, value } = self.source(db)?; diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 4f3d5d9d00c2..22a2fe4e9eb2 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -386,6 +386,9 @@ pub(super) fn highlight_def( Definition::Field(_) | Definition::TupleField(_) => { Highlight::new(HlTag::Symbol(SymbolKind::Field)) } + Definition::Crate(_) => { + Highlight::new(HlTag::Symbol(SymbolKind::Module)) | HlMod::CrateRoot + } Definition::Module(module) => { let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Module)); if module.is_crate_root() { diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 0a157c157c38..1a9c1beba1ae 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -287,7 +287,9 @@ fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option HlTag { let symbol = match def { - Definition::Module(_) | Definition::ExternCrateDecl(_) => SymbolKind::Module, + Definition::Module(_) | Definition::Crate(_) | Definition::ExternCrateDecl(_) => { + SymbolKind::Module + } Definition::Function(_) => SymbolKind::Function, Definition::Adt(hir::Adt::Struct(_)) => SymbolKind::Struct, Definition::Adt(hir::Adt::Enum(_)) => SymbolKind::Enum, diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html b/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html index edd9639768ab..c6eab90e42b0 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_block_mod_items.html @@ -45,7 +45,7 @@ .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
macro_rules! foo {
+
macro_rules! foo {
     ($foo:ident) => {
         mod y {
             pub struct $foo;
@@ -53,9 +53,9 @@
     };
 }
 fn main() {
-    foo!(Foo);
+    foo!(Foo);
     mod module {
-        foo!(Bar);
+        foo!(Bar);
         fn func(_: y::Bar) {
             mod inner {
                 struct Innerest<const C: usize> { field: [(); {C}] }
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_const.html b/crates/ide/src/syntax_highlighting/test_data/highlight_const.html
index 05289cfe3fe3..96cdb532dd54 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_const.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_const.html
@@ -45,7 +45,7 @@
 .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
 .unresolved_reference    { color: #FC5555; text-decoration: wavy underline; }
 
-
macro_rules! id {
+
macro_rules! id {
     ($($tt:tt)*) => {
         $($tt)*
     };
@@ -57,7 +57,7 @@
     const {
         const || {}
     }
-    id!(
+    id!(
         CONST_ITEM;
         CONST_PARAM;
         const {
@@ -78,7 +78,7 @@
     const fn assoc_const_fn() {}
 }
 
-macro_rules! unsafe_deref {
+macro_rules! unsafe_deref {
     () => {
         *(&() as *const ())
     };
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
index aa9d23250c15..5ff96ae2a74f 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
@@ -147,10 +147,10 @@
 }
 
 /// ```
-/// macro_rules! noop { ($expr:expr) => { $expr }}
-/// noop!(1);
+/// macro_rules! noop { ($expr:expr) => { $expr }}
+/// noop!(1);
 /// ```
-macro_rules! noop {
+macro_rules! noop {
     ($expr:expr) => {
         $expr
     }
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html
index 7820e4e5a5f9..fe5f5ab6a9a2 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html
@@ -45,7 +45,7 @@
 .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; }
 .unresolved_reference    { color: #FC5555; text-decoration: wavy underline; }
 
-
extern crate self as this;
+
extern crate self as this;
 extern crate std;
 extern crate alloc as abc;
 extern crate unresolved as definitely_unresolved;
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_issue_18089.html b/crates/ide/src/syntax_highlighting/test_data/highlight_issue_18089.html
index 361dcd1bc37c..06817af1b1f2 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_issue_18089.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_issue_18089.html
@@ -46,8 +46,8 @@
 .unresolved_reference    { color: #FC5555; text-decoration: wavy underline; }
 
 
fn main() {
-    template!(template);
+    template!(template);
 }
 
 #[proc_macros::issue_18089]
-fn template() {}
\ No newline at end of file +fn template() {}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2015.html b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2015.html index c2bf94fd9b6f..2d3407dbcda0 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2015.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2015.html @@ -53,22 +53,22 @@ use super::*; } -macro_rules! void { +macro_rules! void { ($($tt:tt)*) => {} } struct __ where Self:; fn __(_: Self) {} -void!(Self); +void!(Self); // edition dependent -void!(try async await gen); +void!(try async await gen); // edition and context dependent -void!(dyn); +void!(dyn); // builtin custom syntax -void!(builtin offset_of format_args asm); +void!(builtin offset_of format_args asm); // contextual -void!(macro_rules, union, default, raw, auto, yeet); +void!(macro_rules, union, default, raw, auto, yeet); // reserved -void!(abstract become box do final macro override priv typeof unsized virtual yield); -void!('static 'self 'unsafe)
\ No newline at end of file +void!(abstract become box do final macro override priv typeof unsized virtual yield); +void!('static 'self 'unsafe)
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2018.html b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2018.html index a30d16d53271..f8eb5d068a81 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2018.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2018.html @@ -53,22 +53,22 @@ use super::*; } -macro_rules! void { +macro_rules! void { ($($tt:tt)*) => {} } struct __ where Self:; fn __(_: Self) {} -void!(Self); +void!(Self); // edition dependent -void!(try async await gen); +void!(try async await gen); // edition and context dependent -void!(dyn); +void!(dyn); // builtin custom syntax -void!(builtin offset_of format_args asm); +void!(builtin offset_of format_args asm); // contextual -void!(macro_rules, union, default, raw, auto, yeet); +void!(macro_rules, union, default, raw, auto, yeet); // reserved -void!(abstract become box do final macro override priv typeof unsized virtual yield); -void!('static 'self 'unsafe)
\ No newline at end of file +void!(abstract become box do final macro override priv typeof unsized virtual yield); +void!('static 'self 'unsafe)
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2021.html b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2021.html index a30d16d53271..f8eb5d068a81 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2021.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2021.html @@ -53,22 +53,22 @@ use super::*; } -macro_rules! void { +macro_rules! void { ($($tt:tt)*) => {} } struct __ where Self:; fn __(_: Self) {} -void!(Self); +void!(Self); // edition dependent -void!(try async await gen); +void!(try async await gen); // edition and context dependent -void!(dyn); +void!(dyn); // builtin custom syntax -void!(builtin offset_of format_args asm); +void!(builtin offset_of format_args asm); // contextual -void!(macro_rules, union, default, raw, auto, yeet); +void!(macro_rules, union, default, raw, auto, yeet); // reserved -void!(abstract become box do final macro override priv typeof unsized virtual yield); -void!('static 'self 'unsafe)
\ No newline at end of file +void!(abstract become box do final macro override priv typeof unsized virtual yield); +void!('static 'self 'unsafe) \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2024.html b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2024.html index b82a3f9f8196..fca840170696 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2024.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_keywords_2024.html @@ -53,22 +53,22 @@ use super::*; } -macro_rules! void { +macro_rules! void { ($($tt:tt)*) => {} } struct __ where Self:; fn __(_: Self) {} -void!(Self); +void!(Self); // edition dependent -void!(try async await gen); +void!(try async await gen); // edition and context dependent -void!(dyn); +void!(dyn); // builtin custom syntax -void!(builtin offset_of format_args asm); +void!(builtin offset_of format_args asm); // contextual -void!(macro_rules, union, default, raw, auto, yeet); +void!(macro_rules, union, default, raw, auto, yeet); // reserved -void!(abstract become box do final macro override priv typeof unsized virtual yield); -void!('static 'self 'unsafe) \ No newline at end of file +void!(abstract become box do final macro override priv typeof unsized virtual yield); +void!('static 'self 'unsafe) \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html b/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html index 06673d1a73c7..f640a5e6ca7f 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_macros.html @@ -53,34 +53,34 @@ ,i32 :y pub } Foo struct } -macro_rules! def_fn { +macro_rules! def_fn { ($($tt:tt)*) => {$($tt)*} } -def_fn! { +def_fn! { fn bar() -> u32 { 100 } } -macro_rules! dont_color_me_braces { +macro_rules! dont_color_me_braces { () => {0} } -macro_rules! noop { +macro_rules! noop { ($expr:expr) => { $expr } } /// textually shadow previous definition -macro_rules! noop { +macro_rules! noop { ($expr:expr) => { $expr } } -macro_rules! keyword_frag { +macro_rules! keyword_frag { ($type:ty) => ($type) } @@ -94,7 +94,7 @@ } } -macro_rules! id { +macro_rules! id { ($($tt:tt)*) => { $($tt)* }; @@ -106,10 +106,10 @@ fn main() { struct TestLocal; // regression test, TestLocal here used to not resolve - let _: S<id![TestLocal]>; + let _: S<id![TestLocal]>; format_args!("Hello, {}!", (92,).0); - dont_color_me_braces!(); - noop!(noop!(1)); + dont_color_me_braces!(); + noop!(noop!(1)); } \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 1385ae0510aa..0a7e273950da 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -45,14 +45,14 @@ .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
macro_rules! println {
+
macro_rules! println {
     ($($arg:tt)*) => ({
         $crate::io::_print(format_args_nl!($($arg)*));
     })
 }
 
 mod panic {
-    pub macro panic_2015 {
+    pub macro panic_2015 {
         () => (
             panic("explicit panic")
         ),
@@ -73,12 +73,12 @@
     }
 }
 
-macro_rules! toho {
+macro_rules! toho {
     () => ($crate::panic!("not yet implemented"));
     ($($arg:tt)+) => ($crate::panic!("not yet implemented: {}", format_args!($($arg)+)));
 }
 
-macro_rules! reuse_twice {
+macro_rules! reuse_twice {
     ($literal:literal) => {{stringify!($literal); format_args!($literal)}};
 }
 
@@ -95,74 +95,74 @@
 
     let a = b'\xFF';
 
-    println!("Hello {{Hello}}");
+    println!("Hello {{Hello}}");
     // from https://doc.rust-lang.org/std/fmt/index.html
-    println!("Hello");                 // => "Hello"
-    println!("Hello, {}!", "world");   // => "Hello, world!"
-    println!("The number is {}", 1);   // => "The number is 1"
-    println!("{:?}", (3, 4));          // => "(3, 4)"
-    println!("{value}", value=4);      // => "4"
-    println!("{} {}", 1, 2);           // => "1 2"
-    println!("{:04}", 42);             // => "0042" with leading zerosV
-    println!("{1} {} {0} {}", 1, 2);   // => "2 1 1 2"
-    println!("{argument}", argument = "test");   // => "test"
-    println!("{name} {}", 1, name = 2);          // => "2 1"
-    println!("{a} {c} {b}", a="a", b='b', c=3);  // => "a 3 b"
-    println!("{{{}}}", 2);                       // => "{2}"
-    println!("Hello {:5}!", "x");
-    println!("Hello {:1$}!", "x", 5);
-    println!("Hello {1:0$}!", 5, "x");
-    println!("Hello {:width$}!", "x", width = 5);
-    println!("Hello {:<5}!", "x");
-    println!("Hello {:-<5}!", "x");
-    println!("Hello {:^5}!", "x");
-    println!("Hello {:>5}!", "x");
-    println!("Hello {:+}!", 5);
-    println!("{:#x}!", 27);
-    println!("Hello {:05}!", 5);
-    println!("Hello {:05}!", -5);
-    println!("{:#010x}!", 27);
-    println!("Hello {0} is {1:.5}", "x", 0.01);
-    println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
-    println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
-    println!("Hello {} is {:.*}",    "x", 5, 0.01);
-    println!("Hello {} is {2:.*}",   "x", 5, 0.01);
-    println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
-    println!("{}, `{name:.*}` has 3 fractional digits", "Hello", 3, name=1234.56);
-    println!("{}, `{name:.*}` has 3 characters", "Hello", 3, name="1234.56");
-    println!("{}, `{name:>8.*}` has 3 right-aligned characters", "Hello", 3, name="1234.56");
+    println!("Hello");                 // => "Hello"
+    println!("Hello, {}!", "world");   // => "Hello, world!"
+    println!("The number is {}", 1);   // => "The number is 1"
+    println!("{:?}", (3, 4));          // => "(3, 4)"
+    println!("{value}", value=4);      // => "4"
+    println!("{} {}", 1, 2);           // => "1 2"
+    println!("{:04}", 42);             // => "0042" with leading zerosV
+    println!("{1} {} {0} {}", 1, 2);   // => "2 1 1 2"
+    println!("{argument}", argument = "test");   // => "test"
+    println!("{name} {}", 1, name = 2);          // => "2 1"
+    println!("{a} {c} {b}", a="a", b='b', c=3);  // => "a 3 b"
+    println!("{{{}}}", 2);                       // => "{2}"
+    println!("Hello {:5}!", "x");
+    println!("Hello {:1$}!", "x", 5);
+    println!("Hello {1:0$}!", 5, "x");
+    println!("Hello {:width$}!", "x", width = 5);
+    println!("Hello {:<5}!", "x");
+    println!("Hello {:-<5}!", "x");
+    println!("Hello {:^5}!", "x");
+    println!("Hello {:>5}!", "x");
+    println!("Hello {:+}!", 5);
+    println!("{:#x}!", 27);
+    println!("Hello {:05}!", 5);
+    println!("Hello {:05}!", -5);
+    println!("{:#010x}!", 27);
+    println!("Hello {0} is {1:.5}", "x", 0.01);
+    println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
+    println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
+    println!("Hello {} is {:.*}",    "x", 5, 0.01);
+    println!("Hello {} is {2:.*}",   "x", 5, 0.01);
+    println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
+    println!("{}, `{name:.*}` has 3 fractional digits", "Hello", 3, name=1234.56);
+    println!("{}, `{name:.*}` has 3 characters", "Hello", 3, name="1234.56");
+    println!("{}, `{name:>8.*}` has 3 right-aligned characters", "Hello", 3, name="1234.56");
 
     let _ = "{}"
     let _ = "{{}}";
 
-    println!("Hello {{}}");
-    println!("{{ Hello");
-    println!("Hello }}");
-    println!("{{Hello}}");
-    println!("{{ Hello }}");
-    println!("{{Hello }}");
-    println!("{{ Hello}}");
+    println!("Hello {{}}");
+    println!("{{ Hello");
+    println!("Hello }}");
+    println!("{{Hello}}");
+    println!("{{ Hello }}");
+    println!("{{Hello }}");
+    println!("{{ Hello}}");
 
-    println!(r"Hello, {}!", "world");
+    println!(r"Hello, {}!", "world");
 
     // escape sequences
-    println!("Hello\nWorld");
-    println!("\u{48}\x65\x6C\x6C\x6F World");
+    println!("Hello\nWorld");
+    println!("\u{48}\x65\x6C\x6C\x6F World");
 
     let _ = "\x28\x28\x00\x63\xFF\u{FF}\n"; // invalid non-UTF8 escape sequences
     let _ = b"\x28\x28\x00\x63\xFF\u{FF}\n"; // valid bytes, invalid unicodes
     let _ = c"\u{FF}\xFF"; // valid bytes, valid unicodes
     let backslash = r"\\";
 
-    println!("{\x41}", A = 92);
-    println!("{ничоси}", ничоси = 92);
+    println!("{\x41}", A = 92);
+    println!("{ничоси}", ничоси = 92);
 
-    println!("{:x?} {} ", thingy, n2);
+    println!("{:x?} {} ", thingy, n2);
     panic!("{}", 0);
     panic!("more {}", 1);
     assert!(true, "{}", 1);
     assert!(true, "{} asdasd", 1);
-    toho!("{}fmt", 0);
+    toho!("{}fmt", 0);
     let i: u64 = 3;
     let o: u64;
     core::arch::asm!(
@@ -175,6 +175,6 @@
     const CONSTANT: () = ():
     let mut m = ();
     format_args!(concat!("{}"), "{}");
-    format_args!("{} {} {} {} {} {} {backslash} {CONSTANT} {m}", backslash, format_args!("{}", 0), foo, "bar", toho!(), backslash);
-    reuse_twice!("{backslash}");
+    format_args!("{} {} {} {} {} {} {backslash} {CONSTANT} {m}", backslash, format_args!("{}", 0), foo, "bar", toho!(), backslash);
+    reuse_twice!("{backslash}");
 }
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 4e69c82f3da6..d9beac308982 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -45,12 +45,12 @@ .invalid_escape_sequence { color: #FC5555; text-decoration: wavy underline; } .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
macro_rules! id {
+
macro_rules! id {
     ($($tt:tt)*) => {
         $($tt)*
     };
 }
-macro_rules! unsafe_deref {
+macro_rules! unsafe_deref {
     () => {
         *(&() as *const ())
     };
@@ -92,13 +92,13 @@
     let x = &5 as *const _ as *const usize;
     let u = Union { b: 0 };
 
-    id! {
-        unsafe { unsafe_deref!() }
+    id! {
+        unsafe { unsafe_deref!() }
     };
 
     unsafe {
-        unsafe_deref!();
-        id! { unsafe_deref!() };
+        unsafe_deref!();
+        id! { unsafe_deref!() };
 
         // unsafe fn and method calls
         unsafe_fn();