From 4547b622d8d29df964fa2914213088b148c498fc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:32 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_ty_utils/src/ty.rs | 73 +++------------------------------------ 1 file changed, 4 insertions(+), 69 deletions(-) (limited to 'compiler/rustc_ty_utils/src/ty.rs') diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 3eebb4ace..5fc9bcac1 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -49,12 +49,9 @@ fn sized_constraint_for_ty<'tcx>( // it on the impl. let Some(sized_trait) = tcx.lang_items().sized_trait() else { return vec![ty] }; - let sized_predicate = ty::Binder::dummy(ty::TraitRef { - def_id: sized_trait, - substs: tcx.mk_substs_trait(ty, &[]), - }) - .without_const() - .to_predicate(tcx); + let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(sized_trait, [ty])) + .without_const() + .to_predicate(tcx); let predicates = tcx.predicates_of(adtdef.did()).predicates; if predicates.iter().any(|(p, _)| *p == sized_predicate) { vec![] } else { vec![ty] } } @@ -108,12 +105,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] { /// See `ParamEnv` struct definition for details. fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { - // The param_env of an impl Trait type is its defining function's param_env - if let Some(parent) = ty::is_impl_trait_defn(tcx, def_id) { - return param_env(tcx, parent.to_def_id()); - } // Compute the bounds on Self and the type parameters. - let ty::InstantiatedPredicates { mut predicates, .. } = tcx.predicates_of(def_id).instantiate_identity(tcx); @@ -413,63 +405,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { /// Check if a function is async. fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync { let node = tcx.hir().get_by_def_id(def_id.expect_local()); - if let Some(fn_kind) = node.fn_kind() { fn_kind.asyncness() } else { hir::IsAsync::NotAsync } -} - -/// Don't call this directly: use ``tcx.conservative_is_privately_uninhabited`` instead. -pub fn conservative_is_privately_uninhabited_raw<'tcx>( - tcx: TyCtxt<'tcx>, - param_env_and: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, -) -> bool { - let (param_env, ty) = param_env_and.into_parts(); - match ty.kind() { - ty::Never => { - debug!("ty::Never =>"); - true - } - ty::Adt(def, _) if def.is_union() => { - debug!("ty::Adt(def, _) if def.is_union() =>"); - // For now, `union`s are never considered uninhabited. - false - } - ty::Adt(def, substs) => { - debug!("ty::Adt(def, _) if def.is_not_union() =>"); - // Any ADT is uninhabited if either: - // (a) It has no variants (i.e. an empty `enum`); - // (b) Each of its variants (a single one in the case of a `struct`) has at least - // one uninhabited field. - def.variants().iter().all(|var| { - var.fields.iter().any(|field| { - let ty = tcx.bound_type_of(field.did).subst(tcx, substs); - tcx.conservative_is_privately_uninhabited(param_env.and(ty)) - }) - }) - } - ty::Tuple(fields) => { - debug!("ty::Tuple(..) =>"); - fields.iter().any(|ty| tcx.conservative_is_privately_uninhabited(param_env.and(ty))) - } - ty::Array(ty, len) => { - debug!("ty::Array(ty, len) =>"); - match len.try_eval_usize(tcx, param_env) { - Some(0) | None => false, - // If the array is definitely non-empty, it's uninhabited if - // the type of its elements is uninhabited. - Some(1..) => tcx.conservative_is_privately_uninhabited(param_env.and(*ty)), - } - } - ty::Ref(..) => { - debug!("ty::Ref(..) =>"); - // References to uninitialised memory is valid for any type, including - // uninhabited types, in unsafe code, so we treat all references as - // inhabited. - false - } - _ => { - debug!("_ =>"); - false - } - } + node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness) } pub fn provide(providers: &mut ty::query::Providers) { @@ -481,7 +417,6 @@ pub fn provide(providers: &mut ty::query::Providers) { instance_def_size_estimate, issue33140_self_ty, impl_defaultness, - conservative_is_privately_uninhabited: conservative_is_privately_uninhabited_raw, ..*providers }; } -- cgit v1.2.3