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: unexpected 'SelfCtor' in pattern, expected identifier #133272

Closed
matthiaskrgr opened this issue Nov 21, 2024 · 3 comments · Fixed by #133286
Closed

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

matthiaskrgr opened this issue Nov 21, 2024 · 3 comments · Fixed by #133286
Assignees
Labels
A-patterns Relating to patterns and pattern matching 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.

Comments

@matthiaskrgr
Copy link
Member

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:

None
}
Res::SelfCtor(_) => {
// We resolve `Self` in pattern position as an ident sometimes during recovery,
// so delay a bug instead of ICEing. (Note: is this no longer true? We now ICE. If
// this triggers, please convert to a delayed bug and add a test.)
self.r.dcx().span_bug(
ident.span,
"unexpected `SelfCtor` in pattern, expected identifier"
);
}
_ => span_bug!(
ident.span,

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<dyn Any>
stack backtrace:
   0:     0x70dca9e75eca - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::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::<alloc[cbefbba4106c24e6]::boxed::Box<rustc_driver_impl[a02cca374e721ba2]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x70dca9e788d8 - std::panicking::rust_panic_with_hook::hb612322ec5da5d64
   8:     0x70dca8f362a1 - std[2244cad2f80807fb]::panicking::begin_panic::<rustc_errors[f9771b9e181d5533]::ExplicitBug>::{closure#0}
   9:     0x70dca8f29266 - std[2244cad2f80807fb]::sys::backtrace::__rust_end_short_backtrace::<std[2244cad2f80807fb]::panicking::begin_panic<rustc_errors[f9771b9e181d5533]::ExplicitBug>::{closure#0}, !>
  10:     0x70dca8f24839 - std[2244cad2f80807fb]::panicking::begin_panic::<rustc_errors[f9771b9e181d5533]::ExplicitBug>
  11:     0x70dca8f401d1 - <rustc_errors[f9771b9e181d5533]::diagnostic::BugAbort as rustc_errors[f9771b9e181d5533]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x70dca9a0ebf4 - <rustc_errors[f9771b9e181d5533]::DiagCtxtHandle>::span_bug::<rustc_span[17c8ace98e68264b]::span_encoding::Span, &str>
  13:     0x70dcab3da5cf - <rustc_ast[cb4a9f145e050deb]::ast::Pat>::walk::<<rustc_resolve[da9d6586afcb5ccb]::late::LateResolutionVisitor>::resolve_pattern_inner::{closure#0}>
  14:     0x70dcab3d945a - <rustc_ast[cb4a9f145e050deb]::ast::Pat>::walk::<<rustc_resolve[da9d6586afcb5ccb]::late::LateResolutionVisitor>::resolve_pattern_inner::{closure#0}>
  15:     0x70dcab3e7cf2 - <rustc_resolve[da9d6586afcb5ccb]::late::LateResolutionVisitor>::resolve_block
  16:     0x70dcab3e1be9 - <rustc_resolve[da9d6586afcb5ccb]::late::LateResolutionVisitor as rustc_ast[cb4a9f145e050deb]::visit::Visitor>::visit_fn
  17:     0x70dcab40d3a7 - <rustc_resolve[da9d6586afcb5ccb]::late::LateResolutionVisitor as rustc_ast[cb4a9f145e050deb]::visit::Visitor>::visit_item
  18:     0x70dcab9a3ff8 - <rustc_resolve[da9d6586afcb5ccb]::Resolver>::resolve_crate::{closure#0}
  19:     0x70dcab99e4bf - <rustc_resolve[da9d6586afcb5ccb]::Resolver>::resolve_crate
  20:     0x70dcaaa9f94f - rustc_interface[c2b60ea3c5f8ab84]::passes::resolver_for_lowering_raw
  21:     0x70dcaaa9ea4d - rustc_query_impl[6938d1d3b9759c59]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6938d1d3b9759c59]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[65a7c84fae00e80e]::query::erase::Erased<[u8; 16usize]>>
  22:     0x70dcaaa9ea25 - <rustc_query_impl[6938d1d3b9759c59]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[f62530bb87197118]::ops::function::FnOnce<(rustc_middle[65a7c84fae00e80e]::ty::context::TyCtxt, ())>>::call_once
  23:     0x70dcab5e9b24 - rustc_query_system[37669824fe84eed8]::query::plumbing::try_execute_query::<rustc_query_impl[6938d1d3b9759c59]::DynamicConfig<rustc_query_system[37669824fe84eed8]::query::caches::SingleCache<rustc_middle[65a7c84fae00e80e]::query::erase::Erased<[u8; 16usize]>>, 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::<core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>, rustc_driver_impl[a02cca374e721ba2]::run_compiler::{closure#0}>::{closure#1}
  26:     0x70dcab5401e0 - std[2244cad2f80807fb]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2b60ea3c5f8ab84]::util::run_in_thread_with_globals<rustc_interface[c2b60ea3c5f8ab84]::util::run_in_thread_pool_with_globals<rustc_interface[c2b60ea3c5f8ab84]::interface::run_compiler<core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>, 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 - <<std[2244cad2f80807fb]::thread::Builder>::spawn_unchecked_<rustc_interface[c2b60ea3c5f8ab84]::util::run_in_thread_with_globals<rustc_interface[c2b60ea3c5f8ab84]::util::run_in_thread_pool_with_globals<rustc_interface[c2b60ea3c5f8ab84]::interface::run_compiler<core[f62530bb87197118]::result::Result<(), rustc_span[17c8ace98e68264b]::ErrorGuaranteed>, 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 - <unknown>
  30:     0x70dcace2149c - <unknown>
  31:                0x0 - <unknown>

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 matthiaskrgr 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 Nov 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2024
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Nov 21, 2024

impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}

@matthiaskrgr
Copy link
Member Author

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

@matthiaskrgr matthiaskrgr added the A-patterns Relating to patterns and pattern matching label Nov 21, 2024
@jieyouxu jieyouxu self-assigned this Nov 21, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 21, 2024
@jieyouxu
Copy link
Member

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.

jieyouxu added a commit to jieyouxu/rust that referenced this issue Nov 21, 2024
For the code pattern reported in
<rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a
`span_bug` from a `span_delayed_bug` because this specific self-ctor
code pattern lacked test coverage. It turns out this can be hit but we
just lacked test coverage, so change it back to a `span_delayed_bug` and
add a target tested case.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Nov 22, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc `@nnethercote` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
jhpratt added a commit to jhpratt/rust that referenced this issue Nov 22, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Nov 22, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc ```@nnethercote``` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Nov 22, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc ````@nnethercote```` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Nov 23, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc `````@nnethercote````` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 23, 2024
…-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc `@nnethercote` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
@bors bors closed this as completed in 4d9cd66 Nov 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 23, 2024
Rollup merge of rust-lang#133286 - jieyouxu:bug-ourselves, r=compiler-errors

Re-delay a resolve `bug` related to `Self`-ctor in patterns

For the code pattern reported in <rust-lang#133272>,

```rs
impl Foo {
   fn fun() {
        let S { ref Self } = todo!();
   }
}
```

<rust-lang#121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case.

Follow-up to rust-lang#121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps).
Fixes rust-lang#133272.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants