@@ -10,31 +10,34 @@ use rustc_span::{Span, Symbol};
10
10
11
11
use super :: ConstCx ;
12
12
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 {
15
15
debug ! ( "illegal_op: op={:?}" , op) ;
16
16
17
17
let gate = match op. status_in_item ( ccx) {
18
- Status :: Allowed => return ,
18
+ Status :: Allowed => return false ,
19
19
20
20
Status :: Unstable ( gate) if ccx. tcx . features ( ) . enabled ( gate) => {
21
21
let unstable_in_stable = ccx. is_const_stable_const_fn ( )
22
22
&& !super :: allow_internal_unstable ( ccx. tcx , ccx. def_id . to_def_id ( ) , gate) ;
23
23
24
24
if unstable_in_stable {
25
25
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
+ )
27
30
. span_suggestion (
28
31
ccx. body . span ,
29
32
"if it is not part of the public API, make this function unstably const" ,
30
33
concat ! ( r#"#[rustc_const_unstable(feature = "...", issue = "...")]"# , '\n' ) . to_owned ( ) ,
31
34
Applicability :: HasPlaceholders ,
32
35
)
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" )
34
37
. emit ( ) ;
35
38
}
36
39
37
- return ;
40
+ return unstable_in_stable ;
38
41
}
39
42
40
43
Status :: Unstable ( gate) => Some ( gate) ,
@@ -43,10 +46,11 @@ pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) {
43
46
44
47
if ccx. tcx . sess . opts . debugging_opts . unleash_the_miri_inside_of_you {
45
48
ccx. tcx . sess . miri_unleashed_feature ( span, gate) ;
46
- return ;
49
+ return false ;
47
50
}
48
51
49
52
op. emit_error ( ccx, span) ;
53
+ true
50
54
}
51
55
52
56
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
0 commit comments