@@ -4,7 +4,7 @@ use rustc::middle::lang_items;
4
4
use rustc:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
5
5
use rustc:: mir:: * ;
6
6
use rustc:: ty:: cast:: CastTy ;
7
- use rustc:: ty:: { self , TyCtxt } ;
7
+ use rustc:: ty:: { self , Instance , InstanceDef , TyCtxt } ;
8
8
use rustc_errors:: struct_span_err;
9
9
use rustc_hir:: { def_id:: DefId , HirId } ;
10
10
use rustc_index:: bit_set:: BitSet ;
@@ -501,8 +501,8 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
501
501
TerminatorKind :: Call { func, .. } => {
502
502
let fn_ty = func. ty ( * self . body , self . tcx ) ;
503
503
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 ) ,
506
506
507
507
ty:: FnPtr ( _) => {
508
508
self . check_op ( ops:: FnCallIndirect ) ;
@@ -519,6 +519,20 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
519
519
return ;
520
520
}
521
521
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
+
522
536
if is_lang_panic_fn ( self . tcx , def_id) {
523
537
self . check_op ( ops:: Panic ) ;
524
538
} else if let Some ( feature) = is_unstable_const_fn ( self . tcx , def_id) {
0 commit comments