Skip to content

Suggest pub const fn for const pub fn #76691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jyn514 opened this issue Sep 14, 2020 · 2 comments
Closed

Suggest pub const fn for const pub fn #76691

jyn514 opened this issue Sep 14, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Sep 14, 2020

Currently the error message is not great:

error: expected identifier, found keyword `pub`
   --> library/core/src/option.rs:391:11
    |
391 |     const pub fn unwrap_or(self, default: T) -> T {
    |           ^^^ expected identifier, found keyword

error: expected one of `:`, `;`, or `=`, found keyword `fn`
   --> library/core/src/option.rs:391:15
    |
160 | impl<T> Option<T> {
    |                   - while parsing this item list starting here
...
391 |     const pub fn unwrap_or(self, default: T) -> T {
    |               ^^ expected one of `:`, `;`, or `=`
...
940 | }
    | - the item list ends here

error: expected identifier, found keyword `pub`
   --> library/core/src/result.rs:801:11
    |
801 |     const pub fn unwrap_or(self, default: T) -> T {
    |           ^^^ expected identifier, found keyword

error: expected one of `:`, `;`, or `=`, found keyword `fn`
   --> library/core/src/result.rs:801:15
    |
257 | impl<T, E> Result<T, E> {
    |                         - while parsing this item list starting here
...
801 |     const pub fn unwrap_or(self, default: T) -> T {
    |               ^^ expected one of `:`, `;`, or `=`
...
829 | }
    | - the item list ends here

It would be better to suggest pub const fn unwrap_or(self, default: T) -> T { instead.

Originally posted by @pickfire in #76330 (comment)

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 14, 2020
@jyn514
Copy link
Member Author

jyn514 commented Sep 14, 2020

Duplicate of #76437.

@jyn514 jyn514 closed this as completed Sep 14, 2020
@pickfire
Copy link
Contributor

pickfire commented Sep 14, 2020

@jyn514 Haha, you posted what I post. How was the solution I posted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants