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

internal compiler error: &mut ! was a subtype of &mut std::cell::RefMut<,<generic #8>> but now is not? #13847

Closed
regehr opened this issue Apr 29, 2014 · 8 comments · Fixed by #18099
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@regehr
Copy link

regehr commented Apr 29, 2014

Seen using rustc from Apr 28 on Ubuntu 14.04 on x86-64

Might be the same as issue #13202

regehr@regehr-M51AC:~/quickcheck/foo/foo2$ cat lib.rs 
#![crate_type = "lib"]
mod a {
  struct TestResult;
  impl TestResult {
    fn is_error() { return.is_failure }
  }
}
regehr@regehr-M51AC:~/quickcheck/foo/foo2$ rustc lib.rs
lib.rs:5:21: 5:38 error: multiple applicable methods in scope
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:38 note: candidate #1 is `std::rc::Rc<T>.Deref<T>::deref`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:38 note: candidate #2 is `std::cell::Ref<'b, T>.Deref<T>::deref`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:38 note: candidate #3 is `std::cell::RefMut<'b, T>.Deref<T>::deref`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:38 note: candidate #4 is `std::rt::local_ptr::Borrowed<T>.Deref<T>::deref`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:38 error: the type of this value must be known in this context
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~~~~~~~~~~~~
lib.rs:5:21: 5:27 error: multiple applicable methods in scope
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~
lib.rs:5:21: 5:27 note: candidate #1 is `std::cell::RefMut<'b, T>.DerefMut<T>::deref_mut`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~
lib.rs:5:21: 5:27 note: candidate #2 is `std::rt::local_ptr::Borrowed<T>.DerefMut<T>::deref_mut`
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~
lib.rs:5:21: 5:27 error: internal compiler error: &mut ! was a subtype of &mut std::cell::RefMut<,<generic #8>> but now is not?
lib.rs:5     fn is_error() { return.is_failure }
                             ^~~~~~
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at '~Any', /home/regehr/rust/src/libsyntax/diagnostic.rs:99
stack backtrace:
   1:     0x7fefa1fdaff0 - rt::backtrace::imp::write::h136b9cbd56c2506cMwa::v0.11.pre
   2:     0x7fefa1f3a960 - rt::unwind::begin_unwind_inner::h3497e91d7ad8db5eR69::v0.11.pre
   3:     0x7fefa0956410 - rt::unwind::begin_unwind::h9302574564411321173::v0.11.pre
   4:     0x7fefa0956340 - diagnostic::SpanHandler::span_bug::hc5e60985cdb28780ITb::v0.11.pre
   5:     0x7fefa29f12e0 - driver::session::Session::span_bug::h6192694ebf2fa0f4qYg::v0.11.pre
   6:     0x7fefa2c220e0 - middle::typeck::check::method::LookupContext<'a>::bug::hc0db9e2df5b80d9a8J6::v0.11.pre
   7:     0x7fefa2c221a0 - middle::typeck::check::method::LookupContext<'a>::consider_candidates::h8f9fb184402efba6725::v0.11.pre
   8:     0x7fefa2c1f7c0 - middle::typeck::check::method::LookupContext<'a>::search_for_method::h49111f5047e2d3630X5::v0.11.pre
   9:     0x7fefa2c20e80 - middle::typeck::check::method::LookupContext<'a>::search_for_some_kind_of_autorefd_method::h8a4cb7ab104ab02esR5::v0.11.pre
  10:     0x7fefa2c1a3c0 - middle::typeck::check::method::LookupContext<'a>::search_for_autoptrd_method::h647683d2a6838d345O5::v0.11.pre
  11:     0x7fefa2c18a40 - middle::typeck::check::method::LookupContext<'a>::search_step::hd15e63a17c8a0f26s44::v0.11.pre
  12:     0x7fefa2c16000 - middle::typeck::check::method::LookupContext<'a>::search::h0ea96b8185aa8367V24::v0.11.pre
  13:     0x7fefa2c16fe0 - middle::typeck::check::method::lookup_in_trait::hc04ecbc7b46011583S4::v0.11.pre
  14:     0x7fefa2c17d50 - middle::typeck::check::try_overloaded_deref::h8f6a7e95b271d861RP8::v0.11.pre
  15:     0x7fefa2c1a5a0 - middle::typeck::check::autoderef::h17792651969169316491::v0.11.pre
  16:     0x7fefa2c155c0 - middle::typeck::check::method::lookup::h82d40a3169cb9cc97L4::v0.11.pre
  17:     0x7fefa2c68a10 - middle::typeck::check::check_expr_with_unifier::check_field::hfd76eba9be2a5a6bgea::v0.11.pre
  18:     0x7fefa2c54190 - middle::typeck::check::check_expr_with_unifier::ha11746da088278681j9::v0.11.pre
  19:     0x7fefa2c357f0 - middle::typeck::check::check_block_with_expected::h805f28014cc9d442WEb::v0.11.pre
  20:     0x7fefa2c31250 - middle::typeck::check::check_fn::h94bad4d935ed4f62h96::v0.11.pre
  21:     0x7fefa2c30ff0 - middle::typeck::check::check_bare_fn::h5c36a49e5fccfdfe8Y6::v0.11.pre
  22:     0x7fefa2c3a160 - middle::typeck::check::check_method_body::h88f49d38779a74077F7::v0.11.pre
  23:     0x7fefa2c28d50 - middle::typeck::check::check_item::h76bb63cb120ff746vv7::v0.11.pre
  24:     0x7fefa2c2a870 - visit::walk_item::h12134269049250110285::v0.11.pre
  25:     0x7fefa2c30df0 - middle::typeck::check::check_item_types::hd75ba5625f9aca47qY6::v0.11.pre
  26:     0x7fefa2d6bb80 - util::common::time::h6444374424509661037::v0.11.pre
  27:     0x7fefa2d6a8d0 - middle::typeck::check_crate::h9011ee56e63b57d6znu::v0.11.pre
  28:     0x7fefa31a9330 - driver::driver::phase_3_run_analysis_passes::he6e52dd5c9a56737Daf::v0.11.pre
  29:     0x7fefa31af320 - driver::driver::compile_input::h85a843a78d6397c8qAf::v0.11.pre
  30:     0x7fefa31d4060 - run_compiler::h264aa4ba7e50875dW4m::v0.11.pre
  31:     0x7fefa31ebee0 - main_args::closure.91249
  32:     0x7fefa31ea3e0 - monitor::closure.91124
  33:     0x7fefa31e5cd0 - task::TaskBuilder::try::closure.90890
  34:     0x7fefa4f85950 - task::spawn_opts::closure.7111
  35:     0x7fefa1fd6030 - rt::task::Task::run::closure.40120
  36:     0x7fefa1fe0f30 - rust_try
  37:     0x7fefa1fd5e70 - rt::task::Task::run::hd272e48af74afe0aUW7::v0.11.pre
  38:     0x7fefa4f85720 - task::spawn_opts::closure.7084
  39:     0x7fefa1fd9b30 - rt::thread::thread_start::hc9411307f5ee01da7B8::v0.11.pre
  40:     0x7fefa18f60c0 - start_thread
  41:     0x7fefa1c072d9 - __clone
  42:                0x0 - <unknown>

regehr@regehr-M51AC:~/quickcheck/foo/foo2$ 
@brson
Copy link
Contributor

brson commented May 9, 2014

This may be a fairly easy problem to track down for a new compiler hacker. Tagging as E-easy.

@lilyball
Copy link
Contributor

lilyball commented May 9, 2014

Smaller test case:

fn main() {
    return.is_failure
}

Slightly more illuminating test case:

fn main() {
    (fail!("bottom")).foo
}

@lilyball
Copy link
Contributor

lilyball commented May 9, 2014

And yes, this appears to be a dupe of #13202. The same issue is in play in both cases, which is attempting to call a method on !, which is attempting to go through various Deref impls.

@nikomatsakis
Copy link
Contributor

My preferred fix is to remove ty_bot from the set of types and instead instantiate a fresh type variable. This may cause a slight change in the set of programs we accept, but not much of one, and it should simplify a number of bits of code that must currently consider bot, which rarely makes sense. It will require some changes to the representation here and there -- for example fn return types will need to be an enum rather just a ty::t.

@ghost
Copy link

ghost commented Aug 18, 2014

There seems to be a discrepancy between subtyping rules for mutable references (where invariance is required?) and method lookup, which happily accepts covariance.

@nikomatsakis
Copy link
Contributor

@jakub- can you produce a specific example where that occurs? (the examples in this bug don't see to be examples of mutable references and method lookup interacting in that way)

@ghost
Copy link

ghost commented Aug 20, 2014

@nikomatsakis Sorry, I was just describing what I'd inferred from looking at the code. Specifically

_ => mutability_matches(mt.mutbl, m) &&
vs .

I understand the Sub combiner will only combine &mut T and &mut U if T == U. For method lookup T <: U are accepted (where T is the type of self).

Not familiar enough with the codebase to say how useful that information is.

@ghost
Copy link

ghost commented Sep 6, 2014

@nikomatsakis #17033 seems to be the same issue and offers a better example of what I meant.

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 3, 2014
bors added a commit that referenced this issue Oct 18, 2014
Closes #9249.
Closes #13105.
Closes #13837.
Closes #13847.
Closes #15207.
Closes #15261.
Closes #16048. 
Closes #16098.
Closes #16256.
Closes #16562.
Closes #16596.
Closes #16709.
Closes #16747.
Closes #17025.
Closes #17121.
Closes #17450.
Closes #17636.
bors added a commit that referenced this issue Oct 28, 2014
We now instead use a fresh variable for expressions that diverge.

Closes #14973.
Closes #13847.

[Work in progress]

cc @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants