about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-29 13:40:58 +0000
committerbors <bors@rust-lang.org>2020-01-29 13:40:58 +0000
commiteed12bcd0cb281979c4c9ed956b9e41fda2bfaeb (patch)
treefdf73820fb17548b3ae1a65849819d42d1783dd5 /src
parentedb368491551a77d77a48446d4ee88b35490c565 (diff)
parent50df7880a77912702de51f454e58ae65a48d9e29 (diff)
downloadrust-eed12bcd0cb281979c4c9ed956b9e41fda2bfaeb.tar.gz
rust-eed12bcd0cb281979c4c9ed956b9e41fda2bfaeb.zip
Auto merge of #68635 - JohnTitor:rollup-jsc34ac, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #67722 (Minor: note how Any is an unsafe trait in SAFETY comments)
 - #68586 (Make conflicting_repr_hints a deny-by-default c-future-compat lint)
 - #68598 (Fix null synthetic_implementors error)
 - #68603 (Changelog: Demonstrate final build-override syntax)
 - #68609 (Set lld flavor for MSVC to link.exe)
 - #68611 (Correct ICE caused by macros generating invalid spans.)
 - #68627 (Document that write_all will not call write if given an empty buffer)

Failed merges:

r? @ghost
Diffstat (limited to 'src')
-rw-r--r--src/libcore/any.rs8
-rw-r--r--src/librustc/hir/check_attr.rs21
-rw-r--r--src/librustc_errors/emitter.rs9
-rw-r--r--src/librustc_session/lint/builtin.rs11
-rw-r--r--src/librustc_target/spec/windows_msvc_base.rs7
-rw-r--r--src/librustdoc/html/static/main.js30
-rw-r--r--src/libstd/io/mod.rs2
-rw-r--r--src/test/ui/conflicting-repr-hints.rs2
-rw-r--r--src/test/ui/conflicting-repr-hints.stderr25
-rw-r--r--src/test/ui/feature-gates/feature-gate-repr-simd.rs1
-rw-r--r--src/test/ui/feature-gates/feature-gate-repr-simd.stderr7
-rw-r--r--src/test/ui/issues/issue-47094.rs2
-rw-r--r--src/test/ui/issues/issue-47094.stderr10
13 files changed, 96 insertions, 39 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index af02e84d3fa..97ef513cbcc 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -194,7 +194,9 @@ impl dyn Any {
     #[inline]
     pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
         if self.is::<T>() {
-            // SAFETY: just checked whether we are pointing to the correct type
+            // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
+            // that check for memory safety because we have implemented Any for all types; no other
+            // impls can exist as they would conflict with our impl.
             unsafe { Some(&*(self as *const dyn Any as *const T)) }
         } else {
             None
@@ -228,7 +230,9 @@ impl dyn Any {
     #[inline]
     pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
         if self.is::<T>() {
-            // SAFETY: just checked whether we are pointing to the correct type
+            // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
+            // that check for memory safety because we have implemented Any for all types; no other
+            // impls can exist as they would conflict with our impl.
             unsafe { Some(&mut *(self as *mut dyn Any as *mut T)) }
         } else {
             None
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index 86eab3d92d3..03fa426460d 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
 use rustc_hir::DUMMY_HIR_ID;
 use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
-use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
+use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
 use rustc_span::symbol::sym;
 use rustc_span::Span;
 use syntax::ast::Attribute;
@@ -196,7 +196,7 @@ impl CheckAttrVisitor<'tcx> {
             self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
         }
 
-        self.check_repr(attrs, span, target, item);
+        self.check_repr(attrs, span, target, item, hir_id);
         self.check_used(attrs, target);
     }
 
@@ -357,6 +357,7 @@ impl CheckAttrVisitor<'tcx> {
         span: &Span,
         target: Target,
         item: Option<&Item<'_>>,
+        hir_id: HirId,
     ) {
         // Extract the names of all repr hints, e.g., [foo, bar, align] for:
         // ```
@@ -446,13 +447,15 @@ impl CheckAttrVisitor<'tcx> {
             || (is_simd && is_c)
             || (int_reprs == 1 && is_c && item.map_or(false, |item| is_c_like_enum(item)))
         {
-            struct_span_err!(
-                self.tcx.sess,
-                hint_spans.collect::<Vec<Span>>(),
-                E0566,
-                "conflicting representation hints",
-            )
-            .emit();
+            self.tcx
+                .struct_span_lint_hir(
+                    CONFLICTING_REPR_HINTS,
+                    hir_id,
+                    hint_spans.collect::<Vec<Span>>(),
+                    "conflicting representation hints",
+                )
+                .code(rustc_errors::error_code!(E0566))
+                .emit();
         }
     }
 
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index bf660d188b2..7ef623807d0 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -19,6 +19,7 @@ use crate::{
     pluralize, CodeSuggestion, Diagnostic, DiagnosticId, Level, SubDiagnostic, SuggestionStyle,
 };
 
+use log::*;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::Lrc;
 use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -2108,7 +2109,13 @@ impl<'a> Drop for WritableDst<'a> {
 /// Whether the original and suggested code are visually similar enough to warrant extra wording.
 pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
     // FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.
-    let found = sm.span_to_snippet(sp).unwrap();
+    let found = match sm.span_to_snippet(sp) {
+        Ok(snippet) => snippet,
+        Err(e) => {
+            warn!("Invalid span {:?}. Err={:?}", sp, e);
+            return false;
+        }
+    };
     let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
     // All the chars that differ in capitalization are confusable (above):
     let confusable = found
diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs
index 3e8503ef661..c326061100b 100644
--- a/src/librustc_session/lint/builtin.rs
+++ b/src/librustc_session/lint/builtin.rs
@@ -19,6 +19,16 @@ declare_lint! {
 }
 
 declare_lint! {
+    pub CONFLICTING_REPR_HINTS,
+    Deny,
+    "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
+    @future_incompatible = FutureIncompatibleInfo {
+        reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
+        edition: None,
+    };
+}
+
+declare_lint! {
     pub META_VARIABLE_MISUSE,
     Allow,
     "possible meta-variable misuse at macro definition"
@@ -520,6 +530,7 @@ declare_lint_pass! {
         MACRO_USE_EXTERN_CRATE,
         MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
         ILL_FORMED_ATTRIBUTE_INPUT,
+        CONFLICTING_REPR_HINTS,
         META_VARIABLE_MISUSE,
         DEPRECATED_IN_FUTURE,
         AMBIGUOUS_ASSOCIATED_ITEMS,
diff --git a/src/librustc_target/spec/windows_msvc_base.rs b/src/librustc_target/spec/windows_msvc_base.rs
index 63a443cd07a..52b166df939 100644
--- a/src/librustc_target/spec/windows_msvc_base.rs
+++ b/src/librustc_target/spec/windows_msvc_base.rs
@@ -1,9 +1,11 @@
-use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
+use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
 use std::default::Default;
 
 pub fn opts() -> TargetOptions {
+    let pre_args = vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string()];
     let mut args = LinkArgs::new();
-    args.insert(LinkerFlavor::Msvc, vec!["/NOLOGO".to_string(), "/NXCOMPAT".to_string()]);
+    args.insert(LinkerFlavor::Msvc, pre_args.clone());
+    args.insert(LinkerFlavor::Lld(LldFlavor::Link), pre_args);
 
     TargetOptions {
         function_sections: true,
@@ -21,6 +23,7 @@ pub fn opts() -> TargetOptions {
         // language packs, and avoid generating Non-UTF-8 error
         // messages if a link error occurred.
         link_env: vec![("VSLANG".to_string(), "1033".to_string())],
+        lld_flavor: LldFlavor::Link,
         pre_link_args: args,
         crt_static_allows_dylibs: true,
         crt_static_respected: true,
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index ec881d25dd2..44fd8b929f3 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -1895,21 +1895,23 @@ function getSearchElement() {
         var implementors = document.getElementById("implementors-list");
         var synthetic_implementors = document.getElementById("synthetic-implementors-list");
 
-        // This `inlined_types` variable is used to avoid having the same implementation showing
-        // up twice. For example "String" in the "Sync" doc page.
-        //
-        // By the way, this is only used by and useful for traits implemented automatically (like
-        // "Send" and "Sync").
-        var inlined_types = new Set();
-        onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
-            var aliases = el.getAttribute("aliases");
-            if (!aliases) {
-                return;
-            }
-            aliases.split(",").forEach(function(alias) {
-                inlined_types.add(alias);
+        if (synthetic_implementors) {
+            // This `inlined_types` variable is used to avoid having the same implementation
+            // showing up twice. For example "String" in the "Sync" doc page.
+            //
+            // By the way, this is only used by and useful for traits implemented automatically
+            // (like "Send" and "Sync").
+            var inlined_types = new Set();
+            onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
+                var aliases = el.getAttribute("aliases");
+                if (!aliases) {
+                    return;
+                }
+                aliases.split(",").forEach(function(alias) {
+                    inlined_types.add(alias);
+                });
             });
-        });
+        }
 
         var libs = Object.getOwnPropertyNames(imp);
         var llength = libs.length;
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 95c8934b3d6..67b382c7a84 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -1327,6 +1327,8 @@ pub trait Write {
     /// not of [`ErrorKind::Interrupted`] kind generated from this method will be
     /// returned.
     ///
+    /// If the buffer contains no data, this will never call [`write`].
+    ///
     /// # Errors
     ///
     /// This function will return the first error of
diff --git a/src/test/ui/conflicting-repr-hints.rs b/src/test/ui/conflicting-repr-hints.rs
index 8e9c11690a8..09dade20992 100644
--- a/src/test/ui/conflicting-repr-hints.rs
+++ b/src/test/ui/conflicting-repr-hints.rs
@@ -11,11 +11,13 @@ enum B {
 }
 
 #[repr(C, u64)] //~ ERROR conflicting representation hints
+//~^ WARN this was previously accepted
 enum C {
     C,
 }
 
 #[repr(u32, u64)] //~ ERROR conflicting representation hints
+//~^ WARN this was previously accepted
 enum D {
     D,
 }
diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr
index 0dfe360dbb3..43b76bf6497 100644
--- a/src/test/ui/conflicting-repr-hints.stderr
+++ b/src/test/ui/conflicting-repr-hints.stderr
@@ -3,45 +3,52 @@ error[E0566]: conflicting representation hints
    |
 LL | #[repr(C, u64)]
    |        ^  ^^^
+   |
+   = note: `#[deny(conflicting_repr_hints)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
 
 error[E0566]: conflicting representation hints
-  --> $DIR/conflicting-repr-hints.rs:18:8
+  --> $DIR/conflicting-repr-hints.rs:19:8
    |
 LL | #[repr(u32, u64)]
    |        ^^^  ^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:27:1
+  --> $DIR/conflicting-repr-hints.rs:29:1
    |
 LL | struct F(i32);
    | ^^^^^^^^^^^^^^
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:31:1
+  --> $DIR/conflicting-repr-hints.rs:33:1
    |
 LL | struct G(i32);
    | ^^^^^^^^^^^^^^
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:35:1
+  --> $DIR/conflicting-repr-hints.rs:37:1
    |
 LL | struct H(i32);
    | ^^^^^^^^^^^^^^
 
 error[E0634]: type has conflicting packed representation hints
-  --> $DIR/conflicting-repr-hints.rs:38:1
+  --> $DIR/conflicting-repr-hints.rs:40:1
    |
 LL | struct I(i32);
    | ^^^^^^^^^^^^^^
 
 error[E0634]: type has conflicting packed representation hints
-  --> $DIR/conflicting-repr-hints.rs:42:1
+  --> $DIR/conflicting-repr-hints.rs:44:1
    |
 LL | struct J(i32);
    | ^^^^^^^^^^^^^^
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:48:1
+  --> $DIR/conflicting-repr-hints.rs:50:1
    |
 LL | / union X {
 LL | |
@@ -50,7 +57,7 @@ LL | | }
    | |_^
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:55:1
+  --> $DIR/conflicting-repr-hints.rs:57:1
    |
 LL | / union Y {
 LL | |
@@ -59,7 +66,7 @@ LL | | }
    | |_^
 
 error[E0587]: type has conflicting packed and align representation hints
-  --> $DIR/conflicting-repr-hints.rs:62:1
+  --> $DIR/conflicting-repr-hints.rs:64:1
    |
 LL | / union Z {
 LL | |
diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.rs b/src/test/ui/feature-gates/feature-gate-repr-simd.rs
index 1e4a404fa25..c527404f572 100644
--- a/src/test/ui/feature-gates/feature-gate-repr-simd.rs
+++ b/src/test/ui/feature-gates/feature-gate-repr-simd.rs
@@ -2,6 +2,7 @@
 struct Foo(u64, u64);
 
 #[repr(C)] //~ ERROR conflicting representation hints
+//~^ WARN this was previously accepted
 #[repr(simd)] //~ error: SIMD types are experimental
 struct Bar(u64, u64);
 
diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
index 37a7bd0b129..013bad069d8 100644
--- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
+++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
@@ -8,7 +8,7 @@ LL | #[repr(simd)]
    = help: add `#![feature(repr_simd)]` to the crate attributes to enable
 
 error[E0658]: SIMD types are experimental and possibly buggy
-  --> $DIR/feature-gate-repr-simd.rs:5:1
+  --> $DIR/feature-gate-repr-simd.rs:6:1
    |
 LL | #[repr(simd)]
    | ^^^^^^^^^^^^^
@@ -21,8 +21,13 @@ error[E0566]: conflicting representation hints
    |
 LL | #[repr(C)]
    |        ^
+LL |
 LL | #[repr(simd)]
    |        ^^^^
+   |
+   = note: `#[deny(conflicting_repr_hints)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/issues/issue-47094.rs b/src/test/ui/issues/issue-47094.rs
index 3258ee92a74..c5d37feb144 100644
--- a/src/test/ui/issues/issue-47094.rs
+++ b/src/test/ui/issues/issue-47094.rs
@@ -1,10 +1,12 @@
 #[repr(C, u8)] //~ ERROR conflicting representation hints
+//~^ WARN this was previously accepted
 enum Foo {
     A,
     B,
 }
 
 #[repr(C)] //~ ERROR conflicting representation hints
+//~^ WARN this was previously accepted
 #[repr(u8)]
 enum Bar {
     A,
diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr
index c807f644fd3..e323ce66029 100644
--- a/src/test/ui/issues/issue-47094.stderr
+++ b/src/test/ui/issues/issue-47094.stderr
@@ -3,14 +3,22 @@ error[E0566]: conflicting representation hints
    |
 LL | #[repr(C, u8)]
    |        ^  ^^
+   |
+   = note: `#[deny(conflicting_repr_hints)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
 
 error[E0566]: conflicting representation hints
-  --> $DIR/issue-47094.rs:7:8
+  --> $DIR/issue-47094.rs:8:8
    |
 LL | #[repr(C)]
    |        ^
+LL |
 LL | #[repr(u8)]
    |        ^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
 
 error: aborting due to 2 previous errors