From 11580ced403211c8c422a952a2c5dabedf6812d6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Nov 2019 20:11:05 +0300 Subject: [PATCH] Address review comments --- src/librustc_parse/parser/expr.rs | 3 +++ src/libsyntax/ast.rs | 5 +---- src/libsyntax_ext/asm.rs | 5 ++--- src/libsyntax_pos/symbol.rs | 1 - src/test/ui/asm/asm-parse-errors.stderr | 10 +++++----- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index be1dc4f19a70e..a56a7bf1802c7 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -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> { match self.parse_opt_lit() { Some(lit) => match lit.kind { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index dee493a708e49..bbf00825acb33 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -2448,10 +2448,7 @@ pub enum Extern { impl Extern { pub fn from_abi(abi: Option) -> Extern { - match abi { - Some(abi) => Extern::Explicit(abi), - None => Extern::Implicit, - } + abi.map_or(Extern::Implicit, Extern::Explicit) } } diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 9b37143557efb..bd345a9a7dada 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -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) } } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index b3e9576f43f59..86eaeeab5a426 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -570,7 +570,6 @@ symbols! { rust_2018_preview, rust_begin_unwind, rustc, - Rust, RustcDecodable, RustcEncodable, rustc_allocator, diff --git a/src/test/ui/asm/asm-parse-errors.stderr b/src/test/ui/asm/asm-parse-errors.stderr index 9fe59d12e12cd..2b29332fef5e5 100644 --- a/src/test/ui/asm/asm-parse-errors.stderr +++ b/src/test/ui/asm/asm-parse-errors.stderr @@ -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