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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

0 commit comments

Comments
 (0)