Skip to content

Commit c082e15

Browse files
authored
Rollup merge of #88592 - b-naber:region_substs, r=oli-obk
Fix ICE in const check Fixes #88433
2 parents 8f88d44 + f825d6c commit c082e15

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// build-pass
2+
3+
#![feature(const_trait_impl)]
4+
5+
trait Func<T> {
6+
type Output;
7+
8+
fn call_once(self, arg: T) -> Self::Output;
9+
}
10+
11+
12+
struct Closure;
13+
14+
impl const Func<&usize> for Closure {
15+
type Output = usize;
16+
17+
fn call_once(self, arg: &usize) -> Self::Output {
18+
*arg
19+
}
20+
}
21+
22+
enum Bug<T = [(); Closure.call_once(&0) ]> {
23+
V(T),
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)