]> git.lizzy.rs Git - rust.git/commitdiff
Don't ICE on tuple struct ctor with incorrect arg count
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 26 Apr 2018 21:19:21 +0000 (14:19 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 26 Apr 2018 21:19:21 +0000 (14:19 -0700)
src/librustc/traits/error_reporting.rs
src/test/ui/mismatched_types/closure-arg-count.rs
src/test/ui/mismatched_types/closure-arg-count.stderr

index 33abc0c7e15aa4a58dfb2afc75e18306055fcd60..3eb45439001cd16298fd037056b8b5819fb5d536 100644 (file)
@@ -976,6 +976,12 @@ pub fn get_fn_like_arguments(&self, node: hir::map::Node) -> (Span, Vec<ArgKind>
                      ArgKind::Arg(format!("{}", field.name), "_".to_string())
                  }).collect::<Vec<_>>())
             }
+            hir::map::NodeStructCtor(ref variant_data) => {
+                (self.tcx.sess.codemap().def_span(self.tcx.hir.span(variant_data.id())),
+                 variant_data.fields()
+                    .iter().map(|_| ArgKind::Arg("_".to_owned(), "_".to_owned()))
+                    .collect())
+            }
             _ => panic!("non-FnLike node found: {:?}", node),
         }
     }
index 34232e81cbdeef0a5a5bff568fc08d9a383850c0..9eb11148a8bcef45200484c0163c2371927fe782 100644 (file)
@@ -39,7 +39,13 @@ fn main() {
 
     let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
     //~^ ERROR function is expected to take
+
+    call(Foo);
+    //~^ ERROR function is expected to take
 }
 
 fn foo() {}
 fn qux(x: usize, y: usize) {}
+
+fn call<F, R>(_: F) where F: FnOnce() -> R {}
+struct Foo(u8);
index 6451c0d06fa2094ca9c89e16cd5e047b1baf7fc8..6270e794498766f17fcba58f4b3e8e130e07b981 100644 (file)
@@ -116,6 +116,21 @@ error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
 LL |     let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
    |                                         ^^^ expected function that takes 1 argument
 
-error: aborting due to 12 previous errors
+error[E0593]: function is expected to take 0 arguments, but it takes 1 argument
+  --> $DIR/closure-arg-count.rs:43:5
+   |
+LL |     call(Foo);
+   |     ^^^^ expected function that takes 0 arguments
+...
+LL | struct Foo(u8);
+   | --------------- takes 1 argument
+   |
+note: required by `call`
+  --> $DIR/closure-arg-count.rs:50:1
+   |
+LL | fn call<F, R>(_: F) where F: FnOnce() -> R {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 13 previous errors
 
 For more information about this error, try `rustc --explain E0593`.