Skip to content

Commit

Permalink
Rename consuming chaining methods on DiagnosticBuilder.
Browse files Browse the repository at this point in the history
In rust-lang#119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
  • Loading branch information
nnethercote committed Jan 9, 2024
1 parent 8a34317 commit e7b6d0e
Show file tree
Hide file tree
Showing 75 changed files with 298 additions and 296 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_mv($help)
.with_help($help)
.emit();
}
}};
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_attr/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ 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<_>>();
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)
.with_span(self.span)
.with_code(error_code!(E0541))
.with_arg("item", self.item)
.with_arg("expected", expected.join(", "))
.with_span_label(self.span, fluent::attr_label)
}
}

Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
"cannot use {} because it was mutably borrowed",
desc,
)
.span_label_mv(borrow_span, format!("{borrow_desc} is borrowed here"))
.span_label_mv(span, format!("use of borrowed {borrow_desc}"))
.with_span_label(borrow_span, format!("{borrow_desc} is borrowed here"))
.with_span_label(span, format!("use of borrowed {borrow_desc}"))
}

pub(crate) fn cannot_mutably_borrow_multiply(
Expand Down Expand Up @@ -243,8 +243,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
"cannot assign to {} because it is borrowed",
desc,
)
.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"))
.with_span_label(borrow_span, format!("{desc} is borrowed here"))
.with_span_label(span, format!("{desc} is assigned to here but it was already borrowed"))
}

pub(crate) fn cannot_reassign_immutable(
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
ty,
type_name,
)
.span_label_mv(move_from_span, "cannot move out of here")
.with_span_label(move_from_span, "cannot move out of here")
}

pub(crate) fn cannot_move_out_of_interior_of_drop(
Expand All @@ -312,7 +312,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
"cannot move out of type `{}`, which implements the `Drop` trait",
container_ty,
)
.span_label_mv(move_from_span, "cannot move out of here")
.with_span_label(move_from_span, "cannot move out of here")
}

pub(crate) fn cannot_act_on_moved_value(
Expand Down Expand Up @@ -368,8 +368,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_place,
immutable_section,
)
.span_label_mv(mutate_span, format!("cannot {action}"))
.span_label_mv(immutable_span, format!("value is immutable in {immutable_section}"))
.with_span_label(mutate_span, format!("cannot {action}"))
.with_span_label(immutable_span, format!("value is immutable in {immutable_section}"))
}

pub(crate) fn cannot_borrow_across_coroutine_yield(
Expand All @@ -384,7 +384,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
E0626,
"borrow may still be in use when {coroutine_kind:#} yields",
)
.span_label_mv(yield_span, "possible yield occurs here")
.with_span_label(yield_span, "possible yield occurs here")
}

pub(crate) fn cannot_borrow_across_destructor(
Expand Down Expand Up @@ -423,7 +423,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
REFERENCE = reference_desc,
LOCAL = path_desc,
)
.span_label_mv(
.with_span_label(
span,
format!("{return_kind}s a {reference_desc} data owned by the current function"),
)
Expand All @@ -444,8 +444,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
which is owned by the current {scope}",
)
.span_label_mv(capture_span, format!("{borrowed_path} is borrowed here"))
.span_label_mv(closure_span, format!("may outlive borrowed value {borrowed_path}"))
.with_span_label(capture_span, format!("{borrowed_path} is borrowed here"))
.with_span_label(closure_span, format!("may outlive borrowed value {borrowed_path}"))
}

pub(crate) fn thread_local_value_does_not_live_long_enough(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,11 +2225,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);

self.thread_local_value_does_not_live_long_enough(borrow_span)
.span_label_mv(
.with_span_label(
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")
.with_span_label(drop_span, "end of enclosing function is here")
}

#[instrument(level = "debug", skip(self))]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
span,
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
)
.note_mv(
.with_note(
"variables bound in patterns cannot be moved from \
until after the end of the pattern guard",
until after the end of the pattern guard",
);
} else if decl.is_ref_to_static() {
return self.report_cannot_move_from_static(move_place, span);
Expand Down Expand Up @@ -382,8 +382,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
);

self.cannot_move_out_of(span, &place_description)
.span_label_mv(upvar_span, "captured outer variable")
.span_label_mv(
.with_span_label(upvar_span, "captured outer variable")
.with_span_label(
self.infcx.tcx.def_span(def_id),
format!("captured by this `{closure_kind}` closure"),
)
Expand Down
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
Expand Up @@ -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_mv(spans, format!("{descr} used multiple times"))
.with_span_note(spans, format!("{descr} used multiple times"))
.emit());
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
let (sp, msg) = unused_operands.into_iter().next().unwrap();
ecx.dcx()
.struct_span_err(sp, msg)
.span_label_mv(sp, msg)
.help_mv(format!(
.with_span_label(sp, msg)
.with_help(format!(
"if this argument is intentionally unused, \
consider using it in an asm comment: `\"/*{help_str} */\"`"
))
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,9 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
level,
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
)
.span_mv(self.spans.clone())
.span_labels_mv(self.clobbers, &lbl1)
.span_labels_mv(self.spans, &lbl2)
.with_span(self.spans.clone())
.with_span_labels(self.clobbers, &lbl1)
.with_span_labels(self.spans, &lbl2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {

self.dcx
.struct_span_err(attr.span, msg)
.span_label_mv(prev_attr.span, "previous attribute here")
.with_span_label(prev_attr.span, "previous attribute here")
.emit();

return;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
),
);
}
err.span_label_mv(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
.span_suggestion_mv(attr_sp,
err.with_span_label(attr_sp, "the `#[test]` macro causes a function to be run as a test and has no effect on non-functions")
.with_span_suggestion(attr_sp,
"replace with conditional compilation to make the item only exist when tests are being run",
"#[cfg(test)]",
Applicability::MaybeIncorrect)
Expand Down Expand Up @@ -480,7 +480,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
"argument must be of the form: \
`expected = \"error message\"`",
)
.note_mv(
.with_note(
"errors in this attribute were erroneously \
allowed and will become a hard error in a \
future release",
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());

DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
.arg_mv("error", message)
.with_arg("error", message)
}
}

Expand Down Expand Up @@ -204,8 +204,8 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
};
self.0
.into_diagnostic(dcx, level)
.primary_message_mv(msg_with_llvm_err)
.arg_mv("llvm_err", self.1)
.with_primary_message(msg_with_llvm_err)
.with_arg("llvm_err", self.1)
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
attr.span,
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
)
.span_label_mv(tcx.def_span(did), "not an `unsafe` function")
.with_span_label(tcx.def_span(did), "not an `unsafe` function")
.emit();
} else {
check_target_feature_trait_unsafe(tcx, did, attr.span);
Expand Down Expand Up @@ -478,7 +478,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
InlineAttr::Never
} else {
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
.help_mv("valid inline arguments are `always` and `never`")
.with_help("valid inline arguments are `always` and `never`")
.emit();

InlineAttr::None
Expand Down Expand Up @@ -663,7 +663,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal);
tcx.dcx()
.struct_span_err(attr.span, msg)
.note_mv("the value may not exceed `u16::MAX`")
.with_note("the value may not exceed `u16::MAX`")
.emit();
None
}
Expand Down
53 changes: 26 additions & 27 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,25 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
thorin::Error::DecompressData(_) => build(fluent::codegen_ssa_thorin_decompress_data),
thorin::Error::NamelessSection(_, offset) => {
build(fluent::codegen_ssa_thorin_section_without_name)
.arg_mv("offset", format!("0x{offset:08x}"))
.with_arg("offset", format!("0x{offset:08x}"))
}
thorin::Error::RelocationWithInvalidSymbol(section, offset) => {
build(fluent::codegen_ssa_thorin_relocation_with_invalid_symbol)
.arg_mv("section", section)
.arg_mv("offset", format!("0x{offset:08x}"))
.with_arg("section", section)
.with_arg("offset", format!("0x{offset:08x}"))
}
thorin::Error::MultipleRelocations(section, offset) => {
build(fluent::codegen_ssa_thorin_multiple_relocations)
.arg_mv("section", section)
.arg_mv("offset", format!("0x{offset:08x}"))
.with_arg("section", section)
.with_arg("offset", format!("0x{offset:08x}"))
}
thorin::Error::UnsupportedRelocation(section, offset) => {
build(fluent::codegen_ssa_thorin_unsupported_relocation)
.arg_mv("section", section)
.arg_mv("offset", format!("0x{offset:08x}"))
.with_arg("section", section)
.with_arg("offset", format!("0x{offset:08x}"))
}
thorin::Error::MissingDwoName(id) => build(fluent::codegen_ssa_thorin_missing_dwo_name)
.arg_mv("id", format!("0x{id:08x}")),
.with_arg("id", format!("0x{id:08x}")),
thorin::Error::NoCompilationUnits => {
build(fluent::codegen_ssa_thorin_no_compilation_units)
}
Expand All @@ -258,7 +258,7 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
}
thorin::Error::MissingRequiredSection(section) => {
build(fluent::codegen_ssa_thorin_missing_required_section)
.arg_mv("section", section)
.with_arg("section", section)
}
thorin::Error::ParseUnitAbbreviations(_) => {
build(fluent::codegen_ssa_thorin_parse_unit_abbreviations)
Expand All @@ -272,31 +272,30 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
thorin::Error::ParseUnit(_) => build(fluent::codegen_ssa_thorin_parse_unit),
thorin::Error::IncompatibleIndexVersion(section, format, actual) => {
build(fluent::codegen_ssa_thorin_incompatible_index_version)
.arg_mv("section", section)
.arg_mv("actual", actual)
.arg_mv("format", format)
.with_arg("section", section)
.with_arg("actual", actual)
.with_arg("format", format)
}
thorin::Error::OffsetAtIndex(_, index) => {
build(fluent::codegen_ssa_thorin_offset_at_index).arg_mv("index", index)
build(fluent::codegen_ssa_thorin_offset_at_index).with_arg("index", index)
}
thorin::Error::StrAtOffset(_, offset) => {
build(fluent::codegen_ssa_thorin_str_at_offset)
.arg_mv("offset", format!("0x{offset:08x}"))
.with_arg("offset", format!("0x{offset:08x}"))
}
thorin::Error::ParseIndex(_, section) => {
build(fluent::codegen_ssa_thorin_parse_index).arg_mv("section", section)
build(fluent::codegen_ssa_thorin_parse_index).with_arg("section", section)
}
thorin::Error::UnitNotInIndex(unit) => {
build(fluent::codegen_ssa_thorin_unit_not_in_index)
.arg_mv("unit", format!("0x{unit:08x}"))
.with_arg("unit", format!("0x{unit:08x}"))
}
thorin::Error::RowNotInIndex(_, row) => {
build(fluent::codegen_ssa_thorin_row_not_in_index).arg_mv("row", row)
build(fluent::codegen_ssa_thorin_row_not_in_index).with_arg("row", row)
}
thorin::Error::SectionNotInRow => build(fluent::codegen_ssa_thorin_section_not_in_row),
thorin::Error::EmptyUnit(unit) => {
build(fluent::codegen_ssa_thorin_empty_unit).arg_mv("unit", format!("0x{unit:08x}"))
}
thorin::Error::EmptyUnit(unit) => build(fluent::codegen_ssa_thorin_empty_unit)
.with_arg("unit", format!("0x{unit:08x}")),
thorin::Error::MultipleDebugInfoSection => {
build(fluent::codegen_ssa_thorin_multiple_debug_info_section)
}
Expand All @@ -305,10 +304,10 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
}
thorin::Error::NotSplitUnit => build(fluent::codegen_ssa_thorin_not_split_unit),
thorin::Error::DuplicateUnit(unit) => build(fluent::codegen_ssa_thorin_duplicate_unit)
.arg_mv("unit", format!("0x{unit:08x}")),
.with_arg("unit", format!("0x{unit:08x}")),
thorin::Error::MissingReferencedUnit(unit) => {
build(fluent::codegen_ssa_thorin_missing_referenced_unit)
.arg_mv("unit", format!("0x{unit:08x}"))
.with_arg("unit", format!("0x{unit:08x}"))
}
thorin::Error::NoOutputObjectCreated => {
build(fluent::codegen_ssa_thorin_not_output_object_created)
Expand All @@ -317,19 +316,19 @@ impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
build(fluent::codegen_ssa_thorin_mixed_input_encodings)
}
thorin::Error::Io(e) => {
build(fluent::codegen_ssa_thorin_io).arg_mv("error", format!("{e}"))
build(fluent::codegen_ssa_thorin_io).with_arg("error", format!("{e}"))
}
thorin::Error::ObjectRead(e) => {
build(fluent::codegen_ssa_thorin_object_read).arg_mv("error", format!("{e}"))
build(fluent::codegen_ssa_thorin_object_read).with_arg("error", format!("{e}"))
}
thorin::Error::ObjectWrite(e) => {
build(fluent::codegen_ssa_thorin_object_write).arg_mv("error", format!("{e}"))
build(fluent::codegen_ssa_thorin_object_write).with_arg("error", format!("{e}"))
}
thorin::Error::GimliRead(e) => {
build(fluent::codegen_ssa_thorin_gimli_read).arg_mv("error", format!("{e}"))
build(fluent::codegen_ssa_thorin_gimli_read).with_arg("error", format!("{e}"))
}
thorin::Error::GimliWrite(e) => {
build(fluent::codegen_ssa_thorin_gimli_write).arg_mv("error", format!("{e}"))
build(fluent::codegen_ssa_thorin_gimli_write).with_arg("error", format!("{e}"))
}
_ => unimplemented!("Untranslated thorin error"),
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn from_target_feature(
let code = "enable = \"..\"";
tcx.dcx()
.struct_span_err(span, msg)
.span_suggestion_mv(span, "must be of the form", code, Applicability::HasPlaceholders)
.with_span_suggestion(span, "must be of the form", code, Applicability::HasPlaceholders)
.emit();
};
let rust_features = tcx.features();
Expand Down
Loading

0 comments on commit e7b6d0e

Please sign in to comment.