diff options
| author | bors <bors@rust-lang.org> | 2022-08-27 00:38:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-27 00:38:06 +0000 |
| commit | bb8a08f011ce481adc62e45150b642d1f160bd78 (patch) | |
| tree | df99bf6d92dc38fcaf9136c447825c4eb244a881 /compiler/rustc_codegen_ssa/src | |
| parent | 2b443a8d97ff1f26c35e4bcf682bf9a89e8a66d2 (diff) | |
| parent | 96ceadde76e204a269252b1252b916278ecc4ea7 (diff) | |
| download | rust-bb8a08f011ce481adc62e45150b642d1f160bd78.tar.gz rust-bb8a08f011ce481adc62e45150b642d1f160bd78.zip | |
Auto merge of #101064 - compiler-errors:rollup-fwm5m5f, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #100724 (Migrate ast lowering to session diagnostic) - #100735 (Migrate `rustc_ty_utils` to `SessionDiagnostic`) - #100738 (Diagnostics migr const eval) - #100744 (Migrate rustc_mir_dataflow to diagnostic structs) - #100776 (Migrate `rustc_lint` errors to `SessionDiagnostic`) - #100817 (sugg: suggest the usage of boolean value when there is a typo in the keyword) - #100836 (Migrate `rustc_attr` crate diagnostics) - #100890 (Migrate rustc_driver to SessionDiagnostic) - #100900 (on `region_errors.rs`) Failed merges: - #100831 (Migrate `symbol_mangling` module to new diagnostics structs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/lib.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 1802eedf193..0faf51b062b 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -168,6 +168,13 @@ pub struct CodegenResults { pub crate_info: CrateInfo, } +pub enum CodegenErrors<'a> { + WrongFileType, + EmptyVersionNumber, + EncodingVersionMismatch { version_array: String, rlink_version: u32 }, + RustcVersionMismatch { rustc_version: String, current_version: &'a str }, +} + pub fn provide(providers: &mut Providers) { crate::back::symbol_export::provide(providers); crate::base::provide(providers); @@ -212,30 +219,34 @@ impl CodegenResults { encoder.finish() } - pub fn deserialize_rlink(data: Vec<u8>) -> Result<Self, String> { + pub fn deserialize_rlink<'a>(data: Vec<u8>) -> Result<Self, CodegenErrors<'a>> { // The Decodable machinery is not used here because it panics if the input data is invalid // and because its internal representation may change. if !data.starts_with(RLINK_MAGIC) { - return Err("The input does not look like a .rlink file".to_string()); + return Err(CodegenErrors::WrongFileType); } let data = &data[RLINK_MAGIC.len()..]; if data.len() < 4 { - return Err("The input does not contain version number".to_string()); + return Err(CodegenErrors::EmptyVersionNumber); } let mut version_array: [u8; 4] = Default::default(); version_array.copy_from_slice(&data[..4]); if u32::from_be_bytes(version_array) != RLINK_VERSION { - return Err(".rlink file was produced with encoding version {version_array}, but the current version is {RLINK_VERSION}".to_string()); + return Err(CodegenErrors::EncodingVersionMismatch { + version_array: String::from_utf8_lossy(&version_array).to_string(), + rlink_version: RLINK_VERSION, + }); } let mut decoder = MemDecoder::new(&data[4..], 0); let rustc_version = decoder.read_str(); let current_version = RUSTC_VERSION.unwrap(); if rustc_version != current_version { - return Err(format!( - ".rlink file was produced by rustc version {rustc_version}, but the current version is {current_version}." - )); + return Err(CodegenErrors::RustcVersionMismatch { + rustc_version: rustc_version.to_string(), + current_version, + }); } let codegen_results = CodegenResults::decode(&mut decoder); |
