@@ -812,7 +812,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
812
812
813
813
let fn_ty = func. ty ( self . mir , self . tcx ) ;
814
814
let mut callee_def_id = None ;
815
- let ( mut is_shuffle, mut is_const_fn) = ( false , false ) ;
815
+ let mut is_shuffle = false ;
816
+ let mut is_const_fn = false ;
817
+ let mut is_promotable_const_fn = false ;
816
818
if let ty:: FnDef ( def_id, _) = fn_ty. sty {
817
819
callee_def_id = Some ( def_id) ;
818
820
match self . tcx . fn_sig ( def_id) . abi ( ) {
@@ -873,6 +875,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
873
875
// functions without #[rustc_promotable]
874
876
if self . tcx . is_promotable_const_fn ( def_id) {
875
877
is_const_fn = true ;
878
+ is_promotable_const_fn = true ;
879
+ } else if self . tcx . is_const_fn ( def_id) {
880
+ is_const_fn = true ;
876
881
}
877
882
} else {
878
883
// stable const fn or unstable const fns with their feature gate
@@ -974,7 +979,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
974
979
if !constant_arguments. contains ( & i) {
975
980
return
976
981
}
977
- if this. qualif . is_empty ( ) {
982
+ // if the argument requires a constant, we care about constness, not
983
+ // promotability
984
+ if ( this. qualif - Qualif :: NOT_PROMOTABLE ) . is_empty ( ) {
978
985
this. promotion_candidates . push ( candidate) ;
979
986
} else {
980
987
this. tcx . sess . span_err ( this. span ,
@@ -985,7 +992,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
985
992
}
986
993
987
994
// non-const fn calls.
988
- if !is_const_fn {
995
+ if is_const_fn {
996
+ if !is_promotable_const_fn && self . mode == Mode :: Fn {
997
+ self . qualif = Qualif :: NOT_PROMOTABLE ;
998
+ }
999
+ } else {
989
1000
self . qualif = Qualif :: NOT_CONST ;
990
1001
if self . mode != Mode :: Fn {
991
1002
self . tcx . sess . delay_span_bug (
@@ -1003,7 +1014,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
1003
1014
// Be conservative about the returned value of a const fn.
1004
1015
let tcx = self . tcx ;
1005
1016
let ty = dest. ty ( self . mir , tcx) . to_ty ( tcx) ;
1006
- self . qualif = Qualif :: empty ( ) ;
1007
1017
self . add_type ( ty) ;
1008
1018
}
1009
1019
self . assign ( dest, location) ;
0 commit comments