mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Dont suggest !
for path in function call if it has generic args
This commit is contained in:
parent
6cf088810f
commit
8490b8ec63
@ -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");
|
||||
}
|
||||
|
4
tests/ui/resolve/resolve-dont-hint-macro.rs
Normal file
4
tests/ui/resolve/resolve-dont-hint-macro.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
let zero = assert_eq::<()>();
|
||||
//~^ ERROR expected function, found macro `assert_eq`
|
||||
}
|
9
tests/ui/resolve/resolve-dont-hint-macro.stderr
Normal file
9
tests/ui/resolve/resolve-dont-hint-macro.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user