@@ -7,10 +7,10 @@ use syntax::{
7
7
8
8
use crate :: { AssistContext , AssistId , Assists } ;
9
9
10
- // FIXME: this really should be a fix for diagnostic, rather than an assist.
11
-
12
10
// Assist: fix_visibility
13
11
//
12
+ // Note that there is some duplication between this and the no_such_field diagnostic.
13
+ //
14
14
// Makes inaccessible item public.
15
15
//
16
16
// ```
@@ -32,7 +32,6 @@ use crate::{AssistContext, AssistId, Assists};
32
32
// ```
33
33
pub ( crate ) fn fix_visibility ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
34
34
add_vis_to_referenced_module_def ( acc, ctx)
35
- . or_else ( || add_vis_to_referenced_record_field ( acc, ctx) )
36
35
}
37
36
38
37
fn add_vis_to_referenced_module_def ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
@@ -88,59 +87,6 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>)
88
87
} )
89
88
}
90
89
91
- fn add_vis_to_referenced_record_field ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
92
- let record_field: ast:: RecordExprField = ctx. find_node_at_offset ( ) ?;
93
- let ( record_field_def, _, _) = ctx. sema . resolve_record_field ( & record_field) ?;
94
-
95
- let current_module = ctx. sema . scope ( record_field. syntax ( ) ) ?. module ( ) ;
96
- let current_edition = current_module. krate ( ) . edition ( ctx. db ( ) ) ;
97
- let visibility = record_field_def. visibility ( ctx. db ( ) ) ;
98
- if visibility. is_visible_from ( ctx. db ( ) , current_module. into ( ) ) {
99
- return None ;
100
- }
101
-
102
- let parent = record_field_def. parent_def ( ctx. db ( ) ) ;
103
- let parent_name = parent. name ( ctx. db ( ) ) ;
104
- let target_module = parent. module ( ctx. db ( ) ) ;
105
-
106
- let in_file_source = record_field_def. source ( ctx. db ( ) ) ?;
107
- let ( vis_owner, target) = match in_file_source. value {
108
- hir:: FieldSource :: Named ( it) => {
109
- let range = it. syntax ( ) . text_range ( ) ;
110
- ( ast:: AnyHasVisibility :: new ( it) , range)
111
- }
112
- hir:: FieldSource :: Pos ( it) => {
113
- let range = it. syntax ( ) . text_range ( ) ;
114
- ( ast:: AnyHasVisibility :: new ( it) , range)
115
- }
116
- } ;
117
-
118
- let missing_visibility = if current_module. krate ( ) == target_module. krate ( ) {
119
- make:: visibility_pub_crate ( )
120
- } else {
121
- make:: visibility_pub ( )
122
- } ;
123
- let target_file = in_file_source. file_id . original_file ( ctx. db ( ) ) ;
124
-
125
- let target_name = record_field_def. name ( ctx. db ( ) ) ;
126
- let assist_label = format ! (
127
- "Change visibility of {}.{} to {missing_visibility}" ,
128
- parent_name. display( ctx. db( ) , current_edition) ,
129
- target_name. display( ctx. db( ) , current_edition)
130
- ) ;
131
-
132
- acc. add ( AssistId :: quick_fix ( "fix_visibility" ) , assist_label, target, |edit| {
133
- edit. edit_file ( target_file. file_id ( ctx. db ( ) ) ) ;
134
-
135
- let vis_owner = edit. make_mut ( vis_owner) ;
136
- vis_owner. set_visibility ( Some ( missing_visibility. clone_for_update ( ) ) ) ;
137
-
138
- if let Some ( ( cap, vis) ) = ctx. config . snippet_cap . zip ( vis_owner. visibility ( ) ) {
139
- edit. add_tabstop_before ( cap, vis) ;
140
- }
141
- } )
142
- }
143
-
144
90
fn target_data_for_def (
145
91
db : & dyn HirDatabase ,
146
92
def : hir:: ModuleDef ,
@@ -293,44 +239,6 @@ struct Foo;
293
239
) ;
294
240
}
295
241
296
- #[ test]
297
- fn fix_visibility_of_struct_field ( ) {
298
- check_assist (
299
- fix_visibility,
300
- r"mod foo { pub struct Foo { bar: (), } }
301
- fn main() { foo::Foo { $0bar: () }; } " ,
302
- r"mod foo { pub struct Foo { $0pub(crate) bar: (), } }
303
- fn main() { foo::Foo { bar: () }; } " ,
304
- ) ;
305
- check_assist (
306
- fix_visibility,
307
- r"
308
- //- /lib.rs
309
- mod foo;
310
- fn main() { foo::Foo { $0bar: () }; }
311
- //- /foo.rs
312
- pub struct Foo { bar: () }
313
- " ,
314
- r"pub struct Foo { $0pub(crate) bar: () }
315
- " ,
316
- ) ;
317
- check_assist_not_applicable (
318
- fix_visibility,
319
- r"mod foo { pub struct Foo { pub bar: (), } }
320
- fn main() { foo::Foo { $0bar: () }; } " ,
321
- ) ;
322
- check_assist_not_applicable (
323
- fix_visibility,
324
- r"
325
- //- /lib.rs
326
- mod foo;
327
- fn main() { foo::Foo { $0bar: () }; }
328
- //- /foo.rs
329
- pub struct Foo { pub bar: () }
330
- " ,
331
- ) ;
332
- }
333
-
334
242
#[ test]
335
243
fn fix_visibility_of_enum_variant_field ( ) {
336
244
// Enum variants, as well as their fields, always get the enum's visibility. In fact, rustc
@@ -367,44 +275,6 @@ pub struct Foo { pub bar: () }
367
275
) ;
368
276
}
369
277
370
- #[ test]
371
- fn fix_visibility_of_union_field ( ) {
372
- check_assist (
373
- fix_visibility,
374
- r"mod foo { pub union Foo { bar: (), } }
375
- fn main() { foo::Foo { $0bar: () }; } " ,
376
- r"mod foo { pub union Foo { $0pub(crate) bar: (), } }
377
- fn main() { foo::Foo { bar: () }; } " ,
378
- ) ;
379
- check_assist (
380
- fix_visibility,
381
- r"
382
- //- /lib.rs
383
- mod foo;
384
- fn main() { foo::Foo { $0bar: () }; }
385
- //- /foo.rs
386
- pub union Foo { bar: () }
387
- " ,
388
- r"pub union Foo { $0pub(crate) bar: () }
389
- " ,
390
- ) ;
391
- check_assist_not_applicable (
392
- fix_visibility,
393
- r"mod foo { pub union Foo { pub bar: (), } }
394
- fn main() { foo::Foo { $0bar: () }; } " ,
395
- ) ;
396
- check_assist_not_applicable (
397
- fix_visibility,
398
- r"
399
- //- /lib.rs
400
- mod foo;
401
- fn main() { foo::Foo { $0bar: () }; }
402
- //- /foo.rs
403
- pub union Foo { pub bar: () }
404
- " ,
405
- ) ;
406
- }
407
-
408
278
#[ test]
409
279
fn fix_visibility_of_const ( ) {
410
280
check_assist (
@@ -570,19 +440,6 @@ foo::Bar$0
570
440
pub(crate) struct Bar;
571
441
" ,
572
442
r"$0pub struct Bar;
573
- " ,
574
- ) ;
575
- check_assist (
576
- fix_visibility,
577
- r"
578
- //- /main.rs crate:a deps:foo
579
- fn main() {
580
- foo::Foo { $0bar: () };
581
- }
582
- //- /lib.rs crate:foo
583
- pub struct Foo { pub(crate) bar: () }
584
- " ,
585
- r"pub struct Foo { $0pub bar: () }
586
443
" ,
587
444
) ;
588
445
}
0 commit comments