Skip to content

Commit 24e41f1

Browse files
Replace Deref bounds on Interner in favor of a SliceLike trait
1 parent f26cc34 commit 24e41f1

File tree

22 files changed

+221
-159
lines changed

22 files changed

+221
-159
lines changed

compiler/rustc_middle/src/ty/list.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ impl<H, T> RawList<H, T> {
133133
}
134134
}
135135

136+
impl<'a, H, T: Copy> rustc_type_ir::inherent::SliceLike for &'a RawList<H, T> {
137+
type Item = T;
138+
139+
type IntoIter = iter::Copied<<&'a [T] as IntoIterator>::IntoIter>;
140+
141+
fn iter(self) -> Self::IntoIter {
142+
(*self).iter()
143+
}
144+
145+
fn as_slice(&self) -> &[Self::Item] {
146+
(*self).as_slice()
147+
}
148+
}
149+
136150
macro_rules! impl_list_empty {
137151
($header_ty:ty, $header_init:expr) => {
138152
impl<T> RawList<$header_ty, T> {

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ where
527527
};
528528

529529
for assumption in
530-
self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), &alias_ty.args)
530+
self.cx().item_bounds(alias_ty.def_id).iter_instantiated(self.cx(), alias_ty.args)
531531
{
532532
candidates.extend(G::probe_and_consider_implied_clause(
533533
self,
@@ -603,7 +603,7 @@ where
603603
// Consider all of the auto-trait and projection bounds, which don't
604604
// need to be recorded as a `BuiltinImplSource::Object` since they don't
605605
// really have a vtable base...
606-
for bound in bounds {
606+
for bound in bounds.iter() {
607607
match bound.skip_binder() {
608608
ty::ExistentialPredicate::Trait(_) => {
609609
// Skip principal

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858

5959
ty::Tuple(tys) => {
6060
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
61-
Ok(tys.into_iter().map(ty::Binder::dummy).collect())
61+
Ok(tys.iter().map(ty::Binder::dummy).collect())
6262
}
6363

6464
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
@@ -79,23 +79,21 @@ where
7979
.cx()
8080
.bound_coroutine_hidden_types(def_id)
8181
.into_iter()
82-
.map(|bty| bty.instantiate(tcx, &args))
82+
.map(|bty| bty.instantiate(tcx, args))
8383
.collect()),
8484

8585
// For `PhantomData<T>`, we pass `T`.
8686
ty::Adt(def, args) if def.is_phantom_data() => Ok(vec![ty::Binder::dummy(args.type_at(0))]),
8787

88-
ty::Adt(def, args) => Ok(def
89-
.all_field_tys(tcx)
90-
.iter_instantiated(tcx, &args)
91-
.map(ty::Binder::dummy)
92-
.collect()),
88+
ty::Adt(def, args) => {
89+
Ok(def.all_field_tys(tcx).iter_instantiated(tcx, args).map(ty::Binder::dummy).collect())
90+
}
9391

9492
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
9593
// We can resolve the `impl Trait` to its concrete type,
9694
// which enforces a DAG between the functions requiring
9795
// the auto trait bounds in question.
98-
Ok(vec![ty::Binder::dummy(tcx.type_of(def_id).instantiate(tcx, &args))])
96+
Ok(vec![ty::Binder::dummy(tcx.type_of(def_id).instantiate(tcx, args))])
9997
}
10098
}
10199
}
@@ -147,7 +145,7 @@ where
147145

148146
// impl Sized for ()
149147
// impl Sized for (T1, T2, .., Tn) where Tn: Sized if n >= 1
150-
ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |&ty| vec![ty::Binder::dummy(ty)])),
148+
ty::Tuple(tys) => Ok(tys.last().map_or_else(Vec::new, |ty| vec![ty::Binder::dummy(ty)])),
151149

152150
// impl Sized for Adt<Args...> where sized_constraint(Adt)<Args...>: Sized
153151
// `sized_constraint(Adt)` is the deepest struct trail that can be determined
@@ -160,7 +158,7 @@ where
160158
// if the ADT is sized for all possible args.
161159
ty::Adt(def, args) => {
162160
if let Some(sized_crit) = def.sized_constraint(ecx.cx()) {
163-
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.cx(), &args))])
161+
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.cx(), args))])
164162
} else {
165163
Ok(vec![])
166164
}
@@ -213,7 +211,7 @@ where
213211
}
214212

215213
// impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
216-
ty::Tuple(tys) => Ok(tys.into_iter().map(ty::Binder::dummy).collect()),
214+
ty::Tuple(tys) => Ok(tys.iter().map(ty::Binder::dummy).collect()),
217215

218216
// impl Copy/Clone for Closure where Self::TupledUpvars: Copy/Clone
219217
ty::Closure(_, args) => Ok(vec![ty::Binder::dummy(args.as_closure().tupled_upvars_ty())]),
@@ -242,7 +240,7 @@ where
242240
.cx()
243241
.bound_coroutine_hidden_types(def_id)
244242
.into_iter()
245-
.map(|bty| bty.instantiate(ecx.cx(), &args))
243+
.map(|bty| bty.instantiate(ecx.cx(), args))
246244
.collect()),
247245
}
248246
}
@@ -259,7 +257,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
259257
let sig = tcx.fn_sig(def_id);
260258
if sig.skip_binder().is_fn_trait_compatible() && !tcx.has_target_features(def_id) {
261259
Ok(Some(
262-
sig.instantiate(tcx, &args)
260+
sig.instantiate(tcx, args)
263261
.map_bound(|sig| (Ty::new_tup(tcx, &sig.inputs()), sig.output())),
264262
))
265263
} else {
@@ -669,7 +667,7 @@ where
669667
let tcx = ecx.cx();
670668
let mut requirements = vec![];
671669
requirements
672-
.extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, &trait_ref.args));
670+
.extend(tcx.super_predicates_of(trait_ref.def_id).iter_instantiated(tcx, trait_ref.args));
673671

674672
// FIXME(associated_const_equality): Also add associated consts to
675673
// the requirements here.
@@ -680,13 +678,12 @@ where
680678
continue;
681679
}
682680

683-
requirements.extend(
684-
tcx.item_bounds(associated_type_def_id).iter_instantiated(tcx, &trait_ref.args),
685-
);
681+
requirements
682+
.extend(tcx.item_bounds(associated_type_def_id).iter_instantiated(tcx, trait_ref.args));
686683
}
687684

688685
let mut replace_projection_with = HashMap::default();
689-
for bound in object_bounds {
686+
for bound in object_bounds.iter() {
690687
if let ty::ExistentialPredicate::Projection(proj) = bound.skip_binder() {
691688
let proj = proj.with_self_ty(tcx, trait_ref.self_ty());
692689
let old_ty = replace_projection_with.insert(proj.def_id(), bound.rebind(proj));

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ where
267267
// We therefore instantiate the existential variable in the canonical response with the
268268
// inference variable of the input right away, which is more performant.
269269
let mut opt_values = IndexVec::from_elem_n(None, response.variables.len());
270-
for (original_value, result_value) in iter::zip(original_values, var_values.var_values) {
270+
for (original_value, result_value) in
271+
iter::zip(original_values, var_values.var_values.iter())
272+
{
271273
match result_value.kind() {
272274
ty::GenericArgKind::Type(t) => {
273275
if let ty::Bound(debruijn, b) = t.kind() {
@@ -291,7 +293,7 @@ where
291293
}
292294

293295
let var_values = delegate.cx().mk_args_from_iter(
294-
response.variables.into_iter().enumerate().map(|(index, info)| {
296+
response.variables.iter().enumerate().map(|(index, info)| {
295297
if info.universe() != ty::UniverseIndex::ROOT {
296298
// A variable from inside a binder of the query. While ideally these shouldn't
297299
// exist at all (see the FIXME at the start of this method), we have to deal with
@@ -344,7 +346,7 @@ where
344346
) {
345347
assert_eq!(original_values.len(), var_values.len());
346348

347-
for (&orig, response) in iter::zip(original_values, var_values.var_values) {
349+
for (&orig, response) in iter::zip(original_values, var_values.var_values.iter()) {
348350
let goals =
349351
delegate.eq_structurally_relating_aliases(param_env, orig, response).unwrap();
350352
assert!(goals.is_empty());
@@ -413,7 +415,8 @@ where
413415
// In case any fresh inference variables have been created between `state`
414416
// and the previous instantiation, extend `orig_values` for it.
415417
assert!(orig_values.len() <= state.value.var_values.len());
416-
for &arg in &state.value.var_values.var_values[orig_values.len()..state.value.var_values.len()]
418+
for &arg in &state.value.var_values.var_values.as_slice()
419+
[orig_values.len()..state.value.var_values.len()]
417420
{
418421
// FIXME: This is so ugly.
419422
let unconstrained = delegate.fresh_var_for_kind_with_span(arg, span);

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ where
875875

876876
pub(super) fn fresh_args_for_item(&mut self, def_id: I::DefId) -> I::GenericArgs {
877877
let args = self.delegate.fresh_args_for_item(def_id);
878-
for arg in args {
878+
for arg in args.iter() {
879879
self.inspect.add_var_value(arg);
880880
}
881881
args
@@ -979,7 +979,7 @@ where
979979
result: *result,
980980
})
981981
.enter(|ecx| {
982-
for (a, b) in std::iter::zip(candidate_key.args, key.args) {
982+
for (a, b) in std::iter::zip(candidate_key.args.iter(), key.args.iter()) {
983983
ecx.eq(param_env, a, b)?;
984984
}
985985
ecx.eq(param_env, candidate_ty, ty)?;

compiler/rustc_next_trait_solver/src/solve/inspect/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::marker::PhantomData;
88
use std::mem;
99

10+
use rustc_type_ir::inherent::*;
1011
use rustc_type_ir::{self as ty, Interner};
1112

1213
use crate::delegate::SolverDelegate;

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ where
182182
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
183183
}
184184
ty::ConstKind::Unevaluated(uv) => {
185-
self.cx().type_of(uv.def).instantiate(self.cx(), &uv.args)
185+
self.cx().type_of(uv.def).instantiate(self.cx(), uv.args)
186186
}
187187
ty::ConstKind::Expr(_) => unimplemented!(
188188
"`feature(generic_const_exprs)` is not supported in the new trait solver"

compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where
2929
self.eq(
3030
goal.param_env,
3131
inherent.self_ty(),
32-
tcx.type_of(impl_def_id).instantiate(tcx, &impl_args),
32+
tcx.type_of(impl_def_id).instantiate(tcx, impl_args),
3333
)?;
3434

3535
// Equate IAT with the RHS of the project goal
@@ -44,11 +44,11 @@ where
4444
self.add_goals(
4545
GoalSource::Misc,
4646
tcx.predicates_of(inherent.def_id)
47-
.iter_instantiated(tcx, &inherent_args)
47+
.iter_instantiated(tcx, inherent_args)
4848
.map(|pred| goal.with(tcx, pred)),
4949
);
5050

51-
let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, &inherent_args);
51+
let normalized = tcx.type_of(inherent.def_id).instantiate(tcx, inherent_args);
5252
self.instantiate_normalizes_to_term(goal, normalized.into());
5353
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
5454
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ where
121121
ecx.add_goals(
122122
GoalSource::Misc,
123123
tcx.own_predicates_of(goal.predicate.def_id())
124-
.iter_instantiated(tcx, &goal.predicate.alias.args)
124+
.iter_instantiated(tcx, goal.predicate.alias.args)
125125
.map(|pred| goal.with(tcx, pred)),
126126
);
127127

@@ -163,21 +163,21 @@ where
163163

164164
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
165165
let impl_args = ecx.fresh_args_for_item(impl_def_id);
166-
let impl_trait_ref = impl_trait_ref.instantiate(tcx, &impl_args);
166+
let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
167167

168168
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
169169

170170
let where_clause_bounds = tcx
171171
.predicates_of(impl_def_id)
172-
.iter_instantiated(tcx, &impl_args)
172+
.iter_instantiated(tcx, impl_args)
173173
.map(|pred| goal.with(tcx, pred));
174174
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
175175

176176
// Add GAT where clauses from the trait's definition
177177
ecx.add_goals(
178178
GoalSource::Misc,
179179
tcx.own_predicates_of(goal.predicate.def_id())
180-
.iter_instantiated(tcx, &goal.predicate.alias.args)
180+
.iter_instantiated(tcx, goal.predicate.alias.args)
181181
.map(|pred| goal.with(tcx, pred)),
182182
);
183183

@@ -254,7 +254,7 @@ where
254254
kind => panic!("expected projection, found {kind:?}"),
255255
};
256256

257-
ecx.instantiate_normalizes_to_term(goal, term.instantiate(tcx, &target_args));
257+
ecx.instantiate_normalizes_to_term(goal, term.instantiate(tcx, target_args));
258258
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
259259
})
260260
}
@@ -467,7 +467,7 @@ where
467467
tupled_inputs_ty,
468468
tupled_upvars_ty,
469469
coroutine_captures_by_ref_ty,
470-
] = **goal.predicate.alias.args
470+
] = *goal.predicate.alias.args.as_slice()
471471
else {
472472
panic!();
473473
};
@@ -567,14 +567,14 @@ where
567567
ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(tcx) {
568568
None => Ty::new_unit(tcx),
569569
Some(tail_ty) => {
570-
Ty::new_projection(tcx, metadata_def_id, [tail_ty.instantiate(tcx, &args)])
570+
Ty::new_projection(tcx, metadata_def_id, [tail_ty.instantiate(tcx, args)])
571571
}
572572
},
573573
ty::Adt(_, _) => Ty::new_unit(tcx),
574574

575575
ty::Tuple(elements) => match elements.last() {
576576
None => Ty::new_unit(tcx),
577-
Some(&tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]),
577+
Some(tail_ty) => Ty::new_projection(tcx, metadata_def_id, [tail_ty]),
578578
},
579579

580580
ty::Infer(
@@ -895,15 +895,15 @@ where
895895
} else {
896896
let target_args = self.fresh_args_for_item(target_container_def_id);
897897
let target_trait_ref =
898-
tcx.impl_trait_ref(target_container_def_id).instantiate(tcx, &target_args);
898+
tcx.impl_trait_ref(target_container_def_id).instantiate(tcx, target_args);
899899
// Relate source impl to target impl by equating trait refs.
900900
self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?;
901901
// Also add predicates since they may be needed to constrain the
902902
// target impl's params.
903903
self.add_goals(
904904
GoalSource::Misc,
905905
tcx.predicates_of(target_container_def_id)
906-
.iter_instantiated(tcx, &target_args)
906+
.iter_instantiated(tcx, target_args)
907907
.map(|pred| goal.with(tcx, pred)),
908908
);
909909
goal.predicate.alias.args.rebase_onto(tcx, impl_trait_ref.def_id, target_args)

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
}
8787
(Reveal::All, _) => {
8888
// FIXME: Add an assertion that opaque type storage is empty.
89-
let actual = tcx.type_of(opaque_ty.def_id).instantiate(tcx, &opaque_ty.args);
89+
let actual = tcx.type_of(opaque_ty.def_id).instantiate(tcx, opaque_ty.args);
9090
self.eq(goal.param_env, expected, actual)?;
9191
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
9292
}
@@ -102,7 +102,7 @@ pub fn uses_unique_placeholders_ignoring_regions<I: Interner>(
102102
args: I::GenericArgs,
103103
) -> Result<(), NotUniqueParam<I>> {
104104
let mut seen = GrowableBitSet::default();
105-
for arg in args {
105+
for arg in args.iter() {
106106
match arg.kind() {
107107
// Ignore regions, since we can't resolve those in a canonicalized
108108
// query in the trait solver.

compiler/rustc_next_trait_solver/src/solve/normalizes_to/weak_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ where
2525
self.add_goals(
2626
GoalSource::Misc,
2727
tcx.predicates_of(weak_ty.def_id)
28-
.iter_instantiated(tcx, &weak_ty.args)
28+
.iter_instantiated(tcx, weak_ty.args)
2929
.map(|pred| goal.with(tcx, pred)),
3030
);
3131

32-
let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, &weak_ty.args);
32+
let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args);
3333
self.instantiate_normalizes_to_term(goal, actual.into());
3434

3535
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

0 commit comments

Comments
 (0)