about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-07-18 21:14:47 +0530
committerGitHub <noreply@github.com>2022-07-18 21:14:47 +0530
commit60c1068c924d5dacaa2bebb4427cf5aaca9577e9 (patch)
tree5f04376b20e0787a77af661c332f3d0785831c42
parentaffdcd6cef020ca7a110c3b954214486a0727b85 (diff)
parent75a1b1cf066b36decf39f4d5036c0b1aae53c680 (diff)
downloadrust-60c1068c924d5dacaa2bebb4427cf5aaca9577e9.tar.gz
rust-60c1068c924d5dacaa2bebb4427cf5aaca9577e9.zip
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 :smile_cat:
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs20
-rw-r--r--src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr4
-rw-r--r--src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs2
-rw-r--r--src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr2
4 files changed, 14 insertions, 14 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 89b376442a8..41c38f558b6 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -443,17 +443,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // Next, let's construct the error
         let (error_span, full_call_span, ctor_of) = match &call_expr.kind {
             hir::ExprKind::Call(
-                hir::Expr {
-                    span,
-                    kind:
-                        hir::ExprKind::Path(hir::QPath::Resolved(
-                            _,
-                            hir::Path { res: Res::Def(DefKind::Ctor(of, _), _), .. },
-                        )),
-                    ..
-                },
+                hir::Expr { hir_id, span, kind: hir::ExprKind::Path(qpath), .. },
                 _,
-            ) => (call_span, *span, Some(of)),
+            ) => {
+                if let Res::Def(DefKind::Ctor(of, _), _) =
+                    self.typeck_results.borrow().qpath_res(qpath, *hir_id)
+                {
+                    (call_span, *span, Some(of))
+                } else {
+                    (call_span, *span, None)
+                }
+            }
             hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None),
             hir::ExprKind::MethodCall(path_segment, _, span) => {
                 let ident_span = path_segment.ident.span;
diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr
index 5467f61bee4..a922d7a5e41 100644
--- a/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr
+++ b/src/test/ui/type-alias-enum-variants/enum-variant-generic-args.stderr
@@ -7,7 +7,7 @@ LL |     fn ts_variant() {
 LL |         Self::TSVariant(());
    |         --------------- ^^ expected type parameter `T`, found `()`
    |         |
-   |         arguments to this function are incorrect
+   |         arguments to this enum variant are incorrect
    |
    = note: expected type parameter `T`
                    found unit type `()`
@@ -55,7 +55,7 @@ LL | impl<T> Enum<T> {
 LL |         Self::<()>::TSVariant(());
    |         --------------------- ^^ expected type parameter `T`, found `()`
    |         |
-   |         arguments to this function are incorrect
+   |         arguments to this enum variant are incorrect
    |
    = note: expected type parameter `T`
                    found unit type `()`
diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs
index d012687533b..3a8712f2ae5 100644
--- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs
+++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.rs
@@ -18,6 +18,6 @@ impl E2 {
 }
 
 fn main() {
-    <E>::V(); //~ ERROR this function takes 1 argument but 0 arguments were supplied
+    <E>::V(); //~ ERROR this enum variant takes 1 argument but 0 arguments were supplied
     let _: u8 = <E2>::V; //~ ERROR mismatched types
 }
diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr
index 6ae2aa1dc77..006253f8432 100644
--- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr
+++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr
@@ -1,4 +1,4 @@
-error[E0061]: this function takes 1 argument but 0 arguments were supplied
+error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
   --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:21:5
    |
 LL |     <E>::V();