about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_ast_passes/messages.ftl1
-rw-r--r--compiler/rustc_ast_passes/src/ast_validation.rs6
-rw-r--r--compiler/rustc_ast_passes/src/errors.rs6
-rw-r--r--tests/ui/error-codes/E0449.fixed18
-rw-r--r--tests/ui/error-codes/E0449.rs4
-rw-r--r--tests/ui/error-codes/E0449.stderr12
-rw-r--r--tests/ui/issues/issue-28433.stderr4
-rw-r--r--tests/ui/parser/assoc/assoc-static-semantic-fail.stderr4
-rw-r--r--tests/ui/parser/default.stderr2
-rw-r--r--tests/ui/parser/trait-pub-assoc-const.stderr2
-rw-r--r--tests/ui/parser/trait-pub-assoc-ty.stderr2
-rw-r--r--tests/ui/parser/trait-pub-method.stderr2
-rw-r--r--tests/ui/privacy/issue-113860-1.stderr2
-rw-r--r--tests/ui/privacy/issue-113860-2.stderr2
-rw-r--r--tests/ui/privacy/issue-113860.stderr2
-rw-r--r--tests/ui/privacy/issue-29161.stderr2
-rw-r--r--tests/ui/privacy/priv-in-bad-locations.stderr8
-rw-r--r--tests/ui/privacy/privacy-sanity.stderr36
-rw-r--r--tests/ui/privacy/useless-pub.stderr6
19 files changed, 77 insertions, 44 deletions
diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl
index ac3799e7a05..a3731e94276 100644
--- a/compiler/rustc_ast_passes/messages.ftl
+++ b/compiler/rustc_ast_passes/messages.ftl
@@ -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
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 093a985495c..a386bc70ad4 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -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)) {
diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs
index 8ae9f7d3966..f397c949e04 100644
--- a/compiler/rustc_ast_passes/src/errors.rs
+++ b/compiler/rustc_ast_passes/src/errors.rs
@@ -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)]
diff --git a/tests/ui/error-codes/E0449.fixed b/tests/ui/error-codes/E0449.fixed
new file mode 100644
index 00000000000..c7b4566303d
--- /dev/null
+++ b/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() {
+}
diff --git a/tests/ui/error-codes/E0449.rs b/tests/ui/error-codes/E0449.rs
index eba0d479e97..32d9b35169c 100644
--- a/tests/ui/error-codes/E0449.rs
+++ b/tests/ui/error-codes/E0449.rs
@@ -1,3 +1,7 @@
+//@ run-rustfix
+
+#![allow(warnings)]
+
 struct Bar;
 
 trait Foo {
diff --git a/tests/ui/error-codes/E0449.stderr b/tests/ui/error-codes/E0449.stderr
index cf41bcce8c2..c6a98269a19 100644
--- a/tests/ui/error-codes/E0449.stderr
+++ b/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
 
diff --git a/tests/ui/issues/issue-28433.stderr b/tests/ui/issues/issue-28433.stderr
index 5fb8a89621c..0fa67e35f1d 100644
--- a/tests/ui/issues/issue-28433.stderr
+++ b/tests/ui/issues/issue-28433.stderr
@@ -2,7 +2,7 @@ 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
 
@@ -10,7 +10,7 @@ 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
 
diff --git a/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr b/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr
index 8178bd22373..cc21df77353 100644
--- a/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr
+++ b/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr
@@ -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
 
@@ -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
 
diff --git a/tests/ui/parser/default.stderr b/tests/ui/parser/default.stderr
index e6330f368d9..c420e5a774d 100644
--- a/tests/ui/parser/default.stderr
+++ b/tests/ui/parser/default.stderr
@@ -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
 
diff --git a/tests/ui/parser/trait-pub-assoc-const.stderr b/tests/ui/parser/trait-pub-assoc-const.stderr
index 436f6a3909c..1bace786b21 100644
--- a/tests/ui/parser/trait-pub-assoc-const.stderr
+++ b/tests/ui/parser/trait-pub-assoc-const.stderr
@@ -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
 
diff --git a/tests/ui/parser/trait-pub-assoc-ty.stderr b/tests/ui/parser/trait-pub-assoc-ty.stderr
index 279e3a95354..28e05bdc630 100644
--- a/tests/ui/parser/trait-pub-assoc-ty.stderr
+++ b/tests/ui/parser/trait-pub-assoc-ty.stderr
@@ -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
 
diff --git a/tests/ui/parser/trait-pub-method.stderr b/tests/ui/parser/trait-pub-method.stderr
index ee8b6f7cb62..cc1ba0eaaea 100644
--- a/tests/ui/parser/trait-pub-method.stderr
+++ b/tests/ui/parser/trait-pub-method.stderr
@@ -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
 
diff --git a/tests/ui/privacy/issue-113860-1.stderr b/tests/ui/privacy/issue-113860-1.stderr
index c33ce26f0f6..c05452fb51c 100644
--- a/tests/ui/privacy/issue-113860-1.stderr
+++ b/tests/ui/privacy/issue-113860-1.stderr
@@ -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
 
diff --git a/tests/ui/privacy/issue-113860-2.stderr b/tests/ui/privacy/issue-113860-2.stderr
index 6748bc27668..c53c490ca1e 100644
--- a/tests/ui/privacy/issue-113860-2.stderr
+++ b/tests/ui/privacy/issue-113860-2.stderr
@@ -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
 
diff --git a/tests/ui/privacy/issue-113860.stderr b/tests/ui/privacy/issue-113860.stderr
index 3204f4ff916..d813b740ac5 100644
--- a/tests/ui/privacy/issue-113860.stderr
+++ b/tests/ui/privacy/issue-113860.stderr
@@ -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
 
diff --git a/tests/ui/privacy/issue-29161.stderr b/tests/ui/privacy/issue-29161.stderr
index 1a6c80499a1..f8911cb09c1 100644
--- a/tests/ui/privacy/issue-29161.stderr
+++ b/tests/ui/privacy/issue-29161.stderr
@@ -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
 
diff --git a/tests/ui/privacy/priv-in-bad-locations.stderr b/tests/ui/privacy/priv-in-bad-locations.stderr
index 70dab5bfe13..93a0eabb914 100644
--- a/tests/ui/privacy/priv-in-bad-locations.stderr
+++ b/tests/ui/privacy/priv-in-bad-locations.stderr
@@ -2,7 +2,7 @@ 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
 
@@ -10,7 +10,7 @@ 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
 
@@ -18,7 +18,7 @@ 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
 
@@ -26,7 +26,7 @@ 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
 
diff --git a/tests/ui/privacy/privacy-sanity.stderr b/tests/ui/privacy/privacy-sanity.stderr
index a537f8c1901..0acb05cbaba 100644
--- a/tests/ui/privacy/privacy-sanity.stderr
+++ b/tests/ui/privacy/privacy-sanity.stderr
@@ -2,7 +2,7 @@ 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
 
@@ -10,7 +10,7 @@ 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
 
@@ -18,7 +18,7 @@ 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
 
@@ -26,7 +26,7 @@ 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
 
@@ -34,7 +34,7 @@ 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
 
@@ -42,7 +42,7 @@ 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
 
@@ -50,7 +50,7 @@ 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
 
@@ -58,7 +58,7 @@ 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
 
@@ -66,7 +66,7 @@ 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
 
@@ -74,7 +74,7 @@ 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
 
@@ -82,7 +82,7 @@ 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
 
@@ -90,7 +90,7 @@ 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
 
@@ -98,7 +98,7 @@ 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
 
@@ -106,7 +106,7 @@ 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
 
@@ -114,7 +114,7 @@ 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
 
@@ -122,7 +122,7 @@ 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
 
@@ -130,7 +130,7 @@ 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
 
@@ -138,7 +138,7 @@ 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
 
diff --git a/tests/ui/privacy/useless-pub.stderr b/tests/ui/privacy/useless-pub.stderr
index 73497e3fed5..7d064c12a09 100644
--- a/tests/ui/privacy/useless-pub.stderr
+++ b/tests/ui/privacy/useless-pub.stderr
@@ -2,7 +2,7 @@ error[E0449]: visibility qualifiers are not permitted here
   --> $DIR/useless-pub.rs:8:5
    |
 LL |     pub fn foo(&self) {}
-   |     ^^^
+   |     ^^^ help: remove the qualifier
    |
    = 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
    |
 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
 
@@ -18,7 +18,7 @@ error[E0449]: visibility qualifiers are not permitted here
   --> $DIR/useless-pub.rs:13:8
    |
 LL |     V2(pub i32),
-   |        ^^^
+   |        ^^^ help: remove the qualifier
    |
    = note: enum variants and their fields always share the visibility of the enum they are in