-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustc_typeck: enforce argument type is sized #42642
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! just one minor nit.
src/librustc_typeck/check/mod.rs
Outdated
// Check the pattern. | ||
fcx.check_pat_arg(&arg.pat, arg_ty, true); | ||
|
||
// Check that argument is Sized. | ||
// Hack to avoid duplicate warnings for simple cases like `fn foo(x: Trait)`, where we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you modify this to say "the check for a non-trivial pattern is a hack to avoid..."? Otherwise, it seems like this whole test is a hack, which isn't quite right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it.
@nikomatsakis I have fixed the comment. |
@bors r+ Nice! |
📌 Commit 589a377 has been approved by |
@nikomatsakis A run-pass test failed in CI. [00:54:08] error[E0277]: the trait bound `<Self as std::ops::Deref>::Target: std::marker::Sized` is not satisfied
[00:54:08] --> /checkout/src/test/run-pass/associated-types-sugar-path.rs:19:29
[00:54:08] |
[00:54:08] 19 | fn baz(_: Self::Target) where Self: Deref {}
[00:54:08] | ^ `<Self as std::ops::Deref>::Target` does not have a constant size known at compile-time
[00:54:08] |
[00:54:08] = help: the trait `std::marker::Sized` is not implemented for `<Self as std::ops::Deref>::Target`
[00:54:08] = help: consider adding a `where <Self as std::ops::Deref>::Target: std::marker::Sized` bound
[00:54:08]
[00:54:08] error: aborting due to previous error(s) |
@bors r- |
I do not think this code should type-check. But I do think it's probably worth doing a crater run -- we may need a warning cycle here. |
Commenced crater run:
|
Crater report:
Coverage
Root regressions, sorted by rank:
|
Everything appears to be false positives. @venkatagiri I think we're good to go, if you just want to adjust that failing test. |
@nikomatsakis An UI test is failing now. src/test/ui/type-check/unknown_type_for_closure.rs. Error difference is below. Should my PR be affecting this type error? diff of stderr:
error[E0282]: type annotations needed
- --> $DIR/unknown_type_for_closure.rs:12:14
+ --> $DIR/unknown_type_for_closure.rs:12:17
|
12 | let x = |_| { };
- | ^ consider giving this closure parameter a type
+ | ^ cannot infer type for `_`
error: aborting due to previous error(s)
|
@venkatagiri hmm. So I'm a bit surprised that this code would be affected, but it's certainly possible. What's going wrong in this particular case is that the type of this argument is an uninferred type variable (i.e., unconstrained). There is some logic here that tries to special-case |
@nikomatsakis The |
Ah, very interesting. Can you maybe add a |
|
So the problem is that |
@arielb1 Could you please provide some mentoring instructions on how I can go about plumbing the body of function through |
The "body of a function" - the "code" within a function's block - is represented by a BodyId. fn main()
{ // we want this body
let x = |_|
{ // but currently we get this, which misses the _ arg
};
} We need to pass
Then you'll only need to pass that
You can pass the |
yeah that's sort of what I expected
Not very hard, I suppose. However, looking at the closure body-id should also be ok, I would think, since the body actually contains the patterns for the parameters; it might just be a matter of tweaking the visitor? |
Still, I do eventually plan to remove the body-id from its current position, so threading the body-id down is probably a good idea. |
The body is just the expression and does not include the signature. In any case, there could be |
@arielb1 yes, ok |
@venkatagiri I see that @arielb1 left some pretty good instructions here -- GH wasn't showing me those at first, or I failed to refresh anyway -- but I agree with the plan he laid out for how to fix it. |
@arielb1 Thanks for the detailed instructions. I have updated the PR with the changes. But, now, there is another fn main() {
let ex = |x| { // Error is thrown for x and below error is missing.
let_(add(x,x), |y| { //~ ERROR type annotations needed
let_(add(x, x), |x|x)})};
} |
@venkatagiri that seems fine; I think you can just update the test and move the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks nice :)
@bors r+ |
📌 Commit 5ed21f5 has been approved by |
rustc_typeck: enforce argument type is sized closes #42312 r? @nikomatsakis
💔 Test failed - status-travis |
rustc_typeck: enforce argument type is sized closes #42312 r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
closes #42312
r? @nikomatsakis