Skip to content
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
6 changes: 3 additions & 3 deletions src/libproc_macro/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ impl<'a> Quote for &'a str {
}
}

impl Quote for usize {
impl Quote for u16 {
fn quote(self) -> TokenStream {
TokenTree::from(Literal::usize_unsuffixed(self)).into()
TokenTree::from(Literal::u16_unsuffixed(self)).into()
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ macro_rules! literals {
($($i:ident),*; $($raw:ident),*) => {
pub enum LiteralKind {
$($i,)*
$($raw(usize),)*
$($raw(u16),)*
}

impl LiteralKind {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,8 @@ pub enum StrStyle {
Cooked,
/// A raw string, like `r##"foo"##`
///
/// The uint is the number of `#` symbols used
Raw(usize)
/// The value is the number of `#` symbols used.
Raw(u16)
}

/// A literal
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub trait AstBuilder {
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>;
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr>;
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr>;
fn expr_u16(&self, sp: Span, u: u16) -> P<ast::Expr>;
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr>;
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr>;

Expand Down Expand Up @@ -708,6 +709,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_lit(sp, ast::LitKind::Int(u as u128,
ast::LitIntType::Unsigned(ast::UintTy::U32)))
}
fn expr_u16(&self, sp: Span, u: u16) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitKind::Int(u as u128,
ast::LitIntType::Unsigned(ast::UintTy::U16)))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitKind::Int(u as u128, ast::LitIntType::Unsigned(ast::UintTy::U8)))
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {
($name: expr, $suffix: expr, $content: expr $(, $count: expr)*) => {{
let name = mk_name(cx, sp, ast::Ident::with_empty_ctxt($content));
let inner = cx.expr_call(sp, mk_token_path(cx, sp, $name), vec![
name $(, cx.expr_usize(sp, $count))*
name $(, cx.expr_u16(sp, $count))*
]);
let suffix = match $suffix {
Some(name) => cx.expr_some(sp, mk_name(cx, sp, ast::Ident::with_empty_ctxt(name))),
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ impl<'a> StringReader<'a> {
Ok(ret_val)
}

fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: usize) {
fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: u16) {
let mut err = self.struct_span_fatal(pos, pos, "unterminated raw string");
err.span_label(self.mk_sp(pos, pos), "unterminated raw string");
if hash_count > 0 {
err.note(&format!("this raw string should be terminated with `\"{}`",
"#".repeat(hash_count)));
"#".repeat(hash_count as usize)));
}
err.emit();
FatalError.raise();
Expand Down Expand Up @@ -1439,7 +1439,7 @@ impl<'a> StringReader<'a> {
'r' => {
let start_bpos = self.pos;
self.bump();
let mut hash_count = 0;
let mut hash_count: u16 = 0;
while self.ch_is('#') {
self.bump();
hash_count += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub enum Lit {
Integer(ast::Name),
Float(ast::Name),
Str_(ast::Name),
StrRaw(ast::Name, usize), /* raw str delimited by n hash symbols */
StrRaw(ast::Name, u16), /* raw str delimited by n hash symbols */
ByteStr(ast::Name),
ByteStrRaw(ast::Name, usize), /* raw byte str delimited by n hash symbols */
ByteStrRaw(ast::Name, u16), /* raw byte str delimited by n hash symbols */
}

impl Lit {
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ pub fn token_to_string(tok: &Token) -> String {
token::Integer(c) => c.to_string(),
token::Str_(s) => format!("\"{}\"", s),
token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}",
delim=repeat("#", n),
delim=repeat("#", n as usize),
string=s),
token::ByteStr(v) => format!("b\"{}\"", v),
token::ByteStrRaw(s, n) => format!("br{delim}\"{string}\"{delim}",
delim=repeat("#", n),
delim=repeat("#", n as usize),
string=s),
};

Expand Down Expand Up @@ -660,7 +660,7 @@ pub trait PrintState<'a> {
}
ast::StrStyle::Raw(n) => {
(format!("r{delim}\"{string}\"{delim}",
delim=repeat("#", n),
delim=repeat("#", n as usize),
string=st))
}
};
Expand Down