This commit is contained in:
Aleksey Kladov 2020-07-31 20:23:52 +02:00
parent 81359af733
commit af53d5f4b0
8 changed files with 12 additions and 15 deletions

View File

@ -81,7 +81,7 @@ impl<'a> SubstituteTypeParams<'a> {
// FIXME: It would probably be nicer if we could get this via HIR (i.e. get the
// trait ref, and then go from the types in the substs back to the syntax).
fn get_syntactic_substs(impl_def: ast::Impl) -> Option<Vec<ast::Type>> {
let target_trait = impl_def.target_trait()?;
let target_trait = impl_def.trait_()?;
let path_type = match target_trait {
ast::Type::PathType(path) => path,
_ => return None,

View File

@ -111,11 +111,8 @@ pub(crate) fn resolve_target_trait(
sema: &Semantics<RootDatabase>,
impl_def: &ast::Impl,
) -> Option<hir::Trait> {
let ast_path = impl_def
.target_trait()
.map(|it| it.syntax().clone())
.and_then(ast::PathType::cast)?
.path()?;
let ast_path =
impl_def.trait_().map(|it| it.syntax().clone()).and_then(ast::PathType::cast)?.path()?;
match sema.resolve_path(&ast_path) {
Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def),

View File

@ -448,8 +448,8 @@ impl Ctx {
fn lower_impl(&mut self, impl_def: &ast::Impl) -> Option<FileItemTreeId<Impl>> {
let generic_params =
self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
let target_trait = impl_def.target_trait().map(|tr| self.lower_type_ref(&tr));
let target_type = self.lower_type_ref(&impl_def.target_type()?);
let target_trait = impl_def.trait_().map(|tr| self.lower_type_ref(&tr));
let target_type = self.lower_type_ref(&impl_def.self_ty()?);
let is_negative = impl_def.excl_token().is_some();
// We cannot use `assoc_items()` here as that does not include macro calls.

View File

@ -253,7 +253,7 @@ impl ToNav for hir::ImplDef {
let focus_range = if derive_attr.is_some() {
None
} else {
src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range)
src.value.self_ty().map(|ty| original_range(db, src.with_value(ty.syntax())).range)
};
NavigationTarget::from_syntax(

View File

@ -130,8 +130,8 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
ast::Const(it) => decl_with_type_ref(&it, it.ty()),
ast::Static(it) => decl_with_type_ref(&it, it.ty()),
ast::Impl(it) => {
let target_type = it.target_type()?;
let target_trait = it.target_trait();
let target_type = it.self_ty()?;
let target_trait = it.trait_();
let label = match target_trait {
None => format!("impl {}", target_type.syntax().text()),
Some(t) => {

View File

@ -194,7 +194,7 @@ fn text_edit_from_self_param(
new_name: &str,
) -> Option<TextEdit> {
fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
if let Some(ast::Type::PathType(p)) = impl_def.target_type() {
if let Some(ast::Type::PathType(p)) = impl_def.self_ty() {
return Some(p.path()?.segment()?.name_ref()?.text().to_string());
}
None

View File

@ -136,14 +136,14 @@ impl ast::UseTreeList {
}
impl ast::Impl {
pub fn target_type(&self) -> Option<ast::Type> {
pub fn self_ty(&self) -> Option<ast::Type> {
match self.target() {
(Some(t), None) | (_, Some(t)) => Some(t),
_ => None,
}
}
pub fn target_trait(&self) -> Option<ast::Type> {
pub fn trait_(&self) -> Option<ast::Type> {
match self.target() {
(Some(t), Some(_)) => Some(t),
_ => None,

View File

@ -208,7 +208,7 @@ fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) {
Some(it) => it,
None => return,
};
if impl_def.target_trait().is_some() {
if impl_def.trait_().is_some() {
errors.push(SyntaxError::new("Unnecessary visibility qualifier", vis.syntax.text_range()));
}
}