mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 15:47:31 +00:00
fix: Walk const block expressions for unsafety checking
This commit is contained in:
parent
4fdc2507c6
commit
8df812f14d
3 changed files with 21 additions and 0 deletions
|
@ -282,6 +282,9 @@ impl ExpressionStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// Walks the immediate children expressions and calls `f` for each child expression.
|
||||
///
|
||||
/// Note that this does not walk const blocks.
|
||||
pub fn walk_child_exprs(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) {
|
||||
let expr = &self[expr_id];
|
||||
match expr {
|
||||
|
@ -415,6 +418,10 @@ impl ExpressionStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// Walks the immediate children expressions and calls `f` for each child expression but does
|
||||
/// not walk expressions within patterns.
|
||||
///
|
||||
/// Note that this does not walk const blocks.
|
||||
pub fn walk_child_exprs_without_pats(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) {
|
||||
let expr = &self[expr_id];
|
||||
match expr {
|
||||
|
|
|
@ -348,6 +348,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
Expr::Closure { args, .. } => {
|
||||
self.walk_pats_top(args.iter().copied(), current);
|
||||
}
|
||||
Expr::Const(e) => self.walk_expr(*e),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -874,6 +874,19 @@ fn baz() {
|
|||
fn f(it: unsafe fn()){
|
||||
it();
|
||||
// ^^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsafe_call_in_const_expr() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
unsafe fn f() {}
|
||||
fn main() {
|
||||
const { f(); };
|
||||
// ^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue