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

Projects
None yet
7 participants
@davidtwco
Copy link
Member

davidtwco commented Jul 23, 2018

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

@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Jul 23, 2018

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`

This comment has been minimized.

@csmoe

csmoe Jul 23, 2018

Member

maybe missing whitespace between region and type(u32)?

This comment has been minimized.

@davidtwco

davidtwco Jul 23, 2018

Author Member

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

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

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 \

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 24, 2018

Contributor

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

This comment has been minimized.

@davidtwco

davidtwco Jul 24, 2018

Author Member

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(

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 24, 2018

Contributor

huh, this is pretty grody

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

Addressed this with most recent commit.

@davidtwco davidtwco force-pushed the davidtwco:issue-52533 branch 3 times, most recently from 98e4cb2 to 70ed4e2 Jul 24, 2018

@@ -32,6 +32,10 @@ use syntax::ast::CRATE_NODE_ID;
use syntax::symbol::{Symbol, InternedString};
use hir;

thread_local! {

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

comment please =)

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

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 {

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

Updated most recent commit to address this.

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

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

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

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

so wait why this diff?

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

Updated most recent commit to address this.

@davidtwco davidtwco force-pushed the davidtwco:issue-52533 branch from 70ed4e2 to 92d1fd0 Jul 26, 2018

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

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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. =)

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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

This comment has been minimized.

@davidtwco

davidtwco Jul 26, 2018

Author Member

Fixed this in recent commit.

@davidtwco davidtwco force-pushed the davidtwco:issue-52533 branch from 92d1fd0 to 1933f1d Jul 26, 2018

| - - ^ 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>`

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 26, 2018

Contributor

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

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 26, 2018

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 davidtwco force-pushed the davidtwco:issue-52533 branch from 1933f1d to 3efc77b Jul 26, 2018

@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Jul 26, 2018

Oops! Fixed that.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 26, 2018

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 3efc77b has been approved by nikomatsakis

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 26, 2018

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 davidtwco force-pushed the davidtwco:issue-52533 branch from 3efc77b to 301e4da Jul 26, 2018

@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Jul 26, 2018

Oops again! Fixed that.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 26, 2018

@bors r+ p=1

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 301e4da has been approved by nikomatsakis

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Jul 26, 2018

@bors r=nikomatsakis p=1 NLL critical

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 26, 2018

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

  • There's another pull request that is currently being tested, blocking this pull request: #52488
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 26, 2018

📌 Commit 301e4da has been approved by nikomatsakis

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 26, 2018

@bors r-

Merge conflict ↓

davidtwco added some commits Jul 23, 2018

@davidtwco davidtwco force-pushed the davidtwco:issue-52533 branch from 301e4da to 2e4224a Jul 27, 2018

@davidtwco

This comment has been minimized.

Copy link
Member Author

davidtwco commented Jul 27, 2018

Rebased!

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Jul 27, 2018

@bors r=nikomatsakis p=1

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 27, 2018

📌 Commit 2e4224a has been approved by nikomatsakis

@bors

This comment has been minimized.

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

Auto merge of #52648 - davidtwco:issue-52533, r=nikomatsakis
[nll] improve the "fully elaborated type" case in region errors

Fixes #52533.

r? @nikomatsakis
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 27, 2018

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

@bors bors merged commit 2e4224a into rust-lang:master Jul 27, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@davidtwco davidtwco deleted the davidtwco:issue-52533 branch Jul 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.