rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.93k stars 12.24k forks source link

Rustc bug when building Elrond Smart Contract #93123

Open thounyy opened 2 years ago

thounyy commented 2 years ago

Edit

Someone found how to fix the bug. Apparently by modifying lines above contract trait in main.rs it creates the bug when compiling. So the DIY solution is to delete ./meta and build the contract again.

Context

Developing Smart Contract on Elrond with their sdk. Basically following this tutorial https://docs.elrond.com/developers/tutorials/crowdfunding-p2/

When I run erdpy build contract I get this bug. First time I fixed it by deleting and typing the content of the smart contract a second time. But now I get this bug again and the contract is too long.

Checking backtrace I got "error[E0554]: #![feature] may not be used on the stable release channel". So I tried with nightly but nothing change.

Code

#![no_std]

elrond_wasm::imports!();
elrond_wasm::derive_imports!();

#[derive(TopEncode, TopDecode, TypeAbi, PartialEq, Clone, Copy)]
pub enum Status {
    FundingPeriod,
    Successful,
    Failed,
}

#[elrond_wasm::contract]
pub trait Crowdfunding {

  #[view(getTarget)]
  #[storage_mapper("target")]
  fn target(&self) -> SingleValueMapper<BigUint>;

  #[view(getDeadline)]
  #[storage_mapper("deadline")]
  fn deadline(&self) -> SingleValueMapper<u64>;

  #[view(getDeposit)]
  #[storage_mapper("deposit")]
  fn deposit(&self, donor: &ManagedAddress) -> SingleValueMapper<BigUint>;

  #[init]
  fn init(&self, target: BigUint, deadline: u64) {
      self.target().set(&target);
      self.deadline().set(&deadline);
  }

  #[view]
  fn status(&self) -> Status {
      if self.blockchain().get_block_nonce() <= self.deadline().get() {
          Status::FundingPeriod
      } else if self.get_current_funds() >= self.target().get() {
          Status::Successful
      } else {
          Status::Failed
      }
  }

  #[view(getCurrentFunds)]
  fn get_current_funds(&self) -> BigUint {
      self.blockchain().get_sc_balance(&TokenIdentifier::egld(), 0)
  }

  #[payable("*")]
  #[endpoint]
  fn fund(&self, #[payment] payment: BigUint) -> SCResult<()> {
      let current_time = self.blockchain().get_block_nonce();
      require!(current_time < self.deadline().get(), "cannot fund after deadline");

      let caller = self.blockchain().get_caller();
      self.deposit(&caller).update(|deposit| *deposit += payment);
      Ok(())
  }
}

Meta

rustc --version --verbose:

rustc --version --verbose
rustc 1.60.0-nightly (5e57faa78 2022-01-19)
binary: rustc
commit-hash: 5e57faa78aa7661c6000204591558f6665f11abc
commit-date: 2022-01-19
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Error output

Compiling crowdfunding-meta v0.0.0 (/home/thoune/ThounyBreasty/Courses/Elrond/crowdfunding/meta)
thread 'rustc' panicked at 'no entry found for key', compiler/rustc_metadata/src/rmeta/decoder.rs:1640:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

[...]
Backtrace

``` error[E0554]: `#![feature]` may not be used on the stable release channel --> /home/thoune/.cargo/registry/src/github.com-1ecc6299db9ec823/elrond-wasm-derive-0.26.0/src/lib.rs:4:12 | 4 | #![feature(proc_macro_quote)] | ^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0554`. error: could not compile `elrond-wasm-derive` due to previous error warning: build failed, waiting for other jobs to finish... error: build failed ```

Aaron1011 commented 2 years ago

Do you remember what changes you made in between re-typing the code to fix the bug, and when the bug occured for the second time?

thounyy commented 2 years ago

I think until validation in this tutorial it worked fine and when I added the querying part it happened https://docs.elrond.com/developers/tutorials/crowdfunding-p2/ And the first time it happened was in the part 1 when I wrote the init function

Aaron1011 commented 2 years ago

Could you link me to your full repository?

thounyy commented 2 years ago

sure it's here : https://github.com/ThounyBreasty/ElrondCrowdfunding

dan-merlea commented 1 year ago

Just got the same error after updating rust using brew error[E0554]: #![feature] may not be used on the stable release channel --> /elrondsdk/vendor-rust/registry/src/github.com-1ecc6299db9ec823/elrond-wasm-derive-0.36.1/src/lib.rs:4:12

rust: stable 1.64.0 (bottled), HEAD

dan-merlea commented 1 year ago

Uninstalling rust from brew did the trick for me..

You can also take a look here: https://stackoverflow.com/questions/72448056/error-while-building-with-erdpy-for-crowdfunding