Highlight unsafe trait refs as unsafe only in impl blocks and definitions

This commit is contained in:
Lukas Wirth 2021-06-15 21:44:07 +02:00
parent 7f482afada
commit 29054e02fb
13 changed files with 60 additions and 19 deletions

View file

@ -325,6 +325,15 @@ impl ast::Impl {
let second = types.next();
(first, second)
}
pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option<ast::Impl> {
let this = name_ref.syntax().ancestors().find_map(ast::Impl::cast)?;
if this.trait_()?.syntax().text_range().start() == name_ref.syntax().text_range().start() {
Some(this)
} else {
None
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]