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

ICE: Use a type that has already been pub used. #45876

Closed
NoelWidmer opened this issue Nov 8, 2017 · 5 comments
Closed

ICE: Use a type that has already been pub used. #45876

NoelWidmer opened this issue Nov 8, 2017 · 5 comments
Labels
A-visibility Area: Visibility / privacy C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@NoelWidmer
Copy link

NoelWidmer commented Nov 8, 2017

Summary:
The compilation of my source panics. I believe this happens because I use a struct that has already been pub used. You may be able to reproduce the issue using this github commit from my repository.

I tried this code:
The following source is inside the file: src\syntactic_analysis\nodes\item\mod.rs
These are the complete file contents.

mod visibility;
pub use self::visibility::*;

mod item_raw;
pub use self::item_raw::*;

use syntactic_analysis::nodes::Node;
use syntactic_analysis::nodes::Visibility;



pub struct Item {
    pub visibility: Option<Visibility>,
    pub item_raw: ItemRaw
}



impl Node for Item {
    
    fn get_nodes(&self) -> Vec<&Node> {
        match self.visibility {
            Some(ref visibility) => vec![
                visibility, 
                &self.item_raw
            ], 
            None => vec![
                &self.item_raw
            ]
        }
    }
}

Modifying the file to the following snippet resolves the issue:
(Only one line has been modified)

mod visibility;
pub use self::visibility::*;

mod item_raw;
pub use self::item_raw::*;

use syntactic_analysis::nodes::Node;
use syntactic_analysis::nodes::SingleTokenNode; // This line has been modified.



pub struct Item {
    pub visibility: Option<Visibility>,
    pub item_raw: ItemRaw
}



impl Node for Item {
    
    fn get_nodes(&self) -> Vec<&Node> {
        match self.visibility {
            Some(ref visibility) => vec![
                visibility, 
                &self.item_raw
            ], 
            None => vec![
                &self.item_raw
            ]
        }
    }
}

I expected to see this happen:
A compilation result.

Instead, this happened:

error: internal compiler error: cat_expr Errd
  --> src\syntactic_analysis\nodes\item\mod.rs:24:17
   |
24 |                 visibility,
   |                 ^^^^^^^^^^

error: internal compiler error: src\librustc\hir\def.rs:162: attempted .def_id() on invalid def: Err

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0 (3b72af97e 2017-10-09) running on x86_64-pc-windows-msvc

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:490:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `inkc`.

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose:

rustc 1.21.0 (3b72af97e 2017-10-09)
binary: rustc
commit-hash: 3b72af97e42989b2fe104d8edbaee123cdf7c58f
commit-date: 2017-10-09
host: x86_64-pc-windows-msvc
release: 1.21.0
LLVM version: 4.0

Backtrace:

0: _rdl_shrink_in_place
1: std::panicking::Location::column
2: std::panicking::Location::column
3: std::panicking::rust_panic_with_hook
4: <unknown>
5: rustc_errors::Handler::bug
6: rustc::session::bug_fmt
7: rustc::session::bug_fmt
8: rustc::session::bug_fmt
9: rustc::hir::def::Def::def_id
10: <rustc_privacy::TypePrivacyVisitor<'a, 'tcx> as rustc::ty::fold::TypeVisitor<'tcx>>::visit_ty
11: <unknown>
12: <unknown>
13: <rustc_privacy::ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
@shepmaster
Copy link
Member

I was unable to reproduce the ICE from any of the 10 most recent commits of that repository (starting at 41e849b3fea70753e12a2e04444c80593fb49837). I attempted on macOS with Rust 1.21.0.

for r in $(git rev-list origin/master~10..origin/master); do git checkout $r; echo $r; cargo build; done

@NoelWidmer NoelWidmer changed the title The compiler unexpectedly panicked. This is a bug. ICE: Use a type that has already been pub used. Nov 8, 2017
@NoelWidmer
Copy link
Author

NoelWidmer commented Nov 8, 2017

@shepmaster None of the 10 commits you used can be used to reproduce the issue. I can use this commit to reproduce the issue on 2 of my machines.

@shepmaster
Copy link
Member

Yep, I can confirm I see the ICE now.

@shepmaster
Copy link
Member

shepmaster commented Nov 8, 2017

Here is a reduced testcase:

mod item {
    mod visibility {
        pub struct Visibility;
    }
    pub use self::visibility::*;

    use Visibility;

    struct Item(Visibility);

    impl Item {
        fn get_nodes(&self) {
            self.0;
        }
    }
}
pub use self::item::*;

fn main() {}
error: internal compiler error: cat_expr Errd
  --> src/main.rs:13:13
   |
13 |             self.0;
   |             ^^^^^^

I see this fail on:

  • macOS 1.21.0 & 1.23.0-nightly (d9f124965 2017-10-27)
  • Linux 1.21.0 & 1.23.0-nightly (2017-11-07 ee2286149a5f0b148334841d4f067dc819dcca3b)

@shepmaster
Copy link
Member

It appears to me that item::visibility::Visibility is reachable through multiple paths:

  1. pub use self::visibility::*; -> item::visibility::Visibility
  2. use Visibility; -> pub use self::item::*; -> item::visibility::Visibility

I'd guess the problem lies therein

@shepmaster shepmaster added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-visibility Area: Visibility / privacy C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 8, 2017
@bors bors closed this as completed in f6f9cbe Dec 27, 2017
@estebank estebank reopened this Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-visibility Area: Visibility / privacy C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants