diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-03-01 11:34:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-01 11:34:00 +0100 |
| commit | 1d9992d4d27ac773c444f46b6c80f6b43e6e4608 (patch) | |
| tree | 73b50004e05dde543e3f6463c29cd7474bd88eef | |
| parent | db12f00627e0ebabf6fca52049789e63257fbdfb (diff) | |
| parent | 371c073ecff1d9e9ad6adb46e25bdbc53834be61 (diff) | |
| download | rust-1d9992d4d27ac773c444f46b6c80f6b43e6e4608.tar.gz rust-1d9992d4d27ac773c444f46b6c80f6b43e6e4608.zip | |
Rollup merge of #137763 - compiler-errors:ty-nits, r=BoxyUwU
Use `mk_ty_from_kind` a bit less, clean up lifetime handling in borrowck r? ``@BoxyUwU`` Pulled out of my attempt to turn that `*const dyn Tr + '_` casting into a lint (which failed lmao)
| -rw-r--r-- | compiler/rustc_borrowck/src/type_check/mod.rs | 44 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/cast.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/codec.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 2 |
4 files changed, 21 insertions, 37 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index bd0d98028ae..6d05696e146 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Spanned; -use rustc_span::{DUMMY_SP, Span, sym}; +use rustc_span::{Span, sym}; use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; use tracing::{debug, instrument, trace}; @@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable}; use crate::polonius::{PoloniusContext, PoloniusLivenessContext}; use crate::region_infer::TypeTest; use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices}; -use crate::renumber::RegionCtxt; use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst}; use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations}; use crate::universal_regions::{DefiningTy, UniversalRegions}; @@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // // Note that other checks (such as denying `dyn Send` -> `dyn // Debug`) are in `rustc_hir_typeck`. - if let ty::Dynamic(src_tty, ..) = src_tail.kind() - && let ty::Dynamic(dst_tty, ..) = dst_tail.kind() + if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind() + && let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind() && src_tty.principal().is_some() && dst_tty.principal().is_some() { // Remove auto traits. // Auto trait checks are handled in `rustc_hir_typeck` as FCW. - let src_obj = tcx.mk_ty_from_kind(ty::Dynamic( + let src_obj = Ty::new_dynamic( + tcx, tcx.mk_poly_existential_predicates( &src_tty.without_auto_traits().collect::<Vec<_>>(), ), - tcx.lifetimes.re_static, + // FIXME: Once we disallow casting `*const dyn Trait + 'short` + // to `*const dyn Trait + 'long`, then this can just be `src_lt`. + dst_lt, ty::Dyn, - )); - let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic( + ); + let dst_obj = Ty::new_dynamic( + tcx, tcx.mk_poly_existential_predicates( &dst_tty.without_auto_traits().collect::<Vec<_>>(), ), - tcx.lifetimes.re_static, + dst_lt, ty::Dyn, - )); - - // Replace trait object lifetimes with fresh vars, to allow - // casts like - // `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static` - let src_obj = - freshen_single_trait_object_lifetime(self.infcx, src_obj); - let dst_obj = - freshen_single_trait_object_lifetime(self.infcx, dst_obj); + ); debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj); @@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> { Ok(output) } } - -fn freshen_single_trait_object_lifetime<'tcx>( - infcx: &BorrowckInferCtxt<'tcx>, - ty: Ty<'tcx>, -) -> Ty<'tcx> { - let &ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") }; - - let fresh = infcx - .next_region_var(rustc_infer::infer::RegionVariableOrigin::MiscVariable(DUMMY_SP), || { - RegionCtxt::Unknown - }); - infcx.tcx.mk_ty_from_kind(ty::Dynamic(tty, fresh, dyn_kind)) -} diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 462983be88d..ea4ec345ad0 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -895,20 +895,22 @@ impl<'a, 'tcx> CastCheck<'tcx> { // e.g. we want to allow `dyn T -> (dyn T,)`, etc. // // We also need to skip auto traits to emit an FCW and not an error. - let src_obj = tcx.mk_ty_from_kind(ty::Dynamic( + let src_obj = Ty::new_dynamic( + tcx, tcx.mk_poly_existential_predicates( &src_tty.without_auto_traits().collect::<Vec<_>>(), ), tcx.lifetimes.re_erased, ty::Dyn, - )); - let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic( + ); + let dst_obj = Ty::new_dynamic( + tcx, tcx.mk_poly_existential_predicates( &dst_tty.without_auto_traits().collect::<Vec<_>>(), ), tcx.lifetimes.re_erased, ty::Dyn, - )); + ); // `dyn Src = dyn Dst`, this checks for matching traits/generics/projections // This is `fcx.demand_eqtype`, but inlined to give a better error. diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 41958949836..fe42a224d9f 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -224,7 +224,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> { }) } else { let tcx = decoder.interner(); - tcx.mk_ty_from_kind(rustc_type_ir::TyKind::decode(decoder)) + tcx.mk_ty_from_kind(ty::TyKind::decode(decoder)) } } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index e46ab302be2..ce563c59251 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -462,7 +462,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> { - tcx.mk_ty_from_kind(Param(ParamTy { index, name })) + Ty::new(tcx, Param(ParamTy { index, name })) } #[inline] |
