Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAbility to refer to a path relative to the current scope in use declarations #959
Comments
crumblingstatue
changed the title
Ability to refer to items from an inner scope in use declarations
Ability to refer to a relative path in use declarations
Mar 10, 2015
crumblingstatue
changed the title
Ability to refer to a relative path in use declarations
Ability to refer to a path relative to the current scope in use declarations
Mar 10, 2015
This comment has been minimized.
This comment has been minimized.
|
Not sure I understand the issue. I think @eddyb has the best understanding of this area. |
glaebhoerl
referenced this issue
Apr 9, 2015
Closed
Non-module extern crate is not visible to imports #24219
This comment has been minimized.
This comment has been minimized.
|
Another option would be to change the existing |
Kimundi
referenced this issue
Sep 21, 2015
Open
Improve the remaining rough corners of the module system #1289
crumblingstatue
referenced this issue
Oct 29, 2015
Closed
"use self::..." doesn't work inside of functions #18084
steveklabnik
referenced this issue
Jan 3, 2017
Closed
Can't 'use' from an 'extern crate' defined in a function #23314
This comment has been minimized.
This comment has been minimized.
|
This seems like it should enter FCP. |
This comment has been minimized.
This comment has been minimized.
|
If not outright considered a bug. |
parched
referenced this issue
Aug 21, 2017
Closed
Tracking issue for RFC 1566: Procedural macros #38356
This comment has been minimized.
This comment has been minimized.
|
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. |
glaebhoerl
referenced this issue
Oct 1, 2017
Closed
Tracking issue for RFC 2126: Clarify and streamline paths and visibility #44660
Centril
added
the
T-lang
label
Feb 23, 2018
petrochenkov
referenced this issue
Sep 5, 2018
Closed
(Modules) Tracking issue for Picking a Module Path System variant #53130
This comment has been minimized.
This comment has been minimized.
|
Closing in favor of rust-lang/rust#53130. |
crumblingstatue commentedMar 10, 2015
(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?