Skip to content

Commit 1038db5

Browse files
WaffleLapkinVeykril
andcommitted
Apply suggestions from code review
Co-authored-by: Lukas Wirth <[email protected]>
1 parent 608dc49 commit 1038db5

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

crates/hir/src/semantics.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
485485
}
486486

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

@@ -1471,17 +1471,18 @@ impl<'db> SemanticsImpl<'db> {
14711471
.unwrap_or(false)
14721472
}
14731473

1474-
fn is_inside_unsafe(&self, node: &SyntaxNode) -> bool {
1474+
fn is_inside_unsafe(&self, expr: &ast::Expr) -> bool {
14751475
let item_or_variant = |ancestor: SyntaxNode| {
14761476
if ast::Item::can_cast(ancestor.kind()) {
14771477
ast::Item::cast(ancestor).map(Either::Left)
14781478
} else {
14791479
ast::Variant::cast(ancestor).map(Either::Right)
14801480
}
14811481
};
1482-
let Some(enclosing_item) = node.ancestors().find_map(item_or_variant) else { return false };
1482+
let Some(enclosing_item) = expr.syntax().ancestors().find_map(item_or_variant) else { return false };
14831483

14841484
let def = match &enclosing_item {
1485+
Either::Left(ast::Item::Fn(it)) if it.unsafe_token().is_some() => return true,
14851486
Either::Left(ast::Item::Fn(it)) => {
14861487
self.to_def(it).map(<_>::into).map(DefWithBodyId::FunctionId)
14871488
}
@@ -1497,15 +1498,11 @@ impl<'db> SemanticsImpl<'db> {
14971498
let Some(def) = def else { return false };
14981499
let enclosing_node = enclosing_item.as_ref().either(|i| i.syntax(), |v| v.syntax());
14991500

1500-
if ast::Fn::cast(enclosing_node.clone()).and_then(|f| f.unsafe_token()).is_some() {
1501-
return true;
1502-
}
1503-
15041501
let (body, source_map) = self.db.body_with_source_map(def);
15051502

1506-
let file_id = self.find_file(node).file_id;
1503+
let file_id = self.find_file(expr.syntax()).file_id;
15071504

1508-
let Some(mut parent) = node.parent() else { return false };
1505+
let Some(mut parent) = expr.syntax().parent() else { return false };
15091506
loop {
15101507
if &parent == enclosing_node {
15111508
break false;

crates/ide/src/inlay_hints/adjustment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn hints(
1515
config: &InlayHintsConfig,
1616
expr: &ast::Expr,
1717
) -> Option<()> {
18-
if config.adjustment_hints_hide_outside_unsafe && !sema.is_inside_unsafe(expr.syntax()) {
18+
if config.adjustment_hints_hide_outside_unsafe && !sema.is_inside_unsafe(expr) {
1919
return None;
2020
}
2121

0 commit comments

Comments
 (0)