Skip to content

Commit dc6b167

Browse files
committed
Rollup merge of #50257 - estebank:fix-49560, r=nikomatsakis
Don't ICE on tuple struct ctor with incorrect arg count Fix #49560.
2 parents e598394 + d92d193 commit dc6b167

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/librustc/traits/error_reporting.rs

+6
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
979979
ArgKind::Arg(format!("{}", field.name), "_".to_string())
980980
}).collect::<Vec<_>>())
981981
}
982+
hir::map::NodeStructCtor(ref variant_data) => {
983+
(self.tcx.sess.codemap().def_span(self.tcx.hir.span(variant_data.id())),
984+
variant_data.fields()
985+
.iter().map(|_| ArgKind::Arg("_".to_owned(), "_".to_owned()))
986+
.collect())
987+
}
982988
_ => panic!("non-FnLike node found: {:?}", node),
983989
}
984990
}

src/test/ui/mismatched_types/closure-arg-count.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ fn main() {
3939

4040
let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
4141
//~^ ERROR function is expected to take
42+
43+
call(Foo);
44+
//~^ ERROR function is expected to take
4245
}
4346

4447
fn foo() {}
4548
fn qux(x: usize, y: usize) {}
49+
50+
fn call<F, R>(_: F) where F: FnOnce() -> R {}
51+
struct Foo(u8);

src/test/ui/mismatched_types/closure-arg-count.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
116116
LL | let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
117117
| ^^^ expected function that takes 1 argument
118118

119-
error: aborting due to 12 previous errors
119+
error[E0593]: function is expected to take 0 arguments, but it takes 1 argument
120+
--> $DIR/closure-arg-count.rs:43:5
121+
|
122+
LL | call(Foo);
123+
| ^^^^ expected function that takes 0 arguments
124+
...
125+
LL | struct Foo(u8);
126+
| --------------- takes 1 argument
127+
|
128+
note: required by `call`
129+
--> $DIR/closure-arg-count.rs:50:1
130+
|
131+
LL | fn call<F, R>(_: F) where F: FnOnce() -> R {}
132+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
134+
error: aborting due to 13 previous errors
120135

121136
For more information about this error, try `rustc --explain E0593`.

0 commit comments

Comments
 (0)