Skip to content

Commit 76372ad

Browse files
committed
fix(ty_utils): higher normalize erasing regions call
1 parent 6e96802 commit 76372ad

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

compiler/rustc_lint/src/internal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
9090
impl LateLintPass<'_> for QueryStability {
9191
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
9292
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
93+
let substs = cx.tcx.normalize_erasing_regions(cx.param_env, substs);
9394
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) {
9495
let def_id = instance.def_id();
9596
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
@@ -380,6 +381,7 @@ declare_lint_pass!(Diagnostics => [ UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSID
380381
impl LateLintPass<'_> for Diagnostics {
381382
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
382383
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
384+
let substs = cx.tcx.normalize_erasing_regions(cx.param_env, substs);
383385
debug!(?span, ?def_id, ?substs);
384386
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
385387
.ok()

compiler/rustc_middle/src/mir/interpret/queries.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ impl<'tcx> TyCtxt<'tcx> {
8282
bug!("did not expect inference variables here");
8383
}
8484

85-
match ty::Instance::resolve(self, param_env, ct.def, ct.substs) {
85+
let substs = match self.try_normalize_erasing_regions(param_env, ct.substs) {
86+
Ok(substs) => substs,
87+
Err(_) => return Err(ErrorHandled::TooGeneric),
88+
};
89+
90+
match ty::Instance::resolve(self, param_env, ct.def, substs) {
8691
Ok(Some(instance)) => {
8792
let cid = GlobalId { instance, promoted: None };
8893
self.const_eval_global_id_for_typeck(param_env, cid, span).inspect(|_| {

compiler/rustc_ty_utils/src/instance.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ fn resolve_instance<'tcx>(
1818

1919
let result = if let Some(trait_def_id) = tcx.trait_of_item(def) {
2020
debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env);
21-
resolve_associated_item(
22-
tcx,
23-
def,
24-
param_env,
25-
trait_def_id,
26-
tcx.normalize_erasing_regions(param_env, substs),
27-
)
21+
resolve_associated_item(tcx, def, param_env, trait_def_id, substs)
2822
} else {
2923
let ty = tcx.type_of(def);
3024
let item_type =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_const_exprs)]
3+
4+
trait Indices<const N:usize> {
5+
const NUM_ELEMS: usize = 0;
6+
}
7+
8+
trait Concat {
9+
type Output;
10+
}
11+
12+
struct Tensor<A: Indices<42>>(A)
13+
where
14+
[(); A::NUM_ELEMS]: Sized;
15+
16+
impl<I: Indices<42>> Concat for Tensor<I>
17+
where
18+
[(); I::NUM_ELEMS]: Sized
19+
{
20+
type Output = Tensor<<I as Concat>::Output>;
21+
//~^ ERROR the trait bound `I: Concat` is not satisfied
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `I: Concat` is not satisfied
2+
--> $DIR/issue-110630.rs:20:26
3+
|
4+
LL | type Output = Tensor<<I as Concat>::Output>;
5+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Concat` is not implemented for `I`
6+
|
7+
help: consider further restricting this bound
8+
|
9+
LL | impl<I: Indices<42> + Concat> Concat for Tensor<I>
10+
| ++++++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)