Skip to content

Error suggests additional pub when using pub pub fn ... #87694

Closed
@poliorcetics

Description

@poliorcetics

I tried this code:

pub pub fn toto() {}

I expected to see this happen: Rust tells me to fix the issue by removing a pub.

Instead, this happened: Rust tells me to add a pub before the existing ones: pub pub pub:

3 | pub pub fn toto() {}
  |     ^^^
  |     |
  |     expected one of 9 possible tokens
  |     help: visibility `pub` must come before `pub pub`: `pub pub pub`

This will also be an issue with const async const (and similar errors with other keywords) after #87235 is merged.

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (2827db2b1 2021-08-01)
binary: rustc
commit-hash: 2827db2b137e899242e81f1beea39ae26e245153
commit-date: 2021-08-01
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 12.0.1
Backtrace

   Compiling playground v0.1.0 (/Users/alexis/Projects/rust/playground)
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `unsafe`, or `use`, found keyword `pub`
 --> src/main.rs:3:5
  |
3 | pub pub fn toto() {}
  |     ^^^
  |     |
  |     expected one of 9 possible tokens
  |     help: visibility `pub` must come before `pub pub`: `pub pub pub`

error: could not compile `playground` due to previous error

@rustbot label A-diagnostics T-compiler

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions