]> git.lizzy.rs Git - rust.git/commitdiff
Point at variant on pattern field count mismatch
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 5 Sep 2019 02:04:26 +0000 (19:04 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 5 Sep 2019 02:04:44 +0000 (19:04 -0700)
src/librustc_typeck/check/pat.rs
src/test/ui/error-codes/E0023.stderr
src/test/ui/match/match-pattern-field-mismatch.stderr
src/test/ui/pattern/pat-tuple-overfield.stderr
src/test/ui/pattern/pattern-error-continue.stderr

index 4cf0df308fb4c7efec9b19cabef93826b77a2bae..9a3f5e9e1b5d835718219ca798b14f071ac1ee6a 100644 (file)
@@ -677,12 +677,14 @@ fn check_pat_tuple_struct(
         } else {
             let subpats_ending = if subpats.len() == 1 { "" } else { "s" };
             let fields_ending = if variant.fields.len() == 1 { "" } else { "s" };
+            let span = tcx.def_span(res.def_id());
             struct_span_err!(tcx.sess, pat.span, E0023,
                              "this pattern has {} field{}, but the corresponding {} has {} field{}",
                              subpats.len(), subpats_ending, res.descr(),
                              variant.fields.len(),  fields_ending)
                 .span_label(pat.span, format!("expected {} field{}, found {}",
                                               variant.fields.len(), fields_ending, subpats.len()))
+                .span_label(span, format!("{} defined here", res.descr()))
                 .emit();
             on_error();
             return tcx.types.err;
index 1bc90a995fe3077e75d491bae90beff64047a6e4..d04e494c2585c0e8b342b1d5cea5b1e364bd61d9 100644 (file)
@@ -1,18 +1,27 @@
 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
   --> $DIR/E0023.rs:10:9
    |
+LL |     Apple(String, String),
+   |     --------------------- tuple variant defined here
+...
 LL |         Fruit::Apple(a) => {},
    |         ^^^^^^^^^^^^^^^ expected 2 fields, found 1
 
 error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
   --> $DIR/E0023.rs:11:9
    |
+LL |     Apple(String, String),
+   |     --------------------- tuple variant defined here
+...
 LL |         Fruit::Apple(a, b, c) => {},
    |         ^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3
 
 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
   --> $DIR/E0023.rs:12:9
    |
+LL |     Pear(u32),
+   |     --------- tuple variant defined here
+...
 LL |         Fruit::Pear(1, 2) => {},
    |         ^^^^^^^^^^^^^^^^^ expected 1 field, found 2
 
index 663cd2cd24d56c02ce19d7172f949094d14832ed..c2298d6fbbf02a34dc50bc17df8b46781a5f3669 100644 (file)
@@ -1,6 +1,9 @@
 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields
   --> $DIR/match-pattern-field-mismatch.rs:10:11
    |
+LL |         Rgb(usize, usize, usize),
+   |         ------------------------ tuple variant defined here
+...
 LL |           Color::Rgb(_, _) => { }
    |           ^^^^^^^^^^^^^^^^ expected 3 fields, found 2
 
index 0430897510b85e4ad46faadfdf5a1ba566d2c690..e64b6efb08da8fabcdd34ae064e9d05608b8faef 100644 (file)
@@ -19,12 +19,18 @@ LL |         (1, 2, .., 3, 4) => {}
 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields
   --> $DIR/pat-tuple-overfield.rs:10:9
    |
+LL | struct S(u8, u8, u8);
+   | --------------------- tuple struct defined here
+...
 LL |         S(1, 2, 3, 4) => {}
    |         ^^^^^^^^^^^^^ expected 3 fields, found 4
 
 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields
   --> $DIR/pat-tuple-overfield.rs:12:9
    |
+LL | struct S(u8, u8, u8);
+   | --------------------- tuple struct defined here
+...
 LL |         S(1, 2, .., 3, 4) => {}
    |         ^^^^^^^^^^^^^^^^^ expected 3 fields, found 4
 
index a581f07496e6cf2ffec99bf9e87e3b434cb07c0c..4fbc630644baa5854bee04812f7fb6c39acc1b23 100644 (file)
@@ -15,6 +15,9 @@ LL |         A::D(_) => (),
 error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
   --> $DIR/pattern-error-continue.rs:17:9
    |
+LL |     B(isize, isize),
+   |     --------------- tuple variant defined here
+...
 LL |         A::B(_, _, _) => (),
    |         ^^^^^^^^^^^^^ expected 2 fields, found 3