From 1d2acdf8ec1959424be2728fa868e91b3eaeedc6 Mon Sep 17 00:00:00 2001 From: Camelid Date: Fri, 12 Jun 2020 11:31:41 -0700 Subject: [PATCH] Use `Vec` instead of `Option>` --- src/librustc_builtin_macros/asm.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/asm.rs index e98431a2695..8f6b8903d66 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/asm.rs @@ -16,7 +16,7 @@ struct AsmArgs { named_args: FxHashMap, reg_args: FxHashSet, options: ast::InlineAsmOptions, - options_spans: Option>, + options_spans: Vec, } fn parse_args<'a>( @@ -59,7 +59,7 @@ fn parse_args<'a>( named_args: FxHashMap::default(), reg_args: FxHashSet::default(), options: ast::InlineAsmOptions::empty(), - options_spans: None, + options_spans: vec![], }; let mut allow_templates = true; @@ -174,9 +174,9 @@ fn parse_args<'a>( // Validate the order of named, positional & explicit register operands and options. We do // this at the end once we have the full span of the argument available. - if let Some(ref options_spans) = args.options_spans { + if args.options_spans.len() > 0 { ecx.struct_span_err(span, "arguments are not allowed after options") - .span_labels(options_spans.clone(), "previous options") + .span_labels(args.options_spans.clone(), "previous options") .span_label(span, "argument") .emit(); } @@ -227,21 +227,21 @@ fn parse_args<'a>( if args.options.contains(ast::InlineAsmOptions::NOMEM) && args.options.contains(ast::InlineAsmOptions::READONLY) { - let spans = args.options_spans.clone().unwrap(); + let spans = args.options_spans.clone(); ecx.struct_span_err(spans, "the `nomem` and `readonly` options are mutually exclusive") .emit(); } if args.options.contains(ast::InlineAsmOptions::PURE) && args.options.contains(ast::InlineAsmOptions::NORETURN) { - let spans = args.options_spans.clone().unwrap(); + let spans = args.options_spans.clone(); ecx.struct_span_err(spans, "the `pure` and `noreturn` options are mutually exclusive") .emit(); } if args.options.contains(ast::InlineAsmOptions::PURE) && !args.options.intersects(ast::InlineAsmOptions::NOMEM | ast::InlineAsmOptions::READONLY) { - let span = args.options_spans.clone().unwrap(); + let span = args.options_spans.clone(); ecx.struct_span_err( span, "the `pure` option must be combined with either `nomem` or `readonly`", @@ -267,7 +267,7 @@ fn parse_args<'a>( } if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output { ecx.struct_span_err( - args.options_spans.clone().unwrap(), + args.options_spans.clone(), "asm with `pure` option must have at least one output", ) .emit(); @@ -314,11 +314,7 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn } let new_span = span_start.to(p.prev_token.span); - if let Some(options_spans) = &mut args.options_spans { - options_spans.push(new_span); - } else { - args.options_spans = Some(vec![new_span]); - } + args.options_spans.push(new_span); Ok(()) }