-
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
Fix NLL issue 50716 and add a regression test. #51139
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
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.
I think the test needs to either be moved to the ui/
directory (and a corresponding .stderr
file is then also added to the PR), or it needs an explicit #![feature(nll)]
. As it stands right now I don’t think it’s actually testing the code you’ve added.
Good catch @pnkfelix! I have updated the test. |
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.
Sorry for ping-ponging!
for<'b> &'b T: A, | ||
<&'static T as A>::X: Sized | ||
{ | ||
let _x = *s; //~ ERROR free region `'a` does not outlive free region `'static` |
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.
the compile-fail
test directory is basically deprecated... I'd prefer this to be in src/test/ui/nll/
=)
(I took the liberty of moving the test in the fashion that @nikomatsakis requested, and plan to r+ it if travis accepts it.) |
(I could have also removed the |
@pnkfelix Thanks! |
@bors r+ |
📌 Commit 415a10f has been approved by |
🔒 Merge conflict |
@bors r+ |
📌 Commit 61f55d2 has been approved by |
⌛ Testing commit 61f55d2d61cd9ca6e6965e3d4108d696d5afc785 with merge 89ff7f5155b59426b0428d4800bb6e96fb0bb8b4... |
💔 Test failed - status-appveyor |
@pnkfelix @nikomatsakis The error we got on bors looks very similar to the one I was getting during the Rust Fest:
Do you have any idea how to investigate it? |
@michaelwoerister do we use incremental on bors ? presumably not... |
(No reason to blame incremental per se) |
@vakaras I don't know but it does seem like it could be related to this PR — after all, you added an obligation to prove |
@vakaras: Do you think you'll be able to investigate this issue? It looks like compiling |
@TimNN I am not sure I understand well enough what is happening here to investigate this issue properly. However, I will try at least to reproduce the error on my machine. |
@TimNN Thanks! You were right, the following steps reproduce the issue: git clone https://github.com/vakaras/rust.git -b issue-50716 issue-50716
cd issue-50716/
./x.py build
./x.py test src/tools/cargotest src/tools/cargo I will try to investigate this issue. |
@bors r- Wrongly requeued |
@nikomatsakis The minimal not working example (taken from linked-hash-map): struct Qey<Q: ?Sized>(Q); Do you have any idea what could be wrong here? Full repro steps:
|
@vakaras I guess that the problem comes from the "auto-generated" MIR for the constructor of fn Qey(_1: Q) -> Qey<Q>{
let mut _0: Qey<Q>; // return place
bb0: {
(_0.0: Q) = move _1; // bb0[0]: scope 0 at src/main.rs:1:1: 1:26
return; // bb0[1]: scope 0 at src/main.rs:1:1: 1:26
}
} You can see that this does I can think of two fixes. One might be to skip borrowck for such generated code -- in fact, we should probably do that just for performance reasons. The other would be to modify the generated code to carry an extended environment. While more correct, I'm not inclined to do that just because it's complicated. To skip this we would probably want to modify rust/src/librustc_mir/borrow_check/mod.rs Lines 79 to 84 in 2a1c4ee
Maybe we should add some code that checks if the variable Lines 521 to 523 in 2a1c4ee
This might look like: /// True if this def-id refers to the implicit constructor for a tuple struct like `struct Foo(u32)`
pub fn is_struct_constructor(self, def_id: DefId) -> bool {
self.def_key(def_id).disambiguated_data.data == DefPathData::StructCtor
} (What this is doing is looking up, via Then we can modify MIR borrowck to return early if Also, let's add this as a test case =) |
@nikomatsakis I have tried to implement your suggestions here. However, it does not seem to fix the issue and for some reason affects the reported error spans in two tests. |
I think I finally understood why it still crashes. The fix in the pull request fixes only when NLL is used. However, when the old borrow checker is used, the MIR is still type checked by this code: rust/src/librustc_mir/borrow_check/nll/type_check/mod.rs Lines 1708 to 1740 in c208243
I will try to implement the same early return for this function too. |
// The problem here is that `(_0.0: Q) = move _1;` is valid only if `Q` is | ||
// of statically known size, which is not known to be true because of the | ||
// `Q: ?Sized` constraint. However, it is true because the constructor can be | ||
// called only when `Q` is of statically known size. |
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.
Nice comment =)
@bors r+ |
📌 Commit 03ecd98 has been approved by |
Fix NLL issue 50716 and add a regression test. Fix for NLL issue #50716. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Fix for NLL issue #50716.
r? @nikomatsakis