From 12804230a25d4f996f4738de20c161d95df4933b Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 30 Jul 2021 19:04:16 +0200 Subject: [PATCH 1/7] Properly find owner of closure in THIR unsafeck Co-authored-by: FabianWolff --- compiler/rustc_mir_build/src/check_unsafety.rs | 11 ++++------- src/test/ui/unsafe/issue-87414-query-cycle.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/unsafe/issue-87414-query-cycle.rs diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 21534290d1291..d27ce6ec81a90 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -599,13 +599,10 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam() -> Box> { todo!() } + +fn foo() -> [(); { |x: u32| { x }; 4 }] { todo!() } +fn bar() { let _: [(); { |x: u32| { x }; 4 }]; } + +// This one should not cause any errors either: +unsafe fn unsf() {} +fn bad2() -> Box> { todo!() } + +fn main() {} From d2d851949bab4c96b54d11126a0efd1826557d3f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 31 Jul 2021 06:09:54 +0900 Subject: [PATCH 2/7] Fix a parser ICE on invalid `fn` body --- compiler/rustc_parse/src/parser/item.rs | 4 +--- src/test/ui/parser/issue-87635.rs | 9 +++++++++ src/test/ui/parser/issue-87635.stderr | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/parser/issue-87635.rs create mode 100644 src/test/ui/parser/issue-87635.stderr diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 2ce63d011f438..1e4bc49cb39cb 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1715,13 +1715,11 @@ impl<'a> Parser<'a> { // the AST for typechecking. err.span_label(ident.span, "while parsing this `fn`"); err.emit(); - (Vec::new(), None) } else { return Err(err); } - } else { - unreachable!() } + (Vec::new(), None) }; attrs.extend(inner_attrs); Ok(body) diff --git a/src/test/ui/parser/issue-87635.rs b/src/test/ui/parser/issue-87635.rs new file mode 100644 index 0000000000000..da74c1877b165 --- /dev/null +++ b/src/test/ui/parser/issue-87635.rs @@ -0,0 +1,9 @@ +struct Foo {} + +impl Foo { + pub fn bar() + //~^ ERROR: expected `;`, found `}` + //~| ERROR: associated function in `impl` without body +} + +fn main() {} diff --git a/src/test/ui/parser/issue-87635.stderr b/src/test/ui/parser/issue-87635.stderr new file mode 100644 index 0000000000000..920a9f937dd6b --- /dev/null +++ b/src/test/ui/parser/issue-87635.stderr @@ -0,0 +1,19 @@ +error: expected `;`, found `}` + --> $DIR/issue-87635.rs:4:17 + | +LL | pub fn bar() + | ^ help: add `;` here +... +LL | } + | - unexpected token + +error: associated function in `impl` without body + --> $DIR/issue-87635.rs:4:5 + | +LL | pub fn bar() + | ^^^^^^^^^^^- + | | + | help: provide a definition for the function: `{ }` + +error: aborting due to 2 previous errors + From 7954a76a588e86326830b8ae7a24a19504d0aaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sun, 1 Aug 2021 13:12:21 +0200 Subject: [PATCH 3/7] Update stacker and psm crates --- Cargo.lock | 10 +++++----- compiler/rustc_data_structures/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7c180012e08a..abc05e565d320 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2733,9 +2733,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e0536f6528466dbbbbe6b986c34175a8d0ff25b794c4bacda22e068cd2f2c5" +checksum = "14ce37fa8c0428a37307d163292add09b3aedc003472e6b3622486878404191d" dependencies = [ "cc", ] @@ -4810,12 +4810,12 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stacker" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ccb4c06ec57bc82d0f610f1a2963d7648700e43a6f513e564b9c89f7991786" +checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" dependencies = [ "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "psm", "winapi", diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 112b94f6e0ebc..ba7587cf7f60e 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -26,7 +26,7 @@ rustc_index = { path = "../rustc_index", package = "rustc_index" } bitflags = "1.2.1" measureme = "9.1.0" libc = "0.2" -stacker = "0.1.12" +stacker = "0.1.14" tempfile = "3.2" [dependencies.parking_lot] From e0172b380d8260883ddecc060996ea6f5441c54c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 1 Aug 2021 14:37:38 -0700 Subject: [PATCH 4/7] Write docs for SyncOnceCell From and Default impl --- library/std/src/lazy.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index ca86e569bc127..132733a052510 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -87,6 +87,19 @@ impl UnwindSafe for SyncOnceCell {} #[unstable(feature = "once_cell", issue = "74465")] impl Default for SyncOnceCell { + /// Creates a new empty cell. + /// + /// # Example + /// + /// ``` + /// #![feature(once_cell)] + /// + /// use std::lazy::SyncOnceCell; + /// + /// fn main() { + /// assert_eq!(SyncOnceCell::<()>::new(), SyncOnceCell::default()); + /// } + /// ``` fn default() -> SyncOnceCell { SyncOnceCell::new() } @@ -118,6 +131,23 @@ impl Clone for SyncOnceCell { #[unstable(feature = "once_cell", issue = "74465")] impl From for SyncOnceCell { + /// Create a new cell with its contents set to `value`. + /// + /// # Example + /// + /// ``` + /// #![feature(once_cell)] + /// + /// use std::lazy::SyncOnceCell; + /// + /// # fn main() -> Result<(), i32> { + /// let a = SyncOnceCell::from(3); + /// let b = SyncOnceCell::new(); + /// b.set(3)?; + /// assert_eq!(a, b); + /// Ok(()) + /// # } + /// ``` fn from(value: T) -> Self { let cell = Self::new(); match cell.set(value) { From 28382ff2c881577ee39c2a5259a074f5b28729ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 2 Aug 2021 09:32:09 +0300 Subject: [PATCH 5/7] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index ea105f9396a9d..df0936b4af7bd 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit ea105f9396a9dab68e71efb06016b7c76c83ba7c +Subproject commit df0936b4af7bd573dc8906b6dbdbf80ff40b75f3 From a43c464acf648e69e57e31203859797f50e53ec7 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Mon, 2 Aug 2021 10:28:33 +0200 Subject: [PATCH 6/7] Add `aarch64-apple-ios-sim` as a possible target to the manifest This should allow rustup and similar to actually make use of this new target now. --- src/tools/build-manifest/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 1e19b7b21d8bf..ab63a9e2dfa0b 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -54,6 +54,7 @@ static HOSTS: &[&str] = &[ static TARGETS: &[&str] = &[ "aarch64-apple-darwin", "aarch64-apple-ios", + "aarch64-apple-ios-sim", "aarch64-fuchsia", "aarch64-linux-android", "aarch64-pc-windows-msvc", From a5cdff3bd42e82f58de45dd49d468a6d4c54b54b Mon Sep 17 00:00:00 2001 From: The8472 Date: Mon, 2 Aug 2021 20:28:31 +0200 Subject: [PATCH 7/7] Add convenience for handling ipv4-mapped addresses by canonicalizing them This simplifies checking common properties in an address-family-agnostic way since since #86335 commits to not checking IPv4 semantics of IPv4-mapped addresses in the `Ipv6Addr` property methods. --- library/std/src/net/ip.rs | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 88309875978e2..2108c62b4cdf4 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -291,6 +291,29 @@ impl IpAddr { pub const fn is_ipv6(&self) -> bool { matches!(self, IpAddr::V6(_)) } + + /// Converts this address to an `IpAddr::V4` if it is a IPv4-mapped IPv6 addresses, otherwise it + /// return `self` as-is. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip)] + /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; + /// + /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true); + /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false); + /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true); + /// ``` + #[inline] + #[rustc_const_unstable(feature = "const_ip", issue = "76205")] + #[unstable(feature = "ip", issue = "27709")] + pub const fn to_canonical(&self) -> IpAddr { + match self { + &v4 @ IpAddr::V4(_) => v4, + IpAddr::V6(v6) => v6.to_canonical(), + } + } } impl Ipv4Addr { @@ -1532,6 +1555,28 @@ impl Ipv6Addr { } } + /// Converts this address to an `IpAddr::V4` if it is a IPv4-mapped addresses, otherwise it + /// returns self wrapped in a `IpAddr::V6`. + /// + /// # Examples + /// + /// ``` + /// #![feature(ip)] + /// use std::net::Ipv6Addr; + /// + /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false); + /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).to_canonical().is_loopback(), true); + /// ``` + #[inline] + #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] + #[unstable(feature = "ip", issue = "27709")] + pub const fn to_canonical(&self) -> IpAddr { + if let Some(mapped) = self.to_ipv4_mapped() { + return IpAddr::V4(mapped); + } + IpAddr::V6(*self) + } + /// Returns the sixteen eight-bit integers the IPv6 address consists of. /// /// ```