Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ICE on tuple struct ctor with incorrect arg count #50257

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
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),
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/mismatched_types/closure-arg-count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
17 changes: 16 additions & 1 deletion src/test/ui/mismatched_types/closure-arg-count.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.