diff options
| author | Sean McArthur <sean.monstar@gmail.com> | 2014-12-20 00:09:35 -0800 |
|---|---|---|
| committer | Sean McArthur <sean.monstar@gmail.com> | 2015-01-06 14:49:42 -0800 |
| commit | 44440e5c18a1dbcc9685866ffffe00c508929079 (patch) | |
| tree | b66c50cd1e471dc0e37b8a0db2cf7f8f28fbac5f /src/libsyntax/parse/lexer | |
| parent | 8efd9901b628d687d11a4d0ccc153553b38ada49 (diff) | |
| download | rust-44440e5c18a1dbcc9685866ffffe00c508929079.tar.gz rust-44440e5c18a1dbcc9685866ffffe00c508929079.zip | |
core: split into fmt::Show and fmt::String
fmt::Show is for debugging, and can and should be implemented for
all public types. This trait is used with `{:?}` syntax. There still
exists #[derive(Show)].
fmt::String is for types that faithfully be represented as a String.
Because of this, there is no way to derive fmt::String, all
implementations must be purposeful. It is used by the default format
syntax, `{}`.
This will break most instances of `{}`, since that now requires the type
to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the
correct fix. Types that were being printed specifically for users should
receive a fmt::String implementation to fix this.
Part of #20013
[breaking-change]
Diffstat (limited to 'src/libsyntax/parse/lexer')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index a50b97142c2..65187dedeb0 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -111,7 +111,7 @@ impl<'a> Reader for TtReader<'a> { } fn next_token(&mut self) -> TokenAndSpan { let r = tt_next_token(self); - debug!("TtReader: r={}", r); + debug!("TtReader: r={:?}", r); r } fn fatal(&self, m: &str) -> ! { @@ -256,13 +256,13 @@ impl<'a> StringReader<'a> { /// adjusted 1 towards each other (assumes that on either side there is a /// single-byte delimiter). pub fn name_from(&self, start: BytePos) -> ast::Name { - debug!("taking an ident from {} to {}", start, self.last_pos); + debug!("taking an ident from {:?} to {:?}", start, self.last_pos); self.with_str_from(start, token::intern) } /// As name_from, with an explicit endpoint. pub fn name_from_to(&self, start: BytePos, end: BytePos) -> ast::Name { - debug!("taking an ident from {} to {}", start, end); + debug!("taking an ident from {:?} to {:?}", start, end); self.with_str_from_to(start, end, token::intern) } @@ -496,7 +496,7 @@ impl<'a> StringReader<'a> { // for skipping over all "junk" '/' | '#' => { let c = self.scan_comment(); - debug!("scanning a comment {}", c); + debug!("scanning a comment {:?}", c); c }, c if is_whitespace(Some(c)) => { @@ -506,7 +506,7 @@ impl<'a> StringReader<'a> { tok: token::Whitespace, sp: codemap::mk_sp(start_bpos, self.last_pos) }); - debug!("scanning whitespace: {}", c); + debug!("scanning whitespace: {:?}", c); c }, _ => None @@ -592,8 +592,8 @@ impl<'a> StringReader<'a> { whence: &str) { match r.curr { Some(r_c) if r_c == c => r.bump(), - Some(r_c) => panic!("expected {}, hit {}, {}", described_c, r_c, whence), - None => panic!("expected {}, hit EOF, {}", described_c, whence), + Some(r_c) => panic!("expected {:?}, hit {:?}, {}", described_c, r_c, whence), + None => panic!("expected {:?}, hit EOF, {}", described_c, whence), } } @@ -614,7 +614,7 @@ impl<'a> StringReader<'a> { self.scan_digits(base); let encoded_name : u32 = self.with_str_from(start_bpos, |s| { num::from_str_radix(s, 10).unwrap_or_else(|| { - panic!("expected digits representing a name, got `{}`, {}, range [{},{}]", + panic!("expected digits representing a name, got {:?}, {}, range [{:?},{:?}]", s, whence, start_bpos, self.last_pos); }) }); @@ -632,7 +632,7 @@ impl<'a> StringReader<'a> { self.scan_digits(base); let encoded_ctxt : ast::SyntaxContext = self.with_str_from(start_bpos, |s| { num::from_str_radix(s, 10).unwrap_or_else(|| { - panic!("expected digits representing a ctxt, got `{}`, {}", s, whence); + panic!("expected digits representing a ctxt, got {:?}, {}", s, whence); }) }); @@ -652,7 +652,7 @@ impl<'a> StringReader<'a> { if c == Some('_') { debug!("skipping a _"); self.bump(); continue; } match c.and_then(|cc| cc.to_digit(radix)) { Some(_) => { - debug!("{} in scan_digits", c); + debug!("{:?} in scan_digits", c); len += 1; self.bump(); } @@ -728,7 +728,7 @@ impl<'a> StringReader<'a> { delim: char, below_0x7f_only: bool) -> bool { - debug!("scanning {} digits until {}", n_digits, delim); + debug!("scanning {} digits until {:?}", n_digits, delim); let start_bpos = self.last_pos; let mut accum_int = 0; @@ -990,7 +990,7 @@ impl<'a> StringReader<'a> { if is_dec_digit(c) { let num = self.scan_number(c.unwrap()); let suffix = self.scan_optional_raw_name(); - debug!("next_token_inner: scanned number {}, {}", num, suffix); + debug!("next_token_inner: scanned number {:?}, {:?}", num, suffix); return token::Literal(num, suffix) } @@ -1444,14 +1444,14 @@ fn is_dec_digit(c: Option<char>) -> bool { return in_range(c, '0', '9'); } pub fn is_doc_comment(s: &str) -> bool { let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') || s.starts_with("//!"); - debug!("is `{}` a doc comment? {}", s, res); + debug!("is {:?} a doc comment? {}", s, res); res } pub fn is_block_doc_comment(s: &str) -> bool { let res = (s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') || s.starts_with("/*!"); - debug!("is `{}` a doc comment? {}", s, res); + debug!("is {:?} a doc comment? {}", s, res); res } |
