Skip to content
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

Merged
merged 8 commits into from
Aug 25, 2017
Merged

Conversation

gaurikholkar-zz
Copy link

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

return false;
};

if let Some(error_label) = self.process_anon_anon_conflict(first_is_struct, second_is_struct) {
Copy link
Member

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.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Aug 6, 2017

You'll have a conflict with #43699. Change E0623 to E0624 please.

EDIT: woups, nevermind. I'm the one who's in the wrong here.

@gaurikholkar-zz gaurikholkar-zz force-pushed the struct_lifetimes branch 2 times, most recently from 98189ad to 5cf4f2a Compare August 6, 2017 18:36
is_arg2_struct: bool)
-> Option<(String)> {
let arg1_label = {
if is_arg1_struct && is_arg2_struct {
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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`
Copy link
Contributor

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
Copy link
Contributor

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

@gaurikholkar-zz
Copy link
Author

gaurikholkar-zz commented Aug 7, 2017

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 two types are declared with different lifetimes...
15 |     x.push(y);
   |            ^ ...but data from `y` flows into `x` here

error: aborting due to previous error

Generalized the error message after a discussion with @nikomatsakis. @estebank updated PR.

@arielb1
Copy link
Contributor

arielb1 commented Aug 8, 2017

Maybe it would scale better to attach spans to anonymous lifetimes in resolve_lifetime?

@arielb1 arielb1 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2017
@gaurikholkar-zz
Copy link
Author

gaurikholkar-zz commented Aug 9, 2017

Fixed tidy checks

@gaurikholkar-zz
Copy link
Author

gaurikholkar-zz commented Aug 11, 2017

@nikomatsakis @estebank @arielb1 @kennytm Needed help with writing examples for the cases where both the regions are anonymous and the anonymous region is in

1. self
2. return type
3. case of trait impls

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.
My examples self and
return-type

As per the logs I generated, for the above to examples, they seem to return a false value at
this line it returns a false here i.e. for the function find_anon_type().
I also need to add NodeImplItem(it) and NodeTraitItem(it) checks here and I doubt that is causing a problem here. Also, for the case of trait impls, I have the following example which gives the same error as above(I'm hoping adding a NodeImplItem will fix that though)

trait Foo {
    fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8);
}
impl Foo for () {

    fn foo(x: &mut Vec<&u8>, y: &u8) {
       x.push(y);
   }
}

EDIT - Turns out the report_anon_anon_conflict method was incomplete and didn't have checks for NodeImplItems and NodeTraitItems. Working now :)

@gaurikholkar-zz gaurikholkar-zz force-pushed the struct_lifetimes branch 3 times, most recently from 11ddeb4 to 8da0aed Compare August 11, 2017 18:45
@@ -0,0 +1,22 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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",
}
}
}
}
Copy link
Contributor

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.

@estebank
Copy link
Contributor

https://travis-ci.org/rust-lang/rust/jobs/263641387#L1240

[00:19:55] error: variable does not need to be mutable
[00:19:55]    --> /checkout/src/librustc/infer/error_reporting/anon_anon_conflict.rs:261:21
[00:19:55]     |
[00:19:55] 261 |                 let mut subvisitor = &mut TyPathVisitor {
[00:19:55]     |                     ^^^^^^^^^^^^^^
[00:19:55]     |
[00:19:55] note: lint level defined here
[00:19:55]    --> /checkout/src/librustc/lib.rs:23:9
[00:19:55]     |
[00:19:55] 23  | #![deny(warnings)]
[00:19:55]     |         ^^^^^^^^
[00:19:55]     = note: #[deny(unused_mut)] implied by #[deny(warnings)]
[00:19:55] 
[00:19:56] error: aborting due to previous error
[00:19:56] 
[00:19:56] error: Could not compile `rustc`.
[00:19:56] 

@kennytm
Copy link
Member

kennytm commented Aug 12, 2017

@gaurikholkar: the CI failure that @estebank mentioned still exists in 1ed03e7...

@gaurikholkar-zz gaurikholkar-zz force-pushed the struct_lifetimes branch 2 times, most recently from 0239364 to 591b8f6 Compare August 13, 2017 11:05
@gaurikholkar-zz
Copy link
Author

@kennytm I changed it to let subvisitor = &mut TyPathVisitor { but it is still giving the same error. Also the variable is being used here - if subvisitor.found_it {. Doesn't it have to be mutable?

@gaurikholkar-zz
Copy link
Author

gaurikholkar-zz commented Aug 13, 2017

@nikomatsakis Also, the E0623 is enabled for trait impls too. With the code changes, E0611 which was disabled for impls is enabled again, hence the ui output changed here Fixed this :D

@kennytm
Copy link
Member

kennytm commented Aug 13, 2017

@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 subvisitor as mut since you are not mutating subvisitor itself. Reading subvisitor.found_it is not a mutation.

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() {
Copy link
Member

@kennytm kennytm Aug 13, 2017

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Author

@gaurikholkar-zz gaurikholkar-zz Aug 23, 2017

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?

@arielb1
Copy link
Contributor

arielb1 commented Aug 21, 2017

Ok by me modulo nits - I'll fix the binder trouble myself

@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2017
@gaurikholkar-zz
Copy link
Author

@arielb1 updated


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)) =
Copy link
Contributor

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

Copy link
Author

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

@nikomatsakis
Copy link
Contributor

We decided to do more "flattening" as a separate PR.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2017

📌 Commit cb563a9 has been approved by nikomatsakis

@kennytm
Copy link
Member

kennytm commented Aug 23, 2017

@nikomatsakis Needs re-r+ after the CI actually passes.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 25, 2017

📌 Commit 2cd1318 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Aug 25, 2017

⌛ Testing commit 2cd1318 with merge a4d1149...

bors added a commit that referenced this pull request Aug 25, 2017
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
@bors
Copy link
Contributor

bors commented Aug 25, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing a4d1149 to master...

@bors bors merged commit 2cd1318 into rust-lang:master Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants