Skip to content

Commit ead5e12

Browse files
committed
Remove QPath::LangItem
1 parent a96e21b commit ead5e12

File tree

35 files changed

+19
-144
lines changed

35 files changed

+19
-144
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21712171
lang_item: hir::LangItem,
21722172
fields: &'hir [hir::Expr<'hir>],
21732173
) -> hir::Expr<'hir> {
2174-
let path = self.arena.alloc(self.lang_item_qpath(span, lang_item));
2174+
let path = self.arena.alloc(self.make_lang_item_qpath(lang_item, span, None));
21752175
self.expr_enum_variant(span, path, fields)
21762176
}
21772177

@@ -2203,43 +2203,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
22032203
self.arena.alloc(self.expr_call_lang_item_fn_mut(span, lang_item, args))
22042204
}
22052205

2206-
// TEMPORARY - will be replaced with expr_call_lang_item_fn_mut
2207-
pub(super) fn expr_call_lang_item_qpath_fn_mut(
2206+
pub(super) fn expr_lang_item_path(
22082207
&mut self,
22092208
span: Span,
22102209
lang_item: hir::LangItem,
2211-
args: &'hir [hir::Expr<'hir>],
22122210
) -> hir::Expr<'hir> {
2213-
let path = self.arena.alloc(self.expr_lang_item_qpath(span, lang_item));
2214-
self.expr_call_mut(span, path, args)
2215-
}
2216-
2217-
// TEMPORARY - will be replaced with expr_call_lang_item_fn
2218-
pub(super) fn expr_call_lang_item_qpath_fn(
2219-
&mut self,
2220-
span: Span,
2221-
lang_item: hir::LangItem,
2222-
args: &'hir [hir::Expr<'hir>],
2223-
) -> &'hir hir::Expr<'hir> {
2224-
self.arena.alloc(self.expr_call_lang_item_qpath_fn_mut(span, lang_item, args))
2225-
}
2226-
2227-
fn expr_lang_item_path(&mut self, span: Span, lang_item: hir::LangItem) -> hir::Expr<'hir> {
22282211
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
22292212
self.expr(span, hir::ExprKind::Path(qpath))
22302213
}
22312214

2232-
// TEMPORARY - will be replaced with expr_lang_item_path
2233-
fn expr_lang_item_qpath(&mut self, span: Span, lang_item: hir::LangItem) -> hir::Expr<'hir> {
2234-
let qpath = self.lang_item_qpath(span, lang_item);
2235-
self.expr(span, hir::ExprKind::Path(qpath))
2236-
}
2237-
2238-
// TEMPORARY - will be replaced with expr_lang_item_path
2239-
fn lang_item_qpath(&mut self, span: Span, lang_item: hir::LangItem) -> hir::QPath<'hir> {
2240-
hir::QPath::LangItem(lang_item, self.lower_span(span))
2241-
}
2242-
22432215
/// `<LangItem>::name`
22442216
pub(super) fn expr_lang_item_type_relative(
22452217
&mut self,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,8 +2535,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25352535
lang_item: hir::LangItem,
25362536
fields: &'hir [hir::PatField<'hir>],
25372537
) -> &'hir hir::Pat<'hir> {
2538-
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
2539-
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))
25402540
}
25412541

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

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 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

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use smallvec::SmallVec;
3131
use thin_vec::ThinVec;
3232
use tracing::debug;
3333

34-
use crate::LangItem;
3534
use crate::attrs::AttributeKind;
3635
use crate::def::{CtorKind, DefKind, MacroKinds, PerNS, Res};
3736
use crate::def_id::{DefId, LocalDefIdMap};
@@ -2420,9 +2419,6 @@ impl Expr<'_> {
24202419
allow_projections_from(base) || base.is_place_expr(allow_projections_from)
24212420
}
24222421

2423-
// Lang item paths cannot currently be local variables or statics.
2424-
ExprKind::Path(QPath::LangItem(..)) => false,
2425-
24262422
// Suppress errors for bad expressions.
24272423
ExprKind::Err(_guar)
24282424
| ExprKind::Let(&LetExpr { recovered: ast::Recovered::Yes(_guar), .. }) => true,
@@ -2592,10 +2588,6 @@ impl Expr<'_> {
25922588
pub fn equivalent_for_indexing(&self, other: &Expr<'_>) -> bool {
25932589
match (self.kind, other.kind) {
25942590
(ExprKind::Lit(lit1), ExprKind::Lit(lit2)) => lit1.node == lit2.node,
2595-
(
2596-
ExprKind::Path(QPath::LangItem(item1, _)),
2597-
ExprKind::Path(QPath::LangItem(item2, _)),
2598-
) => item1 == item2,
25992591
(
26002592
ExprKind::Path(QPath::Resolved(None, path1)),
26012593
ExprKind::Path(QPath::Resolved(None, path2)),
@@ -2850,9 +2842,6 @@ pub enum QPath<'hir> {
28502842
/// `<Vec>::new`, and `T::X::Y::method` into `<<<T>::X>::Y>::method`,
28512843
/// the `X` and `Y` nodes each being a `TyKind::Path(QPath::TypeRelative(..))`.
28522844
TypeRelative(&'hir Ty<'hir>, &'hir PathSegment<'hir>),
2853-
2854-
/// Reference to a `#[lang = "foo"]` item.
2855-
LangItem(LangItem, Span),
28562845
}
28572846

28582847
impl<'hir> QPath<'hir> {
@@ -2861,7 +2850,6 @@ impl<'hir> QPath<'hir> {
28612850
match *self {
28622851
QPath::Resolved(_, path) => path.span,
28632852
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
2864-
QPath::LangItem(_, span) => span,
28652853
}
28662854
}
28672855

@@ -2871,7 +2859,6 @@ impl<'hir> QPath<'hir> {
28712859
match *self {
28722860
QPath::Resolved(_, path) => path.span,
28732861
QPath::TypeRelative(qself, _) => qself.span,
2874-
QPath::LangItem(_, span) => span,
28752862
}
28762863
}
28772864
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,6 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(
14161416
try_visit!(visitor.visit_ty_unambig(qself));
14171417
visitor.visit_path_segment(segment)
14181418
}
1419-
QPath::LangItem(..) => V::Result::output(),
14201419
}
14211420
}
14221421

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,13 +2240,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22402240
)
22412241
.unwrap_or_else(|guar| Const::new_error(tcx, guar))
22422242
}
2243-
hir::ConstArgKind::Path(qpath @ hir::QPath::LangItem(..)) => {
2244-
ty::Const::new_error_with_message(
2245-
tcx,
2246-
qpath.span(),
2247-
format!("Const::lower_const_arg: invalid qpath {qpath:?}"),
2248-
)
2249-
}
22502243
hir::ConstArgKind::Anon(anon) => self.lower_anon_const(anon),
22512244
hir::ConstArgKind::Infer(span, ()) => self.ct_infer(None, span),
22522245
}
@@ -2561,17 +2554,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25612554
.map(|(ty, _, _)| ty)
25622555
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
25632556
}
2564-
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => {
2565-
let def_id = tcx.require_lang_item(lang_item, span);
2566-
let (args, _) = self.lower_generic_args_of_path(
2567-
span,
2568-
def_id,
2569-
&[],
2570-
&hir::PathSegment::invalid(),
2571-
None,
2572-
);
2573-
tcx.at(span).type_of(def_id).instantiate(tcx, args)
2574-
}
25752557
hir::TyKind::Array(ty, length) => {
25762558
let length = self.lower_const_arg(length, FeedConstTy::No);
25772559
Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,6 @@ impl<'a> State<'a> {
17741774
self.print_ident(item_segment.ident);
17751775
self.print_generic_args(item_segment.args(), colons_before_params)
17761776
}
1777-
hir::QPath::LangItem(lang_item, span) => {
1778-
self.word("#[lang = \"");
1779-
self.print_ident(Ident::new(lang_item.name(), span));
1780-
self.word("\"]");
1781-
}
17821777
}
17831778
}
17841779

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
545545
ExprKind::AddrOf(kind, mutbl, oprnd) => {
546546
self.check_expr_addr_of(kind, mutbl, oprnd, expected, expr)
547547
}
548-
ExprKind::Path(QPath::LangItem(..)) => unreachable!(),
549548
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, None),
550549
ExprKind::InlineAsm(asm) => {
551550
// We defer some asm checks as we may not have resolved the input and output types yet (they may still be infer vars).

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,6 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
671671
path.segments.last().expect("paths should have a segment")
672672
}
673673
hir::QPath::TypeRelative(_, segment) => segment,
674-
hir::QPath::LangItem(..) => {
675-
return hir::intravisit::walk_qpath(self, qpath, id);
676-
}
677674
};
678675
// Alternatively, try to turbofish `::<_, (), _>`.
679676
if let Some(def_id) = self.fcx.typeck_results.borrow().qpath_res(qpath, id).opt_def_id()

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
721721
let ty = self.lowerer().lower_ty(qself);
722722
(LoweredTy::from_raw(self, span, ty), qself, segment)
723723
}
724-
QPath::LangItem(..) => {
725-
bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`")
726-
}
727724
};
728725

729726
self.register_wf_obligation(

0 commit comments

Comments
 (0)