-
Notifications
You must be signed in to change notification settings - Fork 13.4k
ICE defining function taking raw trait object #42312
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
Comments
cc @nikomatsakis More fallout from us not banning unsized argument types outright. |
This is supposed to fail in WF checking, I believe. That is, any actual function body should demand that the arguments types are sized. |
Well it's ignored as a pattern, that might have something to do with it. |
Good call, that's exactly it. It looks like we're missing some checks -- we should require that the arguments themselves are all sized, and not just the bindings. I'll note down some mentoring instructions. |
It seems like the right place to enforce this is when type-checking function bodies. Right now, that code does the following checks:
So I think what we need to do is to add a call to |
While we're at it, I think we can remove these lines. |
I would like to work on this. compile-fail/unsized6.rs is failing as same error is repeated twice. One pointing at the arguments and the other pointing at the function body(which is being created by my changes). error[E0277]: the trait bound `X: std::marker::Sized` is not satisfied
--> /home/vagrant/repos/rust/src/test/compile-fail/unsized6.rs:37:18
|
37 | fn g1<X: ?Sized>(x: X) {} //~ERROR `X: std::marker::Sized` is not satisfied
| ^ `X` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= help: consider adding a `where X: std::marker::Sized` bound
= note: all local variables must have a statically known size
error[E0277]: the trait bound `X: std::marker::Sized` is not satisfied
--> /home/vagrant/repos/rust/src/test/compile-fail/unsized6.rs:37:24
|
37 | fn g1<X: ?Sized>(x: X) {} //~ERROR `X: std::marker::Sized` is not satisfied
| ^ `X` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `X`
= help: consider adding a `where X: std::marker::Sized` bound compile-fail/issue-38954.rs is failing with below error when no error was expected before. error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
--> /home/vagrant/repos/rust/src/test/compile-fail/issue-38954.rs:13:23
|
13 | fn _test(ref _p: str) {}
| ^ `str` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str` |
Ah, I guess the problem is that we are adding (1) check on "the binding" and one check on the variable as a whole. That's kind of annoying. I kind of feel like we potentially need both checks; e.g., if you had something like We could avoid this in almost all cases via a simple hack, where we skip the new check if the pattern binding is simple (i.e., just some identifier
that should have been failing all along I think. You can just adjust the |
@nikomatsakis Thanks for the tip. Have opened #42642 with the fix. |
rustc_typeck: enforce argument type is sized closes #42312 r? @nikomatsakis
rustc_typeck: enforce argument type is sized closes #42312 r? @nikomatsakis
The following code:
Produces the following in the playground:
The text was updated successfully, but these errors were encountered: