Skip to content

Commit

Permalink
Fixes according comments in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Feb 9, 2022
1 parent 5410a5b commit bf251aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TraitRegistry<'_> {
/// # Note
///
/// That implementation is used by builder generated in the body of the contract
/// and by reference to contract(aka `ContractRef` in case of `Contract`).
/// and by reference to contract (a.k.a `ContractRef` in case of `Contract`).
impl<T> #trait_ident for T
where
T: ::ink_lang::reflect::CallBuilder,
Expand Down
6 changes: 6 additions & 0 deletions crates/lang/src/reflect/trait_def/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ pub trait TraitModulePath {
const NAME: &'static str;
}

/// Implemented by call builders of smart contracts and by `TraitDefinitionRegistry`
/// during codegen to apply the blanket implementation.
///
/// The blanket implementation is generated by `#[ink_lang::trait_definition]` and
/// defined in the same place with the trait. It generates the body for methods of the trait.
/// These methods contain cross-contract calls inside and define the `__ink_TraitInfo`.
pub trait CallBuilder: ContractEnv + ToAccountId<<Self as ContractEnv>::Env> {}
11 changes: 9 additions & 2 deletions crates/lang/src/reflect/trait_def/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,21 @@ impl<E> ToAccountId<E> for TraitDefinitionRegistry<E>
where
E: ink_env::Environment,
{
/// `to_account_id` is not allowed for `TraitDefinitionRegistry`.
///
/// We insert markers for these errors in the generated contract code.
/// This is necessary since we can't check these errors at compile time
/// of the contract.
/// `cargo-contract` checks the contract code for these error markers
/// when building a contract and fails if it finds markers.
#[cold]
fn to_account_id(&self) -> E::AccountId {
/// We enforce linking errors in case this is ever actually called.
/// These linker errors are properly resolved by the cargo-contract tool.
extern "C" {
fn _ink_compilation_error() -> !;
fn __ink_enforce_error_to_account_id() -> !;
}
unsafe { _ink_compilation_error() }
unsafe { __ink_enforce_error_to_account_id() }
}
}

Expand Down

0 comments on commit bf251aa

Please sign in to comment.