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

Improve SubSupConflict with a named and an anonymous lifetime parameter #42701 #44167

Merged
merged 7 commits into from
Nov 12, 2017
Merged

Conversation

cengiz-io
Copy link
Contributor

@cengiz-io cengiz-io commented Aug 29, 2017

Hello!

This fixes #42701.

UPDATE 01

Tests are producing different results between different env builds.
This inconsistency might take a long time to investigate and fix. So, be patient

UPDATE 02

Changed an FxHashMap with a BTreeMap. Inconsistency seems to be resolved for now.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -0,0 +1,41 @@
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42700
The first snippet of code, that's how the ui test must output

@@ -0,0 +1,24 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is of type ConcreteFailure, not SubSupConflict

pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
let (span, sub, sup) = match *error {
ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
_ => return false, // inapplicable
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to remove the is_self_anon check. Maybe you can try an example without self, that should work.

@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

I think this is a good test case:

struct Foo {
    field: i32,
}

fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
    if true {
        let p: &i32 = &a.field;
        &*p
    } else {
        &*x
    }
}

fn main() { }

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 31, 2017
@arielb1
Copy link
Contributor

arielb1 commented Sep 5, 2017

Hi @cengizio! Nice PR! Can you add @nikomatsakis's test so we can see how the errors look and fix this?

@gaurikholkar-zz
Copy link

@nikomatsakis can you suggest a test case for anon_anon conflicts too?

@nikomatsakis
Copy link
Contributor

@gaurikholkar I guess that's a bit harder. If you just remove the named lifetime, then the elision rules will fail. You can use an &self to still create a conflict, but then we get into the rules that disable anon-anon reporting around self, I believe.

@bors
Copy link
Contributor

bors commented Sep 10, 2017

☔ The latest upstream changes (presumably #44079) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

@cengizio

Maybe try this example too?

struct Foo {
    field: i32, 
}

fn foo2<'a, 'b>(a: &'a Foo, x: &'b i32) -> &'a i32 {
    if true {
        let p: &i32 = &a.field;
        &*p
    } else {
        &*x
    }
}

fn main() { }

I imagine this will exercise the "different lifetimes" code a bit.

@arielb1
Copy link
Contributor

arielb1 commented Sep 19, 2017

You have a tidy error:

[00:03:51] tidy error: /checkout/src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.rs:12: trailing whitespace

@arielb1
Copy link
Contributor

arielb1 commented Sep 26, 2017

This PR is basically ready to land, you just have to fix the tidy error. Just a ping to make sure this isn't getting lost.

@cengiz-io
Copy link
Contributor Author

Hello @arielb1

Thanks for notifying. I'm still trying to resolve this example case #44167 (comment)

Whenever that finishes, I'll fix tidy error and push them.

@cengiz-io
Copy link
Contributor Author

cengiz-io commented Sep 26, 2017

Just fixed tidy error.

Also, while rebasing, it turned out to change 3 ui tests. I'm not sure about this because it was an implicit change. 314bb98

@nikomatsakis maybe can shed some light to this implicit change

@cengiz-io
Copy link
Contributor Author

There seems to be some changes which are breaking other tests also. Back to the drawing board...

@nikomatsakis
Copy link
Contributor

@cengizio those 3 ui tests appear to be bug fixes =) that is, thanks to your change, the 'new and improved' errors are triggering more often. seems good!

@nikomatsakis
Copy link
Contributor

@cengizio also those test errors are not unexpected. I think you just have to update the tests to change them to expect the new error message. However, these tests are a bit surprising to me:

object-lifetime-default-from-box-error.rs
issue-40288-2.rs

I'm not sure what's up with those two cases!

@cengiz-io
Copy link
Contributor Author

cengiz-io commented Oct 2, 2017

@nikomatsakis update-references.sh doesn't help much on compile-fail tests (there's a bash issue but even solving that didn't work out) so I'm updating them manually.

I will also check those two surprising cases and report here.
Thank you!

@nikomatsakis
Copy link
Contributor

@cengizio yes, compile-fail tests have to be edited manually.

@cengiz-io
Copy link
Contributor Author

@nikomatsakis @arielb1 @gaurikholkar hello again!

I've updated the test cases.

NOTE: I decided to make test assertions in compile-fail tests as specific as possible. Please let me know if that's not the general case.

@gaurikholkar-zz
Copy link

@cengizio this test fails
src/test/compile-fail/associated-types/cache/project-fn-ret-invariant.rs

[01:00:24]     Error {
[01:00:24]         line_num: 50,
[01:00:24]         kind: Some(
[01:00:24]             Error
[01:00:24]         ),
[01:00:24]         msg: "50:5: 50:6: lifetime mismatch [E0623]"
[01:00:24]     }
[01:00:24] ]
[01:00:24]

I guess you have given the wrong column no for the error

@cengiz-io
Copy link
Contributor Author

cengiz-io commented Oct 8, 2017

@gaurikholkar thanks for noticing. The annoying part is, all tests are passing on my local machine. (with latest HEAD).

Let's see if this fixes the problem.

@cengiz-io
Copy link
Contributor Author

Argh! There seems to be line differences between my git clone and travis' copy. I'll investigate this further tomorrow.

@gaurikholkar-zz
Copy link

gaurikholkar-zz@cb0d746
Maybe this should work

@gaurikholkar-zz
Copy link

Ignore the indentation mess

@bors
Copy link
Contributor

bors commented Nov 9, 2017

☀️ Test successful - status-travis
State: approved= try=True

@kennytm
Copy link
Member

kennytm commented Nov 9, 2017

@rust-lang/infra Perf check wanted (44a477ee0833eef8007499fec6ebd88c5289da8a).

@nikomatsakis
Copy link
Contributor

Looks like try build is ready. cc @rust-lang/infra

@nikomatsakis
Copy link
Contributor

OK so -- the perf results seem fine, but @cengizio and I were discussing that maybe it's still worth replacing the BTreeMap with a Vec and a FxHashSet for duplicate checking. That would achieve the same results and seems better.

@kennytm kennytm 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 Nov 12, 2017
@nikomatsakis
Copy link
Contributor

@arielb1 and I were talking. We think we'll r+ this PR and then do any perf experiments in follow-up work.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 12, 2017

📌 Commit dad7d94 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Nov 12, 2017

⌛ Testing commit dad7d94 with merge 5b1b7b6c84a3e8e723a0416485a228abf756918c...

@bors
Copy link
Contributor

bors commented Nov 12, 2017

💔 Test failed - status-travis

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 12, 2017

📌 Commit f53fc57 has been approved by nikomatsakis

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 12, 2017
@bors
Copy link
Contributor

bors commented Nov 12, 2017

⌛ Testing commit f53fc57 with merge 79cfce3...

bors added a commit that referenced this pull request Nov 12, 2017
Improve SubSupConflict with a named and an anonymous lifetime parameter #42701

Hello!

This fixes #42701.

## UPDATE 01
Tests are producing different results between different env builds.
This inconsistency might take a long time to investigate and fix. So, be patient

## UPDATE 02
Changed an `FxHashMap` with a `BTreeMap`. Inconsistency seems to be resolved for now.
@bors
Copy link
Contributor

bors commented Nov 12, 2017

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

@bors bors merged commit f53fc57 into rust-lang:master Nov 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve case with one named, one anonymous lifetime parameter - SubSupConflict Errors