Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
8c92dc8
Expand `OptionFlatten`'s iterator methods
cuviper Feb 25, 2026
c0c2185
Stabilize LoongArch CRC intrinsics
heiher May 25, 2026
09d22ac
Correct some wrong uses of LLVM intrinsics
sayantn May 30, 2026
2dd54ff
Use `unadjusted` ABI everywhere
sayantn May 31, 2026
fe9d6fe
test that even ZST references prevent deallocation via child pointers
RalfJung Jun 3, 2026
a444517
Prepare for merging from rust-lang/rust
invalid-email-address Jun 8, 2026
e6bcef3
Merge ref '029c9e18dd1f' from rust-lang/rust
invalid-email-address Jun 8, 2026
1709e20
intrinsic-test: remove now-unnecessary feat attr
davidtwco Jun 9, 2026
ffdf5d0
Merge pull request #2156 from rust-lang/rustc-pull
davidtwco Jun 9, 2026
bc34a3f
Merge pull request #2144 from sayantn/llvm-intrinsics
adamgemmell Jun 10, 2026
9b80946
loongarch: Remove explicit zero-extension from CRC[C].W.{B,H}.W
heiher Jun 11, 2026
1d67d0d
Update rand to 0.9.3 to fix GHSA-cq8v-f236-94qc
ruyrocha Jun 4, 2026
72abf46
Merge pull request #2149 from ruyrocha/hotfix/bump-rand-version
davidtwco Jun 12, 2026
50897da
Merge pull request #2137 from heiher/stabilize-loong64-crc
folkertdev Jun 13, 2026
22fdc30
Merge pull request #2159 from heiher/crc
sayantn Jun 13, 2026
e5c59b3
libc: Minimal support for `mprotect` and `madvise`
foonathan May 25, 2026
3f5f981
arm-intrinsics: `svget{2,3,4}`
davidtwco Jun 1, 2026
992cb1d
arm-intrinsics: `svset{2,3,4}`
davidtwco Jun 1, 2026
35e9bf6
core_arch: redefine `svrev_b{16,32,64}`
davidtwco Jun 15, 2026
6346107
core_arch: redefine `sv{zip,uzp}_b{16,32,64}`
davidtwco Jun 15, 2026
ae20f10
intrinsic-test: fwd args in `intrinsic-test.sh`
davidtwco Jun 15, 2026
da637ab
Merge pull request #2162 from davidtwco/intrinsic-data-update-sve
adamgemmell Jun 16, 2026
cf43ffa
Merge pull request #2164 from davidtwco/intrinsic-test-fwd-args
adamgemmell Jun 16, 2026
89b4de5
Merge pull request #2163 from davidtwco/intrinsic-redefinition-svrev-…
adamgemmell Jun 16, 2026
e668e1b
move drop and dropck tests out of tests/ui/issues
danieljofficial Jun 8, 2026
2e4d8c9
add issue links and bless
danieljofficial Jun 8, 2026
6a53473
add minimal NetBSD support
joboet Jun 18, 2026
9f27f6d
[Priroda] Add structured locals output
moabo3li Jun 17, 2026
e418127
[Priroda] Add type strings to locals output
moabo3li Jun 19, 2026
37df0fc
Prepare for merging from rust-lang/rust
invalid-email-address Jun 19, 2026
9020baf
Merge ref '8e150217bafc' from rust-lang/rust
invalid-email-address Jun 19, 2026
ca7c1ad
Merge pull request #2168 from rust-lang/rustc-pull
davidtwco Jun 19, 2026
169a8e9
intrinsic-test: skip unimplemented SVE intrinsics
davidtwco Jun 1, 2026
937c582
intrinsic-test: skip SVE intrinsics on big endian
davidtwco Jun 11, 2026
922330e
intrinsic-test: do not test `svundef*`
davidtwco Jun 15, 2026
dabb59e
intrinsic-test: skip `sveorv*` (llvm-project#203921)
davidtwco Jun 15, 2026
6638cf5
intrinsic-test: skip `svld*_gather_*`
davidtwco Jun 15, 2026
dc2f964
intrinsic-test: no SVE testing under GCC
davidtwco Jun 15, 2026
e8ff32d
intrinsic-test: remove `concatln!`
davidtwco May 20, 2026
92ca3a5
intrinsic-test: remove unnecessary newlines
davidtwco Jun 9, 2026
c2c6cb4
Fix too-short variance slice in `variances_of` cycle recovery
xmakro Jun 20, 2026
77a83f2
Add stdarch-gen-common
xonx4l Jun 9, 2026
db43c44
Merge pull request #2157 from xonx4l/stdarch-gen-common
folkertdev Jun 20, 2026
80844b8
perf: drop the full-crate AST walk in check_unused
xmakro Jun 11, 2026
2d471ac
Merge pull request #2169 from davidtwco/intrinsic-test-sve-skips
sayantn Jun 20, 2026
397f748
Merge pull request #2171 from davidtwco/intrinsic-test-formatting-pri…
sayantn Jun 20, 2026
9558c38
intrinsic-test: shorten various type names
davidtwco Jun 2, 2026
a7e203a
intrinsic-test: intrinsic generic over arch not type
davidtwco Jun 2, 2026
2a346c5
intrinsic-test: arg generic over arch not type
davidtwco Jun 9, 2026
764a571
Merge pull request #2170 from davidtwco/intrinsic-test-generic-over-arch
davidtwco Jun 21, 2026
f4b49bc
intrinsic-test: simplify architecture constants
davidtwco Jun 11, 2026
0c9c049
Merge pull request #2172 from davidtwco/intrinsic-test-simplify-consts
davidtwco Jun 21, 2026
62ddde1
intrinsic-test: simplify type printing
davidtwco Jun 1, 2026
bae77b1
intrinsic-test: introduce `get_comparison_function`
davidtwco Jun 1, 2026
9686ccc
intrinsic-test: rename `get_*_function` fns
davidtwco Jun 4, 2026
a8fabf0
Merge pull request #2173 from davidtwco/intrinsic-test-type-printing-…
davidtwco Jun 21, 2026
cc45b69
Prepare for merging from rust-lang/rust
Jun 22, 2026
e1e5e25
Merge ref '942ac9ce4116' from rust-lang/rust
Jun 22, 2026
9969ff0
Merge pull request #5119 from moabo3li/restructured_locals
oli-obk Jun 22, 2026
4b7eb68
Merge pull request #5123 from rust-lang/rustup-2026-06-22
RalfJung Jun 22, 2026
b973eb9
Allow unstable attribute on foreign types and add stability test
kantnero Jun 22, 2026
8d2cf93
Update `cargo miri --help` to point to README.md.
eswartz Jun 18, 2026
aa5792a
reformat pointers to README
RalfJung Jun 23, 2026
88fa4bf
Merge pull request #5113 from eswartz/expose-readme-md-info
RalfJung Jun 23, 2026
90231c7
Merge pull request #5114 from joboet/min-netbsd
RalfJung Jun 23, 2026
0cf893e
dont ICE on generic no_mangle items
RalfJung Jun 24, 2026
dc5b1a9
test-cargo-miri: test all workspace members
RalfJung Jun 24, 2026
01a12a4
add ui test for no mangle generic
HerrCai0907 Mar 29, 2026
1545b13
Merge pull request #5129 from RalfJung/no-mangle-generic
RalfJung Jun 24, 2026
135a0f7
Merge pull request #5063 from foonathan/master
RalfJung Jun 24, 2026
eca4b5b
move nextest section up and mark it more clearly as such
RalfJung Jun 25, 2026
d6d568b
Merge pull request #5131 from RalfJung/nextest
RalfJung Jun 25, 2026
2337590
add some more errno_result
RalfJung Jun 25, 2026
d2c6980
rename read_split_slice → read_partial
RalfJung Jun 25, 2026
5445de0
remove dangling comment
RalfJung Jun 25, 2026
b0d28dc
Merge pull request #5132 from RalfJung/errno-result
RalfJung Jun 25, 2026
ab88669
replace cfg_if with cfg_select
hkBst Jun 25, 2026
37ffa9a
run some more tests natively
RalfJung Jun 25, 2026
528bd23
update lockfile
RalfJung Jun 25, 2026
dfb71b7
Merge pull request #5134 from hkBst/cfg-select
RalfJung Jun 25, 2026
4a2d36a
Prepare for merging from rust-lang/rust
Jun 26, 2026
9beed1d
Merge ref '40557f6225e3' from rust-lang/rust
Jun 26, 2026
fb9fa4e
Merge pull request #5136 from rust-lang/rustup-2026-06-26
RalfJung Jun 26, 2026
58f80da
Fix inconsistent safety requirement in VecDeque::nonoverlapping_ranges
yilin0518 Jun 26, 2026
3c00af9
Add supertrait item shadowing for type-level path resolution
Amanieu Feb 5, 2026
1efd5a6
Address review feedback
Amanieu Jun 3, 2026
e4ef1cf
Move supertrait shadowing tests to tests/ui/supertrait-shadowing
Amanieu Jun 3, 2026
af3eaee
Address review feedback for tests
Amanieu Jun 4, 2026
2592b41
Add test to confirm usage of unstable foreign type error
kantnero Jun 26, 2026
ca28237
move batch
zedddie Jun 27, 2026
f6ac864
bless batch
zedddie Jun 27, 2026
d69c87a
Upgrade `jsonsocck` and `jsondoclint` to edition 2024.
obi1kenobi Jun 27, 2026
f9a88c6
Prepare for merging from rust-lang/rust
Jun 27, 2026
b3c27e5
Merge ref '16761606d606' from rust-lang/rust
Jun 27, 2026
972dd17
Merge pull request #5139 from rust-lang/rustup-2026-06-27
oli-obk Jun 27, 2026
c3864be
rustdoc: show impl Trait<Box<Local>> for Foreign, etc on Local's docs
sunshowers Jun 27, 2026
5eb878a
move batch
zedddie Jun 27, 2026
2e08805
fix: keep readable readiness when socket read end is closed
WhySoBad Jun 13, 2026
80f8d1c
avoid Windows quirk, and make write test consistent with read test
RalfJung Jun 27, 2026
eb9bdc4
bless batch
zedddie Jun 27, 2026
f67abfb
Merge pull request #5106 from WhySoBad/network-sockets-stay-readable-…
RalfJung Jun 27, 2026
29643cf
Merge pull request #5088 from RalfJung/dealloc-protected
RalfJung Jun 27, 2026
290b370
Merge pull request #5133 from RalfJung/native
RalfJung Jun 27, 2026
9ab5135
Upgrade `rustdoc-json-types` to 2024 edition.
obi1kenobi Jun 27, 2026
aac0746
run x86 intrinsic tests natively
RalfJung Jun 27, 2026
a672666
run aarch64 intrinsic tests natively
RalfJung Jun 27, 2026
21dfe67
fix bug in `mpsadbw`
folkertdev Jun 27, 2026
18c10cd
Adds RmetaLinkCache a per-link cache that uses path as the key of dec…
mehdiakiki Jun 20, 2026
94888f0
update bless output
kantnero Jun 27, 2026
f734a15
Merge pull request #5140 from RalfJung/arch-intrinsic-native
RalfJung Jun 27, 2026
075f549
add `vqdmulh*` aarch64 intrinsics
folkertdev Jun 22, 2026
8e4a0e1
Merge pull request #5125 from folkertdev/vqdmulh
RalfJung Jun 27, 2026
3515461
use `"llvm.prefetch.p0"` instead of `"llvm.prefetch"`
folkertdev Jun 27, 2026
6bc6675
Rollup merge of #158497 - folkertdev:stdarch-sync-2026-06-27, r=folke…
jhpratt Jun 28, 2026
f477b56
Rollup merge of #152225 - Amanieu:type-supertrait-shadowing, r=jackh726
jhpratt Jun 28, 2026
de0afe7
Rollup merge of #158194 - mehdiakiki:rlib-link-meta-cache, r=petroche…
jhpratt Jun 28, 2026
a1fbf7b
Rollup merge of #158466 - sunshowers:nested-fundamental, r=notriddle
jhpratt Jun 28, 2026
a1968bf
Rollup merge of #158501 - RalfJung:miri, r=RalfJung
jhpratt Jun 28, 2026
899a154
Rollup merge of #153097 - cuviper:expand-into_flat_iter, r=joboet
jhpratt Jun 28, 2026
1feba18
Rollup merge of #157614 - danieljofficial:move-tests-drop, r=Kivooeo
jhpratt Jun 28, 2026
f117ef7
Rollup merge of #157996 - xmakro:perf/projcache-entry-probe, r=nnethe…
jhpratt Jun 28, 2026
c997ea4
Rollup merge of #158163 - xmakro:fix-variances-cycle-recovery-count, …
jhpratt Jun 28, 2026
dc0e276
Rollup merge of #158233 - kantnero:allow-unstable-attr-on-target, r=J…
jhpratt Jun 28, 2026
d78d87a
Rollup merge of #158433 - yilin0518:fix_nonoverlapping_ranges, r=jhpratt
jhpratt Jun 28, 2026
2e43e58
Rollup merge of #158464 - zedddie:gsoc-batch-15-meow, r=Kivooeo
jhpratt Jun 28, 2026
f1313c1
Rollup merge of #158470 - obi1kenobi:pg/upgrade-json-tool-editions, r…
jhpratt Jun 28, 2026
8981bcf
Rollup merge of #158485 - zedddie:gsoc-batch-16-meow, r=Teapot4195,Ki…
jhpratt Jun 28, 2026
2f26f3a
Rollup merge of #158488 - obi1kenobi:pg/upgrade-rustdoc-json-types-ed…
jhpratt Jun 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::Static),
Allow(Target::ForeignFn),
Allow(Target::ForeignStatic),
Allow(Target::ForeignTy),
Allow(Target::ExternCrate),
]);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
}

match intrinsic {
"llvm.prefetch" => {
"llvm.prefetch.p0" => {
// Nothing to do. This is merely a perf hint.
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
#[cfg(feature = "master")]
pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function<'gcc> {
let gcc_name = match name {
"llvm.prefetch" => {
"llvm.prefetch.p0" => {
let gcc_name = "__builtin_prefetch";
let func = cx.context.get_builtin_function(gcc_name);
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
let ptr = args[0].immediate();
let locality = fn_args.const_at(1).to_leaf().to_i32();
self.call_intrinsic(
"llvm.prefetch",
"llvm.prefetch.p0",
&[self.val_ty(ptr)],
&[
ptr,
Expand Down
26 changes: 18 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_target::spec::Arch;
use tracing::trace;

use super::metadata::{create_compressed_metadata_file, search_for_section};
use super::rmeta_link;
use super::rmeta_link::{self, RmetaLinkCache};
use super::symbol_edit::{apply_edits, collect_internal_names};
use crate::common;
// Public for ArchiveBuilderBuilder::extract_bundled_libs
Expand Down Expand Up @@ -311,7 +311,7 @@ fn find_binutils_dlltool(sess: &Session) -> OsString {
}

pub enum AddArchiveKind<'a> {
Rlib(/*skip*/ &'a dyn Fn(&str, ArchiveEntryKind) -> bool),
Rlib(&'a mut RmetaLinkCache, /*skip*/ &'a dyn Fn(&str, ArchiveEntryKind) -> bool),
Other,
}

Expand Down Expand Up @@ -466,7 +466,11 @@ pub fn try_extract_macho_fat_archive(
}

impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
fn add_archive(&mut self, archive_path: &Path, ar_kind: AddArchiveKind<'_>) -> io::Result<()> {
fn add_archive(
&mut self,
archive_path: &Path,
mut ar_kind: AddArchiveKind<'_>,
) -> io::Result<()> {
let mut archive_path = archive_path.to_path_buf();
if self.sess.target.llvm_target.contains("-apple-macosx")
&& let Some(new_archive_path) = try_extract_macho_fat_archive(self.sess, &archive_path)?
Expand All @@ -481,8 +485,14 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
let archive_map = unsafe { Mmap::map(File::open(&archive_path)?)? };
let archive = ArchiveFile::parse(&*archive_map)
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
let metadata_link = match ar_kind {
AddArchiveKind::Rlib(..) => rmeta_link::read(&archive, &archive_map, &archive_path),
let skip = match &ar_kind {
AddArchiveKind::Rlib(_, skip) => Some(*skip),
AddArchiveKind::Other => None,
};
let metadata_link = match &mut ar_kind {
AddArchiveKind::Rlib(cache, _) => cache.get_or_insert_with(&archive_path, || {
rmeta_link::read(&archive, &archive_map, &archive_path)
}),
AddArchiveKind::Other => None,
};
let archive_index = self.src_archives.len();
Expand Down Expand Up @@ -512,9 +522,9 @@ impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
} else {
ArchiveEntryKind::Other
};
let drop = match ar_kind {
AddArchiveKind::Rlib(skip) => skip(&file_name, kind),
AddArchiveKind::Other => false,
let drop = match skip {
Some(skip) => skip(&file_name, kind),
None => false,
};
if !drop {
let source = if entry.is_thin() {
Expand Down
16 changes: 14 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use super::archive::{
use super::command::Command;
use super::linker::{self, Linker};
use super::metadata::{MetadataPosition, create_wrapper_file};
use super::rmeta_link::RmetaLinkCache;
use super::rpath::{self, RPathConfig};
use super::{apple, rmeta_link, versioned_llvm_target};
use crate::base::needs_allocator_shim_for_linking;
Expand Down Expand Up @@ -86,6 +87,7 @@ pub fn link_binary(
let _timer = sess.timer("link_binary");
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
let mut tempfiles_for_stdout_output: Vec<PathBuf> = Vec::new();
let mut rmeta_link_cache = RmetaLinkCache::default();
for &crate_type in &crate_info.crate_types {
// Ignore executable crates if we have -Z no-codegen, as they will error.
if (sess.opts.unstable_opts.no_codegen || !sess.opts.output_types.should_codegen())
Expand Down Expand Up @@ -139,6 +141,7 @@ pub fn link_binary(
link_staticlib(
sess,
archive_builder_builder,
&mut rmeta_link_cache,
&compiled_modules,
&crate_info,
&metadata,
Expand All @@ -150,6 +153,7 @@ pub fn link_binary(
link_natively(
sess,
archive_builder_builder,
&mut rmeta_link_cache,
crate_type,
&out_filename,
&compiled_modules,
Expand Down Expand Up @@ -502,6 +506,7 @@ fn link_rlib<'a>(
fn link_staticlib(
sess: &Session,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
rmeta_link_cache: &mut RmetaLinkCache,
compiled_modules: &CompiledModules,
crate_info: &CrateInfo,
metadata: &EncodedMetadata,
Expand Down Expand Up @@ -531,7 +536,7 @@ fn link_staticlib(
let bundled_libs: FxIndexSet<_> = native_libs.filter_map(|lib| lib.filename).collect();
ab.add_archive(
path,
AddArchiveKind::Rlib(&|fname: &str, entry_kind| {
AddArchiveKind::Rlib(rmeta_link_cache, &|fname: &str, entry_kind| {
// Ignore metadata and rmeta-link files.
if fname == METADATA_FILENAME || fname == rmeta_link::FILENAME {
return true;
Expand Down Expand Up @@ -939,6 +944,7 @@ fn report_linker_output(
fn link_natively(
sess: &Session,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
rmeta_link_cache: &mut RmetaLinkCache,
crate_type: CrateType,
out_filename: &Path,
compiled_modules: &CompiledModules,
Expand All @@ -965,6 +971,7 @@ fn link_natively(
flavor,
sess,
archive_builder_builder,
rmeta_link_cache,
crate_type,
tmpdir,
temp_filename,
Expand Down Expand Up @@ -2562,6 +2569,7 @@ fn linker_with_args(
flavor: LinkerFlavor,
sess: &Session,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
rmeta_link_cache: &mut RmetaLinkCache,
crate_type: CrateType,
tmpdir: &Path,
out_filename: &Path,
Expand Down Expand Up @@ -2690,6 +2698,7 @@ fn linker_with_args(
cmd,
sess,
archive_builder_builder,
rmeta_link_cache,
crate_info,
crate_type,
tmpdir,
Expand Down Expand Up @@ -3126,6 +3135,7 @@ fn add_upstream_rust_crates(
cmd: &mut dyn Linker,
sess: &Session,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
rmeta_link_cache: &mut RmetaLinkCache,
crate_info: &CrateInfo,
crate_type: CrateType,
tmpdir: &Path,
Expand Down Expand Up @@ -3178,6 +3188,7 @@ fn add_upstream_rust_crates(
cmd,
sess,
archive_builder_builder,
rmeta_link_cache,
crate_info,
tmpdir,
cnum,
Expand Down Expand Up @@ -3309,6 +3320,7 @@ fn add_static_crate(
cmd: &mut dyn Linker,
sess: &Session,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
rmeta_link_cache: &mut RmetaLinkCache,
crate_info: &CrateInfo,
tmpdir: &Path,
cnum: CrateNum,
Expand Down Expand Up @@ -3339,7 +3351,7 @@ fn add_static_crate(
let mut archive = archive_builder_builder.new_archive_builder(sess);
if let Err(error) = archive.add_archive(
cratepath,
AddArchiveKind::Rlib(&|f, entry_kind| {
AddArchiveKind::Rlib(rmeta_link_cache, &|f, entry_kind| {
if f == METADATA_FILENAME || f == rmeta_link::FILENAME {
return true;
}
Expand Down
18 changes: 17 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/rmeta_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
//! and potentially other data collected and used when building or linking a rlib.
//! See <https://github.com/rust-lang/rust/issues/138243>.

use std::path::Path;
use std::path::{Path, PathBuf};

use object::read::archive::ArchiveFile;
use rustc_data_structures::fx::FxHashMap;
use rustc_serialize::opaque::mem_encoder::MemEncoder;
use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder};
use rustc_serialize::{Decodable, Encodable};
Expand Down Expand Up @@ -54,3 +55,18 @@ pub fn read_from_data(archive_data: &[u8], rlib_path: &Path) -> Option<RmetaLink
let archive = ArchiveFile::parse(archive_data).ok()?;
read(&archive, archive_data, rlib_path)
}

#[derive(Default)]
pub struct RmetaLinkCache {
cache: FxHashMap<PathBuf, Option<RmetaLink>>,
}

impl RmetaLinkCache {
pub fn get_or_insert_with(
&mut self,
rlib_path: &Path,
load: impl FnOnce() -> Option<RmetaLink>,
) -> Option<&RmetaLink> {
self.cache.entry(rlib_path.to_path_buf()).or_insert_with(load).as_ref()
}
}
6 changes: 2 additions & 4 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

pub(super) fn report_ambiguous_assoc_item(
&self,
bound1: ty::PolyTraitRef<'tcx>,
bound2: ty::PolyTraitRef<'tcx>,
matching_candidates: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
matching_candidates: &[ty::PolyTraitRef<'tcx>],
qself: AssocItemQSelf,
assoc_tag: ty::AssocTag,
assoc_ident: Ident,
Expand Down Expand Up @@ -443,7 +441,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// predicates!).
// FIXME: Turn this into a structured, translatable & more actionable suggestion.
let mut where_bounds = vec![];
for bound in [bound1, bound2].into_iter().chain(matching_candidates) {
for &bound in matching_candidates {
let bound_id = bound.def_id();
let assoc_item = tcx.associated_items(bound_id).find_by_ident_and_kind(
tcx,
Expand Down
80 changes: 77 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{assert_matches, slice};
use rustc_abi::FIRST_VARIANT;
use rustc_ast::LitKind;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::sso::SsoHashSet;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, StashKey,
Expand Down Expand Up @@ -1262,6 +1263,74 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
)
}

/// When there are multiple traits which contain an identically named
/// associated item, this function eliminates any traits which are a
/// supertrait of another candidate trait.
///
/// This is the type-level analogue of
/// `rustc_hir_typeck::method::probe::ProbeContext::collapse_candidates_to_subtrait_pick`;
/// keep both implementations in sync.
///
/// This implements RFC #3624.
fn collapse_candidates_to_subtrait_pick(
&self,
matching_candidates: &[ty::PolyTraitRef<'tcx>],
) -> Option<ty::PolyTraitRef<'tcx>> {
if !self.tcx().features().supertrait_item_shadowing() {
return None;
}

let mut child_trait = matching_candidates[0];
let mut supertraits: SsoHashSet<_> =
traits::supertrait_def_ids(self.tcx(), child_trait.def_id()).collect();

let mut remaining_candidates: Vec<_> = matching_candidates[1..].iter().copied().collect();
while !remaining_candidates.is_empty() {
let mut made_progress = false;
let mut next_round = vec![];

for remaining_trait in remaining_candidates {
if supertraits.contains(&remaining_trait.def_id()) {
made_progress = true;
continue;
}

// This candidate is not a supertrait of the `child_trait`.
// Check if it's a subtrait of the `child_trait`, instead.
// If it is, then it must have been a subtrait of every
// other pick we've eliminated at this point. It will
// take over at this point.
let remaining_trait_supertraits: SsoHashSet<_> =
traits::supertrait_def_ids(self.tcx(), remaining_trait.def_id()).collect();
if remaining_trait_supertraits.contains(&child_trait.def_id()) {
child_trait = remaining_trait;
supertraits = remaining_trait_supertraits;
made_progress = true;
continue;
}

// Neither `child_trait` or the current candidate are
// supertraits of each other.
// Don't bail here, since we may be comparing two supertraits
// of a common subtrait. These two supertraits won't be related
// at all, but we will pick them up next round when we find their
// child as we continue iterating in this round.
next_round.push(remaining_trait);
}

if made_progress {
// If we've made progress, iterate again.
remaining_candidates = next_round;
} else {
// Otherwise, we must have at least two candidates which
// are not related to each other at all.
return None;
}
}

Some(child_trait)
}

/// Search for a single trait bound whose trait defines the associated item given by
/// `assoc_ident`.
///
Expand Down Expand Up @@ -1296,10 +1365,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
};

if let Some(bound2) = matching_candidates.next() {
let all_matching_candidates: Vec<_> =
[bound1, bound2].into_iter().chain(matching_candidates).collect();
if let Some(bound) = self.collapse_candidates_to_subtrait_pick(&all_matching_candidates)
{
return Ok(bound);
}

return Err(self.report_ambiguous_assoc_item(
bound1,
bound2,
matching_candidates,
&all_matching_candidates,
qself,
assoc_tag,
assoc_ident,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
/// multiple conflicting picks if there is one pick whose trait container is a subtrait
/// of the trait containers of all of the other picks.
///
/// This is the method-probe analogue of
/// `rustc_hir_analysis::hir_ty_lowering::HirTyLowerer::collapse_candidates_to_subtrait_pick`;
/// keep both implementations in sync.
///
/// This implements RFC #3624.
fn collapse_candidates_to_subtrait_pick(
&self,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/handle_cycle_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(crate) fn variances_of<'tcx>(
err: Diag<'_>,
) -> &'tcx [ty::Variance] {
let _guar = err.delay_as_bug();
let n = tcx.generics_of(def_id).own_params.len();
let n = tcx.generics_of(def_id).count();
tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n))
}

Expand Down
Loading
Loading