about summary refs log tree commit diff
path: root/src/test/ui/numeric
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-11656/+0
2022-12-14Rollup merge of #105161 - cassaundra:numeric-literal-error, r=nnethercoteMatthias Krüger-0/+84
Refine when invalid prefix case error arises Fix cases where the "invalid base prefix for number literal" error arises with suffixes that look erroneously capitalized but which are actually invalid.
2022-12-12Refine when invalid prefix case error arisesCassaundra Smith-0/+84
Fix cases where the "invalid base prefix for number literal" error arises with suffixes that look erroneously capitalized but which are in fact invalid.
2022-12-08Point at LHS on binop type err if relevantEsteban Küber-168/+504
2022-04-16Implementation for 65853Jack Huey-2260/+5680
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-01-31Write UI tests, tweak message5225225-0/+252
2021-12-03Remove incorrect newline from float cast suggestionEsteban Kuber-10/+10
2021-11-14Move some tests to more reasonable directoriesCaio-0/+795
2021-09-19Rollup merge of #87960 - ↵Yuki Okushi-1/+4
hkmatsumoto:suggest-inexisting-field-for-unmentioned-field, r=estebank Suggest replacing an inexisting field for an unmentioned field Fix #87938 This PR adds a suggestion to replace an inexisting field for an unmentioned field. Given the following code: ```rust enum Foo { Bar { alpha: u8, bravo: u8, charlie: u8 }, } fn foo(foo: Foo) { match foo { Foo::Bar { alpha, beta, // `bravo` miswritten as `beta` here. charlie, } => todo!(), } } ``` the compiler now emits the error messages below. ```text error[E0026]: variant `Foo::Bar` does not have a field named `beta` --> src/lib.rs:9:13 | 9 | beta, // `bravo` miswritten as `beta` here. | ^^^^ | | | variant `Foo::Bar` does not have this field | help: `Foo::Bar` has a field named `bravo`: `bravo` ``` Note that this suggestion is available iff the number of inexisting fields and unmentioned fields are both 1.
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-593/+725
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-13Suggest replacing an inexisting field for an unmentioned fieldHirochika Matsumoto-1/+4
This PR adds a suggestion to replace an inexisting field for an unmentioned field. Given the following code: ```rust enum Foo { Bar { alpha: u8, bravo: u8, charlie: u8 }, } fn foo(foo: Foo) { match foo { Foo::Bar { alpha, beta, // `bravo` miswritten as `beta` here. charlie, } => todo!(), } } ``` the compiler now emits the error messages below. ```text error[E0026]: variant `Foo::Bar` does not have a field named `beta` --> src/lib.rs:9:13 | 9 | beta, // `bravo` miswritten as `beta` here. | ^^^^ | | | variant `Foo::Bar` does not have this field | help: `Foo::Bar` has a field named `bravo`: `bravo` ``` Note that this suggestion is available iff the number of inexisting fields and unmentioned fields are both 1.
2021-09-01Ensure suggestion is in its own diagnostic windowNoah Lev-4/+6
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-2/+3
(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-08-12Use smaller spans for some structured suggestionsEsteban Kuber-593/+725
Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts * E0212
2021-08-11Modify structured suggestion outputEsteban Küber-333/+333
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-02-04typeck: Emit structured suggestions for tuple struct syntaxCamelid-1/+1
And tuple variant syntax, but that didn't fit in the subject :) Now the fact that these are suggestions is exposed both to the layout engine and to IDEs and rustfix for automatic application.
2020-09-29Say "doesn't" instead of "wouldn't" in convert messageCamelid-132/+132
2020-09-29Add article after "to"Camelid-227/+227
Also added missing backtick in "you can cast" message.
2020-09-27Use correct article in help message for conversion or castCamelid-119/+119
Before it always used `an`; now it uses the correct article for the type.
2020-06-16fixup! Note numeric literals that can never fit in an expected typeAyaz Hafiz-125/+25
2020-06-16fixup! Note numeric literals that can never fit in an expected typeAyaz Hafiz-1/+416
2020-06-13fixup! Note numeric literals that can never fit in an expected typeAyaz Hafiz-5/+5
2020-06-13Note numeric literals that can never fit in an expected typeAyaz Hafiz-0/+96
re https://github.com/rust-lang/rust/pull/72380#discussion_r438289385 Given the toy code ```rust fn is_positive(n: usize) { n > -1_isize; } ``` We currently get a type mismatch error like the following: ``` error[E0308]: mismatched types --> src/main.rs:2:9 | 2 | n > -1_isize; | ^^^^^^^^ expected `usize`, found `isize` | help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit | 2 | n > (-1_isize).try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` But clearly, `-1` can never fit into a `usize`, so the suggestion will always panic. A more useful message would tell the user that the value can never fit in the expected type: ``` error[E0308]: mismatched types --> test.rs:2:9 | 2 | n > -1_isize; | ^^^^^^^^ expected `usize`, found `isize` | note: `-1_isize` can never fit into `usize` --> test.rs:2:9 | 2 | n > -1_isize; | ^^^^^^^^ ``` Which is what this commit implements. I only added this check for negative literals because - Currently we can only perform such a check for literals (constant value propagation is outside the scope of the typechecker at this point) - A lint error for out-of-range numeric literals is already emitted IMO it makes more sense to put this check in librustc_lint, but as far as I can tell the typecheck pass happens before the lint pass, so I've added it here. r? @estebank
2020-06-11fixup! Provide suggestion to convert numeric op LHS rather than unwrapping RHSAyaz Hafiz-138/+463
2020-06-11Provide suggestion to convert numeric op LHS rather than unwrapping RHSAyaz Hafiz-0/+1700
Given a code ```rust fn foo(x: u8, y: u32) -> bool { x > y } fn main() {} ``` it could be more helpful to provide a suggestion to do "u32::from(x)" rather than "y.try_into().unwrap()", since the latter may panic. We do this by passing the LHS of a binary expression up the stack into the coercion checker. Closes #73145
2020-05-20refactor check_for_castBastian Kauschke-0/+10
2020-04-28Fix numeric-cast tests for new `into` suggestionSamrat Man Singh-63/+43
Remove `integer-into.rs` since the numeric-cast tests already cover these cases.
2020-04-12Add blessed tests after compiler message fixYashhwanth Ram-28/+20
2019-11-21Point at type in `let` assignment on type errorsEsteban Küber-7/+21
2019-11-18Surround types with backticks in type errorsEsteban Küber-278/+278
2019-10-24Increase spacing for suggestions in diagnosticsEsteban Küber-0/+236
Make the spacing between the code snippet and verbose structured suggestions consistent with note and help messages.
2019-06-19fix indentationCedric-1/+1
2019-06-19provide variant definition on tuple struct unknow field errorCedric-1/+4
2019-06-19adt hint pointing to adt spanCedric-4/+3
2019-06-17suggest tuple struct syntaxCedric-3/+4
2019-05-03Reword casting messageEsteban Küber-83/+83
2019-04-29Account for const fns to avoid incorrect suggestionsEsteban Küber-0/+59
2019-04-29Add testEsteban Küber-0/+21
2019-04-29Suggest try_into when possibleEsteban Küber-359/+2963
2019-04-18hide `--explain` hint if error has no extended infoAndy Russell-1/+1
2019-03-16use the identifier span for missing struct fieldAndy Russell-1/+1
2018-12-25Remove licensesMark Rousskov-170/+139
2018-08-14Merged migrated compile-fail tests and ui tests. Fixes #46841.David Wood-0/+1307