mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
fix break-outside-of-loop false positive in try block
This commit is contained in:
parent
6312fbf521
commit
3a3c3630a2
2 changed files with 20 additions and 1 deletions
|
@ -505,6 +505,7 @@ impl ExprCollector<'_> {
|
||||||
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
|
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
|
||||||
|
|
||||||
let prev_is_lowering_generator = mem::take(&mut this.is_lowering_generator);
|
let prev_is_lowering_generator = mem::take(&mut this.is_lowering_generator);
|
||||||
|
let prev_try_block_label = this.current_try_block_label.take();
|
||||||
|
|
||||||
let body = this.collect_expr_opt(e.body());
|
let body = this.collect_expr_opt(e.body());
|
||||||
|
|
||||||
|
@ -520,11 +521,11 @@ impl ExprCollector<'_> {
|
||||||
} else {
|
} else {
|
||||||
ClosureKind::Closure
|
ClosureKind::Closure
|
||||||
};
|
};
|
||||||
this.is_lowering_generator = prev_is_lowering_generator;
|
|
||||||
let capture_by =
|
let capture_by =
|
||||||
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
|
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
|
||||||
this.is_lowering_generator = prev_is_lowering_generator;
|
this.is_lowering_generator = prev_is_lowering_generator;
|
||||||
this.current_binding_owner = prev_binding_owner;
|
this.current_binding_owner = prev_binding_owner;
|
||||||
|
this.current_try_block_label = prev_try_block_label;
|
||||||
this.body.exprs[result_expr_id] = Expr::Closure {
|
this.body.exprs[result_expr_id] = Expr::Closure {
|
||||||
args: args.into(),
|
args: args.into(),
|
||||||
arg_types: arg_types.into(),
|
arg_types: arg_types.into(),
|
||||||
|
|
|
@ -132,6 +132,24 @@ fn test() {
|
||||||
// ^^^^^^^ error: can't break with a value in this position
|
// ^^^^^^^ error: can't break with a value in this position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn try_block_desugaring_inside_closure() {
|
||||||
|
// regression test for #14701
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- minicore: option, try
|
||||||
|
fn test() {
|
||||||
|
try {
|
||||||
|
|| {
|
||||||
|
let x = Some(2);
|
||||||
|
Some(x?)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue