about summary refs log tree commit diff
path: root/src/test/ui/inference
AgeCommit message (Collapse)AuthorLines
2022-04-16Implementation for 65853Jack Huey-10/+66
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-03Cleanup feature gates.Camille GILLOT-3/+1
2022-02-08Rollup merge of #92715 - chordtoll:empty-string, r=davidtwcoMatthias Krüger-2/+11
Do not suggest char literal for zero-length strings PR #92507 adds a hint to switch to single quotes when a char is expected and a single-character string literal is provided. The check to ensure the string literal is one character long missed the 0-char case, and would incorrectly offer the hint. This PR adds the missing check, and a test case to confirm the new behavior.
2022-01-16Only suggest char literal for single-character stringschordtoll-2/+11
2022-01-14Don't use source-map when detecting struct field shorthandMichael Goulet-1/+1
2022-01-04Auto merge of #92560 - matthiaskrgr:rollup-jeli7ip, r=matthiaskrgrbors-60/+0
Rollup of 7 pull requests Successful merges: - #91587 (core::ops::unsize: improve docs for DispatchFromDyn) - #91907 (Allow `_` as the length of array types and repeat expressions) - #92515 (RustWrapper: adapt for an LLVM API change) - #92516 (Do not use deprecated -Zsymbol-mangling-version in bootstrap) - #92530 (Move `contains` method of Option and Result lower in docs) - #92546 (Update books) - #92551 (rename StackPopClean::None to Root) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-03Suggest changing quotes when str/char type mismatchchordtoll-0/+100
2021-12-23implement `generic_arg_infer` for array lengthslcnr-60/+0
2021-12-11Tweak assoc type obligation spansEsteban Kuber-1/+1
* 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-12-07Add test with multiple type params failing inferenceEsteban Kuber-12/+45
2021-12-07Refer to const params as "const params" and not "type params"Esteban Kuber-1/+1
2021-12-07Refer to uninferred `const` params by their name, instead of `{ _: _ }`Esteban Kuber-1/+1
When the value of a const param isn't inferred, replace it with the param name from the definition.
2021-12-07Only shown relevant type params in E0283 labelEsteban Kuber-1/+36
When we point at a binding to suggest giving it a type, erase all the type for ADTs that have been resolved, leaving only the ones that could not be inferred. For small shallow types this is not a problem, but for big nested types with lots of params, this can otherwise cause a lot of unnecessary visual output.
2021-11-20Point at source of trait bound obligations in more placesEsteban Kuber-0/+9
Be more thorough in using `ItemObligation` and `BindingObligation` when evaluating obligations so that we can point at trait bounds that introduced unfulfilled obligations. We no longer incorrectly point at unrelated trait bounds (`substs-ppaux.verbose.stderr`). In particular, we now point at trait bounds on method calls. We no longer point at "obvious" obligation sources (we no longer have a note pointing at `Trait` saying "required by a bound in `Trait`", like in `associated-types-no-suitable-supertrait*`). Address part of #89418.
2021-11-19Auto merge of #91033 - JohnTitor:rollup-sr9zg6o, r=JohnTitorbors-0/+162
Rollup of 8 pull requests Successful merges: - #89258 (Make char conversion functions unstably const) - #90578 (add const generics test) - #90633 (Refactor single variant `Candidate` enum into a struct) - #90800 (bootstap: create .cargo/config only if not present) - #90942 (windows: Return the "Not Found" error when a path is empty) - #90947 (Move some tests to more reasonable directories - 9.5) - #90961 (Suggest removal of arguments for unit variant, not replacement) - #90990 (Arenas cleanup) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-11-19Auto merge of #90329 - nbdd0121:typeck, r=nagisabors-2/+75
Try all stable method candidates first before trying unstable ones Currently we try methods in this order in each step: * Stable by value * Unstable by value * Stable autoref * Unstable autoref * ... This PR changes it to first try pick methods without any unstable candidates, and if none is found, try again to pick unstable ones. Fix #90320 CC #88971, hopefully would allow us to rename the "unstable_*" methods for integer impls back. `@rustbot` label T-compiler T-libs-api
2021-11-18Move some tests to more reasonable directoriesCaio-0/+162
2021-11-15Add regression test for issue 90320Gary Guo-2/+75
2021-11-14Move some tests to more reasonable directoriesCaio-0/+38
2021-11-06Move some tests to more reasonable directoriesCaio-0/+15
2021-10-24Point at overlapping impls when type annotations are neededEsteban Kuber-2/+9
2021-10-15Bless testsCameron Steffen-1/+1
2021-09-17Make diagnostics clearer for `?` operatorsYuki Okushi-0/+22
2021-08-16Use note to point at bound introducing requirementEsteban Küber-6/+10
2021-08-14Auto merge of #87600 - JohnTitor:classify-ui-tests, r=petrochenkovbors-0/+220
Move some UI tests to more suitable subdirs The classifui result: https://gist.github.com/JohnTitor/c9e00840990b5e4a8fc562ec3571e427/e06c42226c6038da91e403c33b9947843420cf44 Some notes: - backtrace-debuginfo.rs: previously I skipped this, I'm still not sure what the best dir is. Any ideas? - estr-subtyping.rs: Seems a quite old test so removed, shouldn't? - deref-suggestion.rs: moved to inference as `suggestions` is not an ideal dir. - issue-43023.rs: a bit misclassified, moved to `derives` cc #73494 r? `@petrochenkov`
2021-08-11Modify structured suggestion outputEsteban Küber-4/+4
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-10Move some UI tests to more suitable subdirsYuki Okushi-0/+218
2021-08-03Do not suggest impl traits as type argumentsYuki Okushi-0/+51
2021-07-26Actually infer args in visitorskadmin-0/+60
2021-07-18Remove impl_trait_in_bindings handling on inference error reportingSantiago Pastorino-38/+0
2021-07-02Add a regression test for issue-70703Yuki Okushi-0/+26
2021-06-25Address PR feedbackRyan Levick-2/+2
2021-06-25Change how edition based future compatibility warnings are handledRyan Levick-2/+2
2021-05-06Better rustc_on_unimplemented, and UI test fixesScott McMurray-24/+20
2021-04-05Rollup merge of #81922 - magurotuna:issue81522, r=matthewjasperDylan DPC-0/+31
Let `#[allow(unstable_name_collisions)]` work for things other than function Fixes #81522 In addition to the report in #81522, currently `#[allow(unstable_name_collisions)]` doesn't suppress the corresponding diagnostics even if this attribute is appended to an expression statement or a let statement. It seems like this is because the wrong `HirId` is passed to `struct_span_lint_hir`. It's fixed in this PR, and a regression test for it is also added.
2021-03-30Do not emit a suggestion that causes the E0632 errorJohnTitor-0/+21
2021-03-24Add regression test to ensure `#[allow(unstable_name_collisions)]` worksYusuke Tanaka-0/+31
2021-02-25Rollup merge of #81713 - estebank:unstable-assoc-item-lint, r=oli-obkDylan DPC-7/+28
Account for associated consts in the "unstable assoc item name colission" lint Fix #81663.
2021-02-24Account for associated consts in the "unstable assoc item name colission" lintEsteban Küber-7/+28
Fix #81663.
2021-02-06path trimming: ignore type aliasesDan Aloni-9/+9
2021-01-10Tweak `?` inference error messagesWilliam Bain-8/+8
2021-01-10Note inference failures using `?` conversionWilliam Bain-3/+68
2020-10-23Add regression test for issue-71732Yuki Okushi-0/+36
2020-10-23Add a regression test for issue-72616Yuki Okushi-0/+42
2020-10-06Fix tests from rebaseMatthew Jasper-1/+1
2020-10-06Separate bounds and predicates for associated/opaque typesMatthew Jasper-7/+7
2020-09-02pretty: trim paths of unique symbolsDan Aloni-8/+8
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-05-09adjust testsRalf Jung-2/+3
2020-04-14Rename AssocKind::Method to AssocKind::FnRustin-Liu-2/+2
Rename fn_has_self_argument to fn_has_self_parameter Rename AssocItemKind::Method to AssocItemKind::Fn Refine has_no_input_arg Refine has_no_input_arg Revert has_no_input_arg Refine suggestion_descr Move as_def_kind into AssocKind Signed-off-by: Rustin-Liu <rustin.liu@gmail.com> Fix tidy check issue Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>
2020-04-11rustc: Add a warning count upon completionRoccoDev-1/+5