Skip to content

Commit 37a1f2e

Browse files
committed
rollup merge of #24487: erickt/syntax
This removes the usage of `#[feature(into_cow, slice_patterns, box_syntax, box_patterns, quote, unsafe_destructor)]` from being used in libsyntax. My main desire for this is that it brings me one step closer to letting [syntex](https://github.com/erickt/rust-syntex) compile with stable rust. Hopefully this doesn't inconvenience rust development.
2 parents 957cb42 + 19c8d70 commit 37a1f2e

36 files changed

+258
-178
lines changed

src/librustc_trans/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ unsafe extern "C" fn report_inline_asm<'a, 'b>(cgcx: &'a CodegenContext<'a>,
348348

349349
match cgcx.lto_ctxt {
350350
Some((sess, _)) => {
351-
sess.codemap().with_expn_info(ExpnId::from_llvm_cookie(cookie), |info| match info {
351+
sess.codemap().with_expn_info(ExpnId::from_u32(cookie), |info| match info {
352352
Some(ei) => sess.span_err(ei.call_site, msg),
353353
None => sess.err(msg),
354354
});

src/librustc_trans/trans/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
138138
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx().llcx(),
139139
key.as_ptr() as *const c_char, key.len() as c_uint);
140140

141-
let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id.to_llvm_cookie());
141+
let val: llvm::ValueRef = C_i32(bcx.ccx(), ia.expn_id.into_u32() as i32);
142142

143143
llvm::LLVMSetMetadata(r, kind,
144144
llvm::LLVMMDNodeInContext(bcx.ccx().llcx(), &val, 1));

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
238238
pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: Option<&Ty>) -> Ident {
239239
let mut pretty = match ty {
240240
Some(t) => pprust::ty_to_string(t),
241-
None => String::from_str("..")
241+
None => String::from("..")
242242
};
243243

244244
match *trait_ref {

src/libsyntax/codemap.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::rc::Rc;
2626

2727
use std::fmt;
2828

29-
use libc::c_uint;
3029
use serialize::{Encodable, Decodable, Encoder, Decoder};
3130

3231

@@ -287,13 +286,12 @@ pub const NO_EXPANSION: ExpnId = ExpnId(!0);
287286
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(!1);
288287

289288
impl ExpnId {
290-
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
291-
ExpnId(cookie)
289+
pub fn from_u32(id: u32) -> ExpnId {
290+
ExpnId(id)
292291
}
293292

294-
pub fn to_llvm_cookie(self) -> i32 {
295-
let ExpnId(cookie) = self;
296-
cookie as i32
293+
pub fn into_u32(self) -> u32 {
294+
self.0
297295
}
298296
}
299297

@@ -557,9 +555,9 @@ impl CodeMap {
557555
// FIXME #12884: no efficient/safe way to remove from the start of a string
558556
// and reuse the allocation.
559557
let mut src = if src.starts_with("\u{feff}") {
560-
String::from_str(&src[3..])
558+
String::from(&src[3..])
561559
} else {
562-
String::from_str(&src[..])
560+
String::from(&src[..])
563561
};
564562

565563
// Append '\n' in case it's not already there.
@@ -594,8 +592,8 @@ impl CodeMap {
594592
pub fn new_imported_filemap(&self,
595593
filename: FileName,
596594
source_len: usize,
597-
file_local_lines: Vec<BytePos>,
598-
file_local_multibyte_chars: Vec<MultiByteChar>)
595+
mut file_local_lines: Vec<BytePos>,
596+
mut file_local_multibyte_chars: Vec<MultiByteChar>)
599597
-> Rc<FileMap> {
600598
let mut files = self.files.borrow_mut();
601599
let start_pos = match files.last() {
@@ -606,19 +604,21 @@ impl CodeMap {
606604
let end_pos = Pos::from_usize(start_pos + source_len);
607605
let start_pos = Pos::from_usize(start_pos);
608606

609-
let lines = file_local_lines.map_in_place(|pos| pos + start_pos);
610-
let multibyte_chars = file_local_multibyte_chars.map_in_place(|mbc| MultiByteChar {
611-
pos: mbc.pos + start_pos,
612-
bytes: mbc.bytes
613-
});
607+
for pos in &mut file_local_lines {
608+
*pos = *pos + start_pos;
609+
}
610+
611+
for mbc in &mut file_local_multibyte_chars {
612+
mbc.pos = mbc.pos + start_pos;
613+
}
614614

615615
let filemap = Rc::new(FileMap {
616616
name: filename,
617617
src: None,
618618
start_pos: start_pos,
619619
end_pos: end_pos,
620-
lines: RefCell::new(lines),
621-
multibyte_chars: RefCell::new(multibyte_chars),
620+
lines: RefCell::new(file_local_lines),
621+
multibyte_chars: RefCell::new(file_local_multibyte_chars),
622622
});
623623

624624
files.push(filemap.clone());

src/libsyntax/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,15 @@ impl<'a> fold::Folder for CfgAttrFolder<'a> {
284284
return fold::noop_fold_attribute(attr, self);
285285
}
286286

287-
let (cfg, mi) = match attr.meta_item_list() {
288-
Some([ref cfg, ref mi]) => (cfg, mi),
287+
let attr_list = match attr.meta_item_list() {
288+
Some(attr_list) => attr_list,
289+
None => {
290+
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
291+
return None;
292+
}
293+
};
294+
let (cfg, mi) = match (attr_list.len(), attr_list.get(0), attr_list.get(1)) {
295+
(2, Some(cfg), Some(mi)) => (cfg, mi),
289296
_ => {
290297
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
291298
return None;

src/libsyntax/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ fn highlight_lines(err: &mut EmitterWriter,
644644
}
645645

646646
try!(write!(&mut err.dst, "{}", s));
647-
let mut s = String::from_str("^");
647+
let mut s = String::from("^");
648648
let count = match lastc {
649649
// Most terminals have a tab stop every eight columns by default
650650
'\t' => 8 - col%8,

src/libsyntax/diagnostics/plugin.rs

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
5454
span: Span,
5555
token_tree: &[TokenTree])
5656
-> Box<MacResult+'cx> {
57-
let code = match token_tree {
58-
[ast::TtToken(_, token::Ident(code, _))] => code,
57+
let code = match (token_tree.len(), token_tree.get(0)) {
58+
(1, Some(&ast::TtToken(_, token::Ident(code, _)))) => code,
5959
_ => unreachable!()
6060
};
6161
with_used_diagnostics(|diagnostics| {
@@ -77,20 +77,25 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
7777
));
7878
}
7979
});
80-
MacEager::expr(quote_expr!(ecx, ()))
80+
MacEager::expr(ecx.expr_tuple(span, Vec::new()))
8181
}
8282

8383
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
8484
span: Span,
8585
token_tree: &[TokenTree])
8686
-> Box<MacResult+'cx> {
87-
let (code, description) = match token_tree {
88-
[ast::TtToken(_, token::Ident(ref code, _))] => {
87+
let (code, description) = match (
88+
token_tree.len(),
89+
token_tree.get(0),
90+
token_tree.get(1),
91+
token_tree.get(2)
92+
) {
93+
(1, Some(&ast::TtToken(_, token::Ident(ref code, _))), None, None) => {
8994
(code, None)
9095
},
91-
[ast::TtToken(_, token::Ident(ref code, _)),
92-
ast::TtToken(_, token::Comma),
93-
ast::TtToken(_, token::Literal(token::StrRaw(description, _), None))] => {
96+
(3, Some(&ast::TtToken(_, token::Ident(ref code, _))),
97+
Some(&ast::TtToken(_, token::Comma)),
98+
Some(&ast::TtToken(_, token::Literal(token::StrRaw(description, _), None)))) => {
9499
(code, Some(description))
95100
}
96101
_ => unreachable!()
@@ -123,15 +128,23 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
123128
let sym = Ident::new(token::gensym(&(
124129
"__register_diagnostic_".to_string() + &token::get_ident(*code)
125130
)));
126-
MacEager::items(SmallVector::many(vec![quote_item!(ecx, mod $sym {}).unwrap()]))
131+
MacEager::items(SmallVector::many(vec![
132+
ecx.item_mod(
133+
span,
134+
span,
135+
sym,
136+
Vec::new(),
137+
Vec::new()
138+
)
139+
]))
127140
}
128141

129142
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
130143
span: Span,
131144
token_tree: &[TokenTree])
132145
-> Box<MacResult+'cx> {
133-
let name = match token_tree {
134-
[ast::TtToken(_, token::Ident(ref name, _))] => name,
146+
let name = match (token_tree.len(), token_tree.get(0)) {
147+
(1, Some(&ast::TtToken(_, token::Ident(ref name, _)))) => name,
135148
_ => unreachable!()
136149
};
137150

@@ -148,7 +161,37 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
148161
(descriptions.len(), ecx.expr_vec(span, descriptions))
149162
});
150163

151-
MacEager::items(SmallVector::many(vec![quote_item!(ecx,
152-
pub static $name: [(&'static str, &'static str); $count] = $expr;
153-
).unwrap()]))
164+
let static_ = ecx.lifetime(span, ecx.name_of("'static"));
165+
let ty_str = ecx.ty_rptr(
166+
span,
167+
ecx.ty_ident(span, ecx.ident_of("str")),
168+
Some(static_),
169+
ast::MutImmutable,
170+
);
171+
172+
let ty = ecx.ty(
173+
span,
174+
ast::TyFixedLengthVec(
175+
ecx.ty(
176+
span,
177+
ast::TyTup(vec![ty_str.clone(), ty_str])
178+
),
179+
ecx.expr_usize(span, count),
180+
),
181+
);
182+
183+
MacEager::items(SmallVector::many(vec![
184+
P(ast::Item {
185+
ident: name.clone(),
186+
attrs: Vec::new(),
187+
id: ast::DUMMY_NODE_ID,
188+
node: ast::ItemStatic(
189+
ty,
190+
ast::MutImmutable,
191+
expr,
192+
),
193+
vis: ast::Public,
194+
span: span,
195+
})
196+
]))
154197
}

src/libsyntax/ext/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ macro_rules! make_MacEager {
262262
impl MacEager {
263263
$(
264264
pub fn $fld(v: $t) -> Box<MacResult> {
265-
box MacEager {
265+
Box::new(MacEager {
266266
$fld: Some(v),
267267
..Default::default()
268-
}
268+
})
269269
}
270270
)*
271271
}
@@ -331,7 +331,7 @@ impl DummyResult {
331331
/// Use this as a return value after hitting any errors and
332332
/// calling `span_err`.
333333
pub fn any(sp: Span) -> Box<MacResult+'static> {
334-
box DummyResult { expr_only: false, span: sp }
334+
Box::new(DummyResult { expr_only: false, span: sp })
335335
}
336336

337337
/// Create a default MacResult that can only be an expression.
@@ -340,7 +340,7 @@ impl DummyResult {
340340
/// if an error is encountered internally, the user will receive
341341
/// an error that they also used it in the wrong place.
342342
pub fn expr(sp: Span) -> Box<MacResult+'static> {
343-
box DummyResult { expr_only: true, span: sp }
343+
Box::new(DummyResult { expr_only: true, span: sp })
344344
}
345345

346346
/// A plain dummy expression.

src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
106106
// }
107107

108108
let new = {
109-
let other_f = match other_fs {
110-
[ref o_f] => o_f,
109+
let other_f = match (other_fs.len(), other_fs.get(0)) {
110+
(1, Some(o_f)) => o_f,
111111
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`"),
112112
};
113113

src/libsyntax/ext/deriving/cmp/partial_eq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
2929
cs_fold(
3030
true, // use foldl
3131
|cx, span, subexpr, self_f, other_fs| {
32-
let other_f = match other_fs {
33-
[ref o_f] => o_f,
32+
let other_f = match (other_fs.len(), other_fs.get(0)) {
33+
(1, Some(o_f)) => o_f,
3434
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
3535
};
3636

@@ -46,8 +46,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
4646
cs_fold(
4747
true, // use foldl
4848
|cx, span, subexpr, self_f, other_fs| {
49-
let other_f = match other_fs {
50-
[ref o_f] => o_f,
49+
let other_f = match (other_fs.len(), other_fs.get(0)) {
50+
(1, Some(o_f)) => o_f,
5151
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
5252
};
5353

0 commit comments

Comments
 (0)