-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Extend E0623 for LateBound and EarlyBound Regions #44079
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
5823310
to
3665a7f
Compare
☔ The latest upstream changes (presumably #43700) made this pull request unmergeable. Please resolve the merge conflicts. |
Based on this and the merge conflicts, I'm going to treat this as a kind of WIP. |
@shepmaster the first commit was #43700 itself which just got merged. I'll fix the merge conflicts and the compile - tests now |
1c9d960
to
b8559a5
Compare
6cdae88
to
a944650
Compare
@arielb1 can you review this please. The error code works fine for LateBound, not working yet for EarlyBound. |
@nikomatsakis can you please review the compile-fail tests? |
if debruijn_index.depth == 1 && anon_index == br_index { | ||
self.found_type = Some(arg); | ||
return; // we can stop visiting now | ||
match self.bound_region { |
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.
style: you could do a
match (self.infcx.tcx.named_region_map.defs.get(&lifetime.id),
self.bound_region) {
(Some(&rl::Region::LateBoundAnon(debruijn_index, anon_index)),
ty::BrAnon(br_index)) => {
// ..
}
// ..
}
} | ||
return true; | ||
} | ||
} | ||
} |
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.
style: no newline at end of file
.as_local_node_id(suitable_region_binding_scope) | ||
.unwrap(); | ||
let mut is_impl_item = false; | ||
match self.tcx.hir.find(node_id) { |
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.
style:
let is_impl_item = match self.tcx.hir.find(node_id) {
Some(hir_map::NodeItem(..)) |
Some(hir_map::NodeTraitItem(..)) => {
false
}
Some(hir_map::NodeImplItem(..)) => {
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
}
_ => return None
};
@@ -40,7 +40,6 @@ fn with_assoc<'a,'b>() { | |||
// We get an error because 'b:'a does not hold: | |||
|
|||
let _: &'a WithHrAssoc<TheType<'b>> = loop { }; |
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.
Where did the error go?
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.
Does this code compile with your patch? Could you try to figure out why an error is not generated?
} | ||
|
||
fn call<T>() { } | ||
|
||
fn main() { | ||
} | ||
}p |
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.
stray p
in program
| ^ ...but data from `y` flows into `x` here | ||
|
||
error: aborting due to previous error | ||
|
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.
Also add a test for early-bound regions (using the 'static: 'a
, 'static: 'b
trick?)
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 example we had discussed with where clause and sized trait doesn't seem to be working. So.still trying to get the code working for early bound
I would say r=me after style fixes, but WTF is happening with the error messages? |
@arielb some of the tests keep failing, I fixed them but they failed again. |
Are you on IRC? |
Afk for a few hours. @gkholkar on irc. |
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 few comments. This looks pretty nice altogether, though I am concerned about the "disappearing errors" that @arielb1 noted. That said, I see travis isn't passing, so maybe those errors are still being generated?
@@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
}; | |||
|
|||
// Determine whether the sub and sup consist of both anonymous (elided) regions. | |||
let anon_reg_sup = or_false!(self.is_suitable_anonymous_region(sup)); | |||
let anon_reg_sup = or_false!(self.is_suitable_region(sup)); |
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.
Maybe we should rename this variable, if it's not always anonymous? (For that matter, this file and fn?)
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.
How about both_params_anon_or_named_conflict.rs ?
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.
hmm, maybe something like different_lifetimes.rs
? (since this generates the "types declared with different lifetimes..." message)
@@ -193,4 +191,4 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
} | |||
false | |||
} | |||
} | |||
} |
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: newline at end of file
@@ -47,7 +47,7 @@ fn with_assoc<'a,'b>() { | |||
// outlive 'a. In this case, that means TheType<'b>::TheAssocType, | |||
// which is &'b (), must outlive 'a. | |||
|
|||
let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR reference has a longer lifetime | |||
let _: &'a WithAssoc<TheType<'b>> = loop { };//~ ERROR reference has a longer lifetime |
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: no need to remove this space, I'd say...
Status update: doesn't fully work for early bound regions yet. Have to investigate to see why. |
5442498
to
ef2f0e1
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.
Lookin' good! Left a few more nits. We have to solve the disappearing error problem, obviously.
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) { | ||
debug!("report_region_errors(): {} errors to start", errors.len()); | ||
|
||
// try to pre-process the errors, which will group some of them | ||
// together into a `ProcessedErrors` group: | ||
let errors = self.process_errors(errors); | ||
|
||
debug!("report_region_errors: {} errors after preprocessing", errors.len()); | ||
debug!("report_region_errors: {} errors after preprocessing", | ||
errors.len()); | ||
|
||
for error in errors { | ||
debug!("report_region_errors: error = {:?}", error); | ||
|
||
if !self.try_report_named_anon_conflict(&error) && | ||
!self.try_report_anon_anon_conflict(&error) { |
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.
we should rename try_report_anon_anon_conflict()
to try_report_different_lifetime_conflict()
// and returns the DefId and the BoundRegion corresponding to the given region. | ||
pub fn is_suitable_anonymous_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> { | ||
// This method returns the DefId and the BoundRegion corresponding to the given region. | ||
pub fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> { |
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.
Maybe we can call this is_suitable_free_region()
? Seems a touch more informative.
@@ -15,7 +15,7 @@ fn a<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) where 'b: 'a { | |||
|
|||
fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) { | |||
// Illegal now because there is no `'b:'a` declaration. | |||
*x = *y; //~ ERROR E0312 | |||
*x = *y; //~ ERROR E0623 |
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 =)
@@ -15,20 +15,16 @@ | |||
struct Paramd<'a> { x: &'a usize } | |||
|
|||
fn call2<'a, 'b>(a: &'a usize, b: &'b usize) { | |||
let z: Option<&'b &'a usize> = None; | |||
//~^ ERROR reference has a longer lifetime than the data it references | |||
let z: Option<&'b &'a usize> = None;//~ ERROR E0623 |
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 guess that the error in this case could be a touch misleading -- we'll say that "data flows from a
into b
here" or whatever, when in fact no dataflow actually occurs. This seems kind of like an edge case though. I'm inclined to leave it as is for now. We may want to reconsider in the future though. Maybe worth opening an issue about at some point.
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.
sure.
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.
Done
@@ -40,7 +40,6 @@ fn with_assoc<'a,'b>() { | |||
// We get an error because 'b:'a does not hold: | |||
|
|||
let _: &'a WithHrAssoc<TheType<'b>> = loop { }; | |||
//~^ ERROR reference has a longer lifetime |
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.
indeed, this error should not disappear -- when I investigated a bit, it appeared we were ICEing...?
@@ -61,7 +60,7 @@ fn with_assoc_sub<'a,'b>() { | |||
// below to be well-formed, it is not related to the HR relation. | |||
|
|||
let _: &'a WithHrAssocSub<TheType<'b>> = loop { }; | |||
//~^ ERROR reference has a longer lifetime |
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.
error should not disappear
@@ -42,7 +42,7 @@ fn with_assoc<'a,'b>() { | |||
// which is &'b (), must outlive 'a. | |||
|
|||
let _: &'a WithAssoc<TheType<'b>> = loop { }; | |||
//~^ ERROR reference has a longer lifetime |
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.
error should not disappear
} | ||
|
||
fn call_without_assoc<'a,'b>() { | ||
// As `without_assoc`, but in a distinct scenario. | ||
|
||
call::<&'a WithoutAssoc<TheType<'b>>>(); //~ ERROR reference has a longer lifetime | ||
call::<&'a WithoutAssoc<TheType<'b>>>(); |
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.
error should not disappear
@GuillaumeGomez, changed the diagnostics.rs for E0312 |
src/librustc/diagnostics.rs
Outdated
@@ -1383,38 +1383,6 @@ struct Foo<T: 'static> { | |||
``` | |||
"##, | |||
|
|||
E0312: r##" |
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 error E0312 still exists so why not writing its long error diagnostic instead of just removing the old one?
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.
At it. Just thought you should know.
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.
done
25fa4e8
to
44810d9
Compare
@bors r+ |
📌 Commit 1c304d2 has been approved by |
🔒 Merge conflict |
☔ The latest upstream changes (presumably #44142) made this pull request unmergeable. Please resolve the merge conflicts. |
f91c3fe
to
f2ac5dd
Compare
@bors r+ |
📌 Commit f2ac5dd has been approved by |
I was directed here from this comment. I may be missing what this message is trying to say, but it looks like the compiler should suggest an "outlives" annotation in this case.
The above message doesn't tell me what to do. I believe it is saying that
since Could this be modified to do so, or a new issue opened to add the Help message? |
1770e90
to
9caab73
Compare
9caab73
to
09d1a43
Compare
09d1a43
to
cfc7cf3
Compare
Thanks for the suggestion. =) This is tricky. This message is intended, in part, as a fallback message -- with the extended error ( |
@bors r+ |
📌 Commit 88e4bf6 has been approved by |
Extend E0623 for LateBound and EarlyBound Regions This is a fix for #43882 ``` fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) { x.push(y); } ``` now gives ``` error[E0623]: lifetime mismatch --> $DIR/ex3-both-anon-regions-latebound-regions.rs:12:12 | 11 | fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) { | ------ ------ these two types are declared with different lifetimes... 12 | x.push(y); | ^ ...but data from `y` flows into `x` here ``` cc @nikomatsakis @arielb1 Please ignore the second commit. It will be merged in a separate PR.
☀️ Test successful - status-appveyor, status-travis |
This is a fix for #43882
now gives
cc @nikomatsakis @arielb1
Please ignore the second commit. It will be merged in a separate PR.