@@ -10,31 +10,34 @@ use rustc_span::{Span, Symbol};
1010
1111use super :: ConstCx ;
1212
13- /// Emits an error if `op` is not allowed in the given const context.
14- pub fn non_const < O : NonConstOp > ( ccx : & ConstCx < ' _ , ' _ > , op : O , span : Span ) {
13+ /// Emits an error and returns `true` if `op` is not allowed in the given const context.
14+ pub fn non_const < O : NonConstOp > ( ccx : & ConstCx < ' _ , ' _ > , op : O , span : Span ) -> bool {
1515 debug ! ( "illegal_op: op={:?}" , op) ;
1616
1717 let gate = match op. status_in_item ( ccx) {
18- Status :: Allowed => return ,
18+ Status :: Allowed => return false ,
1919
2020 Status :: Unstable ( gate) if ccx. tcx . features ( ) . enabled ( gate) => {
2121 let unstable_in_stable = ccx. is_const_stable_const_fn ( )
2222 && !super :: allow_internal_unstable ( ccx. tcx , ccx. def_id . to_def_id ( ) , gate) ;
2323
2424 if unstable_in_stable {
2525 ccx. tcx . sess
26- . struct_span_err ( span, & format ! ( "`#[feature({})]` cannot be depended on in a const-stable function" , gate. as_str( ) ) )
26+ . struct_span_err (
27+ span,
28+ & format ! ( "const-stable function cannot use `#[feature({})]`" , gate. as_str( ) ) ,
29+ )
2730 . span_suggestion (
2831 ccx. body . span ,
2932 "if it is not part of the public API, make this function unstably const" ,
3033 concat ! ( r#"#[rustc_const_unstable(feature = "...", issue = "...")]"# , '\n' ) . to_owned ( ) ,
3134 Applicability :: HasPlaceholders ,
3235 )
33- . help ( "otherwise `#[allow_internal_unstable]` can be used to bypass stability checks" )
36+ . note ( "otherwise `#[allow_internal_unstable]` can be used to bypass stability checks" )
3437 . emit ( ) ;
3538 }
3639
37- return ;
40+ return unstable_in_stable ;
3841 }
3942
4043 Status :: Unstable ( gate) => Some ( gate) ,
@@ -43,10 +46,11 @@ pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) {
4346
4447 if ccx. tcx . sess . opts . debugging_opts . unleash_the_miri_inside_of_you {
4548 ccx. tcx . sess . miri_unleashed_feature ( span, gate) ;
46- return ;
49+ return false ;
4750 }
4851
4952 op. emit_error ( ccx, span) ;
53+ true
5054}
5155
5256#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
0 commit comments