From 826362db17e5ae129f3dcb3639b0d45c8c2ee44b Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 19 Dec 2017 15:04:02 +0100 Subject: [PATCH 1/3] 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). ---- (This is cherry-pick of aa030dd3deb438c688c85c32eb75d009378c5f12 to beta.) --- src/librustc_metadata/cstore_impl.rs | 12 +++++++++++- src/test/compile-fail/auxiliary/issue_1920.rs | 14 ++++++++++++++ src/test/compile-fail/issue-17959.rs | 2 +- src/test/compile-fail/issue-1920-1.rs | 8 +++++--- src/test/compile-fail/issue-1920-2.rs | 8 +++++--- src/test/compile-fail/issue-1920-3.rs | 10 ++++++---- src/test/compile-fail/kindck-send-unsafe.rs | 2 +- src/test/ui/print_type_sizes/niche-filling.stdout | 4 ++-- 8 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 src/test/compile-fail/auxiliary/issue_1920.rs diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index b26ebfd6121b4..ccd8ed7c2a536 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -297,7 +297,17 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { assert_eq!(cnum, LOCAL_CRATE); let mut visible_parent_map: DefIdMap = 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 = (*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 diff --git a/src/test/compile-fail/auxiliary/issue_1920.rs b/src/test/compile-fail/auxiliary/issue_1920.rs new file mode 100644 index 0000000000000..55065174ca759 --- /dev/null +++ b/src/test/compile-fail/auxiliary/issue_1920.rs @@ -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 or the MIT license +// , 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; diff --git a/src/test/compile-fail/issue-17959.rs b/src/test/compile-fail/issue-17959.rs index 23be4d3536117..37c8173c4f66b 100644 --- a/src/test/compile-fail/issue-17959.rs +++ b/src/test/compile-fail/issue-17959.rs @@ -19,7 +19,7 @@ struct G { } impl Drop for G { -//~^ ERROR: The requirement `T: core::marker::Sized` is added only by the Drop impl. [E0367] +//~^ ERROR: The requirement `T: std::marker::Sized` is added only by the Drop impl. [E0367] fn drop(&mut self) { if !self._ptr.is_null() { } diff --git a/src/test/compile-fail/issue-1920-1.rs b/src/test/compile-fail/issue-1920-1.rs index f829d4645a089..97dd290a45bc8 100644 --- a/src/test/compile-fail/issue-1920-1.rs +++ b/src/test/compile-fail/issue-1920-1.rs @@ -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() where T : Clone { } fn main() { - assert_clone::(); - //~^ ERROR `foo::core::sync::atomic::AtomicBool: foo::core::clone::Clone` is not satisfied + assert_clone::(); + //~^ ERROR `foo::issue_1920::S: std::clone::Clone` is not satisfied } diff --git a/src/test/compile-fail/issue-1920-2.rs b/src/test/compile-fail/issue-1920-2.rs index 02c925f336eae..2af6e2cc991fa 100644 --- a/src/test/compile-fail/issue-1920-2.rs +++ b/src/test/compile-fail/issue-1920-2.rs @@ -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() where T : Clone { } fn main() { - assert_clone::(); - //~^ ERROR `bar::sync::atomic::AtomicBool: bar::clone::Clone` is not satisfied + assert_clone::(); + //~^ ERROR `bar::S: std::clone::Clone` is not satisfied } diff --git a/src/test/compile-fail/issue-1920-3.rs b/src/test/compile-fail/issue-1920-3.rs index 2f5da907b95f6..fa6efea845fce 100644 --- a/src/test/compile-fail/issue-1920-3.rs +++ b/src/test/compile-fail/issue-1920-3.rs @@ -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() where T : Clone { } fn main() { - assert_clone::(); - //~^ ERROR `core::sync::atomic::AtomicBool: core::clone::Clone` is not satisfied + assert_clone::(); + //~^ ERROR `issue_1920::S: std::clone::Clone` is not satisfied } diff --git a/src/test/compile-fail/kindck-send-unsafe.rs b/src/test/compile-fail/kindck-send-unsafe.rs index ecee2e0a4c63a..c717d1a72e05d 100644 --- a/src/test/compile-fail/kindck-send-unsafe.rs +++ b/src/test/compile-fail/kindck-send-unsafe.rs @@ -14,7 +14,7 @@ fn assert_send() { } fn test71<'a>() { assert_send::<*mut &'a isize>(); - //~^ ERROR `*mut &'a isize: core::marker::Send` is not satisfied + //~^ ERROR `*mut &'a isize: std::marker::Send` is not satisfied } fn main() { diff --git a/src/test/ui/print_type_sizes/niche-filling.stdout b/src/test/ui/print_type_sizes/niche-filling.stdout index af3e89a936ee0..0f53e7722dd51 100644 --- a/src/test/ui/print_type_sizes/niche-filling.stdout +++ b/src/test/ui/print_type_sizes/niche-filling.stdout @@ -69,11 +69,11 @@ print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes print-type-size variant `None`: 0 bytes print-type-size variant `Some`: 1 bytes print-type-size field `.0`: 1 bytes -print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes +print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes print-type-size variant `None`: 0 bytes print-type-size variant `Some`: 1 bytes print-type-size field `.0`: 1 bytes -print-type-size type: `core::cmp::Ordering`: 1 bytes, alignment: 1 bytes +print-type-size type: `std::cmp::Ordering`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Less`: 0 bytes print-type-size variant `Equal`: 0 bytes From 7db6372d8576e84715775d58c87e47dbd8cad492 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 12 Dec 2017 23:18:53 -0600 Subject: [PATCH 2/3] Regression test for issue #46112. --- .../xcrate_issue_46112_rexport_core.rs | 13 ++++++++++++ src/test/ui/issue-46112.rs | 20 +++++++++++++++++++ src/test/ui/issue-46112.stderr | 14 +++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/test/ui/auxiliary/xcrate_issue_46112_rexport_core.rs create mode 100644 src/test/ui/issue-46112.rs create mode 100644 src/test/ui/issue-46112.stderr diff --git a/src/test/ui/auxiliary/xcrate_issue_46112_rexport_core.rs b/src/test/ui/auxiliary/xcrate_issue_46112_rexport_core.rs new file mode 100644 index 0000000000000..80f877f834d8b --- /dev/null +++ b/src/test/ui/auxiliary/xcrate_issue_46112_rexport_core.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type="lib"] + +pub extern crate core; diff --git a/src/test/ui/issue-46112.rs b/src/test/ui/issue-46112.rs new file mode 100644 index 0000000000000..c292f73bf0b23 --- /dev/null +++ b/src/test/ui/issue-46112.rs @@ -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 or the MIT license +// , 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, &'static str>) { } +fn main() { test(Ok(())); } +//~^ mismatched types diff --git a/src/test/ui/issue-46112.stderr b/src/test/ui/issue-46112.stderr new file mode 100644 index 0000000000000..b9b87a941fd27 --- /dev/null +++ b/src/test/ui/issue-46112.stderr @@ -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 + From 5f85764788dba12d57a8955619be53634386228a Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 21 Dec 2017 11:38:12 +0100 Subject: [PATCH 3/3] reverted tests to cope with "regression" back to printing leading `core::` The reason we see `core::` even after visiting the `std` crate first is the special case code that looks like this: ```rust Entry::Occupied(mut entry) => { // If `child` is defined in crate `cnum`, ensure // that it is mapped to a parent in `cnum`. if child.krate == cnum && entry.get().krate != cnum { entry.insert(parent); } } ``` This causes items to be associated with the crates they were originally defined in, even if we had encountered them during the traversal of an earlier crate. (Having said that, I am not clear on why this same logic does not apply when both #46708 and #46838 have been applied. But at this point, I am just happy to have a plausible explanation for why we see `core::foo::bar` in the output for these tests, and want to focus on getting this fix for #46112 backported to beta.) --- src/test/compile-fail/issue-17959.rs | 2 +- src/test/compile-fail/kindck-send-unsafe.rs | 2 +- src/test/ui/print_type_sizes/niche-filling.stdout | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/compile-fail/issue-17959.rs b/src/test/compile-fail/issue-17959.rs index 37c8173c4f66b..23be4d3536117 100644 --- a/src/test/compile-fail/issue-17959.rs +++ b/src/test/compile-fail/issue-17959.rs @@ -19,7 +19,7 @@ struct G { } impl Drop for G { -//~^ ERROR: The requirement `T: std::marker::Sized` is added only by the Drop impl. [E0367] +//~^ ERROR: The requirement `T: core::marker::Sized` is added only by the Drop impl. [E0367] fn drop(&mut self) { if !self._ptr.is_null() { } diff --git a/src/test/compile-fail/kindck-send-unsafe.rs b/src/test/compile-fail/kindck-send-unsafe.rs index c717d1a72e05d..ecee2e0a4c63a 100644 --- a/src/test/compile-fail/kindck-send-unsafe.rs +++ b/src/test/compile-fail/kindck-send-unsafe.rs @@ -14,7 +14,7 @@ fn assert_send() { } fn test71<'a>() { assert_send::<*mut &'a isize>(); - //~^ ERROR `*mut &'a isize: std::marker::Send` is not satisfied + //~^ ERROR `*mut &'a isize: core::marker::Send` is not satisfied } fn main() { diff --git a/src/test/ui/print_type_sizes/niche-filling.stdout b/src/test/ui/print_type_sizes/niche-filling.stdout index 0f53e7722dd51..af3e89a936ee0 100644 --- a/src/test/ui/print_type_sizes/niche-filling.stdout +++ b/src/test/ui/print_type_sizes/niche-filling.stdout @@ -69,11 +69,11 @@ print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes print-type-size variant `None`: 0 bytes print-type-size variant `Some`: 1 bytes print-type-size field `.0`: 1 bytes -print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes +print-type-size type: `MyOption`: 1 bytes, alignment: 1 bytes print-type-size variant `None`: 0 bytes print-type-size variant `Some`: 1 bytes print-type-size field `.0`: 1 bytes -print-type-size type: `std::cmp::Ordering`: 1 bytes, alignment: 1 bytes +print-type-size type: `core::cmp::Ordering`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Less`: 0 bytes print-type-size variant `Equal`: 0 bytes