Skip to content

Commit

Permalink
Dont suggest ! for path in function call if it has generic args
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 27, 2023
1 parent 6cf0888 commit 8490b8e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 16 additions & 6 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err,
span,
source,
path,
res,
&path_str,
&base_error.fallback_label,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/resolve/resolve-dont-hint-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let zero = assert_eq::<()>();
//~^ ERROR expected function, found macro `assert_eq`
}
9 changes: 9 additions & 0 deletions tests/ui/resolve/resolve-dont-hint-macro.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 8490b8e

Please sign in to comment.