Skip to content

rustc panics on fn that returns associated struct tuple with Self #38919

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
vandenoever opened this issue Jan 8, 2017 · 6 comments
Closed

rustc panics on fn that returns associated struct tuple with Self #38919

vandenoever opened this issue Jan 8, 2017 · 6 comments
Assignees
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vandenoever
Copy link

A function that returns an associated struct tuple such as that starts with Self:: such as Self::Type(0) causes a panic.

This lib.rs gives a panic in rustc 1.15.0-nightly.

pub trait Trait {
    type Type;
    fn get(&self) -> Self::Type;
}

pub struct Struct (usize);

impl Trait for Struct {
    type Type = Struct;
    fn get(&self) -> Self::Type {
        Self::Type(0)
    }
}
$ RUST_BACKTRACE=1 cargo build --verbose
   Compiling bug v0.1.0 (file:///home/oever/src/bug)
     Running `rustc src/lib.rs --crate-name bug --crate-type lib -g -C metadata=0262005d8de49048 --out-dir /home/oever/src/bug/target/debug/deps --emit=dep-info,link -L dependency=/home/oever/src/bug/target/debug/deps`
error: internal compiler error: src/librustc_typeck/check/mod.rs:4379: unexpected definition: AssociatedTy(DefId { krate: CrateNum(0), node: DefIndex(5) => bug/5baa2d6ec3a2d3d06eef63d5c6fc5cad::Trait[0]::Type[0] })

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 'Box<Any>', src/librustc_errors/lib.rs:424
stack backtrace:
   1:     0x7f529c62da4a - std::sys::imp::backtrace::tracing::imp::write::h944c02ac40aee2d7
   2:     0x7f529c63c9df - std::panicking::default_hook::{{closure}}::h6875a2976258b020
   3:     0x7f529c63c57d - std::panicking::default_hook::h88ffbc5922643264
   4:     0x7f529c63ce87 - std::panicking::rust_panic_with_hook::ha5aed1dfc0e220e3
   5:     0x7f52981fb47a - std::panicking::begin_panic::h264cdc75d51b518b
   6:     0x7f529820c08d - rustc_errors::Handler::bug::h620f7270292f0095
   7:     0x7f52999fcee1 - rustc::session::opt_span_bug_fmt::{{closure}}::h4a9b70c3df8b4b3a
   8:     0x7f52999fccfe - rustc::session::opt_span_bug_fmt::h7d83586c6e2c7ae6
   9:     0x7f52999fc962 - rustc::session::bug_fmt::he2d2f00a4afa9d1e
  10:     0x7f529ab2c039 - rustc_typeck::check::FnCtxt::instantiate_value_path::h4229ac945aebfa55
  11:     0x7f529ab1b96f - rustc_typeck::check::FnCtxt::check_expr_kind::hfeeca7568cc99087
  12:     0x7f529ab18d62 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h5d7f5141d7386bb8
  13:     0x7f529aaeac74 - rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_call::h762a25d0c9a1f5b4
  14:     0x7f529ab19eff - rustc_typeck::check::FnCtxt::check_expr_kind::hfeeca7568cc99087
  15:     0x7f529ab18d62 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h5d7f5141d7386bb8
  16:     0x7f529ab2acfe - rustc_typeck::check::FnCtxt::check_block_with_expected::he90dd72b6855e5e4
  17:     0x7f529ab19218 - rustc_typeck::check::FnCtxt::check_expr_kind::hfeeca7568cc99087
  18:     0x7f529ab18d62 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h5d7f5141d7386bb8
  19:     0x7f529ab00087 - rustc_typeck::check::check_fn::h96bd864b4d4fc711
  20:     0x7f529aafec5b - rustc_typeck::check::check_bare_fn::heb8c1cdb84569c5e
  21:     0x7f529ab01a2d - rustc_typeck::check::check_item_body::h1e039ede2f960fb9
  22:     0x7f529aafc52d - rustc_typeck::check::check_item_bodies::hd22adb7703cc56d7
  23:     0x7f529ab63202 - rustc_typeck::check_crate::h4045752b69a796e8
  24:     0x7f529c9dda6e - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h97a3a12d948df547
  25:     0x7f529c955019 - rustc::ty::context::TyCtxt::create_and_enter::hdbe8789e1b639eb8
  26:     0x7f529c9c6c55 - rustc_driver::driver::compile_input::h8e119234b60571d5
  27:     0x7f529ca081e8 - rustc_driver::run_compiler::hbdfc4f84e2e0f4b9
  28:     0x7f529c923418 - std::panicking::try::do_call::hf679f17bf3b43b0b
  29:     0x7f529c64563a - __rust_maybe_catch_panic
  30:     0x7f529c9452d8 - <F as alloc::boxed::FnBox<A>>::call_box::h506fb5d7b8891cd4
  31:     0x7f529c63b844 - std::sys::imp::thread::Thread::new::thread_start::h8084b1107992ae5b
  32:     0x7f52979a41f3 - start_thread
  33:     0x7f529c30312e - __GI___clone
  34:                0x0 - <unknown>

error: Could not compile `bug`.

Caused by:
  process didn't exit successfully: `rustc src/lib.rs --crate-name bug --crate-type lib -g -C metadata=0262005d8de49048 --out-dir /home/oever/src/bug/target/debug/deps --emit=dep-info,link -L dependency=/home/oever/src/bug/target/debug/deps` (exit code: 101)
@est31
Copy link
Member

est31 commented Jan 8, 2017

This is fixed on 1.14 stable, and on 1.16.0-nightly (7e38a89a7 2017-01-06), but broken on 1.15.0-beta.3 (a035041ba 2017-01-07).

@arielb1 arielb1 added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Jan 9, 2017
@nikomatsakis nikomatsakis added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2017
@nikomatsakis
Copy link
Contributor

cc @jseyfried @eddyb -- any idea what this is?

@jseyfried
Copy link
Contributor

cc @petrochenkov

@petrochenkov
Copy link
Contributor

This looks very similar to #38145, but somehow got fixed while #38145 still ICEs.
I suspect #37676 or/and some other PR in the series was the cause.

@eddyb
Copy link
Member

eddyb commented Jan 11, 2017

How does this get past UFCS lookup? Are we supposed to error elsewhere?

EDIT: Reduced:

fn foo<T: Iterator>() {
    T::Item;
}

EDIT2: Alright, it's my fault (from #37402 - amazing that we don't have a test for this).
Fix would be to replace the true with a condition, either item.kind != ty::AssociatedKind::Type or item.kind == ty::AssociatedKind::Method || item.kind == ty::AssociatedKind::Const.

@eddyb eddyb added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jan 11, 2017
@eddyb
Copy link
Member

eddyb commented Jan 11, 2017

@est31 Huh, the problematic change is from November, and playpen still shows the same ICE for my reduced testcase, I wonder how the original one gets the new error on nightly (Self is special?).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

8 participants