File tree Expand file tree Collapse file tree
compiler/rustc_const_eval/src/check_consts
tests/run-make/const-destruct-stable-toolchain Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -614,7 +614,10 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
614614 } ;
615615
616616 // If the dropped type is a type parameter, suggest adding a `[const] Destruct` bound.
617- if let Param ( param_ty) = self . dropped_ty . kind ( ) {
617+ // The suggestion is only offered on nightly, since `[const]` bounds are unstable.
618+ if let Param ( param_ty) = self . dropped_ty . kind ( )
619+ && ccx. tcx . sess . is_nightly_build ( )
620+ {
618621 let tcx = ccx. tcx ;
619622 let caller = ccx. def_id ( ) ;
620623 if let Some ( generics) = tcx. hir_node_by_def_id ( caller) . generics ( ) {
Original file line number Diff line number Diff line change 1+ error[E0493]: destructor of `T` cannot be evaluated at compile-time
2+ --> const-drop.rs:1:24
3+ |
4+ LL | const fn const_drop<T>(_: T) {}
5+ | ^ - value is dropped here
6+ | |
7+ | the destructor for this type cannot be evaluated in constant functions
8+ |
9+ help: consider restricting type parameter `T` with unstable trait `Destruct`
10+ |
11+ LL | const fn const_drop<T: [const] Destruct>(_: T) {}
12+ | ++++++++++++++++++
13+
14+ error: aborting due to 1 previous error
15+
16+ For more information about this error, try `rustc --explain E0493`.
Original file line number Diff line number Diff line change 1+ error[E0493]: destructor of `T` cannot be evaluated at compile-time
2+ --> const-drop.rs:1:24
3+ |
4+ 1 | const fn const_drop<T>(_: T) {}
5+ | ^ - value is dropped here
6+ | |
7+ | the destructor for this type cannot be evaluated in constant functions
8+
9+ error: aborting due to 1 previous error
10+
11+ For more information about this error, try `rustc --explain E0493`.
Original file line number Diff line number Diff line change 1+ const fn const_drop < T > ( _: T ) { }
2+
3+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ //@ needs-target-std
2+ //
3+ // Test that the suggestion to constrain a type parameter that is dropped in a const
4+ // function with a `[const] Destruct` bound is only offered on nightly, since the bound
5+ // requires an unstable feature.
6+
7+ use run_make_support:: { diff, rustc} ;
8+
9+ fn main ( ) {
10+ let out = rustc ( )
11+ . input ( "const-drop.rs" )
12+ . env ( "RUSTC_BOOTSTRAP" , "-1" )
13+ . run_fail ( )
14+ . assert_stderr_not_contains ( "consider restricting type parameter `T`" )
15+ . stderr_utf8 ( ) ;
16+ diff ( ) . expected_file ( "const-drop-stable.stderr" ) . actual_text ( "(rustc)" , & out) . run ( ) ;
17+ let out = rustc ( )
18+ . input ( "const-drop.rs" )
19+ . ui_testing ( )
20+ . run_fail ( )
21+ . assert_stderr_contains (
22+ "consider restricting type parameter `T` with unstable trait `Destruct`" ,
23+ )
24+ . stderr_utf8 ( ) ;
25+ diff ( ) . expected_file ( "const-drop-nightly.stderr" ) . actual_text ( "(rustc)" , & out) . run ( ) ;
26+ }
You can’t perform that action at this time.
0 commit comments