Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion crates/ide-assists/src/handlers/inline_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,24 @@ fn inline(
let expr: &ast::Expr = expr;

let mut insert_let_stmt = || {
let ty = sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty.clone());
let param_ty = match param_ty {
None => None,
Some(param_ty) => {
if sema.hir_file_for(param_ty.syntax()).is_macro() {
if let Some(param_ty) =
ast::Type::cast(insert_ws_into(param_ty.syntax().clone()))
{
Some(param_ty)
} else {
Some(param_ty.clone_for_update())
}
} else {
Some(param_ty.clone_for_update())
}
}
};
let ty: Option<syntax::ast::Type> =
sema.type_of_expr(expr).filter(TypeInfo::has_adjustment).and(param_ty);

let is_self = param
.name(sema.db)
Expand Down Expand Up @@ -1732,6 +1749,49 @@ pub fn main() {
this.0 += 1;
};
}
"#,
)
}

#[test]
fn inline_call_with_reference_in_macros() {
check_assist(
inline_call,
r#"
fn _write_u64(s: &mut u64, x: u64) {
*s += x;
}
macro_rules! impl_write {
($(($ty:ident, $meth:ident),)*) => {$(
fn _hash(inner_self_: &u64, state: &mut u64) {
$meth(state, *inner_self_)
}
)*}
}
impl_write! { (u64, _write_u64), }
fn _hash2(self_: &u64, state: &mut u64) {
$0_hash(&self_, state);
}
"#,
r#"
fn _write_u64(s: &mut u64, x: u64) {
*s += x;
}
macro_rules! impl_write {
($(($ty:ident, $meth:ident),)*) => {$(
fn _hash(inner_self_: &u64, state: &mut u64) {
$meth(state, *inner_self_)
}
)*}
}
impl_write! { (u64, _write_u64), }
fn _hash2(self_: &u64, state: &mut u64) {
{
let inner_self_: &u64 = &self_;
let state: &mut u64 = state;
_write_u64(state, *inner_self_)
};
}
"#,
)
}
Expand Down