Comments (6)
I think it's not about being smarter about type parameters, but about being replacement-aware. That's partially why the replaces
annotation sucks quite a bit (and it'd come a bit more handy to have a replaced_by
annotation or something, but that's way more annoying).
Right now the amount of code that is replacement-aware is minimal. Probably we should make Context::resolve_item
replacement-aware by default (it's not hard, just slightly annoying), and then have another function to bypass this in the appropriate places.
from rust-bindgen.
After digging in more, this is not what we thought this was. Code generation, which is when we get the named types we need to emit, happens after we have already processed replacements, so the issue is not that we are failing to be replacement aware.
In fact, it looks like we end up replacing the wrong items, and then end up ignoring the replacements or something.
I'm digging in further...
from rust-bindgen.
First, we parse the replaces_MaybeWrapped
template alias, which has the use_instead_of
(né replaces
) annotation, and it ends up with an id of ItemId(13)
:
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(13), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: Some("/// But the replacement type does use T!\n///\n/// <div rustbindgen replaces=\"MaybeWrapped\" />"), annotations: Annotations { opaque: false, hide: false, use_instead_of: Some("MaybeWrapped"), disallow_copy: false, private_fields: None, accessor_kind: None }, parent_id: ItemId(0), kind: Type(Type { name: None, layout: None, kind: TemplateAlias(ItemId(16), [ItemId(15)]), is_const: false }) }, declaration: Some(Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(replaces_MaybeWrapped kind: TypeAliasTemplateDecl, loc: tests/headers/replace_template_alias.hpp:23:1, usr: Some("c:@replaces_MaybeWrapped")))
Then, we define the replacement for MaybeWrapped
(ie a call to BindgenContext::replace
) as ItemId(18)
(!!) and not the template alias above which is ItemId(13)
:
DEBUG:bindgen::ir::context: Defining replacement for MaybeWrapped as ItemId(18)
Finally, we add the item with id itemId(18)
, which is the named template type argument T
:
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(18), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None }, parent_id: ItemId(13), kind: Type(Type { name: Some("T"), layout: None, kind: Named("T", None), is_const: false }) }, declaration: None, loc: None
So that seems to be the bug: we should be defining the replacement as ItemId(13)
not ItemId(18)
.
Still figuring out why this is happening in the first place.
from rust-bindgen.
I bet we're inserting it twice in the hashmap?
from rust-bindgen.
I bet we're inserting it twice in the hashmap?
Great guess! ;)
DEBUG:bindgen::ir::context: Defining replacement for MaybeWrapped as ItemId(13)
DEBUG:bindgen::ir::context: Defining replacement for MaybeWrapped as ItemId(16)
DEBUG:bindgen::ir::context: Defining replacement for MaybeWrapped as ItemId(18)
from rust-bindgen.
I guess we can assume the first is the correct replacement and then warn for duplicate replacement definition attempts.
Fix incoming.
from rust-bindgen.
Related Issues (20)
- Publishing self-contained static executable (with bundled libclang.a) HOT 1
- How to construct the std::string variable in the generated rust HOT 2
- Feature request: use DST to represent structures with flexible array members HOT 7
- BindgenUnion can get incorrect alignment on i686 HOT 1
- feature: wrap every C function on unsafe blocks HOT 8
- docummenting of usage dynamic_library_name
- `size_t` incorrectly used when stdlib.h is included for aarch64-unknown-none HOT 4
- Workaround for atomic types
- Private padding and alignment fields + missing Defaut/Clone/Copy implementations HOT 3
- Convert `pub type __u8 = ::std::os::raw::c_uchar;` to `u8` (native) Rust types HOT 6
- Deriving common traits (`Copy` / `Clone`) doesn't appear to be working for anonymous unions/structs HOT 1
- Feature request: compile-time layout tests
- RFE: API for renaming struct fields HOT 1
- `__IncompleteArrayField` does not `impl ::std::marker::Copy` HOT 2
- Enhancing VTable Generation to Support Inherited Classes HOT 1
- error: linking with `link.exe` failed: exit code: 1120 HOT 3
- `static mut` deprecation HOT 1
- Bindgen release
- Failed to generate `Default` impl for arrays larger than 32 entries HOT 8
- wrap-static-fns converts _Bool to bool, causing a compile error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-bindgen.