Skip to content

Commit e68108b

Browse files
pcwaltonhuonw
authored andcommitted
librustc: Stop using @str for source.
1 parent f152be7 commit e68108b

File tree

10 files changed

+87
-89
lines changed

10 files changed

+87
-89
lines changed

src/librustc/driver/driver.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,15 @@ fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
138138
-> ast::CrateConfig {
139139
cfgspecs.move_iter().map(|s| {
140140
let sess = parse::new_parse_sess(Some(demitter));
141-
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
141+
parse::parse_meta_from_source_str(@"cfgspec", s, ~[], sess)
142142
}).collect::<ast::CrateConfig>()
143143
}
144144

145145
pub enum Input {
146146
/// Load source from file
147147
FileInput(Path),
148148
/// The string is the source
149-
// FIXME (#2319): Don't really want to box the source string
150-
StrInput(@str)
149+
StrInput(~str)
151150
}
152151

153152
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
@@ -157,9 +156,11 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
157156
FileInput(ref file) => {
158157
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
159158
}
160-
StrInput(src) => {
161-
parse::parse_crate_from_source_str(
162-
anon_src(), src, cfg.clone(), sess.parse_sess)
159+
StrInput(ref src) => {
160+
parse::parse_crate_from_source_str(anon_src(),
161+
(*src).clone(),
162+
cfg.clone(),
163+
sess.parse_sess)
163164
}
164165
}
165166
})
@@ -624,7 +625,7 @@ pub fn pretty_print_input(sess: Session,
624625
_ => @pprust::NoAnn as @pprust::PpAnn,
625626
};
626627

627-
let src = sess.codemap.get_filemap(source_name(input)).src;
628+
let src = &sess.codemap.get_filemap(source_name(input)).src;
628629
let mut rdr = MemReader::new(src.as_bytes().to_owned());
629630
let stdout = io::stdout();
630631
pprust::print_crate(sess.codemap,

src/librustc/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
236236
1u => {
237237
let ifile = matches.free[0].as_slice();
238238
if "-" == ifile {
239-
let src = str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
240-
(d::StrInput(src.to_managed()), None)
239+
let src =
240+
str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
241+
(d::StrInput(src), None)
241242
} else {
242243
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))
243244
}
@@ -319,9 +320,11 @@ fn parse_crate_attrs(sess: session::Session,
319320
d::FileInput(ref ifile) => {
320321
parse::parse_crate_attrs_from_file(ifile, ~[], sess.parse_sess)
321322
}
322-
d::StrInput(src) => {
323-
parse::parse_crate_attrs_from_source_str(
324-
d::anon_src(), src, ~[], sess.parse_sess)
323+
d::StrInput(ref src) => {
324+
parse::parse_crate_attrs_from_source_str(d::anon_src(),
325+
(*src).clone(),
326+
~[],
327+
sess.parse_sess)
325328
}
326329
}
327330
}

src/librustdoc/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>) {
137137
}
138138
}
139139

140-
fn maketest(s: &str, cratename: &str) -> @str {
140+
fn maketest(s: &str, cratename: &str) -> ~str {
141141
let mut prog = ~r"
142142
#[deny(warnings)];
143143
#[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
@@ -156,7 +156,7 @@ fn maketest(s: &str, cratename: &str) -> @str {
156156
prog.push_str("\n}");
157157
}
158158

159-
return prog.to_managed();
159+
return prog;
160160
}
161161

162162
pub struct Collector {

src/libsyntax/codemap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub struct FileMap {
206206
/// e.g. `<anon>`
207207
name: FileName,
208208
/// The complete source code
209-
src: @str,
209+
src: ~str,
210210
/// The start position of this source in the CodeMap
211211
start_pos: BytePos,
212212
/// Locations of lines beginnings in the source code
@@ -267,7 +267,7 @@ impl CodeMap {
267267
}
268268
}
269269

270-
pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap {
270+
pub fn new_filemap(&self, filename: FileName, src: ~str) -> @FileMap {
271271
let mut files = self.files.borrow_mut();
272272
let start_pos = match files.get().last() {
273273
None => 0,

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ mod test {
10471047
~[], sess);
10481048
// should fail:
10491049
let mut loader = ErrLoader;
1050-
expand_crate(sess,&mut loader,~[],crate_ast);
1050+
expand_crate(sess, &mut loader, ~[], crate_ast);
10511051
}
10521052
10531053
#[test] fn test_contains_flatten (){

src/libsyntax/ext/quote.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub mod rt {
203203
($t:ty) => (
204204
impl ToTokens for $t {
205205
fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] {
206-
cx.parse_tts(self.to_source().to_managed())
206+
cx.parse_tts(self.to_source())
207207
}
208208
}
209209
)
@@ -213,7 +213,7 @@ pub mod rt {
213213
($t:ty) => (
214214
impl<'a> ToTokens for $t {
215215
fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] {
216-
cx.parse_tts(self.to_source().to_managed())
216+
cx.parse_tts(self.to_source())
217217
}
218218
}
219219
)
@@ -240,15 +240,15 @@ pub mod rt {
240240
impl_to_tokens!(u64)
241241

242242
pub trait ExtParseUtils {
243-
fn parse_item(&self, s: @str) -> @ast::Item;
244-
fn parse_expr(&self, s: @str) -> @ast::Expr;
245-
fn parse_stmt(&self, s: @str) -> @ast::Stmt;
246-
fn parse_tts(&self, s: @str) -> ~[ast::TokenTree];
243+
fn parse_item(&self, s: ~str) -> @ast::Item;
244+
fn parse_expr(&self, s: ~str) -> @ast::Expr;
245+
fn parse_stmt(&self, s: ~str) -> @ast::Stmt;
246+
fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree];
247247
}
248248

249249
impl<'a> ExtParseUtils for ExtCtxt<'a> {
250250

251-
fn parse_item(&self, s: @str) -> @ast::Item {
251+
fn parse_item(&self, s: ~str) -> @ast::Item {
252252
let res = parse::parse_item_from_source_str(
253253
@"<quote expansion>",
254254
s,
@@ -257,13 +257,13 @@ pub mod rt {
257257
match res {
258258
Some(ast) => ast,
259259
None => {
260-
error!("Parse error with ```\n{}\n```", s);
260+
error!("Parse error");
261261
fail!()
262262
}
263263
}
264264
}
265265

266-
fn parse_stmt(&self, s: @str) -> @ast::Stmt {
266+
fn parse_stmt(&self, s: ~str) -> @ast::Stmt {
267267
parse::parse_stmt_from_source_str(
268268
@"<quote expansion>",
269269
s,
@@ -272,15 +272,15 @@ pub mod rt {
272272
self.parse_sess())
273273
}
274274
275-
fn parse_expr(&self, s: @str) -> @ast::Expr {
275+
fn parse_expr(&self, s: ~str) -> @ast::Expr {
276276
parse::parse_expr_from_source_str(
277277
@"<quote expansion>",
278278
s,
279279
self.cfg(),
280280
self.parse_sess())
281281
}
282282
283-
fn parse_tts(&self, s: @str) -> ~[ast::TokenTree] {
283+
fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree] {
284284
parse::parse_tts_from_source_str(
285285
@"<quote expansion>",
286286
s,

src/libsyntax/ext/source_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
114114
Some(src) => {
115115
// Add this input file to the code map to make it available as
116116
// dependency information
117-
let src = src.to_managed();
118117
let filename = file.display().to_str().to_managed();
118+
let interned = token::intern_and_get_ident(src);
119119
cx.parse_sess.cm.new_filemap(filename, src);
120120

121-
base::MRExpr(cx.expr_str(sp, token::intern_and_get_ident(src)))
121+
base::MRExpr(cx.expr_str(sp, interned))
122122
}
123123
None => {
124124
cx.span_err(sp, format!("{} wasn't a utf-8 file", file.display()));

src/libsyntax/parse/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub fn gather_comments_and_literals(span_diagnostic:
350350
path: @str,
351351
srdr: &mut io::Reader)
352352
-> (~[Comment], ~[Literal]) {
353-
let src = str::from_utf8_owned(srdr.read_to_end()).unwrap().to_managed();
353+
let src = str::from_utf8_owned(srdr.read_to_end()).unwrap();
354354
let cm = CodeMap::new();
355355
let filemap = cm.new_filemap(path, src);
356356
let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);

src/libsyntax/parse/mod.rs

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,23 @@ pub fn parse_crate_attrs_from_file(
8989
return inner;
9090
}
9191

92-
pub fn parse_crate_from_source_str(
93-
name: @str,
94-
source: @str,
95-
cfg: ast::CrateConfig,
96-
sess: @ParseSess
97-
) -> ast::Crate {
92+
pub fn parse_crate_from_source_str(name: @str,
93+
source: ~str,
94+
cfg: ast::CrateConfig,
95+
sess: @ParseSess)
96+
-> ast::Crate {
9897
let mut p = new_parser_from_source_str(sess,
9998
/*bad*/ cfg.clone(),
10099
name,
101100
source);
102101
maybe_aborted(p.parse_crate_mod(),p)
103102
}
104103

105-
pub fn parse_crate_attrs_from_source_str(
106-
name: @str,
107-
source: @str,
108-
cfg: ast::CrateConfig,
109-
sess: @ParseSess
110-
) -> ~[ast::Attribute] {
104+
pub fn parse_crate_attrs_from_source_str(name: @str,
105+
source: ~str,
106+
cfg: ast::CrateConfig,
107+
sess: @ParseSess)
108+
-> ~[ast::Attribute] {
111109
let mut p = new_parser_from_source_str(sess,
112110
/*bad*/ cfg.clone(),
113111
name,
@@ -116,44 +114,40 @@ pub fn parse_crate_attrs_from_source_str(
116114
return inner;
117115
}
118116

119-
pub fn parse_expr_from_source_str(
120-
name: @str,
121-
source: @str,
122-
cfg: ast::CrateConfig,
123-
sess: @ParseSess
124-
) -> @ast::Expr {
117+
pub fn parse_expr_from_source_str(name: @str,
118+
source: ~str,
119+
cfg: ast::CrateConfig,
120+
sess: @ParseSess)
121+
-> @ast::Expr {
125122
let mut p = new_parser_from_source_str(sess, cfg, name, source);
126123
maybe_aborted(p.parse_expr(), p)
127124
}
128125

129-
pub fn parse_item_from_source_str(
130-
name: @str,
131-
source: @str,
132-
cfg: ast::CrateConfig,
133-
sess: @ParseSess
134-
) -> Option<@ast::Item> {
126+
pub fn parse_item_from_source_str(name: @str,
127+
source: ~str,
128+
cfg: ast::CrateConfig,
129+
sess: @ParseSess)
130+
-> Option<@ast::Item> {
135131
let mut p = new_parser_from_source_str(sess, cfg, name, source);
136132
let attrs = p.parse_outer_attributes();
137133
maybe_aborted(p.parse_item(attrs),p)
138134
}
139135

140-
pub fn parse_meta_from_source_str(
141-
name: @str,
142-
source: @str,
143-
cfg: ast::CrateConfig,
144-
sess: @ParseSess
145-
) -> @ast::MetaItem {
136+
pub fn parse_meta_from_source_str(name: @str,
137+
source: ~str,
138+
cfg: ast::CrateConfig,
139+
sess: @ParseSess)
140+
-> @ast::MetaItem {
146141
let mut p = new_parser_from_source_str(sess, cfg, name, source);
147142
maybe_aborted(p.parse_meta_item(),p)
148143
}
149144

150-
pub fn parse_stmt_from_source_str(
151-
name: @str,
152-
source: @str,
153-
cfg: ast::CrateConfig,
154-
attrs: ~[ast::Attribute],
155-
sess: @ParseSess
156-
) -> @ast::Stmt {
145+
pub fn parse_stmt_from_source_str(name: @str,
146+
source: ~str,
147+
cfg: ast::CrateConfig,
148+
attrs: ~[ast::Attribute],
149+
sess: @ParseSess)
150+
-> @ast::Stmt {
157151
let mut p = new_parser_from_source_str(
158152
sess,
159153
cfg,
@@ -163,12 +157,11 @@ pub fn parse_stmt_from_source_str(
163157
maybe_aborted(p.parse_stmt(attrs),p)
164158
}
165159

166-
pub fn parse_tts_from_source_str(
167-
name: @str,
168-
source: @str,
169-
cfg: ast::CrateConfig,
170-
sess: @ParseSess
171-
) -> ~[ast::TokenTree] {
160+
pub fn parse_tts_from_source_str(name: @str,
161+
source: ~str,
162+
cfg: ast::CrateConfig,
163+
sess: @ParseSess)
164+
-> ~[ast::TokenTree] {
172165
let mut p = new_parser_from_source_str(
173166
sess,
174167
cfg,
@@ -184,8 +177,8 @@ pub fn parse_tts_from_source_str(
184177
pub fn new_parser_from_source_str(sess: @ParseSess,
185178
cfg: ast::CrateConfig,
186179
name: @str,
187-
source: @str)
188-
-> Parser {
180+
source: ~str)
181+
-> Parser {
189182
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
190183
}
191184

@@ -248,7 +241,8 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>)
248241
};
249242
match str::from_utf8_owned(bytes) {
250243
Some(s) => {
251-
return string_to_filemap(sess, s.to_managed(),
244+
return string_to_filemap(sess,
245+
s,
252246
path.as_str().unwrap().to_managed());
253247
}
254248
None => {
@@ -260,7 +254,7 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>)
260254

261255
// given a session and a string, add the string to
262256
// the session's codemap and return the new filemap
263-
pub fn string_to_filemap(sess: @ParseSess, source: @str, path: @str)
257+
pub fn string_to_filemap(sess: @ParseSess, source: ~str, path: @str)
264258
-> @FileMap {
265259
sess.cm.new_filemap(path, source)
266260
}

0 commit comments

Comments
 (0)