Skip to content

Commit 5165ee9

Browse files
committed
Auto merge of #46838 - pnkfelix:issue-46112-followup, r=estebank
Followup for #46112. Sorting by crate-num should ensure that we favor `std::foo::bar` over `any_other_crate::foo::bar`. Interestingly, *this* change had a much larger impact on our internal test suite than PR #46708 (which was my original fix to #46112).
2 parents 2c037d5 + aa030dd commit 5165ee9

File tree

8 files changed

+46
-15
lines changed

8 files changed

+46
-15
lines changed

src/librustc_metadata/cstore_impl.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,18 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
305305
// whatever crate we happened to encounter first in this
306306
// traversal, but not globally minimal across all crates.
307307
let bfs_queue = &mut VecDeque::new();
308-
for &cnum in tcx.crates().iter() {
308+
309+
// Preferring shortest paths alone does not guarantee a
310+
// deterministic result; so sort by crate num to avoid
311+
// hashtable iteration non-determinism. This only makes
312+
// things as deterministic as crate-nums assignment is,
313+
// which is to say, its not deterministic in general. But
314+
// we believe that libstd is consistently assigned crate
315+
// num 1, so it should be enough to resolve #46112.
316+
let mut crates: Vec<CrateNum> = (*tcx.crates()).clone();
317+
crates.sort();
318+
319+
for &cnum in crates.iter() {
309320
// Ignore crates without a corresponding local `extern crate` item.
310321
if tcx.missing_extern_crate_item(cnum) {
311322
continue
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Just exporting some type to test for correct diagnostics when this
12+
// crate is pulled in at a non-root location in client crate.
13+
14+
pub struct S;

src/test/compile-fail/issue-17959.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct G<T: ?Sized> {
1919
}
2020

2121
impl<T> Drop for G<T> {
22-
//~^ ERROR: The requirement `T: core::marker::Sized` is added only by the Drop impl. [E0367]
22+
//~^ ERROR: The requirement `T: std::marker::Sized` is added only by the Drop impl. [E0367]
2323
fn drop(&mut self) {
2424
if !self._ptr.is_null() {
2525
}

src/test/compile-fail/issue-1920-1.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
//! Test that absolute path names are correct when a crate is not linked into the root namespace
1212
13+
// aux-build:issue_1920.rs
14+
1315
mod foo {
14-
pub extern crate core;
16+
pub extern crate issue_1920;
1517
}
1618

1719
fn assert_clone<T>() where T : Clone { }
1820

1921
fn main() {
20-
assert_clone::<foo::core::sync::atomic::AtomicBool>();
21-
//~^ ERROR `foo::core::sync::atomic::AtomicBool: foo::core::clone::Clone` is not satisfied
22+
assert_clone::<foo::issue_1920::S>();
23+
//~^ ERROR `foo::issue_1920::S: std::clone::Clone` is not satisfied
2224
}

src/test/compile-fail/issue-1920-2.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111
//! Test that when a crate is linked under another name that name is used in global paths
1212
13-
extern crate core as bar;
13+
// aux-build:issue_1920.rs
14+
15+
extern crate issue_1920 as bar;
1416

1517
fn assert_clone<T>() where T : Clone { }
1618

1719
fn main() {
18-
assert_clone::<bar::sync::atomic::AtomicBool>();
19-
//~^ ERROR `bar::sync::atomic::AtomicBool: bar::clone::Clone` is not satisfied
20+
assert_clone::<bar::S>();
21+
//~^ ERROR `bar::S: std::clone::Clone` is not satisfied
2022
}

src/test/compile-fail/issue-1920-3.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
//! Test that when a crate is linked multiple times that the shortest absolute path name is used
1212
13+
// aux-build:issue_1920.rs
14+
1315
mod foo {
14-
pub extern crate core;
16+
pub extern crate issue_1920;
1517
}
1618

17-
extern crate core;
19+
extern crate issue_1920;
1820

1921
fn assert_clone<T>() where T : Clone { }
2022

2123
fn main() {
22-
assert_clone::<foo::core::sync::atomic::AtomicBool>();
23-
//~^ ERROR `core::sync::atomic::AtomicBool: core::clone::Clone` is not satisfied
24+
assert_clone::<foo::issue_1920::S>();
25+
//~^ ERROR `issue_1920::S: std::clone::Clone` is not satisfied
2426
}

src/test/compile-fail/kindck-send-unsafe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn assert_send<T:Send>() { }
1414

1515
fn test71<'a>() {
1616
assert_send::<*mut &'a isize>();
17-
//~^ ERROR `*mut &'a isize: core::marker::Send` is not satisfied
17+
//~^ ERROR `*mut &'a isize: std::marker::Send` is not satisfied
1818
}
1919

2020
fn main() {

src/test/ui/print_type_sizes/niche-filling.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ print-type-size type: `MyOption<bool>`: 1 bytes, alignment: 1 bytes
6969
print-type-size variant `None`: 0 bytes
7070
print-type-size variant `Some`: 1 bytes
7171
print-type-size field `.0`: 1 bytes
72-
print-type-size type: `MyOption<core::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
72+
print-type-size type: `MyOption<std::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
7373
print-type-size variant `None`: 0 bytes
7474
print-type-size variant `Some`: 1 bytes
7575
print-type-size field `.0`: 1 bytes
76-
print-type-size type: `core::cmp::Ordering`: 1 bytes, alignment: 1 bytes
76+
print-type-size type: `std::cmp::Ordering`: 1 bytes, alignment: 1 bytes
7777
print-type-size discriminant: 1 bytes
7878
print-type-size variant `Less`: 0 bytes
7979
print-type-size variant `Equal`: 0 bytes

0 commit comments

Comments
 (0)