-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in which the private/restricted-in-public error messaging gets specific
April 2016's Issue #33174 called out the E0446 diagnostics as confusing. While adding the name of the restricted type to the message (548e681) clarified matters somewhat, Esteban Küber pointed out that we could stand to place a secondary span on the restricted type. Here, we differentiate between crate-visible, truly private, and otherwise restricted types, and place a secondary span specifically on the visibility modifier of the restricted type's declaration (which we can do now that HIR visibilities have spans!). At long last, this resolves #33174.
- Loading branch information
1 parent
8d1cbb0
commit c2d44b2
Showing
4 changed files
with
84 additions
and
6 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
38 changes: 38 additions & 0 deletions
38
src/test/ui/pub/issue-33174-restricted-type-in-public-interface.rs
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,38 @@ | ||
// Copyright 2018 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. | ||
|
||
#![allow(non_camel_case_types)] // genus is always capitalized | ||
|
||
pub(crate) struct Snail; | ||
//~^ NOTE `Snail` declared as crate-visible | ||
|
||
mod sea { | ||
pub(super) struct Turtle; | ||
//~^ NOTE `sea::Turtle` declared as restricted | ||
} | ||
|
||
struct Tortoise; | ||
//~^ NOTE `Tortoise` declared as private | ||
|
||
pub struct Shell<T> { | ||
pub(crate) creature: T, | ||
} | ||
|
||
pub type Helix_pomatia = Shell<Snail>; | ||
//~^ ERROR crate-visible type `Snail` in public interface | ||
//~| NOTE can't leak crate-visible type | ||
pub type Dermochelys_coriacea = Shell<sea::Turtle>; | ||
//~^ ERROR restricted type `sea::Turtle` in public interface | ||
//~| NOTE can't leak restricted type | ||
pub type Testudo_graeca = Shell<Tortoise>; | ||
//~^ ERROR private type `Tortoise` in public interface | ||
//~| NOTE can't leak private type | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/pub/issue-33174-restricted-type-in-public-interface.stderr
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,30 @@ | ||
error[E0446]: crate-visible type `Snail` in public interface | ||
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1 | ||
| | ||
LL | pub(crate) struct Snail; | ||
| ---------- `Snail` declared as crate-visible | ||
... | ||
LL | pub type Helix_pomatia = Shell<Snail>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-visible type | ||
|
||
error[E0446]: restricted type `sea::Turtle` in public interface | ||
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:31:1 | ||
| | ||
LL | pub(super) struct Turtle; | ||
| ---------- `sea::Turtle` declared as restricted | ||
... | ||
LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak restricted type | ||
|
||
error[E0446]: private type `Tortoise` in public interface | ||
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:34:1 | ||
| | ||
LL | struct Tortoise; | ||
| - `Tortoise` declared as private | ||
... | ||
LL | pub type Testudo_graeca = Shell<Tortoise>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0446`. |