Skip to content
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

Subpar error message on pub (ident) fn foo #40599

Closed
pnkfelix opened this issue Mar 17, 2017 · 1 comment · Fixed by #40627
Closed

Subpar error message on pub (ident) fn foo #40599

pnkfelix opened this issue Mar 17, 2017 · 1 comment · Fixed by #40627

Comments

@pnkfelix
Copy link
Member

Someone who had code with the old pub_restricted feature is going to get pretty bad error message feedback:

#![feature(pub_restricted)]
mod a { pub (a) fn foo() -> i32 { 13 } }

fn main() {}

Here's the message you get (ever since pub(in path) was implemented, sometime after March 4th:

error: unmatched visibility `pub`
 --> pub_restricted.rs:2:9
  |
2 | mod a { pub (a) fn foo() -> i32 { 13 } }
  |         ^^^

(At the very least, it would be good if it highlighted pub (a) in its entirety, not just pub...)

Also, someone who doesn't know about pub restricted and just has a syntactic typo is also going to have problems here, since it is very confusing that the compiler seems to be saying that it doesn't know about the pub visibility, when that is one of the most fundamental visibilities.

@estebank
Copy link
Contributor

estebank commented Mar 18, 2017

#40627 proposes the following output for a given statement pub (a) fn afn() {}:

error: incorrect restriction in `pub`
  --> file.rs:15:1
   |
15 | pub (a) fn afn() {}
   |     ^^^
   |
   = help: valid visibility restrictions are:
           `pub`: visible on every module that imports this module
           `pub(crate)`: visible only on the current crate
           `pub(super)`: visible only in the current module's parent
           `pub(in path::to::module)`: visible only on the specified path
           `pub(self)` or ``: visible only in the current module
help: to make this visible only to module `a`, add `in` before the path:
   | pub (in a) fn afn() {}

frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 23, 2017
…nkov

Add diagnostic for incorrect `pub (restriction)`

Given the following statement

```rust
pub (a) fn afn() {}
```

Provide the following diagnostic:

```rust
error: incorrect restriction in `pub`
  --> file.rs:15:1
   |
15 | pub (a) fn afn() {}
   |     ^^^
   |
   = help: some valid visibility restrictions are:
           `pub(crate)`: visible only on the current crate
           `pub(super)`: visible only in the current module's parent
           `pub(in path::to::module)`: visible only on the specified path
help: to make this visible only to module `a`, add `in` before the path:
   | pub (in a) fn afn() {}
```

Follow up to rust-lang#40340, fix rust-lang#40599, cc rust-lang#32409.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants