-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Stabilize use_extern_macros
#50911
Stabilize use_extern_macros
#50911
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
r? @kennytm |
@bors try |
⌛ Trying commit 66dfde18bfdfe1f9ae1c516e56228c77284a90b5 with merge ea32c49808849674e3d126b5732b2abfba9ed226... |
☀️ Test successful - status-travis |
cc @rust-lang/infra Crater run (check only) requested. |
Crater run (check only) started. |
Hi @kennytm (crater requester, PR reviewer)! Crater results are at: http://cargobomb-reports.s3.amazonaws.com/pr-50911/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. If you see any spurious failures not on the list, please make a PR against that file. (interested observers: Crater is a tool for testing the impact of changes on the crates.io ecosystem. You can find out more at the repo if you're curious) |
6 regressions.
Relevant source code in npbot-1.0.0[dependencies]
structopt = "0.2.5" #[macro_use]
extern crate quicli;
// ...
use structopt::StructOpt;
use quicli::prelude::*;
// ...
#[derive(StructOpt)]
pub(crate) struct Opt {
#[structopt(short = "d", long = "debug", help = "only use the local, println!() sink")]
debug: bool,
#[structopt(long = "verbose", short = "v", parse(from_occurrences))]
verbose: u8,
// for the SoundTouch source
#[structopt(long = "soundtouch-host")]
soundtouch_host: Option<String>,
// for the last.fm source
#[structopt(long = "lastfm-api-key")]
lastfm_api_key: Option<String>,
#[structopt(long = "lastfm-username")]
lastfm_username: Option<String>,
} Note the lack of Error log
|
I'll look what happens with |
MacroBinding::Global(binding) | ||
} else { | ||
return None; | ||
}; | ||
|
||
if !self.use_extern_macros { | ||
if let Some(scope) = possible_time_travel { |
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.
FIXME: possible_time_travel
is now unused
It looks like So the error should be something like "cannot determine resolution for the derive macro However, due to a scary hole in our macro resolution checking such dummy expansions can happen silently without generating any errors. |
Fixed in #51145 |
use_extern_macros
use_extern_macros
resolve: Some macro resolution refactoring Work towards completing #50911 (comment) The last commit also fixes #53269 by not using `def_id()` on `Def::Err` and also fixes #53512.
resolve: Future proof resolutions for potentially built-in attributes Based on #53778 This is not full "pass all attributes through name resolution", but a more conservative solution. If built-in attribute is ambiguous with any other macro in scope, then an error is reported. TODO: Explain what complications arise with the full solution. cc #50911 (comment) Closes #53531
Feature gate non-builtin attributes in inner attribute position Closes item 3 from #50911 (comment)
resolve: Future proof resolutions for potentially built-in attributes This is not full "pass all attributes through name resolution", but a more conservative solution. If built-in attribute is ambiguous with any other macro in scope, then an error is reported. What complications arise with the full solution - #53913 (comment). cc #50911 (comment) cc #52269 Closes #53531
Temporarily prohibit proc macro attributes placed after derives ... and also proc macro attributes used together with `#[test]`/`#[bench]`. Addresses item 6 from #50911 (comment). The end goal is straightforward predictable left-to-right expansion order for attributes. Right now derives are expanded last regardless of their relative ordering with macro attributes and right now it's simpler to temporarily prohibit macro attributes placed after derives than changing the expansion order. I'm not sure whether the new beta is already released or not, but if it's released, then this patch needs to be backported, so the solution needs to be minimal. How to fix broken code (derives): - Move macro attributes above derives. This won't change expansion order, they are expanded before derives anyway. Using attribute macros on same items with `#[test]` and `#[bench]` is prohibited for similar expansion order reasons, but this one is going to be reverted much sooner than restrictions on derives. How to fix broken code (test/bench): - Enable `#![feature(plugin)]` (don't ask why). r? @ghost
The 1.30.0 release notes for Where can I find more documentation on this feature? So far I've tried local_inner_macros in two cases where a crate's macros depended on anothers and it didn't work in either case. |
@softprops It will be available at https://rust-lang-nursery.github.io/edition-guide/rust-2018/macros/macro-changes.html when merged. |
@petrochenkov thanks! I'll take a look and report back if it looks like what I'm trying to do, re-export transitive dependency crates macros` is actually what this new feature supports. |
@petrochenkov l need to do a bit more testing but I worked it out, at least enough to get a fork of rust crowbar to compile. I still need to test a crate that uses that fork before I can call this 👍 'd It may not be clear to new rust users that for foreign macros, you'll also need namespace the macro's path. In my case I just needed to prefix crowbars use of cpython's macros with |
found a potential bug but I'm not sure if its by design when experimenting with the with extern crate crowbar;
crowbar::lambda!(...) however with extern crate crowbar;
crowbar::lambda!(...)
interestingly though I can do the following with extern crate crowbar;
use crowbar::lambda;
lambda!(...) this feels a bit inconsistent in the way the newer system attempts to line up with what you can do with path references for non macro items. |
@softprops This way the first iteration |
@petrochenkov 100%. that was it. thanks! |
Signed-off-by: JmPotato <ghzpotato@gmail.com> ### What problem does this PR solve? Import macros from other crates with the `use` syntax. ### What is changed and how it works? rust-lang/rust#50911 ### Check List <!--REMOVE the items that are not applicable--> Tests <!-- At least one of them must be included. --> - Unit test - Integration test ### Release note <!-- bugfixes or new feature need a release note --> * No release note.
Closes #35896