-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement minimal, internal-only pattern types in the type system #120131
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
Changes from all commits
fc27a91
c340e67
c4efc25
1d6cd8d
6b24a9c
84acfe8
18ff131
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use rustc_ast::{ast, ptr::P, tokenstream::TokenStream, Pat, Ty}; | ||
use rustc_errors::PResult; | ||
use rustc_expand::base::{self, DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult}; | ||
use rustc_span::{sym, Span}; | ||
|
||
pub fn expand<'cx>( | ||
cx: &'cx mut ExtCtxt<'_>, | ||
sp: Span, | ||
tts: TokenStream, | ||
) -> MacroExpanderResult<'cx> { | ||
let (ty, pat) = match parse_pat_ty(cx, tts) { | ||
Ok(parsed) => parsed, | ||
Err(err) => { | ||
return ExpandResult::Ready(DummyResult::any(sp, err.emit())); | ||
} | ||
}; | ||
|
||
ExpandResult::Ready(base::MacEager::ty(cx.ty(sp, ast::TyKind::Pat(ty, pat)))) | ||
} | ||
|
||
fn parse_pat_ty<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Ty>, P<Pat>)> { | ||
let mut parser = cx.new_parser_from_tts(stream); | ||
|
||
let ty = parser.parse_ty()?; | ||
parser.eat_keyword(sym::is); | ||
let pat = parser.parse_pat_no_top_alt(None, None)?; | ||
|
||
Ok((ty, pat)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,6 +349,9 @@ hir_analysis_pass_to_variadic_function = can't pass `{$ty}` to variadic function | |
.suggestion = cast the value to `{$cast_ty}` | ||
.help = cast the value to `{$cast_ty}` | ||
|
||
hir_analysis_pattern_type_non_const_range = "range patterns must have constant range start and end" | ||
hir_analysis_pattern_type_wild_pat = "wildcard patterns are not permitted for pattern types" | ||
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 error on wildcards. is it just so that you dont have to support it as a 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. Yea. I can keep ICEing, but I used wildcard patterns for tests before implementing range patterns |
||
.label = "this type is the same as the inner type without a pattern" | ||
hir_analysis_placeholder_not_allowed_item_signatures = the placeholder `_` is not allowed within types on item signatures for {$kind} | ||
.label = not allowed in type signatures | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use rustc_macros::Diagnostic; | ||
use rustc_span::Span; | ||
|
||
#[derive(Diagnostic)] | ||
#[diag(hir_analysis_pattern_type_wild_pat)] | ||
pub struct WildPatTy { | ||
#[primary_span] | ||
pub span: Span, | ||
} |
Uh oh!
There was an error while loading. Please reload this page.