rust/compiler
Nicholas Nethercote 1acbe7573d Use delayed error handling for Encodable and Encoder infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.

Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).

This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.

This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.

Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
  `into_inner` method is changed into `finish`, which returns
  `Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
  strategy. Its `Ok` type is a `usize`, returning the number of bytes
  written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
  passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-08 07:01:26 +10:00
..
rustc Auto merge of #96737 - ChrisDenton:win-manifest, r=wesleywiser 2022-06-02 07:58:29 +00:00
rustc_apfloat Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_ast_lowering Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_ast_passes Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_ast_pretty Revert #96682. 2022-06-02 11:22:16 +10:00
rustc_attr RFC3239: Implement compact cfg(target(..)) 2022-05-24 13:51:36 +02:00
rustc_borrowck Rollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank 2022-06-03 17:10:51 +02:00
rustc_builtin_macros Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_codegen_cranelift Auto merge of #97825 - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC 2022-06-07 11:08:58 +00:00
rustc_codegen_gcc Finish bumping stage0 2022-05-27 07:36:17 -04:00
rustc_codegen_llvm Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_codegen_ssa Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_const_eval Auto merge of #97795 - Dylan-DPC:rollup-dxilagr, r=Dylan-DPC 2022-06-06 16:09:54 +00:00
rustc_data_structures Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_driver Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_codes Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_messages migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
rustc_errors Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_expand Basic compiler infra 2022-06-02 09:00:04 -03:00
rustc_feature Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors 2022-06-06 14:34:55 +02:00
rustc_hir_pretty Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_incremental Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_index Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_infer Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_interface Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_lint_defs Use serde_json for json error messages 2022-06-03 16:46:19 +00:00
rustc_llvm Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_metadata Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_middle Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_mir_build Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
rustc_mir_dataflow Add a pointer to address cast kind 2022-05-31 00:00:00 +00:00
rustc_mir_transform Auto merge of #97697 - WaffleLapkin:no_ref_vec, r=WaffleLapkin 2022-06-05 09:30:53 +00:00
rustc_monomorphize Auto merge of #97168 - SparrowLii:accesses, r=cjgillot 2022-05-26 11:15:15 +00:00
rustc_parse Add spaces before and after expr in add {} suggestion 2022-06-06 01:40:52 +04:00
rustc_parse_format Make rustc_parse_format compile on stable 2022-05-03 11:26:58 +02:00
rustc_passes Rollup merge of #97301 - semicoleon:unstable-reexport, r=petrochenkov 2022-06-07 11:41:07 +02:00
rustc_plugin_impl Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_privacy Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_query_impl Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_query_system Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_resolve Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_save_analysis Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_serialize Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_session Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_span Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_symbol_mangling Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_target Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_trait_selection Rollup merge of #97721 - compiler-errors:issue-97704, r=jackh726 2022-06-06 08:37:01 +02:00
rustc_traits Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_ty_utils Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_type_ir Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
rustc_typeck Rollup merge of #97301 - semicoleon:unstable-reexport, r=petrochenkov 2022-06-07 11:41:07 +02:00