mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Create an assist to convert closure to freestanding fn
The assist converts all captures to parameters.
This commit is contained in:
parent
095926ea6f
commit
0e4f4d3f9c
6 changed files with 1511 additions and 13 deletions
|
@ -16,7 +16,8 @@ use base_db::CrateId;
|
|||
use chalk_ir::Mutability;
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
hir::{BindingId, Expr, ExprId, Ordering, PatId},
|
||||
body::Body,
|
||||
hir::{BindingAnnotation, BindingId, Expr, ExprId, Ordering, PatId},
|
||||
DefWithBodyId, FieldId, StaticId, TupleFieldId, UnionId, VariantId,
|
||||
};
|
||||
use la_arena::{Arena, ArenaMap, Idx, RawIdx};
|
||||
|
@ -1174,6 +1175,20 @@ pub enum MirSpan {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
impl MirSpan {
|
||||
pub fn is_ref_span(&self, body: &Body) -> bool {
|
||||
match *self {
|
||||
MirSpan::ExprId(expr) => matches!(body[expr], Expr::Ref { .. }),
|
||||
// FIXME: Figure out if this is correct wrt. match ergonomics.
|
||||
MirSpan::BindingId(binding) => matches!(
|
||||
body.bindings[binding].mode,
|
||||
BindingAnnotation::Ref | BindingAnnotation::RefMut
|
||||
),
|
||||
MirSpan::PatId(_) | MirSpan::SelfParam | MirSpan::Unknown => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_from!(ExprId, PatId for MirSpan);
|
||||
|
||||
impl From<&ExprId> for MirSpan {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue