about summary refs log tree commit diff
path: root/tests/ui
AgeCommit message (Collapse)AuthorLines
2024-05-12Auto merge of #125051 - dtolnay:printletelse, r=compiler-errorsbors-0/+41
Pretty-print let-else with added parenthesization when needed Rustc used to produce invalid syntax for the following code, which is problematic because it means we cannot apply rustfmt to the output of `-Zunpretty=expanded`. ```rust macro_rules! expr { ($e:expr) => { $e }; } fn main() { let _ = expr!(loop {}) else { return; }; } ``` ```console $ rustc repro.rs -Zunpretty=expanded | rustfmt error: `loop...else` loops are not supported --> <stdin>:9:29 | 9 | fn main() { let _ = loop {} else { return; }; } | ---- ^^^^^^^^^^^^^^^^ | | | `else` is attached to this loop | = note: consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run ```
2024-05-12Pretty-print let-else with added parenthesization when neededDavid Tolnay-1/+1
2024-05-12Add AST pretty-printer tests for let-elseDavid Tolnay-0/+41
2024-05-12Auto merge of #124639 - ↵bors-47/+223
Jules-Bertholet:match-ergonomics-2024-migration-lint, r=Nadrieril Match ergonomics 2024: migration lint Depends on #124567 r? `@Nadrieril` cc https://github.com/rust-lang/rust/issues/123076 `@rustbot` label A-edition-2024 A-patterns
2024-05-12Propagate errors rather than using return_if_errMichael Goulet-0/+28
2024-05-12Apply nitsMichael Goulet-0/+4
2024-05-12Try structurally resolveMichael Goulet-0/+15
2024-05-12Match ergonomics 2024: migration lintJules Bertholet-47/+223
Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion. Co-Authored-By: Guillaume Boisseau <Nadrieril@users.noreply.github.com>
2024-05-12Auto merge of #125012 - RalfJung:format-error, r=Mark-Simulacrum,workingjubileebors-11/+18
io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to https://github.com/rust-lang/rust/pull/124954
2024-05-12Auto merge of #119427 - dtolnay:maccall, r=compiler-errorsbors-24/+332
Fix, document, and test parser and pretty-printer edge cases related to braced macro calls _Review note: this is a deceptively small PR because it comes with 145 lines of docs and 196 lines of tests, and only 25 lines of compiler code changed. However, I recommend reviewing it 1 commit at a time because much of the effect of the code changes is non-local i.e. affecting code that is not visible in the final state of the PR. I have paid attention that reviewing the PR one commit at a time is as easy as I can make it. All of the code you need to know about is touched in those commits, even if some of those changes disappear by the end of the stack._ This is a follow-up to https://github.com/rust-lang/rust/pull/119105. One case that is not relevant to `-Zunpretty=expanded`, but which came up as I'm porting #119105 and #118726 into `syn`'s printer and `prettyplease`'s printer where it **is** relevant, and is also relevant to rustc's `stringify!`, is statement boundaries in the vicinity of braced macro calls. Rustc's AST pretty-printer produces invalid syntax for statements that begin with a braced macro call: ```rust macro_rules! stringify_item { ($i:item) => { stringify!($i) }; } macro_rules! repro { ($e:expr) => { stringify_item!(fn main() { $e + 1; }) }; } fn main() { println!("{}", repro!(m! {})); } ``` **Before this PR:** output is not valid Rust syntax. ```console fn main() { m! {} + 1; } ``` ```console error: leading `+` is not supported --> <anon>:1:19 | 1 | fn main() { m! {} + 1; } | ^ unexpected `+` | help: try removing the `+` | 1 - fn main() { m! {} + 1; } 1 + fn main() { m! {} 1; } | ``` **After this PR:** valid syntax. ```console fn main() { (m! {}) + 1; } ```
2024-05-11Fix redundant parens around braced macro call in match armsDavid Tolnay-1/+1
2024-05-11Remove MacCall special case from recovery after missing 'if' after 'else'David Tolnay-6/+4
The change to the test is a little goofy because the compiler was guessing "correctly" before that `falsy! {}` is the condition as opposed to the else body. But I believe this change is fundamentally correct. Braced macro invocations in statement position are most often item-like (`thread_local! {...}`) as opposed to parenthesized macro invocations which are condition-like (`cfg!(...)`).
2024-05-11Add macro calls to else-no-if parser testDavid Tolnay-5/+83
2024-05-11Add parser tests for statement boundary insertionDavid Tolnay-0/+104
2024-05-11Add test of unused_parens lint involving macro callsDavid Tolnay-19/+117
2024-05-11Fix pretty printer statement boundaries after braced macro callDavid Tolnay-2/+2
2024-05-11Add ExprKind::MacCall statement boundary testsDavid Tolnay-0/+30
2024-05-11Auto merge of #125028 - matthiaskrgr:rollup-3qk782d, r=matthiaskrgrbors-154/+70
Rollup of 6 pull requests Successful merges: - #124096 (Clean up users of rust_dbg_call) - #124829 (Enable profiler for armv7-unknown-linux-gnueabihf.) - #124939 (Always hide private fields in aliased type) - #124963 (Migrate `run-make/rustdoc-shared-flags` to rmake) - #124981 (Relax allocator requirements on some Rc/Arc APIs.) - #125008 (Add test for #122775) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-11Rollup merge of #125008 - Dirbaio:test-issue-122775, r=compiler-errorsMatthias Krüger-0/+17
Add test for #122775 Closes #122775
2024-05-11Rollup merge of #124096 - saethlin:rust-dbg-call, r=NilstriebMatthias Krüger-154/+53
Clean up users of rust_dbg_call `rust_dbg_call` is a C test helper that until this PR was declared in C with `void*` arguments and used in Rust _mostly_ with `libc::uintptr_t` arguments. Nearly every user just wants to pass integers around, so I've changed all users to `uint64_t` or `u64`. The single test that actually used the pointer-ness of the argument is a test for ensuring that Rust can make extern calls outside of tasks. Rust hasn't had tasks for quite a few years now, so I'm deleting that test under the same logic as the test deleted in https://github.com/rust-lang/rust/pull/124073
2024-05-11Auto merge of #124988 - compiler-errors:name-span, r=lcnrbors-6/+41
Consolidate obligation cause codes for where clauses Removes some unncessary redundancy between `SpannedWhereClause`/`WhereClause` r? lcnr
2024-05-11io::Write::write_fmt: panic if the formatter fails when the stream does not failRalf Jung-11/+18
2024-05-11Auto merge of #125010 - matthiaskrgr:rollup-270pck3, r=matthiaskrgrbors-0/+7
Rollup of 5 pull requests Successful merges: - #124928 (Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`) - #124954 (Document proper usage of `fmt::Error` and `fmt()`'s `Result`.) - #124969 (check if `x test tests` missing any test directory) - #124978 (Handle Deref expressions in invalid_reference_casting) - #125005 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-11Rollup merge of #124978 - saethlin:ref-casting_derefs, r=Urgau,NilstriebMatthias Krüger-0/+7
Handle Deref expressions in invalid_reference_casting Similar to https://github.com/rust-lang/rust/pull/124908 See https://github.com/rust-lang/rust/issues/124951 for context; this PR fixes the last of the known false postiive cases with this lint that we encounter in Crater.
2024-05-11Add test for #122775Dario Nieuwenhuis-0/+17
2024-05-11Auto merge of #124567 - Jules-Bertholet:and-eats-andmut, r=Nadrierilbors-73/+201
Match ergonomics 2024: let `&` patterns eat `&mut` r? `@Nadrieril` cc https://github.com/rust-lang/rust/issues/123076 `@rustbot` label A-edition-2024 A-patterns
2024-05-11Consolidate obligation cause codes for where clausesMichael Goulet-6/+41
2024-05-11Rollup merge of #124930 - compiler-errors:consume-arg, r=petrochenkov许杰友 Jieyou Xu (Joe)-0/+20
Make sure we consume a generic arg when checking mistyped turbofish When recovering un-turbofish-ed args in expr position (e.g. `let x = a<T, U>();` in `check_mistyped_turbofish_with_multiple_type_params`, we used `parse_seq_to_before_end` to parse the fake generic args; however, it used `parse_generic_arg` which *optionally* parses a generic arg. If it doesn't end up parsing an arg, it returns `Ok(None)` and consumes no tokens. If we don't find a delimiter after this (`,`), we try parsing *another* element. In this case, we just infinitely loop looking for a subsequent element. We can fix this by making sure that we either parse a generic arg or error in `parse_seq_to_before_end`'s callback. Fixes #124897
2024-05-11Rollup merge of #124318 - bvanjoi:fix-123911, r=petrochenkov许杰友 Jieyou Xu (Joe)-8/+71
ignore generics args in attribute paths Fixes #97006 Fixes #123911 Fixes #123912 This patch ensures that we no longer have to handle invalid generic arguments in attribute paths. r? `@petrochenkov`
2024-05-10Comments and fixesJules Bertholet-42/+108
2024-05-10Fix spans when macros are involvedJules Bertholet-4/+3
2024-05-10Various fixes:Jules Bertholet-24/+41
- Only show error when move-check would not be triggered - Add structured suggestion
2024-05-10Match ergonomics 2024: let `&` patterns eat `&mut`Jules Bertholet-69/+115
2024-05-10Handle Deref expressions in invalid_reference_castingBen Kimock-0/+7
2024-05-11ignore generics args in attribute pathsbohan-8/+71
2024-05-10Rollup merge of #124797 - beetrees:primitive-float, r=davidtwcoMatthias Krüger-1/+3
Refactor float `Primitive`s to a separate `Float` type Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`. As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`. Tracking issue: #116909 `@rustbot` label +F-f16_and_f128
2024-05-10Rollup merge of #124778 - fmease:fix-diag-msg-parse-meta-item, r=nnethercoteMatthias Krüger-37/+58
Fix parse error message for meta items Addresses https://github.com/rust-lang/rust/issues/122796#issuecomment-2010803906, cc [``@]Thomasdezeeuw.`` For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`): ``` error: expected unsuffixed literal or identifier, found `ident` --> weird.rs:6:19 | 6 | #[cfg(feature = $ident)] | ^^^^^^ ... 11 | m!(id); | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) ``` This was incorrect and caused confusion, justifiably so (see #122796). In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers. Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens: ``` error: expected unsuffixed literal, found `-` --> weird.rs:16:17 | 16 | #[cfg(feature = -1)] | ^ | help: surround the identifier with quotation marks to parse it as a string | 16 | #[cfg(feature =" "-1)] | + + ``` Now we no longer do.
2024-05-10Fix parse error message for meta itemsLeón Orell Valerian Liehr-37/+58
2024-05-10Rollup merge of #124936 - lcnr:cool-beans, r=compiler-errorsMatthias Krüger-9/+79
analyse visitor: build proof tree in probe see inline comments fixes #124791 fixes #124702 r? ```@compiler-errors```
2024-05-09analyse visitor: build proof tree in probelcnr-9/+79
2024-05-09Rollup merge of #124923 - RalfJung:offset-from-errors, r=compiler-errorsMatthias Krüger-7/+7
interpret/miri: better errors on failing offset_from Fixes https://github.com/rust-lang/miri/issues/3104
2024-05-09Make sure we consume a generic arg when checking mistyped turbofishMichael Goulet-0/+20
2024-05-09Auto merge of #124706 - Zalathar:revision-checker, r=jieyouxubors-41/+87
Tidy check for test revisions that are mentioned but not declared If a `[revision]` name appears in a test header directive or error annotation, but isn't declared in the `//@ revisions:` header, that is almost always a mistake. In cases where a revision needs to be temporarily disabled, adding it to an `//@ unused-revision-names:` header will suppress these checks for that name. Adding the wildcard name `*` to the unused list will suppress these checks for the entire file. (None of the tests actually use `*`; it's just there because it was easy to add and could be handy as an escape hatch when dealing with other problems.) --- Most of the existing problems discovered by this check were fairly straightforward to fix (or ignore); the trickiest cases are in `borrowck` tests.
2024-05-09interpret/miri: better errors on failing offset_fromRalf Jung-7/+7
2024-05-09Auto merge of #124157 - wutchzone:partial_eq, r=estebankbors-10/+48
Do not add leading asterisk in the `PartialEq` I think we should address this issue, however I am not exactly sure, if this is the right way to do it. It is related to the #123056. Imagine the simplified code: ```rust trait MyTrait {} impl PartialEq for dyn MyTrait { fn eq(&self, _other: &Self) -> bool { true } } #[derive(PartialEq)] enum Bar { Foo(Box<dyn MyTrait>), } ``` On the nightly compiler, the `derive` produces invalid code with the weird error message: ``` error[E0507]: cannot move out of `*__arg1_0` which is behind a shared reference --> src/main.rs:11:9 | 9 | #[derive(PartialEq)] | --------- in this derive macro expansion 10 | enum Things { 11 | Foo(Box<dyn MyTrait>), | ^^^^^^^^^^^^^^^^ move occurs because `*__arg1_0` has type `Box<dyn MyTrait>`, which does not implement the `Copy` trait | = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) ``` It may be related to the perfect derive problem, although requiring the _type_ to be `Copy` seems unfortunate because it is not necessary. Besides, we are adding the extra dereference only for the diagnostics?
2024-05-09Fix test problems discovered by the revision checkZalathar-41/+87
Most of these changes either add revision names that were apparently missing, or explicitly mark a revision name as currently unused.
2024-05-09Rollup merge of #124908 - saethlin:ref-casting_bigger_place_projection, ↵Matthias Krüger-0/+6
r=fee1-dead Handle field projections like slice indexing in invalid_reference_casting r? `@Urgau` I saw the implementation in https://github.com/rust-lang/rust/pull/124761, and I was wondering if we also need to handle field access. We do. Without this PR, we get this errant diagnostic: ``` error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused --> /home/ben/rust/tests/ui/lint/reference_casting.rs:262:18 | LL | let r = &mut v.0; | --- backing allocation comes from here LL | let ptr = r as *mut i32 as *mut Vec3<i32>; | ------------------------------- casting happend here LL | unsafe { *ptr = Vec3(0, 0, 0) } | ^^^^^^^^^^^^^^^^^^^^ | = note: casting from `i32` (4 bytes) to `Vec3<i32>` (12 bytes) ```
2024-05-09Rollup merge of #124875 - compiler-errors:more-diagnostics-ices, r=estebankMatthias Krüger-35/+190
Fix more ICEs in `diagnostic::on_unimplemented` There were 8 other calls to `expect_local` left in `on_unimplemented.rs` -- all of which (afaict) could be turned into ICEs. I would really like to see validation of `on_unimplemented` separated from parsing, so we only emit errors here: https://github.com/rust-lang/rust/blob/a60f077c38fe66d05449919842d3d73e3299bbab/compiler/rustc_hir_analysis/src/check/check.rs#L836-L839 ...And gracefully fail instead when emitting trait predicate failures, not *ever* even trying to emit an error or a lint. But that's left for a separate PR. r? `@estebank`
2024-05-09Rollup merge of #124777 - veera-sivarajan:bugfix-124495-identify-gen-block, ↵Matthias Krüger-6/+101
r=compiler-errors Fix Error Messages for `break` Inside Coroutines Fixes #124495 Previously, `break` inside `gen` blocks and functions were incorrectly identified to be enclosed by a closure. This PR fixes it by displaying an appropriate error message for async blocks, async closures, async functions, gen blocks, gen closures, gen functions, async gen blocks, async gen closures and async gen functions. Note: gen closure and async gen closure are not supported by the compiler yet but I have added an error message here assuming that they might be implemented in the future. ~~Also, fixes grammar in a few places by replacing `inside of a $coroutine` with `inside a $coroutine`.~~
2024-05-08Rollup merge of #124869 - compiler-errors:keyword, r=NilstriebMatthias Krüger-33/+60
Make sure we don't deny macro vars w keyword names `$async:ident`, etc are all valid. Fixes #124862