Move TyCtxt::mk_x
to Ty::new_x
where applicable
This commit is contained in:
parent
5dac6b320b
commit
12138b8e5e
164 changed files with 1386 additions and 1185 deletions
|
@ -363,7 +363,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
|||
);
|
||||
emitted_bad_param_err = true;
|
||||
}
|
||||
tcx.mk_bound(
|
||||
Ty::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
ty::BoundTy {
|
||||
var: ty::BoundVar::from_usize(num_bound_vars),
|
||||
|
@ -527,7 +528,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
|||
}
|
||||
let reported = err.emit();
|
||||
term = match def_kind {
|
||||
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(),
|
||||
hir::def::DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
|
||||
hir::def::DefKind::AssocConst => ty::Const::new_error(
|
||||
tcx,
|
||||
reported,
|
||||
|
@ -558,7 +559,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
|||
// type bound into a trait predicate, since we only want to add predicates
|
||||
// for the `Self` type.
|
||||
if !only_self_bounds.0 {
|
||||
let param_ty = tcx.mk_alias(ty::Projection, projection_ty.skip_binder());
|
||||
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
|
||||
self.add_bounds(
|
||||
param_ty,
|
||||
ast_bounds.iter(),
|
||||
|
|
|
@ -357,7 +357,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let projection_ty = pred.skip_binder().projection_ty;
|
||||
|
||||
let substs_with_infer_self = tcx.mk_substs_from_iter(
|
||||
std::iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into())
|
||||
std::iter::once(Ty::new_var(tcx, ty::TyVid::from_u32(0)).into())
|
||||
.chain(projection_ty.substs.iter().skip(1)),
|
||||
);
|
||||
|
||||
|
|
|
@ -443,7 +443,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) {
|
||||
self.inferred_params.push(ty.span);
|
||||
tcx.ty_error_misc().into()
|
||||
Ty::new_misc_error(tcx).into()
|
||||
} else {
|
||||
self.astconv.ast_ty_to_ty(ty).into()
|
||||
}
|
||||
|
@ -512,14 +512,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
_ => false,
|
||||
}) {
|
||||
// Avoid ICE #86756 when type error recovery goes awry.
|
||||
return tcx.ty_error_misc().into();
|
||||
return Ty::new_misc_error(tcx).into();
|
||||
}
|
||||
tcx.at(self.span).type_of(param.def_id).subst(tcx, substs).into()
|
||||
} else if infer_args {
|
||||
self.astconv.ty_infer(Some(param), self.span).into()
|
||||
} else {
|
||||
// We've already errored above about the mismatch.
|
||||
tcx.ty_error_misc().into()
|
||||
Ty::new_misc_error(tcx).into()
|
||||
}
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
|
@ -912,7 +912,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// referencing a single opaque type) get encoded as a type alias that normalization will
|
||||
// then actually instantiate the where bounds of.
|
||||
let alias_ty = self.tcx().mk_alias_ty(did, substs);
|
||||
self.tcx().mk_alias(ty::Weak, alias_ty)
|
||||
Ty::new_alias(self.tcx(), ty::Weak, alias_ty)
|
||||
} else {
|
||||
ty.subst(self.tcx(), substs)
|
||||
}
|
||||
|
@ -1573,10 +1573,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
match *ty.kind() {
|
||||
ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||
universe: self.universe,
|
||||
bound: bv,
|
||||
}),
|
||||
ty::Bound(_, bv) => Ty::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderType { universe: self.universe, bound: bv },
|
||||
),
|
||||
_ => ty.super_fold_with(self),
|
||||
}
|
||||
}
|
||||
|
@ -1665,7 +1665,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.chain(substs.into_iter().skip(parent_substs.len())),
|
||||
);
|
||||
|
||||
let ty = tcx.mk_alias(ty::Inherent, tcx.mk_alias_ty(assoc_item, substs));
|
||||
let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, substs));
|
||||
|
||||
return Ok(Some((ty, assoc_item)));
|
||||
}
|
||||
|
@ -1850,7 +1850,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
&[path_str],
|
||||
item_segment.ident.name,
|
||||
);
|
||||
return tcx.ty_error(reported)
|
||||
return Ty::new_error(tcx,reported)
|
||||
};
|
||||
|
||||
debug!("qpath_to_ty: self_type={:?}", self_ty);
|
||||
|
@ -1873,7 +1873,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
|
||||
|
||||
tcx.mk_projection(item_def_id, item_substs)
|
||||
Ty::new_projection(tcx, item_def_id, item_substs)
|
||||
}
|
||||
|
||||
pub fn prohibit_generics<'a>(
|
||||
|
@ -2136,7 +2136,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
err.note("`impl Trait` types can't have type parameters");
|
||||
});
|
||||
let substs = self.ast_path_substs_for_ty(span, did, item_segment.0);
|
||||
tcx.mk_opaque(did, substs)
|
||||
Ty::new_opaque(tcx, did, substs)
|
||||
}
|
||||
Res::Def(
|
||||
DefKind::Enum
|
||||
|
@ -2188,16 +2188,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
var: ty::BoundVar::from_u32(index),
|
||||
kind: ty::BoundTyKind::Param(def_id, name),
|
||||
};
|
||||
tcx.mk_bound(debruijn, br)
|
||||
Ty::new_bound(tcx, debruijn, br)
|
||||
}
|
||||
Some(rbv::ResolvedArg::EarlyBound(_)) => {
|
||||
let def_id = def_id.expect_local();
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id))
|
||||
Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id))
|
||||
}
|
||||
Some(rbv::ResolvedArg::Error(guar)) => tcx.ty_error(guar),
|
||||
Some(rbv::ResolvedArg::Error(guar)) => Ty::new_error(tcx, guar),
|
||||
arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -2309,7 +2309,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
{
|
||||
err.span_note(impl_.self_ty.span, "not a concrete type");
|
||||
}
|
||||
tcx.ty_error(err.emit())
|
||||
Ty::new_error(tcx, err.emit())
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
|
@ -2350,9 +2350,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
match prim_ty {
|
||||
hir::PrimTy::Bool => tcx.types.bool,
|
||||
hir::PrimTy::Char => tcx.types.char,
|
||||
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)),
|
||||
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)),
|
||||
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)),
|
||||
hir::PrimTy::Int(it) => Ty::new_int(tcx, ty::int_ty(it)),
|
||||
hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, ty::uint_ty(uit)),
|
||||
hir::PrimTy::Float(ft) => Ty::new_float(tcx, ty::float_ty(ft)),
|
||||
hir::PrimTy::Str => tcx.types.str_,
|
||||
}
|
||||
}
|
||||
|
@ -2362,7 +2362,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.sess
|
||||
.delay_span_bug(path.span, "path with `Res::Err` but no error emitted");
|
||||
self.set_tainted_by_errors(e);
|
||||
self.tcx().ty_error(e)
|
||||
Ty::new_error(self.tcx(), e)
|
||||
}
|
||||
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
|
||||
}
|
||||
|
@ -2387,31 +2387,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let tcx = self.tcx();
|
||||
|
||||
let result_ty = match &ast_ty.kind {
|
||||
hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
|
||||
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)),
|
||||
hir::TyKind::Ptr(mt) => {
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
|
||||
}
|
||||
hir::TyKind::Ref(region, mt) => {
|
||||
let r = self.ast_region_to_region(region, None);
|
||||
debug!(?r);
|
||||
let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
|
||||
tcx.mk_ref(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
|
||||
Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
|
||||
}
|
||||
hir::TyKind::Never => tcx.types.never,
|
||||
hir::TyKind::Tup(fields) => {
|
||||
tcx.mk_tup_from_iter(fields.iter().map(|t| self.ast_ty_to_ty(t)))
|
||||
Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.ast_ty_to_ty(t)))
|
||||
}
|
||||
hir::TyKind::BareFn(bf) => {
|
||||
require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span);
|
||||
|
||||
tcx.mk_fn_ptr(self.ty_of_fn(
|
||||
ast_ty.hir_id,
|
||||
bf.unsafety,
|
||||
bf.abi,
|
||||
bf.decl,
|
||||
None,
|
||||
Some(ast_ty),
|
||||
))
|
||||
Ty::new_fn_ptr(
|
||||
tcx,
|
||||
self.ty_of_fn(ast_ty.hir_id, bf.unsafety, bf.abi, bf.decl, None, Some(ast_ty)),
|
||||
)
|
||||
}
|
||||
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
|
||||
self.maybe_lint_bare_trait(ast_ty, in_path);
|
||||
|
@ -2458,7 +2454,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let ty = self.ast_ty_to_ty_inner(qself, false, true);
|
||||
self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
|
||||
.map(|(ty, _, _)| ty)
|
||||
.unwrap_or_else(|guar| tcx.ty_error(guar))
|
||||
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
|
||||
}
|
||||
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
|
||||
let def_id = tcx.require_lang_item(lang_item, Some(span));
|
||||
|
@ -2482,7 +2478,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
};
|
||||
|
||||
tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length)
|
||||
Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
|
||||
}
|
||||
hir::TyKind::Typeof(e) => {
|
||||
let ty_erased = tcx.type_of(e.def_id).subst_identity();
|
||||
|
@ -2506,7 +2502,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// handled specially and will not descend into this routine.
|
||||
self.ty_infer(None, ast_ty.span)
|
||||
}
|
||||
hir::TyKind::Err(guar) => tcx.ty_error(*guar),
|
||||
hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
|
||||
};
|
||||
|
||||
self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span);
|
||||
|
@ -2543,7 +2539,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
});
|
||||
debug!("impl_trait_ty_to_ty: substs={:?}", substs);
|
||||
|
||||
if in_trait { tcx.mk_projection(def_id, substs) } else { tcx.mk_opaque(def_id, substs) }
|
||||
if in_trait {
|
||||
Ty::new_projection(tcx, def_id, substs)
|
||||
} else {
|
||||
Ty::new_opaque(tcx, def_id, substs)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
|
||||
|
@ -2612,7 +2612,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
self.ast_ty_to_ty(output)
|
||||
}
|
||||
}
|
||||
hir::FnRetTy::DefaultReturn(..) => tcx.mk_unit(),
|
||||
hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx,),
|
||||
};
|
||||
|
||||
debug!(?output_ty);
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.map(|trait_ref| tcx.def_span(trait_ref));
|
||||
let reported =
|
||||
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
|
||||
return tcx.ty_error(reported);
|
||||
return Ty::new_error(tcx, reported);
|
||||
}
|
||||
|
||||
// Check that there are no gross object safety violations;
|
||||
|
@ -148,7 +148,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
&object_safety_violations,
|
||||
)
|
||||
.emit();
|
||||
return tcx.ty_error(reported);
|
||||
return Ty::new_error(tcx, reported);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,10 +271,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
if arg == dummy_self.into() {
|
||||
let param = &generics.params[index];
|
||||
missing_type_params.push(param.name);
|
||||
return tcx.ty_error_misc().into();
|
||||
return Ty::new_misc_error(tcx).into();
|
||||
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
|
||||
references_self = true;
|
||||
return tcx.ty_error_misc().into();
|
||||
return Ty::new_misc_error(tcx).into();
|
||||
}
|
||||
arg
|
||||
})
|
||||
|
@ -342,7 +342,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.iter()
|
||||
.map(|arg| {
|
||||
if arg.walk().any(|arg| arg == dummy_self.into()) {
|
||||
return tcx.ty_error(guar).into();
|
||||
return Ty::new_error(tcx, guar).into();
|
||||
}
|
||||
arg
|
||||
})
|
||||
|
@ -401,7 +401,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
};
|
||||
debug!("region_bound: {:?}", region_bound);
|
||||
|
||||
let ty = tcx.mk_dynamic(existential_predicates, region_bound, representation);
|
||||
let ty = Ty::new_dynamic(tcx, existential_predicates, region_bound, representation);
|
||||
debug!("trait_object_type: {:?}", ty);
|
||||
ty
|
||||
}
|
||||
|
|
|
@ -148,8 +148,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let (normalized_ty, obligations) =
|
||||
self.structurally_normalize(tcx.mk_projection(tcx.lang_items().deref_target()?, [ty]))?;
|
||||
let (normalized_ty, obligations) = self.structurally_normalize(Ty::new_projection(
|
||||
tcx,
|
||||
tcx.lang_items().deref_target()?,
|
||||
[ty],
|
||||
))?;
|
||||
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
|
||||
self.state.obligations.extend(obligations);
|
||||
|
||||
|
|
|
@ -308,9 +308,9 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
|||
{
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let opaque_identity_ty = if in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||
Ty::new_projection(tcx, def_id.to_def_id(), substs)
|
||||
} else {
|
||||
tcx.mk_opaque(def_id.to_def_id(), substs)
|
||||
Ty::new_opaque(tcx, def_id.to_def_id(), substs)
|
||||
};
|
||||
let mut visitor = ProhibitOpaqueVisitor {
|
||||
opaque_identity_ty,
|
||||
|
@ -410,7 +410,7 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs);
|
||||
let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), substs);
|
||||
|
||||
// `ReErased` regions appear in the "parent_substs" of closures/generators.
|
||||
// We're ignoring them here and replacing them with fresh region variables.
|
||||
|
|
|
@ -271,7 +271,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
infer::HigherRankedType,
|
||||
tcx.fn_sig(impl_m.def_id).subst_identity(),
|
||||
);
|
||||
let unnormalized_impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(unnormalized_impl_sig));
|
||||
let unnormalized_impl_fty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(unnormalized_impl_sig));
|
||||
|
||||
let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id);
|
||||
let impl_sig = ocx.normalize(&norm_cause, param_env, unnormalized_impl_sig);
|
||||
|
@ -288,7 +288,7 @@ fn compare_method_predicate_entailment<'tcx>(
|
|||
// We also have to add the normalized trait signature
|
||||
// as we don't normalize during implied bounds computation.
|
||||
wf_tys.extend(trait_sig.inputs_and_output.iter());
|
||||
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));
|
||||
let trait_fty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(trait_sig));
|
||||
|
||||
debug!("compare_impl_method: trait_fty={:?}", trait_fty);
|
||||
|
||||
|
@ -803,7 +803,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
return_span,
|
||||
}) {
|
||||
Ok(ty) => ty,
|
||||
Err(guar) => tcx.ty_error(guar),
|
||||
Err(guar) => Ty::new_error(tcx, guar),
|
||||
};
|
||||
collected_tys.insert(def_id, ty::EarlyBinder::bind(ty));
|
||||
}
|
||||
|
@ -812,7 +812,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
return_span,
|
||||
format!("could not fully resolve: {ty} => {err:?}"),
|
||||
);
|
||||
collected_tys.insert(def_id, ty::EarlyBinder::bind(tcx.ty_error(reported)));
|
||||
collected_tys.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -916,7 +916,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
|
|||
_ => arg.try_fold_with(self)?,
|
||||
});
|
||||
}
|
||||
Ok(self.tcx.mk_opaque(def_id, self.tcx.mk_substs(&mapped_substs)))
|
||||
Ok(Ty::new_opaque(self.tcx, def_id, self.tcx.mk_substs(&mapped_substs)))
|
||||
} else {
|
||||
t.try_super_fold_with(self)
|
||||
}
|
||||
|
@ -2027,7 +2027,8 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
let kind = ty::BoundTyKind::Param(param.def_id, param.name);
|
||||
let bound_var = ty::BoundVariableKind::Ty(kind);
|
||||
bound_vars.push(bound_var);
|
||||
tcx.mk_bound(
|
||||
Ty::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@ use hir::def_id::DefId;
|
|||
use rustc_errors::{struct_span_err, DiagnosticMessage};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
|
@ -53,14 +53,14 @@ fn equate_intrinsic_type<'tcx>(
|
|||
&& gen_count_ok(own_counts.types, n_tps, "type")
|
||||
&& gen_count_ok(own_counts.consts, 0, "const")
|
||||
{
|
||||
let fty = tcx.mk_fn_ptr(sig);
|
||||
let fty = Ty::new_fn_ptr(tcx, sig);
|
||||
let it_def_id = it.owner_id.def_id;
|
||||
let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType);
|
||||
require_same_types(
|
||||
tcx,
|
||||
&cause,
|
||||
ty::ParamEnv::empty(), // FIXME: do all intrinsics have an empty param env?
|
||||
tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()),
|
||||
Ty::new_fn_ptr(tcx, tcx.fn_sig(it.owner_id).subst_identity()),
|
||||
fty,
|
||||
);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
|
|||
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
|
||||
/// and in `library/core/src/intrinsics.rs`.
|
||||
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)));
|
||||
let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{}", n)));
|
||||
let intrinsic_id = it.owner_id.to_def_id();
|
||||
let intrinsic_name = tcx.item_name(intrinsic_id);
|
||||
let name_str = intrinsic_name.as_str();
|
||||
|
@ -156,7 +156,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
|
||||
);
|
||||
let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]);
|
||||
(tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
|
||||
(Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -168,15 +168,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
let (n_tps, inputs, output) = match split[1] {
|
||||
"cxchg" | "cxchgweak" => (
|
||||
1,
|
||||
vec![tcx.mk_mut_ptr(param(0)), param(0), param(0)],
|
||||
tcx.mk_tup(&[param(0), tcx.types.bool]),
|
||||
vec![Ty::new_mut_ptr(tcx, param(0)), param(0), param(0)],
|
||||
Ty::new_tup(tcx, &[param(0), tcx.types.bool]),
|
||||
),
|
||||
"load" => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)),
|
||||
"store" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
|
||||
"load" => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
|
||||
"store" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx)),
|
||||
|
||||
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax"
|
||||
| "umin" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], param(0)),
|
||||
"fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk_unit()),
|
||||
| "umin" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], param(0)),
|
||||
"fence" | "singlethreadfence" => (0, Vec::new(), Ty::new_unit(tcx)),
|
||||
op => {
|
||||
tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op });
|
||||
return;
|
||||
|
@ -188,19 +188,19 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
let (n_tps, inputs, output) = match intrinsic_name {
|
||||
sym::abort => (0, Vec::new(), tcx.types.never),
|
||||
sym::unreachable => (0, Vec::new(), tcx.types.never),
|
||||
sym::breakpoint => (0, Vec::new(), tcx.mk_unit()),
|
||||
sym::breakpoint => (0, Vec::new(), Ty::new_unit(tcx)),
|
||||
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
|
||||
(1, Vec::new(), tcx.types.usize)
|
||||
}
|
||||
sym::size_of_val | sym::min_align_of_val => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0))], tcx.types.usize)
|
||||
(1, vec![Ty::new_imm_ptr(tcx, param(0))], tcx.types.usize)
|
||||
}
|
||||
sym::rustc_peek => (1, vec![param(0)], param(0)),
|
||||
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
|
||||
sym::assert_inhabited
|
||||
| sym::assert_zero_valid
|
||||
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()),
|
||||
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
|
||||
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), Ty::new_unit(tcx)),
|
||||
sym::forget => (1, vec![param(0)], Ty::new_unit(tcx)),
|
||||
sym::transmute | sym::transmute_unchecked => (2, vec![param(0)], param(1)),
|
||||
sym::prefetch_read_data
|
||||
| sym::prefetch_write_data
|
||||
|
@ -208,75 +208,79 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
| sym::prefetch_write_instruction => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.types.i32,
|
||||
],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
),
|
||||
sym::drop_in_place => (1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_unit()),
|
||||
sym::drop_in_place => (1, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_unit(tcx)),
|
||||
sym::needs_drop => (1, Vec::new(), tcx.types.bool),
|
||||
|
||||
sym::type_name => (1, Vec::new(), tcx.mk_static_str()),
|
||||
sym::type_name => (1, Vec::new(), Ty::new_static_str(tcx)),
|
||||
sym::type_id => (1, Vec::new(), tcx.types.u128),
|
||||
sym::offset => (2, vec![param(0), param(1)], param(0)),
|
||||
sym::arith_offset => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.types.isize,
|
||||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
),
|
||||
sym::option_payload_ptr => {
|
||||
let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None);
|
||||
let p0 = param(0);
|
||||
(
|
||||
1,
|
||||
vec![tcx.mk_ptr(ty::TypeAndMut {
|
||||
ty: tcx.mk_adt(
|
||||
tcx.adt_def(option_def_id),
|
||||
tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()),
|
||||
),
|
||||
mutbl: hir::Mutability::Not,
|
||||
})],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
|
||||
vec![Ty::new_ptr(
|
||||
tcx,
|
||||
ty::TypeAndMut {
|
||||
ty: Ty::new_adt(
|
||||
tcx,
|
||||
tcx.adt_def(option_def_id),
|
||||
tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()),
|
||||
),
|
||||
mutbl: hir::Mutability::Not,
|
||||
},
|
||||
)],
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
|
||||
)
|
||||
}
|
||||
sym::ptr_mask => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.types.usize,
|
||||
],
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
),
|
||||
|
||||
sym::copy | sym::copy_nonoverlapping => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
tcx.types.usize,
|
||||
],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
),
|
||||
sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
|
||||
tcx.types.usize,
|
||||
],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
),
|
||||
sym::write_bytes | sym::volatile_set_memory => (
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }),
|
||||
tcx.types.u8,
|
||||
tcx.types.usize,
|
||||
],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
),
|
||||
sym::sqrtf32 => (0, vec![tcx.types.f32], tcx.types.f32),
|
||||
sym::sqrtf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
||||
|
@ -324,10 +328,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
sym::roundevenf64 => (0, vec![tcx.types.f64], tcx.types.f64),
|
||||
|
||||
sym::volatile_load | sym::unaligned_volatile_load => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0))], param(0))
|
||||
(1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0))
|
||||
}
|
||||
sym::volatile_store | sym::unaligned_volatile_store => {
|
||||
(1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit())
|
||||
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
||||
}
|
||||
|
||||
sym::ctpop
|
||||
|
@ -339,28 +343,34 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
| sym::bitreverse => (1, vec![param(0)], param(0)),
|
||||
|
||||
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
|
||||
(1, vec![param(0), param(0)], tcx.mk_tup(&[param(0), tcx.types.bool]))
|
||||
(1, vec![param(0), param(0)], Ty::new_tup(tcx, &[param(0), tcx.types.bool]))
|
||||
}
|
||||
|
||||
sym::ptr_guaranteed_cmp => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.u8)
|
||||
}
|
||||
sym::ptr_guaranteed_cmp => (
|
||||
1,
|
||||
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
||||
tcx.types.u8,
|
||||
),
|
||||
|
||||
sym::const_allocate => {
|
||||
(0, vec![tcx.types.usize, tcx.types.usize], tcx.mk_mut_ptr(tcx.types.u8))
|
||||
(0, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
|
||||
}
|
||||
sym::const_deallocate => (
|
||||
0,
|
||||
vec![tcx.mk_mut_ptr(tcx.types.u8), tcx.types.usize, tcx.types.usize],
|
||||
tcx.mk_unit(),
|
||||
vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
|
||||
Ty::new_unit(tcx),
|
||||
),
|
||||
|
||||
sym::ptr_offset_from => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.isize)
|
||||
}
|
||||
sym::ptr_offset_from_unsigned => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.usize)
|
||||
}
|
||||
sym::ptr_offset_from => (
|
||||
1,
|
||||
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
||||
tcx.types.isize,
|
||||
),
|
||||
sym::ptr_offset_from_unsigned => (
|
||||
1,
|
||||
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
||||
tcx.types.usize,
|
||||
),
|
||||
sym::unchecked_div | sym::unchecked_rem | sym::exact_div => {
|
||||
(1, vec![param(0), param(0)], param(0))
|
||||
}
|
||||
|
@ -379,12 +389,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
}
|
||||
sym::float_to_int_unchecked => (2, vec![param(0)], param(1)),
|
||||
|
||||
sym::assume => (0, vec![tcx.types.bool], tcx.mk_unit()),
|
||||
sym::assume => (0, vec![tcx.types.bool], Ty::new_unit(tcx)),
|
||||
sym::likely => (0, vec![tcx.types.bool], tcx.types.bool),
|
||||
sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool),
|
||||
|
||||
sym::read_via_copy => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)),
|
||||
sym::write_via_move => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
|
||||
sym::read_via_copy => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
|
||||
sym::write_via_move => {
|
||||
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
||||
}
|
||||
|
||||
sym::discriminant_value => {
|
||||
let assoc_items = tcx.associated_item_def_ids(
|
||||
|
@ -395,48 +407,47 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
||||
(
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_imm_ref(
|
||||
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
|
||||
param(0),
|
||||
),
|
||||
],
|
||||
tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
|
||||
vec![Ty::new_imm_ref(
|
||||
tcx,
|
||||
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
|
||||
param(0),
|
||||
)],
|
||||
Ty::new_projection(tcx, discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
|
||||
)
|
||||
}
|
||||
|
||||
kw::Try => {
|
||||
let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
|
||||
let mut_u8 = Ty::new_mut_ptr(tcx, tcx.types.u8);
|
||||
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[mut_u8],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
));
|
||||
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[mut_u8, mut_u8],
|
||||
tcx.mk_unit(),
|
||||
Ty::new_unit(tcx),
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
));
|
||||
(
|
||||
0,
|
||||
vec![tcx.mk_fn_ptr(try_fn_ty), mut_u8, tcx.mk_fn_ptr(catch_fn_ty)],
|
||||
vec![Ty::new_fn_ptr(tcx, try_fn_ty), mut_u8, Ty::new_fn_ptr(tcx, catch_fn_ty)],
|
||||
tcx.types.i32,
|
||||
)
|
||||
}
|
||||
|
||||
sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
|
||||
Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk_unit()),
|
||||
Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
|
||||
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
||||
},
|
||||
|
||||
sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
|
||||
Some((va_list_ref_ty, va_list_ty)) => {
|
||||
let va_list_ptr_ty = tcx.mk_mut_ptr(va_list_ty);
|
||||
(0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk_unit())
|
||||
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
|
||||
(0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
|
||||
}
|
||||
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
||||
},
|
||||
|
@ -446,12 +457,17 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
|
||||
},
|
||||
|
||||
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
|
||||
sym::nontemporal_store => {
|
||||
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
|
||||
}
|
||||
|
||||
sym::raw_eq => {
|
||||
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
||||
let param_ty =
|
||||
tcx.mk_imm_ref(ty::Region::new_late_bound(tcx, ty::INNERMOST, br), param(0));
|
||||
let param_ty = Ty::new_imm_ref(
|
||||
tcx,
|
||||
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
|
||||
param(0),
|
||||
);
|
||||
(1, vec![param_ty; 2], tcx.types.bool)
|
||||
}
|
||||
|
||||
|
@ -460,7 +476,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)),
|
||||
|
||||
sym::vtable_size | sym::vtable_align => {
|
||||
(0, vec![tcx.mk_imm_ptr(tcx.mk_unit())], tcx.types.usize)
|
||||
(0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
|
||||
}
|
||||
|
||||
other => {
|
||||
|
@ -479,7 +495,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
let param = |n| {
|
||||
let name = Symbol::intern(&format!("P{}", n));
|
||||
tcx.mk_ty_param(n, name)
|
||||
Ty::new_param(tcx, n, name)
|
||||
};
|
||||
|
||||
let name = it.ident.name;
|
||||
|
@ -521,7 +537,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
|
|||
sym::simd_fpowi => (1, vec![param(0), tcx.types.i32], param(0)),
|
||||
sym::simd_fma => (1, vec![param(0), param(0), param(0)], param(0)),
|
||||
sym::simd_gather => (3, vec![param(0), param(1), param(2)], param(0)),
|
||||
sym::simd_scatter => (3, vec![param(0), param(1), param(2)], tcx.mk_unit()),
|
||||
sym::simd_scatter => (3, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
|
||||
sym::simd_insert => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),
|
||||
sym::simd_extract => (2, vec![param(0), tcx.types.u32], param(1)),
|
||||
sym::simd_cast
|
||||
|
@ -550,7 +566,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
|
|||
name if name.as_str().starts_with("simd_shuffle") => {
|
||||
match name.as_str()["simd_shuffle".len()..].parse() {
|
||||
Ok(n) => {
|
||||
let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)];
|
||||
let params = vec![param(0), param(0), Ty::new_array(tcx, tcx.types.u32, n)];
|
||||
(2, params, param(1))
|
||||
}
|
||||
Err(_) => {
|
||||
|
|
|
@ -561,7 +561,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
|
|||
// our example, the type was `Self`, which will also be
|
||||
// `Self` in the GAT.
|
||||
let ty_param = gat_generics.param_at(*ty_idx, tcx);
|
||||
let ty_param = tcx.mk_ty_param(ty_param.index, ty_param.name);
|
||||
let ty_param = Ty::new_param(tcx, ty_param.index, ty_param.name);
|
||||
// Same for the region. In our example, 'a corresponds
|
||||
// to the 'me parameter.
|
||||
let region_param = gat_generics.param_at(*region_a_idx, tcx);
|
||||
|
|
|
@ -336,15 +336,17 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> Coe
|
|||
infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a);
|
||||
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
|
||||
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
|
||||
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ref(r_b, ty))
|
||||
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty))
|
||||
}
|
||||
|
||||
(&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => {
|
||||
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
|
||||
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty))
|
||||
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
|
||||
}
|
||||
|
||||
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty)),
|
||||
(&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => {
|
||||
check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ptr(tcx, ty))
|
||||
}
|
||||
|
||||
(&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b))
|
||||
if def_a.is_struct() && def_b.is_struct() =>
|
||||
|
|
|
@ -343,7 +343,7 @@ fn emit_orphan_check_error<'tcx>(
|
|||
// That way if we had `Vec<MyType>`, we will properly attribute the
|
||||
// problem to `Vec<T>` and avoid confusing the user if they were to see
|
||||
// `MyType` in the error.
|
||||
ty::Adt(def, _) => tcx.mk_adt(*def, ty::List::empty()),
|
||||
ty::Adt(def, _) => Ty::new_adt(tcx, *def, ty::List::empty()),
|
||||
_ => ty,
|
||||
};
|
||||
let msg = |ty: &str, postfix: &str| {
|
||||
|
@ -605,7 +605,9 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
|
|||
}
|
||||
|
||||
let self_ty_root = match self_ty.kind() {
|
||||
ty::Adt(def, _) => tcx.mk_adt(*def, InternalSubsts::identity_for_item(tcx, def.did())),
|
||||
ty::Adt(def, _) => {
|
||||
Ty::new_adt(tcx, *def, InternalSubsts::identity_for_item(tcx, def.did()))
|
||||
}
|
||||
_ => unimplemented!("unexpected self ty {:?}", self_ty),
|
||||
};
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||
}
|
||||
|
||||
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
||||
self.tcx().ty_error_with_message(span, "bad placeholder type")
|
||||
Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
|
||||
}
|
||||
|
||||
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
|
||||
|
@ -407,7 +407,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||
item_segment,
|
||||
trait_ref.substs,
|
||||
);
|
||||
self.tcx().mk_projection(item_def_id, item_substs)
|
||||
Ty::new_projection(self.tcx(), item_def_id, item_substs)
|
||||
} else {
|
||||
// There are no late-bound regions; we can just ignore the binder.
|
||||
let (mut mpart_sugg, mut inferred_sugg) = (None, None);
|
||||
|
@ -471,14 +471,15 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
self.tcx().ty_error(self.tcx().sess.emit_err(
|
||||
errors::AssociatedTypeTraitUninferredGenericParams {
|
||||
Ty::new_error(
|
||||
self.tcx(),
|
||||
self.tcx().sess.emit_err(errors::AssociatedTypeTraitUninferredGenericParams {
|
||||
span,
|
||||
inferred_sugg,
|
||||
bound,
|
||||
mpart_sugg,
|
||||
},
|
||||
))
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1239,7 +1240,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
|||
} else {
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
fn_sig.inputs().iter().copied(),
|
||||
tcx.ty_error(guar),
|
||||
Ty::new_error(tcx, guar),
|
||||
fn_sig.c_variadic,
|
||||
fn_sig.unsafety,
|
||||
fn_sig.abi,
|
||||
|
@ -1332,7 +1333,7 @@ fn suggest_impl_trait<'tcx>(
|
|||
let item_ty = ocx.normalize(
|
||||
&ObligationCause::misc(span, def_id),
|
||||
param_env,
|
||||
tcx.mk_projection(assoc_item_def_id, substs),
|
||||
Ty::new_projection(tcx, assoc_item_def_id, substs),
|
||||
);
|
||||
// FIXME(compiler-errors): We may benefit from resolving regions here.
|
||||
if ocx.select_where_possible().is_empty()
|
||||
|
|
|
@ -20,7 +20,8 @@ fn associated_type_bounds<'tcx>(
|
|||
ast_bounds: &'tcx [hir::GenericBound<'tcx>],
|
||||
span: Span,
|
||||
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||
let item_ty = tcx.mk_projection(
|
||||
let item_ty = Ty::new_projection(
|
||||
tcx,
|
||||
assoc_item_def_id.to_def_id(),
|
||||
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
|
||||
);
|
||||
|
@ -91,7 +92,8 @@ pub(super) fn explicit_item_bounds(
|
|||
tcx,
|
||||
opaque_def_id.expect_local(),
|
||||
opaque_ty.bounds,
|
||||
tcx.mk_projection(
|
||||
Ty::new_projection(
|
||||
tcx,
|
||||
def_id.to_def_id(),
|
||||
ty::InternalSubsts::identity_for_item(tcx, def_id),
|
||||
),
|
||||
|
@ -117,9 +119,9 @@ pub(super) fn explicit_item_bounds(
|
|||
}) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||
Ty::new_projection(tcx, def_id.to_def_id(), substs)
|
||||
} else {
|
||||
tcx.mk_opaque(def_id.to_def_id(), substs)
|
||||
Ty::new_opaque(tcx, def_id.to_def_id(), substs)
|
||||
};
|
||||
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
|
||||
}
|
||||
|
|
|
@ -719,6 +719,7 @@ pub(super) fn type_param_predicates(
|
|||
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
|
||||
) -> ty::GenericPredicates<'_> {
|
||||
use rustc_hir::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
// In the AST, bounds can derive from two places. Either
|
||||
// written inline like `<T: Foo>` or in a where-clause like
|
||||
|
@ -728,7 +729,7 @@ pub(super) fn type_param_predicates(
|
|||
let param_owner = tcx.hir().ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(param_owner);
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id));
|
||||
let ty = Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id));
|
||||
|
||||
// Don't look for bounds where the type parameter isn't in scope.
|
||||
let parent = if item_def_id == param_owner {
|
||||
|
|
|
@ -16,6 +16,7 @@ mod opaque;
|
|||
|
||||
fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||
use hir::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
let Node::AnonConst(_) = tcx.hir().get(hir_id) else { panic!() };
|
||||
|
@ -25,13 +26,13 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
|
||||
let (generics, arg_idx) = match parent_node {
|
||||
// Easy case: arrays repeat expressions.
|
||||
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
|
||||
Node::Ty(&hir::Ty { kind: TyKind::Array(_, ref constant), .. })
|
||||
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
|
||||
if constant.hir_id() == hir_id =>
|
||||
{
|
||||
return tcx.types.usize
|
||||
}
|
||||
Node::Ty(&Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => {
|
||||
Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), .. }) if e.hir_id == hir_id => {
|
||||
return tcx.typeck(def_id).node_type(e.hir_id)
|
||||
}
|
||||
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
|
||||
|
@ -67,7 +68,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
) =>
|
||||
{
|
||||
let Some(trait_def_id) = trait_ref.trait_def_id() else {
|
||||
return tcx.ty_error_with_message(tcx.def_span(def_id), "Could not find trait");
|
||||
return Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find trait");
|
||||
};
|
||||
let assoc_items = tcx.associated_items(trait_def_id);
|
||||
let assoc_item = assoc_items.find_by_name_and_kind(
|
||||
|
@ -79,7 +80,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
.expect("const parameter types cannot be generic")
|
||||
} else {
|
||||
// FIXME(associated_const_equality): add a useful error message here.
|
||||
tcx.ty_error_with_message(tcx.def_span(def_id), "Could not find associated const on trait")
|
||||
Ty::new_error_with_message(tcx,tcx.def_span(def_id), "Could not find associated const on trait")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
// arm would handle this.
|
||||
//
|
||||
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
|
||||
Node::Ty(hir_ty @ Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
|
||||
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
|
||||
// Find the Item containing the associated type so we can create an ItemCtxt.
|
||||
// Using the ItemCtxt convert the HIR for the unresolved assoc type into a
|
||||
// ty which is a fully resolved projection.
|
||||
|
@ -137,7 +138,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
(generics, arg_index)
|
||||
} else {
|
||||
// I dont think it's possible to reach this but I'm not 100% sure - BoxyUwU
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
"unexpected non-GAT usage of an anon const",
|
||||
);
|
||||
|
@ -154,7 +155,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
// As there is no relevant param for `def_id`, we simply return
|
||||
// `None` here.
|
||||
let Some(type_dependent_def) = tables.type_dependent_def_id(parent_node_id) else {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unable to find type-dependent def for {:?}", parent_node_id),
|
||||
);
|
||||
|
@ -174,12 +175,12 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
(tcx.generics_of(type_dependent_def), idx)
|
||||
}
|
||||
|
||||
Node::Ty(&Ty { kind: TyKind::Path(_), .. })
|
||||
Node::Ty(&hir::Ty { kind: TyKind::Path(_), .. })
|
||||
| Node::Expr(&Expr { kind: ExprKind::Path(_) | ExprKind::Struct(..), .. })
|
||||
| Node::TraitRef(..)
|
||||
| Node::Pat(_) => {
|
||||
let path = match parent_node {
|
||||
Node::Ty(&Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. })
|
||||
Node::Ty(&hir::Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. })
|
||||
| Node::TraitRef(&TraitRef { path, .. }) => &*path,
|
||||
Node::Expr(&Expr {
|
||||
kind:
|
||||
|
@ -195,14 +196,14 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) {
|
||||
path
|
||||
} else {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unable to find const parent for {} in pat {:?}", hir_id, pat),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected const parent path {:?}", parent_node),
|
||||
);
|
||||
|
@ -224,7 +225,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
.position(|ct| ct.hir_id == hir_id)
|
||||
.map(|idx| (idx, seg)))
|
||||
}) else {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
"no arg matching AnonConst in path",
|
||||
);
|
||||
|
@ -233,7 +234,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
let generics = match tcx.res_generics_def_id(segment.res) {
|
||||
Some(def_id) => tcx.generics_of(def_id),
|
||||
None => {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected anon const res {:?} in path: {:?}", segment.res, path),
|
||||
);
|
||||
|
@ -243,7 +244,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
(generics, arg_index)
|
||||
}
|
||||
|
||||
_ => return tcx.ty_error_with_message(
|
||||
_ => return Ty::new_error_with_message(tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("unexpected const parent in type_of(): {parent_node:?}"),
|
||||
),
|
||||
|
@ -269,7 +270,8 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
|||
{
|
||||
tcx.type_of(param_def_id).no_bound_vars().expect("const parameter types cannot be generic")
|
||||
} else {
|
||||
return tcx.ty_error_with_message(
|
||||
return Ty::new_error_with_message(
|
||||
tcx,
|
||||
tcx.def_span(def_id),
|
||||
format!("const generic parameter not found in {generics:?} at position {arg_idx:?}"),
|
||||
);
|
||||
|
@ -305,6 +307,9 @@ fn get_path_containing_arg_in_pat<'hir>(
|
|||
}
|
||||
|
||||
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty<'_>> {
|
||||
use rustc_hir::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
// If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
|
||||
// side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
|
||||
// associated type in the impl.
|
||||
|
@ -317,7 +322,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
return map[&assoc_item.trait_item_def_id.unwrap()];
|
||||
}
|
||||
Err(_) => {
|
||||
return ty::EarlyBinder::bind(tcx.ty_error_with_message(
|
||||
return ty::EarlyBinder::bind(Ty::new_error_with_message(
|
||||
tcx,
|
||||
DUMMY_SP,
|
||||
"Could not collect return position impl trait in trait tys",
|
||||
));
|
||||
|
@ -325,8 +331,6 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
}
|
||||
}
|
||||
|
||||
use rustc_hir::*;
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
@ -335,7 +339,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
Node::TraitItem(item) => match item.kind {
|
||||
TraitItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
|
||||
}
|
||||
TraitItemKind::Const(ty, body_id) => body_id
|
||||
.and_then(|body_id| {
|
||||
|
@ -360,7 +364,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
Node::ImplItem(item) => match item.kind {
|
||||
ImplItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
|
||||
}
|
||||
ImplItemKind::Const(ty, body_id) => {
|
||||
if is_suggestable_infer_ty(ty) {
|
||||
|
@ -417,18 +421,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
span: spans.into(),
|
||||
note: (),
|
||||
});
|
||||
tcx.ty_error(guar)
|
||||
Ty::new_error(tcx, guar)
|
||||
}
|
||||
_ => icx.to_ty(*self_ty),
|
||||
},
|
||||
ItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
|
||||
}
|
||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
|
||||
let def = tcx.adt_def(def_id);
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_adt(def, substs)
|
||||
Ty::new_adt(tcx, def, substs)
|
||||
}
|
||||
ItemKind::OpaqueTy(OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias { .. },
|
||||
|
@ -469,10 +473,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
Node::ForeignItem(foreign_item) => match foreign_item.kind {
|
||||
ForeignItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
|
||||
}
|
||||
ForeignItemKind::Static(t, _) => icx.to_ty(t),
|
||||
ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()),
|
||||
ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()),
|
||||
},
|
||||
|
||||
Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def {
|
||||
|
@ -481,7 +485,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
}
|
||||
VariantData::Tuple(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
Ty::new_fn_def(tcx, def_id.to_def_id(), substs)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
|
|||
_ => "item",
|
||||
},
|
||||
});
|
||||
tcx.ty_error(reported)
|
||||
Ty::new_error(tcx, reported)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,8 @@ impl TaitConstraintLocator<'_> {
|
|||
// ```
|
||||
let tables = self.tcx.typeck(item_def_id);
|
||||
if let Some(guar) = tables.tainted_by_errors {
|
||||
self.found = Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: self.tcx.ty_error(guar) });
|
||||
self.found =
|
||||
Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: Ty::new_error(self.tcx, guar) });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -162,7 +163,7 @@ impl TaitConstraintLocator<'_> {
|
|||
if let Some(prev) = &mut self.found {
|
||||
if concrete_type.ty != prev.ty && !(concrete_type, prev.ty).references_error() {
|
||||
let guar = prev.report_mismatch(&concrete_type, self.def_id, self.tcx).emit();
|
||||
prev.ty = self.tcx.ty_error(guar);
|
||||
prev.ty = Ty::new_error(self.tcx, guar);
|
||||
}
|
||||
} else {
|
||||
self.found = Some(concrete_type);
|
||||
|
@ -258,7 +259,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
|
|||
if let Some(guar) = tables.tainted_by_errors {
|
||||
// Some error in the owner fn prevented us from populating
|
||||
// the `concrete_opaque_types` table.
|
||||
tcx.ty_error(guar)
|
||||
Ty::new_error(tcx, guar)
|
||||
} else {
|
||||
// Fall back to the RPIT we inferred during HIR typeck
|
||||
if let Some(hir_opaque_ty) = hir_opaque_ty {
|
||||
|
@ -270,7 +271,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
|
|||
// so we can just make the hidden type be `!`.
|
||||
// For backwards compatibility reasons, we fall back to
|
||||
// `()` until we the diverging default is changed.
|
||||
tcx.mk_diverging_default()
|
||||
Ty::new_diverging_default(tcx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,16 +319,19 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
|||
expected_return_type = main_fnsig.output();
|
||||
} else {
|
||||
// standard () main return type
|
||||
expected_return_type = ty::Binder::dummy(tcx.mk_unit());
|
||||
expected_return_type = ty::Binder::dummy(Ty::new_unit(tcx));
|
||||
}
|
||||
|
||||
if error {
|
||||
return;
|
||||
}
|
||||
|
||||
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| {
|
||||
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
|
||||
}));
|
||||
let se_ty = Ty::new_fn_ptr(
|
||||
tcx,
|
||||
expected_return_type.map_bound(|expected_return_type| {
|
||||
tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust)
|
||||
}),
|
||||
);
|
||||
|
||||
require_same_types(
|
||||
tcx,
|
||||
|
@ -339,7 +342,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
|
|||
),
|
||||
param_env,
|
||||
se_ty,
|
||||
tcx.mk_fn_ptr(main_fnsig),
|
||||
Ty::new_fn_ptr(tcx, main_fnsig),
|
||||
);
|
||||
}
|
||||
fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
||||
|
@ -397,13 +400,16 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
|||
}
|
||||
}
|
||||
|
||||
let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))],
|
||||
tcx.types.isize,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
)));
|
||||
let se_ty = Ty::new_fn_ptr(
|
||||
tcx,
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
[tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
|
||||
tcx.types.isize,
|
||||
false,
|
||||
hir::Unsafety::Normal,
|
||||
Abi::Rust,
|
||||
)),
|
||||
);
|
||||
|
||||
require_same_types(
|
||||
tcx,
|
||||
|
@ -414,7 +420,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
|||
),
|
||||
ty::ParamEnv::empty(), // start should not have any where bounds.
|
||||
se_ty,
|
||||
tcx.mk_fn_ptr(tcx.fn_sig(start_def_id).subst_identity()),
|
||||
Ty::new_fn_ptr(tcx, tcx.fn_sig(start_def_id).subst_identity()),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue