Skip to content

Commit 8fb68fc

Browse files
Rollup merge of #118199 - compiler-errors:qpath, r=lcnr
Remove `HirId` from `QPath::LangItem` Remove `HirId` from `QPath::LangItem`, since there was only *one* use-case (`ObligationCauseCode::AwaitableExpr`), which we can instead recover by walking the HIR tree.
2 parents 5d2b6b3 + 4e23448 commit 8fb68fc

File tree

16 files changed

+45
-75
lines changed

16 files changed

+45
-75
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+11-39
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
560560
expr: &'hir hir::Expr<'hir>,
561561
overall_span: Span,
562562
) -> &'hir hir::Expr<'hir> {
563-
let constructor = self.arena.alloc(self.expr_lang_item_path(method_span, lang_item, None));
563+
let constructor = self.arena.alloc(self.expr_lang_item_path(method_span, lang_item));
564564
self.expr_call(overall_span, constructor, std::slice::from_ref(expr))
565565
}
566566

@@ -614,7 +614,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
614614
// Resume argument type: `ResumeTy`
615615
let unstable_span =
616616
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
617-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span, None);
617+
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
618618
let input_ty = hir::Ty {
619619
hir_id: self.next_id(),
620620
kind: hir::TyKind::Path(resume_ty),
@@ -818,19 +818,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
818818
span,
819819
hir::LangItem::PinNewUnchecked,
820820
arena_vec![self; ref_mut_awaitee],
821-
Some(expr_hir_id),
822821
);
823822
let get_context = self.expr_call_lang_item_fn_mut(
824823
gen_future_span,
825824
hir::LangItem::GetContext,
826825
arena_vec![self; task_context],
827-
Some(expr_hir_id),
828826
);
829827
let call = self.expr_call_lang_item_fn(
830828
span,
831829
hir::LangItem::FuturePoll,
832830
arena_vec![self; new_unchecked, get_context],
833-
Some(expr_hir_id),
834831
);
835832
self.arena.alloc(self.expr_unsafe(call))
836833
};
@@ -843,12 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
843840
let (x_pat, x_pat_hid) = self.pat_ident(gen_future_span, x_ident);
844841
let x_expr = self.expr_ident(gen_future_span, x_ident, x_pat_hid);
845842
let ready_field = self.single_pat_field(gen_future_span, x_pat);
846-
let ready_pat = self.pat_lang_item_variant(
847-
span,
848-
hir::LangItem::PollReady,
849-
ready_field,
850-
Some(expr_hir_id),
851-
);
843+
let ready_pat = self.pat_lang_item_variant(span, hir::LangItem::PollReady, ready_field);
852844
let break_x = self.with_loop_scope(loop_node_id, move |this| {
853845
let expr_break =
854846
hir::ExprKind::Break(this.lower_loop_destination(None), Some(x_expr));
@@ -859,12 +851,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
859851

860852
// `::std::task::Poll::Pending => {}`
861853
let pending_arm = {
862-
let pending_pat = self.pat_lang_item_variant(
863-
span,
864-
hir::LangItem::PollPending,
865-
&[],
866-
Some(expr_hir_id),
867-
);
854+
let pending_pat = self.pat_lang_item_variant(span, hir::LangItem::PollPending, &[]);
868855
let empty_block = self.expr_block_empty(span);
869856
self.arm(pending_pat, empty_block)
870857
};
@@ -922,7 +909,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
922909
span,
923910
hir::LangItem::IntoFutureIntoFuture,
924911
arena_vec![self; expr],
925-
Some(expr_hir_id),
926912
);
927913

928914
// match <into_future_expr> {
@@ -1379,8 +1365,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13791365
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
13801366
let e1 = self.lower_expr_mut(e1);
13811367
let e2 = self.lower_expr_mut(e2);
1382-
let fn_path =
1383-
hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, self.lower_span(span), None);
1368+
let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, self.lower_span(span));
13841369
let fn_expr = self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path)));
13851370
hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2])
13861371
}
@@ -1421,7 +1406,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14211406
);
14221407

14231408
hir::ExprKind::Struct(
1424-
self.arena.alloc(hir::QPath::LangItem(lang_item, self.lower_span(span), None)),
1409+
self.arena.alloc(hir::QPath::LangItem(lang_item, self.lower_span(span))),
14251410
fields,
14261411
None,
14271412
)
@@ -1590,7 +1575,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
15901575
head_span,
15911576
hir::LangItem::IteratorNext,
15921577
arena_vec![self; ref_mut_iter],
1593-
None,
15941578
);
15951579
let arms = arena_vec![self; none_arm, some_arm];
15961580

@@ -1619,7 +1603,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
16191603
head_span,
16201604
hir::LangItem::IntoIterIntoIter,
16211605
arena_vec![self; head],
1622-
None,
16231606
)
16241607
};
16251608

@@ -1675,7 +1658,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
16751658
unstable_span,
16761659
hir::LangItem::TryTraitBranch,
16771660
arena_vec![self; sub_expr],
1678-
None,
16791661
)
16801662
};
16811663

@@ -1880,9 +1862,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
18801862
span: Span,
18811863
lang_item: hir::LangItem,
18821864
args: &'hir [hir::Expr<'hir>],
1883-
hir_id: Option<hir::HirId>,
18841865
) -> hir::Expr<'hir> {
1885-
let path = self.arena.alloc(self.expr_lang_item_path(span, lang_item, hir_id));
1866+
let path = self.arena.alloc(self.expr_lang_item_path(span, lang_item));
18861867
self.expr_call_mut(span, path, args)
18871868
}
18881869

@@ -1891,21 +1872,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
18911872
span: Span,
18921873
lang_item: hir::LangItem,
18931874
args: &'hir [hir::Expr<'hir>],
1894-
hir_id: Option<hir::HirId>,
18951875
) -> &'hir hir::Expr<'hir> {
1896-
self.arena.alloc(self.expr_call_lang_item_fn_mut(span, lang_item, args, hir_id))
1876+
self.arena.alloc(self.expr_call_lang_item_fn_mut(span, lang_item, args))
18971877
}
18981878

1899-
fn expr_lang_item_path(
1900-
&mut self,
1901-
span: Span,
1902-
lang_item: hir::LangItem,
1903-
hir_id: Option<hir::HirId>,
1904-
) -> hir::Expr<'hir> {
1905-
self.expr(
1906-
span,
1907-
hir::ExprKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span), hir_id)),
1908-
)
1879+
fn expr_lang_item_path(&mut self, span: Span, lang_item: hir::LangItem) -> hir::Expr<'hir> {
1880+
self.expr(span, hir::ExprKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))))
19091881
}
19101882

19111883
/// `<LangItem>::name`
@@ -1918,7 +1890,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19181890
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
19191891
self.arena.alloc(self.ty(
19201892
span,
1921-
hir::TyKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span), None)),
1893+
hir::TyKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))),
19221894
)),
19231895
self.arena.alloc(hir::PathSegment::new(
19241896
Ident::new(name, span),

compiler/rustc_ast_lowering/src/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2304,21 +2304,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23042304

23052305
fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
23062306
let field = self.single_pat_field(span, pat);
2307-
self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field, None)
2307+
self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
23082308
}
23092309

23102310
fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
23112311
let field = self.single_pat_field(span, pat);
2312-
self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field, None)
2312+
self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field)
23132313
}
23142314

23152315
fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
23162316
let field = self.single_pat_field(span, pat);
2317-
self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field, None)
2317+
self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field)
23182318
}
23192319

23202320
fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
2321-
self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[], None)
2321+
self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
23222322
}
23232323

23242324
fn single_pat_field(
@@ -2341,9 +2341,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23412341
span: Span,
23422342
lang_item: hir::LangItem,
23432343
fields: &'hir [hir::PatField<'hir>],
2344-
hir_id: Option<hir::HirId>,
23452344
) -> &'hir hir::Pat<'hir> {
2346-
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span), hir_id);
2345+
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
23472346
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
23482347
}
23492348

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
445445
&& let hir::ExprKind::Path(hir::QPath::LangItem(
446446
LangItem::IntoIterIntoIter,
447447
_,
448-
_,
449448
)) = call_expr.kind
450449
{
451450
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
@@ -1346,11 +1345,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13461345
// };
13471346
// corresponding to the desugaring of a for loop `for <pat> in <head> { <body> }`.
13481347
if let hir::ExprKind::Call(path, [arg]) = ex.kind
1349-
&& let hir::ExprKind::Path(hir::QPath::LangItem(
1350-
LangItem::IntoIterIntoIter,
1351-
_,
1352-
_,
1353-
)) = path.kind
1348+
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IntoIterIntoIter, _)) =
1349+
path.kind
13541350
&& arg.span.contains(self.issue_span)
13551351
{
13561352
// Find `IntoIterator::into_iter(<head>)`
@@ -1368,10 +1364,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13681364
..
13691365
}) = stmt.kind
13701366
&& let hir::ExprKind::Call(path, _args) = call.kind
1371-
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IteratorNext, _, _)) =
1367+
&& let hir::ExprKind::Path(hir::QPath::LangItem(LangItem::IteratorNext, _)) =
13721368
path.kind
13731369
&& let hir::PatKind::Struct(path, [field, ..], _) = bind.pat.kind
1374-
&& let hir::QPath::LangItem(LangItem::OptionSome, pat_span, _) = path
1370+
&& let hir::QPath::LangItem(LangItem::OptionSome, pat_span) = path
13751371
&& call.span.contains(self.issue_span)
13761372
{
13771373
// Find `<pat>` and the span for the whole `for` loop.

compiler/rustc_hir/src/hir.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,8 @@ pub enum QPath<'hir> {
20582058
/// the `X` and `Y` nodes each being a `TyKind::Path(QPath::TypeRelative(..))`.
20592059
TypeRelative(&'hir Ty<'hir>, &'hir PathSegment<'hir>),
20602060

2061-
/// Reference to a `#[lang = "foo"]` item. `HirId` of the inner expr.
2062-
LangItem(LangItem, Span, Option<HirId>),
2061+
/// Reference to a `#[lang = "foo"]` item.
2062+
LangItem(LangItem, Span),
20632063
}
20642064

20652065
impl<'hir> QPath<'hir> {
@@ -2068,7 +2068,7 @@ impl<'hir> QPath<'hir> {
20682068
match *self {
20692069
QPath::Resolved(_, path) => path.span,
20702070
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
2071-
QPath::LangItem(_, span, _) => span,
2071+
QPath::LangItem(_, span) => span,
20722072
}
20732073
}
20742074

@@ -2078,7 +2078,7 @@ impl<'hir> QPath<'hir> {
20782078
match *self {
20792079
QPath::Resolved(_, path) => path.span,
20802080
QPath::TypeRelative(qself, _) => qself.span,
2081-
QPath::LangItem(_, span, _) => span,
2081+
QPath::LangItem(_, span) => span,
20822082
}
20832083
}
20842084
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25462546
.map(|(ty, _, _)| ty)
25472547
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
25482548
}
2549-
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
2549+
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => {
25502550
let def_id = tcx.require_lang_item(lang_item, Some(span));
25512551
let (args, _) = self.create_args_for_ast_path(
25522552
span,

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ impl<'a> State<'a> {
16231623
self.print_ident(item_segment.ident);
16241624
self.print_generic_args(item_segment.args(), colons_before_params)
16251625
}
1626-
hir::QPath::LangItem(lang_item, span, _) => {
1626+
hir::QPath::LangItem(lang_item, span) => {
16271627
self.word("#[lang = \"");
16281628
self.print_ident(Ident::new(lang_item.name(), span));
16291629
self.word("\"]");

compiler/rustc_hir_typeck/src/expr.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
289289
ExprKind::AddrOf(kind, mutbl, oprnd) => {
290290
self.check_expr_addr_of(kind, mutbl, oprnd, expected, expr)
291291
}
292-
ExprKind::Path(QPath::LangItem(lang_item, _, hir_id)) => {
293-
self.check_lang_item_path(lang_item, expr, hir_id)
292+
ExprKind::Path(QPath::LangItem(lang_item, _)) => {
293+
self.check_lang_item_path(lang_item, expr)
294294
}
295295
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, &[]),
296296
ExprKind::InlineAsm(asm) => {
@@ -497,9 +497,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
497497
&self,
498498
lang_item: hir::LangItem,
499499
expr: &'tcx hir::Expr<'tcx>,
500-
hir_id: Option<hir::HirId>,
501500
) -> Ty<'tcx> {
502-
self.resolve_lang_item_path(lang_item, expr.span, expr.hir_id, hir_id).1
501+
self.resolve_lang_item_path(lang_item, expr.span, expr.hir_id).1
503502
}
504503

505504
pub(crate) fn check_expr_path(

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
753753
lang_item: hir::LangItem,
754754
span: Span,
755755
hir_id: hir::HirId,
756-
expr_hir_id: Option<hir::HirId>,
757756
) -> (Res, Ty<'tcx>) {
758757
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
759758
let def_kind = self.tcx.def_kind(def_id);
@@ -770,7 +769,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
770769

771770
let code = match lang_item {
772771
hir::LangItem::IntoFutureIntoFuture => {
773-
Some(ObligationCauseCode::AwaitableExpr(expr_hir_id))
772+
if let hir::Node::Expr(into_future_call) = self.tcx.hir().get_parent(hir_id)
773+
&& let hir::ExprKind::Call(_, [arg0]) = &into_future_call.kind
774+
{
775+
Some(ObligationCauseCode::AwaitableExpr(arg0.hir_id))
776+
} else {
777+
None
778+
}
774779
}
775780
hir::LangItem::IteratorNext | hir::LangItem::IntoIterIntoIter => {
776781
Some(ObligationCauseCode::ForLoopIterator)

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1842,8 +1842,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18421842

18431843
(result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)), ty)
18441844
}
1845-
QPath::LangItem(lang_item, span, id) => {
1846-
let (res, ty) = self.resolve_lang_item_path(lang_item, span, hir_id, id);
1845+
QPath::LangItem(lang_item, span) => {
1846+
let (res, ty) = self.resolve_lang_item_path(lang_item, span, hir_id);
18471847
(res, self.handle_raw_ty(path_span, ty))
18481848
}
18491849
}

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10871087

10881088
Box::new(segment.into_iter())
10891089
}
1090-
hir::QPath::LangItem(_, _, _) => Box::new(iter::empty()),
1090+
hir::QPath::LangItem(_, _) => Box::new(iter::empty()),
10911091
}
10921092
}
10931093
}

compiler/rustc_middle/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ pub enum ObligationCauseCode<'tcx> {
422422
/// If `X` is the concrete type of an opaque type `impl Y`, then `X` must implement `Y`
423423
OpaqueType,
424424

425-
AwaitableExpr(Option<hir::HirId>),
425+
AwaitableExpr(hir::HirId),
426426

427427
ForLoopIterator,
428428

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1634,8 +1634,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16341634

16351635
fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic) {
16361636
let hir = self.tcx.hir();
1637-
if let ObligationCauseCode::AwaitableExpr(Some(hir_id)) =
1638-
obligation.cause.code().peel_derives()
1637+
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives()
16391638
&& let hir::Node::Expr(expr) = hir.get(*hir_id)
16401639
{
16411640
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`

src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(super) fn check(
6161
// ? is a Call, makes sure not to rec *x?, but rather (*x)?
6262
ExprKind::Call(hir_callee, _) => matches!(
6363
hir_callee.kind,
64-
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
64+
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, ..))
6565
),
6666
ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true,
6767
ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar)

src/tools/clippy/clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn check_final_expr<'tcx>(
309309
let replacement = if let Some(inner_expr) = inner {
310310
// if desugar of `do yeet`, don't lint
311311
if let ExprKind::Call(path_expr, _) = inner_expr.kind
312-
&& let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, _, _)) = path_expr.kind
312+
&& let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, ..)) = path_expr.kind
313313
{
314314
return;
315315
}

src/tools/clippy/clippy_lints/src/unnecessary_map_on_constructor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMapOnConstructor {
5959
}
6060
},
6161
hir::QPath::TypeRelative(_, path) => path.ident.name,
62-
hir::QPath::LangItem(_, _, _) => return,
62+
hir::QPath::LangItem(..) => return,
6363
};
6464
match constructor_symbol {
6565
sym::Some | sym::Ok if path.ident.name == rustc_span::sym::map => (),

0 commit comments

Comments
 (0)