Skip to content

Commit

Permalink
Rollup merge of #123841 - Kohei316:remove_qualifier_sugg, r=wesleywiser
Browse files Browse the repository at this point in the history
Improve diagnostic by suggesting to remove visibility qualifier

Resolves #123529
This PR improve diagnostic by suggesting to remove visibility qualifier.
  • Loading branch information
matthiaskrgr committed Apr 12, 2024
2 parents be3ea1d + ac1bee6 commit 15a8b49
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 44 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/messages.ftl
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
.remove_qualifier_sugg = 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
6 changes: 5 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Expand Up @@ -266,7 +266,11 @@ impl<'a> AstValidator<'a> {
return;
}

self.dcx().emit_err(errors::VisibilityNotPermitted { span: vis.span, note });
self.dcx().emit_err(errors::VisibilityNotPermitted {
span: vis.span,
note,
remove_qualifier_sugg: vis.span,
});
}

fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Expand Up @@ -31,6 +31,12 @@ pub struct VisibilityNotPermitted {
pub span: Span,
#[subdiagnostic]
pub note: VisibilityNotPermittedNote,
#[suggestion(
ast_passes_remove_qualifier_sugg,
code = "",
applicability = "machine-applicable"
)]
pub remove_qualifier_sugg: Span,
}

#[derive(Subdiagnostic)]
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/error-codes/E0449.fixed
@@ -0,0 +1,18 @@
//@ run-rustfix

#![allow(warnings)]

struct Bar;

trait Foo {
fn foo();
}

impl Bar {} //~ ERROR E0449

impl Foo for Bar { //~ ERROR E0449
fn foo() {} //~ ERROR E0449
}

fn main() {
}
4 changes: 4 additions & 0 deletions tests/ui/error-codes/E0449.rs
@@ -1,3 +1,7 @@
//@ run-rustfix

#![allow(warnings)]

struct Bar;

trait Foo {
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/error-codes/E0449.stderr
@@ -1,24 +1,24 @@
error[E0449]: visibility qualifiers are not permitted here
--> $DIR/E0449.rs:7:1
--> $DIR/E0449.rs:11:1
|
LL | pub impl Bar {}
| ^^^
| ^^^ help: remove the qualifier
|
= note: place qualifiers on individual impl items instead

error[E0449]: visibility qualifiers are not permitted here
--> $DIR/E0449.rs:9:1
--> $DIR/E0449.rs:13:1
|
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
--> $DIR/E0449.rs:10:5
--> $DIR/E0449.rs:14:5
|
LL | pub fn foo() {}
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-28433.stderr
Expand Up @@ -2,15 +2,15 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-28433.rs:2:5
|
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
--> $DIR/issue-28433.rs:5:5
|
LL | pub(crate) Dove
| ^^^^^^^^^^
| ^^^^^^^^^^ help: remove the qualifier
|
= note: enum variants and their fields always share the visibility of the enum they are in

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/assoc/assoc-static-semantic-fail.stderr
Expand Up @@ -138,7 +138,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/assoc-static-semantic-fail.rs:32:5
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^
| ^^^^^^^^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/default.stderr
Expand Up @@ -21,7 +21,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/default.rs:17:5
|
LL | pub default fn foo<T: Default>() -> T {
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/trait-pub-assoc-const.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-assoc-const.rs:2:5
|
LL | pub const Foo: u32;
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/trait-pub-assoc-ty.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-assoc-ty.rs:2:5
|
LL | pub type Foo;
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/trait-pub-method.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-method.rs:2:5
|
LL | pub fn foo();
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/issue-113860-1.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860-1.rs:12:5
|
LL | pub(self) fn fun() {}
| ^^^^^^^^^
| ^^^^^^^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/issue-113860-2.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860-2.rs:12:5
|
LL | pub(self) type X = Self;
| ^^^^^^^^^
| ^^^^^^^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/issue-113860.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860.rs:12:5
|
LL | pub(self) const X: u32 = 3;
| ^^^^^^^^^
| ^^^^^^^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/issue-29161.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-29161.rs:5:9
|
LL | pub fn default() -> A {
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/privacy/priv-in-bad-locations.stderr
Expand Up @@ -2,31 +2,31 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:1:1
|
LL | pub extern "C" {
| ^^^
| ^^^ help: remove the qualifier
|
= note: place qualifiers on individual foreign items instead

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

error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:13:1
|
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
--> $DIR/priv-in-bad-locations.rs:14:5
|
LL | pub fn foo(&self) {}
| ^^^
| ^^^ help: remove the qualifier
|
= note: trait items always share the visibility of their trait

Expand Down
36 changes: 18 additions & 18 deletions tests/ui/privacy/privacy-sanity.stderr
Expand Up @@ -2,143 +2,143 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:13:1
|
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
--> $DIR/privacy-sanity.rs:14:5
|
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
--> $DIR/privacy-sanity.rs:15:5
|
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
--> $DIR/privacy-sanity.rs:16:5
|
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
--> $DIR/privacy-sanity.rs:18:1
|
LL | pub impl S {
| ^^^
| ^^^ help: remove the qualifier
|
= note: place qualifiers on individual impl items instead

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

error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:39:5
|
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
--> $DIR/privacy-sanity.rs:40:9
|
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
--> $DIR/privacy-sanity.rs:41:9
|
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
--> $DIR/privacy-sanity.rs:42:9
|
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
--> $DIR/privacy-sanity.rs:44:5
|
LL | pub impl S {
| ^^^
| ^^^ help: remove the qualifier
|
= note: place qualifiers on individual impl items instead

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

error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:68:5
|
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
--> $DIR/privacy-sanity.rs:69:9
|
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
--> $DIR/privacy-sanity.rs:70:9
|
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
--> $DIR/privacy-sanity.rs:71:9
|
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
--> $DIR/privacy-sanity.rs:73:5
|
LL | pub impl S {
| ^^^
| ^^^ help: remove the qualifier
|
= note: place qualifiers on individual impl items instead

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

Expand Down

0 comments on commit 15a8b49

Please sign in to comment.