1 //! Renaming functionality.
3 //! This is mostly front-end for [`ide_db::rename`], but it also includes the
4 //! tests. This module also implements a couple of magic tricks, like renaming
5 //! `self` and to `self` (to switch between associated function and method).
7 use hir::{AsAssocItem, InFile, Semantics};
10 defs::{Definition, NameClass, NameRefClass},
11 rename::{bail, format_err, source_edit_from_references, IdentifierKind},
14 use itertools::Itertools;
15 use stdx::{always, never};
16 use syntax::{ast, AstNode, SyntaxNode};
18 use text_edit::TextEdit;
20 use crate::{FilePosition, RangeInfo, SourceChange};
22 pub use ide_db::rename::RenameError;
24 type RenameResult<T> = Result<T, RenameError>;
26 /// Prepares a rename. The sole job of this function is to return the TextRange of the thing that is
27 /// being targeted for a rename.
28 pub(crate) fn prepare_rename(
30 position: FilePosition,
31 ) -> RenameResult<RangeInfo<()>> {
32 let sema = Semantics::new(db);
33 let source_file = sema.parse(position.file_id);
34 let syntax = source_file.syntax();
36 let res = find_definitions(&sema, syntax, position)?
37 .map(|(name_like, def)| {
38 // ensure all ranges are valid
40 if def.range_for_rename(&sema).is_none() {
41 bail!("No references found at position")
43 let frange = sema.original_range(name_like.syntax());
46 frange.range.contains_inclusive(position.offset)
47 && frange.file_id == position.file_id
51 .reduce(|acc, cur| match (acc, cur) {
52 // ensure all ranges are the same
53 (Ok(acc_inner), Ok(cur_inner)) if acc_inner == cur_inner => Ok(acc_inner),
54 (Err(e), _) => Err(e),
55 _ => bail!("inconsistent text range"),
59 // ensure at least one definition was found
60 Some(res) => res.map(|range| RangeInfo::new(range, ())),
61 None => bail!("No references found at position"),
67 // Renames the item below the cursor and all of its references
70 // | Editor | Shortcut
72 // | VS Code | kbd:[F2]
75 // image::https://user-images.githubusercontent.com/48062697/113065582-055aae80-91b1-11eb-8ade-2b58e6d81883.gif[]
78 position: FilePosition,
80 ) -> RenameResult<SourceChange> {
81 let sema = Semantics::new(db);
82 let source_file = sema.parse(position.file_id);
83 let syntax = source_file.syntax();
85 let defs = find_definitions(&sema, syntax, position)?;
87 let ops: RenameResult<Vec<SourceChange>> = defs
88 .map(|(_namelike, def)| {
89 if let Definition::Local(local) = def {
90 if let Some(self_param) = local.as_self_param(sema.db) {
91 cov_mark::hit!(rename_self_to_param);
92 return rename_self_to_param(&sema, local, self_param, new_name);
94 if new_name == "self" {
95 cov_mark::hit!(rename_to_self);
96 return rename_to_self(&sema, local);
99 def.rename(&sema, new_name)
104 .reduce(|acc, elem| acc.merge(elem))
105 .ok_or_else(|| format_err!("No references found at position"))
108 /// Called by the client when it is about to rename a file.
109 pub(crate) fn will_rename_file(
113 ) -> Option<SourceChange> {
114 let sema = Semantics::new(db);
115 let module = sema.to_module_def(file_id)?;
116 let def = Definition::Module(module);
117 let mut change = def.rename(&sema, new_name_stem).ok()?;
118 change.file_system_edits.clear();
123 sema: &Semantics<'_, RootDatabase>,
125 position: FilePosition,
126 ) -> RenameResult<impl Iterator<Item = (ast::NameLike, Definition)>> {
128 .find_nodes_at_offset_with_descend::<ast::NameLike>(syntax, position.offset)
130 let res = match &name_like {
131 // renaming aliases would rename the item being aliased as the HIR doesn't track aliases yet
132 ast::NameLike::Name(name)
136 .map_or(false, |it| ast::Rename::can_cast(it.kind())) =>
138 bail!("Renaming aliases is currently unsupported")
140 ast::NameLike::Name(name) => NameClass::classify(sema, name)
141 .map(|class| match class {
142 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
143 NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
144 Definition::Local(local_def)
147 .map(|def| (name_like.clone(), def))
148 .ok_or_else(|| format_err!("No references found at position")),
149 ast::NameLike::NameRef(name_ref) => {
150 NameRefClass::classify(sema, name_ref)
151 .map(|class| match class {
152 NameRefClass::Definition(def) => def,
153 NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
154 Definition::Local(local_ref)
157 .ok_or_else(|| format_err!("No references found at position"))
159 // if the name differs from the definitions name it has to be an alias
162 .map_or(false, |it| it.to_smol_str() != name_ref.text().as_str())
164 Err(format_err!("Renaming aliases is currently unsupported"))
166 Ok((name_like.clone(), def))
170 ast::NameLike::Lifetime(lifetime) => {
171 NameRefClass::classify_lifetime(sema, lifetime)
172 .and_then(|class| match class {
173 NameRefClass::Definition(def) => Some(def),
177 NameClass::classify_lifetime(sema, lifetime).and_then(|it| match it {
178 NameClass::Definition(it) => Some(it),
182 .map(|def| (name_like, def))
183 .ok_or_else(|| format_err!("No references found at position"))
189 let res: RenameResult<Vec<_>> = symbols.collect();
193 // FIXME: some semantic duplication between "empty vec" and "Err()"
194 Err(format_err!("No references found at position"))
196 // remove duplicates, comparing `Definition`s
197 Ok(v.into_iter().unique_by(|t| t.1))
205 sema: &Semantics<'_, RootDatabase>,
207 ) -> RenameResult<SourceChange> {
208 if never!(local.is_self(sema.db)) {
209 bail!("rename_to_self invoked on self");
212 let fn_def = match local.parent(sema.db) {
213 hir::DefWithBody::Function(func) => func,
214 _ => bail!("Cannot rename local to self outside of function"),
217 if fn_def.self_param(sema.db).is_some() {
218 bail!("Method already has a self parameter");
221 let params = fn_def.assoc_fn_params(sema.db);
222 let first_param = params
224 .ok_or_else(|| format_err!("Cannot rename local to self unless it is a parameter"))?;
225 match first_param.as_local(sema.db) {
228 bail!("Only the first parameter may be renamed to self");
231 None => bail!("rename_to_self invoked on destructuring parameter"),
234 let assoc_item = fn_def
235 .as_assoc_item(sema.db)
236 .ok_or_else(|| format_err!("Cannot rename parameter to self for free function"))?;
237 let impl_ = match assoc_item.container(sema.db) {
238 hir::AssocItemContainer::Trait(_) => {
239 bail!("Cannot rename parameter to self for trait functions");
241 hir::AssocItemContainer::Impl(impl_) => impl_,
243 let first_param_ty = first_param.ty();
244 let impl_ty = impl_.self_ty(sema.db);
245 let (ty, self_param) = if impl_ty.remove_ref().is_some() {
246 // if the impl is a ref to the type we can just match the `&T` with self directly
247 (first_param_ty.clone(), "self")
249 first_param_ty.remove_ref().map_or((first_param_ty.clone(), "self"), |ty| {
250 (ty, if first_param_ty.is_mutable_reference() { "&mut self" } else { "&self" })
255 bail!("Parameter type differs from impl block type");
258 let InFile { file_id, value: param_source } =
259 first_param.source(sema.db).ok_or_else(|| format_err!("No source for parameter found"))?;
261 let def = Definition::Local(local);
262 let usages = def.usages(sema).all();
263 let mut source_change = SourceChange::default();
264 source_change.extend(usages.iter().map(|(&file_id, references)| {
265 (file_id, source_edit_from_references(references, def, "self"))
267 source_change.insert_source_edit(
268 file_id.original_file(sema.db),
269 TextEdit::replace(param_source.syntax().text_range(), String::from(self_param)),
274 fn rename_self_to_param(
275 sema: &Semantics<'_, RootDatabase>,
277 self_param: hir::SelfParam,
279 ) -> RenameResult<SourceChange> {
280 if new_name == "self" {
281 // Let's do nothing rather than complain.
282 cov_mark::hit!(rename_self_to_self);
283 return Ok(SourceChange::default());
286 let identifier_kind = IdentifierKind::classify(new_name)?;
288 let InFile { file_id, value: self_param } =
289 self_param.source(sema.db).ok_or_else(|| format_err!("cannot find function source"))?;
291 let def = Definition::Local(local);
292 let usages = def.usages(sema).all();
293 let edit = text_edit_from_self_param(&self_param, new_name)
294 .ok_or_else(|| format_err!("No target type found"))?;
295 if usages.len() > 1 && identifier_kind == IdentifierKind::Underscore {
296 bail!("Cannot rename reference to `_` as it is being referenced multiple times");
298 let mut source_change = SourceChange::default();
299 source_change.insert_source_edit(file_id.original_file(sema.db), edit);
300 source_change.extend(usages.iter().map(|(&file_id, references)| {
301 (file_id, source_edit_from_references(references, def, new_name))
306 fn text_edit_from_self_param(self_param: &ast::SelfParam, new_name: &str) -> Option<TextEdit> {
307 fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
308 if let Some(ast::Type::PathType(p)) = impl_def.self_ty() {
309 return Some(p.path()?.segment()?.name_ref()?.text().to_string());
314 let impl_def = self_param.syntax().ancestors().find_map(ast::Impl::cast)?;
315 let type_name = target_type_name(&impl_def)?;
317 let mut replacement_text = String::from(new_name);
318 replacement_text.push_str(": ");
319 match (self_param.amp_token(), self_param.mut_token()) {
320 (Some(_), None) => replacement_text.push('&'),
321 (Some(_), Some(_)) => replacement_text.push_str("&mut "),
324 replacement_text.push_str(type_name.as_str());
326 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
331 use expect_test::{expect, Expect};
332 use stdx::trim_indent;
333 use test_utils::assert_eq_text;
334 use text_edit::TextEdit;
336 use crate::{fixture, FileId};
338 use super::{RangeInfo, RenameError};
341 fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
342 let ra_fixture_after = &trim_indent(ra_fixture_after);
343 let (analysis, position) = fixture::position(ra_fixture_before);
344 let rename_result = analysis
345 .rename(position, new_name)
346 .unwrap_or_else(|err| panic!("Rename to '{}' was cancelled: {}", new_name, err));
347 match rename_result {
348 Ok(source_change) => {
349 let mut text_edit_builder = TextEdit::builder();
350 let mut file_id: Option<FileId> = None;
351 for edit in source_change.source_file_edits {
352 file_id = Some(edit.0);
353 for indel in edit.1.into_iter() {
354 text_edit_builder.replace(indel.delete, indel.insert);
357 if let Some(file_id) = file_id {
358 let mut result = analysis.file_text(file_id).unwrap().to_string();
359 text_edit_builder.finish().apply(&mut result);
360 assert_eq_text!(ra_fixture_after, &*result);
364 if ra_fixture_after.starts_with("error:") {
365 let error_message = ra_fixture_after
368 .skip("error:".len())
369 .collect::<String>();
370 assert_eq!(error_message.trim(), err.to_string());
372 panic!("Rename to '{}' failed unexpectedly: {}", new_name, err)
378 fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
379 let (analysis, position) = fixture::position(ra_fixture);
381 analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
382 expect.assert_debug_eq(&source_change)
385 fn check_expect_will_rename_file(new_name: &str, ra_fixture: &str, expect: Expect) {
386 let (analysis, position) = fixture::position(ra_fixture);
387 let source_change = analysis
388 .will_rename_file(position.file_id, new_name)
390 .expect("Expect returned a RenameError");
391 expect.assert_debug_eq(&source_change)
394 fn check_prepare(ra_fixture: &str, expect: Expect) {
395 let (analysis, position) = fixture::position(ra_fixture);
396 let result = analysis
397 .prepare_rename(position)
398 .unwrap_or_else(|err| panic!("PrepareRename was cancelled: {}", err));
400 Ok(RangeInfo { range, info: () }) => {
401 let source = analysis.file_text(position.file_id).unwrap();
402 expect.assert_eq(&format!("{:?}: {}", range, &source[range]))
404 Err(RenameError(err)) => expect.assert_eq(&err),
409 fn test_prepare_rename_namelikes() {
410 check_prepare(r"fn name$0<'lifetime>() {}", expect![[r#"3..7: name"#]]);
411 check_prepare(r"fn name<'lifetime$0>() {}", expect![[r#"8..17: 'lifetime"#]]);
412 check_prepare(r"fn name<'lifetime>() { name$0(); }", expect![[r#"23..27: name"#]]);
416 fn test_prepare_rename_in_macro() {
424 expect![[r#"83..86: Foo"#]],
429 fn test_prepare_rename_keyword() {
430 check_prepare(r"struct$0 Foo;", expect![[r#"No references found at position"#]]);
434 fn test_prepare_rename_tuple_field() {
444 expect![[r#"No references found at position"#]],
449 fn test_prepare_rename_builtin() {
456 expect![[r#"No references found at position"#]],
461 fn test_prepare_rename_self() {
467 fn foo(self) -> Self$0 {
472 expect![[r#"No references found at position"#]],
477 fn test_rename_to_underscore() {
478 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
482 fn test_rename_to_raw_identifier() {
483 check("r#fn", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
487 fn test_rename_to_invalid_identifier1() {
490 r#"fn main() { let i$0 = 1; }"#,
491 "error: Invalid name `invalid!`: not an identifier",
496 fn test_rename_to_invalid_identifier2() {
499 r#"fn main() { let i$0 = 1; }"#,
500 "error: Invalid name `multiple tokens`: not an identifier",
505 fn test_rename_to_invalid_identifier3() {
508 r#"fn main() { let i$0 = 1; }"#,
509 "error: Invalid name `let`: not an identifier",
514 fn test_rename_to_invalid_identifier_lifetime() {
515 cov_mark::check!(rename_not_an_ident_ref);
518 r#"fn main() { let i$0 = 1; }"#,
519 "error: Invalid name `'foo`: not an identifier",
524 fn test_rename_to_invalid_identifier_lifetime2() {
525 cov_mark::check!(rename_not_a_lifetime_ident_ref);
528 r#"fn main<'a>(_: &'a$0 ()) {}"#,
529 "error: Invalid name `foo`: not a lifetime identifier",
534 fn test_rename_to_underscore_invalid() {
535 cov_mark::check!(rename_underscore_multiple);
538 r#"fn main(foo$0: ()) {foo;}"#,
539 "error: Cannot rename reference to `_` as it is being referenced multiple times",
544 fn test_rename_mod_invalid() {
548 "error: Invalid name `'foo`: cannot rename module to 'foo",
553 fn test_rename_for_local() {
582 fn test_rename_unresolved_reference() {
585 r#"fn main() { let _ = unresolved_ref$0; }"#,
586 "error: No references found at position",
591 fn test_rename_macro_multiple_occurrences() {
594 r#"macro_rules! foo {
596 const $ident: () = ();
603 const _: Foo = Foo {};
608 const $ident: () = ();
615 const _: Baaah = Baaah {};
621 fn test_rename_for_macro_args() {
625 macro_rules! foo {($i:ident) => {$i} }
632 macro_rules! foo {($i:ident) => {$i} }
642 fn test_rename_for_macro_args_rev() {
646 macro_rules! foo {($i:ident) => {$i} }
653 macro_rules! foo {($i:ident) => {$i} }
663 fn test_rename_for_macro_define_fn() {
667 macro_rules! define_fn {($id:ident) => { fn $id{} }}
674 macro_rules! define_fn {($id:ident) => { fn $id{} }}
684 fn test_rename_for_macro_define_fn_rev() {
688 macro_rules! define_fn {($id:ident) => { fn $id{} }}
695 macro_rules! define_fn {($id:ident) => { fn $id{} }}
705 fn test_rename_for_param_inside() {
706 check("j", r#"fn foo(i : u32) -> u32 { i$0 }"#, r#"fn foo(j : u32) -> u32 { j }"#);
710 fn test_rename_refs_for_fn_param() {
711 check("j", r#"fn foo(i$0 : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
715 fn test_rename_for_mut_param() {
716 check("j", r#"fn foo(mut i$0 : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
720 fn test_rename_struct_field() {
724 struct Foo { field$0: i32 }
727 fn new(i: i32) -> Self {
733 struct Foo { foo: i32 }
736 fn new(i: i32) -> Self {
745 fn test_rename_field_in_field_shorthand() {
746 cov_mark::check!(test_rename_field_in_field_shorthand);
750 struct Foo { foo$0: i32 }
753 fn new(foo: i32) -> Self {
759 struct Foo { field: i32 }
762 fn new(foo: i32) -> Self {
771 fn test_rename_local_in_field_shorthand() {
772 cov_mark::check!(test_rename_local_in_field_shorthand);
776 struct Foo { i: i32 }
779 fn new(i$0: i32) -> Self {
785 struct Foo { i: i32 }
788 fn new(j: i32) -> Self {
797 fn test_field_shorthand_correct_struct() {
801 struct Foo { i$0: i32 }
802 struct Bar { i: i32 }
805 fn new(i: i32) -> Self {
811 struct Foo { j: i32 }
812 struct Bar { i: i32 }
815 fn new(i: i32) -> Self {
824 fn test_shadow_local_for_struct_shorthand() {
828 struct Foo { i: i32 }
830 fn baz(i$0: i32) -> Self {
839 struct Foo { i: i32 }
841 fn baz(j: i32) -> Self {
842 let x = Foo { i: j };
853 fn test_rename_mod() {
885 dst: AnchoredPathBuf {
900 fn test_rename_mod_in_use_tree() {
910 pub struct FooContent;
913 use crate::foo$0::FooContent;
944 dst: AnchoredPathBuf {
959 fn test_rename_mod_in_dir() {
984 src: AnchoredPathBuf {
993 dst: AnchoredPathBuf {
1008 fn test_rename_unusually_nested_mod() {
1013 mod outer { mod fo$0o; }
1020 source_file_edits: {
1032 file_system_edits: [
1037 dst: AnchoredPathBuf {
1052 fn test_module_rename_in_path() {
1057 pub use self::bar as qux;
1061 fn main() { foo::bar(); }
1065 pub use self::bar as qux;
1069 fn main() { baz::bar(); }
1075 fn test_rename_mod_filename_and_path() {
1093 source_file_edits: {
1115 file_system_edits: [
1120 dst: AnchoredPathBuf {
1135 fn test_rename_mod_recursive() {
1152 //- /foo/bar/qux/quux/mod.rs
1160 source_file_edits: {
1172 file_system_edits: [
1177 dst: AnchoredPathBuf {
1185 src: AnchoredPathBuf {
1194 dst: AnchoredPathBuf {
1208 fn test_rename_mod_ref_by_super() {
1233 fn test_rename_mod_in_macro() {
1240 macro_rules! submodule {
1249 macro_rules! submodule {
1261 fn test_rename_mod_for_crate_root() {
1262 check_expect_will_rename_file(
1266 use crate::foo as bar;
1272 source_file_edits: {},
1273 file_system_edits: [],
1281 fn test_enum_variant_from_module_1() {
1282 cov_mark::check!(rename_non_local);
1287 pub enum Foo { Bar$0 }
1290 fn func(f: foo::Foo) {
1298 pub enum Foo { Baz }
1301 fn func(f: foo::Foo) {
1311 fn test_enum_variant_from_module_2() {
1316 pub struct Foo { pub bar$0: uint }
1319 fn foo(f: foo::Foo) {
1325 pub struct Foo { pub baz: uint }
1328 fn foo(f: foo::Foo) {
1336 fn test_parameter_to_self() {
1337 cov_mark::check!(rename_to_self);
1341 struct Foo { i: i32 }
1344 fn f(foo$0: &mut Foo) -> i32 {
1350 struct Foo { i: i32 }
1353 fn f(&mut self) -> i32 {
1362 struct Foo { i: i32 }
1365 fn f(foo$0: Foo) -> i32 {
1371 struct Foo { i: i32 }
1383 fn test_parameter_to_self_error_no_impl() {
1387 struct Foo { i: i32 }
1389 fn f(foo$0: &mut Foo) -> i32 {
1393 "error: Cannot rename parameter to self for free function",
1398 struct Foo { i: i32 }
1402 fn f(foo$0: &mut Foo) -> i32 {
1407 "error: Parameter type differs from impl block type",
1412 fn test_parameter_to_self_error_not_first() {
1416 struct Foo { i: i32 }
1418 fn f(x: (), foo$0: &mut Foo) -> i32 {
1423 "error: Only the first parameter may be renamed to self",
1428 fn test_parameter_to_self_impl_ref() {
1432 struct Foo { i: i32 }
1434 fn f(foo$0: &Foo) -> i32 {
1440 struct Foo { i: i32 }
1451 fn test_self_to_parameter() {
1455 struct Foo { i: i32 }
1458 fn f(&mut $0self) -> i32 {
1464 struct Foo { i: i32 }
1467 fn f(foo: &mut Foo) -> i32 {
1476 fn test_owned_self_to_parameter() {
1477 cov_mark::check!(rename_self_to_param);
1481 struct Foo { i: i32 }
1484 fn f($0self) -> i32 {
1490 struct Foo { i: i32 }
1493 fn f(foo: Foo) -> i32 {
1502 fn test_self_in_path_to_parameter() {
1506 struct Foo { i: i32 }
1509 fn f(&self) -> i32 {
1516 struct Foo { i: i32 }
1519 fn f(foo: &Foo) -> i32 {
1529 fn test_rename_field_put_init_shorthand() {
1530 cov_mark::check!(test_rename_field_put_init_shorthand);
1534 struct Foo { i$0: i32 }
1536 fn foo(bar: i32) -> Foo {
1541 struct Foo { bar: i32 }
1543 fn foo(bar: i32) -> Foo {
1551 fn test_rename_local_put_init_shorthand() {
1552 cov_mark::check!(test_rename_local_put_init_shorthand);
1556 struct Foo { i: i32 }
1558 fn foo(bar$0: i32) -> Foo {
1563 struct Foo { i: i32 }
1565 fn foo(i: i32) -> Foo {
1573 fn test_struct_field_pat_into_shorthand() {
1574 cov_mark::check!(test_rename_field_put_init_shorthand_pat);
1578 struct Foo { i$0: i32 }
1581 let Foo { i: ref baz @ qux } = foo;
1586 struct Foo { baz: i32 }
1589 let Foo { baz: ref baz @ qux } = foo;
1597 struct Foo { i$0: i32 }
1600 let Foo { i: ref baz } = foo;
1605 struct Foo { baz: i32 }
1608 let Foo { ref baz } = foo;
1616 fn test_struct_local_pat_into_shorthand() {
1617 cov_mark::check!(test_rename_local_put_init_shorthand_pat);
1621 struct Foo { field: i32 }
1624 let Foo { field: qux$0 } = foo;
1629 struct Foo { field: i32 }
1632 let Foo { field } = foo;
1640 struct Foo { field: i32 }
1643 let Foo { field: x @ qux$0 } = foo;
1648 struct Foo { field: i32 }
1651 let Foo { field: x @ field } = foo;
1659 fn test_rename_binding_in_destructure_pat() {
1660 let expected_fixture = r#"
1666 let Foo { i: bar } = foo;
1678 let Foo { i: b } = foo;
1692 let Foo { i } = foo;
1701 fn test_rename_binding_in_destructure_param_pat() {
1709 fn foo(Foo { i }: Foo) -> i32 {
1718 fn foo(Foo { i: bar }: Foo) -> i32 {
1726 fn test_struct_field_complex_ident_pat() {
1727 cov_mark::check!(rename_record_pat_field_name_split);
1731 struct Foo { i$0: i32 }
1734 let Foo { ref i } = foo;
1738 struct Foo { baz: i32 }
1741 let Foo { baz: ref i } = foo;
1748 fn test_rename_lifetimes() {
1749 cov_mark::check!(rename_lifetime);
1756 impl<'a> Foo<'a> for &'a () {
1757 fn foo() -> &'a$0 () {
1766 impl<'yeeee> Foo<'yeeee> for &'yeeee () {
1767 fn foo() -> &'yeeee () {
1776 fn test_rename_bind_pat() {
1781 enum CustomOption<T> {
1786 let test_variable = CustomOption::Some(22);
1788 match test_variable {
1789 CustomOption::Some(foo$0) if foo == 11 => {}
1795 enum CustomOption<T> {
1800 let test_variable = CustomOption::Some(22);
1802 match test_variable {
1803 CustomOption::Some(new_name) if new_name == 11 => {}
1811 fn test_rename_label() {
1815 fn foo<'a>() -> &'a () {
1824 fn foo<'a>() -> &'a () {
1836 fn test_self_to_self() {
1837 cov_mark::check!(rename_self_to_self);
1856 fn test_rename_field_in_pat_in_macro_doesnt_shorthand() {
1857 // ideally we would be able to make this emit a short hand, but I doubt this is easily possible
1863 let $pattern = loop {};
1870 foo!(Foo { bar: baz });
1876 let $pattern = loop {};
1883 foo!(Foo { baz: baz });
1890 fn test_rename_tuple_field() {
1901 "error: No identifier available to rename",
1906 fn test_rename_builtin() {
1914 "error: Cannot rename builtin type",
1919 fn test_rename_self() {
1926 fn foo(self) -> Self$0 {
1931 "error: Cannot rename `Self`",
1936 fn test_rename_ignores_self_ty() {
1942 impl Foo where Self: {}
1947 impl Fo0 where Self: {}
1953 fn test_rename_fails_on_aliases() {
1960 "error: Renaming aliases is currently unsupported",
1969 "error: Renaming aliases is currently unsupported",
1974 fn test_rename_trait_method() {
2054 fn test_rename_trait_method_prefix_of_second() {
2073 fn test_rename_trait_const() {
2082 fn f() { <()>::FOO; }";
2093 fn f() { <()>::BAR; }"#,
2106 fn f() { <()>::BAR; }"#,
2119 fn f() { <()>::BAR$0; }"#,
2125 fn defs_from_macros_arent_renamed() {
2129 macro_rules! m { () => { fn f() {} } }
2133 "error: No identifier available to rename",
2138 fn attributed_item() {
2142 //- proc_macros: identity
2144 #[proc_macros::identity]
2151 #[proc_macros::identity]
2160 fn in_macro_multi_mapping() {
2165 macro_rules! match_ast2 {
2169 $( if $node { $res } else )*
2184 macro_rules! match_ast2 {
2188 $( if $node { $res } else )*
2205 fn rename_multi_local() {
2209 fn foo((foo$0 | foo | foo): ()) {
2215 fn foo((bar | bar | bar): ()) {
2224 fn foo((foo | foo$0 | foo): ()) {
2230 fn foo((bar | bar | bar): ()) {
2239 fn foo((foo | foo | foo): ()) {
2245 fn foo((bar | bar | bar): ()) {