about summary refs log tree commit diff
path: root/tests/ui/inline-const
AgeCommit message (Collapse)AuthorLines
2025-09-11Revert "Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov"Jieyou Xu-2/+2
This reverts commit 1eeb8e8b151d1da7daa73837a25dc5f7a1a7fa28, reversing changes made to 324bf2b9fd8bf9661e7045c8a93f5ff0ec1a8ca5. Unfortunately the assert desugaring change is not backwards compatible, see RUST-145770. Code such as ```rust #[derive(Debug)] struct F { data: bool } impl std::ops::Not for F { type Output = bool; fn not(self) -> Self::Output { !self.data } } fn main() { let f = F { data: true }; assert!(f); } ``` would be broken by the assert desugaring change. We may need to land the change over an edition boundary, or limit the editions that the desugaring change impacts.
2025-08-12Change the desugaring of `assert!` for better error outputEsteban Küber-2/+2
In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`. The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation. ``` error[E0308]: mismatched types --> $DIR/issue-14091.rs:2:13 | LL | assert!(1,1); | ^ expected `bool`, found integer ``` We no longer mention the expression needing to implement the `Not` trait. ``` error[E0308]: mismatched types --> $DIR/issue-14091-2.rs:15:13 | LL | assert!(x, x); | ^ expected `bool`, found `BytePos` ``` `assert!(val)` now desugars to: ```rust match val { true => {}, _ => $crate::panic::panic_2021!(), } ``` Fix #122159. We make some minor changes to some diagnostics to avoid span overlap on type mismatch or inverted "expected"/"found" on type errors. We remove some unnecessary parens from core, alloc and miri. address review comments
2025-07-07const-block-as-pattern: do not refer to no-longer-existing nightly featureRalf Jung-3/+3
2025-06-10Loop check anon consts on their ownOli Scherer-11/+11
2025-06-10Remove check_mod_loops query and run the checks per-body insteadOli Scherer-22/+22
2025-06-10Add regression test for break inside const itemsOli Scherer-1/+19
2025-06-02Clarify why we are talking about a failed const eval at a random placeOli Scherer-3/+3
2025-06-02Use the informative error as the main const eval error messageOli Scherer-6/+6
2025-04-08UI tests: add missing diagnostic kinds where possibleVadim Petrochenkov-2/+2
2025-03-21remove `feature(inline_const_pat)`lcnr-365/+21
2025-03-14Do not suggest using `-Zmacro-backtrace` for builtin macrosEsteban Küber-4/+0
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-01Rollup merge of #136503 - estebank:const-panic, r=RalfJungMatthias Krüger-2/+2
Tweak output of const panic diagnostic ### Shorten span of panic failures in const context Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ panic: aborted execution: attempted to instantiate uninhabited type `!` ``` ``` error[E0080]: evaluation of `Fail::<i32>::C` failed --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:87:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ### Remove duplicated span from const eval frame list When the primary span for a const error is the same as the first frame in the const error report, skip it. ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ the failure occurred here = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ note: inside `_CONST` --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) note: erroneous constant encountered --> $DIR/issue-88434-removal-index-should-be-less.rs:3:23 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^^ ``` r? ``@oli-obk``
2025-02-28Shorten span of panic failures in const contextEsteban Küber-2/+2
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation panicked: aborted execution: attempted to instantiate uninhabited type `!` ``` ``` error[E0080]: evaluation of `Fail::<i32>::C` failed --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ evaluation panicked: explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:41:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ evaluation panicked: assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- When the primary span for a const error is the same as the first frame in the const error report, skip it. ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ evaluation panicked: explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ the failure occurred here = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ explicit panic | note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>` --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 | LL | panic!() | ^^^^^^^^ note: inside `_CONST` --> $DIR/issue-88434-removal-index-should-be-less.rs:3:24 | LL | const _CONST: &[u8] = &f(&[], |_| {}); | ^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` --- Revert order of constant evaluation errors Point at the code the user wrote first and std functions last. ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ evaluation panicked: Some error occurred | note: called from `my_fn` --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` instead of ``` error[E0080]: evaluation of constant value failed --> $DIR/const-errs-dont-conflict-103369.rs:10:5 | LL | panic!("Some error occurred"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred | note: called from `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` --> $DIR/const-errs-dont-conflict-103369.rs:5:25 | LL | impl ConstGenericTrait<{my_fn(1)}> for () {} | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2025-02-27Fix test directives that were accidentally ignoredYotam Ofek-1/+1
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-2/+3
``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ```
2025-01-09Make sure to walk into nested const blocks in RegionResolutionVisitorMichael Goulet-0/+16
2025-01-06`best_blame_constraint`: don't filter constraints by sup SCCdianne-5/+4
The SCCs of the region graph are not a reliable heuristic to use for blaming an interesting constraint for diagnostics. For region errors, if the outlived region is `'static`, or the involved types are invariant in their lifetiems, there will be cycles in the constraint graph containing both the target region and the most interesting constraints to blame. To get better diagnostics in these cases, this commit removes that heuristic.
2024-12-04review comments: reword messages and simplify logicEsteban Küber-4/+4
2024-12-04Specify type kind of constant that can't be used in patternsEsteban Küber-2/+2
``` error: trait object `dyn Send` cannot be used in patterns --> $DIR/issue-70972-dyn-trait.rs:6:9 | LL | const F: &'static dyn Send = &7u32; | -------------------------- constant defined here ... LL | F => panic!(), | ^ trait object can't be used in patterns ```
2024-12-04Point at generic param through which a const is used in a patternEsteban Küber-4/+4
``` error[E0158]: constant pattern depends on a generic parameter, which is not allowed --> $DIR/associated-const-type-parameter-pattern.rs:20:9 | LL | pub trait Foo { | ------------- LL | const X: EFoo; | ------------- constant defined here ... LL | pub fn test<A: Foo, B: Foo>(arg: EFoo) { | - constant depends on this generic param LL | match arg { LL | A::X => println!("A::X"), | ^^^^ `const` depends on a generic parameter ```
2024-11-16tests: ui/inline-consts: add issue number to a test, rename other tests from ↵Matthias Krüger-11/+11
a_b_c to a-b-c
2024-11-13Add test casesKirill Podoprigora-0/+124
2024-09-15stabilize const_mut_refsRalf Jung-9/+3
2024-09-03Rollup merge of #128701 - veera-sivarajan:fix-128604, r=estebankMatthias Krüger-0/+64
Don't Suggest Labeling `const` and `unsafe` Blocks Fixes #128604 Previously, both anonymous constant blocks (E.g. The labeled block inside `['_'; 'block: { break 'block 1 + 2; }]`) and inline const blocks (E.g. `const { ... }`) were considered to be the same kind of blocks. This caused the compiler to incorrectly suggest labeling both the blocks when only anonymous constant blocks can be labeled. This PR adds an other enum variant to `Context` so that both the blocks can be handled appropriately. Also, adds some doc comments and removes unnecessary `&mut` in a couple of places.
2024-08-08Add testtiif-0/+35
2024-08-06Don't Suggest Labeling `const` and `unsafe` BlocksVeera-13/+20
2024-08-06Add TestsVeera-0/+57
2024-07-18avoid creating an Instance only to immediately disassemble it againRalf Jung-2/+3
2024-06-07Add regression testOli Scherer-0/+18
2024-05-30Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrierilbors-0/+22
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-0/+22
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Reintroduce name resolution check for trying to access locals from an inline ↵Oli Scherer-0/+17
const
2024-05-02Stabilize exclusive_rangeRoss Smyth-1/+1
2024-04-24Fix tests and blessGary Guo-46/+18
2024-03-14preserve span when evaluating mir::ConstOperandRalf Jung-0/+26
2024-02-25fix use of platform_intrinsics in testsRalf Jung-1/+1
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-21/+21
2024-02-01`#![feature(inline_const_pat)]` is no longer incompleteMatthew Jasper-29/+11
2024-01-29Enable tests for unsafe blocks in inline const patternsMatthew Jasper-3/+39
2024-01-29Borrow check inline const patternsMatthew Jasper-5/+48
Add type annotations to MIR so that borrowck can pass constraints from inline constants in patterns to the containing function.
2024-01-05Stabilize THIR unsafeckMatthew Jasper-1/+1
2024-01-05Remove revisions for THIR unsafeckMatthew Jasper-77/+8
This is to make the diff when stabilizing it easier to review.
2023-11-24Show number in error message even for one errorNilstrieb-8/+8
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-10-25Make THIR unused_unsafe lint consistent with MIRMatthew Jasper-9/+0
Updates THIR behavior to match the changes from #93678
2023-10-16Fix inline const pattern unsafety checking in THIRMatthew Jasper-4/+70
THIR unsafety checking was getting a cycle of function unsafety checking -> building THIR for the function -> evaluating pattern inline constants in the function -> building MIR for the inline constant -> checking unsafety of functions (so that THIR can be stolen) This is fixed by not stealing THIR when generating MIR but instead when unsafety checking. This leaves an issue with pattern inline constants not being unsafety checked because they are evaluated away when generating THIR. To fix that we now represent inline constants in THIR patterns and visit them in THIR unsafety checking.
2023-09-21Prevent promotion of const fn calls in inline constsOli Scherer-1/+16
2023-09-21Add regression testOli Scherer-0/+21
2023-08-18Add a test to check that inline const is in required_constsGary Guo-0/+24
Suggested in https://github.com/rust-lang/rust/issues/76001#issuecomment-1315975027
2023-08-15Deny FnDef in patternsMichael Goulet-0/+30
2023-08-09Don't use type_of to determine if item has intrinsic shimMichael Goulet-0/+10