File tree 6 files changed +74
-11
lines changed
compiler/rustc_mir/src/const_eval
const-generics/const_evaluatable_checked
6 files changed +74
-11
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,19 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
312
312
let emit_as_lint = if let Some ( def) = def. as_local ( ) {
313
313
// (Associated) consts only emit a lint, since they might be unused.
314
314
matches ! ( tcx. def_kind( def. did. to_def_id( ) ) , DefKind :: Const | DefKind :: AssocConst )
315
+ || {
316
+ let mut did = def. did . to_def_id ( ) ;
317
+ loop {
318
+ use rustc_middle:: ty:: DefIdTree ;
319
+ match tcx. parent ( did) {
320
+ Some ( parent) => match tcx. def_kind ( did) {
321
+ DefKind :: TyAlias => break true ,
322
+ _ => did = parent,
323
+ } ,
324
+ None => break false ,
325
+ }
326
+ }
327
+ }
315
328
} else {
316
329
// use of broken constant from other crate: always an error
317
330
false
Original file line number Diff line number Diff line change 1
1
error[E0080]: evaluation of constant value failed
2
- --> $DIR/simple_fail.rs:9:48
2
+ --> $DIR/simple_fail.rs:12:10
3
3
|
4
- LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
5
- | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
4
+ LL | [u8; N - 1]: Sized,
5
+ | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
6
6
7
- error[E0080]: evaluation of constant value failed
7
+ error: any use of this value will cause an error
8
8
--> $DIR/simple_fail.rs:6:33
9
9
|
10
10
LL | type Arr<const N: usize> = [u8; N - 1];
11
11
| ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
12
+ |
13
+ = note: `#[deny(const_err)]` on by default
14
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
12
16
13
17
error: aborting due to 2 previous errors
14
18
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ LL | type Arr<const N: usize> = [u8; N - 1];
8
8
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
9
9
10
10
error: generic parameters may not be used in const operations
11
- --> $DIR/simple_fail.rs:9:48
11
+ --> $DIR/simple_fail.rs:12:10
12
12
|
13
- LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
14
- | ^ cannot perform const operation using `N`
13
+ LL | [u8; N - 1]: Sized,
14
+ | ^ cannot perform const operation using `N`
15
15
|
16
16
= help: const parameters may only be used as standalone arguments, i.e. `N`
17
17
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
Original file line number Diff line number Diff line change 3
3
#![ cfg_attr( full, feature( const_evaluatable_checked) ) ]
4
4
#![ allow( incomplete_features) ]
5
5
6
- type Arr < const N : usize > = [ u8 ; N - 1 ] ; //[full]~ ERROR evaluation of constant
6
+ type Arr < const N : usize > = [ u8 ; N - 1 ] ; //[full]~ ERROR any use of this value will cause an error
7
7
//[min]~^ ERROR generic parameters may not be used in const operations
8
+ //[full]~^^ WARN this was previously accepted by the compiler but is being phased out
8
9
9
- fn test < const N : usize > ( ) -> Arr < N > where [ u8 ; N - 1 ] : Sized {
10
- //[min]~^ ERROR generic parameters may not be used in const operations
11
- //[full]~^^ ERROR evaluation of constant
10
+ fn test < const N : usize > ( ) -> Arr < N >
11
+ where
12
+ [ u8 ; N - 1 ] : Sized ,
13
+ //[min]~^ ERROR generic parameters may not be used in const operations
14
+ //[full]~^^ ERROR evaluation of constant
15
+ {
12
16
todo ! ( )
13
17
}
14
18
Original file line number Diff line number Diff line change
1
+ type Foo = [ u8 ; 0 - 1 ] ;
2
+ //~^ ERROR any use of this value will cause an error
3
+ //~| WARN will become a hard error
4
+
5
+ fn foo ( ) -> Foo {
6
+ todo ! ( )
7
+ }
8
+ struct Q < const N : usize > ;
9
+ type Bar = Q < { 0 - 1 } > ;
10
+ //~^ ERROR any use of this value will cause an error
11
+ //~| WARN will become a hard error
12
+
13
+ impl Default for Bar {
14
+ fn default ( ) -> Self {
15
+ Q
16
+ }
17
+ }
18
+
19
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: any use of this value will cause an error
2
+ --> $DIR/erroneous_const.rs:1:17
3
+ |
4
+ LL | type Foo = [u8; 0 - 1];
5
+ | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
6
+ |
7
+ = note: `#[deny(const_err)]` on by default
8
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
10
+
11
+ error: any use of this value will cause an error
12
+ --> $DIR/erroneous_const.rs:9:16
13
+ |
14
+ LL | type Bar = Q<{ 0 - 1 }>;
15
+ | --^^^^^--
16
+ | |
17
+ | attempt to compute `0_usize - 1_usize`, which would overflow
18
+ |
19
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
20
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
21
+
22
+ error: aborting due to 2 previous errors
23
+
You can’t perform that action at this time.
0 commit comments