-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
ambiguous associated type when access Entity::Column #2156
Comments
This should not be a bug, because it's been this way since 0.1. As you already know, there are two workarounds:
But you've made an interesting observation, and the solution is right here! Nobody is using |
Can you open a PR on this? I want to make this change |
I apologize for my significant mistake. Renaming can't solve this problem. Actually, this problem would never be solved. Look at this code: trait T1 {
type Name;
}
struct MyStruct {}
impl T1 for MyStruct {
type Name = i32;
}
fn main() {
let v: MyStruct::Name = 12;
} Just one trait and just one associate type, but also get: Compiling playground v0.0.1 (/playground)
error[E0223]: ambiguous associated type
--> src/main.rs:13:12
|
13 | let v: MyStruct::Name = 12;
| ^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<MyStruct as T1>::Name`
For more information about this error, try `rustc --explain E0223`.
error: could not compile `playground` (bin "playground") due to 1 previous error It can be seen that the ambiguous associated type error is unrelated to associate types with duplicate names. It's easy to understand: If Rust allows to access associate type without fully-qualified syntax, any lib user who define an associate type with duplicate names would cause a break inside the lib. As a conclusion, perhaps accessing associate types from outside of the trait must use fully-qualified syntax like |
There was a discussion around this before, but I couldn't seem to find it. |
Found it rust-lang/rust#8995 |
Description
I use sea-orm-cli to genetate entity for my database, but I get
ambiguous associated type
when I'm trying accessEntity::Column
.Steps to Reproduce
My table is called
node
. Therefore sea-orm-cli generate these codes inentity_crate
:And it would set
Node
to be the alias ofnode::Entity
:Then I want to
INSERT ... ON DUPLICATE KEY UPDATE
, so I write:I get:
Expected Behavior
Should be no error. I want to access everything of node table by
Node
(entity_crate::node::Entity
).Actual Behavior
Compile error: ambiguous associated type.
Reproduces How Often
Always.
Workarounds
To avoid this compile error, I just directly import
entity_crate::node
and usenode::Column
. A little ugly.To find out the reason, I use cargo-expand in
entity_crate
to expand all macros, and I found two trait with associated type calledColumn
:sea_orm::PrimaryKeyToColumn
andsea_orm::entity::EntityTrait
. And theEntity
only implsea_orm::entity::EntityTrait
. However, even thoughsea_orm::PrimaryKeyToColumn
is not imported, the ambiguous associated type error still occurs.This is a problem about associated type. The code below also have ambiguous associated type compile error:
Maybe rename the
sea_orm::PrimaryKeyToColumn::Column
would solve it.Reproducible Example
Minimal reproducible example:
Versions
sea-orm = "0.12"
sea-orm-cli version: 0.12.14
The text was updated successfully, but these errors were encountered: