Skip to content

Commit 380e230

Browse files
Apply suggestions from code review
1 parent 5268ae7 commit 380e230

File tree

4 files changed

+39
-40
lines changed

4 files changed

+39
-40
lines changed

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
3939

4040
#[inline]
4141
fn variant(&self) -> &Self::Variant {
42+
// FIXME(@lcnr): Look into instead returning `Self::Variant` directly here
4243
&self.kind
4344
}
4445
}

compiler/rustc_middle/src/ty/error.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<'tcx> TyCtxt<'tcx> {
353353
);
354354
}
355355
}
356-
match (&values.expected.kind(), &values.found.kind()) {
356+
match (values.expected.kind(), values.found.kind()) {
357357
(ty::Float(_), ty::Infer(ty::IntVar(_))) => {
358358
if let Ok(
359359
// Issue #53280
@@ -372,11 +372,11 @@ impl<'tcx> TyCtxt<'tcx> {
372372
}
373373
(ty::Param(expected), ty::Param(found)) => {
374374
let generics = self.generics_of(body_owner_def_id);
375-
let e_span = self.def_span(generics.type_param(expected, self).def_id);
375+
let e_span = self.def_span(generics.type_param(&expected, self).def_id);
376376
if !sp.contains(e_span) {
377377
db.span_label(e_span, "expected type parameter");
378378
}
379-
let f_span = self.def_span(generics.type_param(found, self).def_id);
379+
let f_span = self.def_span(generics.type_param(&found, self).def_id);
380380
if !sp.contains(f_span) {
381381
db.span_label(f_span, "found type parameter");
382382
}
@@ -395,14 +395,14 @@ impl<'tcx> TyCtxt<'tcx> {
395395
}
396396
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) => {
397397
let generics = self.generics_of(body_owner_def_id);
398-
let p_span = self.def_span(generics.type_param(p, self).def_id);
398+
let p_span = self.def_span(generics.type_param(&p, self).def_id);
399399
if !sp.contains(p_span) {
400400
db.span_label(p_span, "this type parameter");
401401
}
402402
let hir = self.hir();
403403
let mut note = true;
404404
if let Some(generics) = generics
405-
.type_param(p, self)
405+
.type_param(&p, self)
406406
.def_id
407407
.as_local()
408408
.map(|id| hir.local_def_id_to_hir_id(id))
@@ -437,7 +437,7 @@ impl<'tcx> TyCtxt<'tcx> {
437437
(ty::Param(p), ty::Dynamic(..) | ty::Opaque(..))
438438
| (ty::Dynamic(..) | ty::Opaque(..), ty::Param(p)) => {
439439
let generics = self.generics_of(body_owner_def_id);
440-
let p_span = self.def_span(generics.type_param(p, self).def_id);
440+
let p_span = self.def_span(generics.type_param(&p, self).def_id);
441441
if !sp.contains(p_span) {
442442
db.span_label(p_span, "this type parameter");
443443
}
@@ -477,7 +477,7 @@ impl<T> Trait<T> for X {
477477
}
478478
(ty::Param(p), ty::Closure(..) | ty::Generator(..)) => {
479479
let generics = self.generics_of(body_owner_def_id);
480-
let p_span = self.def_span(generics.type_param(p, self).def_id);
480+
let p_span = self.def_span(generics.type_param(&p, self).def_id);
481481
if !sp.contains(p_span) {
482482
db.span_label(p_span, "this type parameter");
483483
}
@@ -489,15 +489,15 @@ impl<T> Trait<T> for X {
489489
}
490490
(ty::Param(p), _) | (_, ty::Param(p)) => {
491491
let generics = self.generics_of(body_owner_def_id);
492-
let p_span = self.def_span(generics.type_param(p, self).def_id);
492+
let p_span = self.def_span(generics.type_param(&p, self).def_id);
493493
if !sp.contains(p_span) {
494494
db.span_label(p_span, "this type parameter");
495495
}
496496
}
497497
(ty::Projection(proj_ty), _) => {
498498
self.expected_projection(
499499
db,
500-
proj_ty,
500+
&proj_ty,
501501
values,
502502
body_owner_def_id,
503503
&cause.code,
@@ -512,7 +512,7 @@ impl<T> Trait<T> for X {
512512
db,
513513
&msg,
514514
body_owner_def_id,
515-
proj_ty,
515+
&proj_ty,
516516
values.expected,
517517
) {
518518
db.help(&msg);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ pub trait PrettyPrinter<'tcx>:
11181118

11191119
let u8_type = self.tcx().types.u8;
11201120

1121-
match (ct, &ty.kind()) {
1121+
match (ct, ty.kind()) {
11221122
// Byte/string slices, printed as (byte) string literals.
11231123
(
11241124
ConstValue::Slice { data, start, end },
@@ -1142,7 +1142,7 @@ pub trait PrettyPrinter<'tcx>:
11421142
p!(write("{:?}", s));
11431143
Ok(self)
11441144
}
1145-
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => {
1145+
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if t == u8_type => {
11461146
let n = n.val.try_to_bits(self.tcx().data_layout.pointer_size).unwrap();
11471147
// cast is ok because we already checked for pointer size (32 or 64 bit) above
11481148
let n = Size::from_bytes(n);

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
325325
) -> RelateResult<'tcx, Ty<'tcx>> {
326326
let tcx = relation.tcx();
327327
debug!("super_relate_tys: a={:?} b={:?}", a, b);
328-
match (&a.kind(), &b.kind()) {
329-
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
328+
match (a.kind(), b.kind()) {
329+
(ty::Infer(_), _) | (_, ty::Infer(_)) => {
330330
// The caller should handle these cases!
331331
bug!("var types encountered in super_relate_tys")
332332
}
@@ -335,39 +335,39 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
335335
bug!("bound types encountered in super_relate_tys")
336336
}
337337

338-
(&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(tcx.ty_error()),
338+
(ty::Error(_), _) | (_, ty::Error(_)) => Ok(tcx.ty_error()),
339339

340-
(&ty::Never, _)
341-
| (&ty::Char, _)
342-
| (&ty::Bool, _)
343-
| (&ty::Int(_), _)
344-
| (&ty::Uint(_), _)
345-
| (&ty::Float(_), _)
346-
| (&ty::Str, _)
340+
(ty::Never, _)
341+
| (ty::Char, _)
342+
| (ty::Bool, _)
343+
| (ty::Int(_), _)
344+
| (ty::Uint(_), _)
345+
| (ty::Float(_), _)
346+
| (ty::Str, _)
347347
if a == b =>
348348
{
349349
Ok(a)
350350
}
351351

352-
(&ty::Param(ref a_p), &ty::Param(ref b_p)) if a_p.index == b_p.index => Ok(a),
352+
(ty::Param(a_p), ty::Param(b_p)) if a_p.index == b_p.index => Ok(a),
353353

354354
(ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a),
355355

356-
(&ty::Adt(a_def, a_substs), &ty::Adt(b_def, b_substs)) if a_def == b_def => {
356+
(ty::Adt(a_def, a_substs), ty::Adt(b_def, b_substs)) if a_def == b_def => {
357357
let substs = relation.relate_item_substs(a_def.did, a_substs, b_substs)?;
358358
Ok(tcx.mk_adt(a_def, substs))
359359
}
360360

361-
(&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk_foreign(a_id)),
361+
(ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk_foreign(a_id)),
362362

363-
(&ty::Dynamic(a_obj, a_region), &ty::Dynamic(b_obj, b_region)) => {
363+
(ty::Dynamic(a_obj, a_region), ty::Dynamic(b_obj, b_region)) => {
364364
let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| {
365365
relation.relate_with_variance(ty::Contravariant, a_region, b_region)
366366
})?;
367367
Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound))
368368
}
369369

370-
(&ty::Generator(a_id, a_substs, movability), &ty::Generator(b_id, b_substs, _))
370+
(ty::Generator(a_id, a_substs, movability), ty::Generator(b_id, b_substs, _))
371371
if a_id == b_id =>
372372
{
373373
// All Generator types with the same id represent
@@ -377,7 +377,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
377377
Ok(tcx.mk_generator(a_id, substs, movability))
378378
}
379379

380-
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
380+
(ty::GeneratorWitness(a_types), ty::GeneratorWitness(b_types)) => {
381381
// Wrap our types with a temporary GeneratorWitness struct
382382
// inside the binder so we can related them
383383
let a_types = a_types.map_bound(GeneratorWitness);
@@ -387,28 +387,28 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
387387
Ok(tcx.mk_generator_witness(types))
388388
}
389389

390-
(&ty::Closure(a_id, a_substs), &ty::Closure(b_id, b_substs)) if a_id == b_id => {
390+
(ty::Closure(a_id, a_substs), ty::Closure(b_id, b_substs)) if a_id == b_id => {
391391
// All Closure types with the same id represent
392392
// the (anonymous) type of the same closure expression. So
393393
// all of their regions should be equated.
394394
let substs = relation.relate(a_substs, b_substs)?;
395395
Ok(tcx.mk_closure(a_id, &substs))
396396
}
397397

398-
(&ty::RawPtr(a_mt), &ty::RawPtr(b_mt)) => {
398+
(ty::RawPtr(a_mt), ty::RawPtr(b_mt)) => {
399399
let mt = relation.relate(a_mt, b_mt)?;
400400
Ok(tcx.mk_ptr(mt))
401401
}
402402

403-
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
403+
(ty::Ref(a_r, a_ty, a_mutbl), ty::Ref(b_r, b_ty, b_mutbl)) => {
404404
let r = relation.relate_with_variance(ty::Contravariant, a_r, b_r)?;
405405
let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl };
406406
let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl };
407407
let mt = relation.relate(a_mt, b_mt)?;
408408
Ok(tcx.mk_ref(r, mt))
409409
}
410410

411-
(&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => {
411+
(ty::Array(a_t, sz_a), ty::Array(b_t, sz_b)) => {
412412
let t = relation.relate(a_t, b_t)?;
413413
match relation.relate(sz_a, sz_b) {
414414
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
@@ -430,12 +430,12 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
430430
}
431431
}
432432

433-
(&ty::Slice(a_t), &ty::Slice(b_t)) => {
433+
(ty::Slice(a_t), ty::Slice(b_t)) => {
434434
let t = relation.relate(a_t, b_t)?;
435435
Ok(tcx.mk_slice(t))
436436
}
437437

438-
(&ty::Tuple(as_), &ty::Tuple(bs)) => {
438+
(ty::Tuple(as_), ty::Tuple(bs)) => {
439439
if as_.len() == bs.len() {
440440
Ok(tcx.mk_tup(
441441
as_.iter().zip(bs).map(|(a, b)| relation.relate(a.expect_ty(), b.expect_ty())),
@@ -447,25 +447,23 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
447447
}
448448
}
449449

450-
(&ty::FnDef(a_def_id, a_substs), &ty::FnDef(b_def_id, b_substs))
451-
if a_def_id == b_def_id =>
452-
{
450+
(ty::FnDef(a_def_id, a_substs), ty::FnDef(b_def_id, b_substs)) if a_def_id == b_def_id => {
453451
let substs = relation.relate_item_substs(a_def_id, a_substs, b_substs)?;
454452
Ok(tcx.mk_fn_def(a_def_id, substs))
455453
}
456454

457-
(&ty::FnPtr(a_fty), &ty::FnPtr(b_fty)) => {
455+
(ty::FnPtr(a_fty), ty::FnPtr(b_fty)) => {
458456
let fty = relation.relate(a_fty, b_fty)?;
459457
Ok(tcx.mk_fn_ptr(fty))
460458
}
461459

462460
// these two are already handled downstream in case of lazy normalization
463-
(&ty::Projection(a_data), &ty::Projection(b_data)) => {
461+
(ty::Projection(a_data), ty::Projection(b_data)) => {
464462
let projection_ty = relation.relate(a_data, b_data)?;
465463
Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs))
466464
}
467465

468-
(&ty::Opaque(a_def_id, a_substs), &ty::Opaque(b_def_id, b_substs))
466+
(ty::Opaque(a_def_id, a_substs), ty::Opaque(b_def_id, b_substs))
469467
if a_def_id == b_def_id =>
470468
{
471469
let substs = relate_substs(relation, None, a_substs, b_substs)?;

0 commit comments

Comments
 (0)