Skip to content

Instantly share code, notes, and snippets.

@tmandry
Created April 7, 2018 20:06
Show Gist options
  • Save tmandry/388b04a268e995aab87fc92d3caf9335 to your computer and use it in GitHub Desktop.
Save tmandry/388b04a268e995aab87fc92d3caf9335 to your computer and use it in GitHub Desktop.
rustc type inference error
Running `rustc --crate-name core src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=dc98e8200778de86 -C extra-filename=-dc98e8200778de86 --out-dir /Users/tyler/code/rust/rust-core-template/target/debug/deps -C incremental=/Users/tyler/code/rust/rust-core-template/target/debug/incremental -L dependency=/Users/tyler/code/rust/rust-core-template/target/debug/deps`
error[E0282]: type annotations needed
--> src/iterator.rs:25:16
|
25 | val == LoopState::Continue(())
| ^^^^^^^^^^^^^^^^^^^ cannot infer type for `B`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
error: Could not compile `core`.
use cmp::*;
enum LoopState<C, B> {
Continue(C),
Break(B),
}
#[allow(dead_code)]
impl<C, B> LoopState<C, B> {
fn my_eq(&self, _other: &Self) -> bool { true }
}
impl<C, B> PartialEq for LoopState<C, B> {
fn eq(&self, _other: &Self) -> bool { true }
fn ne(&self, _other: &Self) -> bool { false }
}
pub trait Iterator {
type Item;
fn all(&mut self) -> bool
{
let val = if false { LoopState::Continue(()) } else { LoopState::Break(()) };
//val.my_eq(&LoopState::Continue(())) // this works!
val == LoopState::Continue(()) // doesn't work when `predicates_of` query is changed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment