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

error: internal compiler error: src/librustc_mir_build/hair/pattern/_match.rs:318: cannot deref ByRef #70972

Closed
jyn514 opened this issue Apr 10, 2020 · 4 comments · Fixed by #71038
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Apr 10, 2020

Code

use std::sync::atomic::{AtomicPtr, Ordering};

const P: &dyn T = &S as &dyn T;
static mut LOGGER: AtomicPtr<&dyn T> = AtomicPtr::new(&mut P);

pub trait T {}
struct S;
impl T for S {}

pub fn f() {
    match *LOGGER.load(Ordering::SeqCst) {
        P | _ => {}
    }
}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (77621317d 2020-03-28)
binary: rustc
commit-hash: 77621317d643cc5d13da60b26ab68b057668e688
commit-date: 2020-03-28
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

Note that the error is also present on stable (1.42.0).

Error output

error: internal compiler error: src/librustc_mir_build/hair/pattern/_match.rs:318: cannot deref ByRef {
    alloc: Allocation {
        bytes: [
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ],
        relocations: Relocations(
            SortedMap {
                data: [
                    (
                        Size {
                            raw: 0,
                        },
                        (
                            (),
                            alloc2,
                        ),
                    ),
                    (
                        Size {
                            raw: 8,
                        },
                        (
                            (),
                            alloc4,
                        ),
                    ),
                ],
            },
        ),
        undef_mask: UndefMask {
            blocks: [
                65535,
            ],
            len: Size {
                raw: 16,
            },
        },
        size: Size {
            raw: 16,
        },
        align: Align {
            pow2: 3,
        },
        mutability: Not,
        extra: (),
    },
    offset: Size {
        raw: 0,
    },
}, dyn T -> dyn T

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
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:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1439
   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:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: <rustc_mir_build::hair::pattern::_match::LiteralExpander as rustc_mir_build::hair::pattern::PatternFolder>::fold_pattern
  21: rustc_mir_build::hair::pattern::PatternFoldable::fold_with
  22: <rustc_mir_build::hair::pattern::PatKind as rustc_mir_build::hair::pattern::PatternFoldable>::super_fold_with
  23: <rustc_mir_build::hair::pattern::_match::LiteralExpander as rustc_mir_build::hair::pattern::PatternFolder>::fold_pattern
  24: rustc_mir_build::hair::pattern::check_match::MatchVisitor::lower_pattern
  25: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  26: rustc_mir_build::hair::pattern::_match::MatchCheckCtxt::create_and_enter
  27: <rustc_mir_build::hair::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  28: <rustc_mir_build::hair::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  29: rustc_mir_build::hair::pattern::check_match::check_match
  30: rustc::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc::ty::context::TyCtxt> for rustc::ty::query::queries::check_match>::compute
  31: rustc::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc::dep_graph::dep_node::DepKind>::with_deps
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_query_system::query::plumbing::get_query
  34: rustc_query_system::query::plumbing::ensure_query
  35: rustc_session::utils::<impl rustc_session::session::Session>::time
  36: rustc_session::utils::<impl rustc_session::session::Session>::time
  37: rustc_interface::passes::analysis
  38: rustc::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc::ty::context::TyCtxt> for rustc::ty::query::queries::analysis>::compute
  39: rustc::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc::dep_graph::dep_node::DepKind>::with_deps
  40: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  41: rustc_query_system::query::plumbing::get_query
  42: rustc::ty::context::tls::enter_global
  43: rustc_interface::interface::run_compiler_in_existing_thread_pool
  44: scoped_tls::ScopedKey<T>::set
  45: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.44.0-nightly (77621317d 2020-03-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_match] processing `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@jyn514 jyn514 added 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. labels Apr 10, 2020
@Centril Centril added I-prioritize Issue: Indicates that prioritization has been requested for this issue. P-medium Medium priority A-HAIR A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching labels Apr 10, 2020
@Centril
Copy link
Contributor

Centril commented Apr 10, 2020

cc @eddyb @varkor @oli-obk @Nadrieril

@eddyb
Copy link
Member

eddyb commented Apr 10, 2020

cc @pnkfelix I don't think dyn Trait should be structurally matchable.

@jyn514
Copy link
Member Author

jyn514 commented Apr 10, 2020

Note that this isn't matching on dyn T, it's matching on &'static dyn T. There's a double pointer indirection because AtomicPtr requires T to be Sized.

@eddyb
Copy link
Member

eddyb commented Apr 10, 2020

@jyn514 References match by their pointee value, unlike raw pointers. You should use *const dyn T if you want to actually compare the pointers.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 11, 2020
@spastorino spastorino added I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 14, 2020
@Centril Centril removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 14, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 28, 2020
…pnkfelix

forbid `dyn Trait` in patterns

Do not allow `&dyn Trait` as a generic const parameters.
This also changes dyn trait in pattern from ICE to error.

closes rust-lang#63322
closes rust-lang#70972

r? @eddyb
@bors bors closed this as completed in 679431f May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants