-
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 "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 adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety.
This adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety.
This adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety.
This adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety.
* Added action template * Added action generation * Added basic create_action_client function * dded action generation * checkin * Fix missing exported pre_field_serde field * Removed extra code * Sketch out action server construction and destruction This follows generally the same pattern as the service server. It required adding a typesupport function to the Action trait and pulling in some more rcl_action bindings. * Fix action typesupport function * Add ActionImpl trait with internal messages and services This is incomplete, since the service types aren't yet being generated. * Split srv.rs.em into idiomatic and rmw template files This results in the exact same file being produced for services, except for some whitespace changes. However, it enables actions to invoke the respective service template for its generation, similar to how the it works for services and their underlying messages. * Generate underlying service definitions for actions Not tested * Add runtime trait to get the UUID from a goal request C++ uses duck typing for this, knowing that for any `Action`, the type `Action::Impl::SendGoalService::Request` will always have a `goal_id` field of type `unique_identifier_msgs::msg::UUID` without having to prove this to the compiler. Rust's generics are more strict, requiring that this be proven using type bounds. The `Request` type is also action-specific as it contains a `goal` field containing the `Goal` message type of the action. We therefore cannot enforce that all `Request`s are a specific type in `rclrs`. This seems most easily represented using associated type bounds on the `SendGoalService` associated type within `ActionImpl`. To avoid introducing to `rosidl_runtime_rs` a circular dependency on message packages like `unique_identifier_msgs`, the `ExtractUuid` trait only operates on a byte array rather than a more nicely typed `UUID` message type. I'll likely revisit this as we introduce more similar bounds on the generated types. * Integrate RMW message methods into ActionImpl Rather than having a bunch of standalone traits implementing various message functions like `ExtractUuid` and `SetAccepted`, with the trait bounds on each associated type in `ActionImpl`, we'll instead add these functions directly to the `ActionImpl` trait. This is simpler on both the rosidl_runtime_rs and the rclrs side. * Add rosidl_runtime_rs::ActionImpl::create_feedback_message() Adds a trait method to create a feedback message given the goal ID and the user-facing feedback message type. Depending on how many times we do this, it may end up valuable to define a GoalUuid type in rosidl_runtime_rs itself. We wouldn't be able to utilize the `RCL_ACTION_UUID_SIZE` constant imported from `rcl_action`, but this is pretty much guaranteed to be 16 forever. Defining this method signature also required inverting the super-trait relationship between Action and ActionImpl. Now ActionImpl is the sub-trait as this gives it access to all of Action's associated types. Action doesn't need to care about anything from ActionImpl (hopefully). * Add GetResultService methods to ActionImpl * Implement ActionImpl trait methods in generator These still don't build without errors, but it's close. * Replace set_result_response_status with create_result_response rclrs needs to be able to generically construct result responses, including the user-defined result field. * Implement client-side trait methods for action messages This adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety. * Format the rosidl_runtime_rs::ActionImpl trait * Wrap longs lines in rosidl_generator_rs action.rs This at least makes the template easier to read, but also helps with the generated code. In general, the generated code could actually fit on one line for the function signatures, but it's not a big deal to split it across multiple. * Use idiomatic message types in Action trait This is user-facing and so should use the friendly message types. * Cleanup ActionImpl using type aliases Signed-off-by: Michael X. Grey <grey@openrobotics.org> * Formatting * Switch from std::os::raw::c_void to std::ffi::c_void While these are aliases of each other, we might as well use the more appropriate std::ffi version, as requested by reviewers. * Clean up rosidl_generator_rs's cmake files Some of the variables are present but no longer used. Others were not updated with the action changes. * Add a short doc page on the message generation pipeline This should help newcomers orient themselves around the rosidl_*_rs packages. --------- Signed-off-by: Michael X. Grey <grey@openrobotics.org> Co-authored-by: Esteve Fernandez <esteve@apache.org> Co-authored-by: Michael X. Grey <grey@openrobotics.org>
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: