From 29054e02fbc7a858d9d4a6efd61583ac45b3213b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 15 Jun 2021 21:44:07 +0200 Subject: Highlight unsafe trait refs as unsafe only in impl blocks and definitions --- crates/syntax/src/ast/node_ext.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/syntax') diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 3d27d2c1a..2bd9ad867 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -325,6 +325,15 @@ impl ast::Impl { let second = types.next(); (first, second) } + + pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option { + 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)] -- cgit v1.2.3