Skip to content

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

Description

@NoelWidmer

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

Activity

  1. shepmaster commented on Nov 8, 2017

    @shepmaster
    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
    
  2. changed the title [-]The compiler unexpectedly panicked. This is a bug.[/-] [+]ICE: Use a type that has already been pub used.[/+] on Nov 8, 2017
  3. NoelWidmer commented on Nov 8, 2017

    @NoelWidmer
    Author

    @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.

  4. shepmaster commented on Nov 8, 2017

    @shepmaster
    Member

    Yep, I can confirm I see the ICE now.

  5. shepmaster commented on Nov 8, 2017

    @shepmaster
    Member

    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)
  6. shepmaster commented on Nov 8, 2017

    @shepmaster
    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

  7. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    A-visibilityArea: Visibility / privacy
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions