about summary refs log tree commit diff
path: root/src/test/ui/issues
AgeCommit message (Collapse)AuthorLines
2021-07-06Make type_implements_trait not a queryAman Arora-1/+3
2021-07-05Fix double warning about illegal floating-point literal patternFabian Wolff-168/+14
2021-07-02Improve error reporting for modifications behind `&` referencesFabian Wolff-6/+6
2021-07-01Avoid ICE on type error recoveryEsteban Küber-0/+58
Fix #86756
2021-06-30Move some UI tests to more suitable subdirsYuki Okushi-620/+0
2021-06-29Rollup merge of #86206 - FabianWolff:issue-86188, r=Mark-SimulacrumYuki Okushi-16/+60
Fix type checking of return expressions outside of function bodies This pull request fixes #86188. The problem is that the current code for type-checking `return` expressions stops if the `return` occurs outside of a function body, while the correct behavior is to continue type-checking the return value expression (otherwise an ICE happens later on because variables declared in the return value expression don't have a type). Also, I have noticed that it is sometimes not obvious why a `return` is outside of a function body; for instance, in the example from #86188 (which currently causes an ICE): ```rust fn main() { [(); return || { let tx; }] } ``` I have changed the error message to also explain why the `return` is considered outside of the function body: ``` error[E0572]: return statement outside of function body --> ice0.rs:2:10 | 1 | / fn main() { 2 | | [(); return || { | |__________^ 3 | || let tx; 4 | || }] | ||_____^ the return is part of this body... 5 | | } | |_- ...not the enclosing function body ```
2021-06-23Auto merge of #86386 - ↵bors-10/+0
inquisitivecrystal:better-errors-for-display-traits-v3, r=estebank Better errors for Debug and Display traits Currently, if someone tries to pass value that does not implement `Debug` or `Display` to a formatting macro, they get a very verbose and confusing error message. This PR changes the error messages for missing `Debug` and `Display` impls to be less overwhelming in this case, as suggested by #85844. I was a little less aggressive in changing the error message than that issue proposed. Still, this implementation would be enough to reduce the number of messages to be much more manageable. After this PR, information on the cause of an error involving a `Debug` or `Display` implementation would suppressed if the requirement originated within a standard library macro. My reasoning was that errors originating from within a macro are confusing when they mention details that the programmer can't see, and this is particularly problematic for `Debug` and `Display`, which are most often used via macros. It is possible that either a broader or a narrower criterion would be better. I'm quite open to any feedback. Fixes #85844.
2021-06-22Updated tests to reflect specified types in E0121Deadbeef-3/+3
2021-06-20Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrumbors-3/+1
Replace some `std::iter::repeat` with `str::repeat` I noticed that there were some instances where `std::iter::repeat` would be used to repeat a string or a char to take a specific count of it and then collect it into a `String` when `str::repeat` is actually much faster and better for that. See also: https://github.com/rust-lang/rust-clippy/issues/7260.
2021-06-19Auto merge of #86460 - JohnTitor:use-static-in-pattern-err, r=oli-obkbors-19/+0
Refactor `PatternError` structure Now we emit the `StaticInPattern` error precisely. Fixes #68395 r? `@oli-obk`
2021-06-19Refactor `PatternError` structureYuki Okushi-19/+0
2021-06-18Lint for unused borrows as part of UNUSED_MUST_USEhi-rustin-4/+4
2021-06-16Move some typeck-related tests to the typeck dirYuki Okushi-38/+0
2021-06-16Update test stderr filesAris Merchant-10/+0
2021-06-11Fix type checking of return expressions outside fn bodiesFabian Wolff-16/+60
2021-06-05Remove `_` from E0121 diagnostic suggestionsDeadbeef-1/+1
2021-06-04Replace some std::iter::repeat with str::repeatr00ster91-3/+1
2021-05-28Auto merge of #85607 - LeSeulArtichaut:thir-unsafeck-closures, r=nikomatsakisbors-4/+47
Make closures inherit their parent's "safety context" Fixes rust-lang/project-thir-unsafeck#9, ~~blocked on #85273~~. r? `@nikomatsakis`
2021-05-28Auto merge of #84968 - FabianWolff:master, r=estebankbors-3/+8
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-27Test THIR unsafeck for unsafe ops in closuresLeSeulArtichaut-4/+47
2021-05-27Rollup merge of #84221 - ABouttefeux:generic-arg-elision, r=estebankDylan DPC-1/+4
E0599 suggestions and elision of generic argument if no canditate is found fixes #81576 changes: In error E0599 (method not found) generic argument are eluded if the method was not found anywhere. If the method was found in another inherent implementation suggest that it was found elsewhere. Example ```rust struct Wrapper<T>(T); struct Wrapper2<T> { x: T, } impl Wrapper2<i8> { fn method(&self) {} } fn main() { let wrapper = Wrapper(i32); wrapper.method(); let wrapper2 = Wrapper2{x: i32}; wrapper2.method(); } ``` ``` Error[E0599]: no method named `method` found for struct `Wrapper<_>` in the current scope .... error[E0599]: no method named `method` found for struct `Wrapper2<i32>` in the current scope ... = note: The method was found for Wrapper2<i8>. ``` I am not very happy with the ```no method named `test` found for struct `Vec<_, _>` in the current scope```. I think it might be better to show only one generic argument `Vec<_>` if there is a default one. But I haven't yet found a way to do that,
2021-05-25show list of candidatesAliénore Bouttefeux-1/+2
2021-05-25Auto merge of #85273 - LeSeulArtichaut:thir-query, r=nikomatsakisbors-8/+8
Make building THIR a stealable query This PR creates a stealable `thir_body` query so that we can build the THIR only once for THIR unsafeck and MIR build. Blocked on #83842. r? `@nikomatsakis`
2021-05-24Replace more "NULL" with "null"LeSeulArtichaut-1/+1
2021-05-22Make the THIR unsafeck use the `thir_body` queryLeSeulArtichaut-8/+8
2021-05-22change from review and show full type if it can be derefAliénore Bouttefeux-1/+1
2021-05-21Check for use of mutable/extern statics in THIR unsafeckLeSeulArtichaut-5/+63
2021-05-21remove generic argument insead of displaying "_"Aliénore Bouttefeux-1/+1
2021-05-20Check for raw pointer dereference in THIR unsafeckLeSeulArtichaut-3/+18
2021-05-18Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnrbors-1/+2
Implement the new desugaring from `try_trait_v2` ~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix. `try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277 Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them. (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits. r? `@ghost` ~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-13Auto merge of #85258 - GuillaumeGomez:rollup-kzay7o5, r=GuillaumeGomezbors-5/+40
Rollup of 4 pull requests Successful merges: - #85068 (Fix diagnostic for cross crate private tuple struct constructors) - #85175 (Rustdoc cleanup) - #85177 (add BITS associated constant to core::num::Wrapping) - #85240 (Don't suggest adding `'static` lifetime to arguments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-05-13Rollup merge of #85240 - Aaron1011:no-suggest-static, r=davidtwcoGuillaume Gomez-2/+0
Don't suggest adding `'static` lifetime to arguments Fixes #69350 This is almost always the wrong this to do
2021-05-13Rollup merge of #85068 - luqmana:78708-xcrate-diag, r=estebankGuillaume Gomez-3/+40
Fix diagnostic for cross crate private tuple struct constructors Fixes #78708. There was already some limited support for certain cross-crate scenarios but that didn't handle a tuple struct rexported from an inner module for example (e.g. the NonZero* types as seen in #85049). ```Rust ➜ cat bug.rs fn main() { let _x = std::num::NonZeroU32(12); let n = std::num::NonZeroU32::new(1).unwrap(); match n { std::num::NonZeroU32(i) => {}, } } ``` **Before:** <details> ```Rust ➜ rustc +nightly bug.rs error[E0423]: expected function, tuple struct or tuple variant, found struct `std::num::NonZeroU32` --> bug.rs:2:14 | 2 | let _x = std::num::NonZeroU32(12); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `std::num::NonZeroU32 { 0: val }` | ::: /home/luqman/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/nonzero.rs:148:1 [snip] error[E0532]: expected tuple struct or tuple variant, found struct `std::num::NonZeroU32` --> bug.rs:5:9 | 5 | std::num::NonZeroU32(i) => {}, | ^^^^^^^^^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `std::num::NonZeroU32 { 0 }` | ::: /home/luqman/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/nonzero.rs:148:1 [snip] error: aborting due to 2 previous errors Some errors have detailed explanations: E0423, E0532. For more information about an error, try `rustc --explain E0423`. ``` </details> **After:** <details> ```Rust ➜ /rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc bug.rs error[E0423]: cannot initialize a tuple struct which contains private fields --> bug.rs:2:14 | 2 | let _x = std::num::NonZeroU32(12); | ^^^^^^^^^^^^^^^^^^^^ | note: constructor is not visible here due to private fields --> /rust/library/core/src/num/nonzero.rs:148:1 [snip] error[E0532]: cannot match against a tuple struct which contains private fields --> bug.rs:5:9 | 5 | std::num::NonZeroU32(i) => {}, | ^^^^^^^^^^^^^^^^^^^^ | note: constructor is not visible here due to private fields --> bug.rs:5:30 | 5 | std::num::NonZeroU32(i) => {}, | ^ private field error: aborting due to 2 previous errors Some errors have detailed explanations: E0423, E0532. For more information about an error, try `rustc --explain E0423`. ``` </details> One question is if we should only collect the needed info for the cross-crate case after encountering an error instead of always doing it. Perf run perhaps to gauge the impact.
2021-05-13Auto merge of #85110 - RalfJung:no-rustc_args_required_const, r=oli-obkbors-20/+0
Remove rustc_args_required_const attribute Now that stdarch no longer needs it (thanks `@Amanieu!),` we can kill the `rustc_args_required_const` attribute. This means that lifetime extension of references to temporaries is the only remaining job that promotion is performing. :-) r? `@oli-obk` Fixes https://github.com/rust-lang/rust/issues/69493
2021-05-13fix test suiteRalf Jung-20/+0
2021-05-13Auto merge of #83129 - LeSeulArtichaut:thir-unsafeck, r=nikomatsakisbors-6/+70
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-12Don't suggest adding `'static` lifetime to argumentsAaron Hill-2/+0
Fixes #69350 This is almost always the wrong this to do
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-44/+44
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 unused unsafe blocksLeSeulArtichaut-3/+26
2021-05-11Test `-Zthir-unsafeck` for unsafe function callsLeSeulArtichaut-3/+44
2021-05-11Auto merge of #82272 - b-naber:gat_diag, r=estebank,jackh726bors-26/+26
Improve diagnostics for GATs Fixes https://github.com/rust-lang/rust/issues/81801 Fixes https://github.com/rust-lang/rust/issues/81961 Fixes https://github.com/rust-lang/rust/issues/81862 r? `@estebank`
2021-05-11improve diagnosts for GATsb-naber-26/+26
2021-05-09remove const_fn feature gateRalf Jung-4/+2
2021-05-08Add tests.Luqman Aden-3/+40
2021-05-07Rollup merge of #84734 - tmandry:compiletest-needs-unwind, r=Mark-SimulacrumDylan DPC-0/+1
Add `needs-unwind` and beginning of support for testing `panic=abort` std to compiletest For the Fuchsia platform we build libstd with `panic=abort` and would like a way to run tests with that enabled. This adds low-level support for this directly to compiletest. In the future I'd like to add high-level support in rustbuild, e.g. having target-specific flags that allow configuring a panic strategy. (Side note: It would be nice if we could also build multiple configurations for the same target, but I'm getting ahead of myself.) This plus #84500 have everything that's needed to get ui tests passing on fuchsia targets. Part of #84766. Note that this change only includes the header on tests which need an unwinder to _build_, not those which need it to _run_. r? ````@Mark-Simulacrum````
2021-05-06Better rustc_on_unimplemented, and UI test fixesScott McMurray-1/+2
2021-05-06Fix up/ignore failing ui tests on fuchsiaTyler Mandry-0/+1
2021-05-06Fix incorrect suggestions for E0605Fabian Wolff-3/+8
2021-05-03Auto merge of #84842 - blkerby:null_lowercase, r=joshtriplettbors-1/+1
Replace 'NULL' with 'null' This replaces occurrences of "NULL" with "null" in docs, comments, and compiler error/lint messages. This is for the sake of consistency, as the lowercase "null" is already the dominant form in Rust. The all-caps NULL looks like the C macro (or SQL keyword), which seems out of place in a Rust context, given that NULL does not exist in the Rust language or standard library (instead having [`ptr::null()`](https://doc.rust-lang.org/stable/std/ptr/fn.null.html)).
2021-05-02Change 'NULL' to 'null'Brent Kerby-1/+1