Closed
Description
(Found while trying to reduce #41726, but I guess it is a different bug)
use std::ops::{Index, IndexMut};
struct S;
struct H;
impl S {
fn f(&mut self) {}
}
impl Index<u32> for H {
type Output = S;
fn index(&self, index: u32) -> &S {
unimplemented!()
}
}
impl IndexMut<u32> for H {
fn index_mut(&mut self, index: u32) -> &mut S {
unimplemented!()
}
}
fn main() {
H["?"].f();
}
Error in nightly:
$ RUST_BACKTRACE=full rustc 1.rs
error[E0308]: mismatched types
--> 1.rs:24:7
|
24 | H["?"].f();
| ^^^ expected u32, found reference
|
= note: expected type `u32`
found type `&'static str`
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 're-trying op failed', src/libcore/option.rs:794
stack backtrace:
<snip>
8: 0x10b01e97d - core::option::expect_failed::hf6ddaca0707dee4e
9: 0x105eb9076 - rustc_typeck::check::method::confirm::ConfirmContext::convert_lvalue_op_to_mutable::h0a19643fe67bd473
10: 0x105eb8024 - rustc_typeck::check::method::confirm::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::confirm_method::h9b8161ac9ec72016
11: 0x105ecc2c7 - rustc_typeck::check::method::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::lookup_method::h56ef9ae2ed618970
12: 0x105f0c021 - rustc_typeck::check::FnCtxt::check_expr_kind::ha9d720cdd9d40244
13: 0x105f0b0f1 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h4f8d554dc5adc888
14: 0x105f16456 - rustc_typeck::check::FnCtxt::check_stmt::h1e4e8f5a38945d3e
15: 0x105f16d9e - rustc_typeck::check::FnCtxt::check_block_with_expected::{{closure}}::h6f559beafce939e1
16: 0x105f16801 - rustc_typeck::check::FnCtxt::check_block_with_expected::h84f076beaa14901c
17: 0x105f0bd6a - rustc_typeck::check::FnCtxt::check_expr_kind::ha9d720cdd9d40244
18: 0x105f0b0f1 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref::h4f8d554dc5adc888
19: 0x105f0771d - rustc_typeck::check::FnCtxt::check_return_expr::h66476709e0aa025f
20: 0x105ef9187 - rustc_typeck::check::check_fn::hb2223142c4611e49
21: 0x105ef7a88 - rustc_typeck::check::typeck_tables_of::h785f93dd2c741a2a
22: 0x106f0dc45 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get::hb0a5c702c688f9b2
23: 0x106f252da - rustc::ty::maps::TyCtxtAt::typeck_tables_of::h7ee387f800510609
24: 0x106f2246e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of::h5646cf71d082673b
25: 0x105ef688f - rustc_typeck::check::typeck_item_bodies::h1eba66163e21279e
26: 0x106f0cdc9 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get::h5bf6b361e42fe78d
27: 0x106f25166 - rustc::ty::maps::TyCtxtAt::typeck_item_bodies::hc87e6dcd01e3f40e
28: 0x106f22432 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies::h7c99318169c1ed83
29: 0x105f4f56e - rustc_typeck::check_crate::h137c39114e0bfc61
<snip>
$ rustc -vV
rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)
binary: rustc
commit-hash: 2d4ed8e0cbe2c5f3763273a5d8f6b15119473ba7
commit-date: 2017-05-03
host: x86_64-apple-darwin
release: 1.19.0-nightly
LLVM version: 4.0
Additionally, on stable 1.17.0 and beta 1.18.0-beta.1 this program prints the error E0308 twice,
error[E0308]: mismatched types
--> 1.rs:24:7
|
24 | H["?"].f();
| ^^^ expected u32, found reference
|
= note: expected type `u32`
found type `&'static str`
error[E0308]: mismatched types
--> 1.rs:24:7
|
24 | H["?"].f();
| ^^^ expected u32, found reference
|
= note: expected type `u32`
found type `&'static str`
error: aborting due to 2 previous errors
Metadata
Metadata
Assignees
Labels
No labels