Skip to content

Instantly share code, notes, and snippets.

@duckinator
Last active October 11, 2016 08:37
Show Gist options
  • Save duckinator/fa92ecea6619ba135317ce4b58d0535a to your computer and use it in GitHub Desktop.
Save duckinator/fa92ecea6619ba135317ce4b58d0535a to your computer and use it in GitHub Desktop.
type Op = Fn(u16, u16);
fn op_mov(one: u16, two: u16) {
}
fn op_add(one: u16, two: u16) {
}
fn op_nand(one: u16, two: u16) {
}
fn op_shl(one: u16, two: u16) {
}
fn op_shr(one: u16, two: u16) {
}
fn op_jz(one: u16, two: u16) {
}
fn op_lt(one: u16, two: u16) {
}
fn op_gt(one: u16, two: u16) {
}
fn op_in(one: u16, two: u16) {
}
fn op_out(one: u16, two: u16) {
}
fn main() {
let methods: std::collections::HashMap<u16, Op> = [
(0b0000, op_mov),
(0b0001, op_add),
(0b0010, op_nand),
(0b0011, op_shl),
(0b0100, op_shr),
(0b0101, op_jz),
(0b0110, op_lt),
(0b0111, op_gt),
// No 0b1000-0b1101.
(0b1110, op_in),
(0b1111, op_out)
].iter().cloned().collect();
println!("Hello, world!");
}
~/dev/tuna-isa/escolar$ cargo run
Compiling escolar v0.1.0 (file:///home/ellen/dev/tuna-isa/escolar)
src/main.rs:35:18: 35:52 error: the trait bound `std::ops::Fn(u16, u16) + 'static: std::marker::Sized` is not satisfied [E0277]
src/main.rs:35 let methods: std::collections::HashMap<u16, Op> = [
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:35:18: 35:52 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:35:18: 35:52 note: `std::ops::Fn(u16, u16) + 'static` does not have a constant size known at compile-time
src/main.rs:35:18: 35:52 note: required by `std::collections::HashMap`
src/main.rs:37:18: 37:24 error: mismatched types [E0308]
src/main.rs:37 (0b0001, op_add),
^~~~~~
src/main.rs:37:18: 37:24 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:37:18: 37:24 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:37:18: 37:24 note: found type `fn(u16, u16) {op_add}`
src/main.rs:38:18: 38:25 error: mismatched types [E0308]
src/main.rs:38 (0b0010, op_nand),
^~~~~~~
src/main.rs:38:18: 38:25 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:38:18: 38:25 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:38:18: 38:25 note: found type `fn(u16, u16) {op_nand}`
src/main.rs:39:18: 39:24 error: mismatched types [E0308]
src/main.rs:39 (0b0011, op_shl),
^~~~~~
src/main.rs:39:18: 39:24 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:39:18: 39:24 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:39:18: 39:24 note: found type `fn(u16, u16) {op_shl}`
src/main.rs:40:18: 40:24 error: mismatched types [E0308]
src/main.rs:40 (0b0100, op_shr),
^~~~~~
src/main.rs:40:18: 40:24 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:40:18: 40:24 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:40:18: 40:24 note: found type `fn(u16, u16) {op_shr}`
src/main.rs:41:18: 41:23 error: mismatched types [E0308]
src/main.rs:41 (0b0101, op_jz),
^~~~~
src/main.rs:41:18: 41:23 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:41:18: 41:23 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:41:18: 41:23 note: found type `fn(u16, u16) {op_jz}`
src/main.rs:42:18: 42:23 error: mismatched types [E0308]
src/main.rs:42 (0b0110, op_lt),
^~~~~
src/main.rs:42:18: 42:23 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:42:18: 42:23 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:42:18: 42:23 note: found type `fn(u16, u16) {op_lt}`
src/main.rs:43:18: 43:23 error: mismatched types [E0308]
src/main.rs:43 (0b0111, op_gt),
^~~~~
src/main.rs:43:18: 43:23 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:43:18: 43:23 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:43:18: 43:23 note: found type `fn(u16, u16) {op_gt}`
src/main.rs:45:18: 45:23 error: mismatched types [E0308]
src/main.rs:45 (0b1110, op_in),
^~~~~
src/main.rs:45:18: 45:23 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:45:18: 45:23 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:45:18: 45:23 note: found type `fn(u16, u16) {op_in}`
src/main.rs:46:18: 46:24 error: mismatched types [E0308]
src/main.rs:46 (0b1111, op_out)
^~~~~~
src/main.rs:46:18: 46:24 help: run `rustc --explain E0308` to see a detailed explanation
src/main.rs:46:18: 46:24 note: expected type `fn(u16, u16) {op_mov}`
src/main.rs:46:18: 46:24 note: found type `fn(u16, u16) {op_out}`
src/main.rs:47:14: 47:20 error: the trait bound `fn(u16, u16) {op_mov}: std::clone::Clone` is not satisfied [E0277]
src/main.rs:47 ].iter().cloned().collect();
^~~~~~
src/main.rs:47:14: 47:20 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:47:14: 47:20 help: the following implementations were found:
src/main.rs:47:14: 47:20 help: <fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:14: 47:20 help: <extern "C" fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:14: 47:20 help: <unsafe fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:14: 47:20 help: <unsafe extern "C" fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:14: 47:20 note: required because of the requirements on the impl of `std::clone::Clone` for `(_, fn(u16, u16) {op_mov})`
src/main.rs:47:23: 47:30 error: the trait bound `fn(u16, u16) {op_mov}: std::clone::Clone` is not satisfied [E0277]
src/main.rs:47 ].iter().cloned().collect();
^~~~~~~
src/main.rs:47:23: 47:30 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:47:23: 47:30 help: the following implementations were found:
src/main.rs:47:23: 47:30 help: <fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:23: 47:30 help: <extern "C" fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:23: 47:30 help: <unsafe fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:23: 47:30 help: <unsafe extern "C" fn(A, B) -> Ret as std::clone::Clone>
src/main.rs:47:23: 47:30 note: required because of the requirements on the impl of `std::clone::Clone` for `(_, fn(u16, u16) {op_mov})`
src/main.rs:47:23: 47:30 note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Cloned<std::slice::Iter<'_, (_, fn(u16, u16) {op_mov})>>`
src/main.rs:47:23: 47:30 error: the trait bound `std::collections::HashMap<u16, std::ops::Fn(u16, u16)>: std::iter::FromIterator<(_, fn(u16, u16) {op_mov})>` is not satisfied [E0277]
src/main.rs:47 ].iter().cloned().collect();
^~~~~~~
src/main.rs:47:23: 47:30 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:47:23: 47:30 note: a collection of type `std::collections::HashMap<u16, std::ops::Fn(u16, u16)>` cannot be built from an iterator over elements of type `(_, fn(u16, u16) {op_mov})`
src/main.rs:35:55: 47:32 error: the trait bound `std::ops::Fn(u16, u16): std::marker::Sized` is not satisfied [E0277]
src/main.rs:35 let methods: std::collections::HashMap<u16, Op> = [
^
src/main.rs:35:55: 47:32 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:35:55: 47:32 note: `std::ops::Fn(u16, u16)` does not have a constant size known at compile-time
src/main.rs:35:55: 47:32 note: required by `std::collections::HashMap`
error: aborting due to 14 previous errors
error: Could not compile `escolar`.
To learn more, run the command again with --verbose.
~/dev/tuna-isa/escolar$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment