From e3044432c7d1d5ec64a3e96f7856df74d9e43b43 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 7 Jul 2021 16:25:46 +0000 Subject: [PATCH 1/7] Move [debug_]assert_matches to mod {core, std}::assert. --- compiler/rustc_middle/src/ich/impls_syntax.rs | 1 + compiler/rustc_mir/src/interpret/memory.rs | 1 + library/core/src/lib.rs | 10 ++++++++++ library/core/src/macros/mod.rs | 17 +++++++++++------ library/std/src/lib.rs | 4 ++-- src/test/ui/macros/assert-matches-macro-msg.rs | 2 ++ src/test/ui/matches2021.rs | 2 ++ src/test/ui/resolve/resolve-hint-macro.rs | 4 ++-- src/test/ui/resolve/resolve-hint-macro.stderr | 10 +++++----- 9 files changed, 36 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index 2d8f661ef59e9..1c66f831b5f4b 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -6,6 +6,7 @@ use crate::ich::StableHashingContext; use rustc_ast as ast; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_span::{BytePos, NormalizedPos, SourceFile}; +use std::assert::assert_matches; use smallvec::SmallVec; diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index cb929c21850cb..4ac0e4efb3b5f 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -6,6 +6,7 @@ //! integer. It is crucial that these operations call `check_align` *before* //! short-circuiting the empty case! +use std::assert::assert_matches; use std::borrow::Cow; use std::collections::VecDeque; use std::convert::{TryFrom, TryInto}; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 3557dbad90cc2..01d33409a4238 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -179,6 +179,16 @@ use prelude::v1::*; #[macro_use] mod macros; +// We don't export this through #[macro_export] for now, to avoid breakage. +// See https://github.com/rust-lang/rust/issues/82913 +#[cfg(not(test))] +#[unstable(feature = "assert_matches", issue = "82775")] +/// Unstable module containing the unstable `assert_matches` macro. +pub mod assert { + #[unstable(feature = "assert_matches", issue = "82775")] + pub use crate::macros::{assert_matches, debug_assert_matches}; +} + #[macro_use] mod internal_macros; diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 7eb65483b99e7..5a8e2f543921b 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -126,6 +126,8 @@ macro_rules! assert_ne { /// ``` /// #![feature(assert_matches)] /// +/// use std::assert::assert_matches; +/// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); /// assert_matches!(a, Some(_)); @@ -134,10 +136,10 @@ macro_rules! assert_ne { /// let c = Ok("abc".to_string()); /// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); /// ``` -#[macro_export] #[unstable(feature = "assert_matches", issue = "82775")] #[allow_internal_unstable(core_panic)] -macro_rules! assert_matches { +#[rustc_macro_transparency = "semitransparent"] +pub macro assert_matches { ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} @@ -149,7 +151,7 @@ macro_rules! assert_matches { ); } } - }); + }), ($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ match $left { $( $pattern )|+ $( if $guard )? => {} @@ -161,7 +163,7 @@ macro_rules! assert_matches { ); } } - }); + }), } /// Asserts that a boolean expression is `true` at runtime. @@ -283,6 +285,8 @@ macro_rules! debug_assert_ne { /// ``` /// #![feature(assert_matches)] /// +/// use std::assert::debug_assert_matches; +/// /// let a = 1u32.checked_add(2); /// let b = 1u32.checked_sub(2); /// debug_assert_matches!(a, Some(_)); @@ -294,8 +298,9 @@ macro_rules! debug_assert_ne { #[macro_export] #[unstable(feature = "assert_matches", issue = "82775")] #[allow_internal_unstable(assert_matches)] -macro_rules! debug_assert_matches { - ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); }) +#[rustc_macro_transparency = "semitransparent"] +pub macro debug_assert_matches($($arg:tt)*) { + if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); } } /// Returns whether the given expression matches any of the given patterns. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8c120f4af288d..472bca3460f46 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -548,8 +548,8 @@ pub use std_detect::{ #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, - debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo, + unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore. diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs index 43be9532f5d1c..714a6561a6d09 100644 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ b/src/test/ui/macros/assert-matches-macro-msg.rs @@ -6,6 +6,8 @@ #![feature(assert_matches)] +use std::assert::assert_matches; + fn main() { assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); } diff --git a/src/test/ui/matches2021.rs b/src/test/ui/matches2021.rs index 1090b1578ba51..a6fa5128d2f86 100644 --- a/src/test/ui/matches2021.rs +++ b/src/test/ui/matches2021.rs @@ -6,6 +6,8 @@ #![feature(assert_matches)] +use std::assert::assert_matches; + fn main() { assert!(matches!((), ())); assert_matches!((), ()); diff --git a/src/test/ui/resolve/resolve-hint-macro.rs b/src/test/ui/resolve/resolve-hint-macro.rs index 6155ae7bcdfdf..5532c8b90e326 100644 --- a/src/test/ui/resolve/resolve-hint-macro.rs +++ b/src/test/ui/resolve/resolve-hint-macro.rs @@ -1,4 +1,4 @@ fn main() { - assert(true); - //~^ ERROR expected function, found macro `assert` + assert_eq(1, 1); + //~^ ERROR expected function, found macro `assert_eq` } diff --git a/src/test/ui/resolve/resolve-hint-macro.stderr b/src/test/ui/resolve/resolve-hint-macro.stderr index 7d35ce7e65e58..efcfc7198ab51 100644 --- a/src/test/ui/resolve/resolve-hint-macro.stderr +++ b/src/test/ui/resolve/resolve-hint-macro.stderr @@ -1,13 +1,13 @@ -error[E0423]: expected function, found macro `assert` +error[E0423]: expected function, found macro `assert_eq` --> $DIR/resolve-hint-macro.rs:2:5 | -LL | assert(true); - | ^^^^^^ not a function +LL | assert_eq(1, 1); + | ^^^^^^^^^ not a function | help: use `!` to invoke the macro | -LL | assert!(true); - | ^ +LL | assert_eq!(1, 1); + | ^ error: aborting due to previous error From 6e47c8db73baecd93cefa023be3336195d9ad8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 12 Jul 2021 14:59:29 +0200 Subject: [PATCH 2/7] Add tracking issue number to `wasi_ext` --- library/std/src/os/wasi/fs.rs | 2 +- library/std/src/os/wasi/io.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/wasi/fs.rs b/library/std/src/os/wasi/fs.rs index 7f26f419a4b7b..bd30d6ae3f333 100644 --- a/library/std/src/os/wasi/fs.rs +++ b/library/std/src/os/wasi/fs.rs @@ -1,7 +1,7 @@ //! WASI-specific extensions to primitives in the `std::fs` module. #![deny(unsafe_op_in_unsafe_fn)] -#![unstable(feature = "wasi_ext", issue = "none")] +#![unstable(feature = "wasi_ext", issue = "71213")] use crate::ffi::OsStr; use crate::fs::{self, File, Metadata, OpenOptions}; diff --git a/library/std/src/os/wasi/io.rs b/library/std/src/os/wasi/io.rs index b2e79cc1b4a9d..cf4501b98cbd4 100644 --- a/library/std/src/os/wasi/io.rs +++ b/library/std/src/os/wasi/io.rs @@ -1,7 +1,7 @@ //! WASI-specific extensions to general I/O primitives #![deny(unsafe_op_in_unsafe_fn)] -#![unstable(feature = "wasi_ext", issue = "none")] +#![unstable(feature = "wasi_ext", issue = "71213")] use crate::fs; use crate::io; From 4541aa971f94f5b262ac44bbba3ad0561c76477b Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Wed, 14 Jul 2021 15:31:12 +0200 Subject: [PATCH 3/7] Add safety comments in private core::slice::rotate::ptr_rotate function --- library/core/src/slice/rotate.rs | 56 ++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/rotate.rs b/library/core/src/slice/rotate.rs index a89596b15ef94..7528927ef33b9 100644 --- a/library/core/src/slice/rotate.rs +++ b/library/core/src/slice/rotate.rs @@ -1,5 +1,3 @@ -// ignore-tidy-undocumented-unsafe - use crate::cmp; use crate::mem::{self, MaybeUninit}; use crate::ptr; @@ -79,8 +77,10 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) // the way until about `left + right == 32`, but the worst case performance breaks even // around 16. 24 was chosen as middle ground. If the size of `T` is larger than 4 // `usize`s, this algorithm also outperforms other algorithms. + // SAFETY: callers must ensure `mid - left` is valid for reading and writing. let x = unsafe { mid.sub(left) }; // beginning of first round + // SAFETY: see previous comment. let mut tmp: T = unsafe { x.read() }; let mut i = right; // `gcd` can be found before hand by calculating `gcd(left + right, right)`, @@ -92,6 +92,21 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) // the very end. This is possibly due to the fact that swapping or replacing temporaries // uses only one memory address in the loop instead of needing to manage two. loop { + // [long-safety-expl] + // SAFETY: callers must ensure `[left, left+mid+right)` are all valid for reading and + // writing. + // + // - `i` start with `right` so `mid-left <= x+i = x+right = mid-left+right < mid+right` + // - `i <= left+right-1` is always true + // - if `i < left`, `right` is added so `i < left+right` and on the next + // iteration `left` is removed from `i` so it doesn't go further + // - if `i >= left`, `left` is removed immediately and so it doesn't go further. + // - overflows cannot happen for `i` since the function's safety contract ask for + // `mid+right-1 = x+left+right` to be valid for writing + // - underflows cannot happen because `i` must be bigger or equal to `left` for + // a substraction of `left` to happen. + // + // So `x+i` is valid for reading and writing if the caller respected the contract tmp = unsafe { x.add(i).replace(tmp) }; // instead of incrementing `i` and then checking if it is outside the bounds, we // check if `i` will go outside the bounds on the next increment. This prevents @@ -100,6 +115,8 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) i -= left; if i == 0 { // end of first round + // SAFETY: tmp has been read from a valid source and x is valid for writing + // according to the caller. unsafe { x.write(tmp) }; break; } @@ -113,13 +130,24 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) } // finish the chunk with more rounds for start in 1..gcd { + // SAFETY: `gcd` is at most equal to `right` so all values in `1..gcd` are valid for + // reading and writing as per the function's safety contract, see [long-safety-expl] + // above tmp = unsafe { x.add(start).read() }; + // [safety-expl-addition] + // + // Here `start < gcd` so `start < right` so `i < right+right`: `right` being the + // greatest common divisor of `(left+right, right)` means that `left = right` so + // `i < left+right` so `x+i = mid-left+i` is always valid for reading and writing + // according to the function's safety contract. i = start + right; loop { + // SAFETY: see [long-safety-expl] and [safety-expl-addition] tmp = unsafe { x.add(i).replace(tmp) }; if i >= left { i -= left; if i == start { + // SAFETY: see [long-safety-expl] and [safety-expl-addition] unsafe { x.add(start).write(tmp) }; break; } @@ -135,14 +163,30 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) // The `[T; 0]` here is to ensure this is appropriately aligned for T let mut rawarray = MaybeUninit::<(BufType, [T; 0])>::uninit(); let buf = rawarray.as_mut_ptr() as *mut T; + // SAFETY: `mid-left <= mid-left+right < mid+right` let dim = unsafe { mid.sub(left).add(right) }; if left <= right { + // SAFETY: + // + // 1) The `else if` condition about the sizes ensures `[mid-left; left]` will fit in + // `buf` without overflow and `buf` was created just above and so cannot be + // overlapped with any value of `[mid-left; left]` + // 2) [mid-left, mid+right) are all valid for reading and writing and we don't care + // about overlaps here. + // 3) The `if` condition about `left <= right` ensures writing `left` elements to + // `dim = mid-left+right` is valid because: + // - `buf` is valid and `left` elements were written in it in 1) + // - `dim+left = mid-left+right+left = mid+right` and we write `[dim, dim+left)` unsafe { + // 1) ptr::copy_nonoverlapping(mid.sub(left), buf, left); + // 2) ptr::copy(mid, mid.sub(left), right); + // 3) ptr::copy_nonoverlapping(buf, dim, left); } } else { + // SAFETY: same reasoning as above but with `left` and `right` reversed unsafe { ptr::copy_nonoverlapping(mid, buf, right); ptr::copy(mid.sub(left), dim, left); @@ -156,6 +200,10 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) // of this algorithm would be, and swapping using that last chunk instead of swapping // adjacent chunks like this algorithm is doing, but this way is still faster. loop { + // SAFETY: + // `left >= right` so `[mid-right, mid+right)` is valid for reading and writing + // Substracting `right` from `mid` each turn is counterbalanced by the addition and + // check after it. unsafe { ptr::swap_nonoverlapping(mid.sub(right), mid, right); mid = mid.sub(right); @@ -168,6 +216,10 @@ pub unsafe fn ptr_rotate(mut left: usize, mut mid: *mut T, mut right: usize) } else { // Algorithm 3, `left < right` loop { + // SAFETY: `[mid-left, mid+left)` is valid for reading and writing because + // `left < right` so `mid+left < mid+right`. + // Adding `left` to `mid` each turn is counterbalanced by the substraction and check + // after it. unsafe { ptr::swap_nonoverlapping(mid.sub(left), mid, left); mid = mid.add(left); From 636fcacb447c65df4d5eda363218b979f11ce057 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 19 Jun 2021 17:06:46 -0700 Subject: [PATCH 4/7] Add -Zfuture-incompat-test to assist with testing future-incompat reports. --- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_middle/src/lint.rs | 14 +++++++------- compiler/rustc_session/src/options.rs | 2 ++ src/test/ui/lint/future-incompat-test.rs | 10 ++++++++++ src/test/ui/lint/future-incompat-test.stderr | 9 +++++++++ .../group-compat-hack/group-compat-hack.stderr | 10 +++++----- .../issue-73933-procedural-masquerade.stderr | 2 +- src/tools/compiletest/src/json.rs | 5 +---- 8 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 src/test/ui/lint/future-incompat-test.rs create mode 100644 src/test/ui/lint/future-incompat-test.stderr diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index a053253ec16e0..5a362a37f2bed 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -633,6 +633,7 @@ fn test_debugging_options_tracking_hash() { untracked!(dump_mir_graphviz, true); untracked!(emit_future_incompat_report, true); untracked!(emit_stack_sizes, true); + untracked!(future_incompat_test, true); untracked!(hir_stats, true); untracked!(identify_regions, true); untracked!(incremental_ignore_spans, true); diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 484e30027e521..848e60fe1342e 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -8,7 +8,7 @@ use rustc_hir::HirId; use rustc_index::vec::IndexVec; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, - FutureIncompatibilityReason, FutureIncompatibleInfo, Level, Lint, LintId, + FutureIncompatibilityReason, Level, Lint, LintId, }; use rustc_session::{DiagnosticMessageId, Session}; use rustc_span::hygiene::MacroKind; @@ -223,12 +223,12 @@ pub fn struct_lint_level<'s, 'd>( let lint_id = LintId::of(lint); let future_incompatible = lint.future_incompatible; - let has_future_breakage = matches!( - future_incompatible, - Some(FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, - .. - }) + let has_future_breakage = future_incompatible.map_or( + // Default allow lints trigger too often for testing. + sess.opts.debugging_opts.future_incompat_test && lint.default_level != Level::Allow, + |incompat| { + matches!(incompat.reason, FutureIncompatibilityReason::FutureReleaseErrorReportNow) + }, ); let mut err = match (level, span) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 4c40d0c367eca..474cd86f43bea 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1084,6 +1084,8 @@ options! { "set the optimization fuel quota for a crate"), function_sections: Option = (None, parse_opt_bool, [TRACKED], "whether each function should go in its own section"), + future_incompat_test: bool = (false, parse_bool, [UNTRACKED], + "forces all lints to be future incompatible, used for internal testing (default: no)"), gcc_ld: Option = (None, parse_gcc_ld, [TRACKED], "implementation of ld used by cc"), graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED], "use dark-themed colors in graphviz output (default: no)"), diff --git a/src/test/ui/lint/future-incompat-test.rs b/src/test/ui/lint/future-incompat-test.rs new file mode 100644 index 0000000000000..ce8c118dab242 --- /dev/null +++ b/src/test/ui/lint/future-incompat-test.rs @@ -0,0 +1,10 @@ +// compile-flags: -Zfuture-incompat-test -Zemit-future-incompat-report +// check-pass + +// The `-Zfuture-incompat-test flag causes any normal warning to be included +// in the future-incompatible report. The stderr output here should mention +// the future incompatible report (as extracted by compiletest). + +fn main() { + let x = 1; +} diff --git a/src/test/ui/lint/future-incompat-test.stderr b/src/test/ui/lint/future-incompat-test.stderr new file mode 100644 index 0000000000000..52674a843847d --- /dev/null +++ b/src/test/ui/lint/future-incompat-test.stderr @@ -0,0 +1,9 @@ +Future incompatibility report: Future breakage diagnostic: +warning: unused variable: `x` + --> $DIR/future-incompat-test.rs:9:9 + | +LL | let x = 1; + | ^ help: if this is intentional, prefix it with an underscore: `_x` + | + = note: `-A unused-variables` implied by `-A unused` + diff --git a/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr b/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr index e764480e8e548..070b066721350 100644 --- a/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr +++ b/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr @@ -81,7 +81,7 @@ LL | tuple_from_req!(Foo); warning: 5 warnings emitted -Future incompatibility report: Future breakage date: None, diagnostic: +Future incompatibility report: Future breakage diagnostic: warning: using an old version of `time-macros-impl` --> $DIR/time-macros-impl/src/lib.rs:5:32 | @@ -99,7 +99,7 @@ LL | impl_macros!(Foo); = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage = note: this warning originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info) -Future breakage date: None, diagnostic: +Future breakage diagnostic: warning: using an old version of `time-macros-impl` --> $DIR/time-macros-impl-0.1.0/src/lib.rs:5:32 | @@ -116,7 +116,7 @@ LL | impl_macros!(Foo); = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage = note: this warning originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info) -Future breakage date: None, diagnostic: +Future breakage diagnostic: warning: using an old version of `js-sys` --> $DIR/js-sys-0.3.17/src/lib.rs:5:32 | @@ -133,7 +133,7 @@ LL | arrays!(Foo); = note: older versions of the `js-sys` crate will stop compiling in future versions of Rust; please update to `js-sys` v0.3.40 or above = note: this warning originates in the macro `arrays` (in Nightly builds, run with -Z macro-backtrace for more info) -Future breakage date: None, diagnostic: +Future breakage diagnostic: warning: using an old version of `actix-web` --> $DIR/actix-web/src/extract.rs:5:34 | @@ -150,7 +150,7 @@ LL | tuple_from_req!(Foo); = note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage = note: this warning originates in the macro `tuple_from_req` (in Nightly builds, run with -Z macro-backtrace for more info) -Future breakage date: None, diagnostic: +Future breakage diagnostic: warning: using an old version of `actix-web` --> $DIR/actix-web-2.0.0/src/extract.rs:5:34 | diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr index 0b930705e3510..4d6edab08e2cf 100644 --- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr +++ b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr @@ -11,7 +11,7 @@ LL | enum ProceduralMasqueradeDummyType { warning: 1 warning emitted -Future incompatibility report: Future breakage date: None, diagnostic: +Future incompatibility report: Future breakage diagnostic: warning: using `procedural-masquerade` crate --> $DIR/issue-73933-procedural-masquerade.rs:8:6 | diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 8d23227fdb8b7..dc6d67983c5d2 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -43,7 +43,6 @@ struct FutureIncompatReport { #[derive(Deserialize)] struct FutureBreakageItem { - future_breakage_date: Option, diagnostic: Diagnostic, } @@ -104,9 +103,7 @@ pub fn extract_rendered(output: &str) -> String { .into_iter() .map(|item| { format!( - "Future breakage date: {}, diagnostic:\n{}", - item.future_breakage_date - .unwrap_or_else(|| "None".to_string()), + "Future breakage diagnostic:\n{}", item.diagnostic .rendered .unwrap_or_else(|| "Not rendered".to_string()) From da189d95146fb6c567aef10f1be400dfd9f43862 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 14 Jul 2021 19:22:32 +0100 Subject: [PATCH 5/7] Change type param -> generic param --- compiler/rustc_resolve/src/diagnostics.rs | 6 ++--- compiler/rustc_resolve/src/lib.rs | 4 ++-- ...fault-const-param-cannot-reference-self.rs | 16 +++++++++++++ ...t-const-param-cannot-reference-self.stderr | 21 ++++++++++++++++ ...efault-type-param-cannot-reference-self.rs | 12 +++++----- ...lt-type-param-cannot-reference-self.stderr | 24 +++++++++---------- 6 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs create mode 100644 src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 03d94f43897ba..7439cd9a0fe3d 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -502,14 +502,14 @@ impl<'a> Resolver<'a> { err } - ResolutionError::SelfInTyParamDefault => { + ResolutionError::SelfInGenericParamDefault => { let mut err = struct_span_err!( self.session, span, E0735, - "type parameters cannot use `Self` in their defaults" + "generic parameters cannot use `Self` in their defaults" ); - err.span_label(span, "`Self` in type parameter default".to_string()); + err.span_label(span, "`Self` in generic parameter default".to_string()); err } ResolutionError::UnreachableLabel { name, definition_span, suggestion } => { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 4d12415215194..fb2eb749e118f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -249,7 +249,7 @@ enum ResolutionError<'a> { /// This error is only emitted when using `min_const_generics`. ParamInNonTrivialAnonConst { name: Symbol, is_type: bool }, /// Error E0735: generic parameters with a default cannot use `Self` - SelfInTyParamDefault, + SelfInGenericParamDefault, /// Error E0767: use of unreachable label UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option }, } @@ -2643,7 +2643,7 @@ impl<'a> Resolver<'a> { if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind { if record_used { let res_error = if rib_ident.name == kw::SelfUpper { - ResolutionError::SelfInTyParamDefault + ResolutionError::SelfInGenericParamDefault } else { ResolutionError::ForwardDeclaredGenericParam }; diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs new file mode 100644 index 0000000000000..9af84439252c7 --- /dev/null +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs @@ -0,0 +1,16 @@ +#![feature(const_generics_defaults)] + +struct Struct; +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +enum Enum { } +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +union Union { not_empty: () } +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +fn main() { + let _: Struct; + let _: Enum; + let _: Union; +} diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr new file mode 100644 index 0000000000000..3cc56e51807bd --- /dev/null +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr @@ -0,0 +1,21 @@ +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:3:36 + | +LL | struct Snobound; + | ^^^^ `Self` in generic parameter default + +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:6:34 + | +LL | enum Enobound { } + | ^^^^ `Self` in generic parameter default + +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:9:35 + | +LL | union Unobound { not_empty: () } + | ^^^^ `Self` in generic parameter default + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0735`. diff --git a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs index b560cc2ce7060..12db143e47449 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs +++ b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs @@ -11,25 +11,25 @@ // compatibility concern. struct Snobound<'a, P = Self> { x: Option<&'a P> } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] enum Enobound<'a, P = Self> { A, B(Option<&'a P>) } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] // Disallowing `Self` in defaults sidesteps need to check the bounds // on the defaults in cases like these. struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> } -//~^ ERROR type parameters cannot use `Self` in their defaults [E0735] +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] fn demo_usages() { // An ICE means you only get the error from the first line of the diff --git a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr index 689ffbd0febc2..f3a550801b9bd 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr @@ -1,38 +1,38 @@ -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:13:25 | LL | struct Snobound<'a, P = Self> { x: Option<&'a P> } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:16:23 | LL | enum Enobound<'a, P = Self> { A, B(Option<&'a P>) } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:19:24 | LL | union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:25:31 | LL | struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:28:29 | LL | enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default -error[E0735]: type parameters cannot use `Self` in their defaults +error[E0735]: generic parameters cannot use `Self` in their defaults --> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:31:30 | LL | union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> } - | ^^^^ `Self` in type parameter default + | ^^^^ `Self` in generic parameter default error: aborting due to 6 previous errors From b3b6b66815ed20531a7a32e9c400a8d40692f9bf Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 14 Jul 2021 19:38:58 +0100 Subject: [PATCH 6/7] OOPS --- ...lt-const-param-cannot-reference-self.stderr | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr index 3cc56e51807bd..5dfec2fcb736f 100644 --- a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr @@ -1,20 +1,20 @@ error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:3:36 + --> $DIR/default-const-param-cannot-reference-self.rs:3:34 | -LL | struct Snobound; - | ^^^^ `Self` in generic parameter default +LL | struct Struct; + | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:6:34 + --> $DIR/default-const-param-cannot-reference-self.rs:6:30 | -LL | enum Enobound { } - | ^^^^ `Self` in generic parameter default +LL | enum Enum { } + | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:9:35 + --> $DIR/default-const-param-cannot-reference-self.rs:9:32 | -LL | union Unobound { not_empty: () } - | ^^^^ `Self` in generic parameter default +LL | union Union { not_empty: () } + | ^^^^ `Self` in generic parameter default error: aborting due to 3 previous errors From 0c4b2a84c6f512bd308eb44f805845981701609c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 14 Jul 2021 19:56:42 -0700 Subject: [PATCH 7/7] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 3ebb5f15a9408..66a6737a0c9f3 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 3ebb5f15a940810f250b68821149387af583a79e +Subproject commit 66a6737a0c9f3a974af2dd032a65d3e409c77aac