@@ -11,7 +11,8 @@ use std::fmt::{Display, Write};
1111use std:: iter:: Peekable ;
1212
1313use rustc_lexer:: { LiteralKind , TokenKind } ;
14- use rustc_span:: symbol:: Ident ;
14+ use rustc_span:: edition:: Edition ;
15+ use rustc_span:: symbol:: Symbol ;
1516use rustc_span:: with_default_session_globals;
1617
1718/// Highlights `src`, returning the HTML output.
@@ -20,6 +21,7 @@ crate fn render_with_highlighting(
2021 class : Option < & str > ,
2122 playground_button : Option < & str > ,
2223 tooltip : Option < ( & str , & str ) > ,
24+ edition : Edition ,
2325) -> String {
2426 debug ! ( "highlighting: ================\n {}\n ==============" , src) ;
2527 let mut out = String :: with_capacity ( src. len ( ) ) ;
@@ -34,7 +36,7 @@ crate fn render_with_highlighting(
3436 }
3537
3638 write_header ( & mut out, class) ;
37- write_code ( & mut out, & src) ;
39+ write_code ( & mut out, & src, edition ) ;
3840 write_footer ( & mut out, playground_button) ;
3941
4042 out
@@ -45,10 +47,10 @@ fn write_header(out: &mut String, class: Option<&str>) {
4547 . unwrap ( )
4648}
4749
48- fn write_code ( out : & mut String , src : & str ) {
50+ fn write_code ( out : & mut String , src : & str , edition : Edition ) {
4951 // This replace allows to fix how the code source with DOS backline characters is displayed.
5052 let src = src. replace ( "\r \n " , "\n " ) ;
51- Classifier :: new ( & src) . highlight ( & mut |highlight| {
53+ Classifier :: new ( & src, edition ) . highlight ( & mut |highlight| {
5254 match highlight {
5355 Highlight :: Token { text, class } => string ( out, Escape ( text) , class) ,
5456 Highlight :: EnterSpan { class } => enter_span ( out, class) ,
@@ -139,12 +141,19 @@ struct Classifier<'a> {
139141 in_attribute : bool ,
140142 in_macro : bool ,
141143 in_macro_nonterminal : bool ,
144+ edition : Edition ,
142145}
143146
144147impl < ' a > Classifier < ' a > {
145- fn new ( src : & str ) -> Classifier < ' _ > {
148+ fn new ( src : & str , edition : Edition ) -> Classifier < ' _ > {
146149 let tokens = TokenIter { src } . peekable ( ) ;
147- Classifier { tokens, in_attribute : false , in_macro : false , in_macro_nonterminal : false }
150+ Classifier {
151+ tokens,
152+ in_attribute : false ,
153+ in_macro : false ,
154+ in_macro_nonterminal : false ,
155+ edition,
156+ }
148157 }
149158
150159 /// Exhausts the `Classifier` writing the output into `sink`.
@@ -296,7 +305,7 @@ impl<'a> Classifier<'a> {
296305 "Option" | "Result" => Class :: PreludeTy ,
297306 "Some" | "None" | "Ok" | "Err" => Class :: PreludeVal ,
298307 // Keywords are also included in the identifier set.
299- _ if Ident :: from_str ( text) . is_reserved ( ) => Class :: KeyWord ,
308+ _ if Symbol :: intern ( text) . is_reserved ( || self . edition ) => Class :: KeyWord ,
300309 _ if self . in_macro_nonterminal => {
301310 self . in_macro_nonterminal = false ;
302311 Class :: MacroNonTerminal
0 commit comments