Skip to content

Commit 07e1b89

Browse files
authored
Unrolled build for rust-lang#116543
Rollup merge of rust-lang#116543 - ouz-a:crate_return_vec, r=oli-obk In smir `find_crates` returns `Vec<Crate>` instead of `Option<Crate>` Addresses rust-lang/project-stable-mir#40 r? `@oli-obk`
2 parents be581d9 + 4ff6e87 commit 07e1b89

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

Diff for: compiler/rustc_smir/src/rustc_smir/mod.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ impl<'tcx> Context for Tables<'tcx> {
3131
self.tcx.crates(()).iter().map(|crate_num| smir_crate(self.tcx, *crate_num)).collect()
3232
}
3333

34-
fn find_crate(&self, name: &str) -> Option<stable_mir::Crate> {
35-
[LOCAL_CRATE].iter().chain(self.tcx.crates(()).iter()).find_map(|crate_num| {
36-
let crate_name = self.tcx.crate_name(*crate_num).to_string();
37-
(name == crate_name).then(|| smir_crate(self.tcx, *crate_num))
38-
})
34+
fn find_crates(&self, name: &str) -> Vec<stable_mir::Crate> {
35+
let crates: Vec<stable_mir::Crate> = [LOCAL_CRATE]
36+
.iter()
37+
.chain(self.tcx.crates(()).iter())
38+
.map(|crate_num| {
39+
let crate_name = self.tcx.crate_name(*crate_num).to_string();
40+
(name == crate_name).then(|| smir_crate(self.tcx, *crate_num))
41+
})
42+
.into_iter()
43+
.filter_map(|c| c)
44+
.collect();
45+
crates
3946
}
4047

4148
fn name_of_def_id(&self, def_id: stable_mir::DefId) -> String {

Diff for: compiler/stable_mir/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ pub fn local_crate() -> Crate {
125125
with(|cx| cx.local_crate())
126126
}
127127

128-
/// Try to find a crate with the given name.
129-
pub fn find_crate(name: &str) -> Option<Crate> {
130-
with(|cx| cx.find_crate(name))
128+
/// Try to find a crate or crates if multiple crates exist from given name.
129+
pub fn find_crates(name: &str) -> Vec<Crate> {
130+
with(|cx| cx.find_crates(name))
131131
}
132132

133133
/// Try to find a crate with the given name.
@@ -174,7 +174,7 @@ pub trait Context {
174174
fn external_crates(&self) -> Vec<Crate>;
175175

176176
/// Find a crate with the given name.
177-
fn find_crate(&self, name: &str) -> Option<Crate>;
177+
fn find_crates(&self, name: &str) -> Vec<Crate>;
178178

179179
/// Prints the name of given `DefId`
180180
fn name_of_def_id(&self, def_id: DefId) -> String;

Diff for: tests/ui-fulldeps/stable-mir/crate-info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
3838
let items = stable_mir::all_local_items();
3939
assert!(get_item(&items, (DefKind::Fn, "foo::bar")).is_some());
4040

41-
// Find the `std` crate.
42-
assert!(stable_mir::find_crate("std").is_some());
41+
// Find the `std` crate and assert that there is only one of it.
42+
assert!(stable_mir::find_crates("std").len() == 1);
4343

4444
let bar = get_item(&items, (DefKind::Fn, "bar")).unwrap();
4545
let body = bar.body();

0 commit comments

Comments
 (0)