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 @@ fn try_lookup_name_relaxed(
err, err,
span, span,
source, source,
path,
res, res,
&path_str, &path_str,
&base_error.fallback_label, &base_error.fallback_label,
@ -1328,6 +1329,7 @@ fn smart_resolve_context_dependent_help(
err: &mut Diagnostic, err: &mut Diagnostic,
span: Span, span: Span,
source: PathSource<'_>, source: PathSource<'_>,
path: &[Segment],
res: Res, res: Res,
path_str: &str, path_str: &str,
fallback_label: &str, fallback_label: &str,
@ -1523,12 +1525,20 @@ fn smart_resolve_context_dependent_help(
| PathSource::Struct, | PathSource::Struct,
) => { ) => {
err.span_label(span, fallback_label.to_string()); err.span_label(span, fallback_label.to_string());
err.span_suggestion_verbose(
span.shrink_to_hi(), // Don't suggest `!` for a macro invocation if there are generic args
"use `!` to invoke the macro", if path
"!", .last()
Applicability::MaybeIncorrect, .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() { if path_str == "try" && span.is_rust_2015() {
err.note("if you want the `try` keyword, you need Rust 2018 or later"); 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`.