about summary refs log tree commit diff
path: root/src/test/ui/tuple
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-624/+0
2023-01-05Tweak wording of fn call with wrong number of argsEsteban Küber-9/+9
2022-12-13Make some diagnostics not depend on the source of what they reference being ↵Oli Scherer-6/+0
available
2022-09-12Auto merge of #100251 - compiler-errors:tuple-trait-2, r=jackh726bors-0/+94
Implement `std::marker::Tuple` Split out from #99943 (https://github.com/rust-lang/rust/pull/99943#pullrequestreview-1064459183). Implements part of rust-lang/compiler-team#537 r? `@jackh726`
2022-09-03Shrink suggestion span of argument mismatch errorMichael Goulet-2/+2
2022-08-13Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, ↵Michael Goulet-3/+6
r=lcnr Argument type error improvements Motivated by this interesting code snippet: ```rust #[derive(Copy, Clone)] struct Wrapper<T>(T); fn foo(_: fn(i32), _: Wrapper<i32>) {} fn f(_: u32) {} fn main() { let w = Wrapper::<isize>(1isize); foo(f, w); } ``` Which currently errors like: ``` error[E0308]: arguments to this function are incorrect --> src/main.rs:10:5 | 10 | foo(f, w); | ^^^ - - expected `i32`, found `isize` | | | expected `i32`, found `u32` | = note: expected fn pointer `fn(i32)` found fn item `fn(u32) {f}` = note: expected struct `Wrapper<i32>` found struct `Wrapper<isize>` note: function defined here --> src/main.rs:4:4 | 4 | fn foo(_: fn(i32), _: Wrapper<i32>) {} | ^^^ ---------- --------------- ``` Specifically, that double `expected .. found ..` which is very difficult to correlate to the types in the arguments. Also, the fact that "expected `i32`, found `isize`" and the other argument mismatch label don't even really explain what's going on here. After this PR: ``` error[E0308]: arguments to this function are incorrect --> $DIR/two-mismatch-notes.rs:10:5 | LL | foo(f, w); | ^^^ | note: expected fn pointer, found fn item --> $DIR/two-mismatch-notes.rs:10:9 | LL | foo(f, w); | ^ = note: expected fn pointer `fn(i32)` found fn item `fn(u32) {f}` note: expected struct `Wrapper`, found a different struct `Wrapper` --> $DIR/two-mismatch-notes.rs:10:12 | LL | foo(f, w); | ^ = note: expected struct `Wrapper<i32>` found struct `Wrapper<isize>` note: function defined here --> $DIR/two-mismatch-notes.rs:4:4 | LL | fn foo(_: fn(i32), _: Wrapper<i32>) {} | ^^^ ---------- --------------- error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. ``` Yeah, it's a bit verbose, but much clearer IMO. --- Open to discussions about how this could be further improved. Motivated by `@jyn514's` [tweet](https://mobile.twitter.com/joshuayn514/status/1558042020601634816) here.
2022-08-13Do not inline non-simple argument type errors into labelsMichael Goulet-3/+6
2022-08-12Point out a single arg if we have a single arg incompatibilityMichael Goulet-2/+2
2022-08-07Add tuple trait testsMichael Goulet-0/+94
2022-07-07Shorten span for closures.Camille GILLOT-1/+1
2022-06-28Remove `final_arg_types`, improve tuple wrapping suggestionMichael Goulet-2/+52
2022-06-27Use typed indices in argument mismatch algorithmMichael Goulet-2/+2
2022-06-19Make missing argument placeholder more obvious that it's a placeholderMichael Goulet-2/+2
2022-05-06Point at closure args tooJack Huey-0/+5
2022-04-16Implementation for 65853Jack Huey-10/+33
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-04check extra args even if the function is not c_variadicMichael Goulet-0/+21
2022-03-03delay bug instead of skipping check_exprMichael Goulet-0/+34
2022-02-27only check method inputs onceMichael Goulet-0/+36
2022-02-25Add one more case to avoid ICEouz-a-0/+36
2022-01-18Implement tuple array diagnosticthreadexception-0/+16
Co-authored-by: David Wood <Q0KPU0H1YOEPHRY1R2SN5B5RL@david.davidtw.co>
2021-11-14Move some tests to more reasonable directoriesCaio-0/+13
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-2/+2
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-03-06Move some tests to more suitable subdirsYuki Okushi-0/+21
2021-02-16Move some tests to more reasonable directoriesCaio-0/+15
2020-10-11rustc_parse: More precise spans for `tuple.0.0`Vadim Petrochenkov-4/+4
2020-07-02Add some requested testsVadim Petrochenkov-0/+1
2020-07-02Update dtolnay's tests that now workVadim Petrochenkov-33/+10
2020-07-02Add test for errors triggered on parts of decomposed indexDavid Tolnay-0/+28
2020-07-02Add test for tuple indexed with float in macro inputDavid Tolnay-0/+20
2020-07-02Add tests in which the token really is a floatDavid Tolnay-0/+21
2020-07-02Test a range, which is not nested indexingDavid Tolnay-0/+3
2020-07-02Test even deeper nested indexingDavid Tolnay-0/+3
2020-07-02Add test of tuple nested indexingDavid Tolnay-0/+6
2020-07-02parser: Break float tokens into parts in tuple field positionsVadim Petrochenkov-21/+0
2020-02-06rustc_macros: don't limit the -Zmacro-backtrace suggestion to extern macros.Eduard-Mihai Burtescu-0/+4
2020-01-09Update testsVadim Petrochenkov-2/+16
2019-11-26Refactor 'parse_enum_item' to use 'parse_delim_comma_seq'Janusz Marcinkiewicz-3/+9
2019-11-18Specific labels when referring to "expected" and "found" typesEsteban Küber-8/+8
2019-11-06Remove "here" from "expected one of X here"Esteban Küber-3/+3
2019-10-27Gather together usefulness testsNadrieril-23/+0
I took most tests that were testing only for match exhaustiveness, pattern refutability or match arm reachability, and put them in the same test folder.
2019-05-28Correct pluralisation of tuple/array/associated type binding mismatch errorsvarkor-2/+2
2019-03-11Update testsVadim Petrochenkov-6/+6
2019-03-02Point at enum definition when match patterns are not exhaustiveEsteban Küber-0/+5
``` error[E0004]: non-exhaustive patterns: type `X` is non-empty --> file.rs:9:11 | 1 | / enum X { 2 | | A, | | - variant not covered 3 | | B, | | - variant not covered 4 | | C, | | - variant not covered 5 | | } | |_- `X` defined here ... 9 | match x { | ^ | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms error[E0004]: non-exhaustive patterns: `B` and `C` not covered --> file.rs:11:11 | 1 | / enum X { 2 | | A, 3 | | B, 4 | | C, | | - not covered 5 | | } | |_- `X` defined here ... 11 | match x { | ^ patterns `C` not covered ``` When a match expression doesn't have patterns covering every variant, point at the enum's definition span. On a best effort basis, point at the variant(s) that are missing. This does not handle the case when the missing pattern is due to a field's enum variants: ``` enum E1 { A, B, C, } enum E2 { A(E1), B, } fn foo() { match E2::A(E1::A) { E2::A(E1::B) => {} E2::B => {} } //~^ ERROR `E2::A(E1::A)` and `E2::A(E1::C)` not handled } ``` Unify look between match with no arms and match with some missing patterns. Fix #37518.
2019-01-06tests: Do not use `-Z parse-only`, continue compilation to test recoveryVadim Petrochenkov-3/+1
2018-12-31Auto merge of #57047 - euclio:field-structured-suggestions, r=estebankbors-2/+2
use structured suggestions for nonexistent fields r? @estebank
2018-12-31use structured suggestions for nonexistent fieldsAndy Russell-2/+2
2018-12-27Fix rebase and more CI failuresVadim Petrochenkov-2/+2
2018-12-27Do not abort compilation if expansion produces errorsVadim Petrochenkov-6/+24
Fix a number of uncovered deficiencies in diagnostics
2018-12-25Remove licensesMark Rousskov-102/+12
2018-08-31cleanup: Add main functions to some UI testsVadim Petrochenkov-7/+4