]> git.lizzy.rs Git - rust.git/commitdiff
Followup for #46112.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 19 Dec 2017 14:04:02 +0000 (15:04 +0100)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 19 Dec 2017 14:04:02 +0000 (15:04 +0100)
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).

src/librustc_metadata/cstore_impl.rs
src/test/compile-fail/auxiliary/issue_1920.rs [new file with mode: 0644]
src/test/compile-fail/issue-17959.rs
src/test/compile-fail/issue-1920-1.rs
src/test/compile-fail/issue-1920-2.rs
src/test/compile-fail/issue-1920-3.rs
src/test/compile-fail/kindck-send-unsafe.rs
src/test/ui/print_type_sizes/niche-filling.stdout

index 90580de07be566d18ed0857a8ebe5b804b49c91b..955648208cd8b773c68c6f250642ce370aec29fa 100644 (file)
@@ -305,7 +305,18 @@ fn is_const_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
             // whatever crate we happened to encounter first in this
             // traversal, but not globally minimal across all crates.
             let bfs_queue = &mut VecDeque::new();
-            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
diff --git a/src/test/compile-fail/auxiliary/issue_1920.rs b/src/test/compile-fail/auxiliary/issue_1920.rs
new file mode 100644 (file)
index 0000000..5506517
--- /dev/null
@@ -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;
index 23be4d3536117fe50a594e3607af41dcb7780b83..37c8173c4f66b8b7d38162ad5bf8adc6274d22d7 100644 (file)
@@ -19,7 +19,7 @@ struct G<T: ?Sized> {
 }
 
 impl<T> Drop for G<T> {
-//~^ 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() {
         }
index f829d4645a0896d4bd9ad321d77e273c51a82332..97dd290a45bc83f7d961f61c67e99c5d63e23e45 100644 (file)
 
 //! 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
 }
index 02c925f336eae8fa20cde1a07638797a6691d096..2af6e2cc991faa98447b0619dbeb99d1f5db8a76 100644 (file)
 
 //! 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
 }
index 2f5da907b95f6712e1991852e3c3b19742e5f108..fa6efea845fce2e80df9823e0cee75c7b8d22adf 100644 (file)
 
 //! 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
 }
index ecee2e0a4c63ae4c6ad976f475cb351549e89338..c717d1a72e05d31c536274cee20a703deb0062b2 100644 (file)
@@ -14,7 +14,7 @@ fn assert_send<T: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() {
index af3e89a936ee05cc85b4a41823fa8b0668e286cf..0f53e7722dd51785d5ca185e5ca0b147ce726876 100644 (file)
@@ -69,11 +69,11 @@ print-type-size type: `MyOption<bool>`: 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<core::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
+print-type-size type: `MyOption<std::cmp::Ordering>`: 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