-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
NLL: disallow creation of immediately unusable variables #54188
Conversation
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
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.
What do you think @lqd -- up for slightly more invasive edits?
@@ -10,15 +10,16 @@ LL | }; | |||
error[E0597]: `a` does not live long enough | |||
--> $DIR/borrowing.rs:24:9 | |||
| | |||
LL | let _b = { | |||
| -- borrow later used here |
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.
So this message is generated here:
"borrow later used here" |
Given that we have the location in the MIR in the location
variable, it would be quite trivial for us to determine if this is a ReadForMatch
statement. The only catch is that we use this same statement both for matches and for this. If we refactor ReadForMatch
to be something like this:
FakeRead(FakeReadCause, Place<'tcx>),
with
enum FakeReadCause {
ForMatch,
ForLet,
}
then we could match on this particular case and give a different message. Perhaps something like
-- borrowed value is then later stored into this variable
This comment has been minimized.
This comment has been minimized.
08f419b
to
9f76655
Compare
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.
Left a minor nit, but this looks good!
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] | ||
pub enum FakeReadCause { | ||
ForMatch, | ||
ForLet, |
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.
Let's add some comments and links here.
I think the best option is to move the comments from the point of insertion to here, and then (in those spots) just refer to
// See comments on `FakeReadCause::ForLet
This is also good because we may insert fake read from multiple places, but this centralizes the comment in one clearly identifiable location.
// Check if the location represents a `FakeRead`, and adapt the error | ||
// message to the `FakeReadCause` it is from: in particular, | ||
// the ones inserted in optimized `let var = <expr>` patterns. | ||
let is_fake_read_for_let = match self.mir.basic_blocks()[location.block] |
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.
extract to a helper function...somewhere? lots of random code for this.
// but in some cases it can affect the borrow checker, as in #53695. | ||
// Therefore, we insert a "fake read" here to ensure that we get | ||
// appropriate errors. | ||
// |
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 is the comment I would move
@@ -157,7 +157,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { | |||
*pre_binding_block, | |||
Statement { | |||
source_info: pattern_source_info, | |||
kind: StatementKind::ReadForMatch(borrow_temp.clone()), | |||
kind: StatementKind::FakeRead(FakeReadCause::ForMatch, borrow_temp.clone()), |
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.
presumably this has a decent-ish comment attached to it, too
This comment has been minimized.
This comment has been minimized.
I've pushed the updated comments, and helper function. Note: I haven't updated 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.
Looks good so far!
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
(for anyone possibly not on zulip and following at home: |
@bors r+ |
📌 Commit c7587c0aa117894910e9a3cd3c39e9c926ae2a68 has been approved by |
☔ The latest upstream changes (presumably #54319) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
cc @michaelwoerister : the above travis failure seems to be a linking problem connected to codegen-units; any advice about how to address this? Update: further investigation indicates that this bug may indeed be due to a combination of the change added by this PR, plus an unfortunate codegen-unit partitioning inhibiting LLVM's ability to optimize the uses of |
also nominating to discuss in compiler team meeting how best to address such codegen-units+linker problems when they arise (e.g., how to help contributors deal with such problems, either by mentoring them through the problems, or guiding them in how to delegate to specialists in the area) Some of my questions:
|
(also, I/we are confused about the expected behavior of running Update: Filed separate issue regarding this question to #54388. |
(removing I-nominated tag; will raise question of how to deal with these kinds of test failures with compiler team asynchronously.) |
@lqd okay, based on the discussion regarding #54388, I think you should comment out the After that, I'll just make a PR that fixes the test to make its |
`src/test/ui/extern/extern-const.rs` seems to have an inconsistent behaviour across build configurations, possibly non-deterministically. This is tracked in issue 54388. For this PR, disable running rustfix on it because it failed on CI, until that issue is fixed.
I've pushed a commit which "unrustfixes" (rustbreaks?) this test |
@bors r+ |
📌 Commit 3bdba74 has been approved by |
@bors r=nikomatsakis |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 3bdba74 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Fix #53695
Original description follows
This WIP PR is for discussing the impact of fixing #53695 by injecting a fake read in let patterns.
(Travis will fail, at least the
mir-opt
suite is failing in its current state)