@@ -45,6 +45,11 @@ use crate::{
4545 traits:: convert_to_def_in_trait,
4646} ;
4747
48+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
49+ pub struct RenameConfig {
50+ pub show_conflicts : bool ,
51+ }
52+
4853pub type Result < T , E = RenameError > = std:: result:: Result < T , E > ;
4954
5055#[ derive( Debug ) ]
@@ -81,6 +86,7 @@ impl Definition {
8186 sema : & Semantics < ' _ , RootDatabase > ,
8287 new_name : & str ,
8388 rename_definition : RenameDefinition ,
89+ config : & RenameConfig ,
8490 ) -> Result < SourceChange > {
8591 // self.krate() returns None if
8692 // self is a built-in attr, built-in type or tool module.
@@ -109,10 +115,15 @@ impl Definition {
109115 bail ! ( "Cannot rename a builtin attr." )
110116 }
111117 Definition :: SelfType ( _) => bail ! ( "Cannot rename `Self`" ) ,
112- Definition :: Macro ( mac) => {
113- rename_reference ( sema, Definition :: Macro ( mac) , new_name, rename_definition, edition)
114- }
115- def => rename_reference ( sema, def, new_name, rename_definition, edition) ,
118+ Definition :: Macro ( mac) => rename_reference (
119+ sema,
120+ Definition :: Macro ( mac) ,
121+ new_name,
122+ rename_definition,
123+ edition,
124+ config,
125+ ) ,
126+ def => rename_reference ( sema, def, new_name, rename_definition, edition, config) ,
116127 }
117128 }
118129
@@ -338,6 +349,7 @@ fn rename_reference(
338349 new_name : & str ,
339350 rename_definition : RenameDefinition ,
340351 edition : Edition ,
352+ config : & RenameConfig ,
341353) -> Result < SourceChange > {
342354 let ( mut new_name, ident_kind) = IdentifierKind :: classify ( edition, new_name) ?;
343355
@@ -396,7 +408,8 @@ fn rename_reference(
396408 if rename_definition == RenameDefinition :: Yes {
397409 // This needs to come after the references edits, because we change the annotation of existing edits
398410 // if a conflict is detected.
399- let ( file_id, edit) = source_edit_from_def ( sema, def, & new_name, & mut source_change) ?;
411+ let ( file_id, edit) =
412+ source_edit_from_def ( sema, config, def, & new_name, & mut source_change) ?;
400413 source_change. insert_source_edit ( file_id, edit) ;
401414 }
402415 Ok ( source_change)
@@ -554,6 +567,7 @@ fn source_edit_from_name_ref(
554567
555568fn source_edit_from_def (
556569 sema : & Semantics < ' _ , RootDatabase > ,
570+ config : & RenameConfig ,
557571 def : Definition ,
558572 new_name : & Name ,
559573 source_change : & mut SourceChange ,
@@ -562,21 +576,22 @@ fn source_edit_from_def(
562576 if let Definition :: Local ( local) = def {
563577 let mut file_id = None ;
564578
565- let conflict_annotation = if !sema. rename_conflicts ( & local, new_name) . is_empty ( ) {
566- Some (
567- source_change. insert_annotation ( ChangeAnnotation {
568- label : "This rename will change the program's meaning" . to_owned ( ) ,
569- needs_confirmation : true ,
570- description : Some (
571- "Some variable(s) will shadow the renamed variable \
579+ let conflict_annotation =
580+ if config. show_conflicts && !sema. rename_conflicts ( & local, new_name) . is_empty ( ) {
581+ Some (
582+ source_change. insert_annotation ( ChangeAnnotation {
583+ label : "This rename will change the program's meaning" . to_owned ( ) ,
584+ needs_confirmation : true ,
585+ description : Some (
586+ "Some variable(s) will shadow the renamed variable \
572587 or be shadowed by it if the rename is performed"
573- . to_owned ( ) ,
574- ) ,
575- } ) ,
576- )
577- } else {
578- None
579- } ;
588+ . to_owned ( ) ,
589+ ) ,
590+ } ) ,
591+ )
592+ } else {
593+ None
594+ } ;
580595
581596 for source in local. sources ( sema. db ) {
582597 let source = match source. source . clone ( ) . original_ast_node_rooted ( sema. db ) {
0 commit comments