diff options
| author | marmeladema <xademax@gmail.com> | 2020-06-06 00:54:28 +0100 |
|---|---|---|
| committer | marmeladema <xademax@gmail.com> | 2020-06-06 23:40:24 +0100 |
| commit | a7c18e021facddcc1e6e747f2b2a625147277cd4 (patch) | |
| tree | d41ffcbf353d7f593d1d3da0388db28f3c88ae88 | |
| parent | 84e4777ae203c0ce93faad89abf4ab1f0b006af2 (diff) | |
| download | rust-a7c18e021facddcc1e6e747f2b2a625147277cd4.tar.gz rust-a7c18e021facddcc1e6e747f2b2a625147277cd4.zip | |
save_analysis: fix panic in `write_sub_paths_truncated`
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/save-analysis/issue-73020.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/save-analysis/issue-73020.stderr | 9 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index a5e61ab9ab0..489d38b00df 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -210,9 +210,11 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> { // As write_sub_paths, but does not process the last ident in the path (assuming it // will be processed elsewhere). See note on write_sub_paths about global. fn write_sub_paths_truncated(&mut self, path: &'tcx hir::Path<'tcx>) { - for seg in &path.segments[..path.segments.len() - 1] { - if let Some(data) = self.save_ctxt.get_path_segment_data(seg) { - self.dumper.dump_ref(data); + if let [segments @ .., _] = path.segments { + for seg in segments { + if let Some(data) = self.save_ctxt.get_path_segment_data(seg) { + self.dumper.dump_ref(data); + } } } } diff --git a/src/test/ui/save-analysis/issue-73020.rs b/src/test/ui/save-analysis/issue-73020.rs new file mode 100644 index 00000000000..87ce0933681 --- /dev/null +++ b/src/test/ui/save-analysis/issue-73020.rs @@ -0,0 +1,5 @@ +// compile-flags: -Zsave-analysis +use {self}; //~ ERROR E0431 + +fn main () { +} diff --git a/src/test/ui/save-analysis/issue-73020.stderr b/src/test/ui/save-analysis/issue-73020.stderr new file mode 100644 index 00000000000..5bb3aae9997 --- /dev/null +++ b/src/test/ui/save-analysis/issue-73020.stderr @@ -0,0 +1,9 @@ +error[E0431]: `self` import can only appear in an import list with a non-empty prefix + --> $DIR/issue-73020.rs:2:6 + | +LL | use {self}; + | ^^^^ can only appear in an import list with a non-empty prefix + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0431`. |
