Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6acc107

Browse files
committed
Prevent a panic on generated labels
1 parent 6e6942b commit 6acc107

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

rust/extractor/src/translate.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ra_ap_hir::{Crate, Module, ModuleDef};
99
use ra_ap_hir_def::body::{Body, BodySourceMap};
1010
use ra_ap_hir_def::hir::{CaptureBy, ExprId, LabelId, MatchArm, PatId, Statement};
1111
use ra_ap_ide_db::line_index::LineIndex;
12-
use ra_ap_ide_db::{LineIndexDatabase, RootDatabase};
12+
use ra_ap_ide_db::{label, LineIndexDatabase, RootDatabase};
1313
use ra_ap_syntax::ast::RangeOp;
1414
use ra_ap_syntax::{AstNode, Edition};
1515
use ra_ap_vfs::{FileId, Vfs};
@@ -137,8 +137,9 @@ impl CrateTranslator<'_> {
137137
label_id: ra_ap_hir_def::hir::LabelId,
138138
source_map: &BodySourceMap,
139139
) -> Option<trap::Label> {
140-
let source = source_map.label_syntax(label_id);
141-
self.emit_location_ast_ptr(source)
140+
// 'catch' a panic if the source map is incomplete
141+
let source = std::panic::catch_unwind(|| source_map.label_syntax(label_id)).ok();
142+
source.and_then(|source| self.emit_location_ast_ptr(source))
142143
}
143144
fn emit_location<T: HasSource>(&mut self, entity: T) -> Option<trap::Label>
144145
where

0 commit comments

Comments
 (0)