Skip to content

Commit ceaeabf

Browse files
committed
Auto merge of #50298 - pietroalbini:beta-backports, r=oli-obk
[Beta] Process backports * #50257: Don't ICE on tuple struct ctor with incorrect arg count
2 parents 6eef61a + 6c07e81 commit ceaeabf

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
@@ -976,6 +976,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
976976
ArgKind::Arg(format!("{}", field.name), "_".to_string())
977977
}).collect::<Vec<_>>())
978978
}
979+
hir::map::NodeStructCtor(ref variant_data) => {
980+
(self.tcx.sess.codemap().def_span(self.tcx.hir.span(variant_data.id())),
981+
variant_data.fields()
982+
.iter().map(|_| ArgKind::Arg("_".to_owned(), "_".to_owned()))
983+
.collect())
984+
}
979985
_ => panic!("non-FnLike node found: {:?}", node),
980986
}
981987
}

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)