Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ty_utils): try normalize earsing regions #111259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for #105561

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) {
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for #105561

debug!(?span, ?def_id, ?substs);
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
.ok()
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/const-generics/issues/issue-110630.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

trait Indices<const N:usize> {
const NUM_ELEMS: usize = 0;
}

trait Concat {
type Output;
}

struct Tensor<A: Indices<42>>(A)
where
[(); A::NUM_ELEMS]: Sized;

impl<I: Indices<42>> Concat for Tensor<I>
where
[(); I::NUM_ELEMS]: Sized
{
type Output = Tensor<<I as Concat>::Output>;
//~^ ERROR the trait bound `I: Concat` is not satisfied
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/const-generics/issues/issue-110630.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0277]: the trait bound `I: Concat` is not satisfied
--> $DIR/issue-110630.rs:20:26
|
LL | type Output = Tensor<<I as Concat>::Output>;
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Concat` is not implemented for `I`
|
help: consider further restricting this bound
|
LL | impl<I: Indices<42> + Concat> Concat for Tensor<I>
| ++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.