@@ -1007,20 +1007,24 @@ impl ast::IdentPat {
10071007}
10081008
10091009pub 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+ }
10231025 }
1026+ } else if let Some ( visibility) = self . visibility ( ) {
1027+ ted:: remove ( visibility. syntax ( ) ) ;
10241028 }
10251029 }
10261030}
0 commit comments