summary refs log tree commit diff
path: root/src/test/ui/error-codes
AgeCommit message (Collapse)AuthorLines
2021-06-19Revert "Allow specifying alignment for functions"Mark Rousskov-3/+10
This reverts commit 448d07683a6defd567996114793a09c9a8aef5df.
2021-06-10Auto merge of #82639 - jyn514:stable-options, r=Mark-Simulacrumbors-31/+3
Don't pass -Z unstable-options by default for UI tests Unconditionally passing -Z unstable-options makes it impossible to test whether an option requires unstable-options or not. This uncovered quite a lot of bugs, I'll open issues for each. These don't strictly need to be fixed before this is merged, it just makes the diff much larger because of the changes to diagnostics. - https://github.com/rust-lang/rust/issues/82636 - https://github.com/rust-lang/rust/issues/82637 - https://github.com/rust-lang/rust/issues/82638
2021-06-06Don't pass -Z unstable-options by default for UI testsJoshua Nelson-31/+3
- Pass it explicitly where appropriate - Update stderr files and warnings; it turns that unstable-options has far-reaching effects on diagnostics.
2021-06-05Remove `_` from E0121 diagnostic suggestionsDeadbeef-1/+1
2021-05-31Auto merge of #85597 - 0yoyoyo:fix-issue-71563-remove-redundant-args, ↵bors-5/+115
r=petrochenkov Fix span of redundant generic arguments Fixes #71563 Above issue is about lifetime arguments, but generic arguments also have same problem. This PR fixes both help messages.
2021-05-30Fix span of redundant generic arguments0yoyoyo-5/+115
2021-05-28Auto merge of #84968 - FabianWolff:master, r=estebankbors-1/+6
Fix incorrect suggestions for E0605 Fixes #84598. Here is a simplified version of the problem presented in issue #84598: ```Rust #![allow(unused_variables)] #![allow(dead_code)] trait T { fn t(&self) -> i32; } unsafe fn foo(t: *mut dyn T) { (t as &dyn T).t(); } fn main() {} ``` The current output is: ``` error[E0605]: non-primitive cast: `*mut (dyn T + 'static)` as `&dyn T` --> src/main.rs:7:5 | 7 | (t as &dyn T).t(); | ^^^^^^^^^^^^^ invalid cast | help: borrow the value for the cast to be valid | 7 | (&t as &dyn T).t(); | ^ ``` This is incorrect, though: The cast will _not_ be valid when writing `&t` instead of `t`: ``` error[E0277]: the trait bound `*mut (dyn T + 'static): T` is not satisfied --> t4.rs:7:6 | 7 | (&t as &dyn T).t(); | ^^ the trait `T` is not implemented for `*mut (dyn T + 'static)` | = note: required for the cast to the object type `dyn T` ``` The correct suggestion is `&*t`, which I have implemented in this pull request. Of course, this suggestion will always require an unsafe block, but arguably, that's what the user really wants if they're trying to cast a pointer to a reference. In any case, claiming that the cast will be valid after implementing the suggestion is overly optimistic, as the coercion logic doesn't seem to resolve all nested obligations, i.e. the cast may still be invalid after implementing the suggestion. I have therefore rephrased the suggestion slightly ("consider borrowing the value" instead of "borrow the value for the cast to be valid"). Additionally, I have fixed another incorrect suggestion not mentioned in #84598, which relates to casting immutable references to mutable ones: ```rust fn main() { let mut x = 0; let m = &x as &mut i32; } ``` currently leads to ``` error[E0605]: non-primitive cast: `&i32` as `&mut i32` --> t5.rs:3:13 | 3 | let m = &x as &mut i32; | ^^^^^^^^^^^^^^ invalid cast | help: borrow the value for the cast to be valid | 3 | let m = &mut &x as &mut i32; | ^^^^ ``` which is obviously incorrect: ``` error[E0596]: cannot borrow data in a `&` reference as mutable --> t5.rs:3:13 | 3 | let m = &mut &x as &mut i32; | ^^^^^^^ cannot borrow as mutable ``` I've changed the suggestion to a note explaining the problem: ``` error[E0605]: non-primitive cast: `&i32` as `&mut i32` --> t5.rs:3:13 | 3 | let m = &x as &mut i32; | ^^^^^^^^^^^^^^ invalid cast | note: this reference is immutable --> t5.rs:3:13 | 3 | let m = &x as &mut i32; | ^^ note: trying to cast to a mutable reference type --> t5.rs:3:19 | 3 | let m = &x as &mut i32; | ^^^^^^^^ ``` In this example, it would have been even nicer to suggest replacing `&x` with `&mut x`, but this would be much more complex because we would have to take apart the expression to be cast (currently, we only look at its type), and `&x` could be stored in a variable, where such a suggestion would not even be directly applicable: ```rust fn main() { let mut x = 0; let r = &x; let m = r as &mut i32; } ``` My solution covers this case, too.
2021-05-13Auto merge of #83129 - LeSeulArtichaut:thir-unsafeck, r=nikomatsakisbors-1/+15
Introduce the beginning of a THIR unsafety checker This poses the foundations for the THIR unsafety checker, so that it can be implemented incrementally: - implements a rudimentary `Visitor` for the THIR (which will definitely need some tweaking in the future) - introduces a new `-Zthir-unsafeck` flag which tells the compiler to use THIR unsafeck instead of MIR unsafeck - implements detection of unsafe functions - adds revisions to the UI tests to test THIR unsafeck alongside MIR unsafeck This uses a very simple query design, where bodies are unsafety-checked on a body per body basis. This however has some big flaws: - the unsafety-checker builds the THIR itself, which means a lot of work is duplicated with MIR building constructing its own copy of the THIR - unsafety-checking closures is currently completely wrong: closures should take into account the "safety context" in which they are created, here we are considering that closures are always a safe context I had intended to fix these problems in follow-up PRs since they are always gated under the `-Zthir-unsafeck` flag (which is explicitely noted to be unsound). r? `@nikomatsakis` cc https://github.com/rust-lang/project-thir-unsafeck/issues/3 https://github.com/rust-lang/project-thir-unsafeck/issues/7
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-05-11Test `-Zthir-unsafeck` for unsafe function callsLeSeulArtichaut-1/+15
2021-05-11improve diagnosts for GATsb-naber-6/+6
2021-05-06E0583: Include secondary path in error messageDeadbeef-1/+1
2021-05-06Fix incorrect suggestions for E0605Fabian Wolff-1/+6
2021-05-03Rollup merge of #84784 - JulianKnodt:suggest_const, r=lcnrDylan DPC-0/+1
Add help message to suggest const for unused type param r? `@lcnr`
2021-05-01Closure capture borrow diagnostics for disjoint capturesChris Pardy-1/+1
2021-05-01Add help message for unused type paramkadmin-0/+1
2021-04-19fix suggestion for unsized function parameterslcnr-2/+2
2021-04-16Remove #[main] attribute.Charles Lew-20/+0
2021-04-08Rollup merge of #83689 - estebank:cool-bears-hot-tip, r=davidtwcoDylan DPC-4/+20
Add more info for common trait resolution and async/await errors * Suggest `Pin::new`/`Box::new`/`Arc::new`/`Box::pin` in more cases * Point at `impl` and type defs introducing requirements on E0277
2021-04-06Point at `impl` and type defs introducing requirements on E0277Esteban Küber-4/+20
2021-04-06Remove trailing `:` from E0119 messageEsteban Küber-9/+9
2021-04-06Auto merge of #81234 - repnop:fn-alignment, r=lcnrbors-10/+3
Allow specifying alignment for functions Fixes #75072 This allows the user to specify alignment for functions, which can be useful for low level work where functions need to necessarily be aligned to a specific value. I believe the error cases not covered in the match are caught earlier based on my testing so I had them just return `None`.
2021-04-05Allow specifying alignment for functionsWesley Norris-10/+3
2021-04-03Remove redundant `ignore-tidy-linelength` annotationsSimon Jakobi-6/+4
This is step 2 towards fixing #77548. In the codegen and codegen-units test suites, the `//` comment markers were kept in order not to affect any source locations. This is because these tests cannot be automatically `--bless`ed.
2021-03-24resolve late lifetimes by itemJack Huey-11/+11
This reverts commit 22ae20733515d710c1134600bc1e29cdd76f6b9b.
2021-03-23Some refactoringvarkor-2/+2
2021-02-25Rollup merge of #82220 - henryboisdequin:fixes-80853, r=varkorDylan DPC-1/+1
fix the false 'defined here' messages Closes #80853. Take this code: ```rust struct S; fn repro_ref(thing: S) { thing(); } ``` Previously, the error message would be this: ``` error[E0618]: expected function, found `S` --> src/lib.rs:4:5 | 3 | fn repro_ref(thing: S) { | ----- `S` defined here 4 | thing(); | ^^^^^-- | | | call expression requires function error: aborting due to previous error ``` This is incorrect as `S` is not defined in the function arguments, `thing` is defined there. With this change, the following is emitted: ``` error[E0618]: expected function, found `S` --> $DIR/80853.rs:4:5 | LL | fn repro_ref(thing: S) { | ----- is of type `S` LL | thing(); | ^^^^^-- | | | call expression requires function | = note: local variable `S` is not a function error: aborting due to previous error ``` As you can see, this error message points out that `thing` is of type `S` and later in a note, that `S` is not a function. This change does seem like a downside for some error messages. Take this example: ``` LL | struct Empty2; | -------------- is of type `Empty2` ``` As you can see, the error message shows that the definition of `Empty2` is of type `Empty2`. Although this isn't wrong, it would be more helpful if it would say something like this (which was there previously): ``` LL | struct Empty2; | -------------- `Empty2` defined here ``` If there is a better way of doing this, where the `Empty2` example would stay the same as without this change, please inform me. **Update: This is now fixed** CC `@camelid`
2021-02-25add helpful error notes and fix the false 'defined here' messagesHenry Boisdequin-1/+1
2021-02-20Make "missing field" error message more naturalr00ster91-3/+3
2021-02-03make const_err a future incompat lintRalf Jung-0/+3
2021-01-26Tweak suggestion for missing field in patternsEsteban Küber-6/+6
Account for parser recovered struct and tuple patterns to avoid invalid suggestion. Follow up to #81103.
2021-01-23Adjust wording of a diagnosticoli-7/+7
2021-01-23Permit mutable references in all const contextsoli-30/+50
2021-01-19Rollup merge of #81147 - estebank:drop-suggestion, r=varkorGuillaume Gomez-5/+26
Fix structured suggestion for explicit `drop` call
2021-01-19Auto merge of #81103 - zackmdavis:comma_trail, r=davidtwcobors-3/+42
don't suggest erroneous trailing comma after `..` In #76612, suggestions were added for missing fields in patterns. However, the suggestions are being inserted just at the end of the last field in the pattern—before any trailing comma after the last field. This resulted in the "if you don't care about missing fields" suggestion to recommend code with a trailing comma after the field ellipsis (`..,`), which is actually not legal ("`..` must be at the end and cannot have a trailing comma")! Incidentally, the doc-comment on `error_unmentioned_fields` was using `you_cant_use_this_field` as an example field name (presumably copy-paste inherited from the description of Issue #76077), but the present author found this confusing, because unmentioned fields aren't necessarily unusable. The suggested code in the diff this commit introduces to `destructuring-assignment/struct_destructure_fail.stderr` doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier `_`" thing), so you can't really call it a regression; it could be fixed in a separate PR. Resolves #78511. r? `@davidtwco` or `@estebank`
2021-01-18Add test case for suggestion E0283Daiki Ihara-2/+32
2021-01-17Fix structured suggestion for explicit `drop` callEsteban Küber-5/+26
2021-01-16don't suggest erroneous trailing comma after `..`Zack M. Davis-3/+42
In #76612, suggestions were added for missing fields in patterns. However, the suggestions are being inserted just at the end of the last field in the pattern—before any trailing comma after the last field. This resulted in the "if you don't care about missing fields" suggestion to recommend code with a trailing comma after the field ellipsis (`..,`), which is actually not legal ("`..` must be at the end and cannot have a trailing comma")! Incidentally, the doc-comment on `error_unmentioned_fields` was using `you_cant_use_this_field` as an example field name (presumably copy-paste inherited from the description of Issue #76077), but the present author found this confusing, because unmentioned fields aren't necessarily unusable. The suggested code in the diff this commit introduces to `destructuring-assignment/struct_destructure_fail.stderr` doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier `_`" thing), so you can't really call it a regression; it could be fixed in a separate PR. Resolves #78511.
2021-01-14Rollup merge of #80017 - camelid:sugg-rest-pattern, r=estebankMara Bos-2/+7
Suggest `_` and `..` if a pattern has too few fields Fixes #80010.
2021-01-13Auto merge of #77524 - Patryk27:fixes/66228, r=estebankbors-17/+44
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924) This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13Update tests for extern block lintingMark Rousskov-19/+17
2021-01-12Always show suggestions in their own subwindowsCamelid-4/+6
2021-01-12Only suggest `..` if more than one field is missingCamelid-10/+4
2021-01-12Specialize `..` help message for all fields vs. the restCamelid-1/+1
2021-01-12Pluralize 'parenthesis' correctlyCamelid-2/+2
It's 'parentheses', not 'parenthesis', when you have more than one.
2021-01-12Suggest `_` and `..` if a pattern has too few fieldsCamelid-0/+9
For example, this code: struct S(i32, f32); let S(x) = S(0, 1.0); will make the compiler suggest either: let S(x, _) = S(0, 1.0); or: let S(x, ..) = S(0, 1.0);
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-17/+44
2021-01-07Use correct span for structured suggestionEsteban Küber-4/+12
On structured suggestion for `let` -> `const` and `const` -> `let`, use a proper `Span` and update tests to check the correct application. Follow up to #80012.
2021-01-07bless testsDaiki Ihara-0/+2
2021-01-03Stylistic fixes to diagnostic messagesoli-1/+1