Skip to content

Commit 0be8758

Browse files
committed
fix the easy features in libsyntax
1 parent 8305394 commit 0be8758

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

src/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libsyntax/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
serialize = { path = "../libserialize" }
1313
log = "0.3"
14-
rustc_bitflags = { path = "../librustc_bitflags" }
14+
bitflags = "0.8"
1515
syntax_pos = { path = "../libsyntax_pos" }
1616
rustc_errors = { path = "../librustc_errors" }
1717
rustc_data_structures = { path = "../librustc_data_structures" }

src/libsyntax/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,15 @@
2424
test(attr(deny(warnings))))]
2525
#![deny(warnings)]
2626

27-
#![feature(associated_consts)]
28-
#![feature(const_fn)]
29-
#![feature(optin_builtin_traits)]
3027
#![feature(rustc_private)]
3128
#![feature(staged_api)]
32-
#![feature(str_escape)]
3329
#![feature(unicode)]
3430
#![feature(rustc_diagnostic_macros)]
35-
#![feature(specialization)]
3631
#![feature(i128_type)]
3732

3833
extern crate serialize;
3934
#[macro_use] extern crate log;
40-
#[macro_use] #[no_link] extern crate rustc_bitflags;
35+
#[macro_use] extern crate bitflags;
4136
extern crate std_unicode;
4237
pub extern crate rustc_errors as errors;
4338
extern crate syntax_pos;

src/libsyntax/parse/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,14 @@ pub fn char_lit(lit: &str) -> (char, isize) {
261261
}
262262
}
263263

264+
pub fn escape_default(s: &str) -> String {
265+
s.chars().map(char::escape_default).flat_map(|x| x).collect()
266+
}
267+
264268
/// Parse a string representing a string literal into its final form. Does
265269
/// unescaping.
266270
pub fn str_lit(lit: &str) -> String {
267-
debug!("parse_str_lit: given {}", lit.escape_default());
271+
debug!("parse_str_lit: given {}", escape_default(lit));
268272
let mut res = String::with_capacity(lit.len());
269273

270274
// FIXME #8372: This could be a for-loop if it didn't borrow the iterator
@@ -339,7 +343,7 @@ pub fn str_lit(lit: &str) -> String {
339343
/// Parse a string representing a raw string literal into its final form. The
340344
/// only operation this does is convert embedded CRLF into a single LF.
341345
pub fn raw_str_lit(lit: &str) -> String {
342-
debug!("raw_str_lit: given {}", lit.escape_default());
346+
debug!("raw_str_lit: given {}", escape_default(lit));
343347
let mut res = String::with_capacity(lit.len());
344348

345349
// FIXME #8372: This could be a for-loop if it didn't borrow the iterator

src/libsyntax/parse/parser.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use std::path::{self, Path, PathBuf};
6464
use std::slice;
6565

6666
bitflags! {
67-
flags Restrictions: u8 {
67+
pub flags Restrictions: u8 {
6868
const RESTRICTION_STMT_EXPR = 1 << 0,
6969
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1,
7070
}
@@ -2291,7 +2291,7 @@ impl<'a> Parser<'a> {
22912291
let e = if self.token.can_begin_expr()
22922292
&& !(self.token == token::OpenDelim(token::Brace)
22932293
&& self.restrictions.contains(
2294-
Restrictions::RESTRICTION_NO_STRUCT_LITERAL)) {
2294+
RESTRICTION_NO_STRUCT_LITERAL)) {
22952295
Some(self.parse_expr()?)
22962296
} else {
22972297
None
@@ -2318,7 +2318,7 @@ impl<'a> Parser<'a> {
23182318
// This is a struct literal, unless we're prohibited
23192319
// from parsing struct literals here.
23202320
let prohibited = self.restrictions.contains(
2321-
Restrictions::RESTRICTION_NO_STRUCT_LITERAL
2321+
RESTRICTION_NO_STRUCT_LITERAL
23222322
);
23232323
if !prohibited {
23242324
return self.parse_struct_expr(lo, pth, attrs);
@@ -2722,7 +2722,7 @@ impl<'a> Parser<'a> {
27222722
token::Ident(..) if self.token.is_keyword(keywords::In) => {
27232723
self.bump();
27242724
let place = self.parse_expr_res(
2725-
Restrictions::RESTRICTION_NO_STRUCT_LITERAL,
2725+
RESTRICTION_NO_STRUCT_LITERAL,
27262726
None,
27272727
)?;
27282728
let blk = self.parse_block()?;
@@ -2785,7 +2785,7 @@ impl<'a> Parser<'a> {
27852785

27862786
let cur_op_span = self.span;
27872787
let restrictions = if op.is_assign_like() {
2788-
self.restrictions & Restrictions::RESTRICTION_NO_STRUCT_LITERAL
2788+
self.restrictions & RESTRICTION_NO_STRUCT_LITERAL
27892789
} else {
27902790
self.restrictions
27912791
};
@@ -2835,21 +2835,21 @@ impl<'a> Parser<'a> {
28352835

28362836
let rhs = match op.fixity() {
28372837
Fixity::Right => self.with_res(
2838-
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
2838+
restrictions - RESTRICTION_STMT_EXPR,
28392839
|this| {
28402840
this.parse_assoc_expr_with(op.precedence(),
28412841
LhsExpr::NotYetParsed)
28422842
}),
28432843
Fixity::Left => self.with_res(
2844-
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
2844+
restrictions - RESTRICTION_STMT_EXPR,
28452845
|this| {
28462846
this.parse_assoc_expr_with(op.precedence() + 1,
28472847
LhsExpr::NotYetParsed)
28482848
}),
28492849
// We currently have no non-associative operators that are not handled above by
28502850
// the special cases. The code is here only for future convenience.
28512851
Fixity::None => self.with_res(
2852-
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
2852+
restrictions - RESTRICTION_STMT_EXPR,
28532853
|this| {
28542854
this.parse_assoc_expr_with(op.precedence() + 1,
28552855
LhsExpr::NotYetParsed)
@@ -2959,7 +2959,7 @@ impl<'a> Parser<'a> {
29592959
if self.token.can_begin_expr() {
29602960
// parse `for i in 1.. { }` as infinite loop, not as `for i in (1..{})`.
29612961
if self.token == token::OpenDelim(token::Brace) {
2962-
return !self.restrictions.contains(Restrictions::RESTRICTION_NO_STRUCT_LITERAL);
2962+
return !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL);
29632963
}
29642964
true
29652965
} else {
@@ -2973,7 +2973,7 @@ impl<'a> Parser<'a> {
29732973
return self.parse_if_let_expr(attrs);
29742974
}
29752975
let lo = self.prev_span;
2976-
let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?;
2976+
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
29772977
let thn = self.parse_block()?;
29782978
let mut els: Option<P<Expr>> = None;
29792979
let mut hi = thn.span;
@@ -2992,7 +2992,7 @@ impl<'a> Parser<'a> {
29922992
self.expect_keyword(keywords::Let)?;
29932993
let pat = self.parse_pat()?;
29942994
self.expect(&token::Eq)?;
2995-
let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?;
2995+
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
29962996
let thn = self.parse_block()?;
29972997
let (hi, els) = if self.eat_keyword(keywords::Else) {
29982998
let expr = self.parse_else_expr()?;
@@ -3046,7 +3046,7 @@ impl<'a> Parser<'a> {
30463046

30473047
let pat = self.parse_pat()?;
30483048
self.expect_keyword(keywords::In)?;
3049-
let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?;
3049+
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
30503050
let (iattrs, loop_block) = self.parse_inner_attrs_and_block()?;
30513051
attrs.extend(iattrs);
30523052

@@ -3061,7 +3061,7 @@ impl<'a> Parser<'a> {
30613061
if self.token.is_keyword(keywords::Let) {
30623062
return self.parse_while_let_expr(opt_ident, span_lo, attrs);
30633063
}
3064-
let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?;
3064+
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
30653065
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
30663066
attrs.extend(iattrs);
30673067
let span = span_lo.to(body.span);
@@ -3075,7 +3075,7 @@ impl<'a> Parser<'a> {
30753075
self.expect_keyword(keywords::Let)?;
30763076
let pat = self.parse_pat()?;
30773077
self.expect(&token::Eq)?;
3078-
let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?;
3078+
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
30793079
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
30803080
attrs.extend(iattrs);
30813081
let span = span_lo.to(body.span);
@@ -3105,7 +3105,7 @@ impl<'a> Parser<'a> {
31053105
fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
31063106
let match_span = self.prev_span;
31073107
let lo = self.prev_span;
3108-
let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL,
3108+
let discriminant = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
31093109
None)?;
31103110
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
31113111
if self.token == token::Token::Semi {
@@ -3146,7 +3146,7 @@ impl<'a> Parser<'a> {
31463146
guard = Some(self.parse_expr()?);
31473147
}
31483148
self.expect(&token::FatArrow)?;
3149-
let expr = self.parse_expr_res(Restrictions::RESTRICTION_STMT_EXPR, None)?;
3149+
let expr = self.parse_expr_res(RESTRICTION_STMT_EXPR, None)?;
31503150

31513151
let require_comma =
31523152
!classify::expr_is_simple_block(&expr)
@@ -3727,7 +3727,7 @@ impl<'a> Parser<'a> {
37273727
self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) &&
37283728

37293729
// prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
3730-
!self.restrictions.contains(Restrictions::RESTRICTION_NO_STRUCT_LITERAL)
3730+
!self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL)
37313731
}
37323732

37333733
fn is_union_item(&self) -> bool {
@@ -3799,7 +3799,7 @@ impl<'a> Parser<'a> {
37993799
self.mk_expr(lo.to(hi), ExprKind::Path(None, pth), ThinVec::new())
38003800
};
38013801

3802-
let expr = self.with_res(Restrictions::RESTRICTION_STMT_EXPR, |this| {
3802+
let expr = self.with_res(RESTRICTION_STMT_EXPR, |this| {
38033803
let expr = this.parse_dot_or_call_expr_with(expr, lo, attrs.into())?;
38043804
this.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(expr))
38053805
})?;
@@ -3939,7 +3939,7 @@ impl<'a> Parser<'a> {
39393939

39403940
// Remainder are line-expr stmts.
39413941
let e = self.parse_expr_res(
3942-
Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into()))?;
3942+
RESTRICTION_STMT_EXPR, Some(attrs.into()))?;
39433943
Stmt {
39443944
id: ast::DUMMY_NODE_ID,
39453945
span: lo.to(e.span),
@@ -3952,7 +3952,7 @@ impl<'a> Parser<'a> {
39523952

39533953
/// Is this expression a successfully-parsed statement?
39543954
fn expr_is_complete(&mut self, e: &Expr) -> bool {
3955-
self.restrictions.contains(Restrictions::RESTRICTION_STMT_EXPR) &&
3955+
self.restrictions.contains(RESTRICTION_STMT_EXPR) &&
39563956
!classify::expr_requires_semi_to_be_stmt(e)
39573957
}
39583958

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ pub trait PrintState<'a> {
677677
style: ast::StrStyle) -> io::Result<()> {
678678
let st = match style {
679679
ast::StrStyle::Cooked => {
680-
(format!("\"{}\"", st.escape_default()))
680+
(format!("\"{}\"", parse::escape_default(st)))
681681
}
682682
ast::StrStyle::Raw(n) => {
683683
(format!("r{delim}\"{string}\"{delim}",

0 commit comments

Comments
 (0)