From 732a6a2a09127e3db19813189aac8d025310888d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Sep 2020 14:47:04 +0200 Subject: [PATCH] Remove struct_span_err function from ExtCtxt --- compiler/rustc_builtin_macros/src/asm.rs | 76 +++++++++++-------- compiler/rustc_builtin_macros/src/assert.rs | 7 +- compiler/rustc_builtin_macros/src/cfg.rs | 4 +- compiler/rustc_builtin_macros/src/concat.rs | 2 +- compiler/rustc_builtin_macros/src/format.rs | 22 +++--- .../rustc_builtin_macros/src/global_asm.rs | 2 +- compiler/rustc_builtin_macros/src/llvm_asm.rs | 5 +- compiler/rustc_builtin_macros/src/test.rs | 11 +-- compiler/rustc_expand/src/base.rs | 10 +-- compiler/rustc_expand/src/config.rs | 4 +- compiler/rustc_expand/src/expand.rs | 5 +- compiler/rustc_expand/src/mbe/macro_rules.rs | 4 +- compiler/rustc_expand/src/mbe/transcribe.rs | 8 +- compiler/rustc_expand/src/proc_macro.rs | 17 +++-- 14 files changed, 97 insertions(+), 80 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 5dafd6b77ab1e..370e8a24617c1 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -27,13 +27,14 @@ fn parse_args<'a>( let mut p = ecx.new_parser_from_tts(tts); if p.token == token::Eof { - return Err(ecx.struct_span_err(sp, "requires at least a template string argument")); + return Err(ecx.sess.struct_span_err(sp, "requires at least a template string argument")); } // Detect use of the legacy llvm_asm! syntax (which used to be called asm!) if p.look_ahead(1, |t| *t == token::Colon || *t == token::ModSep) { - let mut err = - ecx.struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported"); + let mut err = ecx + .sess + .struct_span_err(sp, "the legacy LLVM-style asm! syntax is no longer supported"); err.note("consider migrating to the new asm! syntax specified in RFC 2873"); err.note("alternatively, switch to llvm_asm! to keep your code working as it is"); @@ -67,7 +68,7 @@ fn parse_args<'a>( if !p.eat(&token::Comma) { if allow_templates { // After a template string, we always expect *only* a comma... - let mut err = ecx.struct_span_err(p.token.span, "expected token: `,`"); + let mut err = ecx.sess.struct_span_err(p.token.span, "expected token: `,`"); err.span_label(p.token.span, "expected `,`"); p.maybe_annotate_with_ascription(&mut err, false); return Err(err); @@ -142,6 +143,7 @@ fn parse_args<'a>( ast::ExprKind::Path(..) => {} _ => { let err = ecx + .sess .struct_span_err(expr.span, "argument to `sym` must be a path expression"); return Err(err); } @@ -156,7 +158,7 @@ fn parse_args<'a>( ast::ExprKind::MacCall(..) => {} _ => { let errstr = "expected operand, options, or additional template string"; - let mut err = ecx.struct_span_err(template.span, errstr); + let mut err = ecx.sess.struct_span_err(template.span, errstr); err.span_label(template.span, errstr); return Err(err); } @@ -175,26 +177,30 @@ 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 !args.options_spans.is_empty() { - ecx.struct_span_err(span, "arguments are not allowed after options") + ecx.sess + .struct_span_err(span, "arguments are not allowed after options") .span_labels(args.options_spans.clone(), "previous options") .span_label(span, "argument") .emit(); } if explicit_reg { if name.is_some() { - ecx.struct_span_err(span, "explicit register arguments cannot have names").emit(); + ecx.sess + .struct_span_err(span, "explicit register arguments cannot have names") + .emit(); } args.reg_args.insert(slot); } else if let Some(name) = name { if let Some(&prev) = args.named_args.get(&name) { - ecx.struct_span_err(span, &format!("duplicate argument named `{}`", name)) + ecx.sess + .struct_span_err(span, &format!("duplicate argument named `{}`", name)) .span_label(args.operands[prev].1, "previously here") .span_label(span, "duplicate argument") .emit(); continue; } if !args.reg_args.is_empty() { - let mut err = ecx.struct_span_err( + let mut err = ecx.sess.struct_span_err( span, "named arguments cannot follow explicit register arguments", ); @@ -207,7 +213,7 @@ fn parse_args<'a>( args.named_args.insert(name, slot); } else { if !args.named_args.is_empty() || !args.reg_args.is_empty() { - let mut err = ecx.struct_span_err( + let mut err = ecx.sess.struct_span_err( span, "positional arguments cannot follow named arguments \ or explicit register arguments", @@ -228,25 +234,28 @@ fn parse_args<'a>( && args.options.contains(ast::InlineAsmOptions::READONLY) { let spans = args.options_spans.clone(); - ecx.struct_span_err(spans, "the `nomem` and `readonly` options are mutually exclusive") + ecx.sess + .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(); - ecx.struct_span_err(spans, "the `pure` and `noreturn` options are mutually exclusive") + ecx.sess + .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 spans = args.options_spans.clone(); - ecx.struct_span_err( - spans, - "the `pure` option must be combined with either `nomem` or `readonly`", - ) - .emit(); + ecx.sess + .struct_span_err( + spans, + "the `pure` option must be combined with either `nomem` or `readonly`", + ) + .emit(); } let mut have_real_output = false; @@ -266,14 +275,16 @@ fn parse_args<'a>( } } if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output { - ecx.struct_span_err( - args.options_spans.clone(), - "asm with `pure` option must have at least one output", - ) - .emit(); + ecx.sess + .struct_span_err( + args.options_spans.clone(), + "asm with `pure` option must have at least one output", + ) + .emit(); } if args.options.contains(ast::InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() { let err = ecx + .sess .struct_span_err(outputs_sp, "asm outputs are not allowed with the `noreturn` option"); // Bail out now since this is likely to confuse MIR @@ -445,7 +456,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P, sp: Span, args: AsmArgs) -> P, sp: Span, args: AsmArgs) -> P Some(idx), None => { let msg = format!("there is no argument named `{}`", name); - ecx.struct_span_err(span, &msg[..]).emit(); + ecx.sess.struct_span_err(span, &msg[..]).emit(); None } }, @@ -534,11 +545,12 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P, sp: Span, args: AsmArgs) -> P {} 1 => { let (sp, msg) = unused_operands.into_iter().next().unwrap(); - let mut err = ecx.struct_span_err(sp, msg); + let mut err = ecx.sess.struct_span_err(sp, msg); err.span_label(sp, msg); err.help(&format!( "if this argument is intentionally unused, \ @@ -590,7 +602,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P { - let mut err = ecx.struct_span_err( + let mut err = ecx.sess.struct_span_err( unused_operands.iter().map(|&(sp, _)| sp).collect::>(), "multiple unused asm arguments", ); diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index 2518171554073..82856ffc4588e 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -67,7 +67,8 @@ fn parse_assert<'a>( let mut parser = cx.new_parser_from_tts(stream); if parser.token == token::Eof { - let mut err = cx.struct_span_err(sp, "macro requires a boolean expression as an argument"); + let mut err = + cx.sess.struct_span_err(sp, "macro requires a boolean expression as an argument"); err.span_label(sp, "boolean expression required"); return Err(err); } @@ -82,7 +83,7 @@ fn parse_assert<'a>( // // Emit an error about semicolon and suggest removing it. if parser.token == token::Semi { - let mut err = cx.struct_span_err(sp, "macro requires an expression as an argument"); + let mut err = cx.sess.struct_span_err(sp, "macro requires an expression as an argument"); err.span_suggestion( parser.token.span, "try removing semicolon", @@ -102,7 +103,7 @@ fn parse_assert<'a>( // Emit an error and suggest inserting a comma. let custom_message = if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind { - let mut err = cx.struct_span_err(parser.token.span, "unexpected string literal"); + let mut err = cx.sess.struct_span_err(parser.token.span, "unexpected string literal"); let comma_span = parser.prev_token.span.shrink_to_hi(); err.span_suggestion_short( comma_span, diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs index 4c00162b556b8..ed82458f46819 100644 --- a/compiler/rustc_builtin_macros/src/cfg.rs +++ b/compiler/rustc_builtin_macros/src/cfg.rs @@ -37,7 +37,7 @@ fn parse_cfg<'a>( let mut p = cx.new_parser_from_tts(tts); if p.token == token::Eof { - let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument"); + let mut err = cx.sess.struct_span_err(sp, "macro requires a cfg-pattern as an argument"); err.span_label(sp, "cfg-pattern required"); return Err(err); } @@ -47,7 +47,7 @@ fn parse_cfg<'a>( let _ = p.eat(&token::Comma); if !p.eat(&token::Eof) { - return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern")); + return Err(cx.sess.struct_span_err(sp, "expected 1 cfg-pattern")); } Ok(cfg) diff --git a/compiler/rustc_builtin_macros/src/concat.rs b/compiler/rustc_builtin_macros/src/concat.rs index e5077d93674a1..585140311aac6 100644 --- a/compiler/rustc_builtin_macros/src/concat.rs +++ b/compiler/rustc_builtin_macros/src/concat.rs @@ -53,7 +53,7 @@ pub fn expand_concat( } } if !missing_literal.is_empty() { - let mut err = cx.struct_span_err(missing_literal, "expected a literal"); + let mut err = cx.sess.struct_span_err(missing_literal, "expected a literal"); err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`"); err.emit(); return DummyResult::any(sp); diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 5d6f791f13719..ce1ebc2c63253 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -132,7 +132,7 @@ fn parse_args<'a>( let mut p = ecx.new_parser_from_tts(tts); if p.token == token::Eof { - return Err(ecx.struct_span_err(sp, "requires at least a format string argument")); + return Err(ecx.sess.struct_span_err(sp, "requires at least a format string argument")); } let first_token = &p.token; @@ -194,7 +194,8 @@ fn parse_args<'a>( p.expect(&token::Eq)?; let e = p.parse_expr()?; if let Some(prev) = names.get(&ident.name) { - ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", ident)) + ecx.sess + .struct_span_err(e.span, &format!("duplicate argument named `{}`", ident)) .span_label(args[*prev].span, "previously here") .span_label(e.span, "duplicate argument") .emit(); @@ -212,7 +213,7 @@ fn parse_args<'a>( _ => { let e = p.parse_expr()?; if named { - let mut err = ecx.struct_span_err( + let mut err = ecx.sess.struct_span_err( e.span, "positional arguments cannot follow named arguments", ); @@ -283,7 +284,7 @@ impl<'a, 'b> Context<'a, 'b> { _ => { let fmtsp = self.fmtsp; let sp = arg.format.ty_span.map(|sp| fmtsp.from_inner(sp)); - let mut err = self.ecx.struct_span_err( + let mut err = self.ecx.sess.struct_span_err( sp.unwrap_or(fmtsp), &format!("unknown format trait `{}`", arg.format.ty), ); @@ -371,7 +372,7 @@ impl<'a, 'b> Context<'a, 'b> { let count = self.pieces.len() + self.arg_with_formatting.iter().filter(|fmt| fmt.precision_span.is_some()).count(); if self.names.is_empty() && !numbered_position_args && count != self.args.len() { - e = self.ecx.struct_span_err( + e = self.ecx.sess.struct_span_err( sp, &format!( "{} positional argument{} in format string, but {}", @@ -403,7 +404,7 @@ impl<'a, 'b> Context<'a, 'b> { format!("arguments {head} and {tail}", head = refs.join(", "), tail = reg) }; - e = self.ecx.struct_span_err( + e = self.ecx.sess.struct_span_err( sp, &format!( "invalid reference to positional {} ({})", @@ -555,7 +556,7 @@ impl<'a, 'b> Context<'a, 'b> { } else { self.fmtsp }; - let mut err = self.ecx.struct_span_err(sp, &msg[..]); + let mut err = self.ecx.sess.struct_span_err(sp, &msg[..]); if capture_feature_enabled && !self.is_literal { err.note(&format!( @@ -987,7 +988,8 @@ pub fn expand_preparsed_format_args( if !parser.errors.is_empty() { let err = parser.errors.remove(0); let sp = fmt_span.from_inner(err.span); - let mut e = ecx.struct_span_err(sp, &format!("invalid format string: {}", err.description)); + let mut e = + ecx.sess.struct_span_err(sp, &format!("invalid format string: {}", err.description)); e.span_label(sp, err.label + " in format string"); if let Some(note) = err.note { e.note(¬e); @@ -1093,11 +1095,11 @@ pub fn expand_preparsed_format_args( let mut diag = { if let [(sp, msg)] = &errs[..] { - let mut diag = cx.ecx.struct_span_err(*sp, *msg); + let mut diag = cx.ecx.sess.struct_span_err(*sp, *msg); diag.span_label(*sp, *msg); diag } else { - let mut diag = cx.ecx.struct_span_err( + let mut diag = cx.ecx.sess.struct_span_err( errs.iter().map(|&(sp, _)| sp).collect::>(), "multiple unused formatting arguments", ); diff --git a/compiler/rustc_builtin_macros/src/global_asm.rs b/compiler/rustc_builtin_macros/src/global_asm.rs index 2465f33622e84..f28a685466018 100644 --- a/compiler/rustc_builtin_macros/src/global_asm.rs +++ b/compiler/rustc_builtin_macros/src/global_asm.rs @@ -50,7 +50,7 @@ fn parse_global_asm<'a>( let mut p = cx.new_parser_from_tts(tts); if p.token == token::Eof { - let mut err = cx.struct_span_err(sp, "macro requires a string literal as an argument"); + let mut err = cx.sess.struct_span_err(sp, "macro requires a string literal as an argument"); err.span_label(sp, "string literal required"); return Err(err); } diff --git a/compiler/rustc_builtin_macros/src/llvm_asm.rs b/compiler/rustc_builtin_macros/src/llvm_asm.rs index db73fdbe24ff5..868073c397063 100644 --- a/compiler/rustc_builtin_macros/src/llvm_asm.rs +++ b/compiler/rustc_builtin_macros/src/llvm_asm.rs @@ -121,8 +121,9 @@ fn parse_inline_asm<'a>( let mut p2 = cx.new_parser_from_tts(tts.trees().take(first_colon).collect()); if p2.token == token::Eof { - let mut err = - cx.struct_span_err(sp, "macro requires a string literal as an argument"); + let mut err = cx + .sess + .struct_span_err(sp, "macro requires a string literal as an argument"); err.span_label(sp, "string literal required"); return Err(err); } diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 8e56e80bba204..06283c00bd017 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -78,11 +78,12 @@ pub fn expand_test_or_bench( let item = match item { Annotatable::Item(i) => i, other => { - cx.struct_span_err( - other.span(), - "`#[test]` attribute is only allowed on non associated functions", - ) - .emit(); + cx.sess + .struct_span_err( + other.span(), + "`#[test]` attribute is only allowed on non associated functions", + ) + .emit(); return vec![other]; } }; diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 4c01cb8159a30..4fdec62f16562 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1028,10 +1028,6 @@ impl<'a> ExtCtxt<'a> { self.current_expansion.id.expansion_cause() } - pub fn struct_span_err>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> { - self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg) - } - /// Emit `msg` attached to `sp`, without immediately stopping /// compilation. /// @@ -1100,7 +1096,7 @@ impl<'a> ExtCtxt<'a> { FileName::Real(name) => name.into_local_path(), FileName::DocTest(path, _) => path, other => { - return Err(self.struct_span_err( + return Err(self.sess.struct_span_err( span, &format!("cannot resolve relative path in non-file source `{}`", other), )); @@ -1131,10 +1127,10 @@ pub fn expr_to_spanned_string<'a>( ast::ExprKind::Lit(ref l) => match l.kind { ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)), ast::LitKind::Err(_) => None, - _ => Some(cx.struct_span_err(l.span, err_msg)), + _ => Some(cx.sess.struct_span_err(l.span, err_msg)), }, ast::ExprKind::Err => None, - _ => Some(cx.struct_span_err(expr.span, err_msg)), + _ => Some(cx.sess.struct_span_err(expr.span, err_msg)), }) } diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 97608a389035b..458d29a250aae 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -318,8 +318,6 @@ impl<'a> StripUnconfigured<'a> { fn error_malformed_cfg_attr_missing(&self, span: Span) { self.sess - .parse_sess - .span_diagnostic .struct_span_err(span, "malformed `cfg_attr` attribute input") .span_suggestion( span, @@ -345,7 +343,7 @@ impl<'a> StripUnconfigured<'a> { } }; let error = |span, msg, suggestion: &str| { - let mut err = self.sess.parse_sess.span_diagnostic.struct_span_err(span, msg); + let mut err = self.sess.struct_span_err(span, msg); if !suggestion.is_empty() { err.span_suggestion( span, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 105f81c6e0f67..8bb23cb96991d 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -631,6 +631,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let expn_data = self.cx.current_expansion.id.expn_data(); let suggested_limit = self.cx.ecfg.recursion_limit * 2; self.cx + .sess .struct_span_err( expn_data.call_site, &format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()), @@ -1703,6 +1704,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { if e.kind() == ErrorKind::InvalidData { self.cx + .sess .struct_span_err( lit.span, &format!("{} wasn't a utf-8 file", filename.display()), @@ -1710,7 +1712,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { .span_label(lit.span, "contains invalid utf-8") .emit(); } else { - let mut err = self.cx.struct_span_err( + let mut err = self.cx.sess.struct_span_err( lit.span, &format!("couldn't read {}: {}", filename.display(), e), ); @@ -1723,6 +1725,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } else { let mut err = self .cx + .sess .struct_span_err(it.span(), "expected path to external documentation"); // Check if the user erroneously used `doc(include(...))` syntax. diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index f0e6fe39a3c7f..5efdc6b097866 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -323,7 +323,7 @@ fn generic_extension<'cx>( }, Error(err_sp, ref msg) => { let span = err_sp.substitute_dummy(sp); - cx.struct_span_err(span, &msg).emit(); + cx.sess.struct_span_err(span, &msg).emit(); return DummyResult::any(span); } ErrorReported => return DummyResult::any(sp), @@ -337,7 +337,7 @@ fn generic_extension<'cx>( let (token, label) = best_failure.expect("ran no matchers"); let span = token.span.substitute_dummy(sp); - let mut err = cx.struct_span_err(span, &parse_failure_msg(&token)); + let mut err = cx.sess.struct_span_err(span, &parse_failure_msg(&token)); err.span_label(span, label); if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) { err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro"); diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index b908a12c1fc9e..1c3bbfd5db146 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -173,7 +173,7 @@ pub(super) fn transcribe<'a>( seq @ mbe::TokenTree::Sequence(..) => { match lockstep_iter_size(&seq, interp, &repeats) { LockstepIterSize::Unconstrained => { - return Err(cx.struct_span_err( + return Err(cx.sess.struct_span_err( seq.span(), /* blame macro writer */ "attempted to repeat an expression containing no syntax variables \ matched as repeating at this depth", @@ -185,7 +185,7 @@ pub(super) fn transcribe<'a>( // happens when two meta-variables are used in the same repetition in a // sequence, but they come from different sequence matchers and repeat // different amounts. - return Err(cx.struct_span_err(seq.span(), &msg[..])); + return Err(cx.sess.struct_span_err(seq.span(), &msg[..])); } LockstepIterSize::Constraint(len, _) => { @@ -203,7 +203,7 @@ pub(super) fn transcribe<'a>( // FIXME: this really ought to be caught at macro definition // time... It happens when the Kleene operator in the matcher and // the body for the same meta-variable do not match. - return Err(cx.struct_span_err( + return Err(cx.sess.struct_span_err( sp.entire(), "this must repeat at least once", )); @@ -245,7 +245,7 @@ pub(super) fn transcribe<'a>( } } else { // We were unable to descend far enough. This is an error. - return Err(cx.struct_span_err( + return Err(cx.sess.struct_span_err( sp, /* blame the macro writer */ &format!("variable '{}' is still repeating at this depth", ident), )); diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 94b3fcf2850d2..00560c9234b23 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -25,7 +25,7 @@ impl base::ProcMacro for BangProcMacro { ) -> Result { let server = proc_macro_server::Rustc::new(ecx); self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace).map_err(|e| { - let mut err = ecx.struct_span_err(span, "proc macro panicked"); + let mut err = ecx.sess.struct_span_err(span, "proc macro panicked"); if let Some(s) = e.as_str() { err.help(&format!("message: {}", s)); } @@ -51,7 +51,7 @@ impl base::AttrProcMacro for AttrProcMacro { self.client .run(&EXEC_STRATEGY, server, annotation, annotated, ecx.ecfg.proc_macro_backtrace) .map_err(|e| { - let mut err = ecx.struct_span_err(span, "custom attribute panicked"); + let mut err = ecx.sess.struct_span_err(span, "custom attribute panicked"); if let Some(s) = e.as_str() { err.help(&format!("message: {}", s)); } @@ -117,7 +117,7 @@ impl MultiItemModifier for ProcMacroDerive { match self.client.run(&EXEC_STRATEGY, server, input, ecx.ecfg.proc_macro_backtrace) { Ok(stream) => stream, Err(e) => { - let mut err = ecx.struct_span_err(span, "proc-macro derive panicked"); + let mut err = ecx.sess.struct_span_err(span, "proc-macro derive panicked"); if let Some(s) = e.as_str() { err.help(&format!("message: {}", s)); } @@ -144,7 +144,7 @@ impl MultiItemModifier for ProcMacroDerive { // fail if there have been errors emitted if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before { - ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit(); + ecx.sess.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit(); } ExpandResult::Ready(items) @@ -161,7 +161,8 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec) // 1) First let's ensure that it's a meta item. let nmis = match attr.meta_item_list() { None => { - cx.struct_span_err(attr.span, "malformed `derive` attribute input") + cx.sess + .struct_span_err(attr.span, "malformed `derive` attribute input") .span_suggestion( attr.span, "missing traits to be derived", @@ -182,7 +183,8 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec) .filter_map(|nmi| match nmi { NestedMetaItem::Literal(lit) => { error_reported_filter_map = true; - cx.struct_span_err(lit.span, "expected path to a trait, found literal") + cx.sess + .struct_span_err(lit.span, "expected path to a trait, found literal") .help("for example, write `#[derive(Debug)]` for `Debug`") .emit(); None @@ -197,7 +199,8 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec) let mut traits_dont_accept = |title, action| { error_reported_map = true; let sp = mi.span.with_lo(mi.path.span.hi()); - cx.struct_span_err(sp, title) + cx.sess + .struct_span_err(sp, title) .span_suggestion( sp, action,