diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 595b50c4063ca..6641da6ea71be 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -90,6 +90,7 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]); impl LateLintPass<'_> for QueryStability { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return }; + let substs = cx.tcx.normalize_erasing_regions(cx.param_env, substs); if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) { let def_id = instance.def_id(); if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) { @@ -380,6 +381,7 @@ declare_lint_pass!(Diagnostics => [ UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSID impl LateLintPass<'_> for Diagnostics { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return }; + let substs = cx.tcx.normalize_erasing_regions(cx.param_env, substs); debug!(?span, ?def_id, ?substs); let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) .ok() diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index ed4ee93e97d50..285a97ca380f7 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -82,7 +82,12 @@ impl<'tcx> TyCtxt<'tcx> { bug!("did not expect inference variables here"); } - match ty::Instance::resolve(self, param_env, ct.def, ct.substs) { + let substs = match self.try_normalize_erasing_regions(param_env, ct.substs) { + Ok(substs) => substs, + Err(_) => return Err(ErrorHandled::TooGeneric), + }; + + match ty::Instance::resolve(self, param_env, ct.def, substs) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted: None }; self.const_eval_global_id_for_typeck(param_env, cid, span).inspect(|_| { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index eedf459ce8fbc..7ea6344e3894f 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -18,13 +18,7 @@ fn resolve_instance<'tcx>( let result = if let Some(trait_def_id) = tcx.trait_of_item(def) { debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env); - resolve_associated_item( - tcx, - def, - param_env, - trait_def_id, - tcx.normalize_erasing_regions(param_env, substs), - ) + resolve_associated_item(tcx, def, param_env, trait_def_id, substs) } else { let ty = tcx.type_of(def); let item_type = diff --git a/tests/ui/const-generics/issues/issue-110630.rs b/tests/ui/const-generics/issues/issue-110630.rs new file mode 100644 index 0000000000000..84af41d1c1a83 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-110630.rs @@ -0,0 +1,24 @@ +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +trait Indices { + const NUM_ELEMS: usize = 0; +} + +trait Concat { + type Output; +} + +struct Tensor>(A) +where + [(); A::NUM_ELEMS]: Sized; + +impl> Concat for Tensor +where + [(); I::NUM_ELEMS]: Sized +{ + type Output = Tensor<::Output>; + //~^ ERROR the trait bound `I: Concat` is not satisfied +} + +fn main() {} diff --git a/tests/ui/const-generics/issues/issue-110630.stderr b/tests/ui/const-generics/issues/issue-110630.stderr new file mode 100644 index 0000000000000..0e18a338a5c13 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-110630.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `I: Concat` is not satisfied + --> $DIR/issue-110630.rs:20:26 + | +LL | type Output = Tensor<::Output>; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Concat` is not implemented for `I` + | +help: consider further restricting this bound + | +LL | impl + Concat> Concat for Tensor + | ++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.