Replies: 7 comments 4 replies
-
Remove the
|
Beta Was this translation helpful? Give feedback.
-
Tuple structExamplestruct Foo(pub i32, u32) Motivation
|
Beta Was this translation helpful? Give feedback.
-
Allow specifying visibility in tuple variantExampleenum E {
Record {x: i32, pub y: u32},
Tuple(pub i32, u32)
} Motivation
|
Beta Was this translation helpful? Give feedback.
-
Literal suffix for integer typesExamplelet x = 1i32
let u = 1u32 Motivation
|
Beta Was this translation helpful? Give feedback.
-
Type ascription to sub-patterns(or also to sub-expression).Examplelet (x: Vec<i32>, y) = (i.collect(), false)
let x = Option::None
match x {
Some(_: i32) {}
None {}
} Motivation
|
Beta Was this translation helpful? Give feedback.
-
Enum variant as typeExampleenum Expr {
Bin {lhs: Box<Expr>, rhs: Box<Expr>, op: BinOp}
Un(Box<Expr>, UnOp)
...
}
fn check_bin_expr(expr: Expr::Bin, expected_ty: TyId) -> TyId {
let op = expr.op
...
}
fn check_un_expr(expr: Expr::Un, expected_ty: TyId) -> TyId {
let op = expr.0
...
} Also, it'd be great if we could implement a type narrowing, which is automatically performed depending on the context. fn check_expr(expr: Expr, expected_ty: TyId) -> TyId {
match expr {
// The type of `expr` is narrowed to `Expr::Bin` here.
Expr::Bin(_) => check_bin_expr(expr, expected_ty),
// The type of `expr` is narrowed to `Expr::Un` here.
Expr::Bin(_) => check_un_expr(expr, expected_ty),
}
} Assuming the subtype relation between the variant type and its parent enum type, the code below is also well-typed. fn foo(x: Result<i32, String>) {
match x {
Ok(_) => {
handle_i32(x) // fn handle_i32(x: i32)
handle_result(x) // fn handle_result(x: Result<i32, String>)
}
Err(_) => {
handle_string(x) // fn handle_err(x: String)
handle_result(x)
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Trait aliasesThis feature might be helpful with grouping things like number operations. example:
https://doc.rust-lang.org/beta/unstable-book/language-features/trait-alias.html |
Beta Was this translation helpful? Give feedback.
-
This discussion aims to accumulate our random thoughts on v2 language design and features.
Each topic can be escalated to a concrete issue to proceed to an implementation step or further discussion.
Beta Was this translation helpful? Give feedback.
All reactions