about summary refs log tree commit diff
path: root/tests/ui/consts
AgeCommit message (Collapse)AuthorLines
2023-03-29Rollup merge of #109664 - m-ou-se:format-args-placeholder-span, r=oli-obkDylan DPC-4/+4
Use span of placeholders in format_args!() expansion. `format_args!("{}", x)` expands to something that contains `Argument::new_display(&x)`. That entire expression was generated with the span of `x`. After this PR, `&x` uses the span of `x`, but the `new_display` call uses the span of the `{}` placeholder within the format string. If an implicitly captured argument was used like in `format_args!("{x}")`, both use the span of the `{x}` placeholder. This fixes https://github.com/rust-lang/rust/issues/109576, and also allows for more improvements to similar diagnostics in the future, since the usage of `x` can now be traced to the exact `{}` placeholder that required it to be `Display` (or `Debug` etc.)
2023-03-28Auto merge of #109557 - fee1-dead-contrib:mv-const-traits, r=oli-obkbors-35/+85
Move const trait bounds checks to MIR constck Fixes #109543. When checking paths in HIR typeck, we don't want to check for const predicates since all we want might just be a function pointer. Therefore we move this to MIR constck and check that bounds are met during MIR constck. r? `@oli-obk`
2023-03-28Move const trait bounds checks to MIR constckDeadbeef-35/+85
Fixes #109543. When checking paths in HIR typeck, we don't want to check for const predicates since all we want might just be a function pointer. Therefore we move this to MIR constck and check that bounds are met during MIR constck.
2023-03-27Add notes to non-structural const in pattern error messageJamen Marz-10/+94
2023-03-27Bless UI tests.Mara Bos-4/+4
2023-03-22Add `CastKind::Transmute` to MIRScott McMurray-7/+68
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-21Detect uninhabited types early in const eval.Oli Scherer-28/+26
2023-03-16Don't allow new const panic through format flattening.Mara Bos-11/+21
panic!("a {}", "b") is still not allowed in const, even if the hir flattens to panic!("a b").
2023-03-15Auto merge of #108282 - cjgillot:mir-checked-sh, r=tmiaskobors-3/+3
Implement checked Shl/Shr at MIR building. This does not require any special handling by codegen backends, as the overflow behaviour is entirely determined by the rhs (shift amount). This allows MIR ConstProp to remove the overflow check for constant shifts. ~There is an existing different behaviour between cg_llvm and cg_clif (cc `@bjorn3).` I took cg_llvm's one as reference: overflow if `rhs < 0 || rhs > number_of_bits_in_lhs_ty`.~ EDIT: `cg_llvm` and `cg_clif` implement the overflow check differently. This PR uses `cg_llvm`'s implementation based on a `BitAnd` instead of `cg_clif`'s one based on an unsigned comparison.
2023-03-15Auto merge of #109035 - scottmcm:ptr-read-should-know-undef, ↵bors-22/+4
r=WaffleLapkin,JakobDegen Ensure `ptr::read` gets all the same LLVM `load` metadata that dereferencing does I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Trying to narrow it down, it seems that was because `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. The root cause is that `ptr::read` is currently implemented via the *untyped* `copy_nonoverlapping`, and thus the `load` doesn't get any type-aware metadata: no `noundef`, no `!range`. This PR solves that by lowering `ptr::read(p)` to `copy *p` in MIR, for which the backends already do the right thing. Fortuitiously, this also improves the IR we give to LLVM for things like `mem::replace`, and fixes a couple of long-standing bugs where `ptr::read` on `Copy` types was worse than `*`ing them. Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Move.20array.3A.3AIntoIter.20to.20ManuallyDrop/near/341189936> cc `@erikdesjardins` `@JakobDegen` `@workingjubilee` `@the8472` Fixes #106369 Fixes #73258
2023-03-13Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31bors-20/+14
Remove `box_syntax` r? `@Nilstrieb` This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected. It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute. As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new` Closes #49733
2023-03-12Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obkbors-6/+6
Strengthen state tracking in const-prop Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization. Behaviour changes: - const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen. - we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry. - the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
2023-03-12Remove uses of `box_syntax` in rustc and toolsclubby789-20/+14
2023-03-11`MaybeUninit::assume_init_read` should have `noundef` load metadataScott McMurray-22/+4
I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Turned out to be a more general problem as `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. This PR lowers `ptr::read(p)` to `copy *p` in MIR, which fortuitiously also improves the IR we give to LLVM for things like `mem::replace`.
2023-03-09Test `let _ =` for const_mut_refs.Camille GILLOT-1/+13
2023-03-08Recurse into statement before applying its effect.Camille GILLOT-6/+6
2023-03-05Use `nuw` when calculating slice lengths from `Range`sScott McMurray-0/+27
An `assume` would definitely not be worth it, but since the flag is almost free we might as well tell LLVM this, especially on `_unchecked` calls where there's no obvious way for it to deduce it. (Today neither safe nor unsafe indexing gets it: <https://rust.godbolt.org/z/G1jYT548s>)
2023-02-27Implement checked Shl/Shr at MIR building.Camille GILLOT-3/+3
2023-02-24Rollup merge of #106541 - fee1-dead-contrib:no-const-check-no, r=thomccDylan DPC-0/+16
implement const iterator using `rustc_do_not_const_check` Previous experiment: #102225. Explanation: rather than making all default methods work under `const` all at once, this uses `rustc_do_not_const_check` as a workaround to "trick" the compiler to not run any checks on those other default methods. Any const implementations are only required to implement the `next` method. Any actual calls to the trait methods other than `next` will either error in compile time (at CTFE runs), or run the methods correctly if they do not have any non-const operations. This is extremely easy to maintain, remove, or improve.
2023-02-21Rollup merge of #108295 - compiler-errors:wtf-is-this, r=cjgillotMatthias Krüger-1/+1
Use DefKind to give more item kind information during BindingObligation note The current label says "required by a bound in this". When I see that label, my immediate impression is "this... **what**?". It feels like it was cut short. Alternative to this would be saying "in this item", but adding the item kind is strictly more informational and adds very little overhead to the existing error presentation.
2023-02-21Rollup merge of #108000 - y21:no-zero-init-for-uninhabited, r=jackh726Dylan DPC-16/+4
lint: don't suggest MaybeUninit::assume_init for uninhabited types Creating a zeroed uninhabited type such as `!` or an empty enum with `mem::zeroed()` (or transmuting `()` to `!`) currently triggers this lint: ```rs warning: the type `!` does not permit zero-initialization --> test.rs:5:23 | 5 | let _val: ! = mem::zeroed(); | ^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | = note: the `!` type has no valid value ``` The `MaybeUninit` suggestion in the help message seems confusing/useless for uninhabited types, as such a type cannot be fully initialized in the first place (as the note implies). This PR limits this help message to inhabited types which can be initialized
2023-02-21Specify what 'this' actually isMichael Goulet-1/+1
2023-02-20basic dyn* support for MiriRalf Jung-6/+6
2023-02-18lint: don't suggest assume_init for uninhabited typesy21-16/+4
2023-02-17Rollup merge of #108009 - c410-f3r:moar-tests, r=petrochenkovMatthias Krüger-0/+26
Move some tests r? `@petrochenkov`
2023-02-16Move testsCaio-0/+26
2023-02-15Rollup merge of #107972 - saethlin:fix-test-ub, r=michaelwoeristerMatthias Krüger-1/+4
Fix unintentional UB in ui tests `@matthiaskrgr` found UB in a bunch of the ui tests. This PR fixes a batch of miscellaneous tests I didn't think needed reviewers from a particular part of the project.
2023-02-15Fix unintentional UB in ui testsBen Kimock-1/+4
2023-02-12Suggest the correct array length on mismatchclubby789-2/+21
2023-02-07Tweak ICE messageEsteban Küber-3/+2
Modify main message to be more conversational and emit one fewer note.
2023-02-02Bless tests.Camille GILLOT-12/+0
2023-01-31add and bless testsDeadbeef-0/+16
2023-01-30Modify primary span label for E0308Esteban Küber-5/+5
The previous output was unintuitive to users.
2023-01-29Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obkbors-11/+224
Use stable metric for const eval limit instead of current terminator-based logic This patch adds a `MirPass` that inserts a new MIR instruction `ConstEvalCounter` to any loops and function calls in the CFG. This instruction is used during Const Eval to count against the `const_eval_limit`, and emit the `StepLimitReached` error, replacing the current logic which uses Terminators only. The new method of counting loops and function calls should be more stable across compiler versions (i.e., not cause crates that compiled successfully before, to no longer compile when changes to the MIR generation/optimization are made). Also see: #103877
2023-01-25Rollup merge of #106897 - estebank:issue-99430, r=davidtwcoMatthias Krüger-0/+1
Tweak E0597 CC #99430
2023-01-24Move const-eval/stable-metric ui testsBryan Garza-0/+204
2023-01-23Bless and update consts testsBryan Garza-11/+20
2023-01-18Rollup merge of #106917 - compiler-errors:const-closure-foreign, r=tmiaskoMichael Goulet-0/+16
Encode const mir for closures if they're const Fixes #106913
2023-01-18defer array len printing to const arg printingBoxy-8/+8
2023-01-17Rollup merge of #101698 - raldone01:feat/const_cmp_typeid, r=scottmcmDylan DPC-1/+14
Constify `TypeId` ordering impls Tracking issue: #101871 Adding const ordering to `TypeId` allows rtti crates to optimize some casting scenarios (without transmuting to `u64`). This would also prevent these crates from breaking if the underlying type is changed from `u64` to something different. Feature gate: `#![feature(const_cmp_type_id)]`
2023-01-17Rollup merge of #106591 - Ezrashaw:attempted-integer-identifer, r=EstebankMatthias Krüger-0/+24
suggestion for attempted integer identifier in patterns Fixes #106552 Implemented a suggestion on `E0005` that occurs when no bindings are present and the pattern is a literal integer.
2023-01-16Constify `TypeId` ordering implsonestacked-1/+14
2023-01-16Encode const mir for closures if they're constMichael Goulet-0/+16
2023-01-15Tweak E0597Esteban Küber-0/+1
CC #99430
2023-01-14suggest fix for attempted integer identifier in patternsEzra Shaw-0/+24
2023-01-13Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obkbors-2/+19
Const closures cc https://github.com/rust-lang/rust/issues/106003
2023-01-12Rollup merge of #106322 - compiler-errors:CollectAllMismatches-infer-vars, ↵nils-0/+42
r=oli-obk Handle inference variables in `CollectAllMismatches` correctly 1. Fix #106240 2. Treat int/float type variables correctly (see `src/test/ui/iterators/invalid-iterator-chain-with-int-infer.rs`), so we can point out things like "`Iterator::Item` changed to `{integer}` here"
2023-01-11Rollup merge of #106097 - mejrs:mir_build2, r=oli-obkMichael Goulet-18/+33
Migrate mir_build diagnostics 2 of 3 The first three commits are fairly boring, however I've made some changes to the output of the match checking diagnostics.
2023-01-12fix fmt and blessDeadbeef-2/+19
2023-01-11Migrate pattern matchingmejrs-18/+33