Issue 1:
Attempting to misuse a trait can cause a compiler panic. The offending code is a simplified version of what I was working on.

I tried this code:

fn rem_is_zero<T: Eq + Rem + Zero>(n: T, m: T) -> bool
where <T as Rem>::Output: Zero + Eq
{
let z = <T as Rem>::Output::zero(); // Compiler panic
//let z = <<T as Rem>::Output as Zero>::zero(); // Compiles correctly

(n % m) == z
}

After reviewing the documentation, I expect this to throw a syntax error. Specifically, because the let RHS should be written as: <<T as Rem>::Output as Zero>::zero. This code does compile and work as expected.

I don't know if this is specific to the Zero trait as I was able to use it like this:

fn eq_zero<T:Eq + Zero>(n: T) -> bool
{
let z = T::zero();

n == z
}

Meta

rustc --version --verbose:

rustc 1.4.0-nightly (4f33e43cb 2015-08-05)
binary: rustc
commit-hash: 4f33e43cbceb60ec85bb5140bd5470965ea92d16
commit-date: 2015-08-05
host: x86_64-pc-windows-gnu
release: 1.4.0-nightly

Backtrace:

C:\Stuff\Programming\rust-tut\rust-nightly-bug\src>rustc main.rs
main.rs:18:11: 18:35 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Some(Self)) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]
main.rs:18 let z = <T as Rem>::Output::zero();
^~~~~~~~~~~~~~~~~~~~~~~~
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
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax\diagnostic.rs:176

stack backtrace:
1: 0x699b9ce8 - sys::backtrace::write::h681b474c6c2394f4tNs
2: 0x699c37ff - rt::unwind::register::hb538ab914c4328d5b2w
3: 0x699854df - rt::unwind::begin_unwind_inner::hb80fd8ef51b4060akZw
4: 0x7105ee5b - diagnostic::SpanHandler::span_bug::hc633dbf01b525dc5X6A
5: 0x7105ee13 - diagnostic::SpanHandler::span_bug::hc633dbf01b525dc5X6A
6: 0x692b88d8 - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_ty::hca42f6dc71385de0GnQ
7: 0x670f83d1 - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::ty_infer::hb1193da908738887xBo
8: 0x6716d690 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::h419ad07efdb37e6bUlu
9: 0x671752b2 - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
10: 0x67174689 - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
11: 0x6717a6cc - astconv::PathParamMode...std..cmp..PartialEq::ne::h94fa3bff02dd36c9OIu
12: 0x671630d8 - check::TupleArgumentsFlag...std..clone..Clone::clone::hedb38ea352ace7f6cBq
13: 0x67091969 - check::resolve_ty_and_def_ufcs::h0db529947a54cd24X2r
14: 0x6715813b - check::may_break::he5881651fb8999a1eut
15: 0x670f995e - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::h759a827f017a8a8atDo
16: 0x67141285 - check::may_break::he5881651fb8999a1eut
17: 0x67166240 - check::check_decl_initializer::hf0aa92b366271b1awas
18: 0x671662da - check::check_decl_local::h37a43869df125d9bKbs
19: 0x671664bf - check::check_stmt::h5078de71b85f2dc0Dds
20: 0x671182fb - check::GatherLocalsVisitor<'a, 'tcx>.Visitor<'tcx>::visit_item::h6ba246b1c9f3850dKIn
21: 0x670f920a - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::projected_ty::h759a827f017a8a8atDo
22: 0x6710fa3c - check::check_item_types::h3739f0f18758ac32ewn
23: 0x6710dcf0 - check::check_item_body::hc85a464b96f40859HYn
24: 0x6710f684 - check::check_item_types::h3739f0f18758ac32ewn
25: 0x671c8634 - check_crate::ha45cf61934d4de29laD
26: 0x67be60dc - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
27: 0x67be47f4 - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
28: 0x67bdef86 - driver::assign_node_ids_and_map::h4dcd00430a00f2727Da
29: 0x67bc2472 - driver::compile_input::h456239a0987e1d55Tba
30: 0x67caa553 - run_compiler::ha97eef431fa5768cC7b
31: 0x67ca8407 - run::h1e382076a350f7f7i7b
32: 0x67ca7da9 - run::h1e382076a350f7f7i7b
33: 0x699c318c - rt::unwind::imp::rust_eh_personality_catch::h8647fb0995b90ac0TMw
34: 0x699ad7e2 - rt::unwind::try::inner_try::haade0eef5e14ff2ddVw
35: 0x67ca7f77 - run::h1e382076a350f7f7i7b
36: 0x699c157e - sys::process::Command::cwd::h322b10c2248cc4393Ev
37: 0x7fffae6d2d92 - BaseThreadInitThunk

Issue 2:
Hello! I'm reporting an apparent compiler error stemming from a typo.

Version

$ rustc --version --verbose
rustc 1.4.0-nightly (7bf626a68 2015-09-07)
binary: rustc
commit-hash: 7bf626a68045be1d1a4fac9a635113bb7775b6bb
commit-date: 2015-09-07
host: x86_64-apple-darwin
release: 1.4.0-nightly

Repro

It suffices to attempt compilation of the following:

Ex. 1

use std::ops::BitXor;

fn f() {
let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
}

The above does compile if the obvious typo is fixed. I tried to find an even smaller example which failed similarly. A smaller example which does not compile if the typo is fixed, but as is, also fails with an error similar to Ex. 1:

Ex. 2

use std::ops::BitXor;

fn f() {
let g = BitXor::bitor;
}

My build invocation was cargo build.

Expected behavior

For Ex 1., I would expect to see some sort of name resolution error. That example compiles if bitor is replaced with bitxor. For Ex. 2, I have a less certain expectation, but would still expect some sort of name resolution error.

Observed behavior

Both snippets fail to compile with the following error message:

error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Some(Self)) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]

Backtraces follow below.

Ex. 1

$ RUST_BACKTRACE=1 cargo build
Compiling bugreport v0.1.0 (file:///Users/joe/devel/bugreport)
src/lib.rs:4:17: 4:30 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Some(Self)) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]
src/lib.rs:4 let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
^~~~~~~~~~~~~
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
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/diagnostic.rs:176

stack backtrace:
1: 0x111eab820 - sys::backtrace::tracing::imp::write::h8eb606f0676b1c68Sqs
2: 0x111eb263b - panicking::on_panic::h439344cab6a0722eKXw
3: 0x111e74362 - rt::unwind::begin_unwind_inner::h208ecd91d43787c9Msw
4: 0x10f71977a - rt::unwind::begin_unwind::h544928616495927122
5: 0x10f719742 - diagnostic::SpanHandler::span_bug::hd65799bd4f0c505a6NA
6: 0x10eb9bcfe - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_ty::h93ff7eb3e9afebb7TYQ
7: 0x10e5c1df0 - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::ty_infer::hb0bb190e00a198c90Cq
8: 0x10e63f435 - iter::Map<I, F>.Iterator::next::h1142259025829094402
9: 0x10e63e41e - astconv::create_substs_for_ast_path::hd4dfccf714bc74f4q2v
10: 0x10e6466e9 - astconv::create_substs_for_ast_trait_ref::h4368114ff2eab34dfrw
11: 0x10e64431c - astconv::ast_path_to_poly_trait_ref::h29bb903d881cbabdAow
12: 0x10e63455c - astconv::finish_resolving_def_to_ty::habd24143c000f312Phx
13: 0x10e532532 - check::resolve_ty_and_def_ufcs::h94d5f667283b3292wVt
14: 0x10e62e174 - check::check_expr_with_unifier::h17434517167852192102
15: 0x10e5c3877 - check::callee::check_call::heb2226e51ebba80aGUm
16: 0x10e618052 - check::check_expr_with_unifier::h7638636721109620462
17: 0x10e636fd5 - check::check_decl_initializer::h60197528b46dd3ddB2t
18: 0x10e637083 - check::check_decl_local::hada2f84316d1a260P3t
19: 0x10e6374a7 - check::check_stmt::ha7821baa526c3cf6I5t
20: 0x10e5edd77 - check::check_block_with_expected::h008ebf27f3d681a9F9t
21: 0x10e5c3010 - check::check_fn::h73e2f75c353c138drJp
22: 0x10e5e4bac - check::check_bare_fn::h9d4937e09659b1ff0yp
23: 0x10e5e2903 - check::check_item_body::hbee3397a0255ef56k0p
24: 0x10e69d3e1 - check_crate::hfc612f2e81e3f3ec1BE
25: 0x10de1d74a - driver::phase_3_run_analysis_passes::closure.21870
26: 0x10ddff38a - middle::ty::ctxt<'tcx>::create_and_enter::h10730255013514676807
27: 0x10ddfab95 - driver::phase_3_run_analysis_passes::h3370851894325132430
28: 0x10dddb585 - driver::compile_input::h88f9e5d56c3193e90ba
29: 0x10df40250 - run_compiler::h0bd793d9ea569018qqc
30: 0x10df3db49 - boxed::F.FnBox<A>::call_box::h4277668881798780915
31: 0x10df3d542 - rt::unwind::try::try_fn::h17584184833201088243
32: 0x111eb21f8 - __rust_try
33: 0x111e9e400 - rt::unwind::try::inner_try::h1851ddf9ecd93c2fFow
34: 0x10df3d6f2 - boxed::F.FnBox<A>::call_box::h5084478766513466170
35: 0x111eb156d - sys::thread::Thread::new::thread_start::hc131c4deb753ff20oNv
36: 0x7fff8de30267 - _pthread_body
37: 0x7fff8de301e4 - _pthread_start

Could not compile `bugreport`.

Ex. 2

$ RUST_BACKTRACE=1 cargo build
Compiling bugreport v0.1.0 (file:///Users/joe/devel/bugreport)
src/lib.rs:9:13: 9:26 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Some(Self)) substs=Substs[types=[[];[];[]], regions=[[];[];[]]]
src/lib.rs:9 let g = BitXor::bitor;
^~~~~~~~~~~~~
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
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/diagnostic.rs:176

stack backtrace:
1: 0x1081f2820 - sys::backtrace::tracing::imp::write::h8eb606f0676b1c68Sqs
2: 0x1081f963b - panicking::on_panic::h439344cab6a0722eKXw
3: 0x1081bb362 - rt::unwind::begin_unwind_inner::h208ecd91d43787c9Msw
4: 0x105a7177a - rt::unwind::begin_unwind::h544928616495927122
5: 0x105a71742 - diagnostic::SpanHandler::span_bug::hd65799bd4f0c505a6NA
6: 0x104efbcfe - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_ty::h93ff7eb3e9afebb7TYQ
7: 0x104922df0 - check::FnCtxt<'a, 'tcx>.AstConv<'tcx>::ty_infer::hb0bb190e00a198c90Cq
8: 0x1049a0435 - iter::Map<I, F>.Iterator::next::h1142259025829094402
9: 0x10499f41e - astconv::create_substs_for_ast_path::hd4dfccf714bc74f4q2v
10: 0x1049a76e9 - astconv::create_substs_for_ast_trait_ref::h4368114ff2eab34dfrw
11: 0x1049a531c - astconv::ast_path_to_poly_trait_ref::h29bb903d881cbabdAow
12: 0x10499555c - astconv::finish_resolving_def_to_ty::habd24143c000f312Phx
13: 0x104893532 - check::resolve_ty_and_def_ufcs::h94d5f667283b3292wVt
14: 0x10497c667 - check::check_expr_with_unifier::h7638636721109620462
15: 0x104997fd5 - check::check_decl_initializer::h60197528b46dd3ddB2t
16: 0x104998083 - check::check_decl_local::hada2f84316d1a260P3t
17: 0x1049984a7 - check::check_stmt::ha7821baa526c3cf6I5t
18: 0x10494ed77 - check::check_block_with_expected::h008ebf27f3d681a9F9t
19: 0x104924010 - check::check_fn::h73e2f75c353c138drJp
20: 0x104945bac - check::check_bare_fn::h9d4937e09659b1ff0yp
21: 0x104943903 - check::check_item_body::hbee3397a0255ef56k0p
22: 0x1049fe3e1 - check_crate::hfc612f2e81e3f3ec1BE
23: 0x10417974a - driver::phase_3_run_analysis_passes::closure.21870
24: 0x10415b38a - middle::ty::ctxt<'tcx>::create_and_enter::h10730255013514676807
25: 0x104156b95 - driver::phase_3_run_analysis_passes::h3370851894325132430
26: 0x104137585 - driver::compile_input::h88f9e5d56c3193e90ba
27: 0x10429c250 - run_compiler::h0bd793d9ea569018qqc
28: 0x104299b49 - boxed::F.FnBox<A>::call_box::h4277668881798780915
29: 0x104299542 - rt::unwind::try::try_fn::h17584184833201088243
30: 0x1081f91f8 - __rust_try
31: 0x1081e5400 - rt::unwind::try::inner_try::h1851ddf9ecd93c2fFow
32: 0x1042996f2 - boxed::F.FnBox<A>::call_box::h5084478766513466170
33: 0x1081f856d - sys::thread::Thread::new::thread_start::hc131c4deb753ff20oNv
34: 0x7fff8de30267 - _pthread_body
35: 0x7fff8de301e4 - _pthread_start

Could not compile `bugreport`.

Notes

Similar errors can be elicited with other imports (e.g. using BitOr instead of BitXor) or when the qualified identifier will definitely not be found elsewhere (e.g. referring to BitXor::nonexistent_name instead of BitXor::bitor).