-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Pattern types MVP #107606
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
Pattern types MVP #107606
Changes from 3 commits
846b80e
e3dd737
d220902
f8c08a3
a9c203d
b055a05
50d50ab
8f37d1f
925e0b6
7bdd60c
ff28254
bd41537
e05cbfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2682,6 +2682,8 @@ pub enum TyKind<'hir> { | |||||
Infer, | ||||||
/// Placeholder for a type that has failed to be defined. | ||||||
Err, | ||||||
/// Pattern types (`u32 as 1..`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not |
||||||
Pat(&'hir Ty<'hir>, &'hir Pat<'hir>), | ||||||
} | ||||||
|
||||||
#[derive(Debug, HashStable_Generic)] | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,6 +342,12 @@ impl<'a> Parser<'a> { | |
let span = lo.to(self.prev_token.span); | ||
let mut ty = self.mk_ty(span, kind); | ||
|
||
if self.eat_keyword(sym::is) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this change the behavior of macro code like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. macro rules matches continue being the least forwards compatible thing ever :| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's better to expose this through a builtin macro instead of surface syntax, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And this is where the editions system can shine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... I'm a little surprised/sad that i.e., complicated. And still overly restrictive, since we also have the rule for lexically prior arms taking priority over latter arms, so there's only a forwards compatibility concern if the refining arms come after the refined arm. (And until today I thought that macro parsing was greedier than it actually is, preventing |
||
let pat = self.parse_pat_no_top_alt(None)?; | ||
let span = lo.to(self.prev_token.span); | ||
ty = self.mk_ty(span, TyKind::Pat(ty, pat)); | ||
} | ||
|
||
// Try to recover from use of `+` with incorrect priority. | ||
match allow_plus { | ||
AllowPlus::Yes => self.maybe_recover_from_bad_type_plus(&ty)?, | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -946,6 +946,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { | |||
self.hash_ty(ty); | ||||
self.hash_array_length(len); | ||||
}, | ||||
TyKind::Pat(ty, pat) => { | ||||
self.hash_ty(ty); | ||||
self.hash_pat(pat); | ||||
}, | ||||
Comment on lines
+949
to
+952
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also update
|
||||
TyKind::Ptr(ref mut_ty) => { | ||||
self.hash_ty(mut_ty.ty); | ||||
mut_ty.mutbl.hash(&mut self.s); | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -847,6 +847,11 @@ impl Rewrite for ast::Ty { | |||||||||||||
self.span, | ||||||||||||||
shape, | ||||||||||||||
), | ||||||||||||||
ast::TyKind::Pat(ref ty, ref pat) => { | ||||||||||||||
let ty = ty.rewrite(context, shape)?; | ||||||||||||||
let pat = pat.rewrite(context, shape)?; | ||||||||||||||
Some(format!("{ty} is {pat}")) | ||||||||||||||
}, | ||||||||||||||
Comment on lines
+850
to
+854
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @rust-lang/style This seems quite reasonable and noncontroversial to me, and I'd be surprised if there's any vehement objections to this formatting. However, want to make sure everyone has seen it in case we'd like a chance to discuss this as a team first. In the event we do want to review as a team to identify and codify the formatting rules, then this can be changed to re-emit the original input contents in the interim via something like:
Suggested change
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is supposed to be "is" or "as", but it seems like "is" is used everywhere else