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 E0308 error message wording #70242

Merged
merged 1 commit into from
Mar 24, 2020
Merged

Conversation

DeeDeeG
Copy link
Contributor

@DeeDeeG DeeDeeG commented Mar 21, 2020

Hi folks,

I made a post on Reddit about how (IMO) the docs/error messages can be a bit intimidating, one thing led to another, and I was encouraged to submit a Pull Request if I felt I could re-phrase the error message that I used as an example.

So that's this Pull Request. Open to any feedback or style changes, and I understand this is subjective.

(On another note: I am happy to see this message was recently improved in master, so it's already better than it is in stable Rust 1.42.0.)

Ideally the last sentence could be split into at least two: [sentence explaining the inferred type.] [Sentence explaining explicit type.] [Sentence that summarizes that "this is bad," and why.]

But I'm not sure how to do so; I'm wary of writing something that turns out to be technically incorrect.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 21, 2020
@Dylan-DPC-zz
Copy link

r? @Dylan-DPC

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 21, 2020

I tried to edit the same files that had to be edited in #69139, which was the last PR to update this error message. Apparently the tests hardcode the whole error message several times, so likewise, the changed phrasing needed to be copy-pasted several times.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 21, 2020

Critiquing my own PR: I'm mildly concerned that "on the one hand" (as an idiom) is going to unnecessarily confuse English-as-a-second-language readers. I think it's clearer that way for proficient English speakers, but that shouldn't outweigh other users' needs.

So I'm definitely open to removing those if other folks feel the same way about it.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, 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.
2020-03-21T19:44:22.2318582Z ========================== Starting Command Output ===========================
2020-03-21T19:44:22.2321361Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/cff79fe2-4a16-4d37-8150-8f1f89ddc35e.sh
2020-03-21T19:44:22.2321655Z 
2020-03-21T19:44:22.2325517Z ##[section]Finishing: Disable git automatic line ending conversion
2020-03-21T19:44:22.2345142Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70242/merge to s
2020-03-21T19:44:22.2348444Z Task         : Get sources
2020-03-21T19:44:22.2348779Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-21T19:44:22.2349086Z Version      : 1.0.0
2020-03-21T19:44:22.2349295Z Author       : Microsoft
---
2020-03-21T19:44:23.2290200Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-03-21T19:44:23.2296882Z ##[command]git config gc.auto 0
2020-03-21T19:44:23.2302574Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-03-21T19:44:23.2307433Z ##[command]git config --get-all http.proxy
2020-03-21T19:44:23.2315332Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/70242/merge:refs/remotes/pull/70242/merge
---
2020-03-21T20:40:43.5151194Z .................................................................................................... 1700/9815
2020-03-21T20:40:48.3072520Z .................................................................................................... 1800/9815
2020-03-21T20:40:58.9682784Z .............................................................................i...................... 1900/9815
2020-03-21T20:41:05.3761076Z .................................................................................................... 2000/9815
2020-03-21T20:41:13.0323207Z ...................................................................iiiii............................ 2100/9815
2020-03-21T20:41:32.2985785Z .................................................................................................... 2300/9815
2020-03-21T20:41:34.6186881Z .................................................................................................... 2400/9815
2020-03-21T20:41:37.4361120Z .................................................................................................... 2500/9815
2020-03-21T20:41:54.6595490Z .................................................................................................... 2600/9815
---
2020-03-21T20:44:34.7480661Z .........................................i...............i.......................................... 5000/9815
2020-03-21T20:44:43.5284188Z .................................................................................................... 5100/9815
2020-03-21T20:44:49.7014997Z .....................................................................................i.............. 5200/9815
2020-03-21T20:44:55.3190565Z .................................................................................................... 5300/9815
2020-03-21T20:45:05.1769949Z ...................................................................ii.ii........i...iF....F......... 5400/9815
2020-03-21T20:45:13.0946062Z .......i............................................................................................ 5600/9815
2020-03-21T20:45:22.3375956Z ............i....................................................................................... 5700/9815
2020-03-21T20:45:28.0774419Z .............................ii...................................i................................. 5800/9815
2020-03-21T20:45:34.7437349Z .................................................................................................... 5900/9815
2020-03-21T20:45:34.7437349Z .................................................................................................... 5900/9815
2020-03-21T20:45:41.2153452Z .................................................................................................... 6000/9815
2020-03-21T20:45:50.2343861Z ............................................................ii...i..ii...........i.................. 6100/9815
2020-03-21T20:46:10.1798347Z .................................................................................................... 6300/9815
2020-03-21T20:46:15.0627874Z .................................................................................................... 6400/9815
2020-03-21T20:46:15.0627874Z .................................................................................................... 6400/9815
2020-03-21T20:46:19.3806773Z ..........................................................................................i..ii..... 6500/9815
2020-03-21T20:46:40.3358511Z .................................................................................................... 6700/9815
2020-03-21T20:46:50.5333252Z .........................................................................................i.......... 6800/9815
2020-03-21T20:46:52.5936112Z .................................................................................................... 6900/9815
2020-03-21T20:46:54.7121704Z .................................................................................................... 7000/9815
---
2020-03-21T20:48:36.9067351Z .................................................................................................... 7800/9815
2020-03-21T20:48:41.4222427Z .................................................................................................... 7900/9815
2020-03-21T20:48:47.3675792Z .............................................................................i...................... 8000/9815
2020-03-21T20:48:57.2284752Z .................................................................................................... 8100/9815
2020-03-21T20:49:02.4357493Z ..........................iiiiiiiiii.i.............................................................. 8200/9815
2020-03-21T20:49:16.3090008Z .................................................................................................... 8400/9815
2020-03-21T20:49:21.4938322Z .................................................................................................... 8500/9815
2020-03-21T20:49:36.4207060Z .................................................................................................... 8600/9815
2020-03-21T20:49:43.4153491Z .................................................................................................... 8700/9815
---
2020-03-21T20:51:34.3337250Z 
2020-03-21T20:51:34.3341581Z ---- [ui] ui/json-bom-plus-crlf-multifile.rs stdout ----
2020-03-21T20:51:34.3341997Z diff of stderr:
2020-03-21T20:51:34.3342133Z 
2020-03-21T20:51:34.3342420Z 15 variable. It can happen in several cases, the most common being a mismatch
2020-03-21T20:51:34.3342821Z 16 between the type that the compiler inferred for a variable based on its
2020-03-21T20:51:34.3343229Z 17 initializing expression, on the one hand, and the type the author explicitly
2020-03-21T20:51:34.3343808Z - assigned to the variable, on the other hand."
2020-03-21T20:51:34.3350706Z - },"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `std::string::String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types
2020-03-21T20:51:34.3355801Z + assigned to the variable, on the other hand.
2020-03-21T20:51:34.3364029Z + "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":"expected struct `std::string::String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":612,"byte_end":618,"line_start":17,"line_end":17,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1;  // Error in the middle of line.","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:17:22: error[E0308]: mismatched types
2020-03-21T20:51:34.3369134Z 20 "}
2020-03-21T20:51:34.3369526Z 21 {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
2020-03-21T20:51:34.3370037Z 
2020-03-21T20:51:34.3370189Z 31 //      |
2020-03-21T20:51:34.3370424Z 32 //    type `i32` assigned to variable `x`
2020-03-21T20:51:34.3370653Z 33 ```
2020-03-21T20:51:34.3370653Z 33 ```
2020-03-21T20:51:34.3370976Z - 
2020-03-21T20:51:34.3371259Z 35 This error occurs when the compiler was unable to infer the concrete type of a
2020-03-21T20:51:34.3371688Z 36 variable. It can happen in several cases, the most common being a mismatch
2020-03-21T20:51:34.3372091Z 37 between the type that the compiler inferred for a variable based on its
2020-03-21T20:51:34.3372331Z 
2020-03-21T20:51:34.3372614Z 38 initializing expression, on the one hand, and the type the author explicitly
2020-03-21T20:51:34.3373157Z - assigned to the variable, on the other hand."
2020-03-21T20:51:34.3373451Z + assigned to the variable, on the other hand.
2020-03-21T20:51:34.3378380Z 40 "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1","highlight_start":22,"highlight_end":23}],"label":"expected struct `std::string::String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":672,"byte_end":678,"line_start":19,"line_end":19,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":"    let s : String = 1","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":681,"byte_end":682,"line_start":19,"line_end":19,"column_start":22,"column_end":23,"is_primary":true,"text":[{"text":"    let s : String = 1","highlight_start":22,"highlight_end":23}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:19:22: error[E0308]: mismatched types
2020-03-21T20:51:34.3381680Z 41 "}
2020-03-21T20:51:34.3382082Z 42 {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
2020-03-21T20:51:34.3382587Z 52 //      |
2020-03-21T20:51:34.3382813Z 53 //    type `i32` assigned to variable `x`
2020-03-21T20:51:34.3383041Z 54 ```
2020-03-21T20:51:34.3383335Z - 
2020-03-21T20:51:34.3383335Z - 
2020-03-21T20:51:34.3383617Z 56 This error occurs when the compiler was unable to infer the concrete type of a
2020-03-21T20:51:34.3384044Z 57 variable. It can happen in several cases, the most common being a mismatch
2020-03-21T20:51:34.3384443Z 58 between the type that the compiler inferred for a variable based on its
2020-03-21T20:51:34.3384683Z 
2020-03-21T20:51:34.3384964Z 59 initializing expression, on the one hand, and the type the author explicitly
2020-03-21T20:51:34.3385573Z - assigned to the variable, on the other hand."
2020-03-21T20:51:34.3385870Z + assigned to the variable, on the other hand.
2020-03-21T20:51:34.3391604Z 61 "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1;  // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":"expected struct `std::string::String`, found integer","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":735,"byte_end":741,"line_start":22,"line_end":22,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":"    let s : String =","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using a conversion method","code":null,"level":"help","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":745,"byte_end":746,"line_start":23,"line_end":23,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"1;  // Error after the newline.","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":"1.to_string()","suggestion_applicability":"MaybeIncorrect","expansion":null}],"children":[],"rendered":null}],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:23:1: error[E0308]: mismatched types
2020-03-21T20:51:34.3395827Z 62 "}
2020-03-21T20:51:34.3396229Z 63 {"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.
2020-03-21T20:51:34.3396731Z 73 //      |
2020-03-21T20:51:34.3396957Z 74 //    type `i32` assigned to variable `x`
2020-03-21T20:51:34.3397184Z 75 ```
2020-03-21T20:51:34.3397473Z - 
2020-03-21T20:51:34.3397473Z - 
2020-03-21T20:51:34.3397753Z 77 This error occurs when the compiler was unable to infer the concrete type of a
2020-03-21T20:51:34.3398245Z 78 variable. It can happen in several cases, the most common being a mismatch
2020-03-21T20:51:34.3398649Z 79 between the type that the compiler inferred for a variable based on its
2020-03-21T20:51:34.3398887Z 
2020-03-21T20:51:34.3399170Z 80 initializing expression, on the one hand, and the type the author explicitly
2020-03-21T20:51:34.3420313Z - assigned to the variable, on the other hand."
2020-03-21T20:51:34.3420643Z + assigned to the variable, on the other hand.
2020-03-21T20:51:34.3424678Z 82 "},"level":"error","spans":[{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":801,"byte_end":809,"line_start":25,"line_end":26,"column_start":22,"column_end":6,"is_primary":true,"text":[{"text":"    let s : String = (","highlight_start":22,"highlight_end":23},{"text":"    );  // Error spanning the newline.","highlight_start":1,"highlight_end":6}],"label":"expected struct `std::string::String`, found `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/json-bom-plus-crlf-multifile-aux.rs","byte_start":792,"byte_end":798,"line_start":25,"line_end":25,"column_start":13,"column_end":19,"is_primary":false,"text":[{"text":"    let s : String = (","highlight_start":13,"highlight_end":19}],"label":"expected due to this","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"$DIR/json-bom-plus-crlf-multifile-aux.rs:25:22: error[E0308]: mismatched types
2020-03-21T20:51:34.3427517Z 83 "}
2020-03-21T20:51:34.3428002Z 84 {"message":"aborting due to 4 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 4 previous errors
2020-03-21T20:51:34.3428575Z 
2020-03-21T20:51:34.3428795Z The actual stderr differed from the expected stderr.
2020-03-21T20:51:34.3429565Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf-multifile/json-bom-plus-crlf-multifile.stderr
2020-03-21T20:51:34.3429565Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf-multifile/json-bom-plus-crlf-multifile.stderr
2020-03-21T20:51:34.3430455Z To update references, rerun the tests and pass the `--bless` flag
2020-03-21T20:51:34.3431091Z To only update this specific test, also pass `--test-args json-bom-plus-crlf-multifile.rs`
2020-03-21T20:51:34.3431586Z error: 1 errors occurred comparing output.
2020-03-21T20:51:34.3431839Z status: exit code: 1
2020-03-21T20:51:34.3431839Z status: exit code: 1
2020-03-21T20:51:34.3433991Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/json-bom-plus-crlf-multifile.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf-multifile" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "--json=diagnostic-short" "--error-format=json" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf-multifile/auxiliary"
2020-03-21T20:51:34.3435764Z ------------------------------------------
2020-03-21T20:51:34.3435961Z 
2020-03-21T20:51:34.3436340Z ------------------------------------------
2020-03-21T20:51:34.3436553Z stderr:
---
2020-03-21T20:51:34.3454135Z 80 between the type that the compiler inferred for a variable based on its
2020-03-21T20:51:34.3454372Z 
2020-03-21T20:51:34.3454475Z 
2020-03-21T20:51:34.3454694Z The actual stderr differed from the expected stderr.
2020-03-21T20:51:34.3455416Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf/json-bom-plus-crlf.stderr
2020-03-21T20:51:34.3456079Z To update references, rerun the tests and pass the `--bless` flag
2020-03-21T20:51:34.3456678Z To only update this specific test, also pass `--test-args json-bom-plus-crlf.rs`
2020-03-21T20:51:34.3457186Z error: 1 errors occurred comparing output.
2020-03-21T20:51:34.3457437Z status: exit code: 1
2020-03-21T20:51:34.3457437Z status: exit code: 1
2020-03-21T20:51:34.3460340Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/json-bom-plus-crlf.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-A" "unused" "--json=diagnostic-short" "--error-format=json" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/json-bom-plus-crlf/auxiliary"
2020-03-21T20:51:34.3462868Z ------------------------------------------
2020-03-21T20:51:34.3463054Z 
2020-03-21T20:51:34.3463435Z ------------------------------------------
2020-03-21T20:51:34.3463663Z stderr:
---
2020-03-21T20:51:34.3471557Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:348:22
2020-03-21T20:51:34.3472003Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2020-03-21T20:51:34.3479001Z 
2020-03-21T20:51:34.3479162Z 
2020-03-21T20:51:34.3483584Z 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-7/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -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" "7.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2020-03-21T20:51:34.3486628Z 
2020-03-21T20:51:34.3486735Z 
2020-03-21T20:51:34.3487284Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --exclude src/tools/tidy
2020-03-21T20:51:34.3487678Z Build completed unsuccessfully in 1:01:44
2020-03-21T20:51:34.3487678Z Build completed unsuccessfully in 1:01:44
2020-03-21T20:51:34.3516367Z == clock drift check ==
2020-03-21T20:51:34.3543505Z   local time: Sat Mar 21 20:51:34 UTC 2020
2020-03-21T20:51:34.5206013Z   network time: Sat, 21 Mar 2020 20:51:34 GMT
2020-03-21T20:51:34.5211293Z == end clock drift check ==
2020-03-21T20:51:34.8741712Z 
2020-03-21T20:51:34.8820694Z ##[error]Bash exited with code '1'.
2020-03-21T20:51:34.8888093Z ##[section]Finishing: Run build
2020-03-21T20:51:34.8940418Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/70242/merge to s
2020-03-21T20:51:34.8945730Z Task         : Get sources
2020-03-21T20:51:34.8946090Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-03-21T20:51:34.8946439Z Version      : 1.0.0
2020-03-21T20:51:34.8946680Z Author       : Microsoft
2020-03-21T20:51:34.8946680Z Author       : Microsoft
2020-03-21T20:51:34.8947055Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-03-21T20:51:34.8947498Z ==============================================================================
2020-03-21T20:51:35.2228525Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-03-21T20:51:35.2272432Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/70242/merge to s
2020-03-21T20:51:35.2358231Z Cleaning up task key
2020-03-21T20:51:35.2359674Z Start cleaning up orphan processes.
2020-03-21T20:51:35.2537781Z Terminate orphan process: pid (3490) (python)
2020-03-21T20:51:35.2703632Z ##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 21, 2020

Looks like I didn't edit the test files correctly -- am I supposed to properly type CR, LF, and CR+LF symbols for those tests? I'm not sure I want to guess and check since it took a bit over an hour to run the tests... And it would be tricky to type that correctly.

@Dylan-DPC-zz
Copy link

Did you run tidy ?

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 21, 2020

Did you run tidy ?

No, I actually don't know what that is. Will do if I can understand how to.

Edit: I found the instructions here: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#pull-requests

python x.py test tidy

I'm running that now.

(Sorry I missed that. I tried to skim CONTRIBUTING.md, but most was not applicable to updating the error messages, so I just went for the PR.)

I caught an extra stray quote marks in a few places in the original commit. Fixed (amended the commit) and force-pushed. Maybe it will pass this time.

@Dylan-DPC-zz
Copy link

Dylan-DPC-zz commented Mar 21, 2020

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 21, 2020

Both commits (one before amending and one after amending) appear to pass the x.py test tidy checks.

My output is like this:

$ python3 x.py test tidy
Updating only changed submodules
Submodules updated in 0.04 seconds
    Finished dev [unoptimized] target(s) in 0.20s
Building stage0 tool tidy (x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.20s
tidy check
* 591 error codes
* highest error code: E0748
* 282 features
Checking which error codes lack tests...
Found 489 error codes
Found 0 error codes with no tests
Done!
fmt check
Build completed successfully in 0:00:18

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 22, 2020

It passed, woo! 🎉

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 22, 2020

Just looked up the technical meaning of expressions in Rust. If I understand correctly, in the example snippet:

let x: i32 = "I am not a number!";

The expression would be "I am not a number!".

I think the original wording is clear if you already understand the definition of an "expression" as a technical term meaning roughly "something that is a value, or which can be evaluated".

I think my updated wording is still correct, but less bare-bones, or arguably less focused and concise. However, I hope the added context and hints for reasoning about the error are worth it. I would welcome some technical review that the updated wording is still accurate, and feedback on whether it would be considered an actual improvement by someone who knows the language well. I opened this PR as a beginner to Rust, and I am okay with it not being merged if it doesn't better-explain the error.

I'm also thinking about if I understand the message well enough to split it into more sentences.

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 22, 2020

Something like this would properly break up the sentences to be more manageable:

rustc can usually infer a type for any expression. For example: "5 + 5" would have the inferred type "i32". Variables may have their types explicitly assigned by the author. For example: "let x: u64". If a variable has one type explicitly set by the author, but an expression with a different inferred type is assigned to it, you may see this error.

Note: I'm not sure if i32 is actually the correct default (inferred) type for the expression "5 + 5". If someone knows, I could replace that with the correct (inferred) type).

Edit: The default integer type is i32, according to The Book.

So how do you know which type of integer to use? If you’re unsure, Rust’s defaults are generally good choices, and integer types default to i32 [...]

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 22, 2020

Another attempt at simplifying:

This error occurs when the compiler was unable to infer the concrete type of a variable. It can occur in several cases; the most common case is a mismatch between a variable's explicit type, as set by the author, and the inferred type of an expression that has been assigned to that variable, as deduced by the compiler.


The sentence also works without "as set by the author" and "as deduced by the compiler" which allows it to be even shorter:

This error occurs when the compiler was unable to infer the concrete type of a variable. It can occur in several cases; the most common case is a mismatch between a variable's explicit type, and the inferred type of an expression that has been assigned to that variable.

(Though, IMO, this short version is harder to comprehend for a total programming newbie like I apparently was a couple of hours ago.)

@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 23, 2020

Technical details: The error message can be triggered by any combination of explicit or inferred types that don't match.

Examples:

  • [some var that's explicitly &str] = [some var that's explicitly i32]
  • [some var that's explicitly &str] = [some var or expression that's inferred i32]
  • [some var that's inferred &str] = [some var that's explicitly i32]
  • [some var that's inferred &str] = [some var or expression that's inferred i32]

All these attempts at assignment trigger E0308.

I'm afraid the effort to provide a "common scenario" is just confusing, whereas the core problem or idea is just that "two types didn't match."

Edit to add: If anything needs to be explained here, it's just that Rust is statically typed and won't allow the same variable to take on two different types within the same program.

@Dylan-DPC-zz
Copy link

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 23, 2020

📌 Commit 99ae428 has been approved by Dylan-DPC

@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 Mar 23, 2020
@Dylan-DPC-zz
Copy link

Dont worry. Looks good to me

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 24, 2020
Rollup of 11 pull requests

Successful merges:

 - rust-lang#67761 (Move the dep_graph construction to a dedicated crate.)
 - rust-lang#69740 (Replace some desc logic in librustc_lint with article_and_desc)
 - rust-lang#69981 (Evaluate repeat expression lengths as late as possible)
 - rust-lang#70087 (Remove const eval loop detector)
 - rust-lang#70242 (Improve E0308 error message wording)
 - rust-lang#70264 (Fix invalid suggestion on `&mut` iterators yielding `&` references)
 - rust-lang#70267 (get rid of ConstPropUnsupported; use ZST marker structs instead)
 - rust-lang#70277 (Remove `ReClosureBound`)
 - rust-lang#70283 (Add regression test for rust-lang#70155.)
 - rust-lang#70294 (Account for bad placeholder types in where clauses)
 - rust-lang#70309 (Clean up E0452 explanation)

Failed merges:

r? @ghost
@DeeDeeG
Copy link
Contributor Author

DeeDeeG commented Mar 24, 2020

It seems too late for this, but in light of my better understanding the error, I came up with this wording:

This error occurs when the compiler was unable to infer the concrete type of a variable. It can occur for several cases; The most common case is a mismatch between two types: the type explicitly assigned to a variable by the author, and the type the compiler infers for an expression to be assigned to that variable later on.

I prefer it for its simplicity, clarity and tone.

Should I open another PR if I want to suggest that wording instead?

Edit: I see the earlier wording as I had it in my branch is in master now! Exciting!! Thanks for the review. I'll consider submitting the wording from this comment as another PR some time soon... (It's a bit late where I am to submit it today.)

@bors bors merged commit 7a47df8 into rust-lang:master Mar 24, 2020
variable.
variable. It can happen in several cases, the most common being a mismatch
between the type that the compiler inferred for a variable based on its
initializing expression, on the one hand, and the type the author explicitly
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a typo? on the one hand

Copy link
Contributor

Choose a reason for hiding this comment

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

Just my two cents, on one hand and on the other hand may not be easily understood by non-native english speakers. Maybe it's just me but I learned that late, and is easier to be understood.

Copy link
Contributor Author

@DeeDeeG DeeDeeG Apr 13, 2020

Choose a reason for hiding this comment

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

I meant to contribute a better message with no "on the other hand." But I got side-tracked and honestly a bit discouraged, since there's nobody to workshop good messages with, and no standards of what a good error message looks like.

I'd like there to be a working group to bounce ideas off of, and/or a style guide.

Here's what I had, roughly:

This error occurs when the compiler was unable to infer the concrete type of a variable.
It can occur for several cases; The most common case is a mismatch between
two types: the type explicitly assigned to a variable by the [code's] author,
and the type the compiler infers for an expression assigned to that variable.

Possibly a "hint" line about dynamic typing versus static typing:

In Rust each declared variable is assigned a static type. Dynamic typing is not supported.

See prior discussion here if you want: https://users.rust-lang.org/t/looking-for-feedback-on-an-improved-error-message-for-e0308/40004

I actually think the phrasing can be much simplified.

Any two mis-matching types assigned to the same variable cause this error. Regardless of explicit or inferred, at or after initialization, etc... Just... two non-matching types, one variable.

(Apparently there is a thing called shadowing, but if I read correctly, I believe it just spins up a new variable with a different compiled identity, but re-using the same name in source code. New instance of the variable can have a new type. It's still static typing under the hood, though. I am afraid of over-simplifying, and ending up with a message that is inaccurate regarding shadowing.)

Copy link
Contributor

Choose a reason for hiding this comment

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

This error occurs when the compiler was unable to infer the concrete type of a variable.
It can occur for several cases; The most common case is a mismatch between
two types: the type explicitly assigned to a variable by the [code's] author,
and the type the compiler infers for an expression assigned to that variable.

That is better than the merged one I think but still kinda long-winded, I think documentation should be short, concise and understandable. What I would say a good example is IETF RFC docs, rust docs is good enough for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reply.

I have some things to do at the moment, but I will post that version as a second PR when I get the chance. Hopefully before a new stable release.

It could probably be shortened, mostly by removing the "common example" of when this error occurs. (It is kind of arbitrary, and I think it might be overly specific when the error is more general than that.) But I don't want to be too drastic while I am still getting used to contributing to Rust.


Posting this for reference since you mentioned IETF RFCs as being a good example: https://tools.ietf.org/html/rfc7322 The IETF RFC Style Guide.

Maybe that can be an influence for a Rust docs "style guide" or best practices guide. No time now, but planning to look that over later.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Apr 23, 2020
…bank

Improve E0308 error message wording again

Hello again,

I recently did this PR: rust-lang#70242

I felt the error message could be further improved, so I made [a post on the Rust community forum](https://users.rust-lang.org/t/looking-for-feedback-on-an-improved-error-message-for-e0308/40004) to ask for feedback.

(Also, there were some comments on my original PR that I took into consideration as well.)

This PR is my attempt to take all the feedback into account and propose a better and simplified error message that should still be accurate. Its main benefit is having simpler grammar, and hopefully being easier to read and understand.

Thanks to everyone who commented and gave feedback, and thank you for taking a look at this PR.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 23, 2020
…bank

Improve E0308 error message wording again

Hello again,

I recently did this PR: rust-lang#70242

I felt the error message could be further improved, so I made [a post on the Rust community forum](https://users.rust-lang.org/t/looking-for-feedback-on-an-improved-error-message-for-e0308/40004) to ask for feedback.

(Also, there were some comments on my original PR that I took into consideration as well.)

This PR is my attempt to take all the feedback into account and propose a better and simplified error message that should still be accurate. Its main benefit is having simpler grammar, and hopefully being easier to read and understand.

Thanks to everyone who commented and gave feedback, and thank you for taking a look at this PR.
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.

6 participants