diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_mir_build/src/thir/cx | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_build/src/thir/cx')
-rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/block.rs | 2 | ||||
-rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/expr.rs | 15 | ||||
-rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/mod.rs | 25 |
3 files changed, 25 insertions, 17 deletions
diff --git a/compiler/rustc_mir_build/src/thir/cx/block.rs b/compiler/rustc_mir_build/src/thir/cx/block.rs index 8aacec53f..a46ad6423 100644 --- a/compiler/rustc_mir_build/src/thir/cx/block.rs +++ b/compiler/rustc_mir_build/src/thir/cx/block.rs @@ -5,7 +5,7 @@ use rustc_middle::middle::region; use rustc_middle::thir::*; use rustc_middle::ty; -use rustc_index::vec::Idx; +use rustc_index::Idx; use rustc_middle::ty::CanonicalUserTypeAnnotation; impl<'tcx> Cx<'tcx> { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 8e2e92e6f..b20495d60 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -5,7 +5,7 @@ use crate::thir::util::UserAnnotatedTyHelpers; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; -use rustc_index::vec::Idx; +use rustc_index::Idx; use rustc_middle::hir::place::Place as HirPlace; use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::hir::place::ProjectionKind as HirProjectionKind; @@ -130,6 +130,7 @@ impl<'tcx> Cx<'tcx> { ExprKind::Pointer { cast: PointerCast::Unsize, source: self.thir.exprs.push(expr) } } Adjust::Pointer(cast) => ExprKind::Pointer { cast, source: self.thir.exprs.push(expr) }, + Adjust::NeverToAny if adjustment.target.is_never() => return expr, Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) }, Adjust::Deref(None) => { adjust_span(&mut expr); @@ -332,7 +333,7 @@ impl<'tcx> Cx<'tcx> { } else if let Some(box_item) = tcx.lang_items().owned_box() { if let hir::ExprKind::Path(hir::QPath::TypeRelative(ty, fn_path)) = fun.kind && let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind - && path.res.opt_def_id().map_or(false, |did| did == box_item) + && path.res.opt_def_id().is_some_and(|did| did == box_item) && fn_path.ident.name == sym::new && let [value] = args { @@ -664,6 +665,14 @@ impl<'tcx> Cx<'tcx> { line_spans: asm.line_spans, })), + hir::ExprKind::OffsetOf(_, _) => { + let data = self.typeck_results.offset_of_data(); + let &(container, ref indices) = data.get(expr.hir_id).unwrap(); + let fields = tcx.mk_fields_from_iter(indices.iter().copied()); + + ExprKind::OffsetOf { container, fields } + } + hir::ExprKind::ConstBlock(ref anon_const) => { let ty = self.typeck_results().node_type(anon_const.hir_id); let did = anon_const.def_id.to_def_id(); @@ -947,7 +956,7 @@ impl<'tcx> Cx<'tcx> { let is_upvar = self .tcx .upvars_mentioned(self.body_owner) - .map_or(false, |upvars| upvars.contains_key(&var_hir_id)); + .is_some_and(|upvars| upvars.contains_key(&var_hir_id)); debug!( "convert_var({:?}): is_upvar={}, body_owner={:?}", diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 070544446..463f639de 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -20,25 +20,25 @@ use rustc_span::Span; pub(crate) fn thir_body( tcx: TyCtxt<'_>, - owner_def: ty::WithOptConstParam<LocalDefId>, + owner_def: LocalDefId, ) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> { let hir = tcx.hir(); - let body = hir.body(hir.body_owned_by(owner_def.did)); + let body = hir.body(hir.body_owned_by(owner_def)); let mut cx = Cx::new(tcx, owner_def); if let Some(reported) = cx.typeck_results.tainted_by_errors { return Err(reported); } let expr = cx.mirror_expr(&body.value); - let owner_id = hir.local_def_id_to_hir_id(owner_def.did); + let owner_id = hir.local_def_id_to_hir_id(owner_def); if let Some(ref fn_decl) = hir.fn_decl_by_hir_id(owner_id) { - let closure_env_param = cx.closure_env_param(owner_def.did, owner_id); + let closure_env_param = cx.closure_env_param(owner_def, owner_id); let explicit_params = cx.explicit_params(owner_id, fn_decl, body); cx.thir.params = closure_env_param.into_iter().chain(explicit_params).collect(); // The resume argument may be missing, in that case we need to provide it here. // It will always be `()` in this case. - if tcx.def_kind(owner_def.did) == DefKind::Generator && body.params.is_empty() { + if tcx.def_kind(owner_def) == DefKind::Generator && body.params.is_empty() { cx.thir.params.push(Param { ty: tcx.mk_unit(), pat: None, @@ -78,13 +78,12 @@ struct Cx<'tcx> { } impl<'tcx> Cx<'tcx> { - fn new(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) -> Cx<'tcx> { - let typeck_results = tcx.typeck_opt_const_arg(def); - let did = def.did; + fn new(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Cx<'tcx> { + let typeck_results = tcx.typeck(def); let hir = tcx.hir(); - let hir_id = hir.local_def_id_to_hir_id(did); + let hir_id = hir.local_def_id_to_hir_id(def); - let body_type = if hir.body_owner_kind(did).is_fn_or_closure() { + let body_type = if hir.body_owner_kind(def).is_fn_or_closure() { // fetch the fully liberated fn signature (that is, all bound // types/lifetimes replaced) BodyTy::Fn(typeck_results.liberated_fn_sigs()[hir_id]) @@ -106,11 +105,11 @@ impl<'tcx> Cx<'tcx> { Cx { tcx, thir: Thir::new(body_type), - param_env: tcx.param_env(def.did), - region_scope_tree: tcx.region_scope_tree(def.did), + param_env: tcx.param_env(def), + region_scope_tree: tcx.region_scope_tree(def), typeck_results, rvalue_scopes: &typeck_results.rvalue_scopes, - body_owner: did.to_def_id(), + body_owner: def.to_def_id(), adjustment_span: None, apply_adjustments: hir .attrs(hir_id) |