Skip to content

Commit 15a8b49

Browse files
authored
Rollup merge of #123841 - Kohei316:remove_qualifier_sugg, r=wesleywiser
Improve diagnostic by suggesting to remove visibility qualifier Resolves #123529 This PR improve diagnostic by suggesting to remove visibility qualifier.
2 parents be3ea1d + ac1bee6 commit 15a8b49

19 files changed

+77
-44
lines changed

Diff for: compiler/rustc_ast_passes/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ ast_passes_visibility_not_permitted =
273273
.trait_impl = trait items always share the visibility of their trait
274274
.individual_impl_items = place qualifiers on individual impl items instead
275275
.individual_foreign_items = place qualifiers on individual foreign items instead
276+
.remove_qualifier_sugg = remove the qualifier
276277
277278
ast_passes_where_clause_after_type_alias = where clauses are not allowed after the type for type aliases
278279
.note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ impl<'a> AstValidator<'a> {
266266
return;
267267
}
268268

269-
self.dcx().emit_err(errors::VisibilityNotPermitted { span: vis.span, note });
269+
self.dcx().emit_err(errors::VisibilityNotPermitted {
270+
span: vis.span,
271+
note,
272+
remove_qualifier_sugg: vis.span,
273+
});
270274
}
271275

272276
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {

Diff for: compiler/rustc_ast_passes/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ pub struct VisibilityNotPermitted {
3131
pub span: Span,
3232
#[subdiagnostic]
3333
pub note: VisibilityNotPermittedNote,
34+
#[suggestion(
35+
ast_passes_remove_qualifier_sugg,
36+
code = "",
37+
applicability = "machine-applicable"
38+
)]
39+
pub remove_qualifier_sugg: Span,
3440
}
3541

3642
#[derive(Subdiagnostic)]

Diff for: tests/ui/error-codes/E0449.fixed

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-rustfix
2+
3+
#![allow(warnings)]
4+
5+
struct Bar;
6+
7+
trait Foo {
8+
fn foo();
9+
}
10+
11+
impl Bar {} //~ ERROR E0449
12+
13+
impl Foo for Bar { //~ ERROR E0449
14+
fn foo() {} //~ ERROR E0449
15+
}
16+
17+
fn main() {
18+
}

Diff for: tests/ui/error-codes/E0449.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//@ run-rustfix
2+
3+
#![allow(warnings)]
4+
15
struct Bar;
26

37
trait Foo {

Diff for: tests/ui/error-codes/E0449.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
error[E0449]: visibility qualifiers are not permitted here
2-
--> $DIR/E0449.rs:7:1
2+
--> $DIR/E0449.rs:11:1
33
|
44
LL | pub impl Bar {}
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: place qualifiers on individual impl items instead
88

99
error[E0449]: visibility qualifiers are not permitted here
10-
--> $DIR/E0449.rs:9:1
10+
--> $DIR/E0449.rs:13:1
1111
|
1212
LL | pub impl Foo for Bar {
13-
| ^^^
13+
| ^^^ help: remove the qualifier
1414
|
1515
= note: trait items always share the visibility of their trait
1616

1717
error[E0449]: visibility qualifiers are not permitted here
18-
--> $DIR/E0449.rs:10:5
18+
--> $DIR/E0449.rs:14:5
1919
|
2020
LL | pub fn foo() {}
21-
| ^^^
21+
| ^^^ help: remove the qualifier
2222
|
2323
= note: trait items always share the visibility of their trait
2424

Diff for: tests/ui/issues/issue-28433.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/issue-28433.rs:2:5
33
|
44
LL | pub Duck,
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: enum variants and their fields always share the visibility of the enum they are in
88

99
error[E0449]: visibility qualifiers are not permitted here
1010
--> $DIR/issue-28433.rs:5:5
1111
|
1212
LL | pub(crate) Dove
13-
| ^^^^^^^^^^
13+
| ^^^^^^^^^^ help: remove the qualifier
1414
|
1515
= note: enum variants and their fields always share the visibility of the enum they are in
1616

Diff for: tests/ui/parser/assoc/assoc-static-semantic-fail.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ error[E0449]: visibility qualifiers are not permitted here
138138
--> $DIR/assoc-static-semantic-fail.rs:32:5
139139
|
140140
LL | pub(crate) default static TD: u8;
141-
| ^^^^^^^^^^
141+
| ^^^^^^^^^^ help: remove the qualifier
142142
|
143143
= note: trait items always share the visibility of their trait
144144

@@ -162,7 +162,7 @@ error[E0449]: visibility qualifiers are not permitted here
162162
--> $DIR/assoc-static-semantic-fail.rs:47:5
163163
|
164164
LL | pub default static TD: u8;
165-
| ^^^
165+
| ^^^ help: remove the qualifier
166166
|
167167
= note: trait items always share the visibility of their trait
168168

Diff for: tests/ui/parser/default.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ error[E0449]: visibility qualifiers are not permitted here
2121
--> $DIR/default.rs:17:5
2222
|
2323
LL | pub default fn foo<T: Default>() -> T {
24-
| ^^^
24+
| ^^^ help: remove the qualifier
2525
|
2626
= note: trait items always share the visibility of their trait
2727

Diff for: tests/ui/parser/trait-pub-assoc-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/trait-pub-assoc-const.rs:2:5
33
|
44
LL | pub const Foo: u32;
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/parser/trait-pub-assoc-ty.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/trait-pub-assoc-ty.rs:2:5
33
|
44
LL | pub type Foo;
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/parser/trait-pub-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/trait-pub-method.rs:2:5
33
|
44
LL | pub fn foo();
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/privacy/issue-113860-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/issue-113860-1.rs:12:5
33
|
44
LL | pub(self) fn fun() {}
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/privacy/issue-113860-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/issue-113860-2.rs:12:5
33
|
44
LL | pub(self) type X = Self;
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/privacy/issue-113860.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/issue-113860.rs:12:5
33
|
44
LL | pub(self) const X: u32 = 3;
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/privacy/issue-29161.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/issue-29161.rs:5:9
33
|
44
LL | pub fn default() -> A {
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

Diff for: tests/ui/privacy/priv-in-bad-locations.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/priv-in-bad-locations.rs:1:1
33
|
44
LL | pub extern "C" {
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: place qualifiers on individual foreign items instead
88

99
error[E0449]: visibility qualifiers are not permitted here
1010
--> $DIR/priv-in-bad-locations.rs:11:1
1111
|
1212
LL | pub impl B {}
13-
| ^^^
13+
| ^^^ help: remove the qualifier
1414
|
1515
= note: place qualifiers on individual impl items instead
1616

1717
error[E0449]: visibility qualifiers are not permitted here
1818
--> $DIR/priv-in-bad-locations.rs:13:1
1919
|
2020
LL | pub impl A for B {
21-
| ^^^
21+
| ^^^ help: remove the qualifier
2222
|
2323
= note: trait items always share the visibility of their trait
2424

2525
error[E0449]: visibility qualifiers are not permitted here
2626
--> $DIR/priv-in-bad-locations.rs:14:5
2727
|
2828
LL | pub fn foo(&self) {}
29-
| ^^^
29+
| ^^^ help: remove the qualifier
3030
|
3131
= note: trait items always share the visibility of their trait
3232

Diff for: tests/ui/privacy/privacy-sanity.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,143 +2,143 @@ error[E0449]: visibility qualifiers are not permitted here
22
--> $DIR/privacy-sanity.rs:13:1
33
|
44
LL | pub impl Tr for S {
5-
| ^^^
5+
| ^^^ help: remove the qualifier
66
|
77
= note: trait items always share the visibility of their trait
88

99
error[E0449]: visibility qualifiers are not permitted here
1010
--> $DIR/privacy-sanity.rs:14:5
1111
|
1212
LL | pub fn f() {}
13-
| ^^^
13+
| ^^^ help: remove the qualifier
1414
|
1515
= note: trait items always share the visibility of their trait
1616

1717
error[E0449]: visibility qualifiers are not permitted here
1818
--> $DIR/privacy-sanity.rs:15:5
1919
|
2020
LL | pub const C: u8 = 0;
21-
| ^^^
21+
| ^^^ help: remove the qualifier
2222
|
2323
= note: trait items always share the visibility of their trait
2424

2525
error[E0449]: visibility qualifiers are not permitted here
2626
--> $DIR/privacy-sanity.rs:16:5
2727
|
2828
LL | pub type T = u8;
29-
| ^^^
29+
| ^^^ help: remove the qualifier
3030
|
3131
= note: trait items always share the visibility of their trait
3232

3333
error[E0449]: visibility qualifiers are not permitted here
3434
--> $DIR/privacy-sanity.rs:18:1
3535
|
3636
LL | pub impl S {
37-
| ^^^
37+
| ^^^ help: remove the qualifier
3838
|
3939
= note: place qualifiers on individual impl items instead
4040

4141
error[E0449]: visibility qualifiers are not permitted here
4242
--> $DIR/privacy-sanity.rs:23:1
4343
|
4444
LL | pub extern "C" {
45-
| ^^^
45+
| ^^^ help: remove the qualifier
4646
|
4747
= note: place qualifiers on individual foreign items instead
4848

4949
error[E0449]: visibility qualifiers are not permitted here
5050
--> $DIR/privacy-sanity.rs:39:5
5151
|
5252
LL | pub impl Tr for S {
53-
| ^^^
53+
| ^^^ help: remove the qualifier
5454
|
5555
= note: trait items always share the visibility of their trait
5656

5757
error[E0449]: visibility qualifiers are not permitted here
5858
--> $DIR/privacy-sanity.rs:40:9
5959
|
6060
LL | pub fn f() {}
61-
| ^^^
61+
| ^^^ help: remove the qualifier
6262
|
6363
= note: trait items always share the visibility of their trait
6464

6565
error[E0449]: visibility qualifiers are not permitted here
6666
--> $DIR/privacy-sanity.rs:41:9
6767
|
6868
LL | pub const C: u8 = 0;
69-
| ^^^
69+
| ^^^ help: remove the qualifier
7070
|
7171
= note: trait items always share the visibility of their trait
7272

7373
error[E0449]: visibility qualifiers are not permitted here
7474
--> $DIR/privacy-sanity.rs:42:9
7575
|
7676
LL | pub type T = u8;
77-
| ^^^
77+
| ^^^ help: remove the qualifier
7878
|
7979
= note: trait items always share the visibility of their trait
8080

8181
error[E0449]: visibility qualifiers are not permitted here
8282
--> $DIR/privacy-sanity.rs:44:5
8383
|
8484
LL | pub impl S {
85-
| ^^^
85+
| ^^^ help: remove the qualifier
8686
|
8787
= note: place qualifiers on individual impl items instead
8888

8989
error[E0449]: visibility qualifiers are not permitted here
9090
--> $DIR/privacy-sanity.rs:49:5
9191
|
9292
LL | pub extern "C" {
93-
| ^^^
93+
| ^^^ help: remove the qualifier
9494
|
9595
= note: place qualifiers on individual foreign items instead
9696

9797
error[E0449]: visibility qualifiers are not permitted here
9898
--> $DIR/privacy-sanity.rs:68:5
9999
|
100100
LL | pub impl Tr for S {
101-
| ^^^
101+
| ^^^ help: remove the qualifier
102102
|
103103
= note: trait items always share the visibility of their trait
104104

105105
error[E0449]: visibility qualifiers are not permitted here
106106
--> $DIR/privacy-sanity.rs:69:9
107107
|
108108
LL | pub fn f() {}
109-
| ^^^
109+
| ^^^ help: remove the qualifier
110110
|
111111
= note: trait items always share the visibility of their trait
112112

113113
error[E0449]: visibility qualifiers are not permitted here
114114
--> $DIR/privacy-sanity.rs:70:9
115115
|
116116
LL | pub const C: u8 = 0;
117-
| ^^^
117+
| ^^^ help: remove the qualifier
118118
|
119119
= note: trait items always share the visibility of their trait
120120

121121
error[E0449]: visibility qualifiers are not permitted here
122122
--> $DIR/privacy-sanity.rs:71:9
123123
|
124124
LL | pub type T = u8;
125-
| ^^^
125+
| ^^^ help: remove the qualifier
126126
|
127127
= note: trait items always share the visibility of their trait
128128

129129
error[E0449]: visibility qualifiers are not permitted here
130130
--> $DIR/privacy-sanity.rs:73:5
131131
|
132132
LL | pub impl S {
133-
| ^^^
133+
| ^^^ help: remove the qualifier
134134
|
135135
= note: place qualifiers on individual impl items instead
136136

137137
error[E0449]: visibility qualifiers are not permitted here
138138
--> $DIR/privacy-sanity.rs:78:5
139139
|
140140
LL | pub extern "C" {
141-
| ^^^
141+
| ^^^ help: remove the qualifier
142142
|
143143
= note: place qualifiers on individual foreign items instead
144144

0 commit comments

Comments
 (0)