rust/compiler
Nicholas Nethercote b1b9278851 Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
..
rustc
rustc_abi Avoid specialization for the Span Encodable and Decodable impls 2023-12-31 20:42:17 +00:00
rustc_arena rustc_arena: add alloc_str 2023-12-05 17:52:51 -08:00
rustc_ast Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser 2024-01-06 09:56:00 +00:00
rustc_ast_lowering Remove hir::Guard 2024-01-05 10:56:59 +00:00
rustc_ast_passes Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_ast_pretty Auto merge of #119105 - dtolnay:paren, r=WaffleLapkin 2023-12-27 21:27:26 +00:00
rustc_attr Rename some Diagnostic setters. 2024-01-03 19:40:20 +11:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_builtin_macros Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_codegen_cranelift Merge commit '6d355f6844323db03bfd608899613e363e701951' into sync_cg_clif-2023-12-31 2023-12-31 13:29:53 +00:00
rustc_codegen_gcc Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors 2024-01-05 10:57:21 -05:00
rustc_codegen_llvm Auto merge of #119621 - compiler-errors:rollup-5mxtvuk, r=compiler-errors 2024-01-05 16:31:05 +00:00
rustc_codegen_ssa Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_const_eval Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_data_structures Rollup merge of #119591 - Enselic:DestinationPropagation-stable, r=cjgillot 2024-01-06 16:07:47 +01:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_error_codes Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-dead 2024-01-03 16:08:30 +01:00
rustc_error_messages Remove rustc_error_messages/messages.ftl. 2023-11-26 08:37:27 +11:00
rustc_errors Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_expand Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_feature Rollup merge of #119354 - fmease:negative_bounds-fixes, r=compiler-errors 2024-01-05 20:39:51 +01:00
rustc_fluent_macro Add a useful comment. 2023-11-26 08:38:02 +11:00
rustc_fs_util
rustc_graphviz remove unused pub fn 2023-11-23 14:11:02 +03:00
rustc_hir Remove hir::Guard 2024-01-05 10:56:59 +00:00
rustc_hir_analysis Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_hir_pretty Remove hir::Guard 2024-01-05 10:56:59 +00:00
rustc_hir_typeck Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_incremental Split StableCompare trait out of StableOrd trait. 2024-01-04 13:32:42 +01:00
rustc_index Auto merge of #119499 - cjgillot:dtm-opt, r=nnethercote 2024-01-06 11:54:15 +00:00
rustc_index_macros Put backticks around some attributes in doc comments. 2023-11-27 09:37:01 +11:00
rustc_infer Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_interface Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_lexer Rename some unescaping functions. 2023-12-13 14:17:50 +11:00
rustc_lint rustc_span: Optimize syntax context comparisons 2024-01-06 01:25:20 +03:00
rustc_lint_defs Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillot 2024-01-05 19:38:27 +00:00
rustc_llvm Rollup merge of #118941 - krasimirgg:llvm-cov, r=nikic 2023-12-18 17:03:11 +01:00
rustc_log
rustc_macros Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser 2024-01-06 09:56:00 +00:00
rustc_metadata Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser 2024-01-06 09:56:00 +00:00
rustc_middle Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_mir_build Don't populate yield and resume types after the fact 2024-01-06 18:03:01 +00:00
rustc_mir_dataflow Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_mir_transform Auto merge of #119675 - cjgillot:set-no-discriminant, r=tmiasko 2024-01-07 15:34:05 +00:00
rustc_monomorphize Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors 2024-01-05 10:57:21 -05:00
rustc_next_trait_solver Remove movability from TyKind::Coroutine 2023-12-28 16:35:01 +00:00
rustc_parse Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_parse_format Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstrieb 2023-11-15 14:55:35 +00:00
rustc_passes Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_pattern_analysis Reuse ctor_sub_tys when we have one around 2024-01-06 18:03:13 +01:00
rustc_privacy Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
rustc_query_impl Remove two unused feature gates from rustc_query_impl 2023-12-31 20:51:53 +00:00
rustc_query_system Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_resolve Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_serialize Avoid specialization for the Span Encodable and Decodable impls 2023-12-31 20:42:17 +00:00
rustc_session Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_smir Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_span Auto merge of #119662 - matthiaskrgr:rollup-ehofh5n, r=matthiaskrgr 2024-01-06 15:50:44 +00:00
rustc_symbol_mangling Rename some Diagnostic setters. 2024-01-03 19:40:20 +11:00
rustc_target compiler: update Fuchsia sanitizer support. 2024-01-06 10:06:15 +00:00
rustc_trait_selection Make DiagnosticBuilder::emit consuming. 2024-01-08 15:24:49 +11:00
rustc_traits add unused NormalizesTo predicate 2023-12-07 17:52:51 +01:00
rustc_transmute Update itertools to 0.11. 2023-11-22 08:13:21 +11:00
rustc_ty_utils Movability doesn't need to be a query anymore 2023-12-28 16:35:01 +00:00
rustc_type_ir Fix tidy error 2023-12-31 20:58:36 +00:00
stable_mir Restore movability to SMIR 2023-12-28 16:35:01 +00:00