From 4afea69090b5501c17b16957d090658a1b3c2216 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 10 Apr 2021 23:22:58 +0300 Subject: [PATCH 1/8] Allow setting `target_family` to multiple values This enables us to set more generic labels shared between targets. For example `target_family="wasm"` across all targets that are conceptually "wasm". See https://github.com/rust-lang/reference/pull/1006 --- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_target/src/spec/apple_base.rs | 2 +- .../rustc_target/src/spec/dragonfly_base.rs | 2 +- .../rustc_target/src/spec/freebsd_base.rs | 2 +- .../rustc_target/src/spec/fuchsia_base.rs | 2 +- compiler/rustc_target/src/spec/haiku_base.rs | 2 +- .../rustc_target/src/spec/illumos_base.rs | 2 +- compiler/rustc_target/src/spec/l4re_base.rs | 2 +- compiler/rustc_target/src/spec/linux_base.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 32 +++++++++++-------- compiler/rustc_target/src/spec/netbsd_base.rs | 2 +- .../rustc_target/src/spec/openbsd_base.rs | 2 +- compiler/rustc_target/src/spec/redox_base.rs | 2 +- .../rustc_target/src/spec/solaris_base.rs | 2 +- .../rustc_target/src/spec/vxworks_base.rs | 2 +- .../src/spec/wasm32_unknown_emscripten.rs | 2 +- .../rustc_target/src/spec/windows_gnu_base.rs | 2 +- .../src/spec/windows_msvc_base.rs | 2 +- 18 files changed, 36 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b6b349e4a803d..ad26c73162c90 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -813,7 +813,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig { ret.reserve(6); // the minimum number of insertions // Target bindings. ret.insert((sym::target_os, Some(Symbol::intern(os)))); - if let Some(ref fam) = sess.target.os_family { + for fam in &sess.target.families { ret.insert((sym::target_family, Some(Symbol::intern(fam)))); if fam == "windows" { ret.insert((sym::windows, None)); diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index 6fa0b34545097..bc2ec6709011a 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -23,7 +23,7 @@ pub fn opts(os: &str) -> TargetOptions { function_sections: false, dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_osx: true, dwarf_version: Some(2), has_rpath: true, diff --git a/compiler/rustc_target/src/spec/dragonfly_base.rs b/compiler/rustc_target/src/spec/dragonfly_base.rs index dd0170987824a..fb94498c131fd 100644 --- a/compiler/rustc_target/src/spec/dragonfly_base.rs +++ b/compiler/rustc_target/src/spec/dragonfly_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "dragonfly".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/freebsd_base.rs b/compiler/rustc_target/src/spec/freebsd_base.rs index ad3383cc5f261..5d3c28e5f29c9 100644 --- a/compiler/rustc_target/src/spec/freebsd_base.rs +++ b/compiler/rustc_target/src/spec/freebsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "freebsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/fuchsia_base.rs b/compiler/rustc_target/src/spec/fuchsia_base.rs index 2b925f8b946c4..13264dffeb4ed 100644 --- a/compiler/rustc_target/src/spec/fuchsia_base.rs +++ b/compiler/rustc_target/src/spec/fuchsia_base.rs @@ -25,7 +25,7 @@ pub fn opts() -> TargetOptions { linker: Some("rust-lld".to_owned()), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_fuchsia: true, linker_is_gnu: true, pre_link_args, diff --git a/compiler/rustc_target/src/spec/haiku_base.rs b/compiler/rustc_target/src/spec/haiku_base.rs index 956e4ed4bf9c8..fae56f6a82dc8 100644 --- a/compiler/rustc_target/src/spec/haiku_base.rs +++ b/compiler/rustc_target/src/spec/haiku_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "haiku".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], relro_level: RelroLevel::Full, linker_is_gnu: true, ..Default::default() diff --git a/compiler/rustc_target/src/spec/illumos_base.rs b/compiler/rustc_target/src/spec/illumos_base.rs index d9b5716c04185..2e365d210f3f6 100644 --- a/compiler/rustc_target/src/spec/illumos_base.rs +++ b/compiler/rustc_target/src/spec/illumos_base.rs @@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this eliminate_frame_pointer: false, diff --git a/compiler/rustc_target/src/spec/l4re_base.rs b/compiler/rustc_target/src/spec/l4re_base.rs index db6b74eff6dbd..65c343a5f2169 100644 --- a/compiler/rustc_target/src/spec/l4re_base.rs +++ b/compiler/rustc_target/src/spec/l4re_base.rs @@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions { executables: true, panic_strategy: PanicStrategy::Abort, linker: Some("ld".to_string()), - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/linux_base.rs b/compiler/rustc_target/src/spec/linux_base.rs index eeefd056e4b74..184659e22d986 100644 --- a/compiler/rustc_target/src/spec/linux_base.rs +++ b/compiler/rustc_target/src/spec/linux_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "linux".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 57b0a36e009ef..2223237143b8f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1042,8 +1042,12 @@ pub struct TargetOptions { pub staticlib_prefix: String, /// String to append to the name of every static library. Defaults to ".a". pub staticlib_suffix: String, - /// OS family to use for conditional compilation. Valid options: "unix", "windows". - pub os_family: Option, + /// Values of the `target_family` cfg set for this target. + /// + /// Common options are: "unix", "windows". Defaults to no families. + /// + /// See https://doc.rust-lang.org/reference/conditional-compilation.html#target_family + pub families: Vec, /// Whether the target toolchain's ABI supports returning small structs as an integer. pub abi_return_struct_as_int: bool, /// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS, @@ -1293,7 +1297,7 @@ impl Default for TargetOptions { exe_suffix: String::new(), staticlib_prefix: "lib".to_string(), staticlib_suffix: ".a".to_string(), - os_family: None, + families: Vec::new(), abi_return_struct_as_int: false, is_like_osx: false, is_like_solaris: false, @@ -1605,14 +1609,6 @@ impl Target { .map(|s| s.to_string() ); } } ); - ($key_name:ident = $json_name:expr, optional) => ( { - let name = $json_name; - if let Some(o) = obj.find(name) { - base.$key_name = o - .as_string() - .map(|s| s.to_string() ); - } - } ); ($key_name:ident, LldFlavor) => ( { let name = (stringify!($key_name)).replace("_", "-"); obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { @@ -1759,6 +1755,16 @@ impl Target { Some(Ok(())) })).unwrap_or(Ok(())) } ); + ($key_name:ident, TargetFamilies) => ( { + let value = obj.find("target-family"); + if let Some(v) = value.and_then(Json::as_array) { + base.$key_name = v.iter() + .map(|a| a.as_string().unwrap().to_string()) + .collect(); + } else if let Some(v) = value.and_then(Json::as_string) { + base.$key_name = vec![v.to_string()]; + } + } ); } if let Some(s) = obj.find("target-endian").and_then(Json::as_string) { @@ -1802,7 +1808,7 @@ impl Target { key!(exe_suffix); key!(staticlib_prefix); key!(staticlib_suffix); - key!(os_family = "target-family", optional); + key!(families, TargetFamilies); key!(abi_return_struct_as_int, bool); key!(is_like_osx, bool); key!(is_like_solaris, bool); @@ -2042,7 +2048,7 @@ impl ToJson for Target { target_option_val!(exe_suffix); target_option_val!(staticlib_prefix); target_option_val!(staticlib_suffix); - target_option_val!(os_family, "target-family"); + target_option_val!(families, "target-family"); target_option_val!(abi_return_struct_as_int); target_option_val!(is_like_osx); target_option_val!(is_like_solaris); diff --git a/compiler/rustc_target/src/spec/netbsd_base.rs b/compiler/rustc_target/src/spec/netbsd_base.rs index 680cd60788bde..602fb6eb6413b 100644 --- a/compiler/rustc_target/src/spec/netbsd_base.rs +++ b/compiler/rustc_target/src/spec/netbsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "netbsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, no_default_libraries: false, has_rpath: true, diff --git a/compiler/rustc_target/src/spec/openbsd_base.rs b/compiler/rustc_target/src/spec/openbsd_base.rs index a6fd01ab110df..8f33bacd9228e 100644 --- a/compiler/rustc_target/src/spec/openbsd_base.rs +++ b/compiler/rustc_target/src/spec/openbsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "openbsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, abi_return_struct_as_int: true, diff --git a/compiler/rustc_target/src/spec/redox_base.rs b/compiler/rustc_target/src/spec/redox_base.rs index 0afb4a72ac14f..72052b9e2e2e3 100644 --- a/compiler/rustc_target/src/spec/redox_base.rs +++ b/compiler/rustc_target/src/spec/redox_base.rs @@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions { env: "relibc".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/solaris_base.rs b/compiler/rustc_target/src/spec/solaris_base.rs index 59731f25821ff..4c922eb5cea55 100644 --- a/compiler/rustc_target/src/spec/solaris_base.rs +++ b/compiler/rustc_target/src/spec/solaris_base.rs @@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this eh_frame_header: false, diff --git a/compiler/rustc_target/src/spec/vxworks_base.rs b/compiler/rustc_target/src/spec/vxworks_base.rs index 41c4d7625af2a..0e8e87f2dff5c 100644 --- a/compiler/rustc_target/src/spec/vxworks_base.rs +++ b/compiler/rustc_target/src/spec/vxworks_base.rs @@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions { exe_suffix: ".vxe".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, has_elf_tls: true, diff --git a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs index e028dbaa32520..ddf28b423f0d2 100644 --- a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs +++ b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs @@ -38,7 +38,7 @@ pub fn target() -> Target { is_like_emscripten: true, panic_strategy: PanicStrategy::Unwind, post_link_args, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], ..options }; Target { diff --git a/compiler/rustc_target/src/spec/windows_gnu_base.rs b/compiler/rustc_target/src/spec/windows_gnu_base.rs index 478c567a93b25..35a52896f6fa6 100644 --- a/compiler/rustc_target/src/spec/windows_gnu_base.rs +++ b/compiler/rustc_target/src/spec/windows_gnu_base.rs @@ -71,7 +71,7 @@ pub fn opts() -> TargetOptions { dll_prefix: String::new(), dll_suffix: ".dll".to_string(), exe_suffix: ".exe".to_string(), - os_family: Some("windows".to_string()), + families: vec!["windows".to_string()], is_like_windows: true, allows_weak_linkage: false, pre_link_args, diff --git a/compiler/rustc_target/src/spec/windows_msvc_base.rs b/compiler/rustc_target/src/spec/windows_msvc_base.rs index c041245e32862..0d58618a449a9 100644 --- a/compiler/rustc_target/src/spec/windows_msvc_base.rs +++ b/compiler/rustc_target/src/spec/windows_msvc_base.rs @@ -13,7 +13,7 @@ pub fn opts() -> TargetOptions { exe_suffix: ".exe".to_string(), staticlib_prefix: String::new(), staticlib_suffix: ".lib".to_string(), - os_family: Some("windows".to_string()), + families: vec!["windows".to_string()], crt_static_allows_dylibs: true, crt_static_respected: true, requires_uwtable: true, From dfe3c3cd46dc1dfa0bf297730fcf100f74153fbf Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 10 Apr 2021 23:28:58 +0300 Subject: [PATCH 2/8] Set target_family="wasm" for wasm targets --- compiler/rustc_target/src/spec/wasm_base.rs | 1 + src/test/ui/cfg/cfg-family.rs | 4 ++-- src/test/ui/cfg/cfg-target-family.rs | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_target/src/spec/wasm_base.rs b/compiler/rustc_target/src/spec/wasm_base.rs index b208eb92f8ff9..87e740de08e91 100644 --- a/compiler/rustc_target/src/spec/wasm_base.rs +++ b/compiler/rustc_target/src/spec/wasm_base.rs @@ -61,6 +61,7 @@ pub fn options() -> TargetOptions { TargetOptions { is_like_wasm: true, + families: vec!["wasm".to_string()], // we allow dynamic linking, but only cdylibs. Basically we allow a // final library artifact that exports some symbols (a wasm module) but diff --git a/src/test/ui/cfg/cfg-family.rs b/src/test/ui/cfg/cfg-family.rs index 912bda4b5e500..c7d196a2aa6eb 100644 --- a/src/test/ui/cfg/cfg-family.rs +++ b/src/test/ui/cfg/cfg-family.rs @@ -1,6 +1,6 @@ -// run-pass +// build-pass // pretty-expanded FIXME #23616 -// ignore-wasm32-bare no target_family +// ignore-wasm32-bare no bare family // ignore-sgx #[cfg(windows)] diff --git a/src/test/ui/cfg/cfg-target-family.rs b/src/test/ui/cfg/cfg-target-family.rs index b4dc1b738638c..90a59fab8e250 100644 --- a/src/test/ui/cfg/cfg-target-family.rs +++ b/src/test/ui/cfg/cfg-target-family.rs @@ -1,5 +1,4 @@ -// run-pass -// ignore-wasm32-bare no target_family +// build-pass // ignore-sgx // pretty-expanded FIXME #23616 @@ -11,3 +10,7 @@ pub fn main() { #[cfg(target_family = "unix")] pub fn main() { } + +#[cfg(target_family="wasm")] +pub fn main() { +} From b9a1e693a77b626aade2cc95f549b4b6e6029097 Mon Sep 17 00:00:00 2001 From: Johannes Schilling Date: Wed, 21 Apr 2021 14:09:15 +0200 Subject: [PATCH 3/8] Make AssertKind::fmt_assert_args public --- compiler/rustc_middle/src/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 998868211401f..291ac0118a6cf 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1340,7 +1340,7 @@ impl AssertKind { } /// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing. - fn fmt_assert_args(&self, f: &mut W) -> fmt::Result + pub fn fmt_assert_args(&self, f: &mut W) -> fmt::Result where O: Debug, { From cf46fb1945ac51048b327a84a0b23ae9ec82b35a Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 27 Apr 2021 21:18:01 -0500 Subject: [PATCH 4/8] unignore a couple of tests --- src/test/ui/or-patterns/macro-pat.rs | 2 -- src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/test/ui/or-patterns/macro-pat.rs b/src/test/ui/or-patterns/macro-pat.rs index 8c581b630dece..806d1901702ff 100644 --- a/src/test/ui/or-patterns/macro-pat.rs +++ b/src/test/ui/or-patterns/macro-pat.rs @@ -1,7 +1,5 @@ // run-pass // edition:2021 -// ignore-test -// FIXME(mark-i-m): enable this test again when 2021 machinery is available use Foo::*; diff --git a/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs b/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs index f0ce7597aeed1..c0d148d92042f 100644 --- a/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs +++ b/src/test/ui/or-patterns/or-patterns-syntactic-pass-2021.rs @@ -1,9 +1,7 @@ // Tests that :pat in macros in edition 2021 allows top-level or-patterns. // run-pass -// ignore-test // edition:2021 -// FIXME(mark-i-m): unignore when 2021 machinery is in place. macro_rules! accept_pat { ($p:pat) => {}; From 6697b0d0f61ececf381800e14b4a6720e36e98b9 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 28 Apr 2021 20:51:32 -0500 Subject: [PATCH 5/8] fix test --- src/test/ui/or-patterns/macro-pat.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/or-patterns/macro-pat.rs b/src/test/ui/or-patterns/macro-pat.rs index 806d1901702ff..20d8f84c24743 100644 --- a/src/test/ui/or-patterns/macro-pat.rs +++ b/src/test/ui/or-patterns/macro-pat.rs @@ -3,6 +3,7 @@ use Foo::*; +#[allow(dead_code)] #[derive(Eq, PartialEq, Debug)] enum Foo { A(u64), From c064b6560b7ce0adeb9bbf5d7dcf12b1acb0c807 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Thu, 29 Apr 2021 16:15:50 +0000 Subject: [PATCH 6/8] [Arm64] use isb instruction instead of yield in spin loops On arm64 we have seen on several databases that ISB (instruction synchronization barrier) is better to use than yield in a spin loop. The yield instruction is a nop. The isb instruction puts the processor to sleep for some short time. isb is a good equivalent to the pause instruction on x86. Below is an experiment that shows the effects of yield and isb on Arm64 and the time of a pause instruction on x86 Intel processors. The micro-benchmarks use https://github.com/google/benchmark.git $ cat a.cc static void BM_scalar_increment(benchmark::State& state) { int i = 0; for (auto _ : state) benchmark::DoNotOptimize(i++); } BENCHMARK(BM_scalar_increment); static void BM_yield(benchmark::State& state) { for (auto _ : state) asm volatile("yield"::); } BENCHMARK(BM_yield); static void BM_isb(benchmark::State& state) { for (auto _ : state) asm volatile("isb"::); } BENCHMARK(BM_isb); BENCHMARK_MAIN(); $ g++ -o run a.cc -O2 -lbenchmark -lpthread $ ./run -------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------- AWS Graviton2 (Neoverse-N1) processor: BM_scalar_increment 0.485 ns 0.485 ns 1000000000 BM_yield 0.400 ns 0.400 ns 1000000000 BM_isb 13.2 ns 13.2 ns 52993304 AWS Graviton (A-72) processor: BM_scalar_increment 0.897 ns 0.874 ns 801558633 BM_yield 0.877 ns 0.875 ns 800002377 BM_isb 13.0 ns 12.7 ns 55169412 Apple Arm64 M1 processor: BM_scalar_increment 0.315 ns 0.315 ns 1000000000 BM_yield 0.313 ns 0.313 ns 1000000000 BM_isb 9.06 ns 9.06 ns 77259282 static void BM_pause(benchmark::State& state) { for (auto _ : state) asm volatile("pause"::); } BENCHMARK(BM_pause); Intel Skylake processor: BM_scalar_increment 0.295 ns 0.295 ns 1000000000 BM_pause 41.7 ns 41.7 ns 16780553 Tested on Graviton2 aarch64-linux with `./x.py test`. --- library/core/src/hint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 313729581acd9..8e7c95abd6872 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -128,7 +128,7 @@ pub fn spin_loop() { #[cfg(target_arch = "aarch64")] { // SAFETY: the `cfg` attr ensures that we only execute this on aarch64 targets. - unsafe { crate::arch::aarch64::__yield() }; + unsafe { crate::arch::aarch64::__isb(crate::arch::aarch64::SY) }; } #[cfg(target_arch = "arm")] { From 49e67c393d4706f05f256d87551ea60dc40f20ee Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 30 Apr 2021 13:04:43 -0700 Subject: [PATCH 7/8] Update compiler-builtins to 0.1.41 to get fix for outlined atomics This should fix linking of other C code (and soon Rust-generated code) on aarch64 musl. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a55ef7b61436e..f7075cafb5e2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -666,9 +666,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3748f82c7d366a0b4950257d19db685d4958d2fa27c6d164a3f069fec42b748b" +checksum = "68448b4c6cee41f17bef42cbdad2fde55d05b91a6116c3a517e5389fb742758d" dependencies = [ "cc", "rustc-std-workspace-core", From 39054339c17f283cdb34183cc615a448baa108a3 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 1 May 2021 18:35:56 +0100 Subject: [PATCH 8/8] test: *sneezes* --- compiler/rustc_typeck/src/astconv/generics.rs | 6 ++--- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 16 +++++++++----- .../ui/const-generics/issues/issue-83466.rs | 17 ++++++++++++++ .../const-generics/issues/issue-83466.stderr | 22 +++++++++++++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/const-generics/issues/issue-83466.rs create mode 100644 src/test/ui/const-generics/issues/issue-83466.stderr diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 7a297f2c65f13..a4b3652d21450 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -264,9 +264,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // another. This is an error. However, if we already know that // the arguments don't match up with the parameters, we won't issue // an additional error, as the user already knows what's wrong. - if arg_count.correct.is_ok() - && arg_count.explicit_late_bound == ExplicitLateBound::No - { + if arg_count.correct.is_ok() { // We're going to iterate over the parameters to sort them out, and // show that order to the user as a possible order for the parameters let mut param_types_present = defs @@ -446,7 +444,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } if silent { - return false; + return true; } if provided > expected_max { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 9ace455042103..ded6f901e77c4 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1282,6 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut infer_args_for_err = FxHashSet::default(); + let mut explicit_late_bound = ExplicitLateBound::No; for &PathSeg(def_id, index) in &path_segs { let seg = &segments[index]; let generics = tcx.generics_of(def_id); @@ -1290,17 +1291,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // parameter internally, but we don't allow users to specify the // parameter's value explicitly, so we have to do some error- // checking here. - if let GenericArgCountResult { - correct: Err(GenericArgCountMismatch { reported: Some(_), .. }), - .. - } = >::check_generic_arg_count_for_call( + let arg_count = >::check_generic_arg_count_for_call( tcx, span, def_id, &generics, seg, IsMethodCall::No, - ) { + ); + + if let ExplicitLateBound::Yes = arg_count.explicit_late_bound { + explicit_late_bound = ExplicitLateBound::Yes; + } + + if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct { infer_args_for_err.insert(index); self.set_tainted_by_errors(); // See issue #53251. } @@ -1357,7 +1361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = tcx.type_of(def_id); let arg_count = GenericArgCountResult { - explicit_late_bound: ExplicitLateBound::No, + explicit_late_bound, correct: if infer_args_for_err.is_empty() { Ok(()) } else { diff --git a/src/test/ui/const-generics/issues/issue-83466.rs b/src/test/ui/const-generics/issues/issue-83466.rs new file mode 100644 index 0000000000000..c488a663fbb00 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83466.rs @@ -0,0 +1,17 @@ +// regression test for #83466- tests that generic arg mismatch errors between +// consts and types are not supressed when there are explicit late bound lifetimes + +struct S; +impl S { + fn func<'a, U>(self) -> U { + todo!() + } +} +fn dont_crash<'a, U>() { + S.func::<'a, 10_u32>() + //~^ WARNING cannot specify lifetime arguments explicitly if late bound lifetime parameters are present + //~^^ WARNING this was previously accepted by + //~^^^ ERROR constant provided when a type was expected [E0747] +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83466.stderr b/src/test/ui/const-generics/issues/issue-83466.stderr new file mode 100644 index 0000000000000..a60f71ea61420 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83466.stderr @@ -0,0 +1,22 @@ +warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present + --> $DIR/issue-83466.rs:11:14 + | +LL | fn func<'a, U>(self) -> U { + | -- the late bound lifetime parameter is introduced here +... +LL | S.func::<'a, 10_u32>() + | ^^ + | + = note: `#[warn(late_bound_lifetime_arguments)]` 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 #42868 + +error[E0747]: constant provided when a type was expected + --> $DIR/issue-83466.rs:11:18 + | +LL | S.func::<'a, 10_u32>() + | ^^^^^^ + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0747`.