Skip to content
Open
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
37 changes: 34 additions & 3 deletions compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ where
delegate.create_next_universe();
}

compute_query_response_instantiation_values_in_universe(
delegate,
original_values,
response,
span,
prev_universe,
)
}

fn compute_query_response_instantiation_values_in_universe<D, I, T>(
delegate: &D,
original_values: &[I::GenericArg],
response: &Canonical<I, T>,
span: I::Span,
prev_universe: ty::UniverseIndex,
) -> CanonicalVarValues<I>
where
D: SolverDelegate<Interner = I>,
I: Interner,
T: ResponseT<I>,
{
let var_values = response.value.var_values();
assert_eq!(original_values.len(), var_values.len());

Expand Down Expand Up @@ -343,6 +364,7 @@ pub fn instantiate_canonical_state<D, I, T>(
delegate: &D,
span: I::Span,
param_env: I::ParamEnv,
prev_universe: ty::UniverseIndex,
orig_values: &mut Vec<I::GenericArg>,
state: inspect::CanonicalState<I, T>,
) -> T
Expand All @@ -353,14 +375,23 @@ where
{
// In case any fresh inference variables have been created between `state`
// and the previous instantiation, extend `orig_values` for it.
let max_universe = prev_universe + state.max_universe.index();
while delegate.universe() < max_universe {
delegate.create_next_universe();
}
orig_values.extend(
state.value.var_values.var_values.as_slice()[orig_values.len()..]
.iter()
.map(|&arg| delegate.fresh_var_for_kind_with_span(arg, span)),
.map(|&arg| delegate.fresh_var_for_kind(arg, span, max_universe)),
);

let instantiation =
compute_query_response_instantiation_values(delegate, orig_values, &state, span);
let instantiation = compute_query_response_instantiation_values_in_universe(
delegate,
orig_values,
&state,
span,
prev_universe,
);

let inspect::State { var_values, data } = delegate.instantiate_canonical(state, instantiation);

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_next_trait_solver/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
span: <Self::Interner as Interner>::Span,
) -> Option<Certainty>;

fn fresh_var_for_kind_with_span(
fn fresh_var_for_kind(
&self,
arg: <Self::Interner as Interner>::GenericArg,
span: <Self::Interner as Interner>::Span,
universe: ty::UniverseIndex,
) -> <Self::Interner as Interner>::GenericArg;

// FIXME: Uplift the leak check into this crate.
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_trait_selection/src/solve/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
}
}

fn fresh_var_for_kind_with_span(
fn fresh_var_for_kind(
&self,
arg: ty::GenericArg<'tcx>,
span: Span,
universe: ty::UniverseIndex,
) -> ty::GenericArg<'tcx> {
match arg.kind() {
ty::GenericArgKind::Lifetime(_) => {
self.next_region_var(RegionVariableOrigin::Misc(span)).into()
self.next_region_var_in_universe(RegionVariableOrigin::Misc(span), universe).into()
}
ty::GenericArgKind::Type(_) => self.next_ty_var(span).into(),
ty::GenericArgKind::Const(_) => self.next_const_var(span).into(),
ty::GenericArgKind::Type(_) => self.next_ty_var_in_universe(span, universe).into(),
ty::GenericArgKind::Const(_) => self.next_const_var_in_universe(span, universe).into(),
}
}

Expand Down
24 changes: 21 additions & 3 deletions compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct InspectGoal<'a, 'tcx> {
infcx: &'a SolverDelegate<'tcx>,
depth: usize,
orig_values: Vec<ty::GenericArg<'tcx>>,
prev_universe: ty::UniverseIndex,
goal: Goal<'tcx, ty::Predicate<'tcx>>,
result: Result<Certainty, NoSolution>,
final_revision: &'tcx inspect::Probe<TyCtxt<'tcx>>,
Expand Down Expand Up @@ -102,16 +103,29 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
match **step {
inspect::ProbeStep::AddGoal(source, goal) => instantiated_goals.push((
source,
instantiate_canonical_state(infcx, span, param_env, &mut orig_values, goal),
instantiate_canonical_state(
infcx,
span,
param_env,
self.goal.prev_universe,
&mut orig_values,
goal,
),
)),
inspect::ProbeStep::RecordImplArgs { .. } => {}
inspect::ProbeStep::MakeCanonicalResponse { .. }
| inspect::ProbeStep::NestedProbe(_) => unreachable!(),
}
}

let () =
instantiate_canonical_state(infcx, span, param_env, &mut orig_values, self.final_state);
let () = instantiate_canonical_state(
infcx,
span,
param_env,
self.goal.prev_universe,
&mut orig_values,
self.final_state,
);

instantiated_goals
.into_iter()
Expand Down Expand Up @@ -139,6 +153,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
infcx,
span,
param_env,
self.goal.prev_universe,
&mut orig_values,
impl_args,
);
Expand All @@ -147,6 +162,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
infcx,
span,
param_env,
self.goal.prev_universe,
&mut orig_values,
self.final_state,
);
Expand Down Expand Up @@ -320,6 +336,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
source: GoalSource,
) -> Self {
let infcx = <&SolverDelegate<'tcx>>::from(infcx);
let prev_universe = infcx.universe();

let inspect::GoalEvaluation { uncanonicalized_goal, orig_values, final_revision, result } =
root;
Expand All @@ -331,6 +348,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
infcx,
depth,
orig_values,
prev_universe,
goal: eager_resolve_vars(&**infcx, uncanonicalized_goal),
result,
final_revision,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ compile-flags: -Znext-solver=globally

#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

fn auto_trait()
where
for<T> T: PartialEq + PartialOrd,
{}

fn main() {
auto_trait();
//~^ ERROR can't compare `T` with `T`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: can't compare `T` with `T`
--> $DIR/foreach-partial-eq-next-solver.rs:12:5
|
LL | auto_trait();
| ^^^^^^^^^^^^ no implementation for `T < T` and `T > T`
|
= help: the trait `PartialOrd` is not implemented for `T`
note: required by a bound in `auto_trait`
--> $DIR/foreach-partial-eq-next-solver.rs:8:27
|
LL | fn auto_trait()
| ---------- required by a bound in this function
LL | where
LL | for<T> T: PartialEq + PartialOrd,
| ^^^^^^^^^^ required by this bound in `auto_trait`

error: aborting due to 1 previous error

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