Skip to content

Commit b5f680e

Browse files
committed
do not resolve instances for trait fn ids
1 parent dbb0fe9 commit b5f680e

File tree

1 file changed

+19
-17
lines changed
  • compiler/rustc_mir/src/transform/check_consts

1 file changed

+19
-17
lines changed

compiler/rustc_mir/src/transform/check_consts/check.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
99
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::cast::CastTy;
12-
use rustc_middle::ty::subst::GenericArgKind;
12+
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1313
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
1414
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef};
1515
use rustc_span::{sym, Span, Symbol};
@@ -793,7 +793,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
793793

794794
let fn_ty = func.ty(body, tcx);
795795

796-
let (mut callee, substs) = match *fn_ty.kind() {
796+
let (mut callee, mut substs) = match *fn_ty.kind() {
797797
ty::FnDef(def_id, substs) => (def_id, substs),
798798

799799
ty::FnPtr(_) => {
@@ -846,29 +846,31 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
846846
.iter()
847847
.find(|did| tcx.item_name(**did) == callee_name)
848848
{
849+
// using internal substs is ok here, since this is only
850+
// used for the `resolve` call below
851+
substs = InternalSubsts::identity_for_item(tcx, did);
849852
callee = did;
850853
}
851854
}
852-
_ => {
853-
if !tcx.is_const_fn_raw(callee) {
854-
// At this point, it is only legal when the caller is marked with
855-
// #[default_method_body_is_const], and the callee is in the same
856-
// trait.
857-
let callee_trait = tcx.trait_of_item(callee);
858-
if callee_trait.is_some() {
859-
if tcx.has_attr(caller, sym::default_method_body_is_const) {
860-
if tcx.trait_of_item(caller) == callee_trait {
861-
nonconst_call_permission = true;
862-
}
855+
_ if !tcx.is_const_fn_raw(callee) => {
856+
// At this point, it is only legal when the caller is marked with
857+
// #[default_method_body_is_const], and the callee is in the same
858+
// trait.
859+
let callee_trait = tcx.trait_of_item(callee);
860+
if callee_trait.is_some() {
861+
if tcx.has_attr(caller, sym::default_method_body_is_const) {
862+
if tcx.trait_of_item(caller) == callee_trait {
863+
nonconst_call_permission = true;
863864
}
864865
}
866+
}
865867

866-
if !nonconst_call_permission {
867-
self.check_op(ops::FnCallNonConst);
868-
return;
869-
}
868+
if !nonconst_call_permission {
869+
self.check_op(ops::FnCallNonConst);
870+
return;
870871
}
871872
}
873+
_ => {}
872874
}
873875

874876
// Resolve a trait method call to its concrete implementation, which may be in a

0 commit comments

Comments
 (0)