about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
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-30Detect when trait is implemented for type and suggest importing itEsteban Küber-12/+9
Fix #57457.
2023-10-30Only run panic tests on targets that can unwindOli Scherer-1/+2
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-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-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
2023-10-27Auto merge of #116471 - notriddle:notriddle/js-trait-alias, r=GuillaumeGomezbors-29/+222
rustdoc: use JS to inline target type impl docs into alias Preview docs: - https://notriddle.com/rustdoc-html-demo-5/js-trait-alias/std/io/type.Result.html - https://notriddle.com/rustdoc-html-demo-5/js-trait-alias-compiler/rustc_middle/ty/type.PolyTraitRef.html This pull request also includes a bug fix for trait alias inlining across crates. This means more documentation is generated, and is why ripgrep runs slower (it's a thin wrapper on top of the `grep` crate, so 5% of its docs are now the Result type). - Before, built with rustdoc 1.75.0-nightly (aa1a71e9e 2023-10-26), Result type alias method docs are missing: http://notriddle.com/rustdoc-html-demo-5/ripgrep-js-nightly/rg/type.Result.html - After, built with this branch, all the methods on Result are shown: http://notriddle.com/rustdoc-html-demo-5/ripgrep-js-trait-alias/rg/type.Result.html *Review note: This is mostly just reverting https://github.com/rust-lang/rust/pull/115201. The last commit has the new work in it.* Fixes #115718 This is an attempt to balance three problems, each of which would be violated by a simpler implementation: - A type alias should show all the `impl` blocks for the target type, and vice versa, if they're applicable. If nothing was done, and rustdoc continues to match them up in HIR, this would not work. - Copying the target type's docs into its aliases' HTML pages directly causes far too much redundant HTML text to be generated when a crate has large numbers of methods and large numbers of type aliases. - Using JavaScript exclusively for type alias impl docs would be a functional regression, and could make some docs very hard to find for non-JS readers. - Making sure that only applicable docs are show in the resulting page requires a type checkers. Do not reimplement the type checker in JavaScript. So, to make it work, rustdoc stashes these type-alias-inlined docs in a JSONP "database-lite". The file is generated in `write_shared.rs`, included in a `<script>` tag added in `print_item.rs`, and `main.js` takes care of patching the additional docs into the DOM. The format of `trait.impl` and `type.impl` JS files are superficially similar. Each line, except the JSONP wrapper itself, belongs to a crate, and they are otherwise separate (rustdoc should be idempotent). The "meat" of the file is HTML strings, so the frontend code is very simple. Links are relative to the doc root, though, so the frontend needs to fix that up, and inlined docs can reuse these files. However, there are a few differences, caused by the sophisticated features that type aliases have. Consider this crate graph: ```text --------------------------------- | crate A: struct Foo<T> | | type Bar = Foo<i32> | | impl X for Foo<i8> | | impl Y for Foo<i32> | --------------------------------- | ---------------------------------- | crate B: type Baz = A::Foo<i8> | | type Xyy = A::Foo<i8> | | impl Z for Xyy | ---------------------------------- ``` The type.impl/A/struct.Foo.js JS file has a structure kinda like this: ```js JSONP({ "A": [["impl Y for Foo<i32>", "Y", "A::Bar"]], "B": [["impl X for Foo<i8>", "X", "B::Baz", "B::Xyy"], ["impl Z for Xyy", "Z", "B::Baz"]], }); ``` When the type.impl file is loaded, only the current crate's docs are actually used. The main reason to bundle them together is that there's enough duplication in them for DEFLATE to remove the redundancy. The contents of a crate are a list of impl blocks, themselves represented as lists. The first item in the sublist is the HTML block, the second item is the name of the trait (which goes in the sidebar), and all others are the names of type aliases that successfully match. This way: - There's no need to generate these files for types that have no aliases in the current crate. If a dependent crate makes a type alias, it'll take care of generating its own docs. - There's no need to reimplement parts of the type checker in JavaScript. The Rust backend does the checking, and includes its results in the file. - Docs defined directly on the type alias are dropped directly in the HTML by `render_assoc_items`, and are accessible without JavaScript. The JSONP file will not list impl items that are known to be part of the main HTML file already. [JSONP]: https://en.wikipedia.org/wiki/JSONP
2023-10-28coverage: Consistently remove unused counter IDs from expressions/mappingsZalathar-155/+156
2023-10-28coverage: Regression test for #17012 (bad counter IDs in mappings)Zalathar-0/+298
2023-10-27Auto merge of #117294 - matthiaskrgr:rollup-xylsec7, r=matthiaskrgrbors-128/+154
Rollup of 7 pull requests Successful merges: - #116834 (Remove `rustc_symbol_mangling/messages.ftl`.) - #117212 (Properly restore snapshot when failing to recover parsing ternary) - #117246 (Fix ICE: Restrict param constraint suggestion) - #117247 (NVPTX: Allow PassMode::Direct for ptx kernels for now) - #117270 (Hide internal methods from documentation) - #117281 (std::thread : add SAFETY comment) - #117287 (fix miri target information for Test step) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-27Auto merge of #103208 - cjgillot:match-fake-read, r=oli-obk,RalfJungbors-477/+266
Allow partially moved values in match This PR attempts to unify the behaviour between `let _ = PLACE`, `let _: TY = PLACE;` and `match PLACE { _ => {} }`. The logical conclusion is that the `match` version should not check for uninitialised places nor check that borrows are still live. The `match PLACE {}` case is handled by keeping a `FakeRead` in the unreachable fallback case to verify that `PLACE` has a legal value. Schematically, `match PLACE { arms }` in surface rust becomes in MIR: ```rust PlaceMention(PLACE) match PLACE { // Decision tree for the explicit arms arms, // An extra fallback arm _ => { FakeRead(ForMatchedPlace, PLACE); unreachable } } ``` `match *borrow { _ => {} }` continues to check that `*borrow` is live, but does not read the value. `match *borrow {}` both checks that `*borrow` is live, and fake-reads the value. Continuation of ~https://github.com/rust-lang/rust/pull/102256~ ~https://github.com/rust-lang/rust/pull/104844~ Fixes https://github.com/rust-lang/rust/issues/99180 https://github.com/rust-lang/rust/issues/53114
2023-10-27Rollup merge of #117246 - estebank:issue-117209, r=petrochenkovMatthias Krüger-0/+132
Fix ICE: Restrict param constraint suggestion When encountering an associated item with a type param that could be constrained, do not look at the parent item if the type param comes from the associated item. Fix #117209, fix #89868.
2023-10-27Rollup merge of #117212 - clubby789:fix-ternary-recover, r=compiler-errorsMatthias Krüger-128/+22
Properly restore snapshot when failing to recover parsing ternary If the recovery parsed an expression, then failed to eat a `:`, it would return `false` without restoring the snapshot. Fix this by always restoring the snapshot when returning `false`. Draft for now because I'd like to try and improve this recovery further. Fixes #117208
2023-10-27When encountering sealed traits, point types that implement itEsteban Küber-7/+77
``` 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-27Account for type param from other item in `note_and_explain`Esteban Küber-0/+86
Fix #89868.
2023-10-27fix failure to detect a too-big-type after adding paddingRalf Jung-0/+26
2023-10-27Fuse `gen` blocksOli Scherer-19/+2
2023-10-27Auto merge of #116751 - Nadrieril:lint-overlap-per-column, r=davidtwcobors-25/+76
Lint overlapping ranges as a separate pass This reworks the [`overlapping_range_endpoints`](https://doc.rust-lang.org/beta/nightly-rustc/rustc_lint_defs/builtin/static.OVERLAPPING_RANGE_ENDPOINTS.html) lint. My motivations are: - It was annoying to have this lint entangled with the exhaustiveness algorithm, especially wrt librarification; - This makes the lint behave consistently. Here's the consistency story. Take the following matches: ```rust match (0u8, true) { (0..=10, true) => {} (10..20, true) => {} (10..20, false) => {} _ => {} } match (true, 0u8) { (true, 0..=10) => {} (true, 10..20) => {} (false, 10..20) => {} _ => {} } ``` There are two semantically consistent options: option 1 we lint all overlaps between the ranges, option 2 we only lint the overlaps that could actually occur (i.e. the ones with `true`). Option 1 is what this PR does. Option 2 is possible but would require the exhaustiveness algorithm to track more things for the sake of the lint. The status quo is that we're inconsistent between the two. Option 1 generates more false postives, but I prefer it from a maintainer's perspective. I do think the difference is minimal; cases where the difference is observable seem rare. This PR adds a separate pass, so this will have a perf impact. Let's see how bad, it looked ok locally.
2023-10-27Use targetted diagnostic for borrow across yield errorOli Scherer-2/+2
2023-10-27Prevent generators from being movableOli Scherer-0/+28
2023-10-27Handle `move` generatorsOli Scherer-0/+98
2023-10-27Feature gate coroutine `yield` usageOli Scherer-13/+74
2023-10-27Demonstrate issue with `yield` checksOli Scherer-2/+15
2023-10-27Feature gate `gen` blocks, even in 2024 editionOli Scherer-13/+89
2023-10-27Basic generators workOli Scherer-0/+18
2023-10-27Make `gen` blocks implement the `Iterator` traitOli Scherer-0/+78
2023-10-27Add gen blocks to ast and do some broken ast loweringOli Scherer-10/+10
2023-10-27Auto merge of #116858 - estebank:issue-22488, r=petrochenkovbors-0/+50
Suggest assoc fn `new` when trying to build tuple struct with private fields Fix #22488.
2023-10-27Allows `#[diagnostic::on_unimplemented]` attributes to have multipleGeorg Semmler-0/+73
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.
2023-10-27Auto merge of #117272 - matthiaskrgr:rollup-upg122z, r=matthiaskrgrbors-287/+142
Rollup of 6 pull requests Successful merges: - #114998 (feat(docs): add cargo-pgo to PGO documentation 📝) - #116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr) - #117240 (Fix documentation typo in std::iter::Iterator::collect_into) - #117241 (Stash and cancel cycle errors for auto trait leakage in opaques) - #117262 (Create a new ConstantKind variant (ZeroSized) for StableMIR) - #117266 (replace transmute by raw pointer cast) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-27Better guard against wrong input with check-cfg any()Urgau-1/+7