Skip to content

Commit 7355816

Browse files
committed
Auto merge of #73046 - marmeladema:save-analysis-fix-path, r=Xanewok
save_analysis: fix some ICEs Fixes #73020 Fixes #73022 Fixes #73041
2 parents 6aa1d93 + a7c18e0 commit 7355816

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

src/librustc_save_analysis/dump_visitor.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
210210
// As write_sub_paths, but does not process the last ident in the path (assuming it
211211
// will be processed elsewhere). See note on write_sub_paths about global.
212212
fn write_sub_paths_truncated(&mut self, path: &'tcx hir::Path<'tcx>) {
213-
for seg in &path.segments[..path.segments.len() - 1] {
214-
if let Some(data) = self.save_ctxt.get_path_segment_data(seg) {
215-
self.dumper.dump_ref(data);
213+
if let [segments @ .., _] = path.segments {
214+
for seg in segments {
215+
if let Some(data) = self.save_ctxt.get_path_segment_data(seg) {
216+
self.dumper.dump_ref(data);
217+
}
216218
}
217219
}
218220
}

src/librustc_save_analysis/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,14 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
534534
}
535535
}
536536
}
537-
hir::ExprKind::Struct(hir::QPath::Resolved(_, path), ..) => {
537+
hir::ExprKind::Struct(qpath, ..) => {
538+
let segment = match qpath {
539+
hir::QPath::Resolved(_, path) => path.segments.last().unwrap(),
540+
hir::QPath::TypeRelative(_, segment) => segment,
541+
};
538542
match self.tables.expr_ty_adjusted(&hir_node).kind {
539543
ty::Adt(def, _) if !def.is_enum() => {
540-
let sub_span = path.segments.last().unwrap().ident.span;
544+
let sub_span = segment.ident.span;
541545
filter!(self.span_utils, sub_span);
542546
let span = self.span_from_span(sub_span);
543547
Some(Data::RefData(Ref {
@@ -580,7 +584,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
580584
}
581585
_ => {
582586
// FIXME
583-
bug!();
587+
bug!("invalid expression: {:?}", expr);
584588
}
585589
}
586590
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags: -Zsave-analysis
2+
use {self}; //~ ERROR E0431
3+
4+
fn main () {
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0431]: `self` import can only appear in an import list with a non-empty prefix
2+
--> $DIR/issue-73020.rs:2:6
3+
|
4+
LL | use {self};
5+
| ^^^^ can only appear in an import list with a non-empty prefix
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0431`.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// build-pass
2+
// compile-flags: -Zsave-analysis
3+
enum Enum2 {
4+
Variant8 { _field: bool },
5+
}
6+
7+
impl Enum2 {
8+
fn new_variant8() -> Enum2 {
9+
Self::Variant8 { _field: true }
10+
}
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)