Skip to content

Commit e878c67

Browse files
committed
Auto merge of #46905 - pnkfelix:backport-46112-fix-to-beta, r=michaelwoerister
Backport 46112 fix to beta Its probably easiest to focus on the diff rather than the commit series. If you prefer I could squash them, but I figured preserving the cherry-picking will make it easier to relate what has happened here to what happens on the `master` branch. Note: This is a backport of *just* #46838. It does not include #46708 (which we may end up wanting to revert). Fix #46112
2 parents a1e33e1 + 5f85764 commit e878c67

File tree

8 files changed

+88
-11
lines changed

8 files changed

+88
-11
lines changed

src/librustc_metadata/cstore_impl.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,17 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
297297
assert_eq!(cnum, LOCAL_CRATE);
298298
let mut visible_parent_map: DefIdMap<DefId> = DefIdMap();
299299

300-
for &cnum in tcx.crates().iter() {
300+
// Preferring shortest paths alone does not guarantee a
301+
// deterministic result; so sort by crate num to avoid
302+
// hashtable iteration non-determinism. This only makes
303+
// things as deterministic as crate-nums assignment is,
304+
// which is to say, its not deterministic in general. But
305+
// we believe that libstd is consistently assigned crate
306+
// num 1, so it should be enough to resolve #46112.
307+
let mut crates: Vec<CrateNum> = (*tcx.crates()).clone();
308+
crates.sort();
309+
310+
for &cnum in crates.iter() {
301311
// Ignore crates without a corresponding local `extern crate` item.
302312
if tcx.missing_extern_crate_item(cnum) {
303313
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-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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
#![crate_type="lib"]
12+
13+
pub extern crate core;

src/test/ui/issue-46112.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
// Issue 46112: An extern crate pub reexporting libcore was causing
12+
// paths rooted from `std` to be misrendered in the diagnostic output.
13+
14+
// ignore-windows
15+
// aux-build:xcrate_issue_46112_rexport_core.rs
16+
17+
extern crate xcrate_issue_46112_rexport_core;
18+
fn test(r: Result<Option<()>, &'static str>) { }
19+
fn main() { test(Ok(())); }
20+
//~^ mismatched types

src/test/ui/issue-46112.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-46112.rs:19:21
3+
|
4+
19 | fn main() { test(Ok(())); }
5+
| ^^
6+
| |
7+
| expected enum `std::option::Option`, found ()
8+
| help: try using a variant of the expected type: `Some(())`
9+
|
10+
= note: expected type `std::option::Option<()>`
11+
found type `()`
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)