Address review comments

This commit is contained in:
Vadim Petrochenkov 2019-11-16 20:11:05 +03:00
parent a699f17483
commit 11580ced40
5 changed files with 11 additions and 13 deletions

View file

@ -1073,6 +1073,9 @@ impl<'a> Parser<'a> {
self.maybe_recover_from_bad_qpath(expr, true) self.maybe_recover_from_bad_qpath(expr, true)
} }
/// Returns a string literal if the next token is a string literal.
/// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
/// and returns `None` if the next token is not literal at all.
pub fn parse_str_lit(&mut self) -> Result<ast::StrLit, Option<Lit>> { pub fn parse_str_lit(&mut self) -> Result<ast::StrLit, Option<Lit>> {
match self.parse_opt_lit() { match self.parse_opt_lit() {
Some(lit) => match lit.kind { Some(lit) => match lit.kind {

View file

@ -2448,10 +2448,7 @@ pub enum Extern {
impl Extern { impl Extern {
pub fn from_abi(abi: Option<StrLit>) -> Extern { pub fn from_abi(abi: Option<StrLit>) -> Extern {
match abi { abi.map_or(Extern::Implicit, Extern::Explicit)
Some(abi) => Extern::Explicit(abi),
None => Extern::Implicit,
}
} }
} }

View file

@ -72,9 +72,8 @@ fn parse_asm_str<'a>(p: &mut Parser<'a>) -> PResult<'a, Symbol> {
Ok(str_lit) => Ok(str_lit.symbol_unescaped), Ok(str_lit) => Ok(str_lit.symbol_unescaped),
Err(opt_lit) => { Err(opt_lit) => {
let span = opt_lit.map_or(p.token.span, |lit| lit.span); let span = opt_lit.map_or(p.token.span, |lit| lit.span);
let msg = "expected string literal"; let mut err = p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
let mut err = p.sess.span_diagnostic.struct_span_fatal(span, msg); err.span_label(span, "not a string literal");
err.span_label(span, msg);
Err(err) Err(err)
} }
} }

View file

@ -570,7 +570,6 @@ symbols! {
rust_2018_preview, rust_2018_preview,
rust_begin_unwind, rust_begin_unwind,
rustc, rustc,
Rust,
RustcDecodable, RustcDecodable,
RustcEncodable, RustcEncodable,
rustc_allocator, rustc_allocator,

View file

@ -8,13 +8,13 @@ error: expected string literal
--> $DIR/asm-parse-errors.rs:5:18 --> $DIR/asm-parse-errors.rs:5:18
| |
LL | asm!("nop" : struct); LL | asm!("nop" : struct);
| ^^^^^^ expected string literal | ^^^^^^ not a string literal
error: expected string literal error: expected string literal
--> $DIR/asm-parse-errors.rs:6:30 --> $DIR/asm-parse-errors.rs:6:30
| |
LL | asm!("mov %eax, $$0x2" : struct); LL | asm!("mov %eax, $$0x2" : struct);
| ^^^^^^ expected string literal | ^^^^^^ not a string literal
error: expected `(`, found keyword `struct` error: expected `(`, found keyword `struct`
--> $DIR/asm-parse-errors.rs:7:39 --> $DIR/asm-parse-errors.rs:7:39
@ -32,7 +32,7 @@ error: expected string literal
--> $DIR/asm-parse-errors.rs:9:44 --> $DIR/asm-parse-errors.rs:9:44
| |
LL | asm!("in %dx, %al" : "={al}"(result) : struct); LL | asm!("in %dx, %al" : "={al}"(result) : struct);
| ^^^^^^ expected string literal | ^^^^^^ not a string literal
error: expected `(`, found keyword `struct` error: expected `(`, found keyword `struct`
--> $DIR/asm-parse-errors.rs:10:51 --> $DIR/asm-parse-errors.rs:10:51
@ -50,13 +50,13 @@ error: expected string literal
--> $DIR/asm-parse-errors.rs:12:36 --> $DIR/asm-parse-errors.rs:12:36
| |
LL | asm!("mov $$0x200, %eax" : : : struct); LL | asm!("mov $$0x200, %eax" : : : struct);
| ^^^^^^ expected string literal | ^^^^^^ not a string literal
error: expected string literal error: expected string literal
--> $DIR/asm-parse-errors.rs:13:45 --> $DIR/asm-parse-errors.rs:13:45
| |
LL | asm!("mov eax, 2" : "={eax}"(foo) : : : struct); LL | asm!("mov eax, 2" : "={eax}"(foo) : : : struct);
| ^^^^^^ expected string literal | ^^^^^^ not a string literal
error: inline assembly must be a string literal error: inline assembly must be a string literal
--> $DIR/asm-parse-errors.rs:14:10 --> $DIR/asm-parse-errors.rs:14:10