@@ -28,6 +28,9 @@ pub enum Status {
2828 Unstable {
2929 /// The feature that must be enabled to use this operation.
3030 gate : Symbol ,
31+ /// Whether the feature gate was already checked (because the logic is a bit more
32+ /// complicated than just checking a single gate).
33+ gate_already_checked : bool ,
3134 /// Whether it is allowed to use this operation from stable `const fn`.
3235 /// This will usually be `false`.
3336 safe_to_expose_on_stable : bool ,
@@ -82,6 +85,7 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> {
8285 // We use the `const_trait_impl` gate for all conditionally-const calls.
8386 Status :: Unstable {
8487 gate : sym:: const_trait_impl,
88+ gate_already_checked : false ,
8589 safe_to_expose_on_stable : false ,
8690 // We don't want the "mark the callee as `#[rustc_const_stable_indirect]`" hint
8791 is_function_call : false ,
@@ -330,19 +334,24 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
330334pub ( crate ) struct FnCallUnstable {
331335 pub def_id : DefId ,
332336 pub feature : Symbol ,
337+ /// If this is true, then the feature is enabled, but we need to still check if it is safe to
338+ /// expose on stable.
339+ pub feature_enabled : bool ,
333340 pub safe_to_expose_on_stable : bool ,
334341}
335342
336343impl < ' tcx > NonConstOp < ' tcx > for FnCallUnstable {
337344 fn status_in_item ( & self , _ccx : & ConstCx < ' _ , ' tcx > ) -> Status {
338345 Status :: Unstable {
339346 gate : self . feature ,
347+ gate_already_checked : self . feature_enabled ,
340348 safe_to_expose_on_stable : self . safe_to_expose_on_stable ,
341349 is_function_call : true ,
342350 }
343351 }
344352
345353 fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> Diag < ' tcx > {
354+ assert ! ( !self . feature_enabled) ;
346355 let mut err = ccx. dcx ( ) . create_err ( errors:: UnstableConstFn {
347356 span,
348357 def_path : ccx. tcx . def_path_str ( self . def_id ) ,
@@ -376,14 +385,15 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicNonConst {
376385pub ( crate ) struct IntrinsicUnstable {
377386 pub name : Symbol ,
378387 pub feature : Symbol ,
379- pub const_stable : bool ,
388+ pub const_stable_indirect : bool ,
380389}
381390
382391impl < ' tcx > NonConstOp < ' tcx > for IntrinsicUnstable {
383392 fn status_in_item ( & self , _ccx : & ConstCx < ' _ , ' tcx > ) -> Status {
384393 Status :: Unstable {
385394 gate : self . feature ,
386- safe_to_expose_on_stable : self . const_stable ,
395+ gate_already_checked : false ,
396+ safe_to_expose_on_stable : self . const_stable_indirect ,
387397 // We do *not* want to suggest to mark the intrinsic as `const_stable_indirect`,
388398 // that's not a trivial change!
389399 is_function_call : false ,
@@ -410,6 +420,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
410420 {
411421 Status :: Unstable {
412422 gate : sym:: const_async_blocks,
423+ gate_already_checked : false ,
413424 safe_to_expose_on_stable : false ,
414425 is_function_call : false ,
415426 }
0 commit comments