Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
  • Loading branch information
WaffleLapkin and Veykril committed Dec 21, 2022
1 parent 608dc49 commit 94d0772
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions crates/hir/src/semantics.rs
Expand Up @@ -485,8 +485,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
}

/// Returns `true` if the `node` is inside an `unsafe` context.
pub fn is_inside_unsafe(&self, node: &SyntaxNode) -> bool {
self.imp.is_inside_unsafe(node)
pub fn is_inside_unsafe(&self, expr: &ast::Expr) -> bool {
self.imp.is_inside_unsafe(expr)
}
}

Expand Down Expand Up @@ -1471,15 +1471,15 @@ impl<'db> SemanticsImpl<'db> {
.unwrap_or(false)
}

fn is_inside_unsafe(&self, node: &SyntaxNode) -> bool {
fn is_inside_unsafe(&self, expr: &ast::Expr) -> bool {
let item_or_variant = |ancestor: SyntaxNode| {
if ast::Item::can_cast(ancestor.kind()) {
ast::Item::cast(ancestor).map(Either::Left)
} else {
ast::Variant::cast(ancestor).map(Either::Right)
}
};
let Some(enclosing_item) = node.ancestors().find_map(item_or_variant) else { return false };
let Some(enclosing_item) = expr.syntax().ancestors().find_map(item_or_variant) else { return false };

let def = match &enclosing_item {
Either::Left(ast::Item::Fn(it)) => {
Expand All @@ -1495,17 +1495,17 @@ impl<'db> SemanticsImpl<'db> {
Either::Right(it) => self.to_def(it).map(<_>::into).map(DefWithBodyId::VariantId),
};
let Some(def) = def else { return false };
let enclosing_node = enclosing_item.as_ref().either(|i| i.syntax(), |v| v.syntax());

if ast::Fn::cast(enclosing_node.clone()).and_then(|f| f.unsafe_token()).is_some() {
if matches!(&enclosing_item, Either::Left(ast::Item::Fn(it)) if it.unsafe_token().is_some())
{
return true;
}
let enclosing_node = enclosing_item.as_ref().either(|i| i.syntax(), |v| v.syntax());

let (body, source_map) = self.db.body_with_source_map(def);

let file_id = self.find_file(node).file_id;
let file_id = self.find_file(expr.syntax()).file_id;

let Some(mut parent) = node.parent() else { return false };
let Some(mut parent) = expr.syntax().parent() else { return false };
loop {
if &parent == enclosing_node {
break false;
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/inlay_hints/adjustment.rs
Expand Up @@ -15,7 +15,7 @@ pub(super) fn hints(
config: &InlayHintsConfig,
expr: &ast::Expr,
) -> Option<()> {
if config.adjustment_hints_hide_outside_unsafe && !sema.is_inside_unsafe(expr.syntax()) {
if config.adjustment_hints_hide_outside_unsafe && !sema.is_inside_unsafe(expr) {
return None;
}

Expand Down

0 comments on commit 94d0772

Please sign in to comment.