Skip to content

Commit

Permalink
correct suggestion for restricted-if-not-fully-private reëxport error
Browse files Browse the repository at this point in the history
This is still rust-lang#46248.
  • Loading branch information
zackmdavis committed Nov 26, 2017
1 parent 3b5a5d4 commit e32419d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,14 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
.get(&(enum_ident, TypeNS)).expect("resolution exists").borrow()
.binding.expect("binding should exist")
.span;

let enum_def_span = self.session.codemap().def_span(enum_span);
let enum_def_snippet = self.session.codemap()
.span_to_snippet(enum_def_span).expect("snippet should exist");
let suggestion = format!("pub {}", enum_def_snippet);
// potentially need to strip extant `crate`/`pub(path)` for suggestion
let after_vis_index = enum_def_snippet.find("enum")
.expect("`enum` keyword should exist in snippet");
let suggestion = format!("pub {}",
&enum_def_snippet[after_vis_index..]);

self.session
.diag_span_suggestion_once(&mut err,
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/resolve/issue-46209-private-enum-variant-reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(crate_visibility_modifier)]

mod rank {
pub use self::Professor::*;
//~^ ERROR enum is private and its variants cannot be reexported
pub use self::Lieutenant::{JuniorGrade, Full};
//~^ ERROR variant is private and cannot be reexported
//~| ERROR variant is private and cannot be reexported
pub use self::PettyOfficer::*;
//~^ ERROR enum is private and its variants cannot be reexported
pub use self::Crewman::*;
//~^ ERROR enum is private and its variants cannot be reexported

enum Professor {
Adjunct,
Expand All @@ -27,6 +33,19 @@ mod rank {
Full,
}

pub(in rank) enum PettyOfficer {
SecondClass,
FirstClass,
Chief,
MasterChief
}

crate enum Crewman {
Recruit,
Apprentice,
Full
}

}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
error: enum is private and its variants cannot be reexported
--> $DIR/issue-46209-private-enum-variant-reexport.rs:12:13
--> $DIR/issue-46209-private-enum-variant-reexport.rs:21:13
|
12 | pub use self::Professor::*;
21 | pub use self::Crewman::*;
| ^^^^^^^^^^^^^^^^^
...
43 | crate enum Crewman {
| ------------------ help: consider making the enum public: `pub enum Crewman`

error: enum is private and its variants cannot be reexported
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:13
|
14 | pub use self::Professor::*;
| ^^^^^^^^^^^^^^^^^^^
...
18 | enum Professor {
24 | enum Professor {
| -------------- help: consider making the enum public: `pub enum Professor`

error: variant is private and cannot be reexported
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:45
--> $DIR/issue-46209-private-enum-variant-reexport.rs:16:45
|
14 | pub use self::Lieutenant::{JuniorGrade, Full};
16 | pub use self::Lieutenant::{JuniorGrade, Full};
| ^^^^
...
25 | enum Lieutenant {
31 | enum Lieutenant {
| --------------- help: consider making the enum public: `pub enum Lieutenant`

error: enum is private and its variants cannot be reexported
--> $DIR/issue-46209-private-enum-variant-reexport.rs:19:13
|
19 | pub use self::PettyOfficer::*;
| ^^^^^^^^^^^^^^^^^^^^^^
...
36 | pub(in rank) enum PettyOfficer {
| ------------------------------ help: consider making the enum public: `pub enum PettyOfficer`

error: variant is private and cannot be reexported
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:32
--> $DIR/issue-46209-private-enum-variant-reexport.rs:16:32
|
14 | pub use self::Lieutenant::{JuniorGrade, Full};
16 | pub use self::Lieutenant::{JuniorGrade, Full};
| ^^^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 5 previous errors

0 comments on commit e32419d

Please sign in to comment.