Skip to content

Unwrap on a None in librustc_mir/borrow_check/region_infer when using rustc_args_required_const #74599

Closed

Description

@SuperTails

Code

Minimization by @Kixiron

#![feature(rustc_attrs)]

extern "C" {
    #[rustc_args_required_const(0, 1)]
    pub fn print_raw(data: *const u8, len: usize);
}

pub enum Stmt {
    Print {},
    Let {},
    Loop {}
}

pub fn interpret() {
    match (Stmt::Print {}) {
        Stmt::Let {} => {
            [()].iter().find(|v| *v == &());
        }
        
        Stmt::Print {} => {
            print_raw(b"hello".as_ptr(), 5);
        }

        Stmt::Loop {} => {}
    }
}

Meta

This can only be built on nightly, since it requires an internal rustc attribute on print_raw.

rustc +nightly --version --verbose:

rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

Error output

When run with RUST_BACKTRACE=1 rustc +nightly main.rs

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/librustc_mir/borrow_check/region_infer/mod.rs:2109:35
stack backtrace:
 <... shown below ...>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.46.0-nightly (346aec9b0 2020-07-11) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:530
  12: rust_begin_unwind
             at src/libstd/panicking.rs:437
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::panicking::panic
             at src/libcore/panicking.rs:50
  15: rustc_mir::borrow_check::region_infer::RegionInferenceContext::find_outlives_blame_span
  16: rustc_mir::borrow_check::do_mir_borrowck
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_mir::borrow_check::mir_borrowck
  19: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_query_system::query::plumbing::ensure_query_impl
  23: rustc_session::utils::<impl rustc_session::session::Session>::time
  24: rustc_interface::passes::analysis
  25: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_query_system::query::plumbing::get_query_impl
  28: rustc_middle::ty::context::tls::enter_global
  29: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  30: rustc_span::with_source_map
  31: rustc_interface::interface::create_compiler_and_run
  32: scoped_tls::ScopedKey<T>::set

Activity

  1. added
    C-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.
    on Jul 21, 2020
  2. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Jul 21, 2020
  3. Kixiron commented on Jul 21, 2020

    @Kixiron
    Contributor

    The absolute smallest I was able to get it is this (playground)

    #![feature(rustc_attrs)]
    
    extern {
        // The external function & its parameters don't matter
        #[rustc_args_required_const(0, 1)]
        pub fn print_raw(data: *const u8, len: usize);
    }
    
    pub enum A {
        B {},
        C {},
        D {},
    }
    
    fn main() {
        // The variant used here doesn't matter
        match (A::B {}) {
            A::B {} => {
                [()].iter().find(|v| *v == &());
            }
            A::C {} => {
                print_raw(b"hello".as_ptr(), 5);
            }
            A::D {} => {}
        }
    }

    The specific external function doesn't seem to matter, nor do any variable names

    The panicking line of code is here, as the comment above it says, "Maybe everything is in the same SCC or something?"

  4. mibac138 commented on Jul 21, 2020

    @mibac138
    Contributor

    Further minimized (playground) minimized the wrong ICE, see here for correct minimization or see #74608 for bug report.

    #![feature(rustc_attrs)]
    
    #[rustc_args_required_const(1)]
    fn intrinsic(a: u8){}
    
    fn main() {
        intrinsic(1);
    }

    It appears this issue happens when in #[rustc_args_required_const(x)], x is greater than the amount of a function's parameters

  5. SuperTails commented on Jul 21, 2020

    @SuperTails
    Author

    But in the original example, that's not true--

    extern "C" {
        #[rustc_args_required_const(0, 1)]
        pub fn print_raw(data: *const u8, len: usize);
    }
    
    // later...
    print_raw(b"hello".as_ptr(), 5);

    There are two parameters, and in the code I use both of them, yet the issue still seems to occur.
    Same outcome, different cause?

  6. mibac138 commented on Jul 21, 2020

    @mibac138
    Contributor

    I might've worded my response poorly, however I still stand my ground. I believe that whenever any of the indexes in rustc_args_required_const exceeds the amount of parameters a function has, it will ICE. So, for example

    #[rustc_args_required_const(0, 1)]
    fn x(a: u8, b:u8) {} // won't error as 0 refers to `a`, and 1 refers to `b`
    
    #[rustc_args_required_const(0, 1)]
    fn y(a: u8) {} // will error as 1 refers to nonexistent parameter, i.e. parameter 1 doesn't exist (only parameter 0 exists)

    Does this match with your experience?

  7. Kixiron commented on Jul 21, 2020

    @Kixiron
    Contributor

    This ICE's, it's the original example

    #![feature(rustc_attrs)]
    
    extern "C" {
        #[rustc_args_required_const(0, 1)]
        pub fn print_raw(data: *const u8, len: usize);
    }
    
    pub enum Stmt {
        Print {},
        Let {},
        Loop {}
    }
    
    pub fn interpret() {
        match (Stmt::Print {}) {
            Stmt::Let {} => {
                [()].iter().find(|v| *v == &());
            }
            
            Stmt::Print {} => {
                print_raw(b"hello".as_ptr(), 5);
            }
    
            Stmt::Loop {} => {}
        }
    }

    The indices line up with the function parameters, yet it still ICE's

    extern "C" {
        #[rustc_args_required_const(0, 1)]
        pub fn print_raw(data: *const u8, len: usize);
    }
  8. mibac138 commented on Jul 21, 2020

    @mibac138
    Contributor

    Oh sorry, turns out I have misunderstood what @SuperTails meant. I guess I have accidentally found another ICE then.

    Edit: A bit minimized example this time of the correct ICE (playground)

    #![feature(rustc_attrs)]
    
    #[rustc_args_required_const(0)]
    pub fn print_raw(_: *const u8) {}
    
    fn interpret() {
        match true {
            true => {
                [()].iter().filter(|_| true);
            }
            false => {
                print_raw("".as_ptr());
            }
            _ => {}
        };
    }
  9. isabelmu commented on Jan 22, 2021

    @isabelmu
    Contributor

    The snippet in the original report starts ICE'ing on nightly-2019-10-05. Tracked it down to 2180c24. (EDIT: same for the minimized example.)

  10. Alexendoo commented on May 14, 2021

    @Alexendoo
    Member

    rustc_args_required_const has been removed - #85110

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

    C-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.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions