Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect compiler error message about a trait import #6303

Closed
Yung-Beef opened this issue Oct 30, 2024 · 5 comments
Closed

Incorrect compiler error message about a trait import #6303

Yung-Beef opened this issue Oct 30, 2024 · 5 comments
Labels
I10-unconfirmed Issue might be valid, but it's not yet known.

Comments

@Yung-Beef
Copy link

I'm trying to hash something with BlakeTwo256::hash_of(data).into(), it told me I needed to add use frame::primitives::BlakeTwo256; and then said hash_of wasn't in scope and I should add use polkadot_sdk_frame::traits::Hash.

However, that doesn't exist, and I need use frame::traits::Hash.

I believe this is related to issue 3813 and possibly concerns lines 53-64 here, but I could not find where the compiler error is being generated from.

@github-actions github-actions bot added the I10-unconfirmed Issue might be valid, but it's not yet known. label Oct 30, 2024
@ggwpez
Copy link
Member

ggwpez commented Oct 30, 2024

Can you post the whole error message please? The error is possibly generated by the compiler.

@Yung-Beef
Copy link
Author

Yung-Beef commented Oct 30, 2024

error[E0599]: no function or associated item named `hash_of` found for struct `BlakeTwo256` in the current scope
   --> src/tests.rs:504:40
    |
504 |         let new_dna: [u8; 32] = BlakeTwo256::hash_of(&unique_payload).into();
    |                                              ^^^^^^^ function or associated item not found in `BlakeTwo256`
    |
    = help: items from traits can only be used if the trait is in scope
help: trait `Hash` which provides `hash_of` is implemented but not in scope; perhaps you want to import it
    |
14  + use polkadot_sdk_frame::traits::Hash;
    |

@ggwpez

@Yung-Beef
Copy link
Author

I know the package is named polkadot_sdk_frame and it's renamed or something inside the crate, is the compiler not able to understand that? If I try use polkadot_sdk_frame::traits::Hash; I get

error[E0433]: failed to resolve: use of undeclared crate or module `polkadot_sdk_frame`
  --> src/tests.rs:21:5
   |
21 | use polkadot_sdk_frame::traits::Hash;
   |     ^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `polkadot_sdk_frame`

@gui1117
Copy link
Contributor

gui1117 commented Nov 3, 2024

Do you have a branch to look at to reproduce? also maybe rust version?

Nevermind I can reproduce:
Cargo.toml

[package]
name = "ressai"
version = "0.1.0"
edition = "2021"

[dependencies]
frame = { package = "polkadot-sdk-frame", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master", features = ["experimental", "runtime", "std"] }

main.rs

 use frame::traits::BlakeTwo256;

fn main() {
	let new_dna: [u8; 32] = BlakeTwo256::hash_of(&3u32).into();
}

@gui1117
Copy link
Contributor

gui1117 commented Nov 3, 2024

This is a rustc error.
I reproduce in this repo: https://github.com/gui1117/debug_rustc_suggestion
It seems related to this issue: rust-lang/rust#52485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I10-unconfirmed Issue might be valid, but it's not yet known.
Projects
None yet
Development

No branches or pull requests

3 participants