-
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
Adding E0623 for structs #43700
Adding E0623 for structs #43700
Conversation
return false; | ||
}; | ||
|
||
if let Some(error_label) = self.process_anon_anon_conflict(first_is_struct, second_is_struct) { |
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 line has >100 chars.
EDIT: woups, nevermind. I'm the one who's in the wrong here. |
98189ad
to
5cf4f2a
Compare
is_arg2_struct: bool) | ||
-> Option<(String)> { | ||
let arg1_label = { | ||
if is_arg1_struct && is_arg2_struct { |
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.
Nitpick: This is a case where using match might match
can make the code cleaner and let you be assured that you're not missing a case (the let x = if
already emits an error for missing returns, but match
without matching on _
makes it clear that you didn't forget a case):
let arg1_label = match (is_arg1_struct, is_arg2_struct) {
(true, true) => "these structs".to_string(),
(true, false) => "the struct and reference".to_string(),
(false, true) => "the reference and the struct".to_string(),
(false, false) => "these references".to_string(),
}
} else if is_arg1_struct && !is_arg2_struct { | ||
format!("the struct and reference") | ||
} else if !is_arg1_struct && is_arg2_struct { | ||
format!("the reference and the struct") |
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.
different wording vs line 120
format!("these references") | ||
} | ||
}; | ||
Some(arg1_label) |
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.
There's no case where this method doesn't return Some
, so you can change the method's signature to return String
, instead of Option<String>
.
if subvisitor.found_it { | ||
self.is_struct = true; | ||
self.found_type = Some(arg); | ||
} else { |
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.
Empty else
clause, simply remove it.
_ => {} | ||
} | ||
// walk the embedded contents: e.g., if we are visiting `Vec<&Foo>`, | ||
// go on to visit `&Foo` |
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.
Why removing comments?
@@ -1,10 +0,0 @@ | |||
error[E0623]: lifetime mismatch |
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.
For other reviewers: ex3-both-anon-regions-3.rs
was moved to ex3-both-anon-regions-one-is-struct-2.rs
Generalized the error message after a discussion with @nikomatsakis. @estebank updated PR. |
a96ac00
to
529baac
Compare
Maybe it would scale better to attach spans to anonymous lifetimes in |
Fixed tidy checks |
5ef8486
to
6b08259
Compare
@nikomatsakis @estebank @arielb1 @kennytm Needed help with writing examples for the cases where
I have made the code changes for this but the ui tests I have added don't trigger the error the way I thought it would. As per the logs I generated, for the above to examples, they seem to return a false value at
EDIT - Turns out the |
11ddeb4
to
8da0aed
Compare
@@ -0,0 +1,22 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,22 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,20 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,17 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,17 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,17 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,19 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,19 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -0,0 +1,19 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Update copyright year
@@ -963,4 +963,4 @@ impl<'tcx> ObligationCause<'tcx> { | |||
_ => "types are compatible", | |||
} | |||
} | |||
} | |||
} |
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.
Revert trivial change to this file.
8da0aed
to
11ddeb4
Compare
https://travis-ci.org/rust-lang/rust/jobs/263641387#L1240
|
f636e43
to
1ed03e7
Compare
@gaurikholkar: the CI failure that @estebank mentioned still exists in 1ed03e7... |
0239364
to
591b8f6
Compare
@kennytm I changed it to |
@nikomatsakis Also, the |
@gaurikholkar I don't see any error from Travis about 591b8f6 yet (it is still running), so no conclusion. Perhaps the error is pointing to other places. You don't need to mark |
591b8f6
to
58cfc83
Compare
self.is_suitable_anonymous_region(sup).unwrap()) | ||
} else if sup.is_named_region() && self.is_suitable_anonymous_region(sub).is_some() { | ||
self.is_suitable_anonymous_region(sup, false).unwrap()) | ||
} else if sup.is_named_region() && self.is_suitable_anonymous_region(sub, false).is_some() { |
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 line is too long.
[00:03:12] tidy error: /checkout/src/librustc/infer/error_reporting/named_anon_conflict.rs:38: line longer than 100 chars
@@ -0,0 +1,19 @@ | |||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
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.
duplicate test?
@@ -0,0 +1,17 @@ | |||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
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.
duplicate test with previous (except x
and y
were replaced?)
@@ -0,0 +1,20 @@ | |||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
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.
duplicate test?
@@ -79,22 +106,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
|
|||
// This method returns whether the given Region is Anonymous | |||
// and returns the DefId and the BoundRegion corresponding to the given region. | |||
// The is_anon_anon is set true when we are dealing with cases where |
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.
Could you please store is_impl_item
in FreeRegionInfo
and branch on it instead of passing is_anon_anon
as a parameter? It being a parameter is confusing.
} | ||
Some(hir_map::NodeImplItem(..)) => { | ||
if let ty::BrAnon(..) = free_region.bound_region { | ||
let anonymous_region_binding_scope = free_region.scope; |
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.
Actually, this bunch of code only detects whether we are in an impl item. Could you extract it to an is_bound_region_in_impl_item
function and call it from whenever its needed?
// corresponds to self and if yes, we display E0312. | ||
// FIXME(#42700) - Need to format self properly to | ||
// enable E0621 for it. | ||
pub fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool { |
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.
{
is_first &&
self.tcx
.opt_associated_item(scope_def_id)
.map(|i| i.method_has_self_argument)
== Some(true)
}
anon_reg_sub.boundregion); | ||
if let (Some(anonarg_sup), Some(anonarg_sub)) = | ||
(self.find_anon_type(sup, &br_sup), self.find_anon_type(sub, &br_sub)) { | ||
(anonarg_sup, anonarg_sub, def_id_sup, def_id_sub, br_sup, br_sub) |
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 can return anon_reg_sup
& anon_reg_sub
.
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.
@arielb1 Are you saying use anon_reg_sup
instead of Some(anon_reg_sup)
. Can you elaborate on this please?
Ok by me modulo nits - I'll fix the binder trouble myself |
@arielb1 updated |
151b5bb
to
0f58e18
Compare
|
||
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub)); | ||
|
||
let (main_label, label1, label2) = if let (Some(sup_arg), Some(sub_arg)) = |
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 flatten these if let
constraints with or_else!
too? I hate to drag out this PR anymore though, so happy to do it as follow-up
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'll open up a separate PR for that
0f58e18
to
cb563a9
Compare
We decided to do more "flattening" as a separate PR. |
@bors r+ |
📌 Commit cb563a9 has been approved by |
@nikomatsakis Needs re-r+ after the CI actually passes. |
@bors r+ |
📌 Commit 2cd1318 has been approved by |
Adding E0623 for structs This is a fix to #43275 The error message is ``` +error[E0623]: lifetime mismatch + --> $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12 + | +14 | fn foo(mut x: Vec<Ref>, y: Ref) { + | --- --- these structs are declared with different lifetimes... +15 | x.push(y); + | ^ ...but data from `y` flows into `x` here + +error: aborting due to previous error ``` r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
This is a fix to #43275
The error message is
r? @nikomatsakis