Skip to content

Commit e32419d

Browse files
committed
correct suggestion for restricted-if-not-fully-private reëxport error
This is still #46248.
1 parent 3b5a5d4 commit e32419d

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

src/librustc_resolve/resolve_imports.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,14 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
898898
.get(&(enum_ident, TypeNS)).expect("resolution exists").borrow()
899899
.binding.expect("binding should exist")
900900
.span;
901-
902901
let enum_def_span = self.session.codemap().def_span(enum_span);
903902
let enum_def_snippet = self.session.codemap()
904903
.span_to_snippet(enum_def_span).expect("snippet should exist");
905-
let suggestion = format!("pub {}", enum_def_snippet);
904+
// potentially need to strip extant `crate`/`pub(path)` for suggestion
905+
let after_vis_index = enum_def_snippet.find("enum")
906+
.expect("`enum` keyword should exist in snippet");
907+
let suggestion = format!("pub {}",
908+
&enum_def_snippet[after_vis_index..]);
906909

907910
self.session
908911
.diag_span_suggestion_once(&mut err,

src/test/ui/resolve/issue-46209-private-enum-variant-reexport.rs

+19
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(crate_visibility_modifier)]
12+
1113
mod rank {
1214
pub use self::Professor::*;
1315
//~^ ERROR enum is private and its variants cannot be reexported
1416
pub use self::Lieutenant::{JuniorGrade, Full};
1517
//~^ ERROR variant is private and cannot be reexported
1618
//~| ERROR variant is private and cannot be reexported
19+
pub use self::PettyOfficer::*;
20+
//~^ ERROR enum is private and its variants cannot be reexported
21+
pub use self::Crewman::*;
22+
//~^ ERROR enum is private and its variants cannot be reexported
1723

1824
enum Professor {
1925
Adjunct,
@@ -27,6 +33,19 @@ mod rank {
2733
Full,
2834
}
2935

36+
pub(in rank) enum PettyOfficer {
37+
SecondClass,
38+
FirstClass,
39+
Chief,
40+
MasterChief
41+
}
42+
43+
crate enum Crewman {
44+
Recruit,
45+
Apprentice,
46+
Full
47+
}
48+
3049
}
3150

3251
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
error: enum is private and its variants cannot be reexported
2-
--> $DIR/issue-46209-private-enum-variant-reexport.rs:12:13
2+
--> $DIR/issue-46209-private-enum-variant-reexport.rs:21:13
33
|
4-
12 | pub use self::Professor::*;
4+
21 | pub use self::Crewman::*;
5+
| ^^^^^^^^^^^^^^^^^
6+
...
7+
43 | crate enum Crewman {
8+
| ------------------ help: consider making the enum public: `pub enum Crewman`
9+
10+
error: enum is private and its variants cannot be reexported
11+
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:13
12+
|
13+
14 | pub use self::Professor::*;
514
| ^^^^^^^^^^^^^^^^^^^
615
...
7-
18 | enum Professor {
16+
24 | enum Professor {
817
| -------------- help: consider making the enum public: `pub enum Professor`
918

1019
error: variant is private and cannot be reexported
11-
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:45
20+
--> $DIR/issue-46209-private-enum-variant-reexport.rs:16:45
1221
|
13-
14 | pub use self::Lieutenant::{JuniorGrade, Full};
22+
16 | pub use self::Lieutenant::{JuniorGrade, Full};
1423
| ^^^^
1524
...
16-
25 | enum Lieutenant {
25+
31 | enum Lieutenant {
1726
| --------------- help: consider making the enum public: `pub enum Lieutenant`
1827

28+
error: enum is private and its variants cannot be reexported
29+
--> $DIR/issue-46209-private-enum-variant-reexport.rs:19:13
30+
|
31+
19 | pub use self::PettyOfficer::*;
32+
| ^^^^^^^^^^^^^^^^^^^^^^
33+
...
34+
36 | pub(in rank) enum PettyOfficer {
35+
| ------------------------------ help: consider making the enum public: `pub enum PettyOfficer`
36+
1937
error: variant is private and cannot be reexported
20-
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:32
38+
--> $DIR/issue-46209-private-enum-variant-reexport.rs:16:32
2139
|
22-
14 | pub use self::Lieutenant::{JuniorGrade, Full};
40+
16 | pub use self::Lieutenant::{JuniorGrade, Full};
2341
| ^^^^^^^^^^^
2442

25-
error: aborting due to 3 previous errors
43+
error: aborting due to 5 previous errors
2644

0 commit comments

Comments
 (0)