about summary refs log tree commit diff
path: root/src/test
AgeCommit message (Collapse)AuthorLines
2022-04-11Extend the MIR validator to check many more things around rvalues.Jakob Degen-21/+21
2022-04-11Rollup merge of #95864 - luqmana:inline-asm-unwind-store-miscompile, r=AmanieuDylan DPC-2/+15
Fix miscompilation of inline assembly with outputs in cases where we emit an invoke instead of call instruction. We ran into this bug where rustc would segfault while trying to compile certain uses of inline assembly. Here is a simple repro that demonstrates the issue: ```rust #![feature(asm_unwind)] fn main() { let _x = String::from("string here just cause we need something with a non-trivial drop"); let foo: u64; unsafe { std::arch::asm!( "mov {}, 1", out(reg) foo, options(may_unwind) ); } println!("{}", foo); } ``` ([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7d6641e83370d2536a07234aca2498ff)) But crucially `feature(asm_unwind)` is not actually needed and this can be triggered on stable as a result of the way async functions/generators are handled in the compiler. e.g.: ```rust extern crate futures; // 0.3.21 async fn bar() { let foo: u64; unsafe { std::arch::asm!( "mov {}, 1", out(reg) foo, ); } println!("{}", foo); } fn main() { futures::executor::block_on(bar()); } ``` ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1c7781c34dd4a3e80ae4bd936a0c82fc)) An example of the incorrect LLVM generated: ```llvm bb1: ; preds = %start %1 = invoke i64 asm sideeffect alignstack inteldialect unwind "mov ${0:q}, 1", "=&r,~{dirflag},~{fpsr},~{flags},~{memory}"() to label %bb2 unwind label %cleanup, !srcloc !9 store i64 %1, i64* %foo, align 8 bb2: [...snip...] ``` The store should not be placed after the asm invoke but rather should be in the normal control flow basic block (`bb2` in this case). [Here](https://gist.github.com/luqmana/be1af5b64d2cda5a533e3e23a7830b44) is a writeup of the investigation that lead to finding this.
2022-04-11Rollup merge of #95008 - c410-f3r:let-chains-paren, r=wesleywiserDylan DPC-461/+709
[`let_chains`] Forbid `let` inside parentheses Parenthesizes are mostly a no-op in let chains, in other words, they are mostly ignored. ```rust let opt = Some(Some(1i32)); if (let Some(a) = opt && (let Some(b) = a)) && b == 1 { println!("`b` is declared inside but used outside"); } ``` As seen above, such behavior can lead to confusion. A proper fix or nested encapsulation would probably require research, time and a modified MIR graph so in this PR I simply denied any `let` inside parentheses. Non-let stuff are still allowed. ```rust fn main() { let fun = || true; if let true = (true && fun()) && (true) { println!("Allowed"); } } ``` It is worth noting that `let ...` is not an expression and the RFC did not mention this specific situation. cc `@matthewjasper`
2022-04-11update ui tests using opaque types in impl headersRémy Rakic-2/+2
2022-04-11add regression tests for opaque types in impl headersRémy Rakic-0/+92
2022-04-11prevent opaque types from appearing in impl headersRémy Rakic-35/+55
2022-04-11Auto merge of #95125 - JakobDegen:uninit-variant-rvalue, r=oli-obkbors-200/+565
Add new `Deinit` statement This rvalue replaces `SetDiscriminant` for ADTs. This PR is an alternative to #94590 , which only specifies that the behavior of `SetDiscriminant` is the same as what this rvalue would do. The motivation for this change are discussed in that PR and [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/SetDiscriminant.20and.20aggregate.20initialization.20.2394590) r? `@oli-obk`
2022-04-11Remove inlining cost of `Deinit` statementsJakob Degen-109/+263
2022-04-11Add new `MutatatingUseContext`s for deinit and `SetDiscriminant`Jakob Degen-13/+26
2022-04-11Add const eval tests ensuring padding gets correctly marked as deinit on ↵Jakob Degen-0/+37
deaggregation
2022-04-11Fix tests broken by deaggregation changeJakob Degen-465/+619
2022-04-11Bless tests that broke in a trivial way due to change in deaggregationJakob Degen-11/+18
2022-04-11fix a bad error message for `relative paths are not supported in ↵Takayuki Maeda-2/+2
visibilities` error
2022-04-11Auto merge of #95931 - matthiaskrgr:rollup-1c5zhit, r=matthiaskrgrbors-6/+25
Rollup of 7 pull requests Successful merges: - #95743 (Update binary_search example to instead redirect to partition_point) - #95771 (Update linker-plugin-lto.md to 1.60) - #95861 (Note that CI tests Windows 10) - #95875 (bootstrap: show available paths help text for aliased subcommands) - #95876 (Add a note for unsatisfied `~const Drop` bounds) - #95907 (address fixme for diagnostic variable name) - #95917 (thin_box test: import from std, not alloc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-11Rollup merge of #95876 - fee1-dead:note-const-drop, r=oli-obkMatthias Krüger-6/+25
Add a note for unsatisfied `~const Drop` bounds r? ``@oli-obk``
2022-04-11Auto merge of #95758 - compiler-errors:issue-54771, r=estebankbors-21/+75
Only suggest removing semicolon when expression is compatible with `impl Trait` https://github.com/rust-lang/rust/issues/54771#issuecomment-476423690 > It still needs checking that the last statement's expr can actually conform to the trait, but the naïve behavior is there. Only suggest removing a semicolon when the type behind the semicolon actually implements the trait in an RPIT `-> impl Trait`. Also upgrade the label that suggests removing the semicolon to a suggestion (should it be verbose?). cc #54771
2022-04-11fix Layout struct member naming styleliangyongrui-4/+4
2022-04-11Auto merge of #95754 - compiler-errors:binder-assoc-ty, r=nagisabors-0/+19
Better error for `for<...>` on associated type bound With GATs just around the corner, we'll probably see more people trying out `Trait<for<'a> Assoc<'a> = ..>`. This PR improves the syntax error slightly, and also makes it slightly easier to make this into real syntax in the future. Feel free to push back if the reviewer thinks this should have a suggestion on how to fix it (i.e. push the `for<'a>` outside of the angle brackets), but that can also be handled in a follow-up PR.
2022-04-10use find_ancestor_inside to get right span in CastCheckMichael Goulet-0/+23
2022-04-10Delay a bug when we see SelfCtor in ref patternMichael Goulet-0/+20
2022-04-11Add a note for unsatisfied `~const Drop` boundsDeadbeef-6/+25
2022-04-11Auto merge of #94243 - compiler-errors:compiler-flags-typo, r=Mark-Simulacrumbors-3/+3
`s/compiler-flags/compile-flags` in compiletest Also make compiletest panic so this doesn't happen in the future! I literally always forget which it's called, so I wanted to make my life easier in the future. Also open to the possibility of parsing both.
2022-04-10Fix test case for windowsMichael Howell-0/+70
2022-04-10better error for binder on associated type boundMichael Goulet-0/+19
2022-04-10Fix crate_type attribute to not warn on duplicatesEric Huss-60/+44
2022-04-10only suggest removing semicolon when expr implements traitMichael Goulet-21/+75
2022-04-10Rollup merge of #95857 - ouz-a:mir-opt, r=oli-obkDylan DPC-0/+109
Allow multiple derefs to be splitted in deref_separator Previously in #95649 only a single deref within projection was supported and multiple derefs caused a bunch of issues, this PR fixes those issues. ```@oli-obk``` helped a ton again ❤️
2022-04-10Rollup merge of #95852 - niluxv:strict-provenance-lint-fixup, r=Dylan-DPCDylan DPC-2/+2
Fix missing space in lossy provenance cast lint See https://github.com/rust-lang/rust/pull/95599#discussion_r846425050
2022-04-10Rollup merge of #95807 - TaKO8Ki:suggest-local-var-for-vector, r=fee1-deadDylan DPC-0/+78
Suggest adding a local for vector to fix borrowck errors closes #95574
2022-04-10Rollup merge of #95784 - WaffleLapkin:typeof_cool_suggestion, r=compiler-errorsDylan DPC-0/+15
Suggest replacing `typeof(...)` with an actual type This PR adds suggestion to replace `typeof(...)` with an actual type of `...`, for example in case of `typeof(1)` we suggest replacing it with `i32`. If the expression 1. Is not const (`{ let a = 1; let _: typeof(a); }`) 2. Can't be found (`let _: typeof(this_variable_does_not_exist)`) 3. Or has non-suggestable type (closure, generator, error, etc) we don't suggest anything. The 1 one is sad, but it's not clear how to support non-consts expressions for `typeof`. _This PR is inspired by [this tweet]._ [this tweet]: https://twitter.com/compiler_errors/status/1511945354752638976
2022-04-10resolve: Create dummy bindings for all unresolved importsVadim Petrochenkov-15/+20
2022-04-10--bless testsMaybe Waffle-0/+15
2022-04-09Auto merge of #95435 - cjgillot:one-name, r=oli-obkbors-0/+3
Make def names and HIR names consistent. The name in the `DefKey` is interned to create the `DefId`, so it does not require any query to access. This can be leveraged to avoid a few useless HIR accesses for names. ~In order to achieve that, generic parameters created from universal impl-trait are given the pretty-printed ast as a name, instead of `{{opaque}}`.~ ~Drive-by: the `TyCtxt::opt_item_name` used a dummy span for non-local definitions. We have access to `def_ident_span`, so we use it.~
2022-04-09Update asm-may_unwind test to handle use of asm with outputs.Luqman Aden-2/+15
2022-04-09support multiple derefsouz-a-0/+109
2022-04-09Rollup merge of #95808 - petrochenkov:fragspec, r=nnethercoteDylan DPC-9/+116
expand: Remove `ParseSess::missing_fragment_specifiers` It was used for deduplicating some errors for legacy code which are mostly deduplicated even without that, but at cost of global mutable state, which is not a good tradeoff. cc https://github.com/rust-lang/rust/pull/95747#issuecomment-1091619403 r? ``@nnethercote``
2022-04-09Rollup merge of #95361 - scottmcm:valid-align, r=Mark-SimulacrumDylan DPC-9/+36
Make non-power-of-two alignments a validity error in `Layout` Inspired by the zulip conversation about how `Layout` should better enforce `size <= isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld. This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`. It's left as `pub(crate)` here; a future PR could consider giving it a tracking issue for non-internal usage.
2022-04-09Fix missing space in lossy provenance cast lintniluxv-2/+2
2022-04-09expand: Remove `ParseSess::missing_fragment_specifiers`Vadim Petrochenkov-9/+116
It was used for deduplicating some errors for legacy code which are mostly deduplicated even without that, but at cost of global mutable state, which is not a good tradeoff.
2022-04-09Rollup merge of #95769 - fmease:fix-issue-95717, r=GuillaumeGomezDylan DPC-0/+42
Hide cross-crate `#[doc(hidden)]` associated items in trait impls Fixes #95717. r? ```@GuillaumeGomez``` This is the bug I ran into in #95316. ```@rustbot``` label T-rustdoc A-cross-crate-reexports
2022-04-09Bless tests.Camille GILLOT-0/+3
2022-04-09Rollup merge of #95804 - GuillaumeGomez:empty-doc-comment-with-backline, ↵Dylan DPC-0/+22
r=notriddle rustdoc: Fix empty doc comment with backline ICE Fixes #95800. r? ```@notriddle```
2022-04-09Rollup merge of #95764 - c410-f3r:metavar-test, r=petrochenkovDylan DPC-1/+117
[macro_metavar_expr] Add tests to ensure the feature requirement These tests should have been added in the initial implementation they were unintentionally forgotten cc #83527 r? ````@petrochenkov````
2022-04-09Rollup merge of #95751 - compiler-errors:ambig-int, r=jackh726Dylan DPC-32/+29
Don't report numeric inference ambiguity when we have previous errors Fixes #95648
2022-04-09Rollup merge of #95599 - niluxv:strict-provenance-lint, r=michaelwoeristerDylan DPC-0/+142
Strict provenance lints See #95488. This PR introduces two unstable (allow by default) lints to which lint on int2ptr and ptr2int casts, as the former is not possible in the strict provenance model and the latter can be written nicer using the `.addr()` API. Based on an initial version of the lint by ```@Gankra``` in #95199.
2022-04-09Rollup merge of #95374 - RalfJung:assert_uninit_valid, r=Mark-SimulacrumDylan DPC-0/+28
assert_uninit_valid: ensure we detect at least arrays of uninhabited types We can't easily extend this check to *all* arrays (Cc https://github.com/rust-lang/rust/pull/87041), but it turns out the existing check already catches arrays of uninhabited types. So let's make sure it stays that way by adding them to the test.
2022-04-09Rollup merge of #90066 - yaahc:thinbox, r=joshtriplettDylan DPC-2/+129
Add new ThinBox type for 1 stack pointer wide heap allocated trait objects **Zulip Thread**: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/ThinBox Based on https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs Tracking Issue: https://github.com/rust-lang/rust/issues/92791 Usage Trial: https://github.com/yaahc/pgx/pull/1/files ## TODO - [x] make sure to test with #[repr(align(1024))] structs etc
2022-04-08Make non-power-of-two alignments a validity error in `Layout`Scott McMurray-9/+36
Inspired by the zulip conversation about how `Layout` should better enforce `size < isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld. This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`.
2022-04-08Auto merge of #95519 - oli-obk:tait_ub2, r=compiler-errorsbors-0/+101
Enforce well formedness for type alias impl trait's hidden type fixes #84657 This was not an issue with return-position-impl-trait because the generic bounds of the function are the same as those of the opaque type, and the hidden type must already be well formed within the function. With type-alias-impl-trait the hidden type could be defined in a function that has *more* lifetime bounds than the type alias. This is fine, but the hidden type must still be well formed without those additional bounds.
2022-04-08Add ThinBox type for 1 stack pointer sized heap allocated trait objectsJane Lusby-2/+129
Relevant commit messages from squashed history in order: Add initial version of ThinBox update test to actually capture failure swap to middle ptr impl based on matthieu-m's design Fix stack overflow in debug impl The previous version would take a `&ThinBox<T>` and deref it once, which resulted in a no-op and the same type, which it would then print causing an endless recursion. I've switched to calling `deref` by name to let method resolution handle deref the correct number of times. I've also updated the Drop impl for good measure since it seemed like it could be falling prey to the same bug, and I'll be adding some tests to verify that the drop is happening correctly. add test to verify drop is behaving add doc examples and remove unnecessary Pointee bounds ThinBox: use NonNull ThinBox: tests for size Apply suggestions from code review Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com> use handle_alloc_error and fix drop signature update niche and size tests add cfg for allocating APIs check null before calculating offset add test for zst and trial usage prevent optimizer induced ub in drop and cleanup metadata gathering account for arbitrary size and alignment metadata Thank you nika and thomcc! Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org> Update library/alloc/src/boxed/thin.rs Co-authored-by: Josh Triplett <josh@joshtriplett.org>