@@ -29,13 +29,14 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
2929 let def_id = body. source . def_id ( ) ;
3030
3131 for local in & body. local_decls {
32- check_ty ( tcx, local. ty , local. source_info . span ) ?;
32+ check_ty ( tcx, local. ty , local. source_info . span , msrv ) ?;
3333 }
3434 // impl trait is gone in MIR, so check the return type manually
3535 check_ty (
3636 tcx,
3737 tcx. fn_sig ( def_id) . instantiate_identity ( ) . output ( ) . skip_binder ( ) ,
3838 body. local_decls . iter ( ) . next ( ) . unwrap ( ) . source_info . span ,
39+ msrv,
3940 ) ?;
4041
4142 for bb in & * body. basic_blocks {
@@ -51,7 +52,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
5152 Ok ( ( ) )
5253}
5354
54- fn check_ty < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , span : Span ) -> McfResult {
55+ fn check_ty < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > , span : Span , msrv : & Msrv ) -> McfResult {
5556 for arg in ty. walk ( ) {
5657 let ty = match arg. unpack ( ) {
5758 GenericArgKind :: Type ( ty) => ty,
@@ -62,7 +63,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
6263 } ;
6364
6465 match ty. kind ( ) {
65- ty:: Ref ( _, _, hir:: Mutability :: Mut ) => {
66+ ty:: Ref ( _, _, hir:: Mutability :: Mut ) if !msrv . meets ( msrvs :: CONST_MUT_REFS ) => {
6667 return Err ( ( span, "mutable references in const fn are unstable" . into ( ) ) ) ;
6768 } ,
6869 ty:: Alias ( ty:: Opaque , ..) => return Err ( ( span, "`impl Trait` in const fn is unstable" . into ( ) ) ) ,
0 commit comments