Skip to content

Improve diagnostics by suggesting to remove visibility qualifier #123605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ ast_passes_visibility_not_permitted =
.trait_impl = trait items always share the visibility of their trait
.individual_impl_items = place qualifiers on individual impl items instead
.individual_foreign_items = place qualifiers on individual foreign items instead
.help = remove the qualifier

ast_passes_where_clause_after_type_alias = where clauses are not allowed after the type for type aliases
.note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct InvalidLabel {

#[derive(Diagnostic)]
#[diag(ast_passes_visibility_not_permitted, code = E0449)]
#[help]
pub struct VisibilityNotPermitted {
#[primary_span]
pub span: Span,
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/error-codes/E0449.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub impl Bar {}
| ^^^
|
= help: remove the qualifier
= note: place qualifiers on individual impl items instead

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

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

error: aborting due to 3 previous errors
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/issues/issue-123529.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Fun {
pub fn test() {}
//~^ ERROR visibility qualifiers are not permitted here
//~| NOTE trait items always share the visibility of their trait
//~| HELP remove the qualifier
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/issues/issue-123529.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-123529.rs:2:5
|
LL | pub fn test() {}
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0449`.
2 changes: 2 additions & 0 deletions tests/ui/issues/issue-28433.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub Duck,
| ^^^
|
= help: remove the qualifier
= note: enum variants and their fields always share the visibility of the enum they are in

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

error: aborting due to 2 previous errors
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/parser/assoc/assoc-static-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

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

warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
Expand Down
1 change: 1 addition & 0 deletions tests/ui/parser/default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub default fn foo<T: Default>() -> T {
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
Expand Down
1 change: 1 addition & 0 deletions tests/ui/parser/trait-pub-assoc-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub const Foo: u32;
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: aborting due to 1 previous error
Expand Down
1 change: 1 addition & 0 deletions tests/ui/parser/trait-pub-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub type Foo;
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: aborting due to 1 previous error
Expand Down
1 change: 1 addition & 0 deletions tests/ui/parser/trait-pub-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub fn foo();
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: aborting due to 1 previous error
Expand Down
1 change: 1 addition & 0 deletions tests/ui/privacy/issue-113860-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub(self) fn fun() {}
| ^^^^^^^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: module has missing stability attribute
Expand Down
1 change: 1 addition & 0 deletions tests/ui/privacy/issue-113860-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub(self) type X = Self;
| ^^^^^^^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: module has missing stability attribute
Expand Down
1 change: 1 addition & 0 deletions tests/ui/privacy/issue-113860.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub(self) const X: u32 = 3;
| ^^^^^^^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error: module has missing stability attribute
Expand Down
1 change: 1 addition & 0 deletions tests/ui/privacy/issue-29161.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub fn default() -> A {
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

error[E0603]: struct `A` is private
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/privacy/priv-in-bad-locations.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub extern "C" {
| ^^^
|
= help: remove the qualifier
= note: place qualifiers on individual foreign items instead

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

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

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

error: aborting due to 4 previous errors
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/privacy/privacy-sanity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub impl Tr for S {
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: aborting due to 18 previous errors
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/privacy/useless-pub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0449]: visibility qualifiers are not permitted here
LL | pub fn foo(&self) {}
| ^^^
|
= help: remove the qualifier
= note: trait items always share the visibility of their trait

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

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

error: aborting due to 3 previous errors
Expand Down
Loading