Skip to content

Commit 4ebc96a

Browse files
committed
Improve diagnostics by suggesting to remove visibility qualifier
Resolves #123529
1 parent ca7d34e commit 4ebc96a

18 files changed

+62
-0
lines changed

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+
.help = 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

compiler/rustc_ast_passes/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct InvalidLabel {
2626

2727
#[derive(Diagnostic)]
2828
#[diag(ast_passes_visibility_not_permitted, code = E0449)]
29+
#[help]
2930
pub struct VisibilityNotPermitted {
3031
#[primary_span]
3132
pub span: Span,

tests/ui/error-codes/E0449.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub impl Bar {}
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: place qualifiers on individual impl items instead
89

910
error[E0449]: visibility qualifiers are not permitted here
@@ -12,6 +13,7 @@ error[E0449]: visibility qualifiers are not permitted here
1213
LL | pub impl Foo for Bar {
1314
| ^^^
1415
|
16+
= help: remove the qualifier
1517
= note: trait items always share the visibility of their trait
1618

1719
error[E0449]: visibility qualifiers are not permitted here
@@ -20,6 +22,7 @@ error[E0449]: visibility qualifiers are not permitted here
2022
LL | pub fn foo() {}
2123
| ^^^
2224
|
25+
= help: remove the qualifier
2326
= note: trait items always share the visibility of their trait
2427

2528
error: aborting due to 3 previous errors

tests/ui/issues/issue-123529.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Fun {
2+
pub fn test() {}
3+
//~^ ERROR visibility qualifiers are not permitted here
4+
//~| NOTE trait items always share the visibility of their trait
5+
//~| HELP remove the qualifier
6+
}
7+
8+
fn main() {}

tests/ui/issues/issue-123529.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0449]: visibility qualifiers are not permitted here
2+
--> $DIR/issue-123529.rs:2:5
3+
|
4+
LL | pub fn test() {}
5+
| ^^^
6+
|
7+
= help: remove the qualifier
8+
= note: trait items always share the visibility of their trait
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0449`.

tests/ui/issues/issue-28433.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub Duck,
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: enum variants and their fields always share the visibility of the enum they are in
89

910
error[E0449]: visibility qualifiers are not permitted here
@@ -12,6 +13,7 @@ error[E0449]: visibility qualifiers are not permitted here
1213
LL | pub(crate) Dove
1314
| ^^^^^^^^^^
1415
|
16+
= help: remove the qualifier
1517
= note: enum variants and their fields always share the visibility of the enum they are in
1618

1719
error: aborting due to 2 previous errors

tests/ui/parser/assoc/assoc-static-semantic-fail.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ error[E0449]: visibility qualifiers are not permitted here
140140
LL | pub(crate) default static TD: u8;
141141
| ^^^^^^^^^^
142142
|
143+
= help: remove the qualifier
143144
= note: trait items always share the visibility of their trait
144145

145146
error: associated constant in `impl` without body
@@ -164,6 +165,7 @@ error[E0449]: visibility qualifiers are not permitted here
164165
LL | pub default static TD: u8;
165166
| ^^^
166167
|
168+
= help: remove the qualifier
167169
= note: trait items always share the visibility of their trait
168170

169171
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes

tests/ui/parser/default.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ error[E0449]: visibility qualifiers are not permitted here
2323
LL | pub default fn foo<T: Default>() -> T {
2424
| ^^^
2525
|
26+
= help: remove the qualifier
2627
= note: trait items always share the visibility of their trait
2728

2829
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes

tests/ui/parser/trait-pub-assoc-const.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub const Foo: u32;
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: aborting due to 1 previous error

tests/ui/parser/trait-pub-assoc-ty.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub type Foo;
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: aborting due to 1 previous error

tests/ui/parser/trait-pub-method.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub fn foo();
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: aborting due to 1 previous error

tests/ui/privacy/issue-113860-1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub(self) fn fun() {}
55
| ^^^^^^^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: module has missing stability attribute

tests/ui/privacy/issue-113860-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub(self) type X = Self;
55
| ^^^^^^^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: module has missing stability attribute

tests/ui/privacy/issue-113860.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub(self) const X: u32 = 3;
55
| ^^^^^^^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error: module has missing stability attribute

tests/ui/privacy/issue-29161.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub fn default() -> A {
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error[E0603]: struct `A` is private

tests/ui/privacy/priv-in-bad-locations.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub extern "C" {
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: place qualifiers on individual foreign items instead
89

910
error[E0449]: visibility qualifiers are not permitted here
@@ -12,6 +13,7 @@ error[E0449]: visibility qualifiers are not permitted here
1213
LL | pub impl B {}
1314
| ^^^
1415
|
16+
= help: remove the qualifier
1517
= note: place qualifiers on individual impl items instead
1618

1719
error[E0449]: visibility qualifiers are not permitted here
@@ -20,6 +22,7 @@ error[E0449]: visibility qualifiers are not permitted here
2022
LL | pub impl A for B {
2123
| ^^^
2224
|
25+
= help: remove the qualifier
2326
= note: trait items always share the visibility of their trait
2427

2528
error[E0449]: visibility qualifiers are not permitted here
@@ -28,6 +31,7 @@ error[E0449]: visibility qualifiers are not permitted here
2831
LL | pub fn foo(&self) {}
2932
| ^^^
3033
|
34+
= help: remove the qualifier
3135
= note: trait items always share the visibility of their trait
3236

3337
error: aborting due to 4 previous errors

tests/ui/privacy/privacy-sanity.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub impl Tr for S {
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error[E0449]: visibility qualifiers are not permitted here
@@ -12,6 +13,7 @@ error[E0449]: visibility qualifiers are not permitted here
1213
LL | pub fn f() {}
1314
| ^^^
1415
|
16+
= help: remove the qualifier
1517
= note: trait items always share the visibility of their trait
1618

1719
error[E0449]: visibility qualifiers are not permitted here
@@ -20,6 +22,7 @@ error[E0449]: visibility qualifiers are not permitted here
2022
LL | pub const C: u8 = 0;
2123
| ^^^
2224
|
25+
= help: remove the qualifier
2326
= note: trait items always share the visibility of their trait
2427

2528
error[E0449]: visibility qualifiers are not permitted here
@@ -28,6 +31,7 @@ error[E0449]: visibility qualifiers are not permitted here
2831
LL | pub type T = u8;
2932
| ^^^
3033
|
34+
= help: remove the qualifier
3135
= note: trait items always share the visibility of their trait
3236

3337
error[E0449]: visibility qualifiers are not permitted here
@@ -36,6 +40,7 @@ error[E0449]: visibility qualifiers are not permitted here
3640
LL | pub impl S {
3741
| ^^^
3842
|
43+
= help: remove the qualifier
3944
= note: place qualifiers on individual impl items instead
4045

4146
error[E0449]: visibility qualifiers are not permitted here
@@ -44,6 +49,7 @@ error[E0449]: visibility qualifiers are not permitted here
4449
LL | pub extern "C" {
4550
| ^^^
4651
|
52+
= help: remove the qualifier
4753
= note: place qualifiers on individual foreign items instead
4854

4955
error[E0449]: visibility qualifiers are not permitted here
@@ -52,6 +58,7 @@ error[E0449]: visibility qualifiers are not permitted here
5258
LL | pub impl Tr for S {
5359
| ^^^
5460
|
61+
= help: remove the qualifier
5562
= note: trait items always share the visibility of their trait
5663

5764
error[E0449]: visibility qualifiers are not permitted here
@@ -60,6 +67,7 @@ error[E0449]: visibility qualifiers are not permitted here
6067
LL | pub fn f() {}
6168
| ^^^
6269
|
70+
= help: remove the qualifier
6371
= note: trait items always share the visibility of their trait
6472

6573
error[E0449]: visibility qualifiers are not permitted here
@@ -68,6 +76,7 @@ error[E0449]: visibility qualifiers are not permitted here
6876
LL | pub const C: u8 = 0;
6977
| ^^^
7078
|
79+
= help: remove the qualifier
7180
= note: trait items always share the visibility of their trait
7281

7382
error[E0449]: visibility qualifiers are not permitted here
@@ -76,6 +85,7 @@ error[E0449]: visibility qualifiers are not permitted here
7685
LL | pub type T = u8;
7786
| ^^^
7887
|
88+
= help: remove the qualifier
7989
= note: trait items always share the visibility of their trait
8090

8191
error[E0449]: visibility qualifiers are not permitted here
@@ -84,6 +94,7 @@ error[E0449]: visibility qualifiers are not permitted here
8494
LL | pub impl S {
8595
| ^^^
8696
|
97+
= help: remove the qualifier
8798
= note: place qualifiers on individual impl items instead
8899

89100
error[E0449]: visibility qualifiers are not permitted here
@@ -92,6 +103,7 @@ error[E0449]: visibility qualifiers are not permitted here
92103
LL | pub extern "C" {
93104
| ^^^
94105
|
106+
= help: remove the qualifier
95107
= note: place qualifiers on individual foreign items instead
96108

97109
error[E0449]: visibility qualifiers are not permitted here
@@ -100,6 +112,7 @@ error[E0449]: visibility qualifiers are not permitted here
100112
LL | pub impl Tr for S {
101113
| ^^^
102114
|
115+
= help: remove the qualifier
103116
= note: trait items always share the visibility of their trait
104117

105118
error[E0449]: visibility qualifiers are not permitted here
@@ -108,6 +121,7 @@ error[E0449]: visibility qualifiers are not permitted here
108121
LL | pub fn f() {}
109122
| ^^^
110123
|
124+
= help: remove the qualifier
111125
= note: trait items always share the visibility of their trait
112126

113127
error[E0449]: visibility qualifiers are not permitted here
@@ -116,6 +130,7 @@ error[E0449]: visibility qualifiers are not permitted here
116130
LL | pub const C: u8 = 0;
117131
| ^^^
118132
|
133+
= help: remove the qualifier
119134
= note: trait items always share the visibility of their trait
120135

121136
error[E0449]: visibility qualifiers are not permitted here
@@ -124,6 +139,7 @@ error[E0449]: visibility qualifiers are not permitted here
124139
LL | pub type T = u8;
125140
| ^^^
126141
|
142+
= help: remove the qualifier
127143
= note: trait items always share the visibility of their trait
128144

129145
error[E0449]: visibility qualifiers are not permitted here
@@ -132,6 +148,7 @@ error[E0449]: visibility qualifiers are not permitted here
132148
LL | pub impl S {
133149
| ^^^
134150
|
151+
= help: remove the qualifier
135152
= note: place qualifiers on individual impl items instead
136153

137154
error[E0449]: visibility qualifiers are not permitted here
@@ -140,6 +157,7 @@ error[E0449]: visibility qualifiers are not permitted here
140157
LL | pub extern "C" {
141158
| ^^^
142159
|
160+
= help: remove the qualifier
143161
= note: place qualifiers on individual foreign items instead
144162

145163
error: aborting due to 18 previous errors

tests/ui/privacy/useless-pub.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
44
LL | pub fn foo(&self) {}
55
| ^^^
66
|
7+
= help: remove the qualifier
78
= note: trait items always share the visibility of their trait
89

910
error[E0449]: visibility qualifiers are not permitted here
@@ -12,6 +13,7 @@ error[E0449]: visibility qualifiers are not permitted here
1213
LL | V1 { pub f: i32 },
1314
| ^^^
1415
|
16+
= help: remove the qualifier
1517
= note: enum variants and their fields always share the visibility of the enum they are in
1618

1719
error[E0449]: visibility qualifiers are not permitted here
@@ -20,6 +22,7 @@ error[E0449]: visibility qualifiers are not permitted here
2022
LL | V2(pub i32),
2123
| ^^^
2224
|
25+
= help: remove the qualifier
2326
= note: enum variants and their fields always share the visibility of the enum they are in
2427

2528
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)