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_mir_build/src/thir/cx/expr.rs | 65 ++++++++++++++-------------- compiler/rustc_mir_build/src/thir/cx/mod.rs | 11 ++++- 2 files changed, 43 insertions(+), 33 deletions(-) (limited to 'compiler/rustc_mir_build/src/thir/cx') diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index c7a7c3e3f..261b95ba9 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -14,11 +14,10 @@ use rustc_middle::thir::*; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCast, }; -use rustc_middle::ty::subst::{InternalSubsts, SubstsRef}; +use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{ self, AdtKind, InlineConstSubsts, InlineConstSubstsParts, ScalarInt, Ty, UpvarSubsts, UserType, }; -use rustc_span::def_id::DefId; use rustc_span::Span; use rustc_target::abi::VariantIdx; @@ -51,11 +50,17 @@ impl<'tcx> Cx<'tcx> { trace!(?expr.ty); // Now apply adjustments, if any. - for adjustment in self.typeck_results.expr_adjustments(hir_expr) { - trace!(?expr, ?adjustment); - let span = expr.span; - expr = - self.apply_adjustment(hir_expr, expr, adjustment, adjustment_span.unwrap_or(span)); + if self.apply_adjustments { + for adjustment in self.typeck_results.expr_adjustments(hir_expr) { + trace!(?expr, ?adjustment); + let span = expr.span; + expr = self.apply_adjustment( + hir_expr, + expr, + adjustment, + adjustment_span.unwrap_or(span), + ); + } } trace!(?expr.ty, "after adjustments"); @@ -481,7 +486,7 @@ impl<'tcx> Cx<'tcx> { substs, user_ty, fields: self.field_refs(fields), - base: base.as_ref().map(|base| FruInfo { + base: base.map(|base| FruInfo { base: self.mirror_expr(base), field_types: self.typeck_results().fru_field_types()[expr.hir_id] .iter() @@ -584,7 +589,7 @@ impl<'tcx> Cx<'tcx> { InlineAsmOperand::Out { reg, late, - expr: expr.as_ref().map(|expr| self.mirror_expr(expr)), + expr: expr.map(|expr| self.mirror_expr(expr)), } } hir::InlineAsmOperand::InOut { reg, late, ref expr } => { @@ -599,27 +604,25 @@ impl<'tcx> Cx<'tcx> { reg, late, in_expr: self.mirror_expr(in_expr), - out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)), + out_expr: out_expr.map(|expr| self.mirror_expr(expr)), }, hir::InlineAsmOperand::Const { ref anon_const } => { - let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id); let value = mir::ConstantKind::from_anon_const( tcx, - anon_const_def_id, + anon_const.def_id, self.param_env, ); - let span = tcx.hir().span(anon_const.hir_id); + let span = tcx.def_span(anon_const.def_id); InlineAsmOperand::Const { value, span } } hir::InlineAsmOperand::SymFn { ref anon_const } => { - let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id); let value = mir::ConstantKind::from_anon_const( tcx, - anon_const_def_id, + anon_const.def_id, self.param_env, ); - let span = tcx.hir().span(anon_const.hir_id); + let span = tcx.def_span(anon_const.def_id); InlineAsmOperand::SymFn { value, span } } @@ -634,7 +637,7 @@ impl<'tcx> Cx<'tcx> { hir::ExprKind::ConstBlock(ref anon_const) => { let ty = self.typeck_results().node_type(anon_const.hir_id); - let did = tcx.hir().local_def_id(anon_const.hir_id).to_def_id(); + let did = anon_const.def_id.to_def_id(); let typeck_root_def_id = tcx.typeck_root_def_id(did); let parent_substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id)); @@ -653,13 +656,11 @@ impl<'tcx> Cx<'tcx> { ExprKind::Repeat { value: self.mirror_expr(v), count: *count } } - hir::ExprKind::Ret(ref v) => { - ExprKind::Return { value: v.as_ref().map(|v| self.mirror_expr(v)) } - } + hir::ExprKind::Ret(ref v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) }, hir::ExprKind::Break(dest, ref value) => match dest.target_id { Ok(target_id) => ExprKind::Break { label: region::Scope { id: target_id.local_id, data: region::ScopeData::Node }, - value: value.as_ref().map(|value| self.mirror_expr(value)), + value: value.map(|value| self.mirror_expr(value)), }, Err(err) => bug!("invalid loop id for break: {}", err), }, @@ -703,7 +704,7 @@ impl<'tcx> Cx<'tcx> { hir::ExprKind::Field(ref source, ..) => ExprKind::Field { lhs: self.mirror_expr(source), variant_index: VariantIdx::new(0), - name: Field::new(tcx.field_index(expr.hir_id, self.typeck_results)), + name: Field::new(self.typeck_results.field_index(expr.hir_id)), }, hir::ExprKind::Cast(ref source, ref cast_ty) => { // Check for a user-given type annotation on this `cast` @@ -802,12 +803,12 @@ impl<'tcx> Cx<'tcx> { &mut self, expr: &hir::Expr<'_>, span: Span, - overloaded_callee: Option<(DefId, SubstsRef<'tcx>)>, + overloaded_callee: Option>, ) -> Expr<'tcx> { let temp_lifetime = self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id); - let (def_id, substs, user_ty) = match overloaded_callee { - Some((def_id, substs)) => (def_id, substs, None), + let (ty, user_ty) = match overloaded_callee { + Some(fn_def) => (fn_def, None), None => { let (kind, def_id) = self.typeck_results().type_dependent_def(expr.hir_id).unwrap_or_else(|| { @@ -815,10 +816,12 @@ impl<'tcx> Cx<'tcx> { }); let user_ty = self.user_substs_applied_to_res(expr.hir_id, Res::Def(kind, def_id)); debug!("method_callee: user_ty={:?}", user_ty); - (def_id, self.typeck_results().node_substs(expr.hir_id), user_ty) + ( + self.tcx().mk_fn_def(def_id, self.typeck_results().node_substs(expr.hir_id)), + user_ty, + ) } }; - let ty = self.tcx().mk_fn_def(def_id, substs); Expr { temp_lifetime, ty, span, kind: ExprKind::ZstLiteral { user_ty } } } @@ -853,9 +856,7 @@ impl<'tcx> Cx<'tcx> { Res::Def(DefKind::ConstParam, def_id) => { let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - let item_id = self.tcx.hir().get_parent_node(hir_id); - let item_def_id = self.tcx.hir().local_def_id(item_id); - let generics = self.tcx.generics_of(item_def_id); + let generics = self.tcx.generics_of(hir_id.owner); let index = generics.param_def_id_to_index[&def_id]; let name = self.tcx.hir().name(hir_id); let param = ty::ParamConst::new(index, name); @@ -955,7 +956,7 @@ impl<'tcx> Cx<'tcx> { &mut self, expr: &'tcx hir::Expr<'tcx>, place_ty: Ty<'tcx>, - overloaded_callee: Option<(DefId, SubstsRef<'tcx>)>, + overloaded_callee: Option>, args: Box<[ExprId]>, span: Span, ) -> ExprKind<'tcx> { @@ -1078,7 +1079,7 @@ impl<'tcx> Cx<'tcx> { fields .iter() .map(|field| FieldExpr { - name: Field::new(self.tcx.field_index(field.hir_id, self.typeck_results)), + name: Field::new(self.typeck_results.field_index(field.hir_id)), expr: self.mirror_expr(field.expr), }) .collect() diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 1d95d6b53..b5c4b7b13 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -80,6 +80,9 @@ struct Cx<'tcx> { /// for the receiver. adjustment_span: Option<(HirId, Span)>, + /// False to indicate that adjustments should not be applied. Only used for `custom_mir` + apply_adjustments: bool, + /// The `DefId` of the owner of this body. body_owner: DefId, } @@ -87,6 +90,8 @@ struct Cx<'tcx> { impl<'tcx> Cx<'tcx> { fn new(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam) -> Cx<'tcx> { let typeck_results = tcx.typeck_opt_const_arg(def); + let did = def.did; + let hir = tcx.hir(); Cx { tcx, thir: Thir::new(), @@ -94,8 +99,12 @@ impl<'tcx> Cx<'tcx> { region_scope_tree: tcx.region_scope_tree(def.did), typeck_results, rvalue_scopes: &typeck_results.rvalue_scopes, - body_owner: def.did.to_def_id(), + body_owner: did.to_def_id(), adjustment_span: None, + apply_adjustments: hir + .attrs(hir.local_def_id_to_hir_id(did)) + .iter() + .all(|attr| attr.name_or_empty() != rustc_span::sym::custom_mir), } } -- cgit v1.2.3