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

Cannot use associated constant in a provided associated method #25046

Closed
ghost opened this issue May 2, 2015 · 1 comment · Fixed by #25091
Closed

Cannot use associated constant in a provided associated method #25046

ghost opened this issue May 2, 2015 · 1 comment · Fixed by #25091
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ghost
Copy link

ghost commented May 2, 2015

The compiler fails to compile this:

#![feature(associated_consts)]

pub trait Foo {
    const MIN: i32;

    fn get_min() -> i32 {
        Self::MIN
    }
}

fn main() {}

The error message:

main.rs:4:5: 4:20 error: internal compiler error: Encountered error `Unimplemented` when trying to select an implementation for constant trait item reference.
main.rs:4     const MIN: i32;
              ^~~~~~~~~~~~~~~
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:170

Meta

rustc --version --verbose:
rustc 1.1.0-nightly (c4b23ae 2015-04-29) (built 2015-04-28)
binary: rustc
commit-hash: c4b23ae
commit-date: 2015-04-29
build-date: 2015-04-28
host: x86_64-apple-darwin
release: 1.1.0-nightly

Stack backtrace:

   1:        0x10ae5424f - sys::backtrace::write::h0714aaf7fe41e02dzVr
   2:        0x10ae5c8c0 - panicking::on_panic::hb86b9b356f51f92dEVv
   3:        0x10ae18c35 - rt::unwind::begin_unwind_inner::h58f79e41dbedf2efnDv
   4:        0x10a60998e - rt::unwind::begin_unwind::h17476740655312162035
   5:        0x10a60991a - diagnostic::SpanHandler::span_bug::h6ece18e7aebef0b3cFB
   6:        0x108027cfa - middle::const_eval::resolve_trait_associated_const::hfcf715732ac1e584QMi
   7:        0x107fdba61 - middle::const_eval::lookup_const_by_id::hc5a8309a206ad882OOg
   8:        0x107fd58b2 - middle::check_const::check_expr::h4c113c7ea3d8c1ffB2d
   9:        0x107fcd77c - middle::check_const::CheckCrateVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hdb217d3565a2586cGTd
  10:        0x107fd3e7e - middle::check_const::CheckCrateVisitor<'a, 'tcx>.Visitor<'v>::visit_fn::h37b9b5487c182e36DRd
  11:        0x107fd454e - visit::walk_trait_item::h8343690369834256746
  12:        0x107fd349f - visit::walk_item::h4252660852014709521
  13:        0x107fd2e1c - middle::check_const::CheckCrateVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h3645f3202d46494bKMd
  14:        0x107fdbeea - middle::check_const::check_crate::ha1c34da7b8765db0Hle
  15:        0x107584171 - driver::phase_3_run_analysis_passes::h2554ff95bce00587tGa
  16:        0x10756618c - driver::compile_input::h7c6cf9b085c57594Qba
  17:        0x107625ac3 - run_compiler::h55b523753cbd518765b
  18:        0x10762322a - boxed::F.FnBox<A>::call_box::h11476165885616507686
  19:        0x107622767 - rt::unwind::try::try_fn::h13518150216340287792
  20:        0x10aedec58 - rust_try_inner
  21:        0x10aedec45 - rust_try
  22:        0x107622a4e - boxed::F.FnBox<A>::call_box::h735039165869315632
  23:        0x10ae5b2bd - sys::thread::Thread::new::thread_start::hf4c42a114072ab47mYu
  24:     0x7fff8cfab267 - _pthread_body
  25:     0x7fff8cfab1e4 - _pthread_start
@huonw huonw added A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 2, 2015
@quantheory
Copy link
Contributor

This code should be rejected because it involves a constant that depends on a type parameter (Self). I guess I forgot to put in an error message in type checking, which is why you end up with an ICE.

See also rust-lang/rfcs#1062.

bors added a commit that referenced this issue May 12, 2015
…atsakis

It is currently broken to use syntax such as `<T as Foo>::U::static_method()` where `<T as Foo>::U` is an associated type. I was able to fix this and simplify the parser a bit at the same time.

This also fixes the corresponding issue with associated types (#22139), but that's somewhat irrelevant because #22519 is still open, so this syntax still causes an error in type checking.

Similarly, although this fix applies to associated consts, #25046 forbids associated constants from using type parameters or `Self`, while #19559 means that associated types have to always have one of those two. Therefore, I think that you can't use an associated const from an associated type anyway.
bors added a commit that referenced this issue May 26, 2015
…omatsakis

Closes #25046 (by rejecting the code that causes the ICE) and #24946. I haven't been able to deal with the array size or recursion issues yet for associated consts, though my hope was that the change I made for range match patterns might help with array sizes, too.

This PR is pretty much orthogonal to #25065.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) 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.

2 participants