Skip to content

ICE source trait is private #24877

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
retep998 opened this issue Apr 28, 2015 · 6 comments
Closed

ICE source trait is private #24877

retep998 opened this issue Apr 28, 2015 · 6 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@retep998
Copy link
Member

With this code: retep998/term@2b94c82
I get an ICE

Peter@Win81-SSD MINGW64 ~/term
$ cargo run --example something
   Compiling kernel32-sys v0.1.0
   Compiling libc v0.1.6
   Compiling winapi v0.1.17
   Compiling term v0.2.7 (file:///C:/msys64/home/Peter/term)
examples\something.rs:19:14: 2:54 error: source trait is private
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/masterCONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'capacity overflow', C:/msys64/home/Peter/rust/src/libcore\option.rs:330


Could not compile `term`.

To learn more, run the command again with --verbose.

Peter@Win81-SSD MINGW64 ~/term
$ rustc -vV
rustc 1.1.0-dev (9c88f3be1 2015-04-27) (built 2015-04-27)
binary: rustc
commit-hash: 9c88f3be126d0fe02a92c20e1d78192f4b648401
commit-date: 2015-04-27
build-date: 2015-04-27
host: x86_64-pc-windows-gnu
release: 1.1.0-dev

Backtrace by @kballard using rustc 1.1.0-nightly (5fb0259 2015-04-26) (built 2015-04-26)

$ env RUST_BACKTRACE=1 cargo run --example something
   Compiling term v0.2.7 (file:///Users/kevin/Dev/rust/Scratch/term)
examples/something.rs:19:14: 2:54 error: source trait is private
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'capacity overflow', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcore/option.rs:330

stack backtrace:
   1:        0x105cb7b3f - sys::backtrace::write::h7c4b7b31b5a98994KVr
   2:        0x105cc0242 - panicking::on_panic::h130becb52f065864NVv
   3:        0x105c7c985 - rt::unwind::begin_unwind_inner::hf2ec506d50a3ea22wDv
   4:        0x105c7d7bc - rt::unwind::begin_unwind_fmt::he465542fba1a288eCCv
   5:        0x105cbfd9c - rust_begin_unwind
   6:        0x105d0f7b5 - panicking::panic_fmt::h39c9227a84864bb7yKy
   7:        0x105449ce3 - codemap::CodeMap::span_to_lines::h8832e04ed2aff1a62gA
   8:        0x10548fd2b - diagnostic::emit::h695a3e055df98e351UB
   9:        0x10548d4cc - diagnostic::EmitterWriter.Emitter::emit::h786e8cf93696a544JRB
  10:        0x10543ff39 - diagnostic::SpanHandler::span_err::h9f68fad8e64a9d63PnB
  11:        0x102e69e33 - session::Session::span_err::h2d09ffe9b87a2a3fIOp
  12:        0x102879295 - PrivacyVisitor<'a, 'tcx>::report_error::had53c10fa374641a2Ra
  13:        0x10287c29b - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::h1cd280cef77a740dHhb
  14:        0x10287dcc3 - visit::Visitor::visit_block::h7884039954563752346
  15:        0x10287d549 - visit::Visitor::visit_fn::h18293213297878176316
  16:        0x10287b631 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h83709f09c8dd29dfxdb
  17:        0x10288241a - check_crate::h0ad7434cff2b8431EVb
  18:        0x102437393 - driver::phase_3_run_analysis_passes::h84861191833defe7tGa
  19:        0x102419588 - driver::compile_input::h65cad254ac62afa6Qba
  20:        0x1024d8613 - run_compiler::hbd6a992aacaf1248F4b
  21:        0x1024d5d7a - boxed::F.FnBox<A>::call_box::h9480122591250505076
  22:        0x1024d52c7 - rt::unwind::try::try_fn::h5956310425634165804
  23:        0x105d42618 - rust_try_inner
  24:        0x105d42605 - rust_try
  25:        0x1024d559e - boxed::F.FnBox<A>::call_box::h8195565033996650298
  26:        0x105cbec3d - sys::thread::Thread::new::thread_start::h8efe8b1c3780385fvYu
  27:     0x7fff94dfe267 - _pthread_body
  28:     0x7fff94dfe1e4 - _pthread_start

Could not compile `term`.

To learn more, run the command again with --verbose.
@lilyball
Copy link
Contributor

If I alter the example as

-    writeln!(&mut out, "Hello World!");
+    let _ = writeln!(&mut out, "Hello World!");

it avoids the ICE and correctly reports the span of the error:

$ cargo run --example something
   Compiling term v0.2.7 (file:///Users/kevin/Dev/rust/Scratch/term)
examples/something.rs:19:13: 19:47 error: source trait is private
examples/something.rs:19     let _ = writeln!(&mut out, "Hello World!");
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `term`.

@lilyball lilyball added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 28, 2015
@lilyball
Copy link
Contributor

Besides the ICE, this error is confusing. I assume the problem is that std::io::Write is not in the prelude and the example did not say use std::io::prelude::*. But the error shouldn't be saying "source trait is private", it should be saying something along the lines of error: type Foo does not respond to any method write_fmt. Although even there I think that's incorrect, because the type here is a trait object that declares conformance to Write, meaning that the call to write_fmt() should succeed even without Write being imported.

@mseri
Copy link
Contributor

mseri commented Sep 2, 2015

+1 I was bitten few minutes ago by the same error. I agree with @kballard

@bltavares
Copy link
Contributor

Would this be a good attempt on a reproducible example?

use std::io;
struct Foo;

impl std::io::Write for Foo {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        Ok(0)
    }

    fn flush(&mut self) -> io::Result<()> {
        Ok(())
    }
}

fn example() -> Box<Foo> {
  Box::new(Foo)
}

fn main() {
  let mut out = example();
  writeln!(&mut out, "Hello World!");
}

Here is the error message:

<std macros>:2:8: 2:54 error: no method named `write_fmt` found for type `&mut Box<Foo>` in the current scope
<std macros>:2 $ dst . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:2:1: 2:46 note: in this expansion of write! (defined in <std macros>)
<anon>:20:3: 20:38 note: in this expansion of writeln! (defined in <std macros>)
<std macros>:2:8: 2:54 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
<std macros>:2:8: 2:54 help: candidate #1: use `std::io::Write`
error: aborting due to previous error

Adding a use std::io::Write; on the code makes it compile normally, without ICE. Considering that the example captures the error correctly, could this be closed?

@petrochenkov
Copy link
Contributor

This is fixed in #32073 & #31920

@petrochenkov
Copy link
Contributor

E-needtest and duplicate of #27669

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants