From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_ty_utils/Cargo.toml | 2 +- compiler/rustc_ty_utils/src/abi.rs | 263 +++++++++++++++++++----- compiler/rustc_ty_utils/src/assoc.rs | 28 +-- compiler/rustc_ty_utils/src/consts.rs | 8 +- compiler/rustc_ty_utils/src/implied_bounds.rs | 25 ++- compiler/rustc_ty_utils/src/instance.rs | 23 ++- compiler/rustc_ty_utils/src/layout.rs | 71 ++++--- compiler/rustc_ty_utils/src/lib.rs | 20 +- compiler/rustc_ty_utils/src/opaque_types.rs | 16 +- compiler/rustc_ty_utils/src/representability.rs | 2 +- compiler/rustc_ty_utils/src/sig_types.rs | 14 +- compiler/rustc_ty_utils/src/structural_match.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 18 +- 13 files changed, 333 insertions(+), 159 deletions(-) (limited to 'compiler/rustc_ty_utils') diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index 7e00f1e0c..f8eb82da8 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -itertools = "0.10.1" +itertools = "0.11" rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index fcf6626bb..a5f11ca23 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -16,7 +16,7 @@ use rustc_target::spec::abi::Abi as SpecAbi; use std::iter; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { fn_abi_of_fn_ptr, fn_abi_of_instance, ..*providers }; } @@ -82,7 +82,7 @@ fn fn_sig_for_fn_abi<'tcx>( var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BoundRegionKind::BrEnv, }; - let env_region = ty::Region::new_late_bound(tcx, ty::INNERMOST, br); + let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br); let env_ty = tcx.closure_env_ty(def_id, args, env_region).unwrap(); let sig = sig.skip_binder(); @@ -98,70 +98,130 @@ fn fn_sig_for_fn_abi<'tcx>( ) } ty::Coroutine(did, args, _) => { - let sig = args.as_coroutine().poly_sig(); + let coroutine_kind = tcx.coroutine_kind(did).unwrap(); + let sig = args.as_coroutine().sig(); - let bound_vars = tcx.mk_bound_variable_kinds_from_iter( - sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), - ); + let bound_vars = tcx.mk_bound_variable_kinds_from_iter(iter::once( + ty::BoundVariableKind::Region(ty::BrEnv), + )); let br = ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BoundRegionKind::BrEnv, }; - let env_ty = - Ty::new_mut_ref(tcx, ty::Region::new_late_bound(tcx, ty::INNERMOST, br), ty); + let env_ty = Ty::new_mut_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), ty); let pin_did = tcx.require_lang_item(LangItem::Pin, None); let pin_adt_ref = tcx.adt_def(pin_did); let pin_args = tcx.mk_args(&[env_ty.into()]); - let env_ty = Ty::new_adt(tcx, pin_adt_ref, pin_args); + let env_ty = match coroutine_kind { + hir::CoroutineKind::Gen(_) => { + // Iterator::next doesn't accept a pinned argument, + // unlike for all other coroutine kinds. + env_ty + } + hir::CoroutineKind::Async(_) + | hir::CoroutineKind::AsyncGen(_) + | hir::CoroutineKind::Coroutine => Ty::new_adt(tcx, pin_adt_ref, pin_args), + }; - let sig = sig.skip_binder(); // The `FnSig` and the `ret_ty` here is for a coroutines main // `Coroutine::resume(...) -> CoroutineState` function in case we - // have an ordinary coroutine, or the `Future::poll(...) -> Poll` - // function in case this is a special coroutine backing an async construct. - let (resume_ty, ret_ty) = if tcx.coroutine_is_async(did) { - // The signature should be `Future::poll(_, &mut Context<'_>) -> Poll` - let poll_did = tcx.require_lang_item(LangItem::Poll, None); - let poll_adt_ref = tcx.adt_def(poll_did); - let poll_args = tcx.mk_args(&[sig.return_ty.into()]); - let ret_ty = Ty::new_adt(tcx, poll_adt_ref, poll_args); - - // We have to replace the `ResumeTy` that is used for type and borrow checking - // with `&mut Context<'_>` which is used in codegen. - #[cfg(debug_assertions)] - { - if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() { - let expected_adt = - tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); - assert_eq!(*resume_ty_adt, expected_adt); - } else { - panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); - }; + // have an ordinary coroutine, the `Future::poll(...) -> Poll` + // function in case this is a special coroutine backing an async construct + // or the `Iterator::next(...) -> Option` function in case this is a + // special coroutine backing a gen construct. + let (resume_ty, ret_ty) = match coroutine_kind { + hir::CoroutineKind::Async(_) => { + // The signature should be `Future::poll(_, &mut Context<'_>) -> Poll` + assert_eq!(sig.yield_ty, tcx.types.unit); + + let poll_did = tcx.require_lang_item(LangItem::Poll, None); + let poll_adt_ref = tcx.adt_def(poll_did); + let poll_args = tcx.mk_args(&[sig.return_ty.into()]); + let ret_ty = Ty::new_adt(tcx, poll_adt_ref, poll_args); + + // We have to replace the `ResumeTy` that is used for type and borrow checking + // with `&mut Context<'_>` which is used in codegen. + #[cfg(debug_assertions)] + { + if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() { + let expected_adt = + tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); + assert_eq!(*resume_ty_adt, expected_adt); + } else { + panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); + }; + } + let context_mut_ref = Ty::new_task_context(tcx); + + (Some(context_mut_ref), ret_ty) } - let context_mut_ref = Ty::new_task_context(tcx); + hir::CoroutineKind::Gen(_) => { + // The signature should be `Iterator::next(_) -> Option` + let option_did = tcx.require_lang_item(LangItem::Option, None); + let option_adt_ref = tcx.adt_def(option_did); + let option_args = tcx.mk_args(&[sig.yield_ty.into()]); + let ret_ty = Ty::new_adt(tcx, option_adt_ref, option_args); - (context_mut_ref, ret_ty) - } else { - // The signature should be `Coroutine::resume(_, Resume) -> CoroutineState` - let state_did = tcx.require_lang_item(LangItem::CoroutineState, None); - let state_adt_ref = tcx.adt_def(state_did); - let state_args = tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]); - let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args); + assert_eq!(sig.return_ty, tcx.types.unit); + assert_eq!(sig.resume_ty, tcx.types.unit); + + (None, ret_ty) + } + hir::CoroutineKind::AsyncGen(_) => { + // The signature should be + // `AsyncIterator::poll_next(_, &mut Context<'_>) -> Poll>` + assert_eq!(sig.return_ty, tcx.types.unit); + + // Yield type is already `Poll>` + let ret_ty = sig.yield_ty; + + // We have to replace the `ResumeTy` that is used for type and borrow checking + // with `&mut Context<'_>` which is used in codegen. + #[cfg(debug_assertions)] + { + if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() { + let expected_adt = + tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); + assert_eq!(*resume_ty_adt, expected_adt); + } else { + panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); + }; + } + let context_mut_ref = Ty::new_task_context(tcx); - (sig.resume_ty, ret_ty) + (Some(context_mut_ref), ret_ty) + } + hir::CoroutineKind::Coroutine => { + // The signature should be `Coroutine::resume(_, Resume) -> CoroutineState` + let state_did = tcx.require_lang_item(LangItem::CoroutineState, None); + let state_adt_ref = tcx.adt_def(state_did); + let state_args = tcx.mk_args(&[sig.yield_ty.into(), sig.return_ty.into()]); + let ret_ty = Ty::new_adt(tcx, state_adt_ref, state_args); + + (Some(sig.resume_ty), ret_ty) + } }; - ty::Binder::bind_with_vars( + let fn_sig = if let Some(resume_ty) = resume_ty { tcx.mk_fn_sig( [env_ty, resume_ty], ret_ty, false, hir::Unsafety::Normal, rustc_target::spec::abi::Abi::Rust, - ), - bound_vars, - ) + ) + } else { + // `Iterator::next` doesn't have a `resume` argument. + tcx.mk_fn_sig( + [env_ty], + ret_ty, + false, + hir::Unsafety::Normal, + rustc_target::spec::abi::Abi::Rust, + ) + }; + ty::Binder::bind_with_vars(fn_sig, bound_vars) } _ => bug!("unexpected type {:?} in Instance::fn_sig", ty), } @@ -327,6 +387,93 @@ fn adjust_for_rust_scalar<'tcx>( } } +/// Ensure that the ABI makes basic sense. +fn fn_abi_sanity_check<'tcx>( + cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + spec_abi: SpecAbi, +) { + fn fn_arg_sanity_check<'tcx>( + cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, + fn_abi: &FnAbi<'tcx, Ty<'tcx>>, + spec_abi: SpecAbi, + arg: &ArgAbi<'tcx, Ty<'tcx>>, + ) { + match &arg.mode { + PassMode::Ignore => {} + PassMode::Direct(_) => { + // Here the Rust type is used to determine the actual ABI, so we have to be very + // careful. Scalar/ScalarPair is fine, since backends will generally use + // `layout.abi` and ignore everything else. We should just reject `Aggregate` + // entirely here, but some targets need to be fixed first. + if matches!(arg.layout.abi, Abi::Aggregate { .. }) { + // For an unsized type we'd only pass the sized prefix, so there is no universe + // in which we ever want to allow this. + assert!( + arg.layout.is_sized(), + "`PassMode::Direct` for unsized type in ABI: {:#?}", + fn_abi + ); + // This really shouldn't happen even for sized aggregates, since + // `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an + // LLVM type. This means all sorts of Rust type details leak into the ABI. + // However wasm sadly *does* currently use this mode so we have to allow it -- + // but we absolutely shouldn't let any more targets do that. + // (Also see .) + // + // The unstable abi `PtxKernel` also uses Direct for now. + // It needs to switch to something else before stabilization can happen. + // (See issue: https://github.com/rust-lang/rust/issues/117271) + assert!( + matches!(&*cx.tcx.sess.target.arch, "wasm32" | "wasm64") + || matches!(spec_abi, SpecAbi::PtxKernel | SpecAbi::Unadjusted), + r#"`PassMode::Direct` for aggregates only allowed for "unadjusted" and "ptx-kernel" functions and on wasm\nProblematic type: {:#?}"#, + arg.layout, + ); + } + } + PassMode::Pair(_, _) => { + // Similar to `Direct`, we need to make sure that backends use `layout.abi` and + // ignore the rest of the layout. + assert!( + matches!(arg.layout.abi, Abi::ScalarPair(..)), + "PassMode::Pair for type {}", + arg.layout.ty + ); + } + PassMode::Cast { .. } => { + // `Cast` means "transmute to `CastType`"; that only makes sense for sized types. + assert!(arg.layout.is_sized()); + } + PassMode::Indirect { meta_attrs: None, .. } => { + // No metadata, must be sized. + // Conceptually, unsized arguments must be copied around, which requires dynamically + // determining their size, which we cannot do without metadata. Consult + // t-opsem before removing this check. + assert!(arg.layout.is_sized()); + } + PassMode::Indirect { meta_attrs: Some(_), on_stack, .. } => { + // With metadata. Must be unsized and not on the stack. + assert!(arg.layout.is_unsized() && !on_stack); + // Also, must not be `extern` type. + let tail = cx.tcx.struct_tail_with_normalize(arg.layout.ty, |ty| ty, || {}); + if matches!(tail.kind(), ty::Foreign(..)) { + // These types do not have metadata, so having `meta_attrs` is bogus. + // Conceptually, unsized arguments must be copied around, which requires dynamically + // determining their size. Therefore, we cannot allow `extern` types here. Consult + // t-opsem before removing this check. + panic!("unsized arguments must not be `extern` types"); + } + } + } + } + + for arg in fn_abi.args.iter() { + fn_arg_sanity_check(cx, fn_abi, spec_abi, arg); + } + fn_arg_sanity_check(cx, fn_abi, spec_abi, &fn_abi.ret); +} + // FIXME(eddyb) perhaps group the signature/type-containing (or all of them?) // arguments of this method, into a separate `struct`. #[tracing::instrument(level = "debug", skip(cx, caller_location, fn_def_id, force_thin_self_ptr))] @@ -453,6 +600,7 @@ fn fn_abi_new_uncached<'tcx>( }; fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id)?; debug!("fn_abi_new_uncached = {:?}", fn_abi); + fn_abi_sanity_check(cx, &fn_abi, sig.abi); Ok(cx.tcx.arena.alloc(fn_abi)) } @@ -464,6 +612,24 @@ fn fn_abi_adjust_for_abi<'tcx>( fn_def_id: Option, ) -> Result<(), &'tcx FnAbiError<'tcx>> { if abi == SpecAbi::Unadjusted { + // The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for + // some LLVM intrinsics. + fn unadjust<'tcx>(arg: &mut ArgAbi<'tcx, Ty<'tcx>>) { + // This still uses `PassMode::Pair` for ScalarPair types. That's unlikely to be intended, + // but who knows what breaks if we change this now. + if matches!(arg.layout.abi, Abi::Aggregate { .. }) { + assert!( + arg.layout.abi.is_sized(), + "'unadjusted' ABI does not support unsized arguments" + ); + } + arg.make_direct_deprecated(); + } + + unadjust(&mut fn_abi.ret); + for arg in fn_abi.args.iter_mut() { + unadjust(arg); + } return Ok(()); } @@ -520,13 +686,14 @@ fn fn_abi_adjust_for_abi<'tcx>( _ => return, } - // `Aggregate` ABI must be adjusted to ensure that ABI-compatible Rust types are passed - // the same way. + // Compute `Aggregate` ABI. + + let is_indirect_not_on_stack = + matches!(arg.mode, PassMode::Indirect { on_stack: false, .. }); + assert!(is_indirect_not_on_stack, "{:?}", arg); let size = arg.layout.size; - if arg.layout.is_unsized() || size > Pointer(AddressSpace::DATA).size(cx) { - arg.make_indirect(); - } else { + if !arg.layout.is_unsized() && size <= Pointer(AddressSpace::DATA).size(cx) { // We want to pass small aggregates as immediates, but using // an LLVM aggregate type for this leads to bad optimizations, // so we pick an appropriately sized integer type instead. diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 3e140793b..db37bec4b 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -2,13 +2,12 @@ use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId}; -use rustc_hir::definitions::DefPathData; use rustc_hir::intravisit::{self, Visitor}; use rustc_middle::query::Providers; use rustc_middle::ty::{self, GenericArgs, ImplTraitInTraitData, Ty, TyCtxt}; use rustc_span::symbol::kw; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { associated_item, associated_item_def_ids, @@ -23,7 +22,7 @@ pub fn provide(providers: &mut Providers) { fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { let item = tcx.hir().expect_item(def_id); match item.kind { - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { // We collect RPITITs for each trait method's return type and create a // corresponding associated item using associated_types_for_impl_traits_in_associated_fn // query. @@ -43,11 +42,11 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { trait_fn_def_id, ) }) - .map(|def_id| *def_id), + .copied(), ), ) } - hir::ItemKind::Impl(ref impl_) => { + hir::ItemKind::Impl(impl_) => { // We collect RPITITs for each trait method's return type, on the impl side too and // create a corresponding associated item using // associated_types_for_impl_traits_in_associated_fn query. @@ -69,7 +68,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &[DefId] { impl_fn_def_id, ) }) - .map(|def_id| *def_id) + .copied() })), ) } @@ -94,11 +93,11 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> DefIdMap } fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem { - let id = tcx.hir().local_def_id_to_hir_id(def_id); + let id = tcx.local_def_id_to_hir_id(def_id); let parent_def_id = tcx.hir().get_parent_item(id); let parent_item = tcx.hir().expect_item(parent_def_id.def_id); match parent_item.kind { - hir::ItemKind::Impl(ref impl_) => { + hir::ItemKind::Impl(impl_) => { if let Some(impl_item_ref) = impl_.items.iter().find(|i| i.id.owner_id.def_id == def_id) { let assoc_item = associated_item_from_impl_item_ref(impl_item_ref); @@ -107,7 +106,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AssocItem { } } - hir::ItemKind::Trait(.., ref trait_item_refs) => { + hir::ItemKind::Trait(.., trait_item_refs) => { if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.owner_id.def_id == def_id) { @@ -254,13 +253,11 @@ fn associated_type_for_impl_trait_in_trait( assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait); let span = tcx.def_span(opaque_ty_def_id); - let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, DefPathData::ImplTraitAssocTy); + let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, kw::Empty, DefKind::AssocTy); let local_def_id = trait_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - trait_assoc_ty.opt_def_kind(Some(DefKind::AssocTy)); - // There's no HIR associated with this new synthesized `def_id`, so feed // `opt_local_def_id_to_hir_id` with `None`. trait_assoc_ty.opt_local_def_id_to_hir_id(None); @@ -348,8 +345,7 @@ fn associated_type_for_impl_trait_in_impl( let impl_local_def_id = tcx.local_parent(impl_fn_def_id); let decl = tcx - .hir() - .find_by_def_id(impl_fn_def_id) + .opt_hir_node_by_def_id(impl_fn_def_id) .expect("expected item") .fn_decl() .expect("expected decl"); @@ -357,13 +353,11 @@ fn associated_type_for_impl_trait_in_impl( hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id), hir::FnRetTy::Return(ty) => ty.span, }; - let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy); + let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, kw::Empty, DefKind::AssocTy); let local_def_id = impl_assoc_ty.def_id(); let def_id = local_def_id.to_def_id(); - impl_assoc_ty.opt_def_kind(Some(DefKind::AssocTy)); - // There's no HIR associated with this new synthesized `def_id`, so feed // `opt_local_def_id_to_hir_id` with `None`. impl_assoc_ty.opt_local_def_id_to_hir_id(None); diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 35487d3b6..b521a5c11 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -17,7 +17,7 @@ use crate::errors::{GenericConstantTooComplex, GenericConstantTooComplexSub}; /// Destructures array, ADT or tuple constants into the constants /// of their fields. -pub(crate) fn destructure_const<'tcx>( +fn destructure_const<'tcx>( tcx: TyCtxt<'tcx>, const_: ty::Const<'tcx>, ) -> ty::DestructuredConst<'tcx> { @@ -375,7 +375,7 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> { impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> { fn thir(&self) -> &'a thir::Thir<'tcx> { - &self.thir + self.thir } #[instrument(skip(self), level = "debug")] @@ -396,7 +396,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> { } /// Builds an abstract const, do not use this directly, but use `AbstractConst::new` instead. -pub fn thir_abstract_const( +fn thir_abstract_const( tcx: TyCtxt<'_>, def: LocalDefId, ) -> Result>>, ErrorGuaranteed> { @@ -428,6 +428,6 @@ pub fn thir_abstract_const( Ok(Some(ty::EarlyBinder::bind(recurse_build(tcx, body, body_id, root_span)?))) } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { destructure_const, thir_abstract_const, ..*providers }; } diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 5c34df1ed..3f9bd509b 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; use std::iter; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { assumed_wf_types, assumed_wf_types_for_rpitit: |tcx, def_id| { @@ -53,9 +53,9 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' DefKind::AssocTy if let Some(data) = tcx.opt_rpitit_info(def_id.to_def_id()) => { match data { ty::ImplTraitInTraitData::Trait { fn_def_id, .. } => { - // We need to remap all of the late-bound lifetimes in theassumed wf types - // of the fn (which are represented as ReFree) to the early-bound lifetimes - // of the RPITIT (which are represented by ReEarlyBound owned by the opaque). + // We need to remap all of the late-bound lifetimes in the assumed wf types + // of the fn (which are represented as ReLateParam) to the early-bound lifetimes + // of the RPITIT (which are represented by ReEarlyParam owned by the opaque). // Luckily, this is very easy to do because we already have that mapping // stored in the HIR of this RPITIT. // @@ -65,19 +65,19 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' let mut mapping = FxHashMap::default(); let generics = tcx.generics_of(def_id); - // For each captured opaque lifetime, if it's late-bound (`ReFree` in this case, - // since it has been liberated), map it back to the early-bound lifetime of + // For each captured opaque lifetime, if it's late-bound (`ReLateParam` in this + // case, since it has been liberated), map it back to the early-bound lifetime of // the GAT. Since RPITITs also have all of the fn's generics, we slice only // the end of the list corresponding to the opaque's generics. for param in &generics.params[tcx.generics_of(fn_def_id).params.len()..] { let orig_lt = tcx.map_rpit_lifetime_to_fn_lifetime(param.def_id.expect_local()); - if matches!(*orig_lt, ty::ReFree(..)) { + if matches!(*orig_lt, ty::ReLateParam(..)) { mapping.insert( orig_lt, - ty::Region::new_early_bound( + ty::Region::new_early_param( tcx, - ty::EarlyBoundRegion { + ty::EarlyParamRegion { def_id: param.def_id, index: param.index, name: param.name, @@ -90,7 +90,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' let remapped_wf_tys = tcx.fold_regions( tcx.assumed_wf_types(fn_def_id.expect_local()).to_vec(), |region, _| { - // If `region` is a `ReFree` that is captured by the + // If `region` is a `ReLateParam` that is captured by the // opaque, remap it to its corresponding the early- // bound region. if let Some(remapped_region) = mapping.get(®ion) { @@ -156,13 +156,12 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' | DefKind::Field | DefKind::LifetimeParam | DefKind::GlobalAsm - | DefKind::Closure - | DefKind::Coroutine => ty::List::empty(), + | DefKind::Closure => ty::List::empty(), } } fn fn_sig_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator + '_ { - let node = tcx.hir().get(tcx.local_def_id_to_hir_id(def_id)); + let node = tcx.hir_node_by_def_id(def_id); if let Some(decl) = node.fn_decl() { decl.inputs.iter().map(|ty| ty.span).chain(iter::once(decl.output.span())) } else { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 1487f40fd..f1c9bb23e 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -61,7 +61,7 @@ fn resolve_instance<'tcx>( Ok(Some(Instance { def, args })) }; - debug!("inner_resolve_instance: result={:?}", result); + debug!("resolve_instance: result={:?}", result); result } @@ -79,7 +79,7 @@ fn resolve_associated_item<'tcx>( let vtbl = match tcx.codegen_select_candidate((param_env, trait_ref)) { Ok(vtbl) => vtbl, Err(CodegenObligationError::Ambiguity) => { - let reported = tcx.sess.delay_span_bug( + let reported = tcx.sess.span_delayed_bug( tcx.def_span(trait_item_id), format!( "encountered ambiguity selecting `{trait_ref:?}` during codegen, presuming due to \ @@ -171,7 +171,7 @@ fn resolve_associated_item<'tcx>( // Any final impl is required to define all associated items. if !leaf_def.item.defaultness(tcx).has_value() { - let guard = tcx.sess.delay_span_bug( + let guard = tcx.sess.span_delayed_bug( tcx.def_span(leaf_def.item.def_id), "missing value for assoc item in impl", ); @@ -271,6 +271,21 @@ fn resolve_associated_item<'tcx>( debug_assert!(tcx.defaultness(trait_item_id).has_value()); Some(Instance::new(trait_item_id, rcvr_args)) } + } else if Some(trait_ref.def_id) == lang_items.async_iterator_trait() { + let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { + bug!() + }; + + if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::poll_next { + span_bug!( + tcx.def_span(coroutine_def_id), + "no definition for `{trait_ref}::{}` for built-in coroutine type", + tcx.item_name(trait_item_id) + ) + } + + // `AsyncIterator::poll_next` is generated by the compiler. + Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args }) } else if Some(trait_ref.def_id) == lang_items.coroutine_trait() { let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { bug!() @@ -328,6 +343,6 @@ fn resolve_associated_item<'tcx>( }) } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { resolve_instance, ..*providers }; } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 283862b5e..7918965e0 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -8,9 +8,7 @@ use rustc_middle::ty::layout::{ IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES, }; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{ - self, AdtDef, EarlyBinder, GenericArgsRef, ReprOptions, Ty, TyCtxt, TypeVisitableExt, -}; +use rustc_middle::ty::{self, AdtDef, EarlyBinder, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt}; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use rustc_span::symbol::Symbol; use rustc_span::DUMMY_SP; @@ -24,7 +22,7 @@ use crate::errors::{ }; use crate::layout_sanity_check::sanity_check_layout; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { layout_of, ..*providers }; } @@ -65,7 +63,11 @@ fn layout_of<'tcx>( let layout = layout_of_uncached(&cx, ty)?; let layout = TyAndLayout { ty, layout }; - record_layout_for_printing(&cx, layout); + // If we are running with `-Zprint-type-sizes`, maybe record layouts + // for dumping later. + if cx.tcx.sess.opts.unstable_opts.print_type_sizes { + record_layout_for_printing(&cx, layout); + } sanity_check_layout(&cx, &layout); @@ -89,7 +91,7 @@ fn univariant_uninterned<'tcx>( let dl = cx.data_layout(); let pack = repr.pack; if pack.is_some() && repr.align.is_some() { - cx.tcx.sess.delay_span_bug(DUMMY_SP, "struct cannot be packed and aligned"); + cx.tcx.sess.span_delayed_bug(DUMMY_SP, "struct cannot be packed and aligned"); return Err(cx.tcx.arena.alloc(LayoutError::Unknown(ty))); } @@ -316,7 +318,7 @@ fn layout_of_uncached<'tcx>( ty::Coroutine(def_id, args, _) => coroutine_layout(cx, ty, def_id, args)?, - ty::Closure(_, ref args) => { + ty::Closure(_, args) => { let tys = args.as_closure().upvar_tys(); univariant( &tys.iter() @@ -342,7 +344,7 @@ fn layout_of_uncached<'tcx>( ty::Adt(def, args) if def.repr().simd() => { if !def.is_struct() { // Should have yielded E0517 by now. - tcx.sess.delay_span_bug( + tcx.sess.span_delayed_bug( DUMMY_SP, "#[repr(simd)] was applied to an ADT that is not a struct", ); @@ -372,7 +374,7 @@ fn layout_of_uncached<'tcx>( // (should be caught by typeck) for fi in fields { if fi.ty(tcx, args) != f0_ty { - tcx.sess.delay_span_bug( + tcx.sess.span_delayed_bug( DUMMY_SP, "#[repr(simd)] was applied to an ADT with heterogeneous field type", ); @@ -431,7 +433,21 @@ fn layout_of_uncached<'tcx>( .size .checked_mul(e_len, dl) .ok_or_else(|| error(cx, LayoutError::SizeOverflow(ty)))?; - let align = dl.vector_align(size); + + let (abi, align) = if def.repr().packed() && !e_len.is_power_of_two() { + // Non-power-of-two vectors have padding up to the next power-of-two. + // If we're a packed repr, remove the padding while keeping the alignment as close + // to a vector as possible. + ( + Abi::Aggregate { sized: true }, + AbiAndPrefAlign { + abi: Align::max_for_offset(size), + pref: dl.vector_align(size).pref, + }, + ) + } else { + (Abi::Vector { element: e_abi, count: e_len }, dl.vector_align(size)) + }; let size = size.align_to(align.abi); // Compute the placement of the vector fields: @@ -444,7 +460,7 @@ fn layout_of_uncached<'tcx>( tcx.mk_layout(LayoutS { variants: Variants::Single { index: FIRST_VARIANT }, fields, - abi: Abi::Vector { element: e_abi, count: e_len }, + abi, largest_niche: e_ly.largest_niche, size, align, @@ -469,7 +485,7 @@ fn layout_of_uncached<'tcx>( if def.is_union() { if def.repr().pack.is_some() && def.repr().align.is_some() { - cx.tcx.sess.delay_span_bug( + cx.tcx.sess.span_delayed_bug( tcx.def_span(def.did()), "union cannot be packed and aligned", ); @@ -724,7 +740,7 @@ fn coroutine_layout<'tcx>( let Some(info) = tcx.coroutine_layout(def_id) else { return Err(error(cx, LayoutError::Unknown(ty))); }; - let (ineligible_locals, assignments) = coroutine_saved_local_eligibility(&info); + let (ineligible_locals, assignments) = coroutine_saved_local_eligibility(info); // Build a prefix layout, including "promoting" all ineligible // locals as part of the prefix. We compute the layout of all of @@ -740,11 +756,11 @@ fn coroutine_layout<'tcx>( }; let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag)); - let promoted_layouts = ineligible_locals - .iter() - .map(|local| subst_field(info.field_tys[local].ty)) - .map(|ty| Ty::new_maybe_uninit(tcx, ty)) - .map(|ty| Ok(cx.layout_of(ty)?.layout)); + let promoted_layouts = ineligible_locals.iter().map(|local| { + let field_ty = subst_field(info.field_tys[local].ty); + let uninit_ty = Ty::new_maybe_uninit(tcx, field_ty); + Ok(cx.spanned_layout_of(uninit_ty, info.field_tys[local].source_info.span)?.layout) + }); let prefix_layouts = args .as_coroutine() .prefix_tys() @@ -815,7 +831,10 @@ fn coroutine_layout<'tcx>( Assigned(_) => bug!("assignment does not match variant"), Ineligible(_) => false, }) - .map(|local| subst_field(info.field_tys[*local].ty)); + .map(|local| { + let field_ty = subst_field(info.field_tys[*local].ty); + Ty::new_maybe_uninit(tcx, field_ty) + }); let mut variant = univariant_uninterned( cx, @@ -911,21 +930,7 @@ fn coroutine_layout<'tcx>( Ok(layout) } -/// This is invoked by the `layout_of` query to record the final -/// layout of each type. -#[inline(always)] fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: TyAndLayout<'tcx>) { - // If we are running with `-Zprint-type-sizes`, maybe record layouts - // for dumping later. - if cx.tcx.sess.opts.unstable_opts.print_type_sizes { - record_layout_for_printing_outlined(cx, layout) - } -} - -fn record_layout_for_printing_outlined<'tcx>( - cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, - layout: TyAndLayout<'tcx>, -) { // Ignore layouts that are done with non-empty environments or // non-monomorphic layouts, as the user only wants to see the stuff // resulting from the final codegen session. diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index dabe25589..fa1f94e8b 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -5,16 +5,16 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![cfg_attr(not(bootstrap), doc(rust_logo))] -#![cfg_attr(not(bootstrap), feature(rustdoc_internals))] -#![cfg_attr(not(bootstrap), allow(internal_features))] +#![doc(rust_logo)] +#![feature(rustdoc_internals)] +#![allow(internal_features)] #![feature(assert_matches)] #![feature(associated_type_defaults)] +#![feature(box_patterns)] +#![feature(if_let_guard)] #![feature(iterator_try_collect)] #![feature(let_chains)] -#![feature(if_let_guard)] #![feature(never_type)] -#![feature(box_patterns)] #![recursion_limit = "256"] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] @@ -24,8 +24,6 @@ extern crate rustc_middle; #[macro_use] extern crate tracing; -use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_fluent_macro::fluent_messages; use rustc_middle::query::Providers; mod abi; @@ -34,17 +32,17 @@ mod common_traits; mod consts; mod errors; mod implied_bounds; -pub mod instance; +mod instance; mod layout; mod layout_sanity_check; mod needs_drop; mod opaque_types; -pub mod representability; -pub mod sig_types; +mod representability; +mod sig_types; mod structural_match; mod ty; -fluent_messages! { "../messages.ftl" } +rustc_fluent_macro::fluent_messages! { "../messages.ftl" } pub fn provide(providers: &mut Providers) { abi::provide(providers); diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 9242a1a75..db43c31cc 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -81,8 +81,8 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { /// For the above example, this function returns `true` for `f1` and `false` for `f2`. #[instrument(level = "trace", skip(self), ret)] fn check_tait_defining_scope(&self, opaque_def_id: LocalDefId) -> bool { - let mut hir_id = self.tcx.hir().local_def_id_to_hir_id(self.item); - let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(opaque_def_id); + let mut hir_id = self.tcx.local_def_id_to_hir_id(self.item); + let opaque_hir_id = self.tcx.local_def_id_to_hir_id(opaque_def_id); // Named opaque types can be defined by any siblings or children of siblings. let scope = self.tcx.hir().get_defining_scope(opaque_hir_id); @@ -159,10 +159,10 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { // Only check that the parent generics of the TAIT/RPIT are unique. // the args owned by the opaque are going to always be duplicate // lifetime params for RPITs, and empty for TAITs. - match self - .tcx - .uses_unique_generic_params(&alias_ty.args[..parent_count], CheckRegions::Bound) - { + match self.tcx.uses_unique_generic_params( + &alias_ty.args[..parent_count], + CheckRegions::FromFunction, + ) { Ok(()) => { // FIXME: implement higher kinded lifetime bounds on nested opaque types. They are not // supported at all, so this is sound to do, but once we want to support them, you'll @@ -238,7 +238,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { .instantiate(self.tcx, impl_args) .visit_with(self); } else { - self.tcx.sess.delay_span_bug( + self.tcx.sess.span_delayed_bug( self.tcx.def_span(assoc.def_id), "item had incorrect args", ); @@ -313,7 +313,7 @@ fn opaque_types_defined_by<'tcx>( | DefKind::Impl { .. } => {} // Closures and coroutines are type checked with their parent, so we need to allow all // opaques from the closure signature *and* from the parent body. - DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => { + DefKind::Closure | DefKind::InlineConst => { collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); } } diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index f34e0df2c..3aaa2e73b 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -6,7 +6,7 @@ use rustc_middle::query::Providers; use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; use rustc_span::def_id::LocalDefId; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { representability, representability_adt_ty, params_in_repr, ..*providers }; } diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index ccdc61201..b155a4ac8 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::Span; use rustc_type_ir::visit::TypeVisitable; -pub trait SpannedTypeVisitor<'tcx> { +pub(crate) trait SpannedTypeVisitor<'tcx> { type BreakTy = !; fn visit( &mut self, @@ -17,7 +17,7 @@ pub trait SpannedTypeVisitor<'tcx> { ) -> ControlFlow; } -pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( +pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( tcx: TyCtxt<'tcx>, item: LocalDefId, visitor: &mut V, @@ -28,7 +28,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( // Walk over the signature of the function DefKind::AssocFn | DefKind::Fn => { let ty_sig = tcx.fn_sig(item).instantiate_identity(); - let hir_sig = tcx.hir().get_by_def_id(item).fn_decl().unwrap(); + let hir_sig = tcx.hir_node_by_def_id(item).fn_decl().unwrap(); // Walk over the inputs and outputs manually in order to get good spans for them. visitor.visit(hir_sig.output.span(), ty_sig.output()); for (hir, ty) in hir_sig.inputs.iter().zip(ty_sig.inputs().iter()) { @@ -42,7 +42,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( DefKind::TyAlias {..} | DefKind::AssocTy | // Walk over the type of the item DefKind::Static(_) | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => { - let span = match tcx.hir().get_by_def_id(item).ty() { + let span = match tcx.hir_node_by_def_id(item).ty() { Some(ty) => ty.span, _ => tcx.def_span(item), }; @@ -67,14 +67,14 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( // These are not part of a public API, they can only appear as hidden types, and there // the interesting parts are solely in the signature of the containing item's opaque type // or dyn type. - DefKind::InlineConst | DefKind::Closure | DefKind::Coroutine => {} + DefKind::InlineConst | DefKind::Closure => {} DefKind::Impl { of_trait } => { if of_trait { - let span = tcx.hir().get_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span; + let span = tcx.hir_node_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span; let args = &tcx.impl_trait_ref(item).unwrap().instantiate_identity().args[1..]; visitor.visit(span, args)?; } - let span = match tcx.hir().get_by_def_id(item).ty() { + let span = match tcx.hir_node_by_def_id(item).ty() { Some(ty) => ty.span, _ => tcx.def_span(item), }; diff --git a/compiler/rustc_ty_utils/src/structural_match.rs b/compiler/rustc_ty_utils/src/structural_match.rs index 215acbe2c..6e7a98877 100644 --- a/compiler/rustc_ty_utils/src/structural_match.rs +++ b/compiler/rustc_ty_utils/src/structural_match.rs @@ -39,6 +39,6 @@ fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool { ocx.select_all_or_error().is_empty() } -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.has_structural_eq_impls = has_structural_eq_impls; } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index abf3e108e..2158aacab 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -25,7 +25,7 @@ fn sized_constraint_for_ty<'tcx>( vec![ty] } - Tuple(ref tys) => match tys.last() { + Tuple(tys) => match tys.last() { None => vec![], Some(&ty) => sized_constraint_for_ty(tcx, adtdef, ty), }, @@ -74,7 +74,7 @@ fn sized_constraint_for_ty<'tcx>( } fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { - match tcx.hir().get_by_def_id(def_id) { + match tcx.hir_node_by_def_id(def_id) { hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness, hir::Node::ImplItem(hir::ImplItem { defaultness, .. }) | hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness, @@ -195,7 +195,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { // bounds of the RPITIT. Shift these binders back out when // constructing the top-level projection predicate. let shifted_alias_ty = self.tcx.fold_regions(unshifted_alias_ty, |re, depth| { - if let ty::ReLateBound(index, bv) = re.kind() { + if let ty::ReBound(index, bv) = re.kind() { if depth != ty::INNERMOST { return ty::Region::new_error_with_message( self.tcx, @@ -203,11 +203,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { "we shouldn't walk non-predicate binders with `impl Trait`...", ); } - ty::Region::new_late_bound( - self.tcx, - index.shifted_out_to_binder(self.depth), - bv, - ) + ty::Region::new_bound(self.tcx, index.shifted_out_to_binder(self.depth), bv) } else { re } @@ -289,7 +285,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option data.principal().is_none(), + ty::Dynamic(data, re, _) if re.is_static() => data.principal().is_none(), _ => false, }; @@ -304,7 +300,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option, def_id: LocalDefId) -> ty::Asyncness { - let node = tcx.hir().get_by_def_id(def_id); + let node = tcx.hir_node_by_def_id(def_id); node.fn_sig().map_or(ty::Asyncness::No, |sig| match sig.header.asyncness { hir::IsAsync::Async(_) => ty::Asyncness::Yes, hir::IsAsync::NotAsync => ty::Asyncness::No, @@ -355,7 +351,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet