@@ -54,29 +54,18 @@ pub fn unwrap_or_emit_fatal<T>(expr: Result<T, Vec<Diag<'_>>>) -> T {
5454 }
5555}
5656
57- /// Creates a new parser from a source string. On failure, the errors must be consumed via
58- /// `unwrap_or_emit_fatal`, `emit`, `cancel`, etc., otherwise a panic will occur when they are
59- /// dropped.
60- pub fn new_parser_from_source_str (
61- psess : & ParseSess ,
62- name : FileName ,
63- source : String ,
64- ) -> Result < Parser < ' _ > , Vec < Diag < ' _ > > > {
65- let source_file = psess. source_map ( ) . new_source_file ( name, source) ;
66- new_parser_from_source_file ( psess, source_file, StripTokens :: ShebangAndFrontmatter )
67- }
68-
69- /// Creates a new parser from a simple (no shebang, no frontmatter) source string.
57+ /// Creates a new parser from a source string.
7058///
7159/// On failure, the errors must be consumed via `unwrap_or_emit_fatal`, `emit`, `cancel`,
7260/// etc., otherwise a panic will occur when they are dropped.
73- pub fn new_parser_from_simple_source_str (
61+ pub fn new_parser_from_source_str (
7462 psess : & ParseSess ,
7563 name : FileName ,
7664 source : String ,
65+ strip_tokens : StripTokens ,
7766) -> Result < Parser < ' _ > , Vec < Diag < ' _ > > > {
7867 let source_file = psess. source_map ( ) . new_source_file ( name, source) ;
79- new_parser_from_source_file ( psess, source_file, StripTokens :: Nothing )
68+ new_parser_from_source_file ( psess, source_file, strip_tokens )
8069}
8170
8271/// Creates a new parser from a filename. On failure, the errors must be consumed via
@@ -87,6 +76,7 @@ pub fn new_parser_from_simple_source_str(
8776pub fn new_parser_from_file < ' a > (
8877 psess : & ' a ParseSess ,
8978 path : & Path ,
79+ strip_tokens : StripTokens ,
9080 sp : Option < Span > ,
9181) -> Result < Parser < ' a > , Vec < Diag < ' a > > > {
9282 let sm = psess. source_map ( ) ;
@@ -110,7 +100,7 @@ pub fn new_parser_from_file<'a>(
110100 }
111101 err. emit ( ) ;
112102 } ) ;
113- new_parser_from_source_file ( psess, source_file, StripTokens :: ShebangAndFrontmatter )
103+ new_parser_from_source_file ( psess, source_file, strip_tokens )
114104}
115105
116106pub fn utf8_error < E : EmissionGuarantee > (
@@ -172,20 +162,26 @@ fn new_parser_from_source_file(
172162 Ok ( parser)
173163}
174164
165+ /// Given a source string, produces a sequence of token trees.
166+ ///
167+ /// NOTE: This only strips shebangs, not frontmatter!
175168pub fn source_str_to_stream (
176169 psess : & ParseSess ,
177170 name : FileName ,
178171 source : String ,
179172 override_span : Option < Span > ,
180173) -> Result < TokenStream , Vec < Diag < ' _ > > > {
181174 let source_file = psess. source_map ( ) . new_source_file ( name, source) ;
182- // used mainly for `proc_macro` and the likes, not for our parsing purposes, so don't parse
183- // frontmatters as frontmatters, but for compatibility reason still strip the shebang
175+ // FIXME(frontmatter): Consider stripping frontmatter in a future edition. We can't strip them
176+ // in the current edition since that would be breaking.
177+ // See also <https://github.com/rust-lang/rust/issues/145520>.
178+ // Alternatively, stop stripping shebangs here, too, if T-lang and crater approve.
184179 source_file_to_stream ( psess, source_file, override_span, StripTokens :: Shebang )
185180}
186181
187- /// Given a source file, produces a sequence of token trees. Returns any buffered errors from
188- /// parsing the token stream.
182+ /// Given a source file, produces a sequence of token trees.
183+ ///
184+ /// Returns any buffered errors from parsing the token stream.
189185fn source_file_to_stream < ' psess > (
190186 psess : & ' psess ParseSess ,
191187 source_file : Arc < SourceFile > ,
0 commit comments