about summary refs log tree commit diff
path: root/src/test/ui/suggestions
AgeCommit message (Collapse)AuthorLines
2021-02-26Auto merge of #82552 - GuillaumeGomez:rollup-8dn1ztn, r=GuillaumeGomezbors-9/+16
Rollup of 8 pull requests Successful merges: - #81940 (Stabilize str_split_once) - #82165 (Reword labels on E0308 involving async fn return type) - #82456 (Replaced some unwrap_or and map_or with lazy variants) - #82491 (Consider inexpensive inlining criteria first) - #82506 (Properly account for non-shorthand pattern field in unused variable lint) - #82535 (Set codegen thread names) - #82545 (rustdoc: add optional woff2 versions of FiraSans.) - #82549 (Revert "Update normalize.css to 8.0.1") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-02-26Rollup merge of #82165 - nellshamrell:nell/fix-80658-B, r=estebankGuillaume Gomez-9/+16
Reword labels on E0308 involving async fn return type Fix for #80658. When someone writes code like this: ```rust fn foo() -> u8 { async fn async_fn() -> () {} async_fn() } ``` And they try to compile it, they will see an error that looks like this: ```bash error[E0308]: mismatched types --> test.rs:4:5 | 1 | fn foo() -> u8 { | -- expected `u8` because of return type 2 | async fn async_fn() -> () {} | -- checked the `Output` of this `async fn`, found opaque type 3 | 4 | async_fn() | ^^^^^^^^^^ expected `u8`, found opaque type | = note: while checking the return type of this `async fn` = note: expected type `u8` found opaque type `impl Future` ```
2021-02-26Auto merge of #81458 - estebank:match-stmt-remove-semi, r=oli-obkbors-0/+81
Detect match statement intended to be tail expression CC #24157
2021-02-25Detect match statement intended to be tail expressionEsteban Küber-0/+81
CC #24157
2021-02-25Rollup merge of #82364 - osa1:issue82361, r=estebankDylan DPC-0/+96
Improve error msgs when found type is deref of expected This improves help messages in two cases: - When expected type is `T` and found type is `&T`, we now look through blocks and suggest dereferencing the expression of the block, rather than the whole block. - In the above case, if the expression is an `&`, we not suggest removing the `&` instead of adding `*`. Both of these are demonstrated in the regression test. Before this patch the first error in the test would be: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ expected `usize`, found `&usize` 9 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 7 | } else *{ 8 | b 9 | }; | Now: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ | | | | | expected `usize`, found `&usize` | | help: consider dereferencing the borrow: `*b` 9 | | }; | |_____- `if` and `else` have incompatible types The second error: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^^ expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 13 | } else *{ 14 | &1 15 | }; | now: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^- | | || | | |help: consider removing the `&`: `1` | | expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types Fixes #82361 --- r? ````@estebank````
2021-02-25Rollup merge of #82087 - estebank:abolish-ice, r=oli-obkDylan DPC-0/+25
Fix ICE caused by suggestion with no code substitutions Change suggestion logic to filter and checking _before_ creating specific resolution suggestion. Assert earlier that suggestions contain code substitions to make it easier in the future to debug invalid uses. If we find this becomes too noisy in the wild, we can always make the emitter resilient to these cases and remove the assertions. Fix #78651.
2021-02-24clarifies error when finding mismatched returned types for async functionsNell Shamrell-9/+16
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
2021-02-23Improve error msgs when found type is deref of expectedÖmer Sinan Ağacan-0/+96
This improves help messages in two cases: - When expected type is `T` and found type is `&T`, we now look through blocks and suggest dereferencing the expression of the block, rather than the whole block. - In the above case, if the expression is an `&`, we not suggest removing the `&` instead of adding `*`. Both of these are demonstrated in the regression test. Before this patch the first error in the test would be: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ expected `usize`, found `&usize` 9 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 7 | } else *{ 8 | b 9 | }; | Now: error[E0308]: `if` and `else` have incompatible types --> test.rs:8:9 | 5 | / if true { 6 | | a | | - expected because of this 7 | | } else { 8 | | b | | ^ | | | | | expected `usize`, found `&usize` | | help: consider dereferencing the borrow: `*b` 9 | | }; | |_____- `if` and `else` have incompatible types The second error: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^^ expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types | help: consider dereferencing the borrow | 13 | } else *{ 14 | &1 15 | }; | now: error[E0308]: `if` and `else` have incompatible types --> test.rs:14:9 | 11 | / if true { 12 | | 1 | | - expected because of this 13 | | } else { 14 | | &1 | | ^- | | || | | |help: consider removing the `&`: `1` | | expected integer, found `&{integer}` 15 | | }; | |_____- `if` and `else` have incompatible types Fixes #82361
2021-02-21Do not suggest `;` if expression is side effect freeEsteban Küber-27/+19
When a tail expression isn't unit, we previously always suggested adding a trailing `;` to turn it into a statement. This suggestion isn't appropriate for any expression that doesn't have side-effects, as the user will have likely wanted to call something else or do something with the resulting value, instead of just discarding it.
2021-02-21reword `;` suggestions to have consistent wordingEsteban Küber-1/+1
2021-02-21Add indication of anonymous lifetime position0yoyoyo-49/+34
2021-02-20Rollup merge of #81991 - osa1:issue81839, r=estebankGuillaume Gomez-6/+56
Fix panic in 'remove semicolon' when types are not local It's not possible to check if removing a semicolon fixes the type error when checking match arms and one or both of the last arm's and the current arm's return types are imported "opaque" types. In these cases we don't generate a "consider removing semicolon" suggestions. Fixes #81839 --- I'm not sure how to add a test for this. I think the test would need at least two crates. Do we have any existing tests that do this so that I can take a look?
2021-02-18Add regression testÖmer Sinan Ağacan-0/+53
2021-02-18Update 'match-prev-arm-needing-semi'Ömer Sinan Ağacan-6/+3
2021-02-17In some limited cases, suggest `where` bounds for non-type paramsEsteban Küber-1/+5
Partially address #81971.
2021-02-13Fix ICE caused by suggestion with no code substitutionsEsteban Küber-0/+25
Change suggestion logic to filter and checking _before_ creating specific resolution suggestion. Assert earlier that suggestions contain code substitions to make it easier in the future to debug invalid uses. If we find this becomes too noisy in the wild, we can always make the emitter resilient to these cases and remove the assertions. Fix #78651.
2021-02-13Rollup merge of #81995 - 0yoyoyo:fix-issue-81650-explicit-lifetime-error, ↵Yuki Okushi-0/+64
r=estebank Fix suggestion to introduce explicit lifetime Addresses #81650 Error message after fix: ``` error[E0311]: the parameter type `T` may not live long enough --> src/main.rs:25:11 | 24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) { | -- help: consider adding an explicit lifetime bound...: `T: 'a +` 25 | scope.spawn(move |_| { | ^^^^^ | note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 24:1... --> src/main.rs:24:1 | 24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the type `[closure@src/main.rs:25:17: 27:6]` will meet its required lifetime bounds --> src/main.rs:25:11 | 25 | scope.spawn(move |_| { | ^^^^^ ```
2021-02-12Add nll test0yoyoyo-0/+17
2021-02-12Fix suggestion to introduce explicit lifetime0yoyoyo-0/+47
2021-02-11Make suggestion of changing mutability of arguments broaderHirochika Matsumoto-0/+56
2021-02-10Rollup merge of #81466 - sasurau4:fix/enhance-sugget-mut-method-for-loop, ↵Yuki Okushi-0/+32
r=oli-obk Add suggest mut method for loop Part of #49839 This PR focus on [the comment case](https://github.com/rust-lang/rust/issues/49839#issuecomment-761930746)
2021-02-06Auto merge of #78052 - da-x:path-trimming-type-aliases, r=davidtwcobors-9/+9
path trimming: ignore type aliases Continuation of #73996.
2021-02-06path trimming: ignore type aliasesDan Aloni-9/+9
2021-02-05Add testDaiki Ihara-0/+32
2021-02-03Miscellaneous small diagnostics cleanupCamelid-2/+2
2021-02-03Fix non-existent-field ICE for generic fields.Mara Bos-4/+4
Co-authored-by: eddyb <eddyb@lyken.rs>
2021-02-02Rollup merge of #81655 - matsujika:suggest-accessing-field-rewording, r=estebankJack Huey-12/+12
Improve wording of suggestion about accessing field Follow-up to #81504 The compiler at this moment suggests "you might have meant to use field `b` of type `B`", sounding like it's type `B` which has the field `b`. r? ```@estebank```
2021-02-02Rollup merge of #81634 - jesusprubio:jesusprubio/add-long-explanation-e0521, ↵Jack Huey-0/+1
r=GuillaumeGomez Add long explanation e0521 Helps with #61137
2021-02-02Update ui tests (nll)Jesus Rubio-0/+1
2021-02-02Improve wording of suggestion about accessing fieldHirochika Matsumoto-12/+12
2021-02-01Rollup merge of #81504 - matsujika:suggestion-field-access, r=estebankJonas Schievink-0/+137
Suggest accessing field when appropriate Fix #81222 r? ``@estebank``
2021-01-31Rollup merge of #81480 - b-naber:nested_fields_suggestion, r=estebankJonas Schievink-0/+165
Add suggestion for nested fields Closes https://github.com/rust-lang/rust/issues/81220 r? ```@estebank```
2021-01-30add suggestion for nested fieldsb-naber-0/+165
2021-01-30Account for unionHirochika Matsumoto-4/+42
2021-01-30Fix test to check help message as wellHirochika Matsumoto-21/+16
2021-01-29Add rust-fix testHirochika Matsumoto-3/+32
2021-01-29Add test for match expressionHirochika Matsumoto-1/+42
2021-01-29Suggest accessing field when code compiles with itHirochika Matsumoto-0/+34
2021-01-26Avoid describing a method as 'not found' when bounds are unsatisfiedAaron Hill-12/+12
Fixes #76267 When there is a single applicable method candidate, but its trait bounds are not satisfied, we avoid saying that the method is "not found". Insted, we update the error message to directly mention which bounds are not satisfied, rather than mentioning them in a note.
2021-01-26Refine "remove semicolon" suggestion in trait selectionÖmer Sinan Ağacan-0/+36
Don't suggest it if the last statement doesn't have a semicolon Fixes #81098 See also #54771 for why this suggestion was added
2021-01-17Force vec! to expressions onlyDániel Buga-32/+0
2021-01-13Auto merge of #77524 - Patryk27:fixes/66228, r=estebankbors-30/+132
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924) This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-30/+132
2021-01-08Change wording of noteAaron Hill-1/+1
2021-01-08Explain method-call move errors in loopsAaron Hill-1/+7
PR #73708 added a more detailed explanation of move errors that occur due to a call to a method that takes `self`. This PR extends that logic to work when a move error occurs due to a method call in the previous iteration of a loop.
2020-12-26update testsBastian Kauschke-4/+4
2020-12-19Handle desugaring in impl trait bound suggestionWilliam Bain-1/+89
2020-11-16Rollup merge of #79032 - lcnr:arg-count, r=varkorMara Bos-4/+0
improve type const mismatch errors Doesn't completely remove `check_generic_arg_count` as that would have required some more complex changes but instead checks type and const params in only one step. Also moved the help added by `@JulianKnodt` in #75611 to `generic_arg_mismatch_err`. r? `@varkor` cc `@petrochenkov`
2020-11-16improve error message for const ty param mismatchBastian Kauschke-4/+0
2020-11-14Add underscore expressions for destructuring assignmentsFabian Zaiser-23/+84
Co-authored-by: varkor <github@varkor.com>