Skip to content

Remove some feature flag usage from libsyntax #24487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ unsafe extern "C" fn report_inline_asm<'a, 'b>(cgcx: &'a CodegenContext<'a>,

match cgcx.lto_ctxt {
Some((sess, _)) => {
sess.codemap().with_expn_info(ExpnId::from_llvm_cookie(cookie), |info| match info {
sess.codemap().with_expn_info(ExpnId::from_u32(cookie), |info| match info {
Some(ei) => sess.span_err(ei.call_site, msg),
None => sess.err(msg),
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx().llcx(),
key.as_ptr() as *const c_char, key.len() as c_uint);

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

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(bcx.ccx().llcx(), &val, 1));
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn name_to_dummy_lifetime(name: Name) -> Lifetime {
pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: Option<&Ty>) -> Ident {
let mut pretty = match ty {
Some(t) => pprust::ty_to_string(t),
None => String::from_str("..")
None => String::from("..")
};

match *trait_ref {
Expand Down
34 changes: 17 additions & 17 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::rc::Rc;

use std::fmt;

use libc::c_uint;
use serialize::{Encodable, Decodable, Encoder, Decoder};


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

impl ExpnId {
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
ExpnId(cookie)
pub fn from_u32(id: u32) -> ExpnId {
ExpnId(id)
}

pub fn to_llvm_cookie(self) -> i32 {
let ExpnId(cookie) = self;
cookie as i32
pub fn into_u32(self) -> u32 {
self.0
}
}

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

// Append '\n' in case it's not already there.
Expand Down Expand Up @@ -594,8 +592,8 @@ impl CodeMap {
pub fn new_imported_filemap(&self,
filename: FileName,
source_len: usize,
file_local_lines: Vec<BytePos>,
file_local_multibyte_chars: Vec<MultiByteChar>)
mut file_local_lines: Vec<BytePos>,
mut file_local_multibyte_chars: Vec<MultiByteChar>)
-> Rc<FileMap> {
let mut files = self.files.borrow_mut();
let start_pos = match files.last() {
Expand All @@ -606,19 +604,21 @@ impl CodeMap {
let end_pos = Pos::from_usize(start_pos + source_len);
let start_pos = Pos::from_usize(start_pos);

let lines = file_local_lines.map_in_place(|pos| pos + start_pos);
let multibyte_chars = file_local_multibyte_chars.map_in_place(|mbc| MultiByteChar {
pos: mbc.pos + start_pos,
bytes: mbc.bytes
});
for pos in &mut file_local_lines {
*pos = *pos + start_pos;
}

for mbc in &mut file_local_multibyte_chars {
mbc.pos = mbc.pos + start_pos;
}

let filemap = Rc::new(FileMap {
name: filename,
src: None,
start_pos: start_pos,
end_pos: end_pos,
lines: RefCell::new(lines),
multibyte_chars: RefCell::new(multibyte_chars),
lines: RefCell::new(file_local_lines),
multibyte_chars: RefCell::new(file_local_multibyte_chars),
});

files.push(filemap.clone());
Expand Down
11 changes: 9 additions & 2 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,15 @@ impl<'a> fold::Folder for CfgAttrFolder<'a> {
return fold::noop_fold_attribute(attr, self);
}

let (cfg, mi) = match attr.meta_item_list() {
Some([ref cfg, ref mi]) => (cfg, mi),
let attr_list = match attr.meta_item_list() {
Some(attr_list) => attr_list,
None => {
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
return None;
}
};
let (cfg, mi) = match (attr_list.len(), attr_list.get(0), attr_list.get(1)) {
(2, Some(cfg), Some(mi)) => (cfg, mi),
_ => {
self.diag.span_err(attr.span, "expected `#[cfg_attr(<cfg pattern>, <attr>)]`");
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ fn highlight_lines(err: &mut EmitterWriter,
}

try!(write!(&mut err.dst, "{}", s));
let mut s = String::from_str("^");
let mut s = String::from("^");
let count = match lastc {
// Most terminals have a tab stop every eight columns by default
'\t' => 8 - col%8,
Expand Down
71 changes: 57 additions & 14 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let code = match token_tree {
[ast::TtToken(_, token::Ident(code, _))] => code,
let code = match (token_tree.len(), token_tree.get(0)) {
(1, Some(&ast::TtToken(_, token::Ident(code, _)))) => code,
_ => unreachable!()
};
with_used_diagnostics(|diagnostics| {
Expand All @@ -77,20 +77,25 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
));
}
});
MacEager::expr(quote_expr!(ecx, ()))
MacEager::expr(ecx.expr_tuple(span, Vec::new()))
}

pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
let (code, description) = match token_tree {
[ast::TtToken(_, token::Ident(ref code, _))] => {
let (code, description) = match (
token_tree.len(),
token_tree.get(0),
token_tree.get(1),
token_tree.get(2)
) {
(1, Some(&ast::TtToken(_, token::Ident(ref code, _))), None, None) => {
(code, None)
},
[ast::TtToken(_, token::Ident(ref code, _)),
ast::TtToken(_, token::Comma),
ast::TtToken(_, token::Literal(token::StrRaw(description, _), None))] => {
(3, Some(&ast::TtToken(_, token::Ident(ref code, _))),
Some(&ast::TtToken(_, token::Comma)),
Some(&ast::TtToken(_, token::Literal(token::StrRaw(description, _), None)))) => {
(code, Some(description))
}
_ => unreachable!()
Expand Down Expand Up @@ -123,15 +128,23 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
let sym = Ident::new(token::gensym(&(
"__register_diagnostic_".to_string() + &token::get_ident(*code)
)));
MacEager::items(SmallVector::many(vec![quote_item!(ecx, mod $sym {}).unwrap()]))
MacEager::items(SmallVector::many(vec![
ecx.item_mod(
span,
span,
sym,
Vec::new(),
Vec::new()
)
]))
}

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

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

MacEager::items(SmallVector::many(vec![quote_item!(ecx,
pub static $name: [(&'static str, &'static str); $count] = $expr;
).unwrap()]))
let static_ = ecx.lifetime(span, ecx.name_of("'static"));
let ty_str = ecx.ty_rptr(
span,
ecx.ty_ident(span, ecx.ident_of("str")),
Some(static_),
ast::MutImmutable,
);

let ty = ecx.ty(
span,
ast::TyFixedLengthVec(
ecx.ty(
span,
ast::TyTup(vec![ty_str.clone(), ty_str])
),
ecx.expr_usize(span, count),
),
);

MacEager::items(SmallVector::many(vec![
P(ast::Item {
ident: name.clone(),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
node: ast::ItemStatic(
ty,
ast::MutImmutable,
expr,
),
vis: ast::Public,
span: span,
})
]))
}
8 changes: 4 additions & 4 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ macro_rules! make_MacEager {
impl MacEager {
$(
pub fn $fld(v: $t) -> Box<MacResult> {
box MacEager {
Box::new(MacEager {
$fld: Some(v),
..Default::default()
}
})
}
)*
}
Expand Down Expand Up @@ -331,7 +331,7 @@ impl DummyResult {
/// Use this as a return value after hitting any errors and
/// calling `span_err`.
pub fn any(sp: Span) -> Box<MacResult+'static> {
box DummyResult { expr_only: false, span: sp }
Box::new(DummyResult { expr_only: false, span: sp })
}

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

/// A plain dummy expression.
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
// }

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

Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/deriving/cmp/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
cs_fold(
true, // use foldl
|cx, span, subexpr, self_f, other_fs| {
let other_f = match other_fs {
[ref o_f] => o_f,
let other_f = match (other_fs.len(), other_fs.get(0)) {
(1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
};

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

Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ext/deriving/cmp/partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
let ordering_ty = Literal(path_std!(cx, core::cmp::Ordering));
let ret_ty = Literal(Path::new_(pathvec_std!(cx, core::option::Option),
None,
vec![box ordering_ty],
vec![Box::new(ordering_ty)],
true));

let inline = cx.meta_word(span, InternedString::new("inline"));
Expand Down Expand Up @@ -150,8 +150,8 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
// }

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

Expand Down Expand Up @@ -208,8 +208,8 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
get use the binops to avoid auto-deref dereferencing too many
layers of pointers, if the type includes pointers.
*/
let other_f = match other_fs {
[ref o_f] => o_f,
let other_f = match (other_fs.len(), other_fs.get(0)) {
(1, Some(o_f)) => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
};

Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
vec!(), true))))
},
explicit_self: None,
args: vec!(Ptr(box Literal(Path::new_local("__D")),
args: vec!(Ptr(Box::new(Literal(Path::new_local("__D"))),
Borrowed(None, MutMutable))),
ret_ty: Literal(Path::new_(
pathvec_std!(cx, core::result::Result),
None,
vec!(box Self_, box Literal(Path::new_(
vec!(Box::new(Self_), Box::new(Literal(Path::new_(
vec!["__D", "Error"], None, vec![], false
))),
)))),
true
)),
attributes: Vec::new(),
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
vec!(), true))))
},
explicit_self: borrowed_explicit_self(),
args: vec!(Ptr(box Literal(Path::new_local("__S")),
args: vec!(Ptr(Box::new(Literal(Path::new_local("__S"))),
Borrowed(None, MutMutable))),
ret_ty: Literal(Path::new_(
pathvec_std!(cx, core::result::Result),
None,
vec!(box Tuple(Vec::new()), box Literal(Path::new_(
vec!(Box::new(Tuple(Vec::new())), Box::new(Literal(Path::new_(
vec!["__S", "Error"], None, vec![], false
))),
)))),
true
)),
attributes: Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ impl<'a> MethodDef<'a> {
Self_ if nonstatic => {
self_args.push(arg_expr);
}
Ptr(box Self_, _) if nonstatic => {
Ptr(ref ty, _) if **ty == Self_ && nonstatic => {
self_args.push(cx.expr_deref(trait_.span, arg_expr))
}
_ => {
Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl<'a> MethodDef<'a> {
subpats.push(p);
idents
};
for self_arg_name in self_arg_names.tail() {
for self_arg_name in &self_arg_names[1..] {
let (p, idents) = mk_self_pat(cx, &self_arg_name[..]);
subpats.push(p);
self_pats_idents.push(idents);
Expand Down
Loading