Skip to content

Commit 7658e0f

Browse files
committed
Stop passing the self-type as a separate argument.
1 parent a4da3f8 commit 7658e0f

File tree

38 files changed

+113
-164
lines changed

38 files changed

+113
-164
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
489489
// but the type has region variables, so erase those.
490490
tcx.infer_ctxt()
491491
.build()
492-
.type_implements_trait(
493-
default_trait,
494-
tcx.erase_regions(ty),
495-
ty::List::empty(),
496-
param_env,
497-
)
492+
.type_implements_trait(default_trait, [tcx.erase_regions(ty)], param_env)
498493
.must_apply_modulo_regions()
499494
};
500495

@@ -1707,7 +1702,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17071702
err.span_label(borrow_span, note);
17081703

17091704
let tcx = self.infcx.tcx;
1710-
let ty_params = ty::List::empty();
17111705

17121706
let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
17131707
let return_ty = tcx.erase_regions(return_ty);
@@ -1716,7 +1710,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17161710
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
17171711
&& self
17181712
.infcx
1719-
.type_implements_trait(iter_trait, return_ty, ty_params, self.param_env)
1713+
.type_implements_trait(iter_trait, [return_ty], self.param_env)
17201714
.must_apply_modulo_regions()
17211715
{
17221716
err.span_suggestion_hidden(

compiler/rustc_borrowck/src/type_check/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
547547

548548
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
549549
let tcx = self.tcx();
550-
let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, place_ty.ty, []);
550+
let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, [place_ty.ty]);
551551

552552
// To have a `Copy` operand, the type `T` of the
553553
// value must be `Copy`. Note that we prove that `T: Copy`,
@@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12711271
self.check_rvalue(body, rv, location);
12721272
if !self.unsized_feature_enabled() {
12731273
let trait_ref =
1274-
tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, place_ty, []);
1274+
tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, [place_ty]);
12751275
self.prove_trait_ref(
12761276
trait_ref,
12771277
location.to_locations(),
@@ -1860,7 +1860,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18601860
Operand::Move(place) => {
18611861
// Make sure that repeated elements implement `Copy`.
18621862
let ty = place.ty(body, tcx).ty;
1863-
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, ty, []);
1863+
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, [ty]);
18641864

18651865
self.prove_trait_ref(
18661866
trait_ref,
@@ -1873,7 +1873,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18731873
}
18741874

18751875
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
1876-
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, ty, []);
1876+
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [ty]);
18771877

18781878
self.prove_trait_ref(
18791879
trait_ref,
@@ -1885,7 +1885,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18851885
Rvalue::ShallowInitBox(operand, ty) => {
18861886
self.check_operand(operand, location);
18871887

1888-
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, *ty, []);
1888+
let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, [*ty]);
18891889

18901890
self.prove_trait_ref(
18911891
trait_ref,
@@ -1982,11 +1982,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19821982

19831983
CastKind::Pointer(PointerCast::Unsize) => {
19841984
let &ty = ty;
1985-
let trait_ref = tcx.at(span).mk_trait_ref(
1986-
LangItem::CoerceUnsized,
1987-
op.ty(body, tcx),
1988-
[ty.into()],
1989-
);
1985+
let trait_ref = tcx
1986+
.at(span)
1987+
.mk_trait_ref(LangItem::CoerceUnsized, [op.ty(body, tcx), ty]);
19901988

19911989
self.prove_trait_ref(
19921990
trait_ref,

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Qualif for NeedsNonConstDrop {
158158
ObligationCause::dummy_with_span(cx.body.span),
159159
cx.param_env,
160160
ty::Binder::dummy(ty::TraitPredicate {
161-
trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, ty, []),
161+
trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, [ty]),
162162
constness: ty::BoundConstness::ConstIfConst,
163163
polarity: ty::ImplPolarity::Positive,
164164
}),

compiler/rustc_hir_analysis/src/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> Bounds<'tcx> {
6262
let sized_predicate = self.implicitly_sized.and_then(|span| {
6363
// FIXME: use tcx.at(span).mk_trait_ref(LangItem::Sized) here? This may make no-core code harder to write.
6464
let sized = tcx.lang_items().sized_trait()?;
65-
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized, param_ty, []));
65+
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized, [param_ty]));
6666
Some((trait_ref.without_const().to_predicate(tcx), span))
6767
});
6868

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ fn receiver_is_implemented<'tcx>(
17821782
receiver_ty: Ty<'tcx>,
17831783
) -> bool {
17841784
let tcx = wfcx.tcx();
1785-
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, receiver_ty, []));
1785+
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty]));
17861786

17871787
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
17881788

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
315315
cause.clone(),
316316
dispatch_from_dyn_trait,
317317
0,
318-
field.ty(tcx, substs_a),
319-
[field.ty(tcx, substs_b).into()],
318+
[field.ty(tcx, substs_a), field.ty(tcx, substs_b)],
320319
)
321320
}),
322321
);
@@ -558,7 +557,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
558557
// Register an obligation for `A: Trait<B>`.
559558
let cause = traits::ObligationCause::misc(span, impl_hir_id);
560559
let predicate =
561-
predicate_for_trait_def(tcx, param_env, cause, trait_def_id, 0, source, [target.into()]);
560+
predicate_for_trait_def(tcx, param_env, cause, trait_def_id, 0, [source, target]);
562561
let errors = traits::fully_solve_obligation(&infcx, predicate);
563562
if !errors.is_empty() {
564563
infcx.err_ctxt().report_fulfillment_errors(&errors, None);

compiler/rustc_hir_typeck/src/cast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,9 @@ impl<'a, 'tcx> CastCheck<'tcx> {
498498
let ty = fcx.tcx.erase_regions(ty);
499499
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
500500
let expr_ty = fcx.tcx.erase_regions(expr_ty);
501-
let ty_params = fcx.tcx.mk_substs(std::iter::once(ty::GenericArg::from(expr_ty)));
502501
if fcx
503502
.infcx
504-
.type_implements_trait(from_trait, ty, ty_params, fcx.param_env)
503+
.type_implements_trait(from_trait, [ty, expr_ty], fcx.param_env)
505504
.must_apply_modulo_regions()
506505
{
507506
label = false;

compiler/rustc_hir_typeck/src/coercion.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
630630
cause,
631631
coerce_unsized_did,
632632
0,
633-
coerce_source,
634-
[coerce_target.into()]
633+
[coerce_source, coerce_target]
635634
)];
636635

637636
let mut has_unsized_tuple_coercion = false;
@@ -1086,8 +1085,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10861085
self.infcx
10871086
.type_implements_trait(
10881087
self.tcx.lang_items().deref_mut_trait()?,
1089-
expr_ty,
1090-
ty::List::empty(),
1088+
[expr_ty],
10911089
self.param_env,
10921090
)
10931091
.may_apply()

compiler/rustc_hir_typeck/src/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11191119
.infcx
11201120
.type_implements_trait(
11211121
self.tcx.lang_items().sized_trait().unwrap(),
1122-
lhs_deref_ty,
1123-
ty::List::empty(),
1122+
[lhs_deref_ty],
11241123
self.param_env,
11251124
)
11261125
.may_apply();

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10951095
self.param_env,
10961096
ty::Binder::dummy(self.tcx.mk_trait_ref(
10971097
into_def_id,
1098-
expr_ty, [expected_ty.into()]
1098+
[expr_ty, expected_ty]
10991099
))
11001100
.to_poly_trait_predicate(),
11011101
))

compiler/rustc_hir_typeck/src/method/prelude2021.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_ast::Mutability;
99
use rustc_errors::Applicability;
1010
use rustc_hir as hir;
1111
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
12-
use rustc_middle::ty;
1312
use rustc_middle::ty::{Adt, Array, Ref, Ty};
1413
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
1514
use rustc_span::symbol::kw::{Empty, Underscore};
@@ -232,10 +231,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
232231
kind: TypeVariableOriginKind::MiscVariable,
233232
span,
234233
});
235-
let params = self.tcx.mk_substs(std::iter::once(ty::GenericArg::from(any_type)));
236234
if !self
237235
.infcx
238-
.type_implements_trait(trait_def_id, self_ty, params, self.param_env)
236+
.type_implements_trait(trait_def_id, [self_ty, any_type], self.param_env)
239237
.may_apply()
240238
{
241239
return;

compiler/rustc_hir_typeck/src/method/suggest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7070
self.probe(|_| {
7171
let trait_ref = tcx.mk_trait_ref(
7272
fn_once,
73-
ty,
74-
[self
75-
.next_ty_var(TypeVariableOrigin {
73+
[
74+
ty,
75+
self.next_ty_var(TypeVariableOrigin {
7676
kind: TypeVariableOriginKind::MiscVariable,
7777
span,
78-
})
79-
.into()],
78+
}),
79+
],
8080
);
8181
let poly_trait_ref = ty::Binder::dummy(trait_ref);
8282
let obligation = Obligation::misc(

compiler/rustc_hir_typeck/src/upvar.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
970970
check_trait
971971
.map(|check_trait| {
972972
self.infcx
973-
.type_implements_trait(
974-
check_trait,
975-
ty,
976-
ty::List::empty(),
977-
self.param_env,
978-
)
973+
.type_implements_trait(check_trait, [ty], self.param_env)
979974
.must_apply_modulo_regions()
980975
})
981976
.unwrap_or(false),
@@ -999,12 +994,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
999994
check_trait
1000995
.map(|check_trait| {
1001996
self.infcx
1002-
.type_implements_trait(
1003-
check_trait,
1004-
ty,
1005-
ty::List::empty(),
1006-
self.param_env,
1007-
)
997+
.type_implements_trait(check_trait, [ty], self.param_env)
1008998
.must_apply_modulo_regions()
1009999
})
10101000
.unwrap_or(false),
@@ -1348,12 +1338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13481338
let is_drop_defined_for_ty = |ty: Ty<'tcx>| {
13491339
let drop_trait = self.tcx.require_lang_item(hir::LangItem::Drop, Some(closure_span));
13501340
self.infcx
1351-
.type_implements_trait(
1352-
drop_trait,
1353-
ty,
1354-
ty::List::empty(),
1355-
self.tcx.param_env(closure_def_id),
1356-
)
1341+
.type_implements_trait(drop_trait, [ty], self.tcx.param_env(closure_def_id))
13571342
.must_apply_modulo_regions()
13581343
};
13591344

compiler/rustc_infer/src/traits/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
2727
def_id: DefId,
2828
cause: ObligationCause<'tcx>,
2929
) {
30-
let trait_ref = infcx.tcx.mk_trait_ref(def_id, ty, []);
30+
let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]);
3131
self.register_predicate_obligation(
3232
infcx,
3333
Obligation {

compiler/rustc_lint/src/non_fmt_panic.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,17 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
152152

153153
let infcx = cx.tcx.infer_ctxt().build();
154154
let suggest_display = is_str
155-
|| cx.tcx.get_diagnostic_item(sym::Display).map(|t| {
156-
infcx.type_implements_trait(t, ty, ty::List::empty(), cx.param_env).may_apply()
157-
}) == Some(true);
155+
|| cx
156+
.tcx
157+
.get_diagnostic_item(sym::Display)
158+
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
159+
== Some(true);
158160
let suggest_debug = !suggest_display
159-
&& cx.tcx.get_diagnostic_item(sym::Debug).map(|t| {
160-
infcx.type_implements_trait(t, ty, ty::List::empty(), cx.param_env).may_apply()
161-
}) == Some(true);
161+
&& cx
162+
.tcx
163+
.get_diagnostic_item(sym::Debug)
164+
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
165+
== Some(true);
162166

163167
let suggest_panic_any = !is_str && panic == sym::std_panic_macro;
164168

compiler/rustc_middle/src/ty/context.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -2820,17 +2820,17 @@ impl<'tcx> TyCtxt<'tcx> {
28202820
pub fn mk_trait_ref(
28212821
self,
28222822
trait_def_id: DefId,
2823-
self_ty: Ty<'tcx>,
2824-
rest: impl IntoIterator<Item = GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
2823+
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
28252824
) -> ty::TraitRef<'tcx> {
2826-
let rest = rest.into_iter();
2825+
let substs = substs.into_iter().map(Into::into);
2826+
let n = self.generics_of(trait_def_id).count();
28272827
debug_assert_eq!(
2828-
self.generics_of(trait_def_id).count() - 1,
2829-
rest.len(),
2830-
"wrong number of generic parameters for {trait_def_id:?} on self type {self_ty:?}: {:?} \nDid you accidentally include the self-type in the params list?",
2831-
rest.collect::<Vec<_>>(),
2828+
(n, Some(n)),
2829+
substs.size_hint(),
2830+
"wrong number of generic parameters for {trait_def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
2831+
substs.collect::<Vec<_>>(),
28322832
);
2833-
let substs = self.mk_substs_trait(self_ty, rest);
2833+
let substs = self.mk_substs(substs);
28342834
ty::TraitRef::new(trait_def_id, substs)
28352835
}
28362836

@@ -2994,11 +2994,10 @@ impl<'tcx> TyCtxtAt<'tcx> {
29942994
pub fn mk_trait_ref(
29952995
self,
29962996
trait_lang_item: LangItem,
2997-
self_ty: Ty<'tcx>,
2998-
rest: impl IntoIterator<Item = ty::GenericArg<'tcx>, IntoIter: ExactSizeIterator>,
2997+
substs: impl IntoIterator<Item = impl Into<ty::GenericArg<'tcx>>>,
29992998
) -> ty::TraitRef<'tcx> {
30002999
let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span));
3001-
self.tcx.mk_trait_ref(trait_def_id, self_ty, rest)
3000+
self.tcx.mk_trait_ref(trait_def_id, substs)
30023001
}
30033002
}
30043003

compiler/rustc_middle/src/ty/sty.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
719719
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
720720
}
721721
ExistentialPredicate::AutoTrait(did) => {
722-
let trait_ref = self.rebind(tcx.mk_trait_ref(did, self_ty, []));
722+
let trait_ref = self.rebind(tcx.mk_trait_ref(did, [self_ty]));
723723
trait_ref.without_const().to_predicate(tcx)
724724
}
725725
}
@@ -812,7 +812,10 @@ impl<'tcx> TraitRef<'tcx> {
812812
}
813813

814814
pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
815-
tcx.mk_trait_ref(self.def_id, self_ty, self.substs.iter().skip(1))
815+
tcx.mk_trait_ref(
816+
self.def_id,
817+
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
818+
)
816819
}
817820

818821
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
@@ -910,7 +913,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
910913
// otherwise the escaping vars would be captured by the binder
911914
// debug_assert!(!self_ty.has_escaping_bound_vars());
912915

913-
tcx.mk_trait_ref(self.def_id, self_ty, self.substs.iter())
916+
tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
914917
}
915918
}
916919

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ impl<'tcx> ConstToPat<'tcx> {
232232
ObligationCause::misc(self.span, self.id),
233233
partial_eq_trait_id,
234234
0,
235-
ty,
236-
[ty.into()],
235+
[ty, ty],
237236
);
238237
// FIXME: should this call a `predicate_must_hold` variant instead?
239238

compiler/rustc_monomorphize/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn custom_coerce_unsize_info<'tcx>(
2828
target_ty: Ty<'tcx>,
2929
) -> CustomCoerceUnsized {
3030
let trait_ref =
31-
ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, source_ty, [target_ty.into()]));
31+
ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, [source_ty, target_ty]));
3232

3333
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
3434
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {

compiler/rustc_trait_selection/src/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
122122
let tcx = self.infcx.tcx;
123123

124124
// <ty as Deref>
125-
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, ty, []);
125+
let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]);
126126

127127
let cause = traits::ObligationCause::misc(self.span, self.body_id);
128128

0 commit comments

Comments
 (0)