-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Do not ICE when dereferencing non-Copy raw pointer #65011
Conversation
r? @zackmdavis (rust_highfive has picked a reviewer for you, use r? to override) |
CC @oli-obk |
#[derive(Debug)]
enum MyError {
NotFound { key: Vec<u8> },
Err41,
}
impl std::error::Error for MyError {}
impl std::fmt::Display for MyError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
MyError::NotFound { key } => write!(
f,
"unknown error with code {}.",
String::from_utf8(*key).unwrap()
),
MyError::Err41 => write!(f, "Sit by a lake"),
}
}
}
fn main() {
println!("Hello, world!");
} Before:
before, without backtrace: $ RUST_BACKTRACE=0 /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc -Z treat-err-as-bug=500 ./main.rs
error[E0507]: cannot move out of `*key` which is behind a shared reference
--> ./main.rs:15:35
|
15 | String::from_utf8(*key).unwrap()
| ^^^^ move occurs because `*key` has type `std::vec::Vec<u8>`, which does not implement the `Copy` trait
error: internal compiler error: src/librustc_mir/borrow_check/mod.rs:1949: Accessing `(*_4)` with the kind `Write(Move)` shouldn't be possible
--> ./main.rs:15:35
|
15 | String::from_utf8(*key).unwrap()
| ^^^^
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:871:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.40.0-nightly (22bc9e1d9 2019-09-30) running on x86_64-unknown-linux-gnu
note: compiler flags: -Z treat-err-as-bug=500
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0507`. after patch:
EDIT: looks like this issue happened before and there's a repro. in #54597 (comment) but that version didn't require |
It would be nice to have a repro case for the legit case when that error should be shown. There might be one inside #46908 ????? I'm trying to find it, but my knowledge is limited, I might fail. (already discarded example one if that was even supposed to show the error, unsure) |
Note: true only when using What do I mean by example of such ICE: $ RUST_BACKTRACE=1 /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc -Z treat-err-as-bug=1 ./c.rs
error[E0507]: cannot move out of `*array` which is behind a shared reference
--> ./c.rs:16:13
|
16 | *array
| ^^^^^^
| |
| move occurs because `*array` has type `std::vec::Vec<Value>`, which does not implement the `Copy` trait
| help: consider borrowing here: `&*array`
thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', src/librustc_errors/lib.rs:941:13
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:76
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:60
4: core::fmt::write
at src/libcore/fmt/mod.rs:1028
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1412
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:64
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:196
9: std::panicking::default_hook
at src/libstd/panicking.rs:210
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:477
12: std::panicking::begin_panic
13: rustc_errors::HandlerInner::emit_diagnostic
14: rustc_errors::diagnostic_builder::DiagnosticBuilder::into_diagnostic
15: rustc_errors::diagnostic_builder::DiagnosticBuilder::buffer
16: rustc_mir::borrow_check::move_errors::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report
17: rustc_mir::borrow_check::do_mir_borrowck
18: rustc::ty::context::GlobalCtxt::enter_local
19: rustc_mir::borrow_check::mir_borrowck
20: rustc::ty::query::__query_compute::mir_borrowck
21: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
22: rustc::dep_graph::graph::DepGraph::with_task_impl
23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
24: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
25: rustc::util::common::time
26: rustc_interface::passes::analysis
27: rustc::ty::query::__query_compute::analysis
28: rustc::dep_graph::graph::DepGraph::with_task_impl
29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
30: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
31: rustc_interface::passes::create_global_ctxt::{{closure}}
32: rustc_interface::interface::run_compiler_in_existing_thread_pool
33: std::thread::local::LocalKey<T>::with
34: scoped_tls::ScopedKey<T>::set
35: syntax::with_globals
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.40.0-nightly (22bc9e1d9 2019-09-30) running on x86_64-unknown-linux-gnu
note: compiler flags: -Z treat-err-as-bug=1
query stack during panic:
#0 [mir_borrowck] processing `foo`
#1 [analysis] running analysis passes on this crate
end of query stack this is normal! |
r? @zackmdavis @bors r+ |
📌 Commit e8796ca has been approved by |
Do not ICE when dereferencing non-Copy raw pointer CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
Rollup of 8 pull requests Successful merges: - #64708 (Stabilize `Option::as_deref` and `Option::as_deref_mut`) - #64909 (When encountering chained operators use heuristics to recover from bad turbofish) - #65011 (Do not ICE when dereferencing non-Copy raw pointer) - #65064 (permit asyncawait-ondeck to be added by anyone) - #65066 ([const-prop] Fix ICE when trying to eval polymorphic promoted MIR) - #65100 (Replace GeneratorSubsts with SubstsRef) - #65105 (Split out some passes from librustc) - #65106 (Allow unused attributes to avoid incremental bug) Failed merges: r? @ghost
Do not ICE when dereferencing non-Copy raw pointer CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
Do not ICE when dereferencing non-Copy raw pointer CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
Rollup of 18 pull requests This contains changes from all the successful runs that bors marked as timed out, plus a revert of #63649 which appears to be the immediate cause of the timeouts. Successful merges: - #64708 (Stabilize `Option::as_deref` and `Option::as_deref_mut`) - #64728 (Stabilize UdpSocket::peer_addr) - #64765 (std: Reduce checks for `feature = "backtrace"`) - #64909 (When encountering chained operators use heuristics to recover from bad turbofish) - #65011 (Do not ICE when dereferencing non-Copy raw pointer) - #65064 (permit asyncawait-ondeck to be added by anyone) - #65066 ([const-prop] Fix ICE when trying to eval polymorphic promoted MIR) - #65100 (Replace GeneratorSubsts with SubstsRef) - #65105 (Split out some passes from librustc) - #65106 (Allow unused attributes to avoid incremental bug) - #65113 (Fix lonely backtick) - #65116 (Remove unneeded visit_statement definition) - #65118 (Update the documented default of -Z mutable-noalias) - #65123 (Account for macro invocation in `let mut $pat` diagnostic.) - #65124 (Replace some instances of `as *[const | mut] _` with `.cast()`) - #65126 (Fix typo on `now()` comments) - #65130 (lint: extern non-exhaustive types are improper) - #65151 (Revert #63649 - "Upgrade Emscripten targets to use upstream LLVM backend") Failed merges: r? @ghost
CC #52262. Confirmed to remove the unnecessary ICE, but without a repro case.