@@ -1007,20 +1007,24 @@ impl ast::IdentPat {
1007
1007
}
1008
1008
1009
1009
pub trait HasVisibilityEdit : ast:: HasVisibility {
1010
- fn set_visibility ( & self , visibility : ast:: Visibility ) {
1011
- match self . visibility ( ) {
1012
- Some ( current_visibility) => {
1013
- ted:: replace ( current_visibility. syntax ( ) , visibility. syntax ( ) )
1014
- }
1015
- None => {
1016
- let vis_before = self
1017
- . syntax ( )
1018
- . children_with_tokens ( )
1019
- . find ( |it| !matches ! ( it. kind( ) , WHITESPACE | COMMENT | ATTR ) )
1020
- . unwrap_or_else ( || self . syntax ( ) . first_child_or_token ( ) . unwrap ( ) ) ;
1021
-
1022
- ted:: insert ( ted:: Position :: before ( vis_before) , visibility. syntax ( ) ) ;
1010
+ fn set_visibility ( & self , visibility : Option < ast:: Visibility > ) {
1011
+ if let Some ( visibility) = visibility {
1012
+ match self . visibility ( ) {
1013
+ Some ( current_visibility) => {
1014
+ ted:: replace ( current_visibility. syntax ( ) , visibility. syntax ( ) )
1015
+ }
1016
+ None => {
1017
+ let vis_before = self
1018
+ . syntax ( )
1019
+ . children_with_tokens ( )
1020
+ . find ( |it| !matches ! ( it. kind( ) , WHITESPACE | COMMENT | ATTR ) )
1021
+ . unwrap_or_else ( || self . syntax ( ) . first_child_or_token ( ) . unwrap ( ) ) ;
1022
+
1023
+ ted:: insert ( ted:: Position :: before ( vis_before) , visibility. syntax ( ) ) ;
1024
+ }
1023
1025
}
1026
+ } else if let Some ( visibility) = self . visibility ( ) {
1027
+ ted:: remove ( visibility. syntax ( ) ) ;
1024
1028
}
1025
1029
}
1026
1030
}
0 commit comments