Skip to content

Commit 6906167

Browse files
committed
Auto merge of #148193 - camsteffen:remove-qpath-langitem, r=cjgillot
Remove `QPath::LangItem` Closes #115178. r? cjgillot
2 parents 72fe2ff + 95732f4 commit 6906167

File tree

76 files changed

+326
-477
lines changed

Some content is hidden

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

76 files changed

+326
-477
lines changed

compiler/rustc_ast_lowering/src/contract.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use thin_vec::thin_vec;
24

35
use crate::LoweringContext;
@@ -128,7 +130,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
128130
let req_span = self.mark_span_with_reason(
129131
rustc_span::DesugaringKind::Contract,
130132
lowered_req.span,
131-
None,
133+
Some(Arc::clone(&self.allow_contracts)),
132134
);
133135
let precond = self.expr_call_lang_item_fn_mut(
134136
req_span,
@@ -143,8 +145,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
143145
ens: &Box<rustc_ast::Expr>,
144146
) -> &'hir rustc_hir::Expr<'hir> {
145147
let ens_span = self.lower_span(ens.span);
146-
let ens_span =
147-
self.mark_span_with_reason(rustc_span::DesugaringKind::Contract, ens_span, None);
148+
let ens_span = self.mark_span_with_reason(
149+
rustc_span::DesugaringKind::Contract,
150+
ens_span,
151+
Some(Arc::clone(&self.allow_contracts)),
152+
);
148153
let lowered_ens = self.lower_expr_mut(&ens);
149154
self.expr_call_lang_item_fn(
150155
ens_span,

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
865865
};
866866

867867
let features = match await_kind {
868+
FutureKind::Future if is_async_gen => Some(Arc::clone(&self.allow_async_gen)),
868869
FutureKind::Future => None,
869870
FutureKind::AsyncIterator => Some(Arc::clone(&self.allow_for_await)),
870871
};
@@ -1479,7 +1480,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14791480
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
14801481
let e1 = self.lower_expr_mut(e1);
14811482
let e2 = self.lower_expr_mut(e2);
1482-
let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, span);
1483+
let fn_path = self.make_lang_item_qpath(hir::LangItem::RangeInclusiveNew, span, None);
14831484
let fn_expr = self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path)));
14841485
hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2])
14851486
}
@@ -1565,7 +1566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15651566
);
15661567

15671568
hir::ExprKind::Struct(
1568-
self.arena.alloc(hir::QPath::LangItem(lang_item, span)),
1569+
self.arena.alloc(self.make_lang_item_qpath(lang_item, span, None)),
15691570
fields,
15701571
hir::StructTailExpr::None,
15711572
)
@@ -1715,8 +1716,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
17151716
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
17161717
// This ensures that we store our resumed `ResumeContext` correctly, and also that
17171718
// the apparent value of the `yield` expression is `()`.
1718-
let wrapped_yielded = self.expr_call_lang_item_fn(
1719+
let desugar_span = self.mark_span_with_reason(
1720+
DesugaringKind::Async,
17191721
span,
1722+
Some(Arc::clone(&self.allow_async_gen)),
1723+
);
1724+
let wrapped_yielded = self.expr_call_lang_item_fn(
1725+
desugar_span,
17201726
hir::LangItem::AsyncGenReady,
17211727
std::slice::from_ref(yielded),
17221728
);
@@ -1728,7 +1734,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17281734
unreachable!("use of `await` outside of an async context.");
17291735
};
17301736
let task_context_ident = Ident::with_dummy_span(sym::_task_context);
1731-
let lhs = self.expr_ident(span, task_context_ident, task_context_hid);
1737+
let lhs = self.expr_ident(desugar_span, task_context_ident, task_context_hid);
17321738

17331739
hir::ExprKind::Assign(lhs, yield_expr, self.lower_span(span))
17341740
} else {
@@ -2161,7 +2167,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21612167
lang_item: hir::LangItem,
21622168
fields: &'hir [hir::Expr<'hir>],
21632169
) -> hir::Expr<'hir> {
2164-
let path = self.arena.alloc(self.lang_item_path(span, lang_item));
2170+
let path = self.arena.alloc(self.make_lang_item_qpath(lang_item, span, None));
21652171
self.expr_enum_variant(span, path, fields)
21662172
}
21672173

@@ -2198,16 +2204,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
21982204
span: Span,
21992205
lang_item: hir::LangItem,
22002206
) -> hir::Expr<'hir> {
2201-
let path = self.lang_item_path(span, lang_item);
2202-
self.expr(span, hir::ExprKind::Path(path))
2203-
}
2204-
2205-
pub(super) fn lang_item_path(
2206-
&mut self,
2207-
span: Span,
2208-
lang_item: hir::LangItem,
2209-
) -> hir::QPath<'hir> {
2210-
hir::QPath::LangItem(lang_item, self.lower_span(span))
2207+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2208+
self.expr(span, hir::ExprKind::Path(qpath))
22112209
}
22122210

22132211
/// `<LangItem>::name`

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,8 @@ fn make_format_spec<'hir>(
391391
let flags = ctx.expr_field(Ident::new(sym::flags, sp), ctx.arena.alloc(flags), sp);
392392
let precision = ctx.expr_field(Ident::new(sym::precision, sp), ctx.arena.alloc(precision), sp);
393393
let width = ctx.expr_field(Ident::new(sym::width, sp), ctx.arena.alloc(width), sp);
394-
let placeholder = ctx.arena.alloc(hir::QPath::LangItem(hir::LangItem::FormatPlaceholder, sp));
394+
let placeholder =
395+
ctx.arena.alloc(ctx.make_lang_item_qpath(hir::LangItem::FormatPlaceholder, sp, None));
395396
let fields = ctx.arena.alloc_from_iter([position, flags, precision, width]);
396397
ctx.expr(sp, hir::ExprKind::Struct(placeholder, fields, hir::StructTailExpr::None))
397398
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ struct LoweringContext<'a, 'hir> {
138138
#[cfg(debug_assertions)]
139139
node_id_to_local_id: NodeMap<hir::ItemLocalId>,
140140

141+
allow_contracts: Arc<[Symbol]>,
141142
allow_try_trait: Arc<[Symbol]>,
142143
allow_gen_future: Arc<[Symbol]>,
143144
allow_pattern_type: Arc<[Symbol]>,
145+
allow_async_gen: Arc<[Symbol]>,
144146
allow_async_iterator: Arc<[Symbol]>,
145147
allow_for_await: Arc<[Symbol]>,
146148
allow_async_fn_traits: Arc<[Symbol]>,
@@ -183,15 +185,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
183185
current_item: None,
184186
impl_trait_defs: Vec::new(),
185187
impl_trait_bounds: Vec::new(),
188+
allow_contracts: [sym::contracts_internals].into(),
186189
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
187190
allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
188191
allow_gen_future: if tcx.features().async_fn_track_caller() {
189192
[sym::gen_future, sym::closure_track_caller].into()
190193
} else {
191194
[sym::gen_future].into()
192195
},
193-
allow_for_await: [sym::async_iterator].into(),
196+
allow_for_await: [sym::async_gen_internals, sym::async_iterator].into(),
194197
allow_async_fn_traits: [sym::async_fn_traits].into(),
198+
allow_async_gen: [sym::async_gen_internals].into(),
195199
// FIXME(gen_blocks): how does `closure_track_caller`/`async_fn_track_caller`
196200
// interact with `gen`/`async gen` blocks
197201
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
@@ -2531,8 +2535,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25312535
lang_item: hir::LangItem,
25322536
fields: &'hir [hir::PatField<'hir>],
25332537
) -> &'hir hir::Pat<'hir> {
2534-
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
2535-
self.pat(span, hir::PatKind::Struct(qpath, fields, None))
2538+
let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2539+
self.pat(span, hir::PatKind::Struct(path, fields, None))
25362540
}
25372541

25382542
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
503503
}
504504
if let hir::Node::Expr(parent_expr) = parent
505505
&& let hir::ExprKind::Call(call_expr, _) = parent_expr.kind
506-
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IntoIterIntoIter, _)) =
507-
call_expr.kind
506+
&& let hir::ExprKind::Path(qpath) = call_expr.kind
507+
&& tcx.qpath_is_lang_item(qpath, LangItem::IntoIterIntoIter)
508508
{
509509
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
510510
} else if let UseSpans::FnSelfUse { kind: CallKind::Normal { .. }, .. } = move_spans
@@ -2312,6 +2312,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23122312
let typeck_results = tcx.typeck(self.mir_def_id());
23132313

23142314
struct ExprFinder<'hir> {
2315+
tcx: TyCtxt<'hir>,
23152316
issue_span: Span,
23162317
expr_span: Span,
23172318
body_expr: Option<&'hir hir::Expr<'hir>>,
@@ -2336,9 +2337,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23362337
// };
23372338
// corresponding to the desugaring of a for loop `for <pat> in <head> { <body> }`.
23382339
if let hir::ExprKind::Call(path, [arg]) = ex.kind
2339-
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IntoIterIntoIter, _)) =
2340-
path.kind
2340+
&& let hir::ExprKind::Path(qpath) = path.kind
2341+
&& self.tcx.qpath_is_lang_item(qpath, LangItem::IntoIterIntoIter)
23412342
&& arg.span.contains(self.issue_span)
2343+
&& ex.span.desugaring_kind() == Some(DesugaringKind::ForLoop)
23422344
{
23432345
// Find `IntoIterator::into_iter(<head>)`
23442346
self.head = Some(arg);
@@ -2355,10 +2357,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23552357
..
23562358
}) = stmt.kind
23572359
&& let hir::ExprKind::Call(path, _args) = call.kind
2358-
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IteratorNext, _)) =
2359-
path.kind
2360-
&& let hir::PatKind::Struct(path, [field, ..], _) = bind.pat.kind
2361-
&& let hir::QPath::LangItem(LangItem::OptionSome, pat_span) = path
2360+
&& let hir::ExprKind::Path(qpath) = path.kind
2361+
&& self.tcx.qpath_is_lang_item(qpath, LangItem::IteratorNext)
2362+
&& let hir::PatKind::Struct(qpath, [field, ..], _) = bind.pat.kind
2363+
&& self.tcx.qpath_is_lang_item(qpath, LangItem::OptionSome)
23622364
&& call.span.contains(self.issue_span)
23632365
{
23642366
// Find `<pat>` and the span for the whole `for` loop.
@@ -2370,7 +2372,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23702372
self.loop_bind = Some(ident);
23712373
}
23722374
self.head_span = Some(*head_span);
2373-
self.pat_span = Some(pat_span);
2375+
self.pat_span = Some(bind.pat.span);
23742376
self.loop_span = Some(stmt.span);
23752377
}
23762378

@@ -2385,6 +2387,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23852387
}
23862388
}
23872389
let mut finder = ExprFinder {
2390+
tcx,
23882391
expr_span: span,
23892392
issue_span,
23902393
loop_bind: None,

0 commit comments

Comments
 (0)