about summary refs log tree commit diff
path: root/src/test/ui/suggestions
AgeCommit message (Collapse)AuthorLines
2022-04-28Revert diagnostic duplication and accidental stabilizationOli Scherer-231/+34
2022-04-27Auto merge of #96371 - c410-f3r:z-errors, r=petrochenkovbors-0/+55
Move some tests to more reasonable places cc https://github.com/rust-lang/rust/issues/73494 r? `@petrochenkov`
2022-04-26Move some tests to more reasonable placesCaio-0/+55
2022-04-27Rollup merge of #96385 - ↵Dylan DPC-2/+20
marmeladema:nll-fix-trait-lifetime-bound-suggestions, r=jackh726 Recover most `impl Trait` and `dyn Trait` lifetime bound suggestions under NLL This is done by replacing the duplicated (and very partial) implementation from borrowck with one inspsired from `NiceRegionError::try_report_static_impl_trait` and by re-using `suggest_new_region_bound`. Fixes #96277 r? ```@jackh726```
2022-04-26Rollup merge of #96372 - compiler-errors:field-method-suggest, r=oli-obkGuillaume Gomez-0/+40
Suggest calling method on nested field when struct is missing method Similar to the suggestion to change `x.field` to `x.nested.field`, implement a similar suggestion for when `x.method()` should be replaced with `x.nested.method()`.
2022-04-25Replace suggest_constraining_param with suggest_restricting_param_boundWill Crichton-1/+4
to fix incorrect suggestion for trait bounds involving binary operators. Fixes #93927, #92347, #93744.
2022-04-25Recover most `impl Trait` and `dyn Trait` lifetime bound suggestions under NLLmarmeladema-2/+20
2022-04-24suggestion if struct field has methodMichael Goulet-0/+40
2022-04-24Bless testsmarmeladema-6/+58
2022-04-22Auto merge of #96144 - c410-f3r:z-errors, r=petrochenkovbors-0/+43
Move some tests to more reasonable places cc #73494 r? `@petrochenkov`
2022-04-21Move some tests to more reasonable directoriesCaio-0/+43
2022-04-19Rollup merge of #96122 - ↵Dylan DPC-0/+50
TaKO8Ki:fix-invalid-error-for-suggestion-to-add-slice-in-pattern-matching, r=nagisa Fix an invalid error for a suggestion to add a slice in pattern-matching closes #96103
2022-04-19Auto merge of #95379 - icewind1991:suggest-associated-type-more, r=jackh726bors-8/+5
show suggestion to replace generic bounds with associated types in more cases Moves the hint to replace generic parameters with associated type bounds from the "not all associated type bounds are specified"(`E0191`) to "to many generic type parameters provided"(`E0107`). Since `E0191` is only emitted in places where all associated types must be specified (when creating `dyn` types), the suggesting is currently not shown for other generic type uses (such as in generic type bounds). With this change the suggesting is always emitted when the number of excess generic parameters matches the number of unbound associated types. Main motivation for the change was a lack of useful suggesting when doing ```rust fn foo<I: Iterator<usize>>(i: I) {} ```
2022-04-18implement `Deref` for `Bar`Takayuki Maeda-2/+30
2022-04-17Bless nll test.Camille GILLOT-0/+106
2022-04-17Bless tests.Camille GILLOT-18/+250
2022-04-17show suggestion to replace generic bounds with associated types in more casesRobin Appelman-8/+5
2022-04-17fix an invalid error for a suggestion to add a slice in pattern-matchingTakayuki Maeda-0/+22
2022-04-16Auto merge of #92364 - jackh726:Quantumplation/65853/param-heuristics, ↵bors-53/+275
r=estebank Better method call error messages Rebase/continuation of #71827 ~Based on #92360~ ~Based on #93118~ There's a decent description in #71827 that I won't copy here (for now at least) In addition to rebasing, I've tried to restore most of the original suggestions for invalid arguments. Unfortunately, this does make some of the errors a bit verbose. To fix this will require a bit of refactoring to some of the generalized error suggestion functions, and I just don't have the time to go into it right now. I think this is in a state that the error messages are overall better than before without a reduction in the suggestions given. ~I've tried to split out some of the easier and self-contained changes into separate commits (mostly in #92360, but also one here). There might be more than can be done here, but again just lacking time.~ r? `@estebank` as the original reviewer of #71827
2022-04-16Implementation for 65853Jack Huey-53/+275
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes. The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other. We then modify that algorithm to detect 4 cases: - A function input is missing - An extra argument was provided - The type of an argument is straight up invalid - Two arguments have been swapped - A subset of the arguments have been shuffled (We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.) It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site. The basic sketch of the algorithm is as follows: - Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input. - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type". - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument. - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input - Swapped / Permuted arguments are identified with a cycle detection algorithm. As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again. Note that there's a lot of extra complexity: - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix. - Closure arguments are wrapped in a tuple and need to be unwrapped - We need to resolve closure types after the rest, to allow the most specific type constraints - We need to handle imported C functions that might be variadic in their inputs. I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-15Rollup merge of #95194 - kckeiks:update-algo-in-find-use-placement, r=pnkfelixDylan DPC-1/+0
remove find_use_placement A more robust solution to finding where to place use suggestions was added in #94584. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it instead of calling `find_use_placement` Fixes #94941
2022-04-10only suggest removing semicolon when expr implements traitMichael Goulet-9/+63
2022-04-05Rollup merge of #95654 - notriddle:notriddle/issue-95616, r=davidtwcoDylan DPC-0/+35
diagnostics: use correct span for const generics Fixes #95616
2022-04-05Rollup merge of #95525 - ohno418:suggest-derivable-trait-E0277, ↵Dylan DPC-0/+8
r=compiler-errors Suggest derivable trait on E0277 error Closes https://github.com/rust-lang/rust/issues/95099 .
2022-04-05Suggest derivable trait on E0277ohno418-0/+8
2022-04-04Refer to the TraitRef::identity in the message to be clearerEsteban Kuber-2/+2
2022-04-04Dedup logic and improve output for other types that impl traitEsteban Kuber-2/+2
2022-04-04Fix list lengthEsteban Kuber-0/+2
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-7/+5
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-04-04diagnostics: use correct span for const genericsMichael Howell-0/+35
Fixes #95616
2022-04-03Improve method name suggestionsOliver Downard-1/+1
Attempts to improve method name suggestions when a matching method name is not found. The approach taken is use the Levenshtein distance and account for substrings having a high distance but can sometimes be very close to the intended method (eg. empty vs is_empty).
2022-03-31remove find_use_placementFausto-1/+0
A more robust solution to finding where to place use suggestions was added. The algorithm uses the AST to find the span for the suggestion so we pass this span down to the HIR during lowering and use it. Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-03-30Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakisbors-3/+43
Lazy type-alias-impl-trait take two ### user visible change 1: RPIT inference from recursive call sites Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned. ```rust fn bar(b: bool) -> impl std::fmt::Debug { if b { return 42 } let x: u32 = bar(false); // this errors on stable 99 } ``` The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type. ### user visible change 2: divergence between RPIT and TAIT in return statements Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So ```rust #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![42]; } std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![42] } std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended) } ``` But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same: ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![]; } let mut x = foo(false); x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator vec![] } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![]; } let mut x = bar(false); x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator vec![] } ``` ### user visible change 3: TAIT does not merge types across branches In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile. ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { vec![42_i32] } else { std::iter::empty().collect() //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } ``` It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this). ### PR formalities previous attempt: #92007 This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893 fixes #93411 fixes #88236 fixes #89312 fixes #87340 fixes #86800 fixes #86719 fixes #84073 fixes #83919 fixes #82139 fixes #77987 fixes #74282 fixes #67830 fixes #62742 fixes #54895
2022-03-29Rollup merge of #95437 - notriddle:notriddle/issue-79076, r=compiler-errorsDylan DPC-0/+61
diagnostics: regression test for derive bounds Closes #79076
2022-03-29diagnostics: regression test for derive boundsMichael Howell-0/+61
Closes #79076
2022-03-29Rollup merge of #95415 - notriddle:notriddle/issue-82081, r=Dylan-DPCDylan DPC-0/+57
diagnostics: regression test for HashMap iter_mut suggestion Closes #82081
2022-03-28diagnostics: add regression test for #82081Michael Howell-0/+57
2022-03-28Remove opaque type obligation and just register opaque types as they are ↵Oli Scherer-27/+16
encountered. This also registers obligations for the hidden type immediately.
2022-03-28Revert to inference variable based hidden type computation for RPITOli Scherer-39/+54
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-45/+81
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-28Remove duplicated and unused test filesCaio-65/+0
2022-03-22remove [async output] from impl FutureMichael Goulet-1/+1
2022-03-19diagnostics: do not give Option::as_ref suggestion for complex matchMichael Howell-0/+24
Fixes #82528
2022-03-12Auto merge of #94711 - ouz-a:master3, r=oli-obkbors-0/+92
Return early to fix ICE This fixes #94627, ICE happens because compiler tries to suggest constraining type parameter but the only constraint is implicit `std::Sized` one, so it gets removed and there is nothing to suggest resulting in ICE.
2022-03-11Rollup merge of #94839 - ↵Dylan DPC-0/+56
TaKO8Ki:suggest-using-double-colon-for-struct-field-type, r=cjgillot Suggest using double colon when a struct field type include single colon #92685
2022-03-11fix a suggestion messageTakayuki Maeda-6/+6
2022-03-11suggest using double colon when using single colon in struct field type pathTakayuki Maeda-0/+56
2022-03-10Rollup merge of #94788 - estebank:removal-suggestion, r=petrochenkovMatthias Krüger-0/+113
Account for suggestions for complete removal of lines Fix #94192.
2022-03-09Account for suggestions for complete removal of linesEsteban Kuber-0/+113
Fix #94192.
2022-03-09Auto merge of #94515 - estebank:tweak-move-error, r=davidtwcobors-11/+31
Tweak move error Point at method definition that causes type to be consumed. Fix #94056.