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)
}
/// 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>> {
match self.parse_opt_lit() {
Some(lit) => match lit.kind {

View file

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

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),
Err(opt_lit) => {
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_fatal(span, msg);
err.span_label(span, msg);
let mut err = p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
err.span_label(span, "not a string literal");
Err(err)
}
}

View file

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

View file

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