-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
syntax: unify all MacResult's into a single trait. #13527
Conversation
e: @ast::Expr | ||
} | ||
impl MacExpr { | ||
pub fn new(e: @ast::Expr) -> ~MacResult: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :
shouldn't be necessary anymore now that there are no default bounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. I was just copying of the surrounding code.
Any reason to keep the explicit empty bounds? Otherwise, r=me. |
There's now one unified way to return things from a macro, instead of being able to choose the `AnyMacro` trait or the `MRItem`/`MRExpr` variants of the `MacResult` enum. This does simplify the logic handling the expansions, but the biggest value of this is it makes macros in (for example) type position easier to implement, as there's this single thing to modify. By my measurements (using `-Z time-passes` on libstd and librustc etc.), this appears to have little-to-no impact on expansion speed. There are presumably larger costs than the small number of extra allocations and virtual calls this adds (notably, all `macro_rules!`-defined macros have not changed in behaviour, since they had to use the `AnyMacro` trait anyway).
There's now one unified way to return things from a macro, instead of being able to choose the `AnyMacro` trait or the `MRItem`/`MRExpr` variants of the `MacResult` enum. This does simplify the logic handling the expansions, but the biggest value of this is it makes macros in (for example) type position easier to implement, as there's this single thing to modify. By my measurements (using `-Z time-passes` on libstd and librustc etc.), this appears to have little-to-no impact on expansion speed. There are presumably larger costs than the small number of extra allocations and virtual calls this adds (notably, all `macro_rules!`-defined macros have not changed in behaviour, since they had to use the `AnyMacro` trait anyway). --- Summary of changes for dynamic syntax extension maintainers: - `MacResult` is now a trait, and is returned as `~MacResult` - `MRExpr` & `MRItem` are now `MacExpr::new` and `MacItem:new` respectively (which return `~MacResult`s) - `MacResult::dummy_...` is `DummyResult::any` or `DummyResult::expr`
…o-guarded-return-assist, r=jonas-schievink Use let-else statements in `Convert to guarded return` assist Follow up for rust-lang/rust-analyzer#13516, addresses remaining part of rust-lang/rust-analyzer#13254 (comment)
There's now one unified way to return things from a macro, instead of
being able to choose the
AnyMacro
trait or theMRItem
/MRExpr
variants of the
MacResult
enum. This does simplify the logic handlingthe expansions, but the biggest value of this is it makes macros in (for
example) type position easier to implement, as there's this single thing
to modify.
By my measurements (using
-Z time-passes
on libstd and librustc etc.),this appears to have little-to-no impact on expansion speed. There are
presumably larger costs than the small number of extra allocations and
virtual calls this adds (notably, all
macro_rules!
-defined macros havenot changed in behaviour, since they had to use the
AnyMacro
traitanyway).
Summary of changes for dynamic syntax extension maintainers:
MacResult
is now a trait, and is returned as~MacResult
MRExpr
&MRItem
are nowMacExpr::new
andMacItem:new
respectively (which return~MacResult
s)MacResult::dummy_...
isDummyResult::any
orDummyResult::expr