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};
21 use text_edit::TextEdit;
23 use crate::{FilePosition, RangeInfo, SourceChange};
25 pub use ide_db::rename::RenameError;
27 type RenameResult<T> = Result<T, RenameError>;
29 /// Prepares a rename. The sole job of this function is to return the TextRange of the thing that is
30 /// being targeted for a rename.
31 pub(crate) fn prepare_rename(
33 position: FilePosition,
34 ) -> RenameResult<RangeInfo<()>> {
35 let sema = Semantics::new(db);
36 let source_file = sema.parse(position.file_id);
37 let syntax = source_file.syntax();
39 let mut defs = find_definitions(&sema, syntax, position)?;
42 // - empty case possible or already caught by `find_definitions`?
43 // - is "just take the first" correct? If not, what do?
44 let (name_like, _def) = defs.next().unwrap();
45 let frange = sema.original_range(name_like.syntax());
46 always!(frange.range.contains_inclusive(position.offset) && frange.file_id == position.file_id);
47 Ok(RangeInfo::new(frange.range, ()))
52 // Renames the item below the cursor and all of its references
55 // | Editor | Shortcut
57 // | VS Code | kbd:[F2]
60 // image::https://user-images.githubusercontent.com/48062697/113065582-055aae80-91b1-11eb-8ade-2b58e6d81883.gif[]
63 position: FilePosition,
65 ) -> RenameResult<SourceChange> {
66 let sema = Semantics::new(db);
67 let source_file = sema.parse(position.file_id);
68 let syntax = source_file.syntax();
70 let defs = find_definitions(&sema, syntax, position)?;
72 let ops: RenameResult<Vec<SourceChange>> = defs
73 .map(|(_namelike, def)| {
74 if let Definition::Local(local) = def {
75 if let Some(self_param) = local.as_self_param(sema.db) {
76 cov_mark::hit!(rename_self_to_param);
77 return rename_self_to_param(&sema, local, self_param, new_name);
79 if new_name == "self" {
80 cov_mark::hit!(rename_to_self);
81 return rename_to_self(&sema, local);
84 def.rename(&sema, new_name)
88 .reduce(|acc, elem| acc.merge(elem))
89 .ok_or_else(|| format_err!("No references found at position"))
92 /// Called by the client when it is about to rename a file.
93 pub(crate) fn will_rename_file(
97 ) -> Option<SourceChange> {
98 let sema = Semantics::new(db);
99 let module = sema.to_module_def(file_id)?;
100 let def = Definition::ModuleDef(module.into());
101 let mut change = def.rename(&sema, new_name_stem).ok()?;
102 change.file_system_edits.clear();
107 sema: &Semantics<RootDatabase>,
109 position: FilePosition,
110 ) -> RenameResult<impl Iterator<Item = (ast::NameLike, Definition)>> {
112 .find_nodes_at_offset_with_descend::<ast::NameLike>(syntax, position.offset)
114 let res = match &name_like {
115 // renaming aliases would rename the item being aliased as the HIR doesn't track aliases yet
116 ast::NameLike::Name(name)
120 .map_or(false, |it| ast::Rename::can_cast(it.kind())) =>
122 bail!("Renaming aliases is currently unsupported")
124 ast::NameLike::Name(name) => NameClass::classify(sema, name)
125 .map(|class| match class {
126 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
127 NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
128 Definition::Local(local_def)
131 .map(|def| (name_like.clone(), def))
132 .ok_or_else(|| format_err!("No references found at position")),
133 ast::NameLike::NameRef(name_ref) => NameRefClass::classify(sema, name_ref)
134 .map(|class| match class {
135 NameRefClass::Definition(def) => def,
136 NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
137 Definition::Local(local_ref)
141 // if the name differs from the definitions name it has to be an alias
142 if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) {
145 Some((name_like.clone(), def))
148 .ok_or_else(|| format_err!("Renaming aliases is currently unsupported")),
149 ast::NameLike::Lifetime(lifetime) => {
150 NameRefClass::classify_lifetime(sema, lifetime)
151 .and_then(|class| match class {
152 NameRefClass::Definition(def) => Some(def),
156 NameClass::classify_lifetime(sema, lifetime).and_then(|it| match it {
157 NameClass::Definition(it) => Some(it),
161 .map(|def| (name_like, def))
162 .ok_or_else(|| format_err!("No references found at position"))
168 // TODO avoid collect() somehow?
169 let v: RenameResult<Vec<(ast::NameLike, Definition)>> = symbols.collect();
172 // TODO is "unique by `Definition`" correct?
173 Ok(v) => Ok(v.into_iter().unique_by(|t| t.1)),
178 fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameResult<SourceChange> {
179 if never!(local.is_self(sema.db)) {
180 bail!("rename_to_self invoked on self");
183 let fn_def = match local.parent(sema.db) {
184 hir::DefWithBody::Function(func) => func,
185 _ => bail!("Cannot rename local to self outside of function"),
188 if fn_def.self_param(sema.db).is_some() {
189 bail!("Method already has a self parameter");
192 let params = fn_def.assoc_fn_params(sema.db);
193 let first_param = params
195 .ok_or_else(|| format_err!("Cannot rename local to self unless it is a parameter"))?;
196 if first_param.as_local(sema.db) != local {
197 bail!("Only the first parameter may be renamed to self");
200 let assoc_item = fn_def
201 .as_assoc_item(sema.db)
202 .ok_or_else(|| format_err!("Cannot rename parameter to self for free function"))?;
203 let impl_ = match assoc_item.container(sema.db) {
204 hir::AssocItemContainer::Trait(_) => {
205 bail!("Cannot rename parameter to self for trait functions");
207 hir::AssocItemContainer::Impl(impl_) => impl_,
209 let first_param_ty = first_param.ty();
210 let impl_ty = impl_.self_ty(sema.db);
211 let (ty, self_param) = if impl_ty.remove_ref().is_some() {
212 // if the impl is a ref to the type we can just match the `&T` with self directly
213 (first_param_ty.clone(), "self")
215 first_param_ty.remove_ref().map_or((first_param_ty.clone(), "self"), |ty| {
216 (ty, if first_param_ty.is_mutable_reference() { "&mut self" } else { "&self" })
221 bail!("Parameter type differs from impl block type");
224 let InFile { file_id, value: param_source } =
225 first_param.source(sema.db).ok_or_else(|| format_err!("No source for parameter found"))?;
227 let def = Definition::Local(local);
228 let usages = def.usages(sema).all();
229 let mut source_change = SourceChange::default();
230 source_change.extend(usages.iter().map(|(&file_id, references)| {
231 (file_id, source_edit_from_references(references, def, "self"))
233 source_change.insert_source_edit(
234 file_id.original_file(sema.db),
235 TextEdit::replace(param_source.syntax().text_range(), String::from(self_param)),
240 fn rename_self_to_param(
241 sema: &Semantics<RootDatabase>,
243 self_param: hir::SelfParam,
245 ) -> RenameResult<SourceChange> {
246 if new_name == "self" {
247 // Let's do nothing rather than complain.
248 cov_mark::hit!(rename_self_to_self);
249 return Ok(SourceChange::default());
252 let identifier_kind = IdentifierKind::classify(new_name)?;
254 let InFile { file_id, value: self_param } =
255 self_param.source(sema.db).ok_or_else(|| format_err!("cannot find function source"))?;
257 let def = Definition::Local(local);
258 let usages = def.usages(sema).all();
259 let edit = text_edit_from_self_param(&self_param, new_name)
260 .ok_or_else(|| format_err!("No target type found"))?;
261 if usages.len() > 1 && identifier_kind == IdentifierKind::Underscore {
262 bail!("Cannot rename reference to `_` as it is being referenced multiple times");
264 let mut source_change = SourceChange::default();
265 source_change.insert_source_edit(file_id.original_file(sema.db), edit);
266 source_change.extend(usages.iter().map(|(&file_id, references)| {
267 (file_id, source_edit_from_references(references, def, new_name))
272 fn text_edit_from_self_param(self_param: &ast::SelfParam, new_name: &str) -> Option<TextEdit> {
273 fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
274 if let Some(ast::Type::PathType(p)) = impl_def.self_ty() {
275 return Some(p.path()?.segment()?.name_ref()?.text().to_string());
280 let impl_def = self_param.syntax().ancestors().find_map(ast::Impl::cast)?;
281 let type_name = target_type_name(&impl_def)?;
283 let mut replacement_text = String::from(new_name);
284 replacement_text.push_str(": ");
285 match (self_param.amp_token(), self_param.mut_token()) {
286 (Some(_), None) => replacement_text.push('&'),
287 (Some(_), Some(_)) => replacement_text.push_str("&mut "),
290 replacement_text.push_str(type_name.as_str());
292 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
297 use expect_test::{expect, Expect};
298 use stdx::trim_indent;
299 use test_utils::assert_eq_text;
300 use text_edit::TextEdit;
302 use crate::{fixture, FileId};
304 use super::{RangeInfo, RenameError};
307 fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
308 let ra_fixture_after = &trim_indent(ra_fixture_after);
309 let (analysis, position) = fixture::position(ra_fixture_before);
310 let rename_result = analysis
311 .rename(position, new_name)
312 .unwrap_or_else(|err| panic!("Rename to '{}' was cancelled: {}", new_name, err));
313 match rename_result {
314 Ok(source_change) => {
315 let mut text_edit_builder = TextEdit::builder();
316 let mut file_id: Option<FileId> = None;
317 for edit in source_change.source_file_edits {
318 file_id = Some(edit.0);
319 for indel in edit.1.into_iter() {
320 text_edit_builder.replace(indel.delete, indel.insert);
323 if let Some(file_id) = file_id {
324 let mut result = analysis.file_text(file_id).unwrap().to_string();
325 text_edit_builder.finish().apply(&mut result);
326 assert_eq_text!(ra_fixture_after, &*result);
330 if ra_fixture_after.starts_with("error:") {
331 let error_message = ra_fixture_after
334 .skip("error:".len())
335 .collect::<String>();
336 assert_eq!(error_message.trim(), err.to_string());
338 panic!("Rename to '{}' failed unexpectedly: {}", new_name, err)
344 fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
345 let (analysis, position) = fixture::position(ra_fixture);
347 analysis.rename(position, new_name).unwrap().expect("Expect returned a RenameError");
348 expect.assert_debug_eq(&source_change)
351 fn check_prepare(ra_fixture: &str, expect: Expect) {
352 let (analysis, position) = fixture::position(ra_fixture);
353 let result = analysis
354 .prepare_rename(position)
355 .unwrap_or_else(|err| panic!("PrepareRename was cancelled: {}", err));
357 Ok(RangeInfo { range, info: () }) => {
358 let source = analysis.file_text(position.file_id).unwrap();
359 expect.assert_eq(&format!("{:?}: {}", range, &source[range]))
361 Err(RenameError(err)) => expect.assert_eq(&err),
366 fn test_prepare_rename_namelikes() {
367 check_prepare(r"fn name$0<'lifetime>() {}", expect![[r#"3..7: name"#]]);
368 check_prepare(r"fn name<'lifetime$0>() {}", expect![[r#"8..17: 'lifetime"#]]);
369 check_prepare(r"fn name<'lifetime>() { name$0(); }", expect![[r#"23..27: name"#]]);
373 fn test_prepare_rename_in_macro() {
381 expect![[r#"83..86: Foo"#]],
386 fn test_prepare_rename_keyword() {
387 check_prepare(r"struct$0 Foo;", expect![[r#"No references found at position"#]]);
391 fn test_prepare_rename_tuple_field() {
401 expect![[r#"No references found at position"#]],
406 fn test_prepare_rename_builtin() {
413 expect![[r#"No references found at position"#]],
418 fn test_prepare_rename_self() {
424 fn foo(self) -> Self$0 {
429 expect![[r#"No references found at position"#]],
434 fn test_rename_to_underscore() {
435 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
439 fn test_rename_to_raw_identifier() {
440 check("r#fn", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
444 fn test_rename_to_invalid_identifier1() {
447 r#"fn main() { let i$0 = 1; }"#,
448 "error: Invalid name `invalid!`: not an identifier",
453 fn test_rename_to_invalid_identifier2() {
456 r#"fn main() { let i$0 = 1; }"#,
457 "error: Invalid name `multiple tokens`: not an identifier",
462 fn test_rename_to_invalid_identifier3() {
465 r#"fn main() { let i$0 = 1; }"#,
466 "error: Invalid name `let`: not an identifier",
471 fn test_rename_to_invalid_identifier_lifetime() {
472 cov_mark::check!(rename_not_an_ident_ref);
475 r#"fn main() { let i$0 = 1; }"#,
476 "error: Invalid name `'foo`: not an identifier",
481 fn test_rename_to_invalid_identifier_lifetime2() {
482 cov_mark::check!(rename_not_a_lifetime_ident_ref);
485 r#"fn main<'a>(_: &'a$0 ()) {}"#,
486 "error: Invalid name `foo`: not a lifetime identifier",
491 fn test_rename_to_underscore_invalid() {
492 cov_mark::check!(rename_underscore_multiple);
495 r#"fn main(foo$0: ()) {foo;}"#,
496 "error: Cannot rename reference to `_` as it is being referenced multiple times",
501 fn test_rename_mod_invalid() {
505 "error: Invalid name `'foo`: cannot rename module to 'foo",
510 fn test_rename_for_local() {
539 fn test_rename_unresolved_reference() {
542 r#"fn main() { let _ = unresolved_ref$0; }"#,
543 "error: No references found at position",
548 fn test_rename_for_macro_args() {
552 macro_rules! foo {($i:ident) => {$i} }
559 macro_rules! foo {($i:ident) => {$i} }
569 fn test_rename_for_macro_args_rev() {
573 macro_rules! foo {($i:ident) => {$i} }
580 macro_rules! foo {($i:ident) => {$i} }
590 fn test_rename_for_macro_define_fn() {
594 macro_rules! define_fn {($id:ident) => { fn $id{} }}
601 macro_rules! define_fn {($id:ident) => { fn $id{} }}
611 fn test_rename_for_macro_define_fn_rev() {
615 macro_rules! define_fn {($id:ident) => { fn $id{} }}
622 macro_rules! define_fn {($id:ident) => { fn $id{} }}
632 fn test_rename_for_param_inside() {
633 check("j", r#"fn foo(i : u32) -> u32 { i$0 }"#, r#"fn foo(j : u32) -> u32 { j }"#);
637 fn test_rename_refs_for_fn_param() {
638 check("j", r#"fn foo(i$0 : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
642 fn test_rename_for_mut_param() {
643 check("j", r#"fn foo(mut i$0 : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
647 fn test_rename_struct_field() {
651 struct Foo { field$0: i32 }
654 fn new(i: i32) -> Self {
660 struct Foo { foo: i32 }
663 fn new(i: i32) -> Self {
672 fn test_rename_field_in_field_shorthand() {
673 cov_mark::check!(test_rename_field_in_field_shorthand);
677 struct Foo { foo$0: i32 }
680 fn new(foo: i32) -> Self {
686 struct Foo { field: i32 }
689 fn new(foo: i32) -> Self {
698 fn test_rename_local_in_field_shorthand() {
699 cov_mark::check!(test_rename_local_in_field_shorthand);
703 struct Foo { i: i32 }
706 fn new(i$0: i32) -> Self {
712 struct Foo { i: i32 }
715 fn new(j: i32) -> Self {
724 fn test_field_shorthand_correct_struct() {
728 struct Foo { i$0: i32 }
729 struct Bar { i: i32 }
732 fn new(i: i32) -> Self {
738 struct Foo { j: i32 }
739 struct Bar { i: i32 }
742 fn new(i: i32) -> Self {
751 fn test_shadow_local_for_struct_shorthand() {
755 struct Foo { i: i32 }
757 fn baz(i$0: i32) -> Self {
766 struct Foo { i: i32 }
768 fn baz(j: i32) -> Self {
769 let x = Foo { i: j };
780 fn test_rename_mod() {
812 dst: AnchoredPathBuf {
827 fn test_rename_mod_in_use_tree() {
837 pub struct FooContent;
840 use crate::foo$0::FooContent;
871 dst: AnchoredPathBuf {
886 fn test_rename_mod_in_dir() {
914 dst: AnchoredPathBuf {
918 path: "../foo2/mod.rs",
929 fn test_rename_unusually_nested_mod() {
934 mod outer { mod fo$0o; }
958 dst: AnchoredPathBuf {
973 fn test_module_rename_in_path() {
978 pub use self::bar as qux;
982 fn main() { foo::bar(); }
986 pub use self::bar as qux;
990 fn main() { baz::bar(); }
996 fn test_rename_mod_filename_and_path() {
1014 source_file_edits: {
1036 file_system_edits: [
1041 dst: AnchoredPathBuf {
1056 fn test_enum_variant_from_module_1() {
1057 cov_mark::check!(rename_non_local);
1062 pub enum Foo { Bar$0 }
1065 fn func(f: foo::Foo) {
1073 pub enum Foo { Baz }
1076 fn func(f: foo::Foo) {
1086 fn test_enum_variant_from_module_2() {
1091 pub struct Foo { pub bar$0: uint }
1094 fn foo(f: foo::Foo) {
1100 pub struct Foo { pub baz: uint }
1103 fn foo(f: foo::Foo) {
1111 fn test_parameter_to_self() {
1112 cov_mark::check!(rename_to_self);
1116 struct Foo { i: i32 }
1119 fn f(foo$0: &mut Foo) -> i32 {
1125 struct Foo { i: i32 }
1128 fn f(&mut self) -> i32 {
1137 struct Foo { i: i32 }
1140 fn f(foo$0: Foo) -> i32 {
1146 struct Foo { i: i32 }
1158 fn test_parameter_to_self_error_no_impl() {
1162 struct Foo { i: i32 }
1164 fn f(foo$0: &mut Foo) -> i32 {
1168 "error: Cannot rename parameter to self for free function",
1173 struct Foo { i: i32 }
1177 fn f(foo$0: &mut Foo) -> i32 {
1182 "error: Parameter type differs from impl block type",
1187 fn test_parameter_to_self_error_not_first() {
1191 struct Foo { i: i32 }
1193 fn f(x: (), foo$0: &mut Foo) -> i32 {
1198 "error: Only the first parameter may be renamed to self",
1203 fn test_parameter_to_self_impl_ref() {
1207 struct Foo { i: i32 }
1209 fn f(foo$0: &Foo) -> i32 {
1215 struct Foo { i: i32 }
1226 fn test_self_to_parameter() {
1230 struct Foo { i: i32 }
1233 fn f(&mut $0self) -> i32 {
1239 struct Foo { i: i32 }
1242 fn f(foo: &mut Foo) -> i32 {
1251 fn test_owned_self_to_parameter() {
1252 cov_mark::check!(rename_self_to_param);
1256 struct Foo { i: i32 }
1259 fn f($0self) -> i32 {
1265 struct Foo { i: i32 }
1268 fn f(foo: Foo) -> i32 {
1277 fn test_self_in_path_to_parameter() {
1281 struct Foo { i: i32 }
1284 fn f(&self) -> i32 {
1291 struct Foo { i: i32 }
1294 fn f(foo: &Foo) -> i32 {
1304 fn test_rename_field_put_init_shorthand() {
1305 cov_mark::check!(test_rename_field_put_init_shorthand);
1309 struct Foo { i$0: i32 }
1311 fn foo(bar: i32) -> Foo {
1316 struct Foo { bar: i32 }
1318 fn foo(bar: i32) -> Foo {
1326 fn test_rename_local_put_init_shorthand() {
1327 cov_mark::check!(test_rename_local_put_init_shorthand);
1331 struct Foo { i: i32 }
1333 fn foo(bar$0: i32) -> Foo {
1338 struct Foo { i: i32 }
1340 fn foo(i: i32) -> Foo {
1348 fn test_struct_field_pat_into_shorthand() {
1349 cov_mark::check!(test_rename_field_put_init_shorthand_pat);
1353 struct Foo { i$0: i32 }
1356 let Foo { i: ref baz @ qux } = foo;
1361 struct Foo { baz: i32 }
1364 let Foo { baz: ref baz @ qux } = foo;
1372 struct Foo { i$0: i32 }
1375 let Foo { i: ref baz } = foo;
1380 struct Foo { baz: i32 }
1383 let Foo { ref baz } = foo;
1391 fn test_struct_local_pat_into_shorthand() {
1392 cov_mark::check!(test_rename_local_put_init_shorthand_pat);
1396 struct Foo { field: i32 }
1399 let Foo { field: qux$0 } = foo;
1404 struct Foo { field: i32 }
1407 let Foo { field } = foo;
1415 struct Foo { field: i32 }
1418 let Foo { field: x @ qux$0 } = foo;
1423 struct Foo { field: i32 }
1426 let Foo { field: x @ field } = foo;
1434 fn test_rename_binding_in_destructure_pat() {
1435 let expected_fixture = r#"
1441 let Foo { i: bar } = foo;
1453 let Foo { i: b } = foo;
1467 let Foo { i } = foo;
1476 fn test_rename_binding_in_destructure_param_pat() {
1484 fn foo(Foo { i }: Foo) -> i32 {
1493 fn foo(Foo { i: bar }: Foo) -> i32 {
1501 fn test_struct_field_complex_ident_pat() {
1502 cov_mark::check!(rename_record_pat_field_name_split);
1506 struct Foo { i$0: i32 }
1509 let Foo { ref i } = foo;
1513 struct Foo { baz: i32 }
1516 let Foo { baz: ref i } = foo;
1523 fn test_rename_lifetimes() {
1524 cov_mark::check!(rename_lifetime);
1531 impl<'a> Foo<'a> for &'a () {
1532 fn foo() -> &'a$0 () {
1541 impl<'yeeee> Foo<'yeeee> for &'yeeee () {
1542 fn foo() -> &'yeeee () {
1551 fn test_rename_bind_pat() {
1556 enum CustomOption<T> {
1561 let test_variable = CustomOption::Some(22);
1563 match test_variable {
1564 CustomOption::Some(foo$0) if foo == 11 => {}
1570 enum CustomOption<T> {
1575 let test_variable = CustomOption::Some(22);
1577 match test_variable {
1578 CustomOption::Some(new_name) if new_name == 11 => {}
1586 fn test_rename_label() {
1590 fn foo<'a>() -> &'a () {
1599 fn foo<'a>() -> &'a () {
1611 fn test_self_to_self() {
1612 cov_mark::check!(rename_self_to_self);
1631 fn test_rename_field_in_pat_in_macro_doesnt_shorthand() {
1632 // ideally we would be able to make this emit a short hand, but I doubt this is easily possible
1638 let $pattern = loop {};
1645 foo!(Foo { bar: baz });
1651 let $pattern = loop {};
1658 foo!(Foo { baz: baz });
1665 fn test_rename_tuple_field() {
1676 "error: No identifier available to rename",
1681 fn test_rename_builtin() {
1689 "error: Cannot rename builtin type",
1694 fn test_rename_self() {
1701 fn foo(self) -> Self$0 {
1706 "error: Cannot rename `Self`",
1711 fn test_rename_ignores_self_ty() {
1717 impl Foo where Self: {}
1722 impl Fo0 where Self: {}
1728 fn test_rename_fails_on_aliases() {
1735 "error: Renaming aliases is currently unsupported",
1744 "error: Renaming aliases is currently unsupported",
1749 fn test_rename_trait_method() {
1829 fn test_rename_trait_method_prefix_of_second() {
1848 fn test_rename_trait_const() {
1857 fn f() { <()>::FOO; }";
1868 fn f() { <()>::BAR; }"#,
1881 fn f() { <()>::BAR; }"#,
1894 fn f() { <()>::BAR$0; }"#,
1900 fn defs_from_macros_arent_renamed() {
1904 macro_rules! m { () => { fn f() {} } }
1908 "error: No identifier available to rename",
1913 fn attributed_item() {
1917 //- proc_macros: identity
1919 #[proc_macros::identity]
1926 #[proc_macros::identity]
1935 fn in_macro_multi_mapping() {
1940 macro_rules! match_ast2 {
1944 $( if $node { $res } else )*
1959 macro_rules! match_ast2 {
1963 $( if $node { $res } else )*