summary refs log tree commit diff
path: root/src/test/ui/resolve
AgeCommit message (Collapse)AuthorLines
2022-06-07Remove arg_matrix.rs, bless testsMichael Goulet-5/+3
2022-05-06Resolve vars in note_type_errJack Huey-2/+2
2022-05-05Rollup merge of #96507 - TaKO8Ki:suggest-calling-associated-function, r=lcnrMatthias Krüger-0/+10
Suggest calling `Self::associated_function()` closes #96453
2022-05-05suggest calling `Self::associated_function()`Takayuki Maeda-0/+10
do not suggest when trait_ref is some Update compiler/rustc_resolve/src/late/diagnostics.rs Co-authored-by: lcnr <rust@lcnr.de> use helper struct add a test for functions with some params refactor debug log
2022-05-03Tweak wordingEsteban Kuber-14/+14
2022-05-03When suggesting to import an item, also suggest changing the path if appropriateEsteban Küber-7/+42
When we don't find an item we search all of them for an appropriate import and suggest `use`ing it. This is sometimes done for expressions that have paths with more than one segment. We now also suggest changing that path to work with the `use`. Fix #95413
2022-05-01Move some tests to more reasonable placesCaio-0/+200
2022-04-30When encountering a binding that could be a const or unit variant, suggest ↵Esteban Kuber-17/+14
the right path
2022-04-26Move some tests to more reasonable placesCaio-0/+26
2022-04-16Implementation for 65853Jack Huey-3/+5
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-03-28Remove opaque type obligation and just register opaque types as they are ↵Oli Scherer-2/+13
encountered. This also registers obligations for the hidden type immediately.
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-22/+2
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-04Update use_suggestion_placement.rs test, removing the FIXME that this PR fixes.Felix S. Klock II-13/+5
(There is another issue, in that the fixed output is not ideally indented, but that is a pre-existing issue and should not block this PR.)
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-2/+22
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-22/+2
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-01-19Only suggest adding `!` to expressions that can be macro invocationEsteban Kuber-3/+60
2021-12-11Tweak assoc type obligation spansEsteban Kuber-3/+5
* Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors
2021-11-20Rollup merge of #91021 - compiler-errors:print_future_output, r=estebankMatthias Krüger-1/+1
Elaborate `Future::Output` when printing opaque `impl Future` type I would love to see the `Output =` type when printing type errors involving opaque `impl Future`. [Test code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a800b481edd31575fbcaf5771a9c3678) Before (cut relevant part of output): ``` note: while checking the return type of the `async fn` --> /home/michael/test.rs:5:19 | 5 | async fn bar() -> usize { | ^^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `usize` found opaque type `impl Future` ``` After: ``` note: while checking the return type of the `async fn` --> /home/michael/test.rs:5:19 | 5 | async fn bar() -> usize { | ^^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `usize` found opaque type `impl Future<Output = usize>` ``` Note the "found opaque type `impl Future<Output = usize>`" in the new output. ---- Questions: 1. We skip printing the output type when it's a projection, since I have been seeing some types like `impl Future<Output = <[static generator@/home/michael/test.rs:2:11: 2:21] as Generator<ResumeTy>>::Return>` which are not particularly helpful and leak implementation detail. * Am I able to normalize this type within `rustc_middle::ty::print::pretty`? Alternatively, can we normalize it when creating the diagnostic? Otherwise, I'm fine with skipping it and falling back to the old output. * Should I suppress any other types? I didn't encounter anything other than this generator projection type. 2. Not sure what the formatting of this should be. Do I include spaces in `Output = `?
2021-11-19Rollup merge of #90961 - estebank:suggest-removal-of-call, r=nagisaYuki Okushi-6/+9
Suggest removal of arguments for unit variant, not replacement
2021-11-18Print output ty for opaque future tyMichael Goulet-1/+1
2021-11-18Move some tests to more reasonable directoriesCaio-0/+118
2021-11-16Suggest removal of arguments for unit variant, not replacementEsteban Kuber-6/+9
2021-11-14Move some tests to more reasonable directoriesCaio-0/+336
2021-11-06Move some tests to more reasonable directoriesCaio-0/+253
2021-10-21Do not mention a reexported item if it's privateYuki Okushi-0/+35
2021-10-17Rollup merge of #89963 - r00ster91:parenthesisparentheses, r=nagisaMatthias Krüger-3/+3
Some "parenthesis" and "parentheses" fixes "Parenthesis" is the singular (e.g. one `(` or one `)`) and "parentheses" is the plural (multiple `(` or `)`s) and this is not hard to mix up so here are some fixes for that. Inspired by #89958
2021-10-17Some "parenthesis" and "parentheses" fixesr00ster91-3/+3
2021-10-15Bless testsCameron Steffen-1/+1
2021-10-08testsb-naber-0/+37
2021-09-30Rollup merge of #88838 - FabianWolff:issue-88472, r=estebankManish Goregaokar-38/+108
Do not suggest importing inaccessible items Fixes #88472. For this example: ```rust mod a { struct Foo; } mod b { type Bar = Foo; } ``` rustc currently emits: ``` error[E0412]: cannot find type `Foo` in this scope --> test.rs:6:16 | 6 | type Bar = Foo; | ^^^ not found in this scope | help: consider importing this struct | 6 | use a::Foo; | ``` this is incorrect, as applying this suggestion leads to ``` error[E0603]: struct `Foo` is private --> test.rs:6:12 | 6 | use a::Foo; | ^^^ private struct | note: the struct `Foo` is defined here --> test.rs:2:5 | 2 | struct Foo; | ^^^^^^^^^^^ ``` With my changes, I get: ``` error[E0412]: cannot find type `Foo` in this scope --> test.rs:6:16 | 6 | type Bar = Foo; | ^^^ not found in this scope | = note: this struct exists but is inaccessible: a::Foo ``` As for the wildcard mentioned in #88472, I would argue that the warning is actually correct, since the import _is_ unused. I think the real issue is the wrong suggestion, which I have fixed here.
2021-09-27suggest path for tuple structTakayuki Maeda-0/+45
2021-09-26Improve diagnostics for inaccessible itemsFabian Wolff-22/+51
2021-09-26Do not suggest importing inaccessible itemsFabian Wolff-44/+85
2021-09-15Move some tests to more reasonable directoriesCaio-0/+77
2021-09-03Auto merge of #88386 - estebank:unmatched-delims, r=jackh726bors-8/+8
Point at unclosed delimiters as part of the primary MultiSpan Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output. _Context: https://twitter.com/mwk4/status/1430631546432675840_
2021-09-01Auto merge of #88121 - camelid:better-recursive-alias-error, r=estebankbors-6/+6
Improve errors for recursive type aliases Fixes #17539.
2021-08-30`feature(const_generics)` -> `feature(const_param_types)`lcnr-18/+6
2021-08-27Point at unclosed delimiters as part of the primary MultiSpanEsteban Kuber-8/+8
Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output.
2021-08-21Improve errors for recursive type aliasesNoah Lev-6/+6
2021-08-11Modify structured suggestion outputEsteban Küber-39/+39
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-04Remove trailing whitespace from error messagesFabian Wolff-4/+4
2021-07-27Permit deriving default on enums with `#[default]`Jacob Pratt-1/+1
2021-07-08Move [debug_]assert_matches to mod {core, std}::assert.Mara Bos-7/+7
2021-06-24Auto merge of #85427 - ehuss:fix-use-placement, r=jackh726bors-4/+50
Fix use placement for suggestions near main. This fixes an edge case for the suggestion to add a `use`. When running with `--test`, the `main` function will be annotated with an `#[allow(dead_code)]` attribute. The `UsePlacementFinder` would end up using the dummy span of that synthetic attribute. If there are top-level inner attributes, this would place the `use` in the wrong position. The solution here is to ignore attributes with dummy spans. In the process of working on this, I discovered that the `use_suggestion_placement` test was broken. `UsePlacementFinder` is unaware of active attributes. Attributes like `#[derive]` don't exist in the AST since they are removed. Fixing that is difficult, since the AST does not retain enough information. I considered trying to place the `use` towards the top of the module after any `extern crate` items, but I couldn't find a way to get a span for the start of a module block (the `mod` span starts at the `mod` keyword, and it seems tricky to find the spot just after the opening bracket and past inner attributes). For now, I just put some comments about the issue. This appears to have been a known issue in #44215 where the test for it was introduced, and the fix seemed to be deferred to later.
2021-05-19Disallow shadowing const parametersFabian Wolff-0/+77
2021-05-18Fix use placement for suggestions near main.Eric Huss-4/+50
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-1/+1
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-04-23Auto merge of #83729 - JohnTitor:issue-43913, r=estebankbors-13/+11
Add a suggestion when using a type alias instead of trait alias Fixes #43913 r? `@estebank`
2021-04-19fix suggestion for unsized function parameterslcnr-2/+2
2021-04-18Auto merge of #84065 - c410-f3r:tests-tests-tests, r=petrochenkovbors-0/+210
Move some tests to more reasonable directories - 6 cc #73494 r? `@petrochenkov` git mv bad/bad-const-type.* static/ git mv bad/bad-crate-name.* extern git mv bad/bad-env-capture* fn/ git mv bad/bad-expr-lhs.* expr/ git mv bad/bad-expr-path* expr/ git mv bad/bad-extern-link-attrs.* extern/ git mv bad/bad-intrinsic-monomorphization.* intrinsics/ git mv bad/bad-lint-cap* lint/ git mv bad/bad-main.* fn git mv bad/bad-method-typaram-kind.* type/ git mv bad/bad-mid-path-type-params.* fn git mv bad/bad-module.* modules/ git mv bad/bad-sized.* type/ git mv bad/bad-type-env-capture.* fn