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 Some(frange) = sema.original_range_opt(name_like.syntax()) else {
44 bail!("No references found at position");
48 frange.range.contains_inclusive(position.offset)
49 && frange.file_id == position.file_id
53 .reduce(|acc, cur| match (acc, cur) {
54 // ensure all ranges are the same
55 (Ok(acc_inner), Ok(cur_inner)) if acc_inner == cur_inner => Ok(acc_inner),
56 (e @ Err(_), _) | (_, e @ Err(_)) => e,
57 _ => bail!("inconsistent text range"),
61 // ensure at least one definition was found
62 Some(res) => res.map(|range| RangeInfo::new(range, ())),
63 None => bail!("No references found at position"),
69 // Renames the item below the cursor and all of its references
72 // | Editor | Shortcut
74 // | VS Code | kbd:[F2]
77 // image::https://user-images.githubusercontent.com/48062697/113065582-055aae80-91b1-11eb-8ade-2b58e6d81883.gif[]
80 position: FilePosition,
82 ) -> RenameResult<SourceChange> {
83 let sema = Semantics::new(db);
84 let source_file = sema.parse(position.file_id);
85 let syntax = source_file.syntax();
87 let defs = find_definitions(&sema, syntax, position)?;
89 let ops: RenameResult<Vec<SourceChange>> = defs
90 .map(|(_namelike, def)| {
91 if let Definition::Local(local) = def {
92 if let Some(self_param) = local.as_self_param(sema.db) {
93 cov_mark::hit!(rename_self_to_param);
94 return rename_self_to_param(&sema, local, self_param, new_name);
96 if new_name == "self" {
97 cov_mark::hit!(rename_to_self);
98 return rename_to_self(&sema, local);
101 def.rename(&sema, new_name)
106 .reduce(|acc, elem| acc.merge(elem))
107 .ok_or_else(|| format_err!("No references found at position"))
110 /// Called by the client when it is about to rename a file.
111 pub(crate) fn will_rename_file(
115 ) -> Option<SourceChange> {
116 let sema = Semantics::new(db);
117 let module = sema.to_module_def(file_id)?;
118 let def = Definition::Module(module);
119 let mut change = def.rename(&sema, new_name_stem).ok()?;
120 change.file_system_edits.clear();
125 sema: &Semantics<'_, RootDatabase>,
127 position: FilePosition,
128 ) -> RenameResult<impl Iterator<Item = (ast::NameLike, Definition)>> {
130 .find_nodes_at_offset_with_descend::<ast::NameLike>(syntax, position.offset)
132 let res = match &name_like {
133 // renaming aliases would rename the item being aliased as the HIR doesn't track aliases yet
134 ast::NameLike::Name(name)
138 .map_or(false, |it| ast::Rename::can_cast(it.kind())) =>
140 bail!("Renaming aliases is currently unsupported")
142 ast::NameLike::Name(name) => NameClass::classify(sema, name)
143 .map(|class| match class {
144 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
145 NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
146 Definition::Local(local_def)
149 .map(|def| (name_like.clone(), def))
150 .ok_or_else(|| format_err!("No references found at position")),
151 ast::NameLike::NameRef(name_ref) => {
152 NameRefClass::classify(sema, name_ref)
153 .map(|class| match class {
154 NameRefClass::Definition(def) => def,
155 NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
156 Definition::Local(local_ref)
159 .ok_or_else(|| format_err!("No references found at position"))
161 // if the name differs from the definitions name it has to be an alias
164 .map_or(false, |it| it.to_smol_str() != name_ref.text().as_str())
166 Err(format_err!("Renaming aliases is currently unsupported"))
168 Ok((name_like.clone(), def))
172 ast::NameLike::Lifetime(lifetime) => {
173 NameRefClass::classify_lifetime(sema, lifetime)
174 .and_then(|class| match class {
175 NameRefClass::Definition(def) => Some(def),
179 NameClass::classify_lifetime(sema, lifetime).and_then(|it| match it {
180 NameClass::Definition(it) => Some(it),
184 .map(|def| (name_like, def))
185 .ok_or_else(|| format_err!("No references found at position"))
191 let res: RenameResult<Vec<_>> = symbols.collect();
195 // FIXME: some semantic duplication between "empty vec" and "Err()"
196 Err(format_err!("No references found at position"))
198 // remove duplicates, comparing `Definition`s
199 Ok(v.into_iter().unique_by(|t| t.1))
207 sema: &Semantics<'_, RootDatabase>,
209 ) -> RenameResult<SourceChange> {
210 if never!(local.is_self(sema.db)) {
211 bail!("rename_to_self invoked on self");
214 let fn_def = match local.parent(sema.db) {
215 hir::DefWithBody::Function(func) => func,
216 _ => bail!("Cannot rename local to self outside of function"),
219 if fn_def.self_param(sema.db).is_some() {
220 bail!("Method already has a self parameter");
223 let params = fn_def.assoc_fn_params(sema.db);
224 let first_param = params
226 .ok_or_else(|| format_err!("Cannot rename local to self unless it is a parameter"))?;
227 match first_param.as_local(sema.db) {
230 bail!("Only the first parameter may be renamed to self");
233 None => bail!("rename_to_self invoked on destructuring parameter"),
236 let assoc_item = fn_def
237 .as_assoc_item(sema.db)
238 .ok_or_else(|| format_err!("Cannot rename parameter to self for free function"))?;
239 let impl_ = match assoc_item.container(sema.db) {
240 hir::AssocItemContainer::Trait(_) => {
241 bail!("Cannot rename parameter to self for trait functions");
243 hir::AssocItemContainer::Impl(impl_) => impl_,
245 let first_param_ty = first_param.ty();
246 let impl_ty = impl_.self_ty(sema.db);
247 let (ty, self_param) = if impl_ty.remove_ref().is_some() {
248 // if the impl is a ref to the type we can just match the `&T` with self directly
249 (first_param_ty.clone(), "self")
251 first_param_ty.remove_ref().map_or((first_param_ty.clone(), "self"), |ty| {
252 (ty, if first_param_ty.is_mutable_reference() { "&mut self" } else { "&self" })
257 bail!("Parameter type differs from impl block type");
260 let InFile { file_id, value: param_source } =
261 first_param.source(sema.db).ok_or_else(|| format_err!("No source for parameter found"))?;
263 let def = Definition::Local(local);
264 let usages = def.usages(sema).all();
265 let mut source_change = SourceChange::default();
266 source_change.extend(usages.iter().map(|(&file_id, references)| {
267 (file_id, source_edit_from_references(references, def, "self"))
269 source_change.insert_source_edit(
270 file_id.original_file(sema.db),
271 TextEdit::replace(param_source.syntax().text_range(), String::from(self_param)),
276 fn rename_self_to_param(
277 sema: &Semantics<'_, RootDatabase>,
279 self_param: hir::SelfParam,
281 ) -> RenameResult<SourceChange> {
282 if new_name == "self" {
283 // Let's do nothing rather than complain.
284 cov_mark::hit!(rename_self_to_self);
285 return Ok(SourceChange::default());
288 let identifier_kind = IdentifierKind::classify(new_name)?;
290 let InFile { file_id, value: self_param } =
291 self_param.source(sema.db).ok_or_else(|| format_err!("cannot find function source"))?;
293 let def = Definition::Local(local);
294 let usages = def.usages(sema).all();
295 let edit = text_edit_from_self_param(&self_param, new_name)
296 .ok_or_else(|| format_err!("No target type found"))?;
297 if usages.len() > 1 && identifier_kind == IdentifierKind::Underscore {
298 bail!("Cannot rename reference to `_` as it is being referenced multiple times");
300 let mut source_change = SourceChange::default();
301 source_change.insert_source_edit(file_id.original_file(sema.db), edit);
302 source_change.extend(usages.iter().map(|(&file_id, references)| {
303 (file_id, source_edit_from_references(references, def, new_name))
308 fn text_edit_from_self_param(self_param: &ast::SelfParam, new_name: &str) -> Option<TextEdit> {
309 fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
310 if let Some(ast::Type::PathType(p)) = impl_def.self_ty() {
311 return Some(p.path()?.segment()?.name_ref()?.text().to_string());
316 let impl_def = self_param.syntax().ancestors().find_map(ast::Impl::cast)?;
317 let type_name = target_type_name(&impl_def)?;
319 let mut replacement_text = String::from(new_name);
320 replacement_text.push_str(": ");
321 match (self_param.amp_token(), self_param.mut_token()) {
322 (Some(_), None) => replacement_text.push('&'),
323 (Some(_), Some(_)) => replacement_text.push_str("&mut "),
326 replacement_text.push_str(type_name.as_str());
328 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
333 use expect_test::{expect, Expect};
334 use stdx::trim_indent;
335 use test_utils::assert_eq_text;
336 use text_edit::TextEdit;
338 use crate::{fixture, FileId};
340 use super::{RangeInfo, RenameError};
343 fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
344 let ra_fixture_after = &trim_indent(ra_fixture_after);
345 let (analysis, position) = fixture::position(ra_fixture_before);
346 let rename_result = analysis
347 .rename(position, new_name)
348 .unwrap_or_else(|err| panic!("Rename to '{new_name}' was cancelled: {err}"));
349 match rename_result {
350 Ok(source_change) => {
351 let mut text_edit_builder = TextEdit::builder();
352 let mut file_id: Option<FileId> = None;
353 for edit in source_change.source_file_edits {
354 file_id = Some(edit.0);
355 for indel in edit.1.into_iter() {
356 text_edit_builder.replace(indel.delete, indel.insert);
359 if let Some(file_id) = file_id {
360 let mut result = analysis.file_text(file_id).unwrap().to_string();
361 text_edit_builder.finish().apply(&mut result);
362 assert_eq_text!(ra_fixture_after, &*result);
366 if ra_fixture_after.starts_with("error:") {
368 ra_fixture_after.chars().skip("error:".len()).collect::<String>();
369 assert_eq!(error_message.trim(), err.to_string());
371 panic!("Rename to '{new_name}' failed unexpectedly: {err}")
377 fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
378 let (analysis, position) = fixture::position(ra_fixture);
380 analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
381 expect.assert_debug_eq(&source_change)
384 fn check_expect_will_rename_file(new_name: &str, ra_fixture: &str, expect: Expect) {
385 let (analysis, position) = fixture::position(ra_fixture);
386 let source_change = analysis
387 .will_rename_file(position.file_id, new_name)
389 .expect("Expect returned a RenameError");
390 expect.assert_debug_eq(&source_change)
393 fn check_prepare(ra_fixture: &str, expect: Expect) {
394 let (analysis, position) = fixture::position(ra_fixture);
395 let result = analysis
396 .prepare_rename(position)
397 .unwrap_or_else(|err| panic!("PrepareRename was cancelled: {err}"));
399 Ok(RangeInfo { range, info: () }) => {
400 let source = analysis.file_text(position.file_id).unwrap();
401 expect.assert_eq(&format!("{range:?}: {}", &source[range]))
403 Err(RenameError(err)) => expect.assert_eq(&err),
408 fn test_prepare_rename_namelikes() {
409 check_prepare(r"fn name$0<'lifetime>() {}", expect![[r#"3..7: name"#]]);
410 check_prepare(r"fn name<'lifetime$0>() {}", expect![[r#"8..17: 'lifetime"#]]);
411 check_prepare(r"fn name<'lifetime>() { name$0(); }", expect![[r#"23..27: name"#]]);
415 fn test_prepare_rename_in_macro() {
423 expect![[r#"83..86: Foo"#]],
428 fn test_prepare_rename_keyword() {
429 check_prepare(r"struct$0 Foo;", expect![[r#"No references found at position"#]]);
433 fn test_prepare_rename_tuple_field() {
443 expect![[r#"No references found at position"#]],
448 fn test_prepare_rename_builtin() {
455 expect![[r#"No references found at position"#]],
460 fn test_prepare_rename_self() {
466 fn foo(self) -> Self$0 {
471 expect![[r#"No references found at position"#]],
476 fn test_rename_to_underscore() {
477 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
481 fn test_rename_to_raw_identifier() {
482 check("r#fn", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
486 fn test_rename_to_invalid_identifier1() {
489 r#"fn main() { let i$0 = 1; }"#,
490 "error: Invalid name `invalid!`: not an identifier",
495 fn test_rename_to_invalid_identifier2() {
498 r#"fn main() { let i$0 = 1; }"#,
499 "error: Invalid name `multiple tokens`: not an identifier",
504 fn test_rename_to_invalid_identifier3() {
507 r#"fn main() { let i$0 = 1; }"#,
508 "error: Invalid name `let`: not an identifier",
513 fn test_rename_to_invalid_identifier_lifetime() {
514 cov_mark::check!(rename_not_an_ident_ref);
517 r#"fn main() { let i$0 = 1; }"#,
518 "error: Invalid name `'foo`: not an identifier",
523 fn test_rename_to_invalid_identifier_lifetime2() {
524 cov_mark::check!(rename_not_a_lifetime_ident_ref);
527 r#"fn main<'a>(_: &'a$0 ()) {}"#,
528 "error: Invalid name `foo`: not a lifetime identifier",
533 fn test_rename_to_underscore_invalid() {
534 cov_mark::check!(rename_underscore_multiple);
537 r#"fn main(foo$0: ()) {foo;}"#,
538 "error: Cannot rename reference to `_` as it is being referenced multiple times",
543 fn test_rename_mod_invalid() {
547 "error: Invalid name `'foo`: cannot rename module to 'foo",
552 fn test_rename_for_local() {
581 fn test_rename_unresolved_reference() {
584 r#"fn main() { let _ = unresolved_ref$0; }"#,
585 "error: No references found at position",
590 fn test_rename_macro_multiple_occurrences() {
593 r#"macro_rules! foo {
595 const $ident: () = ();
602 const _: Foo = Foo {};
607 const $ident: () = ();
614 const _: Baaah = Baaah {};
620 fn test_rename_for_macro_args() {
624 macro_rules! foo {($i:ident) => {$i} }
631 macro_rules! foo {($i:ident) => {$i} }
641 fn test_rename_for_macro_args_rev() {
645 macro_rules! foo {($i:ident) => {$i} }
652 macro_rules! foo {($i:ident) => {$i} }
662 fn test_rename_for_macro_define_fn() {
666 macro_rules! define_fn {($id:ident) => { fn $id{} }}
673 macro_rules! define_fn {($id:ident) => { fn $id{} }}
683 fn test_rename_for_macro_define_fn_rev() {
687 macro_rules! define_fn {($id:ident) => { fn $id{} }}
694 macro_rules! define_fn {($id:ident) => { fn $id{} }}
704 fn test_rename_for_param_inside() {
705 check("j", r#"fn foo(i : u32) -> u32 { i$0 }"#, r#"fn foo(j : u32) -> u32 { j }"#);
709 fn test_rename_refs_for_fn_param() {
710 check("j", r#"fn foo(i$0 : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
714 fn test_rename_for_mut_param() {
715 check("j", r#"fn foo(mut i$0 : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
719 fn test_rename_struct_field() {
723 struct Foo { field$0: i32 }
726 fn new(i: i32) -> Self {
732 struct Foo { foo: i32 }
735 fn new(i: i32) -> Self {
744 fn test_rename_field_in_field_shorthand() {
745 cov_mark::check!(test_rename_field_in_field_shorthand);
749 struct Foo { foo$0: i32 }
752 fn new(foo: i32) -> Self {
758 struct Foo { field: i32 }
761 fn new(foo: i32) -> Self {
770 fn test_rename_local_in_field_shorthand() {
771 cov_mark::check!(test_rename_local_in_field_shorthand);
775 struct Foo { i: i32 }
778 fn new(i$0: i32) -> Self {
784 struct Foo { i: i32 }
787 fn new(j: i32) -> Self {
796 fn test_field_shorthand_correct_struct() {
800 struct Foo { i$0: i32 }
801 struct Bar { i: i32 }
804 fn new(i: i32) -> Self {
810 struct Foo { j: i32 }
811 struct Bar { i: i32 }
814 fn new(i: i32) -> Self {
823 fn test_shadow_local_for_struct_shorthand() {
827 struct Foo { i: i32 }
829 fn baz(i$0: i32) -> Self {
838 struct Foo { i: i32 }
840 fn baz(j: i32) -> Self {
841 let x = Foo { i: j };
852 fn test_rename_mod() {
884 dst: AnchoredPathBuf {
899 fn test_rename_mod_in_use_tree() {
909 pub struct FooContent;
912 use crate::foo$0::FooContent;
943 dst: AnchoredPathBuf {
958 fn test_rename_mod_in_dir() {
983 src: AnchoredPathBuf {
992 dst: AnchoredPathBuf {
1007 fn test_rename_unusually_nested_mod() {
1012 mod outer { mod fo$0o; }
1019 source_file_edits: {
1031 file_system_edits: [
1036 dst: AnchoredPathBuf {
1051 fn test_module_rename_in_path() {
1056 pub use self::bar as qux;
1060 fn main() { foo::bar(); }
1064 pub use self::bar as qux;
1068 fn main() { baz::bar(); }
1074 fn test_rename_mod_filename_and_path() {
1092 source_file_edits: {
1114 file_system_edits: [
1119 dst: AnchoredPathBuf {
1134 fn test_rename_mod_recursive() {
1151 //- /foo/bar/qux/quux/mod.rs
1159 source_file_edits: {
1171 file_system_edits: [
1176 dst: AnchoredPathBuf {
1184 src: AnchoredPathBuf {
1193 dst: AnchoredPathBuf {
1207 fn test_rename_mod_ref_by_super() {
1232 fn test_rename_mod_in_macro() {
1239 macro_rules! submodule {
1248 macro_rules! submodule {
1260 fn test_rename_mod_for_crate_root() {
1261 check_expect_will_rename_file(
1265 use crate::foo as bar;
1271 source_file_edits: {},
1272 file_system_edits: [],
1280 fn test_enum_variant_from_module_1() {
1281 cov_mark::check!(rename_non_local);
1286 pub enum Foo { Bar$0 }
1289 fn func(f: foo::Foo) {
1297 pub enum Foo { Baz }
1300 fn func(f: foo::Foo) {
1310 fn test_enum_variant_from_module_2() {
1315 pub struct Foo { pub bar$0: uint }
1318 fn foo(f: foo::Foo) {
1324 pub struct Foo { pub baz: uint }
1327 fn foo(f: foo::Foo) {
1335 fn test_parameter_to_self() {
1336 cov_mark::check!(rename_to_self);
1340 struct Foo { i: i32 }
1343 fn f(foo$0: &mut Foo) -> i32 {
1349 struct Foo { i: i32 }
1352 fn f(&mut self) -> i32 {
1361 struct Foo { i: i32 }
1364 fn f(foo$0: Foo) -> i32 {
1370 struct Foo { i: i32 }
1382 fn test_parameter_to_self_error_no_impl() {
1386 struct Foo { i: i32 }
1388 fn f(foo$0: &mut Foo) -> i32 {
1392 "error: Cannot rename parameter to self for free function",
1397 struct Foo { i: i32 }
1401 fn f(foo$0: &mut Foo) -> i32 {
1406 "error: Parameter type differs from impl block type",
1411 fn test_parameter_to_self_error_not_first() {
1415 struct Foo { i: i32 }
1417 fn f(x: (), foo$0: &mut Foo) -> i32 {
1422 "error: Only the first parameter may be renamed to self",
1427 fn test_parameter_to_self_impl_ref() {
1431 struct Foo { i: i32 }
1433 fn f(foo$0: &Foo) -> i32 {
1439 struct Foo { i: i32 }
1450 fn test_self_to_parameter() {
1454 struct Foo { i: i32 }
1457 fn f(&mut $0self) -> i32 {
1463 struct Foo { i: i32 }
1466 fn f(foo: &mut Foo) -> i32 {
1475 fn test_owned_self_to_parameter() {
1476 cov_mark::check!(rename_self_to_param);
1480 struct Foo { i: i32 }
1483 fn f($0self) -> i32 {
1489 struct Foo { i: i32 }
1492 fn f(foo: Foo) -> i32 {
1501 fn test_self_in_path_to_parameter() {
1505 struct Foo { i: i32 }
1508 fn f(&self) -> i32 {
1515 struct Foo { i: i32 }
1518 fn f(foo: &Foo) -> i32 {
1528 fn test_rename_field_put_init_shorthand() {
1529 cov_mark::check!(test_rename_field_put_init_shorthand);
1533 struct Foo { i$0: i32 }
1535 fn foo(bar: i32) -> Foo {
1540 struct Foo { bar: i32 }
1542 fn foo(bar: i32) -> Foo {
1550 fn test_rename_local_put_init_shorthand() {
1551 cov_mark::check!(test_rename_local_put_init_shorthand);
1555 struct Foo { i: i32 }
1557 fn foo(bar$0: i32) -> Foo {
1562 struct Foo { i: i32 }
1564 fn foo(i: i32) -> Foo {
1572 fn test_struct_field_pat_into_shorthand() {
1573 cov_mark::check!(test_rename_field_put_init_shorthand_pat);
1577 struct Foo { i$0: i32 }
1580 let Foo { i: ref baz @ qux } = foo;
1585 struct Foo { baz: i32 }
1588 let Foo { baz: ref baz @ qux } = foo;
1596 struct Foo { i$0: i32 }
1599 let Foo { i: ref baz } = foo;
1604 struct Foo { baz: i32 }
1607 let Foo { ref baz } = foo;
1615 fn test_struct_local_pat_into_shorthand() {
1616 cov_mark::check!(test_rename_local_put_init_shorthand_pat);
1620 struct Foo { field: i32 }
1623 let Foo { field: qux$0 } = foo;
1628 struct Foo { field: i32 }
1631 let Foo { field } = foo;
1639 struct Foo { field: i32 }
1642 let Foo { field: x @ qux$0 } = foo;
1647 struct Foo { field: i32 }
1650 let Foo { field: x @ field } = foo;
1658 fn test_rename_binding_in_destructure_pat() {
1659 let expected_fixture = r#"
1665 let Foo { i: bar } = foo;
1677 let Foo { i: b } = foo;
1691 let Foo { i } = foo;
1700 fn test_rename_binding_in_destructure_param_pat() {
1708 fn foo(Foo { i }: Foo) -> i32 {
1717 fn foo(Foo { i: bar }: Foo) -> i32 {
1725 fn test_struct_field_complex_ident_pat() {
1726 cov_mark::check!(rename_record_pat_field_name_split);
1730 struct Foo { i$0: i32 }
1733 let Foo { ref i } = foo;
1737 struct Foo { baz: i32 }
1740 let Foo { baz: ref i } = foo;
1747 fn test_rename_lifetimes() {
1748 cov_mark::check!(rename_lifetime);
1755 impl<'a> Foo<'a> for &'a () {
1756 fn foo() -> &'a$0 () {
1765 impl<'yeeee> Foo<'yeeee> for &'yeeee () {
1766 fn foo() -> &'yeeee () {
1775 fn test_rename_bind_pat() {
1780 enum CustomOption<T> {
1785 let test_variable = CustomOption::Some(22);
1787 match test_variable {
1788 CustomOption::Some(foo$0) if foo == 11 => {}
1794 enum CustomOption<T> {
1799 let test_variable = CustomOption::Some(22);
1801 match test_variable {
1802 CustomOption::Some(new_name) if new_name == 11 => {}
1810 fn test_rename_label() {
1814 fn foo<'a>() -> &'a () {
1823 fn foo<'a>() -> &'a () {
1835 fn test_self_to_self() {
1836 cov_mark::check!(rename_self_to_self);
1855 fn test_rename_field_in_pat_in_macro_doesnt_shorthand() {
1856 // ideally we would be able to make this emit a short hand, but I doubt this is easily possible
1862 let $pattern = loop {};
1869 foo!(Foo { bar: baz });
1875 let $pattern = loop {};
1882 foo!(Foo { baz: baz });
1889 fn test_rename_tuple_field() {
1900 "error: No identifier available to rename",
1905 fn test_rename_builtin() {
1913 "error: Cannot rename builtin type",
1918 fn test_rename_self() {
1925 fn foo(self) -> Self$0 {
1930 "error: Cannot rename `Self`",
1935 fn test_rename_ignores_self_ty() {
1941 impl Foo where Self: {}
1946 impl Fo0 where Self: {}
1952 fn test_rename_fails_on_aliases() {
1959 "error: Renaming aliases is currently unsupported",
1968 "error: Renaming aliases is currently unsupported",
1973 fn test_rename_trait_method() {
2053 fn test_rename_trait_method_prefix_of_second() {
2072 fn test_rename_trait_const() {
2081 fn f() { <()>::FOO; }";
2092 fn f() { <()>::BAR; }"#,
2105 fn f() { <()>::BAR; }"#,
2118 fn f() { <()>::BAR$0; }"#,
2124 fn defs_from_macros_arent_renamed() {
2128 macro_rules! m { () => { fn f() {} } }
2132 "error: No identifier available to rename",
2137 fn attributed_item() {
2141 //- proc_macros: identity
2143 #[proc_macros::identity]
2150 #[proc_macros::identity]
2159 fn in_macro_multi_mapping() {
2164 macro_rules! match_ast2 {
2168 $( if $node { $res } else )*
2183 macro_rules! match_ast2 {
2187 $( if $node { $res } else )*
2204 fn rename_multi_local() {
2208 fn foo((foo$0 | foo | foo): ()) {
2214 fn foo((bar | bar | bar): ()) {
2223 fn foo((foo | foo$0 | foo): ()) {
2229 fn foo((bar | bar | bar): ()) {
2238 fn foo((foo | foo | foo): ()) {
2244 fn foo((bar | bar | bar): ()) {
2253 fn regression_13498() {
2261 use foo::Test as Tester;
2272 use foo::Testing as Tester;