Skip to content

Commit 5e7f770

Browse files
authored
Rollup merge of #118342 - compiler-errors:macro-generic-bang, r=estebank
Dont suggest `!` for path in function call if it has generic args Fixes #118335
2 parents b1e56de + 8490b8e commit 5e7f770

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
744744
err,
745745
span,
746746
source,
747+
path,
747748
res,
748749
&path_str,
749750
&base_error.fallback_label,
@@ -1328,6 +1329,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
13281329
err: &mut Diagnostic,
13291330
span: Span,
13301331
source: PathSource<'_>,
1332+
path: &[Segment],
13311333
res: Res,
13321334
path_str: &str,
13331335
fallback_label: &str,
@@ -1523,12 +1525,20 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
15231525
| PathSource::Struct,
15241526
) => {
15251527
err.span_label(span, fallback_label.to_string());
1526-
err.span_suggestion_verbose(
1527-
span.shrink_to_hi(),
1528-
"use `!` to invoke the macro",
1529-
"!",
1530-
Applicability::MaybeIncorrect,
1531-
);
1528+
1529+
// Don't suggest `!` for a macro invocation if there are generic args
1530+
if path
1531+
.last()
1532+
.is_some_and(|segment| !segment.has_generic_args && !segment.has_lifetime_args)
1533+
{
1534+
err.span_suggestion_verbose(
1535+
span.shrink_to_hi(),
1536+
"use `!` to invoke the macro",
1537+
"!",
1538+
Applicability::MaybeIncorrect,
1539+
);
1540+
}
1541+
15321542
if path_str == "try" && span.is_rust_2015() {
15331543
err.note("if you want the `try` keyword, you need Rust 2018 or later");
15341544
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let zero = assert_eq::<()>();
3+
//~^ ERROR expected function, found macro `assert_eq`
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0423]: expected function, found macro `assert_eq`
2+
--> $DIR/resolve-dont-hint-macro.rs:2:16
3+
|
4+
LL | let zero = assert_eq::<()>();
5+
| ^^^^^^^^^^^^^^^ not a function
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)