-
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
Tracking issue for RFC #2166: impl-only-use #48216
Comments
I'm going to implement it this weekend. |
I was thinking about this RFC recently. I wonder if we should enable users of existing preludes to take advantage of this feature. For example, for back-compat reasons, the Rayon prelude cannot change to export (Note that -- with the feature as currently implemented at least -- preludes can have |
Implement import renaming with `_` (RFC 2166) cc rust-lang#48216
One deficiency of the current implementation is that #![feature(decl_macro)]
#![allow(unused)]
struct S;
mod m {
pub trait Tr {
fn f(&self) {}
}
impl Tr for ::S {}
}
pub macro m() {
use m::Tr;
}
m!();
fn main() {
S.f(); // ERROR no method named `f` found for type `S` in the current scope
} This is going to be fixed by #48842 or equivalent. |
You are saying that if we alter the macro in your example to this: pub macro m() {
use m::Tr as _;
} then the code will compile, right? (And that is the problem?) In general, it seems sort of unclear whether one would expect this to work, but I guess consistency is good. |
Why would that fix the problem? |
Yes.
Due to attaching hygiene context to |
Actually, everything is more interesting - this bug is hidden by another bug! pub macro outer_use1($Rename: ident) {
use m::Tr as $Rename;
}
pub macro outer_use2($Tr: ident) {
use m::$Tr;
}
pub macro outer_use3($Tr: path) {
pub use $Tr;
}
outer_use1!(Rename);
outer_use2!(Tr);
outer_use3!(m::Tr);
// still a "no method named `f`" error after expanding all the macros above
S.f(); |
syntax: Make `_` a reserved identifier Why: - Lexically `_` is an identifier. - Internally it makes implementation of `use Trait as _;` (#48216) and some other things cleaner. - We prevent the externally observable effect of `_` being accepted by macros expecting `ident` by treating `_` specially in the `ident` matcher: ```rust macro_rules! m { ($i: ident) => { let $i = 10; } } m!(_); // Still an error ```
I just ran into an interesting corner case: if I write
That seems wrong; |
That bug is not limited to |
Working on fixing this. |
#53479 should fix this for |
For searchability: this is the unstable feature |
Nominating for discussion of Rust 2018-only stabilization at the next @rust-lang/lang meeting. |
@eddyb I would suggest preparing a "stabilization report" that contains summary of what behavior is to be stabilized, what corner cases were uncovered, what changed with respect to the RFC, etc. Given that you wrote "Rust 2018-only" that seems to imply to me that there have been some corner cases or other things discovered? Or some interaction with the module system changes? |
It seems like the behavior is the same when you use
decl macros are not stable, so I guess the hygiene interactions there don't matter too much. |
@nikomatsakis Sadly I am not as informed as @petrochenkov on this feature. I don't think we need to stabilize yet, but allowing However, if we make |
If possible, I'd like for this feature to be included in Rust 2015 as well. |
I'm not aware of any issues preventing stabilization of this on Rust 2015. The hygiene issues appear only if we have both call-site and def-site hygiene, so they affect only nightly. |
@petrochenkov Since you are most informed about this, could you prepare a stabilization report for this for both Rust 2015 and Rust 2018? |
@petrochenkov any progress? |
It's in the queue, but with lower priority than uniform paths. |
Stabilization report + stabilization PR - #56303. |
Stabilize `underscore_imports` Closes #48216
This is a tracking issue for the RFC "impl-only-use " (rust-lang/rfcs#2166).
Steps:
The text was updated successfully, but these errors were encountered: