Change:
First compile is ok, after I modify some contents. It failed. I've to . Then works.
I don't know how to setup a minimal env to reproduce this. But I'd love to provide any info you needed.
cc Is this maybe related to ? (Although this sounds like the opposite of that, where it is missing the bit code.)
Some digging shows that this is a preexisting bug in rustc: I believe that this is only showing up now because Cargo is only just now passing
I've posted a fix for this at

Discussion:
} // Actual LTO type we end up choosing based on multiple factors. <del> enum ComputedLtoType { </del> <ins> pub enum ComputedLtoType { </ins> No, Thin, Fat, } <del> fn execute_optimize_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, module: ModuleCodegen<B::Module>, module_config: &ModuleConfig, ) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { B::optimize(cgcx, &diag_handler, &module, module_config)?; </del> <ins> pub fn compute_per_cgu_lto_type( sess_lto: &Lto, opts: &config::Options, sess_crate_types: &[CrateType], module_kind: ModuleKind, ) -> ComputedLtoType { // Metadata modules never participate in LTO regardless of the lto // settings. if module_kind == ModuleKind::Metadata { return ComputedLtoType::No; </ins> } <del> // After we've done the initial round of optimizations we need to // decide whether to synchronously codegen this module or ship it // back to the coordinator thread for further LTO processing (which // has to wait for all the initial modules to be optimized). </del> // If the linker does LTO, we don't have to do it. Note that we // keep doing full LTO, if it is requested, as not to break the // assumption that the output will be a single module. <del> let linker_does_lto = cgcx.opts.cg.linker_plugin_lto.enabled(); </del> <ins> let linker_does_lto = opts.cg.linker_plugin_lto.enabled(); </ins> // When we're automatically doing ThinLTO for multi-codegen-unit // builds we don't actually want to LTO the allocator modules if // it shows up. This is due to various linker shenanigans that // we'll encounter later. <del> let is_allocator = module.kind == ModuleKind::Allocator; </del> <ins> let is_allocator = module_kind == ModuleKind::Allocator; </ins> // We ignore a request for full crate grath LTO if the cate type // is only an rlib, as there is no full crate graph to process,

// require LTO so the request for LTO is always unconditionally // passed down to the backend, but we don't actually want to do // anything about it yet until we've got a final product. <del> let is_rlib = cgcx.crate_types.len() == 1 && cgcx.crate_types[0] == CrateType::Rlib; </del> <ins> let is_rlib = sess_crate_types.len() == 1 && sess_crate_types[0] == CrateType::Rlib; </ins> <del> // Metadata modules never participate in LTO regardless of the lto // settings. let lto_type = if module.kind == ModuleKind::Metadata { ComputedLtoType::No } else { match cgcx.lto { Lto::ThinLocal if !linker_does_lto && !is_allocator => ComputedLtoType::Thin, Lto::Thin if !linker_does_lto && !is_rlib => ComputedLtoType::Thin, Lto::Fat if !is_rlib => ComputedLtoType::Fat, _ => ComputedLtoType::No, } }; </del> <ins> match sess_lto { Lto::ThinLocal if !linker_does_lto && !is_allocator => ComputedLtoType::Thin, Lto::Thin if !linker_does_lto && !is_rlib => ComputedLtoType::Thin, Lto::Fat if !is_rlib => ComputedLtoType::Fat, _ => ComputedLtoType::No, } } fn execute_optimize_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, module: ModuleCodegen<B::Module>, module_config: &ModuleConfig, ) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { B::optimize(cgcx, &diag_handler, &module, module_config)?; } // After we've done the initial round of optimizations we need to // decide whether to synchronously codegen this module or ship it // back to the coordinator thread for further LTO processing (which // has to wait for all the initial modules to be optimized). let lto_type = compute_per_cgu_lto_type(&cgcx.lto, &cgcx.opts, &cgcx.crate_types, module.kind); </ins> // If we're doing some form of incremental LTO then we need to be sure to // save our module to disk first.

//!   int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`. use crate::back::write::{ <del> start_async_codegen, submit_codegened_module_to_llvm, submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, OngoingCodegen, </del> <ins> compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm, submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen, </ins> }; use crate::common::{IntPredicate, RealPredicate, TypeKind}; use crate::meth;

use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_session::cgu_reuse_tracker::CguReuse; <del> use rustc_session::config::{self, EntryFnType, Lto}; </del> <ins> use rustc_session::config::{self, EntryFnType}; </ins> use rustc_session::Session; use rustc_span::Span; use rustc_symbol_mangling::test as symbol_names_test;

); if tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some() { <del> // We can re-use either the pre- or the post-thinlto state if tcx.sess.lto() != Lto::No { CguReuse::PreLto } else { CguReuse::PostLto } </del> <ins> // We can re-use either the pre- or the post-thinlto state. If no LTO is // being performed then we can use post-LTO artifacts, otherwise we must // reuse pre-LTO artifacts match compute_per_cgu_lto_type( &tcx.sess.lto(), &tcx.sess.opts, &tcx.sess.crate_types.borrow(), ModuleKind::Regular, ) { ComputedLtoType::No => CguReuse::PostLto, _ => CguReuse::PreLto, } </ins> } else { CguReuse::No }

<ins> // revisions:cfail1 cfail2 // compile-flags: -Z query-dep-graph --crate-type rlib -C linker-plugin-lto -O // no-prefer-dynamic // build-pass #![feature(rustc_attrs)] #![rustc_partition_reused(module = "lto_in_linker", cfg = "cfail2")] pub fn foo() {} </ins>

<ins> // revisions:cfail1 cfail2 // compile-flags: -Z query-dep-graph --crate-type rlib -C lto // build-pass #![feature(rustc_attrs)] #![rustc_partition_reused(module = "rlib_lto", cfg = "cfail2")] pub fn foo() {} </ins>