dtolnay/cxx

Implement glob import semantics for builtin type names

Offen

#682 geöffnet am 16.01.2021

 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (253 Forks)batch import
help wanted

Repository-Metriken

Stars
 (4.472 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 8m) (3 gemergte PRs in 30 T)

Beschreibung

Currently we disallow any user-defined type name that collides with one of the builtin type names.

error[cxxbridge]: reserved name
  ┌─ src/main.rs:3:12
  │
3 │     struct UniquePtr { broken: bool }
  │            ^^^^^^^^^ reserved name

error[cxxbridge]: reserved name
  ┌─ src/main.rs:5:12
  │
5 │     struct c_char { broken: bool }
  │            ^^^^^^ reserved name

However, this is bad because it makes it a breaking change for us to add new builtin bindings, such as #681. If the user already had their own type with the same name as the new binding, that code needs to continue to work.

We need to implement basically the same semantics that Rust has for prelude types and glob imports — a user-defined type replaces any builtin binding of the same name.

Contributor Guide