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

resolving bounds after type-checking: predict trait for std::ops::FnMut #70746

Closed
clouds56 opened this issue Apr 3, 2020 · 5 comments · Fixed by #78295
Closed

resolving bounds after type-checking: predict trait for std::ops::FnMut #70746

clouds56 opened this issue Apr 3, 2020 · 5 comments · Fixed by #78295
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@clouds56
Copy link

clouds56 commented Apr 3, 2020

Code

playgound

pub trait Trait1 {
  type C;
}

struct T1;
impl Trait1 for T1 {
  type C = usize;
}
pub trait Callback<T: Trait1>: FnMut(<T as Trait1>::C) {}
impl<T: Trait1, F: FnMut(<T as Trait1>::C)> Callback<T> for F { }


pub struct State<T: Trait1> {
  callback: Option<Box<dyn Callback<T>>>,
}
impl<T: Trait1> State<T> {
  fn new() -> Self { Self { callback: None } }
  fn test_cb(&mut self, d: <T as Trait1>::C) {
    (self.callback.as_mut().unwrap())(d)
  }
}

fn main() {
  let mut s = State::<T1>::new();
  s.test_cb(1);
}

Meta

rustc --version --verbose:

rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-apple-darwin
release: 1.42.0
LLVM version: 9.0

Error output

error: internal compiler error: src/librustc_trait_selection/traits/codegen/mod.rs:107: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<dyn Callback<T1, Output = ()> as std::ops::FnMut<(usize,)>>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (537ccdf3a 2020-04-02) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:873:9
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
...

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::ops::FnMut` fulfills its obligations
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

the backtrace itself is all <unknown>

@clouds56 clouds56 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 Apr 3, 2020
@clouds56
Copy link
Author

clouds56 commented Apr 3, 2020

It's strange, I tried these code in main

fn main() {
  // let mut s = State::<T1>::new();
  // s.test_cb(1);
  let cb: Option<Box<dyn Callback<T1>>> = None;
  (cb.unwrap())(1);
}

and it complains about the trait `std::ops::FnMut<(usize,)>` is not implemented for `dyn Callback<T1, Output = ()>` (Compile Error but not ICE)
I think the trait Callback<T1, Output = ()> is depends on std::ops::FnMut<(usize,)> and dyn could resolve this.

@spastorino
Copy link
Member

spastorino commented Apr 8, 2020

Assigning P-medium and removing nomination. This was discussed as part of pre-triage meeting in Zulip.

This one also sounds a bit similar to #69892 and #27675 which is very old. Would be nice to find if there are duplicates too.

@spastorino spastorino added P-medium Medium priority and removed I-nominated labels Apr 8, 2020
@spastorino
Copy link
Member

Pinging cleanup to find duplicates ...

@rustbot ping cleanup

@rustbot
Copy link
Collaborator

rustbot commented Apr 8, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Apr 8, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 11, 2020
@JohnTitor
Copy link
Member

Triage: It's no longer ICE with the latest nightly, I think it's fixed by #77720.

@nagisa nagisa added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 26, 2020
@bors bors closed this as completed in 75bbd80 Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections 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.

7 participants