Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 46112 fix to beta #46905

Merged
merged 3 commits into from
Dec 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,17 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
assert_eq!(cnum, LOCAL_CRATE);
let mut visible_parent_map: DefIdMap<DefId> = DefIdMap();

for &cnum in tcx.crates().iter() {
// Preferring shortest paths alone does not guarantee a
// deterministic result; so sort by crate num to avoid
// hashtable iteration non-determinism. This only makes
// things as deterministic as crate-nums assignment is,
// which is to say, its not deterministic in general. But
// we believe that libstd is consistently assigned crate
// num 1, so it should be enough to resolve #46112.
let mut crates: Vec<CrateNum> = (*tcx.crates()).clone();
crates.sort();

for &cnum in crates.iter() {
// Ignore crates without a corresponding local `extern crate` item.
if tcx.missing_extern_crate_item(cnum) {
continue
Expand Down
14 changes: 14 additions & 0 deletions src/test/compile-fail/auxiliary/issue_1920.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Just exporting some type to test for correct diagnostics when this
// crate is pulled in at a non-root location in client crate.

pub struct S;
8 changes: 5 additions & 3 deletions src/test/compile-fail/issue-1920-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

//! Test that absolute path names are correct when a crate is not linked into the root namespace

// aux-build:issue_1920.rs

mod foo {
pub extern crate core;
pub extern crate issue_1920;
}

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

fn main() {
assert_clone::<foo::core::sync::atomic::AtomicBool>();
//~^ ERROR `foo::core::sync::atomic::AtomicBool: foo::core::clone::Clone` is not satisfied
assert_clone::<foo::issue_1920::S>();
//~^ ERROR `foo::issue_1920::S: std::clone::Clone` is not satisfied
}
8 changes: 5 additions & 3 deletions src/test/compile-fail/issue-1920-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

//! Test that when a crate is linked under another name that name is used in global paths

extern crate core as bar;
// aux-build:issue_1920.rs

extern crate issue_1920 as bar;

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

fn main() {
assert_clone::<bar::sync::atomic::AtomicBool>();
//~^ ERROR `bar::sync::atomic::AtomicBool: bar::clone::Clone` is not satisfied
assert_clone::<bar::S>();
//~^ ERROR `bar::S: std::clone::Clone` is not satisfied
}
10 changes: 6 additions & 4 deletions src/test/compile-fail/issue-1920-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

//! Test that when a crate is linked multiple times that the shortest absolute path name is used

// aux-build:issue_1920.rs

mod foo {
pub extern crate core;
pub extern crate issue_1920;
}

extern crate core;
extern crate issue_1920;

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

fn main() {
assert_clone::<foo::core::sync::atomic::AtomicBool>();
//~^ ERROR `core::sync::atomic::AtomicBool: core::clone::Clone` is not satisfied
assert_clone::<foo::issue_1920::S>();
//~^ ERROR `issue_1920::S: std::clone::Clone` is not satisfied
}
13 changes: 13 additions & 0 deletions src/test/ui/auxiliary/xcrate_issue_46112_rexport_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_type="lib"]

pub extern crate core;
20 changes: 20 additions & 0 deletions src/test/ui/issue-46112.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Issue 46112: An extern crate pub reexporting libcore was causing
// paths rooted from `std` to be misrendered in the diagnostic output.

// ignore-windows
// aux-build:xcrate_issue_46112_rexport_core.rs

extern crate xcrate_issue_46112_rexport_core;
fn test(r: Result<Option<()>, &'static str>) { }
fn main() { test(Ok(())); }
//~^ mismatched types
14 changes: 14 additions & 0 deletions src/test/ui/issue-46112.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/issue-46112.rs:19:21
|
19 | fn main() { test(Ok(())); }
| ^^
| |
| expected enum `std::option::Option`, found ()
| help: try using a variant of the expected type: `Some(())`
|
= note: expected type `std::option::Option<()>`
found type `()`

error: aborting due to previous error