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

Dedup elaborated predicates with const generic parameter in AutoTrait #108397

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
18 changes: 15 additions & 3 deletions compiler/rustc_trait_selection/src/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::errors::UnableToConstructConstantValue;
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
use crate::infer::InferCtxt;
use crate::traits::project::ProjectAndUnifyResult;
use rustc_infer::traits::util::PredicateSet;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::visit::TypeVisitableExt;
Expand Down Expand Up @@ -344,13 +345,24 @@ impl<'tcx> AutoTraitFinder<'tcx> {
_ => panic!("Unexpected error for '{:?}': {:?}", ty, result),
};

let normalized_preds = elaborate_predicates(
let elaborated_preds = elaborate_predicates(
tcx,
computed_preds.clone().chain(user_computed_preds.iter().cloned()),
)
.map(|o| o.predicate);
.map(|obligation| obligation.predicate);

// FIXME(generic_const_exprs):
// This deduplication is required only when generic_const_exprs is not active
// see #108397 for more information.
let mut seen_preds = PredicateSet::new(tcx);
let obctx = ObligationCtxt::new(infcx);
let deduped_preds = elaborated_preds
.into_iter()
.map(|pred| obctx.normalize(&dummy_cause, param_env, pred))
.filter(|normalized_pred| seen_preds.insert(*normalized_pred));

new_env = ty::ParamEnv::new(
tcx.mk_predicates_from_iter(normalized_preds),
tcx.mk_predicates_from_iter(deduped_preds),
param_env.reveal(),
param_env.constness(),
);
Expand Down
18 changes: 18 additions & 0 deletions tests/rustdoc-ui/issue_107715.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// check-pass
#![crate_type = "lib"]

const N: usize = 1;

trait Supertrait<V> {
type AssociatedType;
}

trait Subtrait: Supertrait<[u8; N]> {}

struct MapType<K: Supertrait<V>, V> {
map: K::AssociatedType,
}

struct Container<S: Subtrait> {
_x: MapType<S, [u8; N]>,
}