Skip to content

Wrong caller location for overloaded index operator #114388

Closed
@ebds-rs

Description

@ebds-rs

Code

for i in 0..=255 {
    for j in 0..=255 {
        for k in 0..=255 {
            &std::str::from_utf8(&[i, j, k])
                .unwrap_or("XXX")
                .to_uppercase()[..3];
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: x86_64-unknown-linux-gnu
release: 1.71.0
LLVM version: 16.0.5

Error output

failures:

---- tests::it_works stdout ----
thread 'tests::it_works' panicked at 'byte index 3 is out of bounds of `I`', src/lib.rs:15:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Backtrace

failures:

---- tests::it_works stdout ----
thread 'tests::it_works' panicked at 'byte index 3 is out of bounds of `I`', src/lib.rs:15:22
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/str/mod.rs:87:9
   4: core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::RangeTo<usize>>::index
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/str/traits.rs:309:21
   5: core::str::traits::<impl core::ops::index::Index<I> for str>::index
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/str/traits.rs:61:15
   6: <alloc::string::String as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/alloc/src/string.rs:2358:10
   7: ice_oob::tests::it_works
             at ./src/lib.rs:15:22
   8: ice_oob::tests::it_works::{{closure}}
             at ./src/lib.rs:11:19
   9: core::ops::function::FnOnce::call_once
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
  10: core::ops::function::FnOnce::call_once
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions