Skip to content

Commit 60c1068

Browse files
authored
Rollup merge of #99351 - compiler-errors:arg-mismatch-blame, r=davidtwco
Use `typeck_results` to get accurate qpath res for arg mismatch error Improves error message from "function" to actually what we're calling (e.g. enum variant constrcutor) in a few cases 😸
2 parents affdcd6 + 75a1b1c commit 60c1068

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
443443
// Next, let's construct the error
444444
let (error_span, full_call_span, ctor_of) = match &call_expr.kind {
445445
hir::ExprKind::Call(
446-
hir::Expr {
447-
span,
448-
kind:
449-
hir::ExprKind::Path(hir::QPath::Resolved(
450-
_,
451-
hir::Path { res: Res::Def(DefKind::Ctor(of, _), _), .. },
452-
)),
453-
..
454-
},
446+
hir::Expr { hir_id, span, kind: hir::ExprKind::Path(qpath), .. },
455447
_,
456-
) => (call_span, *span, Some(of)),
448+
) => {
449+
if let Res::Def(DefKind::Ctor(of, _), _) =
450+
self.typeck_results.borrow().qpath_res(qpath, *hir_id)
451+
{
452+
(call_span, *span, Some(of))
453+
} else {
454+
(call_span, *span, None)
455+
}
456+
}
457457
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None),
458458
hir::ExprKind::MethodCall(path_segment, _, span) => {
459459
let ident_span = path_segment.ident.span;

src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn ts_variant() {
77
LL | Self::TSVariant(());
88
| --------------- ^^ expected type parameter `T`, found `()`
99
| |
10-
| arguments to this function are incorrect
10+
| arguments to this enum variant are incorrect
1111
|
1212
= note: expected type parameter `T`
1313
found unit type `()`
@@ -55,7 +55,7 @@ LL | impl<T> Enum<T> {
5555
LL | Self::<()>::TSVariant(());
5656
| --------------------- ^^ expected type parameter `T`, found `()`
5757
| |
58-
| arguments to this function are incorrect
58+
| arguments to this enum variant are incorrect
5959
|
6060
= note: expected type parameter `T`
6161
found unit type `()`

src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ impl E2 {
1818
}
1919

2020
fn main() {
21-
<E>::V(); //~ ERROR this function takes 1 argument but 0 arguments were supplied
21+
<E>::V(); //~ ERROR this enum variant takes 1 argument but 0 arguments were supplied
2222
let _: u8 = <E2>::V; //~ ERROR mismatched types
2323
}

src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0061]: this function takes 1 argument but 0 arguments were supplied
1+
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
22
--> $DIR/enum-variant-priority-higher-than-other-inherent.rs:21:5
33
|
44
LL | <E>::V();

0 commit comments

Comments
 (0)