coral-xyz/anchor-book

error[E0107]: populated from the Tic-Tac-Toe and CPA examples when followed explicitly

S-Burns opened this issue · 10 comments

Same error code populated from the Tic-Tac-Toe and CPA examples when followed explicitly.
error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied
--> programs/tic-tac-toe/src/lib.rs:58:67
|
58 | pub fn setup_game(ctx: Context, player_two: Pubkey) -> Result<()> {
| ^^^^^^ -- supplied 1 generic argument
| |
| expected 2 generic arguments
|
note: enum defined here, with 2 generic parameters: T, E
help: add missing generic argument
|
58 | pub fn setup_game(ctx: Context, player_two: Pubkey) -> Result<(), E> {
| +++

For more information about this error, try rustc --explain E0107.

I'm not able to reproduce this. Are you you using version 0.22.0 of the cli and the imported anchor-lang?

0.22.0 on Ubuntu WSL on Windows 10 loaded via the AWM & the same errors thrown with 0.20.1 installed with NPM before the upgrade. Following instructions on both verbatim.

Possible to upload the finalized versions of the modified lib.rs files etc.; maybe at the end of the book example...I think there are other requests for this.

have you uninstalled the npm version?

Ill upload the files tmr when Im back at my laptop

Yes. The NPM version was successfully removed. Anchor was off the machine, then reinstalled with the AWM and restarted with latest.

in the Cargo.toml of the program itself does it say anchor-lang = 0.22.0?

No. Now updated from 0.20.1 but this error is thrown...

error[E0412]: cannot find type ProgramResult in this scope
--> programs/tic-tac-toe/src/lib.rs:11:52
|
11 | pub fn initialize(ctx: Context) -> ProgramResult {
| ^^^^^^^^^^^^^ not found in this scope

warning: unused import: num_traits
--> programs/tic-tac-toe/src/lib.rs:6:5
|
6 | use num_traits::*;
| ^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

For more information about this error, try rustc --explain E0412.
warning: tic-tac-toe (lib) generated 1 warning
error: could not compile tic-tac-toe due to previous error; 1 warning emitted

this is a bug in the cli. Just change ProgramResult to Result<()> or copy the code from the book.

Success. Much thanks! Here is the complete, updated lib.rs for reference.

`use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

use num_derive::;
use num_traits::
;

#[program]
pub mod tic_tac_toe {
use super::*;
pub fn initialize(ctx: Context) -> Result<()> {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}

#[account]
#[derive(Default)]
pub struct Game {
players: [Pubkey; 2], // 64
turn: u8, // 1
board: [[Option; 3]; 3], // 9 * (1 + 1) = 18
state: GameState, // 32 + 1
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Eq)]
pub enum GameState {
Active,
Tie,
Won { winner: Pubkey },
}

#[derive(
AnchorSerialize, AnchorDeserialize, FromPrimitive, ToPrimitive, Copy, Clone, PartialEq, Eq,
)]
pub enum Sign {
X,
O,
}

impl Default for GameState {
fn default() -> Self {
Self::Active
}
}

#[derive(Accounts)]
pub struct SetupGame<'info> {
#[account(init, payer = player_one)]
pub game: Account<'info, Game>,
#[account(mut)]
pub player_one: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn setup_game(ctx: Context, player_two: Pubkey) -> Result<()> {
let game = &mut ctx.accounts.game;
game.players = [ctx.accounts.player_one.key(), player_two];
game.turn = 1;
Ok(())
}
`

great! Im uploading the program to the repo currently