diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 79321df6b6..64d08c7364 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -2755,6 +2755,12 @@ impl Macro { } } + pub fn is_asm_or_global_asm(&self, db: &dyn HirDatabase) -> bool { + matches!(self.id, MacroId::Macro2Id(it) if { + matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm()) + }) + } + pub fn is_attr(&self, db: &dyn HirDatabase) -> bool { matches!(self.kind(db), MacroKind::Attr) } diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index a70dc5254c..c8f61a34cb 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -1317,9 +1317,15 @@ impl<'db> SemanticsImpl<'db> { } pub fn resolve_macro_call(&self, macro_call: &ast::MacroCall) -> Option { - let sa = self.analyze(macro_call.syntax())?; let macro_call = self.find_file(macro_call.syntax()).with_value(macro_call); - sa.resolve_macro_call(self.db, macro_call) + self.with_ctx(|ctx| { + ctx.macro_call_to_macro_call(macro_call) + .and_then(|call| macro_call_to_macro_id(ctx, call)) + .map(Into::into) + }) + .or_else(|| { + self.analyze(macro_call.value.syntax())?.resolve_macro_call(self.db, macro_call) + }) } pub fn is_proc_macro_call(&self, macro_call: &ast::MacroCall) -> bool { @@ -1339,12 +1345,17 @@ impl<'db> SemanticsImpl<'db> { } pub fn is_unsafe_macro_call(&self, macro_call: &ast::MacroCall) -> bool { - let sa = match self.analyze(macro_call.syntax()) { - Some(it) => it, - None => return false, - }; + let Some(mac) = self.resolve_macro_call(macro_call) else { return false }; + if mac.is_asm_or_global_asm(self.db) { + return true; + } + + let Some(sa) = self.analyze(macro_call.syntax()) else { return false }; let macro_call = self.find_file(macro_call.syntax()).with_value(macro_call); - sa.is_unsafe_macro_call(self.db, macro_call) + match macro_call.map(|it| it.syntax().parent().and_then(ast::MacroExpr::cast)).transpose() { + Some(it) => sa.is_unsafe_macro_call_expr(self.db, it.as_ref()), + None => false, + } } pub fn resolve_attr_macro_call(&self, item: &ast::Item) -> Option { diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 138f3d8604..7ce64b4c48 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -842,32 +842,13 @@ impl SourceAnalyzer { infer.variant_resolution_for_expr(expr_id) } - pub(crate) fn is_unsafe_macro_call( + pub(crate) fn is_unsafe_macro_call_expr( &self, db: &dyn HirDatabase, - macro_call: InFile<&ast::MacroCall>, + macro_expr: InFile<&ast::MacroExpr>, ) -> bool { - // check for asm/global_asm - if let Some(mac) = self.resolve_macro_call(db, macro_call) { - let ex = match mac.id { - hir_def::MacroId::Macro2Id(it) => it.lookup(db.upcast()).expander, - hir_def::MacroId::MacroRulesId(it) => it.lookup(db.upcast()).expander, - _ => hir_def::MacroExpander::Declarative, - }; - if matches!(ex, hir_def::MacroExpander::BuiltIn(ex) if ex.is_asm()) { - return true; - } - } - let macro_expr = match macro_call - .map(|it| it.syntax().parent().and_then(ast::MacroExpr::cast)) - .transpose() - { - Some(it) => it, - None => return false, - }; - if let (Some((def, body, sm)), Some(infer)) = (&self.def, &self.infer) { - if let Some(expanded_expr) = sm.macro_expansion_expr(macro_expr.as_ref()) { + if let Some(expanded_expr) = sm.macro_expansion_expr(macro_expr) { let mut is_unsafe = false; unsafe_expressions( db, diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 3b784ebec3..c73b6acb0d 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -584,6 +584,9 @@ fn highlight_method_call( if func.is_async(sema.db) { h |= HlMod::Async; } + if func.is_const(sema.db) { + h |= HlMod::Const; + } if func .as_assoc_item(sema.db) .and_then(|it| it.container_or_implemented_trait(sema.db)) 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 eed3968a90..70f2d7203e 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 @@ -48,16 +48,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
macro_rules! foo {
     ($foo:ident) => {
         mod y {
-            struct $foo;
+            pub struct $foo;
         }
     };
 }
 fn main() {
-    foo!(Foo);
+    foo!(Foo);
     mod module {
-        // FIXME: IDE layer has this unresolved
-        foo!(Bar);
-        fn func() {
+        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 cd6ffc2c3a..a14f2cc88c 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_const.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_const.html
@@ -66,10 +66,12 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
         &raw const ();
         const
     );
+    ().assoc_const_method();
 }
 trait ConstTrait {
     const ASSOC_CONST: () = ();
     const fn assoc_const_fn() {}
+    const fn assoc_const_method(self) {}
 }
 impl const ConstTrait for () {
     const ASSOC_CONST: () = ();
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html b/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html
index 893e3c0675..dfad3a6605 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlight_default_library.html
@@ -49,5 +49,5 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 fn main() {
     let foo = Some(92);
-    let nums = iter::repeat(foo.unwrap());
+    let nums = iter::repeat(foo.unwrap());
 }
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html index 413edb6d65..9be7c92fc7 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html @@ -218,7 +218,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd true } } -const USAGE_OF_BOOL: bool = Bool::True.to_primitive(); +const USAGE_OF_BOOL: bool = Bool::True.to_primitive(); trait Baz { type Qux; 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 22706dea1f..cb47fc68bc 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -165,7 +165,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd toho!("{}fmt", 0); let i: u64 = 3; let o: u64; - asm!( + asm!( "mov {0}, {1}", "add {0}, 5", out(reg) o, diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 901e41d27c..08acfca2cb 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -657,10 +657,12 @@ const fn const_fn(const {}: const fn()) where (): const C &raw const (); const ); + ().assoc_const_method(); } trait ConstTrait { const ASSOC_CONST: () = (); const fn assoc_const_fn() {} + const fn assoc_const_method(self) {} } impl const ConstTrait for () { const ASSOC_CONST: () = (); @@ -1070,16 +1072,15 @@ fn test_block_mod_items() { macro_rules! foo { ($foo:ident) => { mod y { - struct $foo; + pub struct $foo; } }; } fn main() { foo!(Foo); mod module { - // FIXME: IDE layer has this unresolved foo!(Bar); - fn func() { + fn func(_: y::Bar) { mod inner { struct Innerest { field: [(); {C}] } } diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs index 4aa5e37f98..7a7661e431 100644 --- a/crates/rust-analyzer/src/integrated_benchmarks.rs +++ b/crates/rust-analyzer/src/integrated_benchmarks.rs @@ -160,7 +160,7 @@ fn integrated_completion_benchmark() { analysis.completions(&config, position, None).unwrap(); } - let _g = crate::tracing::hprof::init("*"); + let _g = crate::tracing::hprof::init("*>10"); let completion_offset = { let _it = stdx::timeit("change");