summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_builtin_macros/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
-rw-r--r--compiler/rustc_builtin_macros/src/alloc_error_handler.rs5
-rw-r--r--compiler/rustc_builtin_macros/src/asm.rs43
-rw-r--r--compiler/rustc_builtin_macros/src/assert/context.rs4
-rw-r--r--compiler/rustc_builtin_macros/src/cfg_accessible.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/cfg_eval.rs28
-rw-r--r--compiler/rustc_builtin_macros/src/cmdline_attrs.rs6
-rw-r--r--compiler/rustc_builtin_macros/src/concat_bytes.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/derive.rs6
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/clone.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/debug.rs4
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/default.rs17
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/mod.rs8
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/ty.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/env.rs14
-rw-r--r--compiler/rustc_builtin_macros/src/errors.rs19
-rw-r--r--compiler/rustc_builtin_macros/src/format.rs42
-rw-r--r--compiler/rustc_builtin_macros/src/format_foreign.rs24
-rw-r--r--compiler/rustc_builtin_macros/src/global_allocator.rs5
-rw-r--r--compiler/rustc_builtin_macros/src/lib.rs10
-rw-r--r--compiler/rustc_builtin_macros/src/proc_macro_harness.rs24
-rw-r--r--compiler/rustc_builtin_macros/src/source_util.rs8
-rw-r--r--compiler/rustc_builtin_macros/src/test.rs58
-rw-r--r--compiler/rustc_builtin_macros/src/test_harness.rs16
-rw-r--r--compiler/rustc_builtin_macros/src/util.rs2
25 files changed, 184 insertions, 169 deletions
diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs
index 070d50708..dffda8acc 100644
--- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs
+++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs
@@ -31,10 +31,7 @@ pub fn expand(
{
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
} else {
- ecx.sess
- .parse_sess
- .span_diagnostic
- .emit_err(errors::AllocErrorMustBeFn { span: item.span() });
+ ecx.sess.dcx().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
return vec![orig_item];
};
diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs
index 9e66eaf73..6f1acd8e5 100644
--- a/compiler/rustc_builtin_macros/src/asm.rs
+++ b/compiler/rustc_builtin_macros/src/asm.rs
@@ -47,10 +47,10 @@ pub fn parse_asm_args<'a>(
sp: Span,
is_global_asm: bool,
) -> PResult<'a, AsmArgs> {
- let diag = &sess.span_diagnostic;
+ let dcx = &sess.dcx;
if p.token == token::Eof {
- return Err(diag.create_err(errors::AsmRequiresTemplate { span: sp }));
+ return Err(dcx.create_err(errors::AsmRequiresTemplate { span: sp }));
}
let first_template = p.parse_expr()?;
@@ -69,7 +69,7 @@ pub fn parse_asm_args<'a>(
if !p.eat(&token::Comma) {
if allow_templates {
// After a template string, we always expect *only* a comma...
- return Err(diag.create_err(errors::AsmExpectedComma { span: p.token.span }));
+ return Err(dcx.create_err(errors::AsmExpectedComma { span: p.token.span }));
} else {
// ...after that delegate to `expect` to also include the other expected tokens.
return Err(p.expect(&token::Comma).err().unwrap());
@@ -110,7 +110,7 @@ pub fn parse_asm_args<'a>(
let op = if !is_global_asm && p.eat_keyword(kw::In) {
let reg = parse_reg(p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
- let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
+ let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
return Err(err);
}
let expr = p.parse_expr()?;
@@ -126,7 +126,7 @@ pub fn parse_asm_args<'a>(
} else if !is_global_asm && p.eat_keyword(sym::inout) {
let reg = parse_reg(p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
- let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
+ let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
return Err(err);
}
let expr = p.parse_expr()?;
@@ -140,7 +140,7 @@ pub fn parse_asm_args<'a>(
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
let reg = parse_reg(p, &mut explicit_reg)?;
if p.eat_keyword(kw::Underscore) {
- let err = diag.create_err(errors::AsmUnderscoreInput { span: p.token.span });
+ let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
return Err(err);
}
let expr = p.parse_expr()?;
@@ -157,7 +157,7 @@ pub fn parse_asm_args<'a>(
} else if p.eat_keyword(sym::sym) {
let expr = p.parse_expr()?;
let ast::ExprKind::Path(qself, path) = &expr.kind else {
- let err = diag.create_err(errors::AsmSymNoPath { span: expr.span });
+ let err = dcx.create_err(errors::AsmSymNoPath { span: expr.span });
return Err(err);
};
let sym = ast::InlineAsmSym {
@@ -178,7 +178,7 @@ pub fn parse_asm_args<'a>(
) => {}
ast::ExprKind::MacCall(..) => {}
_ => {
- let err = diag.create_err(errors::AsmExpectedOther {
+ let err = dcx.create_err(errors::AsmExpectedOther {
span: template.span,
is_global_asm,
});
@@ -201,12 +201,12 @@ pub fn parse_asm_args<'a>(
// of the argument available.
if explicit_reg {
if name.is_some() {
- diag.emit_err(errors::AsmExplicitRegisterName { span });
+ dcx.emit_err(errors::AsmExplicitRegisterName { span });
}
args.reg_args.insert(slot);
} else if let Some(name) = name {
if let Some(&prev) = args.named_args.get(&name) {
- diag.emit_err(errors::AsmDuplicateArg { span, name, prev: args.operands[prev].1 });
+ dcx.emit_err(errors::AsmDuplicateArg { span, name, prev: args.operands[prev].1 });
continue;
}
args.named_args.insert(name, slot);
@@ -215,7 +215,7 @@ pub fn parse_asm_args<'a>(
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
- diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
+ dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
}
}
}
@@ -224,19 +224,19 @@ pub fn parse_asm_args<'a>(
&& args.options.contains(ast::InlineAsmOptions::READONLY)
{
let spans = args.options_spans.clone();
- diag.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "nomem", opt2: "readonly" });
+ dcx.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "nomem", opt2: "readonly" });
}
if args.options.contains(ast::InlineAsmOptions::PURE)
&& args.options.contains(ast::InlineAsmOptions::NORETURN)
{
let spans = args.options_spans.clone();
- diag.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "pure", opt2: "noreturn" });
+ dcx.emit_err(errors::AsmMutuallyExclusive { spans, opt1: "pure", opt2: "noreturn" });
}
if args.options.contains(ast::InlineAsmOptions::PURE)
&& !args.options.intersects(ast::InlineAsmOptions::NOMEM | ast::InlineAsmOptions::READONLY)
{
let spans = args.options_spans.clone();
- diag.emit_err(errors::AsmPureCombine { spans });
+ dcx.emit_err(errors::AsmPureCombine { spans });
}
let mut have_real_output = false;
@@ -263,17 +263,17 @@ pub fn parse_asm_args<'a>(
}
}
if args.options.contains(ast::InlineAsmOptions::PURE) && !have_real_output {
- diag.emit_err(errors::AsmPureNoOutput { spans: args.options_spans.clone() });
+ dcx.emit_err(errors::AsmPureNoOutput { spans: args.options_spans.clone() });
}
if args.options.contains(ast::InlineAsmOptions::NORETURN) && !outputs_sp.is_empty() {
- let err = diag.create_err(errors::AsmNoReturn { outputs_sp });
+ let err = dcx.create_err(errors::AsmNoReturn { outputs_sp });
// Bail out now since this is likely to confuse MIR
return Err(err);
}
if args.clobber_abis.len() > 0 {
if is_global_asm {
- let err = diag.create_err(errors::GlobalAsmClobberAbi {
+ let err = dcx.create_err(errors::GlobalAsmClobberAbi {
spans: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
});
@@ -281,7 +281,7 @@ pub fn parse_asm_args<'a>(
return Err(err);
}
if !regclass_outputs.is_empty() {
- diag.emit_err(errors::AsmClobberNoReg {
+ dcx.emit_err(errors::AsmClobberNoReg {
spans: regclass_outputs,
clobbers: args.clobber_abis.iter().map(|(_, span)| *span).collect(),
});
@@ -298,7 +298,7 @@ pub fn parse_asm_args<'a>(
fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
// Tool-only output
let full_span = if p.token.kind == token::Comma { span.to(p.token.span) } else { span };
- p.sess.span_diagnostic.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
+ p.sess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
}
/// Try to set the provided option in the provided `AsmArgs`.
@@ -370,7 +370,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
p.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
if p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
- return Err(p.sess.span_diagnostic.create_err(errors::NonABI { span: p.token.span }));
+ return Err(p.sess.dcx.create_err(errors::NonABI { span: p.token.span }));
}
let mut new_abis = Vec::new();
@@ -381,8 +381,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
}
Err(opt_lit) => {
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
- let mut err =
- p.sess.span_diagnostic.struct_span_err(span, "expected string literal");
+ let mut err = p.sess.dcx.struct_span_err(span, "expected string literal");
err.span_label(span, "not a string literal");
return Err(err);
}
diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs
index 2a4bfe9e2..b54e11918 100644
--- a/compiler/rustc_builtin_macros/src/assert/context.rs
+++ b/compiler/rustc_builtin_macros/src/assert/context.rs
@@ -151,7 +151,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
fn build_panic(&self, expr_str: &str, panic_path: Path) -> P<Expr> {
let escaped_expr_str = escape_to_fmt(expr_str);
let initial = [
- TokenTree::token_alone(
+ TokenTree::token_joint_hidden(
token::Literal(token::Lit {
kind: token::LitKind::Str,
symbol: Symbol::intern(&if self.fmt_string.is_empty() {
@@ -170,7 +170,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
];
let captures = self.capture_decls.iter().flat_map(|cap| {
[
- TokenTree::token_alone(token::Ident(cap.ident.name, false), cap.ident.span),
+ TokenTree::token_joint_hidden(token::Ident(cap.ident.name, false), cap.ident.span),
TokenTree::token_alone(token::Comma, self.span),
]
});
diff --git a/compiler/rustc_builtin_macros/src/cfg_accessible.rs b/compiler/rustc_builtin_macros/src/cfg_accessible.rs
index 37ac09ccd..64be8da59 100644
--- a/compiler/rustc_builtin_macros/src/cfg_accessible.rs
+++ b/compiler/rustc_builtin_macros/src/cfg_accessible.rs
@@ -47,7 +47,7 @@ impl MultiItemModifier for Expander {
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
validate_attr::check_builtin_meta_item(
&ecx.sess.parse_sess,
- &meta_item,
+ meta_item,
ast::AttrStyle::Outer,
sym::cfg_accessible,
template,
diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs
index f826c6e77..ca26b7ed8 100644
--- a/compiler/rustc_builtin_macros/src/cfg_eval.rs
+++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs
@@ -25,7 +25,7 @@ pub(crate) fn expand(
annotatable: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(ecx, meta_item, sym::cfg_eval);
- warn_on_duplicate_attribute(&ecx, &annotatable, sym::cfg_eval);
+ warn_on_duplicate_attribute(ecx, &annotatable, sym::cfg_eval);
vec![cfg_eval(ecx.sess, ecx.ecfg.features, annotatable, ecx.current_expansion.lint_node_id)]
}
@@ -95,19 +95,19 @@ impl CfgFinder {
fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
let mut finder = CfgFinder { has_cfg_or_cfg_attr: false };
match annotatable {
- Annotatable::Item(item) => finder.visit_item(&item),
- Annotatable::TraitItem(item) => finder.visit_assoc_item(&item, visit::AssocCtxt::Trait),
- Annotatable::ImplItem(item) => finder.visit_assoc_item(&item, visit::AssocCtxt::Impl),
- Annotatable::ForeignItem(item) => finder.visit_foreign_item(&item),
- Annotatable::Stmt(stmt) => finder.visit_stmt(&stmt),
- Annotatable::Expr(expr) => finder.visit_expr(&expr),
- Annotatable::Arm(arm) => finder.visit_arm(&arm),
- Annotatable::ExprField(field) => finder.visit_expr_field(&field),
- Annotatable::PatField(field) => finder.visit_pat_field(&field),
- Annotatable::GenericParam(param) => finder.visit_generic_param(&param),
- Annotatable::Param(param) => finder.visit_param(&param),
- Annotatable::FieldDef(field) => finder.visit_field_def(&field),
- Annotatable::Variant(variant) => finder.visit_variant(&variant),
+ Annotatable::Item(item) => finder.visit_item(item),
+ Annotatable::TraitItem(item) => finder.visit_assoc_item(item, visit::AssocCtxt::Trait),
+ Annotatable::ImplItem(item) => finder.visit_assoc_item(item, visit::AssocCtxt::Impl),
+ Annotatable::ForeignItem(item) => finder.visit_foreign_item(item),
+ Annotatable::Stmt(stmt) => finder.visit_stmt(stmt),
+ Annotatable::Expr(expr) => finder.visit_expr(expr),
+ Annotatable::Arm(arm) => finder.visit_arm(arm),
+ Annotatable::ExprField(field) => finder.visit_expr_field(field),
+ Annotatable::PatField(field) => finder.visit_pat_field(field),
+ Annotatable::GenericParam(param) => finder.visit_generic_param(param),
+ Annotatable::Param(param) => finder.visit_param(param),
+ Annotatable::FieldDef(field) => finder.visit_field_def(field),
+ Annotatable::Variant(variant) => finder.visit_variant(variant),
Annotatable::Crate(krate) => finder.visit_crate(krate),
};
finder.has_cfg_or_cfg_attr
diff --git a/compiler/rustc_builtin_macros/src/cmdline_attrs.rs b/compiler/rustc_builtin_macros/src/cmdline_attrs.rs
index 7b75d7d84..2803ddefb 100644
--- a/compiler/rustc_builtin_macros/src/cmdline_attrs.rs
+++ b/compiler/rustc_builtin_macros/src/cmdline_attrs.rs
@@ -11,7 +11,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
for raw_attr in attrs {
let mut parser = rustc_parse::new_parser_from_source_str(
parse_sess,
- FileName::cli_crate_attr_source_code(&raw_attr),
+ FileName::cli_crate_attr_source_code(raw_attr),
raw_attr.clone(),
);
@@ -25,9 +25,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
};
let end_span = parser.token.span;
if parser.token != token::Eof {
- parse_sess
- .span_diagnostic
- .emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
+ parse_sess.dcx.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
continue;
}
diff --git a/compiler/rustc_builtin_macros/src/concat_bytes.rs b/compiler/rustc_builtin_macros/src/concat_bytes.rs
index c4f5af384..5499852e1 100644
--- a/compiler/rustc_builtin_macros/src/concat_bytes.rs
+++ b/compiler/rustc_builtin_macros/src/concat_bytes.rs
@@ -159,7 +159,7 @@ pub fn expand_concat_bytes(
accumulator.push(val);
}
Ok(ast::LitKind::ByteStr(ref bytes, _)) => {
- accumulator.extend_from_slice(&bytes);
+ accumulator.extend_from_slice(bytes);
}
_ => {
if !has_errors {
diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs
index 140853db6..5a77c3276 100644
--- a/compiler/rustc_builtin_macros/src/derive.rs
+++ b/compiler/rustc_builtin_macros/src/derive.rs
@@ -35,7 +35,7 @@ impl MultiItemModifier for Expander {
AttributeTemplate { list: Some("Trait1, Trait2, ..."), ..Default::default() };
validate_attr::check_builtin_meta_item(
&sess.parse_sess,
- &meta_item,
+ meta_item,
ast::AttrStyle::Outer,
sym::derive,
template,
@@ -48,14 +48,14 @@ impl MultiItemModifier for Expander {
NestedMetaItem::MetaItem(meta) => Some(meta),
NestedMetaItem::Lit(lit) => {
// Reject `#[derive("Debug")]`.
- report_unexpected_meta_item_lit(sess, &lit);
+ report_unexpected_meta_item_lit(sess, lit);
None
}
})
.map(|meta| {
// Reject `#[derive(Debug = "value", Debug(abc))]`, but recover the
// paths.
- report_path_args(sess, &meta);
+ report_path_args(sess, meta);
meta.path.clone()
})
.map(|path| (path, dummy_annotatable(), None, self.0))
diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs
index 1649cc76c..467fa5a2b 100644
--- a/compiler/rustc_builtin_macros/src/deriving/clone.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs
@@ -188,7 +188,7 @@ fn cs_clone(
}
let expr = match *vdata {
- VariantData::Struct(..) => {
+ VariantData::Struct { .. } => {
let fields = all_fields
.iter()
.map(|field| {
diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs
index f3164bd2c..7f5589210 100644
--- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs
@@ -136,7 +136,7 @@ fn cs_partial_cmp(
&& let Some(last) = arms.last_mut()
&& let PatKind::Wild = last.pat.kind
{
- last.body = expr2;
+ last.body = Some(expr2);
expr1
} else {
let eq_arm = cx.arm(
diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs
index 30c9b35bb..50ea86288 100644
--- a/compiler/rustc_builtin_macros/src/deriving/debug.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs
@@ -71,7 +71,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
(false, 0)
}
ast::VariantData::Tuple(..) => (false, 1),
- ast::VariantData::Struct(..) => (true, 2),
+ ast::VariantData::Struct { .. } => (true, 2),
};
// The number of fields that can be handled without an array.
@@ -226,7 +226,7 @@ fn show_fieldless_enum(
debug_assert!(fields.is_empty());
cx.pat_tuple_struct(span, variant_path, ThinVec::new())
}
- ast::VariantData::Struct(fields, _) => {
+ ast::VariantData::Struct { fields, .. } => {
debug_assert!(fields.is_empty());
cx.pat_struct(span, variant_path, ThinVec::new())
}
diff --git a/compiler/rustc_builtin_macros/src/deriving/default.rs b/compiler/rustc_builtin_macros/src/deriving/default.rs
index 07b172bc7..43874a242 100644
--- a/compiler/rustc_builtin_macros/src/deriving/default.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/default.rs
@@ -127,18 +127,17 @@ fn extract_default_variant<'a>(
[first, rest @ ..] => {
let suggs = default_variants
.iter()
- .map(|variant| {
- let spans = default_variants
+ .filter_map(|variant| {
+ let keep = attr::find_by_name(&variant.attrs, kw::Default)?.span;
+ let spans: Vec<Span> = default_variants
.iter()
- .filter_map(|v| {
- if v.span == variant.span {
- None
- } else {
- Some(attr::find_by_name(&v.attrs, kw::Default)?.span)
- }
+ .flat_map(|v| {
+ attr::filter_by_name(&v.attrs, kw::Default)
+ .filter_map(|attr| (attr.span != keep).then_some(attr.span))
})
.collect();
- errors::MultipleDefaultsSugg { spans, ident: variant.ident }
+ (!spans.is_empty())
+ .then_some(errors::MultipleDefaultsSugg { spans, ident: variant.ident })
})
.collect();
cx.emit_err(errors::MultipleDefaults {
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index aa1ce1b92..841cac781 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -467,7 +467,7 @@ impl<'a> TraitDef<'a> {
match item {
Annotatable::Item(item) => {
let is_packed = item.attrs.iter().any(|attr| {
- for r in attr::find_repr_attrs(&cx.sess, attr) {
+ for r in attr::find_repr_attrs(cx.sess, attr) {
if let attr::ReprPacked(_) = r {
return true;
}
@@ -478,7 +478,7 @@ impl<'a> TraitDef<'a> {
let newitem = match &item.kind {
ast::ItemKind::Struct(struct_def, generics) => self.expand_struct_def(
cx,
- &struct_def,
+ struct_def,
item.ident,
generics,
from_scratch,
@@ -496,7 +496,7 @@ impl<'a> TraitDef<'a> {
if self.supports_unions {
self.expand_struct_def(
cx,
- &struct_def,
+ struct_def,
item.ident,
generics,
from_scratch,
@@ -1485,7 +1485,7 @@ impl<'a> TraitDef<'a> {
let struct_path = struct_path.clone();
match *struct_def {
- VariantData::Struct(..) => {
+ VariantData::Struct { .. } => {
let field_pats = pieces_iter
.map(|(sp, ident, pat)| {
if ident.is_none() {
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
index 2d5043112..1a45c3279 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
@@ -182,7 +182,7 @@ impl Bounds {
let params = self
.bounds
.iter()
- .map(|&(name, ref bounds)| mk_ty_param(cx, span, name, &bounds, self_ty, self_generics))
+ .map(|&(name, ref bounds)| mk_ty_param(cx, span, name, bounds, self_ty, self_generics))
.collect();
Generics {
diff --git a/compiler/rustc_builtin_macros/src/env.rs b/compiler/rustc_builtin_macros/src/env.rs
index 8c2fa6ee9..d772642b8 100644
--- a/compiler/rustc_builtin_macros/src/env.rs
+++ b/compiler/rustc_builtin_macros/src/env.rs
@@ -13,6 +13,16 @@ use thin_vec::thin_vec;
use crate::errors;
+fn lookup_env<'cx>(cx: &'cx ExtCtxt<'_>, var: Symbol) -> Option<Symbol> {
+ let var = var.as_str();
+ if let Some(value) = cx.sess.opts.logical_env.get(var) {
+ return Some(Symbol::intern(value));
+ }
+ // If the environment variable was not defined with the `--env` option, we try to retrieve it
+ // from rustc's environment.
+ env::var(var).ok().as_deref().map(Symbol::intern)
+}
+
pub fn expand_option_env<'cx>(
cx: &'cx mut ExtCtxt<'_>,
sp: Span,
@@ -23,7 +33,7 @@ pub fn expand_option_env<'cx>(
};
let sp = cx.with_def_site_ctxt(sp);
- let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
+ let value = lookup_env(cx, var);
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
let e = match value {
None => {
@@ -77,7 +87,7 @@ pub fn expand_env<'cx>(
};
let span = cx.with_def_site_ctxt(sp);
- let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
+ let value = lookup_env(cx, var);
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
let e = match value {
None => {
diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs
index fde427033..6ffeb4014 100644
--- a/compiler/rustc_builtin_macros/src/errors.rs
+++ b/compiler/rustc_builtin_macros/src/errors.rs
@@ -1,5 +1,5 @@
use rustc_errors::{
- AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, Handler, IntoDiagnostic, MultiSpan,
+ AddToDiagnostic, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan,
SingleLabelManySpans,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
@@ -446,14 +446,14 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
}
// Hand-written implementation to support custom user messages.
-impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage {
+impl<'a> IntoDiagnostic<'a> for EnvNotDefinedWithUserMessage {
#[track_caller]
- fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
+ fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
#[expect(
rustc::untranslatable_diagnostic,
reason = "cannot translate user-provided messages"
)]
- let mut diag = handler.struct_diagnostic(self.msg_from_user.to_string());
+ let mut diag = dcx.struct_err(self.msg_from_user.to_string());
diag.set_span(self.span);
diag
}
@@ -801,18 +801,17 @@ pub(crate) struct AsmClobberNoReg {
pub(crate) clobbers: Vec<Span>,
}
-impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
- fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, G> {
- let mut diag =
- handler.struct_diagnostic(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
+impl<'a> IntoDiagnostic<'a> for AsmClobberNoReg {
+ fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
+ let mut diag = dcx.struct_err(crate::fluent_generated::builtin_macros_asm_clobber_no_reg);
diag.set_span(self.spans.clone());
// eager translation as `span_labels` takes `AsRef<str>`
- let lbl1 = handler.eagerly_translate_to_string(
+ let lbl1 = dcx.eagerly_translate_to_string(
crate::fluent_generated::builtin_macros_asm_clobber_abi,
[].into_iter(),
);
diag.span_labels(self.clobbers, &lbl1);
- let lbl2 = handler.eagerly_translate_to_string(
+ let lbl2 = dcx.eagerly_translate_to_string(
crate::fluent_generated::builtin_macros_asm_clobber_outputs,
[].into_iter(),
);
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs
index 214fed8e2..c5fd535b0 100644
--- a/compiler/rustc_builtin_macros/src/format.rs
+++ b/compiler/rustc_builtin_macros/src/format.rs
@@ -547,7 +547,7 @@ fn make_format_args(
span: arg_name.span.into(),
msg: format!("named argument `{}` is not used by name", arg_name.name).into(),
node_id: rustc_ast::CRATE_NODE_ID,
- lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
+ lint_id: LintId::of(NAMED_ARGUMENTS_USED_POSITIONALLY),
diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally {
position_sp_to_replace,
position_sp_for_msg,
@@ -617,16 +617,22 @@ fn report_missing_placeholders(
let placeholders = pieces
.iter()
.filter_map(|piece| {
- if let parse::Piece::NextArgument(argument) = piece && let ArgumentNamed(binding) = argument.position {
- let span = fmt_span.from_inner(InnerSpan::new(argument.position_span.start, argument.position_span.end));
+ if let parse::Piece::NextArgument(argument) = piece
+ && let ArgumentNamed(binding) = argument.position
+ {
+ let span = fmt_span.from_inner(InnerSpan::new(
+ argument.position_span.start,
+ argument.position_span.end,
+ ));
Some((span, binding))
- } else { None }
+ } else {
+ None
+ }
})
.collect::<Vec<_>>();
if !placeholders.is_empty() {
- if let Some(mut new_diag) =
- report_redundant_format_arguments(ecx, &args, used, placeholders)
+ if let Some(mut new_diag) = report_redundant_format_arguments(ecx, args, used, placeholders)
{
diag.cancel();
new_diag.emit();
@@ -666,30 +672,22 @@ fn report_missing_placeholders(
if explained.contains(&sub) {
continue;
}
- explained.insert(sub.clone());
+ explained.insert(sub);
if !found_foreign {
found_foreign = true;
show_doc_note = true;
}
- if let Some(inner_sp) = pos {
- let sp = fmt_span.from_inner(inner_sp);
+ let sp = fmt_span.from_inner(pos);
- if success {
- suggestions.push((sp, trn));
- } else {
- diag.span_note(
- sp,
- format!("format specifiers use curly braces, and {}", trn),
- );
- }
+ if success {
+ suggestions.push((sp, trn));
} else {
- if success {
- diag.help(format!("`{}` should be written as `{}`", sub, trn));
- } else {
- diag.note(format!("`{}` should use curly braces, and {}", sub, trn));
- }
+ diag.span_note(
+ sp,
+ format!("format specifiers use curly braces, and {}", trn),
+ );
}
}
diff --git a/compiler/rustc_builtin_macros/src/format_foreign.rs b/compiler/rustc_builtin_macros/src/format_foreign.rs
index 2fc8a0763..307e582d6 100644
--- a/compiler/rustc_builtin_macros/src/format_foreign.rs
+++ b/compiler/rustc_builtin_macros/src/format_foreign.rs
@@ -19,10 +19,10 @@ pub(crate) mod printf {
}
}
- pub fn position(&self) -> Option<InnerSpan> {
+ pub fn position(&self) -> InnerSpan {
match self {
- Substitution::Format(fmt) => Some(fmt.position),
- &Substitution::Escape((start, end)) => Some(InnerSpan::new(start, end)),
+ Substitution::Format(fmt) => fmt.position,
+ &Substitution::Escape((start, end)) => InnerSpan::new(start, end),
}
}
@@ -302,10 +302,9 @@ pub(crate) mod printf {
fn next(&mut self) -> Option<Self::Item> {
let (mut sub, tail) = parse_next_substitution(self.s)?;
self.s = tail;
- if let Some(InnerSpan { start, end }) = sub.position() {
- sub.set_position(start + self.pos, end + self.pos);
- self.pos += end;
- }
+ let InnerSpan { start, end } = sub.position();
+ sub.set_position(start + self.pos, end + self.pos);
+ self.pos += end;
Some(sub)
}
@@ -629,9 +628,9 @@ pub mod shell {
}
}
- pub fn position(&self) -> Option<InnerSpan> {
+ pub fn position(&self) -> InnerSpan {
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
- Some(InnerSpan::new(pos.0, pos.1))
+ InnerSpan::new(pos.0, pos.1)
}
pub fn set_position(&mut self, start: usize, end: usize) {
@@ -664,10 +663,9 @@ pub mod shell {
fn next(&mut self) -> Option<Self::Item> {
let (mut sub, tail) = parse_next_substitution(self.s)?;
self.s = tail;
- if let Some(InnerSpan { start, end }) = sub.position() {
- sub.set_position(start + self.pos, end + self.pos);
- self.pos += end;
- }
+ let InnerSpan { start, end } = sub.position();
+ sub.set_position(start + self.pos, end + self.pos);
+ self.pos += end;
Some(sub)
}
diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs
index 33392edf0..00c7907cd 100644
--- a/compiler/rustc_builtin_macros/src/global_allocator.rs
+++ b/compiler/rustc_builtin_macros/src/global_allocator.rs
@@ -34,10 +34,7 @@ pub fn expand(
{
(item, true, ecx.with_def_site_ctxt(ty.span))
} else {
- ecx.sess
- .parse_sess
- .span_diagnostic
- .emit_err(errors::AllocMustStatics { span: item.span() });
+ ecx.sess.dcx().emit_err(errors::AllocMustStatics { span: item.span() });
return vec![orig_item];
};
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index d84742c9b..f60b73fbe 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -1,9 +1,9 @@
//! This crate contains implementations of built-in macros and other code generating facilities
//! injecting code into the crate before it is lowered to HIR.
-#![cfg_attr(not(bootstrap), allow(internal_features))]
-#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
-#![cfg_attr(not(bootstrap), doc(rust_logo))]
+#![allow(internal_features)]
+#![feature(rustdoc_internals)]
+#![doc(rust_logo)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)]
#![feature(box_patterns)]
@@ -23,10 +23,8 @@ extern crate tracing;
use crate::deriving::*;
-use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
use rustc_expand::proc_macro::BangProcMacro;
-use rustc_fluent_macro::fluent_messages;
use rustc_span::symbol::sym;
mod alloc_error_handler;
@@ -59,7 +57,7 @@ pub mod proc_macro_harness;
pub mod standard_library_imports;
pub mod test_harness;
-fluent_messages! { "../messages.ftl" }
+rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs
index dae1bc5bf..4fddaa8ab 100644
--- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs
+++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs
@@ -38,7 +38,7 @@ enum ProcMacro {
struct CollectProcMacros<'a> {
macros: Vec<ProcMacro>,
in_root: bool,
- handler: &'a rustc_errors::Handler,
+ dcx: &'a rustc_errors::DiagCtxt,
source_map: &'a SourceMap,
is_proc_macro_crate: bool,
is_test_crate: bool,
@@ -52,7 +52,7 @@ pub fn inject(
is_proc_macro_crate: bool,
has_proc_macro_decls: bool,
is_test_crate: bool,
- handler: &rustc_errors::Handler,
+ dcx: &rustc_errors::DiagCtxt,
) {
let ecfg = ExpansionConfig::default("proc_macro".to_string(), features);
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
@@ -60,7 +60,7 @@ pub fn inject(
let mut collect = CollectProcMacros {
macros: Vec::new(),
in_root: true,
- handler,
+ dcx,
source_map: sess.source_map(),
is_proc_macro_crate,
is_test_crate,
@@ -86,13 +86,13 @@ pub fn inject(
impl<'a> CollectProcMacros<'a> {
fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
if self.is_proc_macro_crate && self.in_root && vis.kind.is_pub() {
- self.handler.emit_err(errors::ProcMacro { span: sp });
+ self.dcx.emit_err(errors::ProcMacro { span: sp });
}
}
fn collect_custom_derive(&mut self, item: &'a ast::Item, attr: &'a ast::Attribute) {
let Some((trait_name, proc_attrs)) =
- parse_macro_name_and_helper_attrs(self.handler, attr, "derive")
+ parse_macro_name_and_helper_attrs(self.dcx, attr, "derive")
else {
return;
};
@@ -112,7 +112,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_derive]` must be `pub`"
};
- self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
+ self.dcx.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
@@ -130,7 +130,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_attribute]` must be `pub`"
};
- self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
+ self.dcx.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
@@ -148,7 +148,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro]` must be `pub`"
};
- self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
+ self.dcx.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
}
@@ -157,7 +157,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
fn visit_item(&mut self, item: &'a ast::Item) {
if let ast::ItemKind::MacroDef(..) = item.kind {
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
- self.handler.emit_err(errors::ExportMacroRules {
+ self.dcx.emit_err(errors::ExportMacroRules {
span: self.source_map.guess_head_span(item.span),
});
}
@@ -192,7 +192,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
)
};
- self.handler
+ self.dcx
.struct_span_err(attr.span, msg)
.span_label(prev_attr.span, "previous attribute here")
.emit();
@@ -218,7 +218,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
pprust::path_to_string(&attr.get_normal_item().path),
);
- self.handler.span_err(attr.span, msg);
+ self.dcx.span_err(attr.span, msg);
return;
}
@@ -232,7 +232,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
pprust::path_to_string(&attr.get_normal_item().path),
);
- self.handler.span_err(attr.span, msg);
+ self.dcx.span_err(attr.span, msg);
return;
}
diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs
index f7bafa285..37808854a 100644
--- a/compiler/rustc_builtin_macros/src/source_util.rs
+++ b/compiler/rustc_builtin_macros/src/source_util.rs
@@ -5,11 +5,11 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirOwnership;
+use rustc_parse::new_parser_from_file;
use rustc_parse::parser::{ForceCollect, Parser};
-use rustc_parse::{self, new_parser_from_file};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::symbol::Symbol;
-use rustc_span::{self, Pos, Span};
+use rustc_span::{Pos, Span};
use smallvec::SmallVec;
use std::rc::Rc;
@@ -133,7 +133,7 @@ pub fn expand_include<'cx>(
let r = base::parse_expr(&mut self.p)?;
if self.p.token != token::Eof {
self.p.sess.buffer_lint(
- &INCOMPLETE_INCLUDE,
+ INCOMPLETE_INCLUDE,
self.p.token.span,
self.node_id,
"include macro expected single expression in source",
@@ -189,7 +189,7 @@ pub fn expand_include_str(
match cx.source_map().load_binary_file(&file) {
Ok(bytes) => match std::str::from_utf8(&bytes) {
Ok(src) => {
- let interned_src = Symbol::intern(&src);
+ let interned_src = Symbol::intern(src);
base::MacEager::expr(cx.expr_str(sp, interned_src))
}
Err(_) => {
diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
index 6d55603c7..ec843a3a0 100644
--- a/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
@@ -26,7 +26,7 @@ pub fn expand_test_case(
anno_item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
- warn_on_duplicate_attribute(&ecx, &anno_item, sym::test_case);
+ warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
if !ecx.ecfg.should_test {
return vec![];
@@ -79,7 +79,7 @@ pub fn expand_test(
item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(cx, meta_item, sym::test);
- warn_on_duplicate_attribute(&cx, &item, sym::test);
+ warn_on_duplicate_attribute(cx, &item, sym::test);
expand_test_or_bench(cx, attr_sp, item, false)
}
@@ -90,7 +90,7 @@ pub fn expand_bench(
item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(cx, meta_item, sym::bench);
- warn_on_duplicate_attribute(&cx, &item, sym::bench);
+ warn_on_duplicate_attribute(cx, &item, sym::bench);
expand_test_or_bench(cx, attr_sp, item, true)
}
@@ -134,9 +134,9 @@ pub fn expand_test_or_bench(
// will fail. We shouldn't try to expand in this case because the errors
// would be spurious.
let check_result = if is_bench {
- check_bench_signature(cx, &item, &fn_)
+ check_bench_signature(cx, &item, fn_)
} else {
- check_test_signature(cx, &item, &fn_)
+ check_test_signature(cx, &item, fn_)
};
if check_result.is_err() {
return if is_stmt {
@@ -389,16 +389,16 @@ pub fn expand_test_or_bench(
}
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
- let diag = &cx.sess.parse_sess.span_diagnostic;
+ let dcx = cx.sess.dcx();
let msg = "the `#[test]` attribute may only be used on a non-associated function";
let mut err = match item.map(|i| &i.kind) {
// These were a warning before #92959 and need to continue being that to avoid breaking
// stable user code (#94508).
- Some(ast::ItemKind::MacCall(_)) => diag.struct_span_warn(attr_sp, msg),
+ Some(ast::ItemKind::MacCall(_)) => dcx.struct_span_warn(attr_sp, msg),
// `.forget_guarantee()` needed to get these two arms to match types. Because of how
// locally close the `.emit()` call is I'm comfortable with it, but if it can be
// reworked in the future to not need it, it'd be nice.
- _ => diag.struct_span_err(attr_sp, msg).forget_guarantee(),
+ _ => dcx.struct_span_err(attr_sp, msg).forget_guarantee(),
};
if let Some(item) = item {
err.span_label(
@@ -466,7 +466,7 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match attr::find_by_name(&i.attrs, sym::should_panic) {
Some(attr) => {
- let sd = &cx.sess.parse_sess.span_diagnostic;
+ let dcx = cx.sess.dcx();
match attr.meta_item_list() {
// Handle #[should_panic(expected = "foo")]
@@ -477,7 +477,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
.and_then(|mi| mi.meta_item())
.and_then(|mi| mi.value_str());
if list.len() != 1 || msg.is_none() {
- sd.struct_span_warn(
+ dcx.struct_span_warn(
attr.span,
"argument must be of the form: \
`expected = \"error message\"`",
@@ -535,14 +535,36 @@ fn check_test_signature(
f: &ast::Fn,
) -> Result<(), ErrorGuaranteed> {
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
- let sd = &cx.sess.parse_sess.span_diagnostic;
+ let dcx = cx.sess.dcx();
if let ast::Unsafe::Yes(span) = f.sig.header.unsafety {
- return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
+ return Err(dcx.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
}
- if let ast::Async::Yes { span, .. } = f.sig.header.asyncness {
- return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "async" }));
+ if let Some(coroutine_kind) = f.sig.header.coroutine_kind {
+ match coroutine_kind {
+ ast::CoroutineKind::Async { span, .. } => {
+ return Err(dcx.emit_err(errors::TestBadFn {
+ span: i.span,
+ cause: span,
+ kind: "async",
+ }));
+ }
+ ast::CoroutineKind::Gen { span, .. } => {
+ return Err(dcx.emit_err(errors::TestBadFn {
+ span: i.span,
+ cause: span,
+ kind: "gen",
+ }));
+ }
+ ast::CoroutineKind::AsyncGen { span, .. } => {
+ return Err(dcx.emit_err(errors::TestBadFn {
+ span: i.span,
+ cause: span,
+ kind: "async gen",
+ }));
+ }
+ }
}
// If the termination trait is active, the compiler will check that the output
@@ -554,15 +576,15 @@ fn check_test_signature(
};
if !f.sig.decl.inputs.is_empty() {
- return Err(sd.span_err(i.span, "functions used as tests can not have any arguments"));
+ return Err(dcx.span_err(i.span, "functions used as tests can not have any arguments"));
}
if has_should_panic_attr && has_output {
- return Err(sd.span_err(i.span, "functions using `#[should_panic]` must return `()`"));
+ return Err(dcx.span_err(i.span, "functions using `#[should_panic]` must return `()`"));
}
if f.generics.params.iter().any(|param| !matches!(param.kind, GenericParamKind::Lifetime)) {
- return Err(sd.span_err(
+ return Err(dcx.span_err(
i.span,
"functions used as tests can not have any non-lifetime generic parameters",
));
@@ -579,7 +601,7 @@ fn check_bench_signature(
// N.B., inadequate check, but we're running
// well before resolve, can't get too deep.
if f.sig.decl.inputs.len() != 1 {
- return Err(cx.sess.parse_sess.span_diagnostic.emit_err(errors::BenchSig { span: i.span }));
+ return Err(cx.sess.dcx().emit_err(errors::BenchSig { span: i.span }));
}
Ok(())
}
diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs
index c7999a226..dc28cd2ea 100644
--- a/compiler/rustc_builtin_macros/src/test_harness.rs
+++ b/compiler/rustc_builtin_macros/src/test_harness.rs
@@ -2,7 +2,7 @@
use rustc_ast as ast;
use rustc_ast::entry::EntryPointType;
-use rustc_ast::mut_visit::{ExpectOne, *};
+use rustc_ast::mut_visit::*;
use rustc_ast::ptr::P;
use rustc_ast::visit::{walk_item, Visitor};
use rustc_ast::{attr, ModKind};
@@ -47,7 +47,7 @@ pub fn inject(
features: &Features,
resolver: &mut dyn ResolverExpand,
) {
- let span_diagnostic = sess.diagnostic();
+ let dcx = sess.dcx();
let panic_strategy = sess.panic_strategy();
let platform_panic_strategy = sess.target.panic_strategy;
@@ -60,7 +60,7 @@ pub fn inject(
// Do this here so that the test_runner crate attribute gets marked as used
// even in non-test builds
- let test_runner = get_test_runner(span_diagnostic, &krate);
+ let test_runner = get_test_runner(dcx, krate);
if sess.is_test_crate() {
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
@@ -70,7 +70,7 @@ pub fn inject(
// Silently allow compiling with panic=abort on these platforms,
// but with old behavior (abort if a test fails).
} else {
- span_diagnostic.emit_err(errors::TestsNotSupport {});
+ dcx.emit_err(errors::TestsNotSupport {});
}
PanicStrategy::Unwind
}
@@ -372,7 +372,7 @@ fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
let ecx = &cx.ext_cx;
let mut tests = cx.test_cases.clone();
- tests.sort_by(|a, b| a.name.as_str().cmp(&b.name.as_str()));
+ tests.sort_by(|a, b| a.name.as_str().cmp(b.name.as_str()));
ecx.expr_array_ref(
sp,
@@ -389,7 +389,7 @@ fn get_test_name(i: &ast::Item) -> Option<Symbol> {
attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
}
-fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast::Path> {
+fn get_test_runner(dcx: &rustc_errors::DiagCtxt, krate: &ast::Crate) -> Option<ast::Path> {
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
let meta_list = test_attr.meta_item_list()?;
let span = test_attr.span;
@@ -397,11 +397,11 @@ fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast
[single] => match single.meta_item() {
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
_ => {
- sd.emit_err(errors::TestRunnerInvalid { span });
+ dcx.emit_err(errors::TestRunnerInvalid { span });
}
},
_ => {
- sd.emit_err(errors::TestRunnerNargs { span });
+ dcx.emit_err(errors::TestRunnerNargs { span });
}
}
None
diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs
index 9463a1418..eeaf00004 100644
--- a/compiler/rustc_builtin_macros/src/util.rs
+++ b/compiler/rustc_builtin_macros/src/util.rs
@@ -10,7 +10,7 @@ pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, na
let template = AttributeTemplate { word: true, ..Default::default() };
validate_attr::check_builtin_meta_item(
&ecx.sess.parse_sess,
- &meta_item,
+ meta_item,
AttrStyle::Outer,
name,
template,