Skip to content

Commit 1e2f350

Browse files
committed
save_analysis: support QPath::LangItem
This commit implements support for `QPath::LangItem` and `GenericBound::LangItemTrait` in save analysis. Signed-off-by: David Wood <[email protected]>
1 parent 762137e commit 1e2f350

File tree

3 files changed

+32
-44
lines changed

3 files changed

+32
-44
lines changed

src/librustc_save_analysis/dump_visitor.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,18 @@ impl<'tcx> DumpVisitor<'tcx> {
702702

703703
// super-traits
704704
for super_bound in trait_refs.iter() {
705-
let trait_ref = match *super_bound {
706-
hir::GenericBound::Trait(ref trait_ref, _) => trait_ref,
705+
let (def_id, sub_span) = match *super_bound {
706+
hir::GenericBound::Trait(ref trait_ref, _) => (
707+
self.lookup_def_id(trait_ref.trait_ref.hir_ref_id),
708+
trait_ref.trait_ref.path.segments.last().unwrap().ident.span,
709+
),
710+
hir::GenericBound::LangItemTrait(lang_item, span, _, _) => {
711+
(Some(self.tcx.require_lang_item(lang_item, Some(span))), span)
712+
}
707713
hir::GenericBound::Outlives(..) => continue,
708-
hir::GenericBound::LangItemTrait(..) => unimplemented!(),
709714
};
710715

711-
let trait_ref = &trait_ref.trait_ref;
712-
if let Some(id) = self.lookup_def_id(trait_ref.hir_ref_id) {
713-
let sub_span = trait_ref.path.segments.last().unwrap().ident.span;
716+
if let Some(id) = def_id {
714717
if !self.span.filter_generated(sub_span) {
715718
let span = self.span_from_span(sub_span);
716719
self.dumper.dump_ref(Ref {
@@ -763,12 +766,7 @@ impl<'tcx> DumpVisitor<'tcx> {
763766
}
764767

765768
fn process_path(&mut self, id: hir::HirId, path: &hir::QPath<'tcx>) {
766-
let span = match path {
767-
hir::QPath::Resolved(_, path) => path.span,
768-
hir::QPath::TypeRelative(_, segment) => segment.ident.span,
769-
hir::QPath::LangItem(..) => unimplemented!(),
770-
};
771-
if self.span.filter_generated(span) {
769+
if self.span.filter_generated(path.span()) {
772770
return;
773771
}
774772
self.dump_path_ref(id, path);
@@ -785,7 +783,7 @@ impl<'tcx> DumpVisitor<'tcx> {
785783
self.visit_ty(ty);
786784
std::slice::from_ref(*segment)
787785
}
788-
hir::QPath::LangItem(..) => unimplemented!(),
786+
hir::QPath::LangItem(..) => return,
789787
};
790788
for seg in segments {
791789
if let Some(ref generic_args) = seg.args {
@@ -1358,11 +1356,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
13581356
}
13591357

13601358
if let Some(id) = self.lookup_def_id(t.hir_id) {
1361-
let sub_span = match path {
1362-
hir::QPath::Resolved(_, path) => path.segments.last().unwrap().ident.span,
1363-
hir::QPath::TypeRelative(_, segment) => segment.ident.span,
1364-
hir::QPath::LangItem(..) => unimplemented!(),
1365-
};
1359+
let sub_span = path.last_segment_span();
13661360
let span = self.span_from_span(sub_span);
13671361
self.dumper.dump_ref(Ref {
13681362
kind: RefKind::Type,

src/librustc_save_analysis/lib.rs

+17-25
Original file line numberDiff line numberDiff line change
@@ -551,29 +551,22 @@ impl<'tcx> SaveContext<'tcx> {
551551
}
552552
}
553553
}
554-
hir::ExprKind::Struct(qpath, ..) => {
555-
let segment = match qpath {
556-
hir::QPath::Resolved(_, path) => path.segments.last().unwrap(),
557-
hir::QPath::TypeRelative(_, segment) => segment,
558-
hir::QPath::LangItem(..) => unimplemented!(),
559-
};
560-
match ty.kind {
561-
ty::Adt(def, _) => {
562-
let sub_span = segment.ident.span;
563-
filter!(self.span_utils, sub_span);
564-
let span = self.span_from_span(sub_span);
565-
Some(Data::RefData(Ref {
566-
kind: RefKind::Type,
567-
span,
568-
ref_id: id_from_def_id(def.did),
569-
}))
570-
}
571-
_ => {
572-
debug!("expected adt, found {:?}", ty);
573-
None
574-
}
554+
hir::ExprKind::Struct(qpath, ..) => match ty.kind {
555+
ty::Adt(def, _) => {
556+
let sub_span = qpath.last_segment_span();
557+
filter!(self.span_utils, sub_span);
558+
let span = self.span_from_span(sub_span);
559+
Some(Data::RefData(Ref {
560+
kind: RefKind::Type,
561+
span,
562+
ref_id: id_from_def_id(def.did),
563+
}))
575564
}
576-
}
565+
_ => {
566+
debug!("expected adt, found {:?}", ty);
567+
None
568+
}
569+
},
577570
hir::ExprKind::MethodCall(ref seg, ..) => {
578571
let method_id = match self.typeck_results().type_dependent_def_id(expr.hir_id) {
579572
Some(id) => id,
@@ -637,10 +630,9 @@ impl<'tcx> SaveContext<'tcx> {
637630
})
638631
| Node::Ty(&hir::Ty { kind: hir::TyKind::Path(ref qpath), .. }) => match qpath {
639632
hir::QPath::Resolved(_, path) => path.res,
640-
hir::QPath::TypeRelative(..) => self
633+
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
641634
.maybe_typeck_results
642635
.map_or(Res::Err, |typeck_results| typeck_results.qpath_res(qpath, hir_id)),
643-
hir::QPath::LangItem(..) => unimplemented!(),
644636
},
645637

646638
Node::Binding(&hir::Pat {
@@ -655,7 +647,7 @@ impl<'tcx> SaveContext<'tcx> {
655647
let segment = match path {
656648
hir::QPath::Resolved(_, path) => path.segments.last(),
657649
hir::QPath::TypeRelative(_, segment) => Some(*segment),
658-
hir::QPath::LangItem(..) => unimplemented!(),
650+
hir::QPath::LangItem(..) => None,
659651
};
660652
segment.and_then(|seg| {
661653
self.get_path_segment_data(seg).or_else(|| self.get_path_segment_data_with_id(seg, id))

src/librustc_save_analysis/sig.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ impl<'hir> Sig for hir::Ty<'hir> {
286286
refs: vec![SigElement { id, start, end }],
287287
})
288288
}
289-
hir::TyKind::Path(hir::QPath::LangItem(..)) => unimplemented!(),
289+
hir::TyKind::Path(hir::QPath::LangItem(lang_item, _)) => {
290+
Ok(text_sig(format!("#[lang = \"{}\"]", lang_item.name())))
291+
}
290292
hir::TyKind::TraitObject(bounds, ..) => {
291293
// FIXME recurse into bounds
292294
let bounds: Vec<hir::GenericBound<'_>> = bounds

0 commit comments

Comments
 (0)