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!(

0 commit comments

Comments
 (0)
Please sign in to comment.