Skip to content
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

Next round of removing feature flags from libsyntax #24715

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 1 addition & 2 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
pub use self::MacroFormat::*;

use std::cell::RefCell;
use std::fmt;
use std::ops::{Add, Sub};
use std::rc::Rc;

use std::fmt;

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


Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/ext/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use feature_gate;
use parse::token::InternedString;
use parse::token;
use ptr::P;
use str::slice_shift_char;

enum State {
Asm,
Expand Down Expand Up @@ -109,7 +110,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
// It's the opposite of '=&' which means that the memory
// cannot be shared with any other operand (usually when
// a register is clobbered early.)
let output = match constraint.slice_shift_char() {
let output = match slice_shift_char(&constraint) {
Some(('=', _)) => None,
Some(('+', operand)) => {
Some(token::intern_and_get_ident(&format!(
Expand Down
11 changes: 2 additions & 9 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use codemap::{respan, Span, Spanned};
use owned_slice::OwnedSlice;
use parse::token;
use ptr::P;
use std::ptr;
use util::small_vector::SmallVector;

use std::rc::Rc;
Expand All @@ -36,14 +35,8 @@ pub trait MoveMap<T> {
}

impl<T> MoveMap<T> for Vec<T> {
fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
for p in &mut self {
unsafe {
// FIXME(#5016) this shouldn't need to zero to be safe.
ptr::write(p, f(ptr::read_and_drop(p)));
}
}
self
fn move_map<F>(self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
self.into_iter().map(|p| f(p)).collect()
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(unicode)]
#![feature(str_char)]

extern crate arena;
extern crate fmt_macros;
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ impl<'a> Parser<'a> {
this_token_str)))
}
} else {
self.expect_one_of(slice::ref_slice(t), &[])
// FIXME: Using this because `slice::ref_slice` is unstable.
let slice = unsafe {
slice::from_raw_parts(t, 1)
};
self.expect_one_of(slice, &[])
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use print::pp::{Breaks, eof};
use print::pp::Breaks::{Consistent, Inconsistent};
use ptr::P;
use std_inject;
use str::slice_shift_char;

use std::ascii;
use std::io::{self, Write, Read};
Expand Down Expand Up @@ -1873,7 +1874,7 @@ impl<'a> State<'a> {

try!(self.commasep(Inconsistent, &a.outputs,
|s, &(ref co, ref o, is_rw)| {
match co.slice_shift_char() {
match slice_shift_char(co) {
Some(('=', operand)) if is_rw => {
try!(s.print_string(&format!("+{}", operand),
ast::CookedStr))
Expand Down
10 changes: 2 additions & 8 deletions src/libsyntax/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use std::fmt::{self, Display, Debug};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::ptr;

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

Expand All @@ -66,15 +65,10 @@ impl<T: 'static> P<T> {
}

/// Transform the inner value, consuming `self` and producing a new `P<T>`.
pub fn map<F>(mut self, f: F) -> P<T> where
pub fn map<F>(self, f: F) -> P<T> where
F: FnOnce(T) -> T,
{
unsafe {
let p = &mut *self.ptr;
// FIXME(#5016) this shouldn't need to drop-fill to be safe.
ptr::write(p, f(ptr::read_and_drop(p)));
}
self
P(f(*self.ptr))
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/libsyntax/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
pub fn char_at(s: &str, byte: usize) -> char {
s[byte..].chars().next().unwrap()
}

// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
#[inline]
pub fn slice_shift_char(s: &str) -> Option<(char, &str)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is actually pretty rarely used (only used twice here), could this just be removed entirely and each call site just have a custom implementation? They don't really need slice_shift_char in its full glory but rather just some smaller specialized versions.

if s.is_empty() {
None
} else {
let ch = char_at(s, 0);
Some((ch, &s[ch.len_utf8()..]))
}
}