about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2023-10-31Only emit `!=` assumptions if the otherwise target is reachable.Camille GILLOT-51/+142
2023-10-31Refactor UninhabitedEnumBranching to mark targets unreachable.Camille GILLOT-6/+37
2023-10-31Simplify assume of a constant.Camille GILLOT-84/+62
2023-10-31Replace SwitchInt to unreachable by an assumption.Camille GILLOT-38/+93
2023-10-31Reorder passes.Camille GILLOT-33/+63
2023-10-30Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgrbors-50/+167
Rollup of 7 pull requests Successful merges: - #116862 (Detect when trait is implemented for type and suggest importing it) - #117389 (Some diagnostics improvements of `gen` blocks) - #117396 (Don't treat closures/coroutine types as part of the public API) - #117398 (Correctly handle nested or-patterns in exhaustiveness) - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it) - #117411 (Improve some diagnostics around `?Trait` bounds) - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-30Rollup merge of #117414 - compiler-errors:tait-forevert, r=oli-obkMatthias Krüger-0/+17
Don't normalize to an un-revealed opaque when we hit the recursion limit Currently, we will normalize `Opaque := Option<&Opaque>` to something like `Option<&Option<&Option<&...Opaque>>>`, hitting a limit and bottoming out in an unnormalized opaque after the recursion limit gets hit. Unfortunately, during `layout_of`, we'll simply recurse and try again if the type normalizes to something different than the type: https://github.com/rust-lang/rust/blob/e6e931dda5fffbae0fd87c5b1af753cc95556880/compiler/rustc_ty_utils/src/layout.rs#L58-L60 That means then we'll try to normalize `Option<&Option<&Option<&...Opaque>>>` again, substituting `Opaque` into itself even deeper. Eventually this will get to the point that we're just stack-overflowing on a really deep type before even hitting an opaque again. To fix this, we just bottom out into `ty::Error` instead of the unrevealed opaque type. Fixes #117412 r? `@oli-obk`
2023-10-30Rollup merge of #117411 - oli-obk:query_merge_immobile_game, ↵Matthias Krüger-31/+31
r=compiler-errors,Nilstrieb Improve some diagnostics around `?Trait` bounds * uses better spans * clarifies a message that was only talking about generic params, but applies to `dyn ?Trait` and `impl ?Trait` as well
2023-10-30Rollup merge of #117403 - oli-obk:the_gift_that_keeps_on_giving_116849, ↵Matthias Krüger-4/+19
r=compiler-errors Poison check_well_formed if method receivers are invalid to prevent typeck from running on it fixes #117379 Though if some code invokes typeck without having first invoked `check_well_formed` then we'll encounter this ICE again. This can happen in const and const fn bodies if they are evaluated due to other `check_well_formed` checks or similar
2023-10-30Rollup merge of #117398 - Nadrieril:fix-117378, r=compiler-errorsMatthias Krüger-0/+6
Correctly handle nested or-patterns in exhaustiveness I had assumed nested or-patterns were flattened, and they mostly are but not always. Fixes https://github.com/rust-lang/rust/issues/117378
2023-10-30Rollup merge of #117396 - oli-obk:privacy_visitor_types, r=compiler-errorsMatthias Krüger-0/+44
Don't treat closures/coroutine types as part of the public API Fixes a regression from https://github.com/rust-lang/rust/pull/117076 r? `@compiler-errors`
2023-10-30Rollup merge of #117389 - oli-obk:gen_fn, r=compiler-errorsMatthias Krüger-3/+41
Some diagnostics improvements of `gen` blocks These are leftovers from https://github.com/rust-lang/rust/pull/116447
2023-10-30Don't super-fold types when we hit the recursion limitMichael Goulet-0/+17
2023-10-30Improve some diagnostics around `?Trait` boundsOli Scherer-31/+31
2023-10-30Detect when trait is implemented for type and suggest importing itEsteban Küber-12/+9
Fix #57457.
2023-10-30Rollup merge of #117395 - gurry:117380-wrong-parent-sugg, r=NilstriebGuillaume Gomez-1/+89
Fix missing leading space in suggestion For a local pattern with no space between `let` and `(` e.g.: ```rust let(_a) = 3; ``` we were previously suggesting this illegal code: ```rust let_a = 3; ``` After this change the suggestion will instead be: ```rust let _a = 3; ``` Fixes #117380
2023-10-30Rollup merge of #117390 - chenyukang:yukang-fix-117284-unused-macro, r=estebankGuillaume Gomez-0/+46
Fix unused variables lint issue for args in macro Fixes #117284 r? ````@estebank````
2023-10-30Rollup merge of #117370 - nicholasbishop:bishop-better-c-variadic-errors, ↵Guillaume Gomez-41/+89
r=oli-obk C-variadic error improvements A couple improvements for c-variadic errors: 1. Fix the bad-c-variadic error being emitted multiple times. If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once rather than once per `...`. 2. Explicitly reject `const` C-variadic functions. Trying to use C-variadics in a const function would previously fail with an error like "destructor of `VaListImpl<'_>` cannot be evaluated at compile-time". Add an explicit check for const C-variadics to provide a clearer error: "functions cannot be both `const` and C-variadic". This also addresses one of the concerns in https://github.com/rust-lang/rust/issues/44930: "Ensure that even when this gets stabilized for regular functions, it is still rejected on const fn."
2023-10-30Rollup merge of #117132 - estebank:issue-80194, r=petrochenkovGuillaume Gomez-0/+67
On object safety error, mention new enum as alternative When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead. Fix #80194.
2023-10-30Rollup merge of #112463 - fmease:rustdoc-elide-x-crate-def-gen-args, ↵Guillaume Gomez-10/+159
r=GuillaumeGomez rustdoc: elide cross-crate default generic arguments Elide cross-crate generic arguments if they coincide with their default. TL;DR: Most notably, no more `Box<…, Global>` in `std`'s docs, just `Box<…>` from now on. Fixes #80379. Also helps with #44306. Follow-up to #103885, #107637. r? ``@ghost``
2023-10-30Only run panic tests on targets that can unwindOli Scherer-1/+2
2023-10-30Poison check_well_formed if method receivers are invalid to prevent typeck ↵Oli Scherer-4/+19
from running on it
2023-10-30rustdoc: elide cross-crate default generic argumentsLeón Orell Valerian Liehr-10/+159
2023-10-30Explicitly reject const C-variadic functionsNicholas Bishop-20/+88
Trying to use C-variadics in a const function would previously fail with an error like "destructor of `VaListImpl<'_>` cannot be evaluated at compile-time". Add an explicit check for const C-variadics to provide a clearer error: "functions cannot be both `const` and C-variadic".
2023-10-30Correctly handle nested or-patterns in column-wise analysesNadrieril-0/+6
2023-10-30Fix bad-c-variadic error being emitted multiple timesNicholas Bishop-37/+17
If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once.
2023-10-30Don't treat closures/coroutines as part of the public APIOli Scherer-15/+7
2023-10-30Add regression testOli Scherer-0/+52
2023-10-30Fix #117284, Fix unused variables lint issue for args in macroyukang-0/+46
2023-10-30Fix missing leading space in suggestionGurinder Singh-1/+89
For a local pattern with no space between `let` and `(` e.g.: let(_a) = 3; we were previously suggesting this illegal code: let_a =3; After this change the suggestion will instead be: let _a =3; (Note the space after `let`)
2023-10-30Add a custom panic message for resuming `gen` blocks after they panickedOli Scherer-0/+37
2023-10-30Talk about `gen fn` in diagnostics about `gen fn`Oli Scherer-3/+3
2023-10-30Rollup merge of #117382 - gurry:114529-ice-const-eval, r=oli-obkLeón Orell Valerian Liehr-0/+49
Fail typeck for illegal break-with-value This is fixes the issue wherein typeck was succeeding for break-with-value exprs at illegal locations such as inside `while`, `while let` and `for` loops which eventually caused an ICE during MIR interpretation for const eval. Now we fail typeck for such code which prevents faulty MIR from being generated and interpreted, thus fixing the ICE. Fixes #114529
2023-10-30Rollup merge of #117371 - compiler-errors:unique-params, r=oli-obkLeón Orell Valerian Liehr-0/+28
Ignore RPIT duplicated lifetimes in `opaque_types_defined_by` An RPIT's or TAIT's own generics are kinda useless -- so just ignore them. For TAITs, they will always be empty, and for RPITs, they're always duplicated lifetimes. Fixes #115013.
2023-10-30Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, ↵León Orell Valerian Liehr-0/+73
r=compiler-errors Allows `#[diagnostic::on_unimplemented]` attributes to have multiple notes This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests. r? `@compiler-errors` I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30Rollup merge of #117147 - DaniPopes:pphir-fn-variadic, r=compiler-errorsLeón Orell Valerian Liehr-0/+28
Print variadic argument pattern in HIR pretty printer Variadic argument name/pattern was ignored during HIR pretty printing. Could not figure out why it only works on normal functions (`va2`) and not in foreign ones (`va1`).
2023-10-30Fail typeck for illegal break-with-valueGurinder Singh-0/+49
This is fixes the issue wherein typeck was succeeding for break-with-value at illegal locations such as inside `while`, `while let` and `for` loops which eventually caused an ICE during MIR interpetation for const eval. Now we fail typeck for such code which prevents faulty MIR from being generated and interpreted, thus fixing the ICE.
2023-10-29On object safety error, mention new enum as alternativeEsteban Küber-0/+67
When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead. Account for object unsafe `impl Trait on dyn Trait {}`. Make a distinction between public and sealed traits. Fix #80194.
2023-10-29Ignore RPIT duplicated lifetimes in opaque_types_defined_byMichael Goulet-0/+28
2023-10-29Auto merge of #116733 - compiler-errors:alias-liveness-but-this-time-sound, ↵bors-0/+210
r=aliemjay Consider alias bounds when computing liveness in NLL (but this time sound hopefully) This is a revival of #116040, except removing the changes to opaque lifetime captures check to make sure that we're not triggering any unsoundness due to the lack of general existential regions and the currently-existing `ReErased` hack we use instead. r? `@aliemjay` -- I appreciate you pointing out the unsoundenss in the previous iteration of this PR, and I'd like to hear that you're happy with this iteration of this PR before this goes back into FCP :> Fixes #116794 as well --- (mostly copied from #116040 and reworked slightly) # Background Right now, liveness analysis in NLL is a bit simplistic. It simply walks through all of the regions of a type and marks them as being live at points. This is problematic in the case of aliases, since it requires that we mark **all** of the regions in their args[^1] as live, leading to bugs like #42940. In reality, we may be able to deduce that fewer regions are allowed to be present in the projected type (or "hidden type" for opaques) via item bounds or where clauses, and therefore ideally, we should be able to soundly require fewer regions to be live in the alias. For example: ```rust trait Captures<'a> {} impl<T> Captures<'_> for T {} fn capture<'o>(_: &'o mut ()) -> impl Sized + Captures<'o> + 'static {} fn test_two_mut(mut x: ()) { let _f1 = capture(&mut x); let _f2 = capture(&mut x); //~^ ERROR cannot borrow `x` as mutable more than once at a time } ``` In the example above, we should be able to deduce from the `'static` bound on `capture`'s opaque that even though `'o` is a captured region, it *can never* show up in the opaque's hidden type, and can soundly be ignored for liveness purposes. # The Fix We apply a simple version of RFC 1214's `OutlivesProjectionEnv` and `OutlivesProjectionTraitDef` rules to NLL's `make_all_regions_live` computation. Specifically, when we encounter an alias type, we: 1. Look for a unique outlives bound in the param-env or item bounds for that alias. If there is more than one unique region, bail, unless any of the outlives bound's regions is `'static`, and in that case, prefer `'static`. If we find such a unique region, we can mark that outlives region as live and skip walking through the args of the opaque. 2. Otherwise, walk through the alias's args recursively, as we do today. ## Limitation: Multiple choices This approach has some limitations. Firstly, since liveness doesn't use the same type-test logic as outlives bounds do, we can't really try several options when we're faced with a choice. If we encounter two unique outlives regions in the param-env or bounds, we simply fall back to walking the opaque via its args. I expect this to be mostly mitigated by the special treatment of `'static`, and can be fixed in a forwards-compatible by a more sophisticated analysis in the future. ## Limitation: Opaque hidden types Secondly, we do not employ any of these rules when considering whether the regions captured by a hidden type are valid. That causes this code (cc #42940) to fail: ```rust trait Captures<'a> {} impl<T> Captures<'_> for T {} fn a() -> impl Sized + 'static { b(&vec![]) } fn b<'o>(_: &'o Vec<i32>) -> impl Sized + Captures<'o> + 'static {} ``` We need to have existential regions to avoid [unsoundness](https://github.com/rust-lang/rust/pull/116040#issuecomment-1751628189) when an opaque captures a region which is not represented in its own substs but which outlives a region that does. ## Read more Context: https://github.com/rust-lang/rust/pull/115822#issuecomment-1731153952 (for the liveness case) More context: https://github.com/rust-lang/rust/issues/42940#issuecomment-455198309 (for the opaque capture case, which this does not fix) [^1]: except for bivariant region args in opaques, which will become less relevant when we move onto edition 2024 capture semantics for opaques.
2023-10-29Auto merge of #116889 - MU001999:master, r=petrochenkovbors-0/+24
Eat close paren if capture_cfg to avoid unbalanced parens Fixes #116781
2023-10-29Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJungbors-2449/+3545
See through aggregates in GVN This PR is extracted from https://github.com/rust-lang/rust/pull/111344 The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others). The next 3 commits add a constant folding mechanism to the GVN pass, presented in https://github.com/rust-lang/rust/pull/116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~ The following commits implement opportunistic simplifications, in particular: - projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too; - projections of arrays: `[a, b][0]` becomes `a`; - projections of repeat expressions: `[a; N][x]` becomes `a`; - transform arrays of equal operands into a repeat rvalue. Fixes https://github.com/rust-lang/miri/issues/3090 r? `@oli-obk`
2023-10-29Rollup merge of #117082 - ↵Guillaume Gomez-0/+1
fortanix:raoul/fix_closure_inherit_target_feature_sgx, r=Mark-Simulacrum Fix closure-inherit-target-feature test for SGX platform PR #116078 adds the `closure-inherit-target-feature.rs` test that checks the generated assembly code for closures. These checks explicitly check the presence of `ret` instructions. This is incompatible with the SGX target as it explicitly rewrites all `ret` instructions to mitigate LVI vulnerabilities of certain processors. This PR simply ignores these tests for the SGX platform. cc: ```@jethrogb```
2023-10-29Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errorsbors-17/+450
Implement `gen` blocks in the 2024 edition Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122 `gen` block tracking issue https://github.com/rust-lang/rust/issues/117078 This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically. An example usage of `gen` blocks is ```rust fn foo() -> impl Iterator<Item = i32> { gen { yield 42; for i in 5..18 { if i.is_even() { continue } yield i * 2; } } } ``` The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-28Auto merge of #116240 - dtolnay:constdiscriminant, r=thomccbors-2/+1
Const stabilize mem::discriminant Tracking issue: #69821. This PR is a rebase of https://github.com/rust-lang/rust/pull/103893 to resolve conflicts in library/core/src/lib.rs (against #102470 and #110393).
2023-10-28Auto merge of #117123 - Zalathar:bad-counter-ids, r=petrochenkovbors-134/+433
coverage: Consistently remove unused counter IDs from expressions/mappings If some coverage counters were removed by MIR optimizations, we need to take care not to refer to those counter IDs in coverage mappings, and instead replace them with a constant zero value. If we don't, `llvm-cov` might see a too-large counter ID and silently discard the entire function from its coverage reports. Fixes #117012.
2023-10-28Rollup merge of #117277 - RalfJung:too-big-with-padding, r=oli-obkJubilee-0/+26
fix failure to detect a too-big-type after adding padding Fixes https://github.com/rust-lang/rust/issues/117265
2023-10-28Rollup merge of #117025 - Urgau:cleanup-improve-check-cfg-impl, r=petrochenkovJubilee-1/+7
Cleanup and improve `--check-cfg` implementation This PR removes some indentation in the code, as well as preventing some bugs/misusages and fix a nit in the doc. r? ```@petrochenkov``` (maybe)
2023-10-28Rollup merge of #116945 - estebank:sealed-trait-impls, r=petrochenkovJubilee-7/+77
When encountering sealed traits, point types that implement it ``` error[E0277]: the trait bound `S: d::Hidden` is not satisfied --> $DIR/sealed-trait-local.rs:53:20 | LL | impl c::Sealed for S {} | ^ the trait `d::Hidden` is not implemented for `S` | note: required by a bound in `c::Sealed` --> $DIR/sealed-trait-local.rs:17:23 | LL | pub trait Sealed: self::d::Hidden { | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` = note: `Sealed` is a "sealed trait", because to implement it you also need to implement `c::d::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - c::X - c::Y ``` The last `help` is new.
2023-10-28restore snapshot when parse_param_generalMu001999-0/+24