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: X should not have been constrained via normalization #126725

Open
matthiaskrgr opened this issue Jun 20, 2024 · 2 comments · Fixed by #132214
Open

ICE: X should not have been constrained via normalization #126725

matthiaskrgr opened this issue Jun 20, 2024 · 2 comments · Fixed by #132214
Assignees
Labels
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):

trait Foo {
    fn foo<'a>(&'a self) -> <&'a impl Sized as Bar>::Output;
}

trait Bar {
    type Output;
}

struct X(i32);

impl<'a> Bar for &'a X {
    type Output = &'a i32;
}

impl Foo for X {
    fn foo<'a>(&'a self) -> <&'a Self as Bar>::Output {
        &self.0
    }
}

original:

fn main() {
    let x = X(15);
    let y = x.foo();
    println!("{:?}",y);
}

trait Foo {
    fn foo<'a>(&'a self) -> <&'a impl Sized as Bar>::Output;
}

trait Bar {
    type Output;
}

struct X(i32);

impl<'a> Bar for &'a X {
    type Output = &'a i32;
}

impl Foo for X {
    fn foo<'a>(&'a self) -> <&'a Self as Bar>::Output {
        &self.0
    }
}

Version information

rustc 1.81.0-nightly (3d5d7a24f 2024-06-19)
binary: rustc
commit-hash: 3d5d7a24f76006b391d8a53d903ae64c1b4a52d2
commit-date: 2024-06-19
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

error[E0667]: `impl Trait` is not allowed in path parameters
 --> /tmp/icemaker_global_tempdir.KXWchhk7HuyN/rustc_testrunner_tmpdir_reporting.A8BXzoc3mNcQ/mvce.rs:2:34
  |
2 |     fn foo<'a>(&'a self) -> <&'a impl Sized as Bar>::Output;
  |                                  ^^^^^^^^^^

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.KXWchhk7HuyN/rustc_testrunner_tmpdir_reporting.A8BXzoc3mNcQ/mvce.rs:19:2
   |
19 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.KXWchhk7HuyN/rustc_testrunner_tmpdir_reporting.A8BXzoc3mNcQ/mvce.rs`

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/compare_impl_item.rs:553:13:
X should not have been constrained via normalization
stack backtrace:
   0:     0x7f664e563915 - std::backtrace_rs::backtrace::libunwind::trace::h7710708045c6b905
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f664e563915 - std::backtrace_rs::backtrace::trace_unsynchronized::h877fe1ea27df51dc
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f664e563915 - std::sys::backtrace::_print_fmt::ha3ebaa2154f7d3cf
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/backtrace.rs:68:5
   3:     0x7f664e563915 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hfe4a08ea96301f2e
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/backtrace.rs:44:22
   4:     0x7f664e5b44bb - core::fmt::rt::Argument::fmt::h2294c3ac43b5ff98
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/core/src/fmt/rt.rs:165:63
   5:     0x7f664e5b44bb - core::fmt::write::h77cb689ff8a7e181
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/core/src/fmt/mod.rs:1168:21
   6:     0x7f664e5585af - std::io::Write::write_fmt::hb5a06bc50edaab60
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/io/mod.rs:1835:15
   7:     0x7f664e5636ee - std::sys::backtrace::_print::h1e23385cc7309809
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/backtrace.rs:47:5
   8:     0x7f664e5636ee - std::sys::backtrace::print::h2eec07d683dcedb2
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/backtrace.rs:34:9
   9:     0x7f664e566129 - std::panicking::default_hook::{{closure}}::hab98a779bfa94b9a
  10:     0x7f664e565ecc - std::panicking::default_hook::he086b8d50b533063
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/panicking.rs:292:9
  11:     0x7f664ab5f49f - std[dbc24bd242c6e4df]::panicking::update_hook::<alloc[37b1fde2ea0a167a]::boxed::Box<rustc_driver_impl[c1f27b1b5d1e2f7b]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f664e566a4f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h5a3e80ce9f8fca6a
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/alloc/src/boxed.rs:2076:9
  13:     0x7f664e566a4f - std::panicking::rust_panic_with_hook::h2d53698c2dcbf3bc
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/panicking.rs:804:13
  14:     0x7f664e566677 - std::panicking::begin_panic_handler::{{closure}}::h3b368e6c6e10fc40
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/panicking.rs:670:13
  15:     0x7f664e563dd9 - std::sys::backtrace::__rust_end_short_backtrace::hefb4b0a87b200300
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/backtrace.rs:171:18
  16:     0x7f664e566304 - rust_begin_unwind
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/panicking.rs:661:5
  17:     0x7f664e5b0a73 - core::panicking::panic_fmt::h915bf95191b1f9f2
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/core/src/panicking.rs:74:14
  18:     0x7f664ad0a34f - rustc_hir_analysis[9774bcfb3f362306]::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys::{closure#0}
  19:     0x7f664b4e94f3 - rustc_query_impl[856b5675e5c7de0f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[856b5675e5c7de0f]::query_impl::collect_return_position_impl_trait_in_trait_tys::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>
  20:     0x7f664c0a041b - rustc_query_system[a3103274ffce3a93]::query::plumbing::try_execute_query::<rustc_query_impl[856b5675e5c7de0f]::DynamicConfig<rustc_query_system[a3103274ffce3a93]::query::caches::DefIdCache<rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[856b5675e5c7de0f]::plumbing::QueryCtxt, false>
  21:     0x7f664b4eb798 - rustc_query_impl[856b5675e5c7de0f]::query_impl::collect_return_position_impl_trait_in_trait_tys::get_query_non_incr::__rust_end_short_backtrace
  22:     0x7f664c7e2f40 - rustc_middle[8eb79f70a5820685]::query::plumbing::query_get_at::<rustc_query_system[a3103274ffce3a93]::query::caches::DefIdCache<rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>>
  23:     0x7f6649950e32 - rustc_hir_analysis[9774bcfb3f362306]::collect::type_of::type_of
  24:     0x7f664c0a182a - rustc_query_impl[856b5675e5c7de0f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[856b5675e5c7de0f]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f664c0a041b - rustc_query_system[a3103274ffce3a93]::query::plumbing::try_execute_query::<rustc_query_impl[856b5675e5c7de0f]::DynamicConfig<rustc_query_system[a3103274ffce3a93]::query::caches::DefIdCache<rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[856b5675e5c7de0f]::plumbing::QueryCtxt, false>
  26:     0x7f664c09ffbb - rustc_query_impl[856b5675e5c7de0f]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7f664c7e2f40 - rustc_middle[8eb79f70a5820685]::query::plumbing::query_get_at::<rustc_query_system[a3103274ffce3a93]::query::caches::DefIdCache<rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 8usize]>>>
  28:     0x7f6649959866 - rustc_hir_analysis[9774bcfb3f362306]::check::wfcheck::check_well_formed
  29:     0x7f664c3ecaa9 - rustc_query_impl[856b5675e5c7de0f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[856b5675e5c7de0f]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7f664c3ecd2a - rustc_query_system[a3103274ffce3a93]::query::plumbing::try_execute_query::<rustc_query_impl[856b5675e5c7de0f]::DynamicConfig<rustc_query_system[a3103274ffce3a93]::query::caches::VecCache<rustc_hir[9fcca5f37a823dfc]::hir_id::OwnerId, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[856b5675e5c7de0f]::plumbing::QueryCtxt, false>
  31:     0x7f664c3eca86 - rustc_query_impl[856b5675e5c7de0f]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f664c3ed801 - rustc_hir_analysis[9774bcfb3f362306]::check::wfcheck::check_mod_type_wf
  33:     0x7f664c3ed647 - rustc_query_impl[856b5675e5c7de0f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[856b5675e5c7de0f]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>
  34:     0x7f664ca886f0 - rustc_query_system[a3103274ffce3a93]::query::plumbing::try_execute_query::<rustc_query_impl[856b5675e5c7de0f]::DynamicConfig<rustc_query_system[a3103274ffce3a93]::query::caches::DefaultCache<rustc_span[6d5d3be9d9ece40]::def_id::LocalModDefId, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[856b5675e5c7de0f]::plumbing::QueryCtxt, false>
  35:     0x7f664ca88499 - rustc_query_impl[856b5675e5c7de0f]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f664c3ff44c - rustc_hir_analysis[9774bcfb3f362306]::check_crate
  37:     0x7f664ca03747 - rustc_interface[744b99f34e0a116f]::passes::analysis
  38:     0x7f664ca03287 - rustc_query_impl[856b5675e5c7de0f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[856b5675e5c7de0f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7f664ce532a5 - rustc_query_system[a3103274ffce3a93]::query::plumbing::try_execute_query::<rustc_query_impl[856b5675e5c7de0f]::DynamicConfig<rustc_query_system[a3103274ffce3a93]::query::caches::SingleCache<rustc_middle[8eb79f70a5820685]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[856b5675e5c7de0f]::plumbing::QueryCtxt, false>
  40:     0x7f664ce5300f - rustc_query_impl[856b5675e5c7de0f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7f664ccf6692 - rustc_interface[744b99f34e0a116f]::interface::run_compiler::<core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>, rustc_driver_impl[c1f27b1b5d1e2f7b]::run_compiler::{closure#0}>::{closure#1}
  42:     0x7f664cce40e7 - std[dbc24bd242c6e4df]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[744b99f34e0a116f]::util::run_in_thread_with_globals<rustc_interface[744b99f34e0a116f]::util::run_in_thread_pool_with_globals<rustc_interface[744b99f34e0a116f]::interface::run_compiler<core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>, rustc_driver_impl[c1f27b1b5d1e2f7b]::run_compiler::{closure#0}>::{closure#1}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>::{closure#0}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>
  43:     0x7f664cce3eaa - <<std[dbc24bd242c6e4df]::thread::Builder>::spawn_unchecked_<rustc_interface[744b99f34e0a116f]::util::run_in_thread_with_globals<rustc_interface[744b99f34e0a116f]::util::run_in_thread_pool_with_globals<rustc_interface[744b99f34e0a116f]::interface::run_compiler<core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>, rustc_driver_impl[c1f27b1b5d1e2f7b]::run_compiler::{closure#0}>::{closure#1}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>::{closure#0}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ac7617a62e79589c]::result::Result<(), rustc_span[6d5d3be9d9ece40]::ErrorGuaranteed>>::{closure#2} as core[ac7617a62e79589c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7f664e5708cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h98214f1bce33fab6
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/alloc/src/boxed.rs:2062:9
  45:     0x7f664e5708cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3f9121c2985de03a
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/alloc/src/boxed.rs:2062:9
  46:     0x7f664e5708cb - std::sys::pal::unix::thread::Thread::new::thread_start::h4f5fdfa8e67af1f6
                               at /rustc/3d5d7a24f76006b391d8a53d903ae64c1b4a52d2/library/std/src/sys/pal/unix/thread.rs:108:17
  47:     0x7f66476a6ded - <unknown>
  48:     0x7f664772a0dc - <unknown>
  49:                0x0 - <unknown>

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

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.81.0-nightly (3d5d7a24f 2024-06-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [collect_return_position_impl_trait_in_trait_tys] comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
#1 [type_of] computing type of `<impl at /tmp/icemaker_global_tempdir.KXWchhk7HuyN/rustc_testrunner_tmpdir_reporting.A8BXzoc3mNcQ/mvce.rs:15:1: 15:15>::{synthetic#0}`
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0601, E0667.
For more information about an error, try `rustc --explain E0601`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jun 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 20, 2024
@compiler-errors compiler-errors self-assigned this Jun 20, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 30, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 5, 2024
@fmease
Copy link
Member

fmease commented Oct 27, 2024

Smaller:

trait Foo {
    fn foo<'a>() -> <&'a impl Sized as Bar>::Output;
}

trait Bar {
    type Output;
}

impl<'a> Bar for &'a () {
    type Output = &'a i32;
}

impl Foo for () {
    fn foo<'a>() -> <&'a Self as Bar>::Output {
        &0
    }
}

fn main() {}

@fmease
Copy link
Member

fmease commented Oct 27, 2024

While my PR #132214 fixes the ICE from the issue description, the underlying bug won't be fixed by it -- my PR simply masks it. Below you can find a reproducer that will trigger even with my PR:

type Indirect<T> = <T as Bar>::Output;

trait Foo {
    fn foo<'a>() -> Indirect<&'a impl Sized>;
}

trait Bar {
    type Output;
}

impl<'a> Bar for &'a () {
    type Output = &'a i32;
}

impl Foo for () {
    fn foo<'a>() -> <&'a Self as Bar>::Output {
        &0
    }
}

fn main() {}

I basically applied by newfound tool for sidestepping "impl Trait is not allowed in path [...]": #132212 (:P)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 27, 2024
…compiler-errors

Cleanup: Move an impl-Trait check from AST validation to AST lowering

Namely the one that rejects `impl Trait` in qself types and non-final path segments.
There's no good reason to perform this during AST validation.
We have better infrastructure in place in the AST lowerer (`ImplTraitContext`).
This shaves off a lot of code.
We now lower `impl Trait` in bad positions to `{type error}` which allows us to
remove a special case from HIR ty lowering.

Coincidentally fixes rust-lang#126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
@bors bors closed this as completed in 574a8ba Oct 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 27, 2024
Rollup merge of rust-lang#132214 - fmease:mv-impl-trait-val-paths, r=compiler-errors

Cleanup: Move an impl-Trait check from AST validation to AST lowering

Namely the one that rejects `impl Trait` in qself types and non-final path segments.
There's no good reason to perform this during AST validation.
We have better infrastructure in place in the AST lowerer (`ImplTraitContext`).
This shaves off a lot of code.
We now lower `impl Trait` in bad positions to `{type error}` which allows us to
remove a special case from HIR ty lowering.

Coincidentally fixes rust-lang#126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
@fmease fmease reopened this Oct 27, 2024
@fmease fmease removed the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants