rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.88k stars 12.78k forks source link

ICE: `unexpected 'SelfCtor' in pattern, expected identifier` #133272

Closed matthiaskrgr closed 2 days ago

matthiaskrgr commented 5 days ago

auto-reduced (treereduce-rust):


impl Foo { fn main() {

    let S { ref Self } = RAW_SLICE_TOO_LONG; 

    ;
} }

original:

struct Baz { q: Option<Foo> }
//~^ ERROR recursive types `Baz` and `Foo` have infinite size

struct Foo { q: Option<Baz> }

impl Foo { fn main() {
    let s = S { f1: 123 };
    let S { ref Self } = RAW_SLICE_TOO_LONG; //~ ERROR unused variable

    let points = vec![Point { x: 1, y: 2 }];
    let _: i32 = points.iter().map(|Point { x, y }| y).sum(); //~ ERROR unused variable

    match (s.0, 0) {
    TEST2 => println!("matched"),
    //~^ ERROR behave unpredictably
    _ => panic!("didn't match")
  };
} }

fn main() {}

Version information

rustc 1.84.0-nightly (3fee0f12e 2024-11-20)
binary: rustc
commit-hash: 3fee0f12e4f595948f8f54f57c8b7a7a58127124
commit-date: 2024-11-20
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Possibly related line of code: https://github.com/rust-lang/rust/blob/3fee0f12e4f595948f8f54f57c8b7a7a58127124/compiler/rustc_resolve/src/late.rs#L3939-L3951

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` error: expected identifier, found keyword `Self` --> /tmp/icemaker_global_tempdir.MevH4NlT2UPr/rustc_testrunner_tmpdir_reporting.rUbmgP8E1aau/mvce.rs:8:17 | 8 | let S { ref Self } = RAW_SLICE_TOO_LONG; | ^^^^ expected identifier, found keyword error: internal compiler error: unexpected `SelfCtor` in pattern, expected identifier --> /tmp/icemaker_global_tempdir.MevH4NlT2UPr/rustc_testrunner_tmpdir_reporting.rUbmgP8E1aau/mvce.rs:8:17 | 8 | let S { ref Self } = RAW_SLICE_TOO_LONG; | ^^^^ thread 'rustc' panicked at compiler/rustc_resolve/src/late.rs:3945:30: Box stack backtrace: 0: 0x70dca9e75eca - ::fmt::h462aecd04ea9579e 1: 0x70dcaa623362 - core::fmt::write::h90ee43f9ea3cba58 2: 0x70dcaba7d091 - std::io::Write::write_fmt::hedeb5e5db4a69c5c 3: 0x70dca9e75d22 - std::sys::backtrace::BacktraceLock::print::h4cd84f50718730a5 4: 0x70dca9e781fa - std::panicking::default_hook::{{closure}}::hd4c3e895ac68f35a 5: 0x70dca9e78060 - std::panicking::default_hook::h63638a03e198d592 6: 0x70dca8efbc25 - std[2244cad2f80807fb]::panicking::update_hook::>::{closure#0} 7: 0x70dca9e788d8 - std::panicking::rust_panic_with_hook::hb612322ec5da5d64 8: 0x70dca8f362a1 - std[2244cad2f80807fb]::panicking::begin_panic::::{closure#0} 9: 0x70dca8f29266 - std[2244cad2f80807fb]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x70dca8f24839 - std[2244cad2f80807fb]::panicking::begin_panic:: 11: 0x70dca8f401d1 - ::emit_producing_guarantee 12: 0x70dca9a0ebf4 - ::span_bug:: 13: 0x70dcab3da5cf - ::walk::<::resolve_pattern_inner::{closure#0}> 14: 0x70dcab3d945a - ::walk::<::resolve_pattern_inner::{closure#0}> 15: 0x70dcab3e7cf2 - ::resolve_block 16: 0x70dcab3e1be9 - ::visit_fn 17: 0x70dcab40d3a7 - ::visit_item 18: 0x70dcab9a3ff8 - ::resolve_crate::{closure#0} 19: 0x70dcab99e4bf - ::resolve_crate 20: 0x70dcaaa9f94f - rustc_interface[c2b60ea3c5f8ab84]::passes::resolver_for_lowering_raw 21: 0x70dcaaa9ea4d - rustc_query_impl[6938d1d3b9759c59]::plumbing::__rust_begin_short_backtrace::> 22: 0x70dcaaa9ea25 - >::call_once 23: 0x70dcab5e9b24 - rustc_query_system[37669824fe84eed8]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[6938d1d3b9759c59]::plumbing::QueryCtxt, false> 24: 0x70dcab5e97e0 - rustc_query_impl[6938d1d3b9759c59]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace 25: 0x70dcab50ff9e - rustc_interface[c2b60ea3c5f8ab84]::interface::run_compiler::, rustc_driver_impl[a02cca374e721ba2]::run_compiler::{closure#0}>::{closure#1} 26: 0x70dcab5401e0 - std[2244cad2f80807fb]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[a02cca374e721ba2]::run_compiler::{closure#0}>::{closure#1}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>>::{closure#0}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>> 27: 0x70dcab53fefd - <::spawn_unchecked_, rustc_driver_impl[a02cca374e721ba2]::run_compiler::{closure#0}>::{closure#1}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>>::{closure#0}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>>::{closure#1} as core[f62530bb87197118]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 28: 0x70dcab53f6b9 - std::sys::pal::unix::thread::Thread::new::thread_start::hbfb59c93227878ea 29: 0x70dcacd9c39d - 30: 0x70dcace2149c - 31: 0x0 - note: 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 make sure that you have updated to the latest nightly note: rustc 1.84.0-nightly (3fee0f12e 2024-11-20) running on x86_64-unknown-linux-gnu query stack during panic: #0 [resolver_for_lowering_raw] getting the resolver for lowering end of query stack error: aborting due to 2 previous errors ```

matthiaskrgr commented 5 days ago
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
matthiaskrgr commented 5 days ago

Regression in nightly-2024-02-22

commit[0] 2024-02-20: Auto merge of #121345 - Nilstrieb:rollup-reb0xge, r=Nilstrieb commit[1] 2024-02-20: Auto merge of #121356 - matthiaskrgr:rollup-d80af2s, r=matthiaskrgr commit[2] 2024-02-21: Auto merge of #120904 - Nadrieril:match-lowering-intermediate-repr, r=matthewjasper commit[3] 2024-02-21: Auto merge of #121172 - Nadrieril:simplify-empty-selection, r=matthewjasper commit[4] 2024-02-21: Auto merge of #121380 - weihanglo:update-cargo, r=weihanglo commit[5] 2024-02-21: Auto merge of #120588 - alexcrichton:wasm-rmeta-object, r=wesleywiser,bjorn3 commit[6] 2024-02-21: Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercote commit[7] 2024-02-21: Auto merge of #121383 - Dylan-DPC:rollup-735p4u4, r=Dylan-DPC commit[8] 2024-02-21: Auto merge of #121400 - fmease:rollup-8m29g7a, r=fmease commit[9] 2024-02-21: Auto merge of #121321 - compiler-errors:yeet-querytyperelating, r=lcnr commit[10] 2024-02-21: Auto merge of #117658 - RalfJung:ptr-dangling, r=m-ou-se

jieyouxu commented 4 days ago

This is because #121208 changed the delayed_bug to bug, but it just means that we lacked any test coverage that could've hit that.