Skip to content

Edge case does not suggest changing invalid public with pub #101626

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

mod test {
    public const X: i32 = 123;
}

fn main() {
    println!("{}", test::X);
}

The current output on stable 1.63.0:

   Compiling playground v0.0.1 (/playground)
error: expected one of `!` or `::`, found keyword `const`
 --> src/main.rs:2:12
  |
2 |     public const X: i32 = 123;
  |            ^^^^^ expected one of `!` or `::`

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

The current output on Beta version 1.64.0-beta.6 (2022-09-09 25912c0):

   Compiling playground v0.0.1 (/playground)
error: expected one of `!` or `::`, found keyword `const`
 --> src/main.rs:2:12
  |
2 |     public const X: i32 = 123;
  |            ^^^^^ expected one of `!` or `::`
  |
help: write `pub` instead of `public` to make the item public
  |
2 |     pub const X: i32 = 123;
  |     ~~~

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

The current output on Nightly version 1.65.0-nightly (2022-09-09 1d37ed6):

   Compiling playground v0.0.1 (/playground)
error: expected one of `!` or `::`, found keyword `const`
 --> src/main.rs:2:12
  |
2 |     public const X: i32 = 123;
  |            ^^^^^ expected one of `!` or `::`

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

Since #99903 ( cc @gimbles ) is somewhat recent the help diagnostics improvement currently is only on beta. However, the latest nightly has regressions regarding the suggestion as shown above. Hence, the output should suggest changing public with pub as that is the desired output.

Note: base issue for improved diagnostics (public -> pub): #99653

Note: since this is technically a regression from beta to nightly, what should be the appropriate label to add? The one below this?
@rustbot label +regression-untriaged

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions