Skip to content

Commit 1f3278c

Browse files
committed
Auto merge of #162996 - Zalathar:rollup-uUWX3SP, r=Zalathar
Rollup of 18 pull requests Successful merges: - #162499 (`rustc_codegen_gcc` subtree update) - #161424 (implement `VaArgSafe` for `f128`) - #161777 (Add Natvis visualiser and debuginfo tests for `f128`) - #162506 (Avoid suggesting imports of traits declared inside fn bodies) - #162591 (Move parse error recovery for expression operators "out of line" & refactor in the area) - #162669 ([rustdoc] Correctly handle intra-doc links on inlined same item with different names) - #162733 (Add useful APIs to `Unique(Arc|Rc)`) - #162913 (Refactor LivenessResults into LivenessComputation, without typeck) - #162950 (More AST lowering cleanups) - #162964 (Update `browser-ui-test` version to `0.25.2`) - #162979 (mark `f128` as reliable on `powerpc64` with `+vsx`) - #161743 (Add performance notes for the floating-point round method) - #162797 (yeet AliasConstKind::opt_def_id) - #162836 (Ping T-libs-ping instead of T-libs-fcp for backports) - #162873 (Adjust `bug!`/`span_bug!` emission) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162956 (Add missing `#[repr(C)]` in UI, codegen and assembly tests) - #162981 (rustc-dev-guide subtree update) Failed merges: - #162177 (Properly implement the gpu-kernel ABI for amdgpu)
2 parents 971903d + d634e9c commit 1f3278c

226 files changed

Lines changed: 7551 additions & 2827 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10181018
expr.span,
10191019
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
10201020
await_kw_span,
1021-
item_span: self.current_item,
1021+
item_span: self.current_item_span,
10221022
})),
10231023
);
10241024
return hir::ExprKind::Block(
@@ -1712,7 +1712,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17121712
}
17131713
Some(hir::CoroutineKind::Coroutine(_)) => false,
17141714
None => {
1715-
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
1715+
let suggestion = self.current_item_span.map(|s| s.shrink_to_lo());
17161716
self.dcx().emit_err(YieldInClosure { span, suggestion });
17171717
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));
17181718

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
55
use rustc_hir::attrs::{AttributeKind, EiiImplResolution};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::{
8-
self as hir, CRATE_OWNER_ID, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target,
9-
find_attr,
8+
self as hir, HirId, ImplItemImplKind, LifetimeSource, PredicateOrigin, Target, find_attr,
109
};
11-
use rustc_middle::middle::resolve::ResolverAstLowering;
12-
use rustc_middle::ty::TyCtxt;
1310
use rustc_middle::ty::data_structures::IndexMap;
1411
use rustc_span::def_id::{DefId, LocalDefId};
1512
use rustc_span::edit_distance::find_best_match_for_name;
@@ -28,14 +25,9 @@ use super::{
2825
};
2926
use crate::diagnostics::{ConstComptimeFn, ResolvingRestrictionKind, RestrictionAncestorOnly};
3027

31-
pub(super) struct ItemLowerer<'a, 'hir> {
32-
pub(super) tcx: TyCtxt<'hir>,
33-
pub(super) resolver: &'a ResolverAstLowering<'hir>,
34-
}
35-
36-
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
37-
/// to the where clause that is preferred, if it exists. Otherwise, it sets the span to the other where
38-
/// clause if it exists.
28+
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set
29+
/// the span to the where clause that is preferred, if it exists. Otherwise, it sets the span to
30+
/// the other where clause if it exists.
3931
fn add_ty_alias_where_clause(
4032
generics: &mut ast::Generics,
4133
after_where_clause: &ast::WhereClause,
@@ -52,48 +44,6 @@ fn add_ty_alias_where_clause(
5244
if before.0 || !after.0 { before } else { after };
5345
}
5446

55-
impl<'hir> ItemLowerer<'_, 'hir> {
56-
fn with_lctx(
57-
&mut self,
58-
owner: NodeId,
59-
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
60-
) -> hir::MaybeOwner<'hir> {
61-
let mut lctx = LoweringContext::new(self.tcx, self.resolver, owner);
62-
63-
let item = f(&mut lctx);
64-
65-
let info = lctx.curr_owner.into_owner_info(self.tcx, item);
66-
hir::MaybeOwner::Owner(lctx.arena.alloc(info))
67-
}
68-
69-
#[instrument(level = "debug", skip(self, c))]
70-
pub(super) fn lower_crate(&mut self, c: &Crate) -> hir::MaybeOwner<'hir> {
71-
self.with_lctx(CRATE_NODE_ID, |lctx| {
72-
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
73-
let module = lctx.lower_mod(&c.items, &c.spans);
74-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
75-
hir::OwnerNode::Crate(module)
76-
})
77-
}
78-
79-
#[instrument(level = "debug", skip(self))]
80-
pub(super) fn lower_item(&mut self, item: &Item) -> hir::MaybeOwner<'hir> {
81-
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
82-
}
83-
84-
pub(super) fn lower_trait_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
85-
self.with_lctx(item.id, |lctx| hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)))
86-
}
87-
88-
pub(super) fn lower_impl_item(&mut self, item: &AssocItem) -> hir::MaybeOwner<'hir> {
89-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)))
90-
}
91-
92-
pub(super) fn lower_foreign_item(&mut self, item: &ForeignItem) -> hir::MaybeOwner<'hir> {
93-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)))
94-
}
95-
}
96-
9747
impl<'hir> LoweringContext<'_, 'hir> {
9848
pub(super) fn lower_mod(
9949
&mut self,
@@ -203,7 +153,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
203153
}
204154
}
205155

206-
fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
156+
pub(super) fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
207157
let owner_id = self.curr_owner.owner_id();
208158
let hir_id: HirId = owner_id.into();
209159
let vis_span = self.lower_span(i.vis.span);
@@ -544,7 +494,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
544494
}
545495
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => {
546496
let ident = self.lower_ident(*ident);
547-
let body = Box::new(self.lower_delim_args(body));
497+
let body = body.clone();
548498
let def_id = self.curr_owner.owner.def_id;
549499
let def_kind = self.tcx.def_kind(def_id);
550500
let DefKind::Macro(macro_kinds) = def_kind else {
@@ -730,7 +680,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
730680
}
731681
}
732682

733-
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
683+
pub(super) fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
734684
let owner_id = self.curr_owner.owner_id();
735685
let hir_id: HirId = owner_id.into();
736686
let attrs =
@@ -911,7 +861,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
911861
}
912862
}
913863

914-
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
864+
pub(super) fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
915865
let trait_item_def_id = self.curr_owner.owner_id();
916866
let hir_id: HirId = trait_item_def_id.into();
917867
let attrs = self.lower_attrs(
@@ -1160,7 +1110,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11601110
ident
11611111
}
11621112

1163-
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
1113+
pub(super) fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
11641114
let owner_id = self.curr_owner.owner_id();
11651115
let hir_id: HirId = owner_id.into();
11661116
let parent_id = self.tcx.local_parent(owner_id.def_id);

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
6060
use rustc_hir::definitions::PerParentDisambiguatorState;
6161
use rustc_hir::lints::DelayedLint;
6262
use rustc_hir::{
63-
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
64-
LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate, find_attr,
63+
self as hir, AngleBrackets, CRATE_OWNER_ID, ConstArg, GenericArg, HirId, ItemLocalMap,
64+
LifetimeSource, LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate,
65+
find_attr,
6566
};
6667
use rustc_index::{Idx, IndexSlice, IndexVec};
6768
use rustc_macros::extension;
@@ -296,7 +297,7 @@ struct LoweringContext<'a, 'hir> {
296297

297298
/// Used to get the current `fn`'s def span to point to when using `await`
298299
/// outside of an `async fn`.
299-
current_item: Option<Span>,
300+
current_item_span: Option<Span>,
300301

301302
try_block_scope: TryBlockScope,
302303
loop_scope: Option<HirId>,
@@ -366,7 +367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
366367
is_in_dyn_type: false,
367368
coroutine_kind: None,
368369
task_context: None,
369-
current_item: None,
370+
current_item_span: None,
370371

371372
move_expr_bindings: Vec::new(),
372373
lowering_move_expr_initializer: false,
@@ -783,15 +784,37 @@ fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
783784
return fallback_to_ancestor(tcx.local_parent(def_id));
784785
};
785786

786-
let mut item_lowerer = item::ItemLowerer { tcx, resolver: &*resolver };
787+
fn with_lctx<'hir>(
788+
tcx: TyCtxt<'hir>,
789+
resolver: &ResolverAstLowering<'hir>,
790+
owner: NodeId,
791+
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
792+
) -> hir::MaybeOwner<'hir> {
793+
let mut lctx = LoweringContext::new(tcx, resolver, owner);
794+
let item = f(&mut lctx);
795+
hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx, item))
796+
}
787797

788798
let item = match &node {
789799
// The item existed in the AST.
790-
AstOwner::Crate(c) => item_lowerer.lower_crate(&c),
791-
AstOwner::Item(item) => item_lowerer.lower_item(&item),
792-
AstOwner::TraitItem(item) => item_lowerer.lower_trait_item(&item),
793-
AstOwner::ImplItem(item) => item_lowerer.lower_impl_item(&item),
794-
AstOwner::ForeignItem(item) => item_lowerer.lower_foreign_item(&item),
800+
AstOwner::Crate(c) => with_lctx(tcx, &*resolver, CRATE_NODE_ID, |lctx| {
801+
debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
802+
let module = lctx.lower_mod(&c.items, &c.spans);
803+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
804+
hir::OwnerNode::Crate(module)
805+
}),
806+
AstOwner::Item(item) => {
807+
with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
808+
}
809+
AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
810+
hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
811+
}),
812+
AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
813+
hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
814+
}),
815+
AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
816+
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
817+
}),
795818
AstOwner::NestedUseTree(owner_id) => fallback_to_ancestor(*owner_id),
796819
// The item existed in the AST, but is not a HIR owner.
797820
// Fetch the correct information from its parent.
@@ -824,7 +847,7 @@ enum GenericArgsMode {
824847
ParenSugar,
825848
/// Allow RTN, don't allow paren sugar.
826849
ReturnTypeNotation,
827-
// Error if parenthesized generics or RTN are encountered.
850+
/// Error if parenthesized generics or RTN are encountered.
828851
Err,
829852
/// Silence errors when lowering generics. Only used with `Res::Err`.
830853
Silence,
@@ -982,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9821005
}
9831006

9841007
#[instrument(level = "trace", skip(self))]
985-
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
1008+
fn lower_res(&self, res: Res<NodeId>) -> Res {
9861009
let res: Result<Res, ()> = res.apply_id(|id| {
9871010
let owner = self.curr_owner.owner_id();
9881011
let local_id =
@@ -999,11 +1022,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
9991022
res.unwrap_or(Res::Err)
10001023
}
10011024

1002-
fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
1025+
fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
10031026
self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
10041027
}
10051028

1006-
fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
1029+
fn lower_import_res(&self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
10071030
debug_assert_eq!(id, self.curr_owner.owner.id);
10081031
let per_ns = self.curr_owner.owner.import_res.map(|res| res.map(|res| self.lower_res(res)));
10091032
if per_ns.is_empty() {
@@ -1154,8 +1177,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11541177
}
11551178

11561179
fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1157-
let current_item = self.current_item;
1158-
self.current_item = Some(scope_span);
1180+
let current_item_span = self.current_item_span;
1181+
self.current_item_span = Some(scope_span);
11591182

11601183
let was_in_loop_condition = self.is_in_loop_condition;
11611184
self.is_in_loop_condition = false;
@@ -1172,7 +1195,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11721195

11731196
self.is_in_loop_condition = was_in_loop_condition;
11741197

1175-
self.current_item = current_item;
1198+
self.current_item_span = current_item_span;
11761199

11771200
ret
11781201
}
@@ -1261,10 +1284,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
12611284
}
12621285
}
12631286

1264-
fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
1265-
args.clone()
1266-
}
1267-
12681287
/// Lower an associated item constraint.
12691288
#[instrument(level = "debug", skip_all)]
12701289
fn lower_assoc_item_constraint(
@@ -1647,8 +1666,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
16471666
self.lower_array_length_to_const_arg(length),
16481667
),
16491668
TyKind::TraitObject(bounds, kind) => {
1650-
let mut lifetime_bound = None;
16511669
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1670+
let mut lifetime_bound = None;
16521671
let bounds =
16531672
this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
16541673
// We can safely ignore constness here since AST validation
@@ -1681,9 +1700,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16811700
None
16821701
}
16831702
}));
1684-
let lifetime_bound =
1685-
lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1686-
(bounds, lifetime_bound)
1703+
(bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
16871704
});
16881705
hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
16891706
}
@@ -3058,15 +3075,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
30583075
}))
30593076
}
30603077

3061-
fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
3078+
fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
30623079
match u {
30633080
CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
30643081
UserProvided => hir::UnsafeSource::UserProvided,
30653082
}
30663083
}
30673084

30683085
fn lower_trait_bound_modifiers(
3069-
&mut self,
3086+
&self,
30703087
modifiers: TraitBoundModifiers,
30713088
) -> hir::TraitBoundModifiers {
30723089
let constness = match modifiers.constness {

‎compiler/rustc_borrowck/src/region_infer/values.rs‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,6 @@ impl<'tcx, N: Idx> RegionValues<'tcx, N> {
409409
}
410410
}
411411

412-
/// For debugging purposes, returns a pretty-printed string of the given points.
413-
pub(crate) fn pretty_print_points(
414-
location_map: &DenseLocationMap,
415-
points: impl IntoIterator<Item = PointIndex>,
416-
) -> String {
417-
pretty_print_region_elements(
418-
points.into_iter().map(|p| location_map.to_location(p)).map(RegionElement::Location),
419-
)
420-
}
421-
422412
/// For debugging purposes, returns a pretty-printed string of the given region elements.
423413
fn pretty_print_region_elements<'tcx>(
424414
elements: impl IntoIterator<Item = RegionElement<'tcx>>,

‎compiler/rustc_borrowck/src/type_check/liveness/mod.rs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use itertools::{Either, Itertools};
22
use rustc_data_structures::fx::FxHashSet;
3+
use rustc_index::interval::IntervalSet;
34
use rustc_middle::mir::visit::{TyContext, Visitor};
45
use rustc_middle::mir::{Body, Local, Location, SourceInfo};
56
use rustc_middle::ty::relate::Relate;
67
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable};
78
use rustc_mir_dataflow::move_paths::MoveData;
8-
use rustc_mir_dataflow::points::DenseLocationMap;
9+
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
910
use rustc_span::span_bug;
11+
use rustc_trait_selection::traits::outlives_for_liveness::FreeRegionsVisitor;
1012
use tracing::debug;
1113

1214
use super::TypeChecker;
15+
use crate::BorrowckInferCtxt;
1316
use crate::constraints::OutlivesConstraintSet;
1417
use crate::polonius::{PoloniusContext, record_live_region_variance};
1518
use crate::region_infer::values::LivenessValues;
@@ -229,3 +232,18 @@ impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {
229232
}
230233
}
231234
}
235+
236+
pub(crate) fn make_all_regions_live<'tcx>(
237+
infcx: &BorrowckInferCtxt<'tcx>,
238+
universal_regions: &UniversalRegions<'tcx>,
239+
liveness: &mut LivenessValues,
240+
value: impl TypeVisitable<TyCtxt<'tcx>>,
241+
live_at: &IntervalSet<PointIndex>,
242+
) {
243+
debug!("make_all_regions_live(value={value:?})");
244+
value.visit_with(&mut FreeRegionsVisitor {
245+
tcx: infcx.tcx,
246+
param_env: infcx.param_env,
247+
op: |r| liveness.add_points(universal_regions.to_region_vid(r), live_at),
248+
});
249+
}

0 commit comments

Comments
 (0)