-
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 De-RFC 3307: Remove type ascription #101728
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@rustbot claim I'll remove all the parsing and diagnostic logic/hacks but leave the AST nodes and everything after it behind for now. |
Add `type_ascribe!` macro as placeholder syntax for type ascription This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription. I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether. Part of rust-lang#101728
delete mentions of type ascription from lint descriptions Tracking Issue: rust-lang#101728
Would it make sense to possibly replace type ascription by an unstable macro in the standard library? macro_rules! type_ascribe {
($e:expr, $t:ty) => {{
let val: $t = $e;
val
}};
} I noticed #104614 added a magic macro that preserves the old semantics, but maybe we can implement this entirely in userland? |
That macro shortens the lifetime of temporaries created in the expression. |
Would a function eliviate this problems with temporaries? pub fn type_ascribe<T>(value: T) -> T { value }
#[allow(unused_macros)]
macro_rules! type_ascribe {
($e:expr, $t:ty) => {{
let val: $t = $e;
val
}};
}
pub fn main() {
// macro dosn't work because of temporaries
// println!("{}", type_ascribe!(String::from("hello world").split_once(' '), _).unwrap().0)
// identity function with turbo fish works
println!("{}", type_ascribe::<_>(String::from("hello world").split_once(' ')).unwrap().0)
} |
That can be wrapped in a macro, of course: pub fn type_ascribe<T>(value: T) -> T { value }
#[allow(unused_macros)]
macro_rules! type_ascribe {
($e:expr, $t:ty) => {type_ascribe::<$t>($e)};
}
pub fn test(x: usize) {
println!("{}", type_ascribe!(String::from("hello world").split_once(' '), _).unwrap().0);
let v = type_ascribe!([[0, 1, 2, 3], [4, 5, 6, 7]][x], [u32; 4]);
} |
This has taken a lot more time than I thought since lots of diagnostics were relying on it in subtle ways and require restructuring. I don't have enough time to work on this and also the other things I'm working on so I'm dropping my assignment here, feel free to take it. There's a WIP PR #106826 which may or may not be useful. |
…tion, r=estebank Remove type ascription from parser and diagnostics Mostly based on rust-lang#106826 Part of rust-lang#101728 r? `@estebank`
…tion, r=estebank Remove type ascription from parser and diagnostics Mostly based on rust-lang#106826 Part of rust-lang#101728 r? `@estebank`
…tion, r=estebank Remove type ascription from parser and diagnostics Mostly based on rust-lang#106826 Part of rust-lang#101728 r? `@estebank`
This supersedes #23416
This is a tracking issue for the RFC "3307" (rust-lang/rfcs#3307).
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
The text was updated successfully, but these errors were encountered: