profile
viewpoint
David Tolnay dtolnay 0xF9BA143B95FF6D82 Menlo Park, CA

dtolnay/cxx 1977

Safe interop between Rust and C++

brson/stdx 1363

The missing batteries of Rust

dtolnay/anyhow 1342

Flexible concrete Error type built on std::error::Error

dtolnay/case-studies 849

Analysis of various tricky Rust code

dtolnay/cargo-expand 764

Subcommand to show result of macro expansion

dtolnay/async-trait 587

Type erasure for async trait methods

chyh1990/yaml-rust 402

A pure rust YAML implementation.

dtolnay/erased-serde 164

Type-erased Serialize, Serializer and Deserializer traits

dtolnay/cargo-llvm-lines 134

Count lines of LLVM IR per generic function

issue openeddtolnay/cxx

Support multiple cxx::bridge modules in one file

Following #370 this should be pretty easy hopefully.

  • As far as the C++ code generator is concerned, I think multiple cxx::bridge is exactly equivalent to seeing all of the contents together in a single module, with appropriate namespace attributes if the two cxx::bridge invocations are different namespaces.

  • As far as the Rust code generator (proc macro) is concerned, I think multiple cxx::bridge can expand totally independently (this probably already does the right thing).

created time in 3 hours

issue closeddtolnay/cxx

Support different namespaces on different extern blocks

Currently the namespace is determined globally for an entire #[cxx::bridge] invocation.

#[cxx::bridge(namespace = path::to)]
mod ffi {...}

It would be good to be able to pull in things from multiple different namespaces at once. Something like:

#[cxx::bridge]
mod ffi {
    #[namespace = path::to::first]
    extern "C" {
        type First;
    }

    #[namespace = path::to::second]
    extern "C" {
        type Second;
    }

    #[namespace = path::to::third]
    extern "Rust" {
        fn wow(first: &First, second: &Second);
    }
}

closed time in 3 hours

dtolnay

issue commentdtolnay/cxx

Support different namespaces on different extern blocks

Implemented as part of #370.

dtolnay

comment created time in 3 hours

push eventdtolnay/cxx

Adrian Taylor

commit sha 3e5cff4a3d29873e0cadb33f2990e63988e5c045

Switch to #[namespace = A::B] syntax. Thanks to sbrocket for this parsing code.

view details

David Tolnay

commit sha 71b34be0be6457e9d939a9005f0f246dc7f98218

Merge pull request #380 from adetaylor/namespaces-syntax-update Switch to #[namespace = A::B] syntax.

view details

push time in 5 hours

PR merged dtolnay/cxx

Switch to #[namespace = A::B] syntax.

Thanks to sbrocket for this parsing code.

+33 -27

0 comment

7 changed files

adetaylor

pr closed time in 5 hours

PullRequestReviewEvent

pull request commentdtolnay/cxx

Allow namespace override

Yeah it should be #[namespace = "path::to"] for now (though implemented in such a way that it accepts #[namespace = path::to] if the user's future compiler is able to feed us that). We can also update existing use of #[cxx::bridge(namespace = ...)] in documentation and tests to #[cxx::bridge(namespace = "...")] to maintain parity.

adetaylor

comment created time in 8 hours

Pull request review commentdtolnay/cxx

Allow namespace override

+// To test receivers on a type in a namespace outide+// the default. cxx::bridge blocks can only have a single+// receiver type, and there can only be one such block per,+// which is why this is outside.

If I'm remembering correctly, I don't think this is the case currently, or if it is then we should fix it.

I would expect there to be able to be one "implicit" receiver type per extern block, multiple "explicit" receiver types per extern block, and multiple extern blocks per FFI module.

#[cxx::bridge]
mod ffi {
    extern "C" {
        type A;
        fn f(&self); // implicitly receiver A
    }
    extern "C" {
        type B;
        type C;
        fn f(self: &B); // explicit receivers
        fn f(self: &C);
    }
}
adetaylor

comment created time in 8 hours

PullRequestReviewEvent

Pull request review commentdtolnay/cxx

Allow namespace override

 error: using C++ string by value is not supported 6 |         s: CxxString,   |         ^^^^^^^^^^^^ -error: needs a cxx::ExternType impl in order to be used as a field of `S`+error: needs a cxx::ExternType impl in order to be used as a field of `::S`

I think this was more correct before. The type being discussed by the error message is not ::S in Rust. It's actually crate::ffi::S but it would suffice to call it S for this message. ::S is the C++ name but doesn't feel appropriate to use for this message.

adetaylor

comment created time in 8 hours

PullRequestReviewEvent

push eventdtolnay/cxx

Adrian Taylor

commit sha 9a158e408fc916255be0dbf88cf39d1d6176d548

Adding tests for types in namespaces.

view details

Adrian Taylor

commit sha 5e79c647696e55934e108397b2e1c3e824ce8079

Tests for namespaced opaque extern types.

view details

Adrian Taylor

commit sha 585bb0bc5605ccf28b5a814b5727967b8ee67c83

Tests for namespaced extern trivial types

view details

Adrian Taylor

commit sha d47af7a9d3640438e3d1371a739297b789296cfb

Tests for opaque C types in namepsaces

view details

Adrian Taylor

commit sha ddc146ef9f4d67ddf75bf7174fdc1e2a95a2ced5

Adding tests for functions in other namespaces.

view details

Adrian Taylor

commit sha 0fac32193904fdd75dcff71e5e4bd846b6e560b7

Adding tests for method calls in foreign namespaces

view details

Adrian Taylor

commit sha c871343ac270f073fd4790269da267e8cb91dbde

Allow namespace override. This change allows a #[namespace (namespace = A::B)] attribute for each item in a cxx::bridge. We now have a fair number of different types of name floating around: * C++ identifiers * C++ fully-qualified names * Rust identifiers * Rust fully-qualified names (future, when we support sub-modules) * Items with both a Rust and C++ name (a 'Pair') * Types with only a known Rust name, which can be resolved to a C++ name. This change attempts to put some sensible names for all these things in syntax/mod.rs, and so that would be a good place to start review. At the moment, the Namespace (included in each CppName) is ruthlessly cloned all over the place. As a given namespace is likely to be applicable to many types and functions, it may save significant memory in future to use Rc<> here. But let's not optimise too early.

view details

David Tolnay

commit sha d60c07b7629a373396c4cb15c57c4903402cee27

Merge pull request 370 from adetaylor/allow-namespace-override

view details

push time in 8 hours

PR merged dtolnay/cxx

Allow namespace override

This PR consists of lots of commits adding tests, then a commit which actually achieves it.

It should achieve points 1-3 on the plan in #353, and most of #​4 (it doesn't currently look for namespace attributes on extern blocks but the rest is done).

Obsoletes #369.

+1167 -449

1 comment

27 changed files

adetaylor

pr closed time in 8 hours

PullRequestReviewEvent

issue openeddtolnay/cxx

Support rust_name/cxx_name on enum variants

Attributes were added for renaming functions in #349. It would make sense to support the same on enum variants.

#[cxx::bridge]
mod ffi {
    enum Enum {
        #[cxx_name = "VARIANT"]
        Variant,
    }
}

created time in 11 hours

pull request commentrust-lang/rust

Revert invalid `fn` return type parsing change

@bors r+

estebank

comment created time in 15 hours

PullRequestReviewEvent

issue openeddtolnay/cxx

Expand API of cxx_gen::Error

https://docs.rs/cxx-gen/0.5.2/cxx_gen/struct.Error.html currently only exposes a Display/Debug impl which is not sufficient to produce diagnostics in the style that cxx-build and cxxbridge-cmd do. We'll want to expose the location information, and/or possibly a way to retrieve a rendered diagnostic containing the source snippet.

created time in a day

delete branch dtolnay/cxx

delete branch : unsupported-type

delete time in a day

push eventdtolnay/cxx

Adrian Taylor

commit sha cca5215060cb472902d52fba9414fdd0ea9009d9

Diagnostic improvement.

view details

David Tolnay

commit sha dbc5377e9f3c6d29cf82fcf4732005ce17872475

Avoid repeating the underlined type in the label

view details

David Tolnay

commit sha 7b14585af9856a7e7bbc042d0292335933c35300

Merge pull request #377 from dtolnay/unsupported-type Include typename in diagnostic on unsupported type

view details

push time in a day

PR merged dtolnay/cxx

Include typename in diagnostic on unsupported type

First commit is extracted from #370.

<pre> <b>error[cxxbridge]: unsupported type: OsString</b> ┌─ src/main.rs:15:21 │ 15 │ fn huh(wtf: <b>OsString</b>); │ <b>^^^^^^^^ unsupported type</b> </pre>

+9 -1

0 comment

2 changed files

dtolnay

pr closed time in a day

delete branch dtolnay/syn

delete branch : description

delete time in a day

push eventdtolnay/syn

David Tolnay

commit sha b52cf67333d4b2a124db55df3086598c509de3fd

Remove deprecated description method from Error impl

view details

David Tolnay

commit sha 41ab7aec71cf33263b320b640a01b42d4a0052f1

Merge pull request #915 from dtolnay/description Remove deprecated description method from Error impl

view details

push time in a day

PR merged dtolnay/syn

Remove deprecated description method from Error impl

This trait method has been soft deprecated in libstd since 1.27.0 and hard deprecated since 1.42.0. Nothing should be using it and it's not able to return a meaningful message anyway. If anything, our message is less useful than the trait's default impl's message.

+1 -5

0 comment

1 changed file

dtolnay

pr closed time in a day

release dtolnay/ref-cast

1.0.3

released time in a day

release dtolnay/ref-cast

1.0.2

released time in a day

created tagdtolnay/ref-cast

tag1.0.3

Safely cast &T to &U where the struct U contains a single field of type T.

created time in a day

push eventdtolnay/ref-cast

David Tolnay

commit sha e14a8d9cccf3bb3445c9e6326b7b8908b9746dc6

Release 1.0.3

view details

push time in a day

delete branch dtolnay/ref-cast

delete branch : fnregression

delete time in a day

PR merged dtolnay/ref-cast

Work around rustc fn ptr parsing regression

https://github.com/rust-lang/rust/issues/78507 affects this crate beginning with nightly-2020-10-29. https://github.com/dtolnay/ref-cast/issues/14

+3 -1

0 comment

1 changed file

dtolnay

pr closed time in a day

push eventdtolnay/ref-cast

David Tolnay

commit sha 9794097e109d656689f18ab1f2072e6666a9c966

Work around rustc fn ptr parsing regression

view details

David Tolnay

commit sha 79e3530d38d25c51c69bff06683c62b3851e6737

Merge pull request #15 from dtolnay/fnregression Work around rustc fn ptr parsing regression

view details

push time in a day

PR opened dtolnay/ref-cast

Work around rustc fn ptr parsing regression

https://github.com/rust-lang/rust/issues/78507 affects this crate beginning with nightly-2020-10-29. https://github.com/dtolnay/ref-cast/issues/14

+3 -1

0 comment

1 changed file

pr created time in a day

create barnchdtolnay/ref-cast

branch : fnregression

created branch time in a day

issue openeddtolnay/ref-cast

Fails to build on nightly-2020-10-29 due to rustc regression

https://github.com/rust-lang/rust/issues/78507 affects this crate.

error: unmatched angle bracket
   --> derive/src/lib.rs:163:72
    |
163 | fn decide_trivial(fields: &Fields) -> Result<fn(&Field) -> Result<bool>> {
    |                                                                        ^^ help: remove extra angle bracket

error: expected one of `,` or `>`, found `{`
   --> derive/src/lib.rs:163:74
    |
163 | fn decide_trivial(fields: &Fields) -> Result<fn(&Field) -> Result<bool>> {
    |                                                                          ^ expected one of `,` or `>`

created time in a day

issue commentrust-lang/rust

Regression parsing closing angle brackets near function ptr return type

Mentioning @estebank @varkor because #78379 "Tweak invalid `fn` header and body parsing" sounds extremely relevant.

dtolnay

comment created time in a day

issue openedrust-lang/rust

Regression parsing closing angle brackets near function ptr return type

Alternate title: "Rust is literally C++" https://wg21.link/N1757

As of the most recent nightly, rustc 1.49.0-nightly (31ee872db 2020-10-28), rustc fails to parse the following code. It works fine in the previous nightly and all past stable releases since 1.0.0.

pub fn f() -> Option<fn() -> Option<bool>> {
    None
}
error: unmatched angle bracket
 --> src/main.rs:1:42
  |
1 | pub fn f() -> Option<fn() -> Option<bool>> {
  |                                          ^^ help: remove extra angle bracket

error: expected one of `,` or `>`, found `{`
 --> src/main.rs:1:44
  |
1 | pub fn f() -> Option<fn() -> Option<bool>> {
  |                                            ^ expected one of `,` or `>`

created time in a day

PR opened dtolnay/syn

Remove deprecated description method from Error impl

This trait method has been soft deprecated in libstd since 1.27.0 and hard deprecated since 1.42.0. Nothing should be using it and it's not able to return a meaningful message anyway. If anything, our message is less useful than the trait's default impl's message.

+1 -5

0 comment

1 changed file

pr created time in a day

create barnchdtolnay/syn

branch : description

created branch time in a day

PR opened dtolnay/cxx

Include typename in diagnostic on unsupported type

First commit is extracted from #370.

<pre> <b>error[cxxbridge]: unsupported type: OsString</b> ┌─ src/main.rs:15:21 │ 15 │ fn huh(wtf: <b>OsString</b>); │ <b>^^^^^^^^ unsupported type</b> </pre>

+9 -1

0 comment

2 changed files

pr created time in a day

create barnchdtolnay/cxx

branch : unsupported-type

created branch time in a day

issue openeddtolnay/cxx

Support C++-defined methods on shared structs

// src/main.rs

#[cxx::bridge]
mod ffi {
    struct Address {
        house_number: u64,
        street: String,
    }

    extern "C" {
        fn print(self: &Address);
    }
}

fn main() {
    let addr = ffi::Address {
        house_number: 1060,
        street: "W Addison St".to_owned(),
    };
    addr.print();
}
// src/address.cc

#include "repro/src/main.rs.h"

void Address::print() const {
  /*...*/
}

Currently this generates noncompilable C++ code because we aren't putting a print member function into the generated Address class.

target/debug/build/repro/out/cxxbridge/sources/repro/src/main.rs.cc: In function ‘void cxxbridge05$Address$print(const Address&)’:
target/debug/build/repro/out/cxxbridge/sources/repro/src/main.rs.cc:54:47: error: ‘print’ is not a member of ‘Address’
   54 |   void (Address::*print$)() const = &Address::print;
      |                                               ^~~~~
// generated
struct Address final {
  uint64_t house_number;
  ::rust::String street;

  // needs to include:
  // void print() const;
};

created time in a day

push eventdtolnay/cxx

David Tolnay

commit sha 353d98cdd93772f2a23e2179386ce3091af85f7f

Move syntax Include to gen Include conversion to From impl

view details

push time in a day

pull request commentdtolnay/cxx

Add error message for invalid include! paths

Probably not. We do almost nothing with includes in this crate, and all of it is only iterating over them (to insert them into the output code). Iterating is easily done on only the syntax tree -- it doesn't require a more structured representation than that. The sets/maps in syntax/types.rs are for things where the generator needs to do more complicated lookup of type information.

https://github.com/dtolnay/cxx/blob/2cc2e3a4d13011e338b1624a6ced35f39f25894d/gen/src/write.rs#L26-L32

Bromeon

comment created time in a day

PullRequestReviewEvent

push eventdtolnay/cxx

David Tolnay

commit sha 2cc2e3a4d13011e338b1624a6ced35f39f25894d

Include angle brackets in include-related errors

view details

push time in a day

delete branch dtolnay/cxx

delete branch : include

delete time in a day

push eventdtolnay/cxx

David Tolnay

commit sha 75c2385e3023e4cf4b0f18b09797be7304f0e4be

Check for disallowed include strings error[cxxbridge]: #include relative to `.` or `..` is not supported in Cargo builds ┌─ src/main.rs:10:18 │ 10 │ include!("../header.h"); │ ^^^^^^^^^^^^^ #include relative to `.` or `..` is not supported in Cargo builds │ = note: use a path starting with the crate name

view details

David Tolnay

commit sha faa1a7c448916d9f52dbc75fdadd56bd151ed13a

Merge pull request #375 from dtolnay/include Check for disallowed include strings in Cargo-based workflow

view details

push time in a day

PR merged dtolnay/cxx

Check for disallowed include strings in Cargo-based workflow
error[cxxbridge]: #include relative to `.` or `..` is not supported in Cargo builds
   ┌─ src/main.rs:10:18
   │
10 │         include!("../header.h");
   │                  ^^^^^^^^^^^^^ #include relative to `.` or `..` is not supported in Cargo builds
   │
   = note: use a path starting with the crate name

Closes #368.

+44 -2

0 comment

5 changed files

dtolnay

pr closed time in a day

PR closed dtolnay/cxx

Add error message for invalid include! paths

As promised in #367, here's the pull request for an error message when include! receives a path that it cannot handle. This is to avoid that such errors propagate further down and only fail at the C++ compile step (and was a reason I spend a lot of time debugging my cxx examples).

The logic is: path must begin with the configured include prefix (crate name by default) or must be an absolute path.

Remarks:

  1. There were multiple places where I could have added the verification, but I thought the parser is not a good idea, because what include! means depends on the user of the parser (can be an external crate such as autocxx). So I implemented it close to the bridge generation.
  2. In the parser, I now no longer skip include! statements, but integrate them with the Types struct and carry that information upward several levels.
  3. There are unit tests for the verify_include_dir() function, but I'm not sure what's the best location for them. I cannot move them to another crate without making the function under test public.
  4. For a similar reason I couldn't write any integration tests (testing the whole chain like in tests/cxx_gen.rs). I did some manual tests however. Probably you know much better how and where to add extra tests, if it's even necessary (this PR is primarily a quality-of-life/diagnostic improvement)
+68 -1

0 comment

3 changed files

Bromeon

pr closed time in a day

PR opened dtolnay/cxx

Check for disallowed include strings in Cargo-based workflow
error[cxxbridge]: #include relative to `.` or `..` is not supported in Cargo builds
   ┌─ src/main.rs:10:18
   │
10 │         include!("../header.h");
   │                  ^^^^^^^^^^^^^ #include relative to `.` or `..` is not supported in Cargo builds
   │
   = note: use a path starting with the crate name

Closes #368.

+44 -2

0 comment

5 changed files

pr created time in a day

create barnchdtolnay/cxx

branch : include

created branch time in a day

delete branch dtolnay/cxx

delete branch : include

delete time in a day

push eventdtolnay/cxx

David Tolnay

commit sha 700cd0c1df3ae50d125f366c57c5c21ccc604139

Expose IncludeKind to cxx_gen library

view details

David Tolnay

commit sha d5107638a1a4ae0c84d5b9ca5a5e5101c65ff686

Merge pull request #374 from dtolnay/include Expose IncludeKind to cxx_gen library

view details

push time in a day

PR merged dtolnay/cxx

Expose IncludeKind to cxx_gen library breaking change
+39 -15

0 comment

6 changed files

dtolnay

pr closed time in a day

PR opened dtolnay/cxx

Expose IncludeKind to cxx_gen library breaking change
+39 -15

0 comment

6 changed files

pr created time in a day

create barnchdtolnay/cxx

branch : include

created branch time in a day

delete branch dtolnay/cxx

delete branch : include

delete time in a day

push eventdtolnay/cxx

David Tolnay

commit sha 4aae7c09b72bfb4299c44468f95bb6d140015900

Distinguish quoted vs bracketed includes in gen::include

view details

David Tolnay

commit sha 36b1dbac2f746ab3a8a5344a836639dabd2eb818

Merge pull request #373 from dtolnay/include Distinguish quoted vs bracketed includes in gen::include

view details

push time in a day

PR merged dtolnay/cxx

Distinguish quoted vs bracketed includes in gen::include
+29 -18

0 comment

2 changed files

dtolnay

pr closed time in a day

PR opened dtolnay/cxx

Distinguish quoted vs bracketed includes in gen::include
+29 -18

0 comment

2 changed files

pr created time in a day

push eventdtolnay/cxx

David Tolnay

commit sha 4aae7c09b72bfb4299c44468f95bb6d140015900

Distinguish quoted vs bracketed includes in gen::include

view details

push time in a day

create barnchdtolnay/cxx

branch : include

created branch time in a day

delete branch dtolnay/cxx

delete branch : include

delete time in a day

push eventdtolnay/cxx

David Tolnay

commit sha b0cd3270b65ce4531c9a50d3b229d558fa1dffa3

Track span information of include statements

view details

David Tolnay

commit sha d927633b8a24cc04a996b119a0c976ddb51f9851

Merge pull request #372 from dtolnay/include Track span information of include statements

view details

push time in a day

PR merged dtolnay/cxx

Track span information of include statements

This will be needed for a correctly positioned error in #368.

+67 -13

0 comment

4 changed files

dtolnay

pr closed time in a day

PR opened dtolnay/cxx

Track span information of include statements

This will be needed for a correctly positioned error in #368.

+67 -13

0 comment

4 changed files

pr created time in a day

create barnchdtolnay/cxx

branch : include

created branch time in a day

delete branch serde-rs/serde

delete branch : clippy

delete time in 2 days

push eventserde-rs/serde

David Tolnay

commit sha 0d5b6c180c8383feea6a213afa667af333623575

Resolve ptr_eq clippy lint error: use `std::ptr::eq` when comparing raw pointers --> serde_derive/src/de.rs:362:12 | 362 | if field as *const Field == transparent_field as *const Field { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(field, transparent_field)` | note: the lint level is defined here --> serde_derive/src/lib.rs:18:9 | 18 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::ptr_eq)]` implied by `#[deny(clippy::all)]` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq

view details

David Tolnay

commit sha 0e1c4093c857d4550573386a1da907707ca6af17

Suppress new result_unit_err clippy lint

view details

push time in 2 days

create barnchserde-rs/serde

branch : clippy

created branch time in 2 days

PullRequestReviewEvent

push eventdtolnay/watt

David Tolnay

commit sha de066c43e8352c9f187a075f83a7d62ddf91c422

Format with rustfmt 1.4.22-nightly

view details

push time in 2 days

push eventdtolnay/watt

David Tolnay

commit sha 5d353f0a7037aa8c3b8833a2cfa379cf9c1a35c0

Format with rustfmt 1.4.22-nightly

view details

push time in 2 days

release dtolnay/proc-macro-hack

0.5.19

released time in 2 days

created tagdtolnay/proc-macro-hack

tag0.5.19

Procedural macros in expression position

created time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha 758784bb05c3d68569ca5001972fe5c31b8175c5

Release 0.5.19

view details

push time in 2 days

delete branch dtolnay/proc-macro-hack

delete branch : native

delete time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha 5cc836b52081d8cf89e3eaddda658b250c1b7f39

Parse only_hack_old_rustc arg

view details

David Tolnay

commit sha 26dc7014116498c4bd6fa1b14a737c376f0fc002

Detect rustc support for native proc macro

view details

David Tolnay

commit sha 11e5ad645844ea107ae36e6ba38ec34b661f5790

Also export the unmodified proc macro behavior

view details

David Tolnay

commit sha f6407e0f92fc5ce75dba85104b88c28dcc3a5599

Switch public name to the one that new rustc can re-export directly

view details

David Tolnay

commit sha a6107565dc80e90040a5f133603fa4a14caf4a93

Expand to direct re-export on new rustc if only_hack_old_rustc

view details

David Tolnay

commit sha a991a7eca28f2730384173b9b18bfd87496a7f64

Add CI coverage of only_hack_old_rustc

view details

David Tolnay

commit sha d686d312d85a1cb041fc2615fd512f59a6b40415

Document only_hack_old_rustc

view details

David Tolnay

commit sha ae11d022e774d8f0b547ae3e5b9508011c350904

Merge pull request #66 from dtolnay/native Add attribute to bypass proc-macro-hack and use native macro

view details

push time in 2 days

PR merged dtolnay/proc-macro-hack

Add attribute to bypass proc-macro-hack and use native macro

Closes #62. Closes #64.

+106 -12

0 comment

7 changed files

dtolnay

pr closed time in 2 days

issue closeddtolnay/proc-macro-hack

Consider compiling to pass-through implementation on new compilers

On Rust versions 1.45 and newer (https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#stabilizing-function-like-procedural-macros-in-expressions-patterns-and-statements) we can bypass all of proc-macro-hack and expand as follows:

#[proc_macro_hack]
pub use mymacro_impl::mymacro;

// expands to:
pub use mymacro_impl::mymacro;
#[proc_macro_hack]
pub fn mymacro(input: TokenStream) -> TokenStream {...}

// expands to:
#[proc_macro]
pub fn mymacro(input: TokenStream) -> TokenStream {...}

This will improve macro expansion performance for libraries that need to support a range of compiler versions including ones older than 1.45.

closed time in 2 days

dtolnay
PullRequestReviewEvent

PR opened dtolnay/proc-macro-hack

Add attribute to bypass proc-macro-hack and use native macro

Closes #62. Closes #64.

+106 -12

0 comment

7 changed files

pr created time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha 5cc836b52081d8cf89e3eaddda658b250c1b7f39

Parse only_hack_old_rustc arg

view details

David Tolnay

commit sha 26dc7014116498c4bd6fa1b14a737c376f0fc002

Detect rustc support for native proc macro

view details

David Tolnay

commit sha 11e5ad645844ea107ae36e6ba38ec34b661f5790

Also export the unmodified proc macro behavior

view details

David Tolnay

commit sha f6407e0f92fc5ce75dba85104b88c28dcc3a5599

Switch public name to the one that new rustc can re-export directly

view details

David Tolnay

commit sha a6107565dc80e90040a5f133603fa4a14caf4a93

Expand to direct re-export on new rustc if only_hack_old_rustc

view details

David Tolnay

commit sha a991a7eca28f2730384173b9b18bfd87496a7f64

Add CI coverage of only_hack_old_rustc

view details

David Tolnay

commit sha d686d312d85a1cb041fc2615fd512f59a6b40415

Document only_hack_old_rustc

view details

push time in 2 days

create barnchdtolnay/proc-macro-hack

branch : native

created branch time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha c194c0b2c873eb6f6f6cfa4ec3d77936a6e536c7

Clarify that 'actual name' is the pub macro in implementation crate

view details

push time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha 0ba7439fb540608cb0b9e0ee95d992c51c5ca1b1

Avoid having to recreate a new pub token

view details

push time in 2 days

push eventrust-lang-nursery/rust-cookbook

Rust Cookbook

commit sha ea0158d3095138fdc08eda0b31b2191f5894f56c

Build cookbook at rust-lang-nursery/rust-cookbook@4789410

view details

push time in 2 days

delete branch dtolnay/proc-macro-hack

delete branch : unexpected

delete time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha c73e24d509c41647248532cfd86cf7337d46bb66

Add ui test of unexpected args on macro definition

view details

David Tolnay

commit sha dc246ed5d3dc8b9bf152c851f6aa680886121a86

Improve unexpected argument error

view details

David Tolnay

commit sha 559631e92306a340bcf3f65abdb8240461fd3d5a

Merge pull request #65 from dtolnay/unexpected Improve unexpected argument error

view details

push time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha eadb0254626ab853e2e1176a7648c8c3795bfeb9

Format with rustfmt 2.0.0-rc.2

view details

David Tolnay

commit sha c73e24d509c41647248532cfd86cf7337d46bb66

Add ui test of unexpected args on macro definition

view details

David Tolnay

commit sha dc246ed5d3dc8b9bf152c851f6aa680886121a86

Improve unexpected argument error

view details

push time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha eadb0254626ab853e2e1176a7648c8c3795bfeb9

Format with rustfmt 2.0.0-rc.2

view details

push time in 2 days

create barnchdtolnay/proc-macro-hack

branch : unexpected

created branch time in 2 days

push eventdtolnay/proc-macro-hack

David Tolnay

commit sha 9e68d2484577fd39c860f129118094fc49469a19

Wrap long line in proc-macro-nested build script

view details

push time in 2 days

pull request commentrust-lang/rfcs

RFC: add the Freeze trait to libcore/libstd

@rfcbot reviewed

If this RFC is reopened in the future, I would want it to discuss PhantomData in more detail. Specifically: PhantomData<T> has impl Send if T is Send, impl Sync if T is Sync, impl Unpin if T is Unpin, impl UnwindSafe if T is UnwindSafe. But, libcore's current Freeze trait has an impl for PhantomData<T> regardless of whether T is Freeze. Before stabilizing we'd want to evaluate the rationale of that.

mtak-

comment created time in 2 days

pull request commentrust-lang/rust

Remove semicolon from internal `err` macro

Er, tidy fails.

Diff in /checkout/library/core/src/str/validations.rs at line 125:
         let old_offset = index;
         macro_rules! err {
             ($error_len: expr) => {
-                return Err(Utf8Error { valid_up_to: old_offset, error_len: $error_len })
+                return Err(Utf8Error { valid_up_to: old_offset, error_len: $error_len });
             };
         }

Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/library/core/src/str/validations.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
Aaron1011

comment created time in 3 days

PullRequestReviewEvent

issue closeddtolnay/quote

try_format_ident!() -> Result<()>

<!-- ❤️ --> Would it be possible to add a function similar to format_ident!() that returns a Result instead of panicking if the string is not valid? ❤️

closed time in 3 days

ctaggart
more