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

Trait's types could not be determined #114057

Closed
Jenya705 opened this issue Jul 25, 2023 · 7 comments · Fixed by #116417
Closed

Trait's types could not be determined #114057

Jenya705 opened this issue Jul 25, 2023 · 7 comments · Fixed by #116417
Labels
C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Jenya705
Copy link

Code

pub trait A {
    type B;

    fn m(b: Self::B);
}

pub trait C<'a> {
    type D: 'a; 
}

struct S;

impl<'a> C<'a> for S {
    type D = ();
}

struct T<CG: C<'static>> {
    d: &'static CG::D,
}

impl A for S
where 
    for<'a> S: C<'a> {
    type B = T<S>;

    fn m(b: Self::B) {
        f(b.d)    
    }
}

fn f(d: &<S as C>::D) {}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (31395ec38 2023-07-24)
binary: rustc
commit-hash: 31395ec38250b60b380fd3c27e94756aba3557de
commit-date: 2023-07-24
host: x86_64-pc-windows-msvc
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

error: internal compiler error: /rustc/31395ec38250b60b380fd3c27e94756aba3557de\compiler\rustc_const_eval\src\interpret\place.rs:653:13: type mismatch when copying!
                                src: &(),
                                dest: &<S as C<'_>>::D
  --> src\main.rs:27:11
   |
27 |         f(b.d)
   |           ^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/31395ec38250b60b380fd3c27e94756aba3557de\compiler\rustc_errors\src\lib.rs:1007:33
stack backtrace:
   0:     0x7ffafe358b6c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd03a95172b6fcf57
   1:     0x7ffafe392a5b - core::fmt::write::he3165d1d7dc3f002
   2:     0x7ffafe34dd91 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h6069b8ca54bb4015
   3:     0x7ffafe35891b - std::sys::common::alloc::realloc_fallback::h49007f5c332b820a
   4:     0x7ffafe35c2d3 - std::panicking::panic_hook_with_disk_dump::he95d68a9852fd168
   5:     0x7ffafe35be7a - std::panicking::panic_hook_with_disk_dump::he95d68a9852fd168
   6:     0x7ffaebeab2f0 - rustc_driver_impl[55ec51074fcbdf41]::ice_path
   7:     0x7ffafe35cc9a - std::panicking::rust_panic_with_hook::h7ab7a381000f0959
   8:     0x7ffaec30a0b3 - <rustc_mir_transform[f49da265e3e79212]::errors::MustNotSupend as rustc_errors[223d10168b8ae2b1]::diagnostic::DecorateLint<()>>::msg
   9:     0x7ffaec306549 - <rustc_mir_transform[f49da265e3e79212]::errors::MustNotSupend as rustc_errors[223d10168b8ae2b1]::diagnostic::DecorateLint<()>>::msg
  10:     0x7ffaec3609a9 - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  11:     0x7ffaec35e391 - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  12:     0x7ffaec35e1ad - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  13:     0x7ffaec39d3df - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  14:     0x7ffaec39d41d - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  15:     0x7ffaec39cacf - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  16:     0x7ffaec39ca76 - <rustc_mir_transform[f49da265e3e79212]::coverage::spans::CoverageSpan as core[5892f5adc6345ffc]::fmt::Debug>::fmt
  17:     0x7ffaeb2fb1a8 - <rustc_mir_transform[f49da265e3e79212]::remove_storage_markers::RemoveStorageMarkers as rustc_middle[f9049dd98e39c010]::mir::MirPass>::run_pass
  18:     0x7ffaeb240dfc - <rustc_mir_transform[f49da265e3e79212]::const_prop_lint::ConstPropagator as rustc_middle[f9049dd98e39c010]::mir::visit::Visitor>::visit_basic_block_data
  19:     0x7ffaeb23f791 - <rustc_mir_transform[f49da265e3e79212]::const_prop_lint::ConstProp as rustc_mir_transform[f49da265e3e79212]::pass_manager::MirLint>::run_lint
  20:     0x7ffaeb22bc8f - <rustc_mir_transform[f49da265e3e79212]::simplify_comparison_integral::SimplifyComparisonIntegral as rustc_middle[f9049dd98e39c010]::mir::MirPass>::run_pass
  21:     0x7ffaeb7efdbf - <rustc_query_impl[194cf41dd8cf861e]::plumbing::QueryCtxt as rustc_query_system[71f5d4e748ef2a3f]::query::QueryContext>::load_side_effects
  22:     0x7ffaeb847eff - <rustc_query_impl[194cf41dd8cf861e]::plumbing::QueryCtxt as rustc_query_system[71f5d4e748ef2a3f]::query::QueryContext>::load_side_effects
  23:     0x7ffaeb8b1249 - <rustc_query_impl[194cf41dd8cf861e]::plumbing::QueryCtxt as rustc_query_system[71f5d4e748ef2a3f]::query::QueryContext>::load_side_effects
  24:     0x7ffaeab9daf2 - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  25:     0x7ffaeaf231ef - rustc_driver_impl[55ec51074fcbdf41]::args::arg_expand_all
  26:     0x7ffae823d750 - rustc_interface[7385ddcaaf499a65]::passes::analysis
  27:     0x7ffaeaafeded - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  28:     0x7ffaeab19ba9 - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  29:     0x7ffaeab3c1e5 - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  30:     0x7ffaeab509aa - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  31:     0x7ffaeab9afdc - rustc_query_impl[194cf41dd8cf861e]::profiling_support::alloc_self_profile_query_strings
  32:     0x7ffae81ecb91 - rustc_driver_impl[55ec51074fcbdf41]::main
  33:     0x7ffae81f7463 - rustc_driver_impl[55ec51074fcbdf41]::main
  34:     0x7ffae820d412 - <rustc_middle[f9049dd98e39c010]::ty::SymbolName as core[5892f5adc6345ffc]::fmt::Display>::fmt
  35:     0x7ffae820ea6f - <rustc_middle[f9049dd98e39c010]::ty::SymbolName as core[5892f5adc6345ffc]::fmt::Display>::fmt
  36:     0x7ffafe37036c - std::sys::windows::thread::Thread::new::he11eb30ab359cca1
  37:     0x7ffb59bf26ad - BaseThreadInitThunk
  38:     0x7ffb5a4aaa68 - RtlUserThreadStart

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

warning: the ICE couldn't be written to `\rusttest\rustc-ice-2023-07-25T13:29:05.2566834Z-44140.txt`: (os error 123)

note: rustc 1.73.0-nightly (31395ec38 2023-07-24) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at src\main.rs:21:1: 21:13>::m`
#1 [analysis] running analysis passes on this crate
end of query stack
warning: `rusttest` (bin "rusttest") generated 1 warning (run `cargo fix --bin "rusttest"` to apply 1 suggestion)
error: could not compile `rusttest` (bin "rusttest"); 1 warning emitted
Backtrace

none

@Jenya705 Jenya705 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 Jul 25, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 25, 2023
@Jenya705
Copy link
Author

This one works okay:

pub trait A {
    type B;

    fn m(b: Self::B);
}

pub trait C<'a> {
    type D: 'a; 
}

struct S;

impl<'a> C<'a> for S {
    type D = ();
}

struct T<D: 'static> {
    d: &'static D,
}

impl A for S
where 
    for<'a> S: C<'a> {
    type B = T<<S as C<'static>>::D>;

    fn m(b: Self::B) {
        f(b.d)
    }
}

fn f(d: &<S as C>::D) {}

fn main() {}

@Jenya705
Copy link
Author

Jenya705 commented Jul 25, 2023

This one also (Just proxying a type, that means that something strange with struct's generics):

pub trait A {
    type B;

    fn m(b: Self::B);
}

pub trait C<'a> {
    type D: 'a; 
}

struct S;

impl<'a> C<'a> for S {
    type D = ();
}

struct T1<D: 'static> {
    d: &'static D,
}

type T<CG> = T1<<CG as C<'static>>::D>;

impl A for S
where 
    for<'a> S: C<'a> {
    type B = T<S>;

    fn m(b: Self::B) {
        f(b.d);
    }
}

fn f(d: &<S as C>::D) {}

fn main() {}

@lqd
Copy link
Member

lqd commented Jul 25, 2023

Bisected to #110107 but it probably just bubbles up a pre-existing issue that the OP could be massaged to emit without this PR, cc author @cjgillot just in case.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 25, 2023
@ouz-a
Copy link
Contributor

ouz-a commented Sep 29, 2023

This worked fine before 1.70.0 so it's a regression.

@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2023

minimized

trait Bar<'a> {
    type Assoc: 'static; 
}

impl<'a> Bar<'a> for () {
    type Assoc = ();
}

struct ImplsStatic<CG: Bar<'static>> {
    d: &'static <CG as Bar<'static>>::Assoc,
}

fn caller(b: ImplsStatic<()>)
where 
    for<'a> (): Bar<'a>
{
    let _: &<() as Bar<'static>>::Assoc = b.d;
}

fn main() {}

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Oct 3, 2023
@apiraino apiraino added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 4, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 4, 2023
Remove is global hack

In attempt to fix rust-lang#114057 we found several issues with how compiler computes layouts, this change removes `is_global` from `and` to stop impl from being shadowed.

In depth conversation can be read here https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Getting.20different.20types.20from.20almost.20same.20inputs

This is a fix candidate opened for performance run.

r? `@lcnr`
@apiraino
Copy link
Contributor

apiraino commented Oct 4, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 4, 2023
@ouz-a
Copy link
Contributor

ouz-a commented Oct 5, 2023

Once #116417 this will be fixed.

@bors bors closed this as completed in cae0791 Oct 5, 2023
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. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

8 participants