From b68b3965a241e47c232613f403fbace64fd8b876 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 3 Aug 2018 10:19:22 +0200 Subject: [PATCH 01/57] Don't collect() when size_hint is useless --- src/librustc/infer/outlives/obligations.rs | 12 +++++++----- src/librustc_data_structures/small_vec.rs | 7 ++++++- src/libsyntax/ast.rs | 6 +++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index c74783f5e4db5..3598d66060bf2 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -151,12 +151,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { debug!("process_registered_region_obligations()"); // pull out the region obligations with the given `body_id` (leaving the rest) - let my_region_obligations = { + let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len()); + { let mut r_o = self.region_obligations.borrow_mut(); - let my_r_o = r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id) - .map(|(_, obligation)| obligation).collect::>(); - my_r_o - }; + my_region_obligations.extend( + r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id) + .map(|(_, obligation)| obligation) + ); + } let outlives = &mut TypeOutlives::new( self, diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs index 76b01beb4bad3..e958fd7da613e 100644 --- a/src/librustc_data_structures/small_vec.rs +++ b/src/librustc_data_structures/small_vec.rs @@ -210,7 +210,12 @@ impl Decodable for SmallVec A::Element: Decodable { fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { - (0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect() + let mut vec = SmallVec::with_capacity(len); + // FIXME(#48994) - could just be collected into a Result + for i in 0..len { + vec.push(d.read_seq_elt(i, |d| Decodable::decode(d))?); + } + Ok(vec) }) } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 28c1e4324de7a..6925ed2afb83b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -501,7 +501,11 @@ impl Pat { PatKind::Slice(pats, None, _) if pats.len() == 1 => pats[0].to_ty().map(TyKind::Slice)?, PatKind::Tuple(pats, None) => { - let tys = pats.iter().map(|pat| pat.to_ty()).collect::>>()?; + let mut tys = Vec::with_capacity(pats.len()); + // FIXME(#48994) - could just be collected into an Option + for pat in pats { + tys.push(pat.to_ty()?); + } TyKind::Tup(tys) } _ => return None, From 1667950d732bdeb9181fb34b247fc72751255b6f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sat, 4 Aug 2018 14:31:03 +0200 Subject: [PATCH 02/57] Remove explicit returns where unnecessary --- src/libcore/alloc.rs | 10 +++++----- src/libcore/char/mod.rs | 4 ++-- src/libcore/ptr.rs | 4 ++-- src/libcore/slice/mod.rs | 20 ++++++++++---------- src/libcore/str/lossy.rs | 2 +- src/libcore/str/mod.rs | 2 +- src/tools/remote-test-server/src/main.rs | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 39ec5d6411c16..35e4eea756d41 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -217,7 +217,7 @@ impl Layout { let len_rounded_up = len.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1); - return len_rounded_up.wrapping_sub(len); + len_rounded_up.wrapping_sub(len) } /// Creates a layout describing the record for `n` instances of @@ -971,9 +971,9 @@ pub unsafe trait Alloc { // _l <= layout.size() [guaranteed by usable_size()] // layout.size() <= new_layout.size() [required by this method] if new_size <= u { - return Ok(()); + Ok(()) } else { - return Err(CannotReallocInPlace); + Err(CannotReallocInPlace) } } @@ -1026,9 +1026,9 @@ pub unsafe trait Alloc { // layout.size() <= _u [guaranteed by usable_size()] // new_layout.size() <= layout.size() [required by this method] if l <= new_size { - return Ok(()); + Ok(()) } else { - return Err(CannotReallocInPlace); + Err(CannotReallocInPlace) } } diff --git a/src/libcore/char/mod.rs b/src/libcore/char/mod.rs index 5be673db3200d..7e1313747eef2 100644 --- a/src/libcore/char/mod.rs +++ b/src/libcore/char/mod.rs @@ -312,8 +312,8 @@ impl Iterator for EscapeDefault { None } }, - EscapeDefaultState::Done => return None, - EscapeDefaultState::Unicode(ref mut i) => return i.nth(n), + EscapeDefaultState::Done => None, + EscapeDefaultState::Unicode(ref mut i) => i.nth(n), } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 479c10c4ffbae..99d93d5687a1c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2288,7 +2288,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { let table_inverse = INV_TABLE_MOD_16[(x & (INV_TABLE_MOD - 1)) >> 1]; if m <= INV_TABLE_MOD { - return table_inverse & (m - 1); + table_inverse & (m - 1) } else { // We iterate "up" using the following formula: // @@ -2375,7 +2375,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { } // Cannot be aligned at all. - return usize::max_value(); + usize::max_value() } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index a4dde38cb7bb6..490a11ac598bc 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1727,7 +1727,7 @@ impl [T] { ctz_b = ::intrinsics::cttz_nonzero(b); } } - return a << k; + a << k } let gcd: usize = gcd(::mem::size_of::(), ::mem::size_of::()); let ts: usize = ::mem::size_of::() / gcd; @@ -1737,7 +1737,7 @@ impl [T] { let us_len = self.len() / ts * us; // And how many `T`s will be in the trailing slice! let ts_len = self.len() % ts; - return (us_len, ts_len); + (us_len, ts_len) } /// Transmute the slice to a slice of another type, ensuring aligment of the types is @@ -1782,13 +1782,13 @@ impl [T] { let ptr = self.as_ptr(); let offset = ::ptr::align_offset(ptr, ::mem::align_of::()); if offset > self.len() { - return (self, &[], &[]); + (self, &[], &[]) } else { let (left, rest) = self.split_at(offset); let (us_len, ts_len) = rest.align_to_offsets::(); - return (left, - from_raw_parts(rest.as_ptr() as *const U, us_len), - from_raw_parts(rest.as_ptr().offset((rest.len() - ts_len) as isize), ts_len)) + (left, + from_raw_parts(rest.as_ptr() as *const U, us_len), + from_raw_parts(rest.as_ptr().offset((rest.len() - ts_len) as isize), ts_len)) } } @@ -1834,14 +1834,14 @@ impl [T] { let ptr = self.as_ptr(); let offset = ::ptr::align_offset(ptr, ::mem::align_of::()); if offset > self.len() { - return (self, &mut [], &mut []); + (self, &mut [], &mut []) } else { let (left, rest) = self.split_at_mut(offset); let (us_len, ts_len) = rest.align_to_offsets::(); let mut_ptr = rest.as_mut_ptr(); - return (left, - from_raw_parts_mut(mut_ptr as *mut U, us_len), - from_raw_parts_mut(mut_ptr.offset((rest.len() - ts_len) as isize), ts_len)) + (left, + from_raw_parts_mut(mut_ptr as *mut U, us_len), + from_raw_parts_mut(mut_ptr.offset((rest.len() - ts_len) as isize), ts_len)) } } } diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs index 5cfb36d3b195b..186d6adbc91cf 100644 --- a/src/libcore/str/lossy.rs +++ b/src/libcore/str/lossy.rs @@ -146,7 +146,7 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> { broken: &[], }; self.source = &[]; - return Some(r); + Some(r) } } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 86b8349fa3c89..b541e627ee3d7 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1567,7 +1567,7 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [ #[unstable(feature = "str_internals", issue = "0")] #[inline] pub fn utf8_char_width(b: u8) -> usize { - return UTF8_CHAR_WIDTH[b as usize] as usize; + UTF8_CHAR_WIDTH[b as usize] as usize } /// Mask of the value bits of a continuation byte. diff --git a/src/tools/remote-test-server/src/main.rs b/src/tools/remote-test-server/src/main.rs index 5116f6662ff4d..9501adb938616 100644 --- a/src/tools/remote-test-server/src/main.rs +++ b/src/tools/remote-test-server/src/main.rs @@ -267,7 +267,7 @@ fn recv(dir: &Path, io: &mut B) -> PathBuf { t!(io::copy(&mut io.take(amt), &mut t!(File::create(&dst)))); t!(fs::set_permissions(&dst, Permissions::from_mode(0o755))); - return dst + dst } fn my_copy(src: &mut dyn Read, which: u8, dst: &Mutex) { From 1dd53f73b2774370ac40954c3831f8d5f534e773 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Kollasch" Date: Sat, 4 Aug 2018 16:53:52 -0500 Subject: [PATCH 03/57] Add aarch64-unknown-netbsd target --- .../spec/aarch64_unknown_netbsd.rs | 31 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 1 + src/libstd/os/raw/mod.rs | 6 ++-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/librustc_target/spec/aarch64_unknown_netbsd.rs diff --git a/src/librustc_target/spec/aarch64_unknown_netbsd.rs b/src/librustc_target/spec/aarch64_unknown_netbsd.rs new file mode 100644 index 0000000000000..c300855b02187 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_netbsd.rs @@ -0,0 +1,31 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::netbsd_base::opts(); + base.max_atomic_width = Some(128); + base.abi_blacklist = super::arm_base::abi_blacklist(); + + Ok(Target { + llvm_target: "aarch64-unknown-netbsd".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + target_os: "netbsd".to_string(), + target_env: "".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 6faab77d7709f..eb6975c094232 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -319,6 +319,7 @@ supported_targets! { ("i686-unknown-openbsd", i686_unknown_openbsd), ("x86_64-unknown-openbsd", x86_64_unknown_openbsd), + ("aarch64-unknown-netbsd", aarch64_unknown_netbsd), ("armv6-unknown-netbsd-eabihf", armv6_unknown_netbsd_eabihf), ("armv7-unknown-netbsd-eabihf", armv7_unknown_netbsd_eabihf), ("i686-unknown-netbsd", i686_unknown_netbsd), diff --git a/src/libstd/os/raw/mod.rs b/src/libstd/os/raw/mod.rs index 4b8dda493b097..dc33747c05b06 100644 --- a/src/libstd/os/raw/mod.rs +++ b/src/libstd/os/raw/mod.rs @@ -29,7 +29,8 @@ use fmt; all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")), all(target_os = "l4re", target_arch = "x86_64"), - all(target_os = "netbsd", any(target_arch = "arm", + all(target_os = "netbsd", any(target_arch = "aarch64", + target_arch = "arm", target_arch = "powerpc")), all(target_os = "openbsd", target_arch = "aarch64"), all(target_os = "fuchsia", target_arch = "aarch64")))] @@ -43,7 +44,8 @@ use fmt; all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")), all(target_os = "l4re", target_arch = "x86_64"), - all(target_os = "netbsd", any(target_arch = "arm", + all(target_os = "netbsd", any(target_arch = "aarch64", + target_arch = "arm", target_arch = "powerpc")), all(target_os = "openbsd", target_arch = "aarch64"), all(target_os = "fuchsia", target_arch = "aarch64"))))] From bf089a1ac108346b5540d55be1d51c087b33931e Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:19:53 -0400 Subject: [PATCH 04/57] [nll] libcore: enable feature(nll) for bootstrap --- src/libcore/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index dc4a2d7c0d7b1..178ae62dd3dfa 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -92,6 +92,7 @@ #![feature(lang_items)] #![feature(link_llvm_intrinsics)] #![feature(never_type)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(exhaustive_patterns)] #![feature(macro_at_most_once_rep)] #![feature(no_core)] From 26991eb8bf8fb4f368db4acba31d9ed4a819fa5f Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:20:20 -0400 Subject: [PATCH 05/57] [nll] libprofiler_builtins: enable feature(nll) for bootstrap --- src/libprofiler_builtins/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libprofiler_builtins/lib.rs b/src/libprofiler_builtins/lib.rs index 6d0d6d115b716..a85593253b100 100644 --- a/src/libprofiler_builtins/lib.rs +++ b/src/libprofiler_builtins/lib.rs @@ -15,4 +15,5 @@ reason = "internal implementation detail of rustc right now", issue = "0")] #![allow(unused_features)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(staged_api)] From ed55520371c349666ba048a3e602d0b7018bf26d Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:20:41 -0400 Subject: [PATCH 06/57] [nll] librustc: enable feature(nll) for bootstrap --- src/librustc/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 804481846afdc..3cc1ca01b7871 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -51,6 +51,7 @@ #![feature(never_type)] #![feature(exhaustive_patterns)] #![feature(extern_types)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(non_exhaustive)] #![feature(proc_macro_internals)] #![feature(quote)] From 9207cc9bd90be84edac8d2d331a47adba50e07af Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:21:01 -0400 Subject: [PATCH 07/57] [nll] librustc_allocator: enable feature(nll) for bootstrap --- src/librustc_allocator/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index b217d3665a245..a920bb0f2b918 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(not(stage0), feature(nll))] #![feature(rustc_private)] #[macro_use] extern crate log; From c556cff96f05530ee63d49eeb55acb3210de0060 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:21:23 -0400 Subject: [PATCH 08/57] [nll] librustc_data_structures: enable feature(nll) for bootstrap --- src/librustc_data_structures/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index dd90cf7ae19e4..67f1c119ea839 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -26,6 +26,7 @@ #![feature(specialization)] #![feature(optin_builtin_traits)] #![feature(macro_vis_matcher)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(allow_internal_unstable)] #![feature(vec_resize_with)] From 75fa16bc60f86a391d5293503a2a066068c19797 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:22:08 -0400 Subject: [PATCH 09/57] [nll] libserialize: enable feature(nll) for bootstrap --- src/libserialize/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index a5f4b32b329e7..794fc095096a4 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -24,6 +24,7 @@ Core encoding and decoding interfaces. #![feature(core_intrinsics)] #![feature(specialization)] #![feature(never_type)] +#![cfg_attr(not(stage0), feature(nll))] #![cfg_attr(test, feature(test))] pub use self::serialize::{Decoder, Encoder, Decodable, Encodable}; From 6858bd890a9cbf7df481f6e643f70f4cb4192730 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:22:33 -0400 Subject: [PATCH 10/57] [nll] libsyntax: enable feature(nll) for bootstrap --- src/libsyntax/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index c8e60620248b3..0948ebea15df4 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -21,6 +21,7 @@ #![feature(crate_visibility_modifier)] #![feature(macro_at_most_once_rep)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(rustc_attrs)] #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] From 9d2c4a3acd352488adfd18fc105f163b710c8f2b Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 09:22:45 -0400 Subject: [PATCH 11/57] [nll] libtest: enable feature(nll) for bootstrap --- src/libtest/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3f8be97571fd7..30094223d0858 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -35,6 +35,7 @@ #![feature(asm)] #![feature(fnbox)] #![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))] +#![cfg_attr(not(stage0), feature(nll))] #![feature(set_stdio)] #![feature(panic_unwind)] #![feature(staged_api)] From 6c7473d0248602060d764cd355363ac6b69b8ae3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 8 Aug 2018 21:42:26 -0700 Subject: [PATCH 12/57] Deny future duplication of rustc-ap-syntax Enable the tidy check to forbid this! Closes #53006 --- src/tools/tidy/src/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 42f4e46085ebe..d63f479f29d94 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -353,7 +353,7 @@ fn check_crate_duplicate(resolve: &Resolve, bad: &mut bool) { // versions of them accidentally sneak into our dependency graph to // ensure we keep our CI times under control // "cargo", // FIXME(#53005) - // "rustc-ap-syntax", // FIXME(#53006) + "rustc-ap-syntax", ]; let mut name_to_id = HashMap::new(); for node in resolve.nodes.iter() { From c9aca0232064ab3f67eec4ceda3258caa3866129 Mon Sep 17 00:00:00 2001 From: BurntPizza Date: Wed, 8 Aug 2018 18:23:52 -0400 Subject: [PATCH 13/57] Don't panic on std::env::vars() when env in null. Fixes #53200 --- src/libstd/sys/unix/os.rs | 6 +----- src/test/run-pass/env-null-vars.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/test/run-pass/env-null-vars.rs diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 08c3e15497843..f8f0bbd5bc250 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -414,12 +414,8 @@ pub fn env() -> Env { unsafe { let _guard = ENV_LOCK.lock(); let mut environ = *environ(); - if environ == ptr::null() { - panic!("os::env() failure getting env string from OS: {}", - io::Error::last_os_error()); - } let mut result = Vec::new(); - while *environ != ptr::null() { + while environ != ptr::null() && *environ != ptr::null() { if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { result.push(key_value); } diff --git a/src/test/run-pass/env-null-vars.rs b/src/test/run-pass/env-null-vars.rs new file mode 100644 index 0000000000000..296764269dec0 --- /dev/null +++ b/src/test/run-pass/env-null-vars.rs @@ -0,0 +1,29 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-windows +// ignore-wasm32-bare no libc to test ffi with + +// issue-53200 + +#![feature(libc)] +extern crate libc; + +use std::env; + +// FIXME: more platforms? +#[cfg(target_os = "linux")] +fn main() { + unsafe { libc::clearenv(); } + assert_eq!(env::vars().count(), 0); +} + +#[cfg(not(target_os = "linux"))] +fn main() {} From ffdac5d592194e7026d3e5fc03bce896c3086cd7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 9 Aug 2018 16:57:55 +0200 Subject: [PATCH 14/57] Make SnapshotMap::{commit, rollback_to} take references --- src/librustc/infer/mod.rs | 2 +- src/librustc/traits/project.rs | 6 +++--- src/librustc_data_structures/snapshot_map/mod.rs | 10 +++++----- src/librustc_data_structures/snapshot_map/test.rs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 0b84c6a0aa77a..eed6215150fdb 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -709,7 +709,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.projection_cache .borrow_mut() - .commit(projection_cache_snapshot); + .commit(&projection_cache_snapshot); self.type_variables .borrow_mut() .commit(type_snapshot); diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 1ce60d8f05599..5a95b27e93c92 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1668,15 +1668,15 @@ impl<'tcx> ProjectionCache<'tcx> { } pub fn rollback_to(&mut self, snapshot: ProjectionCacheSnapshot) { - self.map.rollback_to(snapshot.snapshot); + self.map.rollback_to(&snapshot.snapshot); } pub fn rollback_skolemized(&mut self, snapshot: &ProjectionCacheSnapshot) { self.map.partial_rollback(&snapshot.snapshot, &|k| k.ty.has_re_skol()); } - pub fn commit(&mut self, snapshot: ProjectionCacheSnapshot) { - self.map.commit(snapshot.snapshot); + pub fn commit(&mut self, snapshot: &ProjectionCacheSnapshot) { + self.map.commit(&snapshot.snapshot); } /// Try to start normalize `key`; returns an error if diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index 6ee8c3579f543..5030bf98dffd5 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -92,7 +92,7 @@ impl SnapshotMap pub fn snapshot(&mut self) -> Snapshot { self.undo_log.push(UndoLog::OpenSnapshot); let len = self.undo_log.len() - 1; - Snapshot { len: len } + Snapshot { len } } fn assert_open_snapshot(&self, snapshot: &Snapshot) { @@ -103,8 +103,8 @@ impl SnapshotMap }); } - pub fn commit(&mut self, snapshot: Snapshot) { - self.assert_open_snapshot(&snapshot); + pub fn commit(&mut self, snapshot: &Snapshot) { + self.assert_open_snapshot(snapshot); if snapshot.len == 0 { // The root snapshot. self.undo_log.truncate(0); @@ -135,8 +135,8 @@ impl SnapshotMap } } - pub fn rollback_to(&mut self, snapshot: Snapshot) { - self.assert_open_snapshot(&snapshot); + pub fn rollback_to(&mut self, snapshot: &Snapshot) { + self.assert_open_snapshot(snapshot); while self.undo_log.len() > snapshot.len + 1 { let entry = self.undo_log.pop().unwrap(); self.reverse(entry); diff --git a/src/librustc_data_structures/snapshot_map/test.rs b/src/librustc_data_structures/snapshot_map/test.rs index 4114082839b0b..b163e0fe420ec 100644 --- a/src/librustc_data_structures/snapshot_map/test.rs +++ b/src/librustc_data_structures/snapshot_map/test.rs @@ -20,7 +20,7 @@ fn basic() { map.insert(44, "fourty-four"); assert_eq!(map[&44], "fourty-four"); assert_eq!(map.get(&33), None); - map.rollback_to(snapshot); + map.rollback_to(&snapshot); assert_eq!(map[&22], "twenty-two"); assert_eq!(map.get(&33), None); assert_eq!(map.get(&44), None); @@ -33,7 +33,7 @@ fn out_of_order() { map.insert(22, "twenty-two"); let snapshot1 = map.snapshot(); let _snapshot2 = map.snapshot(); - map.rollback_to(snapshot1); + map.rollback_to(&snapshot1); } #[test] @@ -43,8 +43,8 @@ fn nested_commit_then_rollback() { let snapshot1 = map.snapshot(); let snapshot2 = map.snapshot(); map.insert(22, "thirty-three"); - map.commit(snapshot2); + map.commit(&snapshot2); assert_eq!(map[&22], "thirty-three"); - map.rollback_to(snapshot1); + map.rollback_to(&snapshot1); assert_eq!(map[&22], "twenty-two"); } From 160187937d679d78bfc36aa39c3cb36cc5024012 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 9 Aug 2018 16:59:10 +0200 Subject: [PATCH 15/57] Change transmute()s in IdxSet::{from_slice, from_slice_mut} to casts --- src/librustc_data_structures/indexed_set.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index 2e95a45479c4f..46d6c65101a70 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -59,10 +59,6 @@ impl rustc_serialize::Decodable for IdxSetBuf { // pnkfelix wants to have this be `IdxSet([Word]) and then pass // around `&mut IdxSet` or `&IdxSet`. -// -// WARNING: Mapping a `&IdxSetBuf` to `&IdxSet` (at least today) -// requires a transmute relying on representation guarantees that may -// not hold in the future. /// Represents a set (or packed family of sets), of some element type /// E, where each E is identified by some unique index type `T`. @@ -134,11 +130,11 @@ impl IdxSetBuf { impl IdxSet { unsafe fn from_slice(s: &[Word]) -> &Self { - mem::transmute(s) // (see above WARNING) + &*(s as *const [Word] as *const Self) } unsafe fn from_slice_mut(s: &mut [Word]) -> &mut Self { - mem::transmute(s) // (see above WARNING) + &mut *(s as *mut [Word] as *mut Self) } } From 94c38568048b579c5a29768a8d4bacb8c9d687e1 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 9 Aug 2018 17:00:14 +0200 Subject: [PATCH 16/57] A few cleanups for rustc_data_structures --- src/librustc_data_structures/base_n.rs | 5 +++-- src/librustc_data_structures/bitslice.rs | 5 +++-- src/librustc_data_structures/bitvec.rs | 5 +++-- src/librustc_data_structures/flock.rs | 4 ++-- .../graph/dominators/mod.rs | 3 ++- .../graph/implementation/mod.rs | 8 ++++---- src/librustc_data_structures/indexed_set.rs | 1 + .../obligation_forest/mod.rs | 2 +- src/librustc_data_structures/tiny_list.rs | 3 ++- .../transitive_relation.rs | 15 ++++++--------- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/librustc_data_structures/base_n.rs b/src/librustc_data_structures/base_n.rs index d333b6393b9cc..d3b47daa5b4b8 100644 --- a/src/librustc_data_structures/base_n.rs +++ b/src/librustc_data_structures/base_n.rs @@ -17,7 +17,7 @@ pub const MAX_BASE: usize = 64; pub const ALPHANUMERIC_ONLY: usize = 62; pub const CASE_INSENSITIVE: usize = 36; -const BASE_64: &'static [u8; MAX_BASE as usize] = +const BASE_64: &[u8; MAX_BASE as usize] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$"; #[inline] @@ -37,7 +37,8 @@ pub fn push_str(mut n: u128, base: usize, output: &mut String) { break; } } - &mut s[0..index].reverse(); + s[0..index].reverse(); + output.push_str(str::from_utf8(&s[0..index]).unwrap()); } diff --git a/src/librustc_data_structures/bitslice.rs b/src/librustc_data_structures/bitslice.rs index b8f191c2f57d8..a63033c436528 100644 --- a/src/librustc_data_structures/bitslice.rs +++ b/src/librustc_data_structures/bitslice.rs @@ -75,7 +75,7 @@ fn bit_lookup(bit: usize) -> BitLookup { let word = bit / word_bits; let bit_in_word = bit % word_bits; let bit_mask = 1 << bit_in_word; - BitLookup { word: word, bit_in_word: bit_in_word, bit_mask: bit_mask } + BitLookup { word, bit_in_word, bit_mask } } pub fn bits_to_string(words: &[Word], bits: usize) -> String { @@ -105,7 +105,8 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String { sep = '|'; } result.push(']'); - return result + + result } #[inline] diff --git a/src/librustc_data_structures/bitvec.rs b/src/librustc_data_structures/bitvec.rs index 6e8a45d034250..49ab3e58812dc 100644 --- a/src/librustc_data_structures/bitvec.rs +++ b/src/librustc_data_structures/bitvec.rs @@ -196,7 +196,8 @@ impl<'a, C: Idx> Iterator for BitIter<'a, C> { self.current >>= offset; self.current >>= 1; // shift otherwise overflows for 0b1000_0000_…_0000 self.idx += offset + 1; - return Some(C::new(self.idx - 1)); + + Some(C::new(self.idx - 1)) } fn size_hint(&self) -> (usize, Option) { @@ -299,7 +300,7 @@ impl BitMatrix { let v1 = vector[write_index]; let v2 = v1 | vector[read_index]; vector[write_index] = v2; - changed = changed | (v1 != v2); + changed |= v1 != v2; } changed } diff --git a/src/librustc_data_structures/flock.rs b/src/librustc_data_structures/flock.rs index ff1ebb11b7221..3f248dadb66c1 100644 --- a/src/librustc_data_structures/flock.rs +++ b/src/librustc_data_structures/flock.rs @@ -254,8 +254,8 @@ mod imp { type ULONG_PTR = usize; type LPOVERLAPPED = *mut OVERLAPPED; - const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x00000002; - const LOCKFILE_FAIL_IMMEDIATELY: DWORD = 0x00000001; + const LOCKFILE_EXCLUSIVE_LOCK: DWORD = 0x0000_0002; + const LOCKFILE_FAIL_IMMEDIATELY: DWORD = 0x0000_0001; const FILE_SHARE_DELETE: DWORD = 0x4; const FILE_SHARE_READ: DWORD = 0x1; diff --git a/src/librustc_data_structures/graph/dominators/mod.rs b/src/librustc_data_structures/graph/dominators/mod.rs index d134fad2855bb..e54147cbe7c87 100644 --- a/src/librustc_data_structures/graph/dominators/mod.rs +++ b/src/librustc_data_structures/graph/dominators/mod.rs @@ -107,7 +107,8 @@ fn intersect( node2 = immediate_dominators[node2].unwrap(); } } - return node1; + + node1 } #[derive(Clone, Debug)] diff --git a/src/librustc_data_structures/graph/implementation/mod.rs b/src/librustc_data_structures/graph/implementation/mod.rs index cf9403db658f4..baac756586865 100644 --- a/src/librustc_data_structures/graph/implementation/mod.rs +++ b/src/librustc_data_structures/graph/implementation/mod.rs @@ -90,7 +90,7 @@ pub const INCOMING: Direction = Direction { repr: 1 }; impl NodeIndex { /// Returns unique id (unique with respect to the graph holding associated node). - pub fn node_id(&self) -> usize { + pub fn node_id(self) -> usize { self.0 } } @@ -187,7 +187,7 @@ impl Graph { self.nodes[source.0].first_edge[OUTGOING.repr] = idx; self.nodes[target.0].first_edge[INCOMING.repr] = idx; - return idx; + idx } pub fn edge(&self, idx: EdgeIndex) -> &Edge { @@ -261,8 +261,8 @@ impl Graph { DepthFirstTraversal::with_start_node(self, start, direction) } - pub fn nodes_in_postorder<'a>( - &'a self, + pub fn nodes_in_postorder( + &self, direction: Direction, entry_node: NodeIndex, ) -> Vec { diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index 46d6c65101a70..340fe057096d8 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -65,6 +65,7 @@ impl rustc_serialize::Decodable for IdxSetBuf { /// /// In other words, `T` is the type used to index into the bitslice /// this type uses to represent the set of object it holds. +#[repr(transparent)] pub struct IdxSet { _pd: PhantomData, bits: [Word], diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 0d6cf260dcd98..7ef88852685d5 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -573,7 +573,7 @@ impl ObligationForest { } let mut kill_list = vec![]; - for (predicate, index) in self.waiting_cache.iter_mut() { + for (predicate, index) in &mut self.waiting_cache { let new_index = node_rewrites[index.get()]; if new_index >= nodes_len { kill_list.push(predicate.clone()); diff --git a/src/librustc_data_structures/tiny_list.rs b/src/librustc_data_structures/tiny_list.rs index c12fc22baf020..e1bfdf35b274e 100644 --- a/src/librustc_data_structures/tiny_list.rs +++ b/src/librustc_data_structures/tiny_list.rs @@ -107,7 +107,8 @@ impl Element { }; self.next = new_next; - return true + + true } fn len(&self) -> usize { diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index a8124fb7c5b62..18a1e9129b342 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -77,7 +77,7 @@ impl TransitiveRelation { .. } = self; - map.entry(a.clone()) + *map.entry(a.clone()) .or_insert_with(|| { elements.push(a); @@ -86,7 +86,6 @@ impl TransitiveRelation { Index(elements.len() - 1) }) - .clone() } /// Applies the (partial) function to each edge and returns a new @@ -98,14 +97,12 @@ impl TransitiveRelation { { let mut result = TransitiveRelation::new(); for edge in &self.edges { - let r = f(&self.elements[edge.source.0]).and_then(|source| { + f(&self.elements[edge.source.0]).and_then(|source| { f(&self.elements[edge.target.0]).and_then(|target| { - Some(result.add(source, target)) + result.add(source, target); + Some(()) }) - }); - if r.is_none() { - return None; - } + })?; } Some(result) } @@ -372,7 +369,7 @@ impl TransitiveRelation { let mut changed = true; while changed { changed = false; - for edge in self.edges.iter() { + for edge in &self.edges { // add an edge from S -> T changed |= matrix.add(edge.source.0, edge.target.0); From 6563803ed3ea02d48ad9d853bad502633ae970af Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 9 Aug 2018 19:38:41 +0100 Subject: [PATCH 17/57] Don't set rlimit to a lower value than the current --- src/librustc_driver/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 556ee9f5716ea..f34c4158923d6 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1512,7 +1512,7 @@ pub fn in_named_rustc_thread(name: String, f: F) -> Result(name: String, f: F) -> Result Date: Thu, 9 Aug 2018 19:40:49 +0100 Subject: [PATCH 18/57] Add a safety check for compiletest rlimit --- src/tools/compiletest/src/raise_fd_limit.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tools/compiletest/src/raise_fd_limit.rs b/src/tools/compiletest/src/raise_fd_limit.rs index 220082799a8b0..d1071231530d6 100644 --- a/src/tools/compiletest/src/raise_fd_limit.rs +++ b/src/tools/compiletest/src/raise_fd_limit.rs @@ -57,14 +57,16 @@ pub unsafe fn raise_fd_limit() { panic!("raise_fd_limit: error calling getrlimit: {}", err); } - // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard - // limit - rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max); + // Make sure we're only ever going to increase the rlimit. + if rlim.rlim_cur < maxfiles as libc::rlim_t { + // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard limit. + rlim.rlim_cur = cmp::min(maxfiles as libc::rlim_t, rlim.rlim_max); - // Set our newly-increased resource limit - if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 { - let err = io::Error::last_os_error(); - panic!("raise_fd_limit: error calling setrlimit: {}", err); + // Set our newly-increased resource limit. + if libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) != 0 { + let err = io::Error::last_os_error(); + panic!("raise_fd_limit: error calling setrlimit: {}", err); + } } } From 2cb91dad9fa5b2c82cf29828a727fde3f40507d3 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:28:39 -0400 Subject: [PATCH 19/57] [nll] libsyntax_ext: enable feature(nll) for bootstrap --- src/libsyntax_ext/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index f0d33835cd0fb..1ba4ab474258c 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -16,6 +16,7 @@ #![feature(proc_macro_internals)] #![feature(decl_macro)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(str_escape)] #![feature(rustc_diagnostic_macros)] From ce5b9c662f2ee203fb08c6a07f0a3f059f1697f4 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:32:23 -0400 Subject: [PATCH 20/57] [nll] libsyntax_ext: remove unnecessary mut annotation on variable Pointed out by nll. It is correct that the mut annotation is not needed. --- src/libsyntax_ext/deriving/generic/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e0f985c26c7a1..f5e607fc23d22 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -554,7 +554,7 @@ impl<'a> TraitDef<'a> { GenericParamKind::Type { .. } => { // I don't think this can be moved out of the loop, since // a GenericBound requires an ast id - let mut bounds: Vec<_> = + let bounds: Vec<_> = // extra restrictions on the generics parameters to the // type being derived upon self.additional_bounds.iter().map(|p| { From 48616432ba4474bbbe6c152dfc284f0681b5bd55 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:32:45 -0400 Subject: [PATCH 21/57] [nll] libproc_macro: enable feature(nll) for bootstrap --- src/libproc_macro/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index bf6e4a3aaa405..fec90008c6701 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -31,6 +31,7 @@ test(no_crate_inject, attr(deny(warnings))), test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))] +#![cfg_attr(not(stage0), feature(nll))] #![feature(rustc_private)] #![feature(staged_api)] #![feature(lang_items)] From 4b42a2100bf4060b09dab325c83ff6aa7e0a97f8 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:33:06 -0400 Subject: [PATCH 22/57] [nll] librustc_codegen_utils: enable feature(nll) for bootstrap --- src/librustc_codegen_utils/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 3ff2388beea2a..635819e94e867 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -19,6 +19,7 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(custom_attribute)] +#![cfg_attr(not(stage0), feature(nll))] #![allow(unused_attributes)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] From 8172485b4d3bf89c62f8989f29c4428458096566 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:33:24 -0400 Subject: [PATCH 23/57] [nll] librustc_llvm: enable feature(nll) for bootstrap --- src/librustc_llvm/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index ffa97bd6fa59d..387660473a887 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(not(stage0), feature(nll))] #![feature(static_nobundle)] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", From 588dbed3925a3e48e1d50d25bf8cb282b53cf41d Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:33:50 -0400 Subject: [PATCH 24/57] [nll] librustc_lsan: enable feature(nll) for bootstrap --- src/librustc_lsan/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_lsan/lib.rs b/src/librustc_lsan/lib.rs index 0c78fd74a234e..b3ba86ad8a4b3 100644 --- a/src/librustc_lsan/lib.rs +++ b/src/librustc_lsan/lib.rs @@ -10,6 +10,7 @@ #![sanitizer_runtime] #![feature(alloc_system)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(sanitizer_runtime)] #![feature(staged_api)] #![no_std] From d9f2b51a89b1d802ac98636c6020f398b0606bc1 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:34:05 -0400 Subject: [PATCH 25/57] [nll] librustc_msan: enable feature(nll) for bootstrap --- src/librustc_msan/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_msan/lib.rs b/src/librustc_msan/lib.rs index 0c78fd74a234e..b3ba86ad8a4b3 100644 --- a/src/librustc_msan/lib.rs +++ b/src/librustc_msan/lib.rs @@ -10,6 +10,7 @@ #![sanitizer_runtime] #![feature(alloc_system)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(sanitizer_runtime)] #![feature(staged_api)] #![no_std] From 58407351dde1d42b116b0fc4c64a65fe753d96cf Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:34:31 -0400 Subject: [PATCH 26/57] [nll] librustc_platform_intrinsics: enable feature(nll) for bootstrap --- src/librustc_platform_intrinsics/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_platform_intrinsics/lib.rs b/src/librustc_platform_intrinsics/lib.rs index b57debdd99486..d41f4cd61f763 100644 --- a/src/librustc_platform_intrinsics/lib.rs +++ b/src/librustc_platform_intrinsics/lib.rs @@ -10,6 +10,8 @@ #![allow(bad_style)] +#![cfg_attr(not(stage0), feature(nll))] + pub struct Intrinsic { pub inputs: &'static [&'static Type], pub output: &'static Type, From ac9b7be50b5009308c12ca3e161ee2d9ca1d7258 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:34:54 -0400 Subject: [PATCH 27/57] [nll] librustc_typeck: enable feature(nll) for bootstrap --- src/librustc_typeck/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ecc167d5a1967..62f93ea20e48c 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -76,6 +76,7 @@ This API is completely unstable and subject to change. #![feature(crate_visibility_modifier)] #![feature(exhaustive_patterns)] #![feature(iterator_find_map)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(quote)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] From 4aced68e1835d79c01c739c1bf731d840f6f5c51 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 15:35:06 -0400 Subject: [PATCH 28/57] [nll] librustdoc: enable feature(nll) for bootstrap --- src/librustdoc/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 78ecfd13e2f96..7581965cc0cad 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -17,6 +17,7 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(iterator_find_map)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(set_stdio)] #![feature(slice_sort_by_cached_key)] #![feature(test)] From 1aa6c23a70a2b85693cad2ecaaf9f32b7f588aa2 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 9 Aug 2018 20:58:43 +0100 Subject: [PATCH 29/57] Feature gate where clauses on associated type impls --- src/libsyntax/feature_gate.rs | 13 +++++++++---- .../ui/feature-gate-generic_associated_types.rs | 5 +++++ .../feature-gate-generic_associated_types.stderr | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6d71d276390c4..4786b0a074e4d 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1862,10 +1862,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "existential types are unstable" ); } - - ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { - gate_feature_post!(&self, generic_associated_types, ii.span, - "generic associated types are unstable"); + ast::ImplItemKind::Type(_) => { + if !ii.generics.params.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "generic associated types are unstable"); + } + if !ii.generics.where_clause.predicates.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "where clauses on associated types are unstable"); + } } _ => {} } diff --git a/src/test/ui/feature-gate-generic_associated_types.rs b/src/test/ui/feature-gate-generic_associated_types.rs index 3470662686643..bbaae1ef449fc 100644 --- a/src/test/ui/feature-gate-generic_associated_types.rs +++ b/src/test/ui/feature-gate-generic_associated_types.rs @@ -19,6 +19,7 @@ trait PointerFamily { } struct Foo; + impl PointerFamily for Foo { type Pointer = Box; //~^ ERROR generic associated types are unstable @@ -31,5 +32,9 @@ trait Bar { //~^ ERROR where clauses on associated types are unstable } +impl Bar for Foo { + type Assoc where Self: Sized = Foo; + //~^ ERROR where clauses on associated types are unstable +} fn main() {} diff --git a/src/test/ui/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gate-generic_associated_types.stderr index d7891f13c6b4d..f12cbe727fbed 100644 --- a/src/test/ui/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gate-generic_associated_types.stderr @@ -23,7 +23,7 @@ LL | type Pointer2: Deref where T: Clone, U: Clone; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:23:5 + --> $DIR/feature-gate-generic_associated_types.rs:24:5 | LL | type Pointer = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | type Pointer = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:25:5 + --> $DIR/feature-gate-generic_associated_types.rs:26:5 | LL | type Pointer2 = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,13 +39,21 @@ LL | type Pointer2 = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: where clauses on associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:30:5 + --> $DIR/feature-gate-generic_associated_types.rs:31:5 | LL | type Assoc where Self: Sized; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(generic_associated_types)] to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: where clauses on associated types are unstable (see issue #44265) + --> $DIR/feature-gate-generic_associated_types.rs:36:5 + | +LL | type Assoc where Self: Sized = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(generic_associated_types)] to the crate attributes to enable + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. From 898950caf1a7bc9b6c41e74bbfac9591724f307c Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Thu, 9 Aug 2018 22:04:55 +0200 Subject: [PATCH 30/57] targets: aarch64: Add bare-metal aarch64 target A generic AArch64 target that can be used for writing bare-metal code for 64-bit ARM architectures. --- .../spec/aarch64_unknown_none.rs | 46 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 2 + 2 files changed, 48 insertions(+) create mode 100644 src/librustc_target/spec/aarch64_unknown_none.rs diff --git a/src/librustc_target/spec/aarch64_unknown_none.rs b/src/librustc_target/spec/aarch64_unknown_none.rs new file mode 100644 index 0000000000000..cfba0614adcd6 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_none.rs @@ -0,0 +1,46 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Generic AArch64 target for bare-metal code +// +// Can be used in conjunction with the `target-feature` and +// `target-cpu` compiler flags to opt-in more hardware-specific +// features. +// +// For example, `-C target-cpu=cortex-a53`. + +use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy}; + +pub fn target() -> Result { + let opts = TargetOptions { + linker: Some("rust-lld".to_owned()), + executables: true, + relocation_model: "static".to_string(), + disable_redzone: true, + linker_is_gnu: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + abi_blacklist: super::arm_base::abi_blacklist(), + .. Default::default() + }; + Ok(Target { + llvm_target: "aarch64-unknown-none".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_os: "none".to_string(), + target_env: "".to_string(), + target_vendor: "".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + options: opts, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 6faab77d7709f..8fc1f6ac4a581 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -379,6 +379,8 @@ supported_targets! { ("x86_64-unknown-hermit", x86_64_unknown_hermit), ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf), + + ("aarch64-unknown-none", aarch64_unknown_none), } /// Everything `rustc` knows about how to compile for a specific target. From ef34a16c611419a1b3b3637dee5b97c4ccef1d03 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Thu, 9 Aug 2018 17:31:15 -0400 Subject: [PATCH 31/57] [nll] librustc_data_structures: remove unused mut annotation in test --- src/librustc_data_structures/indexed_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index 2e95a45479c4f..09c734fc01b4d 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -326,7 +326,7 @@ fn test_set_up_to() { #[test] fn test_new_filled() { for i in 0..128 { - let mut idx_buf = IdxSetBuf::new_filled(i); + let idx_buf = IdxSetBuf::new_filled(i); let elems: Vec = idx_buf.iter().collect(); let expected: Vec = (0..i).collect(); assert_eq!(elems, expected); From 176f8c2a616b6b4edd8fa15e7f22cc2d34f12574 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Thu, 9 Aug 2018 21:51:12 +0100 Subject: [PATCH 32/57] Removed `raw_identifiers` feature gate. --- src/librustc_lint/builtin.rs | 14 ++++----- src/libsyntax/diagnostic_list.rs | 5 ++-- src/libsyntax/feature_gate.rs | 15 ++-------- .../auxiliary/edition-kw-macro-2015.rs | 2 -- .../run-pass/edition-keywords-2015-2015.rs | 2 -- .../run-pass/edition-keywords-2015-2018.rs | 2 -- .../run-pass/rfc-2151-raw-identifiers/attr.rs | 2 -- .../rfc-2151-raw-identifiers/basic.rs | 2 -- .../rfc-2151-raw-identifiers/items.rs | 2 -- .../rfc-2151-raw-identifiers/macros.rs | 1 - src/test/ui/E0705.rs | 9 ++---- src/test/ui/E0705.stderr | 6 ++-- .../ui/auxiliary/edition-kw-macro-2015.rs | 1 - .../edition-keywords-2015-2015-expansion.rs | 1 - .../ui/edition-keywords-2015-2015-parsing.rs | 2 -- .../edition-keywords-2015-2015-parsing.stderr | 4 +-- .../edition-keywords-2015-2018-expansion.rs | 2 -- ...dition-keywords-2015-2018-expansion.stderr | 2 +- .../ui/edition-keywords-2015-2018-parsing.rs | 2 -- .../edition-keywords-2015-2018-parsing.stderr | 4 +-- src/test/ui/feature-gate-raw-identifiers.rs | 14 --------- .../ui/feature-gate-raw-identifiers.stderr | 11 ------- src/test/ui/raw-literal-keywords.rs | 2 -- src/test/ui/raw-literal-keywords.stderr | 6 ++-- src/test/ui/raw-literal-self.rs | 2 -- src/test/ui/raw-literal-self.stderr | 2 +- .../ui/rust-2018/async-ident-allowed.stderr | 2 +- src/test/ui/rust-2018/async-ident.fixed | 1 - src/test/ui/rust-2018/async-ident.rs | 1 - src/test/ui/rust-2018/async-ident.stderr | 30 +++++++++---------- 30 files changed, 42 insertions(+), 109 deletions(-) delete mode 100644 src/test/ui/feature-gate-raw-identifiers.rs delete mode 100644 src/test/ui/feature-gate-raw-identifiers.stderr diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 3a449b6a68e4c..88277a7821673 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1927,14 +1927,12 @@ impl Async2018 { ); // Don't suggest about raw identifiers if the feature isn't active - if cx.sess.features_untracked().raw_identifiers { - lint.span_suggestion_with_applicability( - span, - "you can use a raw identifier to stay compatible", - "r#async".to_string(), - Applicability::MachineApplicable, - ); - } + lint.span_suggestion_with_applicability( + span, + "you can use a raw identifier to stay compatible", + "r#async".to_string(), + Applicability::MachineApplicable, + ); lint.emit() } } diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 15abad555f4b6..89af57a085807 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -382,8 +382,9 @@ Erroneous code example: ```ignore (limited to a warning during 2018 edition development) #![feature(rust_2018_preview)] -#![feature(raw_identifiers)] // error: the feature `raw_identifiers` is - // included in the Rust 2018 edition +#![feature(impl_header_lifetime_elision)] // error: the feature + // `impl_header_lifetime_elision` is + // included in the Rust 2018 edition ``` "##, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 65eeaff3f1078..48362d299ceed 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -433,9 +433,6 @@ declare_features! ( // `use path as _;` and `extern crate c as _;` (active, underscore_imports, "1.26.0", Some(48216), None), - // Allows keywords to be escaped for use as identifiers - (active, raw_identifiers, "1.26.0", Some(48589), Some(Edition::Edition2018)), - // Allows macro invocations in `extern {}` blocks (active, macros_in_extern, "1.27.0", Some(49476), None), @@ -645,6 +642,8 @@ declare_features! ( (accepted, repr_transparent, "1.28.0", Some(43036), None), // Defining procedural macros in `proc-macro` crates (accepted, proc_macro, "1.29.0", Some(38356), None), + // Allows keywords to be escaped for use as identifiers + (accepted, raw_identifiers, "1.30.0", Some(48589), None), ); // If you change this, please modify src/doc/unstable-book as well. You must @@ -2015,16 +2014,6 @@ pub fn check_crate(krate: &ast::Crate, plugin_attributes, }; - if !features.raw_identifiers { - for &span in sess.raw_identifier_spans.borrow().iter() { - if !span.allows_unstable() { - gate_feature!(&ctx, raw_identifiers, span, - "raw identifiers are experimental and subject to change" - ); - } - } - } - let visitor = &mut PostExpansionVisitor { context: &ctx }; visitor.whole_crate_feature_gates(krate); visit::walk_crate(visitor, krate); diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs index 69952e9f90af6..f8ed2c7f432eb 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs @@ -10,8 +10,6 @@ // edition:2015 -#![feature(raw_identifiers)] - #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) diff --git a/src/test/run-pass/edition-keywords-2015-2015.rs b/src/test/run-pass/edition-keywords-2015-2015.rs index 73869e63de7c4..1751eacc6b7ce 100644 --- a/src/test/run-pass/edition-keywords-2015-2015.rs +++ b/src/test/run-pass/edition-keywords-2015-2015.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2015.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/run-pass/edition-keywords-2015-2018.rs b/src/test/run-pass/edition-keywords-2015-2018.rs index 0a1c6505854c9..f2794a4b8d81a 100644 --- a/src/test/run-pass/edition-keywords-2015-2018.rs +++ b/src/test/run-pass/edition-keywords-2015-2018.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs b/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs index 6cea75cf1d11e..2ef9fba2076ad 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/attr.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - use std::mem; #[r#repr(r#C, r#packed)] diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs b/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs index 5d495c4e9e557..eefce3981bec1 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/basic.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - fn r#fn(r#match: u32) -> u32 { r#match } diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/items.rs b/src/test/run-pass/rfc-2151-raw-identifiers/items.rs index 256bd263d38d4..4306ffe2042af 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/items.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/items.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] - #[derive(Debug, PartialEq, Eq)] struct IntWrapper(u32); diff --git a/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs b/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs index 4bd16ded52fbd..9e89b79266cfa 100644 --- a/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs +++ b/src/test/run-pass/rfc-2151-raw-identifiers/macros.rs @@ -9,7 +9,6 @@ // except according to those terms. #![feature(decl_macro)] -#![feature(raw_identifiers)] r#macro_rules! r#struct { ($r#struct:expr) => { $r#struct } diff --git a/src/test/ui/E0705.rs b/src/test/ui/E0705.rs index a0ce95e3e02c1..0d3f68ee7c464 100644 --- a/src/test/ui/E0705.rs +++ b/src/test/ui/E0705.rs @@ -11,10 +11,7 @@ // compile-pass #![feature(rust_2018_preview)] -#![feature(raw_identifiers)] -//~^ WARN the feature `raw_identifiers` is included in the Rust 2018 edition +#![feature(impl_header_lifetime_elision)] +//~^ WARN the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition -fn main() { - let foo = 0; - let bar = r#foo; -} +fn main() {} diff --git a/src/test/ui/E0705.stderr b/src/test/ui/E0705.stderr index ebb8dd4975d6f..2bdb6dc354a67 100644 --- a/src/test/ui/E0705.stderr +++ b/src/test/ui/E0705.stderr @@ -1,6 +1,6 @@ -warning[E0705]: the feature `raw_identifiers` is included in the Rust 2018 edition +warning[E0705]: the feature `impl_header_lifetime_elision` is included in the Rust 2018 edition --> $DIR/E0705.rs:14:12 | -LL | #![feature(raw_identifiers)] - | ^^^^^^^^^^^^^^^ +LL | #![feature(impl_header_lifetime_elision)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs index 8f80e000e3caf..5b8832ddaf27c 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -10,7 +10,6 @@ // edition:2015 -#![feature(raw_identifiers)] #![allow(async_idents)] #[macro_export] diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.rs b/src/test/ui/edition-keywords-2015-2015-expansion.rs index 3b78ce80be208..a9037a50ecb6b 100644 --- a/src/test/ui/edition-keywords-2015-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2015-expansion.rs @@ -12,7 +12,6 @@ // aux-build:edition-kw-macro-2015.rs // compile-pass -#![feature(raw_identifiers)] #![allow(async_idents)] #[macro_use] diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.rs b/src/test/ui/edition-keywords-2015-2015-parsing.rs index 08cba2d2908a6..bdb190c748ace 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2015-parsing.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2015.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2015; diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.stderr b/src/test/ui/edition-keywords-2015-2015-parsing.stderr index 5b6fd3e1c9c43..a629d13e6c31b 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2015-parsing.stderr @@ -1,11 +1,11 @@ error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:24:31 + --> $DIR/edition-keywords-2015-2015-parsing.rs:22:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:25:35 + --> $DIR/edition-keywords-2015-2015-parsing.rs:23:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.rs b/src/test/ui/edition-keywords-2015-2018-expansion.rs index 41d5ebd3e7db1..291fd0285e57c 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2018-expansion.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.stderr b/src/test/ui/edition-keywords-2015-2018-expansion.stderr index 5852d56e6d374..d087146d7a14a 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.stderr +++ b/src/test/ui/edition-keywords-2015-2018-expansion.stderr @@ -1,5 +1,5 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2015-2018-expansion.rs:20:5 + --> $DIR/edition-keywords-2015-2018-expansion.rs:18:5 | LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword | ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.rs b/src/test/ui/edition-keywords-2015-2018-parsing.rs index 337d6be6bbcd8..1b7bfb530596a 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2018-parsing.rs @@ -11,8 +11,6 @@ // edition:2015 // aux-build:edition-kw-macro-2018.rs -#![feature(raw_identifiers)] - #[macro_use] extern crate edition_kw_macro_2018; diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.stderr b/src/test/ui/edition-keywords-2015-2018-parsing.stderr index 60cfbce3ff0e4..ab8a34a4a9e3d 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2018-parsing.stderr @@ -1,11 +1,11 @@ error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:24:31 + --> $DIR/edition-keywords-2015-2018-parsing.rs:22:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:25:35 + --> $DIR/edition-keywords-2015-2018-parsing.rs:23:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ diff --git a/src/test/ui/feature-gate-raw-identifiers.rs b/src/test/ui/feature-gate-raw-identifiers.rs deleted file mode 100644 index 38024feb432d9..0000000000000 --- a/src/test/ui/feature-gate-raw-identifiers.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change - println!("{}", foo); -} diff --git a/src/test/ui/feature-gate-raw-identifiers.stderr b/src/test/ui/feature-gate-raw-identifiers.stderr deleted file mode 100644 index 02eff7247c47b..0000000000000 --- a/src/test/ui/feature-gate-raw-identifiers.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: raw identifiers are experimental and subject to change (see issue #48589) - --> $DIR/feature-gate-raw-identifiers.rs:12:9 - | -LL | let r#foo = 3; //~ ERROR raw identifiers are experimental and subject to change - | ^^^^^ - | - = help: add #![feature(raw_identifiers)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/raw-literal-keywords.rs b/src/test/ui/raw-literal-keywords.rs index 9bb6653d77080..f1bfbc95eb395 100644 --- a/src/test/ui/raw-literal-keywords.rs +++ b/src/test/ui/raw-literal-keywords.rs @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -#![feature(raw_identifiers)] - fn test_if() { r#if true { } //~ ERROR found `true` } diff --git a/src/test/ui/raw-literal-keywords.stderr b/src/test/ui/raw-literal-keywords.stderr index 022f80ae8a4ec..8a6b91b4b4b6f 100644 --- a/src/test/ui/raw-literal-keywords.stderr +++ b/src/test/ui/raw-literal-keywords.stderr @@ -1,17 +1,17 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `true` - --> $DIR/raw-literal-keywords.rs:16:10 + --> $DIR/raw-literal-keywords.rs:14:10 | LL | r#if true { } //~ ERROR found `true` | ^^^^ expected one of 8 possible tokens here error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test` - --> $DIR/raw-literal-keywords.rs:20:14 + --> $DIR/raw-literal-keywords.rs:18:14 | LL | r#struct Test; //~ ERROR found `Test` | ^^^^ expected one of 8 possible tokens here error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test` - --> $DIR/raw-literal-keywords.rs:24:13 + --> $DIR/raw-literal-keywords.rs:22:13 | LL | r#union Test; //~ ERROR found `Test` | ^^^^ expected one of 8 possible tokens here diff --git a/src/test/ui/raw-literal-self.rs b/src/test/ui/raw-literal-self.rs index f88d6cf9a67bd..17496d767b622 100644 --- a/src/test/ui/raw-literal-self.rs +++ b/src/test/ui/raw-literal-self.rs @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -#![feature(raw_identifiers)] - fn self_test(r#self: u32) { //~^ ERROR `r#self` is not currently supported. } diff --git a/src/test/ui/raw-literal-self.stderr b/src/test/ui/raw-literal-self.stderr index e3345847aa895..f4b759372471c 100644 --- a/src/test/ui/raw-literal-self.stderr +++ b/src/test/ui/raw-literal-self.stderr @@ -1,5 +1,5 @@ error: `r#self` is not currently supported. - --> $DIR/raw-literal-self.rs:15:14 + --> $DIR/raw-literal-self.rs:13:14 | LL | fn self_test(r#self: u32) { | ^^^^^^ diff --git a/src/test/ui/rust-2018/async-ident-allowed.stderr b/src/test/ui/rust-2018/async-ident-allowed.stderr index 1644102cdca1a..741c1c70209bc 100644 --- a/src/test/ui/rust-2018/async-ident-allowed.stderr +++ b/src/test/ui/rust-2018/async-ident-allowed.stderr @@ -2,7 +2,7 @@ error: `async` is a keyword in the 2018 edition --> $DIR/async-ident-allowed.rs:19:9 | LL | let async = 3; //~ ERROR: is a keyword - | ^^^^^ + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` | note: lint level defined here --> $DIR/async-ident-allowed.rs:13:9 diff --git a/src/test/ui/rust-2018/async-ident.fixed b/src/test/ui/rust-2018/async-ident.fixed index 228bf91125337..15b8eec3bea99 100644 --- a/src/test/ui/rust-2018/async-ident.fixed +++ b/src/test/ui/rust-2018/async-ident.fixed @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] #![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] #![deny(async_idents)] diff --git a/src/test/ui/rust-2018/async-ident.rs b/src/test/ui/rust-2018/async-ident.rs index cc400c2a92e0e..6087d2c16423e 100644 --- a/src/test/ui/rust-2018/async-ident.rs +++ b/src/test/ui/rust-2018/async-ident.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(raw_identifiers)] #![allow(dead_code, unused_variables, non_camel_case_types, non_upper_case_globals)] #![deny(async_idents)] diff --git a/src/test/ui/rust-2018/async-ident.stderr b/src/test/ui/rust-2018/async-ident.stderr index 94fd3e70434cb..06d68a38c5f38 100644 --- a/src/test/ui/rust-2018/async-ident.stderr +++ b/src/test/ui/rust-2018/async-ident.stderr @@ -1,11 +1,11 @@ error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:18:4 + --> $DIR/async-ident.rs:17:4 | LL | fn async() {} //~ ERROR async | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` | note: lint level defined here - --> $DIR/async-ident.rs:13:9 + --> $DIR/async-ident.rs:12:9 | LL | #![deny(async_idents)] | ^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | #![deny(async_idents)] = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:23:7 + --> $DIR/async-ident.rs:22:7 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -22,7 +22,7 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:23:19 + --> $DIR/async-ident.rs:22:19 | LL | ($async:expr, async) => {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -31,7 +31,7 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:37:11 + --> $DIR/async-ident.rs:36:11 | LL | trait async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -40,7 +40,7 @@ LL | trait async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:41:10 + --> $DIR/async-ident.rs:40:10 | LL | impl async for MyStruct {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -49,7 +49,7 @@ LL | impl async for MyStruct {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:47:12 + --> $DIR/async-ident.rs:46:12 | LL | static async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -58,7 +58,7 @@ LL | static async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:53:11 + --> $DIR/async-ident.rs:52:11 | LL | const async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -67,7 +67,7 @@ LL | const async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:59:15 + --> $DIR/async-ident.rs:58:15 | LL | impl Foo { fn async() {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -76,7 +76,7 @@ LL | impl Foo { fn async() {} } = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:64:12 + --> $DIR/async-ident.rs:63:12 | LL | struct async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -85,7 +85,7 @@ LL | struct async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:9 + --> $DIR/async-ident.rs:66:9 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -94,7 +94,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:16 + --> $DIR/async-ident.rs:66:16 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -103,7 +103,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:67:24 + --> $DIR/async-ident.rs:66:24 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -112,7 +112,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:78:19 + --> $DIR/async-ident.rs:77:19 | LL | () => (pub fn async() {}) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -121,7 +121,7 @@ LL | () => (pub fn async() {}) = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:85:6 + --> $DIR/async-ident.rs:84:6 | LL | (async) => (1) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` From b187c4268c50374075d50f9dd173b13c0de2de81 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 3 Aug 2018 13:19:17 +0200 Subject: [PATCH 33/57] Consider changing assert! to debug_assert! when it calls visit_with --- src/librustc/traits/fulfill.rs | 2 +- src/librustc/traits/project.rs | 2 +- src/librustc/traits/select.rs | 8 ++++---- src/librustc/ty/layout.rs | 6 +++--- src/librustc/ty/sty.rs | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index b7d3ad76588f7..5113f3cde3284 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -146,7 +146,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> { debug!("normalize_projection_type(projection_ty={:?})", projection_ty); - assert!(!projection_ty.has_escaping_regions()); + debug_assert!(!projection_ty.has_escaping_regions()); // FIXME(#20304) -- cache diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 1ce60d8f05599..8d03f53266096 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1142,7 +1142,7 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>( if !is_default { true } else if obligation.param_env.reveal == Reveal::All { - assert!(!poly_trait_ref.needs_infer()); + debug_assert!(!poly_trait_ref.needs_infer()); if !poly_trait_ref.needs_subst() { true } else { diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 1e3fe70535bcc..fbd12c9fe8eca 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -563,7 +563,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { pub fn select(&mut self, obligation: &TraitObligation<'tcx>) -> SelectionResult<'tcx, Selection<'tcx>> { debug!("select({:?})", obligation); - assert!(!obligation.predicate.has_escaping_regions()); + debug_assert!(!obligation.predicate.has_escaping_regions()); let stack = self.push_stack(TraitObligationStackList::empty(), obligation); @@ -662,7 +662,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { match obligation.predicate { ty::Predicate::Trait(ref t) => { - assert!(!t.has_escaping_regions()); + debug_assert!(!t.has_escaping_regions()); let obligation = obligation.with(t.clone()); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } @@ -1076,7 +1076,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { debug!("candidate_from_obligation(cache_fresh_trait_pred={:?}, obligation={:?})", cache_fresh_trait_pred, stack); - assert!(!stack.obligation.predicate.has_escaping_regions()); + debug_assert!(!stack.obligation.predicate.has_escaping_regions()); if let Some(c) = self.check_candidate_cache(stack.obligation.param_env, &cache_fresh_trait_pred) { @@ -1586,7 +1586,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { snapshot: &infer::CombinedSnapshot<'cx, 'tcx>) -> bool { - assert!(!skol_trait_ref.has_escaping_regions()); + debug_assert!(!skol_trait_ref.has_escaping_regions()); if self.infcx.at(&obligation.cause, obligation.param_env) .sup(ty::Binder::dummy(skol_trait_ref), trait_bound).is_err() { return false; diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 81cc897232ab0..0da4d5ddea2f2 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -466,7 +466,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { let univariant = |fields: &[TyLayout], repr: &ReprOptions, kind| { Ok(tcx.intern_layout(univariant_uninterned(fields, repr, kind)?)) }; - assert!(!ty.has_infer_types()); + debug_assert!(!ty.has_infer_types()); Ok(match ty.sty { // Basic scalars. @@ -1283,7 +1283,7 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> { tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>) -> Result, LayoutError<'tcx>> { - assert!(!ty.has_infer_types()); + debug_assert!(!ty.has_infer_types()); // First try computing a static layout. let err = match tcx.layout_of(param_env.and(ty)) { @@ -1300,7 +1300,7 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> { let tail = tcx.struct_tail(pointee); match tail.sty { ty::TyParam(_) | ty::TyProjection(_) => { - assert!(tail.has_param_types() || tail.has_self_ty()); + debug_assert!(tail.has_param_types() || tail.has_self_ty()); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(&tail) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 96b4edce86b30..65e31f21792d2 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -708,7 +708,7 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> { pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> { // otherwise the escaping regions would be captured by the binder - assert!(!self_ty.has_escaping_regions()); + debug_assert!(!self_ty.has_escaping_regions()); ty::TraitRef { def_id: self.def_id, @@ -753,7 +753,7 @@ impl Binder { pub fn dummy<'tcx>(value: T) -> Binder where T: TypeFoldable<'tcx> { - assert!(!value.has_escaping_regions()); + debug_assert!(!value.has_escaping_regions()); Binder(value) } @@ -1247,7 +1247,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> { -> ty::ProjectionPredicate<'tcx> { // otherwise the escaping regions would be captured by the binders - assert!(!self_ty.has_escaping_regions()); + debug_assert!(!self_ty.has_escaping_regions()); ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { From 945f0325e3ed08967822bd70c97622a8610f33fd Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Fri, 10 Aug 2018 06:53:07 +0200 Subject: [PATCH 34/57] Add individual documentation for `.swap_bytes`/.`reverse_bits` --- src/libcore/num/mod.rs | 225 ++++++++++++++++++++--------------------- 1 file changed, 112 insertions(+), 113 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 960853333f6c7..eb63966354b86 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -188,7 +188,8 @@ mod wrapping; // `Int` + `SignedInt` implemented for signed integers macro_rules! int_impl { ($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr, - $EndFeature:expr, $rot:expr, $rot_op:expr, $rot_result:expr) => { + $EndFeature:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, + $reversed:expr) => { doc_comment! { concat!("Returns the smallest value that can be represented by this integer type. @@ -380,55 +381,48 @@ assert_eq!(n.rotate_right(", $rot, "), m); (self as $UnsignedT).rotate_right(n) as Self } } - /// Reverses the byte order of the integer. - /// - /// # Examples - /// - /// Please note that this example is shared between integer types. - /// Which explains why `i16` is used here. - /// - /// Basic usage: - /// - /// ``` - /// let n: i16 = 0b0000000_01010101; - /// assert_eq!(n, 85); - /// - /// let m = n.swap_bytes(); - /// - /// assert_eq!(m, 0b01010101_00000000); - /// assert_eq!(m, 21760); - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] - #[inline] - pub const fn swap_bytes(self) -> Self { - (self as $UnsignedT).swap_bytes() as Self + doc_comment! { + concat!("Reverses the byte order of the integer. + +# Examples + +Basic usage: + +``` +let n = ", $swap_op, stringify!($SelfT), "; + +let m = n.swap_bytes(); + +assert_eq!(m, ", $swapped, "); +```"), + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn swap_bytes(self) -> Self { + (self as $UnsignedT).swap_bytes() as Self + } } - /// Reverses the bit pattern of the integer. - /// - /// # Examples - /// - /// Please note that this example is shared between integer types. - /// Which explains why `i16` is used here. - /// - /// Basic usage: - /// - /// ``` - /// #![feature(reverse_bits)] - /// - /// let n: i16 = 0b0000000_01010101; - /// assert_eq!(n, 85); - /// - /// let m = n.reverse_bits(); - /// - /// assert_eq!(m as u16, 0b10101010_00000000); - /// assert_eq!(m, -22016); - /// ``` - #[unstable(feature = "reverse_bits", issue = "48763")] - #[inline] - pub fn reverse_bits(self) -> Self { - (self as $UnsignedT).reverse_bits() as Self + doc_comment! { + concat!("Reverses the bit pattern of the integer. + +# Examples + +Basic usage: + +``` +#![feature(reverse_bits)] + +let n = ", $swap_op, stringify!($SelfT), "; +let m = n.reverse_bits(); + +assert_eq!(m, ", $reversed, "); +```"), + #[unstable(feature = "reverse_bits", issue = "48763")] + #[inline] + pub fn reverse_bits(self) -> Self { + (self as $UnsignedT).reverse_bits() as Self + } } doc_comment! { @@ -2009,50 +2003,57 @@ $EndFeature, " #[lang = "i8"] impl i8 { - int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa" } + int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa", "0x12", "0x12", "0x48" } } #[lang = "i16"] impl i16 { - int_impl! { i16, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a" } + int_impl! { i16, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", "0x3412", + "0x2c48" } } #[lang = "i32"] impl i32 { - int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301" } + int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301", + "0x12345678", "0x78563412", "0x1e6a2c48" } } #[lang = "i64"] impl i64 { int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", 12, - "0xaa00000000006e1", "0x6e10aa" } + "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", + "0x6a2c48091e6a2c48" } } #[lang = "i128"] impl i128 { int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728, 170141183460469231731687303715884105727, "", "", 16, - "0x13f40000000000000000000000004f76", "0x4f7613f4" + "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", + "0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48" } } #[cfg(target_pointer_width = "16")] #[lang = "isize"] impl isize { - int_impl! { isize, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a" } + int_impl! { isize, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", + "0x3412", "0x2c48" } } #[cfg(target_pointer_width = "32")] #[lang = "isize"] impl isize { - int_impl! { isize, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301" } + int_impl! { isize, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301", + "0x12345678", "0x78563412", "0x1e6a2c48" } } #[cfg(target_pointer_width = "64")] #[lang = "isize"] impl isize { int_impl! { isize, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", - 12, "0xaa00000000006e1", "0x6e10aa" } + 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", + "0x6a2c48091e6a2c48" } } // Emits the correct `cttz` call, depending on the size of the type. @@ -2071,7 +2072,8 @@ macro_rules! uint_cttz_call { // `Int` + `UnsignedInt` implemented for unsigned integers macro_rules! uint_impl { ($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr, - $rot:expr, $rot_op:expr, $rot_result:expr) => { + $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, + $reversed:expr ) => { doc_comment! { concat!("Returns the smallest value that can be represented by this integer type. @@ -2263,55 +2265,48 @@ assert_eq!(n.rotate_right(", $rot, "), m); } } - /// Reverses the byte order of the integer. - /// - /// # Examples - /// - /// Basic usage: - /// - /// Please note that this example is shared between integer types. - /// Which explains why `u16` is used here. - /// - /// ``` - /// let n: u16 = 0b0000000_01010101; - /// assert_eq!(n, 85); - /// - /// let m = n.swap_bytes(); - /// - /// assert_eq!(m, 0b01010101_00000000); - /// assert_eq!(m, 21760); - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_ops")] - #[inline] - pub const fn swap_bytes(self) -> Self { - unsafe { intrinsics::bswap(self as $ActualT) as Self } + doc_comment! { + concat!(" +Reverses the byte order of the integer. + +# Examples + +Basic usage: + +``` +let n = ", $swap_op, stringify!($SelfT), "; +let m = n.swap_bytes(); + +assert_eq!(m, ", $swapped, "); +```"), + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_int_ops")] + #[inline] + pub const fn swap_bytes(self) -> Self { + unsafe { intrinsics::bswap(self as $ActualT) as Self } + } } - /// Reverses the bit pattern of the integer. - /// - /// # Examples - /// - /// Basic usage: - /// - /// Please note that this example is shared between integer types. - /// Which explains why `u16` is used here. - /// - /// ``` - /// #![feature(reverse_bits)] - /// - /// let n: u16 = 0b0000000_01010101; - /// assert_eq!(n, 85); - /// - /// let m = n.reverse_bits(); - /// - /// assert_eq!(m, 0b10101010_00000000); - /// assert_eq!(m, 43520); - /// ``` - #[unstable(feature = "reverse_bits", issue = "48763")] - #[inline] - pub fn reverse_bits(self) -> Self { - unsafe { intrinsics::bitreverse(self as $ActualT) as Self } + doc_comment! { + concat!("Reverses the bit pattern of the integer. + +# Examples + +Basic usage: + +``` +#![feature(reverse_bits)] + +let n = ", $swap_op, stringify!($SelfT), "; +let m = n.reverse_bits(); + +assert_eq!(m, ", $reversed, "); +```"), + #[unstable(feature = "reverse_bits", issue = "48763")] + #[inline] + pub fn reverse_bits(self) -> Self { + unsafe { intrinsics::bitreverse(self as $ActualT) as Self } + } } doc_comment! { @@ -3621,7 +3616,7 @@ $EndFeature, " #[lang = "u8"] impl u8 { - uint_impl! { u8, u8, 8, 255, "", "", 2, "0x82", "0xa" } + uint_impl! { u8, u8, 8, 255, "", "", 2, "0x82", "0xa", "0x12", "0x12", "0x48" } /// Checks if the value is within the ASCII range. @@ -4147,41 +4142,45 @@ impl u8 { #[lang = "u16"] impl u16 { - uint_impl! { u16, u16, 16, 65535, "", "", 4, "0xa003", "0x3a" } + uint_impl! { u16, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48" } } #[lang = "u32"] impl u32 { - uint_impl! { u32, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301" } + uint_impl! { u32, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678", + "0x78563412", "0x1e6a2c48" } } #[lang = "u64"] impl u64 { - uint_impl! { u64, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa" } + uint_impl! { u64, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa", + "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48" } } #[lang = "u128"] impl u128 { uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, "", "", 16, - "0x13f40000000000000000000000004f76", "0x4f7613f4" } + "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", + "0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48" } } #[cfg(target_pointer_width = "16")] #[lang = "usize"] impl usize { - uint_impl! { usize, u16, 16, 65536, "", "", 4, "0xa003", "0x3a" } + uint_impl! { usize, u16, 16, 65536, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48" } } #[cfg(target_pointer_width = "32")] #[lang = "usize"] impl usize { - uint_impl! { usize, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301" } + uint_impl! { usize, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678", + "0x78563412", "0x1e6a2c48" } } #[cfg(target_pointer_width = "64")] #[lang = "usize"] impl usize { - uint_impl! { usize, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", - "0x6e10aa" } + uint_impl! { usize, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa", + "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48" } } /// A classification of floating point numbers. From e8d95a5ba1ebc7b4a53ec45b04e344584ac4e93a Mon Sep 17 00:00:00 2001 From: memoryruins Date: Fri, 10 Aug 2018 06:27:10 -0400 Subject: [PATCH 35/57] [nll] libstd: enable feature(nll) for bootstrap --- src/libstd/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 0bc968b6c5cda..5d463225ae93b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -273,6 +273,7 @@ #![feature(macro_vis_matcher)] #![feature(needs_panic_runtime)] #![feature(never_type)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(exhaustive_patterns)] #![feature(on_unimplemented)] #![feature(optin_builtin_traits)] From 5d6ca8e4c52eebeca6721b2276d548a0b29984b3 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Fri, 10 Aug 2018 06:27:35 -0400 Subject: [PATCH 36/57] [nll] librustc_mir: enable feature(nll) for bootstrap --- src/librustc_mir/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 05c843096d27d..42682c34407ca 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -14,6 +14,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! */ +#![cfg_attr(not(stage0), feature(nll))] #![feature(infer_outlives_requirements)] #![feature(in_band_lifetimes)] #![feature(slice_patterns)] From 46b818e276a83b50f6f68f9f54995e4f5a474f88 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Fri, 10 Aug 2018 06:28:24 -0400 Subject: [PATCH 37/57] [nll] librustc_codegen_llvm: enable feature(nll) for bootstrap --- src/librustc_codegen_llvm/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 9599ccfe97964..f66c83cac7c32 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -26,6 +26,7 @@ #![feature(in_band_lifetimes)] #![allow(unused_attributes)] #![feature(libc)] +#![cfg_attr(not(stage0), feature(nll))] #![feature(quote)] #![feature(range_contains)] #![feature(rustc_diagnostic_macros)] From 085535bbe1da2350fb1c58907bf63df446e03dff Mon Sep 17 00:00:00 2001 From: memoryruins Date: Fri, 10 Aug 2018 06:31:10 -0400 Subject: [PATCH 38/57] [nll] librustc_codegen_llvm: change Child signature to fix error pointed out by nll As explained by eddyb in #53221, "An &ArchiveChild doesn't point into the archive itself, it points to an owned object that itself points to the archive, and LLVMRustArchiveMemberNew copies the ArchiveChild (whereas the current signature suggests it keeps the &ArchiveChild)." --- src/librustc_codegen_llvm/llvm/ffi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index a894f8e2fdb96..68a21a537070b 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1564,7 +1564,7 @@ extern "C" { -> LLVMRustResult; pub fn LLVMRustArchiveMemberNew(Filename: *const c_char, Name: *const c_char, - Child: Option<&'a ArchiveChild>) + Child: Option<&ArchiveChild<'a>>) -> &'a mut RustArchiveMember<'a>; pub fn LLVMRustArchiveMemberFree(Member: &'a mut RustArchiveMember<'a>); From 0123ac12e28e1d8672e66404678893bd1d641714 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Fri, 10 Aug 2018 06:31:40 -0400 Subject: [PATCH 39/57] [nll] librustc_codegen_llvm: remove unused mut annotation --- src/librustc_codegen_llvm/type_of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index 5fd4f15acd157..69d91b327283d 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -89,7 +89,7 @@ fn uncached_llvm_type<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, Type::struct_(cx, &[fill], packed) } Some(ref name) => { - let mut llty = Type::named_struct(cx, name); + let llty = Type::named_struct(cx, name); llty.set_struct_body(&[fill], packed); llty } From 8a766564351cf9a2305269aeb28e2db658d701cf Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 1 Aug 2018 11:36:28 -0600 Subject: [PATCH 40/57] Link compiler test documentation to rustc-guide Update the compiler test documentation to point to the relevant rustc-guide page. --- src/test/COMPILER_TESTS.md | 186 +------------------------------------ 1 file changed, 2 insertions(+), 184 deletions(-) diff --git a/src/test/COMPILER_TESTS.md b/src/test/COMPILER_TESTS.md index 7dabb1bddea77..81a46ea0fe718 100644 --- a/src/test/COMPILER_TESTS.md +++ b/src/test/COMPILER_TESTS.md @@ -1,186 +1,4 @@ # Compiler Test Documentation -In the Rust project, we use a special set of commands embedded in -comments to test the Rust compiler. There are two groups of commands: - -1. Header commands -2. Error info commands - -Both types of commands are inside comments, but header commands should -be in a comment before any code. - -## Summary of Error Info Commands - -Error commands specify something about certain lines of the -program. They tell the test what kind of error and what message you -are expecting. - -* `~`: Associates the following error level and message with the - current line -* `~|`: Associates the following error level and message with the same - line as the previous comment -* `~^`: Associates the following error level and message with the - previous line. Each caret (`^`) that you add adds a line to this, so - `~^^^^^^^` is seven lines up. - -The error levels that you can have are: - -1. `ERROR` -2. `WARNING` -3. `NOTE` -4. `HELP` and `SUGGESTION`* - -\* **Note**: `SUGGESTION` must follow immediately after `HELP`. - -## Summary of Header Commands - -Header commands specify something about the entire test file as a -whole. They are normally put right after the copyright comment, e.g.: - -```Rust -// Copyright blah blah blah -// except according to those terms. - -// ignore-test This doesn't actually work -``` - -### Ignoring tests - -These are used to ignore the test in some situations, which means the test won't -be compiled or run. - -* `ignore-X` where `X` is a target detail or stage will ignore the test accordingly (see below) -* `ignore-pretty` will not compile the pretty-printed test (this is done to test the pretty-printer, but might not always work) -* `ignore-test` always ignores the test -* `ignore-lldb` and `ignore-gdb` will skip a debuginfo test on that debugger. - -`only-X` is the opposite. The test will run only when `X` matches. - -Some examples of `X` in `ignore-X`: - -* Architecture: `aarch64`, `arm`, `asmjs`, `mips`, `wasm32`, `x86_64`, `x86`, ... -* OS: `android`, `emscripten`, `freebsd`, `ios`, `linux`, `macos`, `windows`, ... -* Environment (fourth word of the target triple): `gnu`, `msvc`, `musl`. -* Pointer width: `32bit`, `64bit`. -* Stage: `stage0`, `stage1`, `stage2`. - -### Other Header Commands - -* `min-{gdb,lldb}-version` -* `min-llvm-version` -* `compile-pass` for UI tests, indicates that the test is supposed - to compile, as opposed to the default where the test is supposed to error out. -* `compile-flags` passes extra command-line args to the compiler, - e.g. `compile-flags -g` which forces debuginfo to be enabled. -* `should-fail` indicates that the test should fail; used for "meta testing", - where we test the compiletest program itself to check that it will generate - errors in appropriate scenarios. This header is ignored for pretty-printer tests. -* `gate-test-X` where `X` is a feature marks the test as "gate test" for feature X. - Such tests are supposed to ensure that the compiler errors when usage of a gated - feature is attempted without the proper `#![feature(X)]` tag. - Each unstable lang feature is required to have a gate test. - -## Revisions - -Certain classes of tests support "revisions" (as of the time of this -writing, this includes run-pass, compile-fail, run-fail, and -incremental, though incremental tests are somewhat -different). Revisions allow a single test file to be used for multiple -tests. This is done by adding a special header at the top of the file: - -``` -// revisions: foo bar baz -``` - -This will result in the test being compiled (and tested) three times, -once with `--cfg foo`, once with `--cfg bar`, and once with `--cfg -baz`. You can therefore use `#[cfg(foo)]` etc within the test to tweak -each of these results. - -You can also customize headers and expected error messages to a particular -revision. To do this, add `[foo]` (or `bar`, `baz`, etc) after the `//` -comment, like so: - -``` -// A flag to pass in only for cfg `foo`: -//[foo]compile-flags: -Z verbose - -#[cfg(foo)] -fn test_foo() { - let x: usize = 32_u32; //[foo]~ ERROR mismatched types -} -``` - -Note that not all headers have meaning when customized to a revision. -For example, the `ignore-test` header (and all "ignore" headers) -currently only apply to the test as a whole, not to particular -revisions. The only headers that are intended to really work when -customized to a revision are error patterns and compiler flags. - -## Guide to the UI Tests - -The UI tests are intended to capture the compiler's complete output, -so that we can test all aspects of the presentation. They work by -compiling a file (e.g., `ui/hello_world/main.rs`), capturing the output, -and then applying some normalization (see below). This normalized -result is then compared against reference files named -`ui/hello_world/main.stderr` and `ui/hello_world/main.stdout`. If either of -those files doesn't exist, the output must be empty. If the test run -fails, we will print out the current output, but it is also saved in -`build//test/ui/hello_world/main.stdout` (this path is -printed as part of the test failure message), so you can run `diff` and -so forth. - -Normally, the test-runner checks that UI tests fail compilation. If you want -to do a UI test for code that *compiles* (e.g. to test warnings, or if you -have a collection of tests, only some of which error out), you can use the -`// compile-pass` header command to have the test runner instead -check that the test compiles successfully. - -### Editing and updating the reference files - -If you have changed the compiler's output intentionally, or you are -making a new test, you can pass `--bless` to the command you used to -run the tests. This will then copy over the files -from the build directory and use them as the new reference. - -### Normalization - -The normalization applied is aimed at eliminating output difference -between platforms, mainly about filenames: - -- the test directory is replaced with `$DIR` -- all backslashes (`\`) are converted to forward slashes (`/`) (for Windows) -- all CR LF newlines are converted to LF - -Sometimes these built-in normalizations are not enough. In such cases, you -may provide custom normalization rules using the header commands, e.g. - -``` -// normalize-stdout-test: "foo" -> "bar" -// normalize-stderr-32bit: "fn\(\) \(32 bits\)" -> "fn\(\) \($$PTR bits\)" -// normalize-stderr-64bit: "fn\(\) \(64 bits\)" -> "fn\(\) \($$PTR bits\)" -``` - -This tells the test, on 32-bit platforms, whenever the compiler writes -`fn() (32 bits)` to stderr, it should be normalized to read `fn() ($PTR bits)` -instead. Similar for 64-bit. The replacement is performed by regexes using -default regex flavor provided by `regex` crate. - -The corresponding reference file will use the normalized output to test both -32-bit and 64-bit platforms: - -``` -... - | - = note: source type: fn() ($PTR bits) - = note: target type: u16 (16 bits) -... -``` - -Please see `ui/transmute/main.rs` and `.stderr` for a concrete usage example. - -Besides `normalize-stderr-32bit` and `-64bit`, one may use any target -information or stage supported by `ignore-X` here as well (e.g. -`normalize-stderr-windows` or simply `normalize-stderr-test` for unconditional -replacement). +Documentation the compiler testing framework has moved to +[the rustc guide](https://rust-lang-nursery.github.io/rustc-guide/tests/intro.html). From e37391b389a69e7e78dd93f9aadad5834bb5cfd1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 10 Aug 2018 18:48:36 +0200 Subject: [PATCH 41/57] Remove unwanted console log --- src/librustdoc/html/static/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 07507047dc2c9..b63abec1f0e8b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2214,7 +2214,6 @@ if (hash !== null) { var elem = document.getElementById(hash); if (elem && elem.offsetParent === null) { - console.log(elem, elem.parentNode); if (elem.parentNode && elem.parentNode.previousSibling) { var collapses = elem.parentNode .previousSibling From 538d1ba6d7e300ddd4d6d1ca3a84363b8eff5767 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Kollasch" Date: Fri, 10 Aug 2018 13:42:31 -0500 Subject: [PATCH 42/57] aarch64-unknown-netbsd: add openssl configuration --- src/bootstrap/native.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 9aeb4e0edaed5..d5e1ed02b44c1 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -607,6 +607,7 @@ impl Step for Openssl { "aarch64-linux-android" => "linux-aarch64", "aarch64-unknown-linux-gnu" => "linux-aarch64", "aarch64-unknown-linux-musl" => "linux-aarch64", + "aarch64-unknown-netbsd" => "BSD-generic64", "arm-linux-androideabi" => "android", "arm-unknown-linux-gnueabi" => "linux-armv4", "arm-unknown-linux-gnueabihf" => "linux-armv4", From 4076dc46ae4277953b1310d037b0255802146a86 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 10 Aug 2018 09:36:41 +1200 Subject: [PATCH 43/57] Update RLS --- src/Cargo.lock | 2 +- src/tools/rls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 1ef6b2a571e9c..97e0bf0a99bb1 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1770,7 +1770,7 @@ dependencies = [ [[package]] name = "rls" -version = "0.130.4" +version = "0.130.5" dependencies = [ "cargo 0.30.0", "cargo_metadata 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/tools/rls b/src/tools/rls index c51e3ff2f07f8..9e4d8d520390c 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit c51e3ff2f07f84f26f57fcb51808b1ec7cbe45a6 +Subproject commit 9e4d8d520390c6aeebc33260026c6ae2946c67ac From 5a801c89d097ee3f6e66fd27e9554233dcb1978d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 11 Aug 2018 13:34:15 +0200 Subject: [PATCH 44/57] Fix styles --- src/librustdoc/html/static/themes/dark.css | 4 ++-- src/librustdoc/html/static/themes/light.css | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index faca264ea1006..a2cb79582a14c 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -165,8 +165,8 @@ a { color: #ddd; } -.docblock a:not(.srclink):not(.test-arrow), .docblock-short a:not(.srclink):not(.test-arrow), -.stability a { +.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), .docblock-short +a:not(.srclink):not(.test-arrow), .stability a { color: #D2991D; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index 5725a41d939d5..6a3c1988977e7 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -165,8 +165,8 @@ a { color: #000; } -.docblock a:not(.srclink):not(.test-arrow), .docblock-short a:not(.srclink):not(.test-arrow), -.stability a { +.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), .docblock-short +a:not(.srclink):not(.test-arrow), .stability a { color: #3873AD; } From 53d308fdf86b7e499811650b89789c9c7161faab Mon Sep 17 00:00:00 2001 From: Ryan Scheel Date: Sat, 11 Aug 2018 03:13:29 -0700 Subject: [PATCH 45/57] Show that Command can be reused and remodified The prior documentation did not make it clear this was possible. --- src/libstd/process.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 39692836866ba..ad64ed66e8ec7 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -381,6 +381,39 @@ impl fmt::Debug for ChildStderr { /// /// let hello = output.stdout; /// ``` +/// +/// `Command` can be reused to spawn multiple processes. The builder methods +/// change the command without needing to immediately spawn the process. +/// +/// ```no_run +/// use std::process::Command; +/// +/// let mut echo_hello = Command::new("sh"); +/// echo_hello.arg("-c") +/// .arg("echo hello"); +/// let hello_1 = echo_hello.output().expect("failed to execute process"); +/// let hello_2 = echo_hello.output().expect("failed to execute process"); +/// ``` +/// +/// Similarly, you can call builder methods after spawning a process and then +/// spawn a new process with the modified settings. +/// +/// ```no_run +/// use std::process::Command; +/// +/// let mut list_dir = Command::new("ls"); +/// +/// // Execute `ls` in the current directory of the program. +/// list_dir.status().expect("process failed to execute"); +/// +/// println!(""); +/// +/// // Change `ls` to execute in the root directory. +/// list_dir.current_dir("/"); +/// +/// // And then execute `ls` again but in the root directory. +/// list_dir.status().expect("process failed to execute"); +/// ``` #[stable(feature = "process", since = "1.0.0")] pub struct Command { inner: imp::Command, From 44af0683883b0c1ce2a4d5f360cc9f50062dc9d1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 11 Aug 2018 18:54:36 +0200 Subject: [PATCH 46/57] Remove statics field from CodegenCx --- src/librustc_codegen_llvm/consts.rs | 1 - src/librustc_codegen_llvm/context.rs | 5 ----- src/librustc_codegen_llvm/mono_item.rs | 1 - 3 files changed, 7 deletions(-) diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index fafc0e723225d..80db21d0d338f 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -230,7 +230,6 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value { } cx.instances.borrow_mut().insert(instance, g); - cx.statics.borrow_mut().insert(g, def_id); g } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 7a308bb6e8823..0cf8d72be1b2a 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -13,7 +13,6 @@ use common; use llvm; use rustc::dep_graph::DepGraphSafe; use rustc::hir; -use rustc::hir::def_id::DefId; use debuginfo; use callee; use base; @@ -77,9 +76,6 @@ pub struct CodegenCx<'a, 'tcx: 'a> { /// Cache of emitted const globals (value -> global) pub const_globals: RefCell>, - /// Mapping from static definitions to their DefId's. - pub statics: RefCell>, - /// List of globals for static variables which need to be passed to the /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete. /// (We have to make sure we don't invalidate any Values referring @@ -297,7 +293,6 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> { const_cstr_cache: RefCell::new(FxHashMap()), const_unsized: RefCell::new(FxHashMap()), const_globals: RefCell::new(FxHashMap()), - statics: RefCell::new(FxHashMap()), statics_to_rauw: RefCell::new(Vec::new()), used_statics: RefCell::new(Vec::new()), lltypes: RefCell::new(FxHashMap()), diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index a528008e3b4bd..80c4df1d6b005 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -143,7 +143,6 @@ fn predefine_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, } cx.instances.borrow_mut().insert(instance, g); - cx.statics.borrow_mut().insert(g, def_id); } fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, From f9f934f7fdf456bd5fcbf96b2123520675c053b7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 11 Aug 2018 17:02:31 +0200 Subject: [PATCH 47/57] Add let keyword doc --- src/libstd/keyword_docs.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index 01bd3edaee981..4f6bda6cfe379 100644 --- a/src/libstd/keyword_docs.rs +++ b/src/libstd/keyword_docs.rs @@ -1,4 +1,4 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -26,3 +26,33 @@ /// /// [book]: https://doc.rust-lang.org/book/second-edition/ch03-03-how-functions-work.html mod fn_keyword { } + +#[doc(keyword = "let")] +// +/// The `let` keyword. +/// +/// The `let` keyword is used to declare a variable. +/// +/// Example: +/// +/// ```rust +/// # #![allow(unused_assignments)] +/// let x = 3; // We create a variable named `x` with the value `3`. +/// ``` +/// +/// By default, all variables are **not** mutable. If you want a mutable variable, +/// you'll have to use the `mut` keyword. +/// +/// Example: +/// +/// ```rust +/// # #![allow(unused_assignments)] +/// let mut x = 3; // We create a mutable variable named `x` with the value `3`. +/// +/// x += 4; // `x` is now equal to `7`. +/// ``` +/// +/// For more information about the `let` keyword, take a look at the [Rust Book][book]. +/// +/// [book]: https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html +mod let_keyword { } From ec18991492849393a8b3ae4e0c70a22319e8ea60 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Aug 2018 14:09:59 -0400 Subject: [PATCH 48/57] Add links to std::char::REPLACEMENT_CHARACTER from docs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a few places where we mention the replacement character in the docs, and it could be helpful for users to utilize the constant which is available in the standard library, so let’s link to it! --- src/liballoc/string.rs | 6 ++++-- src/libcore/str/mod.rs | 5 ++++- src/libstd/ffi/c_str.rs | 7 ++++--- src/libstd/ffi/os_str.rs | 4 +++- src/libstd/path.rs | 4 +++- src/libstd/sys/windows/ext/ffi.rs | 3 ++- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 631779a17a165..dd559df08cce6 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -519,10 +519,11 @@ impl String { /// between the two. Not all byte slices are valid strings, however: strings /// are required to be valid UTF-8. During this conversion, /// `from_utf8_lossy()` will replace any invalid UTF-8 sequences with - /// `U+FFFD REPLACEMENT CHARACTER`, which looks like this: � + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD], which looks like this: � /// /// [`u8`]: ../../std/primitive.u8.html /// [byteslice]: ../../std/primitive.slice.html + /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html /// /// If you are sure that the byte slice is valid UTF-8, and you don't want /// to incur the overhead of the conversion, there is an unsafe version @@ -621,7 +622,7 @@ impl String { } /// Decode a UTF-16 encoded slice `v` into a `String`, replacing - /// invalid data with the replacement character (U+FFFD). + /// invalid data with [the replacement character (`U+FFFD`)][U+FFFD]. /// /// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`], /// `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8 @@ -629,6 +630,7 @@ impl String { /// /// [`from_utf8_lossy`]: #method.from_utf8_lossy /// [`Cow<'a, str>`]: ../borrow/enum.Cow.html + /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html /// /// # Examples /// diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 356534a91879c..54b17b0fbb320 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -244,7 +244,10 @@ impl Utf8Error { /// The length provided is that of the invalid byte sequence /// that starts at the index given by `valid_up_to()`. /// Decoding should resume after that sequence - /// (after inserting a U+FFFD REPLACEMENT CHARACTER) in case of lossy decoding. + /// (after inserting a [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]) in case of + /// lossy decoding. + /// + /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html #[stable(feature = "utf8_error_error_len", since = "1.20.0")] pub fn error_len(&self) -> Option { self.error_len.map(|len| len as usize) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index b2777f5c48541..2b87094926cf5 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -1175,9 +1175,9 @@ impl CStr { /// If the contents of the `CStr` are valid UTF-8 data, this /// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)` /// with the the corresponding [`&str`] slice. Otherwise, it will - /// replace any invalid UTF-8 sequences with `U+FFFD REPLACEMENT - /// CHARACTER` and return a [`Cow`]`::`[`Owned`]`(`[`String`]`)` - /// with the result. + /// replace any invalid UTF-8 sequences with + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a + /// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result. /// /// > **Note**: This method is currently implemented to check for validity /// > after a constant-time cast, but it is planned to alter its definition @@ -1189,6 +1189,7 @@ impl CStr { /// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned /// [`str`]: ../primitive.str.html /// [`String`]: ../string/struct.String.html + /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html /// /// # Examples /// diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 9e501a84e05ec..6bcd62dbd59c2 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -520,10 +520,12 @@ impl OsStr { /// Converts an `OsStr` to a [`Cow`]`<`[`str`]`>`. /// - /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. + /// Any non-Unicode sequences are replaced with + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]. /// /// [`Cow`]: ../../std/borrow/enum.Cow.html /// [`str`]: ../../std/primitive.str.html + /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html /// /// # Examples /// diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 688a7e99f10ed..ca8be75fab5be 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1737,9 +1737,11 @@ impl Path { /// Converts a `Path` to a [`Cow`]. /// - /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. + /// Any non-Unicode sequences are replaced with + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]. /// /// [`Cow`]: ../borrow/enum.Cow.html + /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html /// /// # Examples /// diff --git a/src/libstd/sys/windows/ext/ffi.rs b/src/libstd/sys/windows/ext/ffi.rs index 98d4355248990..bae0d02786a09 100644 --- a/src/libstd/sys/windows/ext/ffi.rs +++ b/src/libstd/sys/windows/ext/ffi.rs @@ -31,7 +31,7 @@ //! //! If Rust code *does* need to look into those strings, it can //! convert them to valid UTF-8, possibly lossily, by substituting -//! invalid sequences with U+FFFD REPLACEMENT CHARACTER, as is +//! invalid sequences with [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD], as is //! conventionally done in other Rust APIs that deal with string //! encodings. //! @@ -65,6 +65,7 @@ //! [`from_wide`]: trait.OsStringExt.html#tymethod.from_wide //! [`encode_wide`]: trait.OsStrExt.html#tymethod.encode_wide //! [`collect`]: ../../../iter/trait.Iterator.html#method.collect +//! [U+FFFD]: ../../../char/constant.REPLACEMENT_CHARACTER.html #![stable(feature = "rust1", since = "1.0.0")] From 0070b46626407f2e815993d46aef2b2637c2a4ed Mon Sep 17 00:00:00 2001 From: "Havvy (Ryan Scheel)" Date: Sat, 11 Aug 2018 13:02:49 -0700 Subject: [PATCH 49/57] Fix indent --- src/libstd/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index ad64ed66e8ec7..53babd449a992 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -390,7 +390,7 @@ impl fmt::Debug for ChildStderr { /// /// let mut echo_hello = Command::new("sh"); /// echo_hello.arg("-c") -/// .arg("echo hello"); +/// .arg("echo hello"); /// let hello_1 = echo_hello.output().expect("failed to execute process"); /// let hello_2 = echo_hello.output().expect("failed to execute process"); /// ``` From 90a6954327bb4f018eab155f43299d4bf67abe41 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 4 Aug 2018 02:23:21 +0100 Subject: [PATCH 50/57] Emit error for pattern arguments in trait methods The error and check for this already existed, but the parser didn't try to parse trait method arguments as patterns, so the error was never emitted. This surfaces the error, so we get better errors than simple parse errors. --- src/librustc_passes/diagnostics.rs | 14 +++++++- src/libsyntax/lib.rs | 1 + src/libsyntax/parse/parser.rs | 53 +++++++++++++++++++----------- src/test/ui/E0642.rs | 15 +++++++++ src/test/ui/E0642.stderr | 9 +++++ 5 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 src/test/ui/E0642.rs create mode 100644 src/test/ui/E0642.stderr diff --git a/src/librustc_passes/diagnostics.rs b/src/librustc_passes/diagnostics.rs index f1ec3371c3b9a..b78f2ca676d2f 100644 --- a/src/librustc_passes/diagnostics.rs +++ b/src/librustc_passes/diagnostics.rs @@ -261,6 +261,19 @@ let result = loop { // ok! ``` "##, +E0642: r##" +Trait methods currently cannot take patterns as arguments. + +Example of erroneous code: + +```compile_fail,E0642 +trait Foo { + fn foo((x, y): (i32, i32)); // error: patterns aren't allowed + // in methods without bodies +} +``` +"##, + E0695: r##" A `break` statement without a label appeared inside a labeled block. @@ -306,7 +319,6 @@ register_diagnostics! { E0561, // patterns aren't allowed in function pointer types E0567, // auto traits can not have generic parameters E0568, // auto traits can not have super traits - E0642, // patterns aren't allowed in methods without bodies E0666, // nested `impl Trait` is illegal E0667, // `impl Trait` in projections E0696, // `continue` pointing to a labeled block diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index c8e60620248b3..76035a73d1a15 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -26,6 +26,7 @@ #![feature(slice_sort_by_cached_key)] #![feature(str_escape)] #![feature(unicode_internals)] +#![feature(catch_expr)] #![recursion_limit="256"] diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9011b6e48b974..5a2fd5f0145fc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1371,7 +1371,7 @@ impl<'a> Parser<'a> { let ident = self.parse_ident()?; let mut generics = self.parse_generics()?; - let d = self.parse_fn_decl_with_self(|p: &mut Parser<'a>|{ + let d = self.parse_fn_decl_with_self(|p: &mut Parser<'a>| { // This is somewhat dubious; We don't want to allow // argument names to be left off if there is a // definition... @@ -1744,30 +1744,43 @@ impl<'a> Parser<'a> { fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); - let (pat, ty) = if require_name || self.is_named_argument() { - debug!("parse_arg_general parse_pat (require_name:{})", - require_name); - let pat = self.parse_pat()?; + let parser_snapshot_before_pat = self.clone(); + // We're going to try parsing the argument as a pattern (even if it's not + // allowed, such as for trait methods without bodies). This way we can provide + // better errors to the user. + let pat_arg: PResult<'a, (P, P)> = do catch { + let pat = self.parse_pat()?; self.expect(&token::Colon)?; (pat, self.parse_ty()?) - } else { - debug!("parse_arg_general ident_to_pat"); - let ident = Ident::new(keywords::Invalid.name(), self.prev_span); - let ty = self.parse_ty()?; - let pat = P(Pat { - id: ast::DUMMY_NODE_ID, - node: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), ident, None), - span: ty.span, - }); - (pat, ty) }; - Ok(Arg { - ty, - pat, - id: ast::DUMMY_NODE_ID, - }) + let is_named_argument = self.is_named_argument(); + match pat_arg { + Ok((pat, ty)) => { + Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) + } + Err(mut err) => { + if require_name || is_named_argument { + Err(err) + } else { + err.cancel(); + // Recover from attempting to parse the argument as a pattern. This means + // the type is alone, with no name, e.g. `fn foo(u32)`. + mem::replace(self, parser_snapshot_before_pat); + debug!("parse_arg_general ident_to_pat"); + let ident = Ident::new(keywords::Invalid.name(), self.prev_span); + let ty = self.parse_ty()?; + let pat = P(Pat { + id: ast::DUMMY_NODE_ID, + node: PatKind::Ident( + BindingMode::ByValue(Mutability::Immutable), ident, None), + span: ty.span, + }); + Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) + } + } + } } /// Parse a single function argument diff --git a/src/test/ui/E0642.rs b/src/test/ui/E0642.rs new file mode 100644 index 0000000000000..a09846cb3a1e8 --- /dev/null +++ b/src/test/ui/E0642.rs @@ -0,0 +1,15 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies +} + +fn main() {} diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr new file mode 100644 index 0000000000000..edc430d578ba9 --- /dev/null +++ b/src/test/ui/E0642.stderr @@ -0,0 +1,9 @@ +error[E0642]: patterns aren't allowed in methods without bodies + --> $DIR/E0642.rs:12:12 + | +LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0642`. From b05f0bec1a6f576cd275e52a8a0a0165fb25f77a Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 4 Aug 2018 11:48:33 +0100 Subject: [PATCH 51/57] Suggest replacing patterns with underscores --- src/librustc_passes/ast_validation.rs | 7 +++++-- src/test/ui/E0642.stderr | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 0ea90e7453190..c75ae07fe6618 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -344,8 +344,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> { trait_item.id, span, "patterns aren't allowed in methods without bodies"); } else { - struct_span_err!(self.session, span, E0642, - "patterns aren't allowed in methods without bodies").emit(); + let mut err = struct_span_err!(self.session, span, E0642, + "patterns aren't allowed in methods without bodies"); + err.span_suggestion(span, + "use an underscore to ignore the name", "_".to_owned()); + err.emit(); } }); } diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index edc430d578ba9..5291c016c7faf 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -2,7 +2,7 @@ error[E0642]: patterns aren't allowed in methods without bodies --> $DIR/E0642.rs:12:12 | LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies - | ^^^^^^ + | ^^^^^^ help: use an underscore to ignore the name: `_` error: aborting due to previous error From 235905c080bf953a522ff86d4fec6134ac4fb371 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 6 Aug 2018 18:14:57 +0100 Subject: [PATCH 52/57] Fix handling of trait methods with bodies and improve efficiency --- src/librustc_passes/ast_validation.rs | 26 +++++----- src/libsyntax/parse/parser.rs | 49 ++++++++++++------- .../compile-fail/no-patterns-in-args-2.rs | 4 +- .../compile-fail/no-patterns-in-args-macro.rs | 2 +- src/test/ui/E0642.rs | 6 ++- src/test/ui/E0642.stderr | 22 +++++++-- 6 files changed, 70 insertions(+), 39 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index c75ae07fe6618..7022136f23984 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -336,22 +336,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let TraitItemKind::Method(ref sig, ref block) = trait_item.node { self.check_trait_fn_not_async(trait_item.span, sig.header.asyncness); self.check_trait_fn_not_const(sig.header.constness); - if block.is_none() { - self.check_decl_no_pat(&sig.decl, |span, mut_ident| { - if mut_ident { + self.check_decl_no_pat(&sig.decl, |span, mut_ident| { + if mut_ident { + if block.is_none() { self.session.buffer_lint( lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY, trait_item.id, span, - "patterns aren't allowed in methods without bodies"); - } else { - let mut err = struct_span_err!(self.session, span, E0642, - "patterns aren't allowed in methods without bodies"); - err.span_suggestion(span, - "use an underscore to ignore the name", "_".to_owned()); - err.emit(); + "patterns aren't allowed in trait methods"); } - }); - } + } else { + let mut err = struct_span_err!(self.session, span, E0642, + "patterns aren't allowed in trait methods"); + let suggestion = "give this argument a name or use an \ + underscore to ignore it, instead of a \ + tuple pattern"; + err.span_suggestion(span, suggestion, "_".to_owned()); + err.emit(); + } + }); } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5a2fd5f0145fc..57eb1f52fb703 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1744,7 +1744,16 @@ impl<'a> Parser<'a> { fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); - let parser_snapshot_before_pat = self.clone(); + // If we see `ident :`, then we know that the argument is just of the + // form `type`, which means we won't need to recover from parsing a + // pattern and so we don't need to store a parser snapshot. + let parser_snapshot_before_pat = if + self.look_ahead(1, |t| t.is_ident()) && + self.look_ahead(2, |t| t == &token::Colon) { + None + } else { + Some(self.clone()) + }; // We're going to try parsing the argument as a pattern (even if it's not // allowed, such as for trait methods without bodies). This way we can provide @@ -1755,29 +1764,31 @@ impl<'a> Parser<'a> { (pat, self.parse_ty()?) }; - let is_named_argument = self.is_named_argument(); match pat_arg { Ok((pat, ty)) => { Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) } Err(mut err) => { - if require_name || is_named_argument { - Err(err) - } else { - err.cancel(); - // Recover from attempting to parse the argument as a pattern. This means - // the type is alone, with no name, e.g. `fn foo(u32)`. - mem::replace(self, parser_snapshot_before_pat); - debug!("parse_arg_general ident_to_pat"); - let ident = Ident::new(keywords::Invalid.name(), self.prev_span); - let ty = self.parse_ty()?; - let pat = P(Pat { - id: ast::DUMMY_NODE_ID, - node: PatKind::Ident( - BindingMode::ByValue(Mutability::Immutable), ident, None), - span: ty.span, - }); - Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) + match (require_name || self.is_named_argument(), parser_snapshot_before_pat) { + (true, _) | (_, None) => { + Err(err) + } + (false, Some(parser_snapshot_before_pat)) => { + err.cancel(); + // Recover from attempting to parse the argument as a pattern. This means + // the type is alone, with no name, e.g. `fn foo(u32)`. + mem::replace(self, parser_snapshot_before_pat); + debug!("parse_arg_general ident_to_pat"); + let ident = Ident::new(keywords::Invalid.name(), self.prev_span); + let ty = self.parse_ty()?; + let pat = P(Pat { + id: ast::DUMMY_NODE_ID, + node: PatKind::Ident( + BindingMode::ByValue(Mutability::Immutable), ident, None), + span: ty.span, + }); + Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) + } } } } diff --git a/src/test/compile-fail/no-patterns-in-args-2.rs b/src/test/compile-fail/no-patterns-in-args-2.rs index 4d2412c34a5fa..80e6967980119 100644 --- a/src/test/compile-fail/no-patterns-in-args-2.rs +++ b/src/test/compile-fail/no-patterns-in-args-2.rs @@ -11,9 +11,9 @@ #![deny(patterns_in_fns_without_body)] trait Tr { - fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in methods without bodies + fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in trait methods //~^ WARN was previously accepted - fn f2(&arg: u8); //~ ERROR patterns aren't allowed in methods without bodies + fn f2(&arg: u8); //~ ERROR patterns aren't allowed in trait methods fn g1(arg: u8); // OK fn g2(_: u8); // OK #[allow(anonymous_parameters)] diff --git a/src/test/compile-fail/no-patterns-in-args-macro.rs b/src/test/compile-fail/no-patterns-in-args-macro.rs index f85ce8f57ea71..546c40ecbd045 100644 --- a/src/test/compile-fail/no-patterns-in-args-macro.rs +++ b/src/test/compile-fail/no-patterns-in-args-macro.rs @@ -30,7 +30,7 @@ mod bad_pat { m!((bad, pat)); //~^ ERROR patterns aren't allowed in function pointer types //~| ERROR patterns aren't allowed in foreign function declarations - //~| ERROR patterns aren't allowed in methods without bodies + //~| ERROR patterns aren't allowed in trait methods } fn main() {} diff --git a/src/test/ui/E0642.rs b/src/test/ui/E0642.rs index a09846cb3a1e8..837a9365271e2 100644 --- a/src/test/ui/E0642.rs +++ b/src/test/ui/E0642.rs @@ -9,7 +9,11 @@ // except according to those terms. trait Foo { - fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies + fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods +} + +trait Bar { + fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods } fn main() {} diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index 5291c016c7faf..07ec8b4cc2c8f 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -1,9 +1,23 @@ -error[E0642]: patterns aren't allowed in methods without bodies +error[E0642]: patterns aren't allowed in trait methods --> $DIR/E0642.rs:12:12 | -LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies - | ^^^^^^ help: use an underscore to ignore the name: `_` +LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods + | ^^^^^^ +help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern + | +LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods + | ^ + +error[E0642]: patterns aren't allowed in trait methods + --> $DIR/E0642.rs:16:12 + | +LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods + | ^^^^^^ +help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern + | +LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods + | ^ -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0642`. From a478cd41e3f203ec531bfce7efb8fc602aad5c7d Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 7 Aug 2018 00:03:26 +0100 Subject: [PATCH 53/57] Improve diagnostics --- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_passes/diagnostics.rs | 10 +++++++++- src/libsyntax/parse/parser.rs | 2 +- src/test/ui/E0642.stderr | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 7022136f23984..2195331f465ba 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -348,7 +348,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let mut err = struct_span_err!(self.session, span, E0642, "patterns aren't allowed in trait methods"); let suggestion = "give this argument a name or use an \ - underscore to ignore it, instead of a \ + underscore to ignore it instead of using a \ tuple pattern"; err.span_suggestion(span, suggestion, "_".to_owned()); err.emit(); diff --git a/src/librustc_passes/diagnostics.rs b/src/librustc_passes/diagnostics.rs index b78f2ca676d2f..f1d0a4fee341e 100644 --- a/src/librustc_passes/diagnostics.rs +++ b/src/librustc_passes/diagnostics.rs @@ -269,7 +269,15 @@ Example of erroneous code: ```compile_fail,E0642 trait Foo { fn foo((x, y): (i32, i32)); // error: patterns aren't allowed - // in methods without bodies + // in trait methods +} +``` + +You can instead use a single name for the argument: + +``` +trait Foo { + fn foo(x_and_y: (i32, i32)); // ok! } ``` "##, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 57eb1f52fb703..a1dbe93fdfe35 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1744,7 +1744,7 @@ impl<'a> Parser<'a> { fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); - // If we see `ident :`, then we know that the argument is just of the + // If we see `ident :`, then we know that the argument is not just of the // form `type`, which means we won't need to recover from parsing a // pattern and so we don't need to store a parser snapshot. let parser_snapshot_before_pat = if diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index 07ec8b4cc2c8f..8c16b8b30cd53 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -3,7 +3,7 @@ error[E0642]: patterns aren't allowed in trait methods | LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern +help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern | LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^ @@ -13,7 +13,7 @@ error[E0642]: patterns aren't allowed in trait methods | LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it, instead of a tuple pattern +help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern | LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^ From e4c3b49fe790dd23f32acace8157d897d31c0cb3 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 9 Aug 2018 23:23:08 +0100 Subject: [PATCH 54/57] Emit an error during parsing --- src/librustc_passes/ast_validation.rs | 21 ++---- src/libsyntax/parse/parser.rs | 104 +++++++++++++++----------- src/test/ui/E0642.stderr | 9 +-- 3 files changed, 74 insertions(+), 60 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 2195331f465ba..e15dab404f478 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -336,24 +336,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let TraitItemKind::Method(ref sig, ref block) = trait_item.node { self.check_trait_fn_not_async(trait_item.span, sig.header.asyncness); self.check_trait_fn_not_const(sig.header.constness); - self.check_decl_no_pat(&sig.decl, |span, mut_ident| { - if mut_ident { - if block.is_none() { + if block.is_none() { + self.check_decl_no_pat(&sig.decl, |span, mut_ident| { + if mut_ident { self.session.buffer_lint( lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY, trait_item.id, span, "patterns aren't allowed in trait methods"); + } else { + struct_span_err!(self.session, span, E0642, + "patterns aren't allowed in trait methods").emit(); } - } else { - let mut err = struct_span_err!(self.session, span, E0642, - "patterns aren't allowed in trait methods"); - let suggestion = "give this argument a name or use an \ - underscore to ignore it instead of using a \ - tuple pattern"; - err.span_suggestion(span, suggestion, "_".to_owned()); - err.emit(); - } - }); + }); + } } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a1dbe93fdfe35..9a49d705c464b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1744,54 +1744,74 @@ impl<'a> Parser<'a> { fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); - // If we see `ident :`, then we know that the argument is not just of the - // form `type`, which means we won't need to recover from parsing a - // pattern and so we don't need to store a parser snapshot. - let parser_snapshot_before_pat = if - self.look_ahead(1, |t| t.is_ident()) && - self.look_ahead(2, |t| t == &token::Colon) { - None - } else { - Some(self.clone()) - }; - - // We're going to try parsing the argument as a pattern (even if it's not - // allowed, such as for trait methods without bodies). This way we can provide - // better errors to the user. - let pat_arg: PResult<'a, (P, P)> = do catch { + let (pat, ty) = if require_name || self.is_named_argument() { + debug!("parse_arg_general parse_pat (require_name:{})", + require_name); let pat = self.parse_pat()?; + self.expect(&token::Colon)?; (pat, self.parse_ty()?) - }; + } else { + debug!("parse_arg_general ident_to_pat"); + + // If we see `ident :`, then we know that the argument is not just of the + // form `type`, which means we won't need to recover from parsing a + // pattern and so we don't need to store a parser snapshot. + let parser_snapshot_before_pat = if + self.look_ahead(1, |t| t.is_ident()) && + self.look_ahead(2, |t| t == &token::Colon) { + None + } else { + Some(self.clone()) + }; - match pat_arg { - Ok((pat, ty)) => { - Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) - } - Err(mut err) => { - match (require_name || self.is_named_argument(), parser_snapshot_before_pat) { - (true, _) | (_, None) => { - Err(err) - } - (false, Some(parser_snapshot_before_pat)) => { - err.cancel(); - // Recover from attempting to parse the argument as a pattern. This means - // the type is alone, with no name, e.g. `fn foo(u32)`. - mem::replace(self, parser_snapshot_before_pat); - debug!("parse_arg_general ident_to_pat"); - let ident = Ident::new(keywords::Invalid.name(), self.prev_span); - let ty = self.parse_ty()?; - let pat = P(Pat { - id: ast::DUMMY_NODE_ID, - node: PatKind::Ident( - BindingMode::ByValue(Mutability::Immutable), ident, None), - span: ty.span, - }); - Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) - } + // We're going to try parsing the argument as a pattern (even though it's not + // allowed). This way we can provide better errors to the user. + let pat_arg: PResult<'a, _> = do catch { + let pat = self.parse_pat()?; + self.expect(&token::Colon)?; + (pat, self.parse_ty()?) + }; + + match pat_arg { + Ok((pat, ty)) => { + let mut err = self.diagnostic() + .struct_span_err(pat.span, "patterns aren't allowed in trait methods"); + err.span_suggestion_short_with_applicability( + pat.span, + "give this argument a name or use an underscore to ignore it", + "_".to_owned(), + Applicability::MachineApplicable, + ); + err.emit(); + // Pretend the pattern is `_`, to avoid duplicate errors from AST validation. + let pat = P(Pat { + node: PatKind::Wild, + span: pat.span, + id: ast::DUMMY_NODE_ID + }); + (pat, ty) + } + Err(mut err) => { + err.cancel(); + // Recover from attempting to parse the argument as a pattern. This means + // the type is alone, with no name, e.g. `fn foo(u32)`. + mem::replace(self, parser_snapshot_before_pat.unwrap()); + debug!("parse_arg_general ident_to_pat"); + let ident = Ident::new(keywords::Invalid.name(), self.prev_span); + let ty = self.parse_ty()?; + let pat = P(Pat { + id: ast::DUMMY_NODE_ID, + node: PatKind::Ident( + BindingMode::ByValue(Mutability::Immutable), ident, None), + span: ty.span, + }); + (pat, ty) } } - } + }; + + Ok(Arg { ty, pat, id: ast::DUMMY_NODE_ID }) } /// Parse a single function argument diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index 8c16b8b30cd53..b8e0496945a15 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -1,23 +1,22 @@ -error[E0642]: patterns aren't allowed in trait methods +error: patterns aren't allowed in trait methods --> $DIR/E0642.rs:12:12 | LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern +help: give this argument a name or use an underscore to ignore it | LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^ -error[E0642]: patterns aren't allowed in trait methods +error: patterns aren't allowed in trait methods --> $DIR/E0642.rs:16:12 | LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^^^^^^ -help: give this argument a name or use an underscore to ignore it instead of using a tuple pattern +help: give this argument a name or use an underscore to ignore it | LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods | ^ error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0642`. From 49e9c5fe90db9a70697da8a3bf4237492376c541 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 10 Aug 2018 01:49:45 +0100 Subject: [PATCH 55/57] Add E0642 to parser error --- src/libsyntax/parse/parser.rs | 9 ++++++--- src/test/ui/E0642.stderr | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9a49d705c464b..14026c5bede68 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -44,7 +44,7 @@ use ast::{RangeEnd, RangeSyntax}; use {ast, attr}; use codemap::{self, CodeMap, Spanned, respan}; use syntax_pos::{self, Span, MultiSpan, BytePos, FileName, edition::Edition}; -use errors::{self, Applicability, DiagnosticBuilder}; +use errors::{self, Applicability, DiagnosticBuilder, DiagnosticId}; use parse::{self, SeqSep, classify, token}; use parse::lexer::TokenAndSpan; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; @@ -1775,8 +1775,11 @@ impl<'a> Parser<'a> { match pat_arg { Ok((pat, ty)) => { - let mut err = self.diagnostic() - .struct_span_err(pat.span, "patterns aren't allowed in trait methods"); + let mut err = self.diagnostic().struct_span_err_with_code( + pat.span, + "patterns aren't allowed in trait methods", + DiagnosticId::Error("E0642".into()), + ); err.span_suggestion_short_with_applicability( pat.span, "give this argument a name or use an underscore to ignore it", diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index b8e0496945a15..1723e97b45e42 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -1,4 +1,4 @@ -error: patterns aren't allowed in trait methods +error[E0642]: patterns aren't allowed in trait methods --> $DIR/E0642.rs:12:12 | LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods @@ -8,7 +8,7 @@ help: give this argument a name or use an underscore to ignore it LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods | ^ -error: patterns aren't allowed in trait methods +error[E0642]: patterns aren't allowed in trait methods --> $DIR/E0642.rs:16:12 | LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods @@ -20,3 +20,4 @@ LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait met error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0642`. From 5c814e2e4e0649972ec6a18c7dbf57259edf2210 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 Aug 2018 21:25:48 +0100 Subject: [PATCH 56/57] Clean up and add extra tests --- src/librustc_passes/ast_validation.rs | 4 ++-- src/libsyntax/parse/parser.rs | 15 +++------------ src/test/compile-fail/no-patterns-in-args-2.rs | 4 ++-- .../compile-fail/no-patterns-in-args-macro.rs | 2 +- src/test/ui/E0642.rs | 15 ++++++++++----- src/test/ui/E0642.stderr | 16 ++++++++-------- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index e15dab404f478..0ea90e7453190 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -342,10 +342,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.session.buffer_lint( lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY, trait_item.id, span, - "patterns aren't allowed in trait methods"); + "patterns aren't allowed in methods without bodies"); } else { struct_span_err!(self.session, span, E0642, - "patterns aren't allowed in trait methods").emit(); + "patterns aren't allowed in methods without bodies").emit(); } }); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 14026c5bede68..746e03d771a88 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1754,16 +1754,7 @@ impl<'a> Parser<'a> { } else { debug!("parse_arg_general ident_to_pat"); - // If we see `ident :`, then we know that the argument is not just of the - // form `type`, which means we won't need to recover from parsing a - // pattern and so we don't need to store a parser snapshot. - let parser_snapshot_before_pat = if - self.look_ahead(1, |t| t.is_ident()) && - self.look_ahead(2, |t| t == &token::Colon) { - None - } else { - Some(self.clone()) - }; + let parser_snapshot_before_pat = self.clone(); // We're going to try parsing the argument as a pattern (even though it's not // allowed). This way we can provide better errors to the user. @@ -1777,7 +1768,7 @@ impl<'a> Parser<'a> { Ok((pat, ty)) => { let mut err = self.diagnostic().struct_span_err_with_code( pat.span, - "patterns aren't allowed in trait methods", + "patterns aren't allowed in methods without bodies", DiagnosticId::Error("E0642".into()), ); err.span_suggestion_short_with_applicability( @@ -1799,7 +1790,7 @@ impl<'a> Parser<'a> { err.cancel(); // Recover from attempting to parse the argument as a pattern. This means // the type is alone, with no name, e.g. `fn foo(u32)`. - mem::replace(self, parser_snapshot_before_pat.unwrap()); + mem::replace(self, parser_snapshot_before_pat); debug!("parse_arg_general ident_to_pat"); let ident = Ident::new(keywords::Invalid.name(), self.prev_span); let ty = self.parse_ty()?; diff --git a/src/test/compile-fail/no-patterns-in-args-2.rs b/src/test/compile-fail/no-patterns-in-args-2.rs index 80e6967980119..4d2412c34a5fa 100644 --- a/src/test/compile-fail/no-patterns-in-args-2.rs +++ b/src/test/compile-fail/no-patterns-in-args-2.rs @@ -11,9 +11,9 @@ #![deny(patterns_in_fns_without_body)] trait Tr { - fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in trait methods + fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in methods without bodies //~^ WARN was previously accepted - fn f2(&arg: u8); //~ ERROR patterns aren't allowed in trait methods + fn f2(&arg: u8); //~ ERROR patterns aren't allowed in methods without bodies fn g1(arg: u8); // OK fn g2(_: u8); // OK #[allow(anonymous_parameters)] diff --git a/src/test/compile-fail/no-patterns-in-args-macro.rs b/src/test/compile-fail/no-patterns-in-args-macro.rs index 546c40ecbd045..f85ce8f57ea71 100644 --- a/src/test/compile-fail/no-patterns-in-args-macro.rs +++ b/src/test/compile-fail/no-patterns-in-args-macro.rs @@ -30,7 +30,7 @@ mod bad_pat { m!((bad, pat)); //~^ ERROR patterns aren't allowed in function pointer types //~| ERROR patterns aren't allowed in foreign function declarations - //~| ERROR patterns aren't allowed in trait methods + //~| ERROR patterns aren't allowed in methods without bodies } fn main() {} diff --git a/src/test/ui/E0642.rs b/src/test/ui/E0642.rs index 837a9365271e2..58ccfc56ab79a 100644 --- a/src/test/ui/E0642.rs +++ b/src/test/ui/E0642.rs @@ -8,12 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait Foo { - fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods -} +#[derive(Clone, Copy)] +struct S; + +trait T { + fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies + + fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies -trait Bar { - fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods + fn f(&ident: &S) {} // ok + fn g(&&ident: &&S) {} // ok + fn h(mut ident: S) {} // ok } fn main() {} diff --git a/src/test/ui/E0642.stderr b/src/test/ui/E0642.stderr index 1723e97b45e42..34c163e210970 100644 --- a/src/test/ui/E0642.stderr +++ b/src/test/ui/E0642.stderr @@ -1,21 +1,21 @@ -error[E0642]: patterns aren't allowed in trait methods - --> $DIR/E0642.rs:12:12 +error[E0642]: patterns aren't allowed in methods without bodies + --> $DIR/E0642.rs:15:12 | -LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in trait methods +LL | fn foo((x, y): (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies | ^^^^^^ help: give this argument a name or use an underscore to ignore it | -LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in trait methods +LL | fn foo(_: (i32, i32)); //~ ERROR patterns aren't allowed in methods without bodies | ^ -error[E0642]: patterns aren't allowed in trait methods - --> $DIR/E0642.rs:16:12 +error[E0642]: patterns aren't allowed in methods without bodies + --> $DIR/E0642.rs:17:12 | -LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods +LL | fn bar((x, y): (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies | ^^^^^^ help: give this argument a name or use an underscore to ignore it | -LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in trait methods +LL | fn bar(_: (i32, i32)) {} //~ ERROR patterns aren't allowed in methods without bodies | ^ error: aborting due to 2 previous errors From 66fd1ebfae2fff815f27bf2be19469f40dd99c88 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 12 Aug 2018 17:59:18 +0000 Subject: [PATCH 57/57] Make LLVM emit assembly comments with -Z asm-comments. Fixes #35741. --- src/librustc_codegen_llvm/back/write.rs | 3 +++ src/librustc_codegen_llvm/llvm/ffi.rs | 3 ++- src/rustllvm/PassWrapper.cpp | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index cdfa874b1772a..97f3cf614d628 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -182,6 +182,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool) let is_pie_binary = !find_features && is_pie_binary(sess); let trap_unreachable = sess.target.target.options.trap_unreachable; + let asm_comments = sess.asm_comments(); + Arc::new(move || { let tm = unsafe { llvm::LLVMRustCreateTargetMachine( @@ -195,6 +197,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool) fdata_sections, trap_unreachable, singlethread, + asm_comments, ) }; diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index a894f8e2fdb96..d94645e61f2ea 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1455,7 +1455,8 @@ extern "C" { FunctionSections: bool, DataSections: bool, TrapUnreachable: bool, - Singlethread: bool) + Singlethread: bool, + AsmComments: bool) -> Option<&'static mut TargetMachine>; pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine); pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module); diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 7305dc71cbf63..d9fbd494ab348 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -366,7 +366,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( bool PositionIndependentExecutable, bool FunctionSections, bool DataSections, bool TrapUnreachable, - bool Singlethread) { + bool Singlethread, + bool AsmComments) { auto OptLevel = fromRust(RustOptLevel); auto RM = fromRust(RustReloc); @@ -393,6 +394,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( } Options.DataSections = DataSections; Options.FunctionSections = FunctionSections; + Options.MCOptions.AsmVerbose = AsmComments; + Options.MCOptions.PreserveAsmComments = AsmComments; if (TrapUnreachable) { // Tell LLVM to codegen `unreachable` into an explicit trap instruction.