diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 8316102b507..df30c185c60 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -744,6 +744,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { err, span, source, + path, res, &path_str, &base_error.fallback_label, @@ -1328,6 +1329,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { err: &mut Diagnostic, span: Span, source: PathSource<'_>, + path: &[Segment], res: Res, path_str: &str, fallback_label: &str, @@ -1523,12 +1525,20 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { | PathSource::Struct, ) => { err.span_label(span, fallback_label.to_string()); - err.span_suggestion_verbose( - span.shrink_to_hi(), - "use `!` to invoke the macro", - "!", - Applicability::MaybeIncorrect, - ); + + // Don't suggest `!` for a macro invocation if there are generic args + if path + .last() + .is_some_and(|segment| !segment.has_generic_args && !segment.has_lifetime_args) + { + err.span_suggestion_verbose( + span.shrink_to_hi(), + "use `!` to invoke the macro", + "!", + Applicability::MaybeIncorrect, + ); + } + if path_str == "try" && span.is_rust_2015() { err.note("if you want the `try` keyword, you need Rust 2018 or later"); } diff --git a/tests/ui/resolve/resolve-dont-hint-macro.rs b/tests/ui/resolve/resolve-dont-hint-macro.rs new file mode 100644 index 00000000000..da1752b337e --- /dev/null +++ b/tests/ui/resolve/resolve-dont-hint-macro.rs @@ -0,0 +1,4 @@ +fn main() { + let zero = assert_eq::<()>(); + //~^ ERROR expected function, found macro `assert_eq` +} diff --git a/tests/ui/resolve/resolve-dont-hint-macro.stderr b/tests/ui/resolve/resolve-dont-hint-macro.stderr new file mode 100644 index 00000000000..597e014d255 --- /dev/null +++ b/tests/ui/resolve/resolve-dont-hint-macro.stderr @@ -0,0 +1,9 @@ +error[E0423]: expected function, found macro `assert_eq` + --> $DIR/resolve-dont-hint-macro.rs:2:16 + | +LL | let zero = assert_eq::<()>(); + | ^^^^^^^^^^^^^^^ not a function + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0423`.