Skip to content

Consuming emit #119606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ macro_rules! gate {
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
feature_err(&$visitor.sess.parse_sess, sym::$feature, $span, $explain)
.help($help)
.help_mv($help)
.emit();
}
}};
13 changes: 6 additions & 7 deletions compiler/rustc_attr/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
@@ -54,13 +54,12 @@ pub(crate) struct UnknownMetaItem<'a> {
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item);
diag.span(self.span);
diag.code(error_code!(E0541));
diag.arg("item", self.item);
diag.arg("expected", expected.join(", "));
diag.span_label(self.span, fluent::attr_label);
diag
DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
.span_mv(self.span)
.code_mv(error_code!(E0541))
.arg_mv("item", self.item)
.arg_mv("expected", expected.join(", "))
.span_label_mv(self.span, fluent::attr_label)
}
}

70 changes: 29 additions & 41 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
@@ -31,17 +31,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span,
borrow_desc: &str,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
span,
E0503,
"cannot use {} because it was mutably borrowed",
desc,
);

err.span_label(borrow_span, format!("{borrow_desc} is borrowed here"));
err.span_label(span, format!("use of borrowed {borrow_desc}"));
err
)
.span_label_mv(borrow_span, format!("{borrow_desc} is borrowed here"))
.span_label_mv(span, format!("use of borrowed {borrow_desc}"))
}

pub(crate) fn cannot_mutably_borrow_multiply(
@@ -238,17 +236,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
borrow_span: Span,
desc: &str,
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
span,
E0506,
"cannot assign to {} because it is borrowed",
desc,
);

err.span_label(borrow_span, format!("{desc} is borrowed here"));
err.span_label(span, format!("{desc} is assigned to here but it was already borrowed"));
err
)
.span_label_mv(borrow_span, format!("{desc} is borrowed here"))
.span_label_mv(span, format!("{desc} is assigned to here but it was already borrowed"))
}

pub(crate) fn cannot_reassign_immutable(
@@ -287,32 +283,30 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
(&ty::Slice(_), _) => "slice",
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
};
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
move_from_span,
E0508,
"cannot move out of type `{}`, a non-copy {}",
ty,
type_name,
);
err.span_label(move_from_span, "cannot move out of here");
err
)
.span_label_mv(move_from_span, "cannot move out of here")
}

pub(crate) fn cannot_move_out_of_interior_of_drop(
&self,
move_from_span: Span,
container_ty: Ty<'_>,
) -> DiagnosticBuilder<'cx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
move_from_span,
E0509,
"cannot move out of type `{}`, which implements the `Drop` trait",
container_ty,
);
err.span_label(move_from_span, "cannot move out of here");
err
)
.span_label_mv(move_from_span, "cannot move out of here")
}

pub(crate) fn cannot_act_on_moved_value(
@@ -352,18 +346,17 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_section: &str,
action: &str,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
mutate_span,
E0510,
"cannot {} {} in {}",
action,
immutable_place,
immutable_section,
);
err.span_label(mutate_span, format!("cannot {action}"));
err.span_label(immutable_span, format!("value is immutable in {immutable_section}"));
err
)
.span_label_mv(mutate_span, format!("cannot {action}"))
.span_label_mv(immutable_span, format!("value is immutable in {immutable_section}"))
}

pub(crate) fn cannot_borrow_across_coroutine_yield(
@@ -372,14 +365,13 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
yield_span: Span,
) -> DiagnosticBuilder<'tcx> {
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
span,
E0626,
"borrow may still be in use when {coroutine_kind:#} yields",
);
err.span_label(yield_span, "possible yield occurs here");
err
)
.span_label_mv(yield_span, "possible yield occurs here")
}

pub(crate) fn cannot_borrow_across_destructor(
@@ -409,22 +401,19 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
reference_desc: &str,
path_desc: &str,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
span,
E0515,
"cannot {RETURN} {REFERENCE} {LOCAL}",
RETURN = return_kind,
REFERENCE = reference_desc,
LOCAL = path_desc,
);

err.span_label(
)
.span_label_mv(
span,
format!("{return_kind}s a {reference_desc} data owned by the current function"),
);

err
)
}

pub(crate) fn cannot_capture_in_long_lived_closure(
@@ -435,16 +424,15 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
capture_span: Span,
scope: &str,
) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_err!(
struct_span_err!(
self.dcx(),
closure_span,
E0373,
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
which is owned by the current {scope}",
);
err.span_label(capture_span, format!("{borrowed_path} is borrowed here"))
.span_label(closure_span, format!("may outlive borrowed value {borrowed_path}"));
err
)
.span_label_mv(capture_span, format!("{borrowed_path} is borrowed here"))
.span_label_mv(closure_span, format!("may outlive borrowed value {borrowed_path}"))
}

pub(crate) fn thread_local_value_does_not_live_long_enough(
15 changes: 6 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -2218,15 +2218,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span, borrow_span
);

let mut err = self.thread_local_value_does_not_live_long_enough(borrow_span);

err.span_label(
borrow_span,
"thread-local variables cannot be borrowed beyond the end of the function",
);
err.span_label(drop_span, "end of enclosing function is here");

err
self.thread_local_value_does_not_live_long_enough(borrow_span)
.span_label_mv(
borrow_span,
"thread-local variables cannot be borrowed beyond the end of the function",
)
.span_label_mv(drop_span, "end of enclosing function is here")
}

#[instrument(level = "debug", skip(self))]
31 changes: 14 additions & 17 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
@@ -329,15 +329,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let PlaceRef { local, projection: [] } = deref_base {
let decl = &self.body.local_decls[local];
if decl.is_ref_for_guard() {
let mut err = self.cannot_move_out_of(
span,
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
);
err.note(
"variables bound in patterns cannot be moved from \
return self
.cannot_move_out_of(
span,
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
)
.note_mv(
"variables bound in patterns cannot be moved from \
until after the end of the pattern guard",
);
return err;
);
} else if decl.is_ref_to_static() {
return self.report_cannot_move_from_static(move_place, span);
}
@@ -381,15 +381,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
closure_kind_ty, closure_kind, place_description,
);

let mut diag = self.cannot_move_out_of(span, &place_description);

diag.span_label(upvar_span, "captured outer variable");
diag.span_label(
self.infcx.tcx.def_span(def_id),
format!("captured by this `{closure_kind}` closure"),
);

diag
self.cannot_move_out_of(span, &place_description)
.span_label_mv(upvar_span, "captured outer variable")
.span_label_mv(
self.infcx.tcx.def_span(def_id),
format!("captured by this `{closure_kind}` closure"),
)
}
_ => {
let source = self.borrowed_content_source(deref_base);
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
@@ -348,7 +348,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
let named_key = self.regioncx.name_regions(self.infcx.tcx, key);
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
let mut diag = unexpected_hidden_region_diagnostic(
let diag = unexpected_hidden_region_diagnostic(
self.infcx.tcx,
span,
named_ty,
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -421,7 +421,7 @@ fn check_opaque_type_parameter_valid(
return Err(tcx
.dcx()
.struct_span_err(span, "non-defining opaque type use in defining scope")
.span_note(spans, format!("{descr} used multiple times"))
.span_note_mv(spans, format!("{descr} used multiple times"))
.emit());
}
}
21 changes: 11 additions & 10 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
@@ -458,7 +458,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
match expr_to_spanned_string(ecx, template_expr, msg) {
Ok(template_part) => template_part,
Err(err) => {
if let Some((mut err, _)) = err {
if let Some((err, _)) = err {
err.emit();
}
return None;
@@ -693,13 +693,14 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
0 => {}
1 => {
let (sp, msg) = unused_operands.into_iter().next().unwrap();
let mut err = ecx.dcx().struct_span_err(sp, msg);
err.span_label(sp, msg);
err.help(format!(
"if this argument is intentionally unused, \
consider using it in an asm comment: `\"/*{help_str} */\"`"
));
err.emit();
ecx.dcx()
.struct_span_err(sp, msg)
.span_label_mv(sp, msg)
.help_mv(format!(
"if this argument is intentionally unused, \
consider using it in an asm comment: `\"/*{help_str} */\"`"
))
.emit();
}
_ => {
let mut err = ecx.dcx().struct_span_err(
@@ -747,7 +748,7 @@ pub(super) fn expand_asm<'cx>(
};
MacEager::expr(expr)
}
Err(mut err) => {
Err(err) => {
err.emit();
DummyResult::any(sp)
}
@@ -779,7 +780,7 @@ pub(super) fn expand_global_asm<'cx>(
DummyResult::any(sp)
}
}
Err(mut err) => {
Err(err) => {
err.emit();
DummyResult::any(sp)
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ pub fn expand_assert<'cx>(
) -> Box<dyn MacResult + 'cx> {
let Assert { cond_expr, custom_message } = match parse_assert(cx, span, tts) {
Ok(assert) => assert,
Err(mut err) => {
Err(err) => {
err.emit();
return DummyResult::any(span);
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ pub fn expand_cfg(
);
MacEager::expr(cx.expr_bool(sp, matches_cfg))
}
Err(mut err) => {
Err(err) => {
err.emit();
DummyResult::any(sp)
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ impl CfgEval<'_, '_> {
parser.capture_cfg = true;
match parse_annotatable_with(&mut parser) {
Ok(a) => annotatable = a,
Err(mut err) => {
Err(err) => {
err.emit();
return Some(annotatable);
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cmdline_attrs.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
let start_span = parser.token.span;
let AttrItem { path, args, tokens: _ } = match parser.parse_attr_item(false) {
Ok(ai) => ai,
Err(mut err) => {
Err(err) => {
err.emit();
continue;
}
Loading