1 //! FIXME: write short doc here
8 use hir::{Module, ModuleDef, ModuleSource, Semantics};
9 use ide_db::base_db::{AnchoredPathBuf, FileId, FileRange, SourceDatabaseExt};
11 defs::{Definition, NameClass, NameRefClass},
15 algo::find_node_at_offset,
16 ast::{self, NameOwner},
17 lex_single_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken,
20 use text_edit::TextEdit;
23 references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind,
24 SourceChange, SourceFileEdit, TextRange, TextSize,
28 pub struct RenameError(pub(crate) String);
30 impl fmt::Display for RenameError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 Display::fmt(&self.0, f)
36 impl Error for RenameError {}
38 pub(crate) fn prepare_rename(
40 position: FilePosition,
41 ) -> Result<RangeInfo<()>, RenameError> {
42 let sema = Semantics::new(db);
43 let source_file = sema.parse(position.file_id);
44 let syntax = source_file.syntax();
45 if let Some(module) = find_module_at_offset(&sema, position, syntax) {
46 rename_mod(&sema, position, module, "dummy")
47 } else if let Some(self_token) =
48 syntax.token_at_offset(position.offset).find(|t| t.kind() == SyntaxKind::SELF_KW)
50 rename_self_to_param(&sema, position, self_token, "dummy")
52 let range = match find_all_refs(&sema, position, None) {
53 Some(RangeInfo { range, .. }) => range,
54 None => return Err(RenameError("No references found at position".to_string())),
56 Ok(RangeInfo::new(range, SourceChange::from(vec![])))
58 .map(|info| RangeInfo::new(info.range, ()))
63 position: FilePosition,
65 ) -> Result<RangeInfo<SourceChange>, RenameError> {
66 let sema = Semantics::new(db);
67 rename_with_semantics(&sema, position, new_name)
70 pub(crate) fn rename_with_semantics(
71 sema: &Semantics<RootDatabase>,
72 position: FilePosition,
74 ) -> Result<RangeInfo<SourceChange>, RenameError> {
75 let is_lifetime_name = match lex_single_syntax_kind(new_name) {
76 Some(res) => match res {
77 (SyntaxKind::IDENT, _) => false,
78 (SyntaxKind::UNDERSCORE, _) => false,
79 (SyntaxKind::SELF_KW, _) => return rename_to_self(&sema, position),
80 (SyntaxKind::LIFETIME_IDENT, _) if new_name != "'static" && new_name != "'_" => true,
81 (SyntaxKind::LIFETIME_IDENT, _) => {
82 return Err(RenameError(format!(
83 "Invalid name `{0}`: Cannot rename lifetime to {0}",
87 (_, Some(syntax_error)) => {
88 return Err(RenameError(format!("Invalid name `{}`: {}", new_name, syntax_error)))
91 return Err(RenameError(format!("Invalid name `{}`: not an identifier", new_name)))
94 None => return Err(RenameError(format!("Invalid name `{}`: not an identifier", new_name))),
97 let source_file = sema.parse(position.file_id);
98 let syntax = source_file.syntax();
99 // this is here to prevent lifetime renames from happening on modules and self
100 if is_lifetime_name {
101 rename_reference(&sema, position, new_name, is_lifetime_name)
102 } else if let Some(module) = find_module_at_offset(&sema, position, syntax) {
103 rename_mod(&sema, position, module, new_name)
104 } else if let Some(self_token) =
105 syntax.token_at_offset(position.offset).find(|t| t.kind() == SyntaxKind::SELF_KW)
107 rename_self_to_param(&sema, position, self_token, new_name)
109 rename_reference(&sema, position, new_name, is_lifetime_name)
113 pub(crate) fn will_rename_file(
117 ) -> Option<SourceChange> {
118 let sema = Semantics::new(db);
119 let module = sema.to_module_def(file_id)?;
121 let decl = module.declaration_source(db)?;
122 let range = decl.value.name()?.syntax().text_range();
124 let position = FilePosition { file_id: decl.file_id.original_file(db), offset: range.start() };
125 let mut change = rename_mod(&sema, position, module, new_name_stem).ok()?.info;
126 change.file_system_edits.clear();
130 fn find_module_at_offset(
131 sema: &Semantics<RootDatabase>,
132 position: FilePosition,
134 ) -> Option<Module> {
135 let ident = syntax.token_at_offset(position.offset).find(|t| t.kind() == SyntaxKind::IDENT)?;
137 let module = match_ast! {
138 match (ident.parent()) {
139 ast::NameRef(name_ref) => {
140 match NameRefClass::classify(sema, &name_ref)? {
141 NameRefClass::Definition(Definition::ModuleDef(ModuleDef::Module(module))) => module,
146 match NameClass::classify(&sema, &name)? {
147 NameClass::Definition(Definition::ModuleDef(ModuleDef::Module(module))) => module,
158 fn source_edit_from_reference(
159 sema: &Semantics<RootDatabase>,
160 reference: Reference,
162 ) -> SourceFileEdit {
163 let mut replacement_text = String::new();
164 let range = match reference.kind {
165 ReferenceKind::FieldShorthandForField => {
166 mark::hit!(test_rename_struct_field_for_shorthand);
167 replacement_text.push_str(new_name);
168 replacement_text.push_str(": ");
169 TextRange::new(reference.file_range.range.start(), reference.file_range.range.start())
171 ReferenceKind::FieldShorthandForLocal => {
172 mark::hit!(test_rename_local_for_field_shorthand);
173 replacement_text.push_str(": ");
174 replacement_text.push_str(new_name);
175 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end())
177 ReferenceKind::RecordFieldExprOrPat => {
178 mark::hit!(test_rename_field_expr_pat);
179 replacement_text.push_str(new_name);
180 edit_text_range_for_record_field_expr_or_pat(sema, reference.file_range, new_name)
183 replacement_text.push_str(new_name);
184 reference.file_range.range
188 file_id: reference.file_range.file_id,
189 edit: TextEdit::replace(range, replacement_text),
193 fn edit_text_range_for_record_field_expr_or_pat(
194 sema: &Semantics<RootDatabase>,
195 file_range: FileRange,
198 let source_file = sema.parse(file_range.file_id);
199 let file_syntax = source_file.syntax();
200 let original_range = file_range.range;
202 syntax::algo::find_node_at_range::<ast::RecordExprField>(file_syntax, original_range)
203 .and_then(|field_expr| match field_expr.expr().and_then(|e| e.name_ref()) {
204 Some(name) if &name.to_string() == new_name => Some(field_expr.syntax().text_range()),
208 syntax::algo::find_node_at_range::<ast::RecordPatField>(file_syntax, original_range)
209 .and_then(|field_pat| match field_pat.pat() {
210 Some(ast::Pat::IdentPat(pat))
211 if pat.name().map(|n| n.to_string()).as_deref() == Some(new_name) =>
213 Some(field_pat.syntax().text_range())
218 .unwrap_or(original_range)
222 sema: &Semantics<RootDatabase>,
223 position: FilePosition,
226 ) -> Result<RangeInfo<SourceChange>, RenameError> {
227 let mut source_file_edits = Vec::new();
228 let mut file_system_edits = Vec::new();
230 let src = module.definition_source(sema.db);
231 let file_id = src.file_id.original_file(sema.db);
233 ModuleSource::SourceFile(..) => {
234 // mod is defined in path/to/dir/mod.rs
235 let path = if module.is_mod_rs(sema.db) {
236 format!("../{}/mod.rs", new_name)
238 format!("{}.rs", new_name)
240 let dst = AnchoredPathBuf { anchor: file_id, path };
241 let move_file = FileSystemEdit::MoveFile { src: file_id, dst };
242 file_system_edits.push(move_file);
244 ModuleSource::Module(..) => {}
247 if let Some(src) = module.declaration_source(sema.db) {
248 let file_id = src.file_id.original_file(sema.db);
249 let name = src.value.name().unwrap();
250 let edit = SourceFileEdit {
252 edit: TextEdit::replace(name.syntax().text_range(), new_name.into()),
254 source_file_edits.push(edit);
257 let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)
258 .ok_or_else(|| RenameError("No references found at position".to_string()))?;
262 .map(|reference| source_edit_from_reference(sema, reference, new_name));
263 source_file_edits.extend(ref_edits);
265 Ok(RangeInfo::new(range, SourceChange::from_edits(source_file_edits, file_system_edits)))
269 sema: &Semantics<RootDatabase>,
270 position: FilePosition,
271 ) -> Result<RangeInfo<SourceChange>, RenameError> {
272 let source_file = sema.parse(position.file_id);
273 let syn = source_file.syntax();
275 let (fn_def, fn_ast) = find_node_at_offset::<ast::Fn>(syn, position.offset)
276 .and_then(|fn_ast| sema.to_def(&fn_ast).zip(Some(fn_ast)))
277 .ok_or_else(|| RenameError("No surrounding method declaration found".to_string()))?;
278 let param_range = fn_ast
280 .and_then(|p| p.params().next())
281 .ok_or_else(|| RenameError("Method has no parameters".to_string()))?
284 if !param_range.contains(position.offset) {
285 return Err(RenameError("Only the first parameter can be self".to_string()));
288 let impl_block = find_node_at_offset::<ast::Impl>(syn, position.offset)
289 .and_then(|def| sema.to_def(&def))
290 .ok_or_else(|| RenameError("No impl block found for function".to_string()))?;
291 if fn_def.self_param(sema.db).is_some() {
292 return Err(RenameError("Method already has a self parameter".to_string()));
295 let params = fn_def.assoc_fn_params(sema.db);
297 params.first().ok_or_else(|| RenameError("Method has no parameters".into()))?;
298 let first_param_ty = first_param.ty();
299 let impl_ty = impl_block.target_ty(sema.db);
300 let (ty, self_param) = if impl_ty.remove_ref().is_some() {
301 // if the impl is a ref to the type we can just match the `&T` with self directly
302 (first_param_ty.clone(), "self")
304 first_param_ty.remove_ref().map_or((first_param_ty.clone(), "self"), |ty| {
305 (ty, if first_param_ty.is_mutable_reference() { "&mut self" } else { "&self" })
310 return Err(RenameError("Parameter type differs from impl block type".to_string()));
313 let RangeInfo { range, info: refs } = find_all_refs(sema, position, None)
314 .ok_or_else(|| RenameError("No reference found at position".to_string()))?;
316 let (param_ref, usages): (Vec<Reference>, Vec<Reference>) = refs
318 .partition(|reference| param_range.intersect(reference.file_range.range).is_some());
320 if param_ref.is_empty() {
321 return Err(RenameError("Parameter to rename not found".to_string()));
324 let mut edits = usages
326 .map(|reference| source_edit_from_reference(sema, reference, "self"))
327 .collect::<Vec<_>>();
329 edits.push(SourceFileEdit {
330 file_id: position.file_id,
331 edit: TextEdit::replace(param_range, String::from(self_param)),
334 Ok(RangeInfo::new(range, SourceChange::from(edits)))
337 fn text_edit_from_self_param(
339 self_param: &ast::SelfParam,
341 ) -> Option<TextEdit> {
342 fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
343 if let Some(ast::Type::PathType(p)) = impl_def.self_ty() {
344 return Some(p.path()?.segment()?.name_ref()?.text().to_string());
349 let impl_def = find_node_at_offset::<ast::Impl>(syn, self_param.syntax().text_range().start())?;
350 let type_name = target_type_name(&impl_def)?;
352 let mut replacement_text = String::from(new_name);
353 replacement_text.push_str(": ");
354 match (self_param.amp_token(), self_param.mut_token()) {
356 (Some(_), None) => replacement_text.push('&'),
357 (_, Some(_)) => replacement_text.push_str("&mut "),
359 replacement_text.push_str(type_name.as_str());
361 Some(TextEdit::replace(self_param.syntax().text_range(), replacement_text))
364 fn rename_self_to_param(
365 sema: &Semantics<RootDatabase>,
366 position: FilePosition,
367 self_token: SyntaxToken,
369 ) -> Result<RangeInfo<SourceChange>, RenameError> {
370 let source_file = sema.parse(position.file_id);
371 let syn = source_file.syntax();
373 let text = sema.db.file_text(position.file_id);
374 let fn_def = find_node_at_offset::<ast::Fn>(syn, position.offset)
375 .ok_or_else(|| RenameError("No surrounding method declaration found".to_string()))?;
376 let search_range = fn_def.syntax().text_range();
378 let mut edits: Vec<SourceFileEdit> = vec![];
380 for (idx, _) in text.match_indices("self") {
381 let offset: TextSize = idx.try_into().unwrap();
382 if !search_range.contains_inclusive(offset) {
385 if let Some(ref usage) =
386 syn.token_at_offset(offset).find(|t| t.kind() == SyntaxKind::SELF_KW)
388 let edit = if let Some(ref self_param) = ast::SelfParam::cast(usage.parent()) {
389 text_edit_from_self_param(syn, self_param, new_name)
390 .ok_or_else(|| RenameError("No target type found".to_string()))?
392 TextEdit::replace(usage.text_range(), String::from(new_name))
394 edits.push(SourceFileEdit { file_id: position.file_id, edit });
398 let range = ast::SelfParam::cast(self_token.parent())
399 .map_or(self_token.text_range(), |p| p.syntax().text_range());
401 Ok(RangeInfo::new(range, SourceChange::from(edits)))
405 sema: &Semantics<RootDatabase>,
406 position: FilePosition,
408 is_lifetime_name: bool,
409 ) -> Result<RangeInfo<SourceChange>, RenameError> {
410 let RangeInfo { range, info: refs } = match find_all_refs(sema, position, None) {
411 Some(range_info) => range_info,
412 None => return Err(RenameError("No references found at position".to_string())),
415 match (refs.declaration.kind == ReferenceKind::Lifetime, is_lifetime_name) {
417 return Err(RenameError(format!(
418 "Invalid name `{}`: not a lifetime identifier",
423 return Err(RenameError(format!("Invalid name `{}`: not an identifier", new_name)))
430 .map(|reference| source_edit_from_reference(sema, reference, new_name))
431 .collect::<Vec<_>>();
434 return Err(RenameError("No references found at position".to_string()));
437 Ok(RangeInfo::new(range, SourceChange::from(edit)))
442 use expect_test::{expect, Expect};
443 use stdx::trim_indent;
444 use test_utils::{assert_eq_text, mark};
445 use text_edit::TextEdit;
447 use crate::{fixture, FileId};
449 fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
450 let ra_fixture_after = &trim_indent(ra_fixture_after);
451 let (analysis, position) = fixture::position(ra_fixture_before);
452 let rename_result = analysis
453 .rename(position, new_name)
454 .unwrap_or_else(|err| panic!("Rename to '{}' was cancelled: {}", new_name, err));
455 match rename_result {
456 Ok(source_change) => {
457 let mut text_edit_builder = TextEdit::builder();
458 let mut file_id: Option<FileId> = None;
459 for edit in source_change.info.source_file_edits {
460 file_id = Some(edit.file_id);
461 for indel in edit.edit.into_iter() {
462 text_edit_builder.replace(indel.delete, indel.insert);
465 let mut result = analysis.file_text(file_id.unwrap()).unwrap().to_string();
466 text_edit_builder.finish().apply(&mut result);
467 assert_eq_text!(ra_fixture_after, &*result);
470 if ra_fixture_after.starts_with("error:") {
471 let error_message = ra_fixture_after
474 .skip("error:".len())
475 .collect::<String>();
476 assert_eq!(error_message.trim(), err.to_string());
479 panic!("Rename to '{}' failed unexpectedly: {}", new_name, err)
485 fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
486 let (analysis, position) = fixture::position(ra_fixture);
487 let source_change = analysis
488 .rename(position, new_name)
490 .expect("Expect returned RangeInfo to be Some, but was None");
491 expect.assert_debug_eq(&source_change)
495 fn test_rename_to_underscore() {
496 check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
500 fn test_rename_to_raw_identifier() {
501 check("r#fn", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
505 fn test_rename_to_invalid_identifier1() {
508 r#"fn main() { let i$0 = 1; }"#,
509 "error: Invalid name `invalid!`: not an identifier",
514 fn test_rename_to_invalid_identifier2() {
517 r#"fn main() { let i$0 = 1; }"#,
518 "error: Invalid name `multiple tokens`: not an identifier",
523 fn test_rename_to_invalid_identifier3() {
526 r#"fn main() { let i$0 = 1; }"#,
527 "error: Invalid name `let`: not an identifier",
532 fn test_rename_to_invalid_identifier_lifetime() {
535 r#"fn main() { let i$0 = 1; }"#,
536 "error: Invalid name `'foo`: not an identifier",
541 fn test_rename_to_invalid_identifier_lifetime2() {
544 r#"fn main<'a>(_: &'a$0 ()) {}"#,
545 "error: Invalid name `foo`: not a lifetime identifier",
550 fn test_rename_for_local() {
579 fn test_rename_unresolved_reference() {
582 r#"fn main() { let _ = unresolved_ref$0; }"#,
583 "error: No references found at position",
588 fn test_rename_for_macro_args() {
592 macro_rules! foo {($i:ident) => {$i} }
599 macro_rules! foo {($i:ident) => {$i} }
609 fn test_rename_for_macro_args_rev() {
613 macro_rules! foo {($i:ident) => {$i} }
620 macro_rules! foo {($i:ident) => {$i} }
630 fn test_rename_for_macro_define_fn() {
634 macro_rules! define_fn {($id:ident) => { fn $id{} }}
641 macro_rules! define_fn {($id:ident) => { fn $id{} }}
651 fn test_rename_for_macro_define_fn_rev() {
655 macro_rules! define_fn {($id:ident) => { fn $id{} }}
662 macro_rules! define_fn {($id:ident) => { fn $id{} }}
672 fn test_rename_for_param_inside() {
673 check("j", r#"fn foo(i : u32) -> u32 { i$0 }"#, r#"fn foo(j : u32) -> u32 { j }"#);
677 fn test_rename_refs_for_fn_param() {
678 check("j", r#"fn foo(i$0 : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
682 fn test_rename_for_mut_param() {
683 check("j", r#"fn foo(mut i$0 : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
687 fn test_rename_struct_field() {
691 struct Foo { i$0: i32 }
694 fn new(i: i32) -> Self {
700 struct Foo { j: i32 }
703 fn new(i: i32) -> Self {
712 fn test_rename_struct_field_for_shorthand() {
713 mark::check!(test_rename_struct_field_for_shorthand);
717 struct Foo { i$0: i32 }
720 fn new(i: i32) -> Self {
726 struct Foo { j: i32 }
729 fn new(i: i32) -> Self {
738 fn test_rename_local_for_field_shorthand() {
739 mark::check!(test_rename_local_for_field_shorthand);
743 struct Foo { i: i32 }
746 fn new(i$0: i32) -> Self {
752 struct Foo { i: i32 }
755 fn new(j: i32) -> Self {
764 fn test_field_shorthand_correct_struct() {
768 struct Foo { i$0: i32 }
769 struct Bar { i: i32 }
772 fn new(i: i32) -> Self {
778 struct Foo { j: i32 }
779 struct Bar { i: i32 }
782 fn new(i: i32) -> Self {
791 fn test_shadow_local_for_struct_shorthand() {
795 struct Foo { i: i32 }
797 fn baz(i$0: i32) -> Self {
806 struct Foo { i: i32 }
808 fn baz(j: i32) -> Self {
809 let x = Foo { i: j };
820 fn test_rename_mod() {
857 dst: AnchoredPathBuf {
873 fn test_rename_mod_in_use_tree() {
883 pub struct FooContent;
886 use crate::foo$0::FooContent;
925 dst: AnchoredPathBuf {
941 fn test_rename_mod_in_dir() {
974 dst: AnchoredPathBuf {
978 path: "../foo2/mod.rs",
990 fn test_rename_unusually_nested_mod() {
995 mod outer { mod fo$0o; }
1003 info: SourceChange {
1004 source_file_edits: [
1019 file_system_edits: [
1024 dst: AnchoredPathBuf {
1040 fn test_module_rename_in_path() {
1044 mod $0foo { pub fn bar() {} }
1046 fn main() { foo::bar(); }
1049 mod baz { pub fn bar() {} }
1051 fn main() { baz::bar(); }
1057 fn test_rename_mod_filename_and_path() {
1076 info: SourceChange {
1077 source_file_edits: [
1105 file_system_edits: [
1110 dst: AnchoredPathBuf {
1126 fn test_enum_variant_from_module_1() {
1131 pub enum Foo { Bar$0 }
1134 fn func(f: foo::Foo) {
1142 pub enum Foo { Baz }
1145 fn func(f: foo::Foo) {
1155 fn test_enum_variant_from_module_2() {
1160 pub struct Foo { pub bar$0: uint }
1163 fn foo(f: foo::Foo) {
1169 pub struct Foo { pub baz: uint }
1172 fn foo(f: foo::Foo) {
1180 fn test_parameter_to_self() {
1184 struct Foo { i: i32 }
1187 fn f(foo$0: &mut Foo) -> i32 {
1193 struct Foo { i: i32 }
1196 fn f(&mut self) -> i32 {
1205 struct Foo { i: i32 }
1208 fn f(foo$0: Foo) -> i32 {
1214 struct Foo { i: i32 }
1226 fn test_parameter_to_self_error_no_impl() {
1230 struct Foo { i: i32 }
1232 fn f(foo$0: &mut Foo) -> i32 {
1236 "error: No impl block found for function",
1241 struct Foo { i: i32 }
1245 fn f(foo$0: &mut Foo) -> i32 {
1250 "error: Parameter type differs from impl block type",
1255 fn test_parameter_to_self_error_not_first() {
1259 struct Foo { i: i32 }
1261 fn f(x: (), foo$0: &mut Foo) -> i32 {
1266 "error: Only the first parameter can be self",
1271 fn test_parameter_to_self_impl_ref() {
1275 struct Foo { i: i32 }
1277 fn f(foo$0: &Foo) -> i32 {
1283 struct Foo { i: i32 }
1294 fn test_self_to_parameter() {
1298 struct Foo { i: i32 }
1301 fn f(&mut $0self) -> i32 {
1307 struct Foo { i: i32 }
1310 fn f(foo: &mut Foo) -> i32 {
1319 fn test_owned_self_to_parameter() {
1323 struct Foo { i: i32 }
1326 fn f($0self) -> i32 {
1332 struct Foo { i: i32 }
1335 fn f(foo: Foo) -> i32 {
1344 fn test_self_in_path_to_parameter() {
1348 struct Foo { i: i32 }
1351 fn f(&self) -> i32 {
1358 struct Foo { i: i32 }
1361 fn f(foo: &Foo) -> i32 {
1371 fn test_initializer_use_field_init_shorthand() {
1372 mark::check!(test_rename_field_expr_pat);
1376 struct Foo { i$0: i32 }
1378 fn foo(bar: i32) -> Foo {
1383 struct Foo { bar: i32 }
1385 fn foo(bar: i32) -> Foo {
1393 fn test_struct_field_destructure_into_shorthand() {
1397 struct Foo { i$0: i32 }
1400 let Foo { i: baz } = foo;
1405 struct Foo { baz: i32 }
1408 let Foo { baz } = foo;
1416 fn test_rename_binding_in_destructure_pat() {
1417 let expected_fixture = r#"
1423 let Foo { i: bar } = foo;
1435 let Foo { i: b } = foo;
1449 let Foo { i } = foo;
1458 fn test_rename_binding_in_destructure_param_pat() {
1466 fn foo(Foo { i }: foo) -> i32 {
1475 fn foo(Foo { i: bar }: foo) -> i32 {
1483 fn test_rename_lifetimes() {
1490 impl<'a> Foo<'a> for &'a () {
1491 fn foo() -> &'a$0 () {
1500 impl<'yeeee> Foo<'yeeee> for &'yeeee () {
1501 fn foo() -> &'yeeee () {
1510 fn test_rename_bind_pat() {
1515 enum CustomOption<T> {
1520 let test_variable = CustomOption::Some(22);
1522 match test_variable {
1523 CustomOption::Some(foo$0) if foo == 11 => {}
1529 enum CustomOption<T> {
1534 let test_variable = CustomOption::Some(22);
1536 match test_variable {
1537 CustomOption::Some(new_name) if new_name == 11 => {}
1545 fn test_rename_label() {
1549 fn foo<'a>() -> &'a () {
1558 fn foo<'a>() -> &'a () {