mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Remove deprecated Path::from_ast
Long term, we probably should make hir::Path private to hir.
This commit is contained in:
parent
f0ad68b962
commit
2052d33b9b
2 changed files with 13 additions and 25 deletions
|
@ -7,6 +7,17 @@ use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
|
||||||
|
SyntaxRewriter::from_fn(|element| match element {
|
||||||
|
syntax::SyntaxElement::Node(n) => {
|
||||||
|
let replacement = transformer.get_substitution(&n)?;
|
||||||
|
Some(replacement.into())
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.rewrite_ast(&node)
|
||||||
|
}
|
||||||
|
|
||||||
pub trait AstTransform<'a> {
|
pub trait AstTransform<'a> {
|
||||||
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode>;
|
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode>;
|
||||||
|
|
||||||
|
@ -107,10 +118,7 @@ impl<'a> SubstituteTypeParams<'a> {
|
||||||
ast::Type::PathType(path_type) => path_type.path()?,
|
ast::Type::PathType(path_type) => path_type.path()?,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
// FIXME: use `hir::Path::from_src` instead.
|
let resolution = self.source_scope.speculative_resolve(&path)?;
|
||||||
#[allow(deprecated)]
|
|
||||||
let path = hir::Path::from_ast(path)?;
|
|
||||||
let resolution = self.source_scope.resolve_hir_path(&path)?;
|
|
||||||
match resolution {
|
match resolution {
|
||||||
hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
|
hir::PathResolution::TypeParam(tp) => Some(self.substs.get(&tp)?.syntax().clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -146,10 +154,7 @@ impl<'a> QualifyPaths<'a> {
|
||||||
// don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
|
// don't try to qualify `Fn(Foo) -> Bar` paths, they are in prelude anyway
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// FIXME: use `hir::Path::from_src` instead.
|
let resolution = self.source_scope.speculative_resolve(&p)?;
|
||||||
#[allow(deprecated)]
|
|
||||||
let hir_path = hir::Path::from_ast(p.clone());
|
|
||||||
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
|
|
||||||
match resolution {
|
match resolution {
|
||||||
PathResolution::Def(def) => {
|
PathResolution::Def(def) => {
|
||||||
let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
|
let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?;
|
||||||
|
@ -175,17 +180,6 @@ impl<'a> QualifyPaths<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
|
|
||||||
SyntaxRewriter::from_fn(|element| match element {
|
|
||||||
syntax::SyntaxElement::Node(n) => {
|
|
||||||
let replacement = transformer.get_substitution(&n)?;
|
|
||||||
Some(replacement.into())
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.rewrite_ast(&node)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
|
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
|
||||||
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
|
||||||
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
|
||||||
|
|
|
@ -153,12 +153,6 @@ pub enum GenericArg {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
/// Converts an `ast::Path` to `Path`. Works with use trees.
|
|
||||||
#[deprecated = "Doesn't handle hygiene, don't add new calls, remove old ones"]
|
|
||||||
pub fn from_ast(path: ast::Path) -> Option<Path> {
|
|
||||||
lower::lower_path(path, &Hygiene::new_unhygienic())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts an `ast::Path` to `Path`. Works with use trees.
|
/// Converts an `ast::Path` to `Path`. Works with use trees.
|
||||||
/// It correctly handles `$crate` based path from macro call.
|
/// It correctly handles `$crate` based path from macro call.
|
||||||
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<Path> {
|
pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option<Path> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue