mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Fix a bug when synthetic AST node were searched in the AST ID map and caused panics
This commit is contained in:
parent
9224ec4497
commit
b66bc91b4b
3 changed files with 80 additions and 4 deletions
|
@ -34,7 +34,7 @@ use intern::Symbol;
|
|||
use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use span::{EditionedFileId, FileId, HirFileIdRepr, SyntaxContextId};
|
||||
use span::{AstIdMap, EditionedFileId, FileId, HirFileIdRepr, SyntaxContextId};
|
||||
use stdx::TupleExt;
|
||||
use syntax::{
|
||||
algo::skip_trivia_token,
|
||||
|
@ -42,6 +42,7 @@ use syntax::{
|
|||
AstNode, AstToken, Direction, SyntaxKind, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange,
|
||||
TextSize,
|
||||
};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
|
@ -1973,10 +1974,16 @@ impl SemanticsScope<'_> {
|
|||
/// Resolve a path as-if it was written at the given scope. This is
|
||||
/// necessary a heuristic, as it doesn't take hygiene into account.
|
||||
pub fn speculative_resolve(&self, ast_path: &ast::Path) -> Option<PathResolution> {
|
||||
let root = ast_path.syntax().ancestors().last().unwrap();
|
||||
let ast_id_map = Arc::new(AstIdMap::from_source(&root));
|
||||
let (mut types_map, mut types_source_map) =
|
||||
(TypesMap::default(), TypesSourceMap::default());
|
||||
let mut ctx =
|
||||
LowerCtx::new(self.db.upcast(), self.file_id, &mut types_map, &mut types_source_map);
|
||||
let mut ctx = LowerCtx::for_synthetic_ast(
|
||||
self.db.upcast(),
|
||||
ast_id_map,
|
||||
&mut types_map,
|
||||
&mut types_source_map,
|
||||
);
|
||||
let path = Path::from_src(&mut ctx, ast_path.clone())?;
|
||||
resolve_hir_path(
|
||||
self.db,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue