@@ -4,7 +4,7 @@ use rustc::middle::lang_items;
44use rustc:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
55use rustc:: mir:: * ;
66use rustc:: ty:: cast:: CastTy ;
7- use rustc:: ty:: { self , TyCtxt } ;
7+ use rustc:: ty:: { self , Instance , InstanceDef , TyCtxt } ;
88use rustc_errors:: struct_span_err;
99use rustc_hir:: { def_id:: DefId , HirId } ;
1010use rustc_index:: bit_set:: BitSet ;
@@ -501,8 +501,8 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
501501 TerminatorKind :: Call { func, .. } => {
502502 let fn_ty = func. ty ( * self . body , self . tcx ) ;
503503
504- let def_id = match fn_ty. kind {
505- ty:: FnDef ( def_id, _ ) => def_id,
504+ let ( def_id, substs ) = match fn_ty. kind {
505+ ty:: FnDef ( def_id, substs ) => ( def_id, substs ) ,
506506
507507 ty:: FnPtr ( _) => {
508508 self . check_op ( ops:: FnCallIndirect ) ;
@@ -519,6 +519,20 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
519519 return ;
520520 }
521521
522+ // See if this is a trait method for a concrete type whose impl of that trait is
523+ // `const`.
524+ if self . tcx . features ( ) . const_trait_impl {
525+ let instance = Instance :: resolve ( self . tcx , self . param_env , def_id, substs) ;
526+ debug ! ( "Resolving ({:?}) -> {:?}" , def_id, instance) ;
527+ if let Some ( func) = instance {
528+ if let InstanceDef :: Item ( def_id) = func. def {
529+ if is_const_fn ( self . tcx , def_id) {
530+ return ;
531+ }
532+ }
533+ }
534+ }
535+
522536 if is_lang_panic_fn ( self . tcx , def_id) {
523537 self . check_op ( ops:: Panic ) ;
524538 } else if let Some ( feature) = is_unstable_const_fn ( self . tcx , def_id) {
0 commit comments