-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement CompilerDesugaringKind enum #43832
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 1 commit
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 |
---|---|---|
|
@@ -323,8 +323,8 @@ impl NameAndSpan { | |
pub fn name(&self) -> Symbol { | ||
match self.format { | ||
ExpnFormat::MacroAttribute(s) | | ||
ExpnFormat::MacroBang(s) | | ||
ExpnFormat::CompilerDesugaring(s) => s, | ||
ExpnFormat::MacroBang(s) => s, | ||
ExpnFormat::CompilerDesugaring(ref kind) => kind.as_symbol(), | ||
} | ||
} | ||
} | ||
|
@@ -337,7 +337,39 @@ pub enum ExpnFormat { | |
/// e.g. `format!()` | ||
MacroBang(Symbol), | ||
/// Desugaring done by the compiler during HIR lowering. | ||
CompilerDesugaring(Symbol) | ||
CompilerDesugaring(CompilerDesugaringKind) | ||
} | ||
|
||
/// The kind of compiler desugaring. | ||
#[derive(Clone, Hash, Debug, PartialEq, Eq)] | ||
pub enum CompilerDesugaringKind { | ||
BackArrow, | ||
DotFill, | ||
QuestionMark, | ||
} | ||
|
||
impl CompilerDesugaringKind { | ||
pub fn as_symbol(&self) -> Symbol { | ||
use CompilerDesugaringKind::*; | ||
let s = match *self { | ||
BackArrow => "<-", | ||
DotFill => "...", | ||
QuestionMark => "?", | ||
}; | ||
Symbol::intern(s) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a str> for CompilerDesugaringKind { | ||
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. Somewhat along the lines of what @oli-obk was suggesting, I didn't expect to have |
||
fn from(s: &'a str) -> Self { | ||
use CompilerDesugaringKind::*; | ||
match s { | ||
"<-" => BackArrow, | ||
"..." => DotFill, | ||
"?" => QuestionMark, | ||
_ => panic!("Invalid compiler desugaring"), | ||
} | ||
} | ||
} | ||
|
||
impl Encodable for SyntaxContext { | ||
|
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.
Wouldn't it make sense to directly pass the enum as an argument here?