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

Provide existing ref suggestions for more E0308 errors #51822

Merged
merged 1 commit into from
Jun 29, 2018

Conversation

estebank
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2018
@@ -342,11 +329,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// a macro; if so, it's hard to extract the text and make a good
// suggestion, so don't bother.)
if self.infcx.can_sub(self.param_env, checked, &expected).is_ok() &&
expr.span.ctxt().outer().expn_info().is_none() {
sp.ctxt().outer().expn_info().is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

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

since we switched to call_site_if_macro here, do we know that is_none() will always be true?

@nikomatsakis
Copy link
Contributor

r=me modulo the nit above; if you think we can simplify, seems good, otherwise it's fine as is

@nikomatsakis nikomatsakis 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 Jun 27, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/f3/04/ef69353b3bdbc6ddb9de24291039dc06c33feb0e51ed73f5f3be707ae035/awscli-1.15.47-py2.py3-none-any.whl (1.3MB)
    0% |▎                               | 10kB 11.1MB/s eta 0:00:01
    1% |▌                               | 20kB 1.8MB/s eta 0:00:01
    2% |▊                               | 30kB 2.1MB/s eta 0:00:01
    3% |█                               | 40kB 1.9MB/s eta 0:00:01
---
Check compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:46:46] 
[00:46:46] running 1532 tests
[00:46:52] .................................................................................................i..
[00:46:58] ............................................................i..........F............................
[00:47:06] ....................................................................................................
[00:47:09] ....................................................................................................
[00:47:13] ....................................................................................................
[00:47:18] ....................................................................................................
---
[00:47:46] .........i..........................................................................................
[00:47:52] ....................................................................................................
[00:47:57] ....................................................................................................
[00:48:07] status: exit code: 101
[00:48:07] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/deref-suggestion.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/deref-suggestion/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/deref-suggestion/auxiliary" "-A" "unused"
[00:48:07] ------------------------------------------
[00:48:07] 
[00:48:07] ------------------------------------------
[00:48:07] stderr:
[00:48:07] stderr:
[00:48:07] ------------------------------------------
[00:48:07] {"message":"mismatched types","code":{"code":"E0308","explanation":"\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable's\ninitializing expression, and the actual type explicitly assigned to the\nvariable.\n\nFor example:\n\n```compile_fail,E0308\nlet x: i32 = \"I am not a number!\";\n//     ~~~   ~~~~~~~~~~~~~~~~~~~~\n//      |             |\n//      |    initializing expression;\n//      |    compiler infers type `&str`\n//      |\n//    type `i32` assigned to variable `x`\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":596,"byte_end":597,"line_start":18,"line_end":18,"column_start":9,"column_end":10,"is_primary":true,"text":[{"text":"    foo(s); //~ ERROR mismatched types","highlight_start":9,"highlight_end":10}],"label":"expected struct `std::string::String`, found reference","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `std::string::String`\n   found type `&std::string::String`","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":596,"byte_end":597,"line_start":18,"line_end":18,"column_start":9,"column_end":10,"is_primary":true,"text":[{"text":"    foo(s); //~ ERROR mismatched types","highlight_start":9,"highlight_end":10}],"label":null,"suggested_replacement":"s.to_string()","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> /checkout/src/test/ui/deref-suggestion.rs:18:9\n   |\nLL |     foo(s); //~ ERROR mismatched types\n   |         ^\n   |         |\n   |         expected struct `std::string::String`, found reference\n   |         help: try using a conversion method: `s.to_string()`\n   |\n   = note: expected type `std::string::String`\n              found type `&std::string::String`\n\n"}
[00:48:07] {"message":"mismatched types","code":{"code":"E0308","explanation":"\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable's\ninitializing express:"    foo(&\"aaa\".to_owned()); //~ ERROR mismatched types","highlight_start":9,"highlight_end":26}],"label":null,"suggested_replacement":"\"aaa\".to_owned()","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> /checkout/src/test/ui/deref-suggestion.rs:30:9\n   |\nLL |     foo(&\"aaa\".to_owned()); //~ ERROR mismatched types\n   |         ^^^^^^^^^^^^^^^^^\n   |         |\n   |         expected struct `std::string::String`, found reference\n   |         help: consider removing the borrow: `\"aaa\".to_owned()`\n   |\n   = note: expected type `std::string::String`\n              found type `&std::string::String`\n\n"}
[00:48:07] {"message":"mismatched types","code":{"code":"E0308","explanation":"\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable's\ninitializing expression, and the actual type explicitly assigned to the\nvariable.\n\nFor example:\n\n```compile_fail,E0308\nlet x: i32 = \"I am not a number!\";\n//     ~~~   ~~~~~~~~~~~~~~~~~~~~\n//      |             |\n//      |    initializing expression;\n//      |    compiler infers type `&str`\n//      |\n//    type `i32` assigned to variable `x`\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":846,"byte_end":867,"line_start":31,"line_end":31,"column_start":9,"column_end":30,"is_primary":true,"text":[{"text":"    foo(&mut \"aaa\".to_owned()); //~ ERROR mismatched types","highlight_start":9,"highlight_end":30}],"label":"expected struct `std::string::String`, found mutable reference","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected type `std::string::String`\n   found type `&mut std::string::String`","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"consider removing the borrow","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":846,"byte_end":867,"line_start":31,"line_end":31,"column_start":9,"column_end":30,"is_primary":true,"text":[{"text":"    foo(&mut \"aaa\".to_owned()); //~ ERROR mismatched types","highlight_start":9,"highlight_end":30}],"label":null,"suggested_replacement":"\"aaa\".to_owned()","suggestion_applicability":"Unspecified","expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> /checkout/src/test/ui/deref-suggestion.rs:31:9\n   |\nLL |     foo(&mut \"aaa\".to_owned()); //~ ERROR mismatched types\n   |         ^^^^^^^^^^^^^^^^^^^^^\n   |         |\n   |         expected struct `std::string::String`, found mutable reference\n   |         help: consider removing the borrow: `\"aaa\".to_owned()`\n   |\n   = note: expected type `std::string::String`\n              found type `&mut std::string::String`\n\n"}
[00:48:07] {"message":"mismatched types","code":{"code":"E0308","explanation":"\nThis error occurs when the compiler was unable to infer the concrete type of a\nvariable. It can occur for several cases, the most common of which is a\nmismatch in the expected type that the compiler inferred for a variable's\ninitializing expression, and the actual type explicitly assigned to the\nvariable.\n\nFor example:\n\n```compile_fail,E0308\nlet x: i32 = \"I am not a number!\";\n//     ~~~   ~~~~~~~~~~~~~~~~~~~~\n//      |             |\n//      |    initializing expression;\n//      |    compiler infers type `&str`\n//      |\n//    type `i32` assigned to variable `x`\n```\n"},"level":"error","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":508,"byte_end":511,"line_start":12,"line_end":12,"column_start":20,"column_end":23,"is_primary":true,"text":[{"text":"    ($x:expr) => { &$x } //~ ERROR mismatched types","highlight_start":20,"highlight_end":23}],"label":"expected u32, found &{integer}","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":906,"byte_end":916,"line_start":32,"line_end":32,"column_start":10,"column_end":20,"is_primary":false,"text":[{"text":"    foo3(borrow!(0));","highlight_start":10,"highlight_end":20}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"borrow!","def_site_span":{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":467,"byte_end":542,"line_start":11,"line_end":13,"column_start":1,"column_end":2,"is_primary":false,"text":[{"text":"macro_rules! borrow {","highlight_start":1,"highlight_end":22},{"text":"    ($x:expr) => { &$x } //~ ERROR mismatched types","highlight_start":1,"highlight_end":52},{"text":"}","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"expected type `u32`\n   found type `&{integer}`","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"consider removing the borrow","code":null,"level":"help","spans":[{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":508,"byte_end":511,"line_start":12,"line_end":12,"column_start":20,"column_end":23,"is_primary":true,"text":[{"text":"    ($x:expr) => { &$x } //~ ERROR mismatched types","highlight_start":20,"highlight_end":23}],"label":null,"suggested_replacement":"0","suggestion_applicability":"Unspecified","expansion":{"span":{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":906,"byte_end":916,"line_start":32,"line_end":32,"column_start":10,"column_end":20,"is_primary":false,"text":[{"text":"    foo3(borrow!(0));","highlight_start":10,"highlight_end":20}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"borrow!","def_site_span":{"file_name":"/checkout/src/test/ui/deref-suggestion.rs","byte_start":467,"byte_end":542,"line_start":11,"line_end":13,"column_start":1,"column_end":2,"is_primary":false,"text":[{"text":"macro_rules! borrow {","highlight_start":1,"highlight_end":22},{"text":"    ($x:expr) => { &$x } //~ ERROR mismatched types","highlight_start":1,"highlight_end":52},{"text":"}","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> /checkout/src/test/ui/deref-suggestion.rs:12:20\n   |\nLL |     ($x:expr) => { &$x } //~ ERROR mismatched types\n   |                    ^^^\n   |                    |\n   |                    expected u32, found &{integer}\n   |                    help: consider removing the borrow: `0`\n...\nLL |     foo3(borrow!(0));\n   |          ---------- in this macro invocation\n   |\n   = note: expected type `u32`\n              found type `&{integer}`\n\n"}
[00:48:07] {"message":"aborting due to 5 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 5 previous errors\n\n"}
[00:48:07] {"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:48:07] ------------------------------------------
[00:48:07] 
[00:48:07] thread '[ui] ui/deref-suggestion.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3139:9
[00:48:07] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
travis_time:end:071f36d0:start=1530149885150194183,finish=1530149885158686354,duration=8492171
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0304de1a
$ head -30 ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
head: cannot open ‘./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers’ for reading: No such file or directory
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:12325830
$ 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)

@bors

This comment has been minimized.

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.

seems good, but travis is unhappy now? r=me modulo travis and below nit

@@ -328,8 +328,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// (But, also check check the `expn_info()` to see if this is
// a macro; if so, it's hard to extract the text and make a good
// suggestion, so don't bother.)
if self.infcx.can_sub(self.param_env, checked, &expected).is_ok() &&
sp.ctxt().outer().expn_info().is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

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

(maybe we should make it assert?)

Copy link
Contributor Author

@estebank estebank Jun 28, 2018

Choose a reason for hiding this comment

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

No, I think it'd be better to revert that last commit. The checks are in different spans and we should only suggest if both spans are outside of macros. Originally I thought that it would make sense to suggest if the macro was local (meaning that the user could do something about it), but in that case the span already points at the problematic place, and I will assume that anyone using macros would have enough knowledge of the language to deal with an E0308 between u32 and &{integer}. What do you think?

[00:48:07] 50	  --> $DIR/deref-suggestion.rs:12:20
[00:48:07] 51	   |
[00:48:07] 52	LL |     ($x:expr) => { &$x } //~ ERROR mismatched types
[00:48:07] -	   |                    ^^^ expected u32, found &{integer}
[00:48:07] +	   |                    ^^^
[00:48:07] +	   |                    |
[00:48:07] +	   |                    expected u32, found &{integer}
[00:48:07] +	   |                    help: consider removing the borrow: `0`
[00:48:07] 54	...
[00:48:07] 55	LL |     foo3(borrow!(0));
[00:48:07] 56	   |          ---------- in this macro invocation

@estebank estebank force-pushed the suggest-more branch 2 times, most recently from d12eaa0 to d2161c7 Compare June 28, 2018 17:44
@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=nikomatsakis

Assuming that I'm being reasonable with #51822 (comment).

@bors

This comment has been minimized.

@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 Jun 28, 2018
@rust-highfive

This comment has been minimized.

@estebank
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 28, 2018

📌 Commit 54a04b3 has been approved by nikomatsakis

@Mark-Simulacrum
Copy link
Member

@bors rollup

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 28, 2018
Provide existing ref suggestions for more E0308 errors
bors added a commit that referenced this pull request Jun 28, 2018
Rollup of 6 pull requests

Successful merges:

 - #51636 (Refactor error reporting of constants)
 - #51765 (Use assert_eq! in copy_from_slice)
 - #51822 (Provide existing ref suggestions for more E0308 errors)
 - #51839 (Detect overflows of non u32 shifts)
 - #51868 (Remove process::id from 'Stabilized APIs' in 1.27.0 release notes)
 - #51875 (Explicitely disable WASM code generation for Emscripten)

Failed merges:

r? @ghost
@bors bors merged commit 54a04b3 into rust-lang:master Jun 29, 2018
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.

5 participants