@@ -54,29 +54,18 @@ pub fn unwrap_or_emit_fatal<T>(expr: Result<T, Vec<Diag<'_>>>) -> T {
54
54
}
55
55
}
56
56
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.
70
58
///
71
59
/// On failure, the errors must be consumed via `unwrap_or_emit_fatal`, `emit`, `cancel`,
72
60
/// 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 (
74
62
psess : & ParseSess ,
75
63
name : FileName ,
76
64
source : String ,
65
+ strip_tokens : StripTokens ,
77
66
) -> Result < Parser < ' _ > , Vec < Diag < ' _ > > > {
78
67
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 )
80
69
}
81
70
82
71
/// 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(
87
76
pub fn new_parser_from_file < ' a > (
88
77
psess : & ' a ParseSess ,
89
78
path : & Path ,
79
+ strip_tokens : StripTokens ,
90
80
sp : Option < Span > ,
91
81
) -> Result < Parser < ' a > , Vec < Diag < ' a > > > {
92
82
let sm = psess. source_map ( ) ;
@@ -110,7 +100,7 @@ pub fn new_parser_from_file<'a>(
110
100
}
111
101
err. emit ( ) ;
112
102
} ) ;
113
- new_parser_from_source_file ( psess, source_file, StripTokens :: ShebangAndFrontmatter )
103
+ new_parser_from_source_file ( psess, source_file, strip_tokens )
114
104
}
115
105
116
106
pub fn utf8_error < E : EmissionGuarantee > (
@@ -172,20 +162,26 @@ fn new_parser_from_source_file(
172
162
Ok ( parser)
173
163
}
174
164
165
+ /// Given a source string, produces a sequence of token trees.
166
+ ///
167
+ /// NOTE: This only strips shebangs, not frontmatter!
175
168
pub fn source_str_to_stream (
176
169
psess : & ParseSess ,
177
170
name : FileName ,
178
171
source : String ,
179
172
override_span : Option < Span > ,
180
173
) -> Result < TokenStream , Vec < Diag < ' _ > > > {
181
174
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.
184
179
source_file_to_stream ( psess, source_file, override_span, StripTokens :: Shebang )
185
180
}
186
181
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.
189
185
fn source_file_to_stream < ' psess > (
190
186
psess : & ' psess ParseSess ,
191
187
source_file : Arc < SourceFile > ,
0 commit comments