-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Ability to refer to a path relative to the current scope in use declarations #959
Comments
Not sure I understand the issue. I think @eddyb has the best understanding of this area. |
Another option would be to change the existing |
This seems like it should enter FCP. |
If not outright considered a bug. |
I think I've run into this issue with Maud. I'd like to write a function-like proc macro that expands to the following expression (where {
extern crate maud;
use maud::Render;
$expr.render_to($output);
} But because of this issue, the I could call the trait method directly ( I ended up working around this issue using a forwarding trait + blanket impl: {
extern crate maud;
trait RenderWrapper: maud::Render {
fn __render_to(&self, output: &mut String) {
maud::Render::render_to(self, output);
}
}
impl<T: maud::Render> RenderWrapper for T {}
$expr.__render_to($output);
} but this feels kind of icky. |
Closing in favor of rust-lang/rust#53130. |
(Note that this is not about the ability to refer to the current module, which is already possible with
use self::foo
.)Rust allows declaring modules, enums, and extern crates in most places where items can be declared, including block scopes inside functions.
One use of this is bringing an extern crate into scope inside a conditional branch:
The problem is that there is no way to refer to items declared this way in use declarations, as paths in use declarations are absolute.
It feels inconsistent being able to declare items like this, but not being able to refer to them in use declarations, and might surprise some users. It did surprise me.
While referring to the items inside can be done by using their full relative path (e.g.
do_something_with(messagebox::foo)
), there is no way to import traits, so the user has to move the module/crate up to a scope where it can be referred from in use declarations.One way this could be resolved is to give users a way to refer to a relative path in use declarations.
Options include:
use relative::messagebox::Messagebox
, although I'm not sure reserving a new keyword this late in the alpha is desirable._
, as inuse _::messagebox::Messagebox
, but I'm not sure if_
could otherwise refer to a valid path. It's also not as descriptive as a keyword, but still better than nothing.The general ability to use relative paths in use declarations might also bring ergonomic benefits in other cases too.
Any thoughts on this issue?
The text was updated successfully, but these errors were encountered: