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

ICE: begin <= end (12 <= 11) when slicing 'Self::Assoc<'_>' #123414

Closed
cushionbadak opened this issue Apr 3, 2024 · 2 comments · Fixed by #123523
Closed

ICE: begin <= end (12 <= 11) when slicing 'Self::Assoc<'_>' #123414

cushionbadak opened this issue Apr 3, 2024 · 2 comments · Fixed by #123523
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Note

This issue is almost identical to closed issue #121807 , but ICE-triggering input is slightly differnent from previous one.

Code

trait MemoryUnit {
    extern "C" fn read_word(&mut self) -> u8;
    extern "C" fn read_dword(Self::Assoc<'_>) -> u16;
}

struct ROM {}

impl MemoryUnit for ROM {
    extern "C" fn read_dword(&'_ self) -> u16 {
        let a16 = self.read_word() as u16;
        let b16 = self.read_word() as u16;

        (b16 << 8) | a16
    }
}

pub fn main() {}

original test-case's read_dword(&'s self) is mutated to read_dword(&'_ self).

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (88c2f4f5f 2024-04-02)
binary: rustc
commit-hash: 88c2f4f5f50ace5ddc7655ea311435104d3659bd
commit-date: 2024-04-02
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Error output

warning: anonymous parameters are deprecated and will be removed in the next edition
 --> reduced_87933A3C2BEEFEEAFED61025DEE0BD738BBBDEBB1F116B588A791E327AE11916.rs:3:30
  |
3 |     extern "C" fn read_dword(Self::Assoc<'_>) -> u16;
  |                              ^^^^^^^^^^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: Self::Assoc<'_>`
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
  = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
  = note: `#[warn(anonymous_parameters)]` on by default

error[E0220]: associated type `Assoc` not found for `Self`
 --> reduced_87933A3C2BEEFEEAFED61025DEE0BD738BBBDEBB1F116B588A791E327AE11916.rs:3:36
  |
3 |     extern "C" fn read_dword(Self::Assoc<'_>) -> u16;
  |                                    ^^^^^ associated type `Assoc` not found

error[E0185]: method `read_dword` has a `&self` declaration in the impl, but not in the trait
 --> reduced_87933A3C2BEEFEEAFED61025DEE0BD738BBBDEBB1F116B588A791E327AE11916.rs:9:5
  |
3 |     extern "C" fn read_dword(Self::Assoc<'_>) -> u16;
  |     ------------------------------------------------- trait method declared without `&self`
...
9 |     extern "C" fn read_dword(&'_ self) -> u16 {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl

error[E0046]: not all trait items implemented, missing: `read_word`
 --> reduced_87933A3C2BEEFEEAFED61025DEE0BD738BBBDEBB1F116B588A791E327AE11916.rs:8:1
  |
2 |     extern "C" fn read_word(&mut self) -> u8;
  |     ----------------------------------------- `read_word` from trait
...
8 | impl MemoryUnit for ROM {
  | ^^^^^^^^^^^^^^^^^^^^^^^ missing `read_word` in implementation
Backtrace

thread 'rustc' panicked at compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs:1366:48:
begin <= end (12 <= 11) when slicing `Self::Assoc<'_>`
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
   4: rustc_borrowck::diagnostics::mutability_errors::suggest_ampmut_self
   5: <rustc_borrowck::MirBorrowckCtxt>::suggest_make_local_mut
   6: <rustc_borrowck::MirBorrowckCtxt>::report_mutability_error
   7: <rustc_borrowck::MirBorrowckCtxt>::access_place
   8: <rustc_borrowck::MirBorrowckCtxt>::consume_rvalue
   9: rustc_borrowck::do_mir_borrowck
  10: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
  11: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  14: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: it seems that this compiler `1.79.0-nightly (88c2f4f5f 2024-04-02)` is outdated, a newer nightly should have been released in the mean time
  |
  = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
  = note: if the problem still persists, we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/Volumes/T7/workspace/placeholder_rustexec/0403/rustc-ice-2024-04-03T14_18_05-88650.txt` to your bug report

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at reduced_87933A3C2BEEFEEAFED61025DEE0BD738BBBDEBB1F116B588A791E327AE11916.rs:8:1: 8:24>::read_dword`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0046, E0185, E0220.
For more information about an error, try `rustc --explain E0046`.

@cushionbadak cushionbadak added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 3, 2024
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints A-borrow-checker Area: The borrow checker S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 3, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Apr 5, 2024

Similar variants:

trait MemoryUnit {
    extern "C" fn read_word(&mut self) -> u8;
    extern "C" fn read_dword(x: &Self<'_>) -> u16;
}

struct ROM {}

impl MemoryUnit for ROM {
    extern "C" fn read_dword(&'_ self) -> u16 {
        let a16 = self.read_word() as u16;
        let b16 = self.read_word() as u16;

        (b16 << 8) | a16
    }
}

the suggestion that's triggering the ICE is not ready for HIR typeck to not fail before MIR borrowck is reached.

LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => {
let suggestion = suggest_ampmut_self(self.infcx.tcx, decl_span);
Some((true, decl_span, suggestion))
}

Since now it doesn't fail in HIR typeck, the diagnostic can no longer use suggest_ampmut_self (it can no longer assume the trait's item's first local is some variant of simple implicit self)

estebank added a commit to estebank/rust that referenced this issue Apr 5, 2024
…rom ref to mut ref

Do not ICE when encountering a lifetime error involving an argument with an immutable reference of a method that differs from the trait definition.

Fix rust-lang#123414.
estebank added a commit to estebank/rust that referenced this issue Apr 6, 2024
…rom ref to mut ref

Do not ICE when encountering a lifetime error involving an argument with
an immutable reference of a method that differs from the trait definition.

Fix rust-lang#123414.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 11, 2024
Account for trait/impl difference when suggesting changing argument from ref to mut ref

Do not ICE when encountering a lifetime error involving an argument with an immutable reference of a method that differs from the trait definition.

Fix rust-lang#123414.
@bors bors closed this as completed in 731c0e5 Apr 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 12, 2024
Rollup merge of rust-lang#123523 - estebank:issue-123414, r=BoxyUwU

Account for trait/impl difference when suggesting changing argument from ref to mut ref

Do not ICE when encountering a lifetime error involving an argument with an immutable reference of a method that differs from the trait definition.

Fix rust-lang#123414.
@cushionbadak
Copy link
Author

searched nightlies: from nightly-2024-01-01 to nightly-2024-04-04
regressed nightly: nightly-2024-02-09
searched commit range: 8ace7ea...98aa362
regressed commit: af88f7d

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-apple-darwin
Reproduce with:

cargo bisect-rustc --start=2024-01-01 --end=2024-04-04 --preserve --regress=ice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants