Improve diagnostic by suggesting to remove visibility qualifier

This commit is contained in:
morine0122 2024-04-12 12:40:11 +09:00
parent 30840c53f4
commit ac1bee6493
19 changed files with 77 additions and 44 deletions

View File

@ -273,6 +273,7 @@ ast_passes_visibility_not_permitted =
.trait_impl = trait items always share the visibility of their trait .trait_impl = trait items always share the visibility of their trait
.individual_impl_items = place qualifiers on individual impl items instead .individual_impl_items = place qualifiers on individual impl items instead
.individual_foreign_items = place qualifiers on individual foreign 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 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 .note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information

View File

@ -266,7 +266,11 @@ impl<'a> AstValidator<'a> {
return; 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)) { fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {

View File

@ -31,6 +31,12 @@ pub struct VisibilityNotPermitted {
pub span: Span, pub span: Span,
#[subdiagnostic] #[subdiagnostic]
pub note: VisibilityNotPermittedNote, pub note: VisibilityNotPermittedNote,
#[suggestion(
ast_passes_remove_qualifier_sugg,
code = "",
applicability = "machine-applicable"
)]
pub remove_qualifier_sugg: Span,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]

View File

@ -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() {
}

View File

@ -1,3 +1,7 @@
//@ run-rustfix
#![allow(warnings)]
struct Bar; struct Bar;
trait Foo { trait Foo {

View File

@ -1,24 +1,24 @@
error[E0449]: visibility qualifiers are not permitted here error[E0449]: visibility qualifiers are not permitted here
--> $DIR/E0449.rs:7:1 --> $DIR/E0449.rs:11:1
| |
LL | pub impl Bar {} LL | pub impl Bar {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual impl items instead = note: place qualifiers on individual impl items instead
error[E0449]: visibility qualifiers are not permitted here error[E0449]: visibility qualifiers are not permitted here
--> $DIR/E0449.rs:9:1 --> $DIR/E0449.rs:13:1
| |
LL | pub impl Foo for Bar { LL | pub impl Foo for Bar {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
error[E0449]: visibility qualifiers are not permitted here error[E0449]: visibility qualifiers are not permitted here
--> $DIR/E0449.rs:10:5 --> $DIR/E0449.rs:14:5
| |
LL | pub fn foo() {} LL | pub fn foo() {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-28433.rs:2:5 --> $DIR/issue-28433.rs:2:5
| |
LL | pub Duck, LL | pub Duck,
| ^^^ | ^^^ help: remove the qualifier
| |
= note: enum variants and their fields always share the visibility of the enum they are in = note: enum variants and their fields always share the visibility of the enum they are in
@ -10,7 +10,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-28433.rs:5:5 --> $DIR/issue-28433.rs:5:5
| |
LL | pub(crate) Dove LL | pub(crate) Dove
| ^^^^^^^^^^ | ^^^^^^^^^^ help: remove the qualifier
| |
= note: enum variants and their fields always share the visibility of the enum they are in = note: enum variants and their fields always share the visibility of the enum they are in

View File

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

View File

@ -21,7 +21,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/default.rs:17:5 --> $DIR/default.rs:17:5
| |
LL | pub default fn foo<T: Default>() -> T { LL | pub default fn foo<T: Default>() -> T {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-assoc-const.rs:2:5 --> $DIR/trait-pub-assoc-const.rs:2:5
| |
LL | pub const Foo: u32; LL | pub const Foo: u32;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-assoc-ty.rs:2:5 --> $DIR/trait-pub-assoc-ty.rs:2:5
| |
LL | pub type Foo; LL | pub type Foo;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/trait-pub-method.rs:2:5 --> $DIR/trait-pub-method.rs:2:5
| |
LL | pub fn foo(); LL | pub fn foo();
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:1:1 --> $DIR/priv-in-bad-locations.rs:1:1
| |
LL | pub extern "C" { LL | pub extern "C" {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual foreign items instead = note: place qualifiers on individual foreign items instead
@ -10,7 +10,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:11:1 --> $DIR/priv-in-bad-locations.rs:11:1
| |
LL | pub impl B {} LL | pub impl B {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual impl items instead = note: place qualifiers on individual impl items instead
@ -18,7 +18,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:13:1 --> $DIR/priv-in-bad-locations.rs:13:1
| |
LL | pub impl A for B { LL | pub impl A for B {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -26,7 +26,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/priv-in-bad-locations.rs:14:5 --> $DIR/priv-in-bad-locations.rs:14:5
| |
LL | pub fn foo(&self) {} LL | pub fn foo(&self) {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:13:1 --> $DIR/privacy-sanity.rs:13:1
| |
LL | pub impl Tr for S { LL | pub impl Tr for S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -10,7 +10,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:14:5 --> $DIR/privacy-sanity.rs:14:5
| |
LL | pub fn f() {} LL | pub fn f() {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -18,7 +18,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:15:5 --> $DIR/privacy-sanity.rs:15:5
| |
LL | pub const C: u8 = 0; LL | pub const C: u8 = 0;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -26,7 +26,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:16:5 --> $DIR/privacy-sanity.rs:16:5
| |
LL | pub type T = u8; LL | pub type T = u8;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -34,7 +34,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:18:1 --> $DIR/privacy-sanity.rs:18:1
| |
LL | pub impl S { LL | pub impl S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual impl items instead = note: place qualifiers on individual impl items instead
@ -42,7 +42,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:23:1 --> $DIR/privacy-sanity.rs:23:1
| |
LL | pub extern "C" { LL | pub extern "C" {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual foreign items instead = note: place qualifiers on individual foreign items instead
@ -50,7 +50,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:39:5 --> $DIR/privacy-sanity.rs:39:5
| |
LL | pub impl Tr for S { LL | pub impl Tr for S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -58,7 +58,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:40:9 --> $DIR/privacy-sanity.rs:40:9
| |
LL | pub fn f() {} LL | pub fn f() {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -66,7 +66,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:41:9 --> $DIR/privacy-sanity.rs:41:9
| |
LL | pub const C: u8 = 0; LL | pub const C: u8 = 0;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -74,7 +74,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:42:9 --> $DIR/privacy-sanity.rs:42:9
| |
LL | pub type T = u8; LL | pub type T = u8;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -82,7 +82,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:44:5 --> $DIR/privacy-sanity.rs:44:5
| |
LL | pub impl S { LL | pub impl S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual impl items instead = note: place qualifiers on individual impl items instead
@ -90,7 +90,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:49:5 --> $DIR/privacy-sanity.rs:49:5
| |
LL | pub extern "C" { LL | pub extern "C" {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual foreign items instead = note: place qualifiers on individual foreign items instead
@ -98,7 +98,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:68:5 --> $DIR/privacy-sanity.rs:68:5
| |
LL | pub impl Tr for S { LL | pub impl Tr for S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -106,7 +106,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:69:9 --> $DIR/privacy-sanity.rs:69:9
| |
LL | pub fn f() {} LL | pub fn f() {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -114,7 +114,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:70:9 --> $DIR/privacy-sanity.rs:70:9
| |
LL | pub const C: u8 = 0; LL | pub const C: u8 = 0;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -122,7 +122,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:71:9 --> $DIR/privacy-sanity.rs:71:9
| |
LL | pub type T = u8; LL | pub type T = u8;
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -130,7 +130,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:73:5 --> $DIR/privacy-sanity.rs:73:5
| |
LL | pub impl S { LL | pub impl S {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual impl items instead = note: place qualifiers on individual impl items instead
@ -138,7 +138,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/privacy-sanity.rs:78:5 --> $DIR/privacy-sanity.rs:78:5
| |
LL | pub extern "C" { LL | pub extern "C" {
| ^^^ | ^^^ help: remove the qualifier
| |
= note: place qualifiers on individual foreign items instead = note: place qualifiers on individual foreign items instead

View File

@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/useless-pub.rs:8:5 --> $DIR/useless-pub.rs:8:5
| |
LL | pub fn foo(&self) {} LL | pub fn foo(&self) {}
| ^^^ | ^^^ help: remove the qualifier
| |
= note: trait items always share the visibility of their trait = note: trait items always share the visibility of their trait
@ -10,7 +10,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/useless-pub.rs:12:10 --> $DIR/useless-pub.rs:12:10
| |
LL | V1 { pub f: i32 }, 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 = note: enum variants and their fields always share the visibility of the enum they are in
@ -18,7 +18,7 @@ error[E0449]: visibility qualifiers are not permitted here
--> $DIR/useless-pub.rs:13:8 --> $DIR/useless-pub.rs:13:8
| |
LL | V2(pub i32), LL | V2(pub i32),
| ^^^ | ^^^ help: remove the qualifier
| |
= note: enum variants and their fields always share the visibility of the enum they are in = note: enum variants and their fields always share the visibility of the enum they are in