about summary refs log tree commit diff
path: root/src/test/ui
AgeCommit message (Collapse)AuthorLines
2022-04-05trivial cfg(bootstrap) changesPietro Albini-1/+0
2022-04-05Auto merge of #94527 - oli-obk:undef_scalars, r=nagisa,erikdesjardinbors-111/+137
Let CTFE to handle partially uninitialized unions without marking the entire value as uninitialized. follow up to #94411 To fix https://github.com/rust-lang/rust/issues/69488 and by extension fix https://github.com/rust-lang/rust/issues/94371, we should stop treating types like `MaybeUninit<usize>` as something that the `Scalar` type in the interpreter engine can represent. So we add a new field to `abi::Primitive` that records whether the primitive is nested in a union cc `@RalfJung` r? `@ghost`
2022-04-05Rollup merge of #95654 - notriddle:notriddle/issue-95616, r=davidtwcoDylan DPC-55/+90
diagnostics: use correct span for const generics Fixes #95616
2022-04-05Rollup merge of #95525 - ohno418:suggest-derivable-trait-E0277, ↵Dylan DPC-0/+270
r=compiler-errors Suggest derivable trait on E0277 error Closes https://github.com/rust-lang/rust/issues/95099 .
2022-04-05mir-interpret now treats unions as non-immediate, even if they have scalar ↵Oli Scherer-0/+50
layout, allowing partially initializing them
2022-04-05Mark scalar layout unions so that backends that do not support partially ↵Oli Scherer-111/+87
initialized scalars can special case them.
2022-04-05Fix ui test for nllohno418-0/+4
2022-04-05Rollup merge of #95607 - compiler-errors:issue-95272, r=Aaron1011Dylan DPC-109/+143
Note invariance reason for FnDef types Fixes #95272. Is it worthwhile even printing a variance explanation here? Or should I try to track down which function parameter is responsible for the invariance? r? ``@Aaron1011`` since you wrote #89336
2022-04-05macros: support translatable labelsDavid Wood-3/+3
Extends support for generating `DiagnosticMessage::FluentIdentifier` messages from `SessionDiagnostic` derive to `#[label]`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-04Format invariance notes with backticksMichael Goulet-109/+109
2022-04-05Suggest only when all fields impl the traitohno418-8/+0
2022-04-04Handle reporting invariance of fn pointerMichael Goulet-0/+34
2022-04-05Suggest derivable trait on E0277ohno418-0/+274
2022-04-05Rollup merge of #95603 - compiler-errors:dyn-return, r=oli-obkDylan DPC-29/+163
Fix late-bound ICE in `dyn` return type suggestion This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with. Fixes #91801 Fixes #91803 This fix also includes some drive-by changes, specifically: 1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value). 2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial. 3. Split up the multipart suggestion because there's a 6-line max in the printed output... I am open to splitting out the above changes, if we just want to fix the ICE first. cc: ```@terrarier2111``` and #92289
2022-04-05Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, ↵Dylan DPC-187/+942
r=davidtwco Mention implementers of unsatisfied trait When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` ``` error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:5 | LL | f1(2u32, 4u32); | ^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `f1` --> $DIR/associated-types-path-2.rs:13:14 | LL | pub fn f1<T: Foo>(a: T, x: T::A) {} | ^^^ required by this bound in `f1` ``` Suggest dereferencing in more cases. Fix #87437, fix #90970.
2022-04-04Remove hack, fix fmt and testsEsteban Kuber-41/+69
2022-04-04Refer to the TraitRef::identity in the message to be clearerEsteban Kuber-69/+69
2022-04-04Dedup logic and improve output for other types that impl traitEsteban Kuber-294/+298
2022-04-04Fix list lengthEsteban Kuber-0/+224
2022-04-04Suggest dereferncing when possible in E0277, fix #87437Esteban Kuber-3/+55
2022-04-04Fix #90970, doesn't address #87437Esteban Kuber-0/+42
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-125/+530
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-04-04diagnostics: use correct span for const genericsMichael Howell-55/+90
Fixes #95616
2022-04-04Rollup merge of #95609 - compiler-errors:borrow-unsized-to-dyn, r=nagisaDylan DPC-0/+28
Suggest borrowing when trying to coerce unsized type into `dyn Trait` A helpful error in response to #95598, since we can't coerce e.g. `&str` into `&dyn Display`, but we can coerce `&&str` into `&dyn Display` :) Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.
2022-04-04Rollup merge of #95343 - dtolnay:literals, r=petrochenkovDylan DPC-2/+13
Reduce unnecessary escaping in proc_macro::Literal::character/string I noticed that https://doc.rust-lang.org/proc_macro/struct.Literal.html#method.character is producing unreadable literals that make macro-expanded code unnecessarily hard to read. Since the proc macro server was using `escape_unicode()`, every char is escaped using `\u{…}` regardless of whether there is any need to do so. For example `Literal::character('=')` would previously produce `'\u{3d}'` which unnecessarily obscures the meaning when reading the macro-expanded code. I've changed Literal::string also in this PR because `str`'s `Debug` impl is also smarter than just calling `escape_debug` on every char. For example `Literal::string("ferris's")` would previously produce `"ferris\'s"` but will now produce `"ferris's"`.
2022-04-04Auto merge of #95119 - OliverMD:method_suggestions, r=davidtwcobors-5/+12
Improve method name suggestions Attempts to improve method name suggestions when a matching method name is not found. The approach taken is use the Levenshtein distance and account for substrings having a high distance but can sometimes be very close to the intended method (eg. empty vs is_empty). resolves #94747
2022-04-04Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011bors-1/+2
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate. This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen. Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected. <sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps. Fixes #94903 r? `@Aaron1011` (or reassign as you see fit)
2022-04-03Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiaskoDylan DPC-1/+38
Don't emit non-asm contents error for naked function composed of errors ## Motivation For naked functions an error is emitted when they are composed of anything other than a single asm!() block. However, this error triggers in a couple situations in which it adds no additional information or is actively misleading. One example is if you do have an asm!() block but simply one with a syntax error: ```rust #[naked] unsafe extern "C" fn compiler_errors() { asm!(invalid_syntax) } ``` This results in two errors, one for the syntax error itself and another telling you that you need an asm block in your function: ```rust error[E0787]: naked functions must contain a single asm block --> src/main.rs:6:1 | 6 | / unsafe extern "C" fn naked_compile_error() { 7 | | asm!(blah) 8 | | } | |_^ ``` This issue also comes up when [utilizing `compile_error!()` for improving your diagnostics](https://twitter.com/steveklabnik/status/1509538243020218372), such as raising a compiler error when compiling for an unsupported target. ## Implementation The rules this PR implements are as follows: 1. If any non-erroneous non-asm statement is included, an error will still occur 2. If multiple asm statements are included, an error will still occur 3. If 0 or 1 asm statements are present, as well as any non-zero number of erroneous statements, then this error will *not* be raised as it is likely either redundant or incorrect The rule of thumb is effectively "if an error is present and its correction could change things, don't raise an error".
2022-04-03Improve method name suggestionsOliver Downard-5/+12
Attempts to improve method name suggestions when a matching method name is not found. The approach taken is use the Levenshtein distance and account for substrings having a high distance but can sometimes be very close to the intended method (eg. empty vs is_empty).
2022-04-03Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwcobors-0/+277
Suggest `i += 1` when we see `i++` or `++i` Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--` is tricky to handle). This is a continuation of #83536. r? `@estebank`
2022-04-02Suggest borrowing when trying to coerce unsized type into dyn TraitMichael Goulet-0/+28
2022-04-02Fix late-bound ICE in unsized return suggestionMichael Goulet-29/+163
2022-04-02Auto merge of #95600 - Dylan-DPC:rollup-580y2ra, r=Dylan-DPCbors-0/+39
Rollup of 4 pull requests Successful merges: - #95587 (Remove need for associated_type_bounds in std.) - #95589 (Include a header in .rlink files) - #95593 (diagnostics: add test case for bogus T:Sized suggestion) - #95597 (Refer to u8 by absolute path in expansion of thread_local) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-02Rollup merge of #95597 - dtolnay:threadlocalu8, r=Dylan-DPCDylan DPC-0/+15
Refer to u8 by absolute path in expansion of thread_local The standard library's `thread_local!` macro previously referred to `u8` just as `u8`, resolving to whatever `u8` existed in the type namespace at the call site. This PR replaces those with `$crate::primitive::u8` which always refers to `std::primitive::u8` regardless of what's in scope at the call site. Unambiguously naming primitives inside macro-generated code is the reason that std::primitive was introduced in the first place. <details> <summary>Here is the error message prior to this PR ⬇️</summary> ```console error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected struct `u8`, found integer | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_expected struct `u8`, found integer | this expression has type `u8` | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected `u8`, found struct `u8` | = note: expected raw pointer `*mut u8` (`u8`) found raw pointer `*mut u8` (struct `u8`) = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected `u8`, found struct `u8` | = note: expected fn pointer `unsafe extern "C" fn(*mut u8)` found fn item `unsafe extern "C" fn(*mut u8) {destroy}` = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_expected struct `u8`, found integer | expected due to this type | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0369]: binary operation `==` cannot be applied to type `u8` --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_u8 | {integer} | note: an implementation of `PartialEq<_>` might be missing for `u8` --> src/main.rs:4:1 | 4 | struct u8; | ^^^^^^^^^^ must implement `PartialEq<_>` = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `u8` with `#[derive(PartialEq)]` | 4 | #[derive(PartialEq)] | error[E0277]: `u8` doesn't implement `Debug` --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ `u8` cannot be formatted using `{:?}` | = help: the trait `Debug` is not implemented for `u8` = note: add `#[derive(Debug)]` to `u8` or manually `impl Debug for u8` = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) ``` </details>
2022-04-02Add test of thread_local! breaking on redefined u8David Tolnay-0/+15
2022-04-02Auto merge of #94911 - jackh726:gats_extended_2, r=compiler-errorsbors-30/+162
Make GATs object safe under generic_associated_types_extended feature Based on #94869 Let's say we have ```rust trait StreamingIterator { type Item<'a> where Self: 'a; } ``` And `dyn for<'a> StreamingIterator<Item<'a> = &'a i32>`. If we ask `(dyn for<'a> StreamingIterator<Item<'a> = &'a i32>): StreamingIterator`, then we have to prove that `for<'x> (&'x i32): Sized`. So, we generate *new* bound vars to subst for the GAT generics. Importantly, this doesn't fully verify that these are usable and sound. r? `@nikomatsakis`
2022-04-02Make GATs object safe under generic_associated_types_extended featureJack Huey-30/+162
2022-04-02diagnostics: add test case for bogus T:Sized suggestionMichael Howell-0/+24
Closes #69228
2022-04-02Auto merge of #95571 - petrochenkov:nowrapident2, r=Aaron1011bors-18/+6
ast_lowering: Stop wrapping `ident` matchers into groups The lowered forms goes to metadata, for example during encoding of macro definitions. This is a missing part of https://github.com/rust-lang/rust/pull/92472. Fixes https://github.com/rust-lang/rust/issues/95569 r? `@Aaron1011`
2022-04-02Rollup merge of #95557 - niluxv:issue-95533, r=dtolnayDylan DPC-0/+8
Fix `thread_local!` macro to be compatible with `no_implicit_prelude` Fixes issue #95533.
2022-04-02Rollup merge of #95544 - jam1garner:improve-naked-noreturn-diagnostic, r=tmiaskoDylan DPC-0/+25
Add error message suggestion for missing noreturn in naked function I had to google the syntax for inline asm's `noreturn` option when I got this error earlier today, so I figured I'd save others the trouble and add the syntax/fix as a suggestion in the error.
2022-04-02Rollup merge of #95373 - RalfJung:invalid_value, r=davidtwcoDylan DPC-11/+52
invalid_value lint: detect invalid initialization of arrays
2022-04-02Rollup merge of #95354 - dtolnay:rustc_const_stable, r=lcnrDylan DPC-2/+2
Handle rustc_const_stable attribute in library feature collector The library feature collector in [compiler/rustc_passes/src/lib_features.rs](https://github.com/rust-lang/rust/blob/551b4fa395fa588d91cbecfb0cdfe1baa02670cf/compiler/rustc_passes/src/lib_features.rs) has only been looking at `#[stable(…)]`, `#[unstable(…)]`, and `#[rustc_const_unstable(…)]` attributes, while ignoring `#[rustc_const_stable(…)]`. The consequences of this were: - When any const feature got stabilized (changing one or more `rustc_const_unstable` to `rustc_const_stable`), users who had previously enabled that unstable feature using `#![feature(…)]` would get told "unknown feature", rather than rustc's nicer "the feature … has been stable since … and no longer requires an attribute to enable". This can be seen in the way that https://github.com/rust-lang/rust/pull/93957#issuecomment-1079794660 failed after rebase: ```console error[E0635]: unknown feature `const_ptr_offset` --> $DIR/offset_from_ub.rs:1:35 | LL | #![feature(const_ptr_offset_from, const_ptr_offset)] | ^^^^^^^^^^^^^^^^ ``` - We weren't enforcing that a particular feature is either stable everywhere or unstable everywhere, and that a feature that has been stabilized has the same stabilization version everywhere, both of which we enforce for the other stability attributes. This PR updates the library feature collector to handle `rustc_const_stable`, and fixes places in the standard library and test suite where `rustc_const_stable` was being used in a way that does not meet the rules for a stability attribute.
2022-04-02ast_lowering: Stop wrapping `ident` matchers into groupsVadim Petrochenkov-18/+6
The lowered forms goes to metadata, for example during encoding of macro definitions
2022-04-01Add regression test for naked functions with invalid asm syntaxjam1garner-1/+13
2022-04-01Reword purpose description of noreturn in naked functionjam1garner-5/+5
2022-04-01Don't emit non-asm contents error for naked function composed of errorsjam1garner-1/+26
2022-04-01invalid_value lint: detect invalid initialization of arraysRalf Jung-11/+52
2022-04-01Fix `thread_local!` macro to be compatible with `no_implicit_prelude`niluxv-0/+8
Fixes issue #95533
2022-04-01Rollup merge of #95388 - RalfJung:rust-val-limit, r=oli-obkMatthias Krüger-43/+72
interpret: make isize::MAX the limit for dynamic value sizes We are currently enforcing `data_layout.obj_size_bound()` as the maximal dynamic size of a Rust value (including for `size_of_val_raw`), but that does not match the docs. In particular, Miri currently falsely says that this code has UB: ```rust #![feature(layout_for_ptr)] fn main() { let size = isize::MAX as usize; // Creating a raw slice of size isize::MAX and asking for its size is okay. let s = std::ptr::slice_from_raw_parts(1usize as *const u8, size); assert_eq!(size, unsafe { std::mem::size_of_val_raw(s) }); } ```