Dont suggest ! for path in function call if it has generic args

This commit is contained in:
Michael Goulet 2023-11-27 01:02:23 +00:00
parent 6cf088810f
commit 8490b8ec63
3 changed files with 29 additions and 6 deletions

View File

@ -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());
// 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");
}

View File

@ -0,0 +1,4 @@
fn main() {
let zero = assert_eq::<()>();
//~^ ERROR expected function, found macro `assert_eq`
}

View File

@ -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`.