fix: Check whether a parameter can be converted to a local

This commit is contained in:
Lukas Wirth 2022-04-09 00:55:45 +02:00
parent 399559e597
commit 15e7112da3
3 changed files with 41 additions and 24 deletions

View file

@ -219,8 +219,13 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
let first_param = params
.first()
.ok_or_else(|| format_err!("Cannot rename local to self unless it is a parameter"))?;
if first_param.as_local(sema.db) != local {
bail!("Only the first parameter may be renamed to self");
match first_param.as_local(sema.db) {
Some(plocal) => {
if plocal != local {
bail!("Only the first parameter may be renamed to self");
}
}
None => bail!("rename_to_self invoked on destructuring parameter"),
}
let assoc_item = fn_def