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

Do not ICE when dereferencing non-Copy raw pointer #65011

Merged
merged 1 commit into from Oct 6, 2019

Conversation

@estebank
Copy link
Contributor

commented Oct 2, 2019

CC #52262. Confirmed to remove the unnecessary ICE, but without a repro case.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Oct 2, 2019

r? @zackmdavis

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank

This comment has been minimized.

Copy link
Contributor Author

commented Oct 2, 2019

@ghost

This comment has been minimized.

Copy link

commented Oct 2, 2019

main.rs:

#[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:

$ RUST_BACKTRACE=1 /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
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::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_context_opt
  18: rustc::ty::context::tls::with_opt
  19: rustc::util::bug::opt_span_bug_fmt
  20: rustc::util::bug::span_bug_fmt
  21: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  22: rustc_mir::borrow_check::MirBorrowckCtxt::consume_operand
  23: <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::DataflowResultsConsumer>::visit_statement_entry
  24: rustc_mir::borrow_check::do_mir_borrowck
  25: rustc::ty::context::GlobalCtxt::enter_local
  26: rustc_mir::borrow_check::mir_borrowck
  27: rustc::ty::query::__query_compute::mir_borrowck
  28: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  31: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  32: rustc::util::common::time
  33: rustc_interface::passes::analysis
  34: rustc::ty::query::__query_compute::analysis
  35: rustc::dep_graph::graph::DepGraph::with_task_impl
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  37: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  38: rustc_interface::passes::create_global_ctxt::{{closure}}
  39: rustc_interface::interface::run_compiler_in_existing_thread_pool
  40: std::thread::local::LocalKey<T>::with
  41: scoped_tls::ScopedKey<T>::set
  42: syntax::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.40.0-nightly (22bc9e1d9 2019-09-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z treat-err-as-bug=500

query stack during panic:
#0 [mir_borrowck] processing `<MyError as std::fmt::Display>::fmt`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0507`.

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:

$ RUST_BACKTRACE=1 rustc -Z treat-err-as-bug=500 ./main.rs 
!! master-installed (default)
!! Executing '/home/user/.cargo/bin/rustc' in pwd='/tmp/blah/src' with args(3): '-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: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.

EDIT: looks like this issue happened before and there's a repro. in #54597 (comment) but that version didn't require -Z treat-err-as-bug=500 !!

@ghost

This comment has been minimized.

Copy link

commented Oct 2, 2019

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)
EDIT: gave up searching 'cause I don't even know what I'm doing :) need more knowledge, most likely.

@ghost

This comment has been minimized.

Copy link

commented Oct 2, 2019

Do not ICE when dereferencing non-Copy raw pointer

Note: true only when using -Z treat-err-as-bug=500 (500 is a bit random, it has to be large enough, to not cause the ICE because of the original errors, so at least 2 in that case)

What do I mean by ICE because of the original errors? for example when using -Z treat-err-as-bug=1 aka -Z treat-err-as-bug you get the normally occurring ICE because of using treat-err-as-bug
-Z treat-err-as-bug=val -- treat error numberval that occurs as bug (aka causes ICE)

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!

@estebank estebank force-pushed the estebank:ice-o-matic branch from f92b69c to e8796ca Oct 2, 2019
@Centril

This comment has been minimized.

Copy link
Member

commented Oct 2, 2019

@zackmdavis

This comment has been minimized.

Copy link
Member

commented Oct 4, 2019

@bors

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2019

📌 Commit e8796ca has been approved by zackmdavis

Centril added a commit to Centril/rust that referenced this pull request Oct 4, 2019
Do not ICE when dereferencing non-Copy raw pointer

CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
@Centril Centril referenced this pull request Oct 4, 2019
bors added a commit that referenced this pull request Oct 5, 2019
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
bors added a commit that referenced this pull request Oct 5, 2019
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
tmandry added a commit to tmandry/rust that referenced this pull request Oct 5, 2019
Do not ICE when dereferencing non-Copy raw pointer

CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
bors added a commit that referenced this pull request Oct 5, 2019
Rollup of 15 pull requests

Successful merges:

 - #64708 (Stabilize `Option::as_deref` and `Option::as_deref_mut`)
 - #64765 (std: Reduce checks for `feature = "backtrace"`)
 - #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)
 - #65095 (Sort error codes in librustc_passes)
 - #65100 (Replace GeneratorSubsts with SubstsRef)
 - #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)

Failed merges:

 - #65105 (Split out some passes from librustc)

r? @ghost
bors added a commit that referenced this pull request Oct 6, 2019
Rollup of 15 pull requests

Successful merges:

 - #64708 (Stabilize `Option::as_deref` and `Option::as_deref_mut`)
 - #64765 (std: Reduce checks for `feature = "backtrace"`)
 - #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)
 - #65095 (Sort error codes in librustc_passes)
 - #65100 (Replace GeneratorSubsts with SubstsRef)
 - #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)

Failed merges:

 - #65105 (Split out some passes from librustc)

r? @ghost
tmandry added a commit to tmandry/rust that referenced this pull request Oct 6, 2019
Do not ICE when dereferencing non-Copy raw pointer

CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
bors added a commit that referenced this pull request Oct 6, 2019
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
@bors bors merged commit e8796ca into rust-lang:master Oct 6, 2019
4 checks passed
4 checks passed
pr Build #20191002.68 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.