about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-10 18:05:34 +0000
committerbors <bors@rust-lang.org>2022-08-10 18:05:34 +0000
commit7bc32faebcfacb96be73650e624dc94e330298ab (patch)
tree96eb6c6ef5d76613c4a499759280f06b03c2b838
parentc7ff1e8b0090b4ca3d62edef3dc2421861d57c48 (diff)
parenteff71b9927a98900ace67494fb9b1cb45a3b80a5 (diff)
downloadrust-7bc32faebcfacb96be73650e624dc94e330298ab.tar.gz
rust-7bc32faebcfacb96be73650e624dc94e330298ab.zip
Auto merge of #100378 - compiler-errors:rollup-8vzsd92, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #100286 (Add support for link-flavor rust-lld for macOS)
 - #100317 (Remove logic related to deprecated nvptx-nvidia-cuda (32-bit) target)
 - #100339 (Fixes bootstrap panic when running x fmt --check )
 - #100348 (Add regression test for #93205)
 - #100349 (Refactor: remove a type string comparison)
 - #100353 (Fix doc links in core::time::Duration::as_secs)
 - #100359 (Special-case references to leafs in valtree pretty-printing)
 - #100371 (Inline CStr::from_bytes_with_nul_unchecked::rt_impl)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs8
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs4
-rw-r--r--compiler/rustc_target/src/abi/call/mod.rs2
-rw-r--r--compiler/rustc_target/src/abi/call/nvptx.rs33
-rw-r--r--compiler/rustc_target/src/spec/aarch64_apple_darwin.rs8
-rw-r--r--compiler/rustc_target/src/spec/apple_base.rs53
-rw-r--r--compiler/rustc_target/src/spec/apple_sdk_base.rs44
-rw-r--r--compiler/rustc_target/src/spec/i686_apple_darwin.rs3
-rw-r--r--compiler/rustc_target/src/spec/x86_64_apple_darwin.rs6
-rw-r--r--compiler/rustc_typeck/src/check/demand.rs16
-rw-r--r--library/core/src/ffi/c_str.rs1
-rw-r--r--library/core/src/time.rs4
-rw-r--r--src/bootstrap/lib.rs10
-rw-r--r--src/test/rustdoc/intra-doc/assoc-reexport-super.rs20
-rw-r--r--src/test/ui/const-generics/issues/issue-100313.rs21
-rw-r--r--src/test/ui/const-generics/issues/issue-100313.stderr15
-rw-r--r--src/test/ui/suggestions/as-ref.rs7
-rw-r--r--src/test/ui/suggestions/as-ref.stderr62
18 files changed, 210 insertions, 107 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 63207803e32..468d034e635 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -2674,11 +2674,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
     let os = &sess.target.os;
     let llvm_target = &sess.target.llvm_target;
     if sess.target.vendor != "apple"
-        || !matches!(os.as_ref(), "ios" | "tvos" | "watchos")
+        || !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
         || (flavor != LinkerFlavor::Gcc && flavor != LinkerFlavor::Lld(LldFlavor::Ld64))
     {
         return;
     }
+
+    if os == "macos" && flavor != LinkerFlavor::Lld(LldFlavor::Ld64) {
+        return;
+    }
+
     let sdk_name = match (arch.as_ref(), os.as_ref()) {
         ("aarch64", "tvos") => "appletvos",
         ("x86_64", "tvos") => "appletvsimulator",
@@ -2694,6 +2699,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
         ("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
         ("aarch64", "watchos") => "watchos",
         ("arm", "watchos") => "watchos",
+        (_, "macos") => "macosx",
         _ => {
             sess.err(&format!("unsupported arch `{}` for os `{}`", arch, os));
             return;
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index 7f2e81a71a9..cc55b7e8611 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -1513,6 +1513,10 @@ pub trait PrettyPrinter<'tcx>:
                 }
                 return Ok(self);
             }
+            (ty::ValTree::Leaf(leaf), ty::Ref(_, inner_ty, _)) => {
+                p!(write("&"));
+                return self.pretty_print_const_scalar_int(leaf, *inner_ty, print_ty);
+            }
             (ty::ValTree::Leaf(leaf), _) => {
                 return self.pretty_print_const_scalar_int(leaf, ty, print_ty);
             }
diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs
index 577126a95cc..639ce64a9f5 100644
--- a/compiler/rustc_target/src/abi/call/mod.rs
+++ b/compiler/rustc_target/src/abi/call/mod.rs
@@ -14,7 +14,6 @@ mod m68k;
 mod mips;
 mod mips64;
 mod msp430;
-mod nvptx;
 mod nvptx64;
 mod powerpc;
 mod powerpc64;
@@ -702,7 +701,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
             "msp430" => msp430::compute_abi_info(self),
             "sparc" => sparc::compute_abi_info(cx, self),
             "sparc64" => sparc64::compute_abi_info(cx, self),
-            "nvptx" => nvptx::compute_abi_info(self),
             "nvptx64" => {
                 if cx.target_spec().adjust_abi(abi) == spec::abi::Abi::PtxKernel {
                     nvptx64::compute_ptx_kernel_abi_info(cx, self)
diff --git a/compiler/rustc_target/src/abi/call/nvptx.rs b/compiler/rustc_target/src/abi/call/nvptx.rs
deleted file mode 100644
index 428dd95bbcd..00000000000
--- a/compiler/rustc_target/src/abi/call/nvptx.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-// Reference: PTX Writer's Guide to Interoperability
-// https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability
-
-use crate::abi::call::{ArgAbi, FnAbi};
-
-fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
-    if ret.layout.is_aggregate() && ret.layout.size.bits() > 32 {
-        ret.make_indirect();
-    } else {
-        ret.extend_integer_width_to(32);
-    }
-}
-
-fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
-    if arg.layout.is_aggregate() && arg.layout.size.bits() > 32 {
-        arg.make_indirect();
-    } else {
-        arg.extend_integer_width_to(32);
-    }
-}
-
-pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
-    if !fn_abi.ret.is_ignore() {
-        classify_ret(&mut fn_abi.ret);
-    }
-
-    for arg in &mut fn_abi.args {
-        if arg.is_ignore() {
-            continue;
-        }
-        classify_arg(arg);
-    }
-}
diff --git a/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs b/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
index 9d36e37d7b8..6d919a4c2ad 100644
--- a/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
+++ b/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
@@ -1,20 +1,20 @@
-use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, Target, TargetOptions};
+use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
 
 pub fn target() -> Target {
-    let mut base = super::apple_base::opts("macos");
+    let arch = "arm64";
+    let mut base = super::apple_base::opts("macos", arch, "");
     base.cpu = "apple-a14".into();
     base.max_atomic_width = Some(128);
 
     // FIXME: The leak sanitizer currently fails the tests, see #88132.
     base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
 
-    base.add_pre_link_args(LinkerFlavor::Gcc, &["-arch", "arm64"]);
     base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
 
     // Clang automatically chooses a more specific target based on
     // MACOSX_DEPLOYMENT_TARGET.  To enable cross-language LTO to work
     // correctly, we do too.
-    let llvm_target = super::apple_base::macos_llvm_target("arm64");
+    let llvm_target = super::apple_base::macos_llvm_target(arch);
 
     Target {
         llvm_target: llvm_target.into(),
diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs
index 15e4fb9be63..db38ff50c78 100644
--- a/compiler/rustc_target/src/spec/apple_base.rs
+++ b/compiler/rustc_target/src/spec/apple_base.rs
@@ -1,8 +1,45 @@
 use std::{borrow::Cow, env};
 
-use crate::spec::{cvs, FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};
+use crate::spec::{cvs, FramePointer, SplitDebuginfo, TargetOptions};
+use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor};
+
+fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
+    let mut args = LinkArgs::new();
+
+    let platform_name = match abi {
+        "sim" => format!("{}-simulator", os),
+        "macabi" => "mac-catalyst".to_string(),
+        _ => os.to_string(),
+    };
+
+    let platform_version = match os.as_ref() {
+        "ios" => ios_lld_platform_version(),
+        "tvos" => tvos_lld_platform_version(),
+        "watchos" => watchos_lld_platform_version(),
+        "macos" => macos_lld_platform_version(arch),
+        _ => unreachable!(),
+    };
+
+    if abi != "macabi" {
+        args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch.into()]);
+    }
+
+    args.insert(
+        LinkerFlavor::Lld(LldFlavor::Ld64),
+        vec![
+            "-arch".into(),
+            arch.into(),
+            "-platform_version".into(),
+            platform_name.into(),
+            platform_version.clone().into(),
+            platform_version.into(),
+        ],
+    );
+
+    args
+}
 
-pub fn opts(os: &'static str) -> TargetOptions {
+pub fn opts(os: &'static str, arch: &'static str, abi: &'static str) -> TargetOptions {
     // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
     // either the linker will complain if it is used or the binary will end up
     // segfaulting at runtime when run on 10.6. Rust by default supports macOS
@@ -24,6 +61,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
         // macOS has -dead_strip, which doesn't rely on function_sections
         function_sections: false,
         dynamic_linking: true,
+        pre_link_args: pre_link_args(os, arch, abi),
         linker_is_gnu: false,
         families: cvs!["unix"],
         is_like_osx: true,
@@ -73,6 +111,11 @@ fn macos_deployment_target(arch: &str) -> (u32, u32) {
         .unwrap_or_else(|| macos_default_deployment_target(arch))
 }
 
+fn macos_lld_platform_version(arch: &str) -> String {
+    let (major, minor) = macos_deployment_target(arch);
+    format!("{}.{}", major, minor)
+}
+
 pub fn macos_llvm_target(arch: &str) -> String {
     let (major, minor) = macos_deployment_target(arch);
     format!("{}-apple-macosx{}.{}.0", arch, major, minor)
@@ -109,7 +152,7 @@ pub fn ios_llvm_target(arch: &str) -> String {
     format!("{}-apple-ios{}.{}.0", arch, major, minor)
 }
 
-pub fn ios_lld_platform_version() -> String {
+fn ios_lld_platform_version() -> String {
     let (major, minor) = ios_deployment_target();
     format!("{}.{}", major, minor)
 }
@@ -123,7 +166,7 @@ fn tvos_deployment_target() -> (u32, u32) {
     deployment_target("TVOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
 }
 
-pub fn tvos_lld_platform_version() -> String {
+fn tvos_lld_platform_version() -> String {
     let (major, minor) = tvos_deployment_target();
     format!("{}.{}", major, minor)
 }
@@ -132,7 +175,7 @@ fn watchos_deployment_target() -> (u32, u32) {
     deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
 }
 
-pub fn watchos_lld_platform_version() -> String {
+fn watchos_lld_platform_version() -> String {
     let (major, minor) = watchos_deployment_target();
     format!("{}.{}", major, minor)
 }
diff --git a/compiler/rustc_target/src/spec/apple_sdk_base.rs b/compiler/rustc_target/src/spec/apple_sdk_base.rs
index d77558f0f84..bf3ebaa2840 100644
--- a/compiler/rustc_target/src/spec/apple_sdk_base.rs
+++ b/compiler/rustc_target/src/spec/apple_sdk_base.rs
@@ -1,4 +1,4 @@
-use crate::spec::{cvs, LinkArgs, LinkerFlavor, LldFlavor, TargetOptions};
+use crate::spec::{cvs, TargetOptions};
 use std::borrow::Cow;
 
 use Arch::*;
@@ -61,53 +61,13 @@ fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> {
     }
 }
 
-fn pre_link_args(os: &'static str, arch: Arch) -> LinkArgs {
-    let mut args = LinkArgs::new();
-
-    let target_abi = target_abi(arch);
-
-    let platform_name = match target_abi {
-        "sim" => format!("{}-simulator", os),
-        "macabi" => "mac-catalyst".to_string(),
-        _ => os.to_string(),
-    };
-
-    let platform_version = match os.as_ref() {
-        "ios" => super::apple_base::ios_lld_platform_version(),
-        "tvos" => super::apple_base::tvos_lld_platform_version(),
-        "watchos" => super::apple_base::watchos_lld_platform_version(),
-        _ => unreachable!(),
-    };
-
-    let arch_str = target_arch_name(arch);
-
-    if target_abi != "macabi" {
-        args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), arch_str.into()]);
-    }
-
-    args.insert(
-        LinkerFlavor::Lld(LldFlavor::Ld64),
-        vec![
-            "-arch".into(),
-            arch_str.into(),
-            "-platform_version".into(),
-            platform_name.into(),
-            platform_version.clone().into(),
-            platform_version.into(),
-        ],
-    );
-
-    args
-}
-
 pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
     TargetOptions {
         abi: target_abi(arch).into(),
         cpu: target_cpu(arch).into(),
         dynamic_linking: false,
-        pre_link_args: pre_link_args(os, arch),
         link_env_remove: link_env_remove(arch),
         has_thread_local: false,
-        ..super::apple_base::opts(os)
+        ..super::apple_base::opts(os, target_arch_name(arch), target_abi(arch))
     }
 }
diff --git a/compiler/rustc_target/src/spec/i686_apple_darwin.rs b/compiler/rustc_target/src/spec/i686_apple_darwin.rs
index 1718bd77b86..5e9ceb844f7 100644
--- a/compiler/rustc_target/src/spec/i686_apple_darwin.rs
+++ b/compiler/rustc_target/src/spec/i686_apple_darwin.rs
@@ -1,7 +1,8 @@
 use crate::spec::{FramePointer, LinkerFlavor, StackProbeType, Target, TargetOptions};
 
 pub fn target() -> Target {
-    let mut base = super::apple_base::opts("macos");
+    // ld64 only understand i386 and not i686
+    let mut base = super::apple_base::opts("macos", "i386", "");
     base.cpu = "yonah".into();
     base.max_atomic_width = Some(64);
     base.add_pre_link_args(LinkerFlavor::Gcc, &["-m32"]);
diff --git a/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs b/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs
index dbd26899c18..176c9dd6b76 100644
--- a/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs
+++ b/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs
@@ -2,11 +2,12 @@ use crate::spec::TargetOptions;
 use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, StackProbeType, Target};
 
 pub fn target() -> Target {
-    let mut base = super::apple_base::opts("macos");
+    let arch = "x86_64";
+    let mut base = super::apple_base::opts("macos", arch, "");
     base.cpu = "core2".into();
     base.max_atomic_width = Some(128); // core2 support cmpxchg16b
     base.frame_pointer = FramePointer::Always;
-    base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64", "-arch", "x86_64"]);
+    base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64"]);
     base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
     // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
     base.stack_probes = StackProbeType::Call;
@@ -16,7 +17,6 @@ pub fn target() -> Target {
     // Clang automatically chooses a more specific target based on
     // MACOSX_DEPLOYMENT_TARGET.  To enable cross-language LTO to work
     // correctly, we do too.
-    let arch = "x86_64";
     let llvm_target = super::apple_base::macos_llvm_target(&arch);
 
     Target {
diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs
index 0595b9a73be..bac0be44aa9 100644
--- a/compiler/rustc_typeck/src/check/demand.rs
+++ b/compiler/rustc_typeck/src/check/demand.rs
@@ -598,13 +598,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         };
 
         let self_ty = self.typeck_results.borrow().expr_ty(&method_expr[0]);
-        let self_ty = format!("{:?}", self_ty);
         let name = method_path.ident.name;
-        let is_as_ref_able = (self_ty.starts_with("&std::option::Option")
-            || self_ty.starts_with("&std::result::Result")
-            || self_ty.starts_with("std::option::Option")
-            || self_ty.starts_with("std::result::Result"))
-            && (name == sym::map || name == sym::and_then);
+        let is_as_ref_able = match self_ty.peel_refs().kind() {
+            ty::Adt(def, _) => {
+                (self.tcx.is_diagnostic_item(sym::Option, def.did())
+                    || self.tcx.is_diagnostic_item(sym::Result, def.did()))
+                    && (name == sym::map || name == sym::and_then)
+            }
+            _ => false,
+        };
         match (is_as_ref_able, self.sess().source_map().span_to_snippet(method_path.ident.span)) {
             (true, Ok(src)) => {
                 let suggestion = format!("as_ref().{}", src);
@@ -792,7 +794,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                             _ if is_range_literal(expr) => true,
                             _ => false,
                         };
-                        let sugg_expr = if needs_parens { format!("({src})") } else { src };
 
                         if let Some(sugg) = self.can_use_as_ref(expr) {
                             return Some((
@@ -820,6 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                             }
                         }
 
+                        let sugg_expr = if needs_parens { format!("({src})") } else { src };
                         return Some(match mutability {
                             hir::Mutability::Mut => (
                                 sp,
diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs
index 82e63a7fe1d..d8b8ac4d871 100644
--- a/library/core/src/ffi/c_str.rs
+++ b/library/core/src/ffi/c_str.rs
@@ -387,6 +387,7 @@ impl CStr {
     #[rustc_const_stable(feature = "const_cstr_unchecked", since = "1.59.0")]
     #[rustc_allow_const_fn_unstable(const_eval_select)]
     pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
+        #[inline]
         fn rt_impl(bytes: &[u8]) -> &CStr {
             // Chance at catching some UB at runtime with debug builds.
             debug_assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index 2c57569b5aa..153dc4dbb08 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -321,8 +321,8 @@ impl Duration {
     /// To determine the total number of seconds represented by the `Duration`
     /// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`]
     ///
-    /// [`as_secs_f32`]: Duration::as_secs_f64
-    /// [`as_secs_f64`]: Duration::as_secs_f32
+    /// [`as_secs_f64`]: Duration::as_secs_f64
+    /// [`as_secs_f32`]: Duration::as_secs_f32
     /// [`subsec_nanos`]: Duration::subsec_nanos
     #[stable(feature = "duration", since = "1.3.0")]
     #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index f84de73297a..a242243aaaf 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -1631,14 +1631,12 @@ fn chmod(_path: &Path, _perms: u32) {}
 /// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.)
 /// If the test is running and code is an error code, it will cause a panic.
 fn detail_exit(code: i32) -> ! {
-    // Successful exit
-    if code == 0 {
-        std::process::exit(0);
-    }
-    if cfg!(test) {
+    // if in test and code is an error code, panic with staus code provided
+    if cfg!(test) && code != 0 {
         panic!("status code: {}", code);
     } else {
-        std::panic::resume_unwind(Box::new(code));
+        //otherwise,exit with provided status code
+        std::process::exit(code);
     }
 }
 
diff --git a/src/test/rustdoc/intra-doc/assoc-reexport-super.rs b/src/test/rustdoc/intra-doc/assoc-reexport-super.rs
new file mode 100644
index 00000000000..a7bc1c6a29f
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/assoc-reexport-super.rs
@@ -0,0 +1,20 @@
+// Regression test for #93205
+
+#![crate_name = "foo"]
+
+mod generated {
+    pub struct MyNewType;
+    impl MyNewType {
+        pub const FOO: Self = Self;
+    }
+}
+
+pub use generated::MyNewType;
+
+mod prelude {
+    impl super::MyNewType {
+        /// An alias for [`Self::FOO`].
+        // @has 'foo/struct.MyNewType.html' '//a[@href="struct.MyNewType.html#associatedconstant.FOO"]' 'Self::FOO'
+        pub const FOO2: Self = Self::FOO;
+    }
+}
diff --git a/src/test/ui/const-generics/issues/issue-100313.rs b/src/test/ui/const-generics/issues/issue-100313.rs
new file mode 100644
index 00000000000..4e9d3626aa8
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-100313.rs
@@ -0,0 +1,21 @@
+#![allow(incomplete_features)]
+#![feature(const_mut_refs)]
+#![feature(adt_const_params)]
+
+struct T<const B: &'static bool>;
+
+impl <const B: &'static bool> T<B> {
+    const fn set_false(&self) {
+        unsafe {
+            *(B as *const bool as *mut bool) = false;
+            //~^ ERROR evaluation of constant value failed [E0080]
+        }
+    }
+}
+
+const _: () = {
+    let x = T::<{&true}>;
+    x.set_false();
+};
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-100313.stderr b/src/test/ui/const-generics/issues/issue-100313.stderr
new file mode 100644
index 00000000000..f3ce357c2bb
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-100313.stderr
@@ -0,0 +1,15 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/issue-100313.rs:10:13
+   |
+LL |             *(B as *const bool as *mut bool) = false;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |             |
+   |             writing to alloc7 which is read-only
+   |             inside `T::<&true>::set_false` at $DIR/issue-100313.rs:10:13
+...
+LL |     x.set_false();
+   |     ------------- inside `_` at $DIR/issue-100313.rs:18:5
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/suggestions/as-ref.rs b/src/test/ui/suggestions/as-ref.rs
index 46d9461538c..a0535344185 100644
--- a/src/test/ui/suggestions/as-ref.rs
+++ b/src/test/ui/suggestions/as-ref.rs
@@ -17,4 +17,11 @@ fn main() {
     // note: do not suggest because of `E: usize`
     let x: &Result<usize, usize> = &Ok(3);
     let y: Result<&usize, usize> = x; //~ ERROR mismatched types [E0308]
+
+    let multiple_ref_opt = &&Some(Foo);
+    multiple_ref_opt.map(|arg| takes_ref(arg)); //~ ERROR mismatched types [E0308]
+    multiple_ref_opt.and_then(|arg| Some(takes_ref(arg))); //~ ERROR mismatched types [E0308]
+    let multiple_ref_result = &&Ok(Foo);
+    multiple_ref_result.map(|arg| takes_ref(arg)); //~ ERROR mismatched types [E0308]
+    multiple_ref_result.and_then(|arg| Ok(takes_ref(arg))); //~ ERROR mismatched types [E0308]
 }
diff --git a/src/test/ui/suggestions/as-ref.stderr b/src/test/ui/suggestions/as-ref.stderr
index 1efd1b317b7..deafa9f48d4 100644
--- a/src/test/ui/suggestions/as-ref.stderr
+++ b/src/test/ui/suggestions/as-ref.stderr
@@ -97,6 +97,66 @@ LL |     let y: Result<&usize, usize> = x;
    = note:   expected enum `Result<&usize, usize>`
            found reference `&Result<usize, usize>`
 
-error: aborting due to 7 previous errors
+error[E0308]: mismatched types
+  --> $DIR/as-ref.rs:22:42
+   |
+LL |     multiple_ref_opt.map(|arg| takes_ref(arg));
+   |                      ---       --------- ^^^ expected `&Foo`, found struct `Foo`
+   |                      |         |
+   |                      |         arguments to this function are incorrect
+   |                      help: consider using `as_ref` instead: `as_ref().map`
+   |
+note: function defined here
+  --> $DIR/as-ref.rs:3:4
+   |
+LL | fn takes_ref(_: &Foo) {}
+   |    ^^^^^^^^^ -------
+
+error[E0308]: mismatched types
+  --> $DIR/as-ref.rs:23:52
+   |
+LL |     multiple_ref_opt.and_then(|arg| Some(takes_ref(arg)));
+   |                      --------            --------- ^^^ expected `&Foo`, found struct `Foo`
+   |                      |                   |
+   |                      |                   arguments to this function are incorrect
+   |                      help: consider using `as_ref` instead: `as_ref().and_then`
+   |
+note: function defined here
+  --> $DIR/as-ref.rs:3:4
+   |
+LL | fn takes_ref(_: &Foo) {}
+   |    ^^^^^^^^^ -------
+
+error[E0308]: mismatched types
+  --> $DIR/as-ref.rs:25:45
+   |
+LL |     multiple_ref_result.map(|arg| takes_ref(arg));
+   |                         ---       --------- ^^^ expected `&Foo`, found struct `Foo`
+   |                         |         |
+   |                         |         arguments to this function are incorrect
+   |                         help: consider using `as_ref` instead: `as_ref().map`
+   |
+note: function defined here
+  --> $DIR/as-ref.rs:3:4
+   |
+LL | fn takes_ref(_: &Foo) {}
+   |    ^^^^^^^^^ -------
+
+error[E0308]: mismatched types
+  --> $DIR/as-ref.rs:26:53
+   |
+LL |     multiple_ref_result.and_then(|arg| Ok(takes_ref(arg)));
+   |                         --------          --------- ^^^ expected `&Foo`, found struct `Foo`
+   |                         |                 |
+   |                         |                 arguments to this function are incorrect
+   |                         help: consider using `as_ref` instead: `as_ref().and_then`
+   |
+note: function defined here
+  --> $DIR/as-ref.rs:3:4
+   |
+LL | fn takes_ref(_: &Foo) {}
+   |    ^^^^^^^^^ -------
+
+error: aborting due to 11 previous errors
 
 For more information about this error, try `rustc --explain E0308`.