Skip to content

Change the return type of Ty::kind from &TyKind to TyKind. #126069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
&& let hir::ExprKind::Call(call, args) = parent_expr.kind
&& let ty::FnDef(def_id, _) = typeck.node_type(call.hir_id).kind()
{
(Some(*def_id), args, 0)
(Some(def_id), args, 0)
} else {
(None, &[][..], 0)
};
Expand Down Expand Up @@ -498,7 +498,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
.contains(&Some(predicate.def_id()))
&& let ty::Param(param) = predicate.self_ty().kind()
&& let generics = self.infcx.tcx.generics_of(def_id)
&& let param = generics.type_param(*param, self.infcx.tcx)
&& let param = generics.type_param(param, self.infcx.tcx)
&& param.def_id == param_def_id
{
if [
Expand Down Expand Up @@ -870,7 +870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
// These types seem reasonably opaque enough that they could be instantiated with their
// borrowed variants in a function body when we see a move error.
let borrow_level = match *ty.kind() {
let borrow_level = match ty.kind() {
ty::Param(_) => tcx
.explicit_predicates_of(self.mir_def_id().to_def_id())
.predicates
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
} else if let ty::Param(param) = ty.kind()
&& let Some(_clone_trait_def) = self.infcx.tcx.lang_items().clone_trait()
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
&& let generic_param = generics.type_param(*param, self.infcx.tcx)
&& let generic_param = generics.type_param(param, self.infcx.tcx)
&& let param_span = self.infcx.tcx.def_span(generic_param.def_id)
&& if let Some(UseSpans::FnSelfUse { kind, .. }) = use_spans
&& let CallKind::FnCall { fn_trait_id, self_ty } = kind
Expand Down Expand Up @@ -1436,7 +1436,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
.into_iter()
.map(|err| match err.obligation.predicate.kind().skip_binder() {
PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => {
match *predicate.self_ty().kind() {
match predicate.self_ty().kind() {
ty::Param(param_ty) => Ok((
generics.type_param(param_ty, tcx),
predicate.trait_ref.print_trait_sugared().to_string(),
Expand Down
57 changes: 27 additions & 30 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,40 +317,37 @@ impl<'tcx> BorrowExplanation<'tcx> {
let mut has_dyn = false;
let mut failed = false;

let elaborated_args =
std::iter::zip(*args, &generics.own_params).map(|(arg, param)| {
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
let default = tcx.object_lifetime_default(param.def_id);

let re_static = tcx.lifetimes.re_static;

let implied_region = match default {
// This is not entirely precise.
ObjectLifetimeDefault::Empty => re_static,
ObjectLifetimeDefault::Ambiguous => {
let elaborated_args = std::iter::zip(args, &generics.own_params).map(|(arg, param)| {
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
let default = tcx.object_lifetime_default(param.def_id);

let re_static = tcx.lifetimes.re_static;

let implied_region = match default {
// This is not entirely precise.
ObjectLifetimeDefault::Empty => re_static,
ObjectLifetimeDefault::Ambiguous => {
failed = true;
re_static
}
ObjectLifetimeDefault::Param(param_def_id) => {
let index = generics.param_def_id_to_index[&param_def_id] as usize;
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(|| {
failed = true;
re_static
}
ObjectLifetimeDefault::Param(param_def_id) => {
let index = generics.param_def_id_to_index[&param_def_id] as usize;
args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(
|| {
failed = true;
re_static
},
)
}
ObjectLifetimeDefault::Static => re_static,
};
})
}
ObjectLifetimeDefault::Static => re_static,
};

has_dyn = true;
has_dyn = true;

Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
} else {
arg
}
});
let elaborated_ty = Ty::new_adt(tcx, *def, tcx.mk_args_from_iter(elaborated_args));
Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
} else {
arg
}
});
let elaborated_ty = Ty::new_adt(tcx, def, tcx.mk_args_from_iter(elaborated_args));

if has_dyn && !failed {
err.note(format!(
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
..
} = &terminator.kind
{
if let ty::FnDef(id, _) = *const_.ty().kind() {
if let ty::FnDef(id, _) = const_.ty().kind() {
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
if self.infcx.tcx.is_lang_item(self.infcx.tcx.parent(id), LangItem::FnOnce) {
let closure = match args.first() {
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
// If the type is a box, the field is described from the boxed type
self.describe_field_from_ty(ty.boxed_ty(), field, variant_index, including_tuple_field)
} else {
match *ty.kind() {
match ty.kind() {
ty::Adt(def, _) => {
let variant = if let Some(idx) = variant_index {
assert!(def.is_enum());
Expand Down Expand Up @@ -459,7 +459,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
// this by hooking into the pretty printer and telling it to label the
// lifetimes without names with the value `'0`.
if let ty::Ref(region, ..) = ty.kind() {
match **region {
match *region {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand All @@ -479,7 +479,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);

let region = if let ty::Ref(region, ..) = ty.kind() {
match **region {
match *region {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
}

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

Expand Down Expand Up @@ -1048,7 +1048,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
// LL | blk();
// | ----- this value implements `FnOnce`, which causes it to be moved when called
// ```
if let ty::Param(param_ty) = *self_ty.kind()
if let ty::Param(param_ty) = self_ty.kind()
&& let generics = self.infcx.tcx.generics_of(self.mir_def_id())
&& let param = generics.type_param(param_ty, self.infcx.tcx)
&& let Some(hir_generics) = self
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
if suggest {
self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local);
let tcx = self.infcx.tcx;
if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() {
if let ty::Closure(id, _) = the_place_err.ty(self.body, tcx).ty.kind() {
self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err);
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {

let tcx = self.infcx.tcx;
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
&& let ty::Closure(id, _) = *ty.kind()
&& let ty::Closure(id, _) = ty.kind()
{
self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err);
}
Expand Down Expand Up @@ -953,7 +953,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
if let Some(ty::FnDef(def_id, _)) =
typeck_results.node_type_opt(expr.hir_id).as_ref().map(|ty| ty.kind())
{
Some((*def_id, expr.span, *args))
Some((def_id, expr.span, *args))
} else {
None
}
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
ty::VarianceDiagInfo::Invariant { ty, param_index } => {
let (desc, note) = match ty.kind() {
ty::RawPtr(ty, mutbl) => {
assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
assert_eq!(mutbl, rustc_hir::Mutability::Mut);
(
format!("a mutable pointer to `{}`", ty),
"mutable pointers are invariant over their type parameter".to_string(),
)
}
ty::Ref(_, inner_ty, mutbl) => {
assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
assert_eq!(mutbl, rustc_hir::Mutability::Mut);
(
format!("a mutable reference to `{inner_ty}`"),
"mutable references are invariant over their type parameter"
Expand All @@ -525,7 +525,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let generic_arg = args[param_index as usize];
let identity_args =
GenericArgs::identity_for_item(self.infcx.tcx, adt.did());
let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_args);
let base_ty = Ty::new_adt(self.infcx.tcx, adt, identity_args);
let base_generic_arg = identity_args[param_index as usize];
let adt_desc = adt.descr();

Expand All @@ -538,8 +538,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
(desc, note)
}
ty::FnDef(def_id, _) => {
let name = self.infcx.tcx.item_name(*def_id);
let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, *def_id);
let name = self.infcx.tcx.item_name(def_id);
let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, def_id);
let desc = format!("a function pointer to `{name}`");
let note = format!(
"the function `{name}` is invariant over the parameter `{}`",
Expand Down Expand Up @@ -591,7 +591,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;

let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = output_ty.kind() {
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity()
};

Expand All @@ -600,7 +600,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let err = FnMutError {
span: *span,
ty_err: match output_ty.kind() {
ty::Coroutine(def, ..) if self.infcx.tcx.coroutine_is_async(*def) => {
ty::Coroutine(def, ..) if self.infcx.tcx.coroutine_is_async(def) => {
FnMutReturnTypeErr::ReturnAsyncBlock { span: *span }
}
_ if output_ty.contains_closure() => {
Expand Down Expand Up @@ -949,7 +949,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
if let Ok(Some(instance)) = ty::Instance::try_resolve(
tcx,
self.param_env,
*fn_did,
fn_did,
self.infcx.resolve_vars_if_possible(args),
) {
instance
Expand Down Expand Up @@ -1061,8 +1061,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
else {
return;
};
let ty::Closure(_, args) = *tcx.type_of(closure_def_id).instantiate_identity().kind()
else {
let ty::Closure(_, args) = tcx.type_of(closure_def_id).instantiate_identity().kind() else {
return;
};
let args = args.as_closure();
Expand All @@ -1083,7 +1082,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
let liberated_sig = tcx.liberate_late_bound_regions(closure_def_id.to_def_id(), args.sig());
let mut peeled_ty = liberated_sig.output();
let mut count = 0;
while let ty::Ref(_, ref_ty, _) = *peeled_ty.kind() {
while let ty::Ref(_, ref_ty, _) = peeled_ty.kind() {
peeled_ty = ref_ty;
count += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
}

// Otherwise, let's descend into the referent types.
search_stack.push((*referent_ty, referent_hir_ty.ty));
search_stack.push((referent_ty, referent_hir_ty.ty));
}

// Match up something like `Foo<'1>`
Expand Down Expand Up @@ -552,17 +552,17 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
// The following cases don't have lifetimes, so we
// just worry about trying to match up the rustc type
// with the HIR types:
(&ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
(ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => {
search_stack.extend(iter::zip(elem_tys, *elem_hir_tys));
}

(ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty))
| (ty::Array(elem_ty, _), hir::TyKind::Array(elem_hir_ty, _)) => {
search_stack.push((*elem_ty, elem_hir_ty));
search_stack.push((elem_ty, elem_hir_ty));
}

(ty::RawPtr(mut_ty, _), hir::TyKind::Ptr(mut_hir_ty)) => {
search_stack.push((*mut_ty, mut_hir_ty.ty));
search_stack.push((mut_ty, mut_hir_ty.ty));
}

_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn do_mir_borrowck<'tcx>(
// The first argument is the coroutine type passed by value
if let Some(local) = body.local_decls.raw.get(1)
// Get the interior types and args which typeck computed
&& let ty::Coroutine(def_id, _) = *local.ty.kind()
&& let ty::Coroutine(def_id, _) = local.ty.kind()
&& tcx.coroutine_movability(def_id) == hir::Movability::Movable
{
true
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
use ty::TypeSuperFoldable as _;
let tcx = self.tcx;
let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
let ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else {
return t.super_fold_with(self);
};
let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| {
Expand Down
Loading
Loading