Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 50a3cde

Browse files
committedJun 6, 2024
Change the return type of Ty::kind from TyKind to &TyKind.
This is valid because `TyKind` impls `Copy`, and makes `Ty` consistent with `Predicate` and `Region`, both of which have `kind` methods that return a non-reference. The change removes more than one thousand `&` and `*` sigils, while requiring the addition of just five! It's clearly moving with the grain of the existing code. Almost all of the removed sigils fit one of the following three patterns. - Remove the dereference in the match expression: `match *ty.kind() { ... }` -> `match ty.kind() { ... }` - Remove the dereference in the match pattern: `match ty.kind() { &ty::Foo(foo) => { ... foo ... }` -> `match ty.kind() { ty::Foo(foo) => { ... foo ... }` - Remove the derefernce in the match arm: `match ty.kind() { ty::Foo(foo) => { ... *foo ... }` -> `match ty.kind() { ty::Foo(foo) => { ... foo ... }` A couple of other methods had their signatures changed. - `TypeErrCtxt::cmp_fn_sig`: `&` removed from two args. - `EncodableWithShorthand::variant`: `&` removed from return type.
1 parent 2b6a342 commit 50a3cde

File tree

322 files changed

+1092
-1130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+1092
-1130
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
721721
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
722722
// These types seem reasonably opaque enough that they could be instantiated with their
723723
// borrowed variants in a function body when we see a move error.
724-
let borrow_level = match *ty.kind() {
724+
let borrow_level = match ty.kind() {
725725
ty::Param(_) => tcx
726726
.explicit_predicates_of(self.mir_def_id().to_def_id())
727727
.predicates
@@ -1210,7 +1210,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12101210
} else if let ty::Param(param) = ty.kind()
12111211
&& let Some(_clone_trait_def) = self.infcx.tcx.lang_items().clone_trait()
12121212
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
1213-
&& let generic_param = generics.type_param(*param, self.infcx.tcx)
1213+
&& let generic_param = generics.type_param(param, self.infcx.tcx)
12141214
&& let param_span = self.infcx.tcx.def_span(generic_param.def_id)
12151215
&& if let Some(UseSpans::FnSelfUse { kind, .. }) = use_spans
12161216
&& let CallKind::FnCall { fn_trait_id, self_ty } = kind
@@ -1358,7 +1358,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13581358
.into_iter()
13591359
.map(|err| match err.obligation.predicate.kind().skip_binder() {
13601360
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
1361-
match *predicate.self_ty().kind() {
1361+
match predicate.self_ty().kind() {
13621362
ty::Param(param_ty) => Ok((
13631363
generics.type_param(param_ty, tcx),
13641364
predicate.trait_ref.print_trait_sugared().to_string(),

‎compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs‎

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -317,40 +317,37 @@ impl<'tcx> BorrowExplanation<'tcx> {
317317
let mut has_dyn = false;
318318
let mut failed = false;
319319

320-
let elaborated_args =
321-
std::iter::zip(*args, &generics.own_params).map(|(arg, param)| {
322-
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
323-
let default = tcx.object_lifetime_default(param.def_id);
324-
325-
let re_static = tcx.lifetimes.re_static;
326-
327-
let implied_region = match default {
328-
// This is not entirely precise.
329-
ObjectLifetimeDefault::Empty => re_static,
330-
ObjectLifetimeDefault::Ambiguous => {
320+
let elaborated_args = std::iter::zip(args, &generics.own_params).map(|(arg, param)| {
321+
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
322+
let default = tcx.object_lifetime_default(param.def_id);
323+
324+
let re_static = tcx.lifetimes.re_static;
325+
326+
let implied_region = match default {
327+
// This is not entirely precise.
328+
ObjectLifetimeDefault::Empty => re_static,
329+
ObjectLifetimeDefault::Ambiguous => {
330+
failed = true;
331+
re_static
332+
}
333+
ObjectLifetimeDefault::Param(param_def_id) => {
334+
let index = generics.param_def_id_to_index[&param_def_id] as usize;
335+
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(|| {
331336
failed = true;
332337
re_static
333-
}
334-
ObjectLifetimeDefault::Param(param_def_id) => {
335-
let index = generics.param_def_id_to_index[&param_def_id] as usize;
336-
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(
337-
|| {
338-
failed = true;
339-
re_static
340-
},
341-
)
342-
}
343-
ObjectLifetimeDefault::Static => re_static,
344-
};
338+
})
339+
}
340+
ObjectLifetimeDefault::Static => re_static,
341+
};
345342

346-
has_dyn = true;
343+
has_dyn = true;
347344

348-
Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
349-
} else {
350-
arg
351-
}
352-
});
353-
let elaborated_ty = Ty::new_adt(tcx, *def, tcx.mk_args_from_iter(elaborated_args));
345+
Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
346+
} else {
347+
arg
348+
}
349+
});
350+
let elaborated_ty = Ty::new_adt(tcx, def, tcx.mk_args_from_iter(elaborated_args));
354351

355352
if has_dyn && !failed {
356353
err.note(format!(

‎compiler/rustc_borrowck/src/diagnostics/mod.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
114114
..
115115
} = &terminator.kind
116116
{
117-
if let ty::FnDef(id, _) = *const_.ty().kind() {
117+
if let ty::FnDef(id, _) = const_.ty().kind() {
118118
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
119119
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
120120
let closure = match args.first() {
@@ -356,7 +356,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
356356
// If the type is a box, the field is described from the boxed type
357357
self.describe_field_from_ty(ty.boxed_ty(), field, variant_index, including_tuple_field)
358358
} else {
359-
match *ty.kind() {
359+
match ty.kind() {
360360
ty::Adt(def, _) => {
361361
let variant = if let Some(idx) = variant_index {
362362
assert!(def.is_enum());
@@ -467,7 +467,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
467467
// this by hooking into the pretty printer and telling it to label the
468468
// lifetimes without names with the value `'0`.
469469
if let ty::Ref(region, ..) = ty.kind() {
470-
match **region {
470+
match *region {
471471
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
472472
| ty::RePlaceholder(ty::PlaceholderRegion {
473473
bound: ty::BoundRegion { kind: br, .. },
@@ -487,7 +487,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
487487
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
488488

489489
let region = if let ty::Ref(region, ..) = ty.kind() {
490-
match **region {
490+
match *region {
491491
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
492492
| ty::RePlaceholder(ty::PlaceholderRegion {
493493
bound: ty::BoundRegion { kind: br, .. },
@@ -763,7 +763,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
763763
}
764764

765765
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
766-
match *func.kind() {
766+
match func.kind() {
767767
ty::FnDef(def_id, args) => {
768768
let trait_id = tcx.trait_of_item(def_id)?;
769769

@@ -1073,7 +1073,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10731073
// LL | blk();
10741074
// | ----- this value implements `FnOnce`, which causes it to be moved when called
10751075
// ```
1076-
if let ty::Param(param_ty) = *self_ty.kind()
1076+
if let ty::Param(param_ty) = self_ty.kind()
10771077
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
10781078
&& let param = generics.type_param(param_ty, self.infcx.tcx)
10791079
&& let Some(hir_generics) = self

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
377377
if suggest {
378378
self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local);
379379
let tcx = self.infcx.tcx;
380-
if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() {
380+
if let ty::Closure(id, _) = the_place_err.ty(self.body, tcx).ty.kind() {
381381
self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err);
382382
}
383383
}
@@ -431,7 +431,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
431431

432432
let tcx = self.infcx.tcx;
433433
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
434-
&& let ty::Closure(id, _) = *ty.kind()
434+
&& let ty::Closure(id, _) = ty.kind()
435435
{
436436
self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err);
437437
}
@@ -950,7 +950,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
950950
if let Some(ty::FnDef(def_id, _)) =
951951
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())
952952
{
953-
let arg = match hir.get_if_local(*def_id) {
953+
let arg = match hir.get_if_local(def_id) {
954954
Some(
955955
hir::Node::Item(hir::Item {
956956
ident, kind: hir::ItemKind::Fn(sig, ..), ..

0 commit comments

Comments
 (0)