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

Panic when using Self: Send constraint in impl parameter #36638

Closed
xrl opened this issue Sep 22, 2016 · 2 comments
Closed

Panic when using Self: Send constraint in impl parameter #36638

xrl opened this issue Sep 22, 2016 · 2 comments
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xrl
Copy link

xrl commented Sep 22, 2016

Panic when trying to enforce Send on a impl parameter of type Self. Panics with meaningful error. Should perhaps just be a regular compiler error?

I tried this code:

pub trait SpawnableTaskTrait<Self: Send> {
    fn spawn(syncy_self: Arc<Mutex<Self>>) where Self: Send {
        let thread_this = syncy_self.clone();

        let signal = Arc::new(AtomicBool::new(false));
        let signal_clone = signal.clone();

        thread::spawn(move || {
            let this = thread_this;

            loop {
                {
                    let mut this = this.lock().unwrap();
                    let res = Self::werk()(&mut this);
                    match res {
                        Ok(_) => continue,
                        Err(err) => {
                            if err.description() == "Resource temporarily unavailable" || err.description() == "operation would block" {
                                continue
                            } else {
                                panic!("omg: {:?}", err)
                            }
                        }
                    }
                }

                if signal_clone.load(Ordering::Relaxed) {
                    break
                }
            }
        });
    }
}

I expected to see this happen: meaningful error or it would work!

Instead, this happened: panic in rustc

Meta

rustc --version --verbose:

Xaviers-MacBook-Pro-2:~ xavierlange$ rustc --version --verbose
rustc 1.13.0-nightly (a7b2232d2 2016-09-07)
binary: rustc
commit-hash: a7b2232d20320dc3b4044a2aec1d51a129e7e17d
commit-date: 2016-09-07
host: x86_64-apple-darwin
release: 1.13.0-nightly

Backtrace:

error: internal compiler error: ../src/librustc_typeck/collect.rs:1925: `Self` should not be the name of a regular parameter

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:590
stack backtrace:
   1:        0x10f45157a - std::sys::backtrace::tracing::imp::write::h46f28e67d38b4637
   2:        0x10f45fc7f - std::panicking::default_hook::{{closure}}::h1d3243f546573ff4
   3:        0x10f45e31d - std::panicking::default_hook::h96c288d728df3ebf
   4:        0x10f45e9b6 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
   5:        0x10b102d1b - std::panicking::begin_panic::hb7c71bbc491f561c
   6:        0x10b2347d3 - rustc::session::opt_span_bug_fmt::{{closure}}::h0a2486f2fff54208
   7:        0x10b14b9a9 - rustc::session::span_bug_fmt::heb3fdb6acac8d0c7
   8:        0x10b16483e - <core::iter::Map<I, F> as core::iter::iterator::Iterator>::next::h1ff68e27aab0f019
   9:        0x10b21ab21 - rustc_typeck::collect::generics_of_def_id::h3a0f77e827110638
  10:        0x10b219ba9 - rustc_typeck::collect::trait_def_of_item::hed1ea083432e49c3
  11:        0x10b21547b - rustc_typeck::collect::convert_item::h293968d6650e9d0b
  12:        0x10b20f48e - rustc_typeck::collect::collect_item_types::ha4bc6b2aaead1c12
  13:        0x10b22fff6 - rustc_typeck::check_crate::h279dc52e9bc1b4c2
  14:        0x10b00b324 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h2b062b0c671cd504
  15:        0x10afe18e7 - rustc_driver::driver::phase_3_run_analysis_passes::h2f1bd27ff2e4d8a0
  16:        0x10afd3c9f - rustc_driver::driver::compile_input::h7dacd98cd2fd7d2b
  17:        0x10affdc48 - rustc_driver::run_compiler::h37c4294ab73436f7
  18:        0x10af410a0 - std::panicking::try::do_call::h4d040997e2efdaf3
  19:        0x10f46685a - __rust_maybe_catch_panic
  20:        0x10af5f394 - <F as alloc::boxed::FnBox<A>>::call_box::hefd1c85fab3e6c31
  21:        0x10f45d194 - std::sys::thread::Thread::new::thread_start::h5b631f48cd23f128
  22:     0x7fff8745099c - _pthread_body
  23:     0x7fff87450919 - _pthread_start
@Aatch Aatch added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 22, 2016
@TimNN
Copy link
Contributor

TimNN commented Sep 22, 2016

Reduced:

trait SpawnableTaskTrait<Self: Send> {}

The real error is the first one reported (tested on the latest nightly):

error: expected identifier, found keyword `Self`
 --> selsen_orig.rs:1:30
  |
1 | pub trait SpawnableTaskTrait<Self: Send> {
  |                              ^^^^

nightly-2016-08-16 is still good, nightly-2016-08-18 fails (Changes)

This is a regression from stable to nightly.

Probably an effect of #35605, cc @eddyb.

@TimNN TimNN added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2016
@eddyb
Copy link
Member

eddyb commented Sep 22, 2016

Added the actual message to the backtrace in the description. Yeah, what I didn't expect is parser recovery to work, this is minor and easy to fix.

bors added a commit that referenced this issue Sep 23, 2016
Don't let a type parameter named "Self" unchanged past HIR lowering.

Fixes #36638 by rewriting `Self` type parameters (which are a parse error) to a `gensym("Self")`.

Background: #35605 introduced code across rustc that determines `Self` by its keyword name.
Reverting the sanity checks around that would inadvertently cause confusion between the true `Self` of a `trait` and other type parameters named `Self` (which have caused parse errors already).

I do not like to use `gensym`, and we may do something different here in the future, but this should work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants