Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 16, 2019
1 parent a699f17 commit 11580ce
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax_ext/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ symbols! {
rust_2018_preview,
rust_begin_unwind,
rustc,
Rust,
RustcDecodable,
RustcEncodable,
rustc_allocator,
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/asm/asm-parse-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 11580ce

Please sign in to comment.