about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-07-14 05:23:45 +0000
committerbors <bors@rust-lang.org>2020-07-14 05:23:45 +0000
commit4a689da944977496fb758cc2d700984cc6a10b7f (patch)
treea288820eaba278c687bb3f088e40c19ad999dd4c /src
parent9d09331e00b02f81c714b0c41ce3a38380dd36a2 (diff)
parent9a1df31d5581811516874f24a2896ba682422bcc (diff)
downloadrust-4a689da944977496fb758cc2d700984cc6a10b7f.tar.gz
rust-4a689da944977496fb758cc2d700984cc6a10b7f.zip
Auto merge of #74313 - Manishearth:rollup-b55rn6t, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #73354 (Update RELEASES.md for 1.45.0)
 - #73852 (rustdoc: insert newlines between attributes)
 - #73867 (Document the union keyword)
 - #74046 (Fix caching issue when building tools.)
 - #74123 (clean up E0718 explanation)
 - #74147 (rustdoc: Allow linking from private items to private types)
 - #74285 (#71669: add ui, codegen tests for volatile + nearby int intrinsics)
 - #74286 (Added detailed error code explanation for issue E0688 in Rust compiler.)

Failed merges:

r? @ghost
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/bin/rustc.rs4
-rw-r--r--src/bootstrap/builder.rs18
-rw-r--r--src/librustc_error_codes/error_codes.rs2
-rw-r--r--src/librustc_error_codes/error_codes/E0688.md36
-rw-r--r--src/librustc_error_codes/error_codes/E0718.md5
-rw-r--r--src/librustdoc/html/render.rs21
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs1
-rw-r--r--src/libstd/keyword_docs.rs68
-rw-r--r--src/test/codegen/intrinsics/nearby.rs18
-rw-r--r--src/test/codegen/intrinsics/volatile.rs55
-rw-r--r--src/test/codegen/intrinsics/volatile_order.rs18
-rw-r--r--src/test/rustdoc-ui/issue-74134.public.stderr10
-rw-r--r--src/test/rustdoc-ui/issue-74134.rs41
-rw-r--r--src/test/rustdoc/attributes.rs4
-rw-r--r--src/test/ui/in-band-lifetimes/E0688.stderr1
-rw-r--r--src/test/ui/intrinsics/intrinsic-nearby.rs11
-rw-r--r--src/test/ui/intrinsics/intrinsic-volatile.rs44
17 files changed, 337 insertions, 20 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 3072a4a1ae7..fd36cd9bd8b 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -76,6 +76,10 @@ fn main() {
         cmd.env("RUST_BACKTRACE", "1");
     }
 
+    if let Ok(lint_flags) = env::var("RUSTC_LINT_FLAGS") {
+        cmd.args(lint_flags.split_whitespace());
+    }
+
     if target.is_some() {
         // The stage0 compiler has a special sysroot distinct from what we
         // actually downloaded, so we just always pass the `--sysroot` option,
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 3cbecbbaa06..557fb1aa550 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -1130,22 +1130,32 @@ impl<'a> Builder<'a> {
         cargo.env("RUSTC_VERBOSE", self.verbosity.to_string());
 
         if source_type == SourceType::InTree {
+            let mut lint_flags = Vec::new();
             // When extending this list, add the new lints to the RUSTFLAGS of the
             // build_bootstrap function of src/bootstrap/bootstrap.py as well as
             // some code doesn't go through this `rustc` wrapper.
-            rustflags.arg("-Wrust_2018_idioms");
-            rustflags.arg("-Wunused_lifetimes");
+            lint_flags.push("-Wrust_2018_idioms");
+            lint_flags.push("-Wunused_lifetimes");
 
             if self.config.deny_warnings {
-                rustflags.arg("-Dwarnings");
+                lint_flags.push("-Dwarnings");
             }
 
             // FIXME(#58633) hide "unused attribute" errors in incremental
             // builds of the standard library, as the underlying checks are
             // not yet properly integrated with incremental recompilation.
             if mode == Mode::Std && compiler.stage == 0 && self.config.incremental {
-                rustflags.arg("-Aunused-attributes");
+                lint_flags.push("-Aunused-attributes");
             }
+            // This does not use RUSTFLAGS due to caching issues with Cargo.
+            // Clippy is treated as an "in tree" tool, but shares the same
+            // cache as other "submodule" tools. With these options set in
+            // RUSTFLAGS, that causes *every* shared dependency to be rebuilt.
+            // By injecting this into the rustc wrapper, this circumvents
+            // Cargo's fingerprint detection. This is fine because lint flags
+            // are always ignored in dependencies. Eventually this should be
+            // fixed via better support from Cargo.
+            cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
         }
 
         if let Mode::Rustc | Mode::Codegen = mode {
diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs
index f687221d78e..136230d52d9 100644
--- a/src/librustc_error_codes/error_codes.rs
+++ b/src/librustc_error_codes/error_codes.rs
@@ -383,6 +383,7 @@ E0669: include_str!("./error_codes/E0669.md"),
 E0670: include_str!("./error_codes/E0670.md"),
 E0671: include_str!("./error_codes/E0671.md"),
 E0687: include_str!("./error_codes/E0687.md"),
+E0688: include_str!("./error_codes/E0688.md"),
 E0689: include_str!("./error_codes/E0689.md"),
 E0690: include_str!("./error_codes/E0690.md"),
 E0691: include_str!("./error_codes/E0691.md"),
@@ -616,7 +617,6 @@ E0768: include_str!("./error_codes/E0768.md"),
     E0640, // infer outlives requirements
 //  E0645, // trait aliases not finished
     E0667, // `impl Trait` in projections
-    E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
 //  E0694, // an unknown tool name found in scoped attributes
 //  E0702, // replaced with a generic attribute input check
 //  E0707, // multiple elided lifetimes used in arguments of `async fn`
diff --git a/src/librustc_error_codes/error_codes/E0688.md b/src/librustc_error_codes/error_codes/E0688.md
new file mode 100644
index 00000000000..db50f490208
--- /dev/null
+++ b/src/librustc_error_codes/error_codes/E0688.md
@@ -0,0 +1,36 @@
+In-band lifetimes were mixed with explicit lifetime binders.
+
+Erroneous code example:
+
+```compile_fail,E0688
+#![feature(in_band_lifetimes)]
+
+fn foo<'a>(x: &'a u32, y: &'b u32) {}   // error!
+
+struct Foo<'a> { x: &'a u32 }
+
+impl Foo<'a> {
+    fn bar<'b>(x: &'a u32, y: &'b u32, z: &'c u32) {}   // error!
+}
+
+impl<'b> Foo<'a> {  // error!
+    fn baz() {}
+}
+```
+
+In-band lifetimes cannot be mixed with explicit lifetime binders.
+For example:
+
+```
+fn foo<'a, 'b>(x: &'a u32, y: &'b u32) {}   // ok!
+
+struct Foo<'a> { x: &'a u32 }
+
+impl<'a> Foo<'a> {
+    fn bar<'b,'c>(x: &'a u32, y: &'b u32, z: &'c u32) {}    // ok!
+}
+
+impl<'a> Foo<'a> {  // ok!
+    fn baz() {}
+}
+```
diff --git a/src/librustc_error_codes/error_codes/E0718.md b/src/librustc_error_codes/error_codes/E0718.md
index e7ae51ca588..1fe62ecf1f4 100644
--- a/src/librustc_error_codes/error_codes/E0718.md
+++ b/src/librustc_error_codes/error_codes/E0718.md
@@ -1,7 +1,6 @@
-This error indicates that a `#[lang = ".."]` attribute was placed
-on the wrong type of item.
+A `#[lang = ".."]` attribute was placed on the wrong item type.
 
-Examples of erroneous code:
+Erroneous code example:
 
 ```compile_fail,E0718
 #![feature(lang_items)]
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 8bba21a2e7a..301896fd2c1 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -42,6 +42,7 @@ use std::str;
 use std::string::ToString;
 use std::sync::Arc;
 
+use itertools::Itertools;
 use rustc_ast_pretty::pprust;
 use rustc_data_structures::flock;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -3170,15 +3171,19 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
 //     bar: usize,
 // }
 fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
-    let mut attrs = String::new();
-
-    for attr in &it.attrs.other_attrs {
-        if !ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
-            continue;
-        }
+    let attrs = it
+        .attrs
+        .other_attrs
+        .iter()
+        .filter_map(|attr| {
+            if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
+                Some(pprust::attribute_to_string(&attr))
+            } else {
+                None
+            }
+        })
+        .join("\n");
 
-        attrs.push_str(&pprust::attribute_to_string(&attr));
-    }
     if !attrs.is_empty() {
         write!(
             w,
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 4fcf6ceb44d..f707c1a3e1a 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -799,6 +799,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
 
                     let hir_id = self.cx.tcx.hir().as_local_hir_id(local);
                     if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
+                        && (item.visibility == Visibility::Public)
                         && !self.cx.render_options.document_private
                     {
                         let item_name = item.name.as_deref().unwrap_or("<unknown>");
diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs
index 0b3386c05d5..a53e7f5cf57 100644
--- a/src/libstd/keyword_docs.rs
+++ b/src/libstd/keyword_docs.rs
@@ -1732,8 +1732,72 @@ mod dyn_keyword {}
 //
 /// The [Rust equivalent of a C-style union][union].
 ///
-/// The documentation for this keyword is [not yet complete]. Pull requests welcome!
+/// A `union` looks like a [`struct`] in terms of declaration, but all of its
+/// fields exist in the same memory, superimposed over one another. For instance,
+/// if we wanted some bits in memory that we sometimes interpret as a `u32` and
+/// sometimes as an `f32`, we could write:
+///
+/// ```rust
+/// union IntOrFloat {
+///     i: u32,
+///     f: f32,
+/// }
+///
+/// let mut u = IntOrFloat { f: 1.0 };
+/// // Reading the fields of an union is always unsafe
+/// assert_eq!(unsafe { u.i }, 1065353216);
+/// // Updating through any of the field will modify all of them
+/// u.i = 1073741824;
+/// assert_eq!(unsafe { u.f }, 2.0);
+/// ```
+///
+/// # Matching on unions
+///
+/// It is possible to use pattern matching on `union`s. A single field name must
+/// be used and it must match the name of one of the `union`'s field.
+/// Like reading from a `union`, pattern matching on a `union` requires `unsafe`.
+///
+/// ```rust
+/// union IntOrFloat {
+///     i: u32,
+///     f: f32,
+/// }
+///
+/// let u = IntOrFloat { f: 1.0 };
+///
+/// unsafe {
+///     match u {
+///         IntOrFloat { i: 10 } => println!("Found exactly ten!"),
+///         // Matching the field `f` provides an `f32`.
+///         IntOrFloat { f } => println!("Found f = {} !", f),
+///     }
+/// }
+/// ```
+///
+/// # References to union fields
+///
+/// All fields in a `union` are all at the same place in memory which means
+/// borrowing one borrows the entire `union`, for the same lifetime:
+///
+/// ```rust,compile_fail,E0502
+/// union IntOrFloat {
+///     i: u32,
+///     f: f32,
+/// }
 ///
+/// let mut u = IntOrFloat { f: 1.0 };
+///
+/// let f = unsafe { &u.f };
+/// // This will not compile because the field has already been borrowed, even
+/// // if only immutably
+/// let i = unsafe { &mut u.i };
+///
+/// *i = 10;
+/// println!("f = {} and i = {}", f, i);
+/// ```
+///
+/// See the [Reference][union] for more informations on `union`s.
+///
+/// [`struct`]: keyword.struct.html
 /// [union]: ../reference/items/unions.html
-/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
 mod union_keyword {}
diff --git a/src/test/codegen/intrinsics/nearby.rs b/src/test/codegen/intrinsics/nearby.rs
new file mode 100644
index 00000000000..520fe2f1886
--- /dev/null
+++ b/src/test/codegen/intrinsics/nearby.rs
@@ -0,0 +1,18 @@
+#![crate_type = "lib"]
+#![feature(core_intrinsics)]
+
+use std::intrinsics;
+
+// CHECK-LABEL: @nearbyintf32
+#[no_mangle]
+pub unsafe fn nearbyintf32(a: f32) -> f32 {
+    // CHECK: llvm.nearbyint.f32
+    intrinsics::nearbyintf32(a)
+}
+
+// CHECK-LABEL: @nearbyintf64
+#[no_mangle]
+pub unsafe fn nearbyintf64(a: f64) -> f64 {
+    // CHECK: llvm.nearbyint.f64
+    intrinsics::nearbyintf64(a)
+}
diff --git a/src/test/codegen/intrinsics/volatile.rs b/src/test/codegen/intrinsics/volatile.rs
new file mode 100644
index 00000000000..1970517e732
--- /dev/null
+++ b/src/test/codegen/intrinsics/volatile.rs
@@ -0,0 +1,55 @@
+// compile-flags: -C no-prepopulate-passes
+
+#![crate_type = "lib"]
+#![feature(core_intrinsics)]
+
+use std::intrinsics;
+
+// CHECK-LABEL: @volatile_copy_memory
+#[no_mangle]
+pub unsafe fn volatile_copy_memory(a: *mut u8, b: *const u8) {
+    // CHECK: llvm.memmove.p0i8.p0i8.{{\w*(.*true)}}
+    intrinsics::volatile_copy_memory(a, b, 1)
+}
+
+// CHECK-LABEL: @volatile_copy_nonoverlapping_memory
+#[no_mangle]
+pub unsafe fn volatile_copy_nonoverlapping_memory(a: *mut u8, b: *const u8) {
+    // CHECK: llvm.memcpy.p0i8.p0i8.{{\w*(.*true)}}
+    intrinsics::volatile_copy_nonoverlapping_memory(a, b, 1)
+}
+
+// CHECK-LABEL: @volatile_set_memory
+#[no_mangle]
+pub unsafe fn volatile_set_memory(a: *mut u8, b: u8) {
+    // CHECK: llvm.memset.p0i8.{{\w*(.*true)}}
+    intrinsics::volatile_set_memory(a, b, 1)
+}
+
+// CHECK-LABEL: @volatile_load
+#[no_mangle]
+pub unsafe fn volatile_load(a: *const u8) -> u8 {
+    // CHECK: load volatile
+    intrinsics::volatile_load(a)
+}
+
+// CHECK-LABEL: @volatile_store
+#[no_mangle]
+pub unsafe fn volatile_store(a: *mut u8, b: u8) {
+    // CHECK: store volatile
+    intrinsics::volatile_store(a, b)
+}
+
+// CHECK-LABEL: @unaligned_volatile_load
+#[no_mangle]
+pub unsafe fn unaligned_volatile_load(a: *const u8) -> u8 {
+    // CHECK: load volatile
+    intrinsics::unaligned_volatile_load(a)
+}
+
+// CHECK-LABEL: @unaligned_volatile_store
+#[no_mangle]
+pub unsafe fn unaligned_volatile_store(a: *mut u8, b: u8) {
+    // CHECK: store volatile
+    intrinsics::unaligned_volatile_store(a, b)
+}
diff --git a/src/test/codegen/intrinsics/volatile_order.rs b/src/test/codegen/intrinsics/volatile_order.rs
new file mode 100644
index 00000000000..29331219ba6
--- /dev/null
+++ b/src/test/codegen/intrinsics/volatile_order.rs
@@ -0,0 +1,18 @@
+#![crate_type = "lib"]
+#![feature(core_intrinsics)]
+
+use std::intrinsics::*;
+
+pub unsafe fn test_volatile_order() {
+    let mut a: Box<u8> = Box::new(0);
+    // CHECK: load volatile
+    let x = volatile_load(&*a);
+    // CHECK: load volatile
+    let x = volatile_load(&*a);
+    // CHECK: store volatile
+    volatile_store(&mut *a, 12);
+    // CHECK: store volatile
+    unaligned_volatile_store(&mut *a, 12);
+    // CHECK: llvm.memset.p0i8
+    volatile_set_memory(&mut *a, 12, 1)
+}
diff --git a/src/test/rustdoc-ui/issue-74134.public.stderr b/src/test/rustdoc-ui/issue-74134.public.stderr
new file mode 100644
index 00000000000..03f95f19d32
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-74134.public.stderr
@@ -0,0 +1,10 @@
+warning: `[PrivateType]` public documentation for `public_item` links to a private item
+  --> $DIR/issue-74134.rs:19:10
+   |
+LL |     /// [`PrivateType`]
+   |          ^^^^^^^^^^^^^ this item is private
+   |
+   = note: `#[warn(intra_doc_link_resolution_failure)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/src/test/rustdoc-ui/issue-74134.rs b/src/test/rustdoc-ui/issue-74134.rs
new file mode 100644
index 00000000000..d561c2dd890
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-74134.rs
@@ -0,0 +1,41 @@
+// revisions: public private
+// [private]compile-flags: --document-private-items
+// check-pass
+
+// There are 4 cases here:
+// 1. public item  -> public type:  no warning
+// 2. public item  -> private type: warning, if --document-private-items is not passed
+// 3. private item -> public type:  no warning
+// 4. private item -> private type: no warning
+// All 4 cases are tested with and without --document-private-items.
+//
+// Case 4 without --document-private-items is the one described in issue #74134.
+
+struct PrivateType;
+pub struct PublicType;
+
+pub struct Public {
+    /// [`PublicType`]
+    /// [`PrivateType`]
+    //[public]~^ WARNING public documentation for `public_item` links to a private
+    pub public_item: u32,
+
+    /// [`PublicType`]
+    /// [`PrivateType`]
+    private_item: u32,
+}
+
+// The following cases are identical to the ones above, except that they are in a private
+// module. Thus they all fall into cases 3 and 4 and should not produce a warning.
+
+mod private {
+    pub struct Public {
+        /// [`super::PublicType`]
+        /// [`super::PrivateType`]
+        pub public_item: u32,
+
+        /// [`super::PublicType`]
+        /// [`super::PrivateType`]
+        private_item: u32,
+    }
+}
diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs
index e9cd3514a07..54c5939f908 100644
--- a/src/test/rustdoc/attributes.rs
+++ b/src/test/rustdoc/attributes.rs
@@ -8,8 +8,8 @@ pub extern "C" fn f() {}
 #[export_name = "bar"]
 pub extern "C" fn g() {}
 
-// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[repr(i64)]'
-// @has foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' '#[must_use]'
+// @matches foo/enum.Foo.html '//*[@class="docblock attributes top-attr"]' \
+//      '(?m)\A#\[repr\(i64\)\]\n#\[must_use\]\Z'
 #[repr(i64)]
 #[must_use]
 pub enum Foo {
diff --git a/src/test/ui/in-band-lifetimes/E0688.stderr b/src/test/ui/in-band-lifetimes/E0688.stderr
index 0078cd58001..afefcd9fc2c 100644
--- a/src/test/ui/in-band-lifetimes/E0688.stderr
+++ b/src/test/ui/in-band-lifetimes/E0688.stderr
@@ -24,3 +24,4 @@ LL | impl<'b> Foo<'a> {
 
 error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0688`.
diff --git a/src/test/ui/intrinsics/intrinsic-nearby.rs b/src/test/ui/intrinsics/intrinsic-nearby.rs
new file mode 100644
index 00000000000..7b1d1eeaadb
--- /dev/null
+++ b/src/test/ui/intrinsics/intrinsic-nearby.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![feature(core_intrinsics)]
+
+use std::intrinsics::*;
+
+fn main() {
+    unsafe {
+        assert_eq!(nearbyintf32(5.234f32), 5f32);
+        assert_eq!(nearbyintf64(6.777f64), 7f64);
+    }
+}
diff --git a/src/test/ui/intrinsics/intrinsic-volatile.rs b/src/test/ui/intrinsics/intrinsic-volatile.rs
new file mode 100644
index 00000000000..7b2c825a208
--- /dev/null
+++ b/src/test/ui/intrinsics/intrinsic-volatile.rs
@@ -0,0 +1,44 @@
+// run-pass
+
+#![feature(core_intrinsics)]
+
+use std::intrinsics::*;
+
+pub fn main() {
+    unsafe {
+        let mut x: Box<u8> = Box::new(0);
+        let mut y: Box<u8> = Box::new(0);
+
+        // test volatile load
+        assert_eq!(volatile_load(&*x), 0);
+        *x = 1;
+        assert_eq!(volatile_load(&*x), 1);
+
+        // test volatile store
+        volatile_store(&mut *x, 2);
+        assert_eq!(*x, 2);
+
+        // test volatile copy memory
+        volatile_copy_memory(&mut *y, &*x, 1);
+        assert_eq!(*y, 2);
+
+        // test volatile copy non-overlapping memory
+        *x = 3;
+        volatile_copy_nonoverlapping_memory(&mut *y, &*x, 1);
+        assert_eq!(*y, 3);
+
+        // test volatile set memory
+        volatile_set_memory(&mut *x, 4, 1);
+        assert_eq!(*x, 4);
+
+        // test unaligned volatile load
+        let arr: [u8; 3] = [1, 2, 3];
+        let ptr = arr[1..].as_ptr() as *const u16;
+        assert_eq!(unaligned_volatile_load(ptr), u16::from_ne_bytes([arr[1], arr[2]]));
+
+        // test unaligned volatile store
+        let ptr = arr[1..].as_ptr() as *mut u16;
+        unaligned_volatile_store(ptr, 0);
+        assert_eq!(arr, [1, 0, 0]);
+    }
+}