Skip to content

Commit 86756c1

Browse files
Stop taking ParamTy/ParamConst/EarlyParamRegion/AliasTy by ref
1 parent f9b1614 commit 86756c1

File tree

14 files changed

+38
-38
lines changed

14 files changed

+38
-38
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13201320
.into_iter()
13211321
.map(|err| match err.obligation.predicate.kind().skip_binder() {
13221322
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
1323-
match predicate.self_ty().kind() {
1323+
match *predicate.self_ty().kind() {
13241324
ty::Param(param_ty) => Ok((
13251325
generics.type_param(param_ty, tcx),
13261326
predicate.trait_ref.print_only_trait_path().to_string(),

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10701070
// LL | blk();
10711071
// | ----- this value implements `FnOnce`, which causes it to be moved when called
10721072
// ```
1073-
if let ty::Param(param_ty) = self_ty.kind()
1073+
if let ty::Param(param_ty) = *self_ty.kind()
10741074
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
10751075
&& let param = generics.type_param(param_ty, self.infcx.tcx)
10761076
&& let Some(hir_generics) = self

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26972697

26982698
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
26992699
let generics = self.tcx.generics_of(self.body_id);
2700-
let generic_param = generics.type_param(&param, self.tcx);
2700+
let generic_param = generics.type_param(param, self.tcx);
27012701
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
27022702
return;
27032703
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21442144
let callee_ty = callee_ty.peel_refs();
21452145
match *callee_ty.kind() {
21462146
ty::Param(param) => {
2147-
let param = self.tcx.generics_of(self.body_id).type_param(&param, self.tcx);
2147+
let param = self.tcx.generics_of(self.body_id).type_param(param, self.tcx);
21482148
if param.kind.is_synthetic() {
21492149
// if it's `impl Fn() -> ..` then just fall down to the def-id based logic
21502150
def_id = param.def_id;

compiler/rustc_hir_typeck/src/method/suggest.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
125125
let Some(arg_ty) = args[0].as_type() else {
126126
return false;
127127
};
128-
let ty::Param(param) = arg_ty.kind() else {
128+
let ty::Param(param) = *arg_ty.kind() else {
129129
return false;
130130
};
131131
// Is `generic_param` the same as the arg for this trait predicate?
132-
generic_param.index == generics.type_param(&param, tcx).index
132+
generic_param.index == generics.type_param(param, tcx).index
133133
} else {
134134
false
135135
}
@@ -156,10 +156,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156156
return false;
157157
}
158158

159-
match ty.peel_refs().kind() {
159+
match *ty.peel_refs().kind() {
160160
ty::Param(param) => {
161161
let generics = self.tcx.generics_of(self.body_id);
162-
let generic_param = generics.type_param(&param, self.tcx);
162+
let generic_param = generics.type_param(param, self.tcx);
163163
for unsatisfied in unsatisfied_predicates.iter() {
164164
// The parameter implements `IntoIterator`
165165
// but it has called a method that requires it to implement `Iterator`
@@ -3232,9 +3232,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32323232
.sort_by_key(|&info| (!info.def_id.is_local(), self.tcx.def_path_str(info.def_id)));
32333233
candidates.dedup();
32343234

3235-
let param_type = match rcvr_ty.kind() {
3235+
let param_type = match *rcvr_ty.kind() {
32363236
ty::Param(param) => Some(param),
3237-
ty::Ref(_, ty, _) => match ty.kind() {
3237+
ty::Ref(_, ty, _) => match *ty.kind() {
32383238
ty::Param(param) => Some(param),
32393239
_ => None,
32403240
},
@@ -3429,7 +3429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34293429
} else {
34303430
param_type.map_or_else(
34313431
|| "implement".to_string(), // FIXME: it might only need to be imported into scope, not implemented.
3432-
ToString::to_string,
3432+
|p| p.to_string(),
34333433
)
34343434
},
34353435
},

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23542354

23552355
// type_param_sugg_span is (span, has_bounds)
23562356
let (type_scope, type_param_sugg_span) = match bound_kind {
2357-
GenericKind::Param(ref param) => {
2357+
GenericKind::Param(param) => {
23582358
let generics = self.tcx.generics_of(generic_param_scope);
23592359
let def_id = generics.type_param(param, self.tcx).def_id.expect_local();
23602360
let scope = self.tcx.local_def_id_to_hir_id(def_id).owner.def_id;

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2828

2929
match err {
3030
ArgumentSorts(values, _) | Sorts(values) => {
31-
match (values.expected.kind(), values.found.kind()) {
31+
match (*values.expected.kind(), *values.found.kind()) {
3232
(ty::Closure(..), ty::Closure(..)) => {
3333
diag.note("no two closures, even if identical, have the same type");
3434
diag.help("consider boxing your closure and/or using it as a trait object");
@@ -452,7 +452,7 @@ impl<T> Trait<T> for X {
452452
}
453453
(ty::FnPtr(sig), ty::FnDef(def_id, _))
454454
| (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
455-
if tcx.fn_sig(*def_id).skip_binder().unsafety() < sig.unsafety() {
455+
if tcx.fn_sig(def_id).skip_binder().unsafety() < sig.unsafety() {
456456
diag.note(
457457
"unsafe functions cannot be coerced into safe function pointers",
458458
);
@@ -527,7 +527,7 @@ impl<T> Trait<T> for X {
527527
diag: &mut Diag<'_>,
528528
msg: impl Fn() -> String,
529529
body_owner_def_id: DefId,
530-
proj_ty: &ty::AliasTy<'tcx>,
530+
proj_ty: ty::AliasTy<'tcx>,
531531
ty: Ty<'tcx>,
532532
) -> bool {
533533
let tcx = self.tcx;
@@ -541,7 +541,7 @@ impl<T> Trait<T> for X {
541541
};
542542
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
543543
// This will also work for `impl Trait`.
544-
let ty::Param(param_ty) = proj_ty.self_ty().kind() else {
544+
let ty::Param(param_ty) = *proj_ty.self_ty().kind() else {
545545
return false;
546546
};
547547
let generics = tcx.generics_of(body_owner_def_id);
@@ -598,7 +598,7 @@ impl<T> Trait<T> for X {
598598
fn expected_projection(
599599
&self,
600600
diag: &mut Diag<'_>,
601-
proj_ty: &ty::AliasTy<'tcx>,
601+
proj_ty: ty::AliasTy<'tcx>,
602602
values: ExpectedFound<Ty<'tcx>>,
603603
body_owner_def_id: DefId,
604604
cause_code: &ObligationCauseCode<'_>,
@@ -709,7 +709,7 @@ fn foo(&self) -> Self::T { String::new() }
709709
&self,
710710
diag: &mut Diag<'_>,
711711
msg: impl Fn() -> String,
712-
proj_ty: &ty::AliasTy<'tcx>,
712+
proj_ty: ty::AliasTy<'tcx>,
713713
ty: Ty<'tcx>,
714714
) -> bool {
715715
let tcx = self.tcx;

compiler/rustc_middle/src/ty/generics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'tcx> Generics {
263263
/// Returns the `GenericParamDef` associated with this `EarlyParamRegion`.
264264
pub fn region_param(
265265
&'tcx self,
266-
param: &ty::EarlyParamRegion,
266+
param: ty::EarlyParamRegion,
267267
tcx: TyCtxt<'tcx>,
268268
) -> &'tcx GenericParamDef {
269269
let param = self.param_at(param.index as usize, tcx);
@@ -274,7 +274,7 @@ impl<'tcx> Generics {
274274
}
275275

276276
/// Returns the `GenericParamDef` associated with this `ParamTy`.
277-
pub fn type_param(&'tcx self, param: &ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
277+
pub fn type_param(&'tcx self, param: ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
278278
let param = self.param_at(param.index as usize, tcx);
279279
match param.kind {
280280
GenericParamDefKind::Type { .. } => param,
@@ -286,7 +286,7 @@ impl<'tcx> Generics {
286286
/// `Generics`.
287287
pub fn opt_type_param(
288288
&'tcx self,
289-
param: &ParamTy,
289+
param: ParamTy,
290290
tcx: TyCtxt<'tcx>,
291291
) -> Option<&'tcx GenericParamDef> {
292292
let param = self.opt_param_at(param.index as usize, tcx)?;
@@ -297,7 +297,7 @@ impl<'tcx> Generics {
297297
}
298298

299299
/// Returns the `GenericParamDef` associated with this `ParamConst`.
300-
pub fn const_param(&'tcx self, param: &ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
300+
pub fn const_param(&'tcx self, param: ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
301301
let param = self.param_at(param.index as usize, tcx);
302302
match param.kind {
303303
GenericParamDefKind::Const { .. } => param,

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12761276

12771277
fn pretty_print_inherent_projection(
12781278
&mut self,
1279-
alias_ty: &ty::AliasTy<'tcx>,
1279+
alias_ty: ty::AliasTy<'tcx>,
12801280
) -> Result<(), PrintError> {
12811281
let def_key = self.tcx().def_key(alias_ty.def_id);
12821282
self.path_generic_args(
@@ -3204,7 +3204,7 @@ define_print_and_forward_display! {
32043204

32053205
ty::AliasTy<'tcx> {
32063206
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
3207-
p!(pretty_print_inherent_projection(self))
3207+
p!(pretty_print_inherent_projection(*self))
32083208
} else {
32093209
// If we're printing verbosely, or don't want to invoke queries
32103210
// (`is_impl_trait_in_trait`), then fall back to printing the def path.

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ impl<'tcx> ParamTy {
13791379
Ty::new_param(tcx, self.index, self.name)
13801380
}
13811381

1382-
pub fn span_from_generics(&self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span {
1382+
pub fn span_from_generics(self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span {
13831383
let generics = tcx.generics_of(item_with_generics);
13841384
let type_param = generics.type_param(self, tcx);
13851385
tcx.def_span(type_param.def_id)

compiler/rustc_middle/src/ty/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,19 @@ impl<'tcx> TyCtxt<'tcx> {
432432
.filter(|&(_, k)| {
433433
match k.unpack() {
434434
GenericArgKind::Lifetime(region) => match region.kind() {
435-
ty::ReEarlyParam(ref ebr) => {
435+
ty::ReEarlyParam(ebr) => {
436436
!impl_generics.region_param(ebr, self).pure_wrt_drop
437437
}
438438
// Error: not a region param
439439
_ => false,
440440
},
441-
GenericArgKind::Type(ty) => match ty.kind() {
442-
ty::Param(ref pt) => !impl_generics.type_param(pt, self).pure_wrt_drop,
441+
GenericArgKind::Type(ty) => match *ty.kind() {
442+
ty::Param(pt) => !impl_generics.type_param(pt, self).pure_wrt_drop,
443443
// Error: not a type param
444444
_ => false,
445445
},
446446
GenericArgKind::Const(ct) => match ct.kind() {
447-
ty::ConstKind::Param(ref pc) => {
447+
ty::ConstKind::Param(pc) => {
448448
!impl_generics.const_param(pc, self).pure_wrt_drop
449449
}
450450
// Error: not a const param

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
124124
msg: &str,
125125
err: &mut Diag<'_, G>,
126126
fn_sig: Option<&hir::FnSig<'_>>,
127-
projection: Option<&ty::AliasTy<'_>>,
127+
projection: Option<ty::AliasTy<'_>>,
128128
trait_pred: ty::PolyTraitPredicate<'tcx>,
129129
// When we are dealing with a trait, `super_traits` will be `Some`:
130130
// Given `trait T: A + B + C {}`
@@ -142,7 +142,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
142142
let generics = tcx.generics_of(item_id);
143143
// Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`...
144144
if let Some((param, bound_str, fn_sig)) =
145-
fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind() {
145+
fn_sig.zip(projection).and_then(|(sig, p)| match *p.self_ty().kind() {
146146
// Shenanigans to get the `Trait` from the `impl Trait`.
147147
ty::Param(param) => {
148148
let param_def = generics.type_param(param, tcx);
@@ -252,7 +252,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
252252
let trait_pred = self.resolve_numeric_literals_with_default(trait_pred);
253253

254254
let self_ty = trait_pred.skip_binder().self_ty();
255-
let (param_ty, projection) = match self_ty.kind() {
255+
let (param_ty, projection) = match *self_ty.kind() {
256256
ty::Param(_) => (true, None),
257257
ty::Alias(ty::Projection, projection) => (false, Some(projection)),
258258
_ => (false, None),

compiler/rustc_trait_selection/src/traits/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ fn is_impossible_associated_item(
482482
type Result = ControlFlow<()>;
483483
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
484484
// If this is a parameter from the trait item's own generics, then bail
485-
if let ty::Param(param) = t.kind()
485+
if let ty::Param(param) = *t.kind()
486486
&& let param_def_id = self.generics.type_param(param, self.tcx).def_id
487487
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
488488
{
@@ -492,7 +492,7 @@ fn is_impossible_associated_item(
492492
}
493493
fn visit_region(&mut self, r: ty::Region<'tcx>) -> Self::Result {
494494
if let ty::ReEarlyParam(param) = r.kind()
495-
&& let param_def_id = self.generics.region_param(&param, self.tcx).def_id
495+
&& let param_def_id = self.generics.region_param(param, self.tcx).def_id
496496
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
497497
{
498498
return ControlFlow::Break(());
@@ -501,7 +501,7 @@ fn is_impossible_associated_item(
501501
}
502502
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result {
503503
if let ty::ConstKind::Param(param) = ct.kind()
504-
&& let param_def_id = self.generics.const_param(&param, self.tcx).def_id
504+
&& let param_def_id = self.generics.const_param(param, self.tcx).def_id
505505
&& self.tcx.parent(param_def_id) == self.trait_item_def_id
506506
{
507507
return ControlFlow::Break(());

compiler/rustc_ty_utils/src/opaque_types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
130130
TaitInBodyFinder { collector: self }.visit_expr(body);
131131
}
132132

133-
fn visit_opaque_ty(&mut self, alias_ty: &ty::AliasTy<'tcx>) {
133+
fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) {
134134
if !self.seen.insert(alias_ty.def_id.expect_local()) {
135135
return;
136136
}
@@ -205,7 +205,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
205205
#[instrument(skip(self), ret, level = "trace")]
206206
fn visit_ty(&mut self, t: Ty<'tcx>) {
207207
t.super_visit_with(self);
208-
match t.kind() {
208+
match *t.kind() {
209209
ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => {
210210
self.visit_opaque_ty(alias_ty);
211211
}
@@ -279,7 +279,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
279279
// assumption to the `param_env` of the default method. We also separately
280280
// rely on that assumption here.
281281
let ty = self.tcx.type_of(alias_ty.def_id).instantiate(self.tcx, alias_ty.args);
282-
let ty::Alias(ty::Opaque, alias_ty) = ty.kind() else { bug!("{ty:?}") };
282+
let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!("{ty:?}") };
283283
self.visit_opaque_ty(alias_ty);
284284
}
285285
}

0 commit comments

Comments
 (0)