-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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() {} ``` Remove cruft from old `pub(path)` syntax.
- Loading branch information
Showing
12 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
pub(crate) () fn foo() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: unmatched visibility `pub` | ||
--> $DIR/pub-restricted-error-fn.rs:13:10 | ||
| | ||
13 | pub(crate) () fn foo() {} | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
struct Bar(pub(())); | ||
|
||
struct Foo { | ||
pub(crate) () foo: usize, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: expected identifier, found `(` | ||
--> $DIR/pub-restricted-error.rs:16:16 | ||
| | ||
16 | pub(crate) () foo: usize, | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
pub (.) fn afn() {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: expected identifier, found `.` | ||
--> $DIR/pub-restricted-non-path.rs:13:6 | ||
| | ||
13 | pub (.) fn afn() {} | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
mod a {} | ||
|
||
pub (a) fn afn() {} | ||
pub (b) fn bfn() {} | ||
pub fn privfn() {} | ||
mod x { | ||
mod y { | ||
pub (in x) fn foo() {} | ||
pub (super) fn bar() {} | ||
pub (crate) fn qux() {} | ||
} | ||
} | ||
|
||
mod y { | ||
struct Foo { | ||
pub (crate) c: usize, | ||
pub (super) s: usize, | ||
valid_private: usize, | ||
pub (in y) valid_in_x: usize, | ||
pub (a) invalid: usize, | ||
pub (in x) non_parent_invalid: usize, | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
error: incorrect visibility restriction | ||
--> $DIR/pub-restricted.rs:15:5 | ||
| | ||
15 | pub (a) fn afn() {} | ||
| ^^^ | ||
| | ||
= help: some possible 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() {} | ||
|
||
error: incorrect visibility restriction | ||
--> $DIR/pub-restricted.rs:16:5 | ||
| | ||
16 | pub (b) fn bfn() {} | ||
| ^^^ | ||
| | ||
= help: some possible 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 `b`, add `in` before the path: | ||
| pub (in b) fn bfn() {} | ||
|
||
error: incorrect visibility restriction | ||
--> $DIR/pub-restricted.rs:32:13 | ||
| | ||
32 | pub (a) invalid: usize, | ||
| ^^^ | ||
| | ||
= help: some possible 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) invalid: usize, | ||
|
||
error: visibilities can only be restricted to ancestor modules | ||
--> $DIR/pub-restricted.rs:33:17 | ||
| | ||
33 | pub (in x) non_parent_invalid: usize, | ||
| ^ | ||
|
||
error: aborting due to 4 previous errors | ||
|