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 "More Qualified Paths" #86935
Comments
…, r=nagisa Change linked tracking issue for more_qualified_paths This updates the linked tracking issue for the `more_qualified_paths` feature from the implementation PR rust-lang#80080 to an actual tracking issue rust-lang#86935.
cc @petrochenkov: It looks like this might interact with my higher-ranked closure RFC: rust-lang/rfcs#3216 (comment) Since only lifetimes can be specified within a Does that sound correct to you? |
Personally I'm really hoping to someday see closures with generic type parameters in Rust, similar to what exists in C++. There's no need to erase the type parameter; you "just" desugar to a generic for<T> |x: T| { ... } would be like struct MyClosure;
impl<T> FnOnce<(T,)> for MyClosure {
type Output = ();
...
} Though, this is of limited use unless you also have higher-ranked trait bounds, like fn takes_generic_closure<F>(f: F)
where F: for<T> FnOnce(T)
{ ... } But that too is something I would like to see someday. |
@Aaron1011 |
Lack of stable support for this can be worked around with a simple type alias use std::ops::Range;
type Type<T> = T;
fn main() {
let Type::<<Vec<Range<u8>> as IntoIterator>::Item> {start, end} =
Type::<<Vec<Range<u8>> as IntoIterator>::Item> {start: 3, end: 5};
assert_eq!(start, 3);
assert_eq!(end, 5);
} |
Where is this actually wanted? It seems extremely convoluted. Surely if you know the names of the fields, you know the name of the type? I was amazed to see this is already possible via the trivial workaround, and think this should absolutely not be encouraged. |
The main use-case would be macros (for example, if you want to assert a type built from a user-provided type). However, I don't know if there are currently any macros in the wild that would benefit from this. |
The situation where we name a concrete type via an associative type is quite regular in macros, yes.
At least, |
This seems like it may be ready to stabilize. Could we get a stabilization report and documentation PR? |
Why is the proc macro unable to know the name of the concrete type? |
I just came across an issue working on a proc macro as well where this would have been useful. The proc macro knows (well, assumes) that the type implements trait let constructed = construct!(Bar, a = 12, b = 14);
// expansion:
let constructed = <Bar as Foo>::construct(
<Bar as Foo>::Options { a: 12, b: 14 }
); Naturally this is a simplified version of the proc macro I was working on. I know a macro exactly like this one would likely not be very useful. |
I have a use case for this in a real world macro scenario for generating complex bridge code for Objective-C. I have a macro that looks like this: #[objc(error_enum,
mod = ns_url_error,
domain = unsafe { NSURLErrorDomain },
user_info = [
{ key = NSURLErrorFailingURLErrorKey, type = Id<NSURL> },
{ key = NSURLErrorFailingURLStringErrorKey, type = Id<NSString> },
{ key = NSURLErrorBackgroundTaskCancelledReasonKey, type = ns_url_error_reasons::BackgroundTaskCancelledReason },
{ key = NSURLErrorNetworkUnavailableReasonKey, type = ns_url_error_reasons::NetworkUnavailableReason },
]
)]
pub enum NSURLError {
// several variants
} This generates a bunch of code that constructs an error interface similar to the Swift analogue for Later, I want the user to be able to pattern match on that let <NSURLError as objc2::ErrorEnum>::UserInfo {
failing_url,
failing_url_string,
background_task_cancelled_reason,
network_unavailable_reason,
} = error.user_info(); Since there is a different |
I want to highlight that for some reason this feature does not work with unit and tuple structs, i.e. This seems like a bug/missed thing, but at the same time we have a test for it. I couldn't find any reason why this restriction exists, am I missing something? |
@WaffleLapkin |
Today I found a very confusing bug in the Rust compiler associated to this issue:
The qualified paths do not work for named If I apply the suggestion as shown by the Rust compiler on the playground I will get this error:
But just test yourself via playground. |
@Robbepop If you're able to name type SubRef<'lt> = <Test as EnumRef>::Ref<'lt>;
match self {
Self::Ref { a } => SubRef::Ref { a },
} |
Thanks for letting me know about this work around. Not sure if applicable in my proc. macro usage context since usually you want to avoid introducing identifiers at all costs in generated code. edit: Furthermore getting this to work in a generic context where edit 2: In case someone wants to toy around with the implemented fix. Here is the crate where I stumbled upon this bug: https://github.com/Robbepop/enum-ref |
@petrochenkov well, yes. But at the same time, I understand that it is a bit of a stretch, but to me it seems that |
I have another use-case for this (the work around will also probably work though, so will look into that). I'm making html "components" using a jsx like syntax (from the rstml crate). The component trait will probably end up looking something like this: pub trait Component: Sized {
type Props: Into<Self> + Sized;
fn into_template(self) -> HtmlTemplate;
} This will be used when the user writes rstml like the following: let template = html!(<MyComp foo="hello" baz=5 />); which get's translated to something like this: let template = <MyComp as Component>::Props { foo: "hello", baz: 5 }.into(); The reason for this is quite simple, while I can name the |
I've had a trait with an associated type: trait Provider { type Config; } and wanted to make an instance of the associated type (a struct) for a specific implementation (without importing the associated type by its concrete name, since that wasn't necessary in other contexts). I've tried using
let config = <Foo as Provider>::Config { blah };
Foo::new(config); A type alias worked ( |
Also hit this while implementing a jsx-like let mut #type_ident = <<#path as #bevy_scene::Schematic>::Props as Default>::default();
if let <#path as #bevy_scene::Schematic>::Props::#variant { #(#fields,)* .. } = &mut #type_ident {
#(#variant_props)*
} The actual type of The "type alias" workaround does work. |
This is a tracking issue for the "more qualified paths" feature. This feature originally grew out of a bug report #79658 where structs with qualified paths could not be constructed or used in patterns.
For instance:
See the implementation PR #80080 for more detailed discussion.
The feature gate for the issue is
#![feature(more_qualified_paths)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved Questions
Implementation history
#80080
The text was updated successfully, but these errors were encountered: