about summary refs log tree commit diff
path: root/src/test/ui/suggestions
AgeCommit message (Collapse)AuthorLines
2021-10-07Auto merge of #89534 - camsteffen:diag-name, r=oli-obkbors-0/+11
Introduce `tcx.get_diagnostic_name` Introduces a "reverse lookup" for diagnostic items. This is mainly intended for `@rust-lang/clippy` which often does a long series of `is_diagnostic_item` calls for the same `DefId`. r? `@oli-obk`
2021-10-06Rollup merge of #89501 - Aaron1011:escaping-name-regions, r=davidtwcoManish Goregaokar-8/+28
Note specific regions involved in 'borrowed data escapes' error Fixes #67007 Currently, a 'borrowed data escapes' error does not mention the specific lifetime involved (except indirectly through a suggestion about adding a lifetime bound). We now explain the specific lifetime relationship that failed to hold, which improves otherwise vague error messages.
2021-10-06Bless testsCameron Steffen-0/+11
2021-10-06Auto merge of #89323 - estebank:derive-binop, r=petrochenkovbors-0/+9
Consider unfulfilled obligations in binop errors When encountering a binop where the types would have been accepted, if all the predicates had been fulfilled, include information about the predicates and suggest appropriate `#[derive]`s if possible. Fix #84515.
2021-10-05Consider unfulfilled obligations in binop errorsEsteban Kuber-0/+9
When encountering a binop where the types would have been accepted, if all the predicates had been fulfilled, include information about the predicates and suggest appropriate `#[derive]`s if possible. Point at trait(s) that needs to be `impl`emented.
2021-10-05Rollup merge of #88871 - FabianWolff:issue-88403, r=jackh726Manish Goregaokar-0/+60
Fix suggestion for nested struct patterns Fixes #88403, and also a similar problem where the unused binding is in a function parameter pattern.
2021-10-05Note specific regions involved in 'borrowed data escapes' errorAaron Hill-8/+28
Fixes #67007 Currently, a 'borrowed data escapes' error does not mention the specific lifetime involved (except indirectly through a suggestion about adding a lifetime bound). We now explain the specific lifetime relationship that failed to hold, which improves otherwise vague error messages.
2021-10-03Don't suggest replacing region with 'static in NLLAaron Hill-11/+0
Fixes #73159 This is similar to #69350 - if the user didn't initially write out a 'static lifetime, adding 'static in response to a lifetime error is usually the wrong thing to do.
2021-10-01Don't use Default, since the impls are different on wasmjackh726-15/+9
2021-10-01Don't lose binders when printing trait bound suggestionjackh726-0/+32
2021-09-30Rollup merge of #89251 - estebank:negative-index-literals, r=davidtwcoManish Goregaokar-0/+79
Detect when negative literal indices are used and suggest appropriate code
2021-09-30Rollup merge of #89314 - notriddle:notriddle/lint-fix-enum-variant-match, ↵Manish Goregaokar-0/+37
r=davidtwco fix(lint): don't suggest refutable patterns to "fix" irrefutable bind In function arguments and let bindings, do not suggest changing `C` to `Foo::C` unless `C` is the only variant of `Foo`, because it won't work. The general warning is still kept, because code like this is confusing. Fixes #88730 p.s. `src/test/ui/lint/lint-uppercase-variables.rs` already tests the one-variant case.
2021-09-30Rollup merge of #89248 - hkmatsumoto:suggest-similarly-named-assoc-items, ↵Manish Goregaokar-0/+122
r=estebank Suggest similarly named associated items in trait impls Fix #85942 Previously, the compiler didn't suggest similarly named associated items unlike we do in many situations. This patch adds such diagnostics for associated functions, types, and constants.
2021-09-30Auto merge of #89110 - Aaron1011:adjustment-span, r=estebankbors-22/+10
Use larger span for adjustment THIR expressions Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions. These spans are recoded when we first create the adjustment during typecheck. For example, an autoref adjustment triggered by a method call will record the span of the entire method call. The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-29fix(lint): don't suggest refutable patterns to "fix" irrefutable bindMichael Howell-0/+37
In function arguments and let bindings, do not suggest changing `C` to `Foo::C` unless `C` is the only variant of `Foo`, because it won't work. The general warning is still kept, because code like this is confusing. Fixes #88730
2021-09-28Rollup merge of #89283 - camelid:issue-83564-test, r=davidtwcoGuillaume Gomez-0/+26
Add regression test for issue #83564 cc #83564 r? ``@davidtwco``
2021-09-28review commentsEsteban Kuber-3/+3
2021-09-29Suggest similarly named assoc items in trait implsHirochika Matsumoto-0/+122
Previously, the compiler didn't suggest similarly named associated items unlike we do in many situations. This patch adds such diagnostics for associated functions, types and constants.
2021-09-27Auto merge of #89263 - ↵bors-36/+140
TaKO8Ki:suggest-both-immutable-and-mutable-trait-implementations, r=estebank Suggest both of immutable and mutable trait implementations closes #85865
2021-09-26Add regression test for issue #83564Noah Lev-0/+26
2021-09-26Detect when negative literal indices are used and suggest appropriate codeEsteban Kuber-0/+79
2021-09-27test suggesting immutable or mutable trait implementationsTakayuki Maeda-36/+82
2021-09-27fix test errorTakayuki Maeda-4/+6
2021-09-27better suggestionsTakayuki Maeda-26/+34
2021-09-26Auto merge of #89101 - ehuss:compiletest-incremental-build, r=Mark-Simulacrumbors-1/+1
Support incremental in compiletest for non-incremental modes. This adds first-class support for using incremental builds in non-incremental-mode tests. These tests previously manually passed `-C incremental=tmp/foo` which resulted in reusing the same tmp folder between runs. This means that these tests could fail whenever the on-disk incremental format changed (such as when updating one's local source tree). This changes it so that these tests can pass a `// incremental-build` header which instructs compiletest to create a set aside a dedicated incremental directory which will be cleared before the test starts to ensure it has a clean slate.
2021-09-26fix the relevant testsTakayuki Maeda-16/+28
2021-09-26suggest both immutable and mutable trait implementationsTakayuki Maeda-0/+36
2021-09-25Use larger span for adjustments on method callsAaron Hill-22/+10
Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-23Support incremental in compiletest for non-incremental modes.Eric Huss-1/+1
2021-09-23Suggest `_` in turbofish if param will be inferred from fn argumentEsteban Kuber-0/+37
2021-09-17Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011Guillaume Gomez-185/+396
Point to closure when emitting 'cannot move out' for captured variable Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question). cc `@Aaron1011`
2021-09-16Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisabors-59/+105
Point at argument instead of call for their obligations When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled. Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`. When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression. Current output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:31 | 2 | let p = Some(45).and_then({ | ______________________--------_^ | | | | | required by a bound introduced by this call 3 | | |x| println!("doubling {}", x); 4 | | Some(x * 2) | | ----------- 5 | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Previous output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:22 | 2 | let p = Some(45).and_then({ | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Partially address #27300. Will require rebasing on top of #88546.
2021-09-16Point at argument when evaluating `Path`'s boundsEsteban Kuber-13/+2
When evaluating an `ExprKind::Call`, we first have to `check_expr` on it's callee. When this one is a `ExprKind::Path`, we had to evaluate the bounds introduced for its arguments, but by the time we evaluated them we no longer had access to the argument spans. Now we special case this so that we can point at the right place on unsatisfied bounds. This also allows the E0277 deduplication to kick in correctly, so we now emit fewer errors.
2021-09-16Point at call span that introduced obligation for the argEsteban Kuber-46/+103
2021-09-15Move object safety suggestions to the end of the errorEsteban Kuber-2/+2
2021-09-15Point to closure when emitting 'cannot move out' for captured variableFabian Wolff-185/+396
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-24/+34
Use smaller spans for some structured suggestions Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts
2021-09-12Fix suggestion for nested struct patternsFabian Wolff-0/+60
2021-09-10Rollup merge of #88578 - ↵Manish Goregaokar-0/+87
notriddle:notriddle/suggest-add-reference-to-for-loop-iter, r=nagisa fix(rustc): suggest `items` be borrowed in `for i in items[x..]` Fixes #87994
2021-09-07test: add case for mutating iteratorMichael Howell-1/+44
Note that this incorrectly suggests a shared borrow, but at least we know it's happening.
2021-09-06Suggest deriving traits if possiblePaul Trojahn-0/+128
This only applies to builtin derives as I don't think there is a clean way to get the available derives in typeck. Closes #85851
2021-09-06Auto merge of #88631 - camelid:sugg-span, r=davidtwcobors-0/+134
Improve structured tuple struct suggestion Previously, the span was just for the constructor name, which meant it would result in syntactically-invalid code when applied. Now, the span is for the entire expression. I also changed it to use `span_suggestion_verbose`, for two reasons: 1. Now that the suggestion span has been corrected, the output is a bit cluttered and hard to read. Putting the suggestion its own window creates more space. 2. It's easier to see what's being suggested, since now the version after the suggestion is applied is shown. r? `@davidtwco`
2021-09-01Ensure suggestion is in its own diagnostic windowNoah Lev-32/+48
For two reasons: 1. Now that the suggestion span has been corrected, the output is a bit cluttered and hard to read. Putting the suggestion its own window creates more space. 2. It's easier to see what's being suggested, since now the version after the suggestion is applied is shown.
2021-09-01Fix span used for structured tuple struct suggestionNoah Lev-0/+118
(And same for tuple variants.) Previously, the span was just for the constructor name, which meant it would result in syntactically-invalid code when applied. Now, the span is for the entire expression.
2021-09-01fix(rustc): suggest `items` be borrowed in `for i in items[x..]`Michael Howell-0/+44
Fixes #87994
2021-09-01Stop sorting bodies by span.Camille GILLOT-25/+25
The definition order is already close to the span order, and only differs in corner cases.
2021-08-27Remove `Session.if_let_suggestions`Aaron Hill-1/+13
We can instead if either the LHS or RHS types contain `TyKind::Error`. In addition to covering the case where we would have previously updated `if_let_suggestions`, this might also prevent redundant errors in other cases as well.
2021-08-18Use more accurate spans when proposing adding lifetime to itemEsteban Kuber-12/+12
2021-08-16Use note to point at bound introducing requirementEsteban Küber-114/+193
2021-08-13Rollup merge of #87795 - estebank:erase-lifetimes-in-suggestion, r=oli-obkGuillaume Gomez-1/+30
Avoid ICE caused by suggestion When suggesting dereferencing something that can be iterable in a `for` loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region constraints already solved' panic. Fix #87657, fix #87709, fix #87651.