Skip to content

Commit

Permalink
Auto merge of rust-lang#116887 - lcnr:alias-ty-constructor, r=compile…
Browse files Browse the repository at this point in the history
…r-errors

`TyCtxt::mk_alias_ty` -> `AliasTy::new`
  • Loading branch information
bors committed Oct 18, 2023
2 parents e1de04a + 306a7ea commit e1aa9ed
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {

debug!(?args_trait_ref_and_assoc_item);

tcx.mk_alias_ty(assoc_item.def_id, args_trait_ref_and_assoc_item)
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
})
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);

let quiet_projection_ty =
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);

let term = pred.skip_binder().term;

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Type aliases defined in crates that have the
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of.
let alias_ty = tcx.mk_alias_ty(did, args);
let alias_ty = ty::AliasTy::new(tcx, did, args);
Ty::new_alias(tcx, ty::Weak, alias_ty)
} else {
tcx.at(span).type_of(did).instantiate(tcx, args)
Expand Down Expand Up @@ -1718,7 +1718,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.chain(args.into_iter().skip(parent_args.len())),
);

let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, args));
let ty = Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new(tcx, assoc_item, args));

return Ok(Some((ty, assoc_item)));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ pub(super) fn check_type_bounds<'tcx>(
_ => predicates.push(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
term: normalize_impl_ty.into(),
},
bound_vars,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);

let quiet_projection_ty =
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);

let term = pred.skip_binder().term;

Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,6 @@ impl<'tcx> TyCtxt<'tcx> {
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(_def_id))
{
// If this is an inherent projection.

generics.params.len() + 1
} else {
generics.count()
Expand Down Expand Up @@ -1897,15 +1896,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
}

pub fn mk_alias_ty(
self,
def_id: DefId,
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> ty::AliasTy<'tcx> {
let args = self.check_and_mk_args(def_id, args);
ty::AliasTy { def_id, args, _use_mk_alias_ty_instead: () }
}

pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
where
I: Iterator<Item = T>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl<'tcx> Term<'tcx> {
_ => None,
},
TermKind::Const(ct) => match ct.kind() {
ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.args)),
ConstKind::Unevaluated(uv) => Some(AliasTy::new(tcx, uv.def, uv.args)),
_ => None,
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
}
def => bug!("unknown alias DefKind: {def:?}"),
};
Ok(relation.tcx().mk_alias_ty(a.def_id, args))
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,20 @@ pub struct AliasTy<'tcx> {
pub def_id: DefId,

/// This field exists to prevent the creation of `AliasTy` without using
/// [TyCtxt::mk_alias_ty].
pub(super) _use_mk_alias_ty_instead: (),
/// [AliasTy::new].
_use_alias_ty_new_instead: (),
}

impl<'tcx> AliasTy<'tcx> {
pub fn new(
tcx: TyCtxt<'tcx>,
def_id: DefId,
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> ty::AliasTy<'tcx> {
let args = tcx.check_and_mk_args(def_id, args);
ty::AliasTy { def_id, args, _use_alias_ty_new_instead: () }
}

pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
match tcx.def_kind(self.def_id) {
DefKind::AssocTy
Expand Down Expand Up @@ -1245,7 +1254,7 @@ impl<'tcx> AliasTy<'tcx> {
}

pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
AliasTy::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
}
}

Expand Down Expand Up @@ -1667,8 +1676,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
debug_assert!(!self_ty.has_escaping_bound_vars());

ty::ProjectionPredicate {
projection_ty: tcx
.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args)),
projection_ty: AliasTy::new(
tcx,
self.def_id,
[self_ty.into()].into_iter().chain(self.args),
),
term: self.term,
}
}
Expand Down Expand Up @@ -1971,7 +1983,7 @@ impl<'tcx> Ty<'tcx> {

#[inline]
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, args))
Ty::new_alias(tcx, ty::Opaque, AliasTy::new(tcx, def_id, args))
}

/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
Expand Down Expand Up @@ -2135,7 +2147,7 @@ impl<'tcx> Ty<'tcx> {
item_def_id: DefId,
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> Ty<'tcx> {
Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, args))
Ty::new_alias(tcx, ty::Projection, AliasTy::new(tcx, item_def_id, args))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/solve/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
self.at.cause.clone(),
self.at.param_env,
ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(uv.def, uv.args),
projection_ty: AliasTy::new(tcx, uv.def, uv.args),
term: new_infer_ct.into(),
},
);
Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_trait_selection/src/solve/project_goals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {

let pred = tupled_inputs_and_output
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
projection_ty: tcx
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
projection_ty: ty::AliasTy::new(
tcx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), inputs],
),
term: output.into(),
})
.to_predicate(tcx);
Expand Down Expand Up @@ -472,7 +475,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
ecx,
goal,
ty::ProjectionPredicate {
projection_ty: ecx.tcx().mk_alias_ty(goal.predicate.def_id(), [self_ty]),
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
term,
}
.to_predicate(tcx),
Expand Down Expand Up @@ -512,9 +515,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
ecx,
goal,
ty::ProjectionPredicate {
projection_ty: ecx
.tcx()
.mk_alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]),
projection_ty: ty::AliasTy::new(
ecx.tcx(),
goal.predicate.def_id(),
[self_ty, generator.resume_ty()],
),
term,
}
.to_predicate(tcx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// This corresponds to `<ExprTy as Iterator>::Item = _`.
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::Projection(ty::ProjectionPredicate {
projection_ty: self.tcx.mk_alias_ty(proj.def_id, args),
projection_ty: ty::AliasTy::new(self.tcx, proj.def_id, args),
term: ty_var.into(),
}),
));
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
};

ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
term: ty.into(),
}
});
Expand Down Expand Up @@ -2116,7 +2116,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);

ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
term: return_ty.into(),
}
});
Expand Down Expand Up @@ -2172,7 +2172,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
};

let predicate =
ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, args), term };
ty::ProjectionPredicate { projection_ty: ty::AliasTy::new(tcx, item_def_id, args), term };

confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
.with_addl_obligations(obligations)
Expand Down Expand Up @@ -2245,7 +2245,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
flag,
)
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.args),
projection_ty: ty::AliasTy::new(tcx, fn_once_output_def_id, trait_ref.args),
term: ret_type.into(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let ty = traits::normalize_projection_type(
self,
param_env,
tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.args),
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
cause.clone(),
0,
// We're *intentionally* throwing these away,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ pub fn make_projection<'tcx>(
#[cfg(debug_assertions)]
assert_generic_args_match(tcx, assoc_item.def_id, args);

Some(tcx.mk_alias_ty(assoc_item.def_id, args))
Some(ty::AliasTy::new(tcx, assoc_item.def_id, args))
}
helper(
tcx,
Expand Down

0 comments on commit e1aa9ed

Please sign in to comment.