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

false positive when associated_type_bounds used with for<> on super traits #121929

Open
fee1-dead opened this issue Mar 3, 2024 · 2 comments
Open
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_type_bounds `#![feature(associated_type_bounds)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fee1-dead
Copy link
Member

fee1-dead commented Mar 3, 2024

cc #52662.

I tried this code: (play)

#![feature(associated_type_bounds)]

pub trait Rando {}
pub trait Foo<Rhs> {
    type Opaque;
}

pub trait GroupOpsOwned<Rhs = Self, Output = Self>: for<'r> Foo<&'r Rhs, Opaque: Rando> {}

pub trait Curve: Sized + GroupOpsOwned<Self::AffineRepr> {
    type AffineRepr;
}

pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> {
    type Affine;
}

I expected to see this happen: compiles successfully

Instead, this happened: does not compile, with confusing errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `for<'r> Self: Foo<&'r <Self as CofactorCurve>::Affine>` is not satisfied
  --> src/lib.rs:14:1
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'r> Foo<&'r <Self as CofactorCurve>::Affine>` is not implemented for `Self`
   |
help: consider further restricting `Self`
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> + for<'r> Foo<&'r <Self as CofactorCurve>::Affine> {
   |                                                                              ++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `Self: GroupOpsOwned<<Self as CofactorCurve>::Affine>` is not satisfied
  --> src/lib.rs:14:26
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> {
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `GroupOpsOwned<<Self as CofactorCurve>::Affine>` is not implemented for `Self`
   |
note: required by a bound in `Curve`
  --> src/lib.rs:10:26
   |
10 | pub trait Curve: Sized + GroupOpsOwned<Self::AffineRepr> {
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Curve`
help: consider further restricting `Self`
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> + GroupOpsOwned<<Self as CofactorCurve>::Affine> {
   |                                                                              ++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `for<'r> Self: Foo<&'r <Self as CofactorCurve>::Affine>` is not satisfied
  --> src/lib.rs:15:5
   |
15 |     type Affine;
   |     ^^^^^^^^^^^ the trait `for<'r> Foo<&'r <Self as CofactorCurve>::Affine>` is not implemented for `Self`
   |
help: consider further restricting `Self`
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine> + for<'r> Foo<&'r <Self as CofactorCurve>::Affine> {
   |                                                                              ++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 3 previous errors

This came up while implementing #120639. If I remove the bound Opaque: Rando bound it would compile successfully.

backtrace
rustc test.rs --crate-type=lib -Z treat-err-as-bug
error: internal compiler error: `report_selection_error` did not emit an error
  --> test.rs:14:1
   |
14 | pub trait CofactorCurve: Curve<AffineRepr = <Self as CofactorCurve>::Affine...
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:1610:30:
aborting due to `-Z treat-err-as-bug=1`
stack backtrace:
   0:     0x7f8ddb90a7e6 - std::backtrace_rs::backtrace::libunwind::trace::h77800003d5e1d475
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f8ddb90a7e6 - std::backtrace_rs::backtrace::trace_unsynchronized::h053be484c7eba922
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8ddb90a7e6 - std::sys_common::backtrace::_print_fmt::h658f0ed17c0b78d9
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f8ddb90a7e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h92f7276dc2d1ad88
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f8ddb95ced0 - core::fmt::rt::Argument::fmt::heed5d96f67f8a94e
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/fmt/rt.rs:142:9
   5:     0x7f8ddb95ced0 - core::fmt::write::hb0a14a1b109d343e
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f8ddb8fe14f - std::io::Write::write_fmt::hb68419aa79b5d241
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/io/mod.rs:1810:15
   7:     0x7f8ddb90a5c4 - std::sys_common::backtrace::_print::h2515a5f3f70c3f2a
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f8ddb90a5c4 - std::sys_common::backtrace::print::haa99668665f11fc1
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f8ddb90d357 - std::panicking::default_hook::{{closure}}::h98d80deda6602b54
  10:     0x7f8ddb90d0b9 - std::panicking::default_hook::h01558a8bbd5d1c0b
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:292:9
  11:     0x7f8dd835093c - std[ca913780aff877b3]::panicking::update_hook::<alloc[6aabbde17010a607]::boxed::Box<rustc_driver_impl[c8d6e38be153bd2e]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f8ddb90daa6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1171429379e58ebd
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/alloc/src/boxed.rs:2030:9
  13:     0x7f8ddb90daa6 - std::panicking::rust_panic_with_hook::he8cd11bc79b74e48
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:783:13
  14:     0x7f8ddb90d7b9 - std::panicking::begin_panic_handler::{{closure}}::he1868b3475576648
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:649:13
  15:     0x7f8ddb90ace6 - std::sys_common::backtrace::__rust_end_short_backtrace::h9210389720f5c16a
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f8ddb90d550 - rust_begin_unwind
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:645:5
  17:     0x7f8ddb9595d5 - core::panicking::panic_fmt::hfbd09a125111b8b4
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/panicking.rs:72:14
  18:     0x7f8ddad56533 - <rustc_errors[61fc36c27e97ab9]::DiagCtxtInner>::panic_if_treat_err_as_bug.cold.0
  19:     0x7f8dda5da9c5 - <rustc_errors[61fc36c27e97ab9]::DiagCtxtInner>::emit_diagnostic_without_consuming::{closure#2}
  20:     0x7f8dda5d8c55 - rustc_interface[1bd61175f6644bbf]::callbacks::track_diagnostic
  21:     0x7f8dda5d7c5f - <rustc_errors[61fc36c27e97ab9]::DiagCtxtInner>::emit_diagnostic_without_consuming
  22:     0x7f8dda5d7af8 - <rustc_errors[61fc36c27e97ab9]::DiagCtxt>::emit_diagnostic_without_consuming
  23:     0x7f8dd838d329 - <rustc_errors[61fc36c27e97ab9]::diagnostic_builder::BugAbort as rustc_errors[61fc36c27e97ab9]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  24:     0x7f8dd8d66ca0 - <rustc_errors[61fc36c27e97ab9]::DiagCtxt>::span_bug::<rustc_span[5c4821f8b4a403f8]::span_encoding::Span, &str>
  25:     0x7f8dd8d65d47 - <rustc_errors[61fc36c27e97ab9]::DiagCtxt>::span_delayed_bug::<rustc_span[5c4821f8b4a403f8]::span_encoding::Span, &str>
  26:     0x7f8dd8e4b6a4 - <rustc_infer[78f7230a189ac689]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bff7e74ae8aeefe3]::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_selection_error
  27:     0x7f8dd8e74f11 - <rustc_infer[78f7230a189ac689]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bff7e74ae8aeefe3]::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
  28:     0x7f8dd8e48f35 - <rustc_infer[78f7230a189ac689]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[bff7e74ae8aeefe3]::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
  29:     0x7f8dd9fbbbe5 - rustc_trait_selection[bff7e74ae8aeefe3]::traits::do_normalize_predicates
  30:     0x7f8dd9da5529 - rustc_trait_selection[bff7e74ae8aeefe3]::traits::normalize_param_env_or_error
  31:     0x7f8dd98a4118 - rustc_ty_utils[80e37e1806c40575]::ty::param_env
  32:     0x7f8dd98a3ca9 - rustc_query_impl[d71d27d8d4fd2043]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d71d27d8d4fd2043]::query_impl::param_env::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7f8dd9656c54 - rustc_query_system[af0d53eaca50a21]::query::plumbing::try_execute_query::<rustc_query_impl[d71d27d8d4fd2043]::DynamicConfig<rustc_query_system[af0d53eaca50a21]::query::caches::DefaultCache<rustc_span[5c4821f8b4a403f8]::def_id::DefId, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d71d27d8d4fd2043]::plumbing::QueryCtxt, false>
  34:     0x7f8dd9656761 - rustc_query_impl[d71d27d8d4fd2043]::query_impl::param_env::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7f8dd96f54f8 - rustc_middle[fc3d6de4885c956b]::query::plumbing::query_get_at::<rustc_query_system[af0d53eaca50a21]::query::caches::DefaultCache<rustc_span[5c4821f8b4a403f8]::def_id::DefId, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 8usize]>>>
  36:     0x7f8dda245de6 - rustc_hir_analysis[e387dd78e074a169]::check::wfcheck::check_trait
  37:     0x7f8dd9cd7cce - rustc_hir_analysis[e387dd78e074a169]::check::wfcheck::check_well_formed
  38:     0x7f8dd9cd6a0d - rustc_query_impl[d71d27d8d4fd2043]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d71d27d8d4fd2043]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7f8dd9cd610b - rustc_query_system[af0d53eaca50a21]::query::plumbing::try_execute_query::<rustc_query_impl[d71d27d8d4fd2043]::DynamicConfig<rustc_query_system[af0d53eaca50a21]::query::caches::VecCache<rustc_hir[149574241a95a1a8]::hir_id::OwnerId, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d71d27d8d4fd2043]::plumbing::QueryCtxt, false>
  40:     0x7f8dd9cd5e83 - rustc_query_impl[d71d27d8d4fd2043]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7f8dd9cd35f7 - rustc_hir_analysis[e387dd78e074a169]::check::wfcheck::check_mod_type_wf
  42:     0x7f8dd9cd353b - rustc_query_impl[d71d27d8d4fd2043]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d71d27d8d4fd2043]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>
  43:     0x7f8dd9cd26fb - rustc_query_system[af0d53eaca50a21]::query::plumbing::try_execute_query::<rustc_query_impl[d71d27d8d4fd2043]::DynamicConfig<rustc_query_system[af0d53eaca50a21]::query::caches::DefaultCache<rustc_span[5c4821f8b4a403f8]::def_id::LocalModDefId, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d71d27d8d4fd2043]::plumbing::QueryCtxt, false>
  44:     0x7f8dd9cd2489 - rustc_query_impl[d71d27d8d4fd2043]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7f8dd9cd239a - <rustc_middle[fc3d6de4885c956b]::hir::map::Map>::try_par_for_each_module::<rustc_hir_analysis[e387dd78e074a169]::check_crate::{closure#4}::{closure#0}>::{closure#0}
  46:     0x7f8dd97f37b6 - rustc_hir_analysis[e387dd78e074a169]::check_crate
  47:     0x7f8dda20bbd9 - rustc_interface[1bd61175f6644bbf]::passes::analysis
  48:     0x7f8dda20b81f - rustc_query_impl[d71d27d8d4fd2043]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d71d27d8d4fd2043]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>
  49:     0x7f8dda5a79a4 - rustc_query_system[af0d53eaca50a21]::query::plumbing::try_execute_query::<rustc_query_impl[d71d27d8d4fd2043]::DynamicConfig<rustc_query_system[af0d53eaca50a21]::query::caches::SingleCache<rustc_middle[fc3d6de4885c956b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d71d27d8d4fd2043]::plumbing::QueryCtxt, false>
  50:     0x7f8dda5a7795 - rustc_query_impl[d71d27d8d4fd2043]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7f8dda2fb575 - rustc_interface[1bd61175f6644bbf]::interface::run_compiler::<core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>, rustc_driver_impl[c8d6e38be153bd2e]::run_compiler::{closure#0}>::{closure#0}
  52:     0x7f8dda5cc486 - std[ca913780aff877b3]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1bd61175f6644bbf]::util::run_in_thread_with_globals<rustc_interface[1bd61175f6644bbf]::util::run_in_thread_pool_with_globals<rustc_interface[1bd61175f6644bbf]::interface::run_compiler<core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>, rustc_driver_impl[c8d6e38be153bd2e]::run_compiler::{closure#0}>::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>
  53:     0x7f8dda5cc2b3 - <<std[ca913780aff877b3]::thread::Builder>::spawn_unchecked_<rustc_interface[1bd61175f6644bbf]::util::run_in_thread_with_globals<rustc_interface[1bd61175f6644bbf]::util::run_in_thread_pool_with_globals<rustc_interface[1bd61175f6644bbf]::interface::run_compiler<core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>, rustc_driver_impl[c8d6e38be153bd2e]::run_compiler::{closure#0}>::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[db2dbba8ad13fc6d]::result::Result<(), rustc_span[5c4821f8b4a403f8]::ErrorGuaranteed>>::{closure#1} as core[db2dbba8ad13fc6d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  54:     0x7f8ddb9179d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h531f62f3337edeaa
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/alloc/src/boxed.rs:2016:9
  55:     0x7f8ddb9179d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8927a97a093d165e
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/alloc/src/boxed.rs:2016:9
  56:     0x7f8ddb9179d5 - std::sys::unix::thread::Thread::new::thread_start::h95607854405756e7
                               at /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys/unix/thread.rs:108:17
  57:     0x7f8dd54a3084 - start_thread
  58:     0x7f8dd552560c - __GI___clone3
  59:                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 attach the file at `/home/beef/rustc-ice-2024-03-03T05_40_23-307715.txt` to your bug report

note: compiler flags: --crate-type lib -Z treat-err-as-bug

query stack during panic:
#0 [param_env] computing normalized predicates of `CofactorCurve`
#1 [check_well_formed] checking that `CofactorCurve` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
@fee1-dead fee1-dead added A-trait-system Area: Trait system C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. F-associated_type_bounds `#![feature(associated_type_bounds)]` A-implied-bounds Area: Implied bounds / inferred outlives-bounds labels Mar 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2024
@fee1-dead fee1-dead added T-types Relevant to the types team, which will review and decide on the PR/issue. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. labels Mar 3, 2024
@fee1-dead
Copy link
Member Author

This is fixed by -Znext-solver though.

@fee1-dead fee1-dead added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-types Relevant to the types team, which will review and decide on the PR/issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 3, 2024
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Mar 3, 2024
@tgross35
Copy link
Contributor

@rustbot label -requires-nightly
beta now 👀

@rustbot rustbot removed the requires-nightly This issue requires a nightly compiler in some way. label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_type_bounds `#![feature(associated_type_bounds)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants