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

[nll] improve the "fully elaborated type" case in region errors #52648

Merged
merged 8 commits into from
Jul 27, 2018

Conversation

davidtwco
Copy link
Member

Fixes #52533.

r? @nikomatsakis

@davidtwco davidtwco changed the title [nll] improve the "fully elaborated type" case in region errors WIP: [nll] improve the "fully elaborated type" case in region errors Jul 23, 2018
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2018
@davidtwco
Copy link
Member Author

This currently uses the slightly-yucky string manipulation approach that we spoke about briefly in Zulip @nikomatsakis. If this isn't the way we want to do it then I'm happy to change it.

LL | foo(|a, b| b)
| - - ^ closure was supposed to return data with lifetime `'1` but it is returning data with lifetime `'2`
| | |
| | has type `&'1u32`
Copy link
Member

Choose a reason for hiding this comment

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

maybe missing whitespace between region and type(u32)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! Thanks, never spotted these when looking through the changed tests, pushed a fix for that.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

So the string manipulation doesn't feel great but we do have to decide what would be a better way...

match (category, outlived_fr_is_local, fr_is_local) {
(ConstraintCategory::Return, true, _) => {
diag.span_label(*span, format!(
"closure was supposed to return data with lifetime `{}` but it is returning \
Copy link
Contributor

Choose a reason for hiding this comment

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

probably here we don't want to say closure necessarily?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this to match the rest of the PR that detects "function" or "closure" based on the mir_def_id.

/// | | has type `&'1 u32`
/// | has type `&'2 u32`
/// ```
fn give_name_if_we_cannot_match_hir_ty(
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, this is pretty grody

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed this with most recent commit.

@davidtwco davidtwco force-pushed the issue-52533 branch 3 times, most recently from 98e4cb2 to 70ed4e2 Compare July 26, 2018 10:30
@@ -32,6 +32,10 @@ use syntax::ast::CRATE_NODE_ID;
use syntax::symbol::{Symbol, InternedString};
use hir;

thread_local! {
Copy link
Contributor

Choose a reason for hiding this comment

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

comment please =)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated most recent commit to address this.

use rustc_errors::DiagnosticBuilder;
use syntax::ast::Name;
use syntax::symbol::keywords;
use syntax_pos::symbol::InternedString;

fn with_highlight_region<R>(r: RegionVid, counter: usize, op: impl FnOnce() -> R) -> R {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably put this code into ppaux and encapsulate the HIGHLIGHT_REGION variable itself

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated most recent commit to address this.

| |
| has type `&'1 std::cell::Cell<&'2 &'3 u32>`
| has type `&'_ std::cell::Cell<&'1 &'_ u32>`
Copy link
Contributor

Choose a reason for hiding this comment

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

as an aside, it might be nice to not print '_ in this case but just &

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated most recent commit to address this.

@@ -11,7 +11,7 @@ LL | invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR E0495
| ----------^^^^^-----------------
| | | |
| | | free region requires that `'1` must outlive `'2`
| | has type `&'1 i32`
| | lifetime `'1` appears in this argument
Copy link
Contributor

Choose a reason for hiding this comment

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

so wait why this diff?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh because we don't find the '1 at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated most recent commit to address this.

return if *self == region {
write!(f, "'{:?}", counter)
} else {
write!(f, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

well, I know I sort of asked for this, but I think in a way I liked '_ better -- in particular, I'd like to see a test that shows what happens when you elaborate a struct type like TyCtxt -- I'd like to see TyCtxt<'_, '1, '_>, in particular. =)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead I would modify the TyRef code to look for either "'_" or "" and just skip printing in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this in recent commit.

| - - ^ closure was supposed to return data with lifetime `'1` but it is returning data with lifetime `'2`
| | |
| | has type `&Foo<'_, '1, u32>`
| has type `&Foo<'_, '2, u32>`
Copy link
Contributor

Choose a reason for hiding this comment

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

this is so beautiful

@nikomatsakis nikomatsakis changed the title WIP: [nll] improve the "fully elaborated type" case in region errors [nll] improve the "fully elaborated type" case in region errors Jul 26, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

[00:03:51] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:03:51] tidy error: /checkout/src/test/ui/issue-52533-1.rs:15: line longer than 100 chars
[00:03:52] some tidy checks failed
[00:03:52] 
[00:03:52] 
[00:03:52] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:52] 
[00:03:52] 
[00:03:52] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:52] Build completed unsuccessfully in 0:00:52
[00:03:52] Build completed unsuccessfully in 0:00:52
[00:03:52] make: *** [tidy] Error 1
[00:03:52] Makefile:79: recipe for target 'tidy' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2647392c
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:01968cb4:start=1532612962366536213,finish=1532612962374473488,duration=7937275
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1e554640
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:07a4938d
travis_time:start:07a4938d
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:01320810
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@davidtwco
Copy link
Member Author

Oops! Fixed that.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 3efc77b464330a0462f0f7036f77a8eff77d1363 has been approved by nikomatsakis

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 26, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:43:12] ....................................................................................................
[00:43:14] ....................................................................................................
[00:43:17] ....................................................................................................
[00:43:20] ....................................................................................................
[00:43:23] ...................................................................F................................
[00:43:30] ......................................................i.............................................
[00:43:33] ...............................................i....................................................
[00:43:36] ....................................................................................................
[00:43:40] ....................................................................................................
---
[00:43:46] 1 error[E0308]: mismatched types
[00:43:46] -   --> $DIR/issue-52533-1.rs:18:18
[00:43:46] +   --> $DIR/issue-52533-1.rs:19:18
[00:43:46] 3    |
[00:43:46] 4 LL |     gimme(|x, y| y)
[00:43:46] 5    |                  ^ lifetime mismatch
[00:43:46] 6    |
[00:43:46] 6    |
[00:43:46] 7    = note: expected type `&Foo<'_, '_, u32>`
[00:43:46] 8               found type `&Foo<'_, '_, u32>`
[00:43:46] - note: the anonymous lifetime #4 defined on the body at 18:11...
[00:43:46] -   --> $DIR/issue-52533-1.rs:18:11
[00:43:46] + note: the anonymous lifetime #4 defined on the body at 19:11...
[00:43:46] +   --> $DIR/issue-52533-1.rs:19:11
[00:43:46] 11    |
[00:43:46] 12 LL |     gimme(|x, y| y)
[00:43:46] 
[00:43:46] 
[00:43:46] - note: ...does not necessarily outlive the anonymous lifeus lifetime #3 defined on the body at 19:11","code":null,"level":"note","spans":[{"file_name":"/checkout/src/test/ui/issue-52533-1.rs","byte_start":719,"byte_end":727,"line_start":19,"line_end":19,"column_start":11,"column_end":19,"is_primary":true,"text":[{"text":"    gimme(|x, y| y)","highlight_start":11,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> /checkout/src/test/ui/issue-52533-1.rs:19:18\n   |\nLL |     gimme(|x, y| y)\n   |                  ^ lifetime mismatch\n   |\n   = note: expected type `&Foo<'_, '_, u32>`\n              found type `&Foo<'_, '_, u32>`\nnote: the anonymous lifetime #4 defined on the body at 19:11...\n  --> /checkout/src/test/ui/issue-52533-1.rs:19:11\n   |\nLL |     gimme(|x, y| y)\n   |           ^^^^^^^^\nnote: ...does not necessarily outlive the anonymous lifetime #3 defined on the body at 19:11\n  --> /checkout/src/test/ui/issue-52533-1.rs:19:11\n   |\nLL |     gimme(|x, y| y)\n   |           ^^^^^^^^\n\n"}
[00:43:46] {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}
[00:43:46] {"message":"For more information about this error, try `rustc --explain E0308`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0308`.\n"}
[00:43:46] ------------------------------------------
[00:43:46] 
[00:43:46] thread '[ui] ui/issue-52533-1.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3141:9
[00:43:46] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[00:43:46] 
[00:43:46] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00:43:46] 
[00:43:46] 
[00:43:46] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
travis_time:end:1c5ad088:start=1532613719537317861,finish=1532616346212522631,duration=2626675204770

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:21232900

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@davidtwco
Copy link
Member Author

Oops again! Fixed that.

@nikomatsakis
Copy link
Contributor

@bors r+ p=1

@bors
Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 301e4da54648f9fdeff0865048e2c6ade258a58b has been approved by nikomatsakis

@Mark-Simulacrum
Copy link
Member

@bors r=nikomatsakis p=1 NLL critical

@bors
Copy link
Contributor

bors commented Jul 26, 2018

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 301e4da54648f9fdeff0865048e2c6ade258a58b has been approved by nikomatsakis

@kennytm
Copy link
Member

kennytm commented Jul 26, 2018

@bors r-

Merge conflict ↓

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 26, 2018
@davidtwco
Copy link
Member Author

Rebased!

@Mark-Simulacrum
Copy link
Member

@bors r=nikomatsakis p=1

@bors
Copy link
Contributor

bors commented Jul 27, 2018

📌 Commit 2e4224a has been approved by nikomatsakis

@bors bors 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 Jul 27, 2018
@bors
Copy link
Contributor

bors commented Jul 27, 2018

⌛ Testing commit 2e4224a with merge b6cbc1e...

bors added a commit that referenced this pull request Jul 27, 2018
[nll] improve the "fully elaborated type" case in region errors

Fixes #52533.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Jul 27, 2018

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

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.

7 participants