From 9c7dbe82e736a657b298e41cd4640100218b37e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lanteri=20Thauvin?= Date: Thu, 31 Dec 2020 02:22:10 +0100 Subject: [PATCH 001/269] Notify when an `I-prioritize` issue is closed --- triagebot.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index c0cf50e51670..66cad406d483 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -101,6 +101,8 @@ message_on_add = """\ - Needs `I-nominated`? """ message_on_remove = "Issue #{number}'s prioritization request has been removed." +message_on_close = "Issue #{number} has been closed while requested for prioritization." +message_on_reopen = "Issue #{number} has been reopened." [github-releases] format = "rustc" From b76ce696061f6c72a1df5aa6a935ade7cc30696b Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 15 May 2021 19:35:10 +0100 Subject: [PATCH 002/269] Add test for remap-from in the form of $PWD/trailing --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 6 ++++++ .../run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 src/test/run-make-fulldeps/remap-path-prefix/Makefile create mode 100644 src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile new file mode 100644 index 000000000000..c923d7e80117 --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +# Checks if remapping works if the remap-from string contains path to the working directory plus more +all: + $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs + ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 diff --git a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs new file mode 100644 index 000000000000..7067130a4618 --- /dev/null +++ b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs @@ -0,0 +1,3 @@ +fn lib() { + panic!("calm"); +} From 1ced98ac651510f1a614caf287fca88721c2b983 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 15 May 2021 19:36:42 +0100 Subject: [PATCH 003/269] Remap after prepending cwd --- compiler/rustc_metadata/src/rmeta/encoder.rs | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 29fcbffa0b95..1b7b851382e0 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -497,11 +497,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let working_dir = &self.tcx.sess.working_dir; match working_dir { RealFileName::LocalPath(absolute) => { - // If working_dir has not been remapped, then we emit a - // LocalPath variant as it's likely to be a valid path - RealFileName::LocalPath( - Path::new(absolute).join(path_to_file), - ) + // Although neither working_dir or the file name were subject + // to path remapping, the concatenation between the two may + // be. Hence we need to do a remapping here. + let joined = Path::new(absolute).join(path_to_file); + let (joined, remapped) = + source_map.path_mapping().map_prefix(joined); + if remapped { + RealFileName::Remapped { + local_path: None, + virtual_name: joined, + } + } else { + RealFileName::LocalPath( + Path::new(absolute).join(path_to_file), + ) + } } RealFileName::Remapped { local_path: _, virtual_name } => { // If working_dir has been remapped, then we emit From f3c18bb50dd9f09739cab7e69ded6ffb092ede5d Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sun, 16 May 2021 12:38:49 +0100 Subject: [PATCH 004/269] Reuse variable --- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1b7b851382e0..f7701e7fc9dd 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -509,9 +509,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { virtual_name: joined, } } else { - RealFileName::LocalPath( - Path::new(absolute).join(path_to_file), - ) + RealFileName::LocalPath(joined) } } RealFileName::Remapped { local_path: _, virtual_name } => { From 71db7cc0b40306495b8bb69baea653f4b3978c21 Mon Sep 17 00:00:00 2001 From: bstrie <865233+bstrie@users.noreply.github.com> Date: Tue, 25 May 2021 13:57:02 -0400 Subject: [PATCH 005/269] rustc_arena: macros 2.0 --- compiler/rustc_arena/src/lib.rs | 154 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 78 deletions(-) diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index c3e4945c4464..2e8022d9880b 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -15,6 +15,8 @@ #![feature(new_uninit)] #![feature(maybe_uninit_slice)] #![feature(min_specialization)] +#![feature(decl_macro)] +#![feature(rustc_attrs)] #![cfg_attr(test, feature(test))] use rustc_data_structures::sync; @@ -608,117 +610,113 @@ impl DropArena { } } -#[macro_export] -macro_rules! arena_for_type { +pub macro arena_for_type { ([][$ty:ty]) => { $crate::TypedArena<$ty> - }; + }, ([few $(, $attrs:ident)*][$ty:ty]) => { ::std::marker::PhantomData<$ty> - }; + }, ([$ignore:ident $(, $attrs:ident)*]$args:tt) => { $crate::arena_for_type!([$($attrs),*]$args) - }; + }, } -#[macro_export] -macro_rules! which_arena_for_type { +pub macro which_arena_for_type { ([][$arena:expr]) => { ::std::option::Option::Some($arena) - }; + }, ([few$(, $attrs:ident)*][$arena:expr]) => { ::std::option::Option::None - }; + }, ([$ignore:ident$(, $attrs:ident)*]$args:tt) => { $crate::which_arena_for_type!([$($attrs),*]$args) - }; + }, } -#[macro_export] -macro_rules! declare_arena { - ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { - #[derive(Default)] - pub struct Arena<$tcx> { - pub dropless: $crate::DroplessArena, - drop: $crate::DropArena, - $($name: $crate::arena_for_type!($a[$ty]),)* - } +#[rustc_macro_transparency = "semitransparent"] +pub macro declare_arena([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) { + #[derive(Default)] + pub struct Arena<$tcx> { + pub dropless: $crate::DroplessArena, + drop: $crate::DropArena, + $($name: $crate::arena_for_type!($a[$ty]),)* + } - pub trait ArenaAllocatable<'tcx, T = Self>: Sized { - fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self; - fn allocate_from_iter<'a>( - arena: &'a Arena<'tcx>, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [Self]; + pub trait ArenaAllocatable<'tcx, T = Self>: Sized { + fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self; + fn allocate_from_iter<'a>( + arena: &'a Arena<'tcx>, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [Self]; + } + + impl<'tcx, T: Copy> ArenaAllocatable<'tcx, ()> for T { + #[inline] + fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { + arena.dropless.alloc(self) + } + #[inline] + fn allocate_from_iter<'a>( + arena: &'a Arena<'tcx>, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [Self] { + arena.dropless.alloc_from_iter(iter) } - impl<'tcx, T: Copy> ArenaAllocatable<'tcx, ()> for T { + } + $( + impl<$tcx> ArenaAllocatable<$tcx, $ty> for $ty { #[inline] - fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self { - arena.dropless.alloc(self) + fn allocate_on<'a>(self, arena: &'a Arena<$tcx>) -> &'a mut Self { + if !::std::mem::needs_drop::() { + return arena.dropless.alloc(self); + } + match $crate::which_arena_for_type!($a[&arena.$name]) { + ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { + ty_arena.alloc(self) + } + ::std::option::Option::None => unsafe { arena.drop.alloc(self) }, + } } + #[inline] fn allocate_from_iter<'a>( - arena: &'a Arena<'tcx>, + arena: &'a Arena<$tcx>, iter: impl ::std::iter::IntoIterator, ) -> &'a mut [Self] { - arena.dropless.alloc_from_iter(iter) - } - - } - $( - impl<$tcx> ArenaAllocatable<$tcx, $ty> for $ty { - #[inline] - fn allocate_on<'a>(self, arena: &'a Arena<$tcx>) -> &'a mut Self { - if !::std::mem::needs_drop::() { - return arena.dropless.alloc(self); - } - match $crate::which_arena_for_type!($a[&arena.$name]) { - ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { - ty_arena.alloc(self) - } - ::std::option::Option::None => unsafe { arena.drop.alloc(self) }, - } + if !::std::mem::needs_drop::() { + return arena.dropless.alloc_from_iter(iter); } - - #[inline] - fn allocate_from_iter<'a>( - arena: &'a Arena<$tcx>, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [Self] { - if !::std::mem::needs_drop::() { - return arena.dropless.alloc_from_iter(iter); - } - match $crate::which_arena_for_type!($a[&arena.$name]) { - ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { - ty_arena.alloc_from_iter(iter) - } - ::std::option::Option::None => unsafe { arena.drop.alloc_from_iter(iter) }, + match $crate::which_arena_for_type!($a[&arena.$name]) { + ::std::option::Option::<&$crate::TypedArena>::Some(ty_arena) => { + ty_arena.alloc_from_iter(iter) } + ::std::option::Option::None => unsafe { arena.drop.alloc_from_iter(iter) }, } } - )* + } + )* - impl<'tcx> Arena<'tcx> { - #[inline] - pub fn alloc, U>(&self, value: T) -> &mut T { - value.allocate_on(self) - } + impl<'tcx> Arena<'tcx> { + #[inline] + pub fn alloc, U>(&self, value: T) -> &mut T { + value.allocate_on(self) + } - #[inline] - pub fn alloc_slice(&self, value: &[T]) -> &mut [T] { - if value.is_empty() { - return &mut []; - } - self.dropless.alloc_slice(value) + #[inline] + pub fn alloc_slice(&self, value: &[T]) -> &mut [T] { + if value.is_empty() { + return &mut []; } + self.dropless.alloc_slice(value) + } - pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, U>, U>( - &'a self, - iter: impl ::std::iter::IntoIterator, - ) -> &'a mut [T] { - T::allocate_from_iter(self, iter) - } + pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, U>, U>( + &'a self, + iter: impl ::std::iter::IntoIterator, + ) -> &'a mut [T] { + T::allocate_from_iter(self, iter) } } } From 709a6c913eb44f361b264fb98cdd419dc8ae6912 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Tue, 10 Aug 2021 19:22:06 +0200 Subject: [PATCH 006/269] Add Saturating type (based on Wrapping type) --- library/core/src/num/mod.rs | 4 + library/core/src/num/saturating.rs | 814 +++++++++++++++++++++++++++++ library/std/src/lib.rs | 1 + library/std/src/num.rs | 2 + 4 files changed, 821 insertions(+) create mode 100644 library/core/src/num/saturating.rs diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 9788404dd05b..09b7418bec0d 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -43,8 +43,12 @@ mod uint_macros; // import uint_impl! mod error; mod int_log10; mod nonzero; +#[unstable(feature = "saturating_int_impl", issue = "87920")] +mod saturating; mod wrapping; +#[unstable(feature = "saturating_int_impl", issue = "87920")] +pub use saturating::Saturating; #[stable(feature = "rust1", since = "1.0.0")] pub use wrapping::Wrapping; diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs new file mode 100644 index 000000000000..4f1937c68c7e --- /dev/null +++ b/library/core/src/num/saturating.rs @@ -0,0 +1,814 @@ +//! Definitions of `Saturating`. + +use crate::fmt; +use crate::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign}; +use crate::ops::{BitXor, BitXorAssign, Div, DivAssign}; +use crate::ops::{Mul, MulAssign, Neg, Not}; +use crate::ops::{Sub, SubAssign}; + +/// Provides intentionally-wrapped arithmetic on `T`. +/// +/// Operations like `+` on `u32` values are intended to never overflow, +/// and in some debug configurations overflow is detected and results +/// in a panic. While most arithmetic falls into this category, some +/// code explicitly expects and relies upon modular arithmetic (e.g., +/// hashing). +/// +/// Saturating arithmetic can be achieved either through methods like +/// `saturating_add`, or through the `Saturating` type, which says that +/// all standard arithmetic operations on the underlying value are +/// intended to have saturating semantics. +/// +/// The underlying value can be retrieved through the `.0` index of the +/// `Saturating` tuple. +/// +/// # Examples +/// +/// ``` +/// #![feature(saturating_int_impl)] +/// use std::num::Saturating; +/// +/// let max = Saturating(u32::MAX); +/// let one = Saturating(1u32); +/// +/// assert_eq!(u32::MAX, (max + one).0); +/// ``` +#[unstable(feature = "saturating_int_impl", issue = "87920")] +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] +#[repr(transparent)] +pub struct Saturating(#[stable(feature = "rust1", since = "1.0.0")] pub T); + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "saturating_display", since = "1.10.0")] +impl fmt::Display for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "saturating_fmt", since = "1.11.0")] +impl fmt::Binary for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "saturating_fmt", since = "1.11.0")] +impl fmt::Octal for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "saturating_fmt", since = "1.11.0")] +impl fmt::LowerHex for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[stable(feature = "saturating_fmt", since = "1.11.0")] +impl fmt::UpperHex for Saturating { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +#[allow(unused_macros)] +macro_rules! sh_impl_signed { + ($t:ident, $f:ident) => { + + }; +} + +macro_rules! sh_impl_unsigned { + ($t:ident, $f:ident) => { + + }; +} + +// FIXME (#23545): uncomment the remaining impls +macro_rules! sh_impl_all { + ($($t:ident)*) => ($( + //sh_impl_unsigned! { $t, u8 } + //sh_impl_unsigned! { $t, u16 } + //sh_impl_unsigned! { $t, u32 } + //sh_impl_unsigned! { $t, u64 } + //sh_impl_unsigned! { $t, u128 } + sh_impl_unsigned! { $t, usize } + + //sh_impl_signed! { $t, i8 } + //sh_impl_signed! { $t, i16 } + //sh_impl_signed! { $t, i32 } + //sh_impl_signed! { $t, i64 } + //sh_impl_signed! { $t, i128 } + //sh_impl_signed! { $t, isize } + )*) +} + +sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } + +// FIXME(30524): impl Op for Saturating, impl OpAssign for Saturating +macro_rules! saturating_impl { + ($($t:ty)*) => ($( + #[stable(feature = "rust1", since = "1.0.0")] + impl Add for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn add(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.saturating_add(other.0)) + } + } + forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl AddAssign for Saturating<$t> { + #[inline] + fn add_assign(&mut self, other: Saturating<$t>) { + *self = *self + other; + } + } + forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Sub for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn sub(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.saturating_sub(other.0)) + } + } + forward_ref_binop! { impl Sub, sub for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl SubAssign for Saturating<$t> { + #[inline] + fn sub_assign(&mut self, other: Saturating<$t>) { + *self = *self - other; + } + } + forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Mul for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn mul(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.saturating_mul(other.0)) + } + } + forward_ref_binop! { impl Mul, mul for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl MulAssign for Saturating<$t> { + #[inline] + fn mul_assign(&mut self, other: Saturating<$t>) { + *self = *self * other; + } + } + forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "saturating_div", since = "1.3.0")] + impl Div for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn div(self, other: Saturating<$t>) -> Saturating<$t> { + // saturating div is the default behavior? + Saturating(self.0.div(other.0)) + } + } + forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl DivAssign for Saturating<$t> { + #[inline] + fn div_assign(&mut self, other: Saturating<$t>) { + *self = *self / other; + } + } + forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "rust1", since = "1.0.0")] + impl Not for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn not(self) -> Saturating<$t> { + Saturating(!self.0) + } + } + forward_ref_unop! { impl Not, not for Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "rust1", since = "1.0.0")] + impl BitXor for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn bitxor(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0 ^ other.0) + } + } + forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl BitXorAssign for Saturating<$t> { + #[inline] + fn bitxor_assign(&mut self, other: Saturating<$t>) { + *self = *self ^ other; + } + } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "rust1", since = "1.0.0")] + impl BitOr for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn bitor(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0 | other.0) + } + } + forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl BitOrAssign for Saturating<$t> { + #[inline] + fn bitor_assign(&mut self, other: Saturating<$t>) { + *self = *self | other; + } + } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "rust1", since = "1.0.0")] + impl BitAnd for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn bitand(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0 & other.0) + } + } + forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + #[stable(feature = "op_assign_traits", since = "1.8.0")] + impl BitAndAssign for Saturating<$t> { + #[inline] + fn bitand_assign(&mut self, other: Saturating<$t>) { + *self = *self & other; + } + } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t> } + + #[stable(feature = "saturating_neg", since = "1.45.0")] + impl Neg for Saturating<$t> { + type Output = Self; + #[inline] + fn neg(self) -> Self { + Saturating(0) - self + } + } + forward_ref_unop! { impl Neg, neg for Saturating<$t>, + #[stable(feature = "saturating_ref", since = "1.14.0")] } + + )*) +} + +saturating_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } + +macro_rules! saturating_int_impl { + ($($t:ty)*) => ($( + impl Saturating<$t> { + /// Returns the smallest value that can be represented by this integer type. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(>::MIN, Saturating(", stringify!($t), "::MIN));")] + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const MIN: Self = Self(<$t>::MIN); + + /// Returns the largest value that can be represented by this integer type. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(>::MAX, Saturating(", stringify!($t), "::MAX));")] + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const MAX: Self = Self(<$t>::MAX); + + /// Returns the size of this integer type in bits. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(>::BITS, ", stringify!($t), "::BITS);")] + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const BITS: u32 = <$t>::BITS; + + /// Returns the number of ones in the binary representation of `self`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0b01001100", stringify!($t), ");")] + /// + /// assert_eq!(n.count_ones(), 3); + /// ``` + #[inline] + #[doc(alias = "popcount")] + #[doc(alias = "popcnt")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn count_ones(self) -> u32 { + self.0.count_ones() + } + + /// Returns the number of zeros in the binary representation of `self`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(!0", stringify!($t), ").count_zeros(), 0);")] + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn count_zeros(self) -> u32 { + self.0.count_zeros() + } + + /// Returns the number of trailing zeros in the binary representation of `self`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0b0101000", stringify!($t), ");")] + /// + /// assert_eq!(n.trailing_zeros(), 3); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn trailing_zeros(self) -> u32 { + self.0.trailing_zeros() + } + + /// Shifts the bits to the left by a specified amount, `n`, + /// saturating the truncated bits to the end of the resulting + /// integer. + /// + /// Please note this isn't the same operation as the `<<` shifting + /// operator! + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + /// let n: Saturating = Saturating(0x0123456789ABCDEF); + /// let m: Saturating = Saturating(-0x76543210FEDCBA99); + /// + /// assert_eq!(n.rotate_left(32), m); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn rotate_left(self, n: u32) -> Self { + Saturating(self.0.rotate_left(n)) + } + + /// Shifts the bits to the right by a specified amount, `n`, + /// saturating the truncated bits to the beginning of the resulting + /// integer. + /// + /// Please note this isn't the same operation as the `>>` shifting + /// operator! + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + /// let n: Saturating = Saturating(0x0123456789ABCDEF); + /// let m: Saturating = Saturating(-0xFEDCBA987654322); + /// + /// assert_eq!(n.rotate_right(4), m); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn rotate_right(self, n: u32) -> Self { + Saturating(self.0.rotate_right(n)) + } + + /// Reverses the byte order of the integer. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + /// let n: Saturating = Saturating(0b0000000_01010101); + /// assert_eq!(n, Saturating(85)); + /// + /// let m = n.swap_bytes(); + /// + /// assert_eq!(m, Saturating(0b01010101_00000000)); + /// assert_eq!(m, Saturating(21760)); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn swap_bytes(self) -> Self { + Saturating(self.0.swap_bytes()) + } + + /// 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(saturating_int_impl)] + /// use std::num::Saturating; + /// + /// let n = Saturating(0b0000000_01010101i16); + /// assert_eq!(n, Saturating(85)); + /// + /// let m = n.reverse_bits(); + /// + /// assert_eq!(m.0 as u16, 0b10101010_00000000); + /// assert_eq!(m, Saturating(-22016)); + /// ``` + #[stable(feature = "reverse_bits", since = "1.37.0")] + #[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")] + #[inline] + #[must_use] + pub const fn reverse_bits(self) -> Self { + Saturating(self.0.reverse_bits()) + } + + /// Converts an integer from big endian to the target's endianness. + /// + /// On big endian this is a no-op. On little endian the bytes are + /// swapped. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0x1A", stringify!($t), ");")] + /// + /// if cfg!(target_endian = "big") { + #[doc = concat!(" assert_eq!(>::from_be(n), n)")] + /// } else { + #[doc = concat!(" assert_eq!(>::from_be(n), n.swap_bytes())")] + /// } + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn from_be(x: Self) -> Self { + Saturating(<$t>::from_be(x.0)) + } + + /// Converts an integer from little endian to the target's endianness. + /// + /// On little endian this is a no-op. On big endian the bytes are + /// swapped. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0x1A", stringify!($t), ");")] + /// + /// if cfg!(target_endian = "little") { + #[doc = concat!(" assert_eq!(>::from_le(n), n)")] + /// } else { + #[doc = concat!(" assert_eq!(>::from_le(n), n.swap_bytes())")] + /// } + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn from_le(x: Self) -> Self { + Saturating(<$t>::from_le(x.0)) + } + + /// Converts `self` to big endian from the target's endianness. + /// + /// On big endian this is a no-op. On little endian the bytes are + /// swapped. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0x1A", stringify!($t), ");")] + /// + /// if cfg!(target_endian = "big") { + /// assert_eq!(n.to_be(), n) + /// } else { + /// assert_eq!(n.to_be(), n.swap_bytes()) + /// } + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn to_be(self) -> Self { + Saturating(self.0.to_be()) + } + + /// Converts `self` to little endian from the target's endianness. + /// + /// On little endian this is a no-op. On big endian the bytes are + /// swapped. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(0x1A", stringify!($t), ");")] + /// + /// if cfg!(target_endian = "little") { + /// assert_eq!(n.to_le(), n) + /// } else { + /// assert_eq!(n.to_le(), n.swap_bytes()) + /// } + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn to_le(self) -> Self { + Saturating(self.0.to_le()) + } + + /// Raises self to the power of `exp`, using exponentiation by squaring. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(3", stringify!($t), ").pow(4), Saturating(81));")] + /// ``` + /// + /// Results that are too large are wrapped: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + /// assert_eq!(Saturating(3i8).pow(5), Saturating(127)); + /// assert_eq!(Saturating(3i8).pow(6), Saturating(127)); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub fn pow(self, exp: u32) -> Self { + Saturating(self.0.saturating_pow(exp)) + } + } + )*) +} + +saturating_int_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } + +macro_rules! saturating_int_impl_signed { + ($($t:ty)*) => ($( + impl Saturating<$t> { + /// Returns the number of leading zeros in the binary representation of `self`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / 4;")] + /// + /// assert_eq!(n.leading_zeros(), 3); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn leading_zeros(self) -> u32 { + self.0.leading_zeros() + } + + /// Computes the absolute value of `self`, saturating around at + /// the boundary of the type. + /// + /// The only case where such saturating can occur is when one takes the absolute value of the negative + /// minimal value for the type this is a positive value that is too large to represent in the type. In + /// such a case, this function returns `MIN` itself. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(100", stringify!($t), ").abs(), Saturating(100));")] + #[doc = concat!("assert_eq!(Saturating(-100", stringify!($t), ").abs(), Saturating(100));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating(", stringify!($t), "::MIN));")] + /// assert_eq!(Saturating(-128i8).abs().0 as u8, 128u8); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub fn abs(self) -> Saturating<$t> { + Saturating(self.0.saturating_abs()) + } + + /// Returns a number representing sign of `self`. + /// + /// - `0` if the number is zero + /// - `1` if the number is positive + /// - `-1` if the number is negative + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(10", stringify!($t), ").signum(), Saturating(1));")] + #[doc = concat!("assert_eq!(Saturating(0", stringify!($t), ").signum(), Saturating(0));")] + #[doc = concat!("assert_eq!(Saturating(-10", stringify!($t), ").signum(), Saturating(-1));")] + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub fn signum(self) -> Saturating<$t> { + Saturating(self.0.signum()) + } + + /// Returns `true` if `self` is positive and `false` if the number is zero or + /// negative. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert!(Saturating(10", stringify!($t), ").is_positive());")] + #[doc = concat!("assert!(!Saturating(-10", stringify!($t), ").is_positive());")] + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn is_positive(self) -> bool { + self.0.is_positive() + } + + /// Returns `true` if `self` is negative and `false` if the number is zero or + /// positive. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert!(Saturating(-10", stringify!($t), ").is_negative());")] + #[doc = concat!("assert!(!Saturating(10", stringify!($t), ").is_negative());")] + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn is_negative(self) -> bool { + self.0.is_negative() + } + } + )*) +} + +saturating_int_impl_signed! { isize i8 i16 i32 i64 i128 } + +macro_rules! saturating_int_impl_unsigned { + ($($t:ty)*) => ($( + impl Saturating<$t> { + /// Returns the number of leading zeros in the binary representation of `self`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / 4;")] + /// + /// assert_eq!(n.leading_zeros(), 2); + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub const fn leading_zeros(self) -> u32 { + self.0.leading_zeros() + } + + /// Returns `true` if and only if `self == 2^k` for some `k`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert!(Saturating(16", stringify!($t), ").is_power_of_two());")] + #[doc = concat!("assert!(!Saturating(10", stringify!($t), ").is_power_of_two());")] + /// ``` + #[inline] + #[unstable(feature = "saturating_int_impl", issue = "87920")] + pub fn is_power_of_two(self) -> bool { + self.0.is_power_of_two() + } + + } + )*) +} + +saturating_int_impl_unsigned! { usize u8 u16 u32 u64 u128 } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 861a6fc193cc..818ca7df3e37 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -308,6 +308,7 @@ #![feature(ptr_internals)] #![feature(rustc_attrs)] #![feature(rustc_private)] +#![feature(saturating_int_impl)] #![feature(slice_concat_ext)] #![feature(slice_internals)] #![feature(slice_ptr_get)] diff --git a/library/std/src/num.rs b/library/std/src/num.rs index e7051f0ce95b..46064bd28377 100644 --- a/library/std/src/num.rs +++ b/library/std/src/num.rs @@ -12,6 +12,8 @@ mod tests; #[cfg(test)] mod benches; +#[unstable(feature = "saturating_int_impl", issue = "87920")] +pub use core::num::Saturating; #[stable(feature = "rust1", since = "1.0.0")] pub use core::num::Wrapping; #[stable(feature = "rust1", since = "1.0.0")] From 8841155ce5bf0f814243566aeb21e2ec355026c6 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Tue, 10 Aug 2021 19:51:49 +0200 Subject: [PATCH 007/269] Remove unused macros --- library/core/src/num/saturating.rs | 33 ------------------------------ 1 file changed, 33 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 4f1937c68c7e..5a775dd99c98 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -80,39 +80,6 @@ impl fmt::UpperHex for Saturating { } } -#[allow(unused_macros)] -macro_rules! sh_impl_signed { - ($t:ident, $f:ident) => { - - }; -} - -macro_rules! sh_impl_unsigned { - ($t:ident, $f:ident) => { - - }; -} - -// FIXME (#23545): uncomment the remaining impls -macro_rules! sh_impl_all { - ($($t:ident)*) => ($( - //sh_impl_unsigned! { $t, u8 } - //sh_impl_unsigned! { $t, u16 } - //sh_impl_unsigned! { $t, u32 } - //sh_impl_unsigned! { $t, u64 } - //sh_impl_unsigned! { $t, u128 } - sh_impl_unsigned! { $t, usize } - - //sh_impl_signed! { $t, i8 } - //sh_impl_signed! { $t, i16 } - //sh_impl_signed! { $t, i32 } - //sh_impl_signed! { $t, i64 } - //sh_impl_signed! { $t, i128 } - //sh_impl_signed! { $t, isize } - )*) -} - -sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } // FIXME(30524): impl Op for Saturating, impl OpAssign for Saturating macro_rules! saturating_impl { From cdc90f9281251889156098f99ad9a42fc612fd77 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Tue, 10 Aug 2021 19:53:42 +0200 Subject: [PATCH 008/269] Rustfmt --- library/core/src/num/saturating.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 5a775dd99c98..9199dc6dece3 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -80,7 +80,6 @@ impl fmt::UpperHex for Saturating { } } - // FIXME(30524): impl Op for Saturating, impl OpAssign for Saturating macro_rules! saturating_impl { ($($t:ty)*) => ($( From d4c9f76fd287698e4341c0e1137b1fda0d339743 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Tue, 10 Aug 2021 20:34:08 +0200 Subject: [PATCH 009/269] Fix missed tests --- library/core/src/num/saturating.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 9199dc6dece3..6aaa5bf335a4 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -626,7 +626,7 @@ macro_rules! saturating_int_impl_signed { /// #![feature(saturating_int_impl)] /// use std::num::Saturating; /// - #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / 4;")] + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / Saturating(4", stringify!($t), ");")] /// /// assert_eq!(n.leading_zeros(), 3); /// ``` @@ -636,12 +636,8 @@ macro_rules! saturating_int_impl_signed { self.0.leading_zeros() } - /// Computes the absolute value of `self`, saturating around at - /// the boundary of the type. - /// - /// The only case where such saturating can occur is when one takes the absolute value of the negative - /// minimal value for the type this is a positive value that is too large to represent in the type. In - /// such a case, this function returns `MIN` itself. + /// Saturating absolute value. Computes `self.abs()`, returning `MAX` if `self == MIN` + /// instead of overflowing. /// /// # Examples /// @@ -653,8 +649,9 @@ macro_rules! saturating_int_impl_signed { /// #[doc = concat!("assert_eq!(Saturating(100", stringify!($t), ").abs(), Saturating(100));")] #[doc = concat!("assert_eq!(Saturating(-100", stringify!($t), ").abs(), Saturating(100));")] - #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating(", stringify!($t), "::MIN));")] - /// assert_eq!(Saturating(-128i8).abs().0 as u8, 128u8); + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating((", stringify!($t), "::MIN + 1).abs()));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating(", stringify!($t), "::MIN.saturating_abs()));")] + /// assert_eq!(Saturating(-128i8).abs().0 as u8, i8::MAX as u8); /// ``` #[inline] #[unstable(feature = "saturating_int_impl", issue = "87920")] @@ -744,7 +741,7 @@ macro_rules! saturating_int_impl_unsigned { /// #![feature(saturating_int_impl)] /// use std::num::Saturating; /// - #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / 4;")] + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / Saturating(4", stringify!($t), ");")] /// /// assert_eq!(n.leading_zeros(), 2); /// ``` From 631766c0555acad0571f761f948bc4b144620534 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 09:06:43 +0200 Subject: [PATCH 010/269] Make all the impls for Staturating unstable saturating_int_impl --- library/core/src/num/saturating.rs | 66 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 6aaa5bf335a4..4616656b1acc 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -36,44 +36,44 @@ use crate::ops::{Sub, SubAssign}; #[unstable(feature = "saturating_int_impl", issue = "87920")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] #[repr(transparent)] -pub struct Saturating(#[stable(feature = "rust1", since = "1.0.0")] pub T); +pub struct Saturating(#[unstable(feature = "saturating_int_impl", issue = "87920")] pub T); -#[stable(feature = "rust1", since = "1.0.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::Debug for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -#[stable(feature = "saturating_display", since = "1.10.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::Display for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -#[stable(feature = "saturating_fmt", since = "1.11.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::Binary for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -#[stable(feature = "saturating_fmt", since = "1.11.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::Octal for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -#[stable(feature = "saturating_fmt", since = "1.11.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::LowerHex for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -#[stable(feature = "saturating_fmt", since = "1.11.0")] +#[unstable(feature = "saturating_int_impl", issue = "87920")] impl fmt::UpperHex for Saturating { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) @@ -83,7 +83,7 @@ impl fmt::UpperHex for Saturating { // FIXME(30524): impl Op for Saturating, impl OpAssign for Saturating macro_rules! saturating_impl { ($($t:ty)*) => ($( - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Add for Saturating<$t> { type Output = Saturating<$t>; @@ -93,9 +93,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl AddAssign for Saturating<$t> { #[inline] fn add_assign(&mut self, other: Saturating<$t>) { @@ -104,7 +104,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Sub for Saturating<$t> { type Output = Saturating<$t>; @@ -114,9 +114,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Sub, sub for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl SubAssign for Saturating<$t> { #[inline] fn sub_assign(&mut self, other: Saturating<$t>) { @@ -125,7 +125,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Mul for Saturating<$t> { type Output = Saturating<$t>; @@ -135,9 +135,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Mul, mul for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl MulAssign for Saturating<$t> { #[inline] fn mul_assign(&mut self, other: Saturating<$t>) { @@ -146,7 +146,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "saturating_div", since = "1.3.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Div for Saturating<$t> { type Output = Saturating<$t>; @@ -157,9 +157,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl DivAssign for Saturating<$t> { #[inline] fn div_assign(&mut self, other: Saturating<$t>) { @@ -168,7 +168,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Not for Saturating<$t> { type Output = Saturating<$t>; @@ -178,9 +178,9 @@ macro_rules! saturating_impl { } } forward_ref_unop! { impl Not, not for Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitXor for Saturating<$t> { type Output = Saturating<$t>; @@ -190,9 +190,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitXorAssign for Saturating<$t> { #[inline] fn bitxor_assign(&mut self, other: Saturating<$t>) { @@ -201,7 +201,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitOr for Saturating<$t> { type Output = Saturating<$t>; @@ -211,9 +211,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitOrAssign for Saturating<$t> { #[inline] fn bitor_assign(&mut self, other: Saturating<$t>) { @@ -222,7 +222,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitAnd for Saturating<$t> { type Output = Saturating<$t>; @@ -232,9 +232,9 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[stable(feature = "op_assign_traits", since = "1.8.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl BitAndAssign for Saturating<$t> { #[inline] fn bitand_assign(&mut self, other: Saturating<$t>) { @@ -243,7 +243,7 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t> } - #[stable(feature = "saturating_neg", since = "1.45.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Neg for Saturating<$t> { type Output = Self; #[inline] @@ -252,7 +252,7 @@ macro_rules! saturating_impl { } } forward_ref_unop! { impl Neg, neg for Saturating<$t>, - #[stable(feature = "saturating_ref", since = "1.14.0")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } @@ -464,7 +464,7 @@ macro_rules! saturating_int_impl { /// assert_eq!(m.0 as u16, 0b10101010_00000000); /// assert_eq!(m, Saturating(-22016)); /// ``` - #[stable(feature = "reverse_bits", since = "1.37.0")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] #[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")] #[inline] #[must_use] From 6cf4dd975b841a75388cbc4b53effc8d80faeb34 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 09:32:44 +0200 Subject: [PATCH 011/269] Remove mentioning of modular arithmetic --- library/core/src/num/saturating.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 4616656b1acc..55c6a51f581a 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -11,8 +11,7 @@ use crate::ops::{Sub, SubAssign}; /// Operations like `+` on `u32` values are intended to never overflow, /// and in some debug configurations overflow is detected and results /// in a panic. While most arithmetic falls into this category, some -/// code explicitly expects and relies upon modular arithmetic (e.g., -/// hashing). +/// code explicitly expects and relies upon saturating arithmetic. /// /// Saturating arithmetic can be achieved either through methods like /// `saturating_add`, or through the `Saturating` type, which says that @@ -93,7 +92,7 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>, - #[unstable(feature = "saturating_int_impl", issue = "87920")] + #[unstable(feature = "saturating_int_impl", issue = "87920")] } #[unstable(feature = "saturating_int_impl", issue = "87920")] impl AddAssign for Saturating<$t> { From 57dacfe4d14b7e26f627a94e675c936c8a981f24 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 11:25:03 +0200 Subject: [PATCH 012/269] Like in Wrapping use shift in doctest --- library/core/src/num/saturating.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 55c6a51f581a..283fcaed9427 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -625,7 +625,7 @@ macro_rules! saturating_int_impl_signed { /// #![feature(saturating_int_impl)] /// use std::num::Saturating; /// - #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / Saturating(4", stringify!($t), ");")] + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX >> 2);")] /// /// assert_eq!(n.leading_zeros(), 3); /// ``` @@ -740,7 +740,7 @@ macro_rules! saturating_int_impl_unsigned { /// #![feature(saturating_int_impl)] /// use std::num::Saturating; /// - #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX) / Saturating(4", stringify!($t), ");")] + #[doc = concat!("let n = Saturating(", stringify!($t), "::MAX >> 2);")] /// /// assert_eq!(n.leading_zeros(), 2); /// ``` From e240853dfc9c9e448bf32e8f2b059186e3cbd907 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 12:08:30 +0200 Subject: [PATCH 013/269] Replace doc test with doc macro call --- library/core/src/num/saturating.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 283fcaed9427..9f013b71350a 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -650,7 +650,7 @@ macro_rules! saturating_int_impl_signed { #[doc = concat!("assert_eq!(Saturating(-100", stringify!($t), ").abs(), Saturating(100));")] #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating((", stringify!($t), "::MIN + 1).abs()));")] #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating(", stringify!($t), "::MIN.saturating_abs()));")] - /// assert_eq!(Saturating(-128i8).abs().0 as u8, i8::MAX as u8); + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN).abs(), Saturating(", stringify!($t), "::MAX));")] /// ``` #[inline] #[unstable(feature = "saturating_int_impl", issue = "87920")] From 3f7d2ce28f8cf4dec56bf65fa2e6da0cf329ec55 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 12:26:10 +0200 Subject: [PATCH 014/269] Add naive shift implementation to Saturating --- library/core/src/num/saturating.rs | 159 ++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 9f013b71350a..9f4d7104fa5a 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -4,7 +4,7 @@ use crate::fmt; use crate::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign}; use crate::ops::{BitXor, BitXorAssign, Div, DivAssign}; use crate::ops::{Mul, MulAssign, Neg, Not}; -use crate::ops::{Sub, SubAssign}; +use crate::ops::{Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign}; /// Provides intentionally-wrapped arithmetic on `T`. /// @@ -78,6 +78,127 @@ impl fmt::UpperHex for Saturating { self.0.fmt(f) } } +#[allow(unused_macros)] +macro_rules! sh_impl_signed { + ($t:ident, $f:ident) => { + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Shl<$f> for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn shl(self, other: $f) -> Saturating<$t> { + if other < 0 { + Saturating(self.0.shr((-other & self::shift_max::$t as $f) as u32)) + } else { + Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32)) + } + } + } + forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl ShlAssign<$f> for Saturating<$t> { + #[inline] + fn shl_assign(&mut self, other: $f) { + *self = *self << other; + } + } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Shr<$f> for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn shr(self, other: $f) -> Saturating<$t> { + if other < 0 { + Saturating(self.0.shl((-other & self::shift_max::$t as $f) as u32)) + } else { + Saturating(self.0.shr((other & self::shift_max::$t as $f) as u32)) + } + } + } + forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl ShrAssign<$f> for Saturating<$t> { + #[inline] + fn shr_assign(&mut self, other: $f) { + *self = *self >> other; + } + } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } + }; +} + +macro_rules! sh_impl_unsigned { + ($t:ident, $f:ident) => { + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Shl<$f> for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn shl(self, other: $f) -> Saturating<$t> { + Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32)) + } + } + forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl ShlAssign<$f> for Saturating<$t> { + #[inline] + fn shl_assign(&mut self, other: $f) { + *self = *self << other; + } + } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Shr<$f> for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn shr(self, other: $f) -> Saturating<$t> { + Saturating(self.0.shr((other & self::shift_max::$t as $f) as u32)) + } + } + forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl ShrAssign<$f> for Saturating<$t> { + #[inline] + fn shr_assign(&mut self, other: $f) { + *self = *self >> other; + } + } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } + }; +} + +// FIXME (#23545): uncomment the remaining impls +macro_rules! sh_impl_all { + ($($t:ident)*) => ($( + //sh_impl_unsigned! { $t, u8 } + //sh_impl_unsigned! { $t, u16 } + //sh_impl_unsigned! { $t, u32 } + //sh_impl_unsigned! { $t, u64 } + //sh_impl_unsigned! { $t, u128 } + sh_impl_unsigned! { $t, usize } + + //sh_impl_signed! { $t, i8 } + //sh_impl_signed! { $t, i16 } + //sh_impl_signed! { $t, i32 } + //sh_impl_signed! { $t, i64 } + //sh_impl_signed! { $t, i128 } + //sh_impl_signed! { $t, isize } + )*) +} + +sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } // FIXME(30524): impl Op for Saturating, impl OpAssign for Saturating macro_rules! saturating_impl { @@ -774,3 +895,39 @@ macro_rules! saturating_int_impl_unsigned { } saturating_int_impl_unsigned! { usize u8 u16 u32 u64 u128 } + +mod shift_max { + #![allow(non_upper_case_globals)] + + #[cfg(target_pointer_width = "16")] + mod platform { + pub const usize: u32 = super::u16; + pub const isize: u32 = super::i16; + } + + #[cfg(target_pointer_width = "32")] + mod platform { + pub const usize: u32 = super::u32; + pub const isize: u32 = super::i32; + } + + #[cfg(target_pointer_width = "64")] + mod platform { + pub const usize: u32 = super::u64; + pub const isize: u32 = super::i64; + } + + pub const i8: u32 = (1 << 3) - 1; + pub const i16: u32 = (1 << 4) - 1; + pub const i32: u32 = (1 << 5) - 1; + pub const i64: u32 = (1 << 6) - 1; + pub const i128: u32 = (1 << 7) - 1; + pub use self::platform::isize; + + pub const u8: u32 = i8; + pub const u16: u32 = i16; + pub const u32: u32 = i32; + pub const u64: u32 = i64; + pub const u128: u32 = i128; + pub use self::platform::usize; +} From 7861121ae441f94a03b2de8ac1e61ec4fbf1e4cf Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 12:28:30 +0200 Subject: [PATCH 015/269] Add naive remainder impl to Saturating --- library/core/src/num/saturating.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 9f4d7104fa5a..b0a172c72d0b 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -3,7 +3,7 @@ use crate::fmt; use crate::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign}; use crate::ops::{BitXor, BitXorAssign, Div, DivAssign}; -use crate::ops::{Mul, MulAssign, Neg, Not}; +use crate::ops::{Mul, MulAssign, Neg, Not, Rem, RemAssign}; use crate::ops::{Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign}; /// Provides intentionally-wrapped arithmetic on `T`. @@ -288,6 +288,27 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> } + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Rem for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn rem(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.rem(other.0)) + } + } + forward_ref_binop! { impl Rem, rem for Saturating<$t>, Saturating<$t>, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl RemAssign for Saturating<$t> { + #[inline] + fn rem_assign(&mut self, other: Saturating<$t>) { + *self = *self % other; + } + } + forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t> } + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Not for Saturating<$t> { type Output = Saturating<$t>; From f136eea97c8a1aff9814c4ec2779884bd870feed Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 12 Aug 2021 13:43:20 +0200 Subject: [PATCH 016/269] Implement Neg only for signed Saturating types --- library/core/src/num/saturating.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index b0a172c72d0b..3bb668d9340b 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -384,17 +384,6 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t> } - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl Neg for Saturating<$t> { - type Output = Self; - #[inline] - fn neg(self) -> Self { - Saturating(0) - self - } - } - forward_ref_unop! { impl Neg, neg for Saturating<$t>, - #[unstable(feature = "saturating_int_impl", issue = "87920")] } - )*) } @@ -864,6 +853,17 @@ macro_rules! saturating_int_impl_signed { self.0.is_negative() } } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Neg for Saturating<$t> { + type Output = Self; + #[inline] + fn neg(self) -> Self { + Saturating(self.0.saturating_neg()) + } + } + forward_ref_unop! { impl Neg, neg for Saturating<$t>, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } From dabdd6de1fc64ab435476bfc3ef340118097214b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lanteri=20Thauvin?= Date: Wed, 11 Aug 2021 16:10:05 +0200 Subject: [PATCH 017/269] Don't mark `if_let_guard` as an incomplete feature --- compiler/rustc_feature/src/active.rs | 2 +- src/test/ui/generator/yielding-in-match-guards.rs | 1 - .../pattern/usefulness/deny-irrefutable-let-patterns.rs | 1 - .../usefulness/deny-irrefutable-let-patterns.stderr | 8 ++++---- src/test/ui/rfc-2294-if-let-guard/bindings.rs | 1 - src/test/ui/rfc-2294-if-let-guard/bindings.stderr | 4 ++-- src/test/ui/rfc-2294-if-let-guard/run-pass.rs | 1 - src/test/ui/rfc-2294-if-let-guard/typeck.rs | 1 - src/test/ui/rfc-2294-if-let-guard/typeck.stderr | 4 ++-- src/test/ui/rfc-2294-if-let-guard/warns.rs | 1 - src/test/ui/rfc-2294-if-let-guard/warns.stderr | 8 ++++---- 11 files changed, 13 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 73b29d65e913..f1f369a95d94 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -555,7 +555,7 @@ declare_features! ( (incomplete, lazy_normalization_consts, "1.46.0", Some(72219), None), /// Allows `if let` guard in match arms. - (incomplete, if_let_guard, "1.47.0", Some(51114), None), + (active, if_let_guard, "1.47.0", Some(51114), None), /// Allows non-trivial generic constants which have to be manually propagated upwards. (incomplete, const_evaluatable_checked, "1.48.0", Some(76560), None), diff --git a/src/test/ui/generator/yielding-in-match-guards.rs b/src/test/ui/generator/yielding-in-match-guards.rs index 5c10a7c78118..4e89fc975d04 100644 --- a/src/test/ui/generator/yielding-in-match-guards.rs +++ b/src/test/ui/generator/yielding-in-match-guards.rs @@ -11,7 +11,6 @@ // of the underlying generator. #![feature(if_let_guard)] -#![allow(incomplete_features)] async fn f() -> u8 { 1 } async fn foo() -> [bool; 10] { [false; 10] } diff --git a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs index 7549eae7016b..c85af7f3bcc7 100644 --- a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs +++ b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs @@ -1,5 +1,4 @@ #![feature(if_let_guard)] -#![allow(incomplete_features)] #![deny(irrefutable_let_patterns)] diff --git a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr index 0caa79a91529..b97683526bac 100644 --- a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr +++ b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr @@ -1,11 +1,11 @@ error: irrefutable `if let` pattern - --> $DIR/deny-irrefutable-let-patterns.rs:7:8 + --> $DIR/deny-irrefutable-let-patterns.rs:6:8 | LL | if let _ = 5 {} | ^^^^^^^^^ | note: the lint level is defined here - --> $DIR/deny-irrefutable-let-patterns.rs:4:9 + --> $DIR/deny-irrefutable-let-patterns.rs:3:9 | LL | #![deny(irrefutable_let_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | #![deny(irrefutable_let_patterns)] = help: consider replacing the `if let` with a `let` error: irrefutable `while let` pattern - --> $DIR/deny-irrefutable-let-patterns.rs:9:11 + --> $DIR/deny-irrefutable-let-patterns.rs:8:11 | LL | while let _ = 5 { | ^^^^^^^^^ @@ -22,7 +22,7 @@ LL | while let _ = 5 { = help: consider instead using a `loop { ... }` with a `let` inside it error: irrefutable `if let` guard pattern - --> $DIR/deny-irrefutable-let-patterns.rs:14:18 + --> $DIR/deny-irrefutable-let-patterns.rs:13:18 | LL | _ if let _ = 2 => {} | ^ diff --git a/src/test/ui/rfc-2294-if-let-guard/bindings.rs b/src/test/ui/rfc-2294-if-let-guard/bindings.rs index 4e2d70e3290e..1f32e4af121f 100644 --- a/src/test/ui/rfc-2294-if-let-guard/bindings.rs +++ b/src/test/ui/rfc-2294-if-let-guard/bindings.rs @@ -1,5 +1,4 @@ #![feature(if_let_guard)] -#![allow(incomplete_features)] fn main() { match Some(None) { diff --git a/src/test/ui/rfc-2294-if-let-guard/bindings.stderr b/src/test/ui/rfc-2294-if-let-guard/bindings.stderr index 9c5d92a33ada..2463b7f3eacc 100644 --- a/src/test/ui/rfc-2294-if-let-guard/bindings.stderr +++ b/src/test/ui/rfc-2294-if-let-guard/bindings.stderr @@ -1,11 +1,11 @@ error[E0425]: cannot find value `y` in this scope - --> $DIR/bindings.rs:7:14 + --> $DIR/bindings.rs:6:14 | LL | _ => y, | ^ not found in this scope error[E0425]: cannot find value `y` in this scope - --> $DIR/bindings.rs:9:5 + --> $DIR/bindings.rs:8:5 | LL | y | ^ not found in this scope diff --git a/src/test/ui/rfc-2294-if-let-guard/run-pass.rs b/src/test/ui/rfc-2294-if-let-guard/run-pass.rs index a3663003790f..3da57989df2b 100644 --- a/src/test/ui/rfc-2294-if-let-guard/run-pass.rs +++ b/src/test/ui/rfc-2294-if-let-guard/run-pass.rs @@ -1,7 +1,6 @@ // run-pass #![feature(if_let_guard)] -#![allow(incomplete_features)] enum Foo { Bar, diff --git a/src/test/ui/rfc-2294-if-let-guard/typeck.rs b/src/test/ui/rfc-2294-if-let-guard/typeck.rs index a4fc7f8cf2b2..ad178dfa4394 100644 --- a/src/test/ui/rfc-2294-if-let-guard/typeck.rs +++ b/src/test/ui/rfc-2294-if-let-guard/typeck.rs @@ -1,5 +1,4 @@ #![feature(if_let_guard)] -#![allow(incomplete_features)] fn ok() -> Result, ()> { Ok(Some(true)) diff --git a/src/test/ui/rfc-2294-if-let-guard/typeck.stderr b/src/test/ui/rfc-2294-if-let-guard/typeck.stderr index 6407128d8d87..fbb941ffd910 100644 --- a/src/test/ui/rfc-2294-if-let-guard/typeck.stderr +++ b/src/test/ui/rfc-2294-if-let-guard/typeck.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/typeck.rs:10:22 + --> $DIR/typeck.rs:9:22 | LL | Ok(x) if let Err(_) = x => {}, | ^^^^^^ expected enum `Option`, found enum `Result` @@ -8,7 +8,7 @@ LL | Ok(x) if let Err(_) = x => {}, found enum `Result<_, _>` error[E0308]: mismatched types - --> $DIR/typeck.rs:12:22 + --> $DIR/typeck.rs:11:22 | LL | Ok(x) if let 0 = x => {}, | ^ expected enum `Option`, found integer diff --git a/src/test/ui/rfc-2294-if-let-guard/warns.rs b/src/test/ui/rfc-2294-if-let-guard/warns.rs index d921367b9177..3ad1a50c61f8 100644 --- a/src/test/ui/rfc-2294-if-let-guard/warns.rs +++ b/src/test/ui/rfc-2294-if-let-guard/warns.rs @@ -1,5 +1,4 @@ #![feature(if_let_guard)] -#![allow(incomplete_features)] #[deny(irrefutable_let_patterns)] fn irrefutable_let_guard() { diff --git a/src/test/ui/rfc-2294-if-let-guard/warns.stderr b/src/test/ui/rfc-2294-if-let-guard/warns.stderr index c7627f1c3c50..cf64513f9c81 100644 --- a/src/test/ui/rfc-2294-if-let-guard/warns.stderr +++ b/src/test/ui/rfc-2294-if-let-guard/warns.stderr @@ -1,11 +1,11 @@ error: irrefutable `if let` guard pattern - --> $DIR/warns.rs:7:24 + --> $DIR/warns.rs:6:24 | LL | Some(x) if let () = x => {} | ^^ | note: the lint level is defined here - --> $DIR/warns.rs:4:8 + --> $DIR/warns.rs:3:8 | LL | #[deny(irrefutable_let_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | #[deny(irrefutable_let_patterns)] = help: consider removing the guard and adding a `let` inside the match arm error: unreachable pattern - --> $DIR/warns.rs:16:25 + --> $DIR/warns.rs:15:25 | LL | x if let None | None = x => {} | ^^^^ | note: the lint level is defined here - --> $DIR/warns.rs:13:8 + --> $DIR/warns.rs:12:8 | LL | #[deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ From 53a7cdd9a3bd7997730ab800c43f5d1160e670f9 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 14 Aug 2021 18:28:21 +0100 Subject: [PATCH 018/269] Forbid inline const block referencing params from being used in patterns --- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index dd265d881e6c..2a4ec2804bcb 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -21,7 +21,7 @@ use rustc_middle::mir::UserTypeProjection; use rustc_middle::mir::{BorrowKind, Field, Mutability}; use rustc_middle::thir::{Ascription, BindingMode, FieldPat, Pat, PatKind, PatRange, PatTyProj}; use rustc_middle::ty::subst::{GenericArg, SubstsRef}; -use rustc_middle::ty::{self, AdtDef, DefIdTree, Region, Ty, TyCtxt, UserType}; +use rustc_middle::ty::{self, AdtDef, ConstKind, DefIdTree, Region, Ty, TyCtxt, UserType}; use rustc_span::{Span, Symbol}; use std::cmp::Ordering; @@ -545,6 +545,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { hir::ExprKind::ConstBlock(ref anon_const) => { let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id); let value = ty::Const::from_anon_const(self.tcx, anon_const_def_id); + if matches!(value.val, ConstKind::Param(_)) { + let span = self.tcx.hir().span(anon_const.hir_id); + self.errors.push(PatternError::ConstParamInPattern(span)); + return PatKind::Wild; + } return *self.const_to_pat(value, expr.hir_id, expr.span, false).kind; } hir::ExprKind::Lit(ref lit) => (lit, false), From dc52040efd3c61ac71b9d837a67ba220d08bc931 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 14 Aug 2021 18:29:04 +0100 Subject: [PATCH 019/269] Add test for issue 82518 --- .../ui/inline-const/const-match-pat-generic.rs | 16 ++++++++++++++++ .../inline-const/const-match-pat-generic.stderr | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/test/ui/inline-const/const-match-pat-generic.rs create mode 100644 src/test/ui/inline-const/const-match-pat-generic.stderr diff --git a/src/test/ui/inline-const/const-match-pat-generic.rs b/src/test/ui/inline-const/const-match-pat-generic.rs new file mode 100644 index 000000000000..61680d653d02 --- /dev/null +++ b/src/test/ui/inline-const/const-match-pat-generic.rs @@ -0,0 +1,16 @@ +#![allow(incomplete_features)] +#![feature(inline_const)] + +// rust-lang/rust#82518: ICE with inline-const in match referencing const-generic parameter + +fn foo() { + match 0 { + const { V } => {}, + //~^ ERROR const parameters cannot be referenced in patterns [E0158] + _ => {}, + } +} + +fn main() { + foo::<1>(); +} diff --git a/src/test/ui/inline-const/const-match-pat-generic.stderr b/src/test/ui/inline-const/const-match-pat-generic.stderr new file mode 100644 index 000000000000..a3ed41a3f6af --- /dev/null +++ b/src/test/ui/inline-const/const-match-pat-generic.stderr @@ -0,0 +1,9 @@ +error[E0158]: const parameters cannot be referenced in patterns + --> $DIR/const-match-pat-generic.rs:8:11 + | +LL | const { V } => {}, + | ^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0158`. From da25af2940f44f841f91ba038535e8e84c4893f3 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 17 Aug 2021 13:55:31 -0700 Subject: [PATCH 020/269] Make spans for tuple patterns in E0023 more precise As suggested in #86307. --- compiler/rustc_typeck/src/check/pat.rs | 6 ++- .../tuple_struct_destructure_fail.stderr | 24 +++++++---- src/test/ui/error-codes/E0023.stderr | 30 ++++++++----- src/test/ui/issues/issue-72574-2.stderr | 6 ++- .../match/match-pattern-field-mismatch.stderr | 6 ++- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 6 ++- src/test/ui/pattern/issue-74539.stderr | 6 ++- .../ui/pattern/pat-tuple-overfield.stderr | 12 ++++-- .../ui/pattern/pat-tuple-underfield.stderr | 42 ++++++++++++------- .../ui/pattern/pattern-error-continue.stderr | 6 ++- 10 files changed, 96 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index dae574bb7bf0..2ef79c7686c5 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -990,10 +990,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let subpats_ending = pluralize!(subpats.len()); let fields_ending = pluralize!(fields.len()); + let fields_span = pat_span.trim_start(qpath.span()).unwrap_or(pat_span); let res_span = self.tcx.def_span(res.def_id()); let mut err = struct_span_err!( self.tcx.sess, - pat_span, + fields_span, E0023, "this pattern has {} field{}, but the corresponding {} has {} field{}", subpats.len(), @@ -1003,9 +1004,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields_ending, ); err.span_label( - pat_span, + fields_span, format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len(),), ) + .span_label(qpath.span(), format!("this {}", res.descr())) .span_label(res_span, format!("{} defined here", res.descr())); // Identify the case `Some(x, y)` where the expected type is e.g. `Option<(T, U)>`. diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index 0e92cc5c9f28..ec7d76f4fe52 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -15,22 +15,26 @@ LL | Enum::SingleVariant(a, .., b, ..) = Enum::SingleVariant(0, 1); | previously used here error[E0023]: this pattern has 3 fields, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:30:5 + --> $DIR/tuple_struct_destructure_fail.rs:30:16 | LL | struct TupleStruct(S, T); | ------------------------------- tuple struct defined here ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | ^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | -----------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple struct error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:32:5 + --> $DIR/tuple_struct_destructure_fail.rs:32:16 | LL | struct TupleStruct(S, T); | ------------------------------- tuple struct defined here ... LL | TupleStruct(_) = TupleStruct(1, 2); - | ^^^^^^^^^^^^^^ expected 2 fields, found 1 + | -----------^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -42,22 +46,26 @@ LL | TupleStruct(..) = TupleStruct(1, 2); | ~~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:34:5 + --> $DIR/tuple_struct_destructure_fail.rs:34:24 | LL | SingleVariant(S, T) | ------------------- tuple variant defined here ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | -------------------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:36:5 + --> $DIR/tuple_struct_destructure_fail.rs:36:24 | LL | SingleVariant(S, T) | ------------------- tuple variant defined here ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | -------------------^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index ec3aae297141..ecc075b6fb4b 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -1,11 +1,13 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:11:9 + --> $DIR/E0023.rs:11:21 | LL | Apple(String, String), | --------------------- tuple variant defined here ... LL | Fruit::Apple(a) => {}, - | ^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | ------------^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -13,31 +15,37 @@ LL | Fruit::Apple(a, _) => {}, | +++ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:12:9 + --> $DIR/E0023.rs:12:21 | LL | Apple(String, String), | --------------------- tuple variant defined here ... LL | Fruit::Apple(a, b, c) => {}, - | ^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | ------------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:13:9 + --> $DIR/E0023.rs:13:20 | LL | Pear(u32), | --------- tuple variant defined here ... LL | Fruit::Pear(1, 2) => {}, - | ^^^^^^^^^^^^^^^^^ expected 1 field, found 2 + | -----------^^^^^^ expected 1 field, found 2 + | | + | this tuple variant error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:14:9 + --> $DIR/E0023.rs:14:22 | LL | Orange((String, String)), | ------------------------ tuple variant defined here ... LL | Fruit::Orange(a, b) => {}, - | ^^^^^^^^^^^^^^^^^^^ expected 1 field, found 2 + | -------------^^^^^^ expected 1 field, found 2 + | | + | this tuple variant | help: missing parentheses | @@ -45,13 +53,15 @@ LL | Fruit::Orange((a, b)) => {}, | + + error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:15:9 + --> $DIR/E0023.rs:15:22 | LL | Banana(()), | ---------- tuple variant defined here ... LL | Fruit::Banana() => {}, - | ^^^^^^^^^^^^^^^ expected 1 field, found 0 + | -------------^^ expected 1 field, found 0 + | | + | this tuple variant | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 928fa58b1755..4c38d2c31ed6 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -19,13 +19,15 @@ LL | Binder(_a, _x @ ..) => {} = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields - --> $DIR/issue-72574-2.rs:6:9 + --> $DIR/issue-72574-2.rs:6:15 | LL | struct Binder(i32, i32, i32); | ----------------------------- tuple struct defined here ... LL | Binder(_a, _x @ ..) => {} - | ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | ------^^^^^^^^^^^^^ expected 3 fields, found 2 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index e34164ec0db2..776cdfc7083b 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -1,11 +1,13 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields - --> $DIR/match-pattern-field-mismatch.rs:10:11 + --> $DIR/match-pattern-field-mismatch.rs:10:21 | LL | Rgb(usize, usize, usize), | ------------------------ tuple variant defined here ... LL | Color::Rgb(_, _) => { } - | ^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | ----------^^^^^^ expected 3 fields, found 2 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index 7f5da8f3c2dc..ea5f970d1d65 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -10,13 +10,15 @@ LL | let P() = U {}; found struct `P<_>` error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field - --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 + --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 | LL | struct P(T); // 1 type parameter wanted | --------------- tuple struct defined here ... LL | let P() = U {}; - | ^^^ expected 1 field, found 0 + | -^^ expected 1 field, found 0 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index 7d998af7fb38..87c3842d28f4 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -19,13 +19,15 @@ LL | E::A(x @ ..) => { = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/issue-74539.rs:8:9 + --> $DIR/issue-74539.rs:8:13 | LL | A(u8, u8), | --------- tuple variant defined here ... LL | E::A(x @ ..) => { - | ^^^^^^^^^^^^ expected 2 fields, found 1 + | ----^^^^^^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 45b6fd1b4d44..e0386d9cd4ff 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -22,22 +22,26 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:10:9 + --> $DIR/pat-tuple-overfield.rs:10:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here ... LL | S(1, 2, 3, 4) => {} - | ^^^^^^^^^^^^^ expected 3 fields, found 4 + | -^^^^^^^^^^^^ expected 3 fields, found 4 + | | + | this tuple struct error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:12:9 + --> $DIR/pat-tuple-overfield.rs:12:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here ... LL | S(1, 2, .., 3, 4) => {} - | ^^^^^^^^^^^^^^^^^ expected 3 fields, found 4 + | -^^^^^^^^^^^^^^^^ expected 3 fields, found 4 + | | + | this tuple struct error: aborting due to 4 previous errors diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 2fbcb6d67ba3..4cc20a4ac0ef 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -8,13 +8,15 @@ LL | E::S => {} | ^^^^ help: use the tuple variant pattern syntax instead: `E::S(_, _)` error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:9:9 + --> $DIR/pat-tuple-underfield.rs:9:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(x) => {} - | ^^^^ expected 2 fields, found 1 + | -^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -22,13 +24,15 @@ LL | S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:14:9 + --> $DIR/pat-tuple-underfield.rs:14:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(_) => {} - | ^^^^ expected 2 fields, found 1 + | -^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -40,13 +44,15 @@ LL | S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:20:9 + --> $DIR/pat-tuple-underfield.rs:20:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S() => {} - | ^^^ expected 2 fields, found 0 + | -^^ expected 2 fields, found 0 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -58,13 +64,15 @@ LL | S(..) => {} | ++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:9 + --> $DIR/pat-tuple-underfield.rs:27:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(x) => {} - | ^^^^^^^ expected 2 fields, found 1 + | ----^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -72,13 +80,15 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:9 + --> $DIR/pat-tuple-underfield.rs:32:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(_) => {} - | ^^^^^^^ expected 2 fields, found 1 + | ----^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -90,13 +100,15 @@ LL | E::S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:38:9 + --> $DIR/pat-tuple-underfield.rs:38:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S() => {} - | ^^^^^^ expected 2 fields, found 0 + | ----^^ expected 2 fields, found 0 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -108,13 +120,15 @@ LL | E::S(..) => {} | ++ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:9 + --> $DIR/pat-tuple-underfield.rs:50:15 | LL | struct Point4(i32, i32, i32, i32); | ---------------------------------- tuple struct defined here ... LL | Point4( a , _ ) => {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 + | ------^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index 3f28ffed2916..216c3ca47d39 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -26,13 +26,15 @@ LL | A::B(_) => (), | ~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pattern-error-continue.rs:17:9 + --> $DIR/pattern-error-continue.rs:17:13 | LL | B(isize, isize), | --------------- tuple variant defined here ... LL | A::B(_, _, _) => (), - | ^^^^^^^^^^^^^ expected 2 fields, found 3 + | ----^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From 8049230852676cda16fe4fb443b4e2b99be87cf8 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 09:59:05 +0200 Subject: [PATCH 021/269] Saturate negative division --- library/core/src/num/saturating.rs | 59 +++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 3bb668d9340b..b06ed36689cd 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -266,19 +266,6 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl Div for Saturating<$t> { - type Output = Saturating<$t>; - - #[inline] - fn div(self, other: Saturating<$t>) -> Saturating<$t> { - // saturating div is the default behavior? - Saturating(self.0.div(other.0)) - } - } - forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[unstable(feature = "saturating_int_impl", issue = "87920")] } - #[unstable(feature = "saturating_int_impl", issue = "87920")] impl DivAssign for Saturating<$t> { #[inline] @@ -864,6 +851,40 @@ macro_rules! saturating_int_impl_signed { } forward_ref_unop! { impl Neg, neg for Saturating<$t>, #[unstable(feature = "saturating_int_impl", issue = "87920")] } + + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN + 1), Saturating(", stringify!($t), "::MAX) / Saturating(-1));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MIN) / Saturating(-1));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MAX) / Saturating(1));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN), Saturating(", stringify!($t), "::MIN) / Saturating(1));")] + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Div for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn div(self, other: Saturating<$t>) -> Saturating<$t> { + let expected_signum = self.0.signum() * other.0.signum(); + let (result, overflowed) = self.0.overflowing_div(other.0); + + if !overflowed { + Saturating(result) + } else if expected_signum < 0 { + Saturating(<$t>::MIN) + } else { + Saturating(<$t>::MAX) + } + } + } + forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } @@ -912,6 +933,18 @@ macro_rules! saturating_int_impl_unsigned { } } + + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Div for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn div(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.div(other.0)) + } + } + forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } From 742d450783cb9c9e7faef0f2dc3f09c72f7ff217 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 10:08:58 +0200 Subject: [PATCH 022/269] Add and use saturating_div instead of impl inside Saturating --- library/core/src/num/int_macros.rs | 26 ++++++++++++++++++++++++++ library/core/src/num/saturating.rs | 11 +---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 0bc646995c7c..f5966a53ed26 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -918,6 +918,32 @@ macro_rules! int_impl { } } + /// Saturating integer division. Computes `self / rhs`, saturating at the + /// numeric bounds instead of overflowing. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + #[rustc_const_unstable(feature = "saturating_int_impl", issue = "87920")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn saturating_div(self, rhs: Self) -> Self { + match self.checked_div(rhs) { + Some(x) => x, + None => if (self < 0) == (rhs < 0) { + Self::MAX + } else { + Self::MIN + } + } + } + /// Saturating integer exponentiation. Computes `self.pow(exp)`, /// saturating at the numeric bounds instead of overflowing. /// diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index b06ed36689cd..4b346409ebf0 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -871,16 +871,7 @@ macro_rules! saturating_int_impl_signed { #[inline] fn div(self, other: Saturating<$t>) -> Saturating<$t> { - let expected_signum = self.0.signum() * other.0.signum(); - let (result, overflowed) = self.0.overflowing_div(other.0); - - if !overflowed { - Saturating(result) - } else if expected_signum < 0 { - Saturating(<$t>::MIN) - } else { - Saturating(<$t>::MAX) - } + Saturating(self.0.saturating_div(other.0)) } } forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, From 6bb3acab74f9cf4bf3d3b81f0805416cd7b3ee20 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 11:06:08 +0200 Subject: [PATCH 023/269] Add doctests to and fix saturating_div for signed integer types --- library/core/src/num/int_macros.rs | 31 +++++++++++++++++++++--------- library/std/src/lib.rs | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index f5966a53ed26..7c36f4cdd203 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -926,21 +926,34 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` + /// #![feature(saturating_div)] + /// + #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_div(-1), ", stringify!($SelfT), "::MIN + 1);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_div(-1), ", stringify!($SelfT), "::MAX);")] /// /// ``` - #[unstable(feature = "saturating_int_impl", issue = "87920")] - #[rustc_const_unstable(feature = "saturating_int_impl", issue = "87920")] + /// + /// ```should_panic + /// #![feature(saturating_div)] + /// + #[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")] + /// + /// ``` + #[unstable(feature = "saturating_div", issue = "87920")] + #[rustc_const_unstable(feature = "saturating_div", issue = "87920")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] pub const fn saturating_div(self, rhs: Self) -> Self { - match self.checked_div(rhs) { - Some(x) => x, - None => if (self < 0) == (rhs < 0) { - Self::MAX - } else { - Self::MIN - } + let (result, overflowed) = self.overflowing_div(rhs); + + if !overflowed { + result + } else if (self < 0) == (rhs < 0) { + Self::MAX + } else { + Self::MIN } } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 818ca7df3e37..676ca5dea5d2 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -308,6 +308,7 @@ #![feature(ptr_internals)] #![feature(rustc_attrs)] #![feature(rustc_private)] +#![feature(saturating_div)] #![feature(saturating_int_impl)] #![feature(slice_concat_ext)] #![feature(slice_internals)] From a0e61e278057ffa3a6ca1d39fe04bf1569d3cf40 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 11:07:34 +0200 Subject: [PATCH 024/269] Add saturating_div to unsigned integer types --- library/core/src/num/uint_macros.rs | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ae113a47e95d..d6bd3115a025 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1041,6 +1041,36 @@ macro_rules! uint_impl { } } + /// Saturating integer division. Computes `self / rhs`, saturating at the + /// numeric bounds instead of overflowing. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_div)] + /// + #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")] + /// + /// ``` + /// + /// ```should_panic + /// #![feature(saturating_div)] + /// + #[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")] + /// + /// ``` + #[unstable(feature = "saturating_div", issue = "87920")] + #[rustc_const_unstable(feature = "saturating_div", issue = "87920")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn saturating_div(self, rhs: Self) -> Self { + // on unsigned types, there is no overflow in integer division + self.wrapping_div(rhs) + } + /// Saturating integer exponentiation. Computes `self.pow(exp)`, /// saturating at the numeric bounds instead of overflowing. /// From 5ca6993307c926f1eb1e536bf957620685b31b00 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 11:07:53 +0200 Subject: [PATCH 025/269] Simplify Div impl for Saturating by using saturating_div --- library/core/src/num/saturating.rs | 68 ++++++++++++++---------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 4b346409ebf0..2e84f0657131 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -266,6 +266,37 @@ macro_rules! saturating_impl { } forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(saturating_int_impl, saturating_div)] + /// use std::num::Saturating; + /// + #[doc = concat!("assert_eq!(Saturating(2", stringify!($t), "), Saturating(5", stringify!($t), ") / Saturating(2));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MAX) / Saturating(1));")] + #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN), Saturating(", stringify!($t), "::MIN) / Saturating(1));")] + /// ``` + /// + /// ```should_panic + /// #![feature(saturating_int_impl, saturating_div)] + /// use std::num::Saturating; + /// + #[doc = concat!("let _ = Saturating(0", stringify!($t), ") / Saturating(0);")] + /// ``` + #[unstable(feature = "saturating_int_impl", issue = "87920")] + impl Div for Saturating<$t> { + type Output = Saturating<$t>; + + #[inline] + fn div(self, other: Saturating<$t>) -> Saturating<$t> { + Saturating(self.0.saturating_div(other.0)) + } + } + forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, + #[unstable(feature = "saturating_int_impl", issue = "87920")] } + #[unstable(feature = "saturating_int_impl", issue = "87920")] impl DivAssign for Saturating<$t> { #[inline] @@ -851,31 +882,6 @@ macro_rules! saturating_int_impl_signed { } forward_ref_unop! { impl Neg, neg for Saturating<$t>, #[unstable(feature = "saturating_int_impl", issue = "87920")] } - - /// # Examples - /// - /// Basic usage: - /// - /// ``` - /// #![feature(saturating_int_impl)] - /// use std::num::Saturating; - /// - #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN + 1), Saturating(", stringify!($t), "::MAX) / Saturating(-1));")] - #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MIN) / Saturating(-1));")] - #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MAX) / Saturating(1));")] - #[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN), Saturating(", stringify!($t), "::MIN) / Saturating(1));")] - /// ``` - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl Div for Saturating<$t> { - type Output = Saturating<$t>; - - #[inline] - fn div(self, other: Saturating<$t>) -> Saturating<$t> { - Saturating(self.0.saturating_div(other.0)) - } - } - forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } @@ -924,18 +930,6 @@ macro_rules! saturating_int_impl_unsigned { } } - - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl Div for Saturating<$t> { - type Output = Saturating<$t>; - - #[inline] - fn div(self, other: Saturating<$t>) -> Saturating<$t> { - Saturating(self.0.div(other.0)) - } - } - forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[unstable(feature = "saturating_int_impl", issue = "87920")] } )*) } From 2b5970f993a091ad51624cdbfefee7dd97f65682 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 19 Aug 2021 11:28:33 +0200 Subject: [PATCH 026/269] Simplify saturating_div --- library/core/src/num/int_macros.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 7c36f4cdd203..2c866812937e 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -946,14 +946,9 @@ macro_rules! int_impl { without modifying the original"] #[inline] pub const fn saturating_div(self, rhs: Self) -> Self { - let (result, overflowed) = self.overflowing_div(rhs); - - if !overflowed { - result - } else if (self < 0) == (rhs < 0) { - Self::MAX - } else { - Self::MIN + match self.overflowing_div(rhs) { + (result, false) => result, + (_result, true) => Self::MAX, // MIN / -1 is the only possible saturating overflow } } From 4130a323b6aa1df5466d3b0d13c0e51039b6827d Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Thu, 19 Aug 2021 20:21:41 +0800 Subject: [PATCH 027/269] bootstrap.py: recognize riscv64 when auto-detect The architecture auto-detect table has no entry for riscv64 (which rustc uses riscv64gc for the first part of triplet, assuming it's a generic Linux distro). Add it to the table to allow riscv64 systems to bootstrap Rust. Signed-off-by: Icenowy Zheng --- src/bootstrap/bootstrap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 3faf38c66ec8..e34768bc2c90 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -301,6 +301,7 @@ def default_build_triple(verbose): 'ppc': 'powerpc', 'ppc64': 'powerpc64', 'ppc64le': 'powerpc64le', + 'riscv64': 'riscv64gc', 's390x': 's390x', 'x64': 'x86_64', 'x86': 'i686', From 51d598ec285fc8aa29e2a1c64dc90394ccbd4130 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Thu, 19 Aug 2021 12:35:20 +0200 Subject: [PATCH 028/269] Adjust documentation of `Arc::make_mut` Related discussion in the users forum: https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn Also includes small formatting improvement in the documentation of `Rc::make_mut`. This commit makes the two documentations in question complete analogs. The previously claimed point in which one "differs from the behavior of" the other turns out to be incorrect, AFAIK. One remaining inaccuracy: `Weak` pointers aren't disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other. --- library/alloc/src/rc.rs | 10 +++++----- library/alloc/src/sync.rs | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 0b3079fa59db..90b077210a47 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1115,11 +1115,11 @@ impl Rc { /// /// let mut data = Rc::new(5); /// - /// *Rc::make_mut(&mut data) += 1; // Won't clone anything - /// let mut other_data = Rc::clone(&data); // Won't clone inner data - /// *Rc::make_mut(&mut data) += 1; // Clones inner data - /// *Rc::make_mut(&mut data) += 1; // Won't clone anything - /// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything + /// *Rc::make_mut(&mut data) += 1; // Won't clone anything + /// let mut other_data = Rc::clone(&data); // Won't clone inner data + /// *Rc::make_mut(&mut data) += 1; // Clones inner data + /// *Rc::make_mut(&mut data) += 1; // Won't clone anything + /// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything /// /// // Now `data` and `other_data` point to different allocations. /// assert_eq!(*data, 8); diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 3183a6db410b..7e4cb6d2c60f 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1346,18 +1346,17 @@ impl Receiver for Arc {} impl Arc { /// Makes a mutable reference into the given `Arc`. /// - /// If there are other `Arc` or [`Weak`] pointers to the same allocation, - /// then `make_mut` will create a new allocation and invoke [`clone`][clone] on the inner value - /// to ensure unique ownership. This is also referred to as clone-on-write. + /// If there are other `Arc` pointers to the same allocation, then `make_mut` will + /// [`clone`] the inner value to a new allocation to ensure unique ownership. This is also + /// referred to as clone-on-write. /// - /// Note that this differs from the behavior of [`Rc::make_mut`] which disassociates - /// any remaining `Weak` pointers. + /// If there are no other `Arc` pointers to this allocation, then [`Weak`] + /// pointers to this allocation will be disassociated. /// - /// See also [`get_mut`][get_mut], which will fail rather than cloning. + /// See also [`get_mut`], which will fail rather than cloning. /// - /// [clone]: Clone::clone - /// [get_mut]: Arc::get_mut - /// [`Rc::make_mut`]: super::rc::Rc::make_mut + /// [`clone`]: Clone::clone + /// [`get_mut`]: Arc::get_mut /// /// # Examples /// @@ -1376,6 +1375,23 @@ impl Arc { /// assert_eq!(*data, 8); /// assert_eq!(*other_data, 12); /// ``` + /// + /// [`Weak`] pointers will be disassociated: + /// + /// ``` + /// use std::sync::Arc; + /// + /// let mut data = Arc::new(75); + /// let weak = Arc::downgrade(&data); + /// + /// assert!(75 == *data); + /// assert!(75 == *weak.upgrade().unwrap()); + /// + /// *Arc::make_mut(&mut data) += 1; + /// + /// assert!(76 == *data); + /// assert!(weak.upgrade().is_none()); + /// ``` #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "arc_unique", since = "1.4.0")] From 70b9a7b988772817284dda19a5cd6e0d46cb7dbb Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 19 Aug 2021 19:01:19 +0100 Subject: [PATCH 029/269] Make test function pub --- src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs index 7067130a4618..019c786a9023 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs +++ b/src/test/run-make-fulldeps/remap-path-prefix/auxiliary/lib.rs @@ -1,3 +1,3 @@ -fn lib() { +pub fn lib() { panic!("calm"); } From 08c55bdce592154dbbe36588f4e228b4b3a0ecaf Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Thu, 19 Aug 2021 19:04:46 +0100 Subject: [PATCH 030/269] Test presence of remapped path --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile index c923d7e80117..b01f406e5582 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/Makefile +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -3,4 +3,5 @@ # Checks if remapping works if the remap-from string contains path to the working directory plus more all: $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs + grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 ! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 From 39ef8ea767f6dd953e63f8a0a4828dac37bed50c Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Thu, 22 Jul 2021 16:46:19 -0700 Subject: [PATCH 031/269] Refactor Markdown length-limited summary implementation This commit refactors the implementation of `markdown_summary_with_limit()`, separating the logic of determining when the limit has been reached from the actual rendering process. The main advantage of the new approach is that it guarantees that all HTML tags are closed, whereas the previous implementation could generate tags that were never closed. It also ensures that no empty tags are generated (e.g., ``). The new implementation consists of a general-purpose struct `HtmlWithLimit` that manages the length-limiting logic and a function `markdown_summary_with_limit()` that renders Markdown to HTML using the struct. --- src/librustdoc/html/length_limit.rs | 94 +++++++++++++++++++++++++++++ src/librustdoc/html/markdown.rs | 72 +++++++++------------- src/librustdoc/html/mod.rs | 1 + src/librustdoc/lib.rs | 1 + 4 files changed, 125 insertions(+), 43 deletions(-) create mode 100644 src/librustdoc/html/length_limit.rs diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs new file mode 100644 index 000000000000..42b94b511181 --- /dev/null +++ b/src/librustdoc/html/length_limit.rs @@ -0,0 +1,94 @@ +//! See [`HtmlWithLimit`]. + +use std::fmt::Write; +use std::ops::ControlFlow; + +use crate::html::escape::Escape; + +/// A buffer that allows generating HTML with a length limit. +/// +/// This buffer ensures that: +/// +/// * all tags are closed, +/// * only the most recently opened tag is closed, +/// * no tags are left empty (e.g., ``) due to the length limit being reached, +/// * all text is escaped. +#[derive(Debug)] +pub(super) struct HtmlWithLimit { + buf: String, + len: usize, + limit: usize, + /// A list of tags that have been requested to be opened via [`Self::open_tag()`] + /// but have not actually been pushed to `buf` yet. This ensures that tags are not + /// left empty (e.g., ``) due to the length limit being reached. + queued_tags: Vec<&'static str>, + /// A list of all tags that have been opened but not yet closed. + unclosed_tags: Vec<&'static str>, +} + +impl HtmlWithLimit { + /// Create a new buffer, with a limit of `length_limit`. + pub(super) fn new(length_limit: usize) -> Self { + Self { + buf: String::new(), + len: 0, + limit: length_limit, + unclosed_tags: Vec::new(), + queued_tags: Vec::new(), + } + } + + /// Finish using the buffer and get the written output. + /// This function will close all unclosed tags for you. + pub(super) fn finish(mut self) -> String { + self.close_all_tags(); + self.buf + } + + /// Write some plain text to the buffer, escaping as needed. + /// + /// This function skips writing the text if the length limit was reached + /// and returns [`ControlFlow::Break`]. + pub(super) fn push(&mut self, text: &str) -> ControlFlow<(), ()> { + if self.len + text.len() > self.limit { + return ControlFlow::BREAK; + } + + self.flush_queue(); + write!(self.buf, "{}", Escape(text)).unwrap(); + self.len += text.len(); + + ControlFlow::CONTINUE + } + + /// Open an HTML tag. + pub(super) fn open_tag(&mut self, tag_name: &'static str) { + self.queued_tags.push(tag_name); + } + + /// Close the most recently opened HTML tag. + pub(super) fn close_tag(&mut self) { + let tag_name = self.unclosed_tags.pop().unwrap(); + self.buf.push_str("'); + } + + /// Write all queued tags and add them to the `unclosed_tags` list. + fn flush_queue(&mut self) { + for tag_name in self.queued_tags.drain(..) { + self.buf.push('<'); + self.buf.push_str(tag_name); + self.buf.push('>'); + + self.unclosed_tags.push(tag_name); + } + } + + /// Close all unclosed tags. + fn close_all_tags(&mut self) { + while !self.unclosed_tags.is_empty() { + self.close_tag(); + } + } +} diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 472323daf301..5a569c690e54 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -23,12 +23,13 @@ use rustc_hir::HirId; use rustc_middle::ty::TyCtxt; use rustc_span::edition::Edition; use rustc_span::Span; + use std::borrow::Cow; use std::cell::RefCell; use std::collections::VecDeque; use std::default::Default; use std::fmt::Write; -use std::ops::Range; +use std::ops::{ControlFlow, Range}; use std::str; use crate::clean::RenderedLink; @@ -36,6 +37,7 @@ use crate::doctest; use crate::html::escape::Escape; use crate::html::format::Buffer; use crate::html::highlight; +use crate::html::length_limit::HtmlWithLimit; use crate::html::toc::TocBuilder; use pulldown_cmark::{ @@ -1081,15 +1083,6 @@ fn markdown_summary_with_limit( return (String::new(), false); } - let mut s = String::with_capacity(md.len() * 3 / 2); - let mut text_length = 0; - let mut stopped_early = false; - - fn push(s: &mut String, text_length: &mut usize, text: &str) { - write!(s, "{}", Escape(text)).unwrap(); - *text_length += text.len(); - } - let mut replacer = |broken_link: BrokenLink<'_>| { if let Some(link) = link_names.iter().find(|link| &*link.original_text == broken_link.reference) @@ -1101,56 +1094,49 @@ fn markdown_summary_with_limit( }; let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); - let p = LinkReplacer::new(p, link_names); + let mut p = LinkReplacer::new(p, link_names); - 'outer: for event in p { + // FIXME: capacity + let mut buf = HtmlWithLimit::new(length_limit); + let mut stopped_early = false; + p.try_for_each(|event| { match &event { Event::Text(text) => { - for word in text.split_inclusive(char::is_whitespace) { - if text_length + word.len() >= length_limit { - stopped_early = true; - break 'outer; - } - - push(&mut s, &mut text_length, word); + let r = + text.split_inclusive(char::is_whitespace).try_for_each(|word| buf.push(word)); + if r.is_break() { + stopped_early = true; } + return r; } Event::Code(code) => { - if text_length + code.len() >= length_limit { + buf.open_tag("code"); + let r = buf.push(code); + if r.is_break() { stopped_early = true; - break; + } else { + buf.close_tag(); } - - s.push_str(""); - push(&mut s, &mut text_length, code); - s.push_str(""); + return r; } Event::Start(tag) => match tag { - Tag::Emphasis => s.push_str(""), - Tag::Strong => s.push_str(""), - Tag::CodeBlock(..) => break, + Tag::Emphasis => buf.open_tag("em"), + Tag::Strong => buf.open_tag("strong"), + Tag::CodeBlock(..) => return ControlFlow::BREAK, _ => {} }, Event::End(tag) => match tag { - Tag::Emphasis => s.push_str(""), - Tag::Strong => s.push_str(""), - Tag::Paragraph => break, - Tag::Heading(..) => break, + Tag::Emphasis | Tag::Strong => buf.close_tag(), + Tag::Paragraph | Tag::Heading(..) => return ControlFlow::BREAK, _ => {} }, - Event::HardBreak | Event::SoftBreak => { - if text_length + 1 >= length_limit { - stopped_early = true; - break; - } - - push(&mut s, &mut text_length, " "); - } + Event::HardBreak | Event::SoftBreak => buf.push(" ")?, _ => {} - } - } + }; + ControlFlow::CONTINUE + }); - (s, stopped_early) + (buf.finish(), stopped_early) } /// Renders a shortened first paragraph of the given Markdown as a subset of Markdown, diff --git a/src/librustdoc/html/mod.rs b/src/librustdoc/html/mod.rs index 60ebdf5690d0..109b0a356db5 100644 --- a/src/librustdoc/html/mod.rs +++ b/src/librustdoc/html/mod.rs @@ -2,6 +2,7 @@ crate mod escape; crate mod format; crate mod highlight; crate mod layout; +mod length_limit; // used by the error-index generator, so it needs to be public pub mod markdown; crate mod render; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e02d92b11b84..ab94e0d56835 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -5,6 +5,7 @@ #![feature(rustc_private)] #![feature(array_methods)] #![feature(box_patterns)] +#![feature(control_flow_enum)] #![feature(in_band_lifetimes)] #![feature(nll)] #![feature(test)] From 09f0876dc63bb386bc07d182b1bf85afb61f7db6 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 12:39:17 -0700 Subject: [PATCH 032/269] Clarify wording in docs --- src/librustdoc/html/length_limit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 42b94b511181..91e098979acf 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -10,7 +10,7 @@ use crate::html::escape::Escape; /// This buffer ensures that: /// /// * all tags are closed, -/// * only the most recently opened tag is closed, +/// * tags are closed in the reverse order of when they were opened (i.e., the correct HTML order), /// * no tags are left empty (e.g., ``) due to the length limit being reached, /// * all text is escaped. #[derive(Debug)] From 65bfc3130a782464d301c85b3edcbed5732b8a52 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Aug 2021 15:09:03 -0700 Subject: [PATCH 033/269] Remove the `TryV2` alias Post-bootstrap-update cleanup. --- library/core/src/iter/traits/iterator.rs | 4 ++-- library/core/src/ops/control_flow.rs | 4 ++-- library/core/src/ops/mod.rs | 8 +------- library/core/src/option.rs | 2 +- library/core/src/result.rs | 2 +- library/core/src/task/poll.rs | 4 ++-- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 524d8f857e2a..75987d18fe00 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2442,14 +2442,14 @@ pub trait Iterator { R: Try, // FIXME: This bound is rather strange, but means minimal breakage on nightly. // See #85115 for the issue tracking a holistic solution for this and try_map. - R: crate::ops::TryV2>, + R: Try>, { #[inline] fn check(mut f: F) -> impl FnMut((), T) -> ControlFlow> where F: FnMut(&T) -> R, R: Try, - R: crate::ops::TryV2>, + R: Try>, { move |(), x| match f(&x).branch() { ControlFlow::Continue(false) => ControlFlow::CONTINUE, diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index c2270c864dfa..cd2d57699c92 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -63,7 +63,7 @@ pub enum ControlFlow { } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::TryV2 for ControlFlow { +impl ops::Try for ControlFlow { type Output = C; type Residual = ControlFlow; @@ -165,7 +165,7 @@ impl ControlFlow { /// These are used only as part of implementing the iterator adapters. /// They have mediocre names and non-obvious semantics, so aren't /// currently on a path to potential stabilization. -impl ControlFlow { +impl ControlFlow { /// Create a `ControlFlow` from any type implementing `Try`. #[inline] pub(crate) fn from_try(r: R) -> Self { diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 85e04740d96a..bd7feb8b183c 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -182,13 +182,7 @@ pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; pub use self::range::{Bound, RangeBounds, RangeInclusive, RangeToInclusive}; #[unstable(feature = "try_trait_v2", issue = "84277")] -pub use self::try_trait::FromResidual; - -#[unstable(feature = "try_trait_v2", issue = "84277")] -pub use self::try_trait::Try; - -#[unstable(feature = "try_trait_transition", reason = "for bootstrap", issue = "none")] -pub(crate) use self::try_trait::Try as TryV2; +pub use self::try_trait::{FromResidual, Try}; #[unstable(feature = "generator_trait", issue = "43122")] pub use self::generator::{Generator, GeneratorState}; diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 78f5954532ff..47865240f6a6 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2013,7 +2013,7 @@ impl> FromIterator> for Option { } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::TryV2 for Option { +impl ops::Try for Option { type Output = T; type Residual = Option; diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 861790e8a409..092e6544342b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1889,7 +1889,7 @@ impl> FromIterator> for Result { } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::TryV2 for Result { +impl ops::Try for Result { type Output = T; type Residual = Result; diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index fc0a4e747973..250704609963 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -222,7 +222,7 @@ impl From for Poll { } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::TryV2 for Poll> { +impl ops::Try for Poll> { type Output = Poll; type Residual = Result; @@ -252,7 +252,7 @@ impl> ops::FromResidual> for Pol } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::TryV2 for Poll>> { +impl ops::Try for Poll>> { type Output = Poll>; type Residual = Result; From f1e860757e9494c82450c100a9ce5240858b537b Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 21 Aug 2021 23:40:02 +0100 Subject: [PATCH 034/269] Don't stabilize creation of TryReserveError instances --- library/alloc/src/collections/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index 0d442011921b..4e31df8b4b8c 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -117,12 +117,12 @@ impl From for TryReserveError { } } -#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] -impl From for TryReserveError { +#[unstable(feature = "try_reserve_kind", reason = "new API", issue = "48043")] +impl From for TryReserveErrorKind { /// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`]. #[inline] fn from(_: LayoutError) -> Self { - TryReserveErrorKind::CapacityOverflow.into() + TryReserveErrorKind::CapacityOverflow } } From d0b482a27c1a347eac366bde82340e527c6cecf8 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:13:25 -0700 Subject: [PATCH 035/269] Add more tuple pattern too many fields test cases --- src/test/ui/pattern/pat-tuple-overfield.rs | 42 ++++ .../ui/pattern/pat-tuple-overfield.stderr | 222 +++++++++++++++++- 2 files changed, 258 insertions(+), 6 deletions(-) diff --git a/src/test/ui/pattern/pat-tuple-overfield.rs b/src/test/ui/pattern/pat-tuple-overfield.rs index 46a5e15ffa52..dd0548a088c7 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.rs +++ b/src/test/ui/pattern/pat-tuple-overfield.rs @@ -1,4 +1,18 @@ struct S(u8, u8, u8); +struct M( + u8, + u8, + u8, + u8, + u8, +); + +struct Z0; +struct Z1(); +enum E1 { + Z0, + Z1(), +} fn main() { match (1, 2, 3) { @@ -13,4 +27,32 @@ fn main() { //~^ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields _ => {} } + match M(1, 2, 3, 4, 5) { + M(1, 2, 3, 4, 5, 6) => {} + //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + } + match Z0 { + Z0 => {} + Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + } + match Z1() { + Z1 => {} //~ ERROR match bindings cannot shadow tuple structs + Z1() => {} + Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields + Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 0 fields + } + match E1::Z0 { + E1::Z0 => {} + E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + } + match E1::Z1() { + E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + E1::Z1() => {} + E1::Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields + E1::Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 0 fields + } } diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index e0386d9cd4ff..cc4ca4326ecc 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,154 @@ +error[E0530]: match bindings cannot shadow tuple structs + --> $DIR/pat-tuple-overfield.rs:43:9 + | +LL | struct Z1(); + | ------------ the tuple struct `Z1` is defined here +... +LL | Z1 => {} + | ^^ cannot be named the same as a tuple struct + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:38:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0() => {} + | ^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:39:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0(_) => {} + | ^^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(_) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:40:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0(_, _) => {} + | ^^^^^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(_, _) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:50:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0() => {} + | ^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:51:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0(_) => {} + | ^^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(_) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:52:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0(_, _) => {} + | ^^^^^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(_, _) => {} + | ~~ + +error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + --> $DIR/pat-tuple-overfield.rs:55:9 + | +LL | Z0, + | -- similarly named unit variant `Z0` defined here +LL | Z1(), + | ---- `E1::Z1` defined here +... +LL | E1::Z1 => {} + | ^^^^^^ + | +help: use the tuple variant pattern syntax instead + | +LL | E1::Z1() => {} + | ~~~~~~~~ +help: a unit variant with a similar name exists + | +LL | E1::Z0 => {} + | ~~ + error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:5:9 + --> $DIR/pat-tuple-overfield.rs:21:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -10,7 +159,7 @@ LL | (1, 2, 3, 4) => {} found tuple `(_, _, _, _)` error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:6:9 + --> $DIR/pat-tuple-overfield.rs:22:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -22,7 +171,7 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:10:10 + --> $DIR/pat-tuple-overfield.rs:26:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here @@ -33,7 +182,7 @@ LL | S(1, 2, 3, 4) => {} | this tuple struct error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:12:10 + --> $DIR/pat-tuple-overfield.rs:28:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here @@ -43,7 +192,68 @@ LL | S(1, 2, .., 3, 4) => {} | | | this tuple struct -error: aborting due to 4 previous errors +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:33:10 + | +LL | / struct M( +LL | | u8, +LL | | u8, +LL | | u8, +LL | | u8, +LL | | u8, +LL | | ); + | |__- tuple struct defined here +... +LL | M(1, 2, 3, 4, 5, 6) => {} + | -^^^^^^^^^^^^^^^^^^ expected 5 fields, found 6 + | | + | this tuple struct + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-overfield.rs:45:11 + | +LL | struct Z1(); + | ------------ tuple struct defined here +... +LL | Z1(_) => {} + | --^^^ expected 0 fields, found 1 + | | + | this tuple struct + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-overfield.rs:46:11 + | +LL | struct Z1(); + | ------------ tuple struct defined here +... +LL | Z1(_, _) => {} + | --^^^^^^ expected 0 fields, found 2 + | | + | this tuple struct + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-overfield.rs:57:15 + | +LL | Z1(), + | ---- tuple variant defined here +... +LL | E1::Z1(_) => {} + | ------^^^ expected 0 fields, found 1 + | | + | this tuple variant + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-overfield.rs:58:15 + | +LL | Z1(), + | ---- tuple variant defined here +... +LL | E1::Z1(_, _) => {} + | ------^^^^^^ expected 0 fields, found 2 + | | + | this tuple variant + +error: aborting due to 17 previous errors -Some errors have detailed explanations: E0023, E0308. +Some errors have detailed explanations: E0023, E0308, E0530, E0532. For more information about an error, try `rustc --explain E0023`. From 0fa3b4f940b4705dc5a1089e917f521b093fd0bc Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:13:52 -0700 Subject: [PATCH 036/269] Make E0023 spans even more precise --- compiler/rustc_ty_utils/src/ty.rs | 13 +++- compiler/rustc_typeck/src/check/pat.rs | 39 ++++++++-- .../tuple_struct_destructure_fail.stderr | 32 +++----- src/test/ui/error-codes/E0023.stderr | 36 ++++----- src/test/ui/issues/issue-72574-2.stderr | 8 +- .../match/match-pattern-field-mismatch.stderr | 8 +- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 4 +- src/test/ui/pattern/issue-74539.stderr | 8 +- .../ui/pattern/pat-tuple-overfield.stderr | 78 ++++++++----------- .../ui/pattern/pat-tuple-underfield.stderr | 48 ++++-------- .../ui/pattern/pattern-error-continue.stderr | 8 +- 11 files changed, 132 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index b0d644ae028c..7a6ace070dee 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -223,7 +223,18 @@ fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems<'_> { } fn def_ident_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option { - tcx.hir().get_if_local(def_id).and_then(|node| node.ident()).map(|ident| ident.span) + tcx.hir() + .get_if_local(def_id) + .and_then(|node| match node { + // A `Ctor` doesn't have an identifier itself, but its parent + // struct/variant does. Compare with `hir::Map::opt_span`. + hir::Node::Ctor(ctor) => ctor + .ctor_hir_id() + .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) + .and_then(|parent| parent.ident()), + _ => node.ident(), + }) + .map(|ident| ident.span) } /// If the given `DefId` describes an item belonging to a trait, diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 2ef79c7686c5..341385731e7d 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -15,7 +15,7 @@ use rustc_span::hygiene::DesugaringKind; use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::{Span, Spanned}; use rustc_span::symbol::Ident; -use rustc_span::{BytePos, DUMMY_SP}; +use rustc_span::{BytePos, MultiSpan, DUMMY_SP}; use rustc_trait_selection::autoderef::Autoderef; use rustc_trait_selection::traits::{ObligationCause, Pattern}; use ty::VariantDef; @@ -990,11 +990,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let subpats_ending = pluralize!(subpats.len()); let fields_ending = pluralize!(fields.len()); - let fields_span = pat_span.trim_start(qpath.span()).unwrap_or(pat_span); + + let subpat_spans = if subpats.is_empty() { + vec![pat_span.trim_start(qpath.span()).unwrap_or(pat_span)] + } else { + subpats.iter().map(|p| p.span).collect() + }; + let last_subpat_span = *subpat_spans.last().unwrap(); let res_span = self.tcx.def_span(res.def_id()); + let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span); + let field_def_spans = if fields.is_empty() { + vec![res_span.trim_start(def_ident_span).unwrap_or(res_span)] + } else { + fields.iter().map(|f| f.ident.span).collect() + }; + let last_field_def_span = *field_def_spans.last().unwrap(); + let mut err = struct_span_err!( self.tcx.sess, - fields_span, + MultiSpan::from_spans(subpat_spans.clone()), E0023, "this pattern has {} field{}, but the corresponding {} has {} field{}", subpats.len(), @@ -1004,11 +1018,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields_ending, ); err.span_label( - fields_span, - format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len(),), - ) - .span_label(qpath.span(), format!("this {}", res.descr())) - .span_label(res_span, format!("{} defined here", res.descr())); + last_subpat_span, + &format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()), + ); + err.span_label(qpath.span(), ""); + if self.tcx.sess.source_map().is_multiline(def_ident_span.between(field_def_spans[0])) { + err.span_label(def_ident_span, format!("{} defined here", res.descr())); + } + for span in &field_def_spans[..field_def_spans.len() - 1] { + err.span_label(*span, ""); + } + err.span_label( + last_field_def_span, + &format!("{} has {} field{}", res.descr(), fields.len(), fields_ending), + ); // Identify the case `Some(x, y)` where the expected type is e.g. `Option<(T, U)>`. // More generally, the expected type wants a tuple variant with one field of an diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index ec7d76f4fe52..9a47ddf04799 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -15,26 +15,22 @@ LL | Enum::SingleVariant(a, .., b, ..) = Enum::SingleVariant(0, 1); | previously used here error[E0023]: this pattern has 3 fields, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:30:16 + --> $DIR/tuple_struct_destructure_fail.rs:30:17 | LL | struct TupleStruct(S, T); - | ------------------------------- tuple struct defined here + | - - tuple struct has 2 fields ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | -----------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple struct + | ----------- ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:32:16 + --> $DIR/tuple_struct_destructure_fail.rs:32:17 | LL | struct TupleStruct(S, T); - | ------------------------------- tuple struct defined here + | - - tuple struct has 2 fields ... LL | TupleStruct(_) = TupleStruct(1, 2); - | -----------^^^ expected 2 fields, found 1 - | | - | this tuple struct + | ----------- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -46,26 +42,22 @@ LL | TupleStruct(..) = TupleStruct(1, 2); | ~~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:34:24 + --> $DIR/tuple_struct_destructure_fail.rs:34:25 | LL | SingleVariant(S, T) - | ------------------- tuple variant defined here + | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | -------------------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ------------------- ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:36:24 + --> $DIR/tuple_struct_destructure_fail.rs:36:25 | LL | SingleVariant(S, T) - | ------------------- tuple variant defined here + | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | -------------------^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ------------------- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index ecc075b6fb4b..85e1b2cb4cee 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -1,13 +1,11 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:11:21 + --> $DIR/E0023.rs:11:22 | LL | Apple(String, String), - | --------------------- tuple variant defined here + | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a) => {}, - | ------------^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ------------ ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -15,37 +13,31 @@ LL | Fruit::Apple(a, _) => {}, | +++ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:12:21 + --> $DIR/E0023.rs:12:22 | LL | Apple(String, String), - | --------------------- tuple variant defined here + | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a, b, c) => {}, - | ------------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ------------ ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:13:20 + --> $DIR/E0023.rs:13:21 | LL | Pear(u32), - | --------- tuple variant defined here + | --- tuple variant has 1 field ... LL | Fruit::Pear(1, 2) => {}, - | -----------^^^^^^ expected 1 field, found 2 - | | - | this tuple variant + | ----------- ^ ^ expected 1 field, found 2 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:14:22 + --> $DIR/E0023.rs:14:23 | LL | Orange((String, String)), - | ------------------------ tuple variant defined here + | ---------------- tuple variant has 1 field ... LL | Fruit::Orange(a, b) => {}, - | -------------^^^^^^ expected 1 field, found 2 - | | - | this tuple variant + | ------------- ^ ^ expected 1 field, found 2 | help: missing parentheses | @@ -56,12 +48,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has --> $DIR/E0023.rs:15:22 | LL | Banana(()), - | ---------- tuple variant defined here + | -- tuple variant has 1 field ... LL | Fruit::Banana() => {}, | -------------^^ expected 1 field, found 0 - | | - | this tuple variant | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 4c38d2c31ed6..3f8ff4f0bacd 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -19,15 +19,13 @@ LL | Binder(_a, _x @ ..) => {} = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields - --> $DIR/issue-72574-2.rs:6:15 + --> $DIR/issue-72574-2.rs:6:16 | LL | struct Binder(i32, i32, i32); - | ----------------------------- tuple struct defined here + | --- --- --- tuple struct has 3 fields ... LL | Binder(_a, _x @ ..) => {} - | ------^^^^^^^^^^^^^ expected 3 fields, found 2 - | | - | this tuple struct + | ------ ^^ ^^^^^^^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index 776cdfc7083b..01d7cf0d054c 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -1,13 +1,11 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields - --> $DIR/match-pattern-field-mismatch.rs:10:21 + --> $DIR/match-pattern-field-mismatch.rs:10:22 | LL | Rgb(usize, usize, usize), - | ------------------------ tuple variant defined here + | ----- ----- ----- tuple variant has 3 fields ... LL | Color::Rgb(_, _) => { } - | ----------^^^^^^ expected 3 fields, found 2 - | | - | this tuple variant + | ---------- ^ ^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index ea5f970d1d65..c87b70625b40 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -13,12 +13,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 | LL | struct P(T); // 1 type parameter wanted - | --------------- tuple struct defined here + | - tuple struct has 1 field ... LL | let P() = U {}; | -^^ expected 1 field, found 0 - | | - | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index 87c3842d28f4..d7cbcf2cfa10 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -19,15 +19,13 @@ LL | E::A(x @ ..) => { = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/issue-74539.rs:8:13 + --> $DIR/issue-74539.rs:8:14 | LL | A(u8, u8), - | --------- tuple variant defined here + | -- -- tuple variant has 2 fields ... LL | E::A(x @ ..) => { - | ----^^^^^^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^^^^^^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index cc4ca4326ecc..1df9c1c11b8a 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -171,87 +171,77 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:26:10 + --> $DIR/pat-tuple-overfield.rs:26:11 | LL | struct S(u8, u8, u8); - | --------------------- tuple struct defined here + | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, 3, 4) => {} - | -^^^^^^^^^^^^ expected 3 fields, found 4 - | | - | this tuple struct + | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:28:10 + --> $DIR/pat-tuple-overfield.rs:28:11 | LL | struct S(u8, u8, u8); - | --------------------- tuple struct defined here + | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, .., 3, 4) => {} - | -^^^^^^^^^^^^^^^^ expected 3 fields, found 4 - | | - | this tuple struct + | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields - --> $DIR/pat-tuple-overfield.rs:33:10 - | -LL | / struct M( -LL | | u8, -LL | | u8, -LL | | u8, -LL | | u8, -LL | | u8, -LL | | ); - | |__- tuple struct defined here + --> $DIR/pat-tuple-overfield.rs:33:11 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields ... -LL | M(1, 2, 3, 4, 5, 6) => {} - | -^^^^^^^^^^^^^^^^^^ expected 5 fields, found 6 - | | - | this tuple struct +LL | M(1, 2, 3, 4, 5, 6) => {} + | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:45:11 + --> $DIR/pat-tuple-overfield.rs:45:12 | LL | struct Z1(); - | ------------ tuple struct defined here + | --- tuple struct has 0 fields ... LL | Z1(_) => {} - | --^^^ expected 0 fields, found 1 - | | - | this tuple struct + | -- ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:46:11 + --> $DIR/pat-tuple-overfield.rs:46:12 | LL | struct Z1(); - | ------------ tuple struct defined here + | --- tuple struct has 0 fields ... LL | Z1(_, _) => {} - | --^^^^^^ expected 0 fields, found 2 - | | - | this tuple struct + | -- ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:57:15 + --> $DIR/pat-tuple-overfield.rs:57:16 | LL | Z1(), - | ---- tuple variant defined here + | -- tuple variant has 0 fields ... LL | E1::Z1(_) => {} - | ------^^^ expected 0 fields, found 1 - | | - | this tuple variant + | ------ ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:58:15 + --> $DIR/pat-tuple-overfield.rs:58:16 | LL | Z1(), - | ---- tuple variant defined here + | -- tuple variant has 0 fields ... LL | E1::Z1(_, _) => {} - | ------^^^^^^ expected 0 fields, found 2 - | | - | this tuple variant + | ------ ^ ^ expected 0 fields, found 2 error: aborting due to 17 previous errors diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 4cc20a4ac0ef..4c21ad0be3eb 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -8,15 +8,13 @@ LL | E::S => {} | ^^^^ help: use the tuple variant pattern syntax instead: `E::S(_, _)` error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:9:10 + --> $DIR/pat-tuple-underfield.rs:9:11 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S(x) => {} - | -^^^ expected 2 fields, found 1 - | | - | this tuple struct + | - ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -24,15 +22,13 @@ LL | S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:14:10 + --> $DIR/pat-tuple-underfield.rs:14:11 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S(_) => {} - | -^^^ expected 2 fields, found 1 - | | - | this tuple struct + | - ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -47,12 +43,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-underfield.rs:20:10 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S() => {} | -^^ expected 2 fields, found 0 - | | - | this tuple struct | help: use `_` to explicitly ignore each field | @@ -64,15 +58,13 @@ LL | S(..) => {} | ++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:13 + --> $DIR/pat-tuple-underfield.rs:27:14 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S(x) => {} - | ----^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -80,15 +72,13 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:13 + --> $DIR/pat-tuple-underfield.rs:32:14 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S(_) => {} - | ----^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -103,12 +93,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-underfield.rs:38:13 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S() => {} | ----^^ expected 2 fields, found 0 - | | - | this tuple variant | help: use `_` to explicitly ignore each field | @@ -120,15 +108,13 @@ LL | E::S(..) => {} | ++ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:15 + --> $DIR/pat-tuple-underfield.rs:50:19 | LL | struct Point4(i32, i32, i32, i32); - | ---------------------------------- tuple struct defined here + | --- --- --- --- tuple struct has 4 fields ... LL | Point4( a , _ ) => {} - | ------^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 - | | - | this tuple struct + | ------ ^ ^ expected 4 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index 216c3ca47d39..efc6723e9ef8 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -26,15 +26,13 @@ LL | A::B(_) => (), | ~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pattern-error-continue.rs:17:13 + --> $DIR/pattern-error-continue.rs:17:14 | LL | B(isize, isize), - | --------------- tuple variant defined here + | ----- ----- tuple variant has 2 fields ... LL | A::B(_, _, _) => (), - | ----^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ---- ^ ^ ^ expected 2 fields, found 3 error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From 02ed23c0318da7f1125f01b5437ae9e809587f0c Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:09:52 -0700 Subject: [PATCH 037/269] Use an exhaustive match in `Node::ident()` and add docs This should cause a compiler error in the future if more variants are added without `Node::ident()` being updated. --- compiler/rustc_hir/src/hir.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 4e233ed14577..dd5dfe978a47 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3182,6 +3182,20 @@ pub enum Node<'hir> { } impl<'hir> Node<'hir> { + /// Get the identifier of this `Node`, if applicable. + /// + /// # Edge cases + /// + /// Calling `.ident()` on a [`Node::Ctor`] will return `None` + /// because `Ctor`s do not have identifiers themselves. + /// Instead, call `.ident()` on the parent struct/variant, like so: + /// + /// ```ignore (illustrative) + /// ctor + /// .ctor_hir_id() + /// .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) + /// .and_then(|parent| parent.ident()) + /// ``` pub fn ident(&self) -> Option { match self { Node::TraitItem(TraitItem { ident, .. }) @@ -3190,8 +3204,25 @@ impl<'hir> Node<'hir> { | Node::Field(FieldDef { ident, .. }) | Node::Variant(Variant { ident, .. }) | Node::MacroDef(MacroDef { ident, .. }) - | Node::Item(Item { ident, .. }) => Some(*ident), - _ => None, + | Node::Item(Item { ident, .. }) + | Node::PathSegment(PathSegment { ident, .. }) => Some(*ident), + Node::Lifetime(lt) => Some(lt.name.ident()), + Node::GenericParam(p) => Some(p.name.ident()), + Node::Param(..) + | Node::AnonConst(..) + | Node::Expr(..) + | Node::Stmt(..) + | Node::Block(..) + | Node::Ctor(..) + | Node::Pat(..) + | Node::Binding(..) + | Node::Arm(..) + | Node::Local(..) + | Node::Visibility(..) + | Node::Crate(..) + | Node::Ty(..) + | Node::TraitRef(..) + | Node::Infer(..) => None, } } From 08ceac8ee3d740c48e6bb250de0798fcbe0824f4 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 12:29:11 -0700 Subject: [PATCH 038/269] Add cross-crate tuple field count error test --- ...clarations-for-tuple-field-count-errors.rs | 20 + .../ui/pattern/pat-tuple-field-count-cross.rs | 57 ++ .../pat-tuple-field-count-cross.stderr | 536 ++++++++++++++++++ 3 files changed, 613 insertions(+) create mode 100644 src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs create mode 100644 src/test/ui/pattern/pat-tuple-field-count-cross.rs create mode 100644 src/test/ui/pattern/pat-tuple-field-count-cross.stderr diff --git a/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs b/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs new file mode 100644 index 000000000000..f7373c453966 --- /dev/null +++ b/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs @@ -0,0 +1,20 @@ +pub struct Z0; +pub struct Z1(); + +pub struct S(pub u8, pub u8, pub u8); +pub struct M( + pub u8, + pub u8, + pub u8, +); + +pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + +pub enum E2 { + S(u8, u8, u8), + M( + u8, + u8, + u8, + ), +} diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.rs b/src/test/ui/pattern/pat-tuple-field-count-cross.rs new file mode 100644 index 000000000000..b63da4e154f7 --- /dev/null +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.rs @@ -0,0 +1,57 @@ +// aux-build:declarations-for-tuple-field-count-errors.rs + +extern crate declarations_for_tuple_field_count_errors; + +use declarations_for_tuple_field_count_errors::*; + +fn main() { + match Z0 { + Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + } + match Z1() { + Z1 => {} //~ ERROR match bindings cannot shadow tuple structs + Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields + } + + match S(1, 2, 3) { + S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields + S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields + S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields + S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields + } + match M(1, 2, 3) { + M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields + M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields + M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields + M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields + } + + match E1::Z0 { + E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + } + match E1::Z1() { + E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + E1::Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields + } + match E1::S(1, 2, 3) { + E1::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E1::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E1::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E1::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } + + match E2::S(1, 2, 3) { + E2::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E2::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E2::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E2::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } + match E2::M(1, 2, 3) { + E2::M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E2::M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E2::M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E2::M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } +} diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr new file mode 100644 index 000000000000..570bf0cbc081 --- /dev/null +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr @@ -0,0 +1,536 @@ +error[E0530]: match bindings cannot shadow tuple structs + --> $DIR/pat-tuple-field-count-cross.rs:13:9 + | +LL | use declarations_for_tuple_field_count_errors::*; + | -------------------------------------------- the tuple struct `Z1` is imported here +... +LL | Z1 => {} + | ^^ cannot be named the same as a tuple struct + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-field-count-cross.rs:9:9 + | +LL | Z0() => {} + | ^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:1:1 + | +LL | pub struct Z0; + | -------------- `Z0` defined here +LL | pub struct Z1(); + | ---------------- similarly named tuple struct `Z1` defined here + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-field-count-cross.rs:10:9 + | +LL | Z0(x) => {} + | ^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:1:1 + | +LL | pub struct Z0; + | -------------- `Z0` defined here +LL | pub struct Z1(); + | ---------------- similarly named tuple struct `Z1` defined here + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(x) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-field-count-cross.rs:31:9 + | +LL | E1::Z0() => {} + | ^^^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- similarly named tuple variant `Z1` defined here + | | + | `E1::Z0` defined here + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-field-count-cross.rs:32:9 + | +LL | E1::Z0(x) => {} + | ^^^^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- similarly named tuple variant `Z1` defined here + | | + | `E1::Z0` defined here + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(x) => {} + | ~~ + +error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + --> $DIR/pat-tuple-field-count-cross.rs:35:9 + | +LL | E1::Z1 => {} + | ^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- `E1::Z1` defined here + | | + | similarly named unit variant `Z0` defined here + | +help: use the tuple variant pattern syntax instead + | +LL | E1::Z1(/* fields */) => {} + | ~~~~~~~~~~~~~~~~~~~~ +help: a unit variant with a similar name exists + | +LL | E1::Z0 => {} + | ~~ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-field-count-cross.rs:14:12 + | +LL | Z1(x) => {} + | -- ^ expected 0 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:2:1 + | +LL | pub struct Z1(); + | ---------------- tuple struct has 0 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:18:10 + | +LL | S() => {} + | -^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:19:11 + | +LL | S(1) => {} + | - ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:20:11 + | +LL | S(xyz, abc) => {} + | - ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:21:11 + | +LL | S(1, 2, 3, 4) => {} + | - ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:24:10 + | +LL | M() => {} + | -^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | M(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:25:11 + | +LL | M(1) => {} + | - ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | M(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:26:11 + | +LL | M(xyz, abc) => {} + | - ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:27:11 + | +LL | M(1, 2, 3, 4) => {} + | - ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-field-count-cross.rs:36:16 + | +LL | E1::Z1(x) => {} + | ------ ^ expected 0 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | ---- tuple variant has 0 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:39:14 + | +LL | E1::S() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E1::S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:40:15 + | +LL | E1::S(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E1::S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:41:15 + | +LL | E1::S(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:42:15 + | +LL | E1::S(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:46:14 + | +LL | E2::S() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E2::S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:47:15 + | +LL | E2::S(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E2::S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:48:15 + | +LL | E2::S(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:49:15 + | +LL | E2::S(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:52:14 + | +LL | E2::M() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E2::M(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:53:15 + | +LL | E2::M(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E2::M(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:54:15 + | +LL | E2::M(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:55:15 + | +LL | E2::M(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + +error: aborting due to 28 previous errors + +Some errors have detailed explanations: E0023, E0530, E0532. +For more information about an error, try `rustc --explain E0023`. From 74147b86c50ebdaa7d8420fcbf82fa647a6db394 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 16:58:29 -0700 Subject: [PATCH 039/269] Use the length limit as the initial capacity The length limit turns out to be a surprisingly good heuristic for initial allocation size. See here for more details [1]. [1]: https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 --- src/librustdoc/html/length_limit.rs | 12 +++++++++++- src/librustdoc/html/markdown.rs | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 91e098979acf..cc4a7f37fe9a 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -29,8 +29,18 @@ pub(super) struct HtmlWithLimit { impl HtmlWithLimit { /// Create a new buffer, with a limit of `length_limit`. pub(super) fn new(length_limit: usize) -> Self { + let buf = if length_limit > 1000 { + // If the length limit is really large, don't preallocate tons of memory. + String::new() + } else { + // The length limit is actually a good heuristic for initial allocation size. + // Measurements showed that using it as the initial capacity ended up using less memory + // than `String::new`. + // See https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 for more. + String::with_capacity(length_limit) + }; Self { - buf: String::new(), + buf, len: 0, limit: length_limit, unclosed_tags: Vec::new(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5a569c690e54..b2ca13499818 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1096,7 +1096,6 @@ fn markdown_summary_with_limit( let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); let mut p = LinkReplacer::new(p, link_names); - // FIXME: capacity let mut buf = HtmlWithLimit::new(length_limit); let mut stopped_early = false; p.try_for_each(|event| { From d18936a731fa1d2bf49073bd0f059129ef1b0ef1 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 17:24:49 -0700 Subject: [PATCH 040/269] Use `write!` --- src/librustdoc/html/length_limit.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index cc4a7f37fe9a..2b47033744fd 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -79,17 +79,13 @@ impl HtmlWithLimit { /// Close the most recently opened HTML tag. pub(super) fn close_tag(&mut self) { let tag_name = self.unclosed_tags.pop().unwrap(); - self.buf.push_str("'); + write!(self.buf, "", tag_name).unwrap(); } /// Write all queued tags and add them to the `unclosed_tags` list. fn flush_queue(&mut self) { for tag_name in self.queued_tags.drain(..) { - self.buf.push('<'); - self.buf.push_str(tag_name); - self.buf.push('>'); + write!(self.buf, "<{}>", tag_name).unwrap(); self.unclosed_tags.push(tag_name); } From 19f45101e72ed6880b0fd1ebee73d74ea782c8c4 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 18:41:34 -0700 Subject: [PATCH 041/269] Bless tests --- .../ui/pattern/pat-tuple-overfield.stderr | 34 +++++++++---------- ...priority-higher-than-other-inherent.stderr | 6 ++++ .../ui/typeck/struct-enum-wrong-args.stderr | 30 ++++++++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 1df9c1c11b8a..646ac4e66189 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow tuple structs - --> $DIR/pat-tuple-overfield.rs:43:9 + --> $DIR/pat-tuple-overfield.rs:41:9 | LL | struct Z1(); | ------------ the tuple struct `Z1` is defined here @@ -8,7 +8,7 @@ LL | Z1 => {} | ^^ cannot be named the same as a tuple struct error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:38:9 + --> $DIR/pat-tuple-overfield.rs:36:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -28,7 +28,7 @@ LL | Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:39:9 + --> $DIR/pat-tuple-overfield.rs:37:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -48,7 +48,7 @@ LL | Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:40:9 + --> $DIR/pat-tuple-overfield.rs:38:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -68,7 +68,7 @@ LL | Z1(_, _) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:50:9 + --> $DIR/pat-tuple-overfield.rs:48:9 | LL | Z0, | -- `E1::Z0` defined here @@ -88,7 +88,7 @@ LL | E1::Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:51:9 + --> $DIR/pat-tuple-overfield.rs:49:9 | LL | Z0, | -- `E1::Z0` defined here @@ -108,7 +108,7 @@ LL | E1::Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:52:9 + --> $DIR/pat-tuple-overfield.rs:50:9 | LL | Z0, | -- `E1::Z0` defined here @@ -128,7 +128,7 @@ LL | E1::Z1(_, _) => {} | ~~ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` - --> $DIR/pat-tuple-overfield.rs:55:9 + --> $DIR/pat-tuple-overfield.rs:53:9 | LL | Z0, | -- similarly named unit variant `Z0` defined here @@ -148,7 +148,7 @@ LL | E1::Z0 => {} | ~~ error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:21:9 + --> $DIR/pat-tuple-overfield.rs:19:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -159,7 +159,7 @@ LL | (1, 2, 3, 4) => {} found tuple `(_, _, _, _)` error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:22:9 + --> $DIR/pat-tuple-overfield.rs:20:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -171,7 +171,7 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:26:11 + --> $DIR/pat-tuple-overfield.rs:24:11 | LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields @@ -180,7 +180,7 @@ LL | S(1, 2, 3, 4) => {} | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:28:11 + --> $DIR/pat-tuple-overfield.rs:26:11 | LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields @@ -189,7 +189,7 @@ LL | S(1, 2, .., 3, 4) => {} | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields - --> $DIR/pat-tuple-overfield.rs:33:11 + --> $DIR/pat-tuple-overfield.rs:31:11 | LL | struct M( | - tuple struct defined here @@ -208,7 +208,7 @@ LL | M(1, 2, 3, 4, 5, 6) => {} | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:45:12 + --> $DIR/pat-tuple-overfield.rs:43:12 | LL | struct Z1(); | --- tuple struct has 0 fields @@ -217,7 +217,7 @@ LL | Z1(_) => {} | -- ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:46:12 + --> $DIR/pat-tuple-overfield.rs:44:12 | LL | struct Z1(); | --- tuple struct has 0 fields @@ -226,7 +226,7 @@ LL | Z1(_, _) => {} | -- ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:57:16 + --> $DIR/pat-tuple-overfield.rs:55:16 | LL | Z1(), | -- tuple variant has 0 fields @@ -235,7 +235,7 @@ LL | E1::Z1(_) => {} | ------ ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:58:16 + --> $DIR/pat-tuple-overfield.rs:56:16 | LL | Z1(), | -- tuple variant has 0 fields diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr index 1d520613a288..37543c137f66 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr @@ -5,6 +5,12 @@ LL | ::V(); | ^^^^^^-- supplied 0 arguments | | | expected 1 argument + | +note: tuple variant defined here + --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:5:5 + | +LL | V(u8) + | ^ error[E0308]: mismatched types --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:22:17 diff --git a/src/test/ui/typeck/struct-enum-wrong-args.stderr b/src/test/ui/typeck/struct-enum-wrong-args.stderr index d77ef73028b0..6e99feed33f9 100644 --- a/src/test/ui/typeck/struct-enum-wrong-args.stderr +++ b/src/test/ui/typeck/struct-enum-wrong-args.stderr @@ -29,6 +29,12 @@ LL | let _ = Wrapper(); | ^^^^^^^-- supplied 0 arguments | | | expected 1 argument + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ error[E0061]: this struct takes 1 argument but 2 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:10:13 @@ -37,6 +43,12 @@ LL | let _ = Wrapper(5, 2); | ^^^^^^^ - - supplied 2 arguments | | | expected 1 argument + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ error[E0061]: this struct takes 2 arguments but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:11:13 @@ -45,6 +57,12 @@ LL | let _ = DoubleWrapper(); | ^^^^^^^^^^^^^-- supplied 0 arguments | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error[E0061]: this struct takes 2 arguments but 1 argument was supplied --> $DIR/struct-enum-wrong-args.rs:12:13 @@ -53,6 +71,12 @@ LL | let _ = DoubleWrapper(5); | ^^^^^^^^^^^^^ - supplied 1 argument | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error[E0061]: this struct takes 2 arguments but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:13:13 @@ -61,6 +85,12 @@ LL | let _ = DoubleWrapper(5, 2, 7); | ^^^^^^^^^^^^^ - - - supplied 3 arguments | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error: aborting due to 8 previous errors From 41f9f38d6e19c669a14432b9ec56f26425c6c9e2 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 21 Aug 2021 18:45:56 -0500 Subject: [PATCH 042/269] Remove `Session.trait_methods_not_found` Instead, avoid registering the problematic well-formed obligation to begin with. This removes global untracked mutable state, and avoids potential issues with incremental compilation. --- .../src/traits/error_reporting/mod.rs | 6 ----- compiler/rustc_session/src/session.rs | 4 ---- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 23 ++++++++++++++++++- .../rustc_typeck/src/check/method/suggest.rs | 5 +--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index 0ac4b6b25bbf..d0bd508bc257 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -104,11 +104,5 @@ pub fn report_object_safety_error( to be resolvable dynamically; for more information visit \ ", ); - - if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) { - // Avoid emitting error caused by non-existing method (#58734) - err.cancel(); - } - err } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 5b163603d5ff..fabdebfb2127 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -189,9 +189,6 @@ pub struct Session { /// Cap lint level specified by a driver specifically. pub driver_lint_caps: FxHashMap, - /// `Span`s of trait methods that weren't found to avoid emitting object safety errors - pub trait_methods_not_found: Lock>, - /// Mapping from ident span to path span for paths that don't exist as written, but that /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`. pub confused_type_with_std_module: Lock>, @@ -1353,7 +1350,6 @@ pub fn build_session( print_fuel, jobserver: jobserver::client(), driver_lint_caps, - trait_methods_not_found: Lock::new(Default::default()), confused_type_with_std_module: Lock::new(Default::default()), ctfe_backtrace, miri_unleashed_features: Lock::new(Default::default()), diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index bb80f0879a4a..8be57e4b3cab 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -858,13 +858,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { path.segments, ); } - QPath::TypeRelative(ref qself, ref segment) => (self.to_ty(qself), qself, segment), + QPath::TypeRelative(ref qself, ref segment) => { + // Don't use `self.to_ty`, since this will register a WF obligation. + // If we're trying to call a non-existent method on a trait + // (e.g. `MyTrait::missing_method`), then resolution will + // give us a `QPath::TypeRelative` with a trait object as + // `qself`. In that case, we want to avoid registering a WF obligation + // for `dyn MyTrait`, since we don't actually need the trait + // to be object-safe. + // We manually call `register_wf_obligation` in the success path + // below. + (>::ast_ty_to_ty(self, qself), qself, segment) + } QPath::LangItem(..) => { bug!("`resolve_ty_and_res_fully_qualified_call` called on `LangItem`") } }; if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id) { + self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None)); // Return directly on cache hit. This is useful to avoid doubly reporting // errors with default match binding modes. See #44614. let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)); @@ -878,6 +890,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)), _ => Err(ErrorReported), }; + + // If we have a path like `MyTrait::missing_method`, then don't register + // a WF obligation for `dyn MyTrait` when method lookup fails. Otherwise, + // register a WF obligation so that we can detect any additional + // errors in the self type. + if !(matches!(error, method::MethodError::NoMatch(_)) && ty.is_trait()) { + self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None)); + } if item_name.name != kw::Empty { if let Some(mut e) = self.report_method_error( span, @@ -895,6 +915,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if result.is_ok() { self.maybe_lint_bare_trait(qpath, hir_id); + self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None)); } // Write back the new resolution. diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 1d5a9e3e1f96..afe274a2a796 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -70,15 +70,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn report_method_error( &self, - span: Span, + mut span: Span, rcvr_ty: Ty<'tcx>, item_name: Ident, source: SelfSource<'tcx>, error: MethodError<'tcx>, args: Option<&'tcx [hir::Expr<'tcx>]>, ) -> Option> { - let orig_span = span; - let mut span = span; // Avoid suggestions when we don't know what's going on. if rcvr_ty.references_error() { return None; @@ -545,7 +543,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { err.span_label(span, format!("{item_kind} cannot be called on `{ty_str}` due to unsatisfied trait bounds")); } - self.tcx.sess.trait_methods_not_found.borrow_mut().insert(orig_span); }; // If the method name is the name of a field with a function or closure type, From 90ac1ab26af51a08f2434b0201b23519013e9160 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 Aug 2021 03:36:37 +0000 Subject: [PATCH 043/269] Move Cache from Context to SharedContext --- src/librustdoc/html/render/context.rs | 29 +++++++----------- src/librustdoc/html/render/mod.rs | 35 +++++++++++----------- src/librustdoc/html/render/print_item.rs | 12 ++++---- src/librustdoc/html/render/write_shared.rs | 11 +++---- 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 6ce0828e1594..733bedfdde9b 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -62,16 +62,6 @@ crate struct Context<'tcx> { /// /// [#82381]: https://github.com/rust-lang/rust/issues/82381 crate shared: Rc>, - /// The [`Cache`] used during rendering. - /// - /// Ideally the cache would be in [`SharedContext`], but it's mutated - /// between when the `SharedContext` is created and when `Context` - /// is created, so more refactoring would be needed. - /// - /// It's immutable once in `Context`, so it's not as bad that it's not in - /// `SharedContext`. - // FIXME: move `cache` to `SharedContext` - crate cache: Rc, /// This flag indicates whether `[src]` links should be generated or not. If /// the source files are present in the html rendering, then this will be /// `true`. @@ -80,7 +70,7 @@ crate struct Context<'tcx> { // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. #[cfg(target_arch = "x86_64")] -rustc_data_structures::static_assert_size!(Context<'_>, 112); +rustc_data_structures::static_assert_size!(Context<'_>, 104); /// Shared mutable state used in [`Context`] and elsewhere. crate struct SharedContext<'tcx> { @@ -132,6 +122,8 @@ crate struct SharedContext<'tcx> { /// Correspondance map used to link types used in the source code pages to allow to click on /// links to jump to the type's definition. crate span_correspondance_map: FxHashMap, + /// The [`Cache`] used during rendering. + crate cache: Cache, } impl SharedContext<'_> { @@ -162,7 +154,7 @@ impl<'tcx> Context<'tcx> { } pub(crate) fn cache(&self) -> &Cache { - &self.cache + &self.shared.cache } pub(super) fn sess(&self) -> &'tcx Session { @@ -237,7 +229,7 @@ impl<'tcx> Context<'tcx> { &self.shared.style_files, ) } else { - if let Some(&(ref names, ty)) = self.cache.paths.get(&it.def_id.expect_def_id()) { + if let Some(&(ref names, ty)) = self.cache().paths.get(&it.def_id.expect_def_id()) { let mut path = String::new(); for name in &names[..names.len() - 1] { path.push_str(name); @@ -326,7 +318,7 @@ impl<'tcx> Context<'tcx> { return None; } } else { - let (krate, src_root) = match *self.cache.extern_locations.get(&cnum)? { + let (krate, src_root) = match *self.cache().extern_locations.get(&cnum)? { ExternalLocation::Local => { let e = ExternalCrate { crate_num: cnum }; (e.name(self.tcx()), e.src_root(self.tcx())) @@ -487,6 +479,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { show_type_layout, templates, span_correspondance_map: matches, + cache, }; // Add the default themes to the `Vec` of stylepaths @@ -511,7 +504,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { render_redirect_pages: false, id_map: RefCell::new(id_map), shared: Rc::new(scx), - cache: Rc::new(cache), include_sources, }; @@ -520,7 +512,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } // Build our search index - let index = build_index(&krate, Rc::get_mut(&mut cx.cache).unwrap(), tcx); + let index = build_index(&krate, &mut Rc::get_mut(&mut cx.shared).unwrap().cache, tcx); // Write shared runs within a flock; disable thread dispatching of IO temporarily. Rc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true); @@ -536,7 +528,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { render_redirect_pages: self.render_redirect_pages, id_map: RefCell::new(IdMap::new()), shared: Rc::clone(&self.shared), - cache: Rc::clone(&self.cache), include_sources: self.include_sources, } } @@ -561,7 +552,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { extra_scripts: &[], static_extra_scripts: &[], }; - let sidebar = if let Some(ref version) = self.cache.crate_version { + let sidebar = if let Some(ref version) = self.shared.cache.crate_version { format!( "

Crate {}

\
\ @@ -722,7 +713,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } fn cache(&self) -> &Cache { - &self.cache + &self.shared.cache } } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index fd2e18a8be77..7704abc9a72c 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1012,11 +1012,11 @@ fn render_assoc_items( what: AssocItemRender<'_>, ) { info!("Documenting associated items of {:?}", containing_item.name); - let v = match cx.cache.impls.get(&it) { + let cache = cx.cache(); + let v = match cache.impls.get(&it) { Some(v) => v, None => return, }; - let cache = cx.cache(); let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none()); if !non_trait.is_empty() { let render_mode = match what { @@ -1063,11 +1063,11 @@ fn render_assoc_items( if !traits.is_empty() { let deref_impl = traits .iter() - .find(|t| t.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did); + .find(|t| t.inner_impl().trait_.def_id_full(cache) == cache.deref_trait_did); if let Some(impl_) = deref_impl { let has_deref_mut = traits .iter() - .any(|t| t.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_mut_trait_did); + .any(|t| t.inner_impl().trait_.def_id_full(cache) == cache.deref_mut_trait_did); render_deref_methods(w, cx, impl_, containing_item, has_deref_mut); } let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = @@ -1122,6 +1122,7 @@ fn render_deref_methods( container_item: &clean::Item, deref_mut: bool, ) { + let cache = cx.cache(); let deref_type = impl_.inner_impl().trait_.as_ref().unwrap(); let (target, real_target) = impl_ .inner_impl() @@ -1138,8 +1139,8 @@ fn render_deref_methods( debug!("Render deref methods for {:#?}, target {:#?}", impl_.inner_impl().for_, target); let what = AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut }; - if let Some(did) = target.def_id_full(cx.cache()) { - if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cx.cache()) { + if let Some(did) = target.def_id_full(cache) { + if let Some(type_did) = impl_.inner_impl().for_.def_id_full(cache) { // `impl Deref for S` if did == type_did { // Avoid infinite cycles @@ -1149,7 +1150,7 @@ fn render_deref_methods( render_assoc_items(w, cx, container_item, did, what); } else { if let Some(prim) = target.primitive_type() { - if let Some(&did) = cx.cache.primitive_locations.get(&prim) { + if let Some(&did) = cache.primitive_locations.get(&prim) { render_assoc_items(w, cx, container_item, did, what); } } @@ -1286,7 +1287,7 @@ fn render_impl( let render_method_item = match render_mode { RenderMode::Normal => true, RenderMode::ForDeref { mut_: deref_mut_ } => { - should_render_item(&item, deref_mut_, &cx.cache) + should_render_item(&item, deref_mut_, cx.cache()) } }; @@ -1678,7 +1679,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { } if it.is_crate() { - if let Some(ref version) = cx.cache.crate_version { + if let Some(ref version) = cx.cache().crate_version { write!( buffer, "
\ @@ -1825,18 +1826,16 @@ fn small_url_encode(s: String) -> String { fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { let did = it.def_id.expect_def_id(); - if let Some(v) = cx.cache.impls.get(&did) { + let cache = cx.cache(); + if let Some(v) = cache.impls.get(&did) { let mut used_links = FxHashSet::default(); - let cache = cx.cache(); { let used_links_bor = &mut used_links; let mut ret = v .iter() .filter(|i| i.inner_impl().trait_.is_none()) - .flat_map(move |i| { - get_methods(i.inner_impl(), false, used_links_bor, false, &cx.cache) - }) + .flat_map(move |i| get_methods(i.inner_impl(), false, used_links_bor, false, cache)) .collect::>(); if !ret.is_empty() { // We want links' order to be reproducible so we don't use unstable sort. @@ -1857,7 +1856,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { if let Some(impl_) = v .iter() .filter(|i| i.inner_impl().trait_.is_some()) - .find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did) + .find(|i| i.inner_impl().trait_.def_id_full(cache) == cache.deref_trait_did) { sidebar_deref_methods(cx, out, impl_, v); } @@ -2117,15 +2116,15 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean "
", ); - if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_def_id()) { - let cache = cx.cache(); + let cache = cx.cache(); + if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) { let mut res = implementors .iter() .filter(|i| { i.inner_impl() .for_ .def_id_full(cache) - .map_or(false, |d| !cx.cache.paths.contains_key(&d)) + .map_or(false, |d| !cache.paths.contains_key(&d)) }) .filter_map(|i| extract_for_impl_name(&i.impl_item, cx)) .collect::>(); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 96cc67ce97c7..8f4857a69392 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -690,7 +690,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra // If there are methods directly on this trait object, render them here. render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All); - if let Some(implementors) = cx.cache.implementors.get(&it.def_id.expect_def_id()) { + let cache = cx.cache(); + if let Some(implementors) = cache.implementors.get(&it.def_id.expect_def_id()) { // The DefId is for the first Type found with that name. The bool is // if any Types with the same name but different DefId have been found. let mut implementor_dups: FxHashMap = FxHashMap::default(); @@ -712,10 +713,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra } let (local, foreign) = implementors.iter().partition::, _>(|i| { - i.inner_impl() - .for_ - .def_id_full(cx.cache()) - .map_or(true, |d| cx.cache.paths.contains_key(&d)) + i.inner_impl().for_.def_id_full(cache).map_or(true, |d| cache.paths.contains_key(&d)) }); let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = @@ -772,7 +770,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra it, w, &implementor_dups, - &collect_paths_for_type(implementor.inner_impl().for_.clone(), &cx.cache), + &collect_paths_for_type(implementor.inner_impl().for_.clone(), cache), ); } w.write_str("
"); @@ -806,7 +804,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra path = if it.def_id.is_local() { cx.current.join("/") } else { - let (ref path, _) = cx.cache.external_paths[&it.def_id.expect_def_id()]; + let (ref path, _) = cache.external_paths[&it.def_id.expect_def_id()]; path[..path.len() - 1].join("/") }, ty = it.type_(), diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index c16769c474a2..99cd98f7eaeb 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -518,7 +518,8 @@ pub(super) fn write_shared( // Update the list of all implementors for traits let dst = cx.dst.join("implementors"); - for (&did, imps) in &cx.cache.implementors { + let cache = cx.cache(); + for (&did, imps) in &cache.implementors { // Private modules can leak through to this phase of rustdoc, which // could contain implementations for otherwise private types. In some // rare cases we could find an implementation for an item which wasn't @@ -526,9 +527,9 @@ pub(super) fn write_shared( // // FIXME: this is a vague explanation for why this can't be a `get`, in // theory it should be... - let &(ref remote_path, remote_item_type) = match cx.cache.paths.get(&did) { + let &(ref remote_path, remote_item_type) = match cache.paths.get(&did) { Some(p) => p, - None => match cx.cache.external_paths.get(&did) { + None => match cache.external_paths.get(&did) { Some(p) => p, None => continue, }, @@ -557,7 +558,7 @@ pub(super) fn write_shared( Some(Implementor { text: imp.inner_impl().print(false, cx).to_string(), synthetic: imp.inner_impl().synthetic, - types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()), + types: collect_paths_for_type(imp.inner_impl().for_.clone(), cache), }) } }) @@ -566,7 +567,7 @@ pub(super) fn write_shared( // Only create a js file if we have impls to add to it. If the trait is // documented locally though we always create the file to avoid dead // links. - if implementors.is_empty() && !cx.cache.paths.contains_key(&did) { + if implementors.is_empty() && !cache.paths.contains_key(&did) { continue; } From d933edd5c6ee149d53bff4558c3fef8dc68b8766 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 21 Aug 2021 20:15:20 +0000 Subject: [PATCH 044/269] Revert "Revert "Don't load all extern crates unconditionally"" This reverts commit 5f0c54db4e595a6a77048f2b0605138ffa49a326. --- src/librustdoc/core.rs | 43 +++---------- src/librustdoc/lib.rs | 4 +- .../passes/collect_intra_doc_links.rs | 3 + .../passes/collect_intra_doc_links/early.rs | 63 +++++++++++++++++++ src/librustdoc/passes/mod.rs | 2 +- src/test/rustdoc-ui/auxiliary/panic-item.rs | 17 +++++ src/test/rustdoc-ui/unused-extern-crate.rs | 3 + src/test/rustdoc/auxiliary/issue-66159-1.rs | 2 - .../rustdoc/{ => intra-doc}/issue-66159.rs | 4 +- 9 files changed, 100 insertions(+), 41 deletions(-) create mode 100644 src/librustdoc/passes/collect_intra_doc_links/early.rs create mode 100644 src/test/rustdoc-ui/auxiliary/panic-item.rs create mode 100644 src/test/rustdoc-ui/unused-extern-crate.rs delete mode 100644 src/test/rustdoc/auxiliary/issue-66159-1.rs rename src/test/rustdoc/{ => intra-doc}/issue-66159.rs (80%) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 512c4ed2d3cd..249febb72bc5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,12 +1,12 @@ +use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; use rustc_errors::emitter::{Emitter, EmitterWriter}; use rustc_errors::json::JsonEmitter; use rustc_feature::UnstableFeatures; -use rustc_hir::def::Namespace::TypeNS; use rustc_hir::def::Res; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::HirId; use rustc_hir::{ intravisit::{self, NestedVisitorMap, Visitor}, @@ -23,7 +23,7 @@ use rustc_session::DiagnosticOutput; use rustc_session::Session; use rustc_span::source_map; use rustc_span::symbol::sym; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use std::cell::RefCell; use std::mem; @@ -301,41 +301,16 @@ crate fn create_config( } crate fn create_resolver<'a>( - externs: config::Externs, queries: &Queries<'a>, sess: &Session, ) -> Rc> { - let extern_names: Vec = externs - .iter() - .filter(|(_, entry)| entry.add_prelude) - .map(|(name, _)| name) - .cloned() - .collect(); - - let (_, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); - - // Before we actually clone it, let's force all the extern'd crates to - // actually be loaded, just in case they're only referred to inside - // intra-doc links - resolver.borrow_mut().access(|resolver| { - sess.time("load_extern_crates", || { - for extern_name in &extern_names { - debug!("loading extern crate {}", extern_name); - if let Err(()) = resolver - .resolve_str_path_error( - DUMMY_SP, - extern_name, - TypeNS, - LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(), - ) { - warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name) - } - } - }); - }); + let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); + let resolver = resolver.clone(); + + let mut loader = crate::passes::collect_intra_doc_links::IntraLinkCrateLoader::new(resolver); + ast::visit::walk_crate(&mut loader, krate); - // Now we're good to clone the resolver because everything should be loaded - resolver.clone() + loader.resolver } crate fn run_global_ctxt( diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e02d92b11b84..40b1f243a05c 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -30,6 +30,7 @@ extern crate tracing; // Dependencies listed in Cargo.toml do not need `extern crate`. extern crate rustc_ast; +extern crate rustc_ast_lowering; extern crate rustc_ast_pretty; extern crate rustc_attr; extern crate rustc_data_structures; @@ -724,7 +725,6 @@ fn main_options(options: config::Options) -> MainResult { let default_passes = options.default_passes; let output_format = options.output_format; // FIXME: fix this clone (especially render_options) - let externs = options.externs.clone(); let manual_passes = options.manual_passes.clone(); let render_options = options.render_options.clone(); let config = core::create_config(options); @@ -742,7 +742,7 @@ fn main_options(options: config::Options) -> MainResult { // We need to hold on to the complete resolver, so we cause everything to be // cloned for the analysis passes to use. Suboptimal, but necessary in the // current architecture. - let resolver = core::create_resolver(externs, queries, &sess); + let resolver = core::create_resolver(queries, &sess); if sess.has_errors() { sess.fatal("Compilation failed, aborting rustdoc"); diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 807872ae4fde..b909f6b26954 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -37,6 +37,9 @@ use crate::html::markdown::{markdown_links, MarkdownLink}; use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::passes::Pass; +mod early; +crate use early::IntraLinkCrateLoader; + crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass { name: "collect-intra-doc-links", run: collect_intra_doc_links, diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs new file mode 100644 index 000000000000..7cba2523d1a3 --- /dev/null +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -0,0 +1,63 @@ +use rustc_ast as ast; +use rustc_hir::def::Namespace::TypeNS; +use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_interface::interface; + +use std::cell::RefCell; +use std::mem; +use std::rc::Rc; + +// Letting the resolver escape at the end of the function leads to inconsistencies between the +// crates the TyCtxt sees and the resolver sees (because the resolver could load more crates +// after escaping). Hopefully `IntraLinkCrateLoader` gets all the crates we need ... +crate struct IntraLinkCrateLoader { + current_mod: DefId, + crate resolver: Rc>, +} + +impl IntraLinkCrateLoader { + crate fn new(resolver: Rc>) -> Self { + let crate_id = LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(); + Self { current_mod: crate_id, resolver } + } +} + +impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { + fn visit_attribute(&mut self, attr: &ast::Attribute) { + use crate::html::markdown::markdown_links; + use crate::passes::collect_intra_doc_links::preprocess_link; + + if let Some(doc) = attr.doc_str() { + for link in markdown_links(&doc.as_str()) { + let path_str = if let Some(Ok(x)) = preprocess_link(&link) { + x.path_str + } else { + continue; + }; + self.resolver.borrow_mut().access(|resolver| { + let _ = resolver.resolve_str_path_error( + attr.span, + &path_str, + TypeNS, + self.current_mod, + ); + }); + } + } + ast::visit::walk_attribute(self, attr); + } + + fn visit_item(&mut self, item: &ast::Item) { + use rustc_ast_lowering::ResolverAstLowering; + + if let ast::ItemKind::Mod(..) = item.kind { + let new_mod = + self.resolver.borrow_mut().access(|resolver| resolver.local_def_id(item.id)); + let old_mod = mem::replace(&mut self.current_mod, new_mod.to_def_id()); + ast::visit::walk_item(self, item); + self.current_mod = old_mod; + } else { + ast::visit::walk_item(self, item); + } + } +} diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 390ab1694a05..0e86fe45640f 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -30,7 +30,7 @@ crate use self::unindent_comments::UNINDENT_COMMENTS; mod propagate_doc_cfg; crate use self::propagate_doc_cfg::PROPAGATE_DOC_CFG; -mod collect_intra_doc_links; +crate mod collect_intra_doc_links; crate use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS; mod doc_test_lints; diff --git a/src/test/rustdoc-ui/auxiliary/panic-item.rs b/src/test/rustdoc-ui/auxiliary/panic-item.rs new file mode 100644 index 000000000000..17b26850d4d2 --- /dev/null +++ b/src/test/rustdoc-ui/auxiliary/panic-item.rs @@ -0,0 +1,17 @@ +// no-prefer-dynamic +#![crate_type = "lib"] +#![no_std] +#![feature(lang_items)] + +use core::panic::PanicInfo; +use core::sync::atomic::{self, Ordering}; + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop { + atomic::compiler_fence(Ordering::SeqCst); + } +} + +#[lang = "eh_personality"] +fn foo() {} diff --git a/src/test/rustdoc-ui/unused-extern-crate.rs b/src/test/rustdoc-ui/unused-extern-crate.rs new file mode 100644 index 000000000000..f703a1837907 --- /dev/null +++ b/src/test/rustdoc-ui/unused-extern-crate.rs @@ -0,0 +1,3 @@ +// check-pass +// aux-crate:panic_item=panic-item.rs +// @has unused_extern_crate/index.html diff --git a/src/test/rustdoc/auxiliary/issue-66159-1.rs b/src/test/rustdoc/auxiliary/issue-66159-1.rs deleted file mode 100644 index 2f3d069bd51c..000000000000 --- a/src/test/rustdoc/auxiliary/issue-66159-1.rs +++ /dev/null @@ -1,2 +0,0 @@ -/// This will be referred to by the test docstring -pub struct Something; diff --git a/src/test/rustdoc/issue-66159.rs b/src/test/rustdoc/intra-doc/issue-66159.rs similarity index 80% rename from src/test/rustdoc/issue-66159.rs rename to src/test/rustdoc/intra-doc/issue-66159.rs index 003d079a470c..56742b39790a 100644 --- a/src/test/rustdoc/issue-66159.rs +++ b/src/test/rustdoc/intra-doc/issue-66159.rs @@ -1,4 +1,4 @@ -// aux-crate:priv:issue_66159_1=issue-66159-1.rs +// aux-crate:priv:pub_struct=pub-struct.rs // compile-flags:-Z unstable-options // The issue was an ICE which meant that we never actually generated the docs @@ -7,4 +7,4 @@ // verify that the struct is linked correctly. // @has issue_66159/index.html -//! [issue_66159_1::Something] +//! [pub_struct::SomeStruct] From 5a501f73ff753109c7e73d4981fe011633bd8e84 Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Sun, 22 Aug 2021 21:46:03 +0200 Subject: [PATCH 045/269] Use custom wrap-around type instead of Range --- compiler/rustc_codegen_llvm/src/builder.rs | 4 +- compiler/rustc_codegen_llvm/src/consts.rs | 9 ++- .../src/debuginfo/type_names.rs | 8 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 8 +- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 43 +++++++---- compiler/rustc_mir/src/interpret/validity.rs | 27 ++----- compiler/rustc_target/src/abi/mod.rs | 73 ++++++++++-------- .../consts/const-eval/ub-nonnull.64bit.stderr | 2 +- src/test/ui/layout/debug.stderr | 45 ++++++++--- src/test/ui/layout/hexagon-enum.stderr | 75 +++++++++++++++---- src/test/ui/layout/thumb-enum.stderr | 75 +++++++++++++++---- 12 files changed, 255 insertions(+), 116 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 2139f9776b73..2b72b1674263 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -462,7 +462,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { load: &'ll Value, scalar: &abi::Scalar, ) { - let vr = scalar.valid_range.clone(); + let vr = scalar.valid_range; match scalar.value { abi::Int(..) => { let range = scalar.valid_range_exclusive(bx); @@ -470,7 +470,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { bx.range_metadata(load, range); } } - abi::Pointer if vr.start() < vr.end() && !vr.contains(&0) => { + abi::Pointer if vr.start < vr.end && !vr.contains(0) => { bx.nonnull_metadata(load); } _ => {} diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index e1baf95e1d9e..01a93dd8857c 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -16,7 +16,9 @@ use rustc_middle::mir::interpret::{ use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::{bug, span_bug}; -use rustc_target::abi::{AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size}; +use rustc_target::abi::{ + AddressSpace, Align, AllocationRange, HasDataLayout, LayoutOf, Primitive, Scalar, Size, +}; use tracing::debug; pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value { @@ -59,7 +61,10 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), &cx.tcx, ), - &Scalar { value: Primitive::Pointer, valid_range: 0..=!0 }, + &Scalar { + value: Primitive::Pointer, + valid_range: AllocationRange { start: 0, end: !0 }, + }, cx.type_i8p_ext(address_space), )); next_offset = offset + pointer_size; diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 81e905b1b5f5..f0b32c96309d 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -406,11 +406,11 @@ fn push_debuginfo_type_name<'tcx>( let dataful_discriminant_range = &dataful_variant_layout.largest_niche.as_ref().unwrap().scalar.valid_range; - let min = dataful_discriminant_range.start(); - let min = tag.value.size(&tcx).truncate(*min); + let min = dataful_discriminant_range.start; + let min = tag.value.size(&tcx).truncate(min); - let max = dataful_discriminant_range.end(); - let max = tag.value.size(&tcx).truncate(*max); + let max = dataful_discriminant_range.end; + let max = tag.value.size(&tcx).truncate(max); let dataful_variant_name = def.variants[*dataful_variant].ident.as_str(); diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 7e432d274022..90a29f24b8e0 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -310,15 +310,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let er = scalar.valid_range_exclusive(bx.cx()); if er.end != er.start - && scalar.valid_range.end() >= scalar.valid_range.start() + && scalar.valid_range.end >= scalar.valid_range.start { // We want `table[e as usize ± k]` to not // have bound checks, and this is the most // convenient place to put the `assume`s. - if *scalar.valid_range.start() > 0 { + if scalar.valid_range.start > 0 { let enum_value_lower_bound = bx .cx() - .const_uint_big(ll_t_in, *scalar.valid_range.start()); + .const_uint_big(ll_t_in, scalar.valid_range.start); let cmp_start = bx.icmp( IntPredicate::IntUGE, llval, @@ -328,7 +328,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } let enum_value_upper_bound = - bx.cx().const_uint_big(ll_t_in, *scalar.valid_range.end()); + bx.cx().const_uint_big(ll_t_in, scalar.valid_range.end); let cmp_end = bx.icmp( IntPredicate::IntULE, llval, diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 34d342e66945..82a23da3ed9c 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -797,7 +797,7 @@ crate fn repr_nullable_ptr<'tcx>( // Return the nullable type this Option-like enum can be safely represented with. let field_ty_abi = &cx.layout_of(field_ty).unwrap().abi; if let Abi::Scalar(field_ty_scalar) = field_ty_abi { - match (field_ty_scalar.valid_range.start(), field_ty_scalar.valid_range.end()) { + match (field_ty_scalar.valid_range.start, field_ty_scalar.valid_range.end) { (0, _) => unreachable!("Non-null optimisation extended to a non-zero value."), (1, _) => { return Some(get_nullable_type(cx, field_ty).unwrap()); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 3caca313ffdd..3b1990a3e675 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let scalar_unit = |value: Primitive| { let bits = value.size(dl).bits(); assert!(bits <= 128); - Scalar { value, valid_range: 0..=(!0 >> (128 - bits)) } + Scalar { value, valid_range: AllocationRange { start: 0, end: (!0 >> (128 - bits)) } } }; let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value))); @@ -512,11 +512,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Basic scalars. ty::Bool => tcx.intern_layout(Layout::scalar( self, - Scalar { value: Int(I8, false), valid_range: 0..=1 }, + Scalar { value: Int(I8, false), valid_range: AllocationRange { start: 0, end: 1 } }, )), ty::Char => tcx.intern_layout(Layout::scalar( self, - Scalar { value: Int(I32, false), valid_range: 0..=0x10FFFF }, + Scalar { + value: Int(I32, false), + valid_range: AllocationRange { start: 0, end: 0x10FFFF }, + }, )), ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)), ty::Uint(ity) => scalar(Int(Integer::from_uint_ty(dl, ity), false)), @@ -526,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }), ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer); - ptr.valid_range = 1..=*ptr.valid_range.end(); + ptr.valid_range = AllocationRange { start: 1, end: ptr.valid_range.end }; tcx.intern_layout(Layout::scalar(self, ptr)) } @@ -544,7 +547,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { let mut data_ptr = scalar_unit(Pointer); if !ty.is_unsafe_ptr() { - data_ptr.valid_range = 1..=*data_ptr.valid_range.end(); + data_ptr.valid_range = + AllocationRange { start: 1, end: data_ptr.valid_range.end }; } let pointee = tcx.normalize_erasing_regions(param_env, pointee); @@ -560,7 +564,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); - vtable.valid_range = 1..=*vtable.valid_range.end(); + vtable.valid_range = + AllocationRange { start: 1, end: vtable.valid_range.end }; vtable } _ => return Err(LayoutError::Unknown(unsized_part)), @@ -933,14 +938,18 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { if let Bound::Included(start) = start { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. - assert!(*scalar.valid_range.start() <= start); - scalar.valid_range = start..=*scalar.valid_range.end(); + assert!(scalar.valid_range.start <= start); + // scalar.valid_range = + // AllocationRange { start, end: scalar.valid_range.end }; + scalar.valid_range.start = start; } if let Bound::Included(end) = end { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. - assert!(*scalar.valid_range.end() >= end); - scalar.valid_range = *scalar.valid_range.start()..=end; + assert!(scalar.valid_range.end >= end); + // scalar.valid_range = + // AllocationRange { start: scalar.valid_range.start, end }; + scalar.valid_range.end = end; } // Update `largest_niche` if we have introduced a larger niche. @@ -1256,7 +1265,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let tag_mask = !0u128 >> (128 - ity.size().bits()); let tag = Scalar { value: Int(ity, signed), - valid_range: (min as u128 & tag_mask)..=(max as u128 & tag_mask), + valid_range: AllocationRange { + start: (min as u128 & tag_mask), + end: (max as u128 & tag_mask), + }, }; let mut abi = Abi::Aggregate { sized: true }; if tag.value.size(dl) == size { @@ -1535,7 +1547,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let max_discr = (info.variant_fields.len() - 1) as u128; let discr_int = Integer::fit_unsigned(max_discr); let discr_int_ty = discr_int.to_ty(tcx, false); - let tag = Scalar { value: Primitive::Int(discr_int, false), valid_range: 0..=max_discr }; + let tag = Scalar { + value: Primitive::Int(discr_int, false), + valid_range: AllocationRange { start: 0, end: max_discr }, + }; let tag_layout = self.tcx.intern_layout(Layout::scalar(self, tag.clone())); let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout }; @@ -2846,8 +2861,8 @@ where return; } - if scalar.valid_range.start() < scalar.valid_range.end() { - if *scalar.valid_range.start() > 0 { + if scalar.valid_range.start < scalar.valid_range.end { + if scalar.valid_range.start > 0 { attrs.set(ArgAttribute::NonNull); } } diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index 0c7f89c1a36b..71e616ff560c 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -7,7 +7,6 @@ use std::convert::TryFrom; use std::fmt::Write; use std::num::NonZeroUsize; -use std::ops::RangeInclusive; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; @@ -15,7 +14,9 @@ use rustc_middle::mir::interpret::InterpError; use rustc_middle::ty; use rustc_middle::ty::layout::TyAndLayout; use rustc_span::symbol::{sym, Symbol}; -use rustc_target::abi::{Abi, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants}; +use rustc_target::abi::{ + Abi, AllocationRange, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants, +}; use std::hash::Hash; @@ -181,22 +182,10 @@ fn write_path(out: &mut String, path: &[PathElem]) { } } -// Test if a range that wraps at overflow contains `test` -fn wrapping_range_contains(r: &RangeInclusive, test: u128) -> bool { - let (lo, hi) = r.clone().into_inner(); - if lo > hi { - // Wrapped - (..=hi).contains(&test) || (lo..).contains(&test) - } else { - // Normal - r.contains(&test) - } -} - // Formats such that a sentence like "expected something {}" to mean // "expected something " makes sense. -fn wrapping_range_format(r: &RangeInclusive, max_hi: u128) -> String { - let (lo, hi) = r.clone().into_inner(); +fn wrapping_range_format(r: AllocationRange, max_hi: u128) -> String { + let AllocationRange { start: lo, end: hi } = r; assert!(hi <= max_hi); if lo > hi { format!("less or equal to {}, or greater or equal to {}", hi, lo) @@ -634,8 +623,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' scalar_layout: &ScalarAbi, ) -> InterpResult<'tcx> { let value = self.read_scalar(op)?; - let valid_range = &scalar_layout.valid_range; - let (lo, hi) = valid_range.clone().into_inner(); + let valid_range = scalar_layout.valid_range; + let AllocationRange { start: lo, end: hi } = valid_range; // Determine the allowed range // `max_hi` is as big as the size fits let max_hi = u128::MAX >> (128 - op.layout.size.bits()); @@ -684,7 +673,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' Ok(int) => int.assert_bits(op.layout.size), }; // Now compare. This is slightly subtle because this is a special "wrap-around" range. - if wrapping_range_contains(&valid_range, bits) { + if valid_range.contains(bits) { Ok(()) } else { throw_validation_failure!(self.path, diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 8ef6e142caec..07687a4b104c 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -677,32 +677,52 @@ impl Primitive { } } +/// Inclusive wrap-around range of valid values, that is, if +/// start > end, it represents `start..=MAX`, +/// followed by `0..=end`. +/// +/// That is, for an i8 primitive, a range of `254..=2` means following +/// sequence: +/// +/// 254 (-2), 255 (-1), 0, 1, 2 +/// +/// This is intended specifically to mirror LLVM’s `!range` metadata, +/// semantics. +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(HashStable_Generic)] +pub struct AllocationRange { + pub start: u128, + pub end: u128, +} + +impl AllocationRange { + /// Returns `true` if `v` is contained in the range. + #[inline] + pub fn contains(&self, v: u128) -> bool { + if self.start <= self.end { + self.start <= v && v <= self.end + } else { + self.start <= v || v <= self.end + } + } +} + /// Information about one scalar component of a Rust type. #[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(HashStable_Generic)] pub struct Scalar { pub value: Primitive, - /// Inclusive wrap-around range of valid values, that is, if - /// start > end, it represents `start..=MAX`, - /// followed by `0..=end`. - /// - /// That is, for an i8 primitive, a range of `254..=2` means following - /// sequence: - /// - /// 254 (-2), 255 (-1), 0, 1, 2 - /// - /// This is intended specifically to mirror LLVM’s `!range` metadata, - /// semantics. // FIXME(eddyb) always use the shortest range, e.g., by finding // the largest space between two consecutive valid values and // taking everything else as the (shortest) valid range. - pub valid_range: RangeInclusive, + pub valid_range: AllocationRange, } impl Scalar { pub fn is_bool(&self) -> bool { - matches!(self.value, Int(I8, false)) && self.valid_range == (0..=1) + matches!(self.value, Int(I8, false)) + && matches!(self.valid_range, AllocationRange { start: 0, end: 1 }) } /// Returns the valid range as a `x..y` range. @@ -715,8 +735,8 @@ impl Scalar { let bits = self.value.size(cx).bits(); assert!(bits <= 128); let mask = !0u128 >> (128 - bits); - let start = *self.valid_range.start(); - let end = *self.valid_range.end(); + let start = self.valid_range.start; + let end = self.valid_range.end; assert_eq!(start, start & mask); assert_eq!(end, end & mask); start..(end.wrapping_add(1) & mask) @@ -965,20 +985,20 @@ impl Niche { } pub fn available(&self, cx: &C) -> u128 { - let Scalar { value, valid_range: ref v } = self.scalar; + let Scalar { value, valid_range: v } = self.scalar; let bits = value.size(cx).bits(); assert!(bits <= 128); let max_value = !0u128 >> (128 - bits); // Find out how many values are outside the valid range. - let niche = v.end().wrapping_add(1)..*v.start(); + let niche = v.end.wrapping_add(1)..v.start; niche.end.wrapping_sub(niche.start) & max_value } pub fn reserve(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> { assert!(count > 0); - let Scalar { value, valid_range: ref v } = self.scalar; + let Scalar { value, valid_range: v } = self.scalar; let bits = value.size(cx).bits(); assert!(bits <= 128); let max_value = !0u128 >> (128 - bits); @@ -988,24 +1008,17 @@ impl Niche { } // Compute the range of invalid values being reserved. - let start = v.end().wrapping_add(1) & max_value; - let end = v.end().wrapping_add(count) & max_value; + let start = v.end.wrapping_add(1) & max_value; + let end = v.end.wrapping_add(count) & max_value; // If the `end` of our range is inside the valid range, // then we ran out of invalid values. // FIXME(eddyb) abstract this with a wraparound range type. - let valid_range_contains = |x| { - if v.start() <= v.end() { - *v.start() <= x && x <= *v.end() - } else { - *v.start() <= x || x <= *v.end() - } - }; - if valid_range_contains(end) { + if v.contains(end) { return None; } - Some((start, Scalar { value, valid_range: *v.start()..=end })) + Some((start, Scalar { value, valid_range: AllocationRange { start: v.start, end } })) } } @@ -1214,7 +1227,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { if zero { let range = &s.valid_range; // The range must contain 0. - range.contains(&0) || (*range.start() > *range.end()) // wrap-around allows 0 + range.contains(0) || (range.start > range.end) // wrap-around allows 0 } else { // The range must include all values. `valid_range_exclusive` handles // the wrap-around using target arithmetic; with wrap-around then the full diff --git a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr index 1ce87bc7c1ce..41de900f1640 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr @@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:41:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr index 1a371c6b1700..cbe9b6400c35 100644 --- a/src/test/ui/layout/debug.stderr +++ b/src/test/ui/layout/debug.stderr @@ -15,7 +15,10 @@ error: layout_of(E) = Layout { I32, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, tag_encoding: Direct, tag_field: 0, @@ -91,7 +94,10 @@ error: layout_of(E) = Layout { I32, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, }, ), @@ -138,14 +144,20 @@ error: layout_of(S) = Layout { I32, true, ), - valid_range: 0..=4294967295, + valid_range: AllocationRange { + start: 0, + end: 4294967295, + }, }, Scalar { value: Int( I32, true, ), - valid_range: 0..=4294967295, + valid_range: AllocationRange { + start: 0, + end: 4294967295, + }, }, ), largest_niche: None, @@ -207,7 +219,10 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: 0..=1, + valid_range: AllocationRange { + start: 0, + end: 1, + }, }, tag_encoding: Direct, tag_field: 0, @@ -276,14 +291,20 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: 0..=1, + valid_range: AllocationRange { + start: 0, + end: 1, + }, }, Scalar { value: Int( I32, true, ), - valid_range: 0..=4294967295, + valid_range: AllocationRange { + start: 0, + end: 4294967295, + }, }, ), largest_niche: Some( @@ -296,7 +317,10 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: 0..=1, + valid_range: AllocationRange { + start: 0, + end: 1, + }, }, }, ), @@ -326,7 +350,10 @@ error: layout_of(i32) = Layout { I32, true, ), - valid_range: 0..=4294967295, + valid_range: AllocationRange { + start: 0, + end: 4294967295, + }, }, ), largest_niche: None, diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr index d4676a5afb25..520ba12c39fb 100644 --- a/src/test/ui/layout/hexagon-enum.stderr +++ b/src/test/ui/layout/hexagon-enum.stderr @@ -15,7 +15,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, tag_encoding: Direct, tag_field: 0, @@ -52,7 +55,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, ), largest_niche: Some( @@ -65,7 +71,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, }, ), @@ -103,7 +112,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, tag_encoding: Direct, tag_field: 0, @@ -140,7 +152,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, ), largest_niche: Some( @@ -153,7 +168,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, }, ), @@ -191,7 +209,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, tag_encoding: Direct, tag_field: 0, @@ -228,7 +249,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, ), largest_niche: Some( @@ -241,7 +265,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, }, ), @@ -279,7 +306,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, tag_encoding: Direct, tag_field: 0, @@ -316,7 +346,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, ), largest_niche: Some( @@ -329,7 +362,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, }, ), @@ -367,7 +403,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, tag_encoding: Direct, tag_field: 0, @@ -404,7 +443,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, ), largest_niche: Some( @@ -417,7 +459,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, }, ), diff --git a/src/test/ui/layout/thumb-enum.stderr b/src/test/ui/layout/thumb-enum.stderr index 898a61b904db..50e37c541163 100644 --- a/src/test/ui/layout/thumb-enum.stderr +++ b/src/test/ui/layout/thumb-enum.stderr @@ -15,7 +15,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, tag_encoding: Direct, tag_field: 0, @@ -52,7 +55,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, ), largest_niche: Some( @@ -65,7 +71,10 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: 0..=0, + valid_range: AllocationRange { + start: 0, + end: 0, + }, }, }, ), @@ -103,7 +112,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, tag_encoding: Direct, tag_field: 0, @@ -140,7 +152,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, ), largest_niche: Some( @@ -153,7 +168,10 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: 255..=255, + valid_range: AllocationRange { + start: 255, + end: 255, + }, }, }, ), @@ -191,7 +209,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, tag_encoding: Direct, tag_field: 0, @@ -228,7 +249,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, ), largest_niche: Some( @@ -241,7 +265,10 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: 256..=256, + valid_range: AllocationRange { + start: 256, + end: 256, + }, }, }, ), @@ -279,7 +306,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, tag_encoding: Direct, tag_field: 0, @@ -316,7 +346,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, ), largest_niche: Some( @@ -329,7 +362,10 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: 268435456..=268435456, + valid_range: AllocationRange { + start: 268435456, + end: 268435456, + }, }, }, ), @@ -367,7 +403,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, tag_encoding: Direct, tag_field: 0, @@ -404,7 +443,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, ), largest_niche: Some( @@ -417,7 +459,10 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: 2164260864..=2164260864, + valid_range: AllocationRange { + start: 2164260864, + end: 2164260864, + }, }, }, ), From 1b4064f04a5d9f2ff910f448f65e3396502ff280 Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Sun, 22 Aug 2021 22:45:51 +0200 Subject: [PATCH 046/269] fix 32bit err --- src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr index e44f32494548..01403a61e5e2 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr @@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:41:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 } | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { From f28793dd13e8a8132d559629728e6ca9514dbe36 Mon Sep 17 00:00:00 2001 From: linux1 Date: Fri, 6 Aug 2021 17:53:29 -0400 Subject: [PATCH 047/269] Feat: added inline asm support for s390x --- compiler/rustc_codegen_llvm/src/asm.rs | 6 + compiler/rustc_target/src/asm/mod.rs | 25 ++++ compiler/rustc_target/src/asm/s390x.rs | 156 +++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 compiler/rustc_target/src/asm/s390x.rs diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 4387f5301a58..938f036da0e4 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -314,6 +314,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {} InlineAsmArch::Hexagon => {} InlineAsmArch::Mips | InlineAsmArch::Mips64 => {} + InlineAsmArch::s390 => {} InlineAsmArch::SpirV => {} InlineAsmArch::Wasm32 => {} InlineAsmArch::Bpf => {} @@ -633,6 +634,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w", + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => "r", + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => "f", InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -711,6 +714,7 @@ fn modifier_to_llvm( } InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => None, InlineAsmRegClass::Bpf(_) => None, + InlineAsmRegClass::s390x(_) => None, InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -769,6 +773,8 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(), + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => cx.type_i32(), + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => cx.type_f64(), InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 9ebf8235e209..3ce5a8195d60 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -154,6 +154,7 @@ mod mips; mod nvptx; mod powerpc; mod riscv; +mod s390x; mod spirv; mod wasm; mod x86; @@ -166,6 +167,7 @@ pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass}; pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass}; pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass}; pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass}; +pub use s390x::{s390xInlineAsmReg, s390xInlineAsmRegClass}; pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass}; pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass}; pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass}; @@ -184,6 +186,7 @@ pub enum InlineAsmArch { Mips64, PowerPC, PowerPC64, + s390x, SpirV, Wasm32, Bpf, @@ -206,6 +209,7 @@ impl FromStr for InlineAsmArch { "hexagon" => Ok(Self::Hexagon), "mips" => Ok(Self::Mips), "mips64" => Ok(Self::Mips64), + "s390x" => Ok(Self::s390x), "spirv" => Ok(Self::SpirV), "wasm32" => Ok(Self::Wasm32), "bpf" => Ok(Self::Bpf), @@ -235,6 +239,7 @@ pub enum InlineAsmReg { PowerPC(PowerPCInlineAsmReg), Hexagon(HexagonInlineAsmReg), Mips(MipsInlineAsmReg), + s390x(InlineAsmReg), SpirV(SpirVInlineAsmReg), Wasm(WasmInlineAsmReg), Bpf(BpfInlineAsmReg), @@ -252,6 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), + Self::s390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -266,6 +272,7 @@ impl InlineAsmReg { Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()), Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()), Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()), + Self::s390x(r) => InlineAsmRegClass::s390x(r.reg_class()), Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()), Self::Err => InlineAsmRegClass::Err, } @@ -305,6 +312,9 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } + InlineAsmArch::s390x => { + Self::s390x(s390xInlineAsmReg::parse(arch, has_feature, target, &name)?) + } InlineAsmArch::SpirV => { Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?) } @@ -333,6 +343,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.emit(out, arch, modifier), Self::Hexagon(r) => r.emit(out, arch, modifier), Self::Mips(r) => r.emit(out, arch, modifier), + Self::s390x(r) => r.emit(out, arch, modifier), Self::Bpf(r) => r.emit(out, arch, modifier), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -347,6 +358,7 @@ impl InlineAsmReg { Self::PowerPC(_) => cb(self), Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))), Self::Mips(_) => cb(self), + Self::s390x(_) => cb(self), Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -374,6 +386,7 @@ pub enum InlineAsmRegClass { PowerPC(PowerPCInlineAsmRegClass), Hexagon(HexagonInlineAsmRegClass), Mips(MipsInlineAsmRegClass), + s390x(s390xInlineAsmRegClass), SpirV(SpirVInlineAsmRegClass), Wasm(WasmInlineAsmRegClass), Bpf(BpfInlineAsmRegClass), @@ -392,6 +405,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), + Self::s390x(r) => r.name(), Self::SpirV(r) => r.name(), Self::Wasm(r) => r.name(), Self::Bpf(r) => r.name(), @@ -412,6 +426,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC), Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon), Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips), + Self::s390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::s390x), Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV), Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm), Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf), @@ -439,6 +454,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_modifier(arch, ty), Self::Hexagon(r) => r.suggest_modifier(arch, ty), Self::Mips(r) => r.suggest_modifier(arch, ty), + Self::s390x(r) => r.suggest_modifier(arch, ty), Self::SpirV(r) => r.suggest_modifier(arch, ty), Self::Wasm(r) => r.suggest_modifier(arch, ty), Self::Bpf(r) => r.suggest_modifier(arch, ty), @@ -462,6 +478,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.default_modifier(arch), Self::Hexagon(r) => r.default_modifier(arch), Self::Mips(r) => r.default_modifier(arch), + Self::s390x(r) => r.default_modifier(arch), Self::SpirV(r) => r.default_modifier(arch), Self::Wasm(r) => r.default_modifier(arch), Self::Bpf(r) => r.default_modifier(arch), @@ -484,6 +501,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.supported_types(arch), Self::Hexagon(r) => r.supported_types(arch), Self::Mips(r) => r.supported_types(arch), + Self::s390x(r) => r.supported_types(arch), Self::SpirV(r) => r.supported_types(arch), Self::Wasm(r) => r.supported_types(arch), Self::Bpf(r) => r.supported_types(arch), @@ -509,6 +527,7 @@ impl InlineAsmRegClass { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?) } + InlineAsmArch::s390x => Self::s390x(s390xInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?), @@ -527,6 +546,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.valid_modifiers(arch), Self::Hexagon(r) => r.valid_modifiers(arch), Self::Mips(r) => r.valid_modifiers(arch), + Self::s390x(r) => r.valid_modifiers(arch), Self::SpirV(r) => r.valid_modifiers(arch), Self::Wasm(r) => r.valid_modifiers(arch), Self::Bpf(r) => r.valid_modifiers(arch), @@ -695,6 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } + InlineAsmArch::s390x => { + let mut map = s390x::regclass_map(); + s390x::fill_reg_map(arch, has_feature, target, &mut map); + map + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs new file mode 100644 index 000000000000..ad07e20de8a0 --- /dev/null +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -0,0 +1,156 @@ +use super::{InlineAsmArch, InlineAsmType}; +use rustc_macros::HashStable_Generic; +use std::fmt; + +def_reg_class! { + s390x s390xInlineAsmRegClass { + reg, + freg, + } +} + +impl s390xInlineAsmRegClass { + pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] { + &[] + } + + pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option { + None + } + + pub fn suggest_modifier( + self, + _arch: InlineAsmArch, + _ty: InlineAsmType, + ) -> Option<(char, &'static str)> { + None + } + + pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> { + None + } + + pub fn supported_types( + self, + arch: InlineAsmArch, + ) -> &'static [(InlineAsmType, Option<&'static str>)] { + match (self, arch) { + (Self::reg, _) => types! { _: I8, I16, I32; }, + (Self::freg, _) => types! { _: F32, F64; }, + } + } +} + +def_regs! { + s390x s390xInlineAsmReg s390xInlineAsmRegClass { + r0: req = ["r0"], + r1: reg = ["r1"], + r2: reg = ["r2"], + r3: reg = ["r3"], + r4: reg = ["r4"], + r5: reg = ["r5"], + r6: reg = ["r6"], + r7: reg = ["r7"], + r8: reg = ["r8"], + r9: reg = ["r9"], + r10: reg = ["r10"], + r11: reg = ["r11"], + r12: reg = ["r12"], + r14: reg = ["r14"], + f0: freg = ["f0"], + f1: freg = ["f1"], + f2: freg = ["f2"], + f3: freg = ["f3"], + f4: freg = ["f4"], + f5: freg = ["f5"], + f6: freg = ["f6"], + f7: freg = ["f7"], + f8: freg = ["f8"], + f9: freg = ["f9"], + f10: freg = ["f10"], + f11: freg = ["f11"], + f12: freg = ["f12"], + f13: freg = ["f13"], + f14: freg = ["f14"], + f15: freg = ["f15"], + #error = ["r13"] => + "The base pointer cannot be used as an operand for inline asm", + #error = ["r15"] => + "The stack pointer cannot be used as an operand for inline asm", + #error = ["a0"] => + "This pointer is reserved on s390x and cannot be used as an operand for inline asm", + #error = ["a1"] => + "This pointer is reserved on z/Arch and cannot be used as an operand for inline asm", + #error = ["c0"] => + "c0 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c1"] => + "c1 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c2"] => + "c2 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c3"] => + "c3 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c4"] => + "c4 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c5"] => + "c5 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c6"] => + "c6 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c7"] => + "c7 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c8"] => + "c8 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c9"] => + "c9 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c10"] => + "c10 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c11"] => + "c11 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c12"] => + "c12 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c13"] => + "c13 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c14"] => + "c14 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c15"] => + "c15 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["a2"] => + "a2 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a3"] => + "a3 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a4"] => + "a4 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a5"] => + "a5 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a6"] => + "a6 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a7"] => + "a7 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a8"] => + "a8 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a9"] => + "a9 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a10"] => + "a10 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a11"] => + "a11 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a12"] => + "a12 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a13"] => + "a13 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a14"] => + "a14 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a15"] => + "a15 is not supported by LLVM and cannot be used as an operand for inline asm", + } +} + +impl s390xInlineAsmReg { + pub fn emit( + self, + out: &mut dyn fmt::Write, + _arch: InlineAsmArch, + _modifier: Option, + ) -> fmt::Result { + out.write_str(self.name()) + } +} From 5f5afba5fbb869db26c4f9e88c29bad94007dfd1 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 11:25:50 -0400 Subject: [PATCH 048/269] Feat: added s390x reg-definitions, constraint codes, and tests --- compiler/rustc_codegen_llvm/src/asm.rs | 12 ++-- compiler/rustc_target/src/asm/mod.rs | 42 ++++++------- compiler/rustc_target/src/asm/s390x.rs | 10 +-- src/test/assembly/asm/s390x-types.rs | 86 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 src/test/assembly/asm/s390x-types.rs diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 938f036da0e4..1689fdd4f2e8 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -314,7 +314,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {} InlineAsmArch::Hexagon => {} InlineAsmArch::Mips | InlineAsmArch::Mips64 => {} - InlineAsmArch::s390 => {} + InlineAsmArch::S390x => {} InlineAsmArch::SpirV => {} InlineAsmArch::Wasm32 => {} InlineAsmArch::Bpf => {} @@ -634,8 +634,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w", - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => "r", - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => "f", + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r", + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f", InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -714,7 +714,7 @@ fn modifier_to_llvm( } InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => None, InlineAsmRegClass::Bpf(_) => None, - InlineAsmRegClass::s390x(_) => None, + InlineAsmRegClass::S390x(_) => None, InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -773,8 +773,8 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(), - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => cx.type_i32(), - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => cx.type_f64(), + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(), + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(), InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 3ce5a8195d60..015faa14e28a 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -167,7 +167,7 @@ pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass}; pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass}; pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass}; pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass}; -pub use s390x::{s390xInlineAsmReg, s390xInlineAsmRegClass}; +pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass}; pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass}; pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass}; pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass}; @@ -186,7 +186,7 @@ pub enum InlineAsmArch { Mips64, PowerPC, PowerPC64, - s390x, + S390x, SpirV, Wasm32, Bpf, @@ -209,7 +209,7 @@ impl FromStr for InlineAsmArch { "hexagon" => Ok(Self::Hexagon), "mips" => Ok(Self::Mips), "mips64" => Ok(Self::Mips64), - "s390x" => Ok(Self::s390x), + "s390x" => Ok(Self::S390x), "spirv" => Ok(Self::SpirV), "wasm32" => Ok(Self::Wasm32), "bpf" => Ok(Self::Bpf), @@ -239,7 +239,7 @@ pub enum InlineAsmReg { PowerPC(PowerPCInlineAsmReg), Hexagon(HexagonInlineAsmReg), Mips(MipsInlineAsmReg), - s390x(InlineAsmReg), + S390x(S390xInlineAsmReg), SpirV(SpirVInlineAsmReg), Wasm(WasmInlineAsmReg), Bpf(BpfInlineAsmReg), @@ -257,7 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::s390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -272,7 +272,7 @@ impl InlineAsmReg { Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()), Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()), Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()), - Self::s390x(r) => InlineAsmRegClass::s390x(r.reg_class()), + Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()), Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()), Self::Err => InlineAsmRegClass::Err, } @@ -312,8 +312,8 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } - InlineAsmArch::s390x => { - Self::s390x(s390xInlineAsmReg::parse(arch, has_feature, target, &name)?) + InlineAsmArch::S390x => { + Self::S390x(S390xInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::SpirV => { Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?) @@ -343,7 +343,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.emit(out, arch, modifier), Self::Hexagon(r) => r.emit(out, arch, modifier), Self::Mips(r) => r.emit(out, arch, modifier), - Self::s390x(r) => r.emit(out, arch, modifier), + Self::S390x(r) => r.emit(out, arch, modifier), Self::Bpf(r) => r.emit(out, arch, modifier), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -358,7 +358,7 @@ impl InlineAsmReg { Self::PowerPC(_) => cb(self), Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))), Self::Mips(_) => cb(self), - Self::s390x(_) => cb(self), + Self::S390x(_) => cb(self), Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -386,7 +386,7 @@ pub enum InlineAsmRegClass { PowerPC(PowerPCInlineAsmRegClass), Hexagon(HexagonInlineAsmRegClass), Mips(MipsInlineAsmRegClass), - s390x(s390xInlineAsmRegClass), + S390x(S390xInlineAsmRegClass), SpirV(SpirVInlineAsmRegClass), Wasm(WasmInlineAsmRegClass), Bpf(BpfInlineAsmRegClass), @@ -405,7 +405,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::s390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::SpirV(r) => r.name(), Self::Wasm(r) => r.name(), Self::Bpf(r) => r.name(), @@ -426,7 +426,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC), Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon), Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips), - Self::s390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::s390x), + Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x), Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV), Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm), Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf), @@ -454,7 +454,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_modifier(arch, ty), Self::Hexagon(r) => r.suggest_modifier(arch, ty), Self::Mips(r) => r.suggest_modifier(arch, ty), - Self::s390x(r) => r.suggest_modifier(arch, ty), + Self::S390x(r) => r.suggest_modifier(arch, ty), Self::SpirV(r) => r.suggest_modifier(arch, ty), Self::Wasm(r) => r.suggest_modifier(arch, ty), Self::Bpf(r) => r.suggest_modifier(arch, ty), @@ -478,7 +478,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.default_modifier(arch), Self::Hexagon(r) => r.default_modifier(arch), Self::Mips(r) => r.default_modifier(arch), - Self::s390x(r) => r.default_modifier(arch), + Self::S390x(r) => r.default_modifier(arch), Self::SpirV(r) => r.default_modifier(arch), Self::Wasm(r) => r.default_modifier(arch), Self::Bpf(r) => r.default_modifier(arch), @@ -501,7 +501,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.supported_types(arch), Self::Hexagon(r) => r.supported_types(arch), Self::Mips(r) => r.supported_types(arch), - Self::s390x(r) => r.supported_types(arch), + Self::S390x(r) => r.supported_types(arch), Self::SpirV(r) => r.supported_types(arch), Self::Wasm(r) => r.supported_types(arch), Self::Bpf(r) => r.supported_types(arch), @@ -527,7 +527,7 @@ impl InlineAsmRegClass { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?) } - InlineAsmArch::s390x => Self::s390x(s390xInlineAsmRegClass::parse(arch, name)?), + InlineAsmArch::S390x => Self::S390x(S390xInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?), @@ -546,7 +546,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.valid_modifiers(arch), Self::Hexagon(r) => r.valid_modifiers(arch), Self::Mips(r) => r.valid_modifiers(arch), - Self::s390x(r) => r.valid_modifiers(arch), + Self::S390x(r) => r.valid_modifiers(arch), Self::SpirV(r) => r.valid_modifiers(arch), Self::Wasm(r) => r.valid_modifiers(arch), Self::Bpf(r) => r.valid_modifiers(arch), @@ -715,11 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } - InlineAsmArch::s390x => { - let mut map = s390x::regclass_map(); + InlineAsmArch::S390x => { + let mut map = s390x::regclass_map(); s390x::fill_reg_map(arch, has_feature, target, &mut map); map - } + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index ad07e20de8a0..0acbea800930 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -3,13 +3,13 @@ use rustc_macros::HashStable_Generic; use std::fmt; def_reg_class! { - s390x s390xInlineAsmRegClass { + S390x S390xInlineAsmRegClass { reg, freg, } } -impl s390xInlineAsmRegClass { +impl S390xInlineAsmRegClass { pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] { &[] } @@ -42,8 +42,8 @@ impl s390xInlineAsmRegClass { } def_regs! { - s390x s390xInlineAsmReg s390xInlineAsmRegClass { - r0: req = ["r0"], + S390x S390xInlineAsmReg S390xInlineAsmRegClass { + r0: reg = ["r0"], r1: reg = ["r1"], r2: reg = ["r2"], r3: reg = ["r3"], @@ -144,7 +144,7 @@ def_regs! { } } -impl s390xInlineAsmReg { +impl S390xInlineAsmReg { pub fn emit( self, out: &mut dyn fmt::Write, diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs new file mode 100644 index 000000000000..5f1a5f2de56b --- /dev/null +++ b/src/test/assembly/asm/s390x-types.rs @@ -0,0 +1,86 @@ +// min-llvm-version: 10.0.1 +// revisions: s390x +// assembly-output: emit-asm +//[s390x] compile-flags: --target s390x-unknown-linux-gnu +//[s390x] needs-llvm-components: systemz + +#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![crate_type = "rlib"] +#![no_core] +#![allow(asm_sub_register, non_camel_case_types)] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} +#[rustc_builtin_macro] +macro_rules! concat { + () => {}; +} +#[rustc_builtin_macro] +macro_rules! stringify { + () => {}; +} + +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} + +type ptr = *const i32; + +impl Copy for i8 {} +impl Copy for u8 {} +impl Copy for i16 {} +impl Copy for i32 {} +impl Copy for i64 {} +impl Copy for f32 {} +impl Copy for f64 {} +impl Copy for ptr {} + +extern "C" { + fn extern_func(); + static extern_static: u8; +} + +// Hack to avoid function merging +extern "Rust" { + fn dont_merge(s: &str); +} + +macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { + + pub unsafe fn $func(x: $ty) -> $ty { + dont_merge(stringify!(func)); + + let y; + asm!(concat!($mov," {}, {}"), out($class) y, in($class) x); + y + } +};} + +macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { + + pub unsafe fn $func(x: $ty) -> $ty { + dont_merge(stringify!(func)); + + let y; + asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); + y + } +};} + +// systemz-LABEL: sym_fn_32: +// systemz: #APP +// systemz: brasl %r14, extern_func@PLT +// systemz: #NO_APP +#[cfg(s390x)] +pub unsafe fn sym_fn_32() { + asm!("brasl %r14, {}", sym extern_func); +} + +// CHECK-LABEL: reg_i32: +// CHECK: #APP +// CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} +// CHECK: #NO_APP +check!(reg_i32, i32, reg, "lgr"); From 7095dfffc3bde0fc56a837241db84e414e3d9b25 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 12:14:26 -0400 Subject: [PATCH 049/269] Refactor: added #[no_mangle] --- src/test/assembly/asm/s390x-types.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 5f1a5f2de56b..7b2ef9bda347 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -75,6 +75,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { // systemz: brasl %r14, extern_func@PLT // systemz: #NO_APP #[cfg(s390x)] +#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } @@ -83,4 +84,5 @@ pub unsafe fn sym_fn_32() { // CHECK: #APP // CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} // CHECK: #NO_APP +#[no_mangle] check!(reg_i32, i32, reg, "lgr"); From 66e95b17ecfc93e39b1846436a86f0e924ab30b3 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 12:40:18 -0400 Subject: [PATCH 050/269] Fix: moved #[no_mangle] --- src/test/assembly/asm/s390x-types.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 7b2ef9bda347..0fbb77b96175 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -49,7 +49,7 @@ extern "Rust" { } macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { - + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -75,7 +75,6 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { // systemz: brasl %r14, extern_func@PLT // systemz: #NO_APP #[cfg(s390x)] -#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } @@ -84,5 +83,4 @@ pub unsafe fn sym_fn_32() { // CHECK: #APP // CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} // CHECK: #NO_APP -#[no_mangle] check!(reg_i32, i32, reg, "lgr"); From eeb0b52bf852b902b2bd1adaf919c35e2387ce28 Mon Sep 17 00:00:00 2001 From: linux1 Date: Sun, 22 Aug 2021 17:26:18 -0400 Subject: [PATCH 051/269] Feat: further testing & support for i64 general register use --- compiler/rustc_target/src/asm/s390x.rs | 2 +- src/test/assembly/asm/s390x-types.rs | 52 +++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 0acbea800930..dbf4168e4a80 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -35,7 +35,7 @@ impl S390xInlineAsmRegClass { arch: InlineAsmArch, ) -> &'static [(InlineAsmType, Option<&'static str>)] { match (self, arch) { - (Self::reg, _) => types! { _: I8, I16, I32; }, + (Self::reg, _) => types! { _: I8, I16, I32, I64; }, (Self::freg, _) => types! { _: F32, F64; }, } } diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 0fbb77b96175..692193158405 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -60,7 +60,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { };} macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { - + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -70,17 +70,57 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { } };} -// systemz-LABEL: sym_fn_32: -// systemz: #APP -// systemz: brasl %r14, extern_func@PLT -// systemz: #NO_APP +// CHECK-LABEL: sym_fn_32: +// CHECK: #APP +// CHECK: brasl %r14, extern_func +// CHECK: #NO_APP #[cfg(s390x)] +#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } +// CHECK-LABEL: sym_static: +// CHECK: #APP +// CHECK: brasl %r14, extern_static +// CHECK: #NO_APP +#[no_mangle] +pub unsafe fn sym_static() { + asm!("brasl %r14, {}", sym extern_static); +} + +// CHECK-LABEL: reg_i8: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i8, i8, reg, "lgr"); + +// CHECK-LABEL: reg_i16: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i16, i16, reg, "lgr"); + // CHECK-LABEL: reg_i32: // CHECK: #APP -// CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} // CHECK: #NO_APP check!(reg_i32, i32, reg, "lgr"); + +// CHECK-LABEL: reg_i64: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i64, i64, reg, "lgr"); + +// CHECK-LABEL: reg_f32: +// CHECK: #APP +// CHECK: ler %f{{[0-9]+}}, %f{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_f32, f32, freg, "ler"); + +// CHECK-LABEL: reg_f64: +// CHECK: #APP +// CHECK: ldr %f{{[0-9]+}}, %f{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_f64, f64, freg, "ldr"); From 0c9e23c7ce964438b107d064533b89f024e7ccf8 Mon Sep 17 00:00:00 2001 From: linux1 Date: Sun, 22 Aug 2021 17:38:22 -0400 Subject: [PATCH 052/269] Fix: appeased x.py test tidy --bless --- compiler/rustc_target/src/asm/mod.rs | 10 +++++----- compiler/rustc_target/src/asm/s390x.rs | 2 +- src/test/assembly/asm/s390x-types.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 015faa14e28a..3b3017e37c1f 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -257,7 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::S390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -312,7 +312,7 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } - InlineAsmArch::S390x => { + InlineAsmArch::S390x => { Self::S390x(S390xInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::SpirV => { @@ -715,11 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } - InlineAsmArch::S390x => { - let mut map = s390x::regclass_map(); + InlineAsmArch::S390x => { + let mut map = s390x::regclass_map(); s390x::fill_reg_map(arch, has_feature, target, &mut map); map - } + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index dbf4168e4a80..29f370928713 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -113,7 +113,7 @@ def_regs! { "c14 is reserved by the kernel and cannot be used as an operand for inline asm", #error = ["c15"] => "c15 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["a2"] => + #error = ["a2"] => "a2 is not supported by LLVM and cannot be used as an operand for inline asm", #error = ["a3"] => "a3 is not supported by LLVM and cannot be used as an operand for inline asm", diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 692193158405..dd8a256516e6 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -49,7 +49,7 @@ extern "Rust" { } macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { - #[no_mangle] + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -60,7 +60,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { };} macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { - #[no_mangle] + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); From 81412f1af6da5cb3653c23ec02b3627494ebf0c1 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Sun, 22 Aug 2021 16:58:36 -0400 Subject: [PATCH 053/269] Update asm docs --- .../unstable-book/src/library-features/asm.md | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index 220b74ca6e6e..2bb7e4ec266a 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -31,6 +31,7 @@ Inline assembly is currently supported on the following architectures: - MIPS32r2 and MIPS64r2 - wasm32 - BPF +- SPIR-V ## Basic usage @@ -188,8 +189,7 @@ As you can see, this assembly fragment will still work correctly if `a` and `b` Some instructions require that the operands be in a specific register. Therefore, Rust inline assembly provides some more specific constraint specifiers. -While `reg` is generally available on any architecture, these are highly architecture specific. E.g. for x86 the general purpose registers `eax`, `ebx`, `ecx`, `edx`, `ebp`, `esi`, and `edi` -among others can be addressed by their name. +While `reg` is generally available on any architecture, explicit registers are highly architecture specific. E.g. for x86 the general purpose registers `eax`, `ebx`, `ecx`, `edx`, `ebp`, `esi`, and `edi` among others can be addressed by their name. ```rust,allow_fail,no_run #![feature(asm)] @@ -199,11 +199,9 @@ unsafe { } ``` -In this example we call the `out` instruction to output the content of the `cmd` variable -to port `0x64`. Since the `out` instruction only accepts `eax` (and its sub registers) as operand -we had to use the `eax` constraint specifier. +In this example we call the `out` instruction to output the content of the `cmd` variable to port `0x64`. Since the `out` instruction only accepts `eax` (and its sub registers) as operand we had to use the `eax` constraint specifier. -Note that unlike other operand types, explicit register operands cannot be used in the template string: you can't use `{}` and should write the register name directly instead. Also, they must appear at the end of the operand list after all other operand types. +> **Note**: unlike other operand types, explicit register operands cannot be used in the template string: you can't use `{}` and should write the register name directly instead. Also, they must appear at the end of the operand list after all other operand types. Consider this example which uses the x86 `mul` instruction: @@ -237,11 +235,9 @@ The higher 64 bits are stored in `rdx` from which we fill the variable `hi`. ## Clobbered registers In many cases inline assembly will modify state that is not needed as an output. -Usually this is either because we have to use a scratch register in the assembly, -or instructions modify state that we don't need to further examine. +Usually this is either because we have to use a scratch register in the assembly or because instructions modify state that we don't need to further examine. This state is generally referred to as being "clobbered". -We need to tell the compiler about this since it may need to save and restore this state -around the inline assembly block. +We need to tell the compiler about this since it may need to save and restore this state around the inline assembly block. ```rust,allow_fail #![feature(asm)] @@ -321,8 +317,7 @@ fn call_foo(arg: i32) -> i32 { } ``` -Note that the `fn` or `static` item does not need to be public or `#[no_mangle]`: -the compiler will automatically insert the appropriate mangled symbol name into the assembly code. +Note that the `fn` or `static` item does not need to be public or `#[no_mangle]`: the compiler will automatically insert the appropriate mangled symbol name into the assembly code. By default, `asm!` assumes that any register not specified as an output will have its contents preserved by the assembly code. The [`clobber_abi`](#abi-clobbers) argument to `asm!` tells the compiler to automatically insert the necessary clobber operands according to the given calling convention ABI: any register which is not fully preserved in that ABI will be treated as clobbered. @@ -355,9 +350,8 @@ If you use a smaller data type (e.g. `u16`) with an operand and forget the use t ## Memory address operands Sometimes assembly instructions require operands passed via memory addresses/memory locations. -You have to manually use the memory address syntax specified by the respectively architectures. -For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]` -to indicate they are memory operands: +You have to manually use the memory address syntax specified by the target architecture. +For example, on x86/x86_64 using intel assembly syntax, you should wrap inputs/outputs in `[]` to indicate they are memory operands: ```rust,allow_fail #![feature(asm, llvm_asm)] @@ -373,9 +367,15 @@ unsafe { ## Labels -The compiler is allowed to instantiate multiple copies an `asm!` block, for example when the function containing it is inlined in multiple places. As a consequence, you should only use GNU assembler [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions. +Any reuse of a named label, local or otherwise, can result in a assembler or linker error in the best case, ICEs or segfaults in the compiler in other cases, and generally unexpected behavior. Reuse of a named label can happen in a variety of ways including: -Moreover, due to [an llvm bug], you shouldn't use labels exclusively made of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values. +- explicitly: using a label more than once in one `asm!` block, or multiple times across blocks +- implicitly via inlining: the compiler is allowed to instantiate multiple copies of an `asm!` block, for example when the function containing it is inlined in multiple places. +- implicitly via LTO: LTO can cause code from _other crates_ to be placed in the same codegen unit, and so could bring in arbitrary labels + +As a consequence, you should only use GNU assembler **numeric** [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions. + +Moreover, on x86 when using the default intel syntax, due to [an llvm bug], you shouldn't use labels exclusively made of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values. Using `option(att_syntax)` will avoid any ambiguity, but that affects the syntax of the _entire_ `asm!` block. ```rust,allow_fail #![feature(asm)] @@ -410,7 +410,7 @@ Second, that when a numeric label is used as a reference (as an instruction oper ## Options -By default, an inline assembly block is treated the same way as an external FFI function call with a custom calling convention: it may read/write memory, have observable side effects, etc. However in many cases, it is desirable to give the compiler more information about what the assembly code is actually doing so that it can optimize better. +By default, an inline assembly block is treated the same way as an external FFI function call with a custom calling convention: it may read/write memory, have observable side effects, etc. However, in many cases it is desirable to give the compiler more information about what the assembly code is actually doing so that it can optimize better. Let's take our previous example of an `add` instruction: @@ -470,6 +470,7 @@ Inline assembly is currently supported on the following architectures: - MIPS32r2 and MIPS64r2 - wasm32 - BPF +- SPIR-V Support for more targets may be added in the future. The compiler will emit an error if `asm!` is used on an unsupported target. @@ -836,7 +837,7 @@ The compiler performs some additional checks on options: - Note that a `lateout` may be allocated to the same register as an `in`, in which case this rule does not apply. Code should not rely on this however since it depends on the results of register allocation. - Behavior is undefined if execution unwinds out of an asm block. - This also applies if the assembly code calls a function which then unwinds. -- The set of memory locations that assembly code is allowed the read and write are the same as those allowed for an FFI function. +- The set of memory locations that assembly code is allowed to read and write are the same as those allowed for an FFI function. - Refer to the unsafe code guidelines for the exact rules. - If the `readonly` option is set, then only memory reads are allowed. - If the `nomem` option is set then no reads or writes to memory are allowed. From 9c44d80c83eb250594ecad05ea5340e0b51af525 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Wed, 11 Aug 2021 14:38:20 -0400 Subject: [PATCH 054/269] add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells Previously, converting `&mut [T; N]` to `&[Cell; N]` looks like this: let array = &mut [1, 2, 3]; let cells: &[Cell; 3] = Cell::from_mut(&mut array[..]) .as_slice_of_cells() .try_into() .unwrap(); With this new helper method, it looks like this: let array = &mut [1, 2, 3]; let cells: &[Cell; 3] = Cell::from_mut(array).as_array_of_cells(); --- library/core/src/cell.rs | 20 +++++++++++++++++++ src/test/ui/rfcs/rfc-1789-as-cell/from-mut.rs | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index f0c934edf397..85b43f488476 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -576,6 +576,26 @@ impl Cell<[T]> { } } +impl Cell<[T; N]> { + /// Returns a `&[Cell; N]` from a `&Cell<[T; N]>` + /// + /// # Examples + /// + /// ``` + /// #![feature(as_array_of_cells)] + /// use std::cell::Cell; + /// + /// let mut array: [i32; 3] = [1, 2, 3]; + /// let cell_array: &Cell<[i32; 3]> = Cell::from_mut(&mut array); + /// let array_cell: &[Cell; 3] = cell_array.as_array_of_cells(); + /// ``` + #[unstable(feature = "as_array_of_cells", issue = "88248")] + pub fn as_array_of_cells(&self) -> &[Cell; N] { + // SAFETY: `Cell` has the same memory layout as `T`. + unsafe { &*(self as *const Cell<[T; N]> as *const [Cell; N]) } + } +} + /// A mutable memory location with dynamically checked borrow rules /// /// See the [module-level documentation](self) for more. diff --git a/src/test/ui/rfcs/rfc-1789-as-cell/from-mut.rs b/src/test/ui/rfcs/rfc-1789-as-cell/from-mut.rs index ea3ad7aed492..329fadb150fc 100644 --- a/src/test/ui/rfcs/rfc-1789-as-cell/from-mut.rs +++ b/src/test/ui/rfcs/rfc-1789-as-cell/from-mut.rs @@ -1,5 +1,7 @@ // run-pass +#![feature(as_array_of_cells)] + use std::cell::Cell; fn main() { @@ -8,4 +10,11 @@ fn main() { let slice_cell: &[Cell] = cell_slice.as_slice_of_cells(); assert_eq!(slice_cell.len(), 3); + + let mut array: [i32; 3] = [1, 2, 3]; + let cell_array: &Cell<[i32; 3]> = Cell::from_mut(&mut array); + let array_cell: &[Cell; 3] = cell_array.as_array_of_cells(); + + array_cell[0].set(99); + assert_eq!(array, [99, 2, 3]); } From 0ac601d03e0e0951f73d6a89cb6a5aef1905e29b Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 08:27:08 +0200 Subject: [PATCH 055/269] Mach-O (Macos/ios/...) LLD flavor is always LD64. --- compiler/rustc_target/src/spec/apple_base.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index cff0b3651e17..0a0c548fecd0 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -1,6 +1,6 @@ use std::env; -use crate::spec::{FramePointer, SplitDebuginfo, TargetOptions}; +use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions}; pub fn opts(os: &str) -> TargetOptions { // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6 @@ -35,6 +35,7 @@ pub fn opts(os: &str) -> TargetOptions { abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, eh_frame_header: false, + lld_flavor: LldFlavor::Ld64, // The historical default for macOS targets is to run `dsymutil` which // generates a packed version of debuginfo split from the main file. From a5190950546c1d62b5a1b476daae3a28f412df05 Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 09:28:07 +0200 Subject: [PATCH 056/269] Include ld64 nexte to ld for use with -Z gcc-ld --- src/bootstrap/compile.rs | 4 ++++ src/bootstrap/dist.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index d25989954783..2a6a05e8e509 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1121,6 +1121,10 @@ impl Step for Assemble { &lld_install.join("bin").join(&src_exe), &gcc_ld_dir.join(exe("ld", target_compiler.host)), ); + builder.copy( + &lld_install.join("bin").join(&src_exe), + &gcc_ld_dir.join(exe("ld64", target_compiler.host)), + ); } // Similarly, copy `llvm-dwp` into libdir for Split DWARF. Only copy it when the LLVM diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 64075e18366b..d0bcdb179e39 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -412,6 +412,8 @@ impl Step for Rustc { let gcc_lld_dir = dst_dir.join("gcc-ld"); t!(fs::create_dir(&gcc_lld_dir)); builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host))); + builder + .copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld64", compiler.host))); } // Copy over llvm-dwp if it's there From 0f7702efa1cbff1ae0552664dc814e9ac682c09c Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 09:32:19 +0200 Subject: [PATCH 057/269] Pass -fuse-ld=/path/to/ld64 if -Z gcc-ld and the lld_flavor for the target is Ld64 --- compiler/rustc_codegen_ssa/src/back/link.rs | 47 +++++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f3eb1e04d07d..08c6a951ffb9 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2485,20 +2485,39 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { if let LinkerFlavor::Gcc = flavor { match ld_impl { LdImpl::Lld => { - let tools_path = - sess.host_filesearch(PathKind::All).get_tools_search_paths(false); - let lld_path = tools_path - .into_iter() - .map(|p| p.join("gcc-ld")) - .find(|p| { - p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }).exists() - }) - .unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found")); - cmd.cmd().arg({ - let mut arg = OsString::from("-B"); - arg.push(lld_path); - arg - }); + if sess.target.lld_flavor == LldFlavor::Ld64 { + let tools_path = + sess.host_filesearch(PathKind::All).get_tools_search_paths(false); + let ld64_exe = tools_path + .into_iter() + .map(|p| p.join("gcc-ld")) + .map(|p| { + p.join(if sess.host.is_like_windows { "ld64.exe" } else { "ld64" }) + }) + .find(|p| p.exists()) + .unwrap_or_else(|| sess.fatal("rust-lld (as ld64) not found")); + cmd.cmd().arg({ + let mut arg = OsString::from("-fuse-ld="); + arg.push(ld64_exe); + arg + }); + } else { + let tools_path = + sess.host_filesearch(PathKind::All).get_tools_search_paths(false); + let lld_path = tools_path + .into_iter() + .map(|p| p.join("gcc-ld")) + .find(|p| { + p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }) + .exists() + }) + .unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found")); + cmd.cmd().arg({ + let mut arg = OsString::from("-B"); + arg.push(lld_path); + arg + }); + } } } } else { From c3fdefe14267e766e3a590fc5967168c5443c7ee Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 11:21:27 +0200 Subject: [PATCH 058/269] remove commented code --- compiler/rustc_middle/src/ty/layout.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 3b1990a3e675..671f956bf315 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -939,16 +939,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. assert!(scalar.valid_range.start <= start); - // scalar.valid_range = - // AllocationRange { start, end: scalar.valid_range.end }; scalar.valid_range.start = start; } if let Bound::Included(end) = end { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. assert!(scalar.valid_range.end >= end); - // scalar.valid_range = - // AllocationRange { start: scalar.valid_range.start, end }; scalar.valid_range.end = end; } From 225a4bf9222dbef88dc6fbefe437602e55decf1b Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 13:56:28 +0200 Subject: [PATCH 059/269] Removed fixed fixme --- compiler/rustc_target/src/abi/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 07687a4b104c..b30111c6788f 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1011,9 +1011,6 @@ impl Niche { let start = v.end.wrapping_add(1) & max_value; let end = v.end.wrapping_add(count) & max_value; - // If the `end` of our range is inside the valid range, - // then we ran out of invalid values. - // FIXME(eddyb) abstract this with a wraparound range type. if v.contains(end) { return None; } From d50abd024901176f8b21081713bf4a2779d9aadb Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 14:18:48 +0200 Subject: [PATCH 060/269] Use ref --- compiler/rustc_mir/src/interpret/validity.rs | 2 +- compiler/rustc_target/src/abi/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index 71e616ff560c..bf34430cece2 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -623,7 +623,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' scalar_layout: &ScalarAbi, ) -> InterpResult<'tcx> { let value = self.read_scalar(op)?; - let valid_range = scalar_layout.valid_range; + let valid_range = scalar_layout.valid_range.clone(); let AllocationRange { start: lo, end: hi } = valid_range; // Determine the allowed range // `max_hi` is as big as the size fits diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index b30111c6788f..c3ec9bb82336 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -985,7 +985,7 @@ impl Niche { } pub fn available(&self, cx: &C) -> u128 { - let Scalar { value, valid_range: v } = self.scalar; + let Scalar { value, valid_range: ref v } = self.scalar; let bits = value.size(cx).bits(); assert!(bits <= 128); let max_value = !0u128 >> (128 - bits); @@ -998,7 +998,7 @@ impl Niche { pub fn reserve(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> { assert!(count > 0); - let Scalar { value, valid_range: v } = self.scalar; + let Scalar { value, valid_range: ref v } = self.scalar; let bits = value.size(cx).bits(); assert!(bits <= 128); let max_value = !0u128 >> (128 - bits); From 70433955f4531f2742ddeb986e6ac19a8fd4792f Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 14:20:38 +0200 Subject: [PATCH 061/269] implement contains_zero method --- compiler/rustc_codegen_llvm/src/builder.rs | 3 +-- compiler/rustc_middle/src/ty/layout.rs | 6 ++---- compiler/rustc_target/src/abi/mod.rs | 12 +++++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 2b72b1674263..7986d1d9cb28 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -462,7 +462,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { load: &'ll Value, scalar: &abi::Scalar, ) { - let vr = scalar.valid_range; match scalar.value { abi::Int(..) => { let range = scalar.valid_range_exclusive(bx); @@ -470,7 +469,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { bx.range_metadata(load, range); } } - abi::Pointer if vr.start < vr.end && !vr.contains(0) => { + abi::Pointer if !scalar.valid_range.contains_zero() => { bx.nonnull_metadata(load); } _ => {} diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 671f956bf315..c6caab3e798f 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2857,10 +2857,8 @@ where return; } - if scalar.valid_range.start < scalar.valid_range.end { - if scalar.valid_range.start > 0 { - attrs.set(ArgAttribute::NonNull); - } + if !scalar.valid_range.contains_zero() { + attrs.set(ArgAttribute::NonNull); } if let Some(pointee) = layout.pointee_info_at(cx, offset) { diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index c3ec9bb82336..5ce8906e6ac6 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -688,7 +688,7 @@ impl Primitive { /// /// This is intended specifically to mirror LLVM’s `!range` metadata, /// semantics. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(HashStable_Generic)] pub struct AllocationRange { pub start: u128, @@ -705,6 +705,13 @@ impl AllocationRange { self.start <= v || v <= self.end } } + + /// Returns `true` if zero is contained in the range. + /// Equal to `range.contains(0)` but should be faster. + #[inline] + pub fn contains_zero(&self) -> bool { + !(self.start <= self.end && self.start != 0) + } } /// Information about one scalar component of a Rust type. @@ -1222,9 +1229,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { { let scalar_allows_raw_init = move |s: &Scalar| -> bool { if zero { - let range = &s.valid_range; // The range must contain 0. - range.contains(0) || (range.start > range.end) // wrap-around allows 0 + s.valid_range.contains_zero() } else { // The range must include all values. `valid_range_exclusive` handles // the wrap-around using target arithmetic; with wrap-around then the full From e8e6d9bd86c9cf685666718ca99e016275e1751b Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 14:24:34 +0200 Subject: [PATCH 062/269] Rename to WrappingRange --- compiler/rustc_codegen_llvm/src/consts.rs | 7 ++----- compiler/rustc_middle/src/ty/layout.rs | 16 ++++++++-------- compiler/rustc_mir/src/interpret/validity.rs | 8 ++++---- compiler/rustc_target/src/abi/mod.rs | 10 +++++----- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 01a93dd8857c..ec92bd686d2d 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::{bug, span_bug}; use rustc_target::abi::{ - AddressSpace, Align, AllocationRange, HasDataLayout, LayoutOf, Primitive, Scalar, Size, + AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size, WrappingRange, }; use tracing::debug; @@ -61,10 +61,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), &cx.tcx, ), - &Scalar { - value: Primitive::Pointer, - valid_range: AllocationRange { start: 0, end: !0 }, - }, + &Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } }, cx.type_i8p_ext(address_space), )); next_offset = offset + pointer_size; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index c6caab3e798f..6b628cb041b5 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let scalar_unit = |value: Primitive| { let bits = value.size(dl).bits(); assert!(bits <= 128); - Scalar { value, valid_range: AllocationRange { start: 0, end: (!0 >> (128 - bits)) } } + Scalar { value, valid_range: WrappingRange { start: 0, end: (!0 >> (128 - bits)) } } }; let scalar = |value: Primitive| tcx.intern_layout(Layout::scalar(self, scalar_unit(value))); @@ -512,13 +512,13 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Basic scalars. ty::Bool => tcx.intern_layout(Layout::scalar( self, - Scalar { value: Int(I8, false), valid_range: AllocationRange { start: 0, end: 1 } }, + Scalar { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 } }, )), ty::Char => tcx.intern_layout(Layout::scalar( self, Scalar { value: Int(I32, false), - valid_range: AllocationRange { start: 0, end: 0x10FFFF }, + valid_range: WrappingRange { start: 0, end: 0x10FFFF }, }, )), ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)), @@ -529,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }), ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer); - ptr.valid_range = AllocationRange { start: 1, end: ptr.valid_range.end }; + ptr.valid_range = WrappingRange { start: 1, end: ptr.valid_range.end }; tcx.intern_layout(Layout::scalar(self, ptr)) } @@ -548,7 +548,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let mut data_ptr = scalar_unit(Pointer); if !ty.is_unsafe_ptr() { data_ptr.valid_range = - AllocationRange { start: 1, end: data_ptr.valid_range.end }; + WrappingRange { start: 1, end: data_ptr.valid_range.end }; } let pointee = tcx.normalize_erasing_regions(param_env, pointee); @@ -565,7 +565,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); vtable.valid_range = - AllocationRange { start: 1, end: vtable.valid_range.end }; + WrappingRange { start: 1, end: vtable.valid_range.end }; vtable } _ => return Err(LayoutError::Unknown(unsized_part)), @@ -1261,7 +1261,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let tag_mask = !0u128 >> (128 - ity.size().bits()); let tag = Scalar { value: Int(ity, signed), - valid_range: AllocationRange { + valid_range: WrappingRange { start: (min as u128 & tag_mask), end: (max as u128 & tag_mask), }, @@ -1545,7 +1545,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let discr_int_ty = discr_int.to_ty(tcx, false); let tag = Scalar { value: Primitive::Int(discr_int, false), - valid_range: AllocationRange { start: 0, end: max_discr }, + valid_range: WrappingRange { start: 0, end: max_discr }, }; let tag_layout = self.tcx.intern_layout(Layout::scalar(self, tag.clone())); let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout }; diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index bf34430cece2..3ff149d6a7a2 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -15,7 +15,7 @@ use rustc_middle::ty; use rustc_middle::ty::layout::TyAndLayout; use rustc_span::symbol::{sym, Symbol}; use rustc_target::abi::{ - Abi, AllocationRange, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants, + Abi, LayoutOf, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange, }; use std::hash::Hash; @@ -184,8 +184,8 @@ fn write_path(out: &mut String, path: &[PathElem]) { // Formats such that a sentence like "expected something {}" to mean // "expected something " makes sense. -fn wrapping_range_format(r: AllocationRange, max_hi: u128) -> String { - let AllocationRange { start: lo, end: hi } = r; +fn wrapping_range_format(r: WrappingRange, max_hi: u128) -> String { + let WrappingRange { start: lo, end: hi } = r; assert!(hi <= max_hi); if lo > hi { format!("less or equal to {}, or greater or equal to {}", hi, lo) @@ -624,7 +624,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' ) -> InterpResult<'tcx> { let value = self.read_scalar(op)?; let valid_range = scalar_layout.valid_range.clone(); - let AllocationRange { start: lo, end: hi } = valid_range; + let WrappingRange { start: lo, end: hi } = valid_range; // Determine the allowed range // `max_hi` is as big as the size fits let max_hi = u128::MAX >> (128 - op.layout.size.bits()); diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 5ce8906e6ac6..d29b731e4f12 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -690,12 +690,12 @@ impl Primitive { /// semantics. #[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(HashStable_Generic)] -pub struct AllocationRange { +pub struct WrappingRange { pub start: u128, pub end: u128, } -impl AllocationRange { +impl WrappingRange { /// Returns `true` if `v` is contained in the range. #[inline] pub fn contains(&self, v: u128) -> bool { @@ -723,13 +723,13 @@ pub struct Scalar { // FIXME(eddyb) always use the shortest range, e.g., by finding // the largest space between two consecutive valid values and // taking everything else as the (shortest) valid range. - pub valid_range: AllocationRange, + pub valid_range: WrappingRange, } impl Scalar { pub fn is_bool(&self) -> bool { matches!(self.value, Int(I8, false)) - && matches!(self.valid_range, AllocationRange { start: 0, end: 1 }) + && matches!(self.valid_range, WrappingRange { start: 0, end: 1 }) } /// Returns the valid range as a `x..y` range. @@ -1022,7 +1022,7 @@ impl Niche { return None; } - Some((start, Scalar { value, valid_range: AllocationRange { start: v.start, end } })) + Some((start, Scalar { value, valid_range: WrappingRange { start: v.start, end } })) } } From d230b92ba7a2a32000be5e207860aa27d1a11113 Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 15:05:40 +0200 Subject: [PATCH 063/269] implement debug in similar way to RangeInclusive --- compiler/rustc_target/src/abi/mod.rs | 9 ++- .../consts/const-eval/ub-nonnull.32bit.stderr | 2 +- .../consts/const-eval/ub-nonnull.64bit.stderr | 2 +- src/test/ui/layout/debug.stderr | 45 +++-------- src/test/ui/layout/hexagon-enum.stderr | 75 ++++--------------- src/test/ui/layout/thumb-enum.stderr | 75 ++++--------------- 6 files changed, 49 insertions(+), 159 deletions(-) diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index d29b731e4f12..c9d0b12e7396 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -688,7 +688,7 @@ impl Primitive { /// /// This is intended specifically to mirror LLVM’s `!range` metadata, /// semantics. -#[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, PartialEq, Eq, Hash)] #[derive(HashStable_Generic)] pub struct WrappingRange { pub start: u128, @@ -714,6 +714,13 @@ impl WrappingRange { } } +impl fmt::Debug for WrappingRange { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(fmt, "{}..={}", self.start, self.end)?; + Ok(()) + } +} + /// Information about one scalar component of a Rust type. #[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(HashStable_Generic)] diff --git a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr index 01403a61e5e2..e44f32494548 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr @@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:41:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr index 41de900f1640..1ce87bc7c1ce 100644 --- a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr @@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value --> $DIR/ub-nonnull.rs:41:1 | LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30 | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr index cbe9b6400c35..1a371c6b1700 100644 --- a/src/test/ui/layout/debug.stderr +++ b/src/test/ui/layout/debug.stderr @@ -15,10 +15,7 @@ error: layout_of(E) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, tag_encoding: Direct, tag_field: 0, @@ -94,10 +91,7 @@ error: layout_of(E) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, }, ), @@ -144,20 +138,14 @@ error: layout_of(S) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 0, - end: 4294967295, - }, + valid_range: 0..=4294967295, }, Scalar { value: Int( I32, true, ), - valid_range: AllocationRange { - start: 0, - end: 4294967295, - }, + valid_range: 0..=4294967295, }, ), largest_niche: None, @@ -219,10 +207,7 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 0, - end: 1, - }, + valid_range: 0..=1, }, tag_encoding: Direct, tag_field: 0, @@ -291,20 +276,14 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 0, - end: 1, - }, + valid_range: 0..=1, }, Scalar { value: Int( I32, true, ), - valid_range: AllocationRange { - start: 0, - end: 4294967295, - }, + valid_range: 0..=4294967295, }, ), largest_niche: Some( @@ -317,10 +296,7 @@ error: layout_of(std::result::Result) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 0, - end: 1, - }, + valid_range: 0..=1, }, }, ), @@ -350,10 +326,7 @@ error: layout_of(i32) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 0, - end: 4294967295, - }, + valid_range: 0..=4294967295, }, ), largest_niche: None, diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr index 520ba12c39fb..d4676a5afb25 100644 --- a/src/test/ui/layout/hexagon-enum.stderr +++ b/src/test/ui/layout/hexagon-enum.stderr @@ -15,10 +15,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, tag_encoding: Direct, tag_field: 0, @@ -55,10 +52,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, ), largest_niche: Some( @@ -71,10 +65,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, }, ), @@ -112,10 +103,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, tag_encoding: Direct, tag_field: 0, @@ -152,10 +140,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, ), largest_niche: Some( @@ -168,10 +153,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, }, ), @@ -209,10 +191,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, tag_encoding: Direct, tag_field: 0, @@ -249,10 +228,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, ), largest_niche: Some( @@ -265,10 +241,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, }, ), @@ -306,10 +279,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, tag_encoding: Direct, tag_field: 0, @@ -346,10 +316,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, ), largest_niche: Some( @@ -362,10 +329,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, }, ), @@ -403,10 +367,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, tag_encoding: Direct, tag_field: 0, @@ -443,10 +404,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, ), largest_niche: Some( @@ -459,10 +417,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, }, ), diff --git a/src/test/ui/layout/thumb-enum.stderr b/src/test/ui/layout/thumb-enum.stderr index 50e37c541163..898a61b904db 100644 --- a/src/test/ui/layout/thumb-enum.stderr +++ b/src/test/ui/layout/thumb-enum.stderr @@ -15,10 +15,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, tag_encoding: Direct, tag_field: 0, @@ -55,10 +52,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, ), largest_niche: Some( @@ -71,10 +65,7 @@ error: layout_of(A) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 0, - end: 0, - }, + valid_range: 0..=0, }, }, ), @@ -112,10 +103,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, tag_encoding: Direct, tag_field: 0, @@ -152,10 +140,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, ), largest_niche: Some( @@ -168,10 +153,7 @@ error: layout_of(B) = Layout { I8, false, ), - valid_range: AllocationRange { - start: 255, - end: 255, - }, + valid_range: 255..=255, }, }, ), @@ -209,10 +191,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, tag_encoding: Direct, tag_field: 0, @@ -249,10 +228,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, ), largest_niche: Some( @@ -265,10 +241,7 @@ error: layout_of(C) = Layout { I16, false, ), - valid_range: AllocationRange { - start: 256, - end: 256, - }, + valid_range: 256..=256, }, }, ), @@ -306,10 +279,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, tag_encoding: Direct, tag_field: 0, @@ -346,10 +316,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, ), largest_niche: Some( @@ -362,10 +329,7 @@ error: layout_of(P) = Layout { I32, false, ), - valid_range: AllocationRange { - start: 268435456, - end: 268435456, - }, + valid_range: 268435456..=268435456, }, }, ), @@ -403,10 +367,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, tag_encoding: Direct, tag_field: 0, @@ -443,10 +404,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, ), largest_niche: Some( @@ -459,10 +417,7 @@ error: layout_of(T) = Layout { I32, true, ), - valid_range: AllocationRange { - start: 2164260864, - end: 2164260864, - }, + valid_range: 2164260864..=2164260864, }, }, ), From 32d7e5b723f97092e392abc33074d8e750a9cb23 Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 15:44:56 +0200 Subject: [PATCH 064/269] add `with_start` and `with_end` --- compiler/rustc_middle/src/ty/layout.rs | 8 +++----- compiler/rustc_target/src/abi/mod.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 6b628cb041b5..dcb56d5b2ba1 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -529,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }), ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer); - ptr.valid_range = WrappingRange { start: 1, end: ptr.valid_range.end }; + ptr.valid_range = ptr.valid_range.with_start(1); tcx.intern_layout(Layout::scalar(self, ptr)) } @@ -547,8 +547,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { let mut data_ptr = scalar_unit(Pointer); if !ty.is_unsafe_ptr() { - data_ptr.valid_range = - WrappingRange { start: 1, end: data_ptr.valid_range.end }; + data_ptr.valid_range = data_ptr.valid_range.with_start(1); } let pointee = tcx.normalize_erasing_regions(param_env, pointee); @@ -564,8 +563,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); - vtable.valid_range = - WrappingRange { start: 1, end: vtable.valid_range.end }; + vtable.valid_range = vtable.valid_range.with_start(1); vtable } _ => return Err(LayoutError::Unknown(unsized_part)), diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index c9d0b12e7396..6e2f8962eef4 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -712,6 +712,16 @@ impl WrappingRange { pub fn contains_zero(&self) -> bool { !(self.start <= self.end && self.start != 0) } + + /// Returns new `WrappingRange` with replaced `start` + pub fn with_start(&self, start: u128) -> Self { + Self { start, end: self.end } + } + + /// Returns new `WrappingRange` with replaced `end` + pub fn with_end(&self, end: u128) -> Self { + Self { start: self.start, end } + } } impl fmt::Debug for WrappingRange { @@ -1029,7 +1039,7 @@ impl Niche { return None; } - Some((start, Scalar { value, valid_range: WrappingRange { start: v.start, end } })) + Some((start, Scalar { value, valid_range: v.with_end(end) })) } } From d92810646ed517376b16ac3b1fed329d8df2a8a9 Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Mon, 23 Aug 2021 15:52:47 +0200 Subject: [PATCH 065/269] Simplify zero check --- compiler/rustc_target/src/abi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 6e2f8962eef4..b352243c0c44 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -710,7 +710,7 @@ impl WrappingRange { /// Equal to `range.contains(0)` but should be faster. #[inline] pub fn contains_zero(&self) -> bool { - !(self.start <= self.end && self.start != 0) + self.start > self.end || self.start == 0 } /// Returns new `WrappingRange` with replaced `start` From 385a233f1836191837e1a7e575425cf0ce1c9843 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Sat, 14 Aug 2021 21:38:37 -0400 Subject: [PATCH 066/269] Detect incorrect number of lang item generics --- .../src/error_codes/E0152.md | 2 +- compiler/rustc_hir/src/lang_items.rs | 314 +++++++++--------- compiler/rustc_passes/src/lang_items.rs | 122 ++----- src/test/ui/error-codes/E0152.rs | 2 +- src/test/ui/error-codes/E0152.stderr | 4 +- .../lang-items/lang-item-correct-generics.rs | 28 ++ .../lang-item-generic-requirements.rs | 44 +++ .../lang-item-generic-requirements.stderr | 56 ++++ .../wrong-number-generic-args-add.rs | 20 -- .../wrong-number-generic-args-add.stderr | 20 -- .../wrong-number-generic-args-index.rs | 19 -- .../wrong-number-generic-args-index.stderr | 18 - 12 files changed, 330 insertions(+), 319 deletions(-) create mode 100644 src/test/ui/lang-items/lang-item-correct-generics.rs create mode 100644 src/test/ui/lang-items/lang-item-generic-requirements.rs create mode 100644 src/test/ui/lang-items/lang-item-generic-requirements.stderr delete mode 100644 src/test/ui/lang-items/wrong-number-generic-args-add.rs delete mode 100644 src/test/ui/lang-items/wrong-number-generic-args-add.stderr delete mode 100644 src/test/ui/lang-items/wrong-number-generic-args-index.rs delete mode 100644 src/test/ui/lang-items/wrong-number-generic-args-index.stderr diff --git a/compiler/rustc_error_codes/src/error_codes/E0152.md b/compiler/rustc_error_codes/src/error_codes/E0152.md index 120c96b42110..ef17b8b4c75c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0152.md +++ b/compiler/rustc_error_codes/src/error_codes/E0152.md @@ -6,7 +6,7 @@ Erroneous code example: #![feature(lang_items)] #[lang = "owned_box"] -struct Foo; // error: duplicate lang item found: `owned_box` +struct Foo(T); // error: duplicate lang item found: `owned_box` ``` Lang items are already implemented in the standard library. Unless you are diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 55000ae7e59d..b85ed0cb4bbe 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -38,7 +38,7 @@ macro_rules! expand_group { // So you probably just want to nip down to the end. macro_rules! language_item_table { ( - $( $(#[$attr:meta])* $variant:ident $($group:expr)?, $module:ident :: $name:ident, $method:ident, $target:expr; )* + $( $(#[$attr:meta])* $variant:ident $($group:expr)?, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )* ) => { enum_from_u32! { @@ -72,6 +72,12 @@ macro_rules! language_item_table { $( LangItem::$variant => expand_group!($($group)*), )* } } + + pub fn required_generics(&self) -> GenericRequirement { + match self { + $( LangItem::$variant => $generics, )* + } + } } /// All of the language items, defined or not. @@ -165,108 +171,108 @@ where } language_item_table! { -// Variant name, Name, Method name, Target; - Bool, sym::bool, bool_impl, Target::Impl; - Char, sym::char, char_impl, Target::Impl; - Str, sym::str, str_impl, Target::Impl; - Array, sym::array, array_impl, Target::Impl; - Slice, sym::slice, slice_impl, Target::Impl; - SliceU8, sym::slice_u8, slice_u8_impl, Target::Impl; - StrAlloc, sym::str_alloc, str_alloc_impl, Target::Impl; - SliceAlloc, sym::slice_alloc, slice_alloc_impl, Target::Impl; - SliceU8Alloc, sym::slice_u8_alloc, slice_u8_alloc_impl, Target::Impl; - ConstPtr, sym::const_ptr, const_ptr_impl, Target::Impl; - MutPtr, sym::mut_ptr, mut_ptr_impl, Target::Impl; - ConstSlicePtr, sym::const_slice_ptr, const_slice_ptr_impl, Target::Impl; - MutSlicePtr, sym::mut_slice_ptr, mut_slice_ptr_impl, Target::Impl; - I8, sym::i8, i8_impl, Target::Impl; - I16, sym::i16, i16_impl, Target::Impl; - I32, sym::i32, i32_impl, Target::Impl; - I64, sym::i64, i64_impl, Target::Impl; - I128, sym::i128, i128_impl, Target::Impl; - Isize, sym::isize, isize_impl, Target::Impl; - U8, sym::u8, u8_impl, Target::Impl; - U16, sym::u16, u16_impl, Target::Impl; - U32, sym::u32, u32_impl, Target::Impl; - U64, sym::u64, u64_impl, Target::Impl; - U128, sym::u128, u128_impl, Target::Impl; - Usize, sym::usize, usize_impl, Target::Impl; - F32, sym::f32, f32_impl, Target::Impl; - F64, sym::f64, f64_impl, Target::Impl; - F32Runtime, sym::f32_runtime, f32_runtime_impl, Target::Impl; - F64Runtime, sym::f64_runtime, f64_runtime_impl, Target::Impl; - - Sized, sym::sized, sized_trait, Target::Trait; - Unsize, sym::unsize, unsize_trait, Target::Trait; +// Variant name, Name, Method name, Target Generic requirements; + Bool, sym::bool, bool_impl, Target::Impl, GenericRequirement::None; + Char, sym::char, char_impl, Target::Impl, GenericRequirement::None; + Str, sym::str, str_impl, Target::Impl, GenericRequirement::None; + Array, sym::array, array_impl, Target::Impl, GenericRequirement::None; + Slice, sym::slice, slice_impl, Target::Impl, GenericRequirement::None; + SliceU8, sym::slice_u8, slice_u8_impl, Target::Impl, GenericRequirement::None; + StrAlloc, sym::str_alloc, str_alloc_impl, Target::Impl, GenericRequirement::None; + SliceAlloc, sym::slice_alloc, slice_alloc_impl, Target::Impl, GenericRequirement::None; + SliceU8Alloc, sym::slice_u8_alloc, slice_u8_alloc_impl, Target::Impl, GenericRequirement::None; + ConstPtr, sym::const_ptr, const_ptr_impl, Target::Impl, GenericRequirement::None; + MutPtr, sym::mut_ptr, mut_ptr_impl, Target::Impl, GenericRequirement::None; + ConstSlicePtr, sym::const_slice_ptr, const_slice_ptr_impl, Target::Impl, GenericRequirement::None; + MutSlicePtr, sym::mut_slice_ptr, mut_slice_ptr_impl, Target::Impl, GenericRequirement::None; + I8, sym::i8, i8_impl, Target::Impl, GenericRequirement::None; + I16, sym::i16, i16_impl, Target::Impl, GenericRequirement::None; + I32, sym::i32, i32_impl, Target::Impl, GenericRequirement::None; + I64, sym::i64, i64_impl, Target::Impl, GenericRequirement::None; + I128, sym::i128, i128_impl, Target::Impl, GenericRequirement::None; + Isize, sym::isize, isize_impl, Target::Impl, GenericRequirement::None; + U8, sym::u8, u8_impl, Target::Impl, GenericRequirement::None; + U16, sym::u16, u16_impl, Target::Impl, GenericRequirement::None; + U32, sym::u32, u32_impl, Target::Impl, GenericRequirement::None; + U64, sym::u64, u64_impl, Target::Impl, GenericRequirement::None; + U128, sym::u128, u128_impl, Target::Impl, GenericRequirement::None; + Usize, sym::usize, usize_impl, Target::Impl, GenericRequirement::None; + F32, sym::f32, f32_impl, Target::Impl, GenericRequirement::None; + F64, sym::f64, f64_impl, Target::Impl, GenericRequirement::None; + F32Runtime, sym::f32_runtime, f32_runtime_impl, Target::Impl, GenericRequirement::None; + F64Runtime, sym::f64_runtime, f64_runtime_impl, Target::Impl, GenericRequirement::None; + + Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0); + Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1); /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ"). - StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait; + StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None; /// Trait injected by `#[derive(Eq)]`, (i.e. "Total EQ"; no, I will not apologize). - StructuralTeq, sym::structural_teq, structural_teq_trait, Target::Trait; - Copy, sym::copy, copy_trait, Target::Trait; - Clone, sym::clone, clone_trait, Target::Trait; - Sync, sym::sync, sync_trait, Target::Trait; - DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait; + StructuralTeq, sym::structural_teq, structural_teq_trait, Target::Trait, GenericRequirement::None; + Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0); + Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None; + Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0); + DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None; /// The associated item of the [`DiscriminantKind`] trait. - Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy; - - PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait; - Metadata, sym::metadata_type, metadata_type, Target::AssocTy; - DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct; - - Freeze, sym::freeze, freeze_trait, Target::Trait; - - Drop, sym::drop, drop_trait, Target::Trait; - - CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait; - DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait; - - Add(Op), sym::add, add_trait, Target::Trait; - Sub(Op), sym::sub, sub_trait, Target::Trait; - Mul(Op), sym::mul, mul_trait, Target::Trait; - Div(Op), sym::div, div_trait, Target::Trait; - Rem(Op), sym::rem, rem_trait, Target::Trait; - Neg(Op), sym::neg, neg_trait, Target::Trait; - Not(Op), sym::not, not_trait, Target::Trait; - BitXor(Op), sym::bitxor, bitxor_trait, Target::Trait; - BitAnd(Op), sym::bitand, bitand_trait, Target::Trait; - BitOr(Op), sym::bitor, bitor_trait, Target::Trait; - Shl(Op), sym::shl, shl_trait, Target::Trait; - Shr(Op), sym::shr, shr_trait, Target::Trait; - AddAssign(Op), sym::add_assign, add_assign_trait, Target::Trait; - SubAssign(Op), sym::sub_assign, sub_assign_trait, Target::Trait; - MulAssign(Op), sym::mul_assign, mul_assign_trait, Target::Trait; - DivAssign(Op), sym::div_assign, div_assign_trait, Target::Trait; - RemAssign(Op), sym::rem_assign, rem_assign_trait, Target::Trait; - BitXorAssign(Op), sym::bitxor_assign, bitxor_assign_trait, Target::Trait; - BitAndAssign(Op), sym::bitand_assign, bitand_assign_trait, Target::Trait; - BitOrAssign(Op), sym::bitor_assign, bitor_assign_trait, Target::Trait; - ShlAssign(Op), sym::shl_assign, shl_assign_trait, Target::Trait; - ShrAssign(Op), sym::shr_assign, shr_assign_trait, Target::Trait; - Index(Op), sym::index, index_trait, Target::Trait; - IndexMut(Op), sym::index_mut, index_mut_trait, Target::Trait; - - UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct; - VaList, sym::va_list, va_list, Target::Struct; - - Deref, sym::deref, deref_trait, Target::Trait; - DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait; - DerefTarget, sym::deref_target, deref_target, Target::AssocTy; - Receiver, sym::receiver, receiver_trait, Target::Trait; - - Fn, kw::Fn, fn_trait, Target::Trait; - FnMut, sym::fn_mut, fn_mut_trait, Target::Trait; - FnOnce, sym::fn_once, fn_once_trait, Target::Trait; - - FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy; - - Future, sym::future_trait, future_trait, Target::Trait; - GeneratorState, sym::generator_state, gen_state, Target::Enum; - Generator, sym::generator, gen_trait, Target::Trait; - Unpin, sym::unpin, unpin_trait, Target::Trait; - Pin, sym::pin, pin_type, Target::Struct; - - PartialEq, sym::eq, eq_trait, Target::Trait; - PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait; + Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None; + + PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None; + Metadata, sym::metadata_type, metadata_type, Target::AssocTy, GenericRequirement::None; + DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None; + + Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0); + + Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None; + + CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1); + DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1); + + Add(Op), sym::add, add_trait, Target::Trait, GenericRequirement::Exact(1); + Sub(Op), sym::sub, sub_trait, Target::Trait, GenericRequirement::Exact(1); + Mul(Op), sym::mul, mul_trait, Target::Trait, GenericRequirement::Exact(1); + Div(Op), sym::div, div_trait, Target::Trait, GenericRequirement::Exact(1); + Rem(Op), sym::rem, rem_trait, Target::Trait, GenericRequirement::Exact(1); + Neg(Op), sym::neg, neg_trait, Target::Trait, GenericRequirement::Exact(0); + Not(Op), sym::not, not_trait, Target::Trait, GenericRequirement::Exact(0); + BitXor(Op), sym::bitxor, bitxor_trait, Target::Trait, GenericRequirement::Exact(1); + BitAnd(Op), sym::bitand, bitand_trait, Target::Trait, GenericRequirement::Exact(1); + BitOr(Op), sym::bitor, bitor_trait, Target::Trait, GenericRequirement::Exact(1); + Shl(Op), sym::shl, shl_trait, Target::Trait, GenericRequirement::Exact(1); + Shr(Op), sym::shr, shr_trait, Target::Trait, GenericRequirement::Exact(1); + AddAssign(Op), sym::add_assign, add_assign_trait, Target::Trait, GenericRequirement::Exact(1); + SubAssign(Op), sym::sub_assign, sub_assign_trait, Target::Trait, GenericRequirement::Exact(1); + MulAssign(Op), sym::mul_assign, mul_assign_trait, Target::Trait, GenericRequirement::Exact(1); + DivAssign(Op), sym::div_assign, div_assign_trait, Target::Trait, GenericRequirement::Exact(1); + RemAssign(Op), sym::rem_assign, rem_assign_trait, Target::Trait, GenericRequirement::Exact(1); + BitXorAssign(Op), sym::bitxor_assign, bitxor_assign_trait, Target::Trait, GenericRequirement::Exact(1); + BitAndAssign(Op), sym::bitand_assign, bitand_assign_trait, Target::Trait, GenericRequirement::Exact(1); + BitOrAssign(Op), sym::bitor_assign, bitor_assign_trait, Target::Trait, GenericRequirement::Exact(1); + ShlAssign(Op), sym::shl_assign, shl_assign_trait, Target::Trait, GenericRequirement::Exact(1); + ShrAssign(Op), sym::shr_assign, shr_assign_trait, Target::Trait, GenericRequirement::Exact(1); + Index(Op), sym::index, index_trait, Target::Trait, GenericRequirement::Exact(1); + IndexMut(Op), sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1); + + UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None; + VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None; + + Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0); + DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0); + DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None; + Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None; + + Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1); + FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); + FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1); + + FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; + + Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); + GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None; + Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1); + Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None; + Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None; + + PartialEq, sym::eq, eq_trait, Target::Trait, GenericRequirement::Exact(1); + PartialOrd, sym::partial_ord, partial_ord_trait, Target::Trait, GenericRequirement::Exact(1); // A number of panic-related lang items. The `panic` item corresponds to divide-by-zero and // various panic cases with `match`. The `panic_bounds_check` item is for indexing arrays. @@ -275,80 +281,86 @@ language_item_table! { // in the sense that a crate is not required to have it defined to use it, but a final product // is required to define it somewhere. Additionally, there are restrictions on crates that use // a weak lang item, but do not have it defined. - Panic, sym::panic, panic_fn, Target::Fn; - PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn; - PanicStr, sym::panic_str, panic_str, Target::Fn; - ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn; - PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn; - PanicInfo, sym::panic_info, panic_info, Target::Struct; - PanicLocation, sym::panic_location, panic_location, Target::Struct; - PanicImpl, sym::panic_impl, panic_impl, Target::Fn; + Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::None; + PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None; + PanicStr, sym::panic_str, panic_str, Target::Fn, GenericRequirement::None; + ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None; + PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::None; + PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None; + PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None; + PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None; /// libstd panic entry point. Necessary for const eval to be able to catch it - BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn; - BeginPanicFmt, sym::begin_panic_fmt, begin_panic_fmt, Target::Fn; + BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None; + BeginPanicFmt, sym::begin_panic_fmt, begin_panic_fmt, Target::Fn, GenericRequirement::None; - ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn; - BoxFree, sym::box_free, box_free_fn, Target::Fn; - DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn; - Oom, sym::oom, oom, Target::Fn; - AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct; + ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None; + BoxFree, sym::box_free, box_free_fn, Target::Fn, GenericRequirement::Minimum(1); + DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); + Oom, sym::oom, oom, Target::Fn, GenericRequirement::None; + AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None; - Start, sym::start, start_fn, Target::Fn; + Start, sym::start, start_fn, Target::Fn, GenericRequirement::None; - EhPersonality, sym::eh_personality, eh_personality, Target::Fn; - EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static; + EhPersonality, sym::eh_personality, eh_personality, Target::Fn, GenericRequirement::None; + EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None; - OwnedBox, sym::owned_box, owned_box, Target::Struct; + OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1); - PhantomData, sym::phantom_data, phantom_data, Target::Struct; + PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1); - ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct; + ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::None; - MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union; + MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None; /// Align offset for stride != 1; must not panic. - AlignOffset, sym::align_offset, align_offset_fn, Target::Fn; + AlignOffset, sym::align_offset, align_offset_fn, Target::Fn, GenericRequirement::None; - Termination, sym::termination, termination, Target::Trait; + Termination, sym::termination, termination, Target::Trait, GenericRequirement::None; - Try, sym::Try, try_trait, Target::Trait; + Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None; - SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent); + SliceLen, sym::slice_len_fn, slice_len_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None; // Language items from AST lowering - TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }); - TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }); - TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }); + TryTraitFromResidual, sym::from_residual, from_residual_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + TryTraitFromOutput, sym::from_output, from_output_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + + PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None; + PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None; - PollReady, sym::Ready, poll_ready_variant, Target::Variant; - PollPending, sym::Pending, poll_pending_variant, Target::Variant; + FromGenerator, sym::from_generator, from_generator_fn, Target::Fn, GenericRequirement::None; + GetContext, sym::get_context, get_context_fn, Target::Fn, GenericRequirement::None; - FromGenerator, sym::from_generator, from_generator_fn, Target::Fn; - GetContext, sym::get_context, get_context_fn, Target::Fn; + FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; - FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }); + FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; - FromFrom, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }); + OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None; + OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None; - OptionSome, sym::Some, option_some_variant, Target::Variant; - OptionNone, sym::None, option_none_variant, Target::Variant; + ResultOk, sym::Ok, result_ok_variant, Target::Variant, GenericRequirement::None; + ResultErr, sym::Err, result_err_variant, Target::Variant, GenericRequirement::None; - ResultOk, sym::Ok, result_ok_variant, Target::Variant; - ResultErr, sym::Err, result_err_variant, Target::Variant; + ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant, GenericRequirement::None; + ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant, GenericRequirement::None; - ControlFlowContinue, sym::Continue, cf_continue_variant, Target::Variant; - ControlFlowBreak, sym::Break, cf_break_variant, Target::Variant; + IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None; - IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }); - IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}); + PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None; - PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent); + RangeFrom, sym::RangeFrom, range_from_struct, Target::Struct, GenericRequirement::None; + RangeFull, sym::RangeFull, range_full_struct, Target::Struct, GenericRequirement::None; + RangeInclusiveStruct, sym::RangeInclusive, range_inclusive_struct, Target::Struct, GenericRequirement::None; + RangeInclusiveNew, sym::range_inclusive_new, range_inclusive_new_method, Target::Method(MethodKind::Inherent), GenericRequirement::None; + Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None; + RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None; + RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None; +} - RangeFrom, sym::RangeFrom, range_from_struct, Target::Struct; - RangeFull, sym::RangeFull, range_full_struct, Target::Struct; - RangeInclusiveStruct, sym::RangeInclusive, range_inclusive_struct, Target::Struct; - RangeInclusiveNew, sym::range_inclusive_new, range_inclusive_new_method, Target::Method(MethodKind::Inherent); - Range, sym::Range, range_struct, Target::Struct; - RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct; - RangeTo, sym::RangeTo, range_to_struct, Target::Struct; +pub enum GenericRequirement { + None, + Minimum(usize), + Exact(usize), } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 3a88d1932a80..9d449589b162 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -17,7 +17,7 @@ use rustc_errors::{pluralize, struct_span_err}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; -use rustc_hir::lang_items::{extract, ITEM_REFS}; +use rustc_hir::lang_items::{extract, GenericRequirement, ITEM_REFS}; use rustc_hir::{HirId, LangItem, LanguageItems, Target}; use rustc_span::Span; @@ -182,97 +182,39 @@ impl LanguageItemCollector<'tcx> { } // Like collect_item() above, but also checks whether the lang item is declared - // with the right number of generic arguments if it is a trait. + // with the right number of generic arguments. fn collect_item_extended(&mut self, item_index: usize, hir_id: HirId, span: Span) { let item_def_id = self.tcx.hir().local_def_id(hir_id).to_def_id(); let lang_item = LangItem::from_u32(item_index as u32).unwrap(); let name = lang_item.name(); - self.collect_item(item_index, item_def_id); - // Now check whether the lang_item has the expected number of generic - // arguments if it is a trait. Generally speaking, binary and indexing - // operations have one (for the RHS/index), unary operations have none, - // and the rest also have none except for the closure traits (one for - // the argument list), generators (one for the resume argument), - // ordering/equality relations (one for the RHS), and various conversion - // traits. - - let expected_num = match lang_item { - // Binary operations - LangItem::Add - | LangItem::Sub - | LangItem::Mul - | LangItem::Div - | LangItem::Rem - | LangItem::BitXor - | LangItem::BitAnd - | LangItem::BitOr - | LangItem::Shl - | LangItem::Shr - | LangItem::AddAssign - | LangItem::SubAssign - | LangItem::MulAssign - | LangItem::DivAssign - | LangItem::RemAssign - | LangItem::BitXorAssign - | LangItem::BitAndAssign - | LangItem::BitOrAssign - | LangItem::ShlAssign - | LangItem::ShrAssign - | LangItem::Index - | LangItem::IndexMut - - // Miscellaneous - | LangItem::Unsize - | LangItem::CoerceUnsized - | LangItem::DispatchFromDyn - | LangItem::Fn - | LangItem::FnMut - | LangItem::FnOnce - | LangItem::Generator - | LangItem::PartialEq - | LangItem::PartialOrd - => Some(1), - - // Unary operations - LangItem::Neg - | LangItem::Not - - // Miscellaneous - | LangItem::Deref - | LangItem::DerefMut - | LangItem::Sized - | LangItem::StructuralPeq - | LangItem::StructuralTeq - | LangItem::Copy - | LangItem::Clone - | LangItem::Sync - | LangItem::DiscriminantKind - | LangItem::PointeeTrait - | LangItem::Freeze - | LangItem::Drop - | LangItem::Receiver - | LangItem::Future - | LangItem::Unpin - | LangItem::Termination - | LangItem::Try - => Some(0), + // arguments. Generally speaking, binary and indexing operations have + // one (for the RHS/index), unary operations have none, the closure + // traits have one for the argument list, generators have one for the + // resume argument, and ordering/equality relations have one for the RHS + // Some other types like Box and various functions like drop_in_place + // have minimum requirements. - // Not a trait - _ => None, - }; + if let hir::Node::Item(hir::Item { kind, span: item_span, .. }) = self.tcx.hir().get(hir_id) + { + let (actual_num, generics_span) = match kind.generics() { + Some(generics) => (generics.params.len(), generics.span), + None => (0, *item_span), + }; - if let Some(expected_num) = expected_num { - let (actual_num, generics_span) = match self.tcx.hir().get(hir_id) { - hir::Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, generics, ..), - .. - }) => (generics.params.len(), generics.span), - _ => bug!("op/index/deref lang item target is not a trait: {:?}", lang_item), + let required = match lang_item.required_generics() { + GenericRequirement::Exact(num) if num != actual_num => { + Some((format!("{}", num), pluralize!(num))) + } + GenericRequirement::Minimum(num) if actual_num < num => { + Some((format!("at least {}", num), pluralize!(num))) + } + // If the number matches, or there is no requirement, handle it normally + _ => None, }; - if expected_num != actual_num { + if let Some((range_str, pluralized)) = required { // We are issuing E0718 "incorrect target" here, because while the // item kind of the target is correct, the target is still wrong // because of the wrong number of generic arguments. @@ -280,23 +222,29 @@ impl LanguageItemCollector<'tcx> { self.tcx.sess, span, E0718, - "`{}` language item must be applied to a trait with {} generic argument{}", + "`{}` language item must be applied to a {} with {} generic argument{}", name, - expected_num, - pluralize!(expected_num) + kind.descr(), + range_str, + pluralized, ) .span_label( generics_span, format!( - "this trait has {} generic argument{}, not {}", + "this {} has {} generic argument{}", + kind.descr(), actual_num, pluralize!(actual_num), - expected_num ), ) .emit(); + + // return early to not collect the lang item + return; } } + + self.collect_item(item_index, item_def_id); } } diff --git a/src/test/ui/error-codes/E0152.rs b/src/test/ui/error-codes/E0152.rs index d716ca1a14fd..ee8e5e6dffee 100644 --- a/src/test/ui/error-codes/E0152.rs +++ b/src/test/ui/error-codes/E0152.rs @@ -2,7 +2,7 @@ #![feature(lang_items)] #[lang = "owned_box"] -struct Foo; //~ ERROR E0152 +struct Foo(T); //~ ERROR E0152 fn main() { } diff --git a/src/test/ui/error-codes/E0152.stderr b/src/test/ui/error-codes/E0152.stderr index 7445c2880af1..5cdfe1cc5562 100644 --- a/src/test/ui/error-codes/E0152.stderr +++ b/src/test/ui/error-codes/E0152.stderr @@ -1,8 +1,8 @@ error[E0152]: found duplicate lang item `owned_box` --> $DIR/E0152.rs:5:1 | -LL | struct Foo; - | ^^^^^^^^^^^ +LL | struct Foo(T); + | ^^^^^^^^^^^^^^^^^ | = note: the lang item is first defined in crate `alloc` (which `std` depends on) = note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib diff --git a/src/test/ui/lang-items/lang-item-correct-generics.rs b/src/test/ui/lang-items/lang-item-correct-generics.rs new file mode 100644 index 000000000000..a3287db74e73 --- /dev/null +++ b/src/test/ui/lang-items/lang-item-correct-generics.rs @@ -0,0 +1,28 @@ +// build-pass + +#![feature(lang_items,no_core)] +#![no_core] +#![crate_type="lib"] + +#[lang = "sized"] +trait MySized {} + +#[lang = "copy"] +trait MyCopy {} + +#[lang = "drop"] +trait MyDrop {} + +struct S; + +impl MyDrop for S {} + +#[lang = "i32"] +impl<'a> i32 { + fn foo() {} +} + +fn bar() { + i32::foo(); + S; +} diff --git a/src/test/ui/lang-items/lang-item-generic-requirements.rs b/src/test/ui/lang-items/lang-item-generic-requirements.rs new file mode 100644 index 000000000000..d785749afc9c --- /dev/null +++ b/src/test/ui/lang-items/lang-item-generic-requirements.rs @@ -0,0 +1,44 @@ +// Checks whether declaring a lang item with the wrong number +// of generic arguments crashes the compiler (issue #83893, #87573, and part of #9307). + +#![feature(lang_items, no_core)] +#![no_core] +#![crate_type = "lib"] + +#[lang = "sized"] +trait MySized {} + +#[lang = "add"] +trait MyAdd<'a, T> {} +//~^^ ERROR: `add` language item must be applied to a trait with 1 generic argument [E0718] + +#[lang = "drop_in_place"] +//~^ ERROR `drop_in_place` language item must be applied to a function with at least 1 generic +fn my_ptr_drop() {} + +#[lang = "index"] +trait MyIndex<'a, T> {} +//~^^ ERROR: `index` language item must be applied to a trait with 1 generic argument [E0718] + +#[lang = "phantom_data"] +//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument +struct MyPhantomData; +//~^ ERROR parameter `T` is never used +//~| ERROR parameter `U` is never used + +fn ice() { + // Use add + let r = 5; + let a = 6; + r + a; + + // Use drop in place + my_ptr_drop(); + + // Use index + let arr = [0; 5]; + let _ = arr[2]; + + // Use phantomdata + let _ = MyPhantomData::<(), i32>; +} diff --git a/src/test/ui/lang-items/lang-item-generic-requirements.stderr b/src/test/ui/lang-items/lang-item-generic-requirements.stderr new file mode 100644 index 000000000000..add5938811c2 --- /dev/null +++ b/src/test/ui/lang-items/lang-item-generic-requirements.stderr @@ -0,0 +1,56 @@ +error[E0718]: `add` language item must be applied to a trait with 1 generic argument + --> $DIR/lang-item-generic-requirements.rs:11:1 + | +LL | #[lang = "add"] + | ^^^^^^^^^^^^^^^ +LL | trait MyAdd<'a, T> {} + | ------- this trait has 2 generic arguments + +error[E0718]: `drop_in_place` language item must be applied to a function with at least 1 generic argument + --> $DIR/lang-item-generic-requirements.rs:15:1 + | +LL | #[lang = "drop_in_place"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | fn my_ptr_drop() {} + | - this function has 0 generic arguments + +error[E0718]: `index` language item must be applied to a trait with 1 generic argument + --> $DIR/lang-item-generic-requirements.rs:19:1 + | +LL | #[lang = "index"] + | ^^^^^^^^^^^^^^^^^ +LL | trait MyIndex<'a, T> {} + | ------- this trait has 2 generic arguments + +error[E0718]: `phantom_data` language item must be applied to a struct with 1 generic argument + --> $DIR/lang-item-generic-requirements.rs:23:1 + | +LL | #[lang = "phantom_data"] + | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | struct MyPhantomData; + | ------ this struct has 2 generic arguments + +error[E0392]: parameter `T` is never used + --> $DIR/lang-item-generic-requirements.rs:25:22 + | +LL | struct MyPhantomData; + | ^ unused parameter + | + = help: consider removing `T` or referring to it in a field + = help: if you intended `T` to be a const parameter, use `const T: usize` instead + +error[E0392]: parameter `U` is never used + --> $DIR/lang-item-generic-requirements.rs:25:25 + | +LL | struct MyPhantomData; + | ^ unused parameter + | + = help: consider removing `U` or referring to it in a field + = help: if you intended `U` to be a const parameter, use `const U: usize` instead + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0392, E0718. +For more information about an error, try `rustc --explain E0392`. diff --git a/src/test/ui/lang-items/wrong-number-generic-args-add.rs b/src/test/ui/lang-items/wrong-number-generic-args-add.rs deleted file mode 100644 index 9f4f2464a1e6..000000000000 --- a/src/test/ui/lang-items/wrong-number-generic-args-add.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Checks whether declaring a lang item with the wrong number -// of generic arguments crashes the compiler (issue #83893). - -#![feature(lang_items,no_core)] -#![no_core] -#![crate_type="lib"] - -#[lang = "sized"] -trait MySized {} - -#[lang = "add"] -trait MyAdd<'a, T> {} -//~^^ ERROR: `add` language item must be applied to a trait with 1 generic argument [E0718] - -fn ice() { - let r = 5; - let a = 6; - r + a - //~^ ERROR: cannot add `{integer}` to `{integer}` [E0369] -} diff --git a/src/test/ui/lang-items/wrong-number-generic-args-add.stderr b/src/test/ui/lang-items/wrong-number-generic-args-add.stderr deleted file mode 100644 index 6f89441fd285..000000000000 --- a/src/test/ui/lang-items/wrong-number-generic-args-add.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0718]: `add` language item must be applied to a trait with 1 generic argument - --> $DIR/wrong-number-generic-args-add.rs:11:1 - | -LL | #[lang = "add"] - | ^^^^^^^^^^^^^^^ -LL | trait MyAdd<'a, T> {} - | ------- this trait has 2 generic arguments, not 1 - -error[E0369]: cannot add `{integer}` to `{integer}` - --> $DIR/wrong-number-generic-args-add.rs:18:7 - | -LL | r + a - | - ^ - {integer} - | | - | {integer} - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0369, E0718. -For more information about an error, try `rustc --explain E0369`. diff --git a/src/test/ui/lang-items/wrong-number-generic-args-index.rs b/src/test/ui/lang-items/wrong-number-generic-args-index.rs deleted file mode 100644 index 1d90e63dc547..000000000000 --- a/src/test/ui/lang-items/wrong-number-generic-args-index.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Checks whether declaring a lang item with the wrong number -// of generic arguments crashes the compiler (issue #83893). - -#![feature(lang_items,no_core)] -#![no_core] -#![crate_type="lib"] - -#[lang = "sized"] -trait MySized {} - -#[lang = "index"] -trait MyIndex<'a, T> {} -//~^^ ERROR: `index` language item must be applied to a trait with 1 generic argument [E0718] - -fn ice() { - let arr = [0; 5]; - let _ = arr[2]; - //~^ ERROR: cannot index into a value of type `[{integer}; 5]` [E0608] -} diff --git a/src/test/ui/lang-items/wrong-number-generic-args-index.stderr b/src/test/ui/lang-items/wrong-number-generic-args-index.stderr deleted file mode 100644 index bc3f19ff2762..000000000000 --- a/src/test/ui/lang-items/wrong-number-generic-args-index.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0718]: `index` language item must be applied to a trait with 1 generic argument - --> $DIR/wrong-number-generic-args-index.rs:11:1 - | -LL | #[lang = "index"] - | ^^^^^^^^^^^^^^^^^ -LL | trait MyIndex<'a, T> {} - | ------- this trait has 2 generic arguments, not 1 - -error[E0608]: cannot index into a value of type `[{integer}; 5]` - --> $DIR/wrong-number-generic-args-index.rs:17:13 - | -LL | let _ = arr[2]; - | ^^^^^^ - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0608, E0718. -For more information about an error, try `rustc --explain E0608`. From e8910440a24ecb2ddb08b4dbe170488ddf61fc87 Mon Sep 17 00:00:00 2001 From: liudingming Date: Mon, 9 Aug 2021 20:25:57 +0800 Subject: [PATCH 067/269] select obligations after `check_casts` Otherwise, we can get into a situation where you have a subtype obligation `#1 <: #2` pending, #1 is constrained by `check_casts`, but #2` is unaffected. Co-authored-by: Niko Matsakis --- compiler/rustc_typeck/src/check/fallback.rs | 6 +++++- compiler/rustc_typeck/src/check/mod.rs | 3 ++- compiler/rustc_typeck/src/expr_use_visitor.rs | 10 ++++++++-- .../closures/2229_closure_analysis/issue_88118.rs | 14 ++++++++++++++ src/test/ui/closures/issue-87814-1.rs | 8 ++++++++ src/test/ui/closures/issue-87814-2.rs | 11 +++++++++++ 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/closures/2229_closure_analysis/issue_88118.rs create mode 100644 src/test/ui/closures/issue-87814-1.rs create mode 100644 src/test/ui/closures/issue-87814-2.rs diff --git a/compiler/rustc_typeck/src/check/fallback.rs b/compiler/rustc_typeck/src/check/fallback.rs index 69a8970ae094..8f6cdc7bb12a 100644 --- a/compiler/rustc_typeck/src/check/fallback.rs +++ b/compiler/rustc_typeck/src/check/fallback.rs @@ -3,7 +3,9 @@ use rustc_infer::infer::type_variable::Diverging; use rustc_middle::ty::{self, Ty}; impl<'tcx> FnCtxt<'_, 'tcx> { - pub(super) fn type_inference_fallback(&self) { + /// Performs type inference fallback, returning true if any fallback + /// occurs. + pub(super) fn type_inference_fallback(&self) -> bool { // All type checking constraints were added, try to fallback unsolved variables. self.select_obligations_where_possible(false, |_| {}); let mut fallback_has_occurred = false; @@ -50,6 +52,8 @@ impl<'tcx> FnCtxt<'_, 'tcx> { // See if we can make any more progress. self.select_obligations_where_possible(fallback_has_occurred, |_| {}); + + fallback_has_occurred } // Tries to apply a fallback to `ty` if it is an unsolved variable. diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index ad7e96e2833b..ff6cb35a7525 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -446,11 +446,12 @@ fn typeck_with_fallback<'tcx>( fcx }; - fcx.type_inference_fallback(); + let fallback_has_occurred = fcx.type_inference_fallback(); // Even though coercion casts provide type hints, we check casts after fallback for // backwards compatibility. This makes fallback a stronger type hint than a cast coercion. fcx.check_casts(); + fcx.select_obligations_where_possible(fallback_has_occurred, |_| {}); // Closure and generator analysis may run after fallback // because they don't constrain other type variables. diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index b0c95939bb77..8d401b7f4444 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self; let mut needs_to_be_read = false; for arm in arms.iter() { - return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| { + match mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| { match &pat.kind { PatKind::Binding(.., opt_sub_pat) => { // If the opt_sub_pat is None, than the binding does not count as @@ -290,7 +290,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // examined } } - })); + }) { + Ok(_) => (), + Err(_) => { + // If typeck failed, assume borrow is needed. + needs_to_be_read = true; + } + } } if needs_to_be_read { diff --git a/src/test/ui/closures/2229_closure_analysis/issue_88118.rs b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs new file mode 100644 index 000000000000..15c6ae4906c7 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs @@ -0,0 +1,14 @@ +// Regression test for #88118. Used to ICE. +// +// check-pass + +#![feature(capture_disjoint_fields)] + +fn foo(handler: impl FnOnce() -> MsU + Clone + 'static) { + Box::new(move |value| { + (|_| handler.clone()())(value); + None + }) as Box Option>; +} + +fn main() {} \ No newline at end of file diff --git a/src/test/ui/closures/issue-87814-1.rs b/src/test/ui/closures/issue-87814-1.rs new file mode 100644 index 000000000000..5cf01ddf5d71 --- /dev/null +++ b/src/test/ui/closures/issue-87814-1.rs @@ -0,0 +1,8 @@ +// check-pass +fn main() { + let mut schema_all = vec![]; + (0..42).for_each(|_x| match Err(()) as Result<(), _> { + Ok(()) => schema_all.push(()), + Err(_) => (), + }); +} diff --git a/src/test/ui/closures/issue-87814-2.rs b/src/test/ui/closures/issue-87814-2.rs new file mode 100644 index 000000000000..7a5facdac58c --- /dev/null +++ b/src/test/ui/closures/issue-87814-2.rs @@ -0,0 +1,11 @@ +// check-pass +#![feature(try_reserve)] + +fn main() { + let mut schema_all: (Vec, Vec) = (vec![], vec![]); + + let _c = || match schema_all.0.try_reserve(1) as Result<(), _> { + Ok(()) => (), + Err(_) => (), + }; +} From af15e529db5a7b31245d0b03d7af6dcb5ea21321 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Aug 2021 19:07:14 +0000 Subject: [PATCH 068/269] fix apparent typo in resolving variables --- compiler/rustc_typeck/src/check/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 9cbd3f7bb33a..a2ae22eaf393 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let t_cast = self.to_ty_saving_user_provided_ty(t); let t_cast = self.resolve_vars_if_possible(t_cast); let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast)); - let t_cast = self.resolve_vars_if_possible(t_cast); + let t_expr = self.resolve_vars_if_possible(t_expr); // Eagerly check for some obvious errors. if t_expr.references_error() || t_cast.references_error() { From 754d51ebe40df99748bf224b4de7f43d5a345bd3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Aug 2021 19:14:06 +0000 Subject: [PATCH 069/269] useful debug printouts The changes to dumping expressions seem particularly useful --- compiler/rustc_typeck/src/check/_match.rs | 2 ++ compiler/rustc_typeck/src/check/cast.rs | 4 ++-- compiler/rustc_typeck/src/check/coercion.rs | 1 + compiler/rustc_typeck/src/check/expr.rs | 23 ++++++++++++++++++- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 1 + compiler/rustc_typeck/src/expr_use_visitor.rs | 13 +++-------- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 87fd8f1e03bb..0397021c291b 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -14,6 +14,7 @@ use rustc_trait_selection::traits::{ }; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { + #[instrument(skip(self), level="debug")] pub fn check_match( &self, expr: &'tcx hir::Expr<'tcx>, @@ -26,6 +27,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let acrb = arms_contain_ref_bindings(arms); let scrutinee_ty = self.demand_scrutinee_type(scrut, acrb, arms.is_empty()); + debug!(?scrutinee_ty); // If there are no arms, that is a diverging match; a special case. if arms.is_empty() { diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 181972e3e7ba..14550690e63e 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -51,6 +51,7 @@ use rustc_trait_selection::traits::error_reporting::report_object_safety_error; /// Reifies a cast check to be checked once we have full type information for /// a function context. +#[derive(Debug)] pub struct CastCheck<'tcx> { expr: &'tcx hir::Expr<'tcx>, expr_ty: Ty<'tcx>, @@ -603,12 +604,11 @@ impl<'a, 'tcx> CastCheck<'tcx> { }); } + #[instrument(skip(fcx), level = "debug")] pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) { self.expr_ty = fcx.structurally_resolved_type(self.expr.span, self.expr_ty); self.cast_ty = fcx.structurally_resolved_type(self.cast_span, self.cast_ty); - debug!("check_cast({}, {:?} as {:?})", self.expr.hir_id, self.expr_ty, self.cast_ty); - if !fcx.type_is_known_to_be_sized_modulo_regions(self.cast_ty, self.span) { self.report_cast_to_unsized_type(fcx); } else if self.expr_ty.references_error() || self.cast_ty.references_error() { diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 0b4df8e6d3cd..040524df9c7c 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -1328,6 +1328,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { /// The inner coercion "engine". If `expression` is `None`, this /// is a forced-unit case, and hence `expression_ty` must be /// `Nil`. + #[instrument(skip(self,fcx,augment_error,label_expression_as_expected), level="debug")] crate fn coerce_inner<'a>( &mut self, fcx: &FnCtxt<'a, 'tcx>, diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index a2ae22eaf393..7880369e6c29 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -156,12 +156,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Note that inspecting a type's structure *directly* may expose the fact /// that there are actually multiple representations for `Error`, so avoid /// that when err needs to be handled differently. + #[instrument(skip(self), level="debug")] pub(super) fn check_expr_with_expectation( &self, expr: &'tcx hir::Expr<'tcx>, expected: Expectation<'tcx>, ) -> Ty<'tcx> { - debug!(">> type-checking: expected={:?}, expr={:?} ", expected, expr); + if self.tcx().sess.verbose() { + // make this code only run with -Zverbose because it is probably slow + if let Ok(lint_str) = self.tcx.sess.source_map().span_to_snippet(expr.span) { + if !lint_str.contains("\n") { + debug!("expr text: {}", lint_str); + } else { + let mut lines = lint_str.lines(); + if let Some(line0) = lines.next() { + let remaining_lines = lines.count(); + debug!("expr text: {}", line0); + debug!("expr text: ...(and {} more lines)", remaining_lines); + } + } + } + } // True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block // without the final expr (e.g. `try { return; }`). We don't want to generate an @@ -1049,6 +1064,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut(); match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) { Ok(cast_check) => { + debug!( + "check_expr_cast: deferring cast from {:?} to {:?}: {:?}", + t_cast, + t_expr, + cast_check, + ); deferred_cast_checks.push(cast_check); t_cast } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 9952413353fa..b624e07374ec 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -29,6 +29,7 @@ use std::slice; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn check_casts(&self) { let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut(); + debug!("FnCtxt::check_casts: {} deferred checks", deferred_cast_checks.len()); for cast in deferred_cast_checks.drain(..) { cast.check(self); } diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index 8d401b7f4444..08fb6793ac0b 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -120,9 +120,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } + #[instrument(skip(self), level = "debug")] pub fn consume_body(&mut self, body: &hir::Body<'_>) { - debug!("consume_body(body={:?})", body); - for param in body.params { let param_ty = return_if_err!(self.mc.pat_ty_adjusted(¶m.pat)); debug!("consume_body: param_ty = {:?}", param_ty); @@ -243,7 +242,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self; let mut needs_to_be_read = false; for arm in arms.iter() { - match mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| { + return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| { match &pat.kind { PatKind::Binding(.., opt_sub_pat) => { // If the opt_sub_pat is None, than the binding does not count as @@ -290,13 +289,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // examined } } - }) { - Ok(_) => (), - Err(_) => { - // If typeck failed, assume borrow is needed. - needs_to_be_read = true; - } - } + })); } if needs_to_be_read { From e49323b07dd0a53318e2336f579fe9dd45c0741f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Aug 2021 19:53:18 +0000 Subject: [PATCH 070/269] add trailing newline --- src/test/ui/closures/2229_closure_analysis/issue_88118.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/closures/2229_closure_analysis/issue_88118.rs b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs index 15c6ae4906c7..ea898bf1e6ff 100644 --- a/src/test/ui/closures/2229_closure_analysis/issue_88118.rs +++ b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs @@ -11,4 +11,4 @@ fn foo(handler: impl FnOnce() -> MsU + Clone + 'static) { }) as Box Option>; } -fn main() {} \ No newline at end of file +fn main() {} From ed43e02e8c9766206404768096132f10c796745a Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Mon, 23 Aug 2021 15:59:46 -0400 Subject: [PATCH 071/269] 2229: Update signature for truncate function --- compiler/rustc_typeck/src/check/upvar.rs | 118 +++++++++-------------- 1 file changed, 48 insertions(+), 70 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 34176623ebc4..d3d8e73e19a3 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -489,7 +489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut root_var_min_capture_list = typeck_results.closure_min_captures.remove(&closure_def_id).unwrap_or_default(); - for (place, capture_info) in capture_information.into_iter() { + for (mut place, capture_info) in capture_information.into_iter() { let var_hir_id = match place.base { PlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id, base => bug!("Expected upvar, found={:?}", base), @@ -530,14 +530,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Truncate the descendant (already in min_captures) to be same as the ancestor to handle any // possible change in capture mode. - let (_, descendant_capture_kind) = truncate_place_to_len( - possible_descendant.place, - possible_descendant.info.capture_kind, + truncate_place_to_len_and_update_capture_kind( + &mut possible_descendant.place, + &mut possible_descendant.info.capture_kind, place.projections.len(), ); - possible_descendant.info.capture_kind = descendant_capture_kind; - updated_capture_info = determine_capture_info(updated_capture_info, possible_descendant.info); @@ -561,14 +559,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Truncate the descendant (current place) to be same as the ancestor to handle any // possible change in capture mode. - let (_, descendant_capture_kind) = truncate_place_to_len( - place.clone(), - updated_capture_info.capture_kind, + truncate_place_to_len_and_update_capture_kind( + &mut place, + &mut updated_capture_info.capture_kind, possible_ancestor.place.projections.len(), ); - updated_capture_info.capture_kind = descendant_capture_kind; - possible_ancestor.info = determine_capture_info( possible_ancestor.info, updated_capture_info, @@ -1476,7 +1472,7 @@ fn restrict_repr_packed_field_ref_capture<'tcx>( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, place: &Place<'tcx>, - curr_borrow_kind: ty::UpvarCapture<'tcx>, + mut curr_borrow_kind: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { let pos = place.projections.iter().enumerate().position(|(i, p)| { let ty = place.ty_before_projection(i); @@ -1508,13 +1504,13 @@ fn restrict_repr_packed_field_ref_capture<'tcx>( } }); - let place = place.clone(); + let mut place = place.clone(); if let Some(pos) = pos { - truncate_place_to_len(place, curr_borrow_kind, pos) - } else { - (place, curr_borrow_kind) + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_borrow_kind, pos); } + + (place, curr_borrow_kind) } /// Returns a Ty that applies the specified capture kind on the provided capture Ty @@ -1841,31 +1837,28 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> { /// them completely. /// - No projections are applied on top of Union ADTs, since these require unsafe blocks. fn restrict_precision_for_unsafe( - place: Place<'tcx>, - curr_mode: ty::UpvarCapture<'tcx>, + mut place: Place<'tcx>, + mut curr_mode: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { - if place.projections.is_empty() { - // Nothing to do here - return (place, curr_mode); - } - if place.base_ty.is_unsafe_ptr() { - return truncate_place_to_len(place, curr_mode, 0); + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, 0); } if place.base_ty.is_union() { - return truncate_place_to_len(place, curr_mode, 0); + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, 0); } for (i, proj) in place.projections.iter().enumerate() { if proj.ty.is_unsafe_ptr() { // Don't apply any projections on top of an unsafe ptr. - return truncate_place_to_len(place, curr_mode, i + 1); + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1); + break; } if proj.ty.is_union() { // Don't capture preicse fields of a union. - return truncate_place_to_len(place, curr_mode, i + 1); + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1); + break; } } @@ -1880,7 +1873,7 @@ fn restrict_capture_precision<'tcx>( place: Place<'tcx>, curr_mode: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { - let (place, curr_mode) = restrict_precision_for_unsafe(place, curr_mode); + let (mut place, mut curr_mode) = restrict_precision_for_unsafe(place, curr_mode); if place.projections.is_empty() { // Nothing to do here @@ -1891,7 +1884,8 @@ fn restrict_capture_precision<'tcx>( match proj.kind { ProjectionKind::Index => { // Arrays are completely captured, so we drop Index projections - return truncate_place_to_len(place, curr_mode, i); + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i); + return (place, curr_mode); } ProjectionKind::Deref => {} ProjectionKind::Field(..) => {} // ignore @@ -1906,8 +1900,8 @@ fn restrict_capture_precision<'tcx>( /// (or if closure attempts to move data that it doesn’t own). /// Note: When taking ownership, only capture data found on the stack. fn adjust_for_move_closure<'tcx>( - place: Place<'tcx>, - kind: ty::UpvarCapture<'tcx>, + mut place: Place<'tcx>, + mut kind: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { let contains_deref_of_ref = place.deref_tys().any(|ty| ty.is_ref()); let first_deref = place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref); @@ -1917,52 +1911,38 @@ fn adjust_for_move_closure<'tcx>( // If there's any Deref and the data needs to be moved into the closure body, // or it's a Deref of a Box, truncate the path to the first deref - _ if first_deref.is_some() => { - let place = match first_deref { - Some(idx) => { - let (place, _) = truncate_place_to_len(place, kind, idx); - place - } - None => place, - }; + _ => { + if let Some(idx) = first_deref { + truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx); + } // AMAN: I think we don't need the span inside the ByValue anymore // we have more detailed span in CaptureInfo (place, ty::UpvarCapture::ByValue(None)) } - - _ => (place, ty::UpvarCapture::ByValue(None)), } } /// Adjust closure capture just that if taking ownership of data, only move data /// from enclosing stack frame. fn adjust_for_non_move_closure<'tcx>( - place: Place<'tcx>, + mut place: Place<'tcx>, mut kind: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { let contains_deref = place.projections.iter().position(|proj| proj.kind == ProjectionKind::Deref); match kind { - ty::UpvarCapture::ByValue(..) if contains_deref.is_some() => { - let place = match contains_deref { - Some(idx) => { - let (place, new_kind) = truncate_place_to_len(place, kind, idx); - - kind = new_kind; - place - } - // Because of the if guard on the match on `kind`, we should never get here. - None => unreachable!(), - }; - - (place, kind) + ty::UpvarCapture::ByValue(..) => { + if let Some(idx) = contains_deref { + truncate_place_to_len_and_update_capture_kind(&mut place, &mut kind, idx); + } } - ty::UpvarCapture::ByValue(..) => (place, kind), - ty::UpvarCapture::ByRef(..) => (place, kind), + ty::UpvarCapture::ByRef(..) => {} } + + (place, kind) } fn construct_place_string(tcx: TyCtxt<'_>, place: &Place<'tcx>) -> String { @@ -2157,15 +2137,13 @@ fn determine_capture_info( /// /// Note: Capture kind changes from `MutBorrow` to `UniqueImmBorrow` if the truncated part of the `place` /// contained `Deref` of `&mut`. -fn truncate_place_to_len( - mut place: Place<'tcx>, - curr_mode: ty::UpvarCapture<'tcx>, +fn truncate_place_to_len_and_update_capture_kind( + place: &mut Place<'tcx>, + curr_mode: &mut ty::UpvarCapture<'tcx>, len: usize, -) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { +) { let is_mut_ref = |ty: Ty<'_>| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Mut)); - let mut capture_kind = curr_mode; - // If the truncated part of the place contains `Deref` of a `&mut` then convert MutBorrow -> // UniqueImmBorrow // Note that if the place contained Deref of a raw pointer it would've not been MutBorrow, so @@ -2176,7 +2154,7 @@ fn truncate_place_to_len( if place.projections[i].kind == ProjectionKind::Deref && is_mut_ref(place.ty_before_projection(i)) { - capture_kind = ty::UpvarCapture::ByRef(ty::UpvarBorrow { + *curr_mode = ty::UpvarCapture::ByRef(ty::UpvarBorrow { kind: ty::BorrowKind::UniqueImmBorrow, region, }); @@ -2190,8 +2168,6 @@ fn truncate_place_to_len( } place.projections.truncate(len); - - (place, capture_kind) } /// Determines the Ancestry relationship of Place A relative to Place B @@ -2256,8 +2232,8 @@ fn determine_place_ancestry_relation( /// } /// ``` fn truncate_capture_for_optimization<'tcx>( - place: Place<'tcx>, - curr_mode: ty::UpvarCapture<'tcx>, + mut place: Place<'tcx>, + mut curr_mode: ty::UpvarCapture<'tcx>, ) -> (Place<'tcx>, ty::UpvarCapture<'tcx>) { let is_shared_ref = |ty: Ty<'_>| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not)); @@ -2269,10 +2245,12 @@ fn truncate_capture_for_optimization<'tcx>( match idx { // If that pointer is a shared reference, then we don't need those fields. Some(idx) if is_shared_ref(place.ty_before_projection(idx)) => { - truncate_place_to_len(place, curr_mode, idx + 1) + truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, idx + 1) } - None | Some(_) => (place, curr_mode), + None | Some(_) => {} } + + (place, curr_mode) } /// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if From 820e2680ec2f7f5f1b42dc94374986d251a22aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Aug 2021 23:31:01 +0200 Subject: [PATCH 072/269] handle ascription type op in NLL HRTB diagnostics Refactors the `type_op_ascribe_user_type` query into a version which accepts a span, and uses it in the nicer NLL HRTB bound region errors. --- .../diagnostics/bound_region_errors.rs | 42 ++++++++++++++-- compiler/rustc_traits/src/lib.rs | 2 +- compiler/rustc_traits/src/type_op.rs | 48 +++++++++++++------ 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs index d0284dd03023..ac30093ba826 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::Span; use rustc_trait_selection::traits::query::type_op; use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _}; -use rustc_traits::type_op_prove_predicate_with_span; +use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span}; use std::fmt; use std::rc::Rc; @@ -104,10 +104,11 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx> ToUniverseInfo<'t impl<'tcx> ToUniverseInfo<'tcx> for Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>> { - fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - // Ascribe user type isn't usually called on types that have different - // bound regions. - UniverseInfo::other() + fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { + UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery { + canonical_query: self, + base_universe, + }))) } } @@ -267,6 +268,37 @@ where } } +struct AscribeUserTypeQuery<'tcx> { + canonical_query: Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>, + base_universe: ty::UniverseIndex, +} + +impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + // FIXME: This error message isn't great, but it doesn't show up in the existing UI tests, + // and is only the fallback when the nice error fails. Consider improving this some more. + tcx.sess.struct_span_err(span, "higher-ranked lifetime error") + } + + fn base_universe(&self) -> ty::UniverseIndex { + self.base_universe + } + + fn nice_error( + &self, + tcx: TyCtxt<'tcx>, + span: Span, + placeholder_region: ty::Region<'tcx>, + error_region: Option>, + ) -> Option> { + tcx.infer_ctxt().enter_with_canonical(span, &self.canonical_query, |ref infcx, key, _| { + let mut fulfill_cx = >::new(tcx); + type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(span)).ok()?; + try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region) + }) + } +} + fn try_extract_error_from_fulfill_cx<'tcx>( mut fulfill_cx: Box + 'tcx>, infcx: &InferCtxt<'_, 'tcx>, diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index 8dd7c5bdfaeb..48c46c306932 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -19,7 +19,7 @@ mod normalize_erasing_regions; mod normalize_projection_ty; mod type_op; -pub use type_op::type_op_prove_predicate_with_span; +pub use type_op::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span}; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index c2e0a9987858..a76fb8426161 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -40,18 +40,28 @@ fn type_op_ascribe_user_type<'tcx>( canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, AscribeUserType<'tcx>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { - let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts(); - - debug!( - "type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}", - mir_ty, def_id, user_substs - ); + type_op_ascribe_user_type_with_span(infcx, fulfill_cx, key, None) + }) +} - let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx }; - cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs)?; +/// The core of the `type_op_ascribe_user_type` query: for diagnostics purposes in NLL HRTB errors, +/// this query can be re-run to better track the span of the obligation cause, and improve the error +/// message. Do not call directly unless you're in that very specific context. +pub fn type_op_ascribe_user_type_with_span<'a, 'tcx: 'a>( + infcx: &'a InferCtxt<'a, 'tcx>, + fulfill_cx: &'a mut dyn TraitEngine<'tcx>, + key: ParamEnvAnd<'tcx, AscribeUserType<'tcx>>, + span: Option, +) -> Result<(), NoSolution> { + let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts(); + debug!( + "type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}", + mir_ty, def_id, user_substs + ); - Ok(()) - }) + let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx }; + cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs, span)?; + Ok(()) } struct AscribeUserTypeCx<'me, 'tcx> { @@ -85,10 +95,15 @@ impl AscribeUserTypeCx<'me, 'tcx> { Ok(()) } - fn prove_predicate(&mut self, predicate: Predicate<'tcx>) { + fn prove_predicate(&mut self, predicate: Predicate<'tcx>, span: Option) { + let cause = if let Some(span) = span { + ObligationCause::dummy_with_span(span) + } else { + ObligationCause::dummy() + }; self.fulfill_cx.register_predicate_obligation( self.infcx, - Obligation::new(ObligationCause::dummy(), self.param_env, predicate), + Obligation::new(cause, self.param_env, predicate), ); } @@ -108,6 +123,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { mir_ty: Ty<'tcx>, def_id: DefId, user_substs: UserSubsts<'tcx>, + span: Option, ) -> Result<(), NoSolution> { let UserSubsts { user_self_ty, substs } = user_substs; let tcx = self.tcx(); @@ -129,7 +145,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { debug!(?instantiated_predicates.predicates); for instantiated_predicate in instantiated_predicates.predicates { let instantiated_predicate = self.normalize(instantiated_predicate); - self.prove_predicate(instantiated_predicate); + self.prove_predicate(instantiated_predicate, span); } if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty { @@ -141,6 +157,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { self.prove_predicate( ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()), + span, ); } @@ -155,7 +172,10 @@ impl AscribeUserTypeCx<'me, 'tcx> { // them? This would only be relevant if some input // type were ill-formed but did not appear in `ty`, // which...could happen with normalization... - self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx())); + self.prove_predicate( + ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()), + span, + ); Ok(()) } } From 05cd587726b01415f50ab8def30ea07864298e13 Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 17:32:27 -0400 Subject: [PATCH 073/269] Refactor: disabled frame pointer; consolidated unsupported register errors; added register prefix --- compiler/rustc_target/src/asm/s390x.rs | 86 ++++++-------------------- 1 file changed, 18 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 29f370928713..5ed93c0c1a9c 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -54,8 +54,8 @@ def_regs! { r8: reg = ["r8"], r9: reg = ["r9"], r10: reg = ["r10"], - r11: reg = ["r11"], r12: reg = ["r12"], + r13: reg = ["r13"], r14: reg = ["r14"], f0: freg = ["f0"], f1: freg = ["f1"], @@ -73,74 +73,24 @@ def_regs! { f13: freg = ["f13"], f14: freg = ["f14"], f15: freg = ["f15"], - #error = ["r13"] => - "The base pointer cannot be used as an operand for inline asm", + #error = ["r11"] => + "The frame pointer cannot be used as an operand for inline asm", #error = ["r15"] => "The stack pointer cannot be used as an operand for inline asm", - #error = ["a0"] => - "This pointer is reserved on s390x and cannot be used as an operand for inline asm", - #error = ["a1"] => - "This pointer is reserved on z/Arch and cannot be used as an operand for inline asm", - #error = ["c0"] => - "c0 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c1"] => - "c1 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c2"] => - "c2 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c3"] => - "c3 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c4"] => - "c4 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c5"] => - "c5 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c6"] => - "c6 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c7"] => - "c7 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c8"] => - "c8 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c9"] => - "c9 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c10"] => - "c10 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c11"] => - "c11 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c12"] => - "c12 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c13"] => - "c13 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c14"] => - "c14 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c15"] => - "c15 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["a2"] => - "a2 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a3"] => - "a3 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a4"] => - "a4 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a5"] => - "a5 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a6"] => - "a6 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a7"] => - "a7 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a8"] => - "a8 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a9"] => - "a9 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a10"] => - "a10 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a11"] => - "a11 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a12"] => - "a12 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a13"] => - "a13 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a14"] => - "a14 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a15"] => - "a15 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = [ + "c0", "c1", "c2", "c3", + "c4", "c5", "c6", "c7", + "c8", "c9", "c10", "c11", + "c12", "c13", "c14", "c15" + ] => + "control registers are reserved by the kernel and cannot be used as operands for inline asm", + #error = [ + "a0", "a1", "a2", "a3", + "a4", "a5", "a6", "a7", + "a8", "a9", "a10", "a11", + "a12", "a13", "a14", "a15" + ] => + "access registers are not supported and cannot be used as operands for inline asm", } } @@ -151,6 +101,6 @@ impl S390xInlineAsmReg { _arch: InlineAsmArch, _modifier: Option, ) -> fmt::Result { - out.write_str(self.name()) + out.write_str(&format!("%{}", self.name())) } } From d9242ff0aae0189570c0abd173bc05e5ff82d48f Mon Sep 17 00:00:00 2001 From: jackh726 Date: Mon, 9 Aug 2021 19:26:13 -0400 Subject: [PATCH 074/269] When checking associated type bounds, use bound vars for GAT params in param_env --- compiler/rustc_middle/src/ty/subst.rs | 4 +- .../rustc_typeck/src/check/compare_method.rs | 77 ++++++++++++++++--- .../generic-associated-types/issue-87429.rs | 15 ++++ 3 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 src/test/ui/generic-associated-types/issue-87429.rs diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 9b8d22d8eafc..cb8a24351373 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -234,7 +234,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { }) } - fn fill_item( + pub fn fill_item( substs: &mut SmallVec<[GenericArg<'tcx>; 8]>, tcx: TyCtxt<'tcx>, defs: &ty::Generics, @@ -249,7 +249,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> { Self::fill_single(substs, defs, mk_kind) } - fn fill_single( + pub fn fill_single( substs: &mut SmallVec<[GenericArg<'tcx>; 8]>, defs: &ty::Generics, mk_kind: &mut F, diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 8d5bf98be993..b95cbd9025c4 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1225,6 +1225,7 @@ fn compare_type_predicate_entailment<'tcx>( /// For default associated types the normalization is not possible (the value /// from the impl could be overridden). We also can't normalize generic /// associated types (yet) because they contain bound parameters. +#[tracing::instrument(level = "debug", skip(tcx))] pub fn check_type_bounds<'tcx>( tcx: TyCtxt<'tcx>, trait_ty: &ty::AssocItem, @@ -1238,10 +1239,57 @@ pub fn check_type_bounds<'tcx>( // type Bar =... // } // - // - `impl_substs` would be `[A, B, C]` - // - `rebased_substs` would be `[(A, B), u32, C]`, combining the substs from - // the *trait* with the generic associated type parameters. - let impl_ty_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id); + // - `impl_trait_ref` would be `<(A, B) as Foo> + // - `impl_ty_substs` would be `[A, B, ^0.0]` + // - `rebased_substs` would be `[(A, B), u32, ^0.0]`, combining the substs from + // the *trait* with the generic associated type parameters (as bound vars). + let defs: &ty::Generics = tcx.generics_of(impl_ty.def_id); + let mut substs = smallvec::SmallVec::with_capacity(defs.count()); + if let Some(def_id) = defs.parent { + let parent_defs = tcx.generics_of(def_id); + InternalSubsts::fill_item(&mut substs, tcx, parent_defs, &mut |param, _| { + tcx.mk_param_from_def(param) + }); + } + let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> = + smallvec::SmallVec::with_capacity(defs.count()); + InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param.kind { + GenericParamDefKind::Type { .. } => { + let kind = ty::BoundTyKind::Param(param.name); + let bound_var = ty::BoundVariableKind::Ty(kind); + bound_vars.push(bound_var); + tcx.mk_ty(ty::Bound( + ty::INNERMOST, + ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, + )) + .into() + } + GenericParamDefKind::Lifetime => { + let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); + let bound_var = ty::BoundVariableKind::Region(kind); + bound_vars.push(bound_var); + tcx.mk_region(ty::ReLateBound( + ty::INNERMOST, + ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, + )) + .into() + } + GenericParamDefKind::Const { .. } => { + let bound_var = ty::BoundVariableKind::Const; + bound_vars.push(bound_var); + tcx.mk_const(ty::Const { + ty: tcx.type_of(param.def_id), + val: ty::ConstKind::Bound( + ty::INNERMOST, + ty::BoundVar::from_usize(bound_vars.len() - 1), + ), + }) + .into() + } + }); + let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter()); + let impl_ty_substs = tcx.intern_substs(&substs); + let rebased_substs = impl_ty_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs); let impl_ty_value = tcx.type_of(impl_ty.def_id); @@ -1270,18 +1318,26 @@ pub fn check_type_bounds<'tcx>( // impl X for T where T: X { type Y = ::Y; } } _ => predicates.push( - ty::Binder::dummy(ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { - item_def_id: trait_ty.def_id, - substs: rebased_substs, + ty::Binder::bind_with_vars( + ty::ProjectionPredicate { + projection_ty: ty::ProjectionTy { + item_def_id: trait_ty.def_id, + substs: rebased_substs, + }, + ty: impl_ty_value, }, - ty: impl_ty_value, - }) + bound_vars, + ) .to_predicate(tcx), ), }; ty::ParamEnv::new(tcx.intern_predicates(&predicates), Reveal::UserFacing) }; + debug!(?normalize_param_env); + + let impl_ty_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id); + let rebased_substs = + impl_ty_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs); tcx.infer_ctxt().enter(move |infcx| { let constness = impl_ty @@ -1308,6 +1364,7 @@ pub fn check_type_bounds<'tcx>( .explicit_item_bounds(trait_ty.def_id) .iter() .map(|&(bound, span)| { + debug!(?bound); let concrete_ty_bound = bound.subst(tcx, rebased_substs); debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound); diff --git a/src/test/ui/generic-associated-types/issue-87429.rs b/src/test/ui/generic-associated-types/issue-87429.rs new file mode 100644 index 000000000000..f905348ae32a --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429.rs @@ -0,0 +1,15 @@ +// check-pass + +#![feature(generic_associated_types)] + +trait Family { + type Member<'a>: for<'b> PartialEq>; +} + +struct I32; + +impl Family for I32 { + type Member<'a> = i32; +} + +fn main() {} From 6df6eb8ae8358ebab76fcfa35ac7cc41e18a2560 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Mon, 16 Aug 2021 10:49:36 -0400 Subject: [PATCH 075/269] Add a couple more tests --- .../issue-87429-associated-type-default.rs | 18 +++++++++++++ ...issue-87429-associated-type-default.stderr | 14 +++++++++++ .../issue-87429-specialization.rs | 25 +++++++++++++++++++ .../issue-87429-specialization.stderr | 24 ++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-87429-associated-type-default.rs create mode 100644 src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr create mode 100644 src/test/ui/generic-associated-types/issue-87429-specialization.rs create mode 100644 src/test/ui/generic-associated-types/issue-87429-specialization.stderr diff --git a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.rs b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.rs new file mode 100644 index 000000000000..9ee07c2f1e1c --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.rs @@ -0,0 +1,18 @@ +// check-fail + +#![feature(associated_type_defaults)] +#![feature(generic_associated_types)] + +trait Family { + // Fine, i32: PartialEq + type Member<'a>: for<'b> PartialEq> = i32; +} + +struct Foo; +trait Family2 { + // Not fine, not Foo: PartialEq + type Member<'a>: for<'b> PartialEq> = Foo; + //~^ ERROR can't compare +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr new file mode 100644 index 000000000000..8f031c761836 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr @@ -0,0 +1,14 @@ +error[E0277]: can't compare `Foo` with `Foo` + --> $DIR/issue-87429-associated-type-default.rs:14:5 + | +LL | type Member<'a>: for<'b> PartialEq> = Foo; + | ^^^^^^^^^^^^^^^^^-----------------------------------^^^^^^^ + | | | + | | required by this bound in `Family2::Member` + | no implementation for `Foo == Foo` + | + = help: the trait `PartialEq` is not implemented for `Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.rs b/src/test/ui/generic-associated-types/issue-87429-specialization.rs new file mode 100644 index 000000000000..b365e07feb28 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429-specialization.rs @@ -0,0 +1,25 @@ +// check-fail + +#![feature(specialization)] +//~^ WARN incomplete +#![feature(generic_associated_types)] + +trait Family { + type Member<'a>: for<'b> PartialEq>; +} + +struct I32Family; + +impl Family for I32Family { + default type Member<'a> = i32; +} + +struct Foo; +struct FooFamily; + +impl Family for FooFamily { + default type Member<'a> = Foo; + //~^ ERROR can't compare +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr new file mode 100644 index 000000000000..05d40f9e7cc1 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr @@ -0,0 +1,24 @@ +warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-87429-specialization.rs:3:12 + | +LL | #![feature(specialization)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #31844 for more information + = help: consider using `min_specialization` instead, which is more stable and complete + +error[E0277]: can't compare `Foo` with `Foo` + --> $DIR/issue-87429-specialization.rs:21:5 + | +LL | type Member<'a>: for<'b> PartialEq>; + | ----------------------------------- required by this bound in `Family::Member` +... +LL | default type Member<'a> = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `Foo == Foo` + | + = help: the trait `PartialEq` is not implemented for `Foo` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0277`. From b0170779f5c6e9705658cda1b02cf1fd1a925205 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Mon, 23 Aug 2021 16:39:11 -0400 Subject: [PATCH 076/269] Add comment and extra test --- .../rustc_typeck/src/check/compare_method.rs | 28 ++++++++++++++++++- .../generic-associated-types/issue-87429-2.rs | 20 +++++++++++++ ...issue-87429-associated-type-default.stderr | 10 ++++--- .../issue-87429-specialization.stderr | 8 ++++-- 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/generic-associated-types/issue-87429-2.rs diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index b95cbd9025c4..c384e0dcb2ca 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1240,9 +1240,35 @@ pub fn check_type_bounds<'tcx>( // } // // - `impl_trait_ref` would be `<(A, B) as Foo> - // - `impl_ty_substs` would be `[A, B, ^0.0]` + // - `impl_ty_substs` would be `[A, B, ^0.0]` (`^0.0` here is the bound var with db 0 and index 0) // - `rebased_substs` would be `[(A, B), u32, ^0.0]`, combining the substs from // the *trait* with the generic associated type parameters (as bound vars). + // + // A note regarding the use of bound vars here: + // Imagine as an example + // ``` + // trait Family { + // type Member; + // } + // + // impl Family for VecFamily { + // type Member = i32; + // } + // ``` + // Here, we would generate + // ```notrust + // forall { Normalize(::Member => i32) } + // ``` + // when we really would like to generate + // ```notrust + // forall { Normalize(::Member => i32) :- Implemented(C: Eq) } + // ``` + // But, this is probably fine, because although the first clause can be used with types C that + // do not implement Eq, for it to cause some kind of problem, there would have to be a + // VecFamily::Member for some type X where !(X: Eq), that appears in the value of type + // Member = .... That type would fail a well-formedness check that we ought to be doing + // elsewhere, which would check that any ::Member meets the bounds declared in + // the trait (notably, that X: Eq and T: Family). let defs: &ty::Generics = tcx.generics_of(impl_ty.def_id); let mut substs = smallvec::SmallVec::with_capacity(defs.count()); if let Some(def_id) = defs.parent { diff --git a/src/test/ui/generic-associated-types/issue-87429-2.rs b/src/test/ui/generic-associated-types/issue-87429-2.rs new file mode 100644 index 000000000000..d35bb098abdf --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87429-2.rs @@ -0,0 +1,20 @@ +// Derived from `issue-87429`. A test that ensures that using bound vars in the +// predicates in the param env when checking that an associated type satisfies +// its bounds does not cause us to not be able to use the bounds on the parameters. + +// check-pass + +#![feature(generic_associated_types)] + +trait Family { + type Member<'a, C: Eq>: for<'b> MyBound<'b, C>; +} + +trait MyBound<'a, C> { } +impl<'a, C: Eq> MyBound<'a, C> for i32 { } + +impl Family for () { + type Member<'a, C: Eq> = i32; +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr index 8f031c761836..01cb0bfc72cd 100644 --- a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr @@ -2,12 +2,14 @@ error[E0277]: can't compare `Foo` with `Foo` --> $DIR/issue-87429-associated-type-default.rs:14:5 | LL | type Member<'a>: for<'b> PartialEq> = Foo; - | ^^^^^^^^^^^^^^^^^-----------------------------------^^^^^^^ - | | | - | | required by this bound in `Family2::Member` - | no implementation for `Foo == Foo` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `Foo == Foo` | = help: the trait `PartialEq` is not implemented for `Foo` +note: required by a bound in `Family2::Member` + --> $DIR/issue-87429-associated-type-default.rs:14:22 + | +LL | type Member<'a>: for<'b> PartialEq> = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family2::Member` error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr index 05d40f9e7cc1..87bd35f58788 100644 --- a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr @@ -11,13 +11,15 @@ LL | #![feature(specialization)] error[E0277]: can't compare `Foo` with `Foo` --> $DIR/issue-87429-specialization.rs:21:5 | -LL | type Member<'a>: for<'b> PartialEq>; - | ----------------------------------- required by this bound in `Family::Member` -... LL | default type Member<'a> = Foo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `Foo == Foo` | = help: the trait `PartialEq` is not implemented for `Foo` +note: required by a bound in `Family::Member` + --> $DIR/issue-87429-specialization.rs:8:22 + | +LL | type Member<'a>: for<'b> PartialEq>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family::Member` error: aborting due to previous error; 1 warning emitted From a9f623707b8dcaba260b547e1950a4679b3b40eb Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 17:56:04 -0400 Subject: [PATCH 077/269] Fix: made suggested change --- compiler/rustc_target/src/asm/s390x.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 5ed93c0c1a9c..a74873f17476 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -101,6 +101,6 @@ impl S390xInlineAsmReg { _arch: InlineAsmArch, _modifier: Option, ) -> fmt::Result { - out.write_str(&format!("%{}", self.name())) + write!(out, "%{}", self.name()) } } From 7b0e564e7cd3bebea7c41165db42a7b15010d2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Aug 2021 23:34:04 +0200 Subject: [PATCH 078/269] Update NLL HRTB type ascription blessed expectations Some of these tests have reached parity with the migrate-mode output. --- src/test/ui/hrtb/due-to-where-clause.nll.stderr | 8 -------- src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr | 8 -------- src/test/ui/hrtb/hrtb-just-for-static.nll.stderr | 7 +++++-- src/test/ui/issues/issue-54302.nll.stderr | 8 -------- 4 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 src/test/ui/hrtb/due-to-where-clause.nll.stderr delete mode 100644 src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr delete mode 100644 src/test/ui/issues/issue-54302.nll.stderr diff --git a/src/test/ui/hrtb/due-to-where-clause.nll.stderr b/src/test/ui/hrtb/due-to-where-clause.nll.stderr deleted file mode 100644 index 90803a0adb01..000000000000 --- a/src/test/ui/hrtb/due-to-where-clause.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/due-to-where-clause.rs:2:5 - | -LL | test::(&mut 42); - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr b/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr deleted file mode 100644 index 4de35d70c30a..000000000000 --- a/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/hrtb-cache-issue-54302.rs:19:5 - | -LL | assert_deserialize_owned::<&'static str>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr b/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr index a812282def9a..17d59bb321a4 100644 --- a/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr +++ b/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr @@ -17,11 +17,14 @@ LL | want_hrtb::<&'a u32>() | = help: consider replacing `'a` with `'static` -error: higher-ranked subtype error +error: implementation of `Foo` is not general enough --> $DIR/hrtb-just-for-static.rs:30:5 | LL | want_hrtb::<&'a u32>() - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough + | + = note: `Foo<&'0 isize>` would have to be implemented for the type `&u32`, for any lifetime `'0`... + = note: ...but `Foo<&'1 isize>` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1` error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-54302.nll.stderr b/src/test/ui/issues/issue-54302.nll.stderr deleted file mode 100644 index e68de0312824..000000000000 --- a/src/test/ui/issues/issue-54302.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/issue-54302.rs:13:5 - | -LL | assert_deserialize_owned::<&'static str>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - From ef2b9a406811fcfec34c8679099c409cc0a840b3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Aug 2021 22:21:21 +0000 Subject: [PATCH 079/269] x.py fmt --- compiler/rustc_typeck/src/check/_match.rs | 2 +- compiler/rustc_typeck/src/check/coercion.rs | 2 +- compiler/rustc_typeck/src/check/expr.rs | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index 0397021c291b..01227cad334f 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -14,7 +14,7 @@ use rustc_trait_selection::traits::{ }; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - #[instrument(skip(self), level="debug")] + #[instrument(skip(self), level = "debug")] pub fn check_match( &self, expr: &'tcx hir::Expr<'tcx>, diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 040524df9c7c..17a81486048e 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -1328,7 +1328,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { /// The inner coercion "engine". If `expression` is `None`, this /// is a forced-unit case, and hence `expression_ty` must be /// `Nil`. - #[instrument(skip(self,fcx,augment_error,label_expression_as_expected), level="debug")] + #[instrument(skip(self, fcx, augment_error, label_expression_as_expected), level = "debug")] crate fn coerce_inner<'a>( &mut self, fcx: &FnCtxt<'a, 'tcx>, diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 7880369e6c29..eaf24552355d 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -156,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Note that inspecting a type's structure *directly* may expose the fact /// that there are actually multiple representations for `Error`, so avoid /// that when err needs to be handled differently. - #[instrument(skip(self), level="debug")] + #[instrument(skip(self), level = "debug")] pub(super) fn check_expr_with_expectation( &self, expr: &'tcx hir::Expr<'tcx>, @@ -176,7 +176,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - } + } // True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block // without the final expr (e.g. `try { return; }`). We don't want to generate an @@ -1066,9 +1066,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Ok(cast_check) => { debug!( "check_expr_cast: deferring cast from {:?} to {:?}: {:?}", - t_cast, - t_expr, - cast_check, + t_cast, t_expr, cast_check, ); deferred_cast_checks.push(cast_check); t_cast From ec9531bcb09e52c5fbbabbedc8927b99f7e6fd9c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Aug 2021 22:25:55 +0000 Subject: [PATCH 080/269] fix test --- src/test/ui/closures/2229_closure_analysis/issue_88118.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/closures/2229_closure_analysis/issue_88118.rs b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs index ea898bf1e6ff..453b7e04a369 100644 --- a/src/test/ui/closures/2229_closure_analysis/issue_88118.rs +++ b/src/test/ui/closures/2229_closure_analysis/issue_88118.rs @@ -2,6 +2,7 @@ // // check-pass +#![allow(incomplete_features)] #![feature(capture_disjoint_fields)] fn foo(handler: impl FnOnce() -> MsU + Clone + 'static) { From d7b4ee8a324545981063bc8eef5dc5efa88791a7 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Mon, 23 Aug 2021 18:47:38 -0400 Subject: [PATCH 081/269] 2229: Consider varaiables mentioned in closure as used --- compiler/rustc_passes/src/liveness.rs | 36 ++++--------------- .../2229_closure_analysis/issue-87987.rs | 2 +- .../2229_closure_analysis/issue-87987.stderr | 10 +----- .../run_pass/destructure_patterns.rs | 3 -- .../run_pass/destructure_patterns.stderr | 22 ++---------- 5 files changed, 10 insertions(+), 63 deletions(-) diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 2cd780e1b9bb..87c14d9c395f 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -337,8 +337,8 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { return; } - if let Some(captures) = maps.tcx.typeck(local_def_id).closure_min_captures.get(&def_id) { - for &var_hir_id in captures.keys() { + if let Some(upvars) = maps.tcx.upvars_mentioned(def_id) { + for &var_hir_id in upvars.keys() { let var_name = maps.tcx.hir().name(var_hir_id); maps.add_variable(Upvar(var_hir_id, var_name)); } @@ -405,21 +405,14 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { // breaks or continues) self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span)); - // Make a live_node for each captured variable, with the span + // Make a live_node for each mentioned variable, with the span // being the location that the variable is used. This results // in better error messages than just pointing at the closure // construction site. let mut call_caps = Vec::new(); let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id); - if let Some(captures) = self - .tcx - .typeck(closure_def_id) - .closure_min_captures - .get(&closure_def_id.to_def_id()) - { - // If closure_min_captures is Some, upvars_mentioned must also be Some - let upvars = self.tcx.upvars_mentioned(closure_def_id).unwrap(); - call_caps.extend(captures.keys().map(|var_id| { + if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) { + call_caps.extend(upvars.keys().map(|var_id| { let upvar = upvars[var_id]; let upvar_ln = self.add_live_node(UpvarNode(upvar.span)); CaptureInfo { ln: upvar_ln, var_hid: *var_id } @@ -494,7 +487,6 @@ struct Liveness<'a, 'tcx> { ir: &'a mut IrMaps<'tcx>, typeck_results: &'a ty::TypeckResults<'tcx>, param_env: ty::ParamEnv<'tcx>, - upvars: Option<&'tcx FxIndexMap>, closure_min_captures: Option<&'tcx RootVariableMinCaptureList<'tcx>>, successors: IndexVec>, rwu_table: rwu_table::RWUTable, @@ -518,7 +510,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn new(ir: &'a mut IrMaps<'tcx>, body_owner: LocalDefId) -> Liveness<'a, 'tcx> { let typeck_results = ir.tcx.typeck(body_owner); let param_env = ir.tcx.param_env(body_owner); - let upvars = ir.tcx.upvars_mentioned(body_owner); let closure_min_captures = typeck_results.closure_min_captures.get(&body_owner.to_def_id()); let closure_ln = ir.add_live_node(ClosureNode); let exit_ln = ir.add_live_node(ExitNode); @@ -530,7 +521,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ir, typeck_results, param_env, - upvars, closure_min_captures, successors: IndexVec::from_elem_n(None, num_live_nodes), rwu_table: rwu_table::RWUTable::new(num_live_nodes, num_vars), @@ -1234,21 +1224,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { acc: u32, ) -> LiveNode { match path.res { - Res::Local(hid) => { - let in_upvars = self.upvars.map_or(false, |u| u.contains_key(&hid)); - let in_captures = self.closure_min_captures.map_or(false, |c| c.contains_key(&hid)); - - match (in_upvars, in_captures) { - (false, _) | (true, true) => self.access_var(hir_id, hid, succ, acc, path.span), - (true, false) => { - // This case is possible when with RFC-2229, a wild pattern - // is used within a closure. - // eg: `let _ = x`. The closure doesn't capture x here, - // even though it's mentioned in the closure. - succ - } - } - } + Res::Local(hid) => self.access_var(hir_id, hid, succ, acc, path.span), _ => succ, } } diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87987.rs b/src/test/ui/closures/2229_closure_analysis/issue-87987.rs index 5dc2cb7e7109..d4f243ee3475 100644 --- a/src/test/ui/closures/2229_closure_analysis/issue-87987.rs +++ b/src/test/ui/closures/2229_closure_analysis/issue-87987.rs @@ -8,7 +8,7 @@ struct Props { fn main() { // Test 1 - let props_2 = Props { //~ WARNING: unused variable: `props_2` + let props_2 = Props { field_1: 1, field_2: 1, }; diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87987.stderr b/src/test/ui/closures/2229_closure_analysis/issue-87987.stderr index aa7012c3618c..5828295fae33 100644 --- a/src/test/ui/closures/2229_closure_analysis/issue-87987.stderr +++ b/src/test/ui/closures/2229_closure_analysis/issue-87987.stderr @@ -1,11 +1,3 @@ -warning: unused variable: `props_2` - --> $DIR/issue-87987.rs:11:9 - | -LL | let props_2 = Props { - | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_props_2` - | - = note: `#[warn(unused_variables)]` on by default - warning: field is never read: `field_1` --> $DIR/issue-87987.rs:5:5 | @@ -20,5 +12,5 @@ warning: field is never read: `field_2` LL | field_2: u32, | ^^^^^^^^^^^^ -warning: 3 warnings emitted +warning: 2 warnings emitted diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs index 07adbee03f96..dacc2c616b8b 100644 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs @@ -43,7 +43,6 @@ fn test3() { fn test4() { let t = (String::from("Hello"), String::from("World")); - //~^ WARN unused variable: `t` let c = || { let (_, _) = t; @@ -81,9 +80,7 @@ fn test7() { fn test8() { let x = 0; - //~^ WARN unused variable: `x` let tup = (1, 2); - //~^ WARN unused variable: `tup` let p = Point { x: 10, y: 20 }; let c = || { diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr index 6523f2b34d53..7706f68ba5b4 100644 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.stderr @@ -29,29 +29,11 @@ warning: unused variable: `t2` LL | let (_, t2) = t; | ^^ help: if this is intentional, prefix it with an underscore: `_t2` -warning: unused variable: `t` - --> $DIR/destructure_patterns.rs:45:9 - | -LL | let t = (String::from("Hello"), String::from("World")); - | ^ help: if this is intentional, prefix it with an underscore: `_t` - warning: unused variable: `x` - --> $DIR/destructure_patterns.rs:91:21 + --> $DIR/destructure_patterns.rs:88:21 | LL | let Point { x, y } = p; | ^ help: try ignoring the field: `x: _` -warning: unused variable: `x` - --> $DIR/destructure_patterns.rs:83:9 - | -LL | let x = 0; - | ^ help: if this is intentional, prefix it with an underscore: `_x` - -warning: unused variable: `tup` - --> $DIR/destructure_patterns.rs:85:9 - | -LL | let tup = (1, 2); - | ^^^ help: if this is intentional, prefix it with an underscore: `_tup` - -warning: 8 warnings emitted +warning: 5 warnings emitted From bc33861c2240c966e01d6f3e0431d192c9c720c1 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 23 Aug 2021 20:02:17 -0400 Subject: [PATCH 082/269] Fix references to `ControlFlow` in docs --- library/core/src/iter/traits/iterator.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 524d8f857e2a..746548a96a47 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1957,8 +1957,8 @@ pub trait Iterator { /// assert_eq!(it.next(), Some(&40)); /// ``` /// - /// While you cannot `break` from a closure, the [`crate::ops::ControlFlow`] - /// type allows a similar idea: + /// While you cannot `break` from a closure, the [`ControlFlow`] type allows + /// a similar idea: /// /// ``` /// use std::ops::ControlFlow; @@ -2024,8 +2024,8 @@ pub trait Iterator { /// assert_eq!(it.next(), Some("stale_bread.json")); /// ``` /// - /// The [`crate::ops::ControlFlow`] type can be used with this method for the - /// situations in which you'd use `break` and `continue` in a normal loop: + /// The [`ControlFlow`] type can be used with this method for the situations + /// in which you'd use `break` and `continue` in a normal loop: /// /// ``` /// use std::ops::ControlFlow; From 04fa1d81dd435fc5eaf22ed72efdfd699e1d6c97 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 12:33:27 +0200 Subject: [PATCH 083/269] =?UTF-8?q?Fix=20typo=20=E2=80=9Ca=20Rc=E2=80=9D?= =?UTF-8?q?=20=E2=86=92=20=E2=80=9Can=20Rc=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/rustc_data_structures/src/owning_ref/mod.rs | 2 +- library/alloc/src/rc.rs | 2 +- library/std/src/ffi/c_str.rs | 2 +- library/std/src/ffi/os_str.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_data_structures/src/owning_ref/mod.rs b/compiler/rustc_data_structures/src/owning_ref/mod.rs index 5b27a407ad42..251195204da4 100644 --- a/compiler/rustc_data_structures/src/owning_ref/mod.rs +++ b/compiler/rustc_data_structures/src/owning_ref/mod.rs @@ -1146,7 +1146,7 @@ pub type VecRef = OwningRef, U>; /// Typedef of an owning reference that uses a `String` as the owner. pub type StringRef = OwningRef; -/// Typedef of an owning reference that uses a `Rc` as the owner. +/// Typedef of an owning reference that uses an `Rc` as the owner. pub type RcRef = OwningRef, U>; /// Typedef of an owning reference that uses an `Arc` as the owner. pub type ArcRef = OwningRef, U>; diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 0b3079fa59db..c19c61b65cd0 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1743,7 +1743,7 @@ impl fmt::Pointer for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "from_for_ptrs", since = "1.6.0")] impl From for Rc { - /// Converts a generic type `T` into a `Rc` + /// Converts a generic type `T` into an `Rc` /// /// The conversion allocates on the heap and moves `t` /// from the stack into it. diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index 0d082648591c..de05c3778529 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -958,7 +958,7 @@ impl From<&CStr> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts a [`CString`] into a [`Rc`]`` without copying or allocating. + /// Converts a [`CString`] into an [`Rc`]`` without copying or allocating. #[inline] fn from(s: CString) -> Rc { let rc: Rc<[u8]> = Rc::from(s.into_inner()); diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index f05295f89af1..21f354caf6ae 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -916,7 +916,7 @@ impl From<&OsStr> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts an [`OsString`] into a [`Rc`]`` without copying or allocating. + /// Converts an [`OsString`] into an [`Rc`]`` without copying or allocating. #[inline] fn from(s: OsString) -> Rc { let rc = s.inner.into_rc(); From b823dc1bbd57c6525b2cc2420c87795a7264edb4 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 12:39:39 +0200 Subject: [PATCH 084/269] =?UTF-8?q?Also=20fix=20=E2=80=9Ca=20RwLock*?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/rustc_data_structures/src/owning_ref/mod.rs | 6 +++--- src/test/ui/drop/dropck_legal_cycles.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_data_structures/src/owning_ref/mod.rs b/compiler/rustc_data_structures/src/owning_ref/mod.rs index 251195204da4..4689a027895c 100644 --- a/compiler/rustc_data_structures/src/owning_ref/mod.rs +++ b/compiler/rustc_data_structures/src/owning_ref/mod.rs @@ -1157,9 +1157,9 @@ pub type RefRef<'a, T, U = T> = OwningRef, U>; pub type RefMutRef<'a, T, U = T> = OwningRef, U>; /// Typedef of an owning reference that uses a `MutexGuard` as the owner. pub type MutexGuardRef<'a, T, U = T> = OwningRef, U>; -/// Typedef of an owning reference that uses a `RwLockReadGuard` as the owner. +/// Typedef of an owning reference that uses an `RwLockReadGuard` as the owner. pub type RwLockReadGuardRef<'a, T, U = T> = OwningRef, U>; -/// Typedef of an owning reference that uses a `RwLockWriteGuard` as the owner. +/// Typedef of an owning reference that uses an `RwLockWriteGuard` as the owner. pub type RwLockWriteGuardRef<'a, T, U = T> = OwningRef, U>; /// Typedef of a mutable owning reference that uses a `Box` as the owner. @@ -1173,7 +1173,7 @@ pub type StringRefMut = OwningRefMut; pub type RefMutRefMut<'a, T, U = T> = OwningRefMut, U>; /// Typedef of a mutable owning reference that uses a `MutexGuard` as the owner. pub type MutexGuardRefMut<'a, T, U = T> = OwningRefMut, U>; -/// Typedef of a mutable owning reference that uses a `RwLockWriteGuard` as the owner. +/// Typedef of a mutable owning reference that uses an `RwLockWriteGuard` as the owner. pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRef, U>; unsafe impl<'a, T: 'a> IntoErased<'a> for Box { diff --git a/src/test/ui/drop/dropck_legal_cycles.rs b/src/test/ui/drop/dropck_legal_cycles.rs index fb13fd764bfa..27a599315dc1 100644 --- a/src/test/ui/drop/dropck_legal_cycles.rs +++ b/src/test/ui/drop/dropck_legal_cycles.rs @@ -368,7 +368,7 @@ pub fn main() { // We can use refcells if we're single-threaded (as this test is). // If one were to generalize these constructions to a // multi-threaded context, then it might seem like we could choose - // between either a RwLock or a Mutex to hold the owned arcs on + // between either an RwLock or a Mutex to hold the owned arcs on // each node. // // Part of the point of this test is to actually confirm that the From 6248dbcf70fbae9cf6fda9e2b2ba55aeb5837b36 Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Sun, 22 Aug 2021 12:41:53 +0200 Subject: [PATCH 085/269] =?UTF-8?q?Also=20fix=20=E2=80=9Ca=20`OwningRef`?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/rustc_data_structures/src/owning_ref/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_data_structures/src/owning_ref/mod.rs b/compiler/rustc_data_structures/src/owning_ref/mod.rs index 4689a027895c..e7397bf13bad 100644 --- a/compiler/rustc_data_structures/src/owning_ref/mod.rs +++ b/compiler/rustc_data_structures/src/owning_ref/mod.rs @@ -5,7 +5,7 @@ This crate provides the _owning reference_ types `OwningRef` and `OwningRefMut` that enables it to bundle a reference together with the owner of the data it points to. -This allows moving and dropping of a `OwningRef` without needing to recreate the reference. +This allows moving and dropping of an `OwningRef` without needing to recreate the reference. This can sometimes be useful because Rust borrowing rules normally prevent moving a type that has been moved from. For example, this kind of code gets rejected: From 96381d390d7362e06809ee624dba2cca1bc6776f Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 21:53:23 -0400 Subject: [PATCH 086/269] Fix: added necessary prefix --- src/test/assembly/asm/s390x-types.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index dd8a256516e6..ec0515b20bdf 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -51,7 +51,7 @@ extern "Rust" { macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { - dont_merge(stringify!(func)); + dont_merge(stringify!($func)); let y; asm!(concat!($mov," {}, {}"), out($class) y, in($class) x); @@ -62,7 +62,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { - dont_merge(stringify!(func)); + dont_merge(stringify!($func)); let y; asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); @@ -124,3 +124,9 @@ check!(reg_f32, f32, freg, "ler"); // CHECK: ldr %f{{[0-9]+}}, %f{{[0-9]+}} // CHECK: #NO_APP check!(reg_f64, f64, freg, "ldr"); + +// CHECK-LABEL: reg_ptr: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_ptr, ptr, reg, "lgr"); From 2af3b20ad8f3601cf6b21fb8bfa7dce59e17c5fe Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Aug 2021 19:42:31 -0700 Subject: [PATCH 087/269] Update books --- src/doc/book | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book b/src/doc/book index 7e49659102f0..687e21bde2ea 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 7e49659102f0977d9142190e1ba23345c0f00eb1 +Subproject commit 687e21bde2ea10c261f79fa14797c5137425098d diff --git a/src/doc/reference b/src/doc/reference index 4884fe45c14f..da6ea9b03f74 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 4884fe45c14f8b22121760fb117181bb4da8dfe0 +Subproject commit da6ea9b03f74cae0a292f40315723d7a3a973637 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 0dc9cd4e89f0..04f489c88923 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 0dc9cd4e89f00cb5230f120e1a083916386e422b +Subproject commit 04f489c889235fe3b6dfe678ae5410d07deda958 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index c4644b427cbd..cf0e151b7925 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit c4644b427cbdaafc7a87be0ccdf5d8aaa07ac35f +Subproject commit cf0e151b7925a40f13fbc6573c6f97d5f94c7c17 From e3f07b2e30eb29a737b13ab127db927d3825c22b Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Tue, 24 Aug 2021 10:18:07 +0200 Subject: [PATCH 088/269] Force inline: small functions and single call-site --- compiler/rustc_target/src/abi/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index b352243c0c44..49c06fca85ac 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -697,7 +697,7 @@ pub struct WrappingRange { impl WrappingRange { /// Returns `true` if `v` is contained in the range. - #[inline] + #[inline(always)] pub fn contains(&self, v: u128) -> bool { if self.start <= self.end { self.start <= v && v <= self.end @@ -708,17 +708,19 @@ impl WrappingRange { /// Returns `true` if zero is contained in the range. /// Equal to `range.contains(0)` but should be faster. - #[inline] + #[inline(always)] pub fn contains_zero(&self) -> bool { self.start > self.end || self.start == 0 } /// Returns new `WrappingRange` with replaced `start` + #[inline(always)] pub fn with_start(&self, start: u128) -> Self { Self { start, end: self.end } } /// Returns new `WrappingRange` with replaced `end` + #[inline(always)] pub fn with_end(&self, end: u128) -> Self { Self { start: self.start, end } } From 9f6f8620e188d5026f1b23d7714b4e41e2d92e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 19 Apr 2021 00:00:00 +0000 Subject: [PATCH 089/269] Improve liveness analysis for generators Liveness analysis for generators assumes that execution always continues normally after a yield point, not accounting for the fact that generator could be dropped before completion. If generators captures any variables by reference, those variables could be used within a generator, or when the generator completes, but also after each yield point in the case the generator is dropped. Account for the case when generator is dropped after yielding, but before running to the completion. This effectively considers all variables captured by reference to be used after a yield point. --- compiler/rustc_passes/src/liveness.rs | 14 +++- src/test/ui/liveness/liveness-upvars.rs | 36 ++++++++++ src/test/ui/liveness/liveness-upvars.stderr | 80 +++++++++++++++------ 3 files changed, 107 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 36d1a6c10442..edc0ff62bd5e 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -435,7 +435,10 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { } // live nodes required for interesting control flow: - hir::ExprKind::If(..) | hir::ExprKind::Match(..) | hir::ExprKind::Loop(..) => { + hir::ExprKind::If(..) + | hir::ExprKind::Match(..) + | hir::ExprKind::Loop(..) + | hir::ExprKind::Yield(..) => { self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id)); intravisit::walk_expr(self, expr); } @@ -469,7 +472,6 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { | hir::ExprKind::InlineAsm(..) | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::Box(..) - | hir::ExprKind::Yield(..) | hir::ExprKind::Type(..) | hir::ExprKind::Err | hir::ExprKind::Path(hir::QPath::TypeRelative(..)) @@ -866,6 +868,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // at the label ident hir::ExprKind::Loop(ref blk, ..) => self.propagate_through_loop(expr, &blk, succ), + hir::ExprKind::Yield(ref e, ..) => { + let yield_ln = self.live_node(expr.hir_id, expr.span); + self.init_from_succ(yield_ln, succ); + self.merge_from_succ(yield_ln, self.exit_ln); + self.propagate_through_expr(e, yield_ln) + } + hir::ExprKind::If(ref cond, ref then, ref else_opt) => { // // (cond) @@ -1025,7 +1034,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { | hir::ExprKind::Type(ref e, _) | hir::ExprKind::DropTemps(ref e) | hir::ExprKind::Unary(_, ref e) - | hir::ExprKind::Yield(ref e, _) | hir::ExprKind::Repeat(ref e, _) => self.propagate_through_expr(&e, succ), hir::ExprKind::InlineAsm(ref asm) => { diff --git a/src/test/ui/liveness/liveness-upvars.rs b/src/test/ui/liveness/liveness-upvars.rs index 98ea4d71ccf4..d446d57d3964 100644 --- a/src/test/ui/liveness/liveness-upvars.rs +++ b/src/test/ui/liveness/liveness-upvars.rs @@ -1,5 +1,6 @@ // edition:2018 // check-pass +#![feature(generators)] #![warn(unused)] #![allow(unreachable_code)] @@ -105,4 +106,39 @@ pub fn h() { }; } +async fn yield_now() { + todo!(); +} + +pub fn async_generator() { + let mut state: u32 = 0; + + let _ = async { + state = 1; + yield_now().await; + state = 2; + yield_now().await; + state = 3; + }; + + let _ = async move { + state = 4; //~ WARN value assigned to `state` is never read + //~| WARN unused variable: `state` + yield_now().await; + state = 5; //~ WARN value assigned to `state` is never read + }; +} + +pub fn generator() { + let mut s: u32 = 0; + let _ = |_| { + s = 0; + yield (); + s = 1; //~ WARN value assigned to `s` is never read + yield (s = 2); + s = yield (); //~ WARN value assigned to `s` is never read + s = 3; + }; +} + fn main() {} diff --git a/src/test/ui/liveness/liveness-upvars.stderr b/src/test/ui/liveness/liveness-upvars.stderr index 14fed9178643..d17233025136 100644 --- a/src/test/ui/liveness/liveness-upvars.stderr +++ b/src/test/ui/liveness/liveness-upvars.stderr @@ -1,11 +1,11 @@ warning: value assigned to `last` is never read - --> $DIR/liveness-upvars.rs:9:9 + --> $DIR/liveness-upvars.rs:10:9 | LL | last = Some(s); | ^^^^ | note: the lint level is defined here - --> $DIR/liveness-upvars.rs:3:9 + --> $DIR/liveness-upvars.rs:4:9 | LL | #![warn(unused)] | ^^^^^^ @@ -13,13 +13,13 @@ LL | #![warn(unused)] = help: maybe it is overwritten before being read? warning: unused variable: `last` - --> $DIR/liveness-upvars.rs:9:9 + --> $DIR/liveness-upvars.rs:10:9 | LL | last = Some(s); | ^^^^ | note: the lint level is defined here - --> $DIR/liveness-upvars.rs:3:9 + --> $DIR/liveness-upvars.rs:4:9 | LL | #![warn(unused)] | ^^^^^^ @@ -27,7 +27,7 @@ LL | #![warn(unused)] = help: did you mean to capture by reference instead? warning: unused variable: `sum` - --> $DIR/liveness-upvars.rs:21:9 + --> $DIR/liveness-upvars.rs:22:9 | LL | sum += x; | ^^^ @@ -35,7 +35,7 @@ LL | sum += x; = help: did you mean to capture by reference instead? warning: value captured by `c` is never read - --> $DIR/liveness-upvars.rs:31:9 + --> $DIR/liveness-upvars.rs:32:9 | LL | c = 1; | ^ @@ -43,7 +43,7 @@ LL | c = 1; = help: did you mean to capture by reference instead? warning: value captured by `c` is never read - --> $DIR/liveness-upvars.rs:35:9 + --> $DIR/liveness-upvars.rs:36:9 | LL | c = 1; | ^ @@ -51,7 +51,7 @@ LL | c = 1; = help: did you mean to capture by reference instead? warning: unused variable: `c` - --> $DIR/liveness-upvars.rs:41:9 + --> $DIR/liveness-upvars.rs:42:9 | LL | c += 1; | ^ @@ -59,7 +59,7 @@ LL | c += 1; = help: did you mean to capture by reference instead? warning: value assigned to `c` is never read - --> $DIR/liveness-upvars.rs:44:9 + --> $DIR/liveness-upvars.rs:45:9 | LL | c += 1; | ^ @@ -67,7 +67,7 @@ LL | c += 1; = help: maybe it is overwritten before being read? warning: unused variable: `c` - --> $DIR/liveness-upvars.rs:44:9 + --> $DIR/liveness-upvars.rs:45:9 | LL | c += 1; | ^ @@ -75,7 +75,7 @@ LL | c += 1; = help: did you mean to capture by reference instead? warning: value assigned to `c` is never read - --> $DIR/liveness-upvars.rs:57:9 + --> $DIR/liveness-upvars.rs:58:9 | LL | c += 1; | ^ @@ -83,7 +83,7 @@ LL | c += 1; = help: maybe it is overwritten before being read? warning: value assigned to `c` is never read - --> $DIR/liveness-upvars.rs:63:9 + --> $DIR/liveness-upvars.rs:64:9 | LL | c += 1; | ^ @@ -91,7 +91,7 @@ LL | c += 1; = help: maybe it is overwritten before being read? warning: value assigned to `d` is never read - --> $DIR/liveness-upvars.rs:72:13 + --> $DIR/liveness-upvars.rs:73:13 | LL | d = Some("d1"); | ^ @@ -99,7 +99,7 @@ LL | d = Some("d1"); = help: maybe it is overwritten before being read? warning: value assigned to `e` is never read - --> $DIR/liveness-upvars.rs:76:13 + --> $DIR/liveness-upvars.rs:77:13 | LL | e = Some("e1"); | ^ @@ -107,7 +107,7 @@ LL | e = Some("e1"); = help: maybe it is overwritten before being read? warning: value assigned to `e` is never read - --> $DIR/liveness-upvars.rs:78:13 + --> $DIR/liveness-upvars.rs:79:13 | LL | e = Some("e2"); | ^ @@ -115,7 +115,7 @@ LL | e = Some("e2"); = help: maybe it is overwritten before being read? warning: unused variable: `e` - --> $DIR/liveness-upvars.rs:76:13 + --> $DIR/liveness-upvars.rs:77:13 | LL | e = Some("e1"); | ^ @@ -123,7 +123,7 @@ LL | e = Some("e1"); = help: did you mean to capture by reference instead? warning: value assigned to `v` is never read - --> $DIR/liveness-upvars.rs:86:13 + --> $DIR/liveness-upvars.rs:87:13 | LL | v = T::default(); | ^ @@ -131,7 +131,7 @@ LL | v = T::default(); = help: maybe it is overwritten before being read? warning: value assigned to `z` is never read - --> $DIR/liveness-upvars.rs:98:17 + --> $DIR/liveness-upvars.rs:99:17 | LL | z = T::default(); | ^ @@ -139,12 +139,52 @@ LL | z = T::default(); = help: maybe it is overwritten before being read? warning: unused variable: `z` - --> $DIR/liveness-upvars.rs:98:17 + --> $DIR/liveness-upvars.rs:99:17 | LL | z = T::default(); | ^ | = help: did you mean to capture by reference instead? -warning: 17 warnings emitted +warning: value assigned to `state` is never read + --> $DIR/liveness-upvars.rs:125:9 + | +LL | state = 4; + | ^^^^^ + | + = help: maybe it is overwritten before being read? + +warning: value assigned to `state` is never read + --> $DIR/liveness-upvars.rs:128:9 + | +LL | state = 5; + | ^^^^^ + | + = help: maybe it is overwritten before being read? + +warning: unused variable: `state` + --> $DIR/liveness-upvars.rs:125:9 + | +LL | state = 4; + | ^^^^^ + | + = help: did you mean to capture by reference instead? + +warning: value assigned to `s` is never read + --> $DIR/liveness-upvars.rs:137:9 + | +LL | s = 1; + | ^ + | + = help: maybe it is overwritten before being read? + +warning: value assigned to `s` is never read + --> $DIR/liveness-upvars.rs:139:9 + | +LL | s = yield (); + | ^ + | + = help: maybe it is overwritten before being read? + +warning: 22 warnings emitted From 7ed9f2e6aa1e38ff43c0fe56bd9afc7f8aec28ba Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Tue, 24 Aug 2021 13:21:27 +0100 Subject: [PATCH 090/269] Ignore test on Windows --- src/test/run-make-fulldeps/remap-path-prefix/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/run-make-fulldeps/remap-path-prefix/Makefile b/src/test/run-make-fulldeps/remap-path-prefix/Makefile index b01f406e5582..86785c59509d 100644 --- a/src/test/run-make-fulldeps/remap-path-prefix/Makefile +++ b/src/test/run-make-fulldeps/remap-path-prefix/Makefile @@ -1,5 +1,7 @@ -include ../tools.mk +# ignore-windows + # Checks if remapping works if the remap-from string contains path to the working directory plus more all: $(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs From 0b81c2eb82c3663e691c568394455f80dd532fa1 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Thu, 19 Aug 2021 16:34:01 -0400 Subject: [PATCH 091/269] Move `named_asm_labels` to a HIR lint --- compiler/rustc_ast/src/ast.rs | 1 + compiler/rustc_ast/src/visit.rs | 6 +- compiler/rustc_ast_lowering/src/asm.rs | 4 +- compiler/rustc_builtin_macros/src/asm.rs | 90 +++------------- compiler/rustc_hir/src/hir.rs | 1 + compiler/rustc_lint/src/builtin.rs | 124 +++++++++++++++++++++- compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint_defs/src/builtin.rs | 33 ------ src/test/ui/asm/named-asm-labels.rs | 66 +++++++++++- src/test/ui/asm/named-asm-labels.stderr | 125 +++++++++++++++++------ 10 files changed, 304 insertions(+), 147 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 575a00cdd0e4..2c2d30d872e2 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2028,6 +2028,7 @@ pub enum InlineAsmOperand { #[derive(Clone, Encodable, Decodable, Debug)] pub struct InlineAsm { pub template: Vec, + pub template_strs: Box<[(Symbol, Option, Span)]>, pub operands: Vec<(InlineAsmOperand, Span)>, pub clobber_abi: Option<(Symbol, Span)>, pub options: InlineAsmOptions, diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index a377763983a4..774d5cb2dda9 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -19,20 +19,20 @@ use crate::token; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum AssocCtxt { Trait, Impl, } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum FnCtxt { Free, Foreign, Assoc(AssocCtxt), } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub enum FnKind<'a> { /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, Option<&'a Block>), diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index d94fb48d7cb8..b9b27855a0b8 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -392,8 +392,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let operands = self.arena.alloc_from_iter(operands); let template = self.arena.alloc_from_iter(asm.template.iter().cloned()); + let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned()); let line_spans = self.arena.alloc_slice(&asm.line_spans[..]); - let hir_asm = hir::InlineAsm { template, operands, options: asm.options, line_spans }; + let hir_asm = + hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans }; self.arena.alloc(hir_asm) } } diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index cb0cfdcefdc2..652165fb9b60 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -7,10 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_expand::base::{self, *}; use rustc_parse::parser::Parser; use rustc_parse_format as parse; -use rustc_session::lint::{self, BuiltinLintDiagnostics}; +use rustc_session::lint; use rustc_span::symbol::Ident; use rustc_span::symbol::{kw, sym, Symbol}; -use rustc_span::{InnerSpan, MultiSpan, Span}; +use rustc_span::{InnerSpan, Span}; use rustc_target::asm::InlineAsmArch; use smallvec::smallvec; @@ -484,11 +484,7 @@ fn parse_reg<'a>( Ok(result) } -fn expand_preparsed_asm( - ecx: &mut ExtCtxt<'_>, - args: AsmArgs, - is_local_asm: bool, -) -> Option { +fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option { let mut template = vec![]; // Register operands are implicitly used since they are not allowed to be // referenced in the template string. @@ -501,6 +497,8 @@ fn expand_preparsed_asm( let mut line_spans = Vec::with_capacity(args.templates.len()); let mut curarg = 0; + let mut template_strs = Vec::with_capacity(args.templates.len()); + for template_expr in args.templates.into_iter() { if !template.is_empty() { template.push(ast::InlineAsmTemplatePiece::String("\n".to_string())); @@ -524,8 +522,13 @@ fn expand_preparsed_asm( ast::StrStyle::Raw(raw) => Some(raw as usize), }; - let template_str = &template_str.as_str(); let template_snippet = ecx.source_map().span_to_snippet(template_sp).ok(); + template_strs.push(( + template_str, + template_snippet.as_ref().map(|s| Symbol::intern(s)), + template_sp, + )); + let template_str = &template_str.as_str(); if let Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) = ecx.sess.asm_arch { let find_span = |needle: &str| -> Span { @@ -560,72 +563,6 @@ fn expand_preparsed_asm( } } - // Lint against the use of named labels in inline `asm!` but not `global_asm!` - if is_local_asm { - let find_label_span = |needle: &str| -> Option { - if let Some(snippet) = &template_snippet { - if let Some(pos) = snippet.find(needle) { - let end = pos - + &snippet[pos..] - .find(|c| c == ':') - .unwrap_or(snippet[pos..].len() - 1); - let inner = InnerSpan::new(pos, end); - return Some(template_sp.from_inner(inner)); - } - } - - None - }; - - let mut found_labels = Vec::new(); - - // A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always - let statements = template_str.split(|c| matches!(c, '\n' | ';')); - for statement in statements { - // If there's a comment, trim it from the statement - let statement = statement.find("//").map_or(statement, |idx| &statement[..idx]); - let mut start_idx = 0; - for (idx, _) in statement.match_indices(':') { - let possible_label = statement[start_idx..idx].trim(); - let mut chars = possible_label.chars(); - if let Some(c) = chars.next() { - // A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $ - if (c.is_alphabetic() || matches!(c, '.' | '_')) - && chars.all(|c| c.is_alphanumeric() || matches!(c, '_' | '$')) - { - found_labels.push(possible_label); - } else { - // If we encounter a non-label, there cannot be any further labels, so stop checking - break; - } - } else { - // Empty string means a leading ':' in this section, which is not a label - break; - } - - start_idx = idx + 1; - } - } - - if found_labels.len() > 0 { - let spans = - found_labels.into_iter().filter_map(find_label_span).collect::>(); - // If there were labels but we couldn't find a span, combine the warnings and use the template span - let target_spans: MultiSpan = - if spans.len() > 0 { spans.into() } else { template_sp.into() }; - ecx.parse_sess().buffer_lint_with_diagnostic( - lint::builtin::NAMED_ASM_LABELS, - target_spans, - ecx.current_expansion.lint_node_id, - "avoid using named labels in inline assembly", - BuiltinLintDiagnostics::NamedAsmLabel( - "only local labels of the form `:` should be used in inline asm" - .to_string(), - ), - ); - } - } - // Don't treat raw asm as a format string. if args.options.contains(ast::InlineAsmOptions::RAW) { template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string())); @@ -819,6 +756,7 @@ fn expand_preparsed_asm( Some(ast::InlineAsm { template, + template_strs: template_strs.into_boxed_slice(), operands: args.operands, clobber_abi: args.clobber_abi, options: args.options, @@ -833,7 +771,7 @@ pub fn expand_asm<'cx>( ) -> Box { match parse_args(ecx, sp, tts, false) { Ok(args) => { - let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args, true) { + let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args) { P(ast::Expr { id: ast::DUMMY_NODE_ID, kind: ast::ExprKind::InlineAsm(P(inline_asm)), @@ -860,7 +798,7 @@ pub fn expand_global_asm<'cx>( ) -> Box { match parse_args(ecx, sp, tts, true) { Ok(args) => { - if let Some(inline_asm) = expand_preparsed_asm(ecx, args, false) { + if let Some(inline_asm) = expand_preparsed_asm(ecx, args) { MacEager::items(smallvec![P(ast::Item { ident: Ident::invalid(), attrs: Vec::new(), diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 888d1c1832b0..38deb8eaaae6 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2386,6 +2386,7 @@ impl<'hir> InlineAsmOperand<'hir> { #[derive(Debug, HashStable_Generic)] pub struct InlineAsm<'hir> { pub template: &'hir [InlineAsmTemplatePiece], + pub template_strs: &'hir [(Symbol, Option, Span)], pub operands: &'hir [(InlineAsmOperand<'hir>, Span)], pub options: InlineAsmOptions, pub line_spans: &'hir [Span], diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index afa2cfca1880..add0c0ff332f 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -45,11 +45,11 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, Subst}; use rustc_middle::ty::Instance; use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt}; -use rustc_session::lint::FutureIncompatibilityReason; +use rustc_session::lint::{BuiltinLintDiagnostics, FutureIncompatibilityReason}; use rustc_span::edition::Edition; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use rustc_span::{BytePos, Span}; +use rustc_span::{BytePos, InnerSpan, MultiSpan, Span}; use rustc_target::abi::{LayoutOf, VariantIdx}; use rustc_trait_selection::traits::misc::can_type_implement_copy; @@ -3140,3 +3140,123 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr { } } } + +declare_lint! { + /// The `named_asm_labels` lint detects the use of named labels in the + /// inline `asm!` macro. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![feature(asm)] + /// fn main() { + /// unsafe { + /// asm!("foo: bar"); + /// } + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// LLVM is allowed to duplicate inline assembly blocks for any + /// reason, for example when it is in a function that gets inlined. Because + /// of this, GNU assembler [local labels] *must* be used instead of labels + /// with a name. Using named labels might cause assembler or linker errors. + /// + /// See the [unstable book] for more details. + /// + /// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels + /// [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels + pub NAMED_ASM_LABELS, + Deny, + "named labels in inline assembly", +} + +declare_lint_pass!(NamedAsmLabels => [NAMED_ASM_LABELS]); + +impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { + if let hir::Expr { + kind: hir::ExprKind::InlineAsm(hir::InlineAsm { template_strs, .. }), + .. + } = expr + { + for (template_sym, template_snippet, template_span) in template_strs.iter() { + let template_str = &template_sym.as_str(); + let find_label_span = |needle: &str| -> Option { + if let Some(template_snippet) = template_snippet { + let snippet = template_snippet.as_str(); + if let Some(pos) = snippet.find(needle) { + let end = pos + + &snippet[pos..] + .find(|c| c == ':') + .unwrap_or(snippet[pos..].len() - 1); + let inner = InnerSpan::new(pos, end); + return Some(template_span.from_inner(inner)); + } + } + + None + }; + + let mut found_labels = Vec::new(); + + // A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always + let statements = template_str.split(|c| matches!(c, '\n' | ';')); + for statement in statements { + // If there's a comment, trim it from the statement + let statement = statement.find("//").map_or(statement, |idx| &statement[..idx]); + let mut start_idx = 0; + for (idx, _) in statement.match_indices(':') { + let possible_label = statement[start_idx..idx].trim(); + let mut chars = possible_label.chars(); + if let Some(c) = chars.next() { + // A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $ + if (c.is_alphabetic() || matches!(c, '.' | '_')) + && chars.all(|c| c.is_alphanumeric() || matches!(c, '_' | '$')) + { + found_labels.push(possible_label); + } else { + // If we encounter a non-label, there cannot be any further labels, so stop checking + break; + } + } else { + // Empty string means a leading ':' in this section, which is not a label + break; + } + + start_idx = idx + 1; + } + } + + debug!("NamedAsmLabels::check_expr(): found_labels: {:#?}", &found_labels); + + if found_labels.len() > 0 { + let spans = found_labels + .into_iter() + .filter_map(|label| find_label_span(label)) + .collect::>(); + // If there were labels but we couldn't find a span, combine the warnings and use the template span + let target_spans: MultiSpan = + if spans.len() > 0 { spans.into() } else { (*template_span).into() }; + + cx.lookup_with_diagnostics( + NAMED_ASM_LABELS, + Some(target_spans), + |diag| { + let mut err = + diag.build("avoid using named labels in inline assembly"); + err.emit(); + }, + BuiltinLintDiagnostics::NamedAsmLabel( + "only local labels of the form `:` should be used in inline asm" + .to_string(), + ), + ); + } + } + } + } +} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index c4008e77bab7..24ac723f2c91 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -168,6 +168,7 @@ macro_rules! late_lint_passes { NonPanicFmt: NonPanicFmt, NoopMethodCall: NoopMethodCall, InvalidAtomicOrdering: InvalidAtomicOrdering, + NamedAsmLabels: NamedAsmLabels, ] ); }; diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index a1c507b4c847..1d978b6c8292 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2468,38 +2468,6 @@ declare_lint! { "incorrect use of inline assembly", } -declare_lint! { - /// The `named_asm_labels` lint detects the use of named labels in the - /// inline `asm!` macro. - /// - /// ### Example - /// - /// ```rust,compile_fail - /// fn main() { - /// unsafe { - /// asm!("foo: bar"); - /// } - /// } - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// LLVM is allowed to duplicate inline assembly blocks for any - /// reason, for example when it is in a function that gets inlined. Because - /// of this, GNU assembler [local labels] *must* be used instead of labels - /// with a name. Using named labels might cause assembler or linker errors. - /// - /// See the [unstable book] for more details. - /// - /// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels - /// [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels - pub NAMED_ASM_LABELS, - Deny, - "named labels in inline assembly", -} - declare_lint! { /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe /// functions without an explicit unsafe block. @@ -3020,7 +2988,6 @@ declare_lint_pass! { INLINE_NO_SANITIZE, BAD_ASM_STYLE, ASM_SUB_REGISTER, - NAMED_ASM_LABELS, UNSAFE_OP_IN_UNSAFE_FN, INCOMPLETE_INCLUDE, CENUM_IMPL_DROP_CAST, diff --git a/src/test/ui/asm/named-asm-labels.rs b/src/test/ui/asm/named-asm-labels.rs index 803501b40b68..9f487bd8061f 100644 --- a/src/test/ui/asm/named-asm-labels.rs +++ b/src/test/ui/asm/named-asm-labels.rs @@ -1,6 +1,14 @@ // only-x86_64 -#![feature(asm, global_asm)] +// Tests that the use of named labels in the `asm!` macro are linted against +// except for in `#[naked]` fns. +// Using a named label is incorrect as per the RFC because for most cases +// the compiler cannot ensure that inline asm is emitted exactly once per +// codegen unit (except for naked fns) and so the label could be duplicated +// which causes less readable LLVM errors and in the worst cases causes ICEs +// or segfaults based on system dependent behavior and codegen flags. + +#![feature(asm, global_asm, naked_functions)] #[no_mangle] pub static FOO: usize = 42; @@ -126,5 +134,61 @@ fn main() { } } +// Trigger on naked fns too, even though they can't be inlined, reusing a +// label or LTO can cause labels to break +#[naked] +pub extern "C" fn foo() -> i32 { + unsafe { asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } //~ ERROR avoid using named labels +} + +// Make sure that non-naked attributes *do* still let the lint happen +#[no_mangle] +pub extern "C" fn bar() { + unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } + //~^ ERROR avoid using named labels +} + +#[naked] +pub extern "C" fn aaa() { + fn _local() {} + + unsafe { asm!(".Laaa: nop; ret;", options(noreturn)) } //~ ERROR avoid using named labels +} + +pub fn normal() { + fn _local1() {} + + #[naked] + pub extern "C" fn bbb() { + fn _very_local() {} + + unsafe { asm!(".Lbbb: nop; ret;", options(noreturn)) } //~ ERROR avoid using named labels + } + + fn _local2() {} +} + +// Make sure that the lint happens within closures +fn closures() { + || unsafe { + asm!("closure1: nop"); //~ ERROR avoid using named labels + }; + + move || unsafe { + asm!("closure2: nop"); //~ ERROR avoid using named labels + }; + + || { + #[naked] + unsafe extern "C" fn _nested() { + asm!("ret;", options(noreturn)); + } + + unsafe { + asm!("closure3: nop"); //~ ERROR avoid using named labels + } + }; +} + // Don't trigger on global asm global_asm!("aaaaaaaa: nop"); diff --git a/src/test/ui/asm/named-asm-labels.stderr b/src/test/ui/asm/named-asm-labels.stderr index 3c4a4db75e02..396f0a194242 100644 --- a/src/test/ui/asm/named-asm-labels.stderr +++ b/src/test/ui/asm/named-asm-labels.stderr @@ -1,5 +1,5 @@ error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:11:15 + --> $DIR/named-asm-labels.rs:19:15 | LL | asm!("bar: nop"); | ^^^ @@ -9,7 +9,7 @@ LL | asm!("bar: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:14:15 + --> $DIR/named-asm-labels.rs:22:15 | LL | asm!("abcd:"); | ^^^^ @@ -18,7 +18,7 @@ LL | asm!("abcd:"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:17:15 + --> $DIR/named-asm-labels.rs:25:15 | LL | asm!("foo: bar1: nop"); | ^^^ ^^^^ @@ -27,7 +27,7 @@ LL | asm!("foo: bar1: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:21:15 + --> $DIR/named-asm-labels.rs:29:15 | LL | asm!("foo1: nop", "nop"); | ^^^^ @@ -36,7 +36,7 @@ LL | asm!("foo1: nop", "nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:22:15 + --> $DIR/named-asm-labels.rs:30:15 | LL | asm!("foo2: foo3: nop", "nop"); | ^^^^ ^^^^ @@ -45,7 +45,7 @@ LL | asm!("foo2: foo3: nop", "nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:24:22 + --> $DIR/named-asm-labels.rs:32:22 | LL | asm!("nop", "foo4: nop"); | ^^^^ @@ -54,7 +54,7 @@ LL | asm!("nop", "foo4: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:25:15 + --> $DIR/named-asm-labels.rs:33:15 | LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ @@ -63,7 +63,7 @@ LL | asm!("foo5: nop", "foo6: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:25:28 + --> $DIR/named-asm-labels.rs:33:28 | LL | asm!("foo5: nop", "foo6: nop"); | ^^^^ @@ -72,7 +72,7 @@ LL | asm!("foo5: nop", "foo6: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:30:15 + --> $DIR/named-asm-labels.rs:38:15 | LL | asm!("foo7: nop; foo8: nop"); | ^^^^ ^^^^ @@ -81,7 +81,7 @@ LL | asm!("foo7: nop; foo8: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:32:15 + --> $DIR/named-asm-labels.rs:40:15 | LL | asm!("foo9: nop; nop"); | ^^^^ @@ -90,7 +90,7 @@ LL | asm!("foo9: nop; nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:33:20 + --> $DIR/named-asm-labels.rs:41:20 | LL | asm!("nop; foo10: nop"); | ^^^^^ @@ -99,7 +99,7 @@ LL | asm!("nop; foo10: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:36:15 + --> $DIR/named-asm-labels.rs:44:15 | LL | asm!("bar2: nop\n bar3: nop"); | ^^^^ ^^^^ @@ -108,7 +108,7 @@ LL | asm!("bar2: nop\n bar3: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:38:15 + --> $DIR/named-asm-labels.rs:46:15 | LL | asm!("bar4: nop\n nop"); | ^^^^ @@ -117,7 +117,7 @@ LL | asm!("bar4: nop\n nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:39:21 + --> $DIR/named-asm-labels.rs:47:21 | LL | asm!("nop\n bar5: nop"); | ^^^^ @@ -126,7 +126,7 @@ LL | asm!("nop\n bar5: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:40:21 + --> $DIR/named-asm-labels.rs:48:21 | LL | asm!("nop\n bar6: bar7: nop"); | ^^^^ ^^^^ @@ -135,7 +135,7 @@ LL | asm!("nop\n bar6: bar7: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:46:13 + --> $DIR/named-asm-labels.rs:54:13 | LL | blah2: nop | ^^^^^ @@ -146,7 +146,7 @@ LL | blah3: nop = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:55:19 + --> $DIR/named-asm-labels.rs:63:19 | LL | nop ; blah4: nop | ^^^^^ @@ -155,7 +155,7 @@ LL | nop ; blah4: nop = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:69:15 + --> $DIR/named-asm-labels.rs:77:15 | LL | asm!("blah1: 2bar: nop"); | ^^^^^ @@ -164,7 +164,7 @@ LL | asm!("blah1: 2bar: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:72:15 + --> $DIR/named-asm-labels.rs:80:15 | LL | asm!("def: def: nop"); | ^^^ @@ -173,7 +173,7 @@ LL | asm!("def: def: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:73:15 + --> $DIR/named-asm-labels.rs:81:15 | LL | asm!("def: nop\ndef: nop"); | ^^^ @@ -182,7 +182,7 @@ LL | asm!("def: nop\ndef: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:74:15 + --> $DIR/named-asm-labels.rs:82:15 | LL | asm!("def: nop; def: nop"); | ^^^ @@ -191,7 +191,7 @@ LL | asm!("def: nop; def: nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:82:15 + --> $DIR/named-asm-labels.rs:90:15 | LL | asm!("fooo\u{003A} nop"); | ^^^^^^^^^^^^^^^^ @@ -200,7 +200,7 @@ LL | asm!("fooo\u{003A} nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:83:15 + --> $DIR/named-asm-labels.rs:91:15 | LL | asm!("foooo\x3A nop"); | ^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | asm!("foooo\x3A nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:86:15 + --> $DIR/named-asm-labels.rs:94:15 | LL | asm!("fooooo:\u{000A} nop"); | ^^^^^^ @@ -218,7 +218,7 @@ LL | asm!("fooooo:\u{000A} nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:87:15 + --> $DIR/named-asm-labels.rs:95:15 | LL | asm!("foooooo:\x0A nop"); | ^^^^^^^ @@ -227,7 +227,7 @@ LL | asm!("foooooo:\x0A nop"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:91:14 + --> $DIR/named-asm-labels.rs:99:14 | LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +236,7 @@ LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70"); = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:102:13 + --> $DIR/named-asm-labels.rs:110:13 | LL | ab: nop // ab: does foo | ^^ @@ -245,7 +245,7 @@ LL | ab: nop // ab: does foo = note: see the asm section of the unstable book for more information error: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:114:14 + --> $DIR/named-asm-labels.rs:122:14 | LL | asm!(include_str!("named-asm-labels.s")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -254,18 +254,81 @@ LL | asm!(include_str!("named-asm-labels.s")); = note: see the asm section of the unstable book for more information warning: avoid using named labels in inline assembly - --> $DIR/named-asm-labels.rs:124:19 + --> $DIR/named-asm-labels.rs:132:19 | LL | asm!("warned: nop"); | ^^^^^^ | note: the lint level is defined here - --> $DIR/named-asm-labels.rs:122:16 + --> $DIR/named-asm-labels.rs:130:16 | LL | #[warn(named_asm_labels)] | ^^^^^^^^^^^^^^^^ = help: only local labels of the form `:` should be used in inline asm = note: see the asm section of the unstable book for more information -error: aborting due to 28 previous errors; 1 warning emitted +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:141:20 + | +LL | unsafe { asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } + | ^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:147:20 + | +LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noreturn)) } + | ^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:155:20 + | +LL | unsafe { asm!(".Laaa: nop; ret;", options(noreturn)) } + | ^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:165:24 + | +LL | unsafe { asm!(".Lbbb: nop; ret;", options(noreturn)) } + | ^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:174:15 + | +LL | asm!("closure1: nop"); + | ^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:178:15 + | +LL | asm!("closure2: nop"); + | ^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: avoid using named labels in inline assembly + --> $DIR/named-asm-labels.rs:188:19 + | +LL | asm!("closure3: nop"); + | ^^^^^^^^ + | + = help: only local labels of the form `:` should be used in inline asm + = note: see the asm section of the unstable book for more information + +error: aborting due to 35 previous errors; 1 warning emitted From d89b4a705c0de7a8239b7b750950dfa511c2ff81 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 23 Jul 2021 23:59:17 -0700 Subject: [PATCH 092/269] Tidy up lint command line flags --- compiler/rustc_session/src/config.rs | 16 +++++----------- src/librustdoc/lib.rs | 17 +++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 123f47b430a1..ca4ae238ae53 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1089,10 +1089,11 @@ pub fn rustc_short_optgroups() -> Vec { ), opt::flag_s("", "test", "Build a test harness"), opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"), - opt::multi_s("W", "warn", "Set lint warnings", "OPT"), - opt::multi_s("A", "allow", "Set lint allowed", "OPT"), - opt::multi_s("D", "deny", "Set lint denied", "OPT"), - opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"), + opt::multi_s("A", "allow", "Set lint allowed", "LINT"), + opt::multi_s("W", "warn", "Set lint warnings", "LINT"), + opt::multi_s("", "force-warn", "Set lint force-warn", "LINT"), + opt::multi_s("D", "deny", "Set lint denied", "LINT"), + opt::multi_s("F", "forbid", "Set lint forbidden", "LINT"), opt::multi_s( "", "cap-lints", @@ -1101,13 +1102,6 @@ pub fn rustc_short_optgroups() -> Vec { level", "LEVEL", ), - opt::multi_s( - "", - "force-warn", - "Specifiy lints that should warn even if \ - they are allowed somewhere else", - "LINT", - ), opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"), opt::flag_s("V", "version", "Print version info and exit"), opt::flag_s("v", "verbose", "Use verbose output"), diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 34fe808dae2e..d745896e9466 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -503,10 +503,11 @@ fn opts() -> Vec { unstable("disable-minification", |o| { o.optflagmulti("", "disable-minification", "Disable minification applied on JS files") }), - stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")), - stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")), - stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "OPT")), - stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "OPT")), + stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")), + stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")), + unstable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")), + stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")), + stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")), stable("cap-lints", |o| { o.optmulti( "", @@ -517,14 +518,6 @@ fn opts() -> Vec { "LEVEL", ) }), - unstable("force-warn", |o| { - o.optopt( - "", - "force-warn", - "Lints that will warn even if allowed somewhere else", - "LINTS", - ) - }), unstable("index-page", |o| { o.optopt("", "index-page", "Markdown file to be used as index page", "PATH") }), From aee2c30f697797b4dabf92517e797f6f986b2312 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Sat, 24 Jul 2021 00:05:24 -0700 Subject: [PATCH 093/269] Stabilize `force-warn` --- compiler/rustc_session/src/config.rs | 12 +----------- src/librustdoc/config.rs | 3 +-- src/librustdoc/lib.rs | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index ca4ae238ae53..fdedb7e6a4af 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1157,19 +1157,10 @@ pub fn rustc_optgroups() -> Vec { pub fn get_cmd_lint_options( matches: &getopts::Matches, error_format: ErrorOutputType, - debugging_opts: &DebuggingOptions, ) -> (Vec<(String, lint::Level)>, bool, Option) { let mut lint_opts_with_position = vec![]; let mut describe_lints = false; - if !debugging_opts.unstable_options && matches.opt_present("force-warn") { - early_error( - error_format, - "the `-Z unstable-options` flag must also be passed to enable \ - the flag `--force-warn=lints`", - ); - } - for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] { for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { if lint_name == "help" { @@ -1959,8 +1950,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { .unwrap_or_else(|e| early_error(error_format, &e[..])); let mut debugging_opts = DebuggingOptions::build(matches, error_format); - let (lint_opts, describe_lints, lint_cap) = - get_cmd_lint_options(matches, error_format, &debugging_opts); + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); check_debug_option_stability(&debugging_opts, error_format, json_rendered); diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index eef6985ea30a..97930f106994 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -671,8 +671,7 @@ impl Options { return Err(1); } - let (lint_opts, describe_lints, lint_cap) = - get_cmd_lint_options(matches, error_format, &debugging_opts); + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); Ok(Options { input, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d745896e9466..4eae813aff7b 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -505,7 +505,7 @@ fn opts() -> Vec { }), stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")), stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")), - unstable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")), + stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")), stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")), stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")), stable("cap-lints", |o| { From 228a5f40966de084fe4a81cf3aff9c531fa51799 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 23 Jul 2021 23:31:09 -0700 Subject: [PATCH 094/269] Document `force-warn` Co-authored-by: Mark Rousskov --- src/doc/rustc/src/lints/levels.md | 39 +++++++++++++------ .../src/compiler-flags/force-warn.md | 21 ---------- 2 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 src/doc/unstable-book/src/compiler-flags/force-warn.md diff --git a/src/doc/rustc/src/lints/levels.md b/src/doc/rustc/src/lints/levels.md index 3e616f226ed7..7bd46fafadf8 100644 --- a/src/doc/rustc/src/lints/levels.md +++ b/src/doc/rustc/src/lints/levels.md @@ -1,11 +1,12 @@ # Lint levels -In `rustc`, lints are divided into four *levels*: +In `rustc`, lints are divided into five *levels*: 1. allow 2. warn -3. deny -4. forbid +3. force-warn +4. deny +5. forbid Each lint has a default level (explained in the lint listing later in this chapter), and the compiler has a default warning level. First, let's explain @@ -57,6 +58,14 @@ warning: unused variable: `x` = note: to avoid this warning, consider using `_x` instead ``` +## force-warn + +'force-warn' is a special lint level. It's the same as 'warn' in that a lint +at this level will produce a warning, but unlike the 'warn' level, the +'force-warn' level cannot be overridden. If a lint is set to 'force-warn', it +is guaranteed to warn: no more, no less. This is true even if the overall lint +level is capped via cap-lints. + ## deny A 'deny' lint produces an error if you violate it. For example, this code @@ -87,11 +96,12 @@ This lint level gives you that. ## forbid -'forbid' is a special lint level that's stronger than 'deny'. It's the same -as 'deny' in that a lint at this level will produce an error, but unlike the -'deny' level, the 'forbid' level can not be overridden to be anything lower -than an error. However, lint levels may still be capped with `--cap-lints` -(see below) so `rustc --cap-lints warn` will make lints set to 'forbid' just +'forbid' is a special lint level that fills the same role for 'deny' that +'force-warn' does for 'warn'. It's the same as 'deny' in that a lint at this +level will produce an error, but unlike the 'deny' level, the 'forbid' level +can not be overridden to be anything lower than an error. However, lint +levels may still be capped with `--cap-lints` (see below) so `rustc --cap- +lints warn` will make lints set to 'forbid' just warn. ## Configuring warning levels @@ -113,8 +123,8 @@ certain lint levels. We'll talk about that last. ### Via compiler flag -The `-A`, `-W`, `-D`, and `-F` flags let you turn one or more lints -into allowed, warning, deny, or forbid levels, like this: +The `-A`, `-W`, `--force-warn` `-D`, and `-F` flags let you turn one or more lints +into allowed, warning, force-warn, deny, or forbid levels, like this: ```bash $ rustc lib.rs --crate-type=lib -W missing-docs @@ -158,7 +168,7 @@ You can also pass each flag more than once for changing multiple lints: $ rustc lib.rs --crate-type=lib -D missing-docs -D unused-variables ``` -And of course, you can mix these four flags together: +And of course, you can mix these five flags together: ```bash $ rustc lib.rs --crate-type=lib -D missing-docs -A unused-variables @@ -176,6 +186,10 @@ You can make use of this behavior by overriding the level of one specific lint o $ rustc lib.rs --crate-type=lib -D unused -A unused-variables ``` +Since `force-warn` and `forbid` cannot be overridden, setting +one of them will prevent any later level for the same lint from +taking effect. + ### Via an attribute You can also modify the lint level with a crate-wide attribute: @@ -207,7 +221,8 @@ warning: missing documentation for a function | ^^^^^^^^^^^^ ``` -All four, `warn`, `allow`, `deny`, and `forbid` all work this way. +`warn`, `allow`, `deny`, and `forbid` all work this way. There is +no way to set a lint to `force-warn` using an attribute. You can also pass in multiple lints per attribute: diff --git a/src/doc/unstable-book/src/compiler-flags/force-warn.md b/src/doc/unstable-book/src/compiler-flags/force-warn.md deleted file mode 100644 index 052de0f379e7..000000000000 --- a/src/doc/unstable-book/src/compiler-flags/force-warn.md +++ /dev/null @@ -1,21 +0,0 @@ -# `force-warn` - -The tracking issue for this feature is: [#85512](https://github.com/rust-lang/rust/issues/85512). - ------------------------- - -This feature allows you to cause any lint to produce a warning even if the lint has a different level by default or another level is set somewhere else. For instance, the `force-warn` option can be used to make a lint (e.g., `dead_code`) produce a warning even if that lint is allowed in code with `#![allow(dead_code)]`. - -## Example - -```rust,ignore (partial-example) -#![allow(dead_code)] - -fn dead_function() {} -// This would normally not produce a warning even though the -// function is not used, because dead code is being allowed - -fn main() {} -``` - -We can force a warning to be produced by providing `--force-warn dead_code` to rustc. From 1f3170cf164e1b744d007d924e042d6f394fa79b Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Sat, 24 Jul 2021 01:08:33 -0700 Subject: [PATCH 095/269] Update tests This updates tests to reflect that `force-warn` is now stable. --- src/test/run-make/unstable-flag-required/Makefile | 1 - src/test/run-make/unstable-flag-required/force-warn.stderr | 2 -- src/test/ui/lint/cli-lint-override.rs | 2 +- src/test/ui/lint/cli-unknown-force-warn.rs | 2 +- src/test/ui/lint/cli-unknown-force-warn.stderr | 6 +----- src/test/ui/lint/force-warn/allow-warnings.rs | 2 +- src/test/ui/lint/force-warn/allowed-by-default-lint.rs | 2 +- src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs | 2 +- .../lint/force-warn/allowed-group-warn-by-default-lint.rs | 2 +- src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs | 2 +- src/test/ui/lint/force-warn/cap-lints-allow.rs | 2 +- .../cap-lints-warn-allowed-warn-by-default-lint.rs | 2 +- src/test/ui/lint/force-warn/deny-by-default-lint.rs | 2 +- src/test/ui/lint/force-warn/lint-group-allow-warnings.rs | 2 +- .../ui/lint/force-warn/lint-group-allowed-lint-group.rs | 2 +- .../force-warn/lint-group-allowed-warn-by-default-lint.rs | 2 +- 16 files changed, 14 insertions(+), 21 deletions(-) delete mode 100644 src/test/run-make/unstable-flag-required/force-warn.stderr diff --git a/src/test/run-make/unstable-flag-required/Makefile b/src/test/run-make/unstable-flag-required/Makefile index a9aad54162f1..b8769d5f6905 100644 --- a/src/test/run-make/unstable-flag-required/Makefile +++ b/src/test/run-make/unstable-flag-required/Makefile @@ -2,4 +2,3 @@ all: $(RUSTDOC) --output-format=json x.html 2>&1 | diff - output-format-json.stderr - $(RUSTC) --force-warn dead_code x.rs 2>&1 | diff - force-warn.stderr diff --git a/src/test/run-make/unstable-flag-required/force-warn.stderr b/src/test/run-make/unstable-flag-required/force-warn.stderr deleted file mode 100644 index 1b70dc83bdb1..000000000000 --- a/src/test/run-make/unstable-flag-required/force-warn.stderr +++ /dev/null @@ -1,2 +0,0 @@ -error: the `-Z unstable-options` flag must also be passed to enable the flag `--force-warn=lints` - diff --git a/src/test/ui/lint/cli-lint-override.rs b/src/test/ui/lint/cli-lint-override.rs index a0a96d01be3f..7d762b05c97b 100644 --- a/src/test/ui/lint/cli-lint-override.rs +++ b/src/test/ui/lint/cli-lint-override.rs @@ -5,7 +5,7 @@ // //[warn_deny] compile-flags: --warn missing_abi --deny missing_abi //[forbid_warn] compile-flags: --warn missing_abi --forbid missing_abi -//[force_warn_deny] compile-flags: -Z unstable-options --force-warn missing_abi --allow missing_abi +//[force_warn_deny] compile-flags: --force-warn missing_abi --allow missing_abi //[force_warn_deny] check-pass diff --git a/src/test/ui/lint/cli-unknown-force-warn.rs b/src/test/ui/lint/cli-unknown-force-warn.rs index 55544cc73781..f3dea87a6b69 100644 --- a/src/test/ui/lint/cli-unknown-force-warn.rs +++ b/src/test/ui/lint/cli-unknown-force-warn.rs @@ -1,7 +1,7 @@ // Checks that rustc correctly errors when passed an invalid lint with // `--force-warn`. This is a regression test for issue #86958. // -// compile-flags: -Z unstable-options --force-warn foo-qux +// compile-flags: --force-warn foo-qux // error-pattern: unknown lint: `foo_qux` fn main() {} diff --git a/src/test/ui/lint/cli-unknown-force-warn.stderr b/src/test/ui/lint/cli-unknown-force-warn.stderr index 4367c3b4500d..9ce9f405aee6 100644 --- a/src/test/ui/lint/cli-unknown-force-warn.stderr +++ b/src/test/ui/lint/cli-unknown-force-warn.stderr @@ -6,10 +6,6 @@ error[E0602]: unknown lint: `foo_qux` | = note: requested on the command line with `--force-warn foo_qux` -error[E0602]: unknown lint: `foo_qux` - | - = note: requested on the command line with `--force-warn foo_qux` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0602`. diff --git a/src/test/ui/lint/force-warn/allow-warnings.rs b/src/test/ui/lint/force-warn/allow-warnings.rs index 6ee5ba679328..adcefc7ec78c 100644 --- a/src/test/ui/lint/force-warn/allow-warnings.rs +++ b/src/test/ui/lint/force-warn/allow-warnings.rs @@ -1,6 +1,6 @@ // --force-warn $LINT causes $LINT (which is warn-by-default) to warn // despite allowing all warnings in module -// compile-flags: --force-warn dead_code -Zunstable-options +// compile-flags: --force-warn dead_code // check-pass #![allow(warnings)] diff --git a/src/test/ui/lint/force-warn/allowed-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-by-default-lint.rs index fd0b886d84db..b24ab822d930 100644 --- a/src/test/ui/lint/force-warn/allowed-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-by-default-lint.rs @@ -1,5 +1,5 @@ // --force-warn $LINT causes $LINT (which is allow-by-default) to warn -// compile-flags: --force-warn elided_lifetimes_in_paths -Zunstable-options +// compile-flags: --force-warn elided_lifetimes_in_paths // check-pass struct Foo<'a> { diff --git a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs index 82a584ac9726..08e75a775d0b 100644 --- a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs @@ -1,6 +1,6 @@ // --force-warn $LINT causes $LINT (which is deny-by-default) to warn // despite $LINT being allowed in module -// compile-flags: --force-warn const_err -Zunstable-options +// compile-flags: --force-warn const_err // check-pass #![allow(const_err)] diff --git a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs index 86ab12668a3e..9b1edba41aaf 100644 --- a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs @@ -1,6 +1,6 @@ // --force-warn $LINT causes $LINT (which is warn-by-default) to warn // despite $LINT_GROUP (which contains $LINT) being allowed -// compile-flags: --force-warn bare_trait_objects -Zunstable-options +// compile-flags: --force-warn bare_trait_objects // check-pass #![allow(rust_2018_idioms)] diff --git a/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs index 7204782a324e..4ac29ff7d99b 100644 --- a/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs @@ -1,6 +1,6 @@ // --force-warn $LINT causes $LINT (which is warn-by-default) to warn // despite $LINT being allowed in module -// compile-flags: --force-warn dead_code -Zunstable-options +// compile-flags: --force-warn dead_code // check-pass #![allow(dead_code)] diff --git a/src/test/ui/lint/force-warn/cap-lints-allow.rs b/src/test/ui/lint/force-warn/cap-lints-allow.rs index de3a1bd8dd71..9609ea994312 100644 --- a/src/test/ui/lint/force-warn/cap-lints-allow.rs +++ b/src/test/ui/lint/force-warn/cap-lints-allow.rs @@ -1,6 +1,6 @@ // --force-warn $LINT casuses $LINT to warn despite --cap-lints // set to allow -// compile-flags: --cap-lints allow --force-warn bare_trait_objects -Zunstable-options +// compile-flags: --cap-lints allow --force-warn bare_trait_objects // check-pass pub trait SomeTrait {} diff --git a/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs index 70fb90dc1992..e65f156bfdc9 100644 --- a/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs @@ -1,6 +1,6 @@ // --force-warn $LINT_GROUP causes $LINT to warn despite $LINT being // allowed in module and cap-lints set to warn -// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility -Zunstable-options +// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility // check-pass #![allow(ellipsis_inclusive_range_patterns)] diff --git a/src/test/ui/lint/force-warn/deny-by-default-lint.rs b/src/test/ui/lint/force-warn/deny-by-default-lint.rs index b0a15cc2fba0..e371029032fe 100644 --- a/src/test/ui/lint/force-warn/deny-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/deny-by-default-lint.rs @@ -1,5 +1,5 @@ // --force-warn $LINT causes $LINT (which is deny-by-default) to warn -// compile-flags: --force-warn const_err -Zunstable-options +// compile-flags: --force-warn const_err // check-pass const C: i32 = 1 / 0; diff --git a/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs b/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs index e5dcd9a7ea16..4b95f4d2dfbb 100644 --- a/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs +++ b/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs @@ -1,7 +1,7 @@ // --force-warn $LINT_GROUP causes $LINT in $LINT_GROUP to warn // despite all warnings being allowed in module // warn-by-default lint to warn -// compile-flags: --force-warn nonstandard_style -Zunstable-options +// compile-flags: --force-warn nonstandard_style // check-pass #![allow(warnings)] diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs index dc13b2b24748..99cad614c25c 100644 --- a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs +++ b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs @@ -1,6 +1,6 @@ // --force-warn $LINT_GROUP causes $LINT to warn despite // $LINT_GROUP being allowed in module -// compile-flags: --force-warn rust_2018_idioms -Zunstable-options +// compile-flags: --force-warn rust_2018_idioms // check-pass #![allow(rust_2018_idioms)] diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs index b7f79b3d4aa3..f0aacd773401 100644 --- a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs @@ -1,6 +1,6 @@ // --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn // despite $LINT being allowed in module -// compile-flags: --force-warn rust-2018-idioms -Zunstable-options +// compile-flags: --force-warn rust-2018-idioms // check-pass #![allow(bare_trait_objects)] From 54df693dd7e6668b78f0636e269f7f928d4932d2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 16:51:58 +0100 Subject: [PATCH 096/269] io::Error: alphabeticise the match in as_str() There was no rationale for the previous ordering. Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 829ef3d98bbc..3f8f34793af3 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -307,13 +307,13 @@ pub enum ErrorKind { impl ErrorKind { pub(crate) fn as_str(&self) -> &'static str { use ErrorKind::*; + // Strictly alphabetical, please. (Sadly rustfmt cannot do this yet.) match *self { AddrInUse => "address in use", AddrNotAvailable => "address not available", AlreadyExists => "entity already exists", ArgumentListTooLong => "argument list too long", BrokenPipe => "broken pipe", - ResourceBusy => "resource busy", ConnectionAborted => "connection aborted", ConnectionRefused => "connection refused", ConnectionReset => "connection reset", @@ -321,9 +321,10 @@ impl ErrorKind { Deadlock => "deadlock", DirectoryNotEmpty => "directory not empty", ExecutableFileBusy => "executable file busy", + FileTooLarge => "file too large", FilenameTooLong => "filename too long", + FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", FilesystemQuotaExceeded => "filesystem quota exceeded", - FileTooLarge => "file too large", HostUnreachable => "host unreachable", Interrupted => "operation interrupted", InvalidData => "invalid data", @@ -332,16 +333,16 @@ impl ErrorKind { NetworkDown => "network down", NetworkUnreachable => "network unreachable", NotADirectory => "not a directory", - StorageFull => "no storage space", NotConnected => "not connected", NotFound => "entity not found", + NotSeekable => "seek on unseekable file", Other => "other error", OutOfMemory => "out of memory", PermissionDenied => "permission denied", ReadOnlyFilesystem => "read-only filesystem or storage medium", + ResourceBusy => "resource busy", StaleNetworkFileHandle => "stale network file handle", - FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)", - NotSeekable => "seek on unseekable file", + StorageFull => "no storage space", TimedOut => "timed out", TooManyLinks => "too many links", Uncategorized => "uncategorized error", From 4c0203eb4b3406cd2088c5d0092a0445294e2f6c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 16:53:58 +0100 Subject: [PATCH 097/269] io::ErrorKind: rationalise ordering in main enum It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 41 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 3f8f34793af3..6880106a9437 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -261,18 +261,14 @@ pub enum ErrorKind { #[stable(feature = "rust1", since = "1.0.0")] Interrupted, - /// A custom error that does not fall under any other I/O error kind. - /// - /// This can be used to construct your own [`Error`]s that do not match any - /// [`ErrorKind`]. - /// - /// This [`ErrorKind`] is not used by the standard library. + /// This operation is unsupported on this platform. /// - /// Errors from the standard library that do not fall under any of the I/O - /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. - /// New [`ErrorKind`]s might be added in the future for some of those. - #[stable(feature = "rust1", since = "1.0.0")] - Other, + /// This means that the operation can never succeed. + #[stable(feature = "unsupported_error", since = "1.53.0")] + Unsupported, + + // ErrorKinds which are primarily categorisations for OS error + // codes should be added above. /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. @@ -283,17 +279,28 @@ pub enum ErrorKind { #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, - /// This operation is unsupported on this platform. - /// - /// This means that the operation can never succeed. - #[stable(feature = "unsupported_error", since = "1.53.0")] - Unsupported, - /// An operation could not be completed, because it failed /// to allocate enough memory. #[stable(feature = "out_of_memory_error", since = "1.54.0")] OutOfMemory, + // "Unusual" error kinds which do not correspond simply to (sets + // of) OS error codes, should be added just above this comment. + // `Other` and `Uncategorised` should remain at the end: + + /// A custom error that does not fall under any other I/O error kind. + /// + /// This can be used to construct your own [`Error`]s that do not match any + /// [`ErrorKind`]. + /// + /// This [`ErrorKind`] is not used by the standard library. + /// + /// Errors from the standard library that do not fall under any of the I/O + /// error kinds cannot be `match`ed on, and will only match a wildcard (`_`) pattern. + /// New [`ErrorKind`]s might be added in the future for some of those. + #[stable(feature = "rust1", since = "1.0.0")] + Other, + /// Any I/O error from the standard library that's not part of this list. /// /// Errors that are `Uncategorized` now may move to a different or a new From 8f7007991e7fa1a1a6795f81e5d7efbdd503a8c1 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 24 Aug 2021 17:56:39 +0200 Subject: [PATCH 098/269] Fix grammar --- library/alloc/tests/boxed.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index 6a83f5da87cc..a38b5c471bf0 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -35,11 +35,11 @@ fn box_clone_and_clone_from_equivalence() { } } -/// This test might give a false positive in case the box realocates, but the alocator keeps the -/// original pointer. +/// This test might give a false positive in case the box reallocates, +/// but the allocator keeps the original pointer. /// -/// On the other hand it won't give a false negative, if it fails than the memory was definitely not -/// reused +/// On the other hand, it won't give a false negative: If it fails, then the +/// memory was definitely not reused. #[test] fn box_clone_from_ptr_stability() { for size in (0..8).map(|i| 2usize.pow(i)) { From bcfdf55efe67333dccfd3d47b14ca5c703aa0c95 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 24 Aug 2021 09:02:44 -0700 Subject: [PATCH 099/269] Update the stdarch submodule This notably brings in a number of codegen updates to ensure that wasm simd intrinsics generate the expected instruction with LLVM 13 --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index c158cfd38e20..89b0e355bc3c 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit c158cfd38e20d855f5d6ca8a5a101eefb82604a8 +Subproject commit 89b0e355bc3cff5cddec2290c84f36eb3a026aad From e291234f59523f57106a233d3115958ded7d3b04 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 16 Jul 2021 14:12:18 +0300 Subject: [PATCH 100/269] Pretty-print uninhabited const values more explicitly. --- compiler/rustc_middle/src/ty/print/pretty.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 8558d6bb00e7..36d4116f8464 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1218,8 +1218,15 @@ pub trait PrettyPrinter<'tcx>: } p!(")"); } - ty::Adt(def, substs) if def.variants.is_empty() => { - p!(print_value_path(def.did, substs)); + ty::Adt(def, _) if def.variants.is_empty() => { + self = self.typed_value( + |mut this| { + write!(this, "unreachable()")?; + Ok(this) + }, + |this| this.print_type(ty), + ": ", + )?; } ty::Adt(def, substs) => { let variant_id = From eec84b31fb6cbac72043017ef81eba0ced658be7 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 16 Jul 2021 15:34:29 +0300 Subject: [PATCH 101/269] rustc_symbol_mangling: never cache placeholders in print_const. --- compiler/rustc_symbol_mangling/src/v0.rs | 58 +++++++++++++++--------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index c4c1ec8ce4e0..aa670fc64469 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -534,39 +534,53 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { } fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result { + // We only mangle a typed value if the const can be evaluated. + let ct = ct.eval(self.tcx, ty::ParamEnv::reveal_all()); + match ct.val { + ty::ConstKind::Value(_) => {} + + // Placeholders (should be demangled as `_`). + // NOTE(eddyb) despite `Unevaluated` having a `DefId` (and therefore + // a path), even for it we still need to encode a placeholder, as + // the path could refer back to e.g. an `impl` using the constant. + ty::ConstKind::Unevaluated(_) + | ty::ConstKind::Param(_) + | ty::ConstKind::Infer(_) + | ty::ConstKind::Bound(..) + | ty::ConstKind::Placeholder(_) + | ty::ConstKind::Error(_) => { + // Never cached (single-character). + self.push("p"); + return Ok(self); + } + } + if let Some(&i) = self.consts.get(&ct) { return self.print_backref(i); } let start = self.out.len(); - let mut neg = false; - let val = match ct.ty.kind() { - ty::Uint(_) | ty::Bool | ty::Char => { - ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) - } - ty::Int(ity) => { - ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty).and_then(|b| { - let val = Integer::from_int_ty(&self.tcx, *ity).size().sign_extend(b) as i128; + match ct.ty.kind() { + ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => { + self = ct.ty.print(self)?; + + let mut bits = ct.eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty); + + // Negative integer values are mangled using `n` as a "sign prefix". + if let ty::Int(ity) = ct.ty.kind() { + let val = + Integer::from_int_ty(&self.tcx, *ity).size().sign_extend(bits) as i128; if val < 0 { - neg = true; + self.push("n"); } - Some(val.unsigned_abs()) - }) + bits = val.unsigned_abs(); + } + + let _ = write!(self.out, "{:x}_", bits); } _ => { bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct); } - }; - - if let Some(bits) = val { - // We only print the type if the const can be evaluated. - self = ct.ty.print(self)?; - let _ = write!(self.out, "{}{:x}_", if neg { "n" } else { "" }, bits); - } else { - // NOTE(eddyb) despite having the path, we need to - // encode a placeholder, as the path could refer - // back to e.g. an `impl` using the constant. - self.push("p"); } // Only cache consts that do not refer to an enclosing From 948f19ea8ff76975a77a7cca1e4b42ca8758d3aa Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 16 Jul 2021 15:40:33 +0300 Subject: [PATCH 102/269] Fix typo (variant_id should've been variant_idx). --- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 36d4116f8464..a462f5d55e34 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1229,9 +1229,9 @@ pub trait PrettyPrinter<'tcx>: )?; } ty::Adt(def, substs) => { - let variant_id = - contents.variant.expect("destructed const of adt without variant id"); - let variant_def = &def.variants[variant_id]; + let variant_idx = + contents.variant.expect("destructed const of adt without variant idx"); + let variant_def = &def.variants[variant_idx]; p!(print_value_path(variant_def.def_id, substs)); match variant_def.ctor_kind { From cb7890e7913103ce0d196270b6bf86ead51e9ea1 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 16 Jul 2021 18:21:41 +0300 Subject: [PATCH 103/269] rustc_symbol_mangling: support structural constants and &str in v0. --- compiler/rustc_symbol_mangling/src/lib.rs | 1 + compiler/rustc_symbol_mangling/src/v0.rs | 103 ++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 850d44eb339c..551309f4a8cc 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -91,6 +91,7 @@ #![feature(never_type)] #![feature(nll)] #![feature(in_band_lifetimes)] +#![feature(iter_zip)] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index aa670fc64469..80f29aa9c4f1 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -1,8 +1,10 @@ use rustc_data_structures::base_n; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; +use rustc_hir::def::CtorKind; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; +use rustc_middle::mir::interpret::ConstValue; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::print::{Print, Printer}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst}; @@ -11,6 +13,7 @@ use rustc_target::abi::Integer; use rustc_target::spec::abi::Abi; use std::fmt::Write; +use std::iter; use std::ops::Range; pub(super) fn mangle( @@ -578,6 +581,106 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { let _ = write!(self.out, "{:x}_", bits); } + + // HACK(eddyb) because `ty::Const` only supports sized values (for now), + // we can't use `deref_const` + supporting `str`, we have to specially + // handle `&str` and include both `&` ("R") and `str` ("e") prefixes. + ty::Ref(_, ty, hir::Mutability::Not) if *ty == self.tcx.types.str_ => { + self.push("R"); + match ct.val { + ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => { + // NOTE(eddyb) the following comment was kept from `ty::print::pretty`: + // The `inspect` here is okay since we checked the bounds, and there are no + // relocations (we have an active `str` reference here). We don't use this + // result to affect interpreter execution. + let slice = + data.inspect_with_uninit_and_ptr_outside_interpreter(start..end); + let s = std::str::from_utf8(slice).expect("non utf8 str from miri"); + + self.push("e"); + // FIXME(eddyb) use a specialized hex-encoding loop. + for byte in s.bytes() { + let _ = write!(self.out, "{:02x}", byte); + } + self.push("_"); + } + + _ => { + bug!("symbol_names: unsupported `&str` constant: {:?}", ct); + } + } + } + + ty::Ref(_, _, mutbl) => { + self.push(match mutbl { + hir::Mutability::Not => "R", + hir::Mutability::Mut => "Q", + }); + self = self.tcx.deref_const(ty::ParamEnv::reveal_all().and(ct)).print(self)?; + } + + ty::Array(..) | ty::Tuple(..) | ty::Adt(..) => { + let contents = self.tcx.destructure_const(ty::ParamEnv::reveal_all().and(ct)); + let fields = contents.fields.iter().copied(); + + let print_field_list = |mut this: Self| { + for field in fields.clone() { + this = field.print(this)?; + } + this.push("E"); + Ok(this) + }; + + match *ct.ty.kind() { + ty::Array(..) => { + self.push("A"); + self = print_field_list(self)?; + } + ty::Tuple(..) => { + self.push("T"); + self = print_field_list(self)?; + } + ty::Adt(def, substs) => { + let variant_idx = + contents.variant.expect("destructed const of adt without variant idx"); + let variant_def = &def.variants[variant_idx]; + + self.push("V"); + self = self.print_def_path(variant_def.def_id, substs)?; + + match variant_def.ctor_kind { + CtorKind::Const => { + self.push("U"); + } + CtorKind::Fn => { + self.push("T"); + self = print_field_list(self)?; + } + CtorKind::Fictive => { + self.push("S"); + for (field_def, field) in iter::zip(&variant_def.fields, fields) { + // HACK(eddyb) this mimics `path_append`, + // instead of simply using `field_def.ident`, + // just to be able to handle disambiguators. + let disambiguated_field = + self.tcx.def_key(field_def.did).disambiguated_data; + let field_name = + disambiguated_field.data.get_opt_name().map(|s| s.as_str()); + self.push_disambiguator( + disambiguated_field.disambiguator as u64, + ); + self.push_ident(&field_name.as_ref().map_or("", |s| &s[..])); + + self = field.print(self)?; + } + self.push("E"); + } + } + } + _ => unreachable!(), + } + } + _ => { bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct); } From f60d333affb62b5aaec52efddc54db46ead9cf5e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 16 Jul 2021 18:22:14 +0300 Subject: [PATCH 104/269] tests: support -Zsymbol-mangling-version=v0 being the default. --- src/test/debuginfo/function-call.rs | 2 +- src/test/debuginfo/function-names.rs | 2 +- ...stderr => issue-47429-short-backtraces.legacy.run.stderr} | 2 +- src/test/ui/panics/issue-47429-short-backtraces.rs | 5 +++++ .../ui/panics/issue-47429-short-backtraces.v0.run.stderr | 5 +++++ 5 files changed, 13 insertions(+), 3 deletions(-) rename src/test/ui/panics/{issue-47429-short-backtraces.run.stderr => issue-47429-short-backtraces.legacy.run.stderr} (91%) create mode 100644 src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr diff --git a/src/test/debuginfo/function-call.rs b/src/test/debuginfo/function-call.rs index a5d5942b5395..75334558b589 100644 --- a/src/test/debuginfo/function-call.rs +++ b/src/test/debuginfo/function-call.rs @@ -1,5 +1,5 @@ // This test does not passed with gdb < 8.0. See #53497. -// min-gdb-version: 8.0 +// min-gdb-version: 10.1 // compile-flags:-g diff --git a/src/test/debuginfo/function-names.rs b/src/test/debuginfo/function-names.rs index 28ab176ba509..b9e59f8e8297 100644 --- a/src/test/debuginfo/function-names.rs +++ b/src/test/debuginfo/function-names.rs @@ -1,5 +1,5 @@ // Function names are formatted differently in old versions of GDB -// min-gdb-version: 9.2 +// min-gdb-version: 10.1 // compile-flags:-g diff --git a/src/test/ui/panics/issue-47429-short-backtraces.run.stderr b/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr similarity index 91% rename from src/test/ui/panics/issue-47429-short-backtraces.run.stderr rename to src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr index 328796389070..fcdc070a4c39 100644 --- a/src/test/ui/panics/issue-47429-short-backtraces.run.stderr +++ b/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr @@ -1,4 +1,4 @@ -thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:16:5 +thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:21:5 stack backtrace: 0: std::panicking::begin_panic 1: issue_47429_short_backtraces::main diff --git a/src/test/ui/panics/issue-47429-short-backtraces.rs b/src/test/ui/panics/issue-47429-short-backtraces.rs index 015ab8fdd80d..35ecfc0b2715 100644 --- a/src/test/ui/panics/issue-47429-short-backtraces.rs +++ b/src/test/ui/panics/issue-47429-short-backtraces.rs @@ -12,6 +12,11 @@ // ignore-emscripten no panic or subprocess support // ignore-sgx no subprocess support +// NOTE(eddyb) output differs between symbol mangling schemes +// revisions: legacy v0 +// [legacy] compile-flags: -Zsymbol-mangling-version=legacy +// [v0] compile-flags: -Zsymbol-mangling-version=v0 + fn main() { panic!() } diff --git a/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr b/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr new file mode 100644 index 000000000000..1cbf11739bfc --- /dev/null +++ b/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr @@ -0,0 +1,5 @@ +thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:21:5 +stack backtrace: + 0: std::panicking::begin_panic::<&str> + 1: issue_47429_short_backtraces::main +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. From 755385cd4f637fbe631fba805943f79ff39f7622 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 10 Aug 2021 23:46:50 +0300 Subject: [PATCH 105/269] tests: shorten symbol-names/const-generics-demangling output. --- .../symbol-names/const-generics-demangling.rs | 26 +++++++++---------- .../const-generics-demangling.stderr | 24 ++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/test/ui/symbol-names/const-generics-demangling.rs b/src/test/ui/symbol-names/const-generics-demangling.rs index 05c6b8352de6..8d70954c8ced 100644 --- a/src/test/ui/symbol-names/const-generics-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-demangling.rs @@ -1,37 +1,37 @@ // build-fail -// compile-flags: -Z symbol-mangling-version=v0 +// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c #![feature(rustc_attrs)] pub struct Unsigned; #[rustc_symbol_name] -//~^ ERROR symbol-name(_RMCsaP8qXevlYG3_25const_generics_demanglingINtB0_8UnsignedKhb_E) -//~| ERROR demangling(>) -//~| ERROR demangling-alt(>) +//~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_8UnsignedKhb_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) impl Unsigned<11> {} pub struct Signed; #[rustc_symbol_name] -//~^ ERROR symbol-name(_RMs_CsaP8qXevlYG3_25const_generics_demanglingINtB2_6SignedKsn98_E) -//~| ERROR demangling(>) -//~| ERROR demangling-alt(>) +//~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6SignedKsn98_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) impl Signed<-152> {} pub struct Bool; #[rustc_symbol_name] -//~^ ERROR symbol-name(_RMs0_CsaP8qXevlYG3_25const_generics_demanglingINtB3_4BoolKb1_E) -//~| ERROR demangling(>) -//~| ERROR demangling-alt(>) +//~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_4BoolKb1_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) impl Bool {} pub struct Char; #[rustc_symbol_name] -//~^ ERROR symbol-name(_RMs1_CsaP8qXevlYG3_25const_generics_demanglingINtB3_4CharKc2202_E) -//~| ERROR demangling(>) -//~| ERROR demangling-alt(>) +//~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_4CharKc2202_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) impl Char<'∂'> {} fn main() {} diff --git a/src/test/ui/symbol-names/const-generics-demangling.stderr b/src/test/ui/symbol-names/const-generics-demangling.stderr index 05c485d001f0..972f0cdb283a 100644 --- a/src/test/ui/symbol-names/const-generics-demangling.stderr +++ b/src/test/ui/symbol-names/const-generics-demangling.stderr @@ -1,70 +1,70 @@ -error: symbol-name(_RMCsaP8qXevlYG3_25const_generics_demanglingINtB0_8UnsignedKhb_E) +error: symbol-name(_RMCsno73SFvQKx_1cINtB0_8UnsignedKhb_E) --> $DIR/const-generics-demangling.rs:7:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:7:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(>) +error: demangling-alt(>) --> $DIR/const-generics-demangling.rs:7:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: symbol-name(_RMs_CsaP8qXevlYG3_25const_generics_demanglingINtB2_6SignedKsn98_E) +error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6SignedKsn98_E) --> $DIR/const-generics-demangling.rs:15:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:15:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(>) +error: demangling-alt(>) --> $DIR/const-generics-demangling.rs:15:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: symbol-name(_RMs0_CsaP8qXevlYG3_25const_generics_demanglingINtB3_4BoolKb1_E) +error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_4BoolKb1_E) --> $DIR/const-generics-demangling.rs:23:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:23:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(>) +error: demangling-alt(>) --> $DIR/const-generics-demangling.rs:23:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: symbol-name(_RMs1_CsaP8qXevlYG3_25const_generics_demanglingINtB3_4CharKc2202_E) +error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_4CharKc2202_E) --> $DIR/const-generics-demangling.rs:31:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:31:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(>) +error: demangling-alt(>) --> $DIR/const-generics-demangling.rs:31:1 | LL | #[rustc_symbol_name] From 4a9ba65ca9eaf9db3a010cbf5859b3fdf16ac687 Mon Sep 17 00:00:00 2001 From: linux1 Date: Tue, 24 Aug 2021 12:41:49 -0400 Subject: [PATCH 106/269] Feat: added explicit register tests; added prefix to check_reg asm string --- src/test/assembly/asm/s390x-types.rs | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index ec0515b20bdf..69d9cab23c8e 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -65,7 +65,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { dont_merge(stringify!($func)); let y; - asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); + asm!(concat!($mov, " %", $reg, ", %", $reg), lateout($reg) y, in($reg) x); y } };} @@ -130,3 +130,39 @@ check!(reg_f64, f64, freg, "ldr"); // CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} // CHECK: #NO_APP check!(reg_ptr, ptr, reg, "lgr"); + +// CHECK-LABEL: r0_i8: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i8, i8, "r0", "lr"); + +// CHECK-LABEL: r0_i16: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i16, i16, "r0", "lr"); + +// CHECK-LABEL: r0_i32: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i32, i32, "r0", "lr"); + +// CHECK-LABEL: r0_i64: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i64, i64, "r0", "lr"); + +// CHECK-LABEL: f0_f32: +// CHECK: #APP +// CHECK: ler %f0, %f0 +// CHECK: #NO_APP +check_reg!(f0_f32, f32, "f0", "ler"); + +// CHECK-LABEL: f0_f64: +// CHECK: #APP +// CHECK: ldr %f0, %f0 +// CHECK: #NO_APP +check_reg!(f0_f64, f64, "f0", "ldr"); From 7b5c0ecb3d902149fd6caa1d673ad5f7751320f3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Aug 2021 17:44:16 +0100 Subject: [PATCH 107/269] Fix tidy Signed-off-by: Ian Jackson --- library/std/src/io/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 6880106a9437..51666c0a3c7f 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -269,7 +269,7 @@ pub enum ErrorKind { // ErrorKinds which are primarily categorisations for OS error // codes should be added above. - + // /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. /// @@ -287,7 +287,7 @@ pub enum ErrorKind { // "Unusual" error kinds which do not correspond simply to (sets // of) OS error codes, should be added just above this comment. // `Other` and `Uncategorised` should remain at the end: - + // /// A custom error that does not fall under any other I/O error kind. /// /// This can be used to construct your own [`Error`]s that do not match any From f8810ee171d1549cfb4082d4e1289704aad722e9 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 11 Aug 2021 00:05:25 +0300 Subject: [PATCH 108/269] Update rustc-demangle to 0.1.21. --- Cargo.lock | 4 ++-- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_symbol_mangling/Cargo.toml | 2 +- library/std/Cargo.toml | 2 +- src/test/ui/symbol-names/const-generics-demangling.rs | 8 ++++---- src/test/ui/symbol-names/const-generics-demangling.stderr | 8 ++++---- src/test/ui/symbol-names/impl1.rs | 2 +- src/test/ui/symbol-names/impl1.v0.stderr | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4612d8a9542..5e6b11032ab2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3398,9 +3398,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 6187f4000fbd..521ce344180a 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -15,7 +15,7 @@ measureme = "9.1.0" snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } -rustc-demangle = "0.1.18" +rustc-demangle = "0.1.21" rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index aa8fd3045276..aebf77a1fd85 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -9,7 +9,7 @@ doctest = false [dependencies] tracing = "0.1" punycode = "0.4.0" -rustc-demangle = "0.1.18" +rustc-demangle = "0.1.21" rustc_span = { path = "../rustc_span" } rustc_middle = { path = "../rustc_middle" } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 38291b3f57e4..1b051b0d0f6e 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -24,7 +24,7 @@ std_detect = { path = "../stdarch/crates/std_detect", default-features = false, # Dependencies of the `backtrace` crate addr2line = { version = "0.16.0", optional = true, default-features = false } -rustc-demangle = { version = "0.1.18", features = ['rustc-dep-of-std'] } +rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } miniz_oxide = { version = "0.4.0", optional = true, default-features = false } [dependencies.object] version = "0.26.1" diff --git a/src/test/ui/symbol-names/const-generics-demangling.rs b/src/test/ui/symbol-names/const-generics-demangling.rs index 8d70954c8ced..38b07acbdb27 100644 --- a/src/test/ui/symbol-names/const-generics-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-demangling.rs @@ -6,7 +6,7 @@ pub struct Unsigned; #[rustc_symbol_name] //~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_8UnsignedKhb_E) -//~| ERROR demangling(>) +//~| ERROR demangling(>) //~| ERROR demangling-alt(>) impl Unsigned<11> {} @@ -14,7 +14,7 @@ pub struct Signed; #[rustc_symbol_name] //~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6SignedKsn98_E) -//~| ERROR demangling(>) +//~| ERROR demangling(>) //~| ERROR demangling-alt(>) impl Signed<-152> {} @@ -22,7 +22,7 @@ pub struct Bool; #[rustc_symbol_name] //~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_4BoolKb1_E) -//~| ERROR demangling(>) +//~| ERROR demangling(>) //~| ERROR demangling-alt(>) impl Bool {} @@ -30,7 +30,7 @@ pub struct Char; #[rustc_symbol_name] //~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_4CharKc2202_E) -//~| ERROR demangling(>) +//~| ERROR demangling(>) //~| ERROR demangling-alt(>) impl Char<'∂'> {} diff --git a/src/test/ui/symbol-names/const-generics-demangling.stderr b/src/test/ui/symbol-names/const-generics-demangling.stderr index 972f0cdb283a..2abf293071f0 100644 --- a/src/test/ui/symbol-names/const-generics-demangling.stderr +++ b/src/test/ui/symbol-names/const-generics-demangling.stderr @@ -4,7 +4,7 @@ error: symbol-name(_RMCsno73SFvQKx_1cINtB0_8UnsignedKhb_E) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:7:1 | LL | #[rustc_symbol_name] @@ -22,7 +22,7 @@ error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6SignedKsn98_E) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:15:1 | LL | #[rustc_symbol_name] @@ -40,7 +40,7 @@ error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_4BoolKb1_E) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:23:1 | LL | #[rustc_symbol_name] @@ -58,7 +58,7 @@ error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_4CharKc2202_E) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(>) +error: demangling(>) --> $DIR/const-generics-demangling.rs:31:1 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/symbol-names/impl1.rs b/src/test/ui/symbol-names/impl1.rs index 960049be7936..60f19266ba9f 100644 --- a/src/test/ui/symbol-names/impl1.rs +++ b/src/test/ui/symbol-names/impl1.rs @@ -64,7 +64,7 @@ fn main() { //[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method //[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method) //[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs2qSCrjELJET_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hvEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method) - //[v0]~| ERROR demangling(<[&dyn impl1[1c5860ab79c9e305]::Foo extern "C" fn(&'a u8, ...)> + impl1[1c5860ab79c9e305]::AutoTrait; 3: usize] as impl1[1c5860ab79c9e305]::main::{closure#1}::Bar>::method) + //[v0]~| ERROR demangling(<[&dyn impl1[1c5860ab79c9e305]::Foo extern "C" fn(&'a u8, ...)> + impl1[1c5860ab79c9e305]::AutoTrait; 3usize] as impl1[1c5860ab79c9e305]::main::{closure#1}::Bar>::method) //[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) #[rustc_def_path] //[legacy]~^ ERROR def-path(<[&dyn Foo extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method) diff --git a/src/test/ui/symbol-names/impl1.v0.stderr b/src/test/ui/symbol-names/impl1.v0.stderr index a7c3a389909a..926e750e3cda 100644 --- a/src/test/ui/symbol-names/impl1.v0.stderr +++ b/src/test/ui/symbol-names/impl1.v0.stderr @@ -52,7 +52,7 @@ error: symbol-name(_RNvXNCNvCs2qSCrjELJET_5impl14mains_0ARDNtB6_3Foop5AssocFG_KC LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(<[&dyn impl1[1c5860ab79c9e305]::Foo extern "C" fn(&'a u8, ...)> + impl1[1c5860ab79c9e305]::AutoTrait; 3: usize] as impl1[1c5860ab79c9e305]::main::{closure#1}::Bar>::method) +error: demangling(<[&dyn impl1[1c5860ab79c9e305]::Foo extern "C" fn(&'a u8, ...)> + impl1[1c5860ab79c9e305]::AutoTrait; 3usize] as impl1[1c5860ab79c9e305]::main::{closure#1}::Bar>::method) --> $DIR/impl1.rs:62:13 | LL | #[rustc_symbol_name] From af002c152413c6f566ad0def41178938f098c7c1 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 11 Aug 2021 00:38:14 +0300 Subject: [PATCH 109/269] tests: add v0 `&str` const value demangling test. --- .../const-generics-str-demangling.rs | 44 +++++++ .../const-generics-str-demangling.stderr | 110 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/test/ui/symbol-names/const-generics-str-demangling.rs create mode 100644 src/test/ui/symbol-names/const-generics-str-demangling.stderr diff --git a/src/test/ui/symbol-names/const-generics-str-demangling.rs b/src/test/ui/symbol-names/const-generics-str-demangling.rs new file mode 100644 index 000000000000..af111dd39fac --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-str-demangling.rs @@ -0,0 +1,44 @@ +// build-fail +// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c +#![feature(const_generics, rustc_attrs)] +#![allow(incomplete_features)] + +pub struct Str; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_3StrKRe616263_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"abc"> {} + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_3StrKRe27_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"'"> {} + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_3StrKRe090a_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"\t\n"> {} + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_3StrKRee28882c3bc_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"∂ü"> {} + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_3StrKRee183a1e18390e183ade1839be18394e1839ae18390e183935fe18392e18394e1839be183a0e18398e18394e1839ae183985fe183a1e18390e18393e18398e1839ae18398_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"საჭმელად_გემრიელი_სადილი"> {} + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_3StrKRef09f908af09fa688f09fa686f09f90ae20c2a720f09f90b6f09f9192e29895f09f94a520c2a720f09fa7a1f09f929bf09f929af09f9299f09f929c_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Str<"🐊🦈🦆🐮 § 🐶👒☕🔥 § 🧡💛💚💙💜"> {} + +fn main() {} diff --git a/src/test/ui/symbol-names/const-generics-str-demangling.stderr b/src/test/ui/symbol-names/const-generics-str-demangling.stderr new file mode 100644 index 000000000000..f401997017fb --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-str-demangling.stderr @@ -0,0 +1,110 @@ +error: symbol-name(_RMCsno73SFvQKx_1cINtB0_3StrKRe616263_E) + --> $DIR/const-generics-str-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:8:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_3StrKRe27_E) + --> $DIR/const-generics-str-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_3StrKRe090a_E) + --> $DIR/const-generics-str-demangling.rs:20:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:20:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:20:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_3StrKRee28882c3bc_E) + --> $DIR/const-generics-str-demangling.rs:26:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:26:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:26:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_3StrKRee183a1e18390e183ade1839be18394e1839ae18390e183935fe18392e18394e1839be183a0e18398e18394e1839ae183985fe183a1e18390e18393e18398e1839ae18398_E) + --> $DIR/const-generics-str-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_3StrKRef09f908af09fa688f09fa686f09f90ae20c2a720f09f90b6f09f9192e29895f09f94a520c2a720f09fa7a1f09f929bf09f929af09f9299f09f929c_E) + --> $DIR/const-generics-str-demangling.rs:38:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-str-demangling.rs:38:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-str-demangling.rs:38:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 18 previous errors + From b4fcf1b1dc3d0533a7fa554482e99366f532056b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 11 Aug 2021 01:13:31 +0300 Subject: [PATCH 110/269] tests: add v0 structural const value demangling test. --- .../const-generics-structural-demangling.rs | 96 +++++++++++ ...onst-generics-structural-demangling.stderr | 161 ++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 src/test/ui/symbol-names/const-generics-structural-demangling.rs create mode 100644 src/test/ui/symbol-names/const-generics-structural-demangling.stderr diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.rs b/src/test/ui/symbol-names/const-generics-structural-demangling.rs new file mode 100644 index 000000000000..9da6a0f18e69 --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.rs @@ -0,0 +1,96 @@ +// build-fail +// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c + +// NOTE(eddyb) we need `core` for `core::option::Option`, normalize away its +// disambiguator hash, which can/should change (including between stage{1,2}). +// normalize-stderr-test: "Cs[0-9a-zA-Z]+_4core" -> "Cs$$HASH_4core" +// normalize-stderr-test: "core\[[0-9a-f]+\]" -> "core[$$HASH_HEX]" + +#![feature(const_generics, decl_macro, rustc_attrs)] +#![allow(incomplete_features)] + +pub struct RefByte; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl RefByte<{&123}> {} + +// FIXME(eddyb) this was supposed to be `RefMutZst` with `&mut []`, +// but that is currently not allowed in const generics. +pub struct RefZst; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl RefZst<{&[]}> {} + +pub struct Array3Bytes; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Array3Bytes<{[1, 2, 3]}> {} + +pub struct TupleByteBool; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl TupleByteBool<{(1, false)}> {} + +pub struct OptionUsize>; + +// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize +// the `core` disambiguator hash away there, but not here. +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs +//~| ERROR demangling(::None}>>) +impl OptionUsize<{None}> {} + +// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize +// the `core` disambiguator hash away there, but not here. +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs +//~| ERROR demangling(::Some(0)}>>) +impl OptionUsize<{Some(0)}> {} + +#[derive(PartialEq, Eq)] +pub struct Foo { + s: &'static str, + ch: char, + slice: &'static [u8], +} +pub struct Foo_; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Foo_<{Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}> {} + +// NOTE(eddyb) this tests specifically the use of disambiguators in field names, +// using macros 2.0 hygiene to create a `struct` with conflicting field names. +macro duplicate_field_name_test($x:ident) { + #[derive(PartialEq, Eq)] + pub struct Bar { + $x: u8, + x: u16, + } + pub struct Bar_; + + #[rustc_symbol_name] + //~^ ERROR symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE) + //~| ERROR demangling(>) + //~| ERROR demangling-alt(>) + impl Bar_<{Bar { $x: 123, x: 4096 }}> {} +} +duplicate_field_name_test!(x); + +fn main() {} diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.stderr b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr new file mode 100644 index 000000000000..b3c5bd2b89d3 --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr @@ -0,0 +1,161 @@ +error: symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4NoneUE) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(::None}>>) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(::None}>>) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4SomeTj0_EE) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(::Some(0usize)}>>) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(::Some(0)}>>) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 24 previous errors + From db13636f036db4b7988fafd2288dc73ce46a1e53 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 1 May 2021 00:38:01 +0100 Subject: [PATCH 111/269] Stabilise BufWriter::into_parts Signed-off-by: Ian Jackson --- library/std/src/io/buffered/bufwriter.rs | 14 ++++++-------- library/std/src/io/buffered/mod.rs | 2 +- library/std/src/io/mod.rs | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 9da5fbff9cf0..df60af7c36a3 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -323,7 +323,6 @@ impl BufWriter { /// # Examples /// /// ``` - /// #![feature(bufwriter_into_parts)] /// use std::io::{BufWriter, Write}; /// /// let mut buffer = [0u8; 10]; @@ -334,7 +333,7 @@ impl BufWriter { /// assert_eq!(recovered_writer.len(), 0); /// assert_eq!(&buffered_data.unwrap(), b"ata"); /// ``` - #[unstable(feature = "bufwriter_into_parts", issue = "80690")] + #[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub fn into_parts(mut self) -> (W, Result, WriterPanicked>) { let buf = mem::take(&mut self.buf); let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) }; @@ -444,14 +443,13 @@ impl BufWriter { } } -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] /// Error returned for the buffered data from `BufWriter::into_parts`, when the underlying /// writer has previously panicked. Contains the (possibly partly written) buffered data. /// /// # Example /// /// ``` -/// #![feature(bufwriter_into_parts)] /// use std::io::{self, BufWriter, Write}; /// use std::panic::{catch_unwind, AssertUnwindSafe}; /// @@ -478,7 +476,7 @@ pub struct WriterPanicked { impl WriterPanicked { /// Returns the perhaps-unwritten data. Some of this data may have been written by the /// panicking call(s) to the underlying writer, so simply writing it again is not a good idea. - #[unstable(feature = "bufwriter_into_parts", issue = "80690")] + #[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub fn into_inner(self) -> Vec { self.buf } @@ -487,7 +485,7 @@ impl WriterPanicked { "BufWriter inner writer panicked, what data remains unwritten is not known"; } -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] impl error::Error for WriterPanicked { #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { @@ -495,14 +493,14 @@ impl error::Error for WriterPanicked { } } -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] impl fmt::Display for WriterPanicked { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", Self::DESCRIPTION) } } -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] impl fmt::Debug for WriterPanicked { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("WriterPanicked") diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 8cfffc2fd35a..179bdf7fe553 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -14,7 +14,7 @@ use crate::io::Error; pub use bufreader::BufReader; pub use bufwriter::BufWriter; -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub use bufwriter::WriterPanicked; pub use linewriter::LineWriter; use linewritershim::LineWriterShim; diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 28254fea0d37..e8466fa06b89 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -264,7 +264,7 @@ use crate::sys_common::memchr; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::IntoInnerError; -#[unstable(feature = "bufwriter_into_parts", issue = "80690")] +#[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub use self::buffered::WriterPanicked; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; From f17e384a43dd8ca0aefb36bfcd8a69d9ad7f12cf Mon Sep 17 00:00:00 2001 From: Andreas Liljeqvist Date: Tue, 24 Aug 2021 19:41:58 +0200 Subject: [PATCH 112/269] use convention for with_* methods --- compiler/rustc_target/src/abi/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 49c06fca85ac..d206df461200 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -713,16 +713,18 @@ impl WrappingRange { self.start > self.end || self.start == 0 } - /// Returns new `WrappingRange` with replaced `start` + /// Returns `self` with replaced `start` #[inline(always)] - pub fn with_start(&self, start: u128) -> Self { - Self { start, end: self.end } + pub fn with_start(mut self, start: u128) -> Self { + self.start = start; + self } - /// Returns new `WrappingRange` with replaced `end` + /// Returns `self` with replaced `end` #[inline(always)] - pub fn with_end(&self, end: u128) -> Self { - Self { start: self.start, end } + pub fn with_end(mut self, end: u128) -> Self { + self.end = end; + self } } @@ -1024,7 +1026,7 @@ impl Niche { pub fn reserve(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> { assert!(count > 0); - let Scalar { value, valid_range: ref v } = self.scalar; + let Scalar { value, valid_range: v } = self.scalar.clone(); let bits = value.size(cx).bits(); assert!(bits <= 128); let max_value = !0u128 >> (128 - bits); From edb4b2d8c2a9eafc3bdfdb97d5b676afc3f31248 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 24 Aug 2021 21:29:30 +0300 Subject: [PATCH 113/269] Morph `layout_raw` query into `layout_of`. --- compiler/rustc_middle/src/query/mod.rs | 10 +- compiler/rustc_middle/src/ty/layout.rs | 108 ++++++------------ compiler/rustc_mir/src/util/alignment.rs | 2 +- compiler/rustc_target/src/abi/mod.rs | 2 +- compiler/rustc_typeck/src/check/upvar.rs | 2 +- src/test/ui/consts/const-size_of-cycle.stderr | 1 + src/test/ui/consts/issue-44415.stderr | 1 + .../issue-26548-recursion-via-normalize.rs | 9 +- ...issue-26548-recursion-via-normalize.stderr | 13 +-- 9 files changed, 54 insertions(+), 94 deletions(-) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 68de7f29193d..d52ff3b73b2b 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1100,10 +1100,12 @@ rustc_queries! { cache_on_disk_if { false } } - query layout_raw( - env: ty::ParamEnvAnd<'tcx, Ty<'tcx>> - ) -> Result<&'tcx rustc_target::abi::Layout, ty::layout::LayoutError<'tcx>> { - desc { "computing layout of `{}`", env.value } + /// Computes the layout of a type. Note that this implicitly + /// executes in "reveal all" mode, and will normalize the input type. + query layout_of( + key: ty::ParamEnvAnd<'tcx, Ty<'tcx>> + ) -> Result, ty::layout::LayoutError<'tcx>> { + desc { "computing layout of `{}`", key.value } } query dylib_dependency_formats(_: CrateNum) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 80c99872dd76..5b5c19d700c3 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -205,10 +205,10 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> { } } -fn layout_raw<'tcx>( +fn layout_of<'tcx>( tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, -) -> Result<&'tcx Layout, LayoutError<'tcx>> { +) -> Result, LayoutError<'tcx>> { ty::tls::with_related_context(tcx, move |icx| { let (param_env, ty) = query.into_parts(); @@ -220,21 +220,33 @@ fn layout_raw<'tcx>( let icx = ty::tls::ImplicitCtxt { layout_depth: icx.layout_depth + 1, ..icx.clone() }; ty::tls::enter_context(&icx, |_| { + let param_env = param_env.with_reveal_all_normalized(tcx); + let unnormalized_ty = ty; + let ty = tcx.normalize_erasing_regions(param_env, ty); + if ty != unnormalized_ty { + // Ensure this layout is also cached for the normalized type. + return tcx.layout_of(param_env.and(ty)); + } + let cx = LayoutCx { tcx, param_env }; - let layout = cx.layout_raw_uncached(ty); + + let layout = cx.layout_of_uncached(ty)?; + let layout = TyAndLayout { ty, layout }; + + cx.record_layout_for_printing(layout); + // Type-level uninhabitedness should always imply ABI uninhabitedness. - if let Ok(layout) = layout { - if tcx.conservative_is_privately_uninhabited(param_env.and(ty)) { - assert!(layout.abi.is_uninhabited()); - } + if tcx.conservative_is_privately_uninhabited(param_env.and(ty)) { + assert!(layout.abi.is_uninhabited()); } - layout + + Ok(layout) }) }) } pub fn provide(providers: &mut ty::query::Providers) { - *providers = ty::query::Providers { layout_raw, ..*providers }; + *providers = ty::query::Providers { layout_of, ..*providers }; } pub struct LayoutCx<'tcx, C> { @@ -492,7 +504,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }) } - fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'tcx>> { + fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<'tcx>> { let tcx = self.tcx; let param_env = self.param_env; let dl = self.data_layout(); @@ -886,7 +898,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let present_first = match present_first { Some(present_first) => present_first, // Uninhabited because it has no variants, or only absent ones. - None if def.is_enum() => return tcx.layout_raw(param_env.and(tcx.types.never)), + None if def.is_enum() => { + return Ok(tcx.layout_of(param_env.and(tcx.types.never))?.layout); + } // If it's a struct, still compute a layout so that we can still compute the // field offsets. None => VariantIdx::new(0), @@ -1362,11 +1376,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Types with no meaningful known layout. ty::Projection(_) | ty::Opaque(..) => { - let normalized = tcx.normalize_erasing_regions(param_env, ty); - if ty == normalized { - return Err(LayoutError::Unknown(ty)); - } - tcx.layout_raw(param_env.and(normalized))? + // NOTE(eddyb) `layout_of` query should've normalized these away, + // if that was possible, so there's no reason to try again here. + return Err(LayoutError::Unknown(ty)); } ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => { @@ -1703,7 +1715,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { Ok(layout) } - /// This is invoked by the `layout_raw` query to record the final + /// This is invoked by the `layout_of` query to record the final /// layout of each type. #[inline(always)] fn record_layout_for_printing(&self, layout: TyAndLayout<'tcx>) { @@ -2031,22 +2043,9 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { type TyAndLayout = Result, LayoutError<'tcx>>; /// Computes the layout of a type. Note that this implicitly - /// executes in "reveal all" mode. + /// executes in "reveal all" mode, and will normalize the input type. fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { - let param_env = self.param_env.with_reveal_all_normalized(self.tcx); - let ty = self.tcx.normalize_erasing_regions(param_env, ty); - let layout = self.tcx.layout_raw(param_env.and(ty))?; - let layout = TyAndLayout { ty, layout }; - - // N.B., this recording is normally disabled; when enabled, it - // can however trigger recursive invocations of `layout_of`. - // Therefore, we execute it *after* the main query has - // completed, to avoid problems around recursive structures - // and the like. (Admittedly, I wasn't able to reproduce a problem - // here, but it seems like the right thing to do. -nmatsakis) - self.record_layout_for_printing(layout); - - Ok(layout) + self.tcx.layout_of(self.param_env.and(ty)) } } @@ -2055,50 +2054,9 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { type TyAndLayout = Result, LayoutError<'tcx>>; /// Computes the layout of a type. Note that this implicitly - /// executes in "reveal all" mode. + /// executes in "reveal all" mode, and will normalize the input type. fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { - let param_env = self.param_env.with_reveal_all_normalized(*self.tcx); - let ty = self.tcx.normalize_erasing_regions(param_env, ty); - let layout = self.tcx.layout_raw(param_env.and(ty))?; - let layout = TyAndLayout { ty, layout }; - - // N.B., this recording is normally disabled; when enabled, it - // can however trigger recursive invocations of `layout_of`. - // Therefore, we execute it *after* the main query has - // completed, to avoid problems around recursive structures - // and the like. (Admittedly, I wasn't able to reproduce a problem - // here, but it seems like the right thing to do. -nmatsakis) - let cx = LayoutCx { tcx: *self.tcx, param_env: self.param_env }; - cx.record_layout_for_printing(layout); - - Ok(layout) - } -} - -// Helper (inherent) `layout_of` methods to avoid pushing `LayoutCx` to users. -impl TyCtxt<'tcx> { - /// Computes the layout of a type. Note that this implicitly - /// executes in "reveal all" mode. - #[inline] - pub fn layout_of( - self, - param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Result, LayoutError<'tcx>> { - let cx = LayoutCx { tcx: self, param_env: param_env_and_ty.param_env }; - cx.layout_of(param_env_and_ty.value) - } -} - -impl ty::query::TyCtxtAt<'tcx> { - /// Computes the layout of a type. Note that this implicitly - /// executes in "reveal all" mode. - #[inline] - pub fn layout_of( - self, - param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, - ) -> Result, LayoutError<'tcx>> { - let cx = LayoutCx { tcx: self.at(self.span), param_env: param_env_and_ty.param_env }; - cx.layout_of(param_env_and_ty.value) + self.tcx.layout_of(self.param_env.and(ty)) } } diff --git a/compiler/rustc_mir/src/util/alignment.rs b/compiler/rustc_mir/src/util/alignment.rs index 5d4ca871faa2..73adc60577bf 100644 --- a/compiler/rustc_mir/src/util/alignment.rs +++ b/compiler/rustc_mir/src/util/alignment.rs @@ -24,7 +24,7 @@ where }; let ty = place.ty(local_decls, tcx).ty; - match tcx.layout_raw(param_env.and(ty)) { + match tcx.layout_of(param_env.and(ty)) { Ok(layout) if layout.align.abi <= pack => { // If the packed alignment is greater or equal to the field alignment, the type won't be // further disaligned. diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 8ef6e142caec..285c0d1a8498 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1063,7 +1063,7 @@ impl Layout { /// to that obtained from `layout_of(ty)`, as we need to produce /// layouts for which Rust types do not exist, such as enum variants /// or synthetic fields of enums (i.e., discriminants) and fat pointers. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)] pub struct TyAndLayout<'a, Ty> { pub ty: Ty, pub layout: &'a Layout, diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index fc7f55e24b2f..de64f648be21 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -1485,7 +1485,7 @@ fn restrict_repr_packed_field_ref_capture<'tcx>( match p.kind { ProjectionKind::Field(..) => match ty.kind() { ty::Adt(def, _) if def.repr.packed() => { - match tcx.layout_raw(param_env.and(p.ty)) { + match tcx.layout_of(param_env.and(p.ty)) { Ok(layout) if layout.align.abi.bytes() == 1 => { // if the alignment is 1, the type can't be further // disaligned. diff --git a/src/test/ui/consts/const-size_of-cycle.stderr b/src/test/ui/consts/const-size_of-cycle.stderr index 129457ebdf92..1067eb003f7c 100644 --- a/src/test/ui/consts/const-size_of-cycle.stderr +++ b/src/test/ui/consts/const-size_of-cycle.stderr @@ -15,6 +15,7 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`.. LL | bytes: [u8; std::mem::size_of::()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: ...which requires computing layout of `Foo`... + = note: ...which requires computing layout of `[u8; _]`... = note: ...which requires normalizing `[u8; _]`... = note: ...which again requires simplifying constant for the type system `Foo::bytes::{constant#0}`, completing the cycle note: cycle used when checking that `Foo` is well-formed diff --git a/src/test/ui/consts/issue-44415.stderr b/src/test/ui/consts/issue-44415.stderr index 38841e99a722..9e3db5ce9a40 100644 --- a/src/test/ui/consts/issue-44415.stderr +++ b/src/test/ui/consts/issue-44415.stderr @@ -15,6 +15,7 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`.. LL | bytes: [u8; unsafe { intrinsics::size_of::() }], | ^^^^^^ = note: ...which requires computing layout of `Foo`... + = note: ...which requires computing layout of `[u8; _]`... = note: ...which requires normalizing `[u8; _]`... = note: ...which again requires simplifying constant for the type system `Foo::bytes::{constant#0}`, completing the cycle note: cycle used when checking that `Foo` is well-formed diff --git a/src/test/ui/recursion/issue-26548-recursion-via-normalize.rs b/src/test/ui/recursion/issue-26548-recursion-via-normalize.rs index 4d1cd059c27b..03cb3e24b7db 100644 --- a/src/test/ui/recursion/issue-26548-recursion-via-normalize.rs +++ b/src/test/ui/recursion/issue-26548-recursion-via-normalize.rs @@ -1,6 +1,8 @@ -//~ ERROR cycle detected when computing layout of -//~| NOTE ...which requires computing layout of -//~| NOTE ...which again requires computing layout of +//~ ERROR cycle detected when computing layout of `S` +//~| NOTE ...which requires computing layout of `std::option::Option<::It>`... +//~| NOTE ...which requires computing layout of `std::option::Option`... +//~| NOTE ...which again requires computing layout of `S`, completing the cycle +//~| NOTE cycle used when computing layout of `std::option::Option` // build-fail @@ -13,6 +15,5 @@ impl Mirror for T { struct S(Option<::It>); fn main() { - //~^ NOTE cycle used when optimizing MIR for `main` let _s = S(None); } diff --git a/src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr b/src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr index be55890c08c8..21c0e1e6de5f 100644 --- a/src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr +++ b/src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr @@ -1,12 +1,9 @@ -error[E0391]: cycle detected when computing layout of `std::option::Option` +error[E0391]: cycle detected when computing layout of `S` | - = note: ...which requires computing layout of `S`... - = note: ...which again requires computing layout of `std::option::Option`, completing the cycle -note: cycle used when optimizing MIR for `main` - --> $DIR/issue-26548-recursion-via-normalize.rs:15:1 - | -LL | fn main() { - | ^^^^^^^^^ + = note: ...which requires computing layout of `std::option::Option<::It>`... + = note: ...which requires computing layout of `std::option::Option`... + = note: ...which again requires computing layout of `S`, completing the cycle + = note: cycle used when computing layout of `std::option::Option` error: aborting due to previous error From 335bf7ca6b2e63ffc5b7ee732819b7bf228a179e Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Tue, 24 Aug 2021 21:15:26 +0200 Subject: [PATCH 114/269] =?UTF-8?q?Clarifiy=20weak=20pointers=20being=20di?= =?UTF-8?q?associated=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …noting the fact that `clone` is not called. Co-authored-by: Mark Rousskov --- library/alloc/src/rc.rs | 5 +++-- library/alloc/src/sync.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 90b077210a47..272fc119f4ed 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1100,8 +1100,9 @@ impl Rc { /// [`clone`] the inner value to a new allocation to ensure unique ownership. This is also /// referred to as clone-on-write. /// - /// If there are no other `Rc` pointers to this allocation, then [`Weak`] - /// pointers to this allocation will be disassociated. + /// However, if there are no other `Rc` pointers to this allocation, but some [`Weak`] + /// pointers, then the [`Weak`] pointers will be disassociated and the inner value will not + /// be cloned. /// /// See also [`get_mut`], which will fail rather than cloning. /// diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 7e4cb6d2c60f..2367eaec4b93 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1350,8 +1350,9 @@ impl Arc { /// [`clone`] the inner value to a new allocation to ensure unique ownership. This is also /// referred to as clone-on-write. /// - /// If there are no other `Arc` pointers to this allocation, then [`Weak`] - /// pointers to this allocation will be disassociated. + /// However, if there are no other `Arc` pointers to this allocation, but some [`Weak`] + /// pointers, then the [`Weak`] pointers will be disassociated and the inner value will not + /// be cloned. /// /// See also [`get_mut`], which will fail rather than cloning. /// From 90354c719a94db7d393134c00b2a91bd651b5e7a Mon Sep 17 00:00:00 2001 From: Frank Steffahn Date: Tue, 24 Aug 2021 21:34:12 +0200 Subject: [PATCH 115/269] Make explanations of cross-references between `make_mut` and `get_mut` more accurate --- library/alloc/src/rc.rs | 5 +++-- library/alloc/src/sync.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 272fc119f4ed..a9d147fa1a55 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1011,7 +1011,7 @@ impl Rc { /// mutate a shared value. /// /// See also [`make_mut`][make_mut], which will [`clone`][clone] - /// the inner value when there are other pointers. + /// the inner value when there are other `Rc` pointers. /// /// [make_mut]: Rc::make_mut /// [clone]: Clone::clone @@ -1104,7 +1104,8 @@ impl Rc { /// pointers, then the [`Weak`] pointers will be disassociated and the inner value will not /// be cloned. /// - /// See also [`get_mut`], which will fail rather than cloning. + /// See also [`get_mut`], which will fail rather than cloning the inner value + /// or diassociating [`Weak`] pointers. /// /// [`clone`]: Clone::clone /// [`get_mut`]: Rc::get_mut diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 2367eaec4b93..a066e0b49e25 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1354,7 +1354,8 @@ impl Arc { /// pointers, then the [`Weak`] pointers will be disassociated and the inner value will not /// be cloned. /// - /// See also [`get_mut`], which will fail rather than cloning. + /// See also [`get_mut`], which will fail rather than cloning the inner value + /// or diassociating [`Weak`] pointers. /// /// [`clone`]: Clone::clone /// [`get_mut`]: Arc::get_mut @@ -1458,7 +1459,7 @@ impl Arc { /// mutate a shared value. /// /// See also [`make_mut`][make_mut], which will [`clone`][clone] - /// the inner value when there are other pointers. + /// the inner value when there are other `Arc` pointers. /// /// [make_mut]: Arc::make_mut /// [clone]: Clone::clone From 09e02a891963d7418f1db4d8d4cf9a8d177d2cf9 Mon Sep 17 00:00:00 2001 From: Mariano Casco Date: Tue, 24 Aug 2021 12:04:02 -0300 Subject: [PATCH 116/269] Add SAFETY comments to core::slice::sort::partition_in_blocks --- library/core/src/slice/sort.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/library/core/src/slice/sort.rs b/library/core/src/slice/sort.rs index 36c2c4abdb4c..8a31388fbdbb 100644 --- a/library/core/src/slice/sort.rs +++ b/library/core/src/slice/sort.rs @@ -369,6 +369,22 @@ where // Instead of swapping one pair at the time, it is more efficient to perform a cyclic // permutation. This is not strictly equivalent to swapping, but produces a similar // result using fewer memory operations. + + // SAFETY: The use of `ptr::read` is valid because there is at least one element in + // both `offsets_l` and `offsets_r`, so `left!` is a valid pointer to read from. + // + // The uses of `left!` involve calls to `offset` on `l`, which points to the + // beginning of `v`. All the offsets pointed-to by `start_l` are at most `block_l`, so + // these `offset` calls are safe as all reads are within the block. The same argument + // applies for the uses of `right!`. + // + // The calls to `start_l.offset` are valid because there are at most `count-1` of them, + // plus the final one at the end of the unsafe block, where `count` is the minimum number + // of collected offsets in `offsets_l` and `offsets_r`, so there is no risk of there not + // being enough elements. The same reasoning applies to the calls to `start_r.offset`. + // + // The calls to `copy_nonoverlapping` are safe because `left!` and `right!` are guaranteed + // not to overlap, and are valid because of the reasoning above. unsafe { let tmp = ptr::read(left!()); ptr::copy_nonoverlapping(right!(), left!(), 1); @@ -389,11 +405,21 @@ where if start_l == end_l { // All out-of-order elements in the left block were moved. Move to the next block. + + // block-width-guarantee + // SAFETY: if `!is_done` then the slice width is guaranteed to be at least `2*BLOCK` wide. There + // are at most `BLOCK` elements in `offsets_l` because of its size, so the `offset` operation is + // safe. Otherwise, the debug assertions in the `is_done` case guarantee that + // `width(l, r) == block_l + block_r`, namely, that the block sizes have been adjusted to account + // for the smaller number of remaining elements. l = unsafe { l.offset(block_l as isize) }; } if start_r == end_r { // All out-of-order elements in the right block were moved. Move to the previous block. + + // SAFETY: Same argument as [block-width-guarantee]. Either this is a full block `2*BLOCK`-wide, + // or `block_r` has been adjusted for the last handful of elements. r = unsafe { r.offset(-(block_r as isize)) }; } From 451abd311c90e0e94c8c364a282c472323528cf5 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 11 Aug 2021 13:17:21 -0400 Subject: [PATCH 117/269] PGO for LLVM builds on x86_64-unknown-linux-gnu in CI This shows up to 5% less instruction counts on multiple benchmarks, and up to 19% wins on the -j1 wall times for rustc self-compilation. We can afford to spend the extra cycles building LLVM essentially once more for the x86_64-unknown-linux-gnu CI build today. The builder finishes in around 50 minutes on average, and this adds just 10 more minutes. Given the sizeable improvements in compiler performance, this is definitely worth it. --- src/bootstrap/config.rs | 4 + src/bootstrap/dist.rs | 14 ++- src/bootstrap/flags.rs | 20 +++- src/bootstrap/native.rs | 8 ++ .../host-x86_64/dist-x86_64-linux/Dockerfile | 6 ++ .../dist-x86_64-linux/build-clang.sh | 6 +- src/ci/pgo.sh | 96 +++++++++---------- 7 files changed, 98 insertions(+), 56 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index dd536cb7b02b..5706b8f9e7cc 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -143,6 +143,8 @@ pub struct Config { pub rust_new_symbol_mangling: bool, pub rust_profile_use: Option, pub rust_profile_generate: Option, + pub llvm_profile_use: Option, + pub llvm_profile_generate: bool, pub build: TargetSelection, pub hosts: Vec, @@ -605,6 +607,8 @@ impl Config { if let Some(value) = flags.deny_warnings { config.deny_warnings = value; } + config.llvm_profile_use = flags.llvm_profile_use; + config.llvm_profile_generate = flags.llvm_profile_generate; if config.dry_run { let dir = config.out.join("tmp-dry-run"); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 64075e18366b..d7d511c1c921 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2157,10 +2157,16 @@ impl Step for ReproducibleArtifacts { } fn run(self, builder: &Builder<'_>) -> Self::Output { - let path = builder.config.rust_profile_use.as_ref()?; - + let mut added_anything = false; let tarball = Tarball::new(builder, "reproducible-artifacts", &self.target.triple); - tarball.add_file(path, ".", 0o644); - Some(tarball.generate()) + if let Some(path) = builder.config.rust_profile_use.as_ref() { + tarball.add_file(path, ".", 0o644); + added_anything = true; + } + if let Some(path) = builder.config.llvm_profile_use.as_ref() { + tarball.add_file(path, ".", 0o644); + added_anything = true; + } + if added_anything { Some(tarball.generate()) } else { None } } } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 80c33fa4d7c9..2fddda74a28e 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -71,6 +71,13 @@ pub struct Flags { pub rust_profile_use: Option, pub rust_profile_generate: Option, + + pub llvm_profile_use: Option, + // LLVM doesn't support a custom location for generating profile + // information. + // + // llvm_out/build/profiles/ is the location this writes to. + pub llvm_profile_generate: bool, } pub enum Subcommand { @@ -222,8 +229,15 @@ To learn more about a subcommand, run `./x.py -h`", VALUE overrides the skip-rebuild option in config.toml.", "VALUE", ); - opts.optopt("", "rust-profile-generate", "generate PGO profile with rustc build", "FORMAT"); - opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "FORMAT"); + opts.optopt( + "", + "rust-profile-generate", + "generate PGO profile with rustc build", + "PROFILE", + ); + opts.optopt("", "rust-profile-use", "use PGO profile for rustc build", "PROFILE"); + opts.optflag("", "llvm-profile-generate", "generate PGO profile with llvm built for rustc"); + opts.optopt("", "llvm-profile-use", "use PGO profile for llvm build", "PROFILE"); // We can't use getopt to parse the options until we have completed specifying which // options are valid, but under the current implementation, some options are conditional on @@ -687,6 +701,8 @@ Arguments: .expect("`color` should be `always`, `never`, or `auto`"), rust_profile_use: matches.opt_str("rust-profile-use"), rust_profile_generate: matches.opt_str("rust-profile-generate"), + llvm_profile_use: matches.opt_str("llvm-profile-use"), + llvm_profile_generate: matches.opt_present("llvm-profile-generate"), } } } diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index d1397394be75..2172b01706d8 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -189,6 +189,14 @@ impl Step for Llvm { .define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap()) .define("LLVM_DEFAULT_TARGET_TRIPLE", target_native); + if builder.config.llvm_profile_generate { + cfg.define("LLVM_BUILD_INSTRUMENTED", "IR"); + cfg.define("LLVM_BUILD_RUNTIME", "No"); + } + if let Some(path) = builder.config.llvm_profile_use.as_ref() { + cfg.define("LLVM_PROFDATA_FILE", &path); + } + if target != "aarch64-apple-darwin" && !target.contains("windows") { cfg.define("LLVM_ENABLE_ZLIB", "ON"); } else { diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile index 8242e091cd4c..e29d990f0f97 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile @@ -82,6 +82,12 @@ COPY host-x86_64/dist-x86_64-linux/build-clang.sh /tmp/ RUN ./build-clang.sh ENV CC=clang CXX=clang++ +ENV PERF_COMMIT 1e19fc4c6168d2f7596e512f42f358f245d8f09d +RUN curl -LS -o perf.zip https://github.com/rust-lang/rustc-perf/archive/$PERF_COMMIT.zip && \ + unzip perf.zip && \ + mv rustc-perf-$PERF_COMMIT rustc-perf && \ + rm perf.zip + COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh index 40a637616d35..ed5edfec4e1a 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh @@ -20,14 +20,18 @@ cd clang-build # include path, /rustroot/include, to clang's default include path. INC="/rustroot/include:/usr/include" +# We need compiler-rt for the profile runtime (used later to PGO the LLVM build) +# but sanitizers aren't currently building. Since we don't need those, just +# disable them. hide_output \ cmake ../llvm \ -DCMAKE_C_COMPILER=/rustroot/bin/gcc \ -DCMAKE_CXX_COMPILER=/rustroot/bin/g++ \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/rustroot \ + -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DLLVM_TARGETS_TO_BUILD=X86 \ - -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \ -DC_INCLUDE_DIRS="$INC" hide_output make -j$(nproc) diff --git a/src/ci/pgo.sh b/src/ci/pgo.sh index aa009a4eac6a..e35e3e670cc6 100755 --- a/src/ci/pgo.sh +++ b/src/ci/pgo.sh @@ -5,61 +5,59 @@ set -euxo pipefail rm -rf /tmp/rustc-pgo python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \ - --stage 2 library/std --rust-profile-generate=/tmp/rustc-pgo + --stage 2 library/std \ + --rust-profile-generate=/tmp/rustc-pgo \ + --llvm-profile-generate +# Profile libcore compilation in opt-level=0 and opt-level=3 RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ --crate-type=lib ../library/core/src/lib.rs - -# Download and build a single-file stress test benchmark on perf.rust-lang.org. -function pgo_perf_benchmark { - local PERF=1e19fc4c6168d2f7596e512f42f358f245d8f09d - local github_prefix=https://raw.githubusercontent.com/rust-lang/rustc-perf/$PERF - local name=$1 - local edition=$2 - curl -o /tmp/$name.rs $github_prefix/collector/benchmarks/$name/src/lib.rs - - RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=$edition \ - --crate-type=lib /tmp/$name.rs -} - -pgo_perf_benchmark externs 2018 -pgo_perf_benchmark ctfe-stress-4 2018 -pgo_perf_benchmark inflate 2015 - -cp -pri ../src/tools/cargo /tmp/cargo - -# The Cargo repository does not have a Cargo.lock in it, as it relies on the -# lockfile already present in the rust-lang/rust monorepo. This decision breaks -# down when Cargo is built outside the monorepo though (like in this case), -# resulting in a build without any dependency locking. -# -# To ensure Cargo is built with locked dependencies even during PGO profiling -# the following command copies the monorepo's lockfile into the Cargo temporary -# directory. Cargo will *not* keep that lockfile intact, as it will remove all -# the dependencies Cargo itself doesn't rely on. Still, it will prevent -# building Cargo with arbitrary dependency versions. -# -# See #81378 for the bug that prompted adding this. -cp -p ../Cargo.lock /tmp/cargo - -# Build cargo (with some flags) -function pgo_cargo { - RUSTC=./build/$PGO_HOST/stage2/bin/rustc \ - ./build/$PGO_HOST/stage0/bin/cargo $@ \ - --manifest-path /tmp/cargo/Cargo.toml -} - -# Build a couple different variants of Cargo -CARGO_INCREMENTAL=1 pgo_cargo check -echo 'pub fn barbarbar() {}' >> /tmp/cargo/src/cargo/lib.rs -CARGO_INCREMENTAL=1 pgo_cargo check -touch /tmp/cargo/src/cargo/lib.rs -CARGO_INCREMENTAL=1 pgo_cargo check -pgo_cargo build --release +RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ + --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs + +cp -r /tmp/rustc-perf ./ +chown -R $(whoami): ./rustc-perf +cd rustc-perf + +# Build the collector ahead of time, which is needed to make sure the rustc-fake +# binary used by the collector is present. +RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \ +RUSTC_BOOTSTRAP=1 \ +/checkout/obj/build/$PGO_HOST/stage0/bin/cargo build -p collector + +# benchmark using profile_local with eprintln, which essentially just means +# don't actually benchmark -- just make sure we run rustc a bunch of times. +RUST_LOG=collector=debug \ +RUSTC=/checkout/obj/build/$PGO_HOST/stage0/bin/rustc \ +RUSTC_BOOTSTRAP=1 \ +/checkout/obj/build/$PGO_HOST/stage0/bin/cargo run -p collector --bin collector -- \ + profile_local \ + eprintln \ + /checkout/obj/build/$PGO_HOST/stage2/bin/rustc \ + Test \ + --builds Check,Debug,Opt \ + --cargo /checkout/obj/build/$PGO_HOST/stage0/bin/cargo \ + --runs All \ + --include externs,ctfe-stress-4,inflate,cargo,token-stream-stress,match-stress-enum + +cd /checkout/obj # Merge the profile data we gathered ./build/$PGO_HOST/llvm/bin/llvm-profdata \ merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo +# Merge the profile data we gathered for LLVM +# Note that this uses the profdata from the clang we used to build LLVM, +# which likely has a different version than our in-tree clang. +/rustroot/bin/llvm-profdata \ + merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST/llvm/build/profiles + +# Rustbuild currently doesn't support rebuilding LLVM when PGO options +# change (or any other llvm-related options); so just clear out the relevant +# directories ourselves. +rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld + # This produces the actual final set of artifacts. -$@ --rust-profile-use=/tmp/rustc-pgo.profdata +$@ \ + --rust-profile-use=/tmp/rustc-pgo.profdata \ + --llvm-profile-use=/tmp/llvm-pgo.profdata From c565339c37def41500c6d3175c2db3be8c5c4f76 Mon Sep 17 00:00:00 2001 From: klensy Date: Sun, 22 Aug 2021 19:55:45 +0300 Subject: [PATCH 118/269] Convert some functions to return Cow<'static,str> instead of String to reduce potential reallocations --- compiler/rustc_ast_pretty/src/pprust/mod.rs | 6 +- compiler/rustc_ast_pretty/src/pprust/state.rs | 92 +++++++++---------- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 2 +- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/mod.rs b/compiler/rustc_ast_pretty/src/pprust/mod.rs index 976725b308e0..e74f38dd89c3 100644 --- a/compiler/rustc_ast_pretty/src/pprust/mod.rs +++ b/compiler/rustc_ast_pretty/src/pprust/mod.rs @@ -8,17 +8,19 @@ use rustc_ast as ast; use rustc_ast::token::{Nonterminal, Token, TokenKind}; use rustc_ast::tokenstream::{TokenStream, TokenTree}; +use std::borrow::Cow; + pub fn nonterminal_to_string(nt: &Nonterminal) -> String { State::new().nonterminal_to_string(nt) } /// Print the token kind precisely, without converting `$crate` into its respective crate name. -pub fn token_kind_to_string(tok: &TokenKind) -> String { +pub fn token_kind_to_string(tok: &TokenKind) -> Cow<'static, str> { State::new().token_kind_to_string(tok) } /// Print the token precisely, without converting `$crate` into its respective crate name. -pub fn token_to_string(token: &Token) -> String { +pub fn token_to_string(token: &Token) -> Cow<'static, str> { State::new().token_to_string(token) } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b09c668273aa..26a7096781f5 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -658,7 +658,7 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } /// Print the token kind precisely, without converting `$crate` into its respective crate name. - fn token_kind_to_string(&self, tok: &TokenKind) -> String { + fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str> { self.token_kind_to_string_ext(tok, None) } @@ -666,72 +666,72 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere &self, tok: &TokenKind, convert_dollar_crate: Option, - ) -> String { + ) -> Cow<'static, str> { match *tok { - token::Eq => "=".to_string(), - token::Lt => "<".to_string(), - token::Le => "<=".to_string(), - token::EqEq => "==".to_string(), - token::Ne => "!=".to_string(), - token::Ge => ">=".to_string(), - token::Gt => ">".to_string(), - token::Not => "!".to_string(), - token::Tilde => "~".to_string(), - token::OrOr => "||".to_string(), - token::AndAnd => "&&".to_string(), - token::BinOp(op) => binop_to_string(op).to_string(), - token::BinOpEq(op) => format!("{}=", binop_to_string(op)), + token::Eq => "=".into(), + token::Lt => "<".into(), + token::Le => "<=".into(), + token::EqEq => "==".into(), + token::Ne => "!=".into(), + token::Ge => ">=".into(), + token::Gt => ">".into(), + token::Not => "!".into(), + token::Tilde => "~".into(), + token::OrOr => "||".into(), + token::AndAnd => "&&".into(), + token::BinOp(op) => binop_to_string(op).into(), + token::BinOpEq(op) => format!("{}=", binop_to_string(op)).into(), /* Structural symbols */ - token::At => "@".to_string(), - token::Dot => ".".to_string(), - token::DotDot => "..".to_string(), - token::DotDotDot => "...".to_string(), - token::DotDotEq => "..=".to_string(), - token::Comma => ",".to_string(), - token::Semi => ";".to_string(), - token::Colon => ":".to_string(), - token::ModSep => "::".to_string(), - token::RArrow => "->".to_string(), - token::LArrow => "<-".to_string(), - token::FatArrow => "=>".to_string(), - token::OpenDelim(token::Paren) => "(".to_string(), - token::CloseDelim(token::Paren) => ")".to_string(), - token::OpenDelim(token::Bracket) => "[".to_string(), - token::CloseDelim(token::Bracket) => "]".to_string(), - token::OpenDelim(token::Brace) => "{".to_string(), - token::CloseDelim(token::Brace) => "}".to_string(), - token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim) => "".to_string(), - token::Pound => "#".to_string(), - token::Dollar => "$".to_string(), - token::Question => "?".to_string(), - token::SingleQuote => "'".to_string(), + token::At => "@".into(), + token::Dot => ".".into(), + token::DotDot => "..".into(), + token::DotDotDot => "...".into(), + token::DotDotEq => "..=".into(), + token::Comma => ",".into(), + token::Semi => ";".into(), + token::Colon => ":".into(), + token::ModSep => "::".into(), + token::RArrow => "->".into(), + token::LArrow => "<-".into(), + token::FatArrow => "=>".into(), + token::OpenDelim(token::Paren) => "(".into(), + token::CloseDelim(token::Paren) => ")".into(), + token::OpenDelim(token::Bracket) => "[".into(), + token::CloseDelim(token::Bracket) => "]".into(), + token::OpenDelim(token::Brace) => "{".into(), + token::CloseDelim(token::Brace) => "}".into(), + token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim) => "".into(), + token::Pound => "#".into(), + token::Dollar => "$".into(), + token::Question => "?".into(), + token::SingleQuote => "'".into(), /* Literals */ - token::Literal(lit) => literal_to_string(lit), + token::Literal(lit) => literal_to_string(lit).into(), /* Name components */ token::Ident(s, is_raw) => { - IdentPrinter::new(s, is_raw, convert_dollar_crate).to_string() + IdentPrinter::new(s, is_raw, convert_dollar_crate).to_string().into() } - token::Lifetime(s) => s.to_string(), + token::Lifetime(s) => s.to_string().into(), /* Other */ token::DocComment(comment_kind, attr_style, data) => { - doc_comment_to_string(comment_kind, attr_style, data) + doc_comment_to_string(comment_kind, attr_style, data).into() } - token::Eof => "".to_string(), + token::Eof => "".into(), - token::Interpolated(ref nt) => self.nonterminal_to_string(nt), + token::Interpolated(ref nt) => self.nonterminal_to_string(nt).into(), } } /// Print the token precisely, without converting `$crate` into its respective crate name. - fn token_to_string(&self, token: &Token) -> String { + fn token_to_string(&self, token: &Token) -> Cow<'static, str> { self.token_to_string_ext(token, false) } - fn token_to_string_ext(&self, token: &Token, convert_dollar_crate: bool) -> String { + fn token_to_string_ext(&self, token: &Token, convert_dollar_crate: bool) -> Cow<'static, str> { let convert_dollar_crate = convert_dollar_crate.then_some(token.span); self.token_kind_to_string_ext(&token.kind, convert_dollar_crate) } diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 9aee86c9e57d..abc8fd18fd75 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -1221,7 +1221,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String { match *tt { - mbe::TokenTree::Token(ref token) => pprust::token_to_string(&token), + mbe::TokenTree::Token(ref token) => pprust::token_to_string(&token).into(), mbe::TokenTree::MetaVar(_, name) => format!("${}", name), mbe::TokenTree::MetaVarDecl(_, name, Some(kind)) => format!("${}:{}", name, kind), mbe::TokenTree::MetaVarDecl(_, name, None) => format!("${}:", name), diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 6259eff5a1a0..7952b475dc2b 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1528,7 +1528,7 @@ impl<'a> Parser<'a> { .span_suggestion( token.span, "must have an integer part", - pprust::token_to_string(token), + pprust::token_to_string(token).into(), Applicability::MachineApplicable, ) .emit(); diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 51d4e007b598..04ad323e51a9 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -806,7 +806,7 @@ impl<'a> Parser<'a> { .span_suggestion_short( sp, &format!("missing `{}`", token_str), - token_str, + token_str.into(), Applicability::MaybeIncorrect, ) .emit(); From 08e20d9b28685d438839bd695a9309a8947a61fa Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 24 Aug 2021 22:10:38 -0300 Subject: [PATCH 119/269] Add type of a let tait test --- .../ui/type-alias-impl-trait/type_of_a_let.rs | 29 ++++++++ .../type_of_a_let.stderr | 67 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let.rs create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let.stderr diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let.rs b/src/test/ui/type-alias-impl-trait/type_of_a_let.rs new file mode 100644 index 000000000000..7f8e6127cca3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let.rs @@ -0,0 +1,29 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should compile, but it currently doesn't + +use std::fmt::Debug; + +type Foo = impl Debug; +//~^ ERROR: could not find defining uses + +fn foo1() -> u32 { + let x: Foo = 22_u32; + //~^ ERROR: mismatched types [E0308] + x + //~^ ERROR: mismatched types [E0308] +} + +fn foo2() -> u32 { + let x: Foo = 22_u32; + //~^ ERROR: mismatched types [E0308] + let y: Foo = x; + same_type((x, y)); + y + //~^ ERROR: mismatched types [E0308] +} + +fn same_type(x: (T, T)) {} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let.stderr b/src/test/ui/type-alias-impl-trait/type_of_a_let.stderr new file mode 100644 index 000000000000..cac8d6841afd --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let.stderr @@ -0,0 +1,67 @@ +error[E0308]: mismatched types + --> $DIR/type_of_a_let.rs:12:18 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | let x: Foo = 22_u32; + | --- ^^^^^^ expected opaque type, found `u32` + | | + | expected due to this + | + = note: expected opaque type `impl Debug` + found type `u32` + +error[E0308]: mismatched types + --> $DIR/type_of_a_let.rs:14:5 + | +LL | type Foo = impl Debug; + | ---------- the found opaque type +... +LL | fn foo1() -> u32 { + | --- expected `u32` because of return type +... +LL | x + | ^ expected `u32`, found opaque type + | + = note: expected type `u32` + found opaque type `impl Debug` + +error[E0308]: mismatched types + --> $DIR/type_of_a_let.rs:19:18 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | let x: Foo = 22_u32; + | --- ^^^^^^ expected opaque type, found `u32` + | | + | expected due to this + | + = note: expected opaque type `impl Debug` + found type `u32` + +error[E0308]: mismatched types + --> $DIR/type_of_a_let.rs:23:5 + | +LL | type Foo = impl Debug; + | ---------- the found opaque type +... +LL | fn foo2() -> u32 { + | --- expected `u32` because of return type +... +LL | y + | ^ expected `u32`, found opaque type + | + = note: expected type `u32` + found opaque type `impl Debug` + +error: could not find defining uses + --> $DIR/type_of_a_let.rs:8:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0308`. From dbadab54df148b55b2e884440bfaeaa38517e6e8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 24 Aug 2021 22:52:41 -0300 Subject: [PATCH 120/269] Add type of a let tait test impl trait straight in let --- .../type-alias-impl-trait/type_of_a_let2.rs | 25 +++++++++++++++++++ .../type_of_a_let2.stderr | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.rs create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs new file mode 100644 index 000000000000..33d3f164ce15 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs @@ -0,0 +1,25 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should be under a feature flag + +use std::fmt::Debug; + +fn foo1() -> u32 { + let x: impl Debug = 22_u32; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + x // ERROR: we only know x: Debug, we don't know x = u32 +} + +fn foo2() -> u32 { + let x: impl Debug = 22_u32; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + let y: impl Debug = x; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + same_type((x, y)); // ERROR + x +} + +fn same_type(x: (T, T)) {} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr new file mode 100644 index 000000000000..7a1825a8e2d9 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr @@ -0,0 +1,21 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:9:12 + | +LL | let x: impl Debug = 22_u32; + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:15:12 + | +LL | let x: impl Debug = 22_u32; + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:17:12 + | +LL | let y: impl Debug = x; + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0562`. From 8d7707f3c4f72e6eb334d897354beca692b265d1 Mon Sep 17 00:00:00 2001 From: Jack Huey Date: Mon, 3 May 2021 09:25:32 -0400 Subject: [PATCH 121/269] Normalize associated types with bound vars --- compiler/rustc_middle/src/ty/layout.rs | 3 +- .../borrow_check/type_check/input_output.rs | 31 ++++- .../src/borrow_check/type_check/mod.rs | 1 + .../src/traits/project.rs | 71 +++++------ .../src/traits/query/normalize.rs | 114 +++++++++++++----- compiler/rustc_typeck/src/check/coercion.rs | 5 +- .../ui/associated-type-bounds/issue-83017.rs | 4 +- .../associated-type-bounds/issue-83017.stderr | 33 ----- .../higher-ranked-projection.bad.stderr | 4 +- .../hr-associated-type-bound-1.rs | 2 +- .../hr-associated-type-bound-1.stderr | 6 +- .../hr-associated-type-bound-2.rs | 5 +- .../hr-associated-type-bound-2.stderr | 43 +++++-- .../hr-associated-type-bound-param-1.rs | 2 +- .../hr-associated-type-bound-param-1.stderr | 6 +- .../hr-associated-type-bound-param-2.rs | 6 +- .../hr-associated-type-bound-param-2.stderr | 18 +-- .../hr-associated-type-bound-param-3.rs | 2 +- .../hr-associated-type-bound-param-3.stderr | 6 +- .../hr-associated-type-bound-param-4.rs | 2 +- .../hr-associated-type-bound-param-4.stderr | 6 +- .../hr-associated-type-bound-param-5.rs | 6 +- .../hr-associated-type-bound-param-5.stderr | 50 +------- .../hr-associated-type-bound-param-6.rs | 1 - .../hr-associated-type-bound-param-6.stderr | 27 +---- .../hr-associated-type-projection-1.rs | 3 +- .../hr-associated-type-projection-1.stderr | 34 ++---- src/test/ui/closures/issue-41366.rs | 4 +- src/test/ui/closures/issue-41366.stderr | 32 ----- .../normalize-under-binder/issue-62529-1.rs | 88 ++++++++++++++ .../issue-62529-1.stderr | 67 ++++++++++ .../normalize-under-binder/issue-62529-2.rs | 33 +++++ .../normalize-under-binder/issue-62529-3.rs | 32 +++++ .../issue-62529-3.stderr | 15 +++ .../normalize-under-binder/issue-62529-4.rs | 39 ++++++ .../normalize-under-binder/issue-62529-5.rs | 27 +++++ .../normalize-under-binder/issue-62529-6.rs | 77 ++++++++++++ .../normalize-under-binder/issue-70120.rs | 29 +++++ .../normalize-under-binder/issue-70120.stderr | 20 +++ src/test/ui/hrtb/issue-62203-hrtb-ice.stderr | 6 +- .../bound-normalization-fail.stderr | 4 +- src/test/ui/issues/issue-35570.rs | 3 +- src/test/ui/issues/issue-35570.stderr | 9 ++ src/test/ui/issues/issue-43623.rs | 3 +- src/test/ui/issues/issue-43623.stderr | 21 ---- src/test/ui/issues/issue-44005.rs | 9 +- src/test/ui/issues/issue-44005.stderr | 20 +++ src/test/ui/issues/issue-57843.nll.stderr | 11 -- src/test/ui/issues/issue-60218.stderr | 4 +- .../issue-67039-unsound-pin-partialeq.stderr | 4 +- .../issue-75361-mismatched-impl.stderr | 4 +- ...ions-implied-bounds-projection-gap-hr-1.rs | 2 +- ...-implied-bounds-projection-gap-hr-1.stderr | 20 ++- 53 files changed, 716 insertions(+), 358 deletions(-) delete mode 100644 src/test/ui/associated-type-bounds/issue-83017.stderr delete mode 100644 src/test/ui/closures/issue-41366.stderr create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.stderr create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-2.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-4.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-5.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-6.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.rs create mode 100644 src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.stderr create mode 100644 src/test/ui/issues/issue-35570.stderr delete mode 100644 src/test/ui/issues/issue-43623.stderr create mode 100644 src/test/ui/issues/issue-44005.stderr delete mode 100644 src/test/ui/issues/issue-57843.nll.stderr diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 80c99872dd76..5342535ddfe7 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2474,10 +2474,9 @@ impl<'tcx> ty::Instance<'tcx> { // `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping // track of a polymorphization `ParamEnv` to allow normalizing later. let mut sig = match *ty.kind() { - ty::FnDef(def_id, substs) if tcx.sess.opts.debugging_opts.polymorphize => tcx + ty::FnDef(def_id, substs) => tcx .normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id)) .subst(tcx, substs), - ty::FnDef(def_id, substs) => tcx.fn_sig(def_id).subst(tcx, substs), _ => unreachable!(), }; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index f8989a7d9df1..ba3581355581 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -9,7 +9,9 @@ use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::mir::*; -use rustc_middle::ty::Ty; +use rustc_middle::traits::ObligationCause; +use rustc_middle::ty::{self, Ty}; +use rustc_trait_selection::traits::query::normalize::AtExt; use rustc_index::vec::Idx; use rustc_span::Span; @@ -80,6 +82,33 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let local = Local::new(argument_index + 1); let mir_input_ty = body.local_decls[local].ty; + // FIXME(jackh726): This is a hack. It's somewhat like + // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd + // like to normalize *before* inserting into `local_decls`, but I + // couldn't figure out where the heck that was. + let mir_input_ty = match self + .infcx + .at(&ObligationCause::dummy(), ty::ParamEnv::empty()) + .normalize(mir_input_ty) + { + Ok(n) => { + debug!("equate_inputs_and_outputs: {:?}", n); + if n.obligations.iter().all(|o| { + matches!( + o.predicate.kind().skip_binder(), + ty::PredicateKind::RegionOutlives(_) + ) + }) { + n.value + } else { + mir_input_ty + } + } + Err(_) => { + debug!("equate_inputs_and_outputs: NoSolution"); + mir_input_ty + } + }; let mir_input_span = body.local_decls[local].source_info.span; self.equate_normalized_input_or_output( normalized_input_ty, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 35bb6ef6c2d6..999b25319bf8 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -1053,6 +1053,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); for user_annotation in self.user_type_annotations { let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation; + let inferred_ty = self.normalize(inferred_ty, Locations::All(span)); let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty); match annotation { UserType::Ty(mut ty) => { diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 19e3c1afb9fb..df1dca9831ab 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -362,25 +362,25 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { if !needs_normalization(&ty, self.param_env.reveal()) { return ty; } - // We don't want to normalize associated types that occur inside of region - // binders, because they may contain bound regions, and we can't cope with that. - // - // Example: - // - // for<'a> fn(>::A) - // - // Instead of normalizing `>::A` here, we'll - // normalize it when we instantiate those bound regions (which - // should occur eventually). - - let ty = ty.super_fold_with(self); + + // N.b. while we want to call `super_fold_with(self)` on `ty` before + // normalization, we wait until we know whether we need to normalize the + // current type. If we do, then we only fold the ty *after* replacing bound + // vars with placeholders. This means that nested types don't need to replace + // bound vars at the current binder level or above. A key assumption here is + // that folding the type can't introduce new bound vars. + match *ty.kind() { - ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { + ty::Opaque(def_id, substs) => { // Only normalize `impl Trait` after type-checking, usually in codegen. match self.param_env.reveal() { - Reveal::UserFacing => ty, + Reveal::UserFacing => ty.super_fold_with(self), Reveal::All => { + // N.b. there is an assumption here all this code can handle + // escaping bound vars. + + let substs = substs.super_fold_with(self); let recursion_limit = self.tcx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { let obligation = Obligation::with_depth( @@ -403,18 +403,13 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { } ty::Projection(data) if !data.has_escaping_bound_vars() => { - // This is kind of hacky -- we need to be able to - // handle normalization within binders because - // otherwise we wind up a need to normalize when doing - // trait matching (since you can have a trait - // obligation like `for<'a> T::B: Fn(&'a i32)`), but - // we can't normalize with bound regions in scope. So - // far now we just ignore binders but only normalize - // if all bound regions are gone (and then we still - // have to renormalize whenever we instantiate a - // binder). It would be better to normalize in a - // binding-aware fashion. + // This branch is *mostly* just an optimization: when we don't + // have escaping bound vars, we don't need to replace them with + // placeholders (see branch below). *Also*, we know that we can + // register an obligation to *later* project, since we know + // there won't be bound vars there. + let data = data.super_fold_with(self); let normalized_ty = normalize_projection_type( self.selcx, self.param_env, @@ -433,22 +428,19 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { normalized_ty } - ty::Projection(data) if !data.trait_ref(self.tcx()).has_escaping_bound_vars() => { - // Okay, so you thought the previous branch was hacky. Well, to - // extend upon this, when the *trait ref* doesn't have escaping - // bound vars, but the associated item *does* (can only occur - // with GATs), then we might still be able to project the type. - // For this, we temporarily replace the bound vars with - // placeholders. Note though, that in the case that we still - // can't project for whatever reason (e.g. self type isn't - // known enough), we *can't* register an obligation and return - // an inference variable (since then that obligation would have - // bound vars and that's a can of worms). Instead, we just - // give up and fall back to pretending like we never tried! + ty::Projection(data) => { + // If there are escaping bound vars, we temporarily replace the + // bound vars with placeholders. Note though, that in the cas + // that we still can't project for whatever reason (e.g. self + // type isn't known enough), we *can't* register an obligation + // and return an inference variable (since then that obligation + // would have bound vars and that's a can of worms). Instead, + // we just give up and fall back to pretending like we never tried! let infcx = self.selcx.infcx(); let (data, mapped_regions, mapped_types, mapped_consts) = BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, data); + let data = data.super_fold_with(self); let normalized_ty = opt_normalize_projection_type( self.selcx, self.param_env, @@ -459,7 +451,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { ) .ok() .flatten() - .unwrap_or_else(|| ty); + .unwrap_or_else(|| ty.super_fold_with(self)); let normalized_ty = PlaceholderReplacer::replace_placeholders( infcx, @@ -479,7 +471,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { normalized_ty } - _ => ty, + _ => ty.super_fold_with(self), } } @@ -908,6 +900,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>( // an impl, where-clause etc) and hence we must // re-normalize it + let projected_ty = selcx.infcx().resolve_vars_if_possible(projected_ty); debug!(?projected_ty, ?depth, ?projected_obligations); let result = if projected_ty.has_projections() { diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 3f6efa03b3a2..8f8de24981b8 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -14,7 +14,9 @@ use rustc_infer::traits::Normalized; use rustc_middle::mir; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; use rustc_middle::ty::subst::Subst; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; + +use std::ops::ControlFlow; use super::NoSolution; @@ -65,6 +67,14 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { universes: vec![], }; + if value.has_escaping_bound_vars() { + let mut max_visitor = + MaxEscapingBoundVarVisitor { outer_index: ty::INNERMOST, escaping: 0 }; + value.visit_with(&mut max_visitor); + if max_visitor.escaping > 0 { + normalizer.universes.extend((0..max_visitor.escaping).map(|_| None)); + } + } let result = value.fold_with(&mut normalizer); info!( "normalize::<{}>: result={:?} with {} obligations", @@ -85,6 +95,58 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { } } +/// Visitor to find the maximum escaping bound var +struct MaxEscapingBoundVarVisitor { + // The index which would count as escaping + outer_index: ty::DebruijnIndex, + escaping: usize, +} + +impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor { + fn visit_binder>( + &mut self, + t: &ty::Binder<'tcx, T>, + ) -> ControlFlow { + self.outer_index.shift_in(1); + let result = t.super_visit_with(self); + self.outer_index.shift_out(1); + result + } + + #[inline] + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { + if t.outer_exclusive_binder() > self.outer_index { + self.escaping = self + .escaping + .max(t.outer_exclusive_binder().as_usize() - self.outer_index.as_usize()); + } + ControlFlow::CONTINUE + } + + #[inline] + fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { + match *r { + ty::ReLateBound(debruijn, _) if debruijn > self.outer_index => { + self.escaping = + self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize()); + } + _ => {} + } + ControlFlow::CONTINUE + } + + fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> ControlFlow { + match ct.val { + ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => { + self.escaping = + self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize()); + ControlFlow::CONTINUE + } + _ => ct.super_visit_with(self), + } + } +} + struct QueryNormalizer<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, cause: &'cx ObligationCause<'tcx>, @@ -121,14 +183,25 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { return ty; } - let ty = ty.super_fold_with(self); + // N.b. while we want to call `super_fold_with(self)` on `ty` before + // normalization, we wait until we know whether we need to normalize the + // current type. If we do, then we only fold the ty *after* replacing bound + // vars with placeholders. This means that nested types don't need to replace + // bound vars at the current binder level or above. A key assumption here is + // that folding the type can't introduce new bound vars. + + // Wrap this in a closure so we don't accidentally return from the outer function let res = (|| match *ty.kind() { - ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { + ty::Opaque(def_id, substs) => { // Only normalize `impl Trait` after type-checking, usually in codegen. match self.param_env.reveal() { - Reveal::UserFacing => ty, + Reveal::UserFacing => ty.super_fold_with(self), Reveal::All => { + // N.b. there is an assumption here all this code can handle + // escaping bound vars. + + let substs = substs.super_fold_with(self); let recursion_limit = self.tcx().recursion_limit(); if !recursion_limit.value_within_limit(self.anon_depth) { let obligation = Obligation::with_depth( @@ -161,19 +234,11 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } ty::Projection(data) if !data.has_escaping_bound_vars() => { - // This is kind of hacky -- we need to be able to - // handle normalization within binders because - // otherwise we wind up a need to normalize when doing - // trait matching (since you can have a trait - // obligation like `for<'a> T::B: Fn(&'a i32)`), but - // we can't normalize with bound regions in scope. So - // far now we just ignore binders but only normalize - // if all bound regions are gone (and then we still - // have to renormalize whenever we instantiate a - // binder). It would be better to normalize in a - // binding-aware fashion. + // This branch is just an optimization: when we don't have escaping bound vars, + // we don't need to replace them with placeholders (see branch below). let tcx = self.infcx.tcx; + let data = data.super_fold_with(self); let mut orig_values = OriginalQueryValues::default(); // HACK(matthewjasper) `'static` is special-cased in selection, @@ -217,22 +282,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } } } - ty::Projection(data) if !data.trait_ref(self.infcx.tcx).has_escaping_bound_vars() => { - // See note in `rustc_trait_selection::traits::project` - - // One other point mentioning: In `traits::project`, if a - // projection can't be normalized, we return an inference variable - // and register an obligation to later resolve that. Here, the query - // will just return ambiguity. In both cases, the effect is the same: we only want - // to return `ty` because there are bound vars that we aren't yet handling in a more - // complete way. - // `BoundVarReplacer` can't handle escaping bound vars. Ideally, we want this before even calling - // `QueryNormalizer`, but some const-generics tests pass escaping bound vars. - // Also, use `ty` so we get that sweet `outer_exclusive_binder` optimization - assert!(!ty.has_vars_bound_at_or_above(ty::DebruijnIndex::from_usize( - self.universes.len() - ))); + ty::Projection(data) => { + // See note in `rustc_trait_selection::traits::project` let tcx = self.infcx.tcx; let infcx = self.infcx; @@ -292,7 +344,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { ) } - _ => ty, + _ => ty.super_fold_with(self), })(); self.cache.insert(ty, res); res diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 17a81486048e..3bfab9d513f3 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -796,6 +796,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { //! into a closure or a `proc`. let b = self.shallow_resolve(b); + let InferOk { value: b, mut obligations } = + self.normalize_associated_types_in_as_infer_ok(self.cause.span, b); debug!("coerce_from_fn_item(a={:?}, b={:?})", a, b); match b.kind() { @@ -815,8 +817,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } } - let InferOk { value: a_sig, mut obligations } = + let InferOk { value: a_sig, obligations: o1 } = self.normalize_associated_types_in_as_infer_ok(self.cause.span, a_sig); + obligations.extend(o1); let a_fn_pointer = self.tcx.mk_fn_ptr(a_sig); let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn( diff --git a/src/test/ui/associated-type-bounds/issue-83017.rs b/src/test/ui/associated-type-bounds/issue-83017.rs index 8f0a9ea3566f..a02208661f1f 100644 --- a/src/test/ui/associated-type-bounds/issue-83017.rs +++ b/src/test/ui/associated-type-bounds/issue-83017.rs @@ -1,3 +1,5 @@ +// check-pass + #![feature(associated_type_bounds)] trait TraitA<'a> { @@ -34,6 +36,4 @@ where fn main() { foo::(); - //~^ ERROR: the trait bound `for<'a, 'b> >::AsA: TraitB<'a, 'b>` is not satisfied - //~| ERROR: the trait bound `for<'a, 'b, 'c> <>::AsA as TraitB<'a, 'b>>::AsB: TraitC<'a, 'b, 'c>` is not satisfied } diff --git a/src/test/ui/associated-type-bounds/issue-83017.stderr b/src/test/ui/associated-type-bounds/issue-83017.stderr deleted file mode 100644 index af86990ac66a..000000000000 --- a/src/test/ui/associated-type-bounds/issue-83017.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0277]: the trait bound `for<'a, 'b> >::AsA: TraitB<'a, 'b>` is not satisfied - --> $DIR/issue-83017.rs:36:5 - | -LL | foo::(); - | ^^^^^^^^ the trait `for<'a, 'b> TraitB<'a, 'b>` is not implemented for `>::AsA` - | -note: required by a bound in `foo` - --> $DIR/issue-83017.rs:31:32 - | -LL | fn foo() - | --- required by a bound in this -LL | where -LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo` - -error[E0277]: the trait bound `for<'a, 'b, 'c> <>::AsA as TraitB<'a, 'b>>::AsB: TraitC<'a, 'b, 'c>` is not satisfied - --> $DIR/issue-83017.rs:36:5 - | -LL | foo::(); - | ^^^^^^^^ the trait `for<'a, 'b, 'c> TraitC<'a, 'b, 'c>` is not implemented for `<>::AsA as TraitB<'a, 'b>>::AsB` - | -note: required by a bound in `foo` - --> $DIR/issue-83017.rs:31:60 - | -LL | fn foo() - | --- required by a bound in this -LL | where -LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/associated-types/higher-ranked-projection.bad.stderr b/src/test/ui/associated-types/higher-ranked-projection.bad.stderr index e2847b6b72b8..1ac72e4b90c7 100644 --- a/src/test/ui/associated-types/higher-ranked-projection.bad.stderr +++ b/src/test/ui/associated-types/higher-ranked-projection.bad.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types LL | foo(()); | ^^^ lifetime mismatch | - = note: expected type `&'a ()` - found type `&()` + = note: expected reference `&'a ()` + found type `&()` note: the lifetime requirement is introduced here --> $DIR/higher-ranked-projection.rs:15:33 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-1.rs b/src/test/ui/associated-types/hr-associated-type-bound-1.rs index cdf32dd82a6a..db414164e166 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-1.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-1.rs @@ -10,7 +10,7 @@ where impl X<'_> for i32 { type U = str; - //~^ ERROR the trait bound `for<'b> >::U: Clone` + //~^ ERROR the trait bound `str: Clone` } fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-1.stderr b/src/test/ui/associated-types/hr-associated-type-bound-1.stderr index 0bcc9be5c43c..4eed5c9a0083 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-1.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-1.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> >::U: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-1.rs:12:14 | LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `>::U` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `X` --> $DIR/hr-associated-type-bound-1.rs:3:33 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-2.rs b/src/test/ui/associated-types/hr-associated-type-bound-2.rs index 78ee28b17d4b..2eb956c8dbb0 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-2.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-2.rs @@ -8,14 +8,13 @@ where } } -impl X<'_> for u32 +impl X<'_> for u32 //~ overflow evaluating the requirement `for<'b> u32: X<'b>` where for<'b> >::U: Clone, { - type U = str; + type U = str; //~ overflow evaluating the requirement `for<'b> u32: X<'b>` } fn main() { 1u32.f("abc"); - //~^ ERROR the method } diff --git a/src/test/ui/associated-types/hr-associated-type-bound-2.stderr b/src/test/ui/associated-types/hr-associated-type-bound-2.stderr index 043d1ac76de9..079989f2331a 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-2.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-2.stderr @@ -1,13 +1,38 @@ -error[E0599]: the method `f` exists for type `u32`, but its trait bounds were not satisfied - --> $DIR/hr-associated-type-bound-2.rs:19:10 +error[E0275]: overflow evaluating the requirement `for<'b> u32: X<'b>` + --> $DIR/hr-associated-type-bound-2.rs:11:1 | -LL | 1u32.f("abc"); - | ^ method cannot be called on `u32` due to unsatisfied trait bounds +LL | / impl X<'_> for u32 +LL | | where +LL | | for<'b> >::U: Clone, +LL | | { +LL | | type U = str; +LL | | } + | |_^ | - = note: the following trait bounds were not satisfied: - `>::U: Clone` - which is required by `u32: X` + = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`hr_associated_type_bound_2`) +note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32` + --> $DIR/hr-associated-type-bound-2.rs:11:6 + | +LL | impl X<'_> for u32 + | ^^^^^ ^^^ + = note: 128 redundant requirements hidden + = note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32` + +error[E0275]: overflow evaluating the requirement `for<'b> u32: X<'b>` + --> $DIR/hr-associated-type-bound-2.rs:15:5 + | +LL | type U = str; + | ^^^^^^^^^^^^^ + | + = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`hr_associated_type_bound_2`) +note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32` + --> $DIR/hr-associated-type-bound-2.rs:11:6 + | +LL | impl X<'_> for u32 + | ^^^^^ ^^^ + = note: 128 redundant requirements hidden + = note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32` -error: aborting due to previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0599`. +For more information about this error, try `rustc --explain E0275`. diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-1.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-1.rs index 0a81f373ad4c..bbeeb145d1fe 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-1.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-1.rs @@ -12,7 +12,7 @@ where impl<'a> Y<'a, u8> for u8 { type V = str; - //~^ ERROR the trait bound `for<'b> >::V: Clone` is not satisfied + //~^ ERROR the trait bound `str: Clone` is not satisfied } fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-1.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-1.stderr index e16931ee09fc..99f95c200511 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-1.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-1.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> >::V: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-1.rs:14:14 | LL | type V = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `>::V` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `Y` --> $DIR/hr-associated-type-bound-param-1.rs:4:36 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-2.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-2.rs index a04144ba06b6..5193400882d1 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-2.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-2.rs @@ -2,8 +2,8 @@ trait Z<'a, T: ?Sized> where T: Z<'a, u16>, - //~^ the trait bound `for<'b> >::W: Clone` is not satisfied - //~| the trait bound `for<'b> >::W: Clone` is not satisfied + //~^ the trait bound `str: Clone` is not satisfied + //~| the trait bound `str: Clone` is not satisfied for<'b> >::W: Clone, { type W: ?Sized; @@ -14,7 +14,7 @@ where impl<'a> Z<'a, u16> for u16 { type W = str; - //~^ ERROR the trait bound `for<'b> >::W: Clone + //~^ ERROR the trait bound `str: Clone } fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-2.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-2.stderr index 0c9f2a3978cd..730229b5208d 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-2.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-2.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> >::W: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-2.rs:4:8 | LL | T: Z<'a, u16>, - | ^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `>::W` + | ^^^^^^^^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `Z` --> $DIR/hr-associated-type-bound-param-2.rs:7:35 | @@ -15,14 +13,12 @@ LL | trait Z<'a, T: ?Sized> LL | for<'b> >::W: Clone, | ^^^^^ required by this bound in `Z` -error[E0277]: the trait bound `for<'b> >::W: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-2.rs:4:8 | LL | T: Z<'a, u16>, - | ^^^^^^^^^^ the trait `for<'b> Clone` is not implemented for `>::W` + | ^^^^^^^^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `Z` --> $DIR/hr-associated-type-bound-param-2.rs:7:35 | @@ -32,14 +28,12 @@ LL | trait Z<'a, T: ?Sized> LL | for<'b> >::W: Clone, | ^^^^^ required by this bound in `Z` -error[E0277]: the trait bound `for<'b> >::W: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-2.rs:16:14 | LL | type W = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `>::W` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `Z` --> $DIR/hr-associated-type-bound-param-2.rs:7:35 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-3.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-3.rs index 1af63bf9070a..fda7d8111856 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-3.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-3.rs @@ -11,7 +11,7 @@ where impl X<'_, (T,)> for (S,) { type U = str; - //~^ ERROR the trait bound `for<'b> <(T,) as X<'b, (T,)>>::U: Clone` is not satisfied + //~^ ERROR the trait bound `str: Clone` is not satisfied } pub fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-3.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-3.stderr index b1bc1dfbb112..9935445c3065 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-3.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-3.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> <(T,) as X<'b, (T,)>>::U: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-3.rs:13:14 | LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `<(T,) as X<'b, (T,)>>::U` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `X` --> $DIR/hr-associated-type-bound-param-3.rs:4:33 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-4.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-4.rs index 6f06b925bd2e..20c8157ed974 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-4.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-4.rs @@ -11,7 +11,7 @@ where impl X<'_, T> for (S,) { type U = str; - //~^ ERROR the trait bound `for<'b> <(T,) as X<'b, T>>::U: Clone` is not satisfied + //~^ ERROR the trait bound `str: Clone` is not satisfied } pub fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-4.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-4.stderr index 0bd404f8a41b..c26324ee6255 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-4.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-4.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> <(T,) as X<'b, T>>::U: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-4.rs:13:14 | LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `<(T,) as X<'b, T>>::U` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `X` --> $DIR/hr-associated-type-bound-param-4.rs:4:36 | diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-5.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-5.rs index fc3a85171e27..920aa8352807 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-5.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-5.rs @@ -25,14 +25,12 @@ where impl X<'_, Vec> for S { type U = str; - //~^ ERROR the trait bound `for<'b> as X<'b, Box>>::U: Clone` is not satisfied - //~| ERROR the trait bound `for<'b> as X<'b, Vec>>::U: Clone` is not satisfied + //~^ ERROR the trait bound `str: Clone` is not satisfied } impl X<'_, Box> for S { type U = str; - //~^ ERROR the trait bound `for<'b> as X<'b, Box>>::U: Clone` is not satisfied - //~| ERROR the trait bound `for<'b> as X<'b, Vec>>::U: Clone` is not satisfied + //~^ ERROR the trait bound `str: Clone` is not satisfied } pub fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-5.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-5.stderr index 59c0a7268cc8..63cd89316b38 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-5.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-5.stderr @@ -1,11 +1,9 @@ -error[E0277]: the trait bound `for<'b> as X<'b, Box>>::U: Clone` is not satisfied +error[E0277]: the trait bound `str: Clone` is not satisfied --> $DIR/hr-associated-type-bound-param-5.rs:27:14 | LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for ` as X<'b, Box>>::U` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `X` --> $DIR/hr-associated-type-bound-param-5.rs:18:45 | @@ -15,31 +13,12 @@ LL | trait X<'a, T: Cycle + for<'b> X<'b, T>> LL | for<'b> >::U: Clone, | ^^^^^ required by this bound in `X` -error[E0277]: the trait bound `for<'b> as X<'b, Vec>>::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-5.rs:27:14 - | -LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for ` as X<'b, Vec>>::U` - | - = help: the following implementations were found: - <&T as Clone> -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-param-5.rs:16:33 - | -LL | trait X<'a, T: Cycle + for<'b> X<'b, T>> - | - required by a bound in this -LL | where -LL | for<'b> >::U: Clone, - | ^^^^^ required by this bound in `X` - -error[E0277]: the trait bound `for<'b> as X<'b, Vec>>::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-5.rs:33:14 +error[E0277]: the trait bound `str: Clone` is not satisfied + --> $DIR/hr-associated-type-bound-param-5.rs:32:14 | LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for ` as X<'b, Vec>>::U` + | ^^^ the trait `Clone` is not implemented for `str` | - = help: the following implementations were found: - <&T as Clone> note: required by a bound in `X` --> $DIR/hr-associated-type-bound-param-5.rs:18:45 | @@ -49,23 +28,6 @@ LL | trait X<'a, T: Cycle + for<'b> X<'b, T>> LL | for<'b> >::U: Clone, | ^^^^^ required by this bound in `X` -error[E0277]: the trait bound `for<'b> as X<'b, Box>>::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-5.rs:33:14 - | -LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for ` as X<'b, Box>>::U` - | - = help: the following implementations were found: - <&T as Clone> -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-param-5.rs:16:33 - | -LL | trait X<'a, T: Cycle + for<'b> X<'b, T>> - | - required by a bound in this -LL | where -LL | for<'b> >::U: Clone, - | ^^^^^ required by this bound in `X` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-6.rs b/src/test/ui/associated-types/hr-associated-type-bound-param-6.rs index 04b88c7f4fcb..482047b09592 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-6.rs +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-6.rs @@ -12,7 +12,6 @@ where impl X<'_, T> for (S,) { //~^ ERROR the trait bound `for<'b> T: X<'b, T>` is not satisfied type U = str; - //~^ ERROR the trait bound `for<'b> >::U: Clone` is not satisfied } pub fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-bound-param-6.stderr b/src/test/ui/associated-types/hr-associated-type-bound-param-6.stderr index bce5737af1bb..bd6e627a3d0d 100644 --- a/src/test/ui/associated-types/hr-associated-type-bound-param-6.stderr +++ b/src/test/ui/associated-types/hr-associated-type-bound-param-6.stderr @@ -1,39 +1,14 @@ -error[E0277]: the trait bound `for<'b> >::U: Clone` is not satisfied - --> $DIR/hr-associated-type-bound-param-6.rs:14:14 - | -LL | type U = str; - | ^^^ the trait `for<'b> Clone` is not implemented for `>::U` - | - = help: the following implementations were found: - <&T as Clone> -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-param-6.rs:4:33 - | -LL | trait X<'a, T> - | - required by a bound in this -... -LL | for<'b> >::U: Clone, - | ^^^^^ required by this bound in `X` - error[E0277]: the trait bound `for<'b> T: X<'b, T>` is not satisfied --> $DIR/hr-associated-type-bound-param-6.rs:12:12 | LL | impl X<'_, T> for (S,) { | ^^^^^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T` | -note: required by a bound in `X` - --> $DIR/hr-associated-type-bound-param-6.rs:3:16 - | -LL | trait X<'a, T> - | - required by a bound in this -LL | where -LL | for<'b> T: X<'b, T>, - | ^^^^^^^^ required by this bound in `X` help: consider restricting type parameter `T` | LL | impl X<'b, T>> X<'_, T> for (S,) { | ++++++++++++++++++ -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/associated-types/hr-associated-type-projection-1.rs b/src/test/ui/associated-types/hr-associated-type-projection-1.rs index bad736b64c03..951dd9e97d26 100644 --- a/src/test/ui/associated-types/hr-associated-type-projection-1.rs +++ b/src/test/ui/associated-types/hr-associated-type-projection-1.rs @@ -11,9 +11,8 @@ where } impl UnsafeCopy<'_, T> for T { - //~^ ERROR the trait bound `for<'b> >::Item: Deref` is not satisfied + //~^ type mismatch resolving `::Target == T` type Item = T; - //~^ ERROR the trait bound `for<'b> >::Item: Deref } pub fn main() { diff --git a/src/test/ui/associated-types/hr-associated-type-projection-1.stderr b/src/test/ui/associated-types/hr-associated-type-projection-1.stderr index 20d7a206754e..9c29e969de8d 100644 --- a/src/test/ui/associated-types/hr-associated-type-projection-1.stderr +++ b/src/test/ui/associated-types/hr-associated-type-projection-1.stderr @@ -1,32 +1,16 @@ -error[E0277]: the trait bound `for<'b> >::Item: Deref` is not satisfied - --> $DIR/hr-associated-type-projection-1.rs:15:17 - | -LL | type Item = T; - | ^ the trait `for<'b> Deref` is not implemented for `>::Item` - | - = help: the following implementations were found: - <&T as Deref> - <&mut T as Deref> -note: required by a bound in `UnsafeCopy` - --> $DIR/hr-associated-type-projection-1.rs:3:48 - | -LL | trait UnsafeCopy<'a, T: Copy> - | ---------- required by a bound in this -LL | where -LL | for<'b> >::Item: std::ops::Deref, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `UnsafeCopy` - -error[E0277]: the trait bound `for<'b> >::Item: Deref` is not satisfied +error[E0271]: type mismatch resolving `::Target == T` --> $DIR/hr-associated-type-projection-1.rs:13:33 | LL | impl UnsafeCopy<'_, T> for T { - | ^^^^^^^^^^^^^^^^^ the trait `for<'b> Deref` is not implemented for `>::Item` + | - this type parameter ^^^^^^^^^^^^^^^^^ expected associated type, found type parameter `T` | -help: consider further restricting the associated type + = note: expected associated type `::Target` + found type parameter `T` +help: consider further restricting this bound | -LL | impl UnsafeCopy<'_, T> for T where for<'b> >::Item: Deref { - | +++++++++++++++++++++++++++++++++++++++++++++++++++ +LL | impl> UnsafeCopy<'_, T> for T { + | +++++++++++++++++++ -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/closures/issue-41366.rs b/src/test/ui/closures/issue-41366.rs index 909c33f642d3..acc1c6ae1225 100644 --- a/src/test/ui/closures/issue-41366.rs +++ b/src/test/ui/closures/issue-41366.rs @@ -1,3 +1,5 @@ +// check-pass + trait T<'x> { type V; } @@ -8,6 +10,4 @@ impl<'g> T<'g> for u32 { fn main() { (&|_| ()) as &dyn for<'x> Fn(>::V); - //~^ ERROR: type mismatch in closure arguments - //~| ERROR: size for values of type `>::V` cannot be known at compilation time } diff --git a/src/test/ui/closures/issue-41366.stderr b/src/test/ui/closures/issue-41366.stderr deleted file mode 100644 index 06477efac264..000000000000 --- a/src/test/ui/closures/issue-41366.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error[E0631]: type mismatch in closure arguments - --> $DIR/issue-41366.rs:10:5 - | -LL | (&|_| ()) as &dyn for<'x> Fn(>::V); - | ^^------^ - | | | - | | found signature of `fn(u16) -> _` - | expected signature of `for<'x> fn(>::V) -> _` - | - = note: required for the cast to the object type `dyn for<'x> Fn(>::V)` - -error[E0277]: the size for values of type `>::V` cannot be known at compilation time - --> $DIR/issue-41366.rs:10:8 - | -LL | (&|_| ()) as &dyn for<'x> Fn(>::V); - | ^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `>::V` - = help: unsized fn params are gated as an unstable feature -help: consider further restricting the associated type - | -LL | fn main() where >::V: Sized { - | ++++++++++++++++++++++++++++++ -help: function arguments must have a statically known size, borrowed types always have a known size - | -LL | (&|&_| ()) as &dyn for<'x> Fn(>::V); - | + - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0277, E0631. -For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.rs new file mode 100644 index 000000000000..24ac566f9df0 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.rs @@ -0,0 +1,88 @@ +// FamilyType (GAT workaround) +pub trait FamilyLt<'a> { + type Out; +} + +struct RefMutFamily(std::marker::PhantomData, ()); +impl<'a, T: 'a> FamilyLt<'a> for RefMutFamily { + type Out = &'a mut T; +} + +pub trait Execute { + type E: Inject; + fn execute(self, value: <::I as FamilyLt>::Out); +} + +pub trait Inject +where + Self: Sized, +{ + type I: for<'a> FamilyLt<'a>; + fn inject(_: &()) -> ::Out; +} + +impl Inject for RefMutFamily { + type I = Self; + fn inject(_: &()) -> ::Out { + unimplemented!() + } +} + +// This struct is only used to give a hint to the compiler about the type `Q` +struct Annotate(std::marker::PhantomData); +impl Annotate { + fn new() -> Self { + Self(std::marker::PhantomData) + } +} + +// This function annotate a closure so it can have Higher-Rank Lifetime Bounds +// +// See 'annotate' workaround: https://github.com/rust-lang/rust/issues/58052 +fn annotate(_q: Annotate, func: F) -> impl Execute + 'static +where + F: for<'r> FnOnce(<::I as FamilyLt<'r>>::Out) + 'static, + Q: Inject + 'static, +{ + let wrapper: Wrapper = Wrapper(std::marker::PhantomData, func); + wrapper +} + +struct Wrapper(std::marker::PhantomData, F); +impl Execute for Wrapper + where + Q: Inject, + F: for<'r> FnOnce(<::I as FamilyLt<'r>>::Out), +{ + type E = Q; + + fn execute(self, value: <::I as FamilyLt>::Out) { + (self.1)(value) + } +} + +struct Task { + _processor: Box, +} + +// This function consume the closure +fn task

(processor: P) -> Task +where P: Execute + 'static { + Task { + _processor: Box::new(move || { + let q = P::E::inject(&()); + processor.execute(q); + }) + } +} + +fn main() { + task(annotate( //~ type mismatch + //~^ the size + //~^^ the trait bound + Annotate::>::new(), + |value: &mut usize| { + *value = 2; + } + )); +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.stderr new file mode 100644 index 000000000000..8311c147ee3b --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-1.stderr @@ -0,0 +1,67 @@ +error[E0631]: type mismatch in closure arguments + --> $DIR/issue-62529-1.rs:80:10 + | +LL | task(annotate( + | ^^^^^^^^ expected signature of `for<'r> fn( as FamilyLt<'r>>::Out) -> _` +... +LL | |value: &mut usize| { + | ------------------- found signature of `for<'r> fn(&'r mut usize) -> _` + | +note: required by a bound in `annotate` + --> $DIR/issue-62529-1.rs:44:8 + | +LL | fn annotate(_q: Annotate, func: F) -> impl Execute + 'static + | -------- required by a bound in this +LL | where +LL | F: for<'r> FnOnce(<::I as FamilyLt<'r>>::Out) + 'static, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `annotate` + +error[E0277]: the size for values of type `impl Execute` cannot be known at compilation time + --> $DIR/issue-62529-1.rs:80:10 + | +LL | task(annotate( + | __________^ +LL | | +LL | | +LL | | Annotate::>::new(), +... | +LL | | } +LL | | )); + | |_____^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `impl Execute` +note: required by a bound in `task` + --> $DIR/issue-62529-1.rs:69:9 + | +LL | fn task

(processor: P) -> Task + | ^ required by this bound in `task` +help: consider relaxing the implicit `Sized` restriction + | +LL | fn task(processor: P) -> Task + | ++++++++ + +error[E0277]: the trait bound `impl Execute: Execute` is not satisfied + --> $DIR/issue-62529-1.rs:80:10 + | +LL | task(annotate( + | __________^ +LL | | +LL | | +LL | | Annotate::>::new(), +... | +LL | | } +LL | | )); + | |_____^ the trait `Execute` is not implemented for `impl Execute` + | +note: required by a bound in `task` + --> $DIR/issue-62529-1.rs:70:10 + | +LL | fn task

(processor: P) -> Task + | ---- required by a bound in this +LL | where P: Execute + 'static { + | ^^^^^^^ required by this bound in `task` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0631. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-2.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-2.rs new file mode 100644 index 000000000000..002054732919 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-2.rs @@ -0,0 +1,33 @@ +// check-pass + +use std::marker::PhantomData; + +trait Lt<'a> { + type T; +} +struct Id(PhantomData); +impl<'a,T> Lt<'a> for Id { + type T = T; +} + +struct Ref(PhantomData) where T: ?Sized; +impl<'a,T> Lt<'a> for Ref +where T: 'a + Lt<'a> + ?Sized +{ + type T = &'a T; +} +struct Mut(PhantomData) where T: ?Sized; +impl<'a,T> Lt<'a> for Mut +where T: 'a + Lt<'a> + ?Sized +{ + type T = &'a mut T; +} + +struct C(for<'a> fn(>::T) -> O) where I: for<'a> Lt<'a>; + + +fn main() { + let c = C::,_>(|()| 3); + c.0(()); + +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.rs new file mode 100644 index 000000000000..d84e30f4984e --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.rs @@ -0,0 +1,32 @@ +trait ATC<'a> { + type Type: Sized; +} + +trait WithDefault: for<'a> ATC<'a> { + fn with_default Fn(>::Type)>(f: F); +} + +fn call<'b, T: for<'a> ATC<'a>, F: for<'a> Fn(>::Type)>( + f: F, + x: >::Type, +) { + f(x); +} + +impl<'a> ATC<'a> for () { + type Type = Self; +} + +impl WithDefault for () { + fn with_default Fn(>::Type)>(f: F) { + // Errors with a bogus type mismatch. + //f(()); + // Going through another generic function works fine. + call(f, ()); + //~^ expected a + } +} + +fn main() { + // <()>::with_default(|_| {}); +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr new file mode 100644 index 000000000000..b11073464217 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr @@ -0,0 +1,15 @@ +error[E0277]: expected a `Fn<(<_ as ATC<'a>>::Type,)>` closure, found `F` + --> $DIR/issue-62529-3.rs:25:9 + | +LL | call(f, ()); + | ^^^^ expected an `Fn<(<_ as ATC<'a>>::Type,)>` closure, found `F` + | +note: required by a bound in `call` + --> $DIR/issue-62529-3.rs:9:36 + | +LL | fn call<'b, T: for<'a> ATC<'a>, F: for<'a> Fn(>::Type)>( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `call` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-4.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-4.rs new file mode 100644 index 000000000000..8c2a59868ca5 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-4.rs @@ -0,0 +1,39 @@ +// check-pass + +use std::marker::PhantomData; +use std::mem; + +trait Container<'a> { + type Root: 'a; +} + +type RootOf<'a, T> = >::Root; + +struct Test<'a, T> where T: Container<'a> { + pub root: T::Root, + marker: PhantomData<&'a mut &'a mut ()>, +} + +impl<'a, 'b> Container<'b> for &'a str { + type Root = &'b str; +} + +impl<'a, T> Test<'a, T> where T: for<'b> Container<'b> { + fn new(root: RootOf<'a, T>) -> Test<'a, T> { + Test { + root: root, + marker: PhantomData + } + } + + fn with_mut(&mut self, f: F) -> R where + F: for<'b> FnOnce(&'b mut RootOf<'b, T>) -> R { + f(unsafe { mem::transmute(&mut self.root) }) + } +} + +fn main() { + let val = "root"; + let mut test: Test<&str> = Test::new(val); + test.with_mut(|_| { }); +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-5.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-5.rs new file mode 100644 index 000000000000..03f257a029c1 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-5.rs @@ -0,0 +1,27 @@ +// check-pass + +pub struct Struct {} + +pub trait Trait<'a> { + type Assoc; + + fn method() -> Self::Assoc; +} + +impl<'a> Trait<'a> for Struct { + type Assoc = (); + + fn method() -> Self::Assoc {} +} + +pub fn function(f: F) +where + F: for<'a> FnOnce(>::Assoc), + T: for<'b> Trait<'b>, +{ + f(T::method()); +} + +fn main() { + function::<_, Struct>(|_| {}); +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-6.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-6.rs new file mode 100644 index 000000000000..74a4785e478b --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-6.rs @@ -0,0 +1,77 @@ +// check-pass + +use std::cell::RefMut; + +fn main() { + StateMachine2::Init.resume(); +} + +enum StateMachine2<'a> { + Init, + #[allow(dead_code)] // match required for ICE + AfterTwoYields { + p: Backed<'a, *mut String>, + }, +} + +impl<'a> StateMachine2<'a> { + fn take(&self) -> Self { + StateMachine2::Init + } +} + +impl<'a> StateMachine2<'a> { + fn resume(&mut self) -> () { + use StateMachine2::*; + match self.take() { + AfterTwoYields { p } => { + p.with(|_| {}); + } + _ => panic!("Resume after completed."), + } + } +} + +unsafe trait Unpack<'a> { + type Unpacked: 'a; + + fn unpack(&self) -> Self::Unpacked { + unsafe { std::mem::transmute_copy(&self) } + } +} + +unsafe trait Pack { + type Packed; + + fn pack(&self) -> Self::Packed { + unsafe { std::mem::transmute_copy(&self) } + } +} + +unsafe impl<'a> Unpack<'a> for String { + type Unpacked = String; +} + +unsafe impl Pack for String { + type Packed = String; +} + +unsafe impl<'a> Unpack<'a> for *mut String { + type Unpacked = &'a mut String; +} + +unsafe impl<'a> Pack for &'a mut String { + type Packed = *mut String; +} + +struct Backed<'a, U>(RefMut<'a, Option>, U); + +impl<'a, 'b, U: Unpack<'b>> Backed<'a, U> { + fn with(self, f: F) -> Backed<'a, ()> + where + F: for<'f> FnOnce(>::Unpacked) -> (), + { + let result = f(self.1.unpack()); + Backed(self.0, result) + } +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.rs new file mode 100644 index 000000000000..87d1a250f7ae --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.rs @@ -0,0 +1,29 @@ +pub trait MyTrait<'a> { + type Output: 'a; + fn gimme_value(&self) -> Self::Output; +} + +pub struct MyStruct; + +impl<'a> MyTrait<'a> for MyStruct { + type Output = &'a usize; + fn gimme_value(&self) -> Self::Output { + unimplemented!() + } +} + +fn meow(t: T, f: F) +where + T: for<'any> MyTrait<'any>, + F: for<'any2> Fn(>::Output), +{ + let v = t.gimme_value(); + f(v); +} + +fn main() { + let struc = MyStruct; + meow(struc, |foo| { //~ type mismatch + println!("{:?}", foo); + }) +} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.stderr new file mode 100644 index 000000000000..efc956888ee5 --- /dev/null +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-70120.stderr @@ -0,0 +1,20 @@ +error[E0631]: type mismatch in closure arguments + --> $DIR/issue-70120.rs:26:5 + | +LL | meow(struc, |foo| { + | ^^^^ ----- found signature of `for<'r> fn(&'r usize) -> _` + | | + | expected signature of `for<'any2> fn(>::Output) -> _` + | +note: required by a bound in `meow` + --> $DIR/issue-70120.rs:18:8 + | +LL | fn meow(t: T, f: F) + | ---- required by a bound in this +... +LL | F: for<'any2> Fn(>::Output), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `meow` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr index 7b81beeed416..97f53bc70e44 100644 --- a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` +error[E0271]: type mismatch resolving `for<'r> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V` --> $DIR/issue-62203-hrtb-ice.rs:38:19 | LL | let v = Unit2.m( @@ -9,13 +9,13 @@ LL | let v = Unit2.m( = help: consider constraining the associated type `<_ as Ty<'_>>::V` to `Unit4` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html -error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&u8,),)>>::Output == Unit3` +error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&'r u8,),)>>::Output == Unit3` --> $DIR/issue-62203-hrtb-ice.rs:38:19 | LL | let v = Unit2.m( | ^ expected struct `Unit4`, found struct `Unit3` | -note: required because of the requirements on the impl of `for<'r> T0<'r, (>::V,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>` +note: required because of the requirements on the impl of `for<'r> T0<'r, (&'r u8,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>` --> $DIR/issue-62203-hrtb-ice.rs:17:16 | LL | impl<'a, A, T> T0<'a, A> for L diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr index bf04a8c98739..3c720f50d48b 100644 --- a/src/test/ui/impl-trait/bound-normalization-fail.stderr +++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr @@ -5,7 +5,7 @@ LL | fn foo_fail() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` | = note: expected associated type `::Assoc` - found type `()` + found unit type `()` help: consider constraining the associated type `::Assoc` to `()` | LL | fn foo_fail>() -> impl FooLike { @@ -24,7 +24,7 @@ LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` | = note: expected associated type `>::Assoc` - found type `()` + found unit type `()` help: consider constraining the associated type `>::Assoc` to `()` | LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike { diff --git a/src/test/ui/issues/issue-35570.rs b/src/test/ui/issues/issue-35570.rs index fafef79ea5b8..42cef9a47f27 100644 --- a/src/test/ui/issues/issue-35570.rs +++ b/src/test/ui/issues/issue-35570.rs @@ -1,5 +1,3 @@ -// check-pass - use std::mem; trait Trait1 {} @@ -8,6 +6,7 @@ trait Trait2<'a> { } fn _ice(param: Box Trait1<<() as Trait2<'a>>::Ty>>) { +//~^ the trait bound `for<'a> (): Trait2<'a>` is not satisfied let _e: (usize, usize) = unsafe{mem::transmute(param)}; } diff --git a/src/test/ui/issues/issue-35570.stderr b/src/test/ui/issues/issue-35570.stderr new file mode 100644 index 000000000000..dda6145e65ad --- /dev/null +++ b/src/test/ui/issues/issue-35570.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied + --> $DIR/issue-35570.rs:8:4 + | +LL | fn _ice(param: Box Trait1<<() as Trait2<'a>>::Ty>>) { + | ^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-43623.rs b/src/test/ui/issues/issue-43623.rs index 99cae46fd9cf..cedcf7c361c3 100644 --- a/src/test/ui/issues/issue-43623.rs +++ b/src/test/ui/issues/issue-43623.rs @@ -1,3 +1,5 @@ +// check-pass + pub trait Trait<'a> { type Assoc; } @@ -14,7 +16,6 @@ where F: for<'b> FnMut(>::Assoc), { break_me::; - //~^ ERROR: type mismatch in function arguments } fn main() {} diff --git a/src/test/ui/issues/issue-43623.stderr b/src/test/ui/issues/issue-43623.stderr deleted file mode 100644 index b99f367d7336..000000000000 --- a/src/test/ui/issues/issue-43623.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0631]: type mismatch in function arguments - --> $DIR/issue-43623.rs:16:5 - | -LL | break_me::; - | ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected signature of `for<'b> fn(>::Assoc) -> _` - | found signature of `fn(()) -> _` - | -note: required by a bound in `break_me` - --> $DIR/issue-43623.rs:14:16 - | -LL | pub fn break_me(f: F) - | -------- required by a bound in this -... -LL | F: for<'b> FnMut(>::Assoc), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `break_me` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/issues/issue-44005.rs b/src/test/ui/issues/issue-44005.rs index 041fcdbf823b..ab3b92142c8c 100644 --- a/src/test/ui/issues/issue-44005.rs +++ b/src/test/ui/issues/issue-44005.rs @@ -1,4 +1,3 @@ -// build-pass pub trait Foo<'a> { type Bar; fn foo(&'a self) -> Self::Bar; @@ -12,8 +11,9 @@ impl<'a, 'b, T: 'a> Foo<'a> for &'b T { } pub fn uncallable(x: T, f: F) - where T: for<'a> Foo<'a>, - F: for<'a> Fn(>::Bar) +where + T: for<'a> Foo<'a>, + F: for<'a> Fn(>::Bar), { f(x.foo()); } @@ -24,6 +24,7 @@ pub fn catalyst(x: &i32) { pub fn broken(x: &i32, f: F) { uncallable(x, |y| f(y)); + //~^ type mismatch } -fn main() { } +fn main() {} diff --git a/src/test/ui/issues/issue-44005.stderr b/src/test/ui/issues/issue-44005.stderr new file mode 100644 index 000000000000..307e444e6963 --- /dev/null +++ b/src/test/ui/issues/issue-44005.stderr @@ -0,0 +1,20 @@ +error[E0631]: type mismatch in closure arguments + --> $DIR/issue-44005.rs:26:5 + | +LL | uncallable(x, |y| f(y)); + | ^^^^^^^^^^ -------- found signature of `for<'r> fn(&'r i32) -> _` + | | + | expected signature of `for<'a> fn(<&i32 as Foo<'a>>::Bar) -> _` + | +note: required by a bound in `uncallable` + --> $DIR/issue-44005.rs:16:8 + | +LL | pub fn uncallable(x: T, f: F) + | ---------- required by a bound in this +... +LL | F: for<'a> Fn(>::Bar), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `uncallable` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0631`. diff --git a/src/test/ui/issues/issue-57843.nll.stderr b/src/test/ui/issues/issue-57843.nll.stderr deleted file mode 100644 index 2ab49ec61cf5..000000000000 --- a/src/test/ui/issues/issue-57843.nll.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: implementation of `FnOnce` is not general enough - --> $DIR/issue-57843.rs:25:9 - | -LL | Foo(Box::new(|_| ())); - | ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough - | - = note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`... - = note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2` - -error: aborting due to previous error - diff --git a/src/test/ui/issues/issue-60218.stderr b/src/test/ui/issues/issue-60218.stderr index a16363d7c873..ac33cfd04024 100644 --- a/src/test/ui/issues/issue-60218.stderr +++ b/src/test/ui/issues/issue-60218.stderr @@ -1,8 +1,8 @@ -error[E0277]: the trait bound `for<'t> ::IntoIter, _> as Iterator>::Item: Foo` is not satisfied +error[E0277]: the trait bound `&u32: Foo` is not satisfied --> $DIR/issue-60218.rs:18:5 | LL | trigger_error(vec![], |x: &u32| x) - | ^^^^^^^^^^^^^ the trait `for<'t> Foo` is not implemented for `::IntoIter, _> as Iterator>::Item` + | ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `&u32` | note: required by a bound in `trigger_error` --> $DIR/issue-60218.rs:13:72 diff --git a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr index 036a9300a174..733456a1a8bd 100644 --- a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr +++ b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr @@ -4,8 +4,8 @@ error[E0271]: type mismatch resolving ` as Deref>::Target == Rc LL | let _ = Pin::new(Apple) == Rc::pin(Apple); | ^^ expected struct `Apple`, found struct `Rc` | - = note: expected type `Apple` - found struct `Rc` + = note: expected struct `Apple` + found struct `Rc` = note: required because of the requirements on the impl of `PartialEq>>` for `Pin` error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/issue-75361-mismatched-impl.stderr b/src/test/ui/mismatched_types/issue-75361-mismatched-impl.stderr index a64cb82305a4..9867addaf38e 100644 --- a/src/test/ui/mismatched_types/issue-75361-mismatched-impl.stderr +++ b/src/test/ui/mismatched_types/issue-75361-mismatched-impl.stderr @@ -2,10 +2,10 @@ error: `impl` item signature doesn't match `trait` item signature --> $DIR/issue-75361-mismatched-impl.rs:18:3 | LL | fn adjacent_edges(&self) -> Box>; - | --------------------------------------------------------------------- expected `fn(&T) -> Box<(dyn MyTrait + 'static)>` + | --------------------------------------------------------------------- expected `fn(&T) -> Box<(dyn MyTrait + 'static)>` ... LL | fn adjacent_edges(&self) -> Box + '_> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&T) -> Box>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&T) -> Box>` | = note: expected `fn(&T) -> Box<(dyn MyTrait + 'static)>` found `fn(&T) -> Box>` diff --git a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs index a4272802af54..c1dab6086ef3 100644 --- a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs +++ b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs @@ -19,7 +19,7 @@ trait Trait2<'a, 'b> { // since for it to be WF, we would need to know that `'y: 'x`, but we // do not infer that. fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) - //~^ ERROR reference has a longer lifetime than the data it references + //~^ the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied { } diff --git a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr index 6470ebf541b5..44ef13c740c0 100644 --- a/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr +++ b/src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr @@ -1,20 +1,14 @@ -error[E0491]: in type `&'x (dyn for<'z> Trait1<>::Foo> + 'x)`, reference has a longer lifetime than the data it references - --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:25 +error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied + --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:4 | LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T` | -note: the pointer is valid for the lifetime `'x` as defined on the function body at 21:11 - --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:11 +help: consider restricting type parameter `T` | -LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) - | ^^ -note: but the referenced data is only valid for the lifetime `'y` as defined on the function body at 21:15 - --> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:15 - | -LL | fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< >::Foo >) - | ^^ +LL | fn callee<'x, 'y, T: for<'z> Trait2<'y, 'z>>(t: &'x dyn for<'z> Trait1< >::Foo >) + | ++++++++++++++++++++++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0491`. +For more information about this error, try `rustc --explain E0277`. From 07ee86a6fd6ddf0750bf1f1e13b608e92a4e694f Mon Sep 17 00:00:00 2001 From: jackh726 Date: Fri, 23 Jul 2021 00:10:56 -0400 Subject: [PATCH 122/269] Normalize only after failure --- .../borrow_check/type_check/input_output.rs | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index ba3581355581..1e0a2b0c4217 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -82,33 +82,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let local = Local::new(argument_index + 1); let mir_input_ty = body.local_decls[local].ty; - // FIXME(jackh726): This is a hack. It's somewhat like - // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd - // like to normalize *before* inserting into `local_decls`, but I - // couldn't figure out where the heck that was. - let mir_input_ty = match self - .infcx - .at(&ObligationCause::dummy(), ty::ParamEnv::empty()) - .normalize(mir_input_ty) - { - Ok(n) => { - debug!("equate_inputs_and_outputs: {:?}", n); - if n.obligations.iter().all(|o| { - matches!( - o.predicate.kind().skip_binder(), - ty::PredicateKind::RegionOutlives(_) - ) - }) { - n.value - } else { - mir_input_ty - } - } - Err(_) => { - debug!("equate_inputs_and_outputs: NoSolution"); - mir_input_ty - } - }; let mir_input_span = body.local_decls[local].source_info.span; self.equate_normalized_input_or_output( normalized_input_ty, @@ -191,17 +164,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) { debug!("equate_normalized_input_or_output(a={:?}, b={:?})", a, b); - if let Err(terr) = + if let Err(_) = self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation) { - span_mirbug!( - self, - Location::START, - "equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`", - a, - b, - terr - ); + // FIXME(jackh726): This is a hack. It's somewhat like + // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd + // like to normalize *before* inserting into `local_decls`, but I + // couldn't figure out where the heck that was. + let b = match self + .infcx + .at(&ObligationCause::dummy(), ty::ParamEnv::empty()) + .normalize(b) + { + Ok(n) => { + debug!("equate_inputs_and_outputs: {:?}", n); + if n.obligations.iter().all(|o| { + matches!( + o.predicate.kind().skip_binder(), + ty::PredicateKind::RegionOutlives(_) + ) + }) { + n.value + } else { + b + } + } + Err(_) => { + debug!("equate_inputs_and_outputs: NoSolution"); + b + } + }; + if let Err(terr) = + self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation) + { + span_mirbug!( + self, + Location::START, + "equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`", + a, + b, + terr + ); + } } } } From 9891e470b10566bc77db56712afcc740ec27a184 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Fri, 23 Jul 2021 14:26:02 -0400 Subject: [PATCH 123/269] Also ignore typeoutlives predicates --- .../borrow_check/type_check/input_output.rs | 1 + .../normalization-generality-2.rs | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/ui/associated-types/normalization-generality-2.rs diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index 1e0a2b0c4217..c815ed0d1cb4 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -182,6 +182,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { matches!( o.predicate.kind().skip_binder(), ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) ) }) { n.value diff --git a/src/test/ui/associated-types/normalization-generality-2.rs b/src/test/ui/associated-types/normalization-generality-2.rs new file mode 100644 index 000000000000..d8790bb2d12f --- /dev/null +++ b/src/test/ui/associated-types/normalization-generality-2.rs @@ -0,0 +1,30 @@ +// build-pass + +// Ensures that we don't regress on "implementation is not general enough" when +// normalizating under binders. Unlike `normalization-generality.rs`, this also produces +// type outlives predicates that we must ignore. + +pub unsafe trait Yokeable<'a> { + type Output: 'a; +} +pub struct Yoke Yokeable<'a>> { + _marker: std::marker::PhantomData, +} +impl Yokeable<'a>> Yoke { + pub fn project

( + &self, + _f: for<'a> fn(&>::Output, &'a ()) ->

>::Output, + ) -> Yoke

+ where + P: for<'a> Yokeable<'a>, + { + unimplemented!() + } +} +pub fn slice(y: Yoke<&'static str>) -> Yoke<&'static [u8]> { + y.project(move |yk, _| yk.as_bytes()) +} +unsafe impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T { + type Output = &'a T; +} +fn main() {} From af14db14f4aae4cac306f2c38b83311e7cb3c3f0 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Tue, 24 Aug 2021 22:26:48 -0400 Subject: [PATCH 124/269] Review comments --- .../borrow_check/type_check/input_output.rs | 4 +- .../src/traits/project.rs | 54 +++++++++++++------ .../src/traits/query/normalize.rs | 51 ++++++++++-------- 3 files changed, 68 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs index c815ed0d1cb4..ba9b6926526b 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs @@ -169,8 +169,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { { // FIXME(jackh726): This is a hack. It's somewhat like // `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd - // like to normalize *before* inserting into `local_decls`, but I - // couldn't figure out where the heck that was. + // like to normalize *before* inserting into `local_decls`, but + // doing so ends up causing some other trouble. let b = match self .infcx .at(&ObligationCause::dummy(), ty::ParamEnv::empty()) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index df1dca9831ab..91b9ad0af356 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -363,12 +363,28 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { return ty; } - // N.b. while we want to call `super_fold_with(self)` on `ty` before - // normalization, we wait until we know whether we need to normalize the - // current type. If we do, then we only fold the ty *after* replacing bound - // vars with placeholders. This means that nested types don't need to replace - // bound vars at the current binder level or above. A key assumption here is - // that folding the type can't introduce new bound vars. + // We try to be a little clever here as a performance optimization in + // cases where there are nested projections under binders. + // For example: + // ``` + // for<'a> fn(::One<'a, Box::Two<'a>>>>) + // ``` + // We normalize the substs on the projection before the projecting, but + // if we're naive, we'll + // replace bound vars on inner, project inner, replace placeholders on inner, + // replace bound vars on outer, project outer, replace placeholders on outer + // + // However, if we're a bit more clever, we can replace the bound vars + // on the entire type before normalizing nested projections, meaning we + // replace bound vars on outer, project inner, + // project outer, replace placeholders on outer + // + // This is possible because the inner `'a` will already be a placeholder + // when we need to normalize the inner projection + // + // On the other hand, this does add a bit of complexity, since we only + // replace bound vars if the current type is a `Projection` and we need + // to make sure we don't forget to fold the substs regardless. match *ty.kind() { ty::Opaque(def_id, substs) => { @@ -380,7 +396,6 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // N.b. there is an assumption here all this code can handle // escaping bound vars. - let substs = substs.super_fold_with(self); let recursion_limit = self.tcx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { let obligation = Obligation::with_depth( @@ -392,6 +407,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { self.selcx.infcx().report_overflow_error(&obligation, true); } + let substs = substs.super_fold_with(self); let generic_ty = self.tcx().type_of(def_id); let concrete_ty = generic_ty.subst(self.tcx(), substs); self.depth += 1; @@ -430,12 +446,16 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { ty::Projection(data) => { // If there are escaping bound vars, we temporarily replace the - // bound vars with placeholders. Note though, that in the cas + // bound vars with placeholders. Note though, that in the case // that we still can't project for whatever reason (e.g. self // type isn't known enough), we *can't* register an obligation // and return an inference variable (since then that obligation // would have bound vars and that's a can of worms). Instead, // we just give up and fall back to pretending like we never tried! + // + // Note: this isn't necessarily the final approach here; we may + // want to figure out how to register obligations with escaping vars + // or handle this some other way. let infcx = self.selcx.infcx(); let (data, mapped_regions, mapped_types, mapped_consts) = @@ -451,16 +471,18 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { ) .ok() .flatten() + .map(|normalized_ty| { + PlaceholderReplacer::replace_placeholders( + infcx, + mapped_regions, + mapped_types, + mapped_consts, + &self.universes, + normalized_ty, + ) + }) .unwrap_or_else(|| ty.super_fold_with(self)); - let normalized_ty = PlaceholderReplacer::replace_placeholders( - infcx, - mapped_regions, - mapped_types, - mapped_consts, - &self.universes, - normalized_ty, - ); debug!( ?self.depth, ?ty, diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 8f8de24981b8..21e1bd8f4646 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -67,6 +67,16 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { universes: vec![], }; + // This is actually a consequence by the way `normalize_erasing_regions` works currently. + // Because it needs to call the `normalize_generic_arg_after_erasing_regions`, it folds + // through tys and consts in a `TypeFoldable`. Importantly, it skips binders, leaving us + // with trying to normalize with escaping bound vars. + // + // Here, we just add the universes that we *would* have created had we passed through the binders. + // + // We *could* replace escaping bound vars eagerly here, but it doesn't seem really necessary. + // The rest of the code is already set up to be lazy about replacing bound vars, + // and only when we actually have to normalize. if value.has_escaping_bound_vars() { let mut max_visitor = MaxEscapingBoundVarVisitor { outer_index: ty::INNERMOST, escaping: 0 }; @@ -183,12 +193,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { return ty; } - // N.b. while we want to call `super_fold_with(self)` on `ty` before - // normalization, we wait until we know whether we need to normalize the - // current type. If we do, then we only fold the ty *after* replacing bound - // vars with placeholders. This means that nested types don't need to replace - // bound vars at the current binder level or above. A key assumption here is - // that folding the type can't introduce new bound vars. + // See note in `rustc_trait_selection::traits::project` about why we + // wait to fold the substs. // Wrap this in a closure so we don't accidentally return from the outer function let res = (|| match *ty.kind() { @@ -253,7 +259,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // We don't expect ambiguity. if result.is_ambiguous() { self.error = true; - return ty; + return ty.super_fold_with(self); } match self.infcx.instantiate_query_response_and_region_obligations( @@ -271,14 +277,14 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { Err(_) => { self.error = true; - ty + ty.super_fold_with(self) } } } Err(NoSolution) => { self.error = true; - ty + ty.super_fold_with(self) } } } @@ -304,12 +310,12 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { .canonicalize_query_keep_static(self.param_env.and(data), &mut orig_values); debug!("QueryNormalizer: c_data = {:#?}", c_data); debug!("QueryNormalizer: orig_values = {:#?}", orig_values); - let normalized_ty = match tcx.normalize_projection_ty(c_data) { + match tcx.normalize_projection_ty(c_data) { Ok(result) => { // We don't expect ambiguity. if result.is_ambiguous() { self.error = true; - return ty; + return ty.super_fold_with(self); } match self.infcx.instantiate_query_response_and_region_obligations( self.cause, @@ -321,27 +327,26 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { debug!("QueryNormalizer: result = {:#?}", result); debug!("QueryNormalizer: obligations = {:#?}", obligations); self.obligations.extend(obligations); - result.normalized_ty + crate::traits::project::PlaceholderReplacer::replace_placeholders( + infcx, + mapped_regions, + mapped_types, + mapped_consts, + &self.universes, + result.normalized_ty, + ) } Err(_) => { self.error = true; - ty + ty.super_fold_with(self) } } } Err(NoSolution) => { self.error = true; - ty + ty.super_fold_with(self) } - }; - crate::traits::project::PlaceholderReplacer::replace_placeholders( - infcx, - mapped_regions, - mapped_types, - mapped_consts, - &self.universes, - normalized_ty, - ) + } } _ => ty.super_fold_with(self), From 8769b99ef098f3e7e899800f9dcf5accd5e1320a Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Wed, 25 Aug 2021 00:19:22 -0400 Subject: [PATCH 125/269] remove mention of ICEs/segfaults --- src/doc/unstable-book/src/library-features/asm.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index 2bb7e4ec266a..4715388408fe 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -367,11 +367,11 @@ unsafe { ## Labels -Any reuse of a named label, local or otherwise, can result in a assembler or linker error in the best case, ICEs or segfaults in the compiler in other cases, and generally unexpected behavior. Reuse of a named label can happen in a variety of ways including: +Any reuse of a named label, local or otherwise, can result in a assembler or linker error or may cause other strange behavior. Reuse of a named label can happen in a variety of ways including: - explicitly: using a label more than once in one `asm!` block, or multiple times across blocks - implicitly via inlining: the compiler is allowed to instantiate multiple copies of an `asm!` block, for example when the function containing it is inlined in multiple places. -- implicitly via LTO: LTO can cause code from _other crates_ to be placed in the same codegen unit, and so could bring in arbitrary labels +- implicitly via LTO: LTO can cause code from *other crates* to be placed in the same codegen unit, and so could bring in arbitrary labels As a consequence, you should only use GNU assembler **numeric** [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions. From a216d666ca535d3cfcc8839fd3cb3d5e483e2d7e Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 25 Aug 2021 03:52:24 -0400 Subject: [PATCH 126/269] type_implements_trait consider obligation failure on overflow --- compiler/rustc_trait_selection/src/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index ea074192d23b..c55b379741ee 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -117,7 +117,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { recursion_depth: 0, predicate: trait_ref.without_const().to_predicate(self.tcx), }; - self.evaluate_obligation_no_overflow(&obligation) + self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr) } } From f858c7c30062696c163d4ee341010b0b3c655665 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 25 Aug 2021 07:11:48 -0500 Subject: [PATCH 127/269] Add mutable-noalias to the release notes for 1.54 --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 2e7077ed2065..dd299ca936ac 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -175,6 +175,7 @@ Compiler - [Improved debugger output for enums on Windows MSVC platforms.][85292] - [Added tier 3\* support for `bpfel-unknown-none` and `bpfeb-unknown-none`.][79608] +- [`-Zmutable-noalias=yes`][82834] is enabled by default when using LLVM 12 or above. \* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. @@ -244,6 +245,7 @@ Compatibility Notes [83366]: https://github.com/rust-lang/rust/pull/83366 [83278]: https://github.com/rust-lang/rust/pull/83278 [85292]: https://github.com/rust-lang/rust/pull/85292 +[82834]: https://github.com/rust-lang/rust/pull/82834 [cargo/9520]: https://github.com/rust-lang/cargo/pull/9520 [cargo/9499]: https://github.com/rust-lang/cargo/pull/9499 [cargo/9488]: https://github.com/rust-lang/cargo/pull/9488 From d7d122faecfcde3c34ffaa1cfa3f81debb60be59 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 25 Aug 2021 11:39:35 -0400 Subject: [PATCH 128/269] update docs for `type_implements_trait` --- compiler/rustc_trait_selection/src/infer.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index c55b379741ee..3e79545d725e 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -44,6 +44,10 @@ pub trait InferCtxtExt<'tcx> { /// - the self type /// - the *other* type parameters of the trait, excluding the self-type /// - the parameter environment + /// + /// Invokes `evaluate_obligation`, so in the event that evaluating + /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) + /// will be returned. fn type_implements_trait( &self, trait_def_id: DefId, From 88bcd4457be4d37d83d505ad3fe2dc7a5ce7203a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 25 Aug 2021 12:09:48 -0400 Subject: [PATCH 129/269] trailing whitespace --- compiler/rustc_trait_selection/src/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 3e79545d725e..c90649353e80 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -46,7 +46,7 @@ pub trait InferCtxtExt<'tcx> { /// - the parameter environment /// /// Invokes `evaluate_obligation`, so in the event that evaluating - /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) + /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) /// will be returned. fn type_implements_trait( &self, From fde1b76b4b1d0d84f5691f4785906b31bb91f38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lanteri=20Thauvin?= Date: Mon, 16 Aug 2021 17:29:49 +0200 Subject: [PATCH 130/269] Use if-let guards in the codebase --- compiler/rustc_ast/src/attr/mod.rs | 10 +-- compiler/rustc_ast/src/lib.rs | 2 + compiler/rustc_errors/src/lib.rs | 16 ++-- compiler/rustc_expand/src/config.rs | 15 ++-- compiler/rustc_expand/src/lib.rs | 2 + compiler/rustc_expand/src/module.rs | 11 ++- .../rustc_expand/src/proc_macro_server.rs | 23 ++--- compiler/rustc_middle/src/lib.rs | 2 + compiler/rustc_middle/src/ty/error.rs | 30 +++---- compiler/rustc_middle/src/ty/util.rs | 10 +-- compiler/rustc_parse/src/lib.rs | 25 +++--- .../rustc_parse/src/parser/nonterminal.rs | 17 ++-- compiler/rustc_parse/src/parser/stmt.rs | 20 ++--- compiler/rustc_parse/src/validate_attr.rs | 17 ++-- compiler/rustc_save_analysis/src/lib.rs | 89 ++++++++++--------- compiler/rustc_span/src/lib.rs | 2 + compiler/rustc_span/src/source_map.rs | 35 ++++---- compiler/rustc_typeck/src/astconv/mod.rs | 10 +-- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 12 +-- .../rustc_typeck/src/check/method/probe.rs | 50 +++++------ compiler/rustc_typeck/src/check/pat.rs | 29 +++--- compiler/rustc_typeck/src/check/wfcheck.rs | 34 ++++--- compiler/rustc_typeck/src/check/writeback.rs | 8 +- compiler/rustc_typeck/src/collect/type_of.rs | 12 +-- compiler/rustc_typeck/src/lib.rs | 2 + library/core/src/lib.rs | 2 + library/core/src/num/dec2flt/mod.rs | 9 +- 27 files changed, 241 insertions(+), 253 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 41121d095f3e..81195f7fb5cb 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -564,11 +564,11 @@ impl NestedMetaItem { I: Iterator, { match tokens.peek() { - Some(TokenTree::Token(token)) => { - if let Ok(lit) = Lit::from_token(token) { - tokens.next(); - return Some(NestedMetaItem::Literal(lit)); - } + Some(TokenTree::Token(token)) + if let Ok(lit) = Lit::from_token(token) => + { + tokens.next(); + return Some(NestedMetaItem::Literal(lit)); } Some(TokenTree::Delimited(_, token::NoDelim, inner_tokens)) => { let inner_tokens = inner_tokens.clone(); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 502bd69e6a9a..ef3f6035085d 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -11,10 +11,12 @@ #![feature(box_patterns)] #![cfg_attr(bootstrap, feature(const_fn_transmute))] #![feature(crate_visibility_modifier)] +#![feature(if_let_guard)] #![feature(iter_zip)] #![feature(label_break_value)] #![feature(nll)] #![feature(min_specialization)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index a48d4fe8bb55..02b6179f8950 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -5,9 +5,11 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(crate_visibility_modifier)] #![feature(backtrace)] +#![feature(if_let_guard)] #![feature(format_args_capture)] #![feature(iter_zip)] #![feature(nll)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #[macro_use] extern crate rustc_macros; @@ -1027,15 +1029,15 @@ impl HandlerInner { let mut error_codes = self .emitted_diagnostic_codes .iter() - .filter_map(|x| match &x { - DiagnosticId::Error(s) => { - if let Ok(Some(_explanation)) = registry.try_find_description(s) { - Some(s.clone()) - } else { - None - } + .filter_map(|x| { + match &x { + DiagnosticId::Error(s) + if let Ok(Some(_explanation)) = registry.try_find_description(s) => + { + Some(s.clone()) } _ => None, + } }) .collect::>(); if !error_codes.is_empty() { diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index e09893f7f388..38c099fa4f59 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -305,15 +305,14 @@ impl<'a> StripUnconfigured<'a> { Some((AttrAnnotatedTokenTree::Delimited(sp, delim, inner), *spacing)) .into_iter() } + AttrAnnotatedTokenTree::Token(ref token) if let TokenKind::Interpolated(ref nt) = token.kind => { + panic!( + "Nonterminal should have been flattened at {:?}: {:?}", + token.span, nt + ); + } AttrAnnotatedTokenTree::Token(token) => { - if let TokenKind::Interpolated(nt) = token.kind { - panic!( - "Nonterminal should have been flattened at {:?}: {:?}", - token.span, nt - ); - } else { - Some((AttrAnnotatedTokenTree::Token(token), *spacing)).into_iter() - } + Some((AttrAnnotatedTokenTree::Token(token), *spacing)).into_iter() } }) .collect(); diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index efed41de23a8..f38f85a46268 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -2,11 +2,13 @@ #![feature(decl_macro)] #![feature(destructuring_assignment)] #![feature(format_args_capture)] +#![feature(if_let_guard)] #![feature(iter_zip)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] #![feature(proc_macro_span)] #![feature(try_blocks)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #[macro_use] extern crate rustc_macros; diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 4d777049f0d6..60d653ac8b6f 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -86,13 +86,12 @@ crate fn mod_dir_path( inline: Inline, ) -> (PathBuf, DirOwnership) { match inline { + Inline::Yes if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) => { + // For inline modules file path from `#[path]` is actually the directory path + // for historical reasons, so we don't pop the last segment here. + (file_path, DirOwnership::Owned { relative: None }) + } Inline::Yes => { - if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) { - // For inline modules file path from `#[path]` is actually the directory path - // for historical reasons, so we don't pop the last segment here. - return (file_path, DirOwnership::Owned { relative: None }); - } - // We have to push on the current module name in the case of relative // paths in order to ensure that any additional module paths from inline // `mod x { ... }` come after the relative extension. diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 42ae8e972c27..55700f7b0d49 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -178,18 +178,19 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec, &mut Rustc<'_>)> tt!(Punct::new('#', false)) } + Interpolated(nt) + if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, rustc) => + { + TokenTree::Ident(Ident::new(rustc.sess, name.name, is_raw, name.span)) + } Interpolated(nt) => { - if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, rustc) { - TokenTree::Ident(Ident::new(rustc.sess, name.name, is_raw, name.span)) - } else { - let stream = nt_to_tokenstream(&nt, rustc.sess, CanSynthesizeMissingTokens::No); - TokenTree::Group(Group { - delimiter: Delimiter::None, - stream, - span: DelimSpan::from_single(span), - flatten: crate::base::pretty_printing_compatibility_hack(&nt, rustc.sess), - }) - } + let stream = nt_to_tokenstream(&nt, rustc.sess, CanSynthesizeMissingTokens::No); + TokenTree::Group(Group { + delimiter: Delimiter::None, + stream, + span: DelimSpan::from_single(span), + flatten: crate::base::pretty_printing_compatibility_hack(&nt, rustc.sess), + }) } OpenDelim(..) | CloseDelim(..) => unreachable!(), diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 0e72e916cc6a..573fa913d680 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -31,6 +31,7 @@ #![feature(box_patterns)] #![feature(core_intrinsics)] #![feature(discriminant_kind)] +#![feature(if_let_guard)] #![feature(never_type)] #![feature(extern_types)] #![feature(new_uninit)] @@ -52,6 +53,7 @@ #![feature(try_reserve)] #![feature(try_reserve_kind)] #![feature(nonzero_ops)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "512"] #[macro_use] diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 1aa6c84dbc41..ecbe9ca41759 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -279,13 +279,10 @@ impl<'tcx> ty::TyS<'tcx> { } ty::FnDef(..) => "fn item".into(), ty::FnPtr(_) => "fn pointer".into(), - ty::Dynamic(ref inner, ..) => { - if let Some(principal) = inner.principal() { - format!("trait object `dyn {}`", tcx.def_path_str(principal.def_id())).into() - } else { - "trait object".into() - } + ty::Dynamic(ref inner, ..) if let Some(principal) = inner.principal() => { + format!("trait object `dyn {}`", tcx.def_path_str(principal.def_id())).into() } + ty::Dynamic(..) => "trait object".into(), ty::Closure(..) => "closure".into(), ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(), ty::GeneratorWitness(..) => "generator witness".into(), @@ -365,20 +362,19 @@ impl<'tcx> TyCtxt<'tcx> { // Issue #63167 db.note("distinct uses of `impl Trait` result in different opaque types"); } - (ty::Float(_), ty::Infer(ty::IntVar(_))) => { + (ty::Float(_), ty::Infer(ty::IntVar(_))) if let Ok( // Issue #53280 snippet, - ) = self.sess.source_map().span_to_snippet(sp) - { - if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') { - db.span_suggestion( - sp, - "use a float literal", - format!("{}.0", snippet), - MachineApplicable, - ); - } + ) = self.sess.source_map().span_to_snippet(sp) => + { + if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') { + db.span_suggestion( + sp, + "use a float literal", + format!("{}.0", snippet), + MachineApplicable, + ); } } (ty::Param(expected), ty::Param(found)) => { diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index a78206034f08..1b8e94260b9b 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -225,14 +225,12 @@ impl<'tcx> TyCtxt<'tcx> { } } - ty::Tuple(tys) => { - if let Some((&last_ty, _)) = tys.split_last() { - ty = last_ty.expect_ty(); - } else { - break; - } + ty::Tuple(tys) if let Some((&last_ty, _)) = tys.split_last() => { + ty = last_ty.expect_ty(); } + ty::Tuple(_) => break, + ty::Projection(_) | ty::Opaque(..) => { let normalized = normalize(ty); if ty == normalized { diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 07f972c2fa89..73e05a35277e 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -2,8 +2,10 @@ #![feature(array_windows)] #![feature(crate_visibility_modifier)] +#![feature(if_let_guard)] #![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(box_patterns)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] use rustc_ast as ast; @@ -262,20 +264,17 @@ pub fn nt_to_tokenstream( let tokens = match *nt { Nonterminal::NtItem(ref item) => prepend_attrs(&item.attrs, item.tokens.as_ref()), Nonterminal::NtBlock(ref block) => convert_tokens(block.tokens.as_ref()), - Nonterminal::NtStmt(ref stmt) => { - if let ast::StmtKind::Empty = stmt.kind { - let tokens = AttrAnnotatedTokenStream::new(vec![( - tokenstream::AttrAnnotatedTokenTree::Token(Token::new( - TokenKind::Semi, - stmt.span, - )), - Spacing::Alone, - )]); - prepend_attrs(&stmt.attrs(), Some(&LazyTokenStream::new(tokens))) - } else { - prepend_attrs(&stmt.attrs(), stmt.tokens()) - } + Nonterminal::NtStmt(ref stmt) if let ast::StmtKind::Empty = stmt.kind => { + let tokens = AttrAnnotatedTokenStream::new(vec![( + tokenstream::AttrAnnotatedTokenTree::Token(Token::new( + TokenKind::Semi, + stmt.span, + )), + Spacing::Alone, + )]); + prepend_attrs(&stmt.attrs(), Some(&LazyTokenStream::new(tokens))) } + Nonterminal::NtStmt(ref stmt) => prepend_attrs(&stmt.attrs(), stmt.tokens()), Nonterminal::NtPat(ref pat) => convert_tokens(pat.tokens.as_ref()), Nonterminal::NtTy(ref ty) => convert_tokens(ty.tokens.as_ref()), Nonterminal::NtIdent(ident, is_raw) => { diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 313d9db58fc3..72e6f8a1bc85 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -143,15 +143,16 @@ impl<'a> Parser<'a> { token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty())?) } // this could be handled like a token, since it is one + NonterminalKind::Ident + if let Some((ident, is_raw)) = get_macro_ident(&self.token) => + { + self.bump(); + token::NtIdent(ident, is_raw) + } NonterminalKind::Ident => { - if let Some((ident, is_raw)) = get_macro_ident(&self.token) { - self.bump(); - token::NtIdent(ident, is_raw) - } else { - let token_str = pprust::token_to_string(&self.token); - let msg = &format!("expected ident, found {}", &token_str); - return Err(self.struct_span_err(self.token.span, msg)); - } + let token_str = pprust::token_to_string(&self.token); + let msg = &format!("expected ident, found {}", &token_str); + return Err(self.struct_span_err(self.token.span, msg)); } NonterminalKind::Path => token::NtPath( self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 9ef3f61ec346..85515bd2a631 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -493,21 +493,19 @@ impl<'a> Parser<'a> { } } StmtKind::Expr(_) | StmtKind::MacCall(_) => {} - StmtKind::Local(ref mut local) => { - if let Err(e) = self.expect_semi() { - // We might be at the `,` in `let x = foo;`. Try to recover. - match &mut local.init { - Some(ref mut expr) => { - self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; - // We found `foo`, have we fully recovered? - self.expect_semi()?; - } - None => return Err(e), + StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => { + // We might be at the `,` in `let x = foo;`. Try to recover. + match &mut local.init { + Some(ref mut expr) => { + self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; + // We found `foo`, have we fully recovered? + self.expect_semi()?; } + None => return Err(e), } eat_semi = false; } - StmtKind::Empty | StmtKind::Item(_) | StmtKind::Semi(_) => eat_semi = false, + StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false, } if eat_semi && self.eat(&token::Semi) { diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index 21372725a683..67695dc28509 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -24,16 +24,15 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) { Some((name, _, template, _)) if name != sym::rustc_dummy => { check_builtin_attribute(sess, attr, name, template) } - _ => { - if let MacArgs::Eq(..) = attr.get_normal_item().args { - // All key-value attributes are restricted to meta-item syntax. - parse_meta(sess, attr) - .map_err(|mut err| { - err.emit(); - }) - .ok(); - } + _ if let MacArgs::Eq(..) = attr.get_normal_item().args => { + // All key-value attributes are restricted to meta-item syntax. + parse_meta(sess, attr) + .map_err(|mut err| { + err.emit(); + }) + .ok(); } + _ => {} } } diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 0a8a88132e33..41d174cde0a8 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1,5 +1,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(if_let_guard)] #![feature(nll)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] mod dump_visitor; @@ -326,54 +328,53 @@ impl<'tcx> SaveContext<'tcx> { attributes: lower_attributes(attrs.to_vec(), self), })) } - hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) => { - if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = self_ty.kind { - // Common case impl for a struct or something basic. - if generated_code(path.span) { - return None; - } - let sub_span = path.segments.last().unwrap().ident.span; - filter!(self.span_utils, sub_span); + hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) + if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = self_ty.kind => + { + // Common case impl for a struct or something basic. + if generated_code(path.span) { + return None; + } + let sub_span = path.segments.last().unwrap().ident.span; + filter!(self.span_utils, sub_span); - let impl_id = self.next_impl_id(); - let span = self.span_from_span(sub_span); + let impl_id = self.next_impl_id(); + let span = self.span_from_span(sub_span); - let type_data = self.lookup_def_id(self_ty.hir_id); - type_data.map(|type_data| { - Data::RelationData( - Relation { - kind: RelationKind::Impl { id: impl_id }, - span: span.clone(), - from: id_from_def_id(type_data), - to: of_trait - .as_ref() - .and_then(|t| self.lookup_def_id(t.hir_ref_id)) - .map(id_from_def_id) - .unwrap_or_else(null_id), - }, - Impl { - id: impl_id, - kind: match *of_trait { - Some(_) => ImplKind::Direct, - None => ImplKind::Inherent, - }, - span, - value: String::new(), - parent: None, - children: items - .iter() - .map(|i| id_from_def_id(i.id.def_id.to_def_id())) - .collect(), - docs: String::new(), - sig: None, - attributes: vec![], + let type_data = self.lookup_def_id(self_ty.hir_id); + type_data.map(|type_data| { + Data::RelationData( + Relation { + kind: RelationKind::Impl { id: impl_id }, + span: span.clone(), + from: id_from_def_id(type_data), + to: of_trait + .as_ref() + .and_then(|t| self.lookup_def_id(t.hir_ref_id)) + .map(id_from_def_id) + .unwrap_or_else(null_id), + }, + Impl { + id: impl_id, + kind: match *of_trait { + Some(_) => ImplKind::Direct, + None => ImplKind::Inherent, }, - ) - }) - } else { - None - } + span, + value: String::new(), + parent: None, + children: items + .iter() + .map(|i| id_from_def_id(i.id.def_id.to_def_id())) + .collect(), + docs: String::new(), + sig: None, + attributes: vec![], + }, + ) + }) } + hir::ItemKind::Impl(_) => None, _ => { // FIXME bug!(); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 9e127577b61a..89e032b222fe 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -16,10 +16,12 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] #![feature(crate_visibility_modifier)] +#![feature(if_let_guard)] #![feature(negative_impls)] #![feature(nll)] #![feature(min_specialization)] #![feature(thread_local_const_init)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #[macro_use] extern crate rustc_macros; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index f700397fcdf0..2c3af802be55 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -982,15 +982,13 @@ impl SourceMap { None } pub fn ensure_source_file_source_present(&self, source_file: Lrc) -> bool { - source_file.add_external_src(|| match source_file.name { - FileName::Real(ref name) => { - if let Some(local_path) = name.local_path() { + source_file.add_external_src(|| { + match source_file.name { + FileName::Real(ref name) if let Some(local_path) = name.local_path() => { self.file_loader.read_file(local_path).ok() - } else { - None } + _ => None, } - _ => None, }) } @@ -1033,22 +1031,19 @@ impl FilePathMapping { fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) { match file { - FileName::Real(realfile) => { - if let RealFileName::LocalPath(local_path) = realfile { - let (mapped_path, mapped) = self.map_prefix(local_path.to_path_buf()); - let realfile = if mapped { - RealFileName::Remapped { - local_path: Some(local_path.clone()), - virtual_name: mapped_path, - } - } else { - realfile.clone() - }; - (FileName::Real(realfile), mapped) + FileName::Real(realfile) if let RealFileName::LocalPath(local_path) = realfile => { + let (mapped_path, mapped) = self.map_prefix(local_path.to_path_buf()); + let realfile = if mapped { + RealFileName::Remapped { + local_path: Some(local_path.clone()), + virtual_name: mapped_path, + } } else { - unreachable!("attempted to remap an already remapped filename"); - } + realfile.clone() + }; + (FileName::Real(realfile), mapped) } + FileName::Real(_) => unreachable!("attempted to remap an already remapped filename"), other => (other.clone(), false), } } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 7d7d69b40798..606fd2812ecc 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2380,12 +2380,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) { // Our own parameters are the resolved lifetimes. match param.kind { - GenericParamDefKind::Lifetime => { - if let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] { - self.ast_region_to_region(lifetime, None).into() - } else { - bug!() - } + GenericParamDefKind::Lifetime + if let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] => + { + self.ast_region_to_region(lifetime, None).into() } _ => bug!(), } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index f9b7bb8ea991..dc0d8c0aeff2 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1178,12 +1178,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut user_self_ty = None; let mut is_alias_variant_ctor = false; match res { - Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => { - if let Some(self_ty) = self_ty { - let adt_def = self_ty.ty_adt_def().unwrap(); - user_self_ty = Some(UserSelfTy { impl_def_id: adt_def.did, self_ty }); - is_alias_variant_ctor = true; - } + Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) + if let Some(self_ty) = self_ty => + { + let adt_def = self_ty.ty_adt_def().unwrap(); + user_self_ty = Some(UserSelfTy { impl_def_id: adt_def.did, self_ty }); + is_alias_variant_ctor = true; } Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => { let container = tcx.associated_item(def_id).container; diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 486e4d15d658..1c7d68a3d57d 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -616,32 +616,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let lang_items = self.tcx.lang_items(); match *self_ty.value.value.kind() { - ty::Dynamic(ref data, ..) => { - if let Some(p) = data.principal() { - // Subtle: we can't use `instantiate_query_response` here: using it will - // commit to all of the type equalities assumed by inference going through - // autoderef (see the `method-probe-no-guessing` test). - // - // However, in this code, it is OK if we end up with an object type that is - // "more general" than the object type that we are evaluating. For *every* - // object type `MY_OBJECT`, a function call that goes through a trait-ref - // of the form `::func` is a valid - // `ObjectCandidate`, and it should be discoverable "exactly" through one - // of the iterations in the autoderef loop, so there is no problem with it - // being discoverable in another one of these iterations. - // - // Using `instantiate_canonical_with_fresh_inference_vars` on our - // `Canonical>>` and then *throwing away* the - // `CanonicalVarValues` will exactly give us such a generalization - it - // will still match the original object type, but it won't pollute our - // type variables in any form, so just do that! - let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) = - self.fcx - .instantiate_canonical_with_fresh_inference_vars(self.span, &self_ty); - - self.assemble_inherent_candidates_from_object(generalized_self_ty); - self.assemble_inherent_impl_candidates_for_type(p.def_id()); - } + ty::Dynamic(ref data, ..) if let Some(p) = data.principal() => { + // Subtle: we can't use `instantiate_query_response` here: using it will + // commit to all of the type equalities assumed by inference going through + // autoderef (see the `method-probe-no-guessing` test). + // + // However, in this code, it is OK if we end up with an object type that is + // "more general" than the object type that we are evaluating. For *every* + // object type `MY_OBJECT`, a function call that goes through a trait-ref + // of the form `::func` is a valid + // `ObjectCandidate`, and it should be discoverable "exactly" through one + // of the iterations in the autoderef loop, so there is no problem with it + // being discoverable in another one of these iterations. + // + // Using `instantiate_canonical_with_fresh_inference_vars` on our + // `Canonical>>` and then *throwing away* the + // `CanonicalVarValues` will exactly give us such a generalization - it + // will still match the original object type, but it won't pollute our + // type variables in any form, so just do that! + let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) = + self.fcx + .instantiate_canonical_with_fresh_inference_vars(self.span, &self_ty); + + self.assemble_inherent_candidates_from_object(generalized_self_ty); + self.assemble_inherent_impl_candidates_for_type(p.def_id()); } ty::Adt(def, _) => { self.assemble_inherent_impl_candidates_for_type(def.did); diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index dae574bb7bf0..392262628c0c 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -627,15 +627,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let binding_parent = tcx.hir().get(binding_parent_id); debug!("inner {:?} pat {:?} parent {:?}", inner, pat, binding_parent); match binding_parent { - hir::Node::Param(hir::Param { span, .. }) => { - if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(inner.span) { - err.span_suggestion( - *span, - &format!("did you mean `{}`", snippet), - format!(" &{}", expected), - Applicability::MachineApplicable, - ); - } + hir::Node::Param(hir::Param { span, .. }) + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(inner.span) => + { + err.span_suggestion( + *span, + &format!("did you mean `{}`", snippet), + format!(" &{}", expected), + Applicability::MachineApplicable, + ); } hir::Node::Arm(_) | hir::Node::Pat(_) => { // rely on match ergonomics or it might be nested `&&pat` @@ -1293,13 +1293,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (Some(mut err), None) => { err.emit(); } - (None, None) => { - if let Some(mut err) = - self.error_tuple_variant_index_shorthand(variant, pat, fields) - { - err.emit(); - } + (None, None) if let Some(mut err) = + self.error_tuple_variant_index_shorthand(variant, pat, fields) => + { + err.emit(); } + (None, None) => {} } no_field_errors } diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index b82437096592..632b9492ee43 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1049,26 +1049,24 @@ fn check_opaque_types<'fcx, 'tcx>( let arg_is_param = match arg.unpack() { GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)), - GenericArgKind::Lifetime(region) => { - if let ty::ReStatic = region { - tcx.sess - .struct_span_err( - span, - "non-defining opaque type use in defining scope", - ) - .span_label( - tcx.def_span(generics.param_at(i, tcx).def_id), - "cannot use static lifetime; use a bound lifetime \ - instead or remove the lifetime parameter from the \ - opaque type", - ) - .emit(); - continue; - } - - true + GenericArgKind::Lifetime(region) if let ty::ReStatic = region => { + tcx.sess + .struct_span_err( + span, + "non-defining opaque type use in defining scope", + ) + .span_label( + tcx.def_span(generics.param_at(i, tcx).def_id), + "cannot use static lifetime; use a bound lifetime \ + instead or remove the lifetime parameter from the \ + opaque type", + ) + .emit(); + continue; } + GenericArgKind::Lifetime(_) => true, + GenericArgKind::Const(ct) => matches!(ct.val, ty::ConstKind::Param(_)), }; diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index a13157b46082..2e59defdb7ba 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -175,10 +175,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } } } - hir::ExprKind::AssignOp(..) => { - if let Some(a) = typeck_results.adjustments_mut().get_mut(lhs.hir_id) { - a.pop(); - } + hir::ExprKind::AssignOp(..) + if let Some(a) = typeck_results.adjustments_mut().get_mut(lhs.hir_id) => + { + a.pop(); } _ => {} } diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index e63c3346e02b..4048a54b58c9 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -446,13 +446,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } } - Node::AnonConst(_) => { - if let Some(param) = tcx.opt_const_param_of(def_id) { - // We defer to `type_of` of the corresponding parameter - // for generic arguments. - return tcx.type_of(param); - } + Node::AnonConst(_) if let Some(param) = tcx.opt_const_param_of(def_id) => { + // We defer to `type_of` of the corresponding parameter + // for generic arguments. + tcx.type_of(param) + } + Node::AnonConst(_) => { let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); match parent_node { Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. }) diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 61631f3b14bb..638a46fec36f 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -60,6 +60,7 @@ This API is completely unstable and subject to change. #![feature(bool_to_option)] #![feature(crate_visibility_modifier)] #![feature(format_args_capture)] +#![feature(if_let_guard)] #![feature(in_band_lifetimes)] #![feature(is_sorted)] #![feature(iter_zip)] @@ -68,6 +69,7 @@ This API is completely unstable and subject to change. #![feature(never_type)] #![feature(slice_partition_dedup)] #![feature(control_flow_enum)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] #[macro_use] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index a4e57fd6a6db..1a6d1aed2fd1 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -69,6 +69,7 @@ #![warn(missing_debug_implementations)] #![warn(missing_docs)] #![allow(explicit_outlives_requirements)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard // // Library features for const fns: #![feature(const_align_of_val)] @@ -134,6 +135,7 @@ #![feature(exhaustive_patterns)] #![feature(extern_types)] #![feature(fundamental)] +#![feature(if_let_guard)] #![feature(intra_doc_pointers)] #![feature(intrinsics)] #![feature(lang_items)] diff --git a/library/core/src/num/dec2flt/mod.rs b/library/core/src/num/dec2flt/mod.rs index c78492f5ae2c..2b280773e4c5 100644 --- a/library/core/src/num/dec2flt/mod.rs +++ b/library/core/src/num/dec2flt/mod.rs @@ -236,13 +236,8 @@ pub fn dec2flt(s: &str) -> Result { let num = match parse_number(s, negative) { Some(r) => r, - None => { - if let Some(value) = parse_inf_nan(s, negative) { - return Ok(value); - } else { - return Err(pfe_invalid()); - } - } + None if let Some(value) = parse_inf_nan(s, negative) => return Ok(value), + None => return Err(pfe_invalid()), }; if let Some(value) = num.try_fast_path::() { return Ok(value); From 2b0c8fff8a04dd995db0afaafba2ad9a5eff6fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lanteri=20Thauvin?= Date: Mon, 16 Aug 2021 17:30:23 +0200 Subject: [PATCH 131/269] Various pattern cleanups --- compiler/rustc_ast/src/mut_visit.rs | 7 +--- compiler/rustc_ast/src/visit.rs | 7 +--- compiler/rustc_expand/src/lib.rs | 1 + compiler/rustc_middle/src/mir/mod.rs | 9 ++--- compiler/rustc_middle/src/mir/visit.rs | 17 ++++----- compiler/rustc_middle/src/thir.rs | 16 ++------ compiler/rustc_middle/src/ty/print/pretty.rs | 38 ++++++++++--------- compiler/rustc_typeck/src/check/expr.rs | 9 ++--- compiler/rustc_typeck/src/expr_use_visitor.rs | 11 ++---- 9 files changed, 47 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index c82458311872..fb4db6005aca 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1179,13 +1179,10 @@ fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { for (op, _) in &mut asm.operands { match op { InlineAsmOperand::In { expr, .. } + | InlineAsmOperand::Out { expr: Some(expr), .. } | InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr), - InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - vis.visit_expr(expr); - } - } + InlineAsmOperand::Out { expr: None, .. } => {} InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { vis.visit_expr(in_expr); if let Some(out_expr) = out_expr { diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index a377763983a4..cc699b237c21 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -714,13 +714,10 @@ fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) { for (op, _) in &asm.operands { match op { InlineAsmOperand::In { expr, .. } + | InlineAsmOperand::Out { expr: Some(expr), .. } | InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr), - InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - visitor.visit_expr(expr); - } - } + InlineAsmOperand::Out { expr: None, .. } => {} InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { visitor.visit_expr(in_expr); if let Some(out_expr) = out_expr { diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index f38f85a46268..aaded7ba23bb 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] #![feature(destructuring_assignment)] diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index b66995afc6db..00c2f0a0299a 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1664,13 +1664,10 @@ impl Debug for Statement<'_> { AscribeUserType(box (ref place, ref c_ty), ref variance) => { write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty) } - Coverage(box ref coverage) => { - if let Some(rgn) = &coverage.code_region { - write!(fmt, "Coverage::{:?} for {:?}", coverage.kind, rgn) - } else { - write!(fmt, "Coverage::{:?}", coverage.kind) - } + Coverage(box self::Coverage { ref kind, code_region: Some(ref rgn) }) => { + write!(fmt, "Coverage::{:?} for {:?}", kind, rgn) } + Coverage(box ref coverage) => write!(fmt, "Coverage::{:?}", coverage.kind), CopyNonOverlapping(box crate::mir::CopyNonOverlapping { ref src, ref dst, diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 45ea3e3d9f35..af7f77965226 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -587,14 +587,12 @@ macro_rules! make_mir_visitor { InlineAsmOperand::In { value, .. } => { self.visit_operand(value, location); } - InlineAsmOperand::Out { place, .. } => { - if let Some(place) = place { - self.visit_place( - place, - PlaceContext::MutatingUse(MutatingUseContext::Store), - location, - ); - } + InlineAsmOperand::Out { place: Some(place), .. } => { + self.visit_place( + place, + PlaceContext::MutatingUse(MutatingUseContext::Store), + location, + ); } InlineAsmOperand::InOut { in_value, out_place, .. } => { self.visit_operand(in_value, location); @@ -610,7 +608,8 @@ macro_rules! make_mir_visitor { | InlineAsmOperand::SymFn { value } => { self.visit_constant(value, location); } - InlineAsmOperand::SymStatic { def_id: _ } => {} + InlineAsmOperand::Out { place: None, .. } + | InlineAsmOperand::SymStatic { def_id: _ } => {} } } } diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 48337b8cb961..b88bce844fa1 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -14,7 +14,7 @@ use rustc_hir::def::CtorKind; use rustc_hir::def_id::DefId; use rustc_hir::RangeEnd; use rustc_index::newtype_index; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::IndexVec; use rustc_middle::infer::canonical::Canonical; use rustc_middle::middle::region; use rustc_middle::mir::{ @@ -716,17 +716,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> { PatKind::Variant { adt_def, variant_index, .. } => { Some(&adt_def.variants[variant_index]) } - _ => { - if let ty::Adt(adt, _) = self.ty.kind() { - if !adt.is_enum() { - Some(&adt.variants[VariantIdx::new(0)]) - } else { - None - } - } else { - None - } - } + _ => self.ty.ty_adt_def().and_then(|adt| { + if !adt.is_enum() { Some(adt.non_enum_variant()) } else { None } + }), }; if let Some(variant) = variant { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 8558d6bb00e7..4befeb1d827c 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -927,27 +927,29 @@ pub trait PrettyPrinter<'tcx>: } match ct.val { - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => { - if let Some(promoted) = promoted { - p!(print_value_path(def.did, substs)); - p!(write("::{:?}", promoted)); - } else { - match self.tcx().def_kind(def.did) { - DefKind::Static | DefKind::Const | DefKind::AssocConst => { - p!(print_value_path(def.did, substs)) - } - _ => { - if def.is_local() { - let span = self.tcx().def_span(def.did); - if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) - { - p!(write("{}", snip)) - } else { - print_underscore!() - } + ty::ConstKind::Unevaluated(ty::Unevaluated { + def, + substs, + promoted: Some(promoted), + }) => { + p!(print_value_path(def.did, substs)); + p!(write("::{:?}", promoted)); + } + ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: None }) => { + match self.tcx().def_kind(def.did) { + DefKind::Static | DefKind::Const | DefKind::AssocConst => { + p!(print_value_path(def.did, substs)) + } + _ => { + if def.is_local() { + let span = self.tcx().def_span(def.did); + if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) { + p!(write("{}", snip)) } else { print_underscore!() } + } else { + print_underscore!() } } } diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index eaf24552355d..ab927b794422 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -2164,14 +2164,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::InlineAsmOperand::In { expr, .. } => { self.check_expr_asm_operand(expr, true); } - hir::InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - self.check_expr_asm_operand(expr, false); - } - } - hir::InlineAsmOperand::InOut { expr, .. } => { + hir::InlineAsmOperand::Out { expr: Some(expr), .. } + | hir::InlineAsmOperand::InOut { expr, .. } => { self.check_expr_asm_operand(expr, false); } + hir::InlineAsmOperand::Out { expr: None, .. } => {} hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { self.check_expr_asm_operand(in_expr, true); if let Some(out_expr) = out_expr { diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index cd00d181ed04..024370f8d371 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -334,12 +334,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { match op { hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Sym { expr, .. } => self.consume_expr(expr), - hir::InlineAsmOperand::Out { expr, .. } => { - if let Some(expr) = expr { - self.mutate_expr(expr); - } - } - hir::InlineAsmOperand::InOut { expr, .. } => { + hir::InlineAsmOperand::Out { expr: Some(expr), .. } + | hir::InlineAsmOperand::InOut { expr, .. } => { self.mutate_expr(expr); } hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { @@ -348,7 +344,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.mutate_expr(out_expr); } } - hir::InlineAsmOperand::Const { .. } => {} + hir::InlineAsmOperand::Out { expr: None, .. } + | hir::InlineAsmOperand::Const { .. } => {} } } } From 33c71ac87d4c4bad82dfd646d7a9254c6b358a26 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 25 Aug 2021 11:25:26 -0700 Subject: [PATCH 132/269] Add `c_size_t` and `c_ssize_t` to `std::os::raw`. --- library/std/src/os/raw/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 50464a050c70..7ce58fb1d0ff 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -151,3 +151,17 @@ type_alias_no_nz! { "double.md", c_double = f64; } #[stable(feature = "raw_os", since = "1.1.0")] #[doc(no_inline)] pub use core::ffi::c_void; + +/// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++). +/// +/// This type is currently always [`usize`], however in the future there may be +/// platforms where this is not the case. +#[unstable(feature = "c_size_t", issue = "none")] +pub type c_size_t = usize; + +/// Equivalent to C's `ssize_t` type, from `stddef.h` (or `cstddef` for C++). +/// +/// This type is currently always [`isize`], however in the future there may be +/// platforms where this is not the case. +#[unstable(feature = "c_size_t", issue = "none")] +pub type c_ssize_t = isize; From 0a42dfc2fa2b373aedf7a169da3f0ec0e996fc9f Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 23 Jul 2021 18:55:36 -0400 Subject: [PATCH 133/269] Fix debugger stepping behavior around `match` expressions Previously, we would set up the source lines for `match` expressions so that the code generated to perform the test of the scrutinee was matched to the line of the arm that required the test and then jump from the arm block to the "next" block was matched to all of the lines in the `match` expression. While that makes sense, it has the side effect of causing strange stepping behavior in debuggers. I've changed the source information so that all of the generated tests are sourced to `match {scrutinee}` and the jumps are sourced to the last line of the block they are inside. This resolves the weird stepping behavior in all debuggers and resolves some instances of "ambiguous symbol" errors in WinDbg preventing the user from setting breakpoints at `match` expressions. --- .../rustc_mir_build/src/build/matches/mod.rs | 63 ++++++++++++++++--- .../rustc_mir_build/src/build/matches/test.rs | 14 ++++- ..._regression.encode.SimplifyBranchSame.diff | 8 +-- .../const_goto.issue_77355_opt.ConstGoto.diff | 8 +-- ...onst_goto_const_eval_fail.f.ConstGoto.diff | 18 +++--- .../discriminant.main.ConstProp.32bit.diff | 2 +- .../discriminant.main.ConstProp.64bit.diff | 2 +- .../const_prop/switch_int.main.ConstProp.diff | 4 +- ...ain.SimplifyBranches-after-const-prop.diff | 4 +- ..._line_doc_comment_2.DeduplicateBlocks.diff | 30 ++++----- ...wise_branch.opt1.EarlyOtherwiseBranch.diff | 28 ++++----- ...wise_branch.opt2.EarlyOtherwiseBranch.diff | 36 +++++------ ...ement_tuple.opt1.EarlyOtherwiseBranch.diff | 34 +++++----- ...h.before-SimplifyBranches-final.after.diff | 48 +++++++------- ...ch_68867.try_sum.EarlyOtherwiseBranch.diff | 48 +++++++------- ...nch_noopt.noopt1.EarlyOtherwiseBranch.diff | 20 +++--- ...nch_noopt.noopt2.EarlyOtherwiseBranch.diff | 12 ++-- ....match_tuple.SimplifyCfg-initial.after.mir | 12 ++-- ...float_to_exponential_common.ConstProp.diff | 6 +- ...comparison.SimplifyComparisonIntegral.diff | 12 ++-- .../mir-opt/issue_49232.main.mir_map.0.mir | 6 +- ...issue_62289.test.ElaborateDrops.before.mir | 4 +- ..._73223.main.SimplifyArmIdentity.32bit.diff | 4 +- ..._73223.main.SimplifyArmIdentity.64bit.diff | 4 +- ...e_75439.foo.MatchBranchSimplification.diff | 6 +- ...fg-initial.after-ElaborateDrops.after.diff | 20 +++--- ...s.full_tested_match.PromoteTemps.after.mir | 10 +-- ...full_tested_match2.PromoteTemps.before.mir | 10 +-- ...h_false_edges.main.PromoteTemps.before.mir | 12 ++-- ...ch_test.main.SimplifyCfg-initial.after.mir | 10 +-- ...s.bar.MatchBranchSimplification.32bit.diff | 14 ++--- ...s.bar.MatchBranchSimplification.64bit.diff | 14 ++--- ...s.foo.MatchBranchSimplification.32bit.diff | 12 ++-- ...s.foo.MatchBranchSimplification.64bit.diff | 12 ++-- ...ed_if.MatchBranchSimplification.32bit.diff | 4 +- ...ed_if.MatchBranchSimplification.64bit.diff | 4 +- ...match.MatchBranchSimplification.32bit.diff | 8 +-- ...match.MatchBranchSimplification.64bit.diff | 8 +-- ...ch_i8.MatchBranchSimplification.32bit.diff | 8 +-- ...ch_i8.MatchBranchSimplification.64bit.diff | 8 +-- ...wrap.SimplifyCfg-elaborate-drops.after.mir | 4 +- ...tch_guard.CleanupNonCodegenStatements.diff | 10 +-- ...age_markers.main.RemoveStorageMarkers.diff | 4 +- ...arate_const_switch.identity.ConstProp.diff | 16 ++--- ...t_switch.identity.SeparateConstSwitch.diff | 12 ++-- ...te_const_switch.too_complex.ConstProp.diff | 24 +++---- ...st_switch.too_complex.PreCodegen.after.mir | 8 +-- ...witch.too_complex.SeparateConstSwitch.diff | 26 ++++---- ...imple_match.match_bool.mir_map.0.32bit.mir | 6 +- ...imple_match.match_bool.mir_map.0.64bit.mir | 6 +- .../simplify_arm.id.SimplifyArmIdentity.diff | 8 +-- .../simplify_arm.id.SimplifyBranchSame.diff | 12 ++-- ...ify_arm.id_result.SimplifyArmIdentity.diff | 8 +-- ...lify_arm.id_result.SimplifyBranchSame.diff | 12 ++-- ...mplify_arm.id_try.SimplifyArmIdentity.diff | 4 +- ...implify_arm.id_try.SimplifyBranchSame.diff | 6 +- ...entity.main.SimplifyArmIdentity.32bit.diff | 8 +-- ...entity.main.SimplifyArmIdentity.64bit.diff | 8 +-- ..._locals_fixedpoint.foo.SimplifyLocals.diff | 8 +-- ...minant_reads.map.SimplifyLocals.32bit.diff | 6 +- ...minant_reads.map.SimplifyLocals.64bit.diff | 6 +- .../simplify_match.main.ConstProp.diff | 6 +- ...y.try_identity.DestinationPropagation.diff | 6 +- ..._try.try_identity.SimplifyArmIdentity.diff | 4 +- ....try_identity.SimplifyBranchSame.after.mir | 4 +- ...after-uninhabited-enum-branching.after.mir | 10 +-- ...anching.main.UninhabitedEnumBranching.diff | 20 +++--- ...after-uninhabited-enum-branching.after.mir | 16 ++--- ...nching2.main.UninhabitedEnumBranching.diff | 28 ++++----- ...oops.change_loop_body.ConstProp.32bit.diff | 2 +- ...oops.change_loop_body.ConstProp.64bit.diff | 2 +- .../borrowck/borrowck-anon-fields-variant.rs | 7 ++- .../borrowck-anon-fields-variant.stderr | 14 ++--- .../ui/borrowck/borrowck-describe-lvalue.rs | 2 +- .../borrowck/borrowck-describe-lvalue.stderr | 9 ++- .../borrowck-match-already-borrowed.rs | 4 +- .../borrowck-match-already-borrowed.stderr | 5 +- ...issue-27282-move-match-input-into-guard.rs | 2 +- ...e-27282-move-match-input-into-guard.stderr | 7 +-- ..._refers_to_static_cross_crate.32bit.stderr | 4 +- ..._refers_to_static_cross_crate.64bit.stderr | 4 +- src/test/ui/issues/issue-17385.rs | 4 +- src/test/ui/issues/issue-17385.stderr | 5 +- src/test/ui/nll/borrowed-match-issue-45045.rs | 2 +- .../ui/nll/borrowed-match-issue-45045.stderr | 8 +-- src/test/ui/nll/match-cfg-fake-edges2.rs | 4 +- src/test/ui/nll/match-cfg-fake-edges2.stderr | 8 +-- src/test/ui/nll/match-on-borrowed.rs | 9 ++- src/test/ui/nll/match-on-borrowed.stderr | 19 +++--- .../borrowck-non-exhaustive.rs | 2 +- .../borrowck-non-exhaustive.stderr | 5 +- src/test/ui/union/union-unsafe.mir.stderr | 4 +- 92 files changed, 533 insertions(+), 482 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index a36af024ad8d..7c4bdf1066a1 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -21,7 +21,7 @@ use rustc_middle::mir::*; use rustc_middle::thir::{self, *}; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc_span::symbol::Symbol; -use rustc_span::Span; +use rustc_span::{BytePos, Pos, Span}; use rustc_target::abi::VariantIdx; use smallvec::{smallvec, SmallVec}; @@ -143,8 +143,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let mut candidates = arm_candidates.iter_mut().map(|(_, candidate)| candidate).collect::>(); - let fake_borrow_temps = - self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates); + let match_start_span = span.shrink_to_lo().to(scrutinee.span); + + let fake_borrow_temps = self.lower_match_tree( + block, + scrutinee_span, + match_start_span, + match_has_guard, + &mut candidates, + ); self.lower_match_arms( destination, @@ -224,6 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, scrutinee_span: Span, + match_start_span: Span, match_has_guard: bool, candidates: &mut [&mut Candidate<'pat, 'tcx>], ) -> Vec<(Place<'tcx>, Local)> { @@ -236,7 +244,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // This will generate code to test scrutinee_place and // branch to the appropriate arm block - self.match_candidates(scrutinee_span, block, &mut otherwise, candidates, &mut fake_borrows); + self.match_candidates( + match_start_span, + scrutinee_span, + block, + &mut otherwise, + candidates, + &mut fake_borrows, + ); if let Some(otherwise_block) = otherwise { // See the doc comment on `match_candidates` for why we may have an @@ -339,8 +354,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // all the arm blocks will rejoin here let end_block = self.cfg.start_new_block(); + let end_brace = self.source_info( + outer_source_info.span.with_lo(outer_source_info.span.hi() - BytePos::from_usize(1)), + ); for arm_block in arm_end_blocks { - self.cfg.goto(unpack!(arm_block), outer_source_info, end_block); + let block = &self.cfg.basic_blocks[arm_block.0]; + let last_location = block.statements.last().map(|s| s.source_info); + + self.cfg.goto(unpack!(arm_block), last_location.unwrap_or(end_brace), end_block); } self.source_scope = outer_source_info.scope; @@ -533,8 +554,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { set_match_place: bool, ) -> BlockAnd<()> { let mut candidate = Candidate::new(initializer.clone(), &irrefutable_pat, false); - let fake_borrow_temps = - self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]); + let fake_borrow_temps = self.lower_match_tree( + block, + irrefutable_pat.span, + irrefutable_pat.span, + false, + &mut [&mut candidate], + ); // For matches and function arguments, the place that is being matched // can be set when creating the variables. But the place for // let PATTERN = ... might not even exist until we do the assignment. @@ -993,6 +1019,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn match_candidates<'pat>( &mut self, span: Span, + scrutinee_span: Span, start_block: BasicBlock, otherwise_block: &mut Option, candidates: &mut [&mut Candidate<'pat, 'tcx>], @@ -1022,6 +1049,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } self.match_simplified_candidates( span, + scrutinee_span, start_block, otherwise_block, &mut *new_candidates, @@ -1030,6 +1058,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } else { self.match_simplified_candidates( span, + scrutinee_span, start_block, otherwise_block, candidates, @@ -1042,6 +1071,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn match_simplified_candidates( &mut self, span: Span, + scrutinee_span: Span, start_block: BasicBlock, otherwise_block: &mut Option, candidates: &mut [&mut Candidate<'_, 'tcx>], @@ -1087,6 +1117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Test for the remaining candidates. self.test_candidates_with_or( span, + scrutinee_span, unmatched_candidates, block, otherwise_block, @@ -1257,6 +1288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn test_candidates_with_or( &mut self, span: Span, + scrutinee_span: Span, candidates: &mut [&mut Candidate<'_, 'tcx>], block: BasicBlock, otherwise_block: &mut Option, @@ -1269,7 +1301,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match *first_candidate.match_pairs[0].pattern.kind { PatKind::Or { .. } => (), _ => { - self.test_candidates(span, candidates, block, otherwise_block, fake_borrows); + self.test_candidates( + span, + scrutinee_span, + candidates, + block, + otherwise_block, + fake_borrows, + ); return; } } @@ -1302,6 +1341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.match_candidates( span, + scrutinee_span, remainder_start, otherwise_block, remaining_candidates, @@ -1330,6 +1370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { otherwise }; self.match_candidates( + or_span, or_span, candidate.pre_binding_block.unwrap(), otherwise, @@ -1497,6 +1538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn test_candidates<'pat, 'b, 'c>( &mut self, span: Span, + scrutinee_span: Span, mut candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>], block: BasicBlock, otherwise_block: &mut Option, @@ -1591,6 +1633,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let candidate_start = this.cfg.start_new_block(); this.match_candidates( span, + scrutinee_span, candidate_start, remainder_start, &mut *candidates, @@ -1607,6 +1650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let remainder_start = remainder_start.unwrap_or_else(|| this.cfg.start_new_block()); this.match_candidates( span, + scrutinee_span, remainder_start, otherwise_block, candidates, @@ -1617,7 +1661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { target_blocks }; - self.perform_test(block, match_place, &test, make_target_blocks); + self.perform_test(span, scrutinee_span, block, match_place, &test, make_target_blocks); } /// Determine the fake borrows that are needed from a set of places that @@ -1713,6 +1757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = self.lower_match_tree( block, pat.span, + pat.span, false, &mut [&mut guard_candidate, &mut otherwise_candidate], ); diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 42d062c93e9d..a01df2372a09 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -19,6 +19,7 @@ use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::symbol::{sym, Symbol}; +use rustc_span::Span; use rustc_target::abi::VariantIdx; use std::cmp::Ordering; @@ -151,6 +152,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub(super) fn perform_test( &mut self, + match_start_span: Span, + scrutinee_span: Span, block: BasicBlock, place_builder: PlaceBuilder<'tcx>, test: &Test<'tcx>, @@ -206,10 +209,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { debug!("num_enum_variants: {}, variants: {:?}", num_enum_variants, variants); let discr_ty = adt_def.repr.discr_type().to_ty(tcx); let discr = self.temp(discr_ty, test.span); - self.cfg.push_assign(block, source_info, discr, Rvalue::Discriminant(place)); + self.cfg.push_assign( + block, + self.source_info(scrutinee_span), + discr, + Rvalue::Discriminant(place), + ); self.cfg.terminate( block, - source_info, + self.source_info(match_start_span), TerminatorKind::SwitchInt { discr: Operand::Move(discr), switch_ty: discr_ty, @@ -246,7 +254,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { targets: switch_targets, } }; - self.cfg.terminate(block, source_info, terminator); + self.cfg.terminate(block, self.source_info(match_start_span), terminator); } TestKind::Eq { value, ty } => { diff --git a/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff b/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff index 28b8329606c1..1969d5e04040 100644 --- a/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff +++ b/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 + _2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:11:11: 11:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:11:5: 11:12 } bb1: { _0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15 - goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 + goto -> bb3; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15 } bb2: { discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27 - goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 + goto -> bb3; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27 } bb3: { diff --git a/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff b/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff index ddb9a8034e8b..0f64f7c09ab5 100644 --- a/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff +++ b/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff @@ -10,10 +10,10 @@ bb0: { - StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL -- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -+ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -+ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto.rs:12:22: 12:28 +- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20 +- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20 ++ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL } bb1: { diff --git a/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff b/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff index f0103fc42025..9ba02942b58b 100644 --- a/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff +++ b/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff @@ -10,35 +10,35 @@ StorageLive(_1); // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:11: 12:6 StorageLive(_2); // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:15: 8:16 _2 = const A; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:15: 8:16 - switchInt(_2) -> [1_i32: bb2, 2_i32: bb2, 3_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:13: 9:14 + switchInt(_2) -> [1_i32: bb2, 2_i32: bb2, 3_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 8:16 } bb1: { _1 = const true; // scope 0 at $DIR/const_goto_const_eval_fail.rs:10:18: 10:22 - goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 11:10 + goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:10:18: 10:22 } bb2: { _1 = const B; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:26: 9:27 -- goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 11:10 -+ switchInt(_1) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:9: 13:14 +- goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:26: 9:27 ++ switchInt(_1) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 12:6 } bb3: { -- switchInt(_1) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:9: 13:14 +- switchInt(_1) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 12:6 - } - - bb4: { _0 = const 2_u64; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 -- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 -+ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 +- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 ++ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 } - bb5: { + bb4: { _0 = const 1_u64; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 -- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 -+ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 +- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 ++ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 } - bb6: { diff --git a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff index 706cd63a73f6..bbfeb4dc392c 100644 --- a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff +++ b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff @@ -29,7 +29,7 @@ } bb2: { - switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:26: 11:30 + switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 } bb3: { diff --git a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff index 706cd63a73f6..bbfeb4dc392c 100644 --- a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff +++ b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff @@ -29,7 +29,7 @@ } bb2: { - switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:26: 11:30 + switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 } bb3: { diff --git a/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff b/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff index f51df7ae821c..f031a703a9d7 100644 --- a/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff @@ -8,8 +8,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 -- switchInt(_1) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 -+ switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(_1) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 ++ switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 } bb1: { diff --git a/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff b/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff index a444956ad1d0..6a5b88c4a7f0 100644 --- a/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff +++ b/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff @@ -8,8 +8,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 -- switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 -+ goto -> bb2; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 ++ goto -> bb2; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 } bb1: { diff --git a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff index b0c97f423781..48a37a8496cb 100644 --- a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff +++ b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff @@ -31,20 +31,20 @@ } bb1: { - switchInt((*_2)[0 of 4]) -> [47_u8: bb2, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:10: 4:14 + switchInt((*_2)[0 of 4]) -> [47_u8: bb2, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb2: { - switchInt((*_2)[1 of 4]) -> [47_u8: bb3, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:16: 4:20 + switchInt((*_2)[1 of 4]) -> [47_u8: bb3, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb3: { - switchInt((*_2)[2 of 4]) -> [47_u8: bb4, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:22: 4:26 + switchInt((*_2)[2 of 4]) -> [47_u8: bb4, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb4: { -- switchInt((*_2)[3 of 4]) -> [47_u8: bb10, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:28: 4:32 -+ switchInt((*_2)[3 of 4]) -> [47_u8: bb9, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:28: 4:32 +- switchInt((*_2)[3 of 4]) -> [47_u8: bb10, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 ++ switchInt((*_2)[3 of 4]) -> [47_u8: bb9, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb5: { @@ -54,39 +54,39 @@ } bb6: { - switchInt((*_2)[0 of 3]) -> [47_u8: bb7, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:10: 5:14 + switchInt((*_2)[0 of 3]) -> [47_u8: bb7, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb7: { - switchInt((*_2)[1 of 3]) -> [47_u8: bb8, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:16: 5:20 + switchInt((*_2)[1 of 3]) -> [47_u8: bb8, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb8: { -- switchInt((*_2)[2 of 3]) -> [47_u8: bb11, 33_u8: bb12, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:22: 5:26 -+ switchInt((*_2)[2 of 3]) -> [47_u8: bb10, 33_u8: bb10, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:22: 5:26 +- switchInt((*_2)[2 of 3]) -> [47_u8: bb11, 33_u8: bb12, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 ++ switchInt((*_2)[2 of 3]) -> [47_u8: bb10, 33_u8: bb10, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb9: { - _0 = const false; // scope 0 at $DIR/deduplicate_blocks.rs:7:14: 7:19 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:7:14: 7:19 - } - - bb10: { _0 = const false; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 -+ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 ++ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 } - bb11: { - _0 = const true; // scope 0 at $DIR/deduplicate_blocks.rs:5:35: 5:39 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:5:35: 5:39 - } - - bb12: { + bb10: { _0 = const true; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 -+ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 ++ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 } - bb13: { diff --git a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff index 386726bfddc7..c1591e5d7291 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff @@ -29,26 +29,26 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:4:16: 4:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:4:16: 4:17 - _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ _10 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 +- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ _10 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 } bb1: { + StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 -- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 } bb2: { -- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 -- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 +- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 - } - - bb3: { @@ -59,8 +59,8 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:5:31: 5:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 -- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 } - bb4: { diff --git a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff index bc5934dec84e..b949d307e20e 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff @@ -30,31 +30,31 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:12:16: 12:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:12:16: 12:17 - _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -- switchInt(move _8) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ _11 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _8) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ _11 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 } bb1: { -- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 -- switchInt(move _6) -> [0_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _6) -> [0_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 - } - - bb2: { + StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 } - bb3: { -- _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:19: 13:26 -- switchInt(move _7) -> [1_isize: bb4, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:13:19: 13:26 +- _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _7) -> [1_isize: bb4, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 - } - - bb4: { @@ -66,15 +66,15 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 } - bb5: { + bb3: { _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 } - bb6: { diff --git a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff index b0357f1aecd6..5b9ec1e53d94 100644 --- a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff @@ -40,33 +40,33 @@ StorageDead(_7); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 - _10 = discriminant((_4.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -- switchInt(move _10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageLive(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ _14 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + _10 = discriminant((_4.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageLive(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ _14 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 } bb1: { + StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 + StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 -- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 +- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 } bb2: { -- _9 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 -- switchInt(move _9) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 +- _9 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _9) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 - } - - bb3: { - _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 -- switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 -+ switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 + _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 } - bb4: { @@ -81,8 +81,8 @@ StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 -- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 +- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 } - bb5: { diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff index 2893ee9ac334..f23d035545ee 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff @@ -80,19 +80,19 @@ StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 + _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 } bb1: { -- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 -- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 +- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb2: { @@ -126,12 +126,12 @@ + nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + } + bb3: { -- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 +- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 + _20 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -149,12 +149,12 @@ + nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 } bb4: { -- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 -- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 +- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:16: 24:19 + _25 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:16: 24:19 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:28: 24:33 @@ -172,12 +172,12 @@ + nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 } bb5: { -- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 +- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + _30 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 @@ -195,7 +195,7 @@ + nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 } bb6: { @@ -216,7 +216,7 @@ - StorageDead(_14); // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 - StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 - StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:5: 27:7 + discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:5: 27:7 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:27:6: 27:7 @@ -242,7 +242,7 @@ - StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - } - - bb8: { @@ -263,7 +263,7 @@ - StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - } - - bb9: { @@ -284,7 +284,7 @@ - StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - } - - bb10: { diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff index 9039989e0f28..af32d4d2d149 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff @@ -66,19 +66,19 @@ (_4.1: &ViewportPercentageLength) = move _6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 + _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 } bb1: { -- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 -- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 +- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb2: { @@ -93,18 +93,18 @@ } - bb3: { -- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 +- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb4: { -- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 -- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 +- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb5: { -- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 +- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb6: { @@ -126,8 +126,8 @@ StorageDead(_14); // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 } - bb7: { @@ -149,8 +149,8 @@ StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 } - bb8: { @@ -172,8 +172,8 @@ StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 } - bb9: { @@ -195,8 +195,8 @@ StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 } - bb10: { diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff index 9a6094f12dfb..5343f22d3da3 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff @@ -36,23 +36,23 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 - _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 - switchInt(move _8) -> [0_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _8) -> [0_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb1: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 - switchInt(move _6) -> [0_isize: bb2, otherwise: bb6]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 + _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _6) -> [0_isize: bb2, otherwise: bb6]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb2: { _0 = const 3_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:12:25: 12:26 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:12:25: 12:26 } bb3: { - _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 - switchInt(move _7) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 + _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _7) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb4: { @@ -63,7 +63,7 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 } bb5: { @@ -71,7 +71,7 @@ _11 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:15: 10:16 _0 = const 1_u32; // scope 2 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 } bb6: { @@ -79,7 +79,7 @@ _12 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:21: 11:22 _0 = const 2_u32; // scope 3 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 } bb7: { diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff index c3aecb452935..66ea828bf682 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff @@ -27,18 +27,18 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 - _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 - switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 + _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 + switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 19:17 } bb1: { _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:21:14: 21:15 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 + goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:21:14: 21:15 } bb2: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 - switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 + _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 + switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 19:17 } bb3: { @@ -49,7 +49,7 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 + goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 } bb4: { diff --git a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir index 93507879a6f8..6b7b3db05419 100644 --- a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir @@ -19,21 +19,21 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/exponential-or.rs:5:11: 5:12 - switchInt((_1.0: u32)) -> [1_u32: bb2, 4_u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:15: 6:16 + switchInt((_1.0: u32)) -> [1_u32: bb2, 4_u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:15: 6:20 } bb1: { _0 = const 0_u32; // scope 0 at $DIR/exponential-or.rs:7:14: 7:15 - goto -> bb10; // scope 0 at $DIR/exponential-or.rs:5:5: 8:6 + goto -> bb10; // scope 0 at $DIR/exponential-or.rs:7:14: 7:15 } bb2: { - _2 = discriminant((_1.2: std::option::Option)); // scope 0 at $DIR/exponential-or.rs:6:37: 6:48 - switchInt(move _2) -> [0_isize: bb4, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:48 + _2 = discriminant((_1.2: std::option::Option)); // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 + switchInt(move _2) -> [0_isize: bb4, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 } bb3: { - switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1_i32: bb4, 8_i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:42: 6:43 + switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1_i32: bb4, 8_i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 } bb4: { @@ -74,7 +74,7 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { StorageDead(_9); // scope 1 at $DIR/exponential-or.rs:6:87: 6:88 StorageDead(_8); // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 StorageDead(_7); // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 - goto -> bb10; // scope 0 at $DIR/exponential-or.rs:5:5: 8:6 + goto -> bb10; // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 } bb10: { diff --git a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff index a7e4a131bfb7..44167ac0c482 100644 --- a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff +++ b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff @@ -47,17 +47,17 @@ bb1: { StorageDead(_5); // scope 0 at $DIR/funky_arms.rs:15:36: 15:37 StorageLive(_6); // scope 1 at $DIR/funky_arms.rs:19:9: 19:13 - switchInt(_4) -> [false: bb3, otherwise: bb2]; // scope 1 at $DIR/funky_arms.rs:20:9: 20:14 + switchInt(_4) -> [false: bb3, otherwise: bb2]; // scope 1 at $DIR/funky_arms.rs:19:16: 19:32 } bb2: { discriminant(_6) = 1; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41 - goto -> bb4; // scope 1 at $DIR/funky_arms.rs:19:16: 22:6 + goto -> bb4; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41 } bb3: { discriminant(_6) = 0; // scope 1 at $DIR/funky_arms.rs:20:18: 20:38 - goto -> bb4; // scope 1 at $DIR/funky_arms.rs:19:16: 22:6 + goto -> bb4; // scope 1 at $DIR/funky_arms.rs:20:18: 20:38 } bb4: { diff --git a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff index b590be5370f1..fd4dcb2265e6 100644 --- a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff +++ b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff @@ -20,14 +20,14 @@ _3 = _1; // scope 0 at $DIR/if-condition-int.rs:44:13: 44:14 - _2 = Eq(move _3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20 - StorageDead(_3); // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20 -- switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 +- switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 + _2 = Eq(_3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20 + nop; // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20 -+ switchInt(move _3) -> [17_i8: bb1, otherwise: bb2]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ switchInt(move _3) -> [17_i8: bb1, otherwise: bb2]; // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 } bb1: { -+ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 StorageLive(_6); // scope 1 at $DIR/if-condition-int.rs:47:23: 47:31 StorageLive(_7); // scope 1 at $DIR/if-condition-int.rs:47:23: 47:24 _7 = _2; // scope 1 at $DIR/if-condition-int.rs:47:23: 47:24 @@ -35,11 +35,11 @@ StorageDead(_7); // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 _0 = Add(const 100_i32, move _6); // scope 1 at $DIR/if-condition-int.rs:47:17: 47:31 StorageDead(_6); // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 - goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:45:5: 48:6 + goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 } bb2: { -+ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 StorageLive(_4); // scope 1 at $DIR/if-condition-int.rs:46:23: 46:31 StorageLive(_5); // scope 1 at $DIR/if-condition-int.rs:46:23: 46:24 _5 = _2; // scope 1 at $DIR/if-condition-int.rs:46:23: 46:24 @@ -47,7 +47,7 @@ StorageDead(_5); // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 _0 = Add(const 10_i32, move _4); // scope 1 at $DIR/if-condition-int.rs:46:18: 46:31 StorageDead(_4); // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 - goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:45:5: 48:6 + goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 } bb3: { diff --git a/src/test/mir-opt/issue_49232.main.mir_map.0.mir b/src/test/mir-opt/issue_49232.main.mir_map.0.mir index 06fbbda3d9e2..2f8931382a69 100644 --- a/src/test/mir-opt/issue_49232.main.mir_map.0.mir +++ b/src/test/mir-opt/issue_49232.main.mir_map.0.mir @@ -25,7 +25,7 @@ fn main() -> () { StorageLive(_3); // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 _3 = const true; // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 FakeRead(ForMatchedPlace(None), _3); // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 - switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/issue-49232.rs:9:17: 9:22 + switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/issue-49232.rs:8:13: 8:23 } bb3: { @@ -39,7 +39,7 @@ fn main() -> () { bb5: { _2 = const 4_i32; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 - goto -> bb8; // scope 0 at $DIR/issue-49232.rs:8:13: 11:14 + goto -> bb8; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 } bb6: { @@ -47,7 +47,7 @@ fn main() -> () { } bb7: { - goto -> bb8; // scope 0 at $DIR/issue-49232.rs:8:13: 11:14 + goto -> bb8; // scope 0 at $DIR/issue-49232.rs:11:13: 11:14 } bb8: { diff --git a/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir b/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir index ba17a45f984e..95efa74289d8 100644 --- a/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir +++ b/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir @@ -37,8 +37,8 @@ fn test() -> Option> { bb1: { StorageDead(_4); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 - _5 = discriminant(_3); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 - switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 + _5 = discriminant(_3); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20 + switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20 } bb2: { diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index ff8c410a7268..a544f0f4b62a 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -53,8 +53,8 @@ StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 - goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:2:17: 2:30 } bb1: { diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index ff8c410a7268..a544f0f4b62a 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -53,8 +53,8 @@ StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 - goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:2:17: 2:30 } bb1: { diff --git a/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff b/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff index 89ba5eeeef4e..0d19b3d459eb 100644 --- a/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff +++ b/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff @@ -32,15 +32,15 @@ bb1: { StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:7:52: 7:53 - switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:13: 9:14 + switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb2: { - switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:16: 9:17 + switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb3: { - switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:19: 9:20 + switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb4: { diff --git a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff index feb25035ee0e..f756b6bbf3d5 100644 --- a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -32,18 +32,18 @@ bb0: { - FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 -- switchInt((_2.0: bool)) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:15:10: 15:15 -+ switchInt((_2.0: bool)) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/match-arm-scopes.rs:15:10: 15:15 +- switchInt((_2.0: bool)) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 ++ switchInt((_2.0: bool)) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb1: { - falseEdge -> [real: bb8, imaginary: bb3]; // scope 0 at $DIR/match-arm-scopes.rs:15:9: 15:22 -+ switchInt((_2.1: bool)) -> [false: bb10, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:15:29: 15:34 ++ switchInt((_2.1: bool)) -> [false: bb10, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb2: { -- switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/match-arm-scopes.rs:15:29: 15:34 -+ switchInt((_2.0: bool)) -> [false: bb3, otherwise: bb17]; // scope 0 at $DIR/match-arm-scopes.rs:16:10: 16:14 +- switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 ++ switchInt((_2.0: bool)) -> [false: bb3, otherwise: bb17]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb3: { @@ -51,7 +51,7 @@ - } - - bb4: { -- switchInt((_2.0: bool)) -> [false: bb6, otherwise: bb5]; // scope 0 at $DIR/match-arm-scopes.rs:16:10: 16:14 +- switchInt((_2.0: bool)) -> [false: bb6, otherwise: bb5]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 - } - - bb5: { @@ -192,8 +192,8 @@ StorageDead(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 -- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 -+ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 +- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 ++ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 } - bb19: { @@ -217,8 +217,8 @@ + bb18: { StorageDead(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 StorageDead(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 -- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 -+ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 +- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 ++ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 } - bb22: { diff --git a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir index c27ee528b80b..a2fa39d365a0 100644 --- a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir @@ -28,13 +28,13 @@ fn full_tested_match() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 _2 = Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 - _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 - switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 + _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 + switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:15:13: 15:27 } bb1: { _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 } bb2: { @@ -83,7 +83,7 @@ fn full_tested_match() -> () { StorageDead(_8); // scope 2 at $DIR/match_false_edges.rs:16:36: 16:37 StorageDead(_5); // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 } bb8: { @@ -100,7 +100,7 @@ fn full_tested_match() -> () { _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:17:20: 17:26 StorageDead(_10); // scope 3 at $DIR/match_false_edges.rs:17:25: 17:26 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:17:25: 17:26 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:17:25: 17:26 } bb10: { diff --git a/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir index a4ebf8a02466..9913d179edde 100644 --- a/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir @@ -27,8 +27,8 @@ fn full_tested_match2() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 _2 = Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 - _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 - switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 + _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 + switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:26:13: 26:27 } bb1: { @@ -47,7 +47,7 @@ fn full_tested_match2() -> () { _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:29:20: 29:26 StorageDead(_10); // scope 3 at $DIR/match_false_edges.rs:29:25: 29:26 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:29:25: 29:26 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:29:25: 29:26 } bb4: { @@ -81,7 +81,7 @@ fn full_tested_match2() -> () { StorageDead(_8); // scope 2 at $DIR/match_false_edges.rs:27:36: 27:37 StorageDead(_5); // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 } bb8: { @@ -92,7 +92,7 @@ fn full_tested_match2() -> () { bb9: { _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 } bb10: { diff --git a/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir index 5de52b324f43..9113d9d31894 100644 --- a/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir @@ -38,8 +38,8 @@ fn main() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 _2 = Option::::Some(const 1_i32); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 - _4 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 - switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 + _4 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 + switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/match_false_edges.rs:35:13: 35:26 } bb1: { @@ -55,7 +55,7 @@ fn main() -> () { _14 = _2; // scope 0 at $DIR/match_false_edges.rs:39:9: 39:11 _1 = const 4_i32; // scope 5 at $DIR/match_false_edges.rs:39:15: 39:16 StorageDead(_14); // scope 0 at $DIR/match_false_edges.rs:39:15: 39:16 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:39:15: 39:16 } bb4: { @@ -86,7 +86,7 @@ fn main() -> () { _1 = const 1_i32; // scope 2 at $DIR/match_false_edges.rs:36:32: 36:33 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 StorageDead(_7); // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 } bb8: { @@ -100,7 +100,7 @@ fn main() -> () { _9 = _2; // scope 0 at $DIR/match_false_edges.rs:37:9: 37:11 _1 = const 2_i32; // scope 3 at $DIR/match_false_edges.rs:37:15: 37:16 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:37:15: 37:16 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:37:15: 37:16 } bb10: { @@ -130,7 +130,7 @@ fn main() -> () { _1 = const 3_i32; // scope 4 at $DIR/match_false_edges.rs:38:33: 38:34 StorageDead(_10); // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 StorageDead(_11); // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 } bb13: { diff --git a/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir b/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir index 5bb910947ca2..4dab5b4c1ef9 100644 --- a/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir @@ -42,7 +42,7 @@ fn main() -> () { bb3: { _3 = const 3_i32; // scope 2 at $DIR/match_test.rs:16:14: 16:15 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:16:14: 16:15 } bb4: { @@ -60,7 +60,7 @@ fn main() -> () { } bb7: { - switchInt(_1) -> [-1_i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:15:9: 15:11 + switchInt(_1) -> [-1_i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:12:5: 12:12 } bb8: { @@ -78,7 +78,7 @@ fn main() -> () { StorageDead(_9); // scope 2 at $DIR/match_test.rs:13:23: 13:24 FakeRead(ForMatchGuard, _8); // scope 2 at $DIR/match_test.rs:13:18: 13:19 _3 = const 0_i32; // scope 2 at $DIR/match_test.rs:13:23: 13:24 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:13:23: 13:24 } bb11: { @@ -88,12 +88,12 @@ fn main() -> () { bb12: { _3 = const 1_i32; // scope 2 at $DIR/match_test.rs:14:20: 14:21 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:14:20: 14:21 } bb13: { _3 = const 2_i32; // scope 2 at $DIR/match_test.rs:15:15: 15:16 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:15:15: 15:16 } bb14: { diff --git a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff index a52c6ae351b2..d164f62c580f 100644 --- a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff @@ -10,7 +10,7 @@ let mut _8: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:9: 36:10 let mut _9: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:12: 36:13 let mut _10: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:15: 36:16 -+ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:19:5: 19:12 scope 1 { debug a => _2; // in scope 1 at $DIR/matches_reduce_branches.rs:14:9: 14:10 let _3: bool; // in scope 1 at $DIR/matches_reduce_branches.rs:15:9: 15:10 @@ -33,7 +33,7 @@ StorageLive(_4); // scope 2 at $DIR/matches_reduce_branches.rs:16:9: 16:10 StorageLive(_5); // scope 3 at $DIR/matches_reduce_branches.rs:17:9: 17:10 StorageLive(_6); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 -- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 +- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 - } - - bb1: { @@ -41,23 +41,23 @@ - _3 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:29:13: 29:22 - _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:30:13: 30:22 - _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:31:13: 31:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:32:13: 32:15 - } - - bb2: { - _2 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 - _3 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 -+ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 -+ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 ++ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 + _2 = Ne(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 + _3 = Eq(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:23:13: 23:22 _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:24:13: 24:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:25:13: 25:15 - } - - bb3: { -+ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 StorageDead(_6); // scope 4 at $DIR/matches_reduce_branches.rs:34:6: 34:7 StorageLive(_7); // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 _7 = _2; // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 diff --git a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff index a52c6ae351b2..d164f62c580f 100644 --- a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff @@ -10,7 +10,7 @@ let mut _8: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:9: 36:10 let mut _9: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:12: 36:13 let mut _10: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:15: 36:16 -+ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:19:5: 19:12 scope 1 { debug a => _2; // in scope 1 at $DIR/matches_reduce_branches.rs:14:9: 14:10 let _3: bool; // in scope 1 at $DIR/matches_reduce_branches.rs:15:9: 15:10 @@ -33,7 +33,7 @@ StorageLive(_4); // scope 2 at $DIR/matches_reduce_branches.rs:16:9: 16:10 StorageLive(_5); // scope 3 at $DIR/matches_reduce_branches.rs:17:9: 17:10 StorageLive(_6); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 -- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 +- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 - } - - bb1: { @@ -41,23 +41,23 @@ - _3 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:29:13: 29:22 - _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:30:13: 30:22 - _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:31:13: 31:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:32:13: 32:15 - } - - bb2: { - _2 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 - _3 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 -+ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 -+ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 ++ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 + _2 = Ne(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 + _3 = Eq(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:23:13: 23:22 _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:24:13: 24:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:25:13: 25:15 - } - - bb3: { -+ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 StorageDead(_6); // scope 4 at $DIR/matches_reduce_branches.rs:34:6: 34:7 StorageLive(_7); // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 _7 = _2; // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff index 96b03477d010..29f66ceac981 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff @@ -5,11 +5,11 @@ debug bar => _1; // in scope 0 at $DIR/matches_reduce_branches.rs:7:8: 7:11 let mut _0: (); // return place in scope 0 at $DIR/matches_reduce_branches.rs:7:25: 7:25 let mut _2: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ let mut _3: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ let mut _3: isize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 + _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:17: 8:20 +- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - } - - bb1: { @@ -21,9 +21,9 @@ - } - - bb3: { -+ StorageLive(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ _3 = move _2; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ StorageLive(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _3 = move _2; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ StorageDead(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL return; // scope 0 at $DIR/matches_reduce_branches.rs:11:2: 11:2 } } diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff index 96b03477d010..29f66ceac981 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff @@ -5,11 +5,11 @@ debug bar => _1; // in scope 0 at $DIR/matches_reduce_branches.rs:7:8: 7:11 let mut _0: (); // return place in scope 0 at $DIR/matches_reduce_branches.rs:7:25: 7:25 let mut _2: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ let mut _3: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ let mut _3: isize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 + _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:17: 8:20 +- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - } - - bb1: { @@ -21,9 +21,9 @@ - } - - bb3: { -+ StorageLive(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ _3 = move _2; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ StorageLive(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _3 = move _2; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ StorageDead(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL return; // scope 0 at $DIR/matches_reduce_branches.rs:11:2: 11:2 } } diff --git a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff index 410320e643ca..4ce1b57b9a3a 100644 --- a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff @@ -90,13 +90,13 @@ + _10 = move _3; // scope 0 at $DIR/matches_reduce_branches.rs:41:15: 45:10 StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const true; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 - } - - bb11: { - StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const false; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 - } - - bb12: { diff --git a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff index 410320e643ca..4ce1b57b9a3a 100644 --- a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff @@ -90,13 +90,13 @@ + _10 = move _3; // scope 0 at $DIR/matches_reduce_branches.rs:41:15: 45:10 StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const true; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 - } - - bb11: { - StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const false; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 - } - - bb12: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff index 9fde4888809d..711cc31f49f9 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:13:9: 13:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:12:11: 12:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12 } bb1: { _0 = const 1_u8; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 } bb2: { _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff index 9fde4888809d..711cc31f49f9 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:13:9: 13:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:12:11: 12:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12 } bb1: { _0 = const 1_u8; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 } bb2: { _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff index 2dd0a3edb479..6bdeccbf913e 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:21:9: 21:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:20:11: 20:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12 } bb1: { _0 = const 1_i8; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 } bb2: { _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff index 2dd0a3edb479..6bdeccbf913e 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:21:9: 21:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:20:11: 20:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12 } bb1: { _0 = const 1_i8; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 } bb2: { _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 } bb3: { diff --git a/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir index 8a1134478d6b..cc4457cc5f3f 100644 --- a/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir @@ -14,8 +14,8 @@ fn unwrap(_1: Option) -> T { } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 - switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 + _2 = discriminant(_1); // scope 0 at $DIR/no-drop-for-inactive-variant.rs:8:11: 8:14 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:8:5: 8:14 } bb1: { diff --git a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff index 4aa388fc67bd..52b5611e905f 100644 --- a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff +++ b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff @@ -15,17 +15,17 @@ bb0: { - FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 - _3 = discriminant(_1); // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 - switchInt(move _3) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 + _3 = discriminant(_1); // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 + switchInt(move _3) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 7:12 } bb1: { _0 = const 1_i32; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 - goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 10:6 + goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 } bb2: { - switchInt((*(*((_1 as Some).0: &&i32)))) -> [0_i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:14: 8:15 + switchInt((*(*((_1 as Some).0: &&i32)))) -> [0_i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 7:12 } bb3: { @@ -57,7 +57,7 @@ + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 _0 = const 0_i32; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 - goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 10:6 + goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 } bb6: { diff --git a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff index 80024124dc52..6d6c2721973f 100644 --- a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff +++ b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff @@ -115,8 +115,8 @@ bb4: { - StorageDead(_18); // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19 - StorageDead(_9); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19 - _11 = discriminant(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10 - switchInt(move _11) -> [0_isize: bb2, otherwise: bb3]; // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10 + _11 = discriminant(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19 + switchInt(move _11) -> [0_isize: bb2, otherwise: bb3]; // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19 } } diff --git a/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff b/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff index 57299cee7b72..d5190cdb0c7d 100644 --- a/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff +++ b/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff @@ -110,10 +110,10 @@ StorageDead(_13); // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(const 1_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ _5 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(const 1_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } bb4: { @@ -131,10 +131,10 @@ StorageDead(_11); // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(const 0_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ _5 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(const 0_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } } diff --git a/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff b/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff index 4bfd0842db08..69f3bec6fea2 100644 --- a/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff +++ b/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff @@ -64,8 +64,8 @@ bb1: { - StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 - StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 - } - - bb2: { @@ -121,8 +121,8 @@ - goto -> bb1; // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 ++ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } - bb5: { @@ -143,8 +143,8 @@ - goto -> bb1; // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 ++ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } } diff --git a/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff b/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff index 973b7838eca3..5316c34fb37d 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff +++ b/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff @@ -29,8 +29,8 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -42,10 +42,10 @@ discriminant(_2) = 1; // scope 2 at $DIR/separate_const_switch.rs:17:23: 17:44 StorageDead(_7); // scope 2 at $DIR/separate_const_switch.rs:17:43: 17:44 StorageDead(_6); // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 -- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ _8 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(const 1_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ _8 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(const 1_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb2: { @@ -57,10 +57,10 @@ discriminant(_2) = 0; // scope 1 at $DIR/separate_const_switch.rs:16:22: 16:46 StorageDead(_5); // scope 1 at $DIR/separate_const_switch.rs:16:45: 16:46 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 -- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ _8 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(const 0_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ _8 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(const 0_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb3: { @@ -68,7 +68,7 @@ _11 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_11); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 - goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } bb4: { @@ -80,7 +80,7 @@ discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_10); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_9); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 - goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } bb5: { diff --git a/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir b/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir index cc941f251cea..38ad12157e27 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir +++ b/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir @@ -27,8 +27,8 @@ fn too_complex(_1: Result) -> Option { bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -44,7 +44,7 @@ fn too_complex(_1: Result) -> Option { _10 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 - goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } bb2: { @@ -64,7 +64,7 @@ fn too_complex(_1: Result) -> Option { discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_9); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_8); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 - goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } bb3: { diff --git a/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff b/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff index ce32227ed653..0b5b9a490c62 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff +++ b/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff @@ -29,8 +29,8 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -42,9 +42,9 @@ discriminant(_2) = 1; // scope 2 at $DIR/separate_const_switch.rs:17:23: 17:44 StorageDead(_7); // scope 2 at $DIR/separate_const_switch.rs:17:43: 17:44 StorageDead(_6); // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 -- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:15:9: 18:10 -+ _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 ++ _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb2: { @@ -56,13 +56,13 @@ discriminant(_2) = 0; // scope 1 at $DIR/separate_const_switch.rs:16:22: 16:46 StorageDead(_5); // scope 1 at $DIR/separate_const_switch.rs:16:45: 16:46 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 -- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:15:9: 18:10 +- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 - } - - bb3: { - _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 + _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } - bb4: { @@ -71,8 +71,8 @@ _11 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_11); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 -- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 -+ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 +- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 ++ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } - bb5: { @@ -85,8 +85,8 @@ discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_10); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_9); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 -- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 -+ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 +- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 ++ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } - bb6: { diff --git a/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir b/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir index 841cca7c381f..c189c18d2d0e 100644 --- a/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir +++ b/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir @@ -6,7 +6,7 @@ fn match_bool(_1: bool) -> usize { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/simple-match.rs:6:11: 6:12 - switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:7:9: 7:13 + switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:6:5: 6:12 } bb1: { @@ -15,12 +15,12 @@ fn match_bool(_1: bool) -> usize { bb2: { _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 } bb3: { _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 } bb4: { diff --git a/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir b/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir index 841cca7c381f..c189c18d2d0e 100644 --- a/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir +++ b/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir @@ -6,7 +6,7 @@ fn match_bool(_1: bool) -> usize { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/simple-match.rs:6:11: 6:12 - switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:7:9: 7:13 + switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:6:5: 6:12 } bb1: { @@ -15,12 +15,12 @@ fn match_bool(_1: bool) -> usize { bb2: { _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 } bb3: { _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff index e390662307e0..ad47891294a0 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff @@ -13,13 +13,13 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 } bb1: { discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 } bb2: { @@ -36,7 +36,7 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff index 81a0e6ba0b4e..52c036a77007 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff @@ -12,14 +12,14 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 +- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 } bb1: { - discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - } - - bb2: { @@ -28,8 +28,8 @@ - - bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 -+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 ++ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 } - bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff index 40c18fb7282e..b24bdea9b715 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff @@ -19,8 +19,8 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 } bb1: { @@ -33,7 +33,7 @@ - StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 - StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 + _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 } bb2: { @@ -50,7 +50,7 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff index 596dbabead0b..4d6a4edb08ae 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff @@ -17,14 +17,14 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -- switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 +- switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 } bb1: { - _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 - } - - bb2: { @@ -33,8 +33,8 @@ - - bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 -+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 ++ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 } - bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index a3bad4f0c623..272a6756f39f 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -45,8 +45,8 @@ _4 = _1; // scope 0 at $DIR/simplify-arm.rs:36:31: 36:32 _3 = move _4; // scope 4 at $DIR/simplify-arm.rs:36:19: 36:33 StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:36:32: 36:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 - switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:36:19: 36:33 + switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 } bb1: { diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index b6b7511b3f59..651a37f5a972 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -40,9 +40,9 @@ _4 = _1; // scope 0 at $DIR/simplify-arm.rs:36:31: 36:32 _3 = move _4; // scope 4 at $DIR/simplify-arm.rs:36:19: 36:33 StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:36:32: 36:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 -- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:36:19: 36:33 +- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 } bb1: { diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff index 7495b0d407d2..512d9fe172b9 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff @@ -22,14 +22,14 @@ ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 19:25 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 } bb2: { @@ -45,7 +45,7 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 } bb4: { diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff index 7495b0d407d2..512d9fe172b9 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff @@ -22,14 +22,14 @@ ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 19:25 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 } bb2: { @@ -45,7 +45,7 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 } bb4: { diff --git a/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff index 41a6fe30412d..381f4056cc87 100644 --- a/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff @@ -25,13 +25,13 @@ (_1.1: std::option::Option) = move _3; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69 StorageDead(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 StorageDead(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 - _5 = discriminant((_1.0: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 - switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 + _5 = discriminant((_1.0: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 + switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 } bb1: { - _4 = discriminant((_1.1: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 - switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 + _4 = discriminant((_1.1: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 + switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 } bb2: { diff --git a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff index 760fb747f722..e139eedf3a0d 100644 --- a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff +++ b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff @@ -15,9 +15,9 @@ } bb0: { -- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 +- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27 - _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2 return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2 diff --git a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff index 760fb747f722..e139eedf3a0d 100644 --- a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff +++ b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff @@ -15,9 +15,9 @@ } bb0: { -- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 +- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27 - _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2 return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2 diff --git a/src/test/mir-opt/simplify_match.main.ConstProp.diff b/src/test/mir-opt/simplify_match.main.ConstProp.diff index 3f5efcffc199..1c8d043a6030 100644 --- a/src/test/mir-opt/simplify_match.main.ConstProp.diff +++ b/src/test/mir-opt/simplify_match.main.ConstProp.diff @@ -16,13 +16,13 @@ - _1 = _2; // scope 1 at $DIR/simplify_match.rs:6:28: 6:29 + _1 = const false; // scope 1 at $DIR/simplify_match.rs:6:28: 6:29 StorageDead(_2); // scope 0 at $DIR/simplify_match.rs:6:30: 6:31 -- switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:7:9: 7:13 -+ switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:7:9: 7:13 +- switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:6:5: 6:31 ++ switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:6:5: 6:31 } bb1: { nop; // scope 0 at $DIR/simplify_match.rs:8:18: 8:20 - goto -> bb3; // scope 0 at $DIR/simplify_match.rs:6:5: 9:6 + goto -> bb3; // scope 0 at $DIR/simplify_match.rs:8:18: 8:20 } bb2: { diff --git a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff index e09b8cb39bd5..a6ea8cacfd2c 100644 --- a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff +++ b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff @@ -41,14 +41,14 @@ - _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 - _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 - StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 -- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 +- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 + _0 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 + nop; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 -+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - goto -> bb1; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 ++ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff index 488ad33f80a2..bef57548005c 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff @@ -45,8 +45,8 @@ _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir index 5d829f859e9d..aa19c479881a 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir @@ -39,8 +39,8 @@ fn try_identity(_1: Result) -> Result { _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - goto -> bb1; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index 17dcc99bc0c6..bdcb9357308e 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -16,7 +16,7 @@ fn main() -> () { StorageLive(_1); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 - _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 StorageLive(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 _5 = const "C"; // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 // ty::Const @@ -32,8 +32,8 @@ fn main() -> () { StorageLive(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 - _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 26:19 } bb1: { @@ -47,7 +47,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 } bb2: { @@ -58,7 +58,7 @@ fn main() -> () { // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 } bb3: { diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff index 9ae7a9d7384c..d8410caa7cd5 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff @@ -17,9 +17,9 @@ StorageLive(_1); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 - _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -+ switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 +- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 20:19 ++ switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 20:19 } bb1: { @@ -33,7 +33,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _1 = &(*_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 StorageDead(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:23: 23:24 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:23:23: 23:24 } bb2: { @@ -44,7 +44,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:21:24: 21:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:24: 21:34 } bb3: { @@ -58,7 +58,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _1 = &(*_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:24: 22:34 StorageDead(_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:33: 22:34 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:22:33: 22:34 } bb4: { @@ -67,8 +67,8 @@ StorageLive(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 - _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 26:19 } bb5: { @@ -82,7 +82,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 } bb6: { @@ -93,7 +93,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 } bb7: { diff --git a/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index 373be9f174b2..e20faa524749 100644 --- a/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -29,8 +29,8 @@ fn main() -> () { StorageLive(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 StorageLive(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 _4 = &(_1.1: Test1); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 - _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 - switchInt(move _5) -> [2_isize: bb2, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 + _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 + switchInt(move _5) -> [2_isize: bb2, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 } bb1: { @@ -44,7 +44,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:21: 25:24 StorageDead(_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 - goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 } bb2: { @@ -58,15 +58,15 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:21: 24:24 StorageDead(_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 - goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 } bb3: { StorageDead(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageDead(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageLive(_9); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 - _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 - switchInt(move _10) -> [2_isize: bb5, otherwise: bb4]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 + _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:11: 28:21 + switchInt(move _10) -> [2_isize: bb5, otherwise: bb4]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 } bb4: { @@ -80,7 +80,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:21: 32:24 StorageDead(_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 - goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 } bb5: { @@ -94,7 +94,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:21: 31:24 StorageDead(_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 - goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 } bb6: { diff --git a/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff index f9488bae4c83..77507ef1ee02 100644 --- a/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff @@ -30,9 +30,9 @@ StorageLive(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 StorageLive(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 _4 = &(_1.1: Test1); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 - _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 -- switchInt(move _5) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 -+ switchInt(move _5) -> [2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 + _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 +- switchInt(move _5) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 ++ switchInt(move _5) -> [2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 } bb1: { @@ -46,7 +46,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:21: 25:24 StorageDead(_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 } bb2: { @@ -57,7 +57,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching2.rs:22:24: 22:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:24: 22:34 } bb3: { @@ -71,7 +71,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _3 = &(*_6); // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:24: 23:34 StorageDead(_6); // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:33: 23:34 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:33: 23:34 } bb4: { @@ -85,16 +85,16 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:21: 24:24 StorageDead(_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 } bb5: { StorageDead(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageDead(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageLive(_9); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 - _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 -- switchInt(move _10) -> [0_isize: bb7, 1_isize: bb8, 2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 -+ switchInt(move _10) -> [2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 + _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:11: 28:21 +- switchInt(move _10) -> [0_isize: bb7, 1_isize: bb8, 2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 ++ switchInt(move _10) -> [2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 } bb6: { @@ -108,7 +108,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:21: 32:24 StorageDead(_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 } bb7: { @@ -119,7 +119,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching2.rs:29:24: 29:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:24: 29:34 } bb8: { @@ -133,7 +133,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _9 = &(*_11); // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:24: 30:34 StorageDead(_11); // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:33: 30:34 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:33: 30:34 } bb9: { @@ -147,7 +147,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:21: 31:24 StorageDead(_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 } bb10: { diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff index 91927dc7f167..c5a100fe3e50 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff +++ b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff @@ -34,7 +34,7 @@ } bb2: { - switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:20: 7:24 + switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:15: 7:25 } bb3: { diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff index 91927dc7f167..c5a100fe3e50 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff +++ b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff @@ -34,7 +34,7 @@ } bb2: { - switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:20: 7:24 + switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:15: 7:25 } bb3: { diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs index cecc278e1931..6e63de9136cb 100644 --- a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs +++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs @@ -14,8 +14,8 @@ fn distinct_variant() { // also used for the discriminant of `Foo`, which it would be if `a` was a // reference. let b = match y { - Foo::Y(_, ref mut b) => b, //~^ ERROR cannot use `y` + Foo::Y(_, ref mut b) => b, Foo::X => panic!() }; @@ -32,8 +32,9 @@ fn same_variant() { }; let b = match y { - Foo::Y(ref mut b, _) => b, //~ ERROR cannot use `y` - //~| ERROR cannot borrow `y.0` as mutable + //~^ ERROR cannot use `y` + Foo::Y(ref mut b, _) => b, + //~^ ERROR cannot borrow `y.0` as mutable Foo::X => panic!() }; diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr index 2caeed1bd44e..98f6f00a7d48 100644 --- a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr +++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr @@ -1,29 +1,29 @@ error[E0503]: cannot use `y` because it was mutably borrowed - --> $DIR/borrowck-anon-fields-variant.rs:17:7 + --> $DIR/borrowck-anon-fields-variant.rs:16:19 | LL | Foo::Y(ref mut a, _) => a, | --------- borrow of `y.0` occurs here ... -LL | Foo::Y(_, ref mut b) => b, - | ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0` +LL | let b = match y { + | ^ use of borrowed `y.0` ... LL | *a += 1; | ------- borrow later used here error[E0503]: cannot use `y` because it was mutably borrowed - --> $DIR/borrowck-anon-fields-variant.rs:35:7 + --> $DIR/borrowck-anon-fields-variant.rs:34:19 | LL | Foo::Y(ref mut a, _) => a, | --------- borrow of `y.0` occurs here ... -LL | Foo::Y(ref mut b, _) => b, - | ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0` +LL | let b = match y { + | ^ use of borrowed `y.0` ... LL | *a += 1; | ------- borrow later used here error[E0499]: cannot borrow `y.0` as mutable more than once at a time - --> $DIR/borrowck-anon-fields-variant.rs:35:14 + --> $DIR/borrowck-anon-fields-variant.rs:36:14 | LL | Foo::Y(ref mut a, _) => a, | --------- first mutable borrow occurs here diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.rs b/src/test/ui/borrowck/borrowck-describe-lvalue.rs index 0e6c0635adb4..cdcff69d6e52 100644 --- a/src/test/ui/borrowck/borrowck-describe-lvalue.rs +++ b/src/test/ui/borrowck/borrowck-describe-lvalue.rs @@ -164,9 +164,9 @@ fn main() { let mut e = E::A(3); let x = &mut e; match e { + //~^ ERROR cannot use `e` because it was mutably borrowed E::A(ref ax) => //~^ ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable - //~| ERROR cannot use `e` because it was mutably borrowed println!("e.ax: {:?}", ax), E::B { x: ref bx } => //~^ ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr index 0f2ebbcbf3cd..4b9c5a2a98ff 100644 --- a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr @@ -238,23 +238,22 @@ LL | drop(x); | - borrow later used here error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/borrowck-describe-lvalue.rs:167:13 + --> $DIR/borrowck-describe-lvalue.rs:166:15 | LL | let x = &mut e; | ------ borrow of `e` occurs here LL | match e { -LL | E::A(ref ax) => - | ^^^^^^^^^^^^ use of borrowed `e` + | ^ use of borrowed `e` ... LL | drop(x); | - borrow later used here error[E0502]: cannot borrow `e.0` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-describe-lvalue.rs:167:18 + --> $DIR/borrowck-describe-lvalue.rs:168:18 | LL | let x = &mut e; | ------ mutable borrow occurs here -LL | match e { +... LL | E::A(ref ax) => | ^^^^^^ immutable borrow occurs here ... diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs index c766e6c10808..a925cbbf57b6 100644 --- a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs +++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs @@ -6,8 +6,8 @@ enum Foo { fn match_enum() { let mut foo = Foo::B; let p = &mut foo; - let _ = match foo { - Foo::B => 1, //~ ERROR [E0503] + let _ = match foo { //~ ERROR [E0503] + Foo::B => 1, _ => 2, Foo::A(x) => x //~ ERROR [E0503] }; diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr index 286a925bb7f6..39047be9de67 100644 --- a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr +++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr @@ -1,11 +1,10 @@ error[E0503]: cannot use `foo` because it was mutably borrowed - --> $DIR/borrowck-match-already-borrowed.rs:10:9 + --> $DIR/borrowck-match-already-borrowed.rs:9:19 | LL | let p = &mut foo; | -------- borrow of `foo` occurs here LL | let _ = match foo { -LL | Foo::B => 1, - | ^^^^^^ use of borrowed `foo` + | ^^^ use of borrowed `foo` ... LL | drop(p); | - borrow later used here diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs index 71f1f15654b5..4109c10e2e46 100644 --- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs +++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs @@ -10,11 +10,11 @@ fn main() { let b = &mut true; match b { + //~^ ERROR use of moved value: `b` [E0382] &mut false => {}, _ if { (|| { let bar = b; *bar = false; })(); false } => { }, &mut true => { println!("You might think we should get here"); }, - //~^ ERROR use of moved value: `b` [E0382] _ => panic!("surely we could never get here, since rustc warns it is unreachable."), } } diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr index 51f9b464d766..9be1a9279992 100644 --- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr +++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr @@ -1,16 +1,15 @@ error[E0382]: use of moved value: `b` - --> $DIR/issue-27282-move-match-input-into-guard.rs:16:14 + --> $DIR/issue-27282-move-match-input-into-guard.rs:12:5 | LL | let b = &mut true; | - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait +LL | match b { + | ^^^^^^^ value used here after move ... LL | _ if { (|| { let bar = b; *bar = false; })(); | -- - variable moved due to use in closure | | | value moved into closure here -LL | false } => { }, -LL | &mut true => { println!("You might think we should get here"); }, - | ^^^^ value used here after move error: aborting due to previous error diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr index 64a1214e8bf1..64d8540878ec 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr @@ -65,11 +65,11 @@ LL | U8_MUT2 => true, | ^^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:32:51 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | / const U8_MUT3: &u8 = { LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } - | | ^^^^^^^^^^^ constant accesses static + | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static LL | | LL | | LL | | diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr index 66fe4ec07600..8e793ab3f0d9 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr @@ -65,11 +65,11 @@ LL | U8_MUT2 => true, | ^^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:32:51 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | / const U8_MUT3: &u8 = { LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } - | | ^^^^^^^^^^^ constant accesses static + | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static LL | | LL | | LL | | diff --git a/src/test/ui/issues/issue-17385.rs b/src/test/ui/issues/issue-17385.rs index 93364d2f6259..7400aadb059f 100644 --- a/src/test/ui/issues/issue-17385.rs +++ b/src/test/ui/issues/issue-17385.rs @@ -15,8 +15,8 @@ impl Drop for Enum { fn main() { let foo = X(1); drop(foo); - match foo { - X(1) => (), //~ ERROR use of moved value + match foo { //~ ERROR use of moved value + X(1) => (), _ => unreachable!() } diff --git a/src/test/ui/issues/issue-17385.stderr b/src/test/ui/issues/issue-17385.stderr index 28c22260c388..77aa201b3356 100644 --- a/src/test/ui/issues/issue-17385.stderr +++ b/src/test/ui/issues/issue-17385.stderr @@ -1,13 +1,12 @@ error[E0382]: use of moved value: `foo` - --> $DIR/issue-17385.rs:19:11 + --> $DIR/issue-17385.rs:18:5 | LL | let foo = X(1); | --- move occurs because `foo` has type `X`, which does not implement the `Copy` trait LL | drop(foo); | --- value moved here LL | match foo { -LL | X(1) => (), - | ^ value used here after move + | ^^^^^^^^^ value used here after move error[E0382]: use of moved value: `e` --> $DIR/issue-17385.rs:25:11 diff --git a/src/test/ui/nll/borrowed-match-issue-45045.rs b/src/test/ui/nll/borrowed-match-issue-45045.rs index 0cd8e956d309..978eeb868edc 100644 --- a/src/test/ui/nll/borrowed-match-issue-45045.rs +++ b/src/test/ui/nll/borrowed-match-issue-45045.rs @@ -10,8 +10,8 @@ fn main() { let f = &mut e; let g = f; match e { - Xyz::A => println!("a"), //~^ cannot use `e` because it was mutably borrowed [E0503] + Xyz::A => println!("a"), Xyz::B => println!("b"), }; *g = Xyz::B; diff --git a/src/test/ui/nll/borrowed-match-issue-45045.stderr b/src/test/ui/nll/borrowed-match-issue-45045.stderr index 1607304e6716..9d4682667ddd 100644 --- a/src/test/ui/nll/borrowed-match-issue-45045.stderr +++ b/src/test/ui/nll/borrowed-match-issue-45045.stderr @@ -1,11 +1,11 @@ error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/borrowed-match-issue-45045.rs:13:9 + --> $DIR/borrowed-match-issue-45045.rs:12:11 | LL | let f = &mut e; | ------ borrow of `e` occurs here -... -LL | Xyz::A => println!("a"), - | ^^^^^^ use of borrowed `e` +LL | let g = f; +LL | match e { + | ^ use of borrowed `e` ... LL | *g = Xyz::B; | ----------- borrow later used here diff --git a/src/test/ui/nll/match-cfg-fake-edges2.rs b/src/test/ui/nll/match-cfg-fake-edges2.rs index 84c0dec2fe5c..e61db71220e8 100644 --- a/src/test/ui/nll/match-cfg-fake-edges2.rs +++ b/src/test/ui/nll/match-cfg-fake-edges2.rs @@ -7,8 +7,8 @@ fn all_previous_tests_may_be_done(y: &mut (bool, bool)) { let r = &mut y.1; // We don't actually test y.1 to select the second arm, but we don't want // borrowck results to be based on the order we match patterns. - match y { - (false, true) => 1, //~ ERROR cannot use `y.1` because it was mutably borrowed + match y { //~ ERROR cannot use `y.1` because it was mutably borrowed + (false, true) => 1, (true, _) => { r; 2 diff --git a/src/test/ui/nll/match-cfg-fake-edges2.stderr b/src/test/ui/nll/match-cfg-fake-edges2.stderr index eab89658e79b..0ce83849b9f9 100644 --- a/src/test/ui/nll/match-cfg-fake-edges2.stderr +++ b/src/test/ui/nll/match-cfg-fake-edges2.stderr @@ -1,12 +1,12 @@ error[E0503]: cannot use `y.1` because it was mutably borrowed - --> $DIR/match-cfg-fake-edges2.rs:11:17 + --> $DIR/match-cfg-fake-edges2.rs:10:5 | LL | let r = &mut y.1; | -------- borrow of `y.1` occurs here ... -LL | (false, true) => 1, - | ^^^^ use of borrowed `y.1` -LL | (true, _) => { +LL | match y { + | ^^^^^^^ use of borrowed `y.1` +... LL | r; | - borrow later used here diff --git a/src/test/ui/nll/match-on-borrowed.rs b/src/test/ui/nll/match-on-borrowed.rs index aba0a7f71f5c..447dabeb47e5 100644 --- a/src/test/ui/nll/match-on-borrowed.rs +++ b/src/test/ui/nll/match-on-borrowed.rs @@ -45,8 +45,9 @@ fn enum_example(mut e: E) { E::W => panic!(), }; match e { // Don't know that E uses a tag for its discriminant + //~^ ERROR _ if false => (), - E::V(_, r) => (), //~ ERROR + E::V(_, r) => (), E::W => (), } x; @@ -58,8 +59,9 @@ fn indirect_enum_example(mut f: &mut E) { E::W => panic!(), }; match f { // Don't know that E uses a tag for its discriminant + //~^ ERROR _ if false => (), - E::V(_, r) => (), //~ ERROR + E::V(_, r) => (), E::W => (), } x; @@ -77,7 +79,8 @@ fn match_on_muatbly_borrowed_ref(mut p: &bool) { fn match_on_borrowed(mut t: bool) { let x = &mut t; match t { - true => (), //~ ERROR + //~^ ERROR + true => (), false => (), } x; diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr index f9c9a8463221..2121b59b02da 100644 --- a/src/test/ui/nll/match-on-borrowed.stderr +++ b/src/test/ui/nll/match-on-borrowed.stderr @@ -1,41 +1,40 @@ error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:49:9 + --> $DIR/match-on-borrowed.rs:47:11 | LL | E::V(ref mut x, _) => x, | --------- borrow of `e.0` occurs here ... -LL | E::V(_, r) => (), - | ^^^^^^^^^^ use of borrowed `e.0` +LL | match e { // Don't know that E uses a tag for its discriminant + | ^ use of borrowed `e.0` ... LL | x; | - borrow later used here error[E0503]: cannot use `*f` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:62:9 + --> $DIR/match-on-borrowed.rs:61:11 | LL | E::V(ref mut x, _) => x, | --------- borrow of `f.0` occurs here ... -LL | E::V(_, r) => (), - | ^^^^^^^^^^ use of borrowed `f.0` +LL | match f { // Don't know that E uses a tag for its discriminant + | ^ use of borrowed `f.0` ... LL | x; | - borrow later used here error[E0503]: cannot use `t` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:80:9 + --> $DIR/match-on-borrowed.rs:81:5 | LL | let x = &mut t; | ------ borrow of `t` occurs here LL | match t { -LL | true => (), - | ^^^^ use of borrowed `t` + | ^^^^^^^ use of borrowed `t` ... LL | x; | - borrow later used here error[E0381]: use of possibly-uninitialized variable: `n` - --> $DIR/match-on-borrowed.rs:90:11 + --> $DIR/match-on-borrowed.rs:93:11 | LL | match n {} | ^ use of possibly-uninitialized `n` diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs index 00dcf89c7aa6..2ad92b794449 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs +++ b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs @@ -10,8 +10,8 @@ fn main() { let mut x = NonExhaustiveMonovariant::Variant(1); let y = &mut x; match x { - NonExhaustiveMonovariant::Variant(_) => {}, //~^ ERROR cannot use `x` because it was mutably borrowed + NonExhaustiveMonovariant::Variant(_) => {}, _ => {}, } drop(y); diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr index 9edfa84cbc08..de730ce1030f 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr @@ -1,11 +1,10 @@ error[E0503]: cannot use `x` because it was mutably borrowed - --> $DIR/borrowck-non-exhaustive.rs:13:9 + --> $DIR/borrowck-non-exhaustive.rs:12:11 | LL | let y = &mut x; | ------ borrow of `x` occurs here LL | match x { -LL | NonExhaustiveMonovariant::Variant(_) => {}, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of borrowed `x` + | ^ use of borrowed `x` ... LL | drop(y); | - borrow later used here diff --git a/src/test/ui/union/union-unsafe.mir.stderr b/src/test/ui/union/union-unsafe.mir.stderr index 84a7eb2ef2e7..318b00ddea94 100644 --- a/src/test/ui/union/union-unsafe.mir.stderr +++ b/src/test/ui/union/union-unsafe.mir.stderr @@ -55,10 +55,10 @@ LL | let U1 { a } = u1; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:65:20 + --> $DIR/union-unsafe.rs:65:12 | LL | if let U1 { a: 12 } = u1 {} - | ^^ access to union field + | ^^^^^^^^^^^^ access to union field | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior From 994a6bb667d8a0ae7bbc777f4d33994692dd7266 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Wed, 25 Aug 2021 16:06:52 -0400 Subject: [PATCH 134/269] Bless NLL compare mode --- .../associated-types/higher-ranked-projection.bad.nll.stderr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/associated-types/higher-ranked-projection.bad.nll.stderr b/src/test/ui/associated-types/higher-ranked-projection.bad.nll.stderr index 59e27cd2e7dd..e3bd0c2276e4 100644 --- a/src/test/ui/associated-types/higher-ranked-projection.bad.nll.stderr +++ b/src/test/ui/associated-types/higher-ranked-projection.bad.nll.stderr @@ -4,8 +4,8 @@ error[E0308]: mismatched types LL | foo(()); | ^^^^^^^ one type is more general than the other | - = note: expected type `&'a ()` - found reference `&()` + = note: expected reference `&'a ()` + found reference `&()` error: aborting due to previous error From 21d8d5f88101ce15c2072e83d1ccbf7533895b11 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 24 Aug 2021 17:15:14 -0400 Subject: [PATCH 135/269] Bump sccache used in CI to v0.2.15 This skips bumping Windows sccache because we run into compilation failures when doing so (-m32 not supported by clang-cl?). Not clear on cause, but seems easiest to just hold back. This should avoid PGO-related failures encountered on Linux, and more broadly seems like a good idea on other platforms as well (though it is likely not necessary right this moment). --- src/ci/docker/scripts/sccache.sh | 7 +++++-- src/ci/scripts/install-sccache.sh | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/scripts/sccache.sh b/src/ci/docker/scripts/sccache.sh index 292b3c1d5627..6c713e1f8611 100644 --- a/src/ci/docker/scripts/sccache.sh +++ b/src/ci/docker/scripts/sccache.sh @@ -1,12 +1,15 @@ #!/bin/sh + +# ignore-tidy-linelength + set -ex case "$(uname -m)" in x86_64) - url="https://ci-mirrors.rust-lang.org/rustc/2018-04-02-sccache-x86_64-unknown-linux-musl" + url="https://ci-mirrors.rust-lang.org/rustc/2021-08-24-sccache-v0.2.15-x86_64-unknown-linux-musl" ;; aarch64) - url="https://ci-mirrors.rust-lang.org/rustc/2019-12-17-sccache-aarch64-unknown-linux-gnu" + url="https://ci-mirrors.rust-lang.org/rustc/2021-08-25-sccache-v0.2.15-aarch64-unknown-linux-musl" ;; *) echo "unsupported architecture: $(uname -m)" diff --git a/src/ci/scripts/install-sccache.sh b/src/ci/scripts/install-sccache.sh index d3c298992254..e143152f330c 100755 --- a/src/ci/scripts/install-sccache.sh +++ b/src/ci/scripts/install-sccache.sh @@ -8,7 +8,7 @@ IFS=$'\n\t' source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" if isMacOS; then - curl -fo /usr/local/bin/sccache "${MIRRORS_BASE}/2018-04-02-sccache-x86_64-apple-darwin" + curl -fo /usr/local/bin/sccache "${MIRRORS_BASE}/2021-08-25-sccache-v0.2.15-x86_64-apple-darwin" chmod +x /usr/local/bin/sccache elif isWindows; then mkdir -p sccache From 1ea8d93c0ca5168e7f434d87e19af337b83157e4 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 25 Aug 2021 14:33:23 -0400 Subject: [PATCH 136/269] Bump download-ci-llvm stamp This will ensure the optimized LLVM is used for local builds after rebasing immediately, rather than needing to wait for a future LLVM bump. --- src/bootstrap/download-ci-llvm-stamp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index fb5b058cb4d7..19e5fffcc2dd 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/80932 +Last change is for: https://github.com/rust-lang/rust/pull/88069 From 8a6501d28831d864a3af6adf2e0bd83a773062ed Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 14:40:06 -0700 Subject: [PATCH 137/269] Adjust spans * Highlight the whole pattern if it has no fields * Highlight the whole definition if it has no fields * Only highlight the pattern name if the pattern is multi-line * Determine whether a pattern is multi-line based on distance from name to last field, rather than first field --- compiler/rustc_typeck/src/check/pat.rs | 10 +- .../tuple_struct_destructure_fail.stderr | 8 +- src/test/ui/error-codes/E0023.stderr | 12 +- src/test/ui/issues/issue-72574-2.stderr | 2 +- .../match/match-pattern-field-mismatch.stderr | 2 +- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 4 +- src/test/ui/pattern/issue-74539.stderr | 2 +- .../pat-tuple-field-count-cross.stderr | 54 ++++----- src/test/ui/pattern/pat-tuple-overfield.rs | 16 +++ .../ui/pattern/pat-tuple-overfield.stderr | 108 ++++++++++++++---- src/test/ui/pattern/pat-tuple-underfield.rs | 12 ++ .../ui/pattern/pat-tuple-underfield.stderr | 64 ++++++++--- .../ui/pattern/pattern-error-continue.stderr | 2 +- 13 files changed, 211 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 341385731e7d..e1f0d3c43636 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -992,7 +992,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let fields_ending = pluralize!(fields.len()); let subpat_spans = if subpats.is_empty() { - vec![pat_span.trim_start(qpath.span()).unwrap_or(pat_span)] + vec![pat_span] } else { subpats.iter().map(|p| p.span).collect() }; @@ -1000,7 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let res_span = self.tcx.def_span(res.def_id()); let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span); let field_def_spans = if fields.is_empty() { - vec![res_span.trim_start(def_ident_span).unwrap_or(res_span)] + vec![res_span] } else { fields.iter().map(|f| f.ident.span).collect() }; @@ -1021,8 +1021,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { last_subpat_span, &format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()), ); - err.span_label(qpath.span(), ""); - if self.tcx.sess.source_map().is_multiline(def_ident_span.between(field_def_spans[0])) { + if self.tcx.sess.source_map().is_multiline(qpath.span().between(last_subpat_span)) { + err.span_label(qpath.span(), ""); + } + if self.tcx.sess.source_map().is_multiline(def_ident_span.between(last_field_def_span)) { err.span_label(def_ident_span, format!("{} defined here", res.descr())); } for span in &field_def_spans[..field_def_spans.len() - 1] { diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index 9a47ddf04799..9aae4b0a3fae 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -21,7 +21,7 @@ LL | struct TupleStruct(S, T); | - - tuple struct has 2 fields ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | ----------- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields --> $DIR/tuple_struct_destructure_fail.rs:32:17 @@ -30,7 +30,7 @@ LL | struct TupleStruct(S, T); | - - tuple struct has 2 fields ... LL | TupleStruct(_) = TupleStruct(1, 2); - | ----------- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -48,7 +48,7 @@ LL | SingleVariant(S, T) | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | ------------------- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields --> $DIR/tuple_struct_destructure_fail.rs:36:25 @@ -57,7 +57,7 @@ LL | SingleVariant(S, T) | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | ------------------- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index 85e1b2cb4cee..3e321b037b2b 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -5,7 +5,7 @@ LL | Apple(String, String), | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a) => {}, - | ------------ ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -19,7 +19,7 @@ LL | Apple(String, String), | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a, b, c) => {}, - | ------------ ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field --> $DIR/E0023.rs:13:21 @@ -28,7 +28,7 @@ LL | Pear(u32), | --- tuple variant has 1 field ... LL | Fruit::Pear(1, 2) => {}, - | ----------- ^ ^ expected 1 field, found 2 + | ^ ^ expected 1 field, found 2 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field --> $DIR/E0023.rs:14:23 @@ -37,7 +37,7 @@ LL | Orange((String, String)), | ---------------- tuple variant has 1 field ... LL | Fruit::Orange(a, b) => {}, - | ------------- ^ ^ expected 1 field, found 2 + | ^ ^ expected 1 field, found 2 | help: missing parentheses | @@ -45,13 +45,13 @@ LL | Fruit::Orange((a, b)) => {}, | + + error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:15:22 + --> $DIR/E0023.rs:15:9 | LL | Banana(()), | -- tuple variant has 1 field ... LL | Fruit::Banana() => {}, - | -------------^^ expected 1 field, found 0 + | ^^^^^^^^^^^^^^^ expected 1 field, found 0 | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 3f8ff4f0bacd..05650f05cbf5 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -25,7 +25,7 @@ LL | struct Binder(i32, i32, i32); | --- --- --- tuple struct has 3 fields ... LL | Binder(_a, _x @ ..) => {} - | ------ ^^ ^^^^^^^ expected 3 fields, found 2 + | ^^ ^^^^^^^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index 01d7cf0d054c..c994ee4f6d4f 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -5,7 +5,7 @@ LL | Rgb(usize, usize, usize), | ----- ----- ----- tuple variant has 3 fields ... LL | Color::Rgb(_, _) => { } - | ---------- ^ ^ expected 3 fields, found 2 + | ^ ^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index c87b70625b40..75a231f6b4ba 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -10,13 +10,13 @@ LL | let P() = U {}; found struct `P<_>` error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field - --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 + --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 | LL | struct P(T); // 1 type parameter wanted | - tuple struct has 1 field ... LL | let P() = U {}; - | -^^ expected 1 field, found 0 + | ^^^ expected 1 field, found 0 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index d7cbcf2cfa10..7443946c013f 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -25,7 +25,7 @@ LL | A(u8, u8), | -- -- tuple variant has 2 fields ... LL | E::A(x @ ..) => { - | ---- ^^^^^^ expected 2 fields, found 1 + | ^^^^^^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr index 570bf0cbc081..cab8d4759df6 100644 --- a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr @@ -121,7 +121,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 --> $DIR/pat-tuple-field-count-cross.rs:14:12 | LL | Z1(x) => {} - | -- ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:2:1 | @@ -129,10 +129,10 @@ LL | pub struct Z1(); | ---------------- tuple struct has 0 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:18:10 + --> $DIR/pat-tuple-field-count-cross.rs:18:9 | LL | S() => {} - | -^^ expected 3 fields, found 0 + | ^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -152,7 +152,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 --> $DIR/pat-tuple-field-count-cross.rs:19:11 | LL | S(1) => {} - | - ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -172,7 +172,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:20:11 | LL | S(xyz, abc) => {} - | - ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -188,7 +188,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:21:11 | LL | S(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -196,10 +196,10 @@ LL | pub struct S(pub u8, pub u8, pub u8); | ------ ------ ------ tuple struct has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:24:10 + --> $DIR/pat-tuple-field-count-cross.rs:24:9 | LL | M() => {} - | -^^ expected 3 fields, found 0 + | ^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -226,7 +226,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 --> $DIR/pat-tuple-field-count-cross.rs:25:11 | LL | M(1) => {} - | - ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -253,7 +253,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:26:11 | LL | M(xyz, abc) => {} - | - ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -276,7 +276,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:27:11 | LL | M(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -294,7 +294,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:36:16 | LL | E1::Z1(x) => {} - | ------ ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 | @@ -302,10 +302,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } | ---- tuple variant has 0 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:39:14 + --> $DIR/pat-tuple-field-count-cross.rs:39:9 | LL | E1::S() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -325,7 +325,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:40:15 | LL | E1::S(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -345,7 +345,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:41:15 | LL | E1::S(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -361,7 +361,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:42:15 | LL | E1::S(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -369,10 +369,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } | -- -- -- tuple variant has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:46:14 + --> $DIR/pat-tuple-field-count-cross.rs:46:9 | LL | E2::S() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -392,7 +392,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:47:15 | LL | E2::S(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -412,7 +412,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:48:15 | LL | E2::S(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -428,7 +428,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:49:15 | LL | E2::S(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -436,10 +436,10 @@ LL | S(u8, u8, u8), | -- -- -- tuple variant has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:52:14 + --> $DIR/pat-tuple-field-count-cross.rs:52:9 | LL | E2::M() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -466,7 +466,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:53:15 | LL | E2::M(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -493,7 +493,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:54:15 | LL | E2::M(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -516,7 +516,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:55:15 | LL | E2::M(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | diff --git a/src/test/ui/pattern/pat-tuple-overfield.rs b/src/test/ui/pattern/pat-tuple-overfield.rs index dd0548a088c7..c863c657514f 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.rs +++ b/src/test/ui/pattern/pat-tuple-overfield.rs @@ -30,6 +30,22 @@ fn main() { match M(1, 2, 3, 4, 5) { M(1, 2, 3, 4, 5, 6) => {} //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + M(1, + 2, + 3, + 4, + 5, + 6) => {} + //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + M( + 1, + 2, + 3, + 4, + 5, + 6, + ) => {} + //~^^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields } match Z0 { Z0 => {} diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 646ac4e66189..1c44f7e5f6f1 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow tuple structs - --> $DIR/pat-tuple-overfield.rs:41:9 + --> $DIR/pat-tuple-overfield.rs:57:9 | LL | struct Z1(); | ------------ the tuple struct `Z1` is defined here @@ -8,7 +8,7 @@ LL | Z1 => {} | ^^ cannot be named the same as a tuple struct error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:36:9 + --> $DIR/pat-tuple-overfield.rs:52:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -28,7 +28,7 @@ LL | Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:37:9 + --> $DIR/pat-tuple-overfield.rs:53:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -48,7 +48,7 @@ LL | Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:38:9 + --> $DIR/pat-tuple-overfield.rs:54:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -68,7 +68,7 @@ LL | Z1(_, _) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:48:9 + --> $DIR/pat-tuple-overfield.rs:64:9 | LL | Z0, | -- `E1::Z0` defined here @@ -88,7 +88,7 @@ LL | E1::Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:49:9 + --> $DIR/pat-tuple-overfield.rs:65:9 | LL | Z0, | -- `E1::Z0` defined here @@ -108,7 +108,7 @@ LL | E1::Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:50:9 + --> $DIR/pat-tuple-overfield.rs:66:9 | LL | Z0, | -- `E1::Z0` defined here @@ -128,7 +128,7 @@ LL | E1::Z1(_, _) => {} | ~~ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` - --> $DIR/pat-tuple-overfield.rs:53:9 + --> $DIR/pat-tuple-overfield.rs:69:9 | LL | Z0, | -- similarly named unit variant `Z0` defined here @@ -177,7 +177,7 @@ LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields --> $DIR/pat-tuple-overfield.rs:26:11 @@ -186,7 +186,7 @@ LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, .., 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields --> $DIR/pat-tuple-overfield.rs:31:11 @@ -205,45 +205,105 @@ LL | u8, | -- tuple struct has 5 fields ... LL | M(1, 2, 3, 4, 5, 6) => {} - | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 + | ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 + +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:33:11 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields +... +LL | M(1, + | - ^ +LL | 2, + | ^ +LL | 3, + | ^ +LL | 4, + | ^ +LL | 5, + | ^ +LL | 6) => {} + | ^ expected 5 fields, found 6 + +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:41:13 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields +... +LL | M( + | - +LL | 1, + | ^ +LL | 2, + | ^ +LL | 3, + | ^ +LL | 4, + | ^ +LL | 5, + | ^ +LL | 6, + | ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:43:12 + --> $DIR/pat-tuple-overfield.rs:59:12 | LL | struct Z1(); - | --- tuple struct has 0 fields + | ------------ tuple struct has 0 fields ... LL | Z1(_) => {} - | -- ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:44:12 + --> $DIR/pat-tuple-overfield.rs:60:12 | LL | struct Z1(); - | --- tuple struct has 0 fields + | ------------ tuple struct has 0 fields ... LL | Z1(_, _) => {} - | -- ^ ^ expected 0 fields, found 2 + | ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:55:16 + --> $DIR/pat-tuple-overfield.rs:71:16 | LL | Z1(), - | -- tuple variant has 0 fields + | ---- tuple variant has 0 fields ... LL | E1::Z1(_) => {} - | ------ ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:56:16 + --> $DIR/pat-tuple-overfield.rs:72:16 | LL | Z1(), - | -- tuple variant has 0 fields + | ---- tuple variant has 0 fields ... LL | E1::Z1(_, _) => {} - | ------ ^ ^ expected 0 fields, found 2 + | ^ ^ expected 0 fields, found 2 -error: aborting due to 17 previous errors +error: aborting due to 19 previous errors Some errors have detailed explanations: E0023, E0308, E0530, E0532. For more information about an error, try `rustc --explain E0023`. diff --git a/src/test/ui/pattern/pat-tuple-underfield.rs b/src/test/ui/pattern/pat-tuple-underfield.rs index ed852a47bb4e..dac60e3fab2c 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.rs +++ b/src/test/ui/pattern/pat-tuple-underfield.rs @@ -21,6 +21,12 @@ fn main() { //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields //~| HELP use `_` to explicitly ignore each field //~| HELP use `..` to ignore all fields + + // Test non-standard formatting + S () => {} + //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields + //~| HELP use `_` to explicitly ignore each field + //~| HELP use `..` to ignore all fields } match E::S(0, 1.0) { @@ -39,6 +45,12 @@ fn main() { //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields //~| HELP use `_` to explicitly ignore each field //~| HELP use `..` to ignore all fields + + // Test non-standard formatting + E::S () => {} + //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields + //~| HELP use `_` to explicitly ignore each field + //~| HELP use `..` to ignore all fields } match E::S(0, 1.0) { E::S => {} diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 4c21ad0be3eb..e75f9b38da56 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -1,5 +1,5 @@ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E::S` - --> $DIR/pat-tuple-underfield.rs:44:9 + --> $DIR/pat-tuple-underfield.rs:56:9 | LL | S(i32, f32), | ----------- `E::S` defined here @@ -14,7 +14,7 @@ LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S(x) => {} - | - ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -28,7 +28,7 @@ LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S(_) => {} - | - ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -40,13 +40,13 @@ LL | S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:20:10 + --> $DIR/pat-tuple-underfield.rs:20:9 | LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S() => {} - | -^^ expected 2 fields, found 0 + | ^^^ expected 2 fields, found 0 | help: use `_` to explicitly ignore each field | @@ -57,14 +57,32 @@ help: use `..` to ignore all fields LL | S(..) => {} | ++ +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields + --> $DIR/pat-tuple-underfield.rs:26:9 + | +LL | struct S(i32, f32); + | --- --- tuple struct has 2 fields +... +LL | S () => {} + | ^^^^ expected 2 fields, found 0 + | +help: use `_` to explicitly ignore each field + | +LL | S (_, _) => {} + | ++++ +help: use `..` to ignore all fields + | +LL | S (..) => {} + | ++ + error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:14 + --> $DIR/pat-tuple-underfield.rs:33:14 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S(x) => {} - | ---- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -72,13 +90,13 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:14 + --> $DIR/pat-tuple-underfield.rs:38:14 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S(_) => {} - | ---- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -90,13 +108,13 @@ LL | E::S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:38:13 + --> $DIR/pat-tuple-underfield.rs:44:9 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S() => {} - | ----^^ expected 2 fields, found 0 + | ^^^^^^ expected 2 fields, found 0 | help: use `_` to explicitly ignore each field | @@ -107,14 +125,32 @@ help: use `..` to ignore all fields LL | E::S(..) => {} | ++ +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields + --> $DIR/pat-tuple-underfield.rs:50:9 + | +LL | S(i32, f32), + | --- --- tuple variant has 2 fields +... +LL | E::S () => {} + | ^^^^^^^ expected 2 fields, found 0 + | +help: use `_` to explicitly ignore each field + | +LL | E::S (_, _) => {} + | ++++ +help: use `..` to ignore all fields + | +LL | E::S (..) => {} + | ++ + error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:19 + --> $DIR/pat-tuple-underfield.rs:62:19 | LL | struct Point4(i32, i32, i32, i32); | --- --- --- --- tuple struct has 4 fields ... LL | Point4( a , _ ) => {} - | ------ ^ ^ expected 4 fields, found 2 + | ^ ^ expected 4 fields, found 2 | help: use `_` to explicitly ignore each field | @@ -125,7 +161,7 @@ help: use `..` to ignore the rest of the fields LL | Point4( a, ..) => {} | ~~~~ -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0023, E0532. For more information about an error, try `rustc --explain E0023`. diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index efc6723e9ef8..c800afdae2af 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -32,7 +32,7 @@ LL | B(isize, isize), | ----- ----- tuple variant has 2 fields ... LL | A::B(_, _, _) => (), - | ---- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From 4d635fdf63f1ba3480c30a6ea1e6f3e49a39b738 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 31 Mar 2021 00:06:01 -0400 Subject: [PATCH 138/269] use undef for uninitialized bytes in constants --- compiler/rustc_codegen_llvm/src/consts.rs | 67 +++++++++++++++---- .../src/mir/interpret/allocation.rs | 57 ++++++++++++++-- .../rustc_middle/src/mir/interpret/mod.rs | 4 +- compiler/rustc_target/src/abi/mod.rs | 38 +++++++++++ compiler/rustc_target/src/lib.rs | 2 + src/test/codegen/consts.rs | 4 +- src/test/codegen/uninit-consts.rs | 51 ++++++++++++++ 7 files changed, 202 insertions(+), 21 deletions(-) create mode 100644 src/test/codegen/uninit-consts.rs diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index ec92bd686d2d..901fa9fb0474 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -11,7 +11,8 @@ use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::interpret::{ - read_target_uint, Allocation, ErrorHandled, GlobalAlloc, Pointer, Scalar as InterpScalar, + read_target_uint, Allocation, ErrorHandled, GlobalAlloc, InitChunk, Pointer, + Scalar as InterpScalar, }; use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::{self, Instance, Ty}; @@ -19,6 +20,7 @@ use rustc_middle::{bug, span_bug}; use rustc_target::abi::{ AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size, WrappingRange, }; +use std::ops::Range; use tracing::debug; pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value { @@ -26,6 +28,53 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll let dl = cx.data_layout(); let pointer_size = dl.pointer_size.bytes() as usize; + // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, + // so `range` must be within the bounds of `alloc` and not within a relocation. + fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>( + llvals: &mut Vec<&'ll Value>, + cx: &'a CodegenCx<'ll, 'b>, + alloc: &'a Allocation, + range: Range, + ) { + /// Allocations larger than this will only be codegen'd as entirely initialized or entirely undef. + /// This avoids compile time regressions when an alloc would have many chunks, + /// e.g. for `[(u64, u8); N]`, which has undef padding in each element. + const MAX_PARTIALLY_UNDEF_SIZE: usize = 1024; + + let mut chunks = alloc + .init_mask() + .range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end)); + + let chunk_to_llval = move |chunk| match chunk { + InitChunk::Init(range) => { + let range = (range.start.bytes() as usize)..(range.end.bytes() as usize); + let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range); + cx.const_bytes(bytes) + } + InitChunk::Uninit(range) => { + let len = range.end.bytes() - range.start.bytes(); + cx.const_undef(cx.type_array(cx.type_i8(), len)) + } + }; + + if range.len() > MAX_PARTIALLY_UNDEF_SIZE { + let llval = match (chunks.next(), chunks.next()) { + (Some(chunk), None) => { + // exactly one chunk, either fully init or fully uninit + chunk_to_llval(chunk) + } + _ => { + // partially uninit + let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range); + cx.const_bytes(bytes) + } + }; + llvals.push(llval); + } else { + llvals.extend(chunks.map(chunk_to_llval)); + } + } + let mut next_offset = 0; for &(offset, alloc_id) in alloc.relocations().iter() { let offset = offset.bytes(); @@ -34,12 +83,8 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll if offset > next_offset { // This `inspect` is okay since we have checked that it is not within a relocation, it // is within the bounds of the allocation, and it doesn't affect interpreter execution - // (we inspect the result after interpreter execution). Any undef byte is replaced with - // some arbitrary byte value. - // - // FIXME: relay undef bytes to codegen as undef const bytes - let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(next_offset..offset); - llvals.push(cx.const_bytes(bytes)); + // (we inspect the result after interpreter execution). + append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, next_offset..offset); } let ptr_offset = read_target_uint( dl.endian, @@ -70,12 +115,8 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll let range = next_offset..alloc.len(); // This `inspect` is okay since we have check that it is after all relocations, it is // within the bounds of the allocation, and it doesn't affect interpreter execution (we - // inspect the result after interpreter execution). Any undef byte is replaced with some - // arbitrary byte value. - // - // FIXME: relay undef bytes to codegen as undef const bytes - let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range); - llvals.push(cx.const_bytes(bytes)); + // inspect the result after interpreter execution). + append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, range); } cx.const_struct(&llvals, true) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 5964efa78e9e..71580bcc06df 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -721,20 +721,24 @@ impl InitMask { } // FIXME(oli-obk): optimize this for allocations larger than a block. - let idx = (start.bytes()..end.bytes()).map(Size::from_bytes).find(|&i| !self.get(i)); + let idx = (start..end).find(|&i| !self.get(i)); match idx { Some(idx) => { - let uninit_end = (idx.bytes()..end.bytes()) - .map(Size::from_bytes) - .find(|&i| self.get(i)) - .unwrap_or(end); + let uninit_end = (idx..end).find(|&i| self.get(i)).unwrap_or(end); Err(idx..uninit_end) } None => Ok(()), } } + /// Returns an iterator, yielding a range of byte indexes for each contiguous region + /// of initialized or uninitialized bytes inside the range `start..end` (end-exclusive). + #[inline] + pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_> { + InitChunkIter::new(self, start, end) + } + pub fn set_range(&mut self, start: Size, end: Size, new_state: bool) { let len = self.len; if end > len { @@ -827,6 +831,49 @@ impl InitMask { } } +/// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`]. +pub struct InitChunkIter<'a> { + init_mask: &'a InitMask, + /// The current byte index into `init_mask`. + start: Size, + /// The end byte index into `init_mask`. + end: Size, +} + +/// A contiguous chunk of initialized or uninitialized memory. +pub enum InitChunk { + Init(Range), + Uninit(Range), +} + +impl<'a> InitChunkIter<'a> { + fn new(init_mask: &'a InitMask, start: Size, end: Size) -> Self { + assert!(start <= end); + assert!(end <= init_mask.len); + Self { init_mask, start, end } + } +} + +impl<'a> Iterator for InitChunkIter<'a> { + type Item = InitChunk; + + fn next(&mut self) -> Option { + if self.start >= self.end { + return None; + } + + let is_init = self.init_mask.get(self.start); + // FIXME(oli-obk): optimize this for allocations larger than a block. + let end_of_chunk = + (self.start..self.end).find(|&i| self.init_mask.get(i) != is_init).unwrap_or(self.end); + let range = self.start..end_of_chunk; + + self.start = end_of_chunk; + + Some(if is_init { InitChunk::Init(range) } else { InitChunk::Uninit(range) }) + } +} + #[inline] fn bit_index(bits: Size) -> (usize, usize) { let bits = bits.bytes(); diff --git a/compiler/rustc_middle/src/mir/interpret/mod.rs b/compiler/rustc_middle/src/mir/interpret/mod.rs index dd9ac7f5c395..4628c24292f0 100644 --- a/compiler/rustc_middle/src/mir/interpret/mod.rs +++ b/compiler/rustc_middle/src/mir/interpret/mod.rs @@ -125,7 +125,9 @@ pub use self::error::{ pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar, ScalarMaybeUninit}; -pub use self::allocation::{alloc_range, AllocRange, Allocation, InitMask, Relocations}; +pub use self::allocation::{ + alloc_range, AllocRange, Allocation, InitChunk, InitChunkIter, InitMask, Relocations, +}; pub use self::pointer::{Pointer, PointerArithmetic, Provenance}; diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index d206df461200..88f1b1c320c1 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -5,6 +5,7 @@ use crate::spec::Target; use std::convert::{TryFrom, TryInto}; use std::fmt; +use std::iter::Step; use std::num::NonZeroUsize; use std::ops::{Add, AddAssign, Deref, Mul, Range, RangeInclusive, Sub}; use std::str::FromStr; @@ -440,6 +441,43 @@ impl AddAssign for Size { } } +impl Step for Size { + #[inline] + fn steps_between(start: &Self, end: &Self) -> Option { + u64::steps_between(&start.bytes(), &end.bytes()) + } + + #[inline] + fn forward_checked(start: Self, count: usize) -> Option { + u64::forward_checked(start.bytes(), count).map(Self::from_bytes) + } + + #[inline] + fn forward(start: Self, count: usize) -> Self { + Self::from_bytes(u64::forward(start.bytes(), count)) + } + + #[inline] + unsafe fn forward_unchecked(start: Self, count: usize) -> Self { + Self::from_bytes(u64::forward_unchecked(start.bytes(), count)) + } + + #[inline] + fn backward_checked(start: Self, count: usize) -> Option { + u64::backward_checked(start.bytes(), count).map(Self::from_bytes) + } + + #[inline] + fn backward(start: Self, count: usize) -> Self { + Self::from_bytes(u64::backward(start.bytes(), count)) + } + + #[inline] + unsafe fn backward_unchecked(start: Self, count: usize) -> Self { + Self::from_bytes(u64::backward_unchecked(start.bytes(), count)) + } +} + /// Alignment of a type in bytes (always a power of two). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] #[derive(HashStable_Generic)] diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index d39e5a5aa2c3..e75c52555b90 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -14,6 +14,8 @@ #![feature(associated_type_bounds)] #![feature(exhaustive_patterns)] #![feature(min_specialization)] +#![feature(step_trait)] +#![feature(unchecked_math)] use std::path::{Path, PathBuf}; diff --git a/src/test/codegen/consts.rs b/src/test/codegen/consts.rs index 7f945299c22a..e47a9f9ee201 100644 --- a/src/test/codegen/consts.rs +++ b/src/test/codegen/consts.rs @@ -43,7 +43,7 @@ pub fn inline_enum_const() -> E { #[no_mangle] pub fn low_align_const() -> E { // Check that low_align_const and high_align_const use the same constant - // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 2 %1, i8* align 2 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) + // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 2 %1, i8* align 2 getelementptr inbounds (<{ [4 x i8], [4 x i8] }>, <{ [4 x i8], [4 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) *&E::A(0) } @@ -51,6 +51,6 @@ pub fn low_align_const() -> E { #[no_mangle] pub fn high_align_const() -> E { // Check that low_align_const and high_align_const use the same constant - // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) + // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [4 x i8] }>, <{ [4 x i8], [4 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) *&E::A(0) } diff --git a/src/test/codegen/uninit-consts.rs b/src/test/codegen/uninit-consts.rs new file mode 100644 index 000000000000..518bf7f451f2 --- /dev/null +++ b/src/test/codegen/uninit-consts.rs @@ -0,0 +1,51 @@ +// compile-flags: -C no-prepopulate-passes + +// Check that we use undef (and not zero) for uninitialized bytes in constants. + +#![crate_type = "lib"] + +use std::mem::MaybeUninit; + +pub struct PartiallyUninit { + x: u32, + y: MaybeUninit<[u8; 10]> +} + +// CHECK: [[FULLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [10 x i8] }> undef +// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4 +// CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef + +// This shouldn't contain undef, since generating huge partially undef constants is expensive. +// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4 + +// CHECK-LABEL: @fully_uninit +#[no_mangle] +pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> { + const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit(); + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 1 %1, i8* align 1 getelementptr inbounds (<{ [10 x i8] }>, <{ [10 x i8] }>* [[FULLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 10, i1 false) + M +} + +// CHECK-LABEL: @partially_uninit +#[no_mangle] +pub const fn partially_uninit() -> PartiallyUninit { + const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() }; + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [12 x i8] }>, <{ [4 x i8], [12 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false) + X +} + +// CHECK-LABEL: @fully_uninit_huge +#[no_mangle] +pub const fn fully_uninit_huge() -> MaybeUninit<[u32; 4096]> { + const F: MaybeUninit<[u32; 4096]> = MaybeUninit::uninit(); + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [16384 x i8] }>, <{ [16384 x i8] }>* [[FULLY_UNINIT_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 16384, i1 false) + F +} + +// CHECK-LABEL: @uninit_padding_huge +#[no_mangle] +pub const fn uninit_padding_huge() -> [(u32, u8); 4096] { + const X: [(u32, u8); 4096] = [(123, 45); 4096]; + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [32768 x i8] }>, <{ [32768 x i8] }>* [[UNINIT_PADDING_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 32768, i1 false) + X +} From 5e81d643d93e3a1316464b9c83c90ee26098ee7c Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 27 Apr 2021 00:15:41 -0400 Subject: [PATCH 139/269] don't generate partially-undef consts --- compiler/rustc_codegen_llvm/src/consts.rs | 22 +++++++----- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_session/src/options.rs | 3 ++ src/test/codegen/consts.rs | 4 +-- .../uninit-consts-allow-partially-uninit.rs | 35 +++++++++++++++++++ src/test/codegen/uninit-consts.rs | 15 ++------ 6 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 src/test/codegen/uninit-consts-allow-partially-uninit.rs diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 901fa9fb0474..3ece1659b9e0 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -36,11 +36,6 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll alloc: &'a Allocation, range: Range, ) { - /// Allocations larger than this will only be codegen'd as entirely initialized or entirely undef. - /// This avoids compile time regressions when an alloc would have many chunks, - /// e.g. for `[(u64, u8); N]`, which has undef padding in each element. - const MAX_PARTIALLY_UNDEF_SIZE: usize = 1024; - let mut chunks = alloc .init_mask() .range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end)); @@ -57,21 +52,30 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll } }; - if range.len() > MAX_PARTIALLY_UNDEF_SIZE { + // Generating partially-uninit consts inhibits optimizations, so it is disabled by default. + // See https://github.com/rust-lang/rust/issues/84565. + let allow_partially_uninit = + match cx.sess().opts.debugging_opts.partially_uninit_const_threshold { + Some(max) => range.len() <= max, + None => false, + }; + + if allow_partially_uninit { + llvals.extend(chunks.map(chunk_to_llval)); + } else { let llval = match (chunks.next(), chunks.next()) { (Some(chunk), None) => { // exactly one chunk, either fully init or fully uninit chunk_to_llval(chunk) } _ => { - // partially uninit + // partially uninit, codegen as if it was initialized + // (using some arbitrary value for uninit bytes) let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range); cx.const_bytes(bytes) } }; llvals.push(llval); - } else { - llvals.extend(chunks.map(chunk_to_llval)); } } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index b89614340069..afab919bc3c2 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -743,6 +743,7 @@ fn test_debugging_options_tracking_hash() { tracked!(no_profiler_runtime, true); tracked!(osx_rpath_install_name, true); tracked!(panic_abort_tests, true); + tracked!(partially_uninit_const_threshold, Some(123)); tracked!(plt, Some(true)); tracked!(polonius, true); tracked!(precise_enum_drop_elaboration, false); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index f36fc29e9741..9a1be40558cc 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1186,6 +1186,9 @@ options! { "support compiling tests with panic=abort (default: no)"), parse_only: bool = (false, parse_bool, [UNTRACKED], "parse only; do not compile, assemble, or link (default: no)"), + partially_uninit_const_threshold: Option = (None, parse_opt_number, [TRACKED], + "allow generating const initializers with mixed init/uninit bytes, \ + and set the maximum total size of a const allocation for which this is allowed (default: never)"), perf_stats: bool = (false, parse_bool, [UNTRACKED], "print some performance-related statistics (default: no)"), plt: Option = (None, parse_opt_bool, [TRACKED], diff --git a/src/test/codegen/consts.rs b/src/test/codegen/consts.rs index e47a9f9ee201..7f945299c22a 100644 --- a/src/test/codegen/consts.rs +++ b/src/test/codegen/consts.rs @@ -43,7 +43,7 @@ pub fn inline_enum_const() -> E { #[no_mangle] pub fn low_align_const() -> E { // Check that low_align_const and high_align_const use the same constant - // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 2 %1, i8* align 2 getelementptr inbounds (<{ [4 x i8], [4 x i8] }>, <{ [4 x i8], [4 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) + // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 2 %1, i8* align 2 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) *&E::A(0) } @@ -51,6 +51,6 @@ pub fn low_align_const() -> E { #[no_mangle] pub fn high_align_const() -> E { // Check that low_align_const and high_align_const use the same constant - // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [4 x i8] }>, <{ [4 x i8], [4 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) + // CHECK: memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [8 x i8] }>, <{ [8 x i8] }>* [[LOW_HIGH]], i32 0, i32 0, i32 0), i{{(32|64)}} 8, i1 false) *&E::A(0) } diff --git a/src/test/codegen/uninit-consts-allow-partially-uninit.rs b/src/test/codegen/uninit-consts-allow-partially-uninit.rs new file mode 100644 index 000000000000..f7420e4126ed --- /dev/null +++ b/src/test/codegen/uninit-consts-allow-partially-uninit.rs @@ -0,0 +1,35 @@ +// compile-flags: -C no-prepopulate-passes -Z partially_uninit_const_threshold=1024 + +// Like uninit-consts.rs, but tests that we correctly generate partially-uninit consts +// when the (disabled by default) partially_uninit_const_threshold flag is used. + +#![crate_type = "lib"] + +use std::mem::MaybeUninit; + +pub struct PartiallyUninit { + x: u32, + y: MaybeUninit<[u8; 10]> +} + +// This should be partially undef. +// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4 + +// This shouldn't contain undef, since it's larger than the 1024 byte limit. +// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4 + +// CHECK-LABEL: @partially_uninit +#[no_mangle] +pub const fn partially_uninit() -> PartiallyUninit { + const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() }; + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [12 x i8] }>, <{ [4 x i8], [12 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false) + X +} + +// CHECK-LABEL: @uninit_padding_huge +#[no_mangle] +pub const fn uninit_padding_huge() -> [(u32, u8); 4096] { + const X: [(u32, u8); 4096] = [(123, 45); 4096]; + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [32768 x i8] }>, <{ [32768 x i8] }>* [[UNINIT_PADDING_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 32768, i1 false) + X +} diff --git a/src/test/codegen/uninit-consts.rs b/src/test/codegen/uninit-consts.rs index 518bf7f451f2..c4c21e03f167 100644 --- a/src/test/codegen/uninit-consts.rs +++ b/src/test/codegen/uninit-consts.rs @@ -12,12 +12,9 @@ pub struct PartiallyUninit { } // CHECK: [[FULLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [10 x i8] }> undef -// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"\EF\BE\AD\DE", [12 x i8] undef }>, align 4 +// CHECK: [[PARTIALLY_UNINIT:@[0-9]+]] = private unnamed_addr constant <{ [16 x i8] }> <{ [16 x i8] c"\EF\BE\AD\DE\00\00\00\00\00\00\00\00\00\00\00\00" }>, align 4 // CHECK: [[FULLY_UNINIT_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [16384 x i8] }> undef -// This shouldn't contain undef, since generating huge partially undef constants is expensive. -// CHECK: [[UNINIT_PADDING_HUGE:@[0-9]+]] = private unnamed_addr constant <{ [32768 x i8] }> <{ [32768 x i8] c"{{.+}}" }>, align 4 - // CHECK-LABEL: @fully_uninit #[no_mangle] pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> { @@ -30,7 +27,7 @@ pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> { #[no_mangle] pub const fn partially_uninit() -> PartiallyUninit { const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeef, y: MaybeUninit::uninit() }; - // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [4 x i8], [12 x i8] }>, <{ [4 x i8], [12 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false) + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [16 x i8] }>, <{ [16 x i8] }>* [[PARTIALLY_UNINIT]], i32 0, i32 0, i32 0), i{{(32|64)}} 16, i1 false) X } @@ -41,11 +38,3 @@ pub const fn fully_uninit_huge() -> MaybeUninit<[u32; 4096]> { // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [16384 x i8] }>, <{ [16384 x i8] }>* [[FULLY_UNINIT_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 16384, i1 false) F } - -// CHECK-LABEL: @uninit_padding_huge -#[no_mangle] -pub const fn uninit_padding_huge() -> [(u32, u8); 4096] { - const X: [(u32, u8); 4096] = [(123, 45); 4096]; - // CHECK: call void @llvm.memcpy.p0i8.p0i8.i{{(32|64)}}(i8* align 4 %1, i8* align 4 getelementptr inbounds (<{ [32768 x i8] }>, <{ [32768 x i8] }>* [[UNINIT_PADDING_HUGE]], i32 0, i32 0, i32 0), i{{(32|64)}} 32768, i1 false) - X -} From c9599c4cacb4c5b9f8a2c353ac062885525960c9 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 10 Aug 2021 01:26:33 -0400 Subject: [PATCH 140/269] improve comment --- compiler/rustc_codegen_llvm/src/consts.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 3ece1659b9e0..a4e4fc4fffb8 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -29,7 +29,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll let pointer_size = dl.pointer_size.bytes() as usize; // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, - // so `range` must be within the bounds of `alloc` and not within a relocation. + // so `range` must be within the bounds of `alloc` and not contain or overlap a relocation. fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>( llvals: &mut Vec<&'ll Value>, cx: &'a CodegenCx<'ll, 'b>, From 1eaccab24e536f5708bef8538cfe0dca367ed544 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 10 Aug 2021 19:29:18 -0400 Subject: [PATCH 141/269] optimize initialization checks --- .../src/mir/interpret/allocation.rs | 111 ++++++++++++++++-- 1 file changed, 102 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 71580bcc06df..4040f4a112e7 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -1,7 +1,7 @@ //! The virtual memory representation of the MIR interpreter. use std::borrow::Cow; -use std::convert::TryFrom; +use std::convert::{TryFrom, TryInto}; use std::iter; use std::ops::{Deref, Range}; use std::ptr; @@ -720,13 +720,12 @@ impl InitMask { return Err(self.len..end); } - // FIXME(oli-obk): optimize this for allocations larger than a block. - let idx = (start..end).find(|&i| !self.get(i)); + let uninit_start = find_bit(self, start, end, false); - match idx { - Some(idx) => { - let uninit_end = (idx..end).find(|&i| self.get(i)).unwrap_or(end); - Err(idx..uninit_end) + match uninit_start { + Some(uninit_start) => { + let uninit_end = find_bit(self, uninit_start, end, true).unwrap_or(end); + Err(uninit_start..uninit_end) } None => Ok(()), } @@ -863,9 +862,8 @@ impl<'a> Iterator for InitChunkIter<'a> { } let is_init = self.init_mask.get(self.start); - // FIXME(oli-obk): optimize this for allocations larger than a block. let end_of_chunk = - (self.start..self.end).find(|&i| self.init_mask.get(i) != is_init).unwrap_or(self.end); + find_bit(&self.init_mask, self.start, self.end, !is_init).unwrap_or(self.end); let range = self.start..end_of_chunk; self.start = end_of_chunk; @@ -874,6 +872,94 @@ impl<'a> Iterator for InitChunkIter<'a> { } } +/// Returns the index of the first bit in `start..end` (end-exclusive) that is equal to is_init. +fn find_bit(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { + fn find_bit_fast(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { + fn search_block( + bits: Block, + block: usize, + start_bit: usize, + is_init: bool, + ) -> Option { + // invert bits so we're always looking for the first set bit + let bits = if is_init { bits } else { !bits }; + // mask off unused start bits + let bits = bits & (!0 << start_bit); + // find set bit, if any + if bits == 0 { + None + } else { + let bit = bits.trailing_zeros(); + Some(size_from_bit_index(block, bit)) + } + } + + if start >= end { + return None; + } + + let (start_block, start_bit) = bit_index(start); + let (end_block, end_bit) = bit_index(end); + + // handle first block: need to skip `start_bit` bits + if let Some(i) = + search_block(init_mask.blocks[start_block], start_block, start_bit, is_init) + { + if i < end { + return Some(i); + } else { + // if the range is less than a block, we may find a matching bit after `end` + return None; + } + } + + let one_block_past_the_end = if end_bit > 0 { + // if `end_bit` > 0, then the range overlaps `end_block` + end_block + 1 + } else { + end_block + }; + + // handle remaining blocks + if start_block < one_block_past_the_end { + for (&bits, block) in init_mask.blocks[start_block + 1..one_block_past_the_end] + .iter() + .zip(start_block + 1..) + { + if let Some(i) = search_block(bits, block, 0, is_init) { + if i < end { + return Some(i); + } else { + // if this is the last block, we may find a matching bit after `end` + return None; + } + } + } + } + + None + } + + #[cfg_attr(not(debug_assertions), allow(dead_code))] + fn find_bit_slow(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { + (start..end).find(|&i| init_mask.get(i) == is_init) + } + + let result = find_bit_fast(init_mask, start, end, is_init); + + debug_assert_eq!( + result, + find_bit_slow(init_mask, start, end, is_init), + "optimized implementation of find_bit is wrong for start={:?} end={:?} is_init={} init_mask={:#?}", + start, + end, + is_init, + init_mask + ); + + result +} + #[inline] fn bit_index(bits: Size) -> (usize, usize) { let bits = bits.bytes(); @@ -881,3 +967,10 @@ fn bit_index(bits: Size) -> (usize, usize) { let b = bits % InitMask::BLOCK_SIZE; (usize::try_from(a).unwrap(), usize::try_from(b).unwrap()) } + +#[inline] +fn size_from_bit_index(block: impl TryInto, bit: impl TryInto) -> Size { + let block = block.try_into().ok().unwrap(); + let bit = bit.try_into().ok().unwrap(); + Size::from_bytes(block * InitMask::BLOCK_SIZE + bit) +} From 3c2b706da60f3a2d2e5421ac1a7e137a50b18a25 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 10 Aug 2021 23:16:11 -0400 Subject: [PATCH 142/269] implement InitMaskCompressed using InitChunkIter, cleanup --- .../src/mir/interpret/allocation.rs | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 4040f4a112e7..348cf7612859 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -563,22 +563,12 @@ impl Allocation { let mut ranges = smallvec::SmallVec::<[u64; 1]>::new(); let initial = self.init_mask.get(range.start); - let mut cur_len = 1; - let mut cur = initial; - for i in 1..range.size.bytes() { - // FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit. - if self.init_mask.get(range.start + Size::from_bytes(i)) == cur { - cur_len += 1; - } else { - ranges.push(cur_len); - cur_len = 1; - cur = !cur; - } + for chunk in self.init_mask.range_as_init_chunks(range.start, range.end()) { + let len = chunk.range().end.bytes() - chunk.range().start.bytes(); + ranges.push(len); } - ranges.push(cur_len); - InitMaskCompressed { ranges, initial } } @@ -830,45 +820,65 @@ impl InitMask { } } +/// A contiguous chunk of initialized or uninitialized memory. +pub enum InitChunk { + Init(Range), + Uninit(Range), +} + +impl InitChunk { + #[inline] + pub fn range(&self) -> Range { + match self { + Self::Init(r) => r.clone(), + Self::Uninit(r) => r.clone(), + } + } +} + /// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`]. pub struct InitChunkIter<'a> { init_mask: &'a InitMask, + /// Whether the last chunk was initialized. + is_init: bool, /// The current byte index into `init_mask`. start: Size, /// The end byte index into `init_mask`. end: Size, } -/// A contiguous chunk of initialized or uninitialized memory. -pub enum InitChunk { - Init(Range), - Uninit(Range), -} - impl<'a> InitChunkIter<'a> { + #[inline] fn new(init_mask: &'a InitMask, start: Size, end: Size) -> Self { assert!(start <= end); assert!(end <= init_mask.len); - Self { init_mask, start, end } + + let is_init = if start < end { init_mask.get(start) } else { false }; + + Self { init_mask, is_init, start, end } } } impl<'a> Iterator for InitChunkIter<'a> { type Item = InitChunk; + #[inline] fn next(&mut self) -> Option { if self.start >= self.end { return None; } - let is_init = self.init_mask.get(self.start); let end_of_chunk = - find_bit(&self.init_mask, self.start, self.end, !is_init).unwrap_or(self.end); + find_bit(&self.init_mask, self.start, self.end, !self.is_init).unwrap_or(self.end); let range = self.start..end_of_chunk; + let ret = + Some(if self.is_init { InitChunk::Init(range) } else { InitChunk::Uninit(range) }); + + self.is_init = !self.is_init; self.start = end_of_chunk; - Some(if is_init { InitChunk::Init(range) } else { InitChunk::Uninit(range) }) + ret } } From 5bef23d0fac977c9a57fd2900df3381bbbace86a Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 14 Aug 2021 13:54:35 -0400 Subject: [PATCH 143/269] add comments --- .../src/mir/interpret/allocation.rs | 138 +++++++++++++++--- 1 file changed, 119 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 348cf7612859..e636d7612b43 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -548,6 +548,9 @@ impl InitMaskCompressed { /// Transferring the initialization mask to other allocations. impl Allocation { /// Creates a run-length encoding of the initialization mask. + /// + /// This is essentially a more space-efficient version of + /// `InitMask::range_as_init_chunks(...).collect::>()`. pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed { // Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`), // a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from @@ -723,6 +726,12 @@ impl InitMask { /// Returns an iterator, yielding a range of byte indexes for each contiguous region /// of initialized or uninitialized bytes inside the range `start..end` (end-exclusive). + /// + /// The iterator guarantees the following: + /// - Chunks are nonempty. + /// - Chunks are adjacent (each range's start is equal to the previous range's end). + /// - Chunks span exactly `start..end` (the first starts at `start`, the last ends at `end`). + /// - Chunks alternate between [`InitChunk::Init`] and [`InitChunk::Uninit`]. #[inline] pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_> { InitChunkIter::new(self, start, end) @@ -839,7 +848,7 @@ impl InitChunk { /// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`]. pub struct InitChunkIter<'a> { init_mask: &'a InitMask, - /// Whether the last chunk was initialized. + /// Whether the next chunk we will return is initialized. is_init: bool, /// The current byte index into `init_mask`. start: Size, @@ -884,18 +893,45 @@ impl<'a> Iterator for InitChunkIter<'a> { /// Returns the index of the first bit in `start..end` (end-exclusive) that is equal to is_init. fn find_bit(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { + /// A fast implementation of `find_bit`, + /// which skips over an entire block at a time if it's all 0s (resp. 1s), + /// and finds the first 1 (resp. 0) bit inside a block using `trailing_zeros` instead of a loop. + /// + /// Note that all examples below are written with 8 (instead of 64) bit blocks for simplicity, + /// and with the least significant bit (and lowest block) first: + /// + /// 00000000|00000000 + /// ^ ^ ^ ^ + /// index: 0 7 8 15 + /// + /// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit. fn find_bit_fast(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { + /// Search one block, returning the index of the first bit equal to `is_init`. fn search_block( bits: Block, block: usize, start_bit: usize, is_init: bool, ) -> Option { - // invert bits so we're always looking for the first set bit + // For the following examples, assume this function was called with: + // bits = 11011100 + // start_bit = 3 + // is_init = false + // Note again that the least significant bit is written first, + // which is backwards compared to how we normally write numbers. + + // Invert bits so we're always looking for the first set bit. + // ! 11011100 + // bits = 00100011 let bits = if is_init { bits } else { !bits }; - // mask off unused start bits + // Mask off unused start bits. + // 00100011 + // & 00011111 + // bits = 00000011 let bits = bits & (!0 << start_bit); - // find set bit, if any + // Find set bit, if any. + // bit = trailing_zeros(00000011) + // bit = 6 if bits == 0 { None } else { @@ -908,31 +944,83 @@ fn find_bit(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Opti return None; } + // Convert `start` and `end` to block indexes and bit indexes within each block. + // We must convert `end` to an inclusive bound to handle block boundaries correctly. + // + // For example: + // + // (a) 00000000|00000000 (b) 00000000| + // ^~~~~~~~~~~^ ^~~~~~~~~^ + // start end start end + // + // In both cases, the block index of `end` is 1. + // But we do want to search block 1 in (a), and we don't in (b). + // + // If we subtract 1 from both end positions to make them inclusive: + // + // (a) 00000000|00000000 (b) 00000000| + // ^~~~~~~~~~^ ^~~~~~~^ + // start end_inclusive start end_inclusive + // + // For (a), the block index of `end_inclusive` is 1, and for (b), it's 0. + // This provides the desired behavior of searching blocks 0 and 1 for (a), + // and searching only block 0 for (b). let (start_block, start_bit) = bit_index(start); - let (end_block, end_bit) = bit_index(end); - - // handle first block: need to skip `start_bit` bits + let end_inclusive = Size::from_bytes(end.bytes() - 1); + let (end_block_inclusive, _) = bit_index(end_inclusive); + + // Handle first block: need to skip `start_bit` bits. + // + // We need to handle the first block separately, + // because there may be bits earlier in the block that should be ignored, + // such as the bit marked (1) in this example: + // + // (1) + // -|------ + // (c) 01000000|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end if let Some(i) = search_block(init_mask.blocks[start_block], start_block, start_bit, is_init) { if i < end { return Some(i); } else { - // if the range is less than a block, we may find a matching bit after `end` + // If the range is less than a block, we may find a matching bit after `end`. + // + // For example, we shouldn't successfully find bit (2), because it's after `end`: + // + // (2) + // -------| + // (d) 00000001|00000000|00000001 + // ^~~~~^ + // start end + // + // An alternative would be to mask off end bits in the same way as we do for start bits, + // but performing this check afterwards is faster and simpler to implement. return None; } } - let one_block_past_the_end = if end_bit > 0 { - // if `end_bit` > 0, then the range overlaps `end_block` - end_block + 1 - } else { - end_block - }; - - // handle remaining blocks - if start_block < one_block_past_the_end { - for (&bits, block) in init_mask.blocks[start_block + 1..one_block_past_the_end] + // Handle remaining blocks. + // + // We can skip over an entire block at once if it's all 0s (resp. 1s). + // The block marked (3) in this example is the first block that will be handled by this loop, + // and it will be skipped for that reason: + // + // (3) + // -------- + // (e) 01000000|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end + if start_block < end_block_inclusive { + // This loop is written in a specific way for performance. + // Notably: `..end_block_inclusive + 1` is used for an inclusive range instead of `..=end_block_inclusive`, + // and `.zip(start_block + 1..)` is used to track the index instead of `.enumerate().skip().take()`, + // because both alternatives result in significantly worse codegen. + // `end_block_inclusive + 1` is guaranteed not to wrap, because `end_block_inclusive <= end / BLOCK_SIZE`, + // and `BLOCK_SIZE` (the number of bits per block) will always be at least 8 (1 byte). + for (&bits, block) in init_mask.blocks[start_block + 1..end_block_inclusive + 1] .iter() .zip(start_block + 1..) { @@ -940,7 +1028,19 @@ fn find_bit(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Opti if i < end { return Some(i); } else { - // if this is the last block, we may find a matching bit after `end` + // If this is the last block, we may find a matching bit after `end`. + // + // For example, we shouldn't successfully find bit (4), because it's after `end`: + // + // (4) + // -------| + // (f) 00000001|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end + // + // As above with example (d), we could handle the end block separately and mask off end bits, + // but unconditionally searching an entire block at once and performing this check afterwards + // is faster and much simpler to implement. return None; } } From e950f110194c4f9f513fab48448ceb451f818e46 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 14 Aug 2021 14:13:06 -0400 Subject: [PATCH 144/269] put code in a more logical order --- .../src/mir/interpret/allocation.rs | 695 +++++++++--------- 1 file changed, 350 insertions(+), 345 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index e636d7612b43..27a637f2f4f7 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -495,122 +495,6 @@ impl Allocation { } } -/// Uninitialized bytes. -impl Allocation { - /// Checks whether the given range is entirely initialized. - /// - /// Returns `Ok(())` if it's initialized. Otherwise returns the range of byte - /// indexes of the first contiguous uninitialized access. - fn is_init(&self, range: AllocRange) -> Result<(), Range> { - self.init_mask.is_range_initialized(range.start, range.end()) // `Size` addition - } - - /// Checks that a range of bytes is initialized. If not, returns the `InvalidUninitBytes` - /// error which will report the first range of bytes which is uninitialized. - fn check_init(&self, range: AllocRange) -> AllocResult { - self.is_init(range).or_else(|idx_range| { - Err(AllocError::InvalidUninitBytes(Some(UninitBytesAccess { - access_offset: range.start, - access_size: range.size, - uninit_offset: idx_range.start, - uninit_size: idx_range.end - idx_range.start, // `Size` subtraction - }))) - }) - } - - pub fn mark_init(&mut self, range: AllocRange, is_init: bool) { - if range.size.bytes() == 0 { - return; - } - assert!(self.mutability == Mutability::Mut); - self.init_mask.set_range(range.start, range.end(), is_init); - } -} - -/// Run-length encoding of the uninit mask. -/// Used to copy parts of a mask multiple times to another allocation. -pub struct InitMaskCompressed { - /// Whether the first range is initialized. - initial: bool, - /// The lengths of ranges that are run-length encoded. - /// The initialization state of the ranges alternate starting with `initial`. - ranges: smallvec::SmallVec<[u64; 1]>, -} - -impl InitMaskCompressed { - pub fn no_bytes_init(&self) -> bool { - // The `ranges` are run-length encoded and of alternating initialization state. - // So if `ranges.len() > 1` then the second block is an initialized range. - !self.initial && self.ranges.len() == 1 - } -} - -/// Transferring the initialization mask to other allocations. -impl Allocation { - /// Creates a run-length encoding of the initialization mask. - /// - /// This is essentially a more space-efficient version of - /// `InitMask::range_as_init_chunks(...).collect::>()`. - pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed { - // Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`), - // a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from - // the source and write it to the destination. Even if we optimized the memory accesses, - // we'd be doing all of this `repeat` times. - // Therefore we precompute a compressed version of the initialization mask of the source value and - // then write it back `repeat` times without computing any more information from the source. - - // A precomputed cache for ranges of initialized / uninitialized bits - // 0000010010001110 will become - // `[5, 1, 2, 1, 3, 3, 1]`, - // where each element toggles the state. - - let mut ranges = smallvec::SmallVec::<[u64; 1]>::new(); - let initial = self.init_mask.get(range.start); - - for chunk in self.init_mask.range_as_init_chunks(range.start, range.end()) { - let len = chunk.range().end.bytes() - chunk.range().start.bytes(); - ranges.push(len); - } - - InitMaskCompressed { ranges, initial } - } - - /// Applies multiple instances of the run-length encoding to the initialization mask. - pub fn mark_compressed_init_range( - &mut self, - defined: &InitMaskCompressed, - range: AllocRange, - repeat: u64, - ) { - // An optimization where we can just overwrite an entire range of initialization - // bits if they are going to be uniformly `1` or `0`. - if defined.ranges.len() <= 1 { - self.init_mask.set_range_inbounds( - range.start, - range.start + range.size * repeat, // `Size` operations - defined.initial, - ); - return; - } - - for mut j in 0..repeat { - j *= range.size.bytes(); - j += range.start.bytes(); - let mut cur = defined.initial; - for range in &defined.ranges { - let old_j = j; - j += range; - self.init_mask.set_range_inbounds( - Size::from_bytes(old_j), - Size::from_bytes(j), - cur, - ); - cur = !cur; - } - } - } -} - /// "Relocations" stores the provenance information of pointers stored in memory. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] pub struct Relocations(SortedMap); @@ -697,44 +581,25 @@ pub struct InitMask { impl InitMask { pub const BLOCK_SIZE: u64 = 64; - pub fn new(size: Size, state: bool) -> Self { - let mut m = InitMask { blocks: vec![], len: Size::ZERO }; - m.grow(size, state); - m + #[inline] + fn bit_index(bits: Size) -> (usize, usize) { + let bits = bits.bytes(); + let a = bits / InitMask::BLOCK_SIZE; + let b = bits % InitMask::BLOCK_SIZE; + (usize::try_from(a).unwrap(), usize::try_from(b).unwrap()) } - /// Checks whether the range `start..end` (end-exclusive) is entirely initialized. - /// - /// Returns `Ok(())` if it's initialized. Otherwise returns a range of byte - /// indexes for the first contiguous span of the uninitialized access. #[inline] - pub fn is_range_initialized(&self, start: Size, end: Size) -> Result<(), Range> { - if end > self.len { - return Err(self.len..end); - } - - let uninit_start = find_bit(self, start, end, false); - - match uninit_start { - Some(uninit_start) => { - let uninit_end = find_bit(self, uninit_start, end, true).unwrap_or(end); - Err(uninit_start..uninit_end) - } - None => Ok(()), - } + fn size_from_bit_index(block: impl TryInto, bit: impl TryInto) -> Size { + let block = block.try_into().ok().unwrap(); + let bit = bit.try_into().ok().unwrap(); + Size::from_bytes(block * InitMask::BLOCK_SIZE + bit) } - /// Returns an iterator, yielding a range of byte indexes for each contiguous region - /// of initialized or uninitialized bytes inside the range `start..end` (end-exclusive). - /// - /// The iterator guarantees the following: - /// - Chunks are nonempty. - /// - Chunks are adjacent (each range's start is equal to the previous range's end). - /// - Chunks span exactly `start..end` (the first starts at `start`, the last ends at `end`). - /// - Chunks alternate between [`InitChunk::Init`] and [`InitChunk::Uninit`]. - #[inline] - pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_> { - InitChunkIter::new(self, start, end) + pub fn new(size: Size, state: bool) -> Self { + let mut m = InitMask { blocks: vec![], len: Size::ZERO }; + m.grow(size, state); + m } pub fn set_range(&mut self, start: Size, end: Size, new_state: bool) { @@ -746,8 +611,8 @@ impl InitMask { } pub fn set_range_inbounds(&mut self, start: Size, end: Size, new_state: bool) { - let (blocka, bita) = bit_index(start); - let (blockb, bitb) = bit_index(end); + let (blocka, bita) = Self::bit_index(start); + let (blockb, bitb) = Self::bit_index(end); if blocka == blockb { // First set all bits except the first `bita`, // then unset the last `64 - bitb` bits. @@ -791,13 +656,13 @@ impl InitMask { #[inline] pub fn get(&self, i: Size) -> bool { - let (block, bit) = bit_index(i); + let (block, bit) = Self::bit_index(i); (self.blocks[block] & (1 << bit)) != 0 } #[inline] pub fn set(&mut self, i: Size, new_state: bool) { - let (block, bit) = bit_index(i); + let (block, bit) = Self::bit_index(i); self.set_bit(block, bit, new_state); } @@ -827,6 +692,195 @@ impl InitMask { self.len += amount; self.set_range_inbounds(start, start + amount, new_state); // `Size` operation } + + /// Returns the index of the first bit in `start..end` (end-exclusive) that is equal to is_init. + fn find_bit(&self, start: Size, end: Size, is_init: bool) -> Option { + /// A fast implementation of `find_bit`, + /// which skips over an entire block at a time if it's all 0s (resp. 1s), + /// and finds the first 1 (resp. 0) bit inside a block using `trailing_zeros` instead of a loop. + /// + /// Note that all examples below are written with 8 (instead of 64) bit blocks for simplicity, + /// and with the least significant bit (and lowest block) first: + /// + /// 00000000|00000000 + /// ^ ^ ^ ^ + /// index: 0 7 8 15 + /// + /// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit. + fn find_bit_fast( + init_mask: &InitMask, + start: Size, + end: Size, + is_init: bool, + ) -> Option { + /// Search one block, returning the index of the first bit equal to `is_init`. + fn search_block( + bits: Block, + block: usize, + start_bit: usize, + is_init: bool, + ) -> Option { + // For the following examples, assume this function was called with: + // bits = 11011100 + // start_bit = 3 + // is_init = false + // Note again that the least significant bit is written first, + // which is backwards compared to how we normally write numbers. + + // Invert bits so we're always looking for the first set bit. + // ! 11011100 + // bits = 00100011 + let bits = if is_init { bits } else { !bits }; + // Mask off unused start bits. + // 00100011 + // & 00011111 + // bits = 00000011 + let bits = bits & (!0 << start_bit); + // Find set bit, if any. + // bit = trailing_zeros(00000011) + // bit = 6 + if bits == 0 { + None + } else { + let bit = bits.trailing_zeros(); + Some(InitMask::size_from_bit_index(block, bit)) + } + } + + if start >= end { + return None; + } + + // Convert `start` and `end` to block indexes and bit indexes within each block. + // We must convert `end` to an inclusive bound to handle block boundaries correctly. + // + // For example: + // + // (a) 00000000|00000000 (b) 00000000| + // ^~~~~~~~~~~^ ^~~~~~~~~^ + // start end start end + // + // In both cases, the block index of `end` is 1. + // But we do want to search block 1 in (a), and we don't in (b). + // + // If we subtract 1 from both end positions to make them inclusive: + // + // (a) 00000000|00000000 (b) 00000000| + // ^~~~~~~~~~^ ^~~~~~~^ + // start end_inclusive start end_inclusive + // + // For (a), the block index of `end_inclusive` is 1, and for (b), it's 0. + // This provides the desired behavior of searching blocks 0 and 1 for (a), + // and searching only block 0 for (b). + let (start_block, start_bit) = InitMask::bit_index(start); + let end_inclusive = Size::from_bytes(end.bytes() - 1); + let (end_block_inclusive, _) = InitMask::bit_index(end_inclusive); + + // Handle first block: need to skip `start_bit` bits. + // + // We need to handle the first block separately, + // because there may be bits earlier in the block that should be ignored, + // such as the bit marked (1) in this example: + // + // (1) + // -|------ + // (c) 01000000|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end + if let Some(i) = + search_block(init_mask.blocks[start_block], start_block, start_bit, is_init) + { + // If the range is less than a block, we may find a matching bit after `end`. + // + // For example, we shouldn't successfully find bit (2), because it's after `end`: + // + // (2) + // -------| + // (d) 00000001|00000000|00000001 + // ^~~~~^ + // start end + // + // An alternative would be to mask off end bits in the same way as we do for start bits, + // but performing this check afterwards is faster and simpler to implement. + if i < end { + return Some(i); + } else { + return None; + } + } + + // Handle remaining blocks. + // + // We can skip over an entire block at once if it's all 0s (resp. 1s). + // The block marked (3) in this example is the first block that will be handled by this loop, + // and it will be skipped for that reason: + // + // (3) + // -------- + // (e) 01000000|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end + if start_block < end_block_inclusive { + // This loop is written in a specific way for performance. + // Notably: `..end_block_inclusive + 1` is used for an inclusive range instead of `..=end_block_inclusive`, + // and `.zip(start_block + 1..)` is used to track the index instead of `.enumerate().skip().take()`, + // because both alternatives result in significantly worse codegen. + // `end_block_inclusive + 1` is guaranteed not to wrap, because `end_block_inclusive <= end / BLOCK_SIZE`, + // and `BLOCK_SIZE` (the number of bits per block) will always be at least 8 (1 byte). + for (&bits, block) in init_mask.blocks[start_block + 1..end_block_inclusive + 1] + .iter() + .zip(start_block + 1..) + { + if let Some(i) = search_block(bits, block, 0, is_init) { + // If this is the last block, we may find a matching bit after `end`. + // + // For example, we shouldn't successfully find bit (4), because it's after `end`: + // + // (4) + // -------| + // (f) 00000001|00000000|00000001 + // ^~~~~~~~~~~~~~~~~~^ + // start end + // + // As above with example (d), we could handle the end block separately and mask off end bits, + // but unconditionally searching an entire block at once and performing this check afterwards + // is faster and much simpler to implement. + if i < end { + return Some(i); + } else { + return None; + } + } + } + } + + None + } + + #[cfg_attr(not(debug_assertions), allow(dead_code))] + fn find_bit_slow( + init_mask: &InitMask, + start: Size, + end: Size, + is_init: bool, + ) -> Option { + (start..end).find(|&i| init_mask.get(i) == is_init) + } + + let result = find_bit_fast(self, start, end, is_init); + + debug_assert_eq!( + result, + find_bit_slow(self, start, end, is_init), + "optimized implementation of find_bit is wrong for start={:?} end={:?} is_init={} init_mask={:#?}", + start, + end, + is_init, + self + ); + + result + } } /// A contiguous chunk of initialized or uninitialized memory. @@ -845,10 +899,51 @@ impl InitChunk { } } +impl InitMask { + /// Checks whether the range `start..end` (end-exclusive) is entirely initialized. + /// + /// Returns `Ok(())` if it's initialized. Otherwise returns a range of byte + /// indexes for the first contiguous span of the uninitialized access. + #[inline] + pub fn is_range_initialized(&self, start: Size, end: Size) -> Result<(), Range> { + if end > self.len { + return Err(self.len..end); + } + + let uninit_start = self.find_bit(start, end, false); + + match uninit_start { + Some(uninit_start) => { + let uninit_end = self.find_bit(uninit_start, end, true).unwrap_or(end); + Err(uninit_start..uninit_end) + } + None => Ok(()), + } + } + + /// Returns an iterator, yielding a range of byte indexes for each contiguous region + /// of initialized or uninitialized bytes inside the range `start..end` (end-exclusive). + /// + /// The iterator guarantees the following: + /// - Chunks are nonempty. + /// - Chunks are adjacent (each range's start is equal to the previous range's end). + /// - Chunks span exactly `start..end` (the first starts at `start`, the last ends at `end`). + /// - Chunks alternate between [`InitChunk::Init`] and [`InitChunk::Uninit`]. + #[inline] + pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_> { + assert!(end <= self.len); + + let is_init = if start < end { self.get(start) } else { false }; + + InitChunkIter { init_mask: self, is_init, start, end } + } +} + /// Yields [`InitChunk`]s. See [`InitMask::range_as_init_chunks`]. pub struct InitChunkIter<'a> { init_mask: &'a InitMask, /// Whether the next chunk we will return is initialized. + /// If there are no more chunks, contains some arbitrary value. is_init: bool, /// The current byte index into `init_mask`. start: Size, @@ -856,18 +951,6 @@ pub struct InitChunkIter<'a> { end: Size, } -impl<'a> InitChunkIter<'a> { - #[inline] - fn new(init_mask: &'a InitMask, start: Size, end: Size) -> Self { - assert!(start <= end); - assert!(end <= init_mask.len); - - let is_init = if start < end { init_mask.get(start) } else { false }; - - Self { init_mask, is_init, start, end } - } -} - impl<'a> Iterator for InitChunkIter<'a> { type Item = InitChunk; @@ -878,7 +961,7 @@ impl<'a> Iterator for InitChunkIter<'a> { } let end_of_chunk = - find_bit(&self.init_mask, self.start, self.end, !self.is_init).unwrap_or(self.end); + self.init_mask.find_bit(self.start, self.end, !self.is_init).unwrap_or(self.end); let range = self.start..end_of_chunk; let ret = @@ -891,196 +974,118 @@ impl<'a> Iterator for InitChunkIter<'a> { } } -/// Returns the index of the first bit in `start..end` (end-exclusive) that is equal to is_init. -fn find_bit(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { - /// A fast implementation of `find_bit`, - /// which skips over an entire block at a time if it's all 0s (resp. 1s), - /// and finds the first 1 (resp. 0) bit inside a block using `trailing_zeros` instead of a loop. - /// - /// Note that all examples below are written with 8 (instead of 64) bit blocks for simplicity, - /// and with the least significant bit (and lowest block) first: - /// - /// 00000000|00000000 - /// ^ ^ ^ ^ - /// index: 0 7 8 15 +/// Uninitialized bytes. +impl Allocation { + /// Checks whether the given range is entirely initialized. /// - /// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit. - fn find_bit_fast(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { - /// Search one block, returning the index of the first bit equal to `is_init`. - fn search_block( - bits: Block, - block: usize, - start_bit: usize, - is_init: bool, - ) -> Option { - // For the following examples, assume this function was called with: - // bits = 11011100 - // start_bit = 3 - // is_init = false - // Note again that the least significant bit is written first, - // which is backwards compared to how we normally write numbers. - - // Invert bits so we're always looking for the first set bit. - // ! 11011100 - // bits = 00100011 - let bits = if is_init { bits } else { !bits }; - // Mask off unused start bits. - // 00100011 - // & 00011111 - // bits = 00000011 - let bits = bits & (!0 << start_bit); - // Find set bit, if any. - // bit = trailing_zeros(00000011) - // bit = 6 - if bits == 0 { - None - } else { - let bit = bits.trailing_zeros(); - Some(size_from_bit_index(block, bit)) - } - } + /// Returns `Ok(())` if it's initialized. Otherwise returns the range of byte + /// indexes of the first contiguous uninitialized access. + fn is_init(&self, range: AllocRange) -> Result<(), Range> { + self.init_mask.is_range_initialized(range.start, range.end()) // `Size` addition + } - if start >= end { - return None; - } + /// Checks that a range of bytes is initialized. If not, returns the `InvalidUninitBytes` + /// error which will report the first range of bytes which is uninitialized. + fn check_init(&self, range: AllocRange) -> AllocResult { + self.is_init(range).or_else(|idx_range| { + Err(AllocError::InvalidUninitBytes(Some(UninitBytesAccess { + access_offset: range.start, + access_size: range.size, + uninit_offset: idx_range.start, + uninit_size: idx_range.end - idx_range.start, // `Size` subtraction + }))) + }) + } - // Convert `start` and `end` to block indexes and bit indexes within each block. - // We must convert `end` to an inclusive bound to handle block boundaries correctly. - // - // For example: - // - // (a) 00000000|00000000 (b) 00000000| - // ^~~~~~~~~~~^ ^~~~~~~~~^ - // start end start end - // - // In both cases, the block index of `end` is 1. - // But we do want to search block 1 in (a), and we don't in (b). - // - // If we subtract 1 from both end positions to make them inclusive: - // - // (a) 00000000|00000000 (b) 00000000| - // ^~~~~~~~~~^ ^~~~~~~^ - // start end_inclusive start end_inclusive - // - // For (a), the block index of `end_inclusive` is 1, and for (b), it's 0. - // This provides the desired behavior of searching blocks 0 and 1 for (a), - // and searching only block 0 for (b). - let (start_block, start_bit) = bit_index(start); - let end_inclusive = Size::from_bytes(end.bytes() - 1); - let (end_block_inclusive, _) = bit_index(end_inclusive); - - // Handle first block: need to skip `start_bit` bits. - // - // We need to handle the first block separately, - // because there may be bits earlier in the block that should be ignored, - // such as the bit marked (1) in this example: - // - // (1) - // -|------ - // (c) 01000000|00000000|00000001 - // ^~~~~~~~~~~~~~~~~~^ - // start end - if let Some(i) = - search_block(init_mask.blocks[start_block], start_block, start_bit, is_init) - { - if i < end { - return Some(i); - } else { - // If the range is less than a block, we may find a matching bit after `end`. - // - // For example, we shouldn't successfully find bit (2), because it's after `end`: - // - // (2) - // -------| - // (d) 00000001|00000000|00000001 - // ^~~~~^ - // start end - // - // An alternative would be to mask off end bits in the same way as we do for start bits, - // but performing this check afterwards is faster and simpler to implement. - return None; - } + pub fn mark_init(&mut self, range: AllocRange, is_init: bool) { + if range.size.bytes() == 0 { + return; } + assert!(self.mutability == Mutability::Mut); + self.init_mask.set_range(range.start, range.end(), is_init); + } +} - // Handle remaining blocks. - // - // We can skip over an entire block at once if it's all 0s (resp. 1s). - // The block marked (3) in this example is the first block that will be handled by this loop, - // and it will be skipped for that reason: - // - // (3) - // -------- - // (e) 01000000|00000000|00000001 - // ^~~~~~~~~~~~~~~~~~^ - // start end - if start_block < end_block_inclusive { - // This loop is written in a specific way for performance. - // Notably: `..end_block_inclusive + 1` is used for an inclusive range instead of `..=end_block_inclusive`, - // and `.zip(start_block + 1..)` is used to track the index instead of `.enumerate().skip().take()`, - // because both alternatives result in significantly worse codegen. - // `end_block_inclusive + 1` is guaranteed not to wrap, because `end_block_inclusive <= end / BLOCK_SIZE`, - // and `BLOCK_SIZE` (the number of bits per block) will always be at least 8 (1 byte). - for (&bits, block) in init_mask.blocks[start_block + 1..end_block_inclusive + 1] - .iter() - .zip(start_block + 1..) - { - if let Some(i) = search_block(bits, block, 0, is_init) { - if i < end { - return Some(i); - } else { - // If this is the last block, we may find a matching bit after `end`. - // - // For example, we shouldn't successfully find bit (4), because it's after `end`: - // - // (4) - // -------| - // (f) 00000001|00000000|00000001 - // ^~~~~~~~~~~~~~~~~~^ - // start end - // - // As above with example (d), we could handle the end block separately and mask off end bits, - // but unconditionally searching an entire block at once and performing this check afterwards - // is faster and much simpler to implement. - return None; - } - } - } - } +/// Run-length encoding of the uninit mask. +/// Used to copy parts of a mask multiple times to another allocation. +pub struct InitMaskCompressed { + /// Whether the first range is initialized. + initial: bool, + /// The lengths of ranges that are run-length encoded. + /// The initialization state of the ranges alternate starting with `initial`. + ranges: smallvec::SmallVec<[u64; 1]>, +} - None +impl InitMaskCompressed { + pub fn no_bytes_init(&self) -> bool { + // The `ranges` are run-length encoded and of alternating initialization state. + // So if `ranges.len() > 1` then the second block is an initialized range. + !self.initial && self.ranges.len() == 1 } +} - #[cfg_attr(not(debug_assertions), allow(dead_code))] - fn find_bit_slow(init_mask: &InitMask, start: Size, end: Size, is_init: bool) -> Option { - (start..end).find(|&i| init_mask.get(i) == is_init) - } +/// Transferring the initialization mask to other allocations. +impl Allocation { + /// Creates a run-length encoding of the initialization mask. + /// + /// This is essentially a more space-efficient version of + /// `InitMask::range_as_init_chunks(...).collect::>()`. + pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed { + // Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`), + // a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from + // the source and write it to the destination. Even if we optimized the memory accesses, + // we'd be doing all of this `repeat` times. + // Therefore we precompute a compressed version of the initialization mask of the source value and + // then write it back `repeat` times without computing any more information from the source. - let result = find_bit_fast(init_mask, start, end, is_init); + // A precomputed cache for ranges of initialized / uninitialized bits + // 0000010010001110 will become + // `[5, 1, 2, 1, 3, 3, 1]`, + // where each element toggles the state. - debug_assert_eq!( - result, - find_bit_slow(init_mask, start, end, is_init), - "optimized implementation of find_bit is wrong for start={:?} end={:?} is_init={} init_mask={:#?}", - start, - end, - is_init, - init_mask - ); + let mut ranges = smallvec::SmallVec::<[u64; 1]>::new(); + let initial = self.init_mask.get(range.start); - result -} + for chunk in self.init_mask.range_as_init_chunks(range.start, range.end()) { + let len = chunk.range().end.bytes() - chunk.range().start.bytes(); + ranges.push(len); + } -#[inline] -fn bit_index(bits: Size) -> (usize, usize) { - let bits = bits.bytes(); - let a = bits / InitMask::BLOCK_SIZE; - let b = bits % InitMask::BLOCK_SIZE; - (usize::try_from(a).unwrap(), usize::try_from(b).unwrap()) -} + InitMaskCompressed { ranges, initial } + } + + /// Applies multiple instances of the run-length encoding to the initialization mask. + pub fn mark_compressed_init_range( + &mut self, + defined: &InitMaskCompressed, + range: AllocRange, + repeat: u64, + ) { + // An optimization where we can just overwrite an entire range of initialization + // bits if they are going to be uniformly `1` or `0`. + if defined.ranges.len() <= 1 { + self.init_mask.set_range_inbounds( + range.start, + range.start + range.size * repeat, // `Size` operations + defined.initial, + ); + return; + } -#[inline] -fn size_from_bit_index(block: impl TryInto, bit: impl TryInto) -> Size { - let block = block.try_into().ok().unwrap(); - let bit = bit.try_into().ok().unwrap(); - Size::from_bytes(block * InitMask::BLOCK_SIZE + bit) + for mut j in 0..repeat { + j *= range.size.bytes(); + j += range.start.bytes(); + let mut cur = defined.initial; + for range in &defined.ranges { + let old_j = j; + j += range; + self.init_mask.set_range_inbounds( + Size::from_bytes(old_j), + Size::from_bytes(j), + cur, + ); + cur = !cur; + } + } + } } From 75fecd5d40654d8e81539d65495aa98d16029a79 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sun, 15 Aug 2021 12:24:58 -0400 Subject: [PATCH 145/269] improve comments --- .../src/mir/interpret/allocation.rs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 27a637f2f4f7..01f80c8d903a 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -583,6 +583,9 @@ impl InitMask { #[inline] fn bit_index(bits: Size) -> (usize, usize) { + // BLOCK_SIZE is the number of bits that can fit in a `Block`. + // Each bit in a `Block` represents the initialization state of one byte of an allocation, + // so we use `.bytes()` here. let bits = bits.bytes(); let a = bits / InitMask::BLOCK_SIZE; let b = bits % InitMask::BLOCK_SIZE; @@ -721,23 +724,23 @@ impl InitMask { is_init: bool, ) -> Option { // For the following examples, assume this function was called with: - // bits = 11011100 + // bits = 0b00111011 // start_bit = 3 // is_init = false - // Note again that the least significant bit is written first, - // which is backwards compared to how we normally write numbers. + // Note that, for the examples in this function, the most significant bit is written first, + // which is backwards compared to the comments in `find_bit`/`find_bit_fast`. // Invert bits so we're always looking for the first set bit. - // ! 11011100 - // bits = 00100011 + // ! 0b00111011 + // bits = 0b11000100 let bits = if is_init { bits } else { !bits }; // Mask off unused start bits. - // 00100011 - // & 00011111 - // bits = 00000011 + // 0b11000100 + // & 0b11111000 + // bits = 0b11000000 let bits = bits & (!0 << start_bit); // Find set bit, if any. - // bit = trailing_zeros(00000011) + // bit = trailing_zeros(0b11000000) // bit = 6 if bits == 0 { None @@ -772,6 +775,7 @@ impl InitMask { // For (a), the block index of `end_inclusive` is 1, and for (b), it's 0. // This provides the desired behavior of searching blocks 0 and 1 for (a), // and searching only block 0 for (b). + // There is no concern of overflows since we checked for `start >= end` above. let (start_block, start_bit) = InitMask::bit_index(start); let end_inclusive = Size::from_bytes(end.bytes() - 1); let (end_block_inclusive, _) = InitMask::bit_index(end_inclusive); @@ -1046,6 +1050,7 @@ impl Allocation { let mut ranges = smallvec::SmallVec::<[u64; 1]>::new(); let initial = self.init_mask.get(range.start); + // Here we rely on `range_as_init_chunks` to yield alternating init/uninit chunks. for chunk in self.init_mask.range_as_init_chunks(range.start, range.end()) { let len = chunk.range().end.bytes() - chunk.range().start.bytes(); ranges.push(len); From c07a2eb5b417b72583e6331e8eeca1d505f9bac8 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 25 Aug 2021 17:40:57 -0400 Subject: [PATCH 146/269] yet more comment improvements --- compiler/rustc_middle/src/mir/interpret/allocation.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 01f80c8d903a..abc8799d102c 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -766,7 +766,7 @@ impl InitMask { // In both cases, the block index of `end` is 1. // But we do want to search block 1 in (a), and we don't in (b). // - // If we subtract 1 from both end positions to make them inclusive: + // We subtract 1 from both end positions to make them inclusive: // // (a) 00000000|00000000 (b) 00000000| // ^~~~~~~~~~^ ^~~~~~~^ @@ -937,7 +937,12 @@ impl InitMask { pub fn range_as_init_chunks(&self, start: Size, end: Size) -> InitChunkIter<'_> { assert!(end <= self.len); - let is_init = if start < end { self.get(start) } else { false }; + let is_init = if start < end { + self.get(start) + } else { + // `start..end` is empty: there are no chunks, so use some arbitrary value + false + }; InitChunkIter { init_mask: self, is_init, start, end } } From adf3b013c8b51e7d6ceea33ef3005896cc2cd030 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 25 Aug 2021 17:44:27 -0400 Subject: [PATCH 147/269] use a peekable iterator to check the first chunk --- .../src/mir/interpret/allocation.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index abc8799d102c..b6358f992944 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -894,6 +894,14 @@ pub enum InitChunk { } impl InitChunk { + #[inline] + pub fn is_init(&self) -> bool { + match self { + Self::Init(_) => true, + Self::Uninit(_) => false, + } + } + #[inline] pub fn range(&self) -> Range { match self { @@ -1035,7 +1043,7 @@ impl InitMaskCompressed { /// Transferring the initialization mask to other allocations. impl Allocation { - /// Creates a run-length encoding of the initialization mask. + /// Creates a run-length encoding of the initialization mask; panics if range is empty. /// /// This is essentially a more space-efficient version of /// `InitMask::range_as_init_chunks(...).collect::>()`. @@ -1053,10 +1061,13 @@ impl Allocation { // where each element toggles the state. let mut ranges = smallvec::SmallVec::<[u64; 1]>::new(); - let initial = self.init_mask.get(range.start); + + let mut chunks = self.init_mask.range_as_init_chunks(range.start, range.end()).peekable(); + + let initial = chunks.peek().expect("range should be nonempty").is_init(); // Here we rely on `range_as_init_chunks` to yield alternating init/uninit chunks. - for chunk in self.init_mask.range_as_init_chunks(range.start, range.end()) { + for chunk in chunks { let len = chunk.range().end.bytes() - chunk.range().start.bytes(); ranges.push(len); } From 5b25de58d6cbfab4fefe3200de8864ab8f6a71d1 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 25 Aug 2021 14:58:17 -0700 Subject: [PATCH 148/269] Reference tracking issue --- library/std/src/os/raw/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 7ce58fb1d0ff..1e220ea30ab9 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -156,12 +156,12 @@ pub use core::ffi::c_void; /// /// This type is currently always [`usize`], however in the future there may be /// platforms where this is not the case. -#[unstable(feature = "c_size_t", issue = "none")] +#[unstable(feature = "c_size_t", issue = "88345")] pub type c_size_t = usize; /// Equivalent to C's `ssize_t` type, from `stddef.h` (or `cstddef` for C++). /// /// This type is currently always [`isize`], however in the future there may be /// platforms where this is not the case. -#[unstable(feature = "c_size_t", issue = "none")] +#[unstable(feature = "c_size_t", issue = "88345")] pub type c_ssize_t = isize; From 5df5659a6b96436ae55fd6bd8e9a7dbe7e22b37d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 19:14:50 -0300 Subject: [PATCH 149/269] Revert "Add type of a let tait test impl trait straight in let" This reverts commit dbadab54df148b55b2e884440bfaeaa38517e6e8. This is not part of TAITs, so, if tested should probably be done elsewhere. --- .../type-alias-impl-trait/type_of_a_let2.rs | 25 ------------------- .../type_of_a_let2.stderr | 21 ---------------- 2 files changed, 46 deletions(-) delete mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.rs delete mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs deleted file mode 100644 index 33d3f164ce15..000000000000 --- a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -// FIXME This should be under a feature flag - -use std::fmt::Debug; - -fn foo1() -> u32 { - let x: impl Debug = 22_u32; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - x // ERROR: we only know x: Debug, we don't know x = u32 -} - -fn foo2() -> u32 { - let x: impl Debug = 22_u32; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - let y: impl Debug = x; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - same_type((x, y)); // ERROR - x -} - -fn same_type(x: (T, T)) {} - -fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr deleted file mode 100644 index 7a1825a8e2d9..000000000000 --- a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:9:12 - | -LL | let x: impl Debug = 22_u32; - | ^^^^^^^^^^ - -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:15:12 - | -LL | let x: impl Debug = 22_u32; - | ^^^^^^^^^^ - -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:17:12 - | -LL | let y: impl Debug = x; - | ^^^^^^^^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0562`. From bb583f72e3ac42997eaa3522eca54b5326483351 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 20:07:12 -0300 Subject: [PATCH 150/269] Add field types tait tests --- .../ui/type-alias-impl-trait/field-types.rs | 20 ++++++++++++++++++ .../type-alias-impl-trait/field-types.stderr | 21 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/field-types.rs create mode 100644 src/test/ui/type-alias-impl-trait/field-types.stderr diff --git a/src/test/ui/type-alias-impl-trait/field-types.rs b/src/test/ui/type-alias-impl-trait/field-types.rs new file mode 100644 index 000000000000..91494a82d0fb --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/field-types.rs @@ -0,0 +1,20 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should compile, but it currently doesn't + +use std::fmt::Debug; + +type Foo = impl Debug; +//~^ ERROR: could not find defining uses + +struct Bar { + foo: Foo, +} + +fn bar() -> Bar { + Bar { foo: "foo" } + //~^ ERROR: mismatched types [E0308] +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/field-types.stderr b/src/test/ui/type-alias-impl-trait/field-types.stderr new file mode 100644 index 000000000000..18c2abbdf372 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/field-types.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/field-types.rs:16:16 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | Bar { foo: "foo" } + | ^^^^^ expected opaque type, found `&str` + | + = note: expected opaque type `impl Debug` + found reference `&'static str` + +error: could not find defining uses + --> $DIR/field-types.rs:8:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. From 4fcae2c89113e0767ee066a42f418261cebdc4bd Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 20:32:31 -0300 Subject: [PATCH 151/269] Add const and static TAIT tests --- .../static-const-types.rs | 16 +++++++++ .../static-const-types.stderr | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/static-const-types.rs create mode 100644 src/test/ui/type-alias-impl-trait/static-const-types.stderr diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.rs b/src/test/ui/type-alias-impl-trait/static-const-types.rs new file mode 100644 index 000000000000..f630d2783350 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/static-const-types.rs @@ -0,0 +1,16 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME: This should compile, but it currently doesn't + +use std::fmt::Debug; + +type Foo = impl Debug; +//~^ ERROR: could not find defining uses + +static FOO1: Foo = 22_u32; +//~^ ERROR: mismatched types [E0308] +const FOO2: Foo = 22_u32; +//~^ ERROR: mismatched types [E0308] + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.stderr b/src/test/ui/type-alias-impl-trait/static-const-types.stderr new file mode 100644 index 000000000000..72083d014fe3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/static-const-types.stderr @@ -0,0 +1,33 @@ +error[E0308]: mismatched types + --> $DIR/static-const-types.rs:11:20 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | static FOO1: Foo = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error[E0308]: mismatched types + --> $DIR/static-const-types.rs:13:19 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | const FOO2: Foo = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: could not find defining uses + --> $DIR/static-const-types.rs:8:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. From f8ca5764c36feab162893cd16b567d87edd4cf8e Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 18:14:25 -0700 Subject: [PATCH 152/269] Add tests for `HtmlWithLimit` --- src/librustdoc/html/length_limit.rs | 3 + src/librustdoc/html/length_limit/tests.rs | 117 ++++++++++++++++++++++ src/librustdoc/html/markdown/tests.rs | 2 + 3 files changed, 122 insertions(+) create mode 100644 src/librustdoc/html/length_limit/tests.rs diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 2b47033744fd..ecf41f7afa7e 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -98,3 +98,6 @@ impl HtmlWithLimit { } } } + +#[cfg(test)] +mod tests; diff --git a/src/librustdoc/html/length_limit/tests.rs b/src/librustdoc/html/length_limit/tests.rs new file mode 100644 index 000000000000..5a006d44d58c --- /dev/null +++ b/src/librustdoc/html/length_limit/tests.rs @@ -0,0 +1,117 @@ +use super::*; + +#[test] +fn empty() { + assert_eq!(HtmlWithLimit::new(0).finish(), ""); + assert_eq!(HtmlWithLimit::new(60).finish(), ""); +} + +#[test] +fn basic() { + let mut buf = HtmlWithLimit::new(60); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn no_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.push("Hello"); + buf.push(" world!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn limit_0() { + let mut buf = HtmlWithLimit::new(0); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), ""); +} + +#[test] +fn exactly_limit() { + let mut buf = HtmlWithLimit::new(12); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn multiple_nested_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("This is a "); + buf.open_tag("em"); + buf.push("paragraph"); + buf.open_tag("strong"); + buf.push("!"); + buf.close_tag(); + buf.close_tag(); + buf.close_tag(); + assert_eq!(buf.finish(), "

This is a paragraph!

"); +} + +#[test] +fn forgot_to_close_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("This is a "); + buf.open_tag("em"); + buf.push("paragraph"); + buf.open_tag("strong"); + buf.push("!"); + assert_eq!(buf.finish(), "

This is a paragraph!

"); +} + +#[test] +fn past_the_limit() { + let mut buf = HtmlWithLimit::new(20); + buf.open_tag("p"); + (0..10).try_for_each(|n| { + buf.open_tag("strong"); + buf.push("word#")?; + buf.push(&n.to_string())?; + buf.close_tag(); + ControlFlow::CONTINUE + }); + buf.close_tag(); + assert_eq!( + buf.finish(), + "

\ + word#0\ + word#1\ + word#2\ +

" + ); +} + +#[test] +fn quickly_past_the_limit() { + let mut buf = HtmlWithLimit::new(6); + buf.open_tag("p"); + buf.push("Hello"); + buf.push(" World"); + // intentionally not closing

before finishing + assert_eq!(buf.finish(), "

Hello

"); +} + +#[test] +#[should_panic = "called `Option::unwrap()` on a `None` value"] +fn close_too_many() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("Hello"); + buf.close_tag(); + buf.close_tag(); +} diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 1e4bdc2d1519..eca75ef013aa 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -225,6 +225,7 @@ fn test_short_markdown_summary() { assert_eq!(output, expect, "original: {}", input); } + t("", ""); t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)"); t("*italic*", "italic"); t("**bold**", "bold"); @@ -264,6 +265,7 @@ fn test_plain_text_summary() { assert_eq!(output, expect, "original: {}", input); } + t("", ""); t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)"); t("**bold**", "bold"); t("Multi-line\nsummary", "Multi-line summary"); From d932e62dd9a6137a831d0917aa80aefd7ff47018 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 13:49:51 -0700 Subject: [PATCH 153/269] Assert that `tag_name` is alphabetic --- src/librustdoc/html/length_limit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index ecf41f7afa7e..28a207a84ba6 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -72,7 +72,15 @@ impl HtmlWithLimit { } /// Open an HTML tag. + /// + /// **Note:** HTML attributes have not yet been implemented. + /// This function will panic if called with a non-alphabetic `tag_name`. pub(super) fn open_tag(&mut self, tag_name: &'static str) { + assert!( + tag_name.chars().all(|c| ('a'..='z').contains(&c)), + "tag_name contained non-alphabetic chars: {:?}", + tag_name + ); self.queued_tags.push(tag_name); } From 4478ecc352d6f3f12c1cb4b9dd5e7e06762286ee Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 20:09:17 -0700 Subject: [PATCH 154/269] Don't panic if `close_tag()` is called without tags to close This can happen when a tag is opened after the length limit is reached; the tag will not end up being added to `unclosed_tags` because the queue will never be flushed. So, now, if the `unclosed_tags` stack is empty, `close_tag()` does nothing. This change fixes a panic in the `limit_0` unit test. --- src/librustdoc/html/length_limit.rs | 12 ++++++++++-- src/librustdoc/html/length_limit/tests.rs | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 28a207a84ba6..bbdc91c8d2ec 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -86,8 +86,16 @@ impl HtmlWithLimit { /// Close the most recently opened HTML tag. pub(super) fn close_tag(&mut self) { - let tag_name = self.unclosed_tags.pop().unwrap(); - write!(self.buf, "", tag_name).unwrap(); + match self.unclosed_tags.pop() { + // Close the most recently opened tag. + Some(tag_name) => write!(self.buf, "", tag_name).unwrap(), + // There are valid cases where `close_tag()` is called without + // there being any tags to close. For example, this occurs when + // a tag is opened after the length limit is exceeded; + // `flush_queue()` will never be called, and thus, the tag will + // not end up being added to `unclosed_tags`. + None => {} + } } /// Write all queued tags and add them to the `unclosed_tags` list. diff --git a/src/librustdoc/html/length_limit/tests.rs b/src/librustdoc/html/length_limit/tests.rs index 5a006d44d58c..2d02b8a16da6 100644 --- a/src/librustdoc/html/length_limit/tests.rs +++ b/src/librustdoc/html/length_limit/tests.rs @@ -107,11 +107,14 @@ fn quickly_past_the_limit() { } #[test] -#[should_panic = "called `Option::unwrap()` on a `None` value"] fn close_too_many() { let mut buf = HtmlWithLimit::new(60); buf.open_tag("p"); buf.push("Hello"); buf.close_tag(); + // This call does not panic because there are valid cases + // where `close_tag()` is called with no tags left to close. + // So `close_tag()` does nothing in this case. buf.close_tag(); + assert_eq!(buf.finish(), "

Hello

"); } From f4b606fd1703fb54bf75f064482312a67beb4a7b Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 13 Mar 2021 16:05:15 +0100 Subject: [PATCH 155/269] require a `tcx` for `TypeVisitor` --- .../src/infer/error_reporting/mod.rs | 4 ++ .../nice_region_error/static_impl_trait.rs | 12 +++-- .../rustc_infer/src/infer/nll_relate/mod.rs | 6 +++ compiler/rustc_infer/src/infer/resolve.rs | 5 ++ compiler/rustc_lint/src/types.rs | 3 ++ compiler/rustc_middle/src/ty/fold.rs | 46 +++++++++++++++---- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +++ compiler/rustc_mir/src/interpret/util.rs | 4 ++ .../src/monomorphize/polymorphize.rs | 14 ++++-- compiler/rustc_mir/src/util/pretty.rs | 4 ++ compiler/rustc_privacy/src/lib.rs | 4 ++ .../rustc_trait_selection/src/opaque_types.rs | 12 ++++- .../src/traits/object_safety.rs | 3 ++ .../src/traits/structural_match.rs | 3 ++ compiler/rustc_traits/src/chalk/lowering.rs | 14 +++++- compiler/rustc_ty_utils/src/instance.rs | 3 ++ compiler/rustc_typeck/src/check/check.rs | 17 +++++-- compiler/rustc_typeck/src/check/op.rs | 11 +++-- compiler/rustc_typeck/src/check/wfcheck.rs | 11 +++-- compiler/rustc_typeck/src/collect.rs | 2 +- .../src/constrained_generic_params.rs | 21 ++++++--- compiler/rustc_typeck/src/impl_wf_check.rs | 4 +- .../src/impl_wf_check/min_specialization.rs | 8 ++-- .../clippy_lints/src/redundant_clone.rs | 15 +++--- 24 files changed, 182 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 4830158c15af..14fdf03e06d1 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1537,6 +1537,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> { + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { if let Some((kind, def_id)) = TyCategory::from_ty(self.tcx, t) { let span = self.tcx.def_span(def_id); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index fde4ec05ffc8..d3d55d89db67 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -9,7 +9,9 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorRepor use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor}; use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind}; -use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, AssocItemContainer, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor, +}; use rustc_span::symbol::Ident; use rustc_span::{MultiSpan, Span}; @@ -476,8 +478,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Collect all the trait objects in a type that could have received an implicit `'static` lifetime. pub(super) struct TraitObjectVisitor(pub(super) FxHashSet); -impl TypeVisitor<'_> for TraitObjectVisitor { - fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow { +impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor { + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for TraitObjectVisitor"); + } + + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { ty::Dynamic(preds, RegionKind::ReStatic) => { if let Some(def_id) = preds.principal_def_id() { diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 042e6159aff8..8f1ebb116fdb 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -202,6 +202,7 @@ where }; value.skip_binder().visit_with(&mut ScopeInstantiator { + tcx: self.infcx.tcx, next_region: &mut next_region, target_index: ty::INNERMOST, bound_region_scope: &mut scope, @@ -757,6 +758,7 @@ where /// `for<..`>. For each of those, it creates an entry in /// `bound_region_scope`. struct ScopeInstantiator<'me, 'tcx> { + tcx: TyCtxt<'tcx>, next_region: &'me mut dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx>, // The debruijn index of the scope we are instantiating. target_index: ty::DebruijnIndex, @@ -764,6 +766,10 @@ struct ScopeInstantiator<'me, 'tcx> { } impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> { + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_binder>( &mut self, t: &ty::Binder<'tcx, T>, diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 48b8ee17594e..e5ad44c74271 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -126,6 +126,11 @@ impl<'a, 'tcx> UnresolvedTypeFinder<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> { type BreakTy = (Ty<'tcx>, Option); + + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.infcx.tcx + } + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { let t = self.infcx.shallow_resolve(t); if t.has_infer_types() { diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 829a2abef0db..1194d8edc090 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1160,6 +1160,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> { type BreakTy = Ty<'tcx>; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.cx.tcx + } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { match ty.kind() { diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index a40210d5a362..40b3ffb89557 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -189,6 +189,12 @@ pub trait TypeFolder<'tcx>: Sized { pub trait TypeVisitor<'tcx>: Sized { type BreakTy = !; + /// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs + /// are not yet supplied. + /// + /// Visitors which do not look into these substs may leave this unimplemented, so be + /// careful when calling this method elsewhere. + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx>; fn visit_binder>( &mut self, @@ -301,7 +307,8 @@ impl<'tcx> TyCtxt<'tcx> { value: &impl TypeFoldable<'tcx>, callback: impl FnMut(ty::Region<'tcx>) -> bool, ) -> bool { - struct RegionVisitor { + struct RegionVisitor<'tcx, F> { + tcx: TyCtxt<'tcx>, /// The index of a binder *just outside* the things we have /// traversed. If we encounter a bound region bound by this /// binder or one outer to it, it appears free. Example: @@ -323,12 +330,16 @@ impl<'tcx> TyCtxt<'tcx> { callback: F, } - impl<'tcx, F> TypeVisitor<'tcx> for RegionVisitor + impl<'tcx, F> TypeVisitor<'tcx> for RegionVisitor<'tcx, F> where F: FnMut(ty::Region<'tcx>) -> bool, { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_binder>( &mut self, t: &Binder<'tcx, T>, @@ -364,7 +375,9 @@ impl<'tcx> TyCtxt<'tcx> { } } - value.visit_with(&mut RegionVisitor { outer_index: ty::INNERMOST, callback }).is_break() + value + .visit_with(&mut RegionVisitor { tcx: self, outer_index: ty::INNERMOST, callback }) + .is_break() } } @@ -708,7 +721,7 @@ impl<'tcx> TyCtxt<'tcx> { where T: TypeFoldable<'tcx>, { - let mut collector = LateBoundRegionsCollector::new(just_constraint); + let mut collector = LateBoundRegionsCollector::new(self, just_constraint); let result = value.as_ref().skip_binder().visit_with(&mut collector); assert!(result.is_continue()); // should never have stopped early collector.regions @@ -775,6 +788,10 @@ impl<'tcx> ValidateBoundVars<'tcx> { impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("default anon const substs can't contain bound vars"); + } + fn visit_binder>( &mut self, t: &Binder<'tcx, T>, @@ -989,6 +1006,10 @@ struct HasEscapingVarsVisitor { impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { type BreakTy = FoundEscapingVars; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for HasEscpaingVarsVisitor"); + } + fn visit_binder>( &mut self, t: &Binder<'tcx, T>, @@ -1059,6 +1080,9 @@ struct HasTypeFlagsVisitor { impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { type BreakTy = FoundFlags; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for HasTypeFlagsVisitor"); + } #[inline] fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow { @@ -1113,7 +1137,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { /// Collects all the late-bound regions at the innermost binding level /// into a hash set. -struct LateBoundRegionsCollector { +struct LateBoundRegionsCollector<'tcx> { + tcx: TyCtxt<'tcx>, current_index: ty::DebruijnIndex, regions: FxHashSet, @@ -1127,9 +1152,10 @@ struct LateBoundRegionsCollector { just_constrained: bool, } -impl LateBoundRegionsCollector { - fn new(just_constrained: bool) -> Self { +impl LateBoundRegionsCollector<'tcx> { + fn new(tcx: TyCtxt<'tcx>, just_constrained: bool) -> Self { LateBoundRegionsCollector { + tcx, current_index: ty::INNERMOST, regions: Default::default(), just_constrained, @@ -1137,7 +1163,11 @@ impl LateBoundRegionsCollector { } } -impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { +impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector<'tcx> { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_binder>( &mut self, t: &Binder<'tcx, T>, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 4befeb1d827c..ef999285f537 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2017,6 +2017,7 @@ impl FmtPrinter<'_, 'tcx, F> { debug!("prepare_late_bound_region_info(value: {:?})", value); struct LateBoundRegionNameCollector<'a, 'tcx> { + tcx: TyCtxt<'tcx>, used_region_names: &'a mut FxHashSet, type_collector: SsoHashSet>, } @@ -2024,6 +2025,10 @@ impl FmtPrinter<'_, 'tcx, F> { impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { debug!("LateBoundRegionNameCollector::visit_region(r: {:?}, address: {:p})", r, &r); if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r { @@ -2053,6 +2058,7 @@ impl FmtPrinter<'_, 'tcx, F> { self.used_region_names.clear(); let mut collector = LateBoundRegionNameCollector { + tcx: self.tcx, used_region_names: &mut self.used_region_names, type_collector: SsoHashSet::new(), }; diff --git a/compiler/rustc_mir/src/interpret/util.rs b/compiler/rustc_mir/src/interpret/util.rs index 89f34cd07aa4..b7ab2e88b962 100644 --- a/compiler/rustc_mir/src/interpret/util.rs +++ b/compiler/rustc_mir/src/interpret/util.rs @@ -21,6 +21,10 @@ where impl<'tcx> TypeVisitor<'tcx> for UsedParamsNeedSubstVisitor<'tcx> { type BreakTy = FoundParam; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { if !c.needs_subst() { return ControlFlow::CONTINUE; diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index fea1adfa3d58..dd7500e9e9d5 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -178,7 +178,7 @@ fn mark_used_by_predicates<'tcx>( // Consider all generic params in a predicate as used if any other parameter in the // predicate is used. let any_param_used = { - let mut vis = HasUsedGenericParams { unused_parameters }; + let mut vis = HasUsedGenericParams { tcx, unused_parameters }; predicate.visit_with(&mut vis).is_break() }; @@ -283,6 +283,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { } impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { if !c.has_param_types_or_consts() { @@ -346,13 +349,18 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { } /// Visitor used to check if a generic parameter is used. -struct HasUsedGenericParams<'a> { +struct HasUsedGenericParams<'a, 'tcx> { + tcx: TyCtxt<'tcx>, unused_parameters: &'a FiniteBitSet, } -impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> { +impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { if !c.has_param_types_or_consts() { diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 7598a011bb67..435fca4a11b4 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -682,6 +682,10 @@ pub fn write_allocations<'tcx>( } struct CollectAllocIds(BTreeSet); impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for CollectAllocIds") + } + fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { if let ty::ConstKind::Value(val) = c.val { self.0.extend(alloc_ids_from_const(val)); diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index d84175724cc3..45d31068668e 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -179,6 +179,10 @@ where { type BreakTy = V::BreakTy; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.def_id_visitor.tcx() + } + fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { let tcx = self.def_id_visitor.tcx(); // InternalSubsts are not visited here because they are visited below in `super_visit_with`. diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index c5a6e301deba..083a962ac7b2 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -352,6 +352,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if !required_region_bounds.is_empty() { for required_region in required_region_bounds { concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor { + tcx, op: |r| self.sub_regions(infer::CallReturn(span), required_region, r), }); } @@ -427,6 +428,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor { + tcx, op: |r| self.sub_regions(infer::CallReturn(span), least_region, r), }); } @@ -461,6 +463,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ); concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor { + tcx: self.tcx, op: |r| { self.member_constraint( opaque_type_key.def_id, @@ -546,14 +549,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // // We ignore any type parameters because impl trait values are assumed to // capture all the in-scope type parameters. -struct ConstrainOpaqueTypeRegionVisitor { +struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP> { + tcx: TyCtxt<'tcx>, op: OP, } -impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor +impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP> where OP: FnMut(ty::Region<'tcx>), { + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_binder>( &mut self, t: &ty::Binder<'tcx, T>, diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 02b43de0d160..b81ca52f9fd3 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -771,6 +771,9 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>( impl<'tcx> TypeVisitor<'tcx> for IllegalSelfTypeVisitor<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { + self.tcx + } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index a6323a65aadb..fd7dc55ac841 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -130,6 +130,9 @@ impl Search<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> { type BreakTy = NonStructuralMatchTy<'tcx>; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx() + } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { debug!("Search visiting ty: {:?}", ty); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 330fd497fa1f..d07eeaedd82d 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -806,7 +806,7 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( tcx: TyCtxt<'tcx>, ty: Binder<'tcx, T>, ) -> (T, chalk_ir::VariableKinds>, BTreeMap) { - let mut bound_vars_collector = BoundVarsCollector::new(); + let mut bound_vars_collector = BoundVarsCollector::new(tcx); ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector); let mut parameters = bound_vars_collector.parameters; let named_parameters: BTreeMap = bound_vars_collector @@ -836,14 +836,16 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( } crate struct BoundVarsCollector<'tcx> { + tcx: TyCtxt<'tcx>, binder_index: ty::DebruijnIndex, crate parameters: BTreeMap>>, crate named_parameters: Vec, } impl<'tcx> BoundVarsCollector<'tcx> { - crate fn new() -> Self { + crate fn new(tcx: TyCtxt<'tcx>) -> Self { BoundVarsCollector { + tcx, binder_index: ty::INNERMOST, parameters: BTreeMap::new(), named_parameters: vec![], @@ -852,6 +854,10 @@ impl<'tcx> BoundVarsCollector<'tcx> { } impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_binder>( &mut self, t: &Binder<'tcx, T>, @@ -1070,6 +1076,10 @@ impl PlaceholdersCollector { } impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for PlaceholdersCollector"); + } + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { ty::Placeholder(p) if p.universe == self.universe_index => { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 4c03abb38ca5..b9fbb5da3e60 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -54,6 +54,9 @@ impl<'tcx> BoundVarsCollector<'tcx> { impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("default anon const substs can't be bound vars"); + } fn visit_binder>( &mut self, t: &Binder<'tcx, T>, diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index a7fd20888428..06fae26f7df4 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -470,14 +470,17 @@ pub(super) fn check_opaque_for_inheriting_lifetimes( debug!(?item, ?span); struct FoundParentLifetime; - struct FindParentLifetimeVisitor<'tcx>(&'tcx ty::Generics); + struct FindParentLifetimeVisitor<'tcx>(TyCtxt<'tcx>, &'tcx ty::Generics); impl<'tcx> ty::fold::TypeVisitor<'tcx> for FindParentLifetimeVisitor<'tcx> { type BreakTy = FoundParentLifetime; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.0 + } fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { debug!("FindParentLifetimeVisitor: r={:?}", r); if let RegionKind::ReEarlyBound(ty::EarlyBoundRegion { index, .. }) = r { - if *index < self.0.parent_count as u32 { + if *index < self.1.parent_count as u32 { return ControlFlow::Break(FoundParentLifetime); } else { return ControlFlow::CONTINUE; @@ -499,21 +502,24 @@ pub(super) fn check_opaque_for_inheriting_lifetimes( } struct ProhibitOpaqueVisitor<'tcx> { + tcx: TyCtxt<'tcx>, opaque_identity_ty: Ty<'tcx>, generics: &'tcx ty::Generics, - tcx: TyCtxt<'tcx>, selftys: Vec<(Span, Option)>, } impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueVisitor<'tcx> { type BreakTy = Ty<'tcx>; + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { debug!("check_opaque_for_inheriting_lifetimes: (visit_ty) t={:?}", t); if t == self.opaque_identity_ty { ControlFlow::CONTINUE } else { - t.super_visit_with(&mut FindParentLifetimeVisitor(self.generics)) + t.super_visit_with(&mut FindParentLifetimeVisitor(self.tcx, self.generics)) .map_break(|FoundParentLifetime| t) } } @@ -1580,6 +1586,9 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { { struct VisitTypes(Vec); impl<'tcx> ty::fold::TypeVisitor<'tcx> for VisitTypes { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + bug!("tcx_for_anon_const_substs called for VisitTypes"); + } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { ty::Opaque(def, _) => { diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 963436d05d8e..3503d68e8f02 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -428,7 +428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } if let Some(missing_trait) = missing_trait { - let mut visitor = TypeParamVisitor(vec![]); + let mut visitor = TypeParamVisitor(self.tcx, vec![]); visitor.visit_ty(lhs_ty); if op.node == hir::BinOpKind::Add @@ -439,7 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This has nothing here because it means we did string // concatenation (e.g., "Hello " + "World!"). This means // we don't want the note in the else clause to be emitted - } else if let [ty] = &visitor.0[..] { + } else if let [ty] = &visitor.1[..] { if let ty::Param(p) = *ty.kind() { // Check if the method would be found if the type param wasn't // involved. If so, it means that adding a trait bound to the param is @@ -1003,12 +1003,15 @@ fn suggest_constraining_param( } } -struct TypeParamVisitor<'tcx>(Vec>); +struct TypeParamVisitor<'tcx>(TyCtxt<'tcx>, Vec>); impl<'tcx> TypeVisitor<'tcx> for TypeParamVisitor<'tcx> { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.0 + } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { if let ty::Param(_) = ty.kind() { - self.0.push(ty); + self.1.push(ty); } ty.super_visit_with(self) } diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 632b9492ee43..44caf348a98e 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -825,12 +825,15 @@ fn check_where_clauses<'tcx, 'fcx>( .predicates .iter() .flat_map(|&(pred, sp)| { - #[derive(Default)] - struct CountParams { + struct CountParams<'tcx> { + tcx: TyCtxt<'tcx>, params: FxHashSet, } - impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams { + impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { if let ty::Param(param) = t.kind() { @@ -850,7 +853,7 @@ fn check_where_clauses<'tcx, 'fcx>( c.super_visit_with(self) } } - let mut param_count = CountParams::default(); + let mut param_count = CountParams { tcx: fcx.tcx, params: FxHashSet::default() }; let has_region = pred.visit_with(&mut param_count).is_break(); let substituted_pred = pred.subst(tcx, substs); // Don't check non-defaulted params, dependent defaults (including lifetimes) diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 1c6fd5983cb5..d5316352c546 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2320,7 +2320,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP tcx, &mut predicates, trait_ref, - &mut cgp::parameters_for_impl(self_ty, trait_ref), + &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref), ); } diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index 529de1a28748..140348ea4ec1 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -27,12 +27,13 @@ impl From for Parameter { /// Returns the set of parameters constrained by the impl header. pub fn parameters_for_impl<'tcx>( + tcx: TyCtxt<'tcx>, impl_self_ty: Ty<'tcx>, impl_trait_ref: Option>, ) -> FxHashSet { let vec = match impl_trait_ref { - Some(tr) => parameters_for(&tr, false), - None => parameters_for(&impl_self_ty, false), + Some(tr) => parameters_for(tcx, &tr, false), + None => parameters_for(tcx, &impl_self_ty, false), }; vec.into_iter().collect() } @@ -43,20 +44,26 @@ pub fn parameters_for_impl<'tcx>( /// of parameters whose values are needed in order to constrain `ty` - these /// differ, with the latter being a superset, in the presence of projections. pub fn parameters_for<'tcx>( + tcx: TyCtxt<'tcx>, t: &impl TypeFoldable<'tcx>, include_nonconstraining: bool, ) -> Vec { - let mut collector = ParameterCollector { parameters: vec![], include_nonconstraining }; + let mut collector = ParameterCollector { tcx, parameters: vec![], include_nonconstraining }; t.visit_with(&mut collector); collector.parameters } -struct ParameterCollector { +struct ParameterCollector<'tcx> { + tcx: TyCtxt<'tcx>, parameters: Vec, include_nonconstraining: bool, } -impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { +impl<'tcx> TypeVisitor<'tcx> for ParameterCollector<'tcx> { + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.tcx + } + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { ty::Projection(..) | ty::Opaque(..) if !self.include_nonconstraining => { @@ -198,12 +205,12 @@ pub fn setup_constraining_predicates<'tcx>( // `<::Baz as Iterator>::Output = ::Output` // Then the projection only applies if `T` is known, but it still // does not determine `U`. - let inputs = parameters_for(&projection.projection_ty, true); + let inputs = parameters_for(tcx, &projection.projection_ty, true); let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(&p)); if !relies_only_on_inputs { continue; } - input_parameters.extend(parameters_for(&projection.ty, false)); + input_parameters.extend(parameters_for(tcx, &projection.ty, false)); } else { continue; } diff --git a/compiler/rustc_typeck/src/impl_wf_check.rs b/compiler/rustc_typeck/src/impl_wf_check.rs index 124094686057..194c4efdbb05 100644 --- a/compiler/rustc_typeck/src/impl_wf_check.rs +++ b/compiler/rustc_typeck/src/impl_wf_check.rs @@ -119,7 +119,7 @@ fn enforce_impl_params_are_constrained( let impl_predicates = tcx.predicates_of(impl_def_id); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id); - let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref); + let mut input_parameters = cgp::parameters_for_impl(tcx, impl_self_ty, impl_trait_ref); cgp::identify_constrained_generic_params( tcx, impl_predicates, @@ -136,7 +136,7 @@ fn enforce_impl_params_are_constrained( match item.kind { ty::AssocKind::Type => { if item.defaultness.has_value() { - cgp::parameters_for(&tcx.type_of(def_id), true) + cgp::parameters_for(tcx, &tcx.type_of(def_id), true) } else { Vec::new() } diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index e148370a0361..2d71c87bee77 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -207,15 +207,15 @@ fn unconstrained_parent_impl_substs<'tcx>( continue; } - unconstrained_parameters.extend(cgp::parameters_for(&projection_ty, true)); + unconstrained_parameters.extend(cgp::parameters_for(tcx, &projection_ty, true)); - for param in cgp::parameters_for(&projected_ty, false) { + for param in cgp::parameters_for(tcx, &projected_ty, false) { if !unconstrained_parameters.contains(¶m) { constrained_params.insert(param.0); } } - unconstrained_parameters.extend(cgp::parameters_for(&projected_ty, true)); + unconstrained_parameters.extend(cgp::parameters_for(tcx, &projected_ty, true)); } } @@ -249,7 +249,7 @@ fn check_duplicate_params<'tcx>( parent_substs: &Vec>, span: Span, ) { - let mut base_params = cgp::parameters_for(parent_substs, true); + let mut base_params = cgp::parameters_for(tcx, parent_substs, true); base_params.sort_by_key(|param| param.0); if let (_, [duplicate, ..]) = base_params.partition_dedup() { let param = impl1_substs[duplicate.0 as usize]; diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index 530b3396abef..2335d2248aa9 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _}, Mutability, }; -use rustc_middle::ty::{self, fold::TypeVisitor, Ty}; +use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt}; use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{BytePos, Span}; @@ -576,7 +576,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { self.possible_borrower.add(borrowed.local, lhs); }, other => { - if ContainsRegion + if ContainsRegion(self.cx.tcx) .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty) .is_continue() { @@ -625,7 +625,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> { .flat_map(HybridBitSet::iter) .collect(); - if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() { + if ContainsRegion(self.cx.tcx).visit_ty(self.body.local_decls[*dest].ty).is_break() { mutable_variables.push(*dest); } @@ -701,12 +701,15 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> { } } -struct ContainsRegion; +struct ContainsRegion<'tcx>(TyCtxt<'tcx>); -impl TypeVisitor<'_> for ContainsRegion { +impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> { type BreakTy = (); + fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { + self.0 + } - fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow { + fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { ControlFlow::BREAK } } From bfaf13af4e5071b09248979e51c6614bf1353f52 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 16 Mar 2021 00:05:45 +0100 Subject: [PATCH 156/269] make unevaluated const substs optional --- .../rustc_codegen_cranelift/src/constant.rs | 10 ++--- compiler/rustc_infer/src/infer/combine.rs | 18 ++++---- .../src/infer/error_reporting/mod.rs | 4 +- .../nice_region_error/static_impl_trait.rs | 6 ++- compiler/rustc_infer/src/infer/mod.rs | 10 ++--- .../rustc_infer/src/infer/nll_relate/mod.rs | 4 +- compiler/rustc_infer/src/infer/resolve.rs | 4 +- compiler/rustc_lint/src/types.rs | 4 +- .../rustc_middle/src/mir/interpret/queries.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 4 ++ compiler/rustc_middle/src/ty/consts.rs | 3 +- compiler/rustc_middle/src/ty/consts/kind.rs | 38 +++++++++++----- compiler/rustc_middle/src/ty/flags.rs | 3 +- compiler/rustc_middle/src/ty/fold.rs | 35 +++++++++------ compiler/rustc_middle/src/ty/print/pretty.rs | 43 +++++++++---------- compiler/rustc_middle/src/ty/relate.rs | 8 ++-- .../rustc_middle/src/ty/structural_impls.rs | 31 +++++++++---- compiler/rustc_middle/src/ty/walk.rs | 3 +- .../src/borrow_check/type_check/mod.rs | 8 ++-- compiler/rustc_mir/src/interpret/operand.rs | 6 +-- compiler/rustc_mir/src/interpret/util.rs | 4 +- .../src/monomorphize/polymorphize.rs | 16 +++---- .../src/transform/check_consts/qualifs.rs | 2 +- .../rustc_mir/src/transform/const_prop.rs | 2 +- .../rustc_mir/src/transform/promote_consts.rs | 18 +++++--- compiler/rustc_mir/src/util/pretty.rs | 8 ++-- compiler/rustc_mir_build/src/thir/cx/expr.rs | 14 +++--- compiler/rustc_privacy/src/lib.rs | 4 +- .../rustc_trait_selection/src/opaque_types.rs | 4 +- .../src/traits/const_evaluatable.rs | 11 ++--- .../src/traits/fulfill.rs | 5 ++- .../src/traits/object_safety.rs | 4 +- .../src/traits/structural_match.rs | 4 +- .../rustc_trait_selection/src/traits/wf.rs | 9 ++-- compiler/rustc_traits/src/chalk/lowering.rs | 9 ++-- compiler/rustc_ty_utils/src/instance.rs | 5 ++- compiler/rustc_typeck/src/check/check.rs | 19 ++++---- compiler/rustc_typeck/src/check/op.rs | 4 +- compiler/rustc_typeck/src/check/wfcheck.rs | 4 +- compiler/rustc_typeck/src/collect.rs | 4 +- compiler/rustc_typeck/src/collect/type_of.rs | 6 ++- .../src/constrained_generic_params.rs | 4 +- src/librustdoc/clean/utils.rs | 2 +- .../clippy/clippy_lints/src/non_copy_const.rs | 6 +-- .../clippy_lints/src/redundant_clone.rs | 4 +- src/tools/clippy/clippy_utils/src/consts.rs | 6 +-- 46 files changed, 234 insertions(+), 188 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index c87309e22224..424a0d742d12 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -129,13 +129,13 @@ pub(crate) fn codegen_constant<'tcx>( }; let const_val = match const_.val { ConstKind::Value(const_val) => const_val, - ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) - if fx.tcx.is_static(def.did) => + ConstKind::Unevaluated(uv) + if fx.tcx.is_static(uv.def.did) => { - assert!(substs.is_empty()); - assert!(promoted.is_none()); + assert!(uv.substs(fx.tcx).is_empty()); + assert!(uv.promoted.is_none()); - return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty)).to_cvalue(fx); + return codegen_static_ref(fx, uv.def.did, fx.layout_of(const_.ty)).to_cvalue(fx); } ConstKind::Unevaluated(unevaluated) => { match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) { diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 01d84e287bc9..4fb3d4bdfe1c 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -742,10 +742,9 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { } } } - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) - if self.tcx().lazy_normalization() => - { - assert_eq!(promoted, None); + ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => { + assert_eq!(uv.promoted, None); + let substs = uv.substs(self.tcx()); let substs = self.relate_with_variance( ty::Variance::Invariant, ty::VarianceDiagInfo::default(), @@ -754,7 +753,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { )?; Ok(self.tcx().mk_const(ty::Const { ty: c.ty, - val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }), + val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)), })) } _ => relate::super_relate_consts(self, c, c), @@ -976,10 +975,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { } } } - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) - if self.tcx().lazy_normalization() => - { - assert_eq!(promoted, None); + ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => { + assert_eq!(uv.promoted, None); + let substs = uv.substs(self.tcx()); let substs = self.relate_with_variance( ty::Variance::Invariant, ty::VarianceDiagInfo::default(), @@ -988,7 +986,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { )?; Ok(self.tcx().mk_const(ty::Const { ty: c.ty, - val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }), + val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)), })) } _ => relate::super_relate_consts(self, c, c), diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 14fdf03e06d1..299dcf5f17a8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1537,8 +1537,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> { - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index d3d55d89db67..81059fbcb105 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -479,8 +479,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { pub(super) struct TraitObjectVisitor(pub(super) FxHashSet); impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor { - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for TraitObjectVisitor"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // The default anon const substs cannot include + // trait objects, so we don't have to bother looking. + None } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 9013bea749a2..155abf4ef83d 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -679,7 +679,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { b: ty::Unevaluated<'tcx>, ) -> bool { let canonical = self.canonicalize_query( - ((a.def, a.substs), (b.def, b.substs)), + ((a.def, a.substs(self.tcx)), (b.def, b.substs(self.tcx))), &mut OriginalQueryValues::default(), ); debug!("canonical consts: {:?}", &canonical.value); @@ -1592,16 +1592,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn const_eval_resolve( &self, param_env: ty::ParamEnv<'tcx>, - ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>, + unevaluated: ty::Unevaluated<'tcx>, span: Option, ) -> EvalToConstValueResult<'tcx> { let mut original_values = OriginalQueryValues::default(); - let canonical = self.canonicalize_query((param_env, substs), &mut original_values); + let canonical = self.canonicalize_query((param_env, unevaluated), &mut original_values); - let (param_env, substs) = canonical.value; + let (param_env, unevaluated) = canonical.value; // The return value is the evaluated value which doesn't contain any reference to inference // variables, thus we don't need to substitute back the original values. - self.tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, span) + self.tcx.const_eval_resolve(param_env, unevaluated, span) } /// If `typ` is a type variable of some kind, resolve it one level diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 8f1ebb116fdb..c211d8e94a68 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -766,8 +766,8 @@ struct ScopeInstantiator<'me, 'tcx> { } impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> { - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_binder>( diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index e5ad44c74271..4b08c2eb9c19 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -127,8 +127,8 @@ impl<'a, 'tcx> UnresolvedTypeFinder<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> { type BreakTy = (Ty<'tcx>, Option); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.infcx.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.infcx.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 1194d8edc090..5d2557816397 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1160,8 +1160,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> { type BreakTy = Ty<'tcx>; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.cx.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.cx.tcx) } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index fa7c0670e8ce..c63613ae3af2 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -38,7 +38,7 @@ impl<'tcx> TyCtxt<'tcx> { ct: ty::Unevaluated<'tcx>, span: Option, ) -> EvalToConstValueResult<'tcx> { - match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs) { + match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs(self)) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted: ct.promoted }; self.const_eval_global_id(param_env, cid, span) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 68de7f29193d..737b1108f50a 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -114,6 +114,10 @@ rustc_queries! { desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) } } + query default_anon_const_substs(key: DefId) -> SubstsRef<'tcx> { + desc { |tcx| "computing the default generic arguments for `{}`", tcx.def_path_str(key) } + } + /// Records the type of every item. query type_of(key: DefId) -> Ty<'tcx> { desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index c78151271c17..869b2ab9dbcb 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -1,6 +1,5 @@ use crate::mir::interpret::ConstValue; use crate::mir::interpret::{LitToConstInput, Scalar}; -use crate::ty::subst::InternalSubsts; use crate::ty::{self, Ty, TyCtxt}; use crate::ty::{ParamEnv, ParamEnvAnd}; use rustc_errors::ErrorReported; @@ -100,7 +99,7 @@ impl<'tcx> Const<'tcx> { } _ => ty::ConstKind::Unevaluated(ty::Unevaluated { def: def.to_global(), - substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()), + substs_: None, promoted: None, }), }; diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index f2db95d162b8..ab2c57ac605b 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -16,10 +16,23 @@ use super::ScalarInt; #[derive(Hash, HashStable)] pub struct Unevaluated<'tcx> { pub def: ty::WithOptConstParam, - pub substs: SubstsRef<'tcx>, + pub substs_: Option>, pub promoted: Option, } +impl<'tcx> Unevaluated<'tcx> { + pub fn new(def: ty::WithOptConstParam, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> { + Unevaluated { def, substs_: Some(substs), promoted: None } + } + + pub fn substs(self, tcx: TyCtxt<'tcx>) -> SubstsRef<'tcx> { + self.substs_.unwrap_or_else(|| { + debug_assert_eq!(self.promoted, None); + tcx.default_anon_const_substs(self.def.did) + }) + } +} + /// Represents a constant in Rust. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] #[derive(Hash, HashStable)] @@ -109,7 +122,7 @@ impl<'tcx> ConstKind<'tcx> { tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ) -> Option, ErrorReported>> { - if let ConstKind::Unevaluated(Unevaluated { def, substs, promoted }) = self { + if let ConstKind::Unevaluated(unevaluated) = self { use crate::mir::interpret::ErrorHandled; // HACK(eddyb) this erases lifetimes even though `const_eval_resolve` @@ -118,29 +131,32 @@ impl<'tcx> ConstKind<'tcx> { // Note that we erase regions *before* calling `with_reveal_all_normalized`, // so that we don't try to invoke this query with // any region variables. - let param_env_and_substs = tcx + let param_env_and = tcx .erase_regions(param_env) .with_reveal_all_normalized(tcx) - .and(tcx.erase_regions(substs)); + .and(tcx.erase_regions(unevaluated)); // HACK(eddyb) when the query key would contain inference variables, // attempt using identity substs and `ParamEnv` instead, that will succeed // when the expression doesn't depend on any parameters. // FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that // we can call `infcx.const_eval_resolve` which handles inference variables. - let param_env_and_substs = if param_env_and_substs.needs_infer() { - tcx.param_env(def.did).and(InternalSubsts::identity_for_item(tcx, def.did)) + let param_env_and = if param_env_and.needs_infer() { + tcx.param_env(unevaluated.def.did).and(ty::Unevaluated { + def: unevaluated.def, + substs_: Some(InternalSubsts::identity_for_item(tcx, unevaluated.def.did)), + promoted: unevaluated.promoted, + }) } else { - param_env_and_substs + param_env_and }; // FIXME(eddyb) maybe the `const_eval_*` methods should take - // `ty::ParamEnvAnd` instead of having them separate. - let (param_env, substs) = param_env_and_substs.into_parts(); + // `ty::ParamEnvAnd` instead of having them separate. + let (param_env, unevaluated) = param_env_and.into_parts(); // try to resolve e.g. associated constants to their definition on an impl, and then // evaluate the const. - match tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, None) - { + match tcx.const_eval_resolve(param_env, unevaluated, None) { // NOTE(eddyb) `val` contains no lifetimes/types/consts, // and we use the original type, so nothing from `substs` // (which may be identity substs, see above), diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 04df706d9084..89cba4aab836 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -305,7 +305,8 @@ impl FlagComputation { } fn add_unevaluated_const(&mut self, ct: ty::Unevaluated<'tcx>) { - self.add_substs(ct.substs); + // TODO + self.add_substs(ct.substs_.unwrap()); self.add_flags(TypeFlags::HAS_CT_PROJECTION); } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 40b3ffb89557..6e70e8ddaed8 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -192,9 +192,11 @@ pub trait TypeVisitor<'tcx>: Sized { /// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs /// are not yet supplied. /// - /// Visitors which do not look into these substs may leave this unimplemented, so be - /// careful when calling this method elsewhere. - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx>; + /// Visitors which do not look into these substs may return `None` here, in which case + /// `super_visit_with` completely skips the default substs. Incorrectly returning + /// `None` can very quickly lead to ICE or other critical bugs, so be careful and + /// try to return an actual `tcx` if at all possible. + fn tcx_for_anon_const_substs(&self) -> Option>; fn visit_binder>( &mut self, @@ -336,8 +338,8 @@ impl<'tcx> TyCtxt<'tcx> { { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_binder>( @@ -788,8 +790,9 @@ impl<'tcx> ValidateBoundVars<'tcx> { impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("default anon const substs can't contain bound vars"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // Anonymous constants do not contain bound vars in their substs by default. + None } fn visit_binder>( @@ -1006,8 +1009,9 @@ struct HasEscapingVarsVisitor { impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { type BreakTy = FoundEscapingVars; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for HasEscpaingVarsVisitor"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // Anonymous constants do not contain bound vars in their substs by default. + None } fn visit_binder>( @@ -1080,8 +1084,13 @@ struct HasTypeFlagsVisitor { impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { type BreakTy = FoundFlags; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for HasTypeFlagsVisitor"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // TypeFlagsVisitor must not look into the default anon const substs + // as that would cause cycle errors, but we do care about them for + // some flags. + // + // We therefore have to be very careful here. + None } #[inline] @@ -1164,8 +1173,8 @@ impl LateBoundRegionsCollector<'tcx> { } impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector<'tcx> { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_binder>( diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ef999285f537..132223630961 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -927,29 +927,28 @@ pub trait PrettyPrinter<'tcx>: } match ct.val { - ty::ConstKind::Unevaluated(ty::Unevaluated { - def, - substs, - promoted: Some(promoted), - }) => { - p!(print_value_path(def.did, substs)); - p!(write("::{:?}", promoted)); - } - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: None }) => { - match self.tcx().def_kind(def.did) { - DefKind::Static | DefKind::Const | DefKind::AssocConst => { - p!(print_value_path(def.did, substs)) - } - _ => { - if def.is_local() { - let span = self.tcx().def_span(def.did); - if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) { - p!(write("{}", snip)) + ty::ConstKind::Unevaluated(uv) => { + if let Some(promoted) = uv.promoted { + let substs = uv.substs_.unwrap(); + p!(print_value_path(uv.def.did, substs)); + p!(write("::{:?}", promoted)); + } else { + let tcx = self.tcx(); + match tcx.def_kind(uv.def.did) { + DefKind::Static | DefKind::Const | DefKind::AssocConst => { + p!(print_value_path(uv.def.did, uv.substs(tcx))) + } + _ => { + if uv.def.is_local() { + let span = tcx.def_span(uv.def.did); + if let Ok(snip) = tcx.sess.source_map().span_to_snippet(span) { + p!(write("{}", snip)) + } else { + print_underscore!() + } } else { print_underscore!() } - } else { - print_underscore!() } } } @@ -2025,8 +2024,8 @@ impl FmtPrinter<'_, 'tcx, F> { impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 9c48f05617e0..c978e1de38de 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -579,7 +579,7 @@ pub fn super_relate_consts>( (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if tcx.features().const_evaluatable_checked => { - tcx.try_unify_abstract_consts(((au.def, au.substs), (bu.def, bu.substs))) + tcx.try_unify_abstract_consts(((au.def, au.substs(tcx)), (bu.def, bu.substs(tcx)))) } // While this is slightly incorrect, it shouldn't matter for `min_const_generics` @@ -591,13 +591,13 @@ pub fn super_relate_consts>( let substs = relation.relate_with_variance( ty::Variance::Invariant, ty::VarianceDiagInfo::default(), - au.substs, - bu.substs, + au.substs(tcx), + bu.substs(tcx), )?; return Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Unevaluated(ty::Unevaluated { def: au.def, - substs, + substs_: Some(substs), promoted: au.promoted, }), ty: a.ty, diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index a46cac1e7f7f..fe7d46240cb8 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1046,13 +1046,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { match self { ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)), ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)), - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => { - ty::ConstKind::Unevaluated(ty::Unevaluated { - def, - substs: substs.fold_with(folder), - promoted, - }) - } + ty::ConstKind::Unevaluated(uv) => ty::ConstKind::Unevaluated(uv.fold_with(folder)), ty::ConstKind::Value(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(..) @@ -1064,7 +1058,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { match *self { ty::ConstKind::Infer(ic) => ic.visit_with(visitor), ty::ConstKind::Param(p) => p.visit_with(visitor), - ty::ConstKind::Unevaluated(ct) => ct.substs.visit_with(visitor), + ty::ConstKind::Unevaluated(uv) => uv.visit_with(visitor), ty::ConstKind::Value(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) @@ -1082,3 +1076,24 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { ControlFlow::CONTINUE } } + +impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { + fn super_fold_with>(self, folder: &mut F) -> Self { + ty::Unevaluated { + def: self.def, + substs_: Some(self.substs(folder.tcx()).fold_with(folder)), + promoted: self.promoted, + } + } + + fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + if let Some(tcx) = visitor.tcx_for_anon_const_substs() { + self.substs(tcx).visit_with(visitor) + } else if let Some(substs) = self.substs_ { + substs.visit_with(visitor) + } else { + debug!("ignoring default substs of `{:?}`", self.def); + ControlFlow::CONTINUE + } + } +} diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index c2fe5f1ef3f6..c9fc97f0aaf9 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -196,7 +196,8 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) | ty::ConstKind::Error(_) => {} ty::ConstKind::Unevaluated(ct) => { - stack.extend(ct.substs.iter().rev()); + // TODO + stack.extend(ct.substs_.unwrap().iter().rev()); } } } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 999b25319bf8..639bcb8fa94e 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -377,8 +377,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { }, _ => None, }; - if let Some(ty::Unevaluated { def, substs, promoted }) = maybe_uneval { - if let Some(promoted) = promoted { + if let Some(uv) = maybe_uneval { + if let Some(promoted) = uv.promoted { let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, promoted: &Body<'tcx>, ty, @@ -413,8 +413,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { ConstraintCategory::Boring, self.cx.param_env.and(type_op::ascribe_user_type::AscribeUserType::new( constant.literal.ty(), - def.did, - UserSubsts { substs, user_self_ty: None }, + uv.def.did, + UserSubsts { substs: uv.substs(self.tcx()), user_self_ty: None }, )), ) { span_mirbug!( diff --git a/compiler/rustc_mir/src/interpret/operand.rs b/compiler/rustc_mir/src/interpret/operand.rs index 81f78621d145..403dc1b4793d 100644 --- a/compiler/rustc_mir/src/interpret/operand.rs +++ b/compiler/rustc_mir/src/interpret/operand.rs @@ -555,9 +555,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match val.val { ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric), ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorReported)), - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => { - let instance = self.resolve(def, substs)?; - Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into()) + ty::ConstKind::Unevaluated(uv) => { + let instance = self.resolve(uv.def, uv.substs(*self.tcx))?; + Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into()) } ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => { span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val) diff --git a/compiler/rustc_mir/src/interpret/util.rs b/compiler/rustc_mir/src/interpret/util.rs index b7ab2e88b962..b9d6e002e2db 100644 --- a/compiler/rustc_mir/src/interpret/util.rs +++ b/compiler/rustc_mir/src/interpret/util.rs @@ -21,8 +21,8 @@ where impl<'tcx> TypeVisitor<'tcx> for UsedParamsNeedSubstVisitor<'tcx> { type BreakTy = FoundParam; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index dd7500e9e9d5..b086053a0c10 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -283,8 +283,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { } impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { @@ -298,7 +298,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { self.unused_parameters.clear(param.index); ControlFlow::CONTINUE } - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: Some(p)}) + ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: Some(p)}) // Avoid considering `T` unused when constants are of the form: // `>::foo::promoted[p]` if self.def_id == def.did && !self.tcx.generics_of(def.did).has_self => @@ -309,10 +309,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { self.visit_body(&promoted[p]); ControlFlow::CONTINUE } - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: None }) - if self.tcx.def_kind(def.did) == DefKind::AnonConst => + ty::ConstKind::Unevaluated(uv) + if self.tcx.def_kind(uv.def.did) == DefKind::AnonConst => { - self.visit_child_body(def.did, substs); + self.visit_child_body(uv.def.did, uv.substs(self.tcx)); ControlFlow::CONTINUE } _ => c.super_visit_with(self), @@ -357,8 +357,8 @@ struct HasUsedGenericParams<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } #[instrument(skip(self))] diff --git a/compiler/rustc_mir/src/transform/check_consts/qualifs.rs b/compiler/rustc_mir/src/transform/check_consts/qualifs.rs index ac8c748ea857..413a9638eb37 100644 --- a/compiler/rustc_mir/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_mir/src/transform/check_consts/qualifs.rs @@ -247,7 +247,7 @@ where // Check the qualifs of the value of `const` items. if let Some(ct) = constant.literal.const_for_ty() { - if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) = ct.val { + if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val { assert!(promoted.is_none()); // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def.did).is_none() { diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 4578f04c0345..98581f76821b 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -483,7 +483,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // Promoteds must lint and not error as the user didn't ask for them ConstKind::Unevaluated(ty::Unevaluated { def: _, - substs: _, + substs_: _, promoted: Some(_), }) => true, // Out of backwards compatibility we cannot report hard errors in unused diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs index 822b422985cb..14c9b3b0d479 100644 --- a/compiler/rustc_mir/src/transform/promote_consts.rs +++ b/compiler/rustc_mir/src/transform/promote_consts.rs @@ -859,13 +859,17 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { ty, val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, - substs: InternalSubsts::for_item(tcx, def.did, |param, _| { - if let ty::GenericParamDefKind::Lifetime = param.kind { - tcx.lifetimes.re_erased.into() - } else { - tcx.mk_param_from_def(param) - } - }), + substs_: Some(InternalSubsts::for_item( + tcx, + def.did, + |param, _| { + if let ty::GenericParamDefKind::Lifetime = param.kind { + tcx.lifetimes.re_erased.into() + } else { + tcx.mk_param_from_def(param) + } + }, + )), promoted: Some(promoted_id), }), }) diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 435fca4a11b4..92591db668ce 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -475,7 +475,7 @@ impl Visitor<'tcx> for ExtraComments<'tcx> { ty::ConstKind::Unevaluated(uv) => format!( "Unevaluated({}, {:?}, {:?})", self.tcx.def_path_str(uv.def.did), - uv.substs, + uv.substs(self.tcx), uv.promoted ), ty::ConstKind::Value(val) => format!("Value({:?})", val), @@ -682,8 +682,10 @@ pub fn write_allocations<'tcx>( } struct CollectAllocIds(BTreeSet); impl<'tcx> TypeVisitor<'tcx> for CollectAllocIds { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for CollectAllocIds") + fn tcx_for_anon_const_substs(&self) -> Option> { + // `AllocId`s are only inside of `ConstKind::Value` which + // can't be part of the anon const default substs. + None } fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index f1d882e1ddd7..9106f1d2342a 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -693,11 +693,10 @@ impl<'tcx> Cx<'tcx> { // and not the beginning of discriminants (which is always `0`) let substs = InternalSubsts::identity_for_item(self.tcx(), did); let lhs = ty::Const { - val: ty::ConstKind::Unevaluated(ty::Unevaluated { - def: ty::WithOptConstParam::unknown(did), + val: ty::ConstKind::Unevaluated(ty::Unevaluated::new( + ty::WithOptConstParam::unknown(did), substs, - promoted: None, - }), + )), ty: var_ty, }; let lhs = self.thir.exprs.push(mk_const(self.tcx().mk_const(lhs))); @@ -889,11 +888,10 @@ impl<'tcx> Cx<'tcx> { debug!("convert_path_expr: (const) user_ty={:?}", user_ty); ExprKind::Literal { literal: self.tcx.mk_const(ty::Const { - val: ty::ConstKind::Unevaluated(ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), + val: ty::ConstKind::Unevaluated(ty::Unevaluated::new( + ty::WithOptConstParam::unknown(def_id), substs, - promoted: None, - }), + )), ty: self.typeck_results().node_type(expr.hir_id), }), user_ty, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 45d31068668e..fb223d8fa751 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -179,8 +179,8 @@ where { type BreakTy = V::BreakTy; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.def_id_visitor.tcx() + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.def_id_visitor.tcx()) } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 083a962ac7b2..f89ca0fed036 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -558,8 +558,8 @@ impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP> where OP: FnMut(ty::Region<'tcx>), { - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_binder>( diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index b1a938836b70..2f1e7e9d509b 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -155,11 +155,8 @@ pub fn is_const_evaluatable<'cx, 'tcx>( // and hopefully soon change this to an error. // // See #74595 for more details about this. - let concrete = infcx.const_eval_resolve( - param_env, - ty::Unevaluated { def, substs, promoted: None }, - Some(span), - ); + let concrete = + infcx.const_eval_resolve(param_env, ty::Unevaluated::new(def, substs), Some(span)); if concrete.is_ok() && substs.has_param_types_or_consts() { match infcx.tcx.def_kind(def.did) { @@ -217,9 +214,7 @@ impl AbstractConst<'tcx> { ct: &ty::Const<'tcx>, ) -> Result>, ErrorReported> { match ct.val { - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: _ }) => { - AbstractConst::new(tcx, def, substs) - } + ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv.def, uv.substs(tcx)), ty::ConstKind::Error(_) => Err(ErrorReported), _ => Ok(None), } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 4b94deff825b..903912c3361e 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -570,7 +570,8 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ty::PredicateKind::ConstEquate(c1, c2) => { debug!(?c1, ?c2, "equating consts"); - if self.selcx.tcx().features().const_evaluatable_checked { + let tcx = self.selcx.tcx(); + if tcx.features().const_evaluatable_checked { // FIXME: we probably should only try to unify abstract constants // if the constants depend on generic parameters. // @@ -597,7 +598,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { Err(ErrorHandled::TooGeneric) => { stalled_on.extend( unevaluated - .substs + .substs(tcx) .iter() .filter_map(TyOrConstInferVar::maybe_from_generic_arg), ); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b81ca52f9fd3..01bad14c8fa9 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -771,8 +771,8 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>( impl<'tcx> TypeVisitor<'tcx> for IllegalSelfTypeVisitor<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index fd7dc55ac841..ac8bab0cf36a 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -130,8 +130,8 @@ impl Search<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> { type BreakTy = NonStructuralMatchTy<'tcx>; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx() + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx()) } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index afef784b4c6c..e44576061322 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -435,13 +435,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { GenericArgKind::Const(constant) => { match constant.val { - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => { - assert!(promoted.is_none()); + ty::ConstKind::Unevaluated(uv) => { + assert!(uv.promoted.is_none()); + let substs = uv.substs(self.tcx()); - let obligations = self.nominal_obligations(def.did, substs); + let obligations = self.nominal_obligations(uv.def.did, substs); self.out.extend(obligations); - let predicate = ty::PredicateKind::ConstEvaluatable(def, substs) + let predicate = ty::PredicateKind::ConstEvaluatable(uv.def, substs) .to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::with_depth( diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index d07eeaedd82d..1d4196e57478 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -854,8 +854,8 @@ impl<'tcx> BoundVarsCollector<'tcx> { } impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_binder>( @@ -1076,8 +1076,9 @@ impl PlaceholdersCollector { } impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for PlaceholdersCollector"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // Anon const substs do not contain placeholders by default. + None } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index b9fbb5da3e60..b00d2ab35617 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -54,8 +54,9 @@ impl<'tcx> BoundVarsCollector<'tcx> { impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("default anon const substs can't be bound vars"); + fn tcx_for_anon_const_substs(&self) -> Option> { + // Anon const substs do not contain bound vars by default. + None } fn visit_binder>( &mut self, diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 06fae26f7df4..649574fe1957 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -473,8 +473,8 @@ pub(super) fn check_opaque_for_inheriting_lifetimes( struct FindParentLifetimeVisitor<'tcx>(TyCtxt<'tcx>, &'tcx ty::Generics); impl<'tcx> ty::fold::TypeVisitor<'tcx> for FindParentLifetimeVisitor<'tcx> { type BreakTy = FoundParentLifetime; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.0 + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.0) } fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { @@ -510,8 +510,8 @@ pub(super) fn check_opaque_for_inheriting_lifetimes( impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueVisitor<'tcx> { type BreakTy = Ty<'tcx>; - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { @@ -1584,10 +1584,11 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { .filter_map(|e| typeck_results.node_type_opt(e.hir_id).map(|t| (e.span, t))) .filter(|(_, ty)| !matches!(ty.kind(), ty::Never)) { - struct VisitTypes(Vec); - impl<'tcx> ty::fold::TypeVisitor<'tcx> for VisitTypes { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - bug!("tcx_for_anon_const_substs called for VisitTypes"); + struct OpaqueTypeCollector(Vec); + impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypeCollector { + fn tcx_for_anon_const_substs(&self) -> Option> { + // Default anon const substs cannot contain opaque types. + None } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { @@ -1599,7 +1600,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) { } } } - let mut visitor = VisitTypes(vec![]); + let mut visitor = OpaqueTypeCollector(vec![]); ty.visit_with(&mut visitor); for def_id in visitor.0 { let ty_span = tcx.def_span(def_id); diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 3503d68e8f02..9b495fba1975 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -1006,8 +1006,8 @@ fn suggest_constraining_param( struct TypeParamVisitor<'tcx>(TyCtxt<'tcx>, Vec>); impl<'tcx> TypeVisitor<'tcx> for TypeParamVisitor<'tcx> { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.0 + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.0) } fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { if let ty::Param(_) = ty.kind() { diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 44caf348a98e..0d121b9da876 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -831,8 +831,8 @@ fn check_where_clauses<'tcx, 'fcx>( } impl<'tcx> ty::fold::TypeVisitor<'tcx> for CountParams<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index d5316352c546..a5a402bc26a8 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -68,6 +68,7 @@ fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { pub fn provide(providers: &mut Providers) { *providers = Providers { opt_const_param_of: type_of::opt_const_param_of, + default_anon_const_substs: type_of::default_anon_const_substs, type_of: type_of::type_of, item_bounds: item_bounds::item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds, @@ -2355,7 +2356,8 @@ fn const_evaluatable_predicates_of<'tcx>( assert_eq!(uv.promoted, None); let span = self.tcx.hir().span(c.hir_id); self.preds.insert(( - ty::PredicateKind::ConstEvaluatable(uv.def, uv.substs).to_predicate(self.tcx), + ty::PredicateKind::ConstEvaluatable(uv.def, uv.substs(self.tcx)) + .to_predicate(self.tcx), span, )); } diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 4048a54b58c9..98f5f73b7bec 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -7,7 +7,7 @@ use rustc_hir::intravisit; use rustc_hir::intravisit::Visitor; use rustc_hir::{HirId, Node}; use rustc_middle::hir::map::Map; -use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; +use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable, TypeFolder}; use rustc_span::symbol::Ident; @@ -274,6 +274,10 @@ fn get_path_containing_arg_in_pat<'hir>( arg_path } +pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { + InternalSubsts::identity_for_item(tcx, def_id) +} + pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let def_id = def_id.expect_local(); use rustc_hir::*; diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index 140348ea4ec1..9b6f0be47caf 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -60,8 +60,8 @@ struct ParameterCollector<'tcx> { } impl<'tcx> TypeVisitor<'tcx> for ParameterCollector<'tcx> { - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.tcx + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) } fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index bdd5350aab2c..bdfe3ffc13f1 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -287,7 +287,7 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { - ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => { + ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) => { let mut s = if let Some(def) = def.as_local() { let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did); print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(hir_id)) diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 3f9110295fc6..2a85a67fa099 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -187,11 +187,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D let result = cx.tcx.const_eval_resolve( cx.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), - substs, - promoted: None, - }, + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ); is_value_unfrozen_raw(cx, result, ty) diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index 2335d2248aa9..f5e43264a5c6 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -705,8 +705,8 @@ struct ContainsRegion<'tcx>(TyCtxt<'tcx>); impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> { type BreakTy = (); - fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> { - self.0 + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.0) } fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 9ba1381da659..8bf31807d55d 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -346,11 +346,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { .tcx .const_eval_resolve( self.param_env, - ty::Unevaluated { - def: ty::WithOptConstParam::unknown(def_id), - substs, - promoted: None, - }, + ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs), None, ) .ok() From cc47998e2877f13712a12b3814cc2bbf07fbae09 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 17 Jul 2021 16:43:23 +0200 Subject: [PATCH 157/269] add `tcx` to `fn walk` --- .../infer/error_reporting/need_type_info.rs | 2 +- .../rustc_infer/src/infer/outlives/verify.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 4 +- compiler/rustc_middle/src/ty/outlives.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 41 +++++++++++-------- .../rustc_mir/src/monomorphize/collector.rs | 2 +- .../src/transform/check_consts/check.rs | 2 +- .../src/transform/function_item_references.rs | 4 +- .../src/thir/pattern/const_to_pat.rs | 2 +- .../src/traits/fulfill.rs | 5 ++- .../src/traits/object_safety.rs | 2 +- .../src/traits/select/confirmation.rs | 8 ++-- .../rustc_trait_selection/src/traits/wf.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 4 +- compiler/rustc_typeck/src/astconv/mod.rs | 4 +- compiler/rustc_typeck/src/check/check.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 2 +- .../src/outlives/implicit_infer.rs | 4 +- src/tools/clippy/clippy_lints/src/escape.rs | 4 +- .../clippy/clippy_lints/src/let_underscore.rs | 2 +- .../clippy_lints/src/loops/same_item_push.rs | 2 +- .../clippy/clippy_lints/src/methods/mod.rs | 10 ++--- src/tools/clippy/clippy_lints/src/returns.rs | 2 +- .../src/self_named_constructors.rs | 4 +- .../clippy_lints/src/unnecessary_sort_by.rs | 2 +- src/tools/clippy/clippy_lints/src/use_self.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 4 +- .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 12 +++--- 29 files changed, 73 insertions(+), 67 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index c2025f3fe4da..e00003face9c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -51,7 +51,7 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> { fn node_ty_contains_target(&self, hir_id: HirId) -> Option> { self.node_type_opt(hir_id).map(|ty| self.infcx.resolve_vars_if_possible(ty)).filter(|ty| { - ty.walk().any(|inner| { + ty.walk(self.infcx.tcx).any(|inner| { inner == self.target || match (inner.unpack(), self.target.unpack()) { (GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => { diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index f69212c599b6..dba73251b4f0 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -189,7 +189,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { visited: &mut SsoHashSet>, ) -> VerifyBound<'tcx> { let mut bounds = parent - .walk_shallow(visited) + .walk_shallow(self.tcx, visited) .filter_map(|child| match child.unpack() { GenericArgKind::Type(ty) => Some(self.type_bound(ty, visited)), GenericArgKind::Lifetime(lt) => { diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index add0c0ff332f..b4f11a8a0448 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -152,8 +152,8 @@ declare_lint! { declare_lint_pass!(BoxPointers => [BOX_POINTERS]); impl BoxPointers { - fn check_heap_type(&self, cx: &LateContext<'_>, span: Span, ty: Ty<'_>) { - for leaf in ty.walk() { + fn check_heap_type<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { + for leaf in ty.walk(cx.tcx) { if let GenericArgKind::Type(leaf_ty) = leaf.unpack() { if leaf_ty.is_box() { cx.struct_span_lint(BOX_POINTERS, span, |lint| { diff --git a/compiler/rustc_middle/src/ty/outlives.rs b/compiler/rustc_middle/src/ty/outlives.rs index 86750d5c0811..ef4ad998f10c 100644 --- a/compiler/rustc_middle/src/ty/outlives.rs +++ b/compiler/rustc_middle/src/ty/outlives.rs @@ -194,7 +194,7 @@ fn compute_components_recursive( out: &mut SmallVec<[Component<'tcx>; 4]>, visited: &mut SsoHashSet>, ) { - for child in parent.walk_shallow(visited) { + for child in parent.walk_shallow(tcx, visited) { match child.unpack() { GenericArgKind::Type(ty) => { compute_components(tcx, ty, out, visited); diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index c9fc97f0aaf9..3cab813f12ad 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -1,8 +1,8 @@ //! An iterator over the type substructure. //! WARNING: this does not keep track of the region depth. -use crate::ty; use crate::ty::subst::{GenericArg, GenericArgKind}; +use crate::ty::{self, TyCtxt}; use rustc_data_structures::sso::SsoHashSet; use smallvec::{self, SmallVec}; @@ -11,6 +11,7 @@ use smallvec::{self, SmallVec}; type TypeWalkerStack<'tcx> = SmallVec<[GenericArg<'tcx>; 8]>; pub struct TypeWalker<'tcx> { + tcx: TyCtxt<'tcx>, stack: TypeWalkerStack<'tcx>, last_subtree: usize, pub visited: SsoHashSet>, @@ -25,8 +26,8 @@ pub struct TypeWalker<'tcx> { /// It maintains a set of visited types and /// skips any types that are already there. impl<'tcx> TypeWalker<'tcx> { - pub fn new(root: GenericArg<'tcx>) -> Self { - Self { stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() } + fn new(tcx: TyCtxt<'tcx>, root: GenericArg<'tcx>) -> Self { + Self { tcx, stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() } } /// Skips the subtree corresponding to the last type @@ -55,7 +56,7 @@ impl<'tcx> Iterator for TypeWalker<'tcx> { let next = self.stack.pop()?; self.last_subtree = self.stack.len(); if self.visited.insert(next) { - push_inner(&mut self.stack, next); + push_inner(self.tcx, &mut self.stack, next); debug!("next: stack={:?}", self.stack); return Some(next); } @@ -74,8 +75,8 @@ impl GenericArg<'tcx> { /// Foo> => { Foo>, Bar, isize } /// [isize] => { [isize], isize } /// ``` - pub fn walk(self) -> TypeWalker<'tcx> { - TypeWalker::new(self) + pub fn walk(self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> { + TypeWalker::new(tcx, self) } /// Iterator that walks the immediate children of `self`. Hence @@ -87,10 +88,11 @@ impl GenericArg<'tcx> { /// and skips any types that are already there. pub fn walk_shallow( self, + tcx: TyCtxt<'tcx>, visited: &mut SsoHashSet>, ) -> impl Iterator> { let mut stack = SmallVec::new(); - push_inner(&mut stack, self); + push_inner(tcx, &mut stack, self); stack.retain(|a| visited.insert(*a)); stack.into_iter() } @@ -107,18 +109,22 @@ impl<'tcx> super::TyS<'tcx> { /// Foo> => { Foo>, Bar, isize } /// [isize] => { [isize], isize } /// ``` - pub fn walk(&'tcx self) -> TypeWalker<'tcx> { - TypeWalker::new(self.into()) + pub fn walk(&'tcx self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> { + TypeWalker::new(tcx, self.into()) } } -// We push `GenericArg`s on the stack in reverse order so as to -// maintain a pre-order traversal. As of the time of this -// writing, the fact that the traversal is pre-order is not -// known to be significant to any code, but it seems like the -// natural order one would expect (basically, the order of the -// types as they are written). -fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) { +/// We push `GenericArg`s on the stack in reverse order so as to +/// maintain a pre-order traversal. As of the time of this +/// writing, the fact that the traversal is pre-order is not +/// known to be significant to any code, but it seems like the +/// natural order one would expect (basically, the order of the +/// types as they are written). +fn push_inner<'tcx>( + tcx: TyCtxt<'tcx>, + stack: &mut TypeWalkerStack<'tcx>, + parent: GenericArg<'tcx>, +) { match parent.unpack() { GenericArgKind::Type(parent_ty) => match *parent_ty.kind() { ty::Bool @@ -196,8 +202,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) | ty::ConstKind::Error(_) => {} ty::ConstKind::Unevaluated(ct) => { - // TODO - stack.extend(ct.substs_.unwrap().iter().rev()); + stack.extend(ct.substs(tcx).iter().rev()); } } } diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 95c4237f3839..f03036267acf 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -573,7 +573,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { let type_length = instance .substs .iter() - .flat_map(|arg| arg.walk()) + .flat_map(|arg| arg.walk(tcx)) .filter(|arg| match arg.unpack() { GenericArgKind::Type(_) | GenericArgKind::Const(_) => true, GenericArgKind::Lifetime(_) => false, diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs index 09e908e67573..0361ddc915d4 100644 --- a/compiler/rustc_mir/src/transform/check_consts/check.rs +++ b/compiler/rustc_mir/src/transform/check_consts/check.rs @@ -365,7 +365,7 @@ impl Checker<'mir, 'tcx> { fn check_local_or_return_ty(&mut self, ty: Ty<'tcx>, local: Local) { let kind = self.body.local_kind(local); - for ty in ty.walk() { + for ty in ty.walk(self.tcx) { let ty = match ty.unpack() { GenericArgKind::Type(ty) => ty, diff --git a/compiler/rustc_mir/src/transform/function_item_references.rs b/compiler/rustc_mir/src/transform/function_item_references.rs index 26fe796cb916..ba2c91a9347e 100644 --- a/compiler/rustc_mir/src/transform/function_item_references.rs +++ b/compiler/rustc_mir/src/transform/function_item_references.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FunctionItemRefChecker<'a, 'tcx> { // Handle calls to `transmute` if self.tcx.is_diagnostic_item(sym::transmute, def_id) { let arg_ty = args[0].ty(self.body, self.tcx); - for generic_inner_ty in arg_ty.walk() { + for generic_inner_ty in arg_ty.walk(self.tcx) { if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() { if let Some((fn_id, fn_substs)) = FunctionItemRefChecker::is_fn_ref(inner_ty) @@ -110,7 +110,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { let arg_defs = self.tcx.fn_sig(def_id).skip_binder().inputs(); for (arg_num, arg_def) in arg_defs.iter().enumerate() { // For all types reachable from the argument type in the fn sig - for generic_inner_ty in arg_def.walk() { + for generic_inner_ty in arg_def.walk(self.tcx) { if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() { // If the inner type matches the type bound by `Pointer` if TyS::same_type(inner_ty, bound_ty) { diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 926bd830da0a..bbb5de34d186 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -237,7 +237,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> { // code at the moment, because types like `for <'a> fn(&'a ())` do // not *yet* implement `PartialEq`. So for now we leave this here. has_impl - || ty.walk().any(|t| match t.unpack() { + || ty.walk(self.tcx()).any(|t| match t.unpack() { ty::subst::GenericArgKind::Lifetime(_) => false, ty::subst::GenericArgKind::Type(t) => t.is_fn_ptr(), ty::subst::GenericArgKind::Const(_) => false, diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 903912c3361e..110d83cbe28b 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -767,14 +767,15 @@ fn substs_infer_vars<'a, 'tcx>( selcx: &mut SelectionContext<'a, 'tcx>, substs: ty::Binder<'tcx, SubstsRef<'tcx>>, ) -> impl Iterator> { + let tcx = selcx.tcx(); selcx .infcx() .resolve_vars_if_possible(substs) .skip_binder() // ok because this check doesn't care about regions .iter() .filter(|arg| arg.has_infer_types_or_consts()) - .flat_map(|arg| { - let mut walker = arg.walk(); + .flat_map(move |arg| { + let mut walker = arg.walk(tcx); while let Some(c) = walker.next() { if !c.has_infer_types_or_consts() { walker.visited.remove(&c); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 01bad14c8fa9..9511b41147da 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -278,7 +278,7 @@ fn predicate_references_self( (predicate, sp): (ty::Predicate<'tcx>, Span), ) -> Option { let self_ty = tcx.types.self_param; - let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into()); + let has_self_ty = |arg: &GenericArg<'tcx>| arg.walk(tcx).any(|arg| arg == self_ty.into()); match predicate.kind().skip_binder() { ty::PredicateKind::Trait(ref data) => { // In the case of a trait predicate, we can skip the "self" type. diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index ba62ce1d5312..c571a1d62842 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -947,7 +947,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let mut unsizing_params = GrowableBitSet::new_empty(); if tcx.features().relaxed_struct_unsize { - for arg in tail_field_ty.walk() { + for arg in tail_field_ty.walk(tcx) { if let Some(i) = maybe_unsizing_param_idx(arg) { unsizing_params.insert(i); } @@ -956,7 +956,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Ensure none of the other fields mention the parameters used // in unsizing. for field in prefix_fields { - for arg in tcx.type_of(field.did).walk() { + for arg in tcx.type_of(field.did).walk(tcx) { if let Some(i) = maybe_unsizing_param_idx(arg) { unsizing_params.remove(i); } @@ -968,7 +968,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } else { let mut found = false; - for arg in tail_field_ty.walk() { + for arg in tail_field_ty.walk(tcx) { if let Some(i) = maybe_unsizing_param_idx(arg) { unsizing_params.insert(i); found = true; @@ -984,7 +984,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // by putting it in a query; it would only need the `DefId` as it // looks at declared field types, not anything substituted. for field in prefix_fields { - for arg in tcx.type_of(field.did).walk() { + for arg in tcx.type_of(field.did).walk(tcx) { if let Some(i) = maybe_unsizing_param_idx(arg) { if unsizing_params.contains(i) { return Err(Unimplemented); diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index e44576061322..623215ec34e1 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -422,7 +422,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { /// Pushes all the predicates needed to validate that `ty` is WF into `out`. fn compute(&mut self, arg: GenericArg<'tcx>) { - let mut walker = arg.walk(); + let mut walker = arg.walk(self.tcx()); let param_env = self.param_env; let depth = self.recursion_depth; while let Some(arg) = walker.next() { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 8332e7384110..1b0fff93a99f 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -361,7 +361,7 @@ fn well_formed_types_in_env<'tcx>( // constituents are well-formed. NodeKind::InherentImpl => { let self_ty = tcx.type_of(def_id); - inputs.extend(self_ty.walk()); + inputs.extend(self_ty.walk(tcx)); } // In an fn, we assume that the arguments and all their constituents are @@ -370,7 +370,7 @@ fn well_formed_types_in_env<'tcx>( let fn_sig = tcx.fn_sig(def_id); let fn_sig = tcx.liberate_late_bound_regions(def_id, fn_sig); - inputs.extend(fn_sig.inputs().iter().flat_map(|ty| ty.walk())); + inputs.extend(fn_sig.inputs().iter().flat_map(|ty| ty.walk(tcx))); } NodeKind::Other => (), diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 606fd2812ecc..2879b7fcd911 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -394,7 +394,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if self.is_object && has_default { let default_ty = tcx.at(self.span).type_of(param.def_id); let self_param = tcx.types.self_param; - if default_ty.walk().any(|arg| arg == self_param.into()) { + if default_ty.walk(tcx).any(|arg| arg == self_param.into()) { // There is no suitable inference default for a type parameter // that references self, in an object type. return true; @@ -1354,7 +1354,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // A `Self` within the original bound will be substituted with a // `trait_object_dummy_self`, so check for that. let references_self = - pred.skip_binder().ty.walk().any(|arg| arg == dummy_self.into()); + pred.skip_binder().ty.walk(tcx).any(|arg| arg == dummy_self.into()); // If the projection output contains `Self`, force the user to // elaborate it explicitly to avoid a lot of complexity. diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 649574fe1957..3c9d5b4def4e 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -1482,7 +1482,7 @@ pub(super) fn check_type_params_are_used<'tcx>( return; } - for leaf in ty.walk() { + for leaf in ty.walk(tcx) { if let GenericArgKind::Type(leaf_ty) = leaf.unpack() { if let ty::Param(param) = leaf_ty.kind() { debug!("found use of ty param {:?}", param); diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index b624e07374ec..9efb52a08b7e 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -937,7 +937,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.resolve_vars_if_possible(ty); // We walk the argument type because the argument's type could have // been `Option`, but the `FulfillmentError` references `T`. - if ty.walk().any(|arg| arg == predicate.self_ty().into()) { + if ty.walk(self.tcx).any(|arg| arg == predicate.self_ty().into()) { Some(i) } else { None diff --git a/compiler/rustc_typeck/src/outlives/implicit_infer.rs b/compiler/rustc_typeck/src/outlives/implicit_infer.rs index ccf0fb727383..985ee2169c92 100644 --- a/compiler/rustc_typeck/src/outlives/implicit_infer.rs +++ b/compiler/rustc_typeck/src/outlives/implicit_infer.rs @@ -114,7 +114,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( required_predicates: &mut RequiredPredicates<'tcx>, explicit_map: &mut ExplicitPredicatesMap<'tcx>, ) { - for arg in field_ty.walk() { + for arg in field_ty.walk(tcx) { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, @@ -306,7 +306,7 @@ pub fn check_explicit_predicates<'tcx>( // 'b`. if let Some(self_ty) = ignored_self_ty { if let GenericArgKind::Type(ty) = outlives_predicate.0.unpack() { - if ty.walk().any(|arg| arg == self_ty.into()) { + if ty.walk(tcx).any(|arg| arg == self_ty.into()) { debug!("skipping self ty = {:?}", &ty); continue; } diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index 8b0e9e6bc9b9..685dbf26250c 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -53,7 +53,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { struct EscapeDelegate<'a, 'tcx> { cx: &'a LateContext<'tcx>, set: HirIdSet, - trait_self_ty: Option>, + trait_self_ty: Option>, too_large_for_stack: u64, } @@ -171,7 +171,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { // skip if there is a `self` parameter binding to a type // that contains `Self` (i.e.: `self: Box`), see #4804 if let Some(trait_self_ty) = self.trait_self_ty { - if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) { + if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty) { return; } } diff --git a/src/tools/clippy/clippy_lints/src/let_underscore.rs b/src/tools/clippy/clippy_lints/src/let_underscore.rs index 8992d25932ca..89146b4dd2c9 100644 --- a/src/tools/clippy/clippy_lints/src/let_underscore.rs +++ b/src/tools/clippy/clippy_lints/src/let_underscore.rs @@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { if let Some(init) = local.init; then { let init_ty = cx.typeck_results().expr_ty(init); - let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { + let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => { SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path)) }, diff --git a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs index 0f6cd5de761f..545498a10478 100644 --- a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs +++ b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>( if same_item_push_visitor.should_lint(); if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push; let vec_ty = cx.typeck_results().expr_ty(vec); - let ty = vec_ty.walk().nth(1).unwrap().expect_ty(); + let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty(); if cx .tcx .lang_items() diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 91606ed3b2bb..9626cf79dc12 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -1987,10 +1987,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { // walk the return type and check for Self (this does not check associated types) if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(ret_ty, self_adt) { + if contains_adt_constructor(cx.tcx, ret_ty, self_adt) { return; } - } else if contains_ty(ret_ty, self_ty) { + } else if contains_ty(cx.tcx, ret_ty, self_ty) { return; } @@ -2001,10 +2001,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() { - if contains_adt_constructor(projection_predicate.ty, self_adt) { + if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) { return; } - } else if contains_ty(projection_predicate.ty, self_ty) { + } else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) { return; } } @@ -2053,7 +2053,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let TraitItemKind::Fn(_, _) = item.kind; let ret_ty = return_ty(cx, item.hir_id()); let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); - if !contains_ty(ret_ty, self_ty); + if !contains_ty(cx.tcx, ret_ty, self_ty); then { span_lint( diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index e153288aa58d..681baed8c369 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -288,7 +288,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> { .fn_sig(def_id) .output() .skip_binder() - .walk() + .walk(self.cx.tcx) .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))); } diff --git a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs index 4472edecbed8..4ba5e1a0f535 100644 --- a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs +++ b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs @@ -62,10 +62,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors { // Ensure method is constructor-like if let Some(self_adt) = self_ty.ty_adt_def() { - if !contains_adt_constructor(ret_ty, self_adt) { + if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) { return; } - } else if !contains_ty(ret_ty, self_ty) { + } else if !contains_ty(cx.tcx, ret_ty, self_ty) { return; } diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs index 6fc5707a4eef..97b1b2dae3c1 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_sort_by.rs @@ -218,7 +218,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) + matches!(ty.kind(), ty::Ref(..)) || ty.walk(cx.tcx).any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) } impl LateLintPass<'_> for UnnecessarySortBy { diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index a3601cca2eff..9ae50e47ca4c 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { // // See also https://github.com/rust-lang/rust-clippy/issues/2894. for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) { - if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) { + if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) { let mut visitor = SkipTyCollector::default(); visitor.visit_ty(impl_hir_ty); types_to_skip.extend(visitor.types_to_skip); diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 32a73984674a..98f3937ba3dd 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1627,7 +1627,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option return Some("slice".into()), rustc_ty::Array(..) => return Some("array".into()), rustc_ty::Tuple(..) => return Some("tuple".into()), @@ -1635,7 +1635,7 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option, body: &'a Body<'tcx>, msrv: Option<&Ru } fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { - for arg in ty.walk() { + for arg in ty.walk(tcx) { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index a2221a0b283b..3cd8ed5aa2c8 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -10,7 +10,7 @@ use rustc_hir::{TyKind, Unsafety}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, AdtDef, IntTy, Ty, TypeFoldable, UintTy}; +use rustc_middle::ty::{self, TyCtxt, AdtDef, IntTy, Ty, TypeFoldable, UintTy}; use rustc_span::sym; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::DUMMY_SP; @@ -36,8 +36,8 @@ pub fn can_partially_move_ty(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } /// Walks into `ty` and returns `true` if any inner type is the same as `other_ty` -pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { - ty.walk().any(|inner| match inner.unpack() { +pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool { + ty.walk(tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -45,8 +45,8 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool { /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. -pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool { - ty.walk().any(|inner| match inner.unpack() { +pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool { + ty.walk(tcx).any(|inner| match inner.unpack() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -209,7 +209,7 @@ fn is_normalizable_helper<'tcx>( .iter() .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache)) }), - _ => ty.walk().all(|generic_arg| match generic_arg.unpack() { + _ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() { GenericArgKind::Type(inner_ty) if inner_ty != ty => { is_normalizable_helper(cx, param_env, inner_ty, cache) }, From ab9108b70f25ecd9cce1ab756b82cb00de6c6927 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 17 Jul 2021 18:48:07 +0200 Subject: [PATCH 158/269] update `TypeFlags` to deal with missing ct substs --- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_lint/src/noop_method_call.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 10 +- compiler/rustc_middle/src/ty/consts/kind.rs | 6 + compiler/rustc_middle/src/ty/erase_regions.rs | 4 +- compiler/rustc_middle/src/ty/flags.rs | 18 ++- compiler/rustc_middle/src/ty/fold.rs | 103 ++++++++++++---- compiler/rustc_middle/src/ty/layout.rs | 6 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +- .../rustc_middle/src/ty/structural_impls.rs | 4 + compiler/rustc_middle/src/ty/sty.rs | 20 ++-- compiler/rustc_middle/src/ty/subst.rs | 6 +- .../borrow_check/type_check/liveness/trace.rs | 2 +- compiler/rustc_mir/src/interpret/util.rs | 24 ++-- .../src/monomorphize/polymorphize.rs | 8 +- compiler/rustc_mir/src/shim.rs | 24 +++- .../rustc_mir/src/transform/const_prop.rs | 11 +- .../rustc_mir/src/transform/inline/cycle.rs | 2 +- compiler/rustc_mir/src/transform/mod.rs | 6 +- .../rustc_mir/src/transform/promote_consts.rs | 1 + compiler/rustc_mir_build/src/build/mod.rs | 10 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 3 +- .../rustc_trait_selection/src/opaque_types.rs | 2 +- .../src/traits/coherence.rs | 2 +- .../src/traits/const_evaluatable.rs | 6 +- .../src/traits/fulfill.rs | 4 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/select/mod.rs | 12 +- compiler/rustc_type_ir/src/lib.rs | 112 +++++++++++------- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 8 +- compiler/rustc_typeck/src/check/wfcheck.rs | 12 +- compiler/rustc_typeck/src/check/writeback.rs | 2 +- compiler/rustc_typeck/src/collect/type_of.rs | 11 +- .../src/impl_wf_check/min_specialization.rs | 2 +- .../src/needless_pass_by_value.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- 44 files changed, 305 insertions(+), 166 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 8375d4c7ca56..2e8a96040172 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -499,7 +499,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { ty::Adt(def, ..) if !def.is_box() => { // Again, only create type information if full debuginfo is enabled if cx.sess().opts.debuginfo == DebugInfo::Full - && !impl_self_ty.needs_subst() + && !impl_self_ty.needs_subst(cx.tcx) { Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP)) } else { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 58ce31e0c4c9..673d348a2a89 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1398,7 +1398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"), LocalRef::Operand(None) => { let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst.as_ref())); - assert!(!dst_layout.ty.has_erasable_regions()); + assert!(!dst_layout.ty.has_erasable_regions(self.cx.tcx())); let place = PlaceRef::alloca(bx, dst_layout); place.storage_live(bx); self.codegen_transmute_into(bx, src, place); diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 3bbc481b6109..e2edd4482671 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -216,7 +216,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut allocate_local = |local| { let decl = &mir.local_decls[local]; let layout = bx.layout_of(fx.monomorphize(decl.ty)); - assert!(!layout.ty.has_erasable_regions()); + assert!(!layout.ty.has_erasable_regions(cx.tcx())); if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() { debug!("alloc: {:?} (return place) -> place", local); diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 448dd6623482..c6e150d114c5 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -470,7 +470,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { { let needs_canonical_flags = if canonicalize_region_mode.any() { TypeFlags::NEEDS_INFER | - TypeFlags::HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS` + TypeFlags::HAS_POTENTIAL_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_xxx_FREE_REGIONS` TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER } else { diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index 4af1bdf97a77..c40e409891bc 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -146,7 +146,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if !t.needs_infer() && !t.has_erasable_regions() { + if !t.needs_infer() && !t.has_erasable_regions(self.tcx()) { return t; } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index b4f11a8a0448..8f848f54aad6 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1656,7 +1656,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints { ConstEquate(..) | TypeWellFormedFromEnv(..) => continue, }; - if predicate.is_global() { + if predicate.is_global(cx.tcx) { cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| { lint.build(&format!( "{} bound {} does not depend on any type \ diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 479cc00199f6..908d847915f8 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { _ => return, }; let substs = cx.typeck_results().node_substs(expr.hir_id); - if substs.needs_subst() { + if substs.needs_subst(cx.tcx) { // We can't resolve on types that require monomorphization, so we don't handle them if // we need to perfom substitution. return; diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 00c2f0a0299a..6a7758bedfb8 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -242,6 +242,7 @@ pub struct Body<'tcx> { impl<'tcx> Body<'tcx> { pub fn new( + tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, basic_blocks: IndexVec>, source_scopes: IndexVec>, @@ -284,7 +285,7 @@ impl<'tcx> Body<'tcx> { predecessor_cache: PredecessorCache::new(), is_cyclic: GraphIsCyclicCache::new(), }; - body.is_polymorphic = body.has_param_types_or_consts(); + body.is_polymorphic = body.has_param_types_or_consts(tcx); body } @@ -293,7 +294,10 @@ impl<'tcx> Body<'tcx> { /// The returned MIR contains no `LocalDecl`s (even for the return place) or source scopes. It /// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different /// crate. - pub fn new_cfg_only(basic_blocks: IndexVec>) -> Self { + pub fn new_cfg_only( + tcx: TyCtxt<'tcx>, + basic_blocks: IndexVec>, + ) -> Self { let mut body = Body { phase: MirPhase::Build, source: MirSource::item(DefId::local(CRATE_DEF_INDEX)), @@ -311,7 +315,7 @@ impl<'tcx> Body<'tcx> { predecessor_cache: PredecessorCache::new(), is_cyclic: GraphIsCyclicCache::new(), }; - body.is_polymorphic = body.has_param_types_or_consts(); + body.is_polymorphic = body.has_param_types_or_consts(tcx); body } diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index ab2c57ac605b..174c35dbc718 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -12,6 +12,12 @@ use rustc_target::abi::Size; use super::ScalarInt; /// An unevaluated, potentially generic, constant. +/// +/// If `substs_` is `None` it means that this anon const +/// still has its default substs. +/// +/// We check for all possible substs in `fn default_anon_const_substs`, +/// so refer to that check for more info. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] #[derive(Hash, HashStable)] pub struct Unevaluated<'tcx> { diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs index 759d1a017aa2..63eb55ed1a62 100644 --- a/compiler/rustc_middle/src/ty/erase_regions.rs +++ b/compiler/rustc_middle/src/ty/erase_regions.rs @@ -21,7 +21,9 @@ impl<'tcx> TyCtxt<'tcx> { T: TypeFoldable<'tcx>, { // If there's nothing to erase avoid performing the query at all - if !value.has_type_flags(TypeFlags::HAS_RE_LATE_BOUND | TypeFlags::HAS_FREE_REGIONS) { + if !value + .has_type_flags(TypeFlags::HAS_RE_LATE_BOUND | TypeFlags::HAS_POTENTIAL_FREE_REGIONS) + { return value; } debug!("erase_regions({:?})", value); diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 89cba4aab836..41c2447cfc51 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -34,6 +34,12 @@ impl FlagComputation { result.flags } + pub fn for_unevaluated_const(uv: ty::Unevaluated<'_>) -> TypeFlags { + let mut result = FlagComputation::new(); + result.add_unevaluated_const(uv); + result.flags + } + fn add_flags(&mut self, flags: TypeFlags) { self.flags = self.flags | flags; } @@ -91,7 +97,7 @@ impl FlagComputation { &ty::Error(_) => self.add_flags(TypeFlags::HAS_ERROR), &ty::Param(_) => { - self.add_flags(TypeFlags::HAS_TY_PARAM); + self.add_flags(TypeFlags::HAS_KNOWN_TY_PARAM); self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } @@ -292,7 +298,7 @@ impl FlagComputation { self.add_bound_var(debruijn); } ty::ConstKind::Param(_) => { - self.add_flags(TypeFlags::HAS_CT_PARAM); + self.add_flags(TypeFlags::HAS_KNOWN_CT_PARAM); self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } ty::ConstKind::Placeholder(_) => { @@ -305,8 +311,12 @@ impl FlagComputation { } fn add_unevaluated_const(&mut self, ct: ty::Unevaluated<'tcx>) { - // TODO - self.add_substs(ct.substs_.unwrap()); + if let Some(substs) = ct.substs_ { + self.add_substs(substs); + } else { + self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); + self.add_flags(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS); + } self.add_flags(TypeFlags::HAS_CT_PROJECTION); } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 6e70e8ddaed8..0c5e292e6eb5 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -74,8 +74,14 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { self.has_vars_bound_at_or_above(ty::INNERMOST) } + fn definitely_has_type_flags(&self, tcx: TyCtxt<'tcx>, flags: TypeFlags) -> bool { + self.visit_with(&mut HasTypeFlagsVisitor { tcx: Some(tcx), flags }).break_value() + == Some(FoundFlags) + } + fn has_type_flags(&self, flags: TypeFlags) -> bool { - self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags) + self.visit_with(&mut HasTypeFlagsVisitor { tcx: None, flags }).break_value() + == Some(FoundFlags) } fn has_projections(&self) -> bool { self.has_type_flags(TypeFlags::HAS_PROJECTION) @@ -86,8 +92,18 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { fn references_error(&self) -> bool { self.has_type_flags(TypeFlags::HAS_ERROR) } - fn has_param_types_or_consts(&self) -> bool { - self.has_type_flags(TypeFlags::HAS_TY_PARAM | TypeFlags::HAS_CT_PARAM) + fn has_potential_param_types_or_consts(&self) -> bool { + self.has_type_flags( + TypeFlags::HAS_KNOWN_TY_PARAM + | TypeFlags::HAS_KNOWN_CT_PARAM + | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS, + ) + } + fn has_param_types_or_consts(&self, tcx: TyCtxt<'tcx>) -> bool { + self.definitely_has_type_flags( + tcx, + TypeFlags::HAS_KNOWN_TY_PARAM | TypeFlags::HAS_KNOWN_CT_PARAM, + ) } fn has_infer_regions(&self) -> bool { self.has_type_flags(TypeFlags::HAS_RE_INFER) @@ -108,13 +124,18 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { | TypeFlags::HAS_CT_PLACEHOLDER, ) } - fn needs_subst(&self) -> bool { - self.has_type_flags(TypeFlags::NEEDS_SUBST) + fn potentially_needs_subst(&self) -> bool { + self.has_type_flags( + TypeFlags::KNOWN_NEEDS_SUBST | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS, + ) + } + fn needs_subst(&self, tcx: TyCtxt<'tcx>) -> bool { + self.definitely_has_type_flags(tcx, TypeFlags::KNOWN_NEEDS_SUBST) } /// "Free" regions in this context means that it has any region /// that is not (a) erased or (b) late-bound. - fn has_free_regions(&self) -> bool { - self.has_type_flags(TypeFlags::HAS_FREE_REGIONS) + fn has_free_regions(&self, tcx: TyCtxt<'tcx>) -> bool { + self.definitely_has_type_flags(tcx, TypeFlags::HAS_KNOWN_FREE_REGIONS) } fn has_erased_regions(&self) -> bool { @@ -122,15 +143,25 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { } /// True if there are any un-erased free regions. - fn has_erasable_regions(&self) -> bool { - self.has_type_flags(TypeFlags::HAS_FREE_REGIONS) + fn has_erasable_regions(&self, tcx: TyCtxt<'tcx>) -> bool { + self.definitely_has_type_flags(tcx, TypeFlags::HAS_KNOWN_FREE_REGIONS) + } + + /// Indicates whether this value definitely references only 'global' + /// generic parameters that are the same regardless of what fn we are + /// in. This is used for caching. + /// + /// Note that this function is pessimistic and may incorrectly return + /// `false`. + fn is_known_global(&self) -> bool { + !self.has_type_flags(TypeFlags::HAS_POTENTIAL_FREE_LOCAL_NAMES) } /// Indicates whether this value references only 'global' /// generic parameters that are the same regardless of what fn we are /// in. This is used for caching. - fn is_global(&self) -> bool { - !self.has_type_flags(TypeFlags::HAS_FREE_LOCAL_NAMES) + fn is_global(&self, tcx: TyCtxt<'tcx>) -> bool { + !self.definitely_has_type_flags(tcx, TypeFlags::HAS_KNOWN_FREE_LOCAL_NAMES) } /// True if there are any late-bound regions @@ -217,6 +248,10 @@ pub trait TypeVisitor<'tcx>: Sized { c.super_visit_with(self) } + fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { + uv.super_visit_with(self) + } + fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow { p.super_visit_with(self) } @@ -369,7 +404,7 @@ impl<'tcx> TyCtxt<'tcx> { fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { // We're only interested in types involving regions - if ty.flags().intersects(TypeFlags::HAS_FREE_REGIONS) { + if ty.flags().intersects(TypeFlags::HAS_POTENTIAL_FREE_REGIONS) { ty.super_visit_with(self) } else { ControlFlow::CONTINUE @@ -1078,23 +1113,19 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { struct FoundFlags; // FIXME: Optimize for checking for infer flags -struct HasTypeFlagsVisitor { +struct HasTypeFlagsVisitor<'tcx> { + tcx: Option>, flags: ty::TypeFlags, } -impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { +impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { type BreakTy = FoundFlags; fn tcx_for_anon_const_substs(&self) -> Option> { - // TypeFlagsVisitor must not look into the default anon const substs - // as that would cause cycle errors, but we do care about them for - // some flags. - // - // We therefore have to be very careful here. - None + self.tcx } #[inline] - fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow { + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { debug!( "HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}", t, @@ -1103,6 +1134,11 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { ); if t.flags().intersects(self.flags) { ControlFlow::Break(FoundFlags) + } else if self.tcx.is_some() + && t.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + { + t.super_visit_with(self) } else { ControlFlow::CONTINUE } @@ -1125,6 +1161,26 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) + } else if self.tcx.is_some() + && flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + { + c.super_visit_with(self) + } else { + ControlFlow::CONTINUE + } + } + + fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { + let flags = FlagComputation::for_unevaluated_const(uv); + debug!("HasTypeFlagsVisitor: uv={:?} uv.flags={:?} self.flags={:?}", uv, flags, self.flags); + if flags.intersects(self.flags) { + ControlFlow::Break(FoundFlags) + } else if self.tcx.is_some() + && flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + { + uv.super_visit_with(self) } else { ControlFlow::CONTINUE } @@ -1138,6 +1194,11 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { ); if predicate.inner.flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) + } else if self.tcx.is_some() + && predicate.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + { + predicate.super_visit_with(self) } else { ControlFlow::CONTINUE } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 8f90c7a8845e..6761fbaf5365 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1727,7 +1727,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Ignore layouts that are done with non-empty environments or // non-monomorphic layouts, as the user only wants to see the stuff // resulting from the final codegen session. - if layout.ty.has_param_types_or_consts() || !self.param_env.caller_bounds().is_empty() { + if layout.ty.has_param_types_or_consts(self.tcx) + || !self.param_env.caller_bounds().is_empty() + { return; } @@ -1894,7 +1896,7 @@ impl<'tcx> SizeSkeleton<'tcx> { let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env); match tail.kind() { ty::Param(_) | ty::Projection(_) => { - debug_assert!(tail.has_param_types_or_consts()); + debug_assert!(tail.has_param_types_or_consts(tcx)); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) }) } _ => bug!( diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 62e093581b86..eccc1ebd8051 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1292,7 +1292,7 @@ impl<'tcx> ParamEnv<'tcx> { Reveal::UserFacing => ParamEnvAnd { param_env: self, value }, Reveal::All => { - if value.is_global() { + if value.is_known_global() { ParamEnvAnd { param_env: self.without_caller_bounds(), value } } else { ParamEnvAnd { param_env: self, value } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 132223630961..5c3da507e140 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1201,7 +1201,9 @@ pub trait PrettyPrinter<'tcx>: // // FIXME(eddyb) for `--emit=mir`/`-Z dump-mir`, we should provide the // correct `ty::ParamEnv` to allow printing *all* constant values. - (_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_param_types_or_consts() => { + (_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) + if !ty.has_potential_param_types_or_consts() => + { let contents = self.tcx().destructure_const( ty::ParamEnv::reveal_all() .and(self.tcx().mk_const(ty::Const { val: ty::ConstKind::Value(ct), ty })), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index fe7d46240cb8..369dfaf32a00 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1086,6 +1086,10 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { } } + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_unevaluated_const(*self) + } + fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { if let Some(tcx) = visitor.tcx_for_anon_const_substs() { self.substs(tcx).visit_with(visitor) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 8e0a2d4a28df..8b893b779c0a 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1565,26 +1565,26 @@ impl RegionKind { match *self { ty::ReVar(..) => { - flags = flags | TypeFlags::HAS_FREE_REGIONS; - flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_RE_INFER; } ty::RePlaceholder(..) => { - flags = flags | TypeFlags::HAS_FREE_REGIONS; - flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS; flags = flags | TypeFlags::HAS_RE_PLACEHOLDER; } ty::ReEarlyBound(..) => { - flags = flags | TypeFlags::HAS_FREE_REGIONS; - flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; - flags = flags | TypeFlags::HAS_RE_PARAM; + flags = flags | TypeFlags::HAS_KNOWN_FREE_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_RE_PARAM; } ty::ReFree { .. } => { - flags = flags | TypeFlags::HAS_FREE_REGIONS; - flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS; } ty::ReEmpty(_) | ty::ReStatic => { - flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_KNOWN_FREE_REGIONS; } ty::ReLateBound(..) => { flags = flags | TypeFlags::HAS_RE_LATE_BOUND; diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 84ec2e76c0b0..2438d1a16021 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -486,7 +486,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if !t.needs_subst() { + if !t.potentially_needs_subst() { return t; } @@ -497,10 +497,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> { - if !c.needs_subst() { - return c; - } - if let ty::ConstKind::Param(p) = c.val { self.const_for_param(p, c) } else { diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs b/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs index e411f1dc1088..566c11811e6e 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs @@ -171,7 +171,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> { for (local, location) in drop_used { if !live_locals.contains(&local) { let local_ty = self.cx.body.local_decls[local].ty; - if local_ty.has_free_regions() { + if local_ty.has_free_regions(self.cx.typeck.tcx()) { self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations); } } diff --git a/compiler/rustc_mir/src/interpret/util.rs b/compiler/rustc_mir/src/interpret/util.rs index b9d6e002e2db..37c13c2d42ae 100644 --- a/compiler/rustc_mir/src/interpret/util.rs +++ b/compiler/rustc_mir/src/interpret/util.rs @@ -9,7 +9,7 @@ where T: TypeFoldable<'tcx>, { debug!("ensure_monomorphic_enough: ty={:?}", ty); - if !ty.needs_subst() { + if !ty.potentially_needs_subst() { return Ok(()); } @@ -25,19 +25,8 @@ where Some(self.tcx) } - fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { - if !c.needs_subst() { - return ControlFlow::CONTINUE; - } - - match c.val { - ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam), - _ => c.super_visit_with(self), - } - } - fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - if !ty.needs_subst() { + if !ty.potentially_needs_subst() { return ControlFlow::CONTINUE; } @@ -54,7 +43,7 @@ where let is_used = unused_params.contains(index).map_or(true, |unused| !unused); // Only recurse when generic parameters in fns, closures and generators // are used and require substitution. - match (is_used, subst.needs_subst()) { + match (is_used, subst.needs_subst(self.tcx)) { // Just in case there are closures or generators within this subst, // recurse. (true, true) => return subst.super_visit_with(self), @@ -77,6 +66,13 @@ where _ => ty.super_visit_with(self), } } + + fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { + match c.val { + ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam), + _ => c.super_visit_with(self), + } + } } let mut vis = UsedParamsNeedSubstVisitor { tcx }; diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index b086053a0c10..368ac70b5520 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -288,7 +288,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { } #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { - if !c.has_param_types_or_consts() { + if !c.has_potential_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -321,7 +321,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - if !ty.has_param_types_or_consts() { + if !ty.has_potential_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -363,7 +363,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { - if !c.has_param_types_or_consts() { + if !c.has_potential_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -381,7 +381,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - if !ty.has_param_types_or_consts() { + if !ty.has_potential_param_types_or_consts() { return ControlFlow::CONTINUE; } diff --git a/compiler/rustc_mir/src/shim.rs b/compiler/rustc_mir/src/shim.rs index 8c3d828894c8..8083ec954478 100644 --- a/compiler/rustc_mir/src/shim.rs +++ b/compiler/rustc_mir/src/shim.rs @@ -163,7 +163,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) let source = MirSource::from_instance(ty::InstanceDef::DropGlue(def_id, ty)); let mut body = - new_body(source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); + new_body(tcx, source, blocks, local_decls_for_sig(&sig, span), sig.inputs().len(), span); if ty.is_some() { // The first argument (index 0), but add 1 for the return value. @@ -202,6 +202,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) } fn new_body<'tcx>( + tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, basic_blocks: IndexVec>, local_decls: IndexVec>, @@ -209,6 +210,7 @@ fn new_body<'tcx>( span: Span, ) -> Body<'tcx> { Body::new( + tcx, source, basic_blocks, IndexVec::from_elem_n( @@ -353,7 +355,14 @@ impl CloneShimBuilder<'tcx> { self.def_id, self.sig.inputs_and_output[0], )); - new_body(source, self.blocks, self.local_decls, self.sig.inputs().len(), self.span) + new_body( + self.tcx, + source, + self.blocks, + self.local_decls, + self.sig.inputs().len(), + self.span, + ) } fn source_info(&self) -> SourceInfo { @@ -851,8 +860,14 @@ fn build_call_shim<'tcx>( block(&mut blocks, vec![], TerminatorKind::Resume, true); } - let mut body = - new_body(MirSource::from_instance(instance), blocks, local_decls, sig.inputs().len(), span); + let mut body = new_body( + tcx, + MirSource::from_instance(instance), + blocks, + local_decls, + sig.inputs().len(), + span, + ); if let Abi::RustCall = sig.abi { body.spread_arg = Some(Local::new(sig.inputs().len())); @@ -917,6 +932,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { let source = MirSource::item(ctor_id); let body = new_body( + tcx, source, IndexVec::from_elem_n(start_block, 1), local_decls, diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 98581f76821b..0d58625633f0 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -120,7 +120,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp { .predicates_of(def_id.to_def_id()) .predicates .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); + .filter_map(|(p, _)| if p.is_global(tcx) { Some(*p) } else { None }); if traits::impossible_predicates( tcx, traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(), @@ -132,6 +132,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp { trace!("ConstProp starting for {:?}", def_id); let dummy_body = &Body::new( + tcx, body.source, body.basic_blocks().clone(), body.source_scopes.clone(), @@ -468,7 +469,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { /// Returns the value, if any, of evaluating `c`. fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option> { // FIXME we need to revisit this for #67176 - if c.needs_subst() { + if c.needs_subst(self.tcx) { return None; } @@ -488,9 +489,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { }) => true, // Out of backwards compatibility we cannot report hard errors in unused // generic functions using associated constants of the generic parameters. - _ => c.literal.needs_subst(), + _ => c.literal.needs_subst(*tcx), }, - ConstantKind::Val(_, ty) => ty.needs_subst(), + ConstantKind::Val(_, ty) => ty.needs_subst(*tcx), }; if lint_only { // Out of backwards compatibility we cannot report hard errors in unused @@ -720,7 +721,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } // FIXME we need to revisit this for #67176 - if rvalue.needs_subst() { + if rvalue.needs_subst(self.tcx) { return None; } diff --git a/compiler/rustc_mir/src/transform/inline/cycle.rs b/compiler/rustc_mir/src/transform/inline/cycle.rs index c9eafafff57c..46628b928de9 100644 --- a/compiler/rustc_mir/src/transform/inline/cycle.rs +++ b/compiler/rustc_mir/src/transform/inline/cycle.rs @@ -89,7 +89,7 @@ crate fn mir_callgraph_reachable( // FIXME: A not fully substituted drop shim can cause ICEs if one attempts to // have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this // needs some more analysis. - if callee.needs_subst() { + if callee.needs_subst(tcx) { continue; } } diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index fa648a6dd49f..d4c2456e9a43 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -400,7 +400,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) - } } - debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE"); + debug_assert!(!body.has_free_regions(tcx), "Free regions in MIR for CTFE"); body } @@ -594,7 +594,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did)).steal(); run_optimization_passes(tcx, &mut body); - debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR"); + debug_assert!(!body.has_free_regions(tcx), "Free regions in optimized MIR"); body } @@ -621,7 +621,7 @@ fn promoted_mir<'tcx>( run_post_borrowck_cleanup_passes(tcx, body); } - debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR"); + debug_assert!(!promoted.has_free_regions(tcx), "Free regions in promoted MIR"); tcx.arena.alloc(promoted) } diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs index 14c9b3b0d479..1b43670ba3ac 100644 --- a/compiler/rustc_mir/src/transform/promote_consts.rs +++ b/compiler/rustc_mir/src/transform/promote_consts.rs @@ -992,6 +992,7 @@ pub fn promote_candidates<'tcx>( scope.parent_scope = None; let promoted = Body::new( + tcx, body.source, // `promoted` gets filled in below IndexVec::new(), IndexVec::from_elem_n(scope, 1), diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index bfebe860971e..0a760a740dca 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -239,10 +239,10 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_ // The exception is `body.user_type_annotations`, which is used unmodified // by borrow checking. debug_assert!( - !(body.local_decls.has_free_regions() - || body.basic_blocks().has_free_regions() - || body.var_debug_info.has_free_regions() - || body.yield_ty().has_free_regions()), + !(body.local_decls.has_free_regions(tcx) + || body.basic_blocks().has_free_regions(tcx) + || body.var_debug_info.has_free_regions(tcx) + || body.yield_ty().has_free_regions(tcx)), "Unexpected free regions in MIR: {:?}", body, ); @@ -755,6 +755,7 @@ fn construct_error<'a, 'tcx>( cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable); let mut body = Body::new( + tcx, MirSource::item(def.did.to_def_id()), cfg.basic_blocks, source_scopes, @@ -843,6 +844,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } Body::new( + self.tcx, MirSource::item(self.def_id), self.cfg.basic_blocks, self.source_scopes, diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 1b4e6b4e3817..267e2d8808fb 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -109,7 +109,7 @@ fn get_symbol_hash<'tcx>( // Include the main item-type. Note that, in this case, the // assertions about `needs_subst` may not hold, but this item-type // ought to be the same for every reference anyway. - assert!(!item_type.has_erasable_regions()); + assert!(!item_type.has_erasable_regions(tcx)); hcx.while_hashing_spans(false, |hcx| { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { item_type.hash_stable(hcx, &mut hasher); diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index c4c1ec8ce4e0..3ac9d1e5745f 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -277,7 +277,8 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { // Encode impl generic params if the substitutions contain parameters (implying // polymorphization is enabled) and this isn't an inherent impl. - if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_param_types_or_consts()) { + if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_param_types_or_consts(self.tcx)) + { self = self.path_generic_args( |this| { this.path_append_ns( diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index f89ca0fed036..b743c809ca24 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -583,7 +583,7 @@ where fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { // We're only interested in types involving regions - if !ty.flags().intersects(ty::TypeFlags::HAS_FREE_REGIONS) { + if !ty.flags().intersects(ty::TypeFlags::HAS_POTENTIAL_FREE_REGIONS) { return ControlFlow::CONTINUE; } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 9bb4af16a8f5..6ab079ad404d 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -391,7 +391,7 @@ fn orphan_check_trait_ref<'tcx>( ) -> Result<(), OrphanCheckErr<'tcx>> { debug!("orphan_check_trait_ref(trait_ref={:?}, in_crate={:?})", trait_ref, in_crate); - if trait_ref.needs_infer() && trait_ref.needs_subst() { + if trait_ref.needs_infer() && trait_ref.needs_subst(tcx) { bug!( "can't orphan check a trait ref with both params and inference variables {:?}", trait_ref diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 2f1e7e9d509b..2cc74ca2abb4 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -91,7 +91,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( let leaf = leaf.subst(tcx, ct.substs); if leaf.has_infer_types_or_consts() { failure_kind = FailureKind::MentionsInfer; - } else if leaf.has_param_types_or_consts() { + } else if leaf.has_param_types_or_consts(tcx) { failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam); } @@ -101,7 +101,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( let ty = ty.subst(tcx, ct.substs); if ty.has_infer_types_or_consts() { failure_kind = FailureKind::MentionsInfer; - } else if ty.has_param_types_or_consts() { + } else if ty.has_param_types_or_consts(tcx) { failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam); } @@ -158,7 +158,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( let concrete = infcx.const_eval_resolve(param_env, ty::Unevaluated::new(def, substs), Some(span)); - if concrete.is_ok() && substs.has_param_types_or_consts() { + if concrete.is_ok() && substs.has_param_types_or_consts(infcx.tcx) { match infcx.tcx.def_kind(def.did) { DefKind::AnonConst => { let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(def); diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 110d83cbe28b..edf2274ab54f 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -669,7 +669,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { stalled_on: &mut Vec>, ) -> ProcessResult, FulfillmentErrorCode<'tcx>> { let infcx = self.selcx.infcx(); - if obligation.predicate.is_global() { + if obligation.predicate.is_known_global() { // no type variables present, can use evaluation for better caching. // FIXME: consider caching errors too. // @@ -728,7 +728,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { ) -> ProcessResult, FulfillmentErrorCode<'tcx>> { let tcx = self.selcx.tcx(); - if obligation.predicate.is_global() { + if obligation.predicate.is_global(tcx) { // no type variables present, can use evaluation for better caching. // FIXME: consider caching errors too. // diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 477d29f1a4fb..43ee1c3304ab 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -450,7 +450,7 @@ fn subst_and_check_impossible_predicates<'tcx>( debug!("subst_and_check_impossible_predicates(key={:?})", key); let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates; - predicates.retain(|predicate| !predicate.needs_subst()); + predicates.retain(|predicate| !predicate.needs_subst(tcx)); let result = impossible_predicates(tcx, predicates); debug!("subst_and_check_impossible_predicates(key={:?}) = {:?}", key, result); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index c150b2222662..1c4e7e6c5898 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -544,7 +544,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }, ty::PredicateKind::TypeOutlives(pred) => { - if pred.0.is_global() { + if pred.0.is_known_global() { Ok(EvaluatedToOk) } else { Ok(EvaluatedToOkModuloRegions) @@ -692,8 +692,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?obligation, "evaluate_trait_predicate_recursively"); if !self.intercrate - && obligation.is_global() - && obligation.param_env.caller_bounds().iter().all(|bound| bound.needs_subst()) + && obligation.is_global(self.tcx()) + && obligation + .param_env + .caller_bounds() + .iter() + .all(|bound| bound.needs_subst(self.tcx())) { // If a param env has no global bounds, global obligations do not // depend on its particular value in order to work, so we can clear @@ -1452,7 +1456,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // the param_env so that it can be given the lowest priority. See // #50825 for the motivation for this. let is_global = - |cand: &ty::PolyTraitRef<'_>| cand.is_global() && !cand.has_late_bound_regions(); + |cand: &ty::PolyTraitRef<'_>| cand.is_known_global() && !cand.has_late_bound_regions(); // (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`, // and `DiscriminantKindCandidate` to anything else. diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 2d102127dd9d..c405bbe2d1f5 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -19,94 +19,116 @@ bitflags! { // Does this have parameters? Used to determine whether substitution is // required. /// Does this have `Param`? - const HAS_TY_PARAM = 1 << 0; + const HAS_KNOWN_TY_PARAM = 1 << 0; /// Does this have `ReEarlyBound`? - const HAS_RE_PARAM = 1 << 1; + const HAS_KNOWN_RE_PARAM = 1 << 1; /// Does this have `ConstKind::Param`? - const HAS_CT_PARAM = 1 << 2; + const HAS_KNOWN_CT_PARAM = 1 << 2; - const NEEDS_SUBST = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_RE_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits; + const KNOWN_NEEDS_SUBST = TypeFlags::HAS_KNOWN_TY_PARAM.bits + | TypeFlags::HAS_KNOWN_RE_PARAM.bits + | TypeFlags::HAS_KNOWN_CT_PARAM.bits; /// Does this have `Infer`? - const HAS_TY_INFER = 1 << 3; + const HAS_TY_INFER = 1 << 3; /// Does this have `ReVar`? - const HAS_RE_INFER = 1 << 4; + const HAS_RE_INFER = 1 << 4; /// Does this have `ConstKind::Infer`? - const HAS_CT_INFER = 1 << 5; + const HAS_CT_INFER = 1 << 5; /// Does this have inference variables? Used to determine whether /// inference is required. - const NEEDS_INFER = TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_RE_INFER.bits - | TypeFlags::HAS_CT_INFER.bits; + const NEEDS_INFER = TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_RE_INFER.bits + | TypeFlags::HAS_CT_INFER.bits; /// Does this have `Placeholder`? - const HAS_TY_PLACEHOLDER = 1 << 6; + const HAS_TY_PLACEHOLDER = 1 << 6; /// Does this have `RePlaceholder`? - const HAS_RE_PLACEHOLDER = 1 << 7; + const HAS_RE_PLACEHOLDER = 1 << 7; /// Does this have `ConstKind::Placeholder`? - const HAS_CT_PLACEHOLDER = 1 << 8; + const HAS_CT_PLACEHOLDER = 1 << 8; /// `true` if there are "names" of regions and so forth /// that are local to a particular fn/inferctxt - const HAS_FREE_LOCAL_REGIONS = 1 << 9; + const HAS_KNOWN_FREE_LOCAL_REGIONS = 1 << 9; /// `true` if there are "names" of types and regions and so forth /// that are local to a particular fn - const HAS_FREE_LOCAL_NAMES = TypeFlags::HAS_TY_PARAM.bits - | TypeFlags::HAS_CT_PARAM.bits - | TypeFlags::HAS_TY_INFER.bits - | TypeFlags::HAS_CT_INFER.bits - | TypeFlags::HAS_TY_PLACEHOLDER.bits - | TypeFlags::HAS_CT_PLACEHOLDER.bits - // We consider 'freshened' types and constants - // to depend on a particular fn. - // The freshening process throws away information, - // which can make things unsuitable for use in a global - // cache. Note that there is no 'fresh lifetime' flag - - // freshening replaces all lifetimes with `ReErased`, - // which is different from how types/const are freshened. - | TypeFlags::HAS_TY_FRESH.bits - | TypeFlags::HAS_CT_FRESH.bits - | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits; + const HAS_KNOWN_FREE_LOCAL_NAMES = TypeFlags::HAS_KNOWN_TY_PARAM.bits + | TypeFlags::HAS_KNOWN_CT_PARAM.bits + | TypeFlags::HAS_TY_INFER.bits + | TypeFlags::HAS_CT_INFER.bits + | TypeFlags::HAS_TY_PLACEHOLDER.bits + | TypeFlags::HAS_CT_PLACEHOLDER.bits + // We consider 'freshened' types and constants + // to depend on a particular fn. + // The freshening process throws away information, + // which can make things unsuitable for use in a global + // cache. Note that there is no 'fresh lifetime' flag - + // freshening replaces all lifetimes with `ReErased`, + // which is different from how types/const are freshened. + | TypeFlags::HAS_TY_FRESH.bits + | TypeFlags::HAS_CT_FRESH.bits + | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS.bits; + + const HAS_POTENTIAL_FREE_LOCAL_NAMES = TypeFlags::HAS_KNOWN_FREE_LOCAL_NAMES.bits + | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS.bits; /// Does this have `Projection`? - const HAS_TY_PROJECTION = 1 << 10; + const HAS_TY_PROJECTION = 1 << 10; /// Does this have `Opaque`? - const HAS_TY_OPAQUE = 1 << 11; + const HAS_TY_OPAQUE = 1 << 11; /// Does this have `ConstKind::Unevaluated`? - const HAS_CT_PROJECTION = 1 << 12; + const HAS_CT_PROJECTION = 1 << 12; /// Could this type be normalized further? - const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits - | TypeFlags::HAS_TY_OPAQUE.bits - | TypeFlags::HAS_CT_PROJECTION.bits; + const HAS_PROJECTION = TypeFlags::HAS_TY_PROJECTION.bits + | TypeFlags::HAS_TY_OPAQUE.bits + | TypeFlags::HAS_CT_PROJECTION.bits; /// Is an error type/const reachable? - const HAS_ERROR = 1 << 13; + const HAS_ERROR = 1 << 13; /// Does this have any region that "appears free" in the type? /// Basically anything but `ReLateBound` and `ReErased`. - const HAS_FREE_REGIONS = 1 << 14; + const HAS_KNOWN_FREE_REGIONS = 1 << 14; + + const HAS_POTENTIAL_FREE_REGIONS = TypeFlags::HAS_KNOWN_FREE_REGIONS.bits + | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS.bits; /// Does this have any `ReLateBound` regions? Used to check /// if a global bound is safe to evaluate. - const HAS_RE_LATE_BOUND = 1 << 15; + const HAS_RE_LATE_BOUND = 1 << 15; /// Does this have any `ReErased` regions? - const HAS_RE_ERASED = 1 << 16; + const HAS_RE_ERASED = 1 << 16; /// Does this value have parameters/placeholders/inference variables which could be /// replaced later, in a way that would change the results of `impl` specialization? - const STILL_FURTHER_SPECIALIZABLE = 1 << 17; + /// + /// Note that this flag being set is not a guarantee, as it is also + /// set if there are any anon consts with unknown default substs. + const STILL_FURTHER_SPECIALIZABLE = 1 << 17; /// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`? - const HAS_TY_FRESH = 1 << 18; + const HAS_TY_FRESH = 1 << 18; /// Does this value have `InferConst::Fresh`? - const HAS_CT_FRESH = 1 << 19; + const HAS_CT_FRESH = 1 << 19; + + /// Does this value have unknown default anon const substs. + /// + /// For more details refer to... + /// FIXME(@lcnr): ask me for now, still have to write all of this. + const HAS_UNKNOWN_DEFAULT_CONST_SUBSTS = 1 << 20; + /// Flags which can be influenced by default anon const substs. + const MAY_NEED_DEFAULT_CONST_SUBSTS = TypeFlags::HAS_KNOWN_RE_PARAM.bits + | TypeFlags::HAS_KNOWN_TY_PARAM.bits + | TypeFlags::HAS_KNOWN_CT_PARAM.bits + | TypeFlags::HAS_KNOWN_FREE_LOCAL_REGIONS.bits + | TypeFlags::HAS_KNOWN_FREE_REGIONS.bits; + } } diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 2879b7fcd911..bbfceeeff483 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2204,7 +2204,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.prohibit_generics(path.segments); // Try to evaluate any array length constants. let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id)); - if forbid_generic && normalized_ty.needs_subst() { + if forbid_generic && normalized_ty.needs_subst(tcx) { let mut err = tcx.sess.struct_span_err( path.span, "generic `Self` types are currently not permitted in anonymous constants", diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 15fa696b6c44..25d1c8706e87 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -239,7 +239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tag(), ); - if Self::can_contain_user_lifetime_bounds((substs, user_self_ty)) { + if self.can_contain_user_lifetime_bounds((substs, user_self_ty)) { let canonicalized = self.infcx.canonicalize_user_type_annotation(UserType::TypeOf( def_id, UserSubsts { substs, user_self_ty }, @@ -481,7 +481,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.to_ty(ast_ty); debug!("to_ty_saving_user_provided_ty: ty={:?}", ty); - if Self::can_contain_user_lifetime_bounds(ty) { + if self.can_contain_user_lifetime_bounds(ty) { let c_ty = self.infcx.canonicalize_response(UserType::Ty(ty)); debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty); self.typeck_results.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty); @@ -526,11 +526,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // reader, although I have my doubts). Also pass in types with inference // types, because they may be repeated. Other sorts of things are already // sufficiently enforced with erased regions. =) - fn can_contain_user_lifetime_bounds(t: T) -> bool + fn can_contain_user_lifetime_bounds(&self, t: T) -> bool where T: TypeFoldable<'tcx>, { - t.has_free_regions() || t.has_projections() || t.has_infer_types() + t.has_free_regions(self.tcx) || t.has_projections() || t.has_infer_types() } pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 0d121b9da876..057a15a43586 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -746,7 +746,7 @@ fn check_where_clauses<'tcx, 'fcx>( // Ignore dependent defaults -- that is, where the default of one type // parameter includes another (e.g., ``). In those cases, we can't // be sure if it will error or not as user might always specify the other. - if !ty.needs_subst() { + if !ty.needs_subst(tcx) { fcx.register_wf_obligation( ty.into(), tcx.def_span(param.def_id), @@ -762,7 +762,7 @@ fn check_where_clauses<'tcx, 'fcx>( // for `struct Foo` // we should eagerly error. let default_ct = tcx.const_param_default(param.def_id); - if !default_ct.needs_subst() { + if !default_ct.needs_subst(tcx) { fcx.register_wf_obligation( default_ct.into(), tcx.def_span(param.def_id), @@ -796,7 +796,7 @@ fn check_where_clauses<'tcx, 'fcx>( if is_our_default(param) { let default_ty = tcx.type_of(param.def_id); // ... and it's not a dependent default, ... - if !default_ty.needs_subst() { + if !default_ty.needs_subst(tcx) { // ... then substitute it with the default. return default_ty.into(); } @@ -809,7 +809,7 @@ fn check_where_clauses<'tcx, 'fcx>( if is_our_default(param) { let default_ct = tcx.const_param_default(param.def_id); // ... and it's not a dependent default, ... - if !default_ct.needs_subst() { + if !default_ct.needs_subst(tcx) { // ... then substitute it with the default. return default_ct.into(); } @@ -858,7 +858,7 @@ fn check_where_clauses<'tcx, 'fcx>( let substituted_pred = pred.subst(tcx, substs); // Don't check non-defaulted params, dependent defaults (including lifetimes) // or preds with multiple params. - if substituted_pred.has_param_types_or_consts() + if substituted_pred.has_param_types_or_consts(tcx) || param_count.params.len() > 1 || has_region { @@ -1380,7 +1380,7 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, span: Span, id: hir::HirId) { for obligation in implied_obligations { let pred = obligation.predicate; // Match the existing behavior. - if pred.is_global() && !pred.has_late_bound_regions() { + if pred.is_global(fcx.tcx) && !pred.has_late_bound_regions() { let pred = fcx.normalize_associated_types_in(span, pred); let obligation = traits::Obligation::new( traits::ObligationCause::new(span, id, traits::TrivialBound), diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 2e59defdb7ba..c57ec9ef78f6 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -130,7 +130,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) { debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty); - assert!(!ty.needs_infer() && !ty.has_placeholders() && !ty.has_free_regions()); + assert!(!ty.needs_infer() && !ty.has_placeholders() && !ty.has_free_regions(self.tcx())); self.typeck_results.node_types_mut().insert(hir_id, ty); } diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 98f5f73b7bec..9b10874b8bcf 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -275,7 +275,16 @@ fn get_path_containing_arg_in_pat<'hir>( } pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { - InternalSubsts::identity_for_item(tcx, def_id) + let substs = InternalSubsts::identity_for_item(tcx, def_id); + // We only expect substs with the following type flags as default substs. + // + // Getting this wrong can lead to ICE and unsoundness, so we assert it here. + for arg in substs.iter().flat_map(|s| s.walk(tcx)) { + let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS + | ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE; + assert!(!arg.has_type_flags(!allowed_flags)); + } + substs } pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 2d71c87bee77..d3e4be128a8d 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -363,7 +363,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc match predicate.kind().skip_binder() { // Global predicates are either always true or always false, so we // are fine to specialize on. - _ if predicate.is_global() => (), + _ if predicate.is_global(tcx) => (), // We allow specializing on explicitly marked traits with no associated // items. ty::PredicateKind::Trait(ty::TraitPredicate { diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 5e559991c169..90b2aa168962 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter()) - .filter(|p| !p.is_global()) + .filter(|p| !p.is_global(cx.tcx)) .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 98f3937ba3dd..ddff1686ba2c 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1581,7 +1581,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { .predicates_of(did) .predicates .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); + .filter_map(|(p, _)| if p.is_global(cx.tcx) { Some(*p) } else { None }); traits::impossible_predicates( cx.tcx, traits::elaborate_predicates(cx.tcx, predicates) From 2140016d6c7239fe02c87c5ac421c0df4b880e15 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 12:13:25 +0200 Subject: [PATCH 159/269] don't just compare `ty::Const` --- compiler/rustc_infer/src/infer/combine.rs | 2 + compiler/rustc_middle/src/ty/fold.rs | 40 +++++++++++++++++++ .../rustc_middle/src/ty/structural_impls.rs | 4 ++ 3 files changed, 46 insertions(+) diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 4fb3d4bdfe1c..32308910aa7d 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -129,6 +129,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { where R: ConstEquateRelation<'tcx>, { + let a = self.tcx.expose_default_const_substs(a); + let b = self.tcx.expose_default_const_substs(b); debug!("{}.consts({:?}, {:?})", relation.tag(), a, b); if a == b { return Ok(a); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 0c5e292e6eb5..b249dc8d6f92 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -213,6 +213,10 @@ pub trait TypeFolder<'tcx>: Sized { c.super_fold_with(self) } + fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> { + p.super_fold_with(self) + } + fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> { bug!("most type folders should not be folding MIR datastructures: {:?}", c) } @@ -1205,6 +1209,42 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { } } +impl<'tcx> TyCtxt<'tcx> { + /// This is a HACK(const_generics) and should probably not be needed. + /// Might however be perf relevant, so who knows. + /// + /// FIXME(@lcnr): explain this function a bit more + pub fn expose_default_const_substs>(self, v: T) -> T { + v.fold_with(&mut ExposeDefaultConstSubstsFolder { tcx: self }) + } +} + +struct ExposeDefaultConstSubstsFolder<'tcx> { + tcx: TyCtxt<'tcx>, +} + +impl<'tcx> TypeFolder<'tcx> for ExposeDefaultConstSubstsFolder<'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { + if ty.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + ty.super_fold_with(self) + } else { + ty + } + } + + fn fold_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> { + if pred.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + pred.super_fold_with(self) + } else { + pred + } + } +} + /// Collects all the late-bound regions at the innermost binding level /// into a hash set. struct LateBoundRegionsCollector<'tcx> { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 369dfaf32a00..dcdea8025fa9 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -974,6 +974,10 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { + fn fold_with>(self, folder: &mut F) -> Self { + folder.fold_predicate(self) + } + fn super_fold_with>(self, folder: &mut F) -> Self { let new = self.inner.kind.fold_with(folder); folder.tcx().reuse_or_mk_predicate(self, new) From 031243898eaa138056ea7248fb37324ffaa561e1 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 13:03:29 +0200 Subject: [PATCH 160/269] check for cycles in `default_anon_const_substs` --- compiler/rustc_typeck/src/collect/type_of.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 9b10874b8bcf..2f0a5eb79bc1 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -275,6 +275,11 @@ fn get_path_containing_arg_in_pat<'hir>( } pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { + let generics = tcx.generics_of(def_id); + if let Some(parent) = generics.parent { + let _cycle_check = tcx.predicates_of(parent); + } + let substs = InternalSubsts::identity_for_item(tcx, def_id); // We only expect substs with the following type flags as default substs. // From caa975c89e343cb7e51f77c2710c8460ada50532 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 13:52:43 +0200 Subject: [PATCH 161/269] use `ty::Unevaluated` instead of def substs pair --- compiler/rustc_infer/src/infer/mod.rs | 5 +- compiler/rustc_middle/src/query/mod.rs | 5 +- compiler/rustc_middle/src/ty/consts/kind.rs | 2 +- compiler/rustc_middle/src/ty/flags.rs | 4 +- compiler/rustc_middle/src/ty/mod.rs | 4 +- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +- compiler/rustc_middle/src/ty/relate.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 8 +-- compiler/rustc_privacy/src/lib.rs | 4 +- compiler/rustc_query_impl/src/keys.rs | 11 ++-- .../src/traits/const_evaluatable.rs | 53 ++++++++----------- .../src/traits/error_reporting/mod.rs | 4 +- .../src/traits/fulfill.rs | 9 ++-- .../src/traits/object_safety.rs | 4 +- .../src/traits/select/mod.rs | 5 +- .../rustc_trait_selection/src/traits/wf.rs | 11 ++-- compiler/rustc_typeck/src/check/dropck.rs | 6 +-- compiler/rustc_typeck/src/check/wfcheck.rs | 4 +- compiler/rustc_typeck/src/collect.rs | 7 +-- 19 files changed, 66 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 155abf4ef83d..7f890829e68e 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -678,10 +678,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { a: ty::Unevaluated<'tcx>, b: ty::Unevaluated<'tcx>, ) -> bool { - let canonical = self.canonicalize_query( - ((a.def, a.substs(self.tcx)), (b.def, b.substs(self.tcx))), - &mut OriginalQueryValues::default(), - ); + let canonical = self.canonicalize_query((a, b), &mut OriginalQueryValues::default()); debug!("canonical consts: {:?}", &canonical.value); self.tcx.try_unify_abstract_consts(canonical.value) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 737b1108f50a..9b3de6710ec0 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -303,12 +303,11 @@ rustc_queries! { } query try_unify_abstract_consts(key: ( - (ty::WithOptConstParam, SubstsRef<'tcx>), - (ty::WithOptConstParam, SubstsRef<'tcx>) + ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx> )) -> bool { desc { |tcx| "trying to unify the generic constants {} and {}", - tcx.def_path_str(key.0.0.did), tcx.def_path_str(key.1.0.did) + tcx.def_path_str(key.0.def.did), tcx.def_path_str(key.1.def.did) } } diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index 174c35dbc718..b1f6a6127766 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -18,7 +18,7 @@ use super::ScalarInt; /// /// We check for all possible substs in `fn default_anon_const_substs`, /// so refer to that check for more info. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)] #[derive(Hash, HashStable)] pub struct Unevaluated<'tcx> { pub def: ty::WithOptConstParam, diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 41c2447cfc51..1c4f24cdf394 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -252,8 +252,8 @@ impl FlagComputation { ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => { self.add_substs(substs); } - ty::PredicateKind::ConstEvaluatable(_def_id, substs) => { - self.add_substs(substs); + ty::PredicateKind::ConstEvaluatable(uv) => { + self.add_unevaluated_const(uv); } ty::PredicateKind::ConstEquate(expected, found) => { self.add_const(expected); diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index eccc1ebd8051..b1ebe43c491d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -406,7 +406,7 @@ crate struct PredicateInner<'tcx> { } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(PredicateInner<'_>, 48); +static_assert_size!(PredicateInner<'_>, 56); #[derive(Clone, Copy, Lift)] pub struct Predicate<'tcx> { @@ -502,7 +502,7 @@ pub enum PredicateKind<'tcx> { Coerce(CoercePredicate<'tcx>), /// Constant initializer must evaluate successfully. - ConstEvaluatable(ty::WithOptConstParam, SubstsRef<'tcx>), + ConstEvaluatable(ty::Unevaluated<'tcx>), /// Constants must be equal. The first component is the const that is expected. ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>), diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 5c3da507e140..230a39e639fb 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2294,8 +2294,8 @@ define_print_and_forward_display! { print_value_path(closure_def_id, &[]), write("` implements the trait `{}`", kind)) } - ty::PredicateKind::ConstEvaluatable(def, substs) => { - p!("the constant `", print_value_path(def.did, substs), "` can be evaluated") + ty::PredicateKind::ConstEvaluatable(uv) => { + p!("the constant `", print_value_path(uv.def.did, uv.substs_.map_or(&[], |x| x)), "` can be evaluated") } ty::PredicateKind::ConstEquate(c1, c2) => { p!("the constant `", print(c1), "` equals `", print(c2), "`") diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c978e1de38de..b64d507e0b89 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -579,7 +579,7 @@ pub fn super_relate_consts>( (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if tcx.features().const_evaluatable_checked => { - tcx.try_unify_abstract_consts(((au.def, au.substs(tcx)), (bu.def, bu.substs(tcx)))) + tcx.try_unify_abstract_consts((au, bu)) } // While this is slightly incorrect, it shouldn't matter for `min_const_generics` diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index dcdea8025fa9..31088423efa3 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -190,8 +190,8 @@ impl fmt::Debug for ty::PredicateKind<'tcx> { ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind) } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { - write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) + ty::PredicateKind::ConstEvaluatable(uv) => { + write!(f, "ConstEvaluatable({:?}, {:?})", uv.def, uv.substs_) } ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), ty::PredicateKind::TypeWellFormedFromEnv(ty) => { @@ -447,8 +447,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { ty::PredicateKind::ObjectSafe(trait_def_id) => { Some(ty::PredicateKind::ObjectSafe(trait_def_id)) } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { - tcx.lift(substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs)) + ty::PredicateKind::ConstEvaluatable(uv) => { + tcx.lift(uv).map(|uv| ty::PredicateKind::ConstEvaluatable(uv)) } ty::PredicateKind::ConstEquate(c1, c2) => { tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2)) diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index fb223d8fa751..6fe68a0c17a5 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -134,11 +134,11 @@ where ty.visit_with(self) } ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE, - ty::PredicateKind::ConstEvaluatable(defs, substs) + ty::PredicateKind::ConstEvaluatable(uv) if self.def_id_visitor.tcx().features().const_evaluatable_checked => { let tcx = self.def_id_visitor.tcx(); - if let Ok(Some(ct)) = AbstractConst::new(tcx, defs, substs) { + if let Ok(Some(ct)) = AbstractConst::new(tcx, uv) { self.visit_abstract_const_expr(tcx, ct)?; } ControlFlow::CONTINUE diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 38ab26d66ac6..8523737f8db6 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -217,18 +217,13 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { } } -impl<'tcx> Key - for ( - (ty::WithOptConstParam, SubstsRef<'tcx>), - (ty::WithOptConstParam, SubstsRef<'tcx>), - ) -{ +impl<'tcx> Key for (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>) { #[inline(always)] fn query_crate_is_local(&self) -> bool { - (self.0).0.did.krate == LOCAL_CRATE + (self.0).def.did.krate == LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - (self.0).0.did.default_span(tcx) + (self.0).def.did.default_span(tcx) } } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 2cc74ca2abb4..80c824565d22 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -19,7 +19,7 @@ use rustc_middle::mir::{self, Rvalue, StatementKind, TerminatorKind}; use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::{self, TyCtxt, TypeFoldable}; use rustc_session::lint; -use rustc_span::def_id::{DefId, LocalDefId}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; use std::cmp; @@ -29,26 +29,20 @@ use std::ops::ControlFlow; /// Check if a given constant can be evaluated. pub fn is_const_evaluatable<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, - def: ty::WithOptConstParam, - substs: SubstsRef<'tcx>, + uv: ty::Unevaluated<'tcx>, param_env: ty::ParamEnv<'tcx>, span: Span, ) -> Result<(), NotConstEvaluatable> { - debug!("is_const_evaluatable({:?}, {:?})", def, substs); + debug!("is_const_evaluatable({:?})", uv); if infcx.tcx.features().const_evaluatable_checked { let tcx = infcx.tcx; - match AbstractConst::new(tcx, def, substs)? { + match AbstractConst::new(tcx, uv)? { // We are looking at a generic abstract constant. Some(ct) => { for pred in param_env.caller_bounds() { match pred.kind().skip_binder() { - ty::PredicateKind::ConstEvaluatable(b_def, b_substs) => { - if b_def == def && b_substs == substs { - debug!("is_const_evaluatable: caller_bound ~~> ok"); - return Ok(()); - } - - if let Some(b_ct) = AbstractConst::new(tcx, b_def, b_substs)? { + ty::PredicateKind::ConstEvaluatable(uv) => { + if let Some(b_ct) = AbstractConst::new(tcx, uv)? { // Try to unify with each subtree in the AbstractConst to allow for // `N + 1` being const evaluatable even if theres only a `ConstEvaluatable` // predicate for `(N + 1) * 2` @@ -134,7 +128,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( } let future_compat_lint = || { - if let Some(local_def_id) = def.did.as_local() { + if let Some(local_def_id) = uv.def.did.as_local() { infcx.tcx.struct_span_lint_hir( lint::builtin::CONST_EVALUATABLE_UNCHECKED, infcx.tcx.hir().local_def_id_to_hir_id(local_def_id), @@ -155,13 +149,12 @@ pub fn is_const_evaluatable<'cx, 'tcx>( // and hopefully soon change this to an error. // // See #74595 for more details about this. - let concrete = - infcx.const_eval_resolve(param_env, ty::Unevaluated::new(def, substs), Some(span)); + let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); - if concrete.is_ok() && substs.has_param_types_or_consts(infcx.tcx) { - match infcx.tcx.def_kind(def.did) { + if concrete.is_ok() && uv.substs(infcx.tcx).has_param_types_or_consts(infcx.tcx) { + match infcx.tcx.def_kind(uv.def.did) { DefKind::AnonConst => { - let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(def); + let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(uv.def); if mir_body.is_polymorphic { future_compat_lint(); @@ -173,7 +166,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( debug!(?concrete, "is_const_evaluatable"); match concrete { - Err(ErrorHandled::TooGeneric) => Err(match substs.has_infer_types_or_consts() { + Err(ErrorHandled::TooGeneric) => Err(match uv.has_infer_types_or_consts() { true => NotConstEvaluatable::MentionsInfer, false => NotConstEvaluatable::MentionsParam, }), @@ -198,15 +191,14 @@ pub struct AbstractConst<'tcx> { pub substs: SubstsRef<'tcx>, } -impl AbstractConst<'tcx> { +impl<'tcx> AbstractConst<'tcx> { pub fn new( tcx: TyCtxt<'tcx>, - def: ty::WithOptConstParam, - substs: SubstsRef<'tcx>, + uv: ty::Unevaluated<'tcx>, ) -> Result>, ErrorReported> { - let inner = tcx.mir_abstract_const_opt_const_arg(def)?; - debug!("AbstractConst::new({:?}) = {:?}", def, inner); - Ok(inner.map(|inner| AbstractConst { inner, substs })) + let inner = tcx.mir_abstract_const_opt_const_arg(uv.def)?; + debug!("AbstractConst::new({:?}) = {:?}", uv, inner); + Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs(tcx) })) } pub fn from_const( @@ -214,7 +206,7 @@ impl AbstractConst<'tcx> { ct: &ty::Const<'tcx>, ) -> Result>, ErrorReported> { match ct.val { - ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv.def, uv.substs(tcx)), + ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv), ty::ConstKind::Error(_) => Err(ErrorReported), _ => Ok(None), } @@ -564,14 +556,11 @@ pub(super) fn mir_abstract_const<'tcx>( pub(super) fn try_unify_abstract_consts<'tcx>( tcx: TyCtxt<'tcx>, - ((a, a_substs), (b, b_substs)): ( - (ty::WithOptConstParam, SubstsRef<'tcx>), - (ty::WithOptConstParam, SubstsRef<'tcx>), - ), + (a, b): (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>), ) -> bool { (|| { - if let Some(a) = AbstractConst::new(tcx, a, a_substs)? { - if let Some(b) = AbstractConst::new(tcx, b, b_substs)? { + if let Some(a) = AbstractConst::new(tcx, a)? { + if let Some(b) = AbstractConst::new(tcx, b)? { return Ok(try_unify(tcx, a, b)); } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 90b6ee5f5a6a..6a7aafc334ba 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -811,10 +811,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::ConstEvaluatable(def, _) => { + ty::PredicateKind::ConstEvaluatable(uv) => { let mut err = self.tcx.sess.struct_span_err(span, "unconstrained generic constant"); - let const_span = self.tcx.def_span(def.did); + let const_span = self.tcx.def_span(uv.def.did); match self.tcx.sess.source_map().span_to_snippet(const_span) { Ok(snippet) => err.help(&format!( "try adding a `where` bound using this expression: `where [(); {}]:`", diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index edf2274ab54f..a17921ace307 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -543,11 +543,10 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(uv) => { match const_evaluatable::is_const_evaluatable( self.selcx.infcx(), - def_id, - substs, + uv, obligation.param_env, obligation.cause.span, ) { @@ -555,7 +554,9 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { Err(NotConstEvaluatable::MentionsInfer) => { pending_obligation.stalled_on.clear(); pending_obligation.stalled_on.extend( - substs.iter().filter_map(TyOrConstInferVar::maybe_from_generic_arg), + uv.substs(infcx.tcx) + .iter() + .filter_map(TyOrConstInferVar::maybe_from_generic_arg), ); ProcessResult::Unchanged } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 9511b41147da..dd974e6fd4f1 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -854,12 +854,12 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>( } fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow { - if let ty::PredicateKind::ConstEvaluatable(def, substs) = pred.kind().skip_binder() { + if let ty::PredicateKind::ConstEvaluatable(ct) = pred.kind().skip_binder() { // FIXME(const_evaluatable_checked): We should probably deduplicate the logic for // `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to // take a `ty::Const` instead. use rustc_middle::mir::abstract_const::Node; - if let Ok(Some(ct)) = AbstractConst::new(self.tcx, def, substs) { + if let Ok(Some(ct)) = AbstractConst::new(self.tcx, ct) { const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() { Node::Leaf(leaf) => { let leaf = leaf.subst(self.tcx, ct.substs); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 1c4e7e6c5898..6ddc3aad1b59 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -598,11 +598,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(uv) => { match const_evaluatable::is_const_evaluatable( self.infcx, - def_id, - substs, + uv, obligation.param_env, obligation.cause.span, ) { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 623215ec34e1..75307f135636 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -132,8 +132,9 @@ pub fn predicate_obligations<'a, 'tcx>( wf.compute(a.into()); wf.compute(b.into()); } - ty::PredicateKind::ConstEvaluatable(def, substs) => { - let obligations = wf.nominal_obligations(def.did, substs); + ty::PredicateKind::ConstEvaluatable(uv) => { + let substs = uv.substs(wf.tcx()); + let obligations = wf.nominal_obligations(uv.def.did, substs); wf.out.extend(obligations); for arg in substs.iter() { @@ -442,8 +443,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let obligations = self.nominal_obligations(uv.def.did, substs); self.out.extend(obligations); - let predicate = ty::PredicateKind::ConstEvaluatable(uv.def, substs) - .to_predicate(self.tcx()); + let predicate = ty::PredicateKind::ConstEvaluatable( + ty::Unevaluated::new(uv.def, substs), + ) + .to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::with_depth( cause, diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index c34dd705bef7..fd150978f007 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -236,9 +236,9 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( relator.relate(predicate.rebind(a), p.rebind(b)).is_ok() } ( - ty::PredicateKind::ConstEvaluatable(def_a, substs_a), - ty::PredicateKind::ConstEvaluatable(def_b, substs_b), - ) => tcx.try_unify_abstract_consts(((def_a, substs_a), (def_b, substs_b))), + ty::PredicateKind::ConstEvaluatable(a), + ty::PredicateKind::ConstEvaluatable(b), + ) => tcx.try_unify_abstract_consts((a, b)), (ty::PredicateKind::TypeOutlives(a), ty::PredicateKind::TypeOutlives(b)) => { relator.relate(predicate.rebind(a.0), p.rebind(b.0)).is_ok() } diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 057a15a43586..c76566806ed8 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -541,10 +541,10 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::PredicateKind::ConstEvaluatable( + ty::PredicateKind::ConstEvaluatable(ty::Unevaluated::new( ty::WithOptConstParam::unknown(discr_def_id.to_def_id()), discr_substs, - ) + )) .to_predicate(tcx), )); } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index a5a402bc26a8..df050fc9adc9 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2355,11 +2355,8 @@ fn const_evaluatable_predicates_of<'tcx>( if let ty::ConstKind::Unevaluated(uv) = ct.val { assert_eq!(uv.promoted, None); let span = self.tcx.hir().span(c.hir_id); - self.preds.insert(( - ty::PredicateKind::ConstEvaluatable(uv.def, uv.substs(self.tcx)) - .to_predicate(self.tcx), - span, - )); + self.preds + .insert((ty::PredicateKind::ConstEvaluatable(uv).to_predicate(self.tcx), span)); } } From 6755b2da4472fb82f8105a52a19cb1b32308ab48 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 14:05:13 +0200 Subject: [PATCH 162/269] ignore const substs in `implicit_infer` --- compiler/rustc_middle/src/ty/walk.rs | 31 +++++++++++++------ .../src/outlives/implicit_infer.rs | 7 ++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 3cab813f12ad..73985cf31e0f 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -11,7 +11,7 @@ use smallvec::{self, SmallVec}; type TypeWalkerStack<'tcx> = SmallVec<[GenericArg<'tcx>; 8]>; pub struct TypeWalker<'tcx> { - tcx: TyCtxt<'tcx>, + expose_default_const_substs: Option>, stack: TypeWalkerStack<'tcx>, last_subtree: usize, pub visited: SsoHashSet>, @@ -26,8 +26,13 @@ pub struct TypeWalker<'tcx> { /// It maintains a set of visited types and /// skips any types that are already there. impl<'tcx> TypeWalker<'tcx> { - fn new(tcx: TyCtxt<'tcx>, root: GenericArg<'tcx>) -> Self { - Self { tcx, stack: smallvec![root], last_subtree: 1, visited: SsoHashSet::new() } + fn new(expose_default_const_substs: Option>, root: GenericArg<'tcx>) -> Self { + Self { + expose_default_const_substs, + stack: smallvec![root], + last_subtree: 1, + visited: SsoHashSet::new(), + } } /// Skips the subtree corresponding to the last type @@ -56,7 +61,7 @@ impl<'tcx> Iterator for TypeWalker<'tcx> { let next = self.stack.pop()?; self.last_subtree = self.stack.len(); if self.visited.insert(next) { - push_inner(self.tcx, &mut self.stack, next); + push_inner(self.expose_default_const_substs, &mut self.stack, next); debug!("next: stack={:?}", self.stack); return Some(next); } @@ -76,7 +81,7 @@ impl GenericArg<'tcx> { /// [isize] => { [isize], isize } /// ``` pub fn walk(self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> { - TypeWalker::new(tcx, self) + TypeWalker::new(Some(tcx), self) } /// Iterator that walks the immediate children of `self`. Hence @@ -92,13 +97,17 @@ impl GenericArg<'tcx> { visited: &mut SsoHashSet>, ) -> impl Iterator> { let mut stack = SmallVec::new(); - push_inner(tcx, &mut stack, self); + push_inner(Some(tcx), &mut stack, self); stack.retain(|a| visited.insert(*a)); stack.into_iter() } } impl<'tcx> super::TyS<'tcx> { + pub fn walk_ignoring_default_const_substs(&'tcx self) -> TypeWalker<'tcx> { + TypeWalker::new(None, self.into()) + } + /// Iterator that walks `self` and any types reachable from /// `self`, in depth-first order. Note that just walks the types /// that appear in `self`, it does not descend into the fields of @@ -110,7 +119,7 @@ impl<'tcx> super::TyS<'tcx> { /// [isize] => { [isize], isize } /// ``` pub fn walk(&'tcx self, tcx: TyCtxt<'tcx>) -> TypeWalker<'tcx> { - TypeWalker::new(tcx, self.into()) + TypeWalker::new(Some(tcx), self.into()) } } @@ -121,7 +130,7 @@ impl<'tcx> super::TyS<'tcx> { /// natural order one would expect (basically, the order of the /// types as they are written). fn push_inner<'tcx>( - tcx: TyCtxt<'tcx>, + expose_default_const_substs: Option>, stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>, ) { @@ -202,7 +211,11 @@ fn push_inner<'tcx>( | ty::ConstKind::Error(_) => {} ty::ConstKind::Unevaluated(ct) => { - stack.extend(ct.substs(tcx).iter().rev()); + if let Some(tcx) = expose_default_const_substs { + stack.extend(ct.substs(tcx).iter().rev()); + } else if let Some(substs) = ct.substs_ { + stack.extend(substs.iter().rev()); + } } } } diff --git a/compiler/rustc_typeck/src/outlives/implicit_infer.rs b/compiler/rustc_typeck/src/outlives/implicit_infer.rs index 985ee2169c92..9a728e3f44d5 100644 --- a/compiler/rustc_typeck/src/outlives/implicit_infer.rs +++ b/compiler/rustc_typeck/src/outlives/implicit_infer.rs @@ -114,7 +114,12 @@ fn insert_required_predicates_to_be_wf<'tcx>( required_predicates: &mut RequiredPredicates<'tcx>, explicit_map: &mut ExplicitPredicatesMap<'tcx>, ) { - for arg in field_ty.walk(tcx) { + // We must not look into the default substs of consts + // as computing those depends on the results of `predicates_of`. + // + // Luckily the only types contained in default substs are type + // parameters which don't matter here. + for arg in field_ty.walk_ignoring_default_const_substs() { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, From 5ba8f4d2589a93063d6023a80d51619c60e33f43 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 16:59:19 +0200 Subject: [PATCH 163/269] update mir diffs --- .../const_promotion_extern_static.BAR.PromoteTemps.diff | 2 +- .../const_promotion_extern_static.FOO.PromoteTemps.diff | 2 +- .../bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff | 2 +- .../bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff | 2 +- .../const_prop_fails_gracefully.main.ConstProp.diff | 2 +- src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff | 2 +- .../mir-opt/const_prop/ref_deref.main.PromoteTemps.diff | 2 +- .../const_prop/ref_deref_project.main.ConstProp.diff | 2 +- .../const_prop/ref_deref_project.main.PromoteTemps.diff | 2 +- .../mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff | 2 +- .../mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff | 2 +- src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir | 4 ++-- src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff | 2 +- src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff | 2 +- .../mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff | 2 +- .../mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff | 2 +- .../lower_intrinsics.discriminant.LowerIntrinsics.diff | 6 +++--- ...tch_false_edges.full_tested_match.PromoteTemps.after.mir | 2 +- .../retag.array_casts.SimplifyCfg-elaborate-drops.after.mir | 2 +- .../retag.main.SimplifyCfg-elaborate-drops.after.mir | 2 +- 20 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff b/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff index 6f4bd65b85d4..49d0a7ff4550 100644 --- a/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff +++ b/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff @@ -30,7 +30,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 + // + span: $DIR/const-promotion-extern-static.rs:9:31: 9:35 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[55e6]::BAR), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[55e6]::BAR), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 - StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:9:34: 9:35 diff --git a/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff b/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff index 8c9a37bce854..f2504ae880ea 100644 --- a/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff +++ b/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff @@ -32,7 +32,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 + // + span: $DIR/const-promotion-extern-static.rs:13:31: 13:46 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[55e6]::FOO), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[55e6]::FOO), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 - StorageDead(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:13:45: 13:46 diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff index db6e1369161f..f8fd2cc9b0d0 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.diff @@ -31,7 +31,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff index db6e1369161f..f8fd2cc9b0d0 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.diff @@ -31,7 +31,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[8240]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff index d7bc035e667a..49237934223e 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff @@ -22,7 +22,7 @@ // + val: Unevaluated(FOO, [], None) // mir::Constant // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[2706]::main::FOO), const_param_did: None }, substs: [], promoted: None }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[2706]::main::FOO), const_param_did: None }, substs_: Some([]), promoted: None }) } _2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 _1 = move _2 as usize (Misc); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39 diff --git a/src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff index 4e19465189c9..54acae43abc5 100644 --- a/src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff @@ -17,7 +17,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref.rs:5:6: 5:10 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 - _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 + _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 diff --git a/src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff index a58dabdaa415..3b5c86942a75 100644 --- a/src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff @@ -20,7 +20,7 @@ + // + val: Unevaluated(main, [], Some(promoted[0])) + // mir::Constant + // + span: $DIR/ref_deref.rs:5:6: 5:10 -+ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } ++ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[cb9b]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } + _2 = &(*_4); // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 - StorageDead(_3); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11 diff --git a/src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff index bb265b2af7d3..8590a98491b7 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff @@ -17,7 +17,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref_project.rs:5:6: 5:17 - // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff index bb7570fabbba..4e10ae179348 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff @@ -20,7 +20,7 @@ + // + val: Unevaluated(main, [], Some(promoted[0])) + // mir::Constant + // + span: $DIR/ref_deref_project.rs:5:6: 5:17 -+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } ++ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[e8c3]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } + _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 - StorageDead(_3); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff index d5a36182e350..f305d602bbde 100644 --- a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff +++ b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff @@ -24,7 +24,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff index d5a36182e350..f305d602bbde 100644 --- a/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff +++ b/src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff @@ -24,7 +24,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ slice_len[6547]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir index 5ceefce6114f..0ff0e8ea7b1f 100644 --- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -38,7 +38,7 @@ fn bar() -> bool { // + val: Unevaluated(bar, [], Some(promoted[1])) // mir::Constant // + span: $DIR/inline-retag.rs:12:7: 12:9 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[1]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[1]) }) } Retag(_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 _4 = &(*_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 Retag(_4); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 @@ -52,7 +52,7 @@ fn bar() -> bool { // + val: Unevaluated(bar, [], Some(promoted[0])) // mir::Constant // + span: $DIR/inline-retag.rs:12:11: 12:14 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:4 ~ inline_retag[a78c]::bar), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } Retag(_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 _7 = &(*_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 Retag(_7); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff index e955feb7d1f4..95632293d999 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.32bit.diff @@ -66,7 +66,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _8 = _20; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_6.0: &i32) = move _7; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_6.1: &i32) = move _8; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff index e955feb7d1f4..95632293d999 100644 --- a/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.PreCodegen.64bit.diff @@ -66,7 +66,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _8 = _20; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_6.0: &i32) = move _7; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_6.1: &i32) = move _8; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index ff8c410a7268..1581e945e70e 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -87,7 +87,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _11 = _28; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index ff8c410a7268..1581e945e70e 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -87,7 +87,7 @@ // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ issue_73223[2d0f]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _11 = _28; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff b/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff index acb8aca75904..f427375e5a62 100644 --- a/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff +++ b/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff @@ -50,7 +50,7 @@ // + val: Unevaluated(discriminant, [T], Some(promoted[2])) // mir::Constant // + span: $DIR/lower_intrinsics.rs:70:42: 70:44 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[2]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs_: Some([T]), promoted: Some(promoted[2]) }) } _7 = &(*_19); // scope 0 at $DIR/lower_intrinsics.rs:70:42: 70:44 _6 = &(*_7); // scope 0 at $DIR/lower_intrinsics.rs:70:42: 70:44 - _5 = discriminant_value::(move _6) -> bb2; // scope 0 at $DIR/lower_intrinsics.rs:70:5: 70:45 @@ -74,7 +74,7 @@ // + val: Unevaluated(discriminant, [T], Some(promoted[1])) // mir::Constant // + span: $DIR/lower_intrinsics.rs:71:42: 71:45 - // + literal: Const { ty: &(), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[1]) }) } + // + literal: Const { ty: &(), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs_: Some([T]), promoted: Some(promoted[1]) }) } _11 = &(*_18); // scope 0 at $DIR/lower_intrinsics.rs:71:42: 71:45 _10 = &(*_11); // scope 0 at $DIR/lower_intrinsics.rs:71:42: 71:45 - _9 = discriminant_value::<()>(move _10) -> bb3; // scope 0 at $DIR/lower_intrinsics.rs:71:5: 71:46 @@ -98,7 +98,7 @@ // + val: Unevaluated(discriminant, [T], Some(promoted[0])) // mir::Constant // + span: $DIR/lower_intrinsics.rs:72:42: 72:47 - // + literal: Const { ty: &E, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs: [T], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &E, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:27 ~ lower_intrinsics[2872]::discriminant), const_param_did: None }, substs_: Some([T]), promoted: Some(promoted[0]) }) } _15 = &(*_17); // scope 0 at $DIR/lower_intrinsics.rs:72:42: 72:47 _14 = &(*_15); // scope 0 at $DIR/lower_intrinsics.rs:72:42: 72:47 - _13 = discriminant_value::(move _14) -> bb4; // scope 0 at $DIR/lower_intrinsics.rs:72:5: 72:48 diff --git a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir index c27ee528b80b..7f80d81b7edc 100644 --- a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir @@ -57,7 +57,7 @@ fn full_tested_match() -> () { // + val: Unevaluated(full_tested_match, [], Some(promoted[0])) // mir::Constant // + span: $DIR/match_false_edges.rs:16:14: 16:15 - // + literal: Const { ty: &std::option::Option, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ match_false_edges[4011]::full_tested_match), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &std::option::Option, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ match_false_edges[4011]::full_tested_match), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } _6 = &(((*_11) as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 _4 = &shallow _2; // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 StorageLive(_7); // scope 0 at $DIR/match_false_edges.rs:16:20: 16:27 diff --git a/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir index 787310d072a9..ee99d033af32 100644 --- a/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir @@ -127,7 +127,7 @@ fn array_casts() -> () { // + val: Unevaluated(array_casts, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL - // + literal: Const { ty: &usize, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:15 ~ retag[13e7]::array_casts), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &usize, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:15 ~ retag[13e7]::array_casts), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } Retag(_35); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL _18 = &(*_35); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL Retag(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir index 8abc6a3e4b51..cdf7282c8c3c 100644 --- a/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir @@ -153,7 +153,7 @@ fn main() -> () { // + val: Unevaluated(main, [], Some(promoted[0])) // mir::Constant // + span: $DIR/retag.rs:47:21: 47:23 - // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:13 ~ retag[13e7]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) } + // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:13 ~ retag[13e7]::main), const_param_did: None }, substs_: Some([]), promoted: Some(promoted[0]) }) } Retag(_28); // scope 7 at $DIR/retag.rs:47:21: 47:23 _23 = &(*_28); // scope 7 at $DIR/retag.rs:47:21: 47:23 Retag(_23); // scope 7 at $DIR/retag.rs:47:21: 47:23 From 283e0e670b7b6f925d5973f2b2b373304b17b114 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Jul 2021 17:20:24 +0200 Subject: [PATCH 164/269] is_polymorphic doesn't matter for tests --- compiler/rustc_middle/src/mir/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 6a7758bedfb8..7e99a6ada2f9 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -294,11 +294,8 @@ impl<'tcx> Body<'tcx> { /// The returned MIR contains no `LocalDecl`s (even for the return place) or source scopes. It /// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different /// crate. - pub fn new_cfg_only( - tcx: TyCtxt<'tcx>, - basic_blocks: IndexVec>, - ) -> Self { - let mut body = Body { + pub fn new_cfg_only(basic_blocks: IndexVec>) -> Self { + Body { phase: MirPhase::Build, source: MirSource::item(DefId::local(CRATE_DEF_INDEX)), basic_blocks, @@ -314,9 +311,7 @@ impl<'tcx> Body<'tcx> { is_polymorphic: false, predecessor_cache: PredecessorCache::new(), is_cyclic: GraphIsCyclicCache::new(), - }; - body.is_polymorphic = body.has_param_types_or_consts(tcx); - body + } } #[inline] From bc0156baceed60a4dbfd063554e66bc69b3b0bd4 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 2 Aug 2021 08:47:15 +0200 Subject: [PATCH 165/269] shrink `ty::PredicateKind` again --- compiler/rustc_infer/src/infer/mod.rs | 4 +-- compiler/rustc_middle/src/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/consts/kind.rs | 29 +++++++++++++++---- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 4 +-- compiler/rustc_middle/src/ty/relate.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 25 ++++++++++++++++ compiler/rustc_query_impl/src/keys.rs | 2 +- .../src/traits/const_evaluatable.rs | 10 +++---- .../src/traits/fulfill.rs | 2 +- .../src/traits/select/mod.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 6 ++-- 12 files changed, 68 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 7f890829e68e..bc98a3aa3f95 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -675,8 +675,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// canonicalizing the consts. pub fn try_unify_abstract_consts( &self, - a: ty::Unevaluated<'tcx>, - b: ty::Unevaluated<'tcx>, + a: ty::Unevaluated<'tcx, ()>, + b: ty::Unevaluated<'tcx, ()>, ) -> bool { let canonical = self.canonicalize_query((a, b), &mut OriginalQueryValues::default()); debug!("canonical consts: {:?}", &canonical.value); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 9b3de6710ec0..f8e0d910a546 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -303,7 +303,7 @@ rustc_queries! { } query try_unify_abstract_consts(key: ( - ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx> + ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()> )) -> bool { desc { |tcx| "trying to unify the generic constants {} and {}", diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index b1f6a6127766..e6a6b7f85564 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -1,4 +1,5 @@ use std::convert::TryInto; +use std::fmt; use crate::mir::interpret::{AllocId, ConstValue, Scalar}; use crate::mir::Promoted; @@ -20,20 +21,38 @@ use super::ScalarInt; /// so refer to that check for more info. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)] #[derive(Hash, HashStable)] -pub struct Unevaluated<'tcx> { +pub struct Unevaluated<'tcx, P = Option> { pub def: ty::WithOptConstParam, pub substs_: Option>, - pub promoted: Option, + pub promoted: P, } impl<'tcx> Unevaluated<'tcx> { - pub fn new(def: ty::WithOptConstParam, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx> { - Unevaluated { def, substs_: Some(substs), promoted: None } + pub fn shrink(self) -> Unevaluated<'tcx, ()> { + debug_assert_eq!(self.promoted, None); + Unevaluated { def: self.def, substs_: self.substs_, promoted: () } } +} + +impl<'tcx> Unevaluated<'tcx, ()> { + pub fn expand(self) -> Unevaluated<'tcx> { + Unevaluated { def: self.def, substs_: self.substs_, promoted: None } + } +} + +impl<'tcx, P: Default> Unevaluated<'tcx, P> { + pub fn new(def: ty::WithOptConstParam, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx, P> { + Unevaluated { def, substs_: Some(substs), promoted: Default::default() } + } +} +impl<'tcx, P: Default + PartialEq + fmt::Debug> Unevaluated<'tcx, P> { pub fn substs(self, tcx: TyCtxt<'tcx>) -> SubstsRef<'tcx> { self.substs_.unwrap_or_else(|| { - debug_assert_eq!(self.promoted, None); + // We must not use the parents default substs for promoted constants + // as that can result in incorrect substs and calls the `default_anon_const_substs` + // for something that might not actually be a constant. + debug_assert_eq!(self.promoted, Default::default()); tcx.default_anon_const_substs(self.def.did) }) } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 1c4f24cdf394..763da7e82c86 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -310,7 +310,7 @@ impl FlagComputation { } } - fn add_unevaluated_const(&mut self, ct: ty::Unevaluated<'tcx>) { + fn add_unevaluated_const

(&mut self, ct: ty::Unevaluated<'tcx, P>) { if let Some(substs) = ct.substs_ { self.add_substs(substs); } else { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index b1ebe43c491d..8f814a84b495 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -406,7 +406,7 @@ crate struct PredicateInner<'tcx> { } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(PredicateInner<'_>, 56); +static_assert_size!(PredicateInner<'_>, 48); #[derive(Clone, Copy, Lift)] pub struct Predicate<'tcx> { @@ -502,7 +502,7 @@ pub enum PredicateKind<'tcx> { Coerce(CoercePredicate<'tcx>), /// Constant initializer must evaluate successfully. - ConstEvaluatable(ty::Unevaluated<'tcx>), + ConstEvaluatable(ty::Unevaluated<'tcx, ()>), /// Constants must be equal. The first component is the const that is expected. ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>), diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index b64d507e0b89..4a2c8349fdc6 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -579,7 +579,7 @@ pub fn super_relate_consts>( (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if tcx.features().const_evaluatable_checked => { - tcx.try_unify_abstract_consts((au, bu)) + tcx.try_unify_abstract_consts((au.shrink(), bu.shrink())) } // While this is slightly incorrect, it shouldn't matter for `min_const_generics` diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 31088423efa3..2ab25c839704 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1105,3 +1105,28 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { } } } + +impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> { + fn super_fold_with>(self, folder: &mut F) -> Self { + ty::Unevaluated { + def: self.def, + substs_: Some(self.substs(folder.tcx()).fold_with(folder)), + promoted: self.promoted, + } + } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_unevaluated_const(self.expand()) + } + + fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + if let Some(tcx) = visitor.tcx_for_anon_const_substs() { + self.substs(tcx).visit_with(visitor) + } else if let Some(substs) = self.substs_ { + substs.visit_with(visitor) + } else { + debug!("ignoring default substs of `{:?}`", self.def); + ControlFlow::CONTINUE + } + } +} diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 8523737f8db6..d85f1c04524d 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -217,7 +217,7 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { } } -impl<'tcx> Key for (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>) { +impl<'tcx> Key for (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>) { #[inline(always)] fn query_crate_is_local(&self) -> bool { (self.0).def.did.krate == LOCAL_CRATE diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 80c824565d22..d75408ed8201 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -29,7 +29,7 @@ use std::ops::ControlFlow; /// Check if a given constant can be evaluated. pub fn is_const_evaluatable<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, - uv: ty::Unevaluated<'tcx>, + uv: ty::Unevaluated<'tcx, ()>, param_env: ty::ParamEnv<'tcx>, span: Span, ) -> Result<(), NotConstEvaluatable> { @@ -149,7 +149,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( // and hopefully soon change this to an error. // // See #74595 for more details about this. - let concrete = infcx.const_eval_resolve(param_env, uv, Some(span)); + let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span)); if concrete.is_ok() && uv.substs(infcx.tcx).has_param_types_or_consts(infcx.tcx) { match infcx.tcx.def_kind(uv.def.did) { @@ -194,7 +194,7 @@ pub struct AbstractConst<'tcx> { impl<'tcx> AbstractConst<'tcx> { pub fn new( tcx: TyCtxt<'tcx>, - uv: ty::Unevaluated<'tcx>, + uv: ty::Unevaluated<'tcx, ()>, ) -> Result>, ErrorReported> { let inner = tcx.mir_abstract_const_opt_const_arg(uv.def)?; debug!("AbstractConst::new({:?}) = {:?}", uv, inner); @@ -206,7 +206,7 @@ impl<'tcx> AbstractConst<'tcx> { ct: &ty::Const<'tcx>, ) -> Result>, ErrorReported> { match ct.val { - ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv), + ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv.shrink()), ty::ConstKind::Error(_) => Err(ErrorReported), _ => Ok(None), } @@ -556,7 +556,7 @@ pub(super) fn mir_abstract_const<'tcx>( pub(super) fn try_unify_abstract_consts<'tcx>( tcx: TyCtxt<'tcx>, - (a, b): (ty::Unevaluated<'tcx>, ty::Unevaluated<'tcx>), + (a, b): (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>), ) -> bool { (|| { if let Some(a) = AbstractConst::new(tcx, a)? { diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index a17921ace307..f214930c57fe 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -580,7 +580,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) = (c1.val, c2.val) { - if infcx.try_unify_abstract_consts(a, b) { + if infcx.try_unify_abstract_consts(a.shrink(), b.shrink()) { return ProcessResult::Changed(vec![]); } } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 6ddc3aad1b59..756646c2d88f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -623,7 +623,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) = (c1.val, c2.val) { - if self.infcx.try_unify_abstract_consts(a, b) { + if self.infcx.try_unify_abstract_consts(a.shrink(), b.shrink()) { return Ok(EvaluatedToOk); } } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index df050fc9adc9..75f9405e082c 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2355,8 +2355,10 @@ fn const_evaluatable_predicates_of<'tcx>( if let ty::ConstKind::Unevaluated(uv) = ct.val { assert_eq!(uv.promoted, None); let span = self.tcx.hir().span(c.hir_id); - self.preds - .insert((ty::PredicateKind::ConstEvaluatable(uv).to_predicate(self.tcx), span)); + self.preds.insert(( + ty::PredicateKind::ConstEvaluatable(uv.shrink()).to_predicate(self.tcx), + span, + )); } } From f3996f6a88c7a4f24b673809aa50897fb2615691 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 2 Aug 2021 09:56:05 +0200 Subject: [PATCH 166/269] review --- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 2 +- compiler/rustc_lint/src/noop_method_call.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/ty/flags.rs | 11 +++++++++++ compiler/rustc_middle/src/ty/fold.rs | 17 ++++++++++------- compiler/rustc_middle/src/ty/layout.rs | 4 ++-- compiler/rustc_middle/src/ty/print/pretty.rs | 4 ++-- compiler/rustc_mir/src/interpret/util.rs | 2 +- .../rustc_mir/src/monomorphize/polymorphize.rs | 8 ++++---- compiler/rustc_mir/src/transform/const_prop.rs | 8 ++++---- .../rustc_mir/src/transform/inline/cycle.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 3 ++- .../src/traits/coherence.rs | 2 +- .../src/traits/const_evaluatable.rs | 6 +++--- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/select/mod.rs | 2 +- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- compiler/rustc_typeck/src/check/wfcheck.rs | 10 +++++----- compiler/rustc_typeck/src/collect/type_of.rs | 9 ++++++++- 21 files changed, 62 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 2e8a96040172..914376d58dde 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -499,7 +499,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { ty::Adt(def, ..) if !def.is_box() => { // Again, only create type information if full debuginfo is enabled if cx.sess().opts.debuginfo == DebugInfo::Full - && !impl_self_ty.needs_subst(cx.tcx) + && !impl_self_ty.definitely_needs_subst(cx.tcx) { Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP)) } else { diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index c6e150d114c5..934ada9932e7 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -470,7 +470,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { { let needs_canonical_flags = if canonicalize_region_mode.any() { TypeFlags::NEEDS_INFER | - TypeFlags::HAS_POTENTIAL_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_xxx_FREE_REGIONS` + TypeFlags::HAS_POTENTIAL_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_POTENTIAL_FREE_REGIONS` TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER } else { diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 908d847915f8..c14f16b6d11b 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { _ => return, }; let substs = cx.typeck_results().node_substs(expr.hir_id); - if substs.needs_subst(cx.tcx) { + if substs.definitely_needs_subst(cx.tcx) { // We can't resolve on types that require monomorphization, so we don't handle them if // we need to perfom substitution. return; diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 7e99a6ada2f9..8e2917ee5b47 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -285,7 +285,7 @@ impl<'tcx> Body<'tcx> { predecessor_cache: PredecessorCache::new(), is_cyclic: GraphIsCyclicCache::new(), }; - body.is_polymorphic = body.has_param_types_or_consts(tcx); + body.is_polymorphic = body.definitely_has_param_types_or_consts(tcx); body } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 763da7e82c86..a078b6fb742a 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -311,9 +311,20 @@ impl FlagComputation { } fn add_unevaluated_const

(&mut self, ct: ty::Unevaluated<'tcx, P>) { + // The generic arguments of unevaluated consts are a bit special, + // see the `rustc-dev-guide` for more information. + // + // FIXME(@lcnr): Actually add a link here. if let Some(substs) = ct.substs_ { + // If they are available, we treat them as ordinary generic arguments. self.add_substs(substs); } else { + // Otherwise, we add `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS` to signify + // that our const may potentially refer to generic parameters. + // + // Note that depending on which generic parameters are actually + // used in this constant, we may not actually refer to any generic + // parameters at all. self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); self.add_flags(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS); } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index b249dc8d6f92..604a10f4807e 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -92,14 +92,14 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { fn references_error(&self) -> bool { self.has_type_flags(TypeFlags::HAS_ERROR) } - fn has_potential_param_types_or_consts(&self) -> bool { + fn potentially_has_param_types_or_consts(&self) -> bool { self.has_type_flags( TypeFlags::HAS_KNOWN_TY_PARAM | TypeFlags::HAS_KNOWN_CT_PARAM | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS, ) } - fn has_param_types_or_consts(&self, tcx: TyCtxt<'tcx>) -> bool { + fn definitely_has_param_types_or_consts(&self, tcx: TyCtxt<'tcx>) -> bool { self.definitely_has_type_flags( tcx, TypeFlags::HAS_KNOWN_TY_PARAM | TypeFlags::HAS_KNOWN_CT_PARAM, @@ -129,7 +129,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { TypeFlags::KNOWN_NEEDS_SUBST | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS, ) } - fn needs_subst(&self, tcx: TyCtxt<'tcx>) -> bool { + fn definitely_needs_subst(&self, tcx: TyCtxt<'tcx>) -> bool { self.definitely_has_type_flags(tcx, TypeFlags::KNOWN_NEEDS_SUBST) } /// "Free" regions in this context means that it has any region @@ -227,10 +227,13 @@ pub trait TypeVisitor<'tcx>: Sized { /// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs /// are not yet supplied. /// - /// Visitors which do not look into these substs may return `None` here, in which case - /// `super_visit_with` completely skips the default substs. Incorrectly returning - /// `None` can very quickly lead to ICE or other critical bugs, so be careful and - /// try to return an actual `tcx` if at all possible. + /// Returning `None` for this method is only recommended if the `TypeVisitor` + /// does not care about default anon const substs, as it ignores generic parameters, + /// and fetching the default substs would cause a query cycle. + /// + /// For visitors which return `None` we completely skip the default substs in `ty::Unevaluated::super_visit_with`. + /// This means that incorrectly returning `None` can very quickly lead to ICE or other critical bugs, so be careful and + /// try to return an actual `tcx` if possible. fn tcx_for_anon_const_substs(&self) -> Option>; fn visit_binder>( diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 6761fbaf5365..6f234a3958af 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1727,7 +1727,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Ignore layouts that are done with non-empty environments or // non-monomorphic layouts, as the user only wants to see the stuff // resulting from the final codegen session. - if layout.ty.has_param_types_or_consts(self.tcx) + if layout.ty.definitely_has_param_types_or_consts(self.tcx) || !self.param_env.caller_bounds().is_empty() { return; @@ -1896,7 +1896,7 @@ impl<'tcx> SizeSkeleton<'tcx> { let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env); match tail.kind() { ty::Param(_) | ty::Projection(_) => { - debug_assert!(tail.has_param_types_or_consts(tcx)); + debug_assert!(tail.definitely_has_param_types_or_consts(tcx)); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) }) } _ => bug!( diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 230a39e639fb..0e1197b265bc 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1193,7 +1193,7 @@ pub trait PrettyPrinter<'tcx>: // Aggregates, printed as array/tuple/struct/variant construction syntax. // - // NB: the `has_param_types_or_consts` check ensures that we can use + // NB: the `potentially_has_param_types_or_consts` check ensures that we can use // the `destructure_const` query with an empty `ty::ParamEnv` without // introducing ICEs (e.g. via `layout_of`) from missing bounds. // E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized` @@ -1202,7 +1202,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) for `--emit=mir`/`-Z dump-mir`, we should provide the // correct `ty::ParamEnv` to allow printing *all* constant values. (_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) - if !ty.has_potential_param_types_or_consts() => + if !ty.potentially_has_param_types_or_consts() => { let contents = self.tcx().destructure_const( ty::ParamEnv::reveal_all() diff --git a/compiler/rustc_mir/src/interpret/util.rs b/compiler/rustc_mir/src/interpret/util.rs index 37c13c2d42ae..eb0fdebb665f 100644 --- a/compiler/rustc_mir/src/interpret/util.rs +++ b/compiler/rustc_mir/src/interpret/util.rs @@ -43,7 +43,7 @@ where let is_used = unused_params.contains(index).map_or(true, |unused| !unused); // Only recurse when generic parameters in fns, closures and generators // are used and require substitution. - match (is_used, subst.needs_subst(self.tcx)) { + match (is_used, subst.definitely_needs_subst(self.tcx)) { // Just in case there are closures or generators within this subst, // recurse. (true, true) => return subst.super_visit_with(self), diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index 368ac70b5520..3c55a4b0a8fb 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -288,7 +288,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { } #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { - if !c.has_potential_param_types_or_consts() { + if !c.potentially_has_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -321,7 +321,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - if !ty.has_potential_param_types_or_consts() { + if !ty.potentially_has_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -363,7 +363,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { - if !c.has_potential_param_types_or_consts() { + if !c.potentially_has_param_types_or_consts() { return ControlFlow::CONTINUE; } @@ -381,7 +381,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> { #[instrument(skip(self))] fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - if !ty.has_potential_param_types_or_consts() { + if !ty.potentially_has_param_types_or_consts() { return ControlFlow::CONTINUE; } diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 0d58625633f0..1932cd5de29b 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -469,7 +469,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { /// Returns the value, if any, of evaluating `c`. fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option> { // FIXME we need to revisit this for #67176 - if c.needs_subst(self.tcx) { + if c.definitely_needs_subst(self.tcx) { return None; } @@ -489,9 +489,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { }) => true, // Out of backwards compatibility we cannot report hard errors in unused // generic functions using associated constants of the generic parameters. - _ => c.literal.needs_subst(*tcx), + _ => c.literal.definitely_needs_subst(*tcx), }, - ConstantKind::Val(_, ty) => ty.needs_subst(*tcx), + ConstantKind::Val(_, ty) => ty.definitely_needs_subst(*tcx), }; if lint_only { // Out of backwards compatibility we cannot report hard errors in unused @@ -721,7 +721,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } // FIXME we need to revisit this for #67176 - if rvalue.needs_subst(self.tcx) { + if rvalue.definitely_needs_subst(self.tcx) { return None; } diff --git a/compiler/rustc_mir/src/transform/inline/cycle.rs b/compiler/rustc_mir/src/transform/inline/cycle.rs index 46628b928de9..385394ba67d4 100644 --- a/compiler/rustc_mir/src/transform/inline/cycle.rs +++ b/compiler/rustc_mir/src/transform/inline/cycle.rs @@ -89,7 +89,7 @@ crate fn mir_callgraph_reachable( // FIXME: A not fully substituted drop shim can cause ICEs if one attempts to // have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this // needs some more analysis. - if callee.needs_subst(tcx) { + if callee.definitely_needs_subst(tcx) { continue; } } diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 267e2d8808fb..e236ef996bcc 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -107,7 +107,7 @@ fn get_symbol_hash<'tcx>( tcx.def_path_hash(def_id).hash_stable(&mut hcx, &mut hasher); // Include the main item-type. Note that, in this case, the - // assertions about `needs_subst` may not hold, but this item-type + // assertions about `definitely_needs_subst` may not hold, but this item-type // ought to be the same for every reference anyway. assert!(!item_type.has_erasable_regions(tcx)); hcx.while_hashing_spans(false, |hcx| { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 3ac9d1e5745f..e9ebd6d64aa9 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -277,7 +277,8 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { // Encode impl generic params if the substitutions contain parameters (implying // polymorphization is enabled) and this isn't an inherent impl. - if impl_trait_ref.is_some() && substs.iter().any(|a| a.has_param_types_or_consts(self.tcx)) + if impl_trait_ref.is_some() + && substs.iter().any(|a| a.definitely_has_param_types_or_consts(self.tcx)) { self = self.path_generic_args( |this| { diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 6ab079ad404d..668a74bd6971 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -391,7 +391,7 @@ fn orphan_check_trait_ref<'tcx>( ) -> Result<(), OrphanCheckErr<'tcx>> { debug!("orphan_check_trait_ref(trait_ref={:?}, in_crate={:?})", trait_ref, in_crate); - if trait_ref.needs_infer() && trait_ref.needs_subst(tcx) { + if trait_ref.needs_infer() && trait_ref.definitely_needs_subst(tcx) { bug!( "can't orphan check a trait ref with both params and inference variables {:?}", trait_ref diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index d75408ed8201..5c0bd1d8962f 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -85,7 +85,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( let leaf = leaf.subst(tcx, ct.substs); if leaf.has_infer_types_or_consts() { failure_kind = FailureKind::MentionsInfer; - } else if leaf.has_param_types_or_consts(tcx) { + } else if leaf.definitely_has_param_types_or_consts(tcx) { failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam); } @@ -95,7 +95,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( let ty = ty.subst(tcx, ct.substs); if ty.has_infer_types_or_consts() { failure_kind = FailureKind::MentionsInfer; - } else if ty.has_param_types_or_consts(tcx) { + } else if ty.definitely_has_param_types_or_consts(tcx) { failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam); } @@ -151,7 +151,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>( // See #74595 for more details about this. let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span)); - if concrete.is_ok() && uv.substs(infcx.tcx).has_param_types_or_consts(infcx.tcx) { + if concrete.is_ok() && uv.substs(infcx.tcx).definitely_has_param_types_or_consts(infcx.tcx) { match infcx.tcx.def_kind(uv.def.did) { DefKind::AnonConst => { let mir_body = infcx.tcx.mir_for_ctfe_opt_const_arg(uv.def); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 43ee1c3304ab..554b2950263e 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -450,7 +450,7 @@ fn subst_and_check_impossible_predicates<'tcx>( debug!("subst_and_check_impossible_predicates(key={:?})", key); let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates; - predicates.retain(|predicate| !predicate.needs_subst(tcx)); + predicates.retain(|predicate| !predicate.definitely_needs_subst(tcx)); let result = impossible_predicates(tcx, predicates); debug!("subst_and_check_impossible_predicates(key={:?}) = {:?}", key, result); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 756646c2d88f..1580562a92f3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -696,7 +696,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .param_env .caller_bounds() .iter() - .all(|bound| bound.needs_subst(self.tcx())) + .all(|bound| bound.definitely_needs_subst(self.tcx())) { // If a param env has no global bounds, global obligations do not // depend on its particular value in order to work, so we can clear diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index bbfceeeff483..d916ff7db3d5 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2204,7 +2204,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.prohibit_generics(path.segments); // Try to evaluate any array length constants. let normalized_ty = self.normalize_ty(span, tcx.at(span).type_of(def_id)); - if forbid_generic && normalized_ty.needs_subst(tcx) { + if forbid_generic && normalized_ty.definitely_needs_subst(tcx) { let mut err = tcx.sess.struct_span_err( path.span, "generic `Self` types are currently not permitted in anonymous constants", diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index c76566806ed8..2e01e99d36ec 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -746,7 +746,7 @@ fn check_where_clauses<'tcx, 'fcx>( // Ignore dependent defaults -- that is, where the default of one type // parameter includes another (e.g., ``). In those cases, we can't // be sure if it will error or not as user might always specify the other. - if !ty.needs_subst(tcx) { + if !ty.definitely_needs_subst(tcx) { fcx.register_wf_obligation( ty.into(), tcx.def_span(param.def_id), @@ -762,7 +762,7 @@ fn check_where_clauses<'tcx, 'fcx>( // for `struct Foo` // we should eagerly error. let default_ct = tcx.const_param_default(param.def_id); - if !default_ct.needs_subst(tcx) { + if !default_ct.definitely_needs_subst(tcx) { fcx.register_wf_obligation( default_ct.into(), tcx.def_span(param.def_id), @@ -796,7 +796,7 @@ fn check_where_clauses<'tcx, 'fcx>( if is_our_default(param) { let default_ty = tcx.type_of(param.def_id); // ... and it's not a dependent default, ... - if !default_ty.needs_subst(tcx) { + if !default_ty.definitely_needs_subst(tcx) { // ... then substitute it with the default. return default_ty.into(); } @@ -809,7 +809,7 @@ fn check_where_clauses<'tcx, 'fcx>( if is_our_default(param) { let default_ct = tcx.const_param_default(param.def_id); // ... and it's not a dependent default, ... - if !default_ct.needs_subst(tcx) { + if !default_ct.definitely_needs_subst(tcx) { // ... then substitute it with the default. return default_ct.into(); } @@ -858,7 +858,7 @@ fn check_where_clauses<'tcx, 'fcx>( let substituted_pred = pred.subst(tcx, substs); // Don't check non-defaulted params, dependent defaults (including lifetimes) // or preds with multiple params. - if substituted_pred.has_param_types_or_consts(tcx) + if substituted_pred.definitely_has_param_types_or_consts(tcx) || param_count.params.len() > 1 || has_region { diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 2f0a5eb79bc1..9bce5ee0da26 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -277,6 +277,13 @@ fn get_path_containing_arg_in_pat<'hir>( pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { let generics = tcx.generics_of(def_id); if let Some(parent) = generics.parent { + // This is the reason we bother with having optional anon const substs. + // + // In the future the substs of an anon const will depend on its parents predicates + // at which point eagerly looking at them will cause a query cycle. + // + // So for now this is only an assurance that this approach won't cause cycle errors in + // the future. let _cycle_check = tcx.predicates_of(parent); } @@ -284,7 +291,7 @@ pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> Subst // We only expect substs with the following type flags as default substs. // // Getting this wrong can lead to ICE and unsoundness, so we assert it here. - for arg in substs.iter().flat_map(|s| s.walk(tcx)) { + for arg in substs.iter() { let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS | ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE; assert!(!arg.has_type_flags(!allowed_flags)); From c58d749c8079761f20ef0410cbd0816a20694ca0 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 4 Aug 2021 09:34:46 +0200 Subject: [PATCH 167/269] type flags --- compiler/rustc_middle/src/ty/fold.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 604a10f4807e..a17984bbe419 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -1141,9 +1141,9 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { ); if t.flags().intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if self.tcx.is_some() - && t.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + } else if t.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + && self.tcx.is_some() { t.super_visit_with(self) } else { @@ -1168,9 +1168,9 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if self.tcx.is_some() - && flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + } else if flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + && self.tcx.is_some() { c.super_visit_with(self) } else { @@ -1178,14 +1178,15 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { } } + #[inline] fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { let flags = FlagComputation::for_unevaluated_const(uv); debug!("HasTypeFlagsVisitor: uv={:?} uv.flags={:?} self.flags={:?}", uv, flags, self.flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if self.tcx.is_some() - && flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + } else if flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + && self.tcx.is_some() { uv.super_visit_with(self) } else { @@ -1201,9 +1202,9 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { ); if predicate.inner.flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if self.tcx.is_some() - && predicate.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) + } else if predicate.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) + && self.tcx.is_some() { predicate.super_visit_with(self) } else { From bc0983df060c7131a3a7384cd26b6aef18096670 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 4 Aug 2021 10:17:06 +0200 Subject: [PATCH 168/269] add fixme --- compiler/rustc_typeck/src/outlives/implicit_infer.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_typeck/src/outlives/implicit_infer.rs b/compiler/rustc_typeck/src/outlives/implicit_infer.rs index 9a728e3f44d5..9fe26711f210 100644 --- a/compiler/rustc_typeck/src/outlives/implicit_infer.rs +++ b/compiler/rustc_typeck/src/outlives/implicit_infer.rs @@ -119,6 +119,12 @@ fn insert_required_predicates_to_be_wf<'tcx>( // // Luckily the only types contained in default substs are type // parameters which don't matter here. + // + // FIXME(const_generics): Once more complex const parameter types + // are allowed, this might be incorrect. I think that we will still be + // fine, as all outlives relations of the const param types should also + // be part of the adt containing it, but we should still both update the + // documentation and add some tests for this. for arg in field_ty.walk_ignoring_default_const_substs() { let ty = match arg.unpack() { GenericArgKind::Type(ty) => ty, From 977124590eb6a2230e168eed6391d6f70bfedaaf Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 9 Aug 2021 10:38:27 +0200 Subject: [PATCH 169/269] inline stuff --- compiler/rustc_middle/src/ty/consts/kind.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index e6a6b7f85564..7188eed54455 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -28,6 +28,7 @@ pub struct Unevaluated<'tcx, P = Option> { } impl<'tcx> Unevaluated<'tcx> { + #[inline] pub fn shrink(self) -> Unevaluated<'tcx, ()> { debug_assert_eq!(self.promoted, None); Unevaluated { def: self.def, substs_: self.substs_, promoted: () } @@ -35,18 +36,21 @@ impl<'tcx> Unevaluated<'tcx> { } impl<'tcx> Unevaluated<'tcx, ()> { + #[inline] pub fn expand(self) -> Unevaluated<'tcx> { Unevaluated { def: self.def, substs_: self.substs_, promoted: None } } } impl<'tcx, P: Default> Unevaluated<'tcx, P> { + #[inline] pub fn new(def: ty::WithOptConstParam, substs: SubstsRef<'tcx>) -> Unevaluated<'tcx, P> { Unevaluated { def, substs_: Some(substs), promoted: Default::default() } } } impl<'tcx, P: Default + PartialEq + fmt::Debug> Unevaluated<'tcx, P> { + #[inline] pub fn substs(self, tcx: TyCtxt<'tcx>) -> SubstsRef<'tcx> { self.substs_.unwrap_or_else(|| { // We must not use the parents default substs for promoted constants From eb5bbab37baf750c01ff91edcc64f6729a5cb714 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 17 Aug 2021 10:23:51 +0200 Subject: [PATCH 170/269] optimize `HasTypeFlagsVisitor` --- compiler/rustc_middle/src/ty/fold.rs | 114 +++++++++++++++++++-------- 1 file changed, 81 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index a17984bbe419..a04b0a7ef613 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -1128,26 +1128,20 @@ struct HasTypeFlagsVisitor<'tcx> { impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { type BreakTy = FoundFlags; fn tcx_for_anon_const_substs(&self) -> Option> { - self.tcx + bug!("we shouldn't call this method as we manually look at ct substs"); } #[inline] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - debug!( - "HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}", - t, - t.flags(), - self.flags - ); - if t.flags().intersects(self.flags) { + let flags = t.flags(); + debug!("HasTypeFlagsVisitor: t={:?} flags={:?} self.flags={:?}", t, flags, self.flags); + if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if t.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) - && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) - && self.tcx.is_some() - { - t.super_visit_with(self) } else { - ControlFlow::CONTINUE + match flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + true if self.tcx.is_some() => UnknownConstSubstsVisitor::search(&self, t), + _ => ControlFlow::CONTINUE, + } } } @@ -1168,13 +1162,11 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) - && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) - && self.tcx.is_some() - { - c.super_visit_with(self) } else { - ControlFlow::CONTINUE + match flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + true if self.tcx.is_some() => UnknownConstSubstsVisitor::search(&self, c), + _ => ControlFlow::CONTINUE, + } } } @@ -1184,28 +1176,84 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> { debug!("HasTypeFlagsVisitor: uv={:?} uv.flags={:?} self.flags={:?}", uv, flags, self.flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) - && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) - && self.tcx.is_some() - { - uv.super_visit_with(self) } else { - ControlFlow::CONTINUE + match flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + true if self.tcx.is_some() => UnknownConstSubstsVisitor::search(&self, uv), + _ => ControlFlow::CONTINUE, + } } } #[inline] fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { + let flags = predicate.inner.flags; debug!( - "HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}", - predicate, predicate.inner.flags, self.flags + "HasTypeFlagsVisitor: predicate={:?} flags={:?} self.flags={:?}", + predicate, flags, self.flags ); - if predicate.inner.flags.intersects(self.flags) { + if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) - } else if predicate.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) - && self.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) - && self.tcx.is_some() - { + } else { + match flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + true if self.tcx.is_some() => UnknownConstSubstsVisitor::search(&self, predicate), + _ => ControlFlow::CONTINUE, + } + } + } +} + +struct UnknownConstSubstsVisitor<'tcx> { + tcx: TyCtxt<'tcx>, + flags: ty::TypeFlags, +} + +impl<'tcx> UnknownConstSubstsVisitor<'tcx> { + /// This is fairly cold and we don't want to + /// bloat the size of the `HasTypeFlagsVisitor`. + #[inline(never)] + pub fn search>( + visitor: &HasTypeFlagsVisitor<'tcx>, + v: T, + ) -> ControlFlow { + if visitor.flags.intersects(TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS) { + v.super_visit_with(&mut UnknownConstSubstsVisitor { + tcx: visitor.tcx.unwrap(), + flags: visitor.flags, + }) + } else { + ControlFlow::CONTINUE + } + } +} + +impl<'tcx> TypeVisitor<'tcx> for UnknownConstSubstsVisitor<'tcx> { + type BreakTy = FoundFlags; + fn tcx_for_anon_const_substs(&self) -> Option> { + bug!("we shouldn't call this method as we manually look at ct substs"); + } + + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { + if t.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { + t.super_visit_with(self) + } else { + ControlFlow::CONTINUE + } + } + + #[inline] + fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { + if uv.substs_.is_none() { + self.tcx + .default_anon_const_substs(uv.def.did) + .visit_with(&mut HasTypeFlagsVisitor { tcx: Some(self.tcx), flags: self.flags }) + } else { + ControlFlow::CONTINUE + } + } + + #[inline] + fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { + if predicate.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) { predicate.super_visit_with(self) } else { ControlFlow::CONTINUE From 7cbfa2ee330b6e389027c6276df0f0f9b62fc76b Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 26 Aug 2021 11:04:01 +0200 Subject: [PATCH 171/269] rebase --- .../src/traits/query/normalize.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 21e1bd8f4646..ed5fe466c69f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -78,8 +78,11 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { // The rest of the code is already set up to be lazy about replacing bound vars, // and only when we actually have to normalize. if value.has_escaping_bound_vars() { - let mut max_visitor = - MaxEscapingBoundVarVisitor { outer_index: ty::INNERMOST, escaping: 0 }; + let mut max_visitor = MaxEscapingBoundVarVisitor { + tcx: self.infcx.tcx, + outer_index: ty::INNERMOST, + escaping: 0, + }; value.visit_with(&mut max_visitor); if max_visitor.escaping > 0 { normalizer.universes.extend((0..max_visitor.escaping).map(|_| None)); @@ -106,13 +109,18 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { } /// Visitor to find the maximum escaping bound var -struct MaxEscapingBoundVarVisitor { +struct MaxEscapingBoundVarVisitor<'tcx> { + tcx: TyCtxt<'tcx>, // The index which would count as escaping outer_index: ty::DebruijnIndex, escaping: usize, } -impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor { +impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor<'tcx> { + fn tcx_for_anon_const_substs(&self) -> Option> { + Some(self.tcx) + } + fn visit_binder>( &mut self, t: &ty::Binder<'tcx, T>, From bee13d18af34ce6056a0b76fb7652cafda52cb69 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 26 Aug 2021 12:57:42 +0200 Subject: [PATCH 172/269] add unsized coercion test --- .../unsized/param-mentioned-by-different-field.rs | 10 ++++++++++ .../param-mentioned-by-different-field.stderr | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/ui/unsized/param-mentioned-by-different-field.rs create mode 100644 src/test/ui/unsized/param-mentioned-by-different-field.stderr diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.rs b/src/test/ui/unsized/param-mentioned-by-different-field.rs new file mode 100644 index 000000000000..cda94b306d33 --- /dev/null +++ b/src/test/ui/unsized/param-mentioned-by-different-field.rs @@ -0,0 +1,10 @@ +// We must not allow this with our current setup as `T` +// is mentioned both in the tail of `Foo` and by another +// field. +struct Foo(Box, T); + +fn main() { + let x: Foo<[u8; 1]> = Foo(Box::new([2]), [3]); + let y: &Foo<[u8]> = &x; //~ ERROR mismatched types + assert_eq!(y.0.len(), 1); +} diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.stderr b/src/test/ui/unsized/param-mentioned-by-different-field.stderr new file mode 100644 index 000000000000..d18fa6456f3e --- /dev/null +++ b/src/test/ui/unsized/param-mentioned-by-different-field.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/param-mentioned-by-different-field.rs:8:25 + | +LL | let y: &Foo<[u8]> = &x; + | ---------- ^^ expected slice `[u8]`, found array `[u8; 1]` + | | + | expected due to this + | + = note: expected reference `&Foo<[u8]>` + found reference `&Foo<[u8; 1]>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 84a266149bb212109baa94de98457edddff1bae1 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 6 Aug 2021 14:13:10 -0400 Subject: [PATCH 173/269] Add test for stepping though `match` expressions --- src/test/debuginfo/step-into-match.rs | 383 ++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 src/test/debuginfo/step-into-match.rs diff --git a/src/test/debuginfo/step-into-match.rs b/src/test/debuginfo/step-into-match.rs new file mode 100644 index 000000000000..4a5f7857097a --- /dev/null +++ b/src/test/debuginfo/step-into-match.rs @@ -0,0 +1,383 @@ +// compile-flags: -g +// ignore-android: FIXME(#10381) + +// === GDB TESTS ============================================================== + +// gdb-command: r + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...] Some(42) => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_enum(Some(12)); + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...]Some(_) => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_enum(None); + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...]None => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(1); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]1 => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(2); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]_ => 4, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(0); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]0 => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(-1); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]-1 => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(5, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](5, 12) => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(29, 1); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](29, _) => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(12, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](_, _) => 5 + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(42, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](42, 12) => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(1, 9); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](_, 9) => 4, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]} + +// === CDB TESTS ============================================================== + +// Enable line-based debugging and print lines after stepping. +// cdb-command: .lines -e +// cdb-command: l+s +// cdb-command: l+t + +// cdb-command: g + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: Some(42) => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_enum(Some(12)); + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: Some(_) => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_enum(None); + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: None => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(1); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: 1 => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(2); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: _ => 4, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(0); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: 0 => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(-1); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: -1 => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(5, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (5, 12) => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(29, 1); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (29, _) => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(12, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (_, _) => 5 + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(42, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (42, 12) => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(1, 9); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (_, 9) => 4, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: } + +fn main() { + match_enum(Some(42)); // #break + match_enum(Some(12)); + match_enum(None); + + match_int(1); + match_int(2); + match_int(0); + match_int(-1); + + match_tuple(5, 12); + match_tuple(29, 1); + match_tuple(12, 12); + match_tuple(42, 12); + match_tuple(1, 9); +} + +fn match_enum(x: Option) -> u8 { + match x { + Some(42) => 1, + Some(_) => 2, + None => 3, + } +} + +fn match_int(y: i32) -> u16 { + match y { + -1 => 1, + 0 => 2, + 1 => 3, + _ => 4, + } +} + +fn match_tuple(a: u8, b: i8) -> u32 { + match (a, b) { + (42, 12) => 1, + (29, _) => 2, + (5, 12) => 3, + (_, 9) => 4, + (_, _) => 5 + } +} From 118df1cd6bca455498f6ef0a55133d99dfe99f0d Mon Sep 17 00:00:00 2001 From: 12101111 Date: Sun, 22 Aug 2021 15:54:03 +0800 Subject: [PATCH 174/269] Adjust linking order of static nobundle libraries Link the static libraries with "-bundle" modifier from upstream rust crate right after linking this rust crate. Some linker such as GNU linker `ld.bdf` treat order of linking as order of dependency. After this change, static libraries with "-bundle" modifier is linked in the same order as "+bundle" modifier. So we can change the value of "bundle" modifier without causing linking error. --- compiler/rustc_codegen_ssa/src/back/link.rs | 69 ++++++++++----------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f3eb1e04d07d..e51d6fff7884 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1803,15 +1803,16 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( add_local_native_libraries(cmd, sess, codegen_results); } - // Rust libraries. + // Upstream rust libraries and their nobundle static libraries add_upstream_rust_crates::(cmd, sess, codegen_results, crate_type, tmpdir); - // Native libraries linked with `#[link]` attributes at and `-l` command line options. + // Upstream dymamic native libraries linked with `#[link]` attributes at and `-l` + // command line options. // If -Zlink-native-libraries=false is set, then the assumption is that an // external build system already has the native dependencies defined, and it // will provide them to the linker itself. if sess.opts.debugging_opts.link_native_libraries { - add_upstream_native_libraries(cmd, sess, codegen_results, crate_type); + add_upstream_native_libraries(cmd, sess, codegen_results); } // Library linking above uses some global state for things like `-Bstatic`/`-Bdynamic` to make @@ -2033,7 +2034,7 @@ fn add_local_native_libraries( } } -/// # Rust Crate linking +/// # Linking Rust crates and their nobundle static libraries /// /// Rust crates are not considered at all when creating an rlib output. All dependencies will be /// linked when producing the final output (instead of the intermediate rlib version). @@ -2138,6 +2139,29 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( Linkage::NotLinked | Linkage::IncludedFromDylib => {} Linkage::Static => { add_static_crate::(cmd, sess, codegen_results, tmpdir, crate_type, cnum); + + // Link static native libs with "-bundle" modifier only if the crate they originate from + // is being linked statically to the current crate. If it's linked dynamically + // or is an rlib already included via some other dylib crate, the symbols from + // native libs will have already been included in that dylib. + // + // If -Zlink-native-libraries=false is set, then the assumption is that an + // external build system already has the native dependencies defined, and it + // will provide them to the linker itself. + if sess.opts.debugging_opts.link_native_libraries { + // Skip if this library is the same as the last. + let mut last = None; + for lib in &codegen_results.crate_info.native_libraries[&cnum] { + if lib.name.is_some() + && relevant_lib(sess, lib) + && matches!(lib.kind, NativeLibKind::Static { bundle: Some(false), .. }) + && last != lib.name + { + cmd.link_staticlib(lib.name.unwrap(), lib.verbatim.unwrap_or(false)); + last = lib.name; + } + } + } } Linkage::Dynamic => add_dynamic_crate(cmd, sess, &src.dylib.as_ref().unwrap().0), } @@ -2310,27 +2334,9 @@ fn add_upstream_native_libraries( cmd: &mut dyn Linker, sess: &Session, codegen_results: &CodegenResults, - crate_type: CrateType, ) { - // Be sure to use a topological sorting of crates because there may be - // interdependencies between native libraries. When passing -nodefaultlibs, - // for example, almost all native libraries depend on libc, so we have to - // make sure that's all the way at the right (liblibc is near the base of - // the dependency chain). - // - // This passes RequireStatic, but the actual requirement doesn't matter, - // we're just getting an ordering of crate numbers, we're not worried about - // the paths. - let (_, data) = codegen_results - .crate_info - .dependency_formats - .iter() - .find(|(ty, _)| *ty == crate_type) - .expect("failed to find crate type in dependency format list"); - - let crates = &codegen_results.crate_info.used_crates; let mut last = (NativeLibKind::Unspecified, None); - for &cnum in crates { + for &cnum in &codegen_results.crate_info.used_crates { for lib in codegen_results.crate_info.native_libraries[&cnum].iter() { let name = match lib.name { Some(l) => l, @@ -2352,19 +2358,10 @@ fn add_upstream_native_libraries( NativeLibKind::Framework { as_needed } => { cmd.link_framework(name, as_needed.unwrap_or(true)) } - NativeLibKind::Static { bundle: Some(false), .. } => { - // Link "static-nobundle" native libs only if the crate they originate from - // is being linked statically to the current crate. If it's linked dynamically - // or is an rlib already included via some other dylib crate, the symbols from - // native libs will have already been included in that dylib. - if data[cnum.as_usize() - 1] == Linkage::Static { - cmd.link_staticlib(name, verbatim) - } - } - // ignore statically included native libraries here as we've - // already included them when we included the rust library - // previously - NativeLibKind::Static { bundle: None | Some(true), .. } => {} + // ignore static native libraries here as we've + // already included them in add_local_native_libraries and + // add_upstream_rust_crates + NativeLibKind::Static { .. } => {} NativeLibKind::RawDylib => {} } } From 4924e34526cc8098d36ad60ed974dbe6484ac519 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 12:49:39 -0300 Subject: [PATCH 175/269] Add argument types tait tests --- .../type-alias-impl-trait/argument-types.rs | 28 +++++++++++++++++++ .../argument-types.stderr | 15 ++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/argument-types.rs create mode 100644 src/test/ui/type-alias-impl-trait/argument-types.stderr diff --git a/src/test/ui/type-alias-impl-trait/argument-types.rs b/src/test/ui/type-alias-impl-trait/argument-types.rs new file mode 100644 index 000000000000..8427b5b1fe85 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/argument-types.rs @@ -0,0 +1,28 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type Foo = impl Debug; + +// FIXME: This should compile, but it currently doesn't +fn foo1(mut x: Foo) { + x = 22_u32; + //~^ ERROR: mismatched types [E0308] +} + +fn foo2(mut x: Foo) { + // no constraint on x +} + +fn foo3(x: Foo) { + println!("{:?}", x); +} + +fn foo_value() -> Foo { + 11_u32 +} + +fn main() { + foo3(foo_value()); +} diff --git a/src/test/ui/type-alias-impl-trait/argument-types.stderr b/src/test/ui/type-alias-impl-trait/argument-types.stderr new file mode 100644 index 000000000000..1cbf9c95d314 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/argument-types.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/argument-types.rs:10:9 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | x = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 027db5d036768ba8b0e36cb1b9f3f0ed1e3da000 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 24 Aug 2021 09:44:17 -0400 Subject: [PATCH 176/269] RustWrapper: adapt to LLVM change 0f45c16f2caa The above-mentioned commit (part of the LLVM 14 development cycle) removes a method that rustc uses somewhat extensively. We mostly switch to lower-level methods that exist in all versions of LLVM we use, so no new ifdef logic is required in most cases. --- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 4edfed034018..4f07a0c67c13 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -270,34 +270,30 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, LLVMRustAttribute RustAttr) { Function *A = unwrap(Fn); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); - AttrBuilder B(Attr); - A->addAttributes(Index, B); + A->addAttribute(Index, Attr); } extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, unsigned Index, uint32_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addAlignmentAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithAlignment( + A->getContext(), llvm::Align(Bytes))); } extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, uint64_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addDereferenceableAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(), + Bytes)); } extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, unsigned Index, uint64_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addDereferenceableOrNullAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes( + A->getContext(), Bytes)); } extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index, @@ -323,9 +319,8 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, const char *Name, const char *Value) { Function *F = unwrap(Fn); - AttrBuilder B; - B.addAttribute(Name, Value); - F->addAttributes(Index, B); + F->addAttribute(Index, Attribute::get( + F->getContext(), StringRef(Name), StringRef(Value))); } extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, From 97bf80dfda3627175b21bade3ba8e51b512c2186 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Tue, 24 Aug 2021 20:50:09 -0400 Subject: [PATCH 177/269] Treat types in unnormalized function signatures as well-formed --- .../type_check/free_region_relations.rs | 19 ++++++++++-- .../rustc_typeck/src/check/compare_method.rs | 12 +++++++- compiler/rustc_typeck/src/check/mod.rs | 16 +++++++--- compiler/rustc_typeck/src/check/regionck.rs | 11 ++++++- compiler/rustc_typeck/src/check/wfcheck.rs | 11 ++++++- .../generic-associated-types/issue-87748.rs | 30 +++++++++++++++++++ 6 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/generic-associated-types/issue-87748.rs diff --git a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs b/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs index 012d67255d13..6426098d843f 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs @@ -256,6 +256,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> { let constraint_sets: Vec<_> = unnormalized_input_output_tys .flat_map(|ty| { debug!("build: input_or_output={:?}", ty); + // We add implied bounds from both the unnormalized and normalized ty + // See issue #87748 + let constraints_implied_1 = self.add_implied_bounds(ty); let TypeOpOutput { output: ty, constraints: constraints1, .. } = self .param_env .and(type_op::normalize::Normalize::new(ty)) @@ -271,9 +274,21 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> { canonicalized_query: None, } }); - let constraints2 = self.add_implied_bounds(ty); + // Note: we need this in examples like + // ``` + // trait Foo { + // type Bar; + // fn foo(&self) -> &Self::Bar; + // } + // impl Foo for () { + // type Bar = (); + // fn foo(&self) ->&() {} + // } + // ``` + // Both &Self::Bar and &() are WF + let constraints_implied_2 = self.add_implied_bounds(ty); normalized_inputs_and_output.push(ty); - constraints1.into_iter().chain(constraints2) + constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2) }) .collect(); diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index c384e0dcb2ca..d59291b8fd49 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -250,6 +250,8 @@ fn compare_predicate_entailment<'tcx>( // Compute placeholder form of impl and trait method tys. let tcx = infcx.tcx; + let mut wf_tys = vec![]; + let (impl_sig, _) = infcx.replace_bound_vars_with_fresh_vars( impl_m_span, infer::HigherRankedType, @@ -260,10 +262,18 @@ fn compare_predicate_entailment<'tcx>( let impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(impl_sig)); debug!("compare_impl_method: impl_fty={:?}", impl_fty); + // First liberate late bound regions and subst placeholders let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id)); let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs); + // Next, add all inputs and output as well-formed tys. Importantly, + // we have to do this before normalization, since the normalized ty may + // not contain the input parameters. See issue #87748. + wf_tys.extend(trait_sig.inputs_and_output.iter()); let trait_sig = inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig); + // Also add the resulting inputs and output as well-formed. + // This probably isn't strictly necessary. + wf_tys.extend(trait_sig.inputs_and_output.iter()); let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig)); debug!("compare_impl_method: trait_fty={:?}", trait_fty); @@ -388,7 +398,7 @@ fn compare_predicate_entailment<'tcx>( // Finally, resolve all regions. This catches wily misuses of // lifetime parameters. let fcx = FnCtxt::new(&inh, param_env, impl_m_hir_id); - fcx.regionck_item(impl_m_hir_id, impl_m_span, trait_sig.inputs_and_output); + fcx.regionck_item(impl_m_hir_id, impl_m_span, &wf_tys); Ok(()) }) diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index a88b1c7af5a9..803c440bbc98 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -364,7 +364,7 @@ fn typeck_with_fallback<'tcx>( let typeck_results = Inherited::build(tcx, def_id).enter(|inh| { let param_env = tcx.param_env(def_id); - let fcx = if let Some(hir::FnSig { header, decl, .. }) = fn_sig { + let (fcx, wf_tys) = if let Some(hir::FnSig { header, decl, .. }) = fn_sig { let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() { let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); >::ty_of_fn( @@ -383,17 +383,25 @@ fn typeck_with_fallback<'tcx>( check_abi(tcx, id, span, fn_sig.abi()); + // When normalizing the function signature, we assume all types are + // well-formed. So, we don't need to worry about the obligations + // from normalization. We could just discard these, but to align with + // compare_method and elsewhere, we just add implied bounds for + // these types. + let mut wf_tys = vec![]; // Compute the fty from point of view of inside the fn. let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig); + wf_tys.extend(fn_sig.inputs_and_output.iter()); let fn_sig = inh.normalize_associated_types_in( body.value.span, body_id.hir_id, param_env, fn_sig, ); + wf_tys.extend(fn_sig.inputs_and_output.iter()); let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0; - fcx + (fcx, wf_tys) } else { let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); let expected_type = body_ty @@ -443,7 +451,7 @@ fn typeck_with_fallback<'tcx>( fcx.write_ty(id, expected_type); - fcx + (fcx, vec![]) }; let fallback_has_occurred = fcx.type_inference_fallback(); @@ -467,7 +475,7 @@ fn typeck_with_fallback<'tcx>( fcx.select_all_obligations_or_error(); if fn_sig.is_some() { - fcx.regionck_fn(id, body); + fcx.regionck_fn(id, body, span, &wf_tys); } else { fcx.regionck_expr(body); } diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index ca6828cfdf68..290fa5fc3671 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -144,11 +144,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// rest of type check and because sometimes we need type /// inference to have completed before we can determine which /// constraints to add. - pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) { + pub(crate) fn regionck_fn( + &self, + fn_id: hir::HirId, + body: &'tcx hir::Body<'tcx>, + span: Span, + wf_tys: &[Ty<'tcx>], + ) { debug!("regionck_fn(id={})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); let hir_id = body.value.hir_id; let mut rcx = RegionCtxt::new(self, hir_id, Subject(subject), self.param_env); + // We need to add the implied bounds from the function signature + rcx.outlives_environment.add_implied_bounds(self, wf_tys, fn_id, span); + rcx.outlives_environment.save_implied_bounds(fn_id); if !self.errors_reported_since_creation() { // regionck assumes typeck succeeded diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index b82437096592..0ac265396e3d 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -908,6 +908,7 @@ fn check_where_clauses<'tcx, 'fcx>( } } +#[tracing::instrument(level = "debug", skip(fcx, span, hir_decl))] fn check_fn_or_method<'fcx, 'tcx>( fcx: &FnCtxt<'fcx, 'tcx>, span: Span, @@ -918,6 +919,11 @@ fn check_fn_or_method<'fcx, 'tcx>( ) { let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig); + // Unnormalized types in signature are WF too + implied_bounds.extend(sig.inputs()); + // FIXME(#27579) return types should not be implied bounds + implied_bounds.push(sig.output()); + // Normalize the input and output types one at a time, using a different // `WellFormedLoc` for each. We cannot call `normalize_associated_types` // on the entire `FnSig`, since this would use the same `WellFormedLoc` @@ -967,9 +973,11 @@ fn check_fn_or_method<'fcx, 'tcx>( ObligationCauseCode::ReturnType, ); - // FIXME(#25759) return types should not be implied bounds + // FIXME(#27579) return types should not be implied bounds implied_bounds.push(sig.output()); + debug!(?implied_bounds); + check_where_clauses(fcx, span, def_id, Some((sig.output(), hir_decl.output.span()))); } @@ -1116,6 +1124,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one \ of the previous types except `Self`)"; +#[tracing::instrument(level = "debug", skip(fcx))] fn check_method_receiver<'fcx, 'tcx>( fcx: &FnCtxt<'fcx, 'tcx>, fn_sig: &hir::FnSig<'_>, diff --git a/src/test/ui/generic-associated-types/issue-87748.rs b/src/test/ui/generic-associated-types/issue-87748.rs new file mode 100644 index 000000000000..93c3b3937cb8 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-87748.rs @@ -0,0 +1,30 @@ +// Checks that we properly add implied bounds from unnormalized projections in +// inputs when typechecking functions. + +// check-pass + +#![feature(generic_associated_types)] + +trait MyTrait { + type Assoc<'a, 'b> where 'b: 'a; + fn do_sth(arg: Self::Assoc<'_, '_>); +} + +struct A; +struct B; +struct C; + +impl MyTrait for A { + type Assoc<'a, 'b> where 'b: 'a = u32; + fn do_sth(_: u32) {} +} +impl MyTrait for B { + type Assoc<'a, 'b> where 'b: 'a = u32; + fn do_sth(_: Self::Assoc<'_, '_>) {} +} +impl MyTrait for C { + type Assoc<'a, 'b> where 'b: 'a = u32; + fn do_sth(_: Self::Assoc<'static, 'static>) {} +} + +fn main () {} From c60a370dac4821d0a1a4d55943e28c2da2220dc7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 21 Aug 2021 20:14:56 +0000 Subject: [PATCH 178/269] Fix the bugs and add a regression test - All attributes for an item need to be considered at once, they can't be considered a line at a time. - The top-level crate was not being visited. This bug was caught by `extern-crate-used-only-in-link`, which I'm very glad I added. - Make the loader private to the module, so that only one function is exposed. --- src/librustdoc/core.rs | 6 +-- .../passes/collect_intra_doc_links.rs | 2 +- .../passes/collect_intra_doc_links/early.rs | 44 ++++++++++++------- .../rustdoc/intra-doc/auxiliary/pub-struct.rs | 1 + .../intra-doc/extern-reference-link.rs | 7 +++ 5 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/test/rustdoc/intra-doc/auxiliary/pub-struct.rs create mode 100644 src/test/rustdoc/intra-doc/extern-reference-link.rs diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 249febb72bc5..4d498e6dbdb5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,4 +1,3 @@ -use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; @@ -307,10 +306,7 @@ crate fn create_resolver<'a>( let (krate, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek(); let resolver = resolver.clone(); - let mut loader = crate::passes::collect_intra_doc_links::IntraLinkCrateLoader::new(resolver); - ast::visit::walk_crate(&mut loader, krate); - - loader.resolver + crate::passes::collect_intra_doc_links::load_intra_link_crates(resolver, krate) } crate fn run_global_ctxt( diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b909f6b26954..178c8c15a158 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -38,7 +38,7 @@ use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::passes::Pass; mod early; -crate use early::IntraLinkCrateLoader; +crate use early::load_intra_link_crates; crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass { name: "collect-intra-doc-links", diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index 7cba2523d1a3..cd90528ab9c8 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -1,34 +1,41 @@ use rustc_ast as ast; use rustc_hir::def::Namespace::TypeNS; -use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_interface::interface; +use rustc_span::Span; use std::cell::RefCell; use std::mem; use std::rc::Rc; +type Resolver = Rc>; // Letting the resolver escape at the end of the function leads to inconsistencies between the // crates the TyCtxt sees and the resolver sees (because the resolver could load more crates // after escaping). Hopefully `IntraLinkCrateLoader` gets all the crates we need ... -crate struct IntraLinkCrateLoader { - current_mod: DefId, - crate resolver: Rc>, +crate fn load_intra_link_crates(resolver: Resolver, krate: &ast::Crate) -> Resolver { + let mut loader = IntraLinkCrateLoader { current_mod: CRATE_DEF_ID, resolver }; + // `walk_crate` doesn't visit the crate itself for some reason. + loader.load_links_in_attrs(&krate.attrs, krate.span); + ast::visit::walk_crate(&mut loader, krate); + loader.resolver } -impl IntraLinkCrateLoader { - crate fn new(resolver: Rc>) -> Self { - let crate_id = LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(); - Self { current_mod: crate_id, resolver } - } +struct IntraLinkCrateLoader { + current_mod: LocalDefId, + resolver: Rc>, } -impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { - fn visit_attribute(&mut self, attr: &ast::Attribute) { +impl IntraLinkCrateLoader { + fn load_links_in_attrs(&mut self, attrs: &[ast::Attribute], span: Span) { use crate::html::markdown::markdown_links; use crate::passes::collect_intra_doc_links::preprocess_link; - if let Some(doc) = attr.doc_str() { + // FIXME: this probably needs to consider inlining + let attrs = crate::clean::Attributes::from_ast(attrs, None); + for (parent_module, doc) in attrs.collapsed_doc_value_by_module_level() { + debug!(?doc); for link in markdown_links(&doc.as_str()) { + debug!(?link.link); let path_str = if let Some(Ok(x)) = preprocess_link(&link) { x.path_str } else { @@ -36,27 +43,32 @@ impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { }; self.resolver.borrow_mut().access(|resolver| { let _ = resolver.resolve_str_path_error( - attr.span, + span, &path_str, TypeNS, - self.current_mod, + parent_module.unwrap_or(self.current_mod.to_def_id()), ); }); } } - ast::visit::walk_attribute(self, attr); } +} +impl ast::visit::Visitor<'_> for IntraLinkCrateLoader { fn visit_item(&mut self, item: &ast::Item) { use rustc_ast_lowering::ResolverAstLowering; if let ast::ItemKind::Mod(..) = item.kind { let new_mod = self.resolver.borrow_mut().access(|resolver| resolver.local_def_id(item.id)); - let old_mod = mem::replace(&mut self.current_mod, new_mod.to_def_id()); + let old_mod = mem::replace(&mut self.current_mod, new_mod); + + self.load_links_in_attrs(&item.attrs, item.span); ast::visit::walk_item(self, item); + self.current_mod = old_mod; } else { + self.load_links_in_attrs(&item.attrs, item.span); ast::visit::walk_item(self, item); } } diff --git a/src/test/rustdoc/intra-doc/auxiliary/pub-struct.rs b/src/test/rustdoc/intra-doc/auxiliary/pub-struct.rs new file mode 100644 index 000000000000..75d4289321ca --- /dev/null +++ b/src/test/rustdoc/intra-doc/auxiliary/pub-struct.rs @@ -0,0 +1 @@ +pub struct SomeStruct; diff --git a/src/test/rustdoc/intra-doc/extern-reference-link.rs b/src/test/rustdoc/intra-doc/extern-reference-link.rs new file mode 100644 index 000000000000..bad6ec755798 --- /dev/null +++ b/src/test/rustdoc/intra-doc/extern-reference-link.rs @@ -0,0 +1,7 @@ +// compile-flags: --extern pub_struct +// aux-build:pub-struct.rs + +/// [SomeStruct] +/// +/// [SomeStruct]: pub_struct::SomeStruct +pub fn foo() {} From 24526bbe779b552c3323f3ee1046b534f0888be7 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 26 Aug 2021 20:20:08 +0300 Subject: [PATCH 179/269] compiletest: allow `.` in remote test paths (can arise from revisions). --- src/tools/compiletest/src/runtest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f291918225f4..51a4d74109a6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3227,7 +3227,7 @@ impl<'test> TestCx<'test> { // so it needs to be removed when comparing the run-pass test execution output lazy_static! { static ref REMOTE_TEST_RE: Regex = Regex::new( - "^uploaded \"\\$TEST_BUILD_DIR(/[[:alnum:]_\\-]+)+\", waiting for result\n" + "^uploaded \"\\$TEST_BUILD_DIR(/[[:alnum:]_\\-.]+)+\", waiting for result\n" ) .unwrap(); } From efb4148865f9332c5d7d9c81202be9470fa336eb Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 25 Aug 2021 15:53:08 +0300 Subject: [PATCH 180/269] `#[inline]` non-generic `pub fn`s in `rustc_target::abi` and `ty::layout`. --- compiler/rustc_middle/src/ty/layout.rs | 10 ++++++++++ compiler/rustc_target/src/abi/mod.rs | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 1429769e8f2b..03c0bb79d685 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -42,6 +42,7 @@ pub trait IntegerExt { } impl IntegerExt for Integer { + #[inline] fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> { match (*self, signed) { (I8, false) => tcx.types.u8, @@ -149,6 +150,7 @@ pub trait PrimitiveExt { } impl PrimitiveExt for Primitive { + #[inline] fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { Int(i, signed) => i.to_ty(tcx, signed), @@ -160,6 +162,7 @@ impl PrimitiveExt for Primitive { /// Return an *integer* type matching this primitive. /// Useful in particular when dealing with enum discriminants. + #[inline] fn to_int_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { Int(i, signed) => i.to_ty(tcx, signed), @@ -2016,12 +2019,14 @@ pub trait HasParamEnv<'tcx> { } impl<'tcx> HasDataLayout for TyCtxt<'tcx> { + #[inline] fn data_layout(&self) -> &TargetDataLayout { &self.data_layout } } impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> { + #[inline] fn tcx(&self) -> TyCtxt<'tcx> { *self } @@ -2053,6 +2058,7 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode, and will normalize the input type. + #[inline] fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx.layout_of(self.param_env.and(ty)) } @@ -2064,6 +2070,7 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode, and will normalize the input type. + #[inline] fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { self.tcx.layout_of(self.param_env.and(ty)) } @@ -2414,6 +2421,7 @@ where } impl<'a, 'tcx> HashStable> for LayoutError<'tcx> { + #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::LayoutError::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2604,6 +2612,7 @@ where /// compiled with `-Cpanic=unwind` and referenced from another crate compiled /// with `-Cpanic=abort` will look like they can't unwind when in fact they /// might (from a foreign exception or similar). +#[inline] pub fn fn_can_unwind( tcx: TyCtxt<'tcx>, codegen_fn_attr_flags: CodegenFnAttrFlags, @@ -2679,6 +2688,7 @@ pub fn fn_can_unwind( } } +#[inline] pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv { use rustc_target::spec::abi::Abi::*; match tcx.sess.target.adjust_abi(abi) { diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 00b1b5950220..2820a486dfd4 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -194,6 +194,7 @@ impl TargetDataLayout { /// to represent object size in bits. It would need to be 1 << 61 to account for this, but is /// currently conservatively bounded to 1 << 47 as that is enough to cover the current usable /// address space on 64-bit ARMv8 and x86_64. + #[inline] pub fn obj_size_bound(&self) -> u64 { match self.pointer_size.bits() { 16 => 1 << 15, @@ -203,6 +204,7 @@ impl TargetDataLayout { } } + #[inline] pub fn ptr_sized_integer(&self) -> Integer { match self.pointer_size.bits() { 16 => I16, @@ -212,6 +214,7 @@ impl TargetDataLayout { } } + #[inline] pub fn vector_align(&self, vec_size: Size) -> AbiAndPrefAlign { for &(size, align) in &self.vector_align { if size == vec_size { @@ -562,14 +565,17 @@ pub struct AbiAndPrefAlign { } impl AbiAndPrefAlign { + #[inline] pub fn new(align: Align) -> AbiAndPrefAlign { AbiAndPrefAlign { abi: align, pref: align } } + #[inline] pub fn min(self, other: AbiAndPrefAlign) -> AbiAndPrefAlign { AbiAndPrefAlign { abi: self.abi.min(other.abi), pref: self.pref.min(other.pref) } } + #[inline] pub fn max(self, other: AbiAndPrefAlign) -> AbiAndPrefAlign { AbiAndPrefAlign { abi: self.abi.max(other.abi), pref: self.pref.max(other.pref) } } @@ -586,6 +592,7 @@ pub enum Integer { } impl Integer { + #[inline] pub fn size(self) -> Size { match self { I8 => Size::from_bytes(1), @@ -609,6 +616,7 @@ impl Integer { } /// Finds the smallest Integer type which can represent the signed value. + #[inline] pub fn fit_signed(x: i128) -> Integer { match x { -0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8, @@ -620,6 +628,7 @@ impl Integer { } /// Finds the smallest Integer type which can represent the unsigned value. + #[inline] pub fn fit_unsigned(x: u128) -> Integer { match x { 0..=0x0000_0000_0000_00ff => I8, @@ -655,6 +664,9 @@ impl Integer { I8 } + // FIXME(eddyb) consolidate this and other methods that find the appropriate + // `Integer` given some requirements. + #[inline] fn from_size(size: Size) -> Result { match size.bits() { 8 => Ok(Integer::I8), @@ -706,10 +718,14 @@ impl Primitive { } } + // FIXME(eddyb) remove, it's trivial thanks to `matches!`. + #[inline] pub fn is_float(self) -> bool { matches!(self, F32 | F64) } + // FIXME(eddyb) remove, it's completely unused. + #[inline] pub fn is_int(self) -> bool { matches!(self, Int(..)) } @@ -786,6 +802,7 @@ pub struct Scalar { } impl Scalar { + #[inline] pub fn is_bool(&self) -> bool { matches!(self.value, Int(I8, false)) && matches!(self.valid_range, WrappingRange { start: 0, end: 1 }) @@ -852,6 +869,7 @@ pub enum FieldsShape { } impl FieldsShape { + #[inline] pub fn count(&self) -> usize { match *self { FieldsShape::Primitive => 0, @@ -861,6 +879,7 @@ impl FieldsShape { } } + #[inline] pub fn offset(&self, i: usize) -> Size { match *self { FieldsShape::Primitive => { @@ -884,6 +903,7 @@ impl FieldsShape { } } + #[inline] pub fn memory_index(&self, i: usize) -> usize { match *self { FieldsShape::Primitive => { @@ -967,6 +987,7 @@ impl Abi { } /// Returns `true` if this is a single signed integer scalar + #[inline] pub fn is_signed(&self) -> bool { match *self { Abi::Scalar(ref scal) => match scal.value { From 167ee54904b9acdd5cb8a6b89738b9df53999288 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Aug 2021 19:16:44 -0700 Subject: [PATCH 181/269] Update cargo --- Cargo.lock | 4 ++-- src/tools/cargo | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e6b11032ab2..cef4f11da801 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -871,9 +871,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.44+curl-7.77.0" +version = "0.4.45+curl-7.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6d85e9322b193f117c966e79c2d6929ec08c02f339f950044aba12e20bbaf1" +checksum = "de9e5a72b1c744eb5dd20b2be4d7eb84625070bb5c4ab9b347b70464ab1e62eb" dependencies = [ "cc", "libc", diff --git a/src/tools/cargo b/src/tools/cargo index e96bdb0c3d0a..f559c109cc79 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit e96bdb0c3d0a418e7fcd7fbd69be08abf830b4bc +Subproject commit f559c109cc79fe413a8535fb620a5a58b3823d94 From 8660832086db649e5a7e489ab40f303fa3f6638e Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 25 Aug 2021 11:53:16 +0000 Subject: [PATCH 182/269] Introduce `~const` - [x] Removed `?const` and change uses of `?const` - [x] Added `~const` to the AST. It is gated behind const_trait_impl. - [x] Validate `~const` in ast_validation. - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and `ConstIfConst` allowing future extensions) - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`. - [ ] Optional steps (*for this PR, obviously*) - [ ] Fix #88155 - [ ] Do something with constness bounds in chalk --- compiler/rustc_ast/src/ast.rs | 6 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- .../rustc_ast_passes/src/ast_validation.rs | 152 ++++++++++++------ compiler/rustc_ast_passes/src/feature_gate.rs | 1 - compiler/rustc_feature/src/active.rs | 3 - compiler/rustc_feature/src/removed.rs | 3 + compiler/rustc_middle/src/ty/mod.rs | 7 +- compiler/rustc_parse/src/parser/ty.rs | 46 +++--- compiler/rustc_typeck/src/collect.rs | 8 +- src/librustdoc/html/format.rs | 2 +- src/test/ui/consts/const-eval/issue-49296.rs | 13 +- .../call-generic-method-nonconst-opt-out.rs | 4 +- .../tilde-const-on-non-const-fn.rs | 12 ++ .../tilde-const-on-non-const-fn.stderr | 18 +++ src/tools/rustfmt/src/types.rs | 4 +- src/tools/rustfmt/tests/target/type.rs | 22 ++- 16 files changed, 178 insertions(+), 125 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 2c2d30d872e2..2b86128b3f79 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -284,7 +284,7 @@ impl ParenthesizedArgs { pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; -/// A modifier on a bound, e.g., `?Sized` or `?const Trait`. +/// A modifier on a bound, e.g., `?Sized` or `~const Trait`. /// /// Negative bounds should also be handled here. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] @@ -295,10 +295,10 @@ pub enum TraitBoundModifier { /// `?Trait` Maybe, - /// `?const Trait` + /// `~const Trait` MaybeConst, - /// `?const ?Trait` + /// `~const ?Trait` // // This parses but will be rejected during AST validation. MaybeConstMaybe, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 7b0188755710..948d74e3bf8e 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1414,7 +1414,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ref ty, TraitBoundModifier::None | TraitBoundModifier::MaybeConst, ) => Some(this.lower_poly_trait_ref(ty, itctx.reborrow())), - // `?const ?Bound` will cause an error during AST validation + // `~const ?Bound` will cause an error during AST validation // anyways, so treat it like `?Bound` as compilation proceeds. GenericBound::Trait( _, diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index cff1b70dda90..2658971ecb0e 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -17,10 +17,11 @@ use rustc_errors::{error_code, pluralize, struct_span_err, Applicability}; use rustc_parse::validate_attr; use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY; use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; -use rustc_session::Session; +use rustc_session::{DiagnosticMessageId, Session}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; +use std::convert::TryInto; use std::mem; use std::ops::DerefMut; @@ -33,24 +34,6 @@ enum SelfSemantic { No, } -/// A syntactic context that disallows certain kinds of bounds (e.g., `?Trait` or `?const Trait`). -#[derive(Clone, Copy)] -enum BoundContext { - ImplTrait, - TraitBounds, - TraitObject, -} - -impl BoundContext { - fn description(&self) -> &'static str { - match self { - Self::ImplTrait => "`impl Trait`", - Self::TraitBounds => "supertraits", - Self::TraitObject => "trait objects", - } - } -} - struct AstValidator<'a> { session: &'a Session, @@ -60,6 +43,8 @@ struct AstValidator<'a> { /// Are we inside a trait impl? in_trait_impl: bool, + in_const_trait_impl: bool, + has_proc_macro_decls: bool, /// Used to ban nested `impl Trait`, e.g., `impl Into`. @@ -67,11 +52,7 @@ struct AstValidator<'a> { /// e.g., `impl Iterator`. outer_impl_trait: Option, - /// Keeps track of the `BoundContext` as we recurse. - /// - /// This is used to forbid `?const Trait` bounds in, e.g., - /// `impl Iterator`. - bound_context: Option, + is_tilde_const_allowed: bool, /// Used to ban `impl Trait` in path projections like `::Item` /// or `Foo::Bar` @@ -88,10 +69,18 @@ struct AstValidator<'a> { } impl<'a> AstValidator<'a> { - fn with_in_trait_impl(&mut self, is_in: bool, f: impl FnOnce(&mut Self)) { + fn with_in_trait_impl( + &mut self, + is_in: bool, + constness: Option, + f: impl FnOnce(&mut Self), + ) { let old = mem::replace(&mut self.in_trait_impl, is_in); + let old_const = + mem::replace(&mut self.in_const_trait_impl, matches!(constness, Some(Const::Yes(_)))); f(self); self.in_trait_impl = old; + self.in_const_trait_impl = old_const; } fn with_banned_impl_trait(&mut self, f: impl FnOnce(&mut Self)) { @@ -100,6 +89,18 @@ impl<'a> AstValidator<'a> { self.is_impl_trait_banned = old; } + fn with_tilde_const_allowed(&mut self, f: impl FnOnce(&mut Self)) { + let old = mem::replace(&mut self.is_tilde_const_allowed, true); + f(self); + self.is_tilde_const_allowed = old; + } + + fn with_banned_tilde_const(&mut self, f: impl FnOnce(&mut Self)) { + let old = mem::replace(&mut self.is_tilde_const_allowed, false); + f(self); + self.is_tilde_const_allowed = old; + } + fn with_let_allowed(&mut self, allowed: bool, f: impl FnOnce(&mut Self, bool)) { let old = mem::replace(&mut self.is_let_allowed, allowed); f(self, old); @@ -130,19 +131,13 @@ impl<'a> AstValidator<'a> { fn with_impl_trait(&mut self, outer: Option, f: impl FnOnce(&mut Self)) { let old = mem::replace(&mut self.outer_impl_trait, outer); if outer.is_some() { - self.with_bound_context(BoundContext::ImplTrait, |this| f(this)); + self.with_banned_tilde_const(f); } else { - f(self) + f(self); } self.outer_impl_trait = old; } - fn with_bound_context(&mut self, ctx: BoundContext, f: impl FnOnce(&mut Self)) { - let old = self.bound_context.replace(ctx); - f(self); - self.bound_context = old; - } - fn visit_assoc_ty_constraint_from_generic_args(&mut self, constraint: &'a AssocTyConstraint) { match constraint.kind { AssocTyConstraintKind::Equality { .. } => {} @@ -164,9 +159,7 @@ impl<'a> AstValidator<'a> { TyKind::ImplTrait(..) => { self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t)) } - TyKind::TraitObject(..) => { - self.with_bound_context(BoundContext::TraitObject, |this| visit::walk_ty(this, t)); - } + TyKind::TraitObject(..) => self.with_banned_tilde_const(|this| visit::walk_ty(this, t)), TyKind::Path(ref qself, ref path) => { // We allow these: // - `Option` @@ -1083,13 +1076,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { unsafety, polarity, defaultness: _, - constness: _, - generics: _, + constness, + ref generics, of_trait: Some(ref t), ref self_ty, - items: _, + ref items, }) => { - self.with_in_trait_impl(true, |this| { + self.with_in_trait_impl(true, Some(constness), |this| { this.invalid_visibility(&item.vis, None); if let TyKind::Err = self_ty.kind { this.err_handler() @@ -1112,7 +1105,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> { .emit(); } - visit::walk_item(this, item); + this.visit_vis(&item.vis); + this.visit_ident(item.ident); + if let Const::Yes(_) = constness { + this.with_tilde_const_allowed(|this| this.visit_generics(generics)); + } else { + this.visit_generics(generics); + } + this.visit_trait_ref(t); + this.visit_ty(self_ty); + + walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl); }); return; // Avoid visiting again. } @@ -1157,13 +1160,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> { .emit(); } } - ItemKind::Fn(box FnKind(def, _, _, ref body)) => { + ItemKind::Fn(box FnKind(def, ref sig, ref generics, ref body)) => { self.check_defaultness(item.span, def); if body.is_none() { let msg = "free function without a body"; self.error_item_without_body(item.span, "function", msg, " { }"); } + self.visit_vis(&item.vis); + self.visit_ident(item.ident); + if let Const::Yes(_) = sig.header.constness { + self.with_tilde_const_allowed(|this| this.visit_generics(generics)); + } else { + self.visit_generics(generics); + } + let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, body.as_deref()); + self.visit_fn(kind, item.span, item.id); + walk_list!(self, visit_attribute, &item.attrs); } ItemKind::ForeignMod(ForeignMod { unsafety, .. }) => { let old_item = mem::replace(&mut self.extern_mod, Some(item)); @@ -1206,9 +1219,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.visit_vis(&item.vis); self.visit_ident(item.ident); self.visit_generics(generics); - self.with_bound_context(BoundContext::TraitBounds, |this| { - walk_list!(this, visit_param_bound, bounds); - }); + self.with_banned_tilde_const(|this| walk_list!(this, visit_param_bound, bounds)); walk_list!(self, visit_assoc_item, trait_items, AssocCtxt::Trait); walk_list!(self, visit_attribute, &item.attrs); return; @@ -1281,7 +1292,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { _ => {} } - visit::walk_item(self, item) + visit::walk_item(self, item); } fn visit_foreign_item(&mut self, fi: &'a ForeignItem) { @@ -1428,15 +1439,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> { fn visit_param_bound(&mut self, bound: &'a GenericBound) { match bound { GenericBound::Trait(_, TraitBoundModifier::MaybeConst) => { - if let Some(ctx) = self.bound_context { - let msg = format!("`?const` is not permitted in {}", ctx.description()); - self.err_handler().span_err(bound.span(), &msg); + if !self.is_tilde_const_allowed { + let msg = "`~const` is not allowed here"; + let id_span_msg = ( + DiagnosticMessageId::StabilityId(67792.try_into().ok()), + Some(bound.span()), + msg.to_owned(), + ); + let fresh = self.session.one_time_diagnostics.borrow_mut().insert(id_span_msg); + if fresh { + self.err_handler() + .struct_span_err(bound.span(), msg) + .note("only allowed on bounds on traits' associated types, const fns, const impls and its associated functions") + .emit(); + } } } GenericBound::Trait(_, TraitBoundModifier::MaybeConstMaybe) => { self.err_handler() - .span_err(bound.span(), "`?const` and `?` are mutually exclusive"); + .span_err(bound.span(), "`~const` and `?` are mutually exclusive"); } _ => {} @@ -1589,7 +1611,32 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.check_item_named(item.ident, "const"); } - self.with_in_trait_impl(false, |this| visit::walk_assoc_item(this, item, ctxt)); + match item.kind { + AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref ty)) + if ctxt == AssocCtxt::Trait => + { + self.visit_vis(&item.vis); + self.visit_ident(item.ident); + walk_list!(self, visit_attribute, &item.attrs); + self.with_tilde_const_allowed(|this| { + this.visit_generics(generics); + walk_list!(this, visit_param_bound, bounds); + }); + walk_list!(self, visit_ty, ty); + } + AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, ref body)) + if self.in_const_trait_impl => + { + self.visit_vis(&item.vis); + self.visit_ident(item.ident); + self.with_tilde_const_allowed(|this| this.visit_generics(generics)); + let kind = + FnKind::Fn(FnCtxt::Assoc(ctxt), item.ident, sig, &item.vis, body.as_deref()); + self.visit_fn(kind, item.span, item.id); + } + _ => self + .with_in_trait_impl(false, None, |this| visit::walk_assoc_item(this, item, ctxt)), + } } } @@ -1683,9 +1730,10 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) -> session, extern_mod: None, in_trait_impl: false, + in_const_trait_impl: false, has_proc_macro_decls: false, outer_impl_trait: None, - bound_context: None, + is_tilde_const_allowed: false, is_impl_trait_banned: false, is_assoc_ty_bound_banned: false, is_let_allowed: false, diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 0be26b6f8e9d..557271e32adb 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -656,7 +656,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { gate_all!(more_qualified_paths, "usage of qualified paths in this context is experimental"); gate_all!(generators, "yield syntax is experimental"); gate_all!(raw_ref_op, "raw address of syntax is experimental"); - gate_all!(const_trait_bound_opt_out, "`?const` on trait bounds is experimental"); gate_all!(const_trait_impl, "const trait impls are experimental"); gate_all!(half_open_range_patterns, "half-open range patterns are unstable"); gate_all!(inline_const, "inline-const is experimental"); diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 4f4baf2877df..5ae106353da6 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -515,9 +515,6 @@ declare_features! ( /// Allows `impl const Trait for T` syntax. (active, const_trait_impl, "1.42.0", Some(67792), None), - /// Allows `T: ?const Trait` syntax in bounds. - (incomplete, const_trait_bound_opt_out, "1.42.0", Some(67794), None), - /// Allows the use of `no_sanitize` attribute. (active, no_sanitize, "1.42.0", Some(39699), None), diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 5cadbd9e5cf7..a8aa3c606c6c 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -123,6 +123,9 @@ declare_features! ( /// Allows overlapping impls of marker traits. (removed, overlapping_marker_traits, "1.42.0", Some(29864), None, Some("removed in favor of `#![feature(marker_trait_attr)]`")), + /// Allows `T: ?const Trait` syntax in bounds. + (removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None, + Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")), /// Allows `#[no_debug]`. (removed, no_debug, "1.43.0", Some(29721), None, Some("removed due to lack of demand")), /// Allows comparing raw pointers during const eval. diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 8f814a84b495..c8ca08f9762b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -457,10 +457,6 @@ pub enum PredicateKind<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be /// the `Self` type of the trait reference and `A`, `B`, and `C` /// would be the type parameters. - /// - /// A trait predicate will have `Constness::Const` if it originates - /// from a bound on a `const fn` without the `?const` opt-out (e.g., - /// `const fn foobar() {}`). Trait(TraitPredicate<'tcx>), /// `where 'a: 'b` @@ -633,8 +629,7 @@ pub struct TraitPredicate<'tcx> { pub trait_ref: TraitRef<'tcx>, /// A trait predicate will have `Constness::Const` if it originates - /// from a bound on a `const fn` without the `?const` opt-out (e.g., - /// `const fn foobar() {}`). + /// from a bound marked with `~const`. pub constness: hir::Constness, } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 1fbf01b1b97d..299fc916ac97 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -11,12 +11,12 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, PResult}; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym}; -/// Any `?` or `?const` modifiers that appear at the start of a bound. +/// Any `?` or `~const` modifiers that appear at the start of a bound. struct BoundModifiers { /// `?Trait`. maybe: Option, - /// `?const Trait`. + /// `~const Trait`. maybe_const: Option, } @@ -609,6 +609,7 @@ impl<'a> Parser<'a> { || self.check_lifetime() || self.check(&token::Not) // Used for error reporting only. || self.check(&token::Question) + || self.check(&token::Tilde) || self.check_keyword(kw::For) || self.check(&token::OpenDelim(token::Paren)) } @@ -655,7 +656,7 @@ impl<'a> Parser<'a> { let inner_lo = self.token.span; let is_negative = self.eat(&token::Not); - let modifiers = self.parse_ty_bound_modifiers(); + let modifiers = self.parse_ty_bound_modifiers()?; let bound = if self.token.is_lifetime() { self.error_lt_bound_with_modifiers(modifiers); self.parse_generic_lt_bound(lo, inner_lo, has_parens)? @@ -690,7 +691,7 @@ impl<'a> Parser<'a> { if let Some(span) = modifiers.maybe_const { self.struct_span_err( span, - "`?const` may only modify trait bounds, not lifetime bounds", + "`~const` may only modify trait bounds, not lifetime bounds", ) .emit(); } @@ -721,34 +722,27 @@ impl<'a> Parser<'a> { Ok(()) } - /// Parses the modifiers that may precede a trait in a bound, e.g. `?Trait` or `?const Trait`. + /// Parses the modifiers that may precede a trait in a bound, e.g. `?Trait` or `~const Trait`. /// /// If no modifiers are present, this does not consume any tokens. /// /// ``` - /// TY_BOUND_MODIFIERS = "?" ["const" ["?"]] + /// TY_BOUND_MODIFIERS = ["~const"] ["?"] /// ``` - fn parse_ty_bound_modifiers(&mut self) -> BoundModifiers { - if !self.eat(&token::Question) { - return BoundModifiers { maybe: None, maybe_const: None }; - } - - // `? ...` - let first_question = self.prev_token.span; - if !self.eat_keyword(kw::Const) { - return BoundModifiers { maybe: Some(first_question), maybe_const: None }; - } + fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> { + let maybe_const = if self.eat(&token::Tilde) { + let tilde = self.prev_token.span; + self.expect_keyword(kw::Const)?; + let span = tilde.to(self.prev_token.span); + self.sess.gated_spans.gate(sym::const_trait_impl, span); + Some(span) + } else { + None + }; - // `?const ...` - let maybe_const = first_question.to(self.prev_token.span); - self.sess.gated_spans.gate(sym::const_trait_bound_opt_out, maybe_const); - if !self.eat(&token::Question) { - return BoundModifiers { maybe: None, maybe_const: Some(maybe_const) }; - } + let maybe = if self.eat(&token::Question) { Some(self.prev_token.span) } else { None }; - // `?const ? ...` - let second_question = self.prev_token.span; - BoundModifiers { maybe: Some(second_question), maybe_const: Some(maybe_const) } + Ok(BoundModifiers { maybe, maybe_const }) } /// Parses a type bound according to: @@ -757,7 +751,7 @@ impl<'a> Parser<'a> { /// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for] SIMPLE_PATH /// ``` /// - /// For example, this grammar accepts `?const ?for<'a: 'b> m::Trait<'a>`. + /// For example, this grammar accepts `~const ?for<'a: 'b> m::Trait<'a>`. fn parse_generic_ty_bound( &mut self, lo: Span, diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 75f9405e082c..3ae26c3eb78e 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2227,8 +2227,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP match bound { hir::GenericBound::Trait(poly_trait_ref, modifier) => { let constness = match modifier { - hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst, - hir::TraitBoundModifier::None => constness, + hir::TraitBoundModifier::None => hir::Constness::NotConst, + hir::TraitBoundModifier::MaybeConst => constness, // We ignore `where T: ?Sized`, it is already part of // type parameter `T`. hir::TraitBoundModifier::Maybe => continue, @@ -2497,8 +2497,8 @@ fn predicates_from_bound<'tcx>( hir::GenericBound::Trait(ref tr, modifier) => { let constness = match modifier { hir::TraitBoundModifier::Maybe => return vec![], - hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst, - hir::TraitBoundModifier::None => constness, + hir::TraitBoundModifier::MaybeConst => constness, + hir::TraitBoundModifier::None => hir::Constness::NotConst, }; let mut bounds = Bounds::default(); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index eb7c12d13c33..54be830bf42e 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -387,7 +387,7 @@ impl clean::GenericBound { let modifier_str = match modifier { hir::TraitBoundModifier::None => "", hir::TraitBoundModifier::Maybe => "?", - hir::TraitBoundModifier::MaybeConst => "?const", + hir::TraitBoundModifier::MaybeConst => "~const", }; if f.alternate() { write!(f, "{}{:#}", modifier_str, ty.print(cx)) diff --git a/src/test/ui/consts/const-eval/issue-49296.rs b/src/test/ui/consts/const-eval/issue-49296.rs index bb8113e53f9c..80f6bbec2a18 100644 --- a/src/test/ui/consts/const-eval/issue-49296.rs +++ b/src/test/ui/consts/const-eval/issue-49296.rs @@ -1,22 +1,13 @@ // issue-49296: Unsafe shenigans in constants can result in missing errors #![feature(const_fn_trait_bound)] -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] -const unsafe fn transmute(t: T) -> U { - #[repr(C)] - union Transmute { - from: T, - to: U, - } - - Transmute { from: t }.to -} +use std::mem::transmute; const fn wat(x: u64) -> &'static u64 { unsafe { transmute(&x) } } + const X: u64 = *wat(42); //~^ ERROR evaluation of constant value failed diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs index 1fc2c4fe4456..8a0f39acf258 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs @@ -13,12 +13,10 @@ impl PartialEq for S { } } -const fn equals_self(t: &T) -> bool { +const fn equals_self(t: &T) -> bool { true } pub const EQ: bool = equals_self(&S); -// Calling `equals_self` with a type that only has a non-const impl is fine, because we opted out. - fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs new file mode 100644 index 000000000000..cde5233d4c88 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs @@ -0,0 +1,12 @@ +#![feature(const_trait_impl)] +fn a>() {} +//~^ ERROR: `~const` is not allowed + +struct S; + +impl S { + fn b>() {} + //~^ ERROR: `~const` is not allowed +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr new file mode 100644 index 000000000000..4f81a607f6ea --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr @@ -0,0 +1,18 @@ +error: `~const` is not allowed here + --> $DIR/tilde-const-on-non-const-fn.rs:2:9 + | +LL | fn a>() {} + | ^^^^^^^^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-on-non-const-fn.rs:8:13 + | +LL | fn b>() {} + | ^^^^^^^^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: aborting due to 2 previous errors + diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index c6f89c310650..640d127e8609 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -537,10 +537,10 @@ impl Rewrite for ast::GenericBound { .map(|s| format!("?{}", s)), ast::TraitBoundModifier::MaybeConst => poly_trait_ref .rewrite(context, shape.offset_left(7)?) - .map(|s| format!("?const {}", s)), + .map(|s| format!("~const {}", s)), ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref .rewrite(context, shape.offset_left(8)?) - .map(|s| format!("?const ?{}", s)), + .map(|s| format!("~const ?{}", s)), }; rewrite.map(|s| if has_paren { format!("({})", s) } else { s }) } diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index e7761251688a..9ab66944c8cc 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -145,35 +145,33 @@ type MyFn = fn( b: SomeOtherLongComplexType, ) -> Box>; -// Const opt-out +// Const bound -trait T: ?const Super {} +trait T: ~const Super {} -const fn maybe_const() -> i32 { +const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); +struct S(std::marker::PhantomData); -impl ?const T {} +impl ~const T {} -fn trait_object() -> &'static dyn ?const T { +fn trait_object() -> &'static dyn ~const T { &S } -fn i(_: impl IntoIterator>) {} +fn i(_: impl IntoIterator>) {} -fn apit(_: impl ?const T) {} +fn apit(_: impl ~const T) {} -fn rpit() -> impl ?const T { +fn rpit() -> impl ~const T { S } pub struct Foo(T); -impl Foo { +impl Foo { fn new(t: T) -> Self { - // not calling methods on `t`, so we opt out of requiring - // `` to have const methods via `?const` Self(t) } } From 1164c946b0a5889f6f0ca1dba48db0cf36c32915 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 25 Aug 2021 13:38:14 +0000 Subject: [PATCH 183/269] Fix visiting twice --- .../rustc_ast_passes/src/ast_validation.rs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 2658971ecb0e..c0ea710fdcb4 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -17,11 +17,10 @@ use rustc_errors::{error_code, pluralize, struct_span_err, Applicability}; use rustc_parse::validate_attr; use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY; use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; -use rustc_session::{DiagnosticMessageId, Session}; +use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; -use std::convert::TryInto; use std::mem; use std::ops::DerefMut; @@ -1177,6 +1176,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, body.as_deref()); self.visit_fn(kind, item.span, item.id); walk_list!(self, visit_attribute, &item.attrs); + return; // Avoid visiting again. } ItemKind::ForeignMod(ForeignMod { unsafety, .. }) => { let old_item = mem::replace(&mut self.extern_mod, Some(item)); @@ -1440,19 +1440,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { match bound { GenericBound::Trait(_, TraitBoundModifier::MaybeConst) => { if !self.is_tilde_const_allowed { - let msg = "`~const` is not allowed here"; - let id_span_msg = ( - DiagnosticMessageId::StabilityId(67792.try_into().ok()), - Some(bound.span()), - msg.to_owned(), - ); - let fresh = self.session.one_time_diagnostics.borrow_mut().insert(id_span_msg); - if fresh { - self.err_handler() - .struct_span_err(bound.span(), msg) - .note("only allowed on bounds on traits' associated types, const fns, const impls and its associated functions") - .emit(); - } + self.err_handler() + .struct_span_err(bound.span(), "`~const` is not allowed here") + .note("only allowed on bounds on traits' associated types, const fns, const impls and its associated functions") + .emit(); } } From ff24ac4f2b1415cc93e0cc3edb70097df6dae073 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 25 Aug 2021 14:30:09 +0000 Subject: [PATCH 184/269] Try fixing some tests --- .../call-generic-method-dup-bound.rs | 6 +-- .../call-generic-method-fail.rs | 4 +- ... => call-generic-method-nonconst-bound.rs} | 3 -- .../feature-gate.gated.stderr | 8 ---- .../const-trait-bound-opt-out/feature-gate.rs | 17 --------- .../feature-gate.stock.stderr | 12 ------ .../in-impl-trait.rs | 21 ---------- .../in-impl-trait.stderr | 26 ------------- .../in-trait-bounds.rs | 8 ---- .../in-trait-bounds.stderr | 8 ---- .../in-trait-object.rs | 19 ---------- .../in-trait-object.stderr | 20 ---------- .../opt-out-twice.rs | 8 ---- .../opt-out-twice.stderr | 14 ------- .../const-trait-bound-opt-out/syntax.rs | 10 ----- .../with-maybe-sized.rs | 7 ---- .../with-maybe-sized.stderr | 8 ---- .../without-question-mark.rs | 7 ---- .../without-question-mark.stderr | 8 ---- .../impl-opt-out-trait.stderr | 8 ---- ...out-trait.rs => impl-tilde-const-trait.rs} | 4 +- .../inherent-impl.rs | 2 - .../ui/rfc-2632-const-trait-impl/syntax.rs | 2 +- .../tilde-const-invalid-places.rs | 38 +++++++++++++++++++ .../tilde-const-on-non-const-fn.rs | 12 ------ .../tilde-const-on-non-const-fn.stderr | 18 --------- .../tilde-const-syntax.rs | 9 +++++ 27 files changed, 52 insertions(+), 255 deletions(-) rename src/test/ui/rfc-2632-const-trait-impl/{call-generic-method-nonconst-opt-out.rs => call-generic-method-nonconst-bound.rs} (71%) delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/syntax.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.stderr delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.stderr rename src/test/ui/rfc-2632-const-trait-impl/{impl-opt-out-trait.rs => impl-tilde-const-trait.rs} (53%) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs delete mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-syntax.rs diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs index 00a3c7f51fe9..5853b66b868a 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs @@ -1,9 +1,7 @@ // check-pass #![feature(const_trait_impl)] -#![feature(const_trait_bound_opt_out)] #![feature(const_fn_trait_bound)] -#![allow(incomplete_features)] struct S; @@ -16,9 +14,9 @@ impl const PartialEq for S { } } -// This duplicate bound should not result in ambiguities. It should be equivalent to a single const +// This duplicate bound should not result in ambiguities. It should be equivalent to a single ~const // bound. -const fn equals_self(t: &T) -> bool { +const fn equals_self(t: &T) -> bool { *t == *t } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.rs index dc4d5561d474..e96249ff2fd5 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.rs @@ -1,9 +1,7 @@ #![feature(const_fn_trait_bound)] #![feature(const_trait_impl)] -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] -pub const fn equals_self(t: &T) -> bool { +pub const fn equals_self(t: &T) -> bool { *t == *t //~^ ERROR calls in constant functions are limited to constant functions } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-bound.rs similarity index 71% rename from src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs rename to src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-bound.rs index 8a0f39acf258..585b65988f39 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-opt-out.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst-bound.rs @@ -1,9 +1,6 @@ // check-pass #![feature(const_fn_trait_bound)] -#![feature(const_trait_impl)] -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] struct S; diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr deleted file mode 100644 index 58041454d590..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.gated.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: fatal error triggered by #[rustc_error] - --> $DIR/feature-gate.rs:17:1 - | -LL | fn main() {} - | ^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs deleted file mode 100644 index 4452ad7ea239..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// revisions: stock gated -// gate-test-const_trait_bound_opt_out - -#![cfg_attr(gated, feature(const_trait_bound_opt_out))] -#![allow(incomplete_features)] -#![feature(rustc_attrs)] -#![feature(const_fn_trait_bound)] - -trait T { - const CONST: i32; -} - -const fn get_assoc_const() -> i32 { ::CONST } -//[stock]~^ ERROR `?const` on trait bounds is experimental - -#[rustc_error] -fn main() {} //[gated]~ ERROR fatal error triggered by #[rustc_error] diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr deleted file mode 100644 index 8ae8b8868dde..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/feature-gate.stock.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `?const` on trait bounds is experimental - --> $DIR/feature-gate.rs:13:29 - | -LL | const fn get_assoc_const() -> i32 { ::CONST } - | ^^^^^^ - | - = note: see issue #67794 for more information - = help: add `#![feature(const_trait_bound_opt_out)]` 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/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs deleted file mode 100644 index f5561a922ddc..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(const_trait_bound_opt_out)] -#![feature(associated_type_bounds)] -#![allow(incomplete_features)] - -trait T {} -struct S; -impl T for S {} - -fn rpit() -> impl ?const T { S } -//~^ ERROR `?const` is not permitted in `impl Trait` - -fn apit(_: impl ?const T) {} -//~^ ERROR `?const` is not permitted in `impl Trait` - -fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } -//~^ ERROR `?const` is not permitted in `impl Trait` - -fn apit_assoc_bound(_: impl IntoIterator) {} -//~^ ERROR `?const` is not permitted in `impl Trait` - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr deleted file mode 100644 index 06cd00a956a2..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-impl-trait.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:9:19 - | -LL | fn rpit() -> impl ?const T { S } - | ^^^^^^^^ - -error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:12:17 - | -LL | fn apit(_: impl ?const T) {} - | ^^^^^^^^ - -error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:15:50 - | -LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } - | ^^^^^^^^ - -error: `?const` is not permitted in `impl Trait` - --> $DIR/in-impl-trait.rs:18:48 - | -LL | fn apit_assoc_bound(_: impl IntoIterator) {} - | ^^^^^^^^ - -error: aborting due to 4 previous errors - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs deleted file mode 100644 index fc9ed5b1dc22..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] - -trait Super {} -trait T: ?const Super {} -//~^ ERROR `?const` is not permitted in supertraits - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr deleted file mode 100644 index a0d8f95acd2a..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-bounds.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `?const` is not permitted in supertraits - --> $DIR/in-trait-bounds.rs:5:10 - | -LL | trait T: ?const Super {} - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs deleted file mode 100644 index b3d1f48ace14..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(const_trait_bound_opt_out)] -#![allow(bare_trait_objects)] -#![allow(incomplete_features)] - -struct S; -trait T {} -impl T for S {} - -// An inherent impl for the trait object `?const T`. -impl ?const T {} -//~^ ERROR `?const` is not permitted in trait objects - -fn trait_object() -> &'static dyn ?const T { &S } -//~^ ERROR `?const` is not permitted in trait objects - -fn trait_object_in_apit(_: impl IntoIterator>) {} -//~^ ERROR `?const` is not permitted in trait objects - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr deleted file mode 100644 index 331fe0423fa9..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/in-trait-object.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: `?const` is not permitted in trait objects - --> $DIR/in-trait-object.rs:10:6 - | -LL | impl ?const T {} - | ^^^^^^^^ - -error: `?const` is not permitted in trait objects - --> $DIR/in-trait-object.rs:13:35 - | -LL | fn trait_object() -> &'static dyn ?const T { &S } - | ^^^^^^^^ - -error: `?const` is not permitted in trait objects - --> $DIR/in-trait-object.rs:16:61 - | -LL | fn trait_object_in_apit(_: impl IntoIterator>) {} - | ^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.rs deleted file mode 100644 index 01e941a8fba4..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.rs +++ /dev/null @@ -1,8 +0,0 @@ -// compile-flags: -Z parse-only - -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] - -struct S; -//~^ ERROR expected identifier, found keyword `const` -//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>` diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.stderr deleted file mode 100644 index f7924b3f24db..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/opt-out-twice.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: expected identifier, found keyword `const` - --> $DIR/opt-out-twice.rs:6:21 - | -LL | struct S; - | ^^^^^ expected identifier, found keyword - -error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr` - --> $DIR/opt-out-twice.rs:6:27 - | -LL | struct S; - | ^^ expected one of 7 possible tokens - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/syntax.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/syntax.rs deleted file mode 100644 index a0d9610bbb5e..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/syntax.rs +++ /dev/null @@ -1,10 +0,0 @@ -// compile-flags: -Z parse-only -// check-pass - -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] - -struct S< - T: ?const ?for<'a> Tr<'a> + 'static + ?const std::ops::Add, - T: ?const ?for<'a: 'b> m::Trait<'a>, ->; diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs deleted file mode 100644 index c2c8689e2942..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] - -struct S(std::marker::PhantomData); -//~^ ERROR `?const` and `?` are mutually exclusive - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr deleted file mode 100644 index e8e9d6c1e762..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/with-maybe-sized.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: `?const` and `?` are mutually exclusive - --> $DIR/with-maybe-sized.rs:4:13 - | -LL | struct S(std::marker::PhantomData); - | ^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.rs b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.rs deleted file mode 100644 index b904a2eec0dd..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.rs +++ /dev/null @@ -1,7 +0,0 @@ -// compile-flags: -Z parse-only - -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] - -struct S; -//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.stderr deleted file mode 100644 index 0dbca952c037..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/const-trait-bound-opt-out/without-question-mark.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, lifetime, or path, found keyword `const` - --> $DIR/without-question-mark.rs:6:13 - | -LL | struct S; - | ^^^^^ expected one of 9 possible tokens - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.stderr deleted file mode 100644 index 8f923efb093f..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: expected a trait, found type - --> $DIR/impl-opt-out-trait.rs:8:6 - | -LL | impl ?const T for S {} - | ^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.rs similarity index 53% rename from src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs rename to src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.rs index 98d3a220d867..05b26465c5b0 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/impl-opt-out-trait.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.rs @@ -1,11 +1,9 @@ -#![feature(const_trait_bound_opt_out)] #![feature(const_trait_impl)] -#![allow(incomplete_features)] struct S; trait T {} -impl ?const T for S {} +impl ~const T for S {} //~^ ERROR expected a trait, found type fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs index 04123a532bd9..afd0d137bb4a 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.rs @@ -1,6 +1,4 @@ #![feature(const_trait_impl)] -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] #![allow(bare_trait_objects)] struct S; diff --git a/src/test/ui/rfc-2632-const-trait-impl/syntax.rs b/src/test/ui/rfc-2632-const-trait-impl/syntax.rs index 82a1275bffae..7ac2458e3992 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/syntax.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/syntax.rs @@ -5,4 +5,4 @@ #![feature(const_trait_impl)] // For now, this parses since an error does not occur until AST lowering. -impl ?const T {} +impl ~const T {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs new file mode 100644 index 000000000000..a8912705d945 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -0,0 +1,38 @@ +#![feature(const_trait_impl)] +#![feature(associated_type_bounds)] + +trait T {} +struct S; +impl T for S {} + +fn rpit() -> impl ~const T { S } +//~^ ERROR `~const` is not allowed + +fn apit(_: impl ~const T) {} +//~^ ERROR `~const` is not allowed + +fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } +//~^ ERROR `~const` is not allowed + +fn apit_assoc_bound(_: impl IntoIterator) {} +//~^ ERROR `~const` is not allowed + +fn generic() {} +//~^ ERROR `~const` is not allowed + +fn where_clause() where T: ~const T {} +//~^ ERROR `~const` is not allowed + +impl ~const T {} +//~^ ERROR `~const` is not allowed + +fn trait_object() -> &'static dyn ~const T { &S } +//~^ ERROR `~const` is not allowed + +fn trait_object_in_apit(_: impl IntoIterator>) {} +//~^ ERROR `~const` is not allowed + +struct S(std::marker::PhantomData); +//~^ ERROR `~const` and `?` are mutually exclusive + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs deleted file mode 100644 index cde5233d4c88..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(const_trait_impl)] -fn a>() {} -//~^ ERROR: `~const` is not allowed - -struct S; - -impl S { - fn b>() {} - //~^ ERROR: `~const` is not allowed -} - -fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr deleted file mode 100644 index 4f81a607f6ea..000000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-on-non-const-fn.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: `~const` is not allowed here - --> $DIR/tilde-const-on-non-const-fn.rs:2:9 - | -LL | fn a>() {} - | ^^^^^^^^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions - -error: `~const` is not allowed here - --> $DIR/tilde-const-on-non-const-fn.rs:8:13 - | -LL | fn b>() {} - | ^^^^^^^^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-syntax.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-syntax.rs new file mode 100644 index 000000000000..9b3c2cf2a3b0 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-syntax.rs @@ -0,0 +1,9 @@ +// compile-flags: -Z parse-only +// check-pass + +#![feature(const_trait_impl)] + +struct S< + T: ~const ?for<'a> Tr<'a> + 'static + ~const std::ops::Add, + T: ~const ?for<'a: 'b> m::Trait<'a>, +>; From 703c557aaa48ba647f6fafea2330819a8bbe6734 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 25 Aug 2021 15:21:55 +0000 Subject: [PATCH 185/269] Fix more tests --- compiler/rustc_typeck/src/astconv/mod.rs | 4 +- .../ui/consts/const-eval/issue-49296.stderr | 2 +- .../projection-bound-cycle-generic.stderr | 8 +-- .../projection-bound-cycle.stderr | 8 +-- src/test/ui/parser/bounds-type.rs | 8 +-- src/test/ui/parser/bounds-type.stderr | 4 +- src/test/ui/parser/trait-object-delimiters.rs | 2 +- .../ui/parser/trait-object-delimiters.stderr | 4 +- .../rfc-2632-const-trait-impl/assoc-type.rs | 6 +- .../assoc-type.stderr | 8 +-- .../call-generic-in-impl.rs | 2 +- .../call-generic-method-chain.rs | 4 +- .../call-generic-method-fail.stderr | 2 +- .../call-generic-method-nonconst.rs | 2 +- .../call-generic-method-nonconst.stderr | 4 +- .../call-generic-method-pass.rs | 2 +- .../impl-tilde-const-trait.stderr | 8 +++ .../inherent-impl.stderr | 4 +- .../tilde-const-invalid-places.rs | 15 +---- .../tilde-const-invalid-places.stderr | 56 +++++++++++++++++++ 20 files changed, 103 insertions(+), 50 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index d916ff7db3d5..b7054d156268 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -927,7 +927,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.instantiate_poly_trait_ref( &b.trait_ref, b.span, - constness, + Constness::NotConst, param_ty, bounds, false, @@ -937,7 +937,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.instantiate_poly_trait_ref( &b.trait_ref, b.span, - Constness::NotConst, + constness, param_ty, bounds, false, diff --git a/src/test/ui/consts/const-eval/issue-49296.stderr b/src/test/ui/consts/const-eval/issue-49296.stderr index 28fdcb7c4863..bc3074b10bee 100644 --- a/src/test/ui/consts/const-eval/issue-49296.stderr +++ b/src/test/ui/consts/const-eval/issue-49296.stderr @@ -1,5 +1,5 @@ error[E0080]: evaluation of constant value failed - --> $DIR/issue-49296.rs:20:16 + --> $DIR/issue-49296.rs:11:16 | LL | const X: u64 = *wat(42); | ^^^^^^^^ pointer to alloc2 was dereferenced after this allocation got freed diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr index 5e7e72ca562d..2b57c439fe9a 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr @@ -4,11 +4,11 @@ error[E0275]: overflow evaluating the requirement `::Item: Sized` LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: required by a bound in `Foo::Item` - --> $DIR/projection-bound-cycle-generic.rs:11:49 +note: required by a bound in `OnlySized` + --> $DIR/projection-bound-cycle-generic.rs:28:18 | -LL | type Item: Sized where ::Item: Sized; - | ^^^^^ required by this bound in `Foo::Item` +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr index 1153bf53ba43..d9d0bf4274bd 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr @@ -4,11 +4,11 @@ error[E0275]: overflow evaluating the requirement `::Item: Sized` LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: required by a bound in `Foo::Item` - --> $DIR/projection-bound-cycle.rs:13:49 +note: required by a bound in `OnlySized` + --> $DIR/projection-bound-cycle.rs:30:18 | -LL | type Item: Sized where ::Item: Sized; - | ^^^^^ required by this bound in `Foo::Item` +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error diff --git a/src/test/ui/parser/bounds-type.rs b/src/test/ui/parser/bounds-type.rs index 7a187a0518af..4ae4549ea589 100644 --- a/src/test/ui/parser/bounds-type.rs +++ b/src/test/ui/parser/bounds-type.rs @@ -9,10 +9,10 @@ struct S< T: Tr +, // OK T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds - T: ?const Tr, // OK - T: ?const ?Tr, // OK - T: ?const Tr + 'a, // OK - T: ?const 'a, //~ ERROR `?const` may only modify trait bounds, not lifetime bounds + T: ~const Tr, // OK + T: ~const ?Tr, // OK + T: ~const Tr + 'a, // OK + T: ~const 'a, //~ ERROR `~const` may only modify trait bounds, not lifetime bounds >; fn main() {} diff --git a/src/test/ui/parser/bounds-type.stderr b/src/test/ui/parser/bounds-type.stderr index 9a1f2ed39824..005bc1e54bd0 100644 --- a/src/test/ui/parser/bounds-type.stderr +++ b/src/test/ui/parser/bounds-type.stderr @@ -4,10 +4,10 @@ error: `?` may only modify trait bounds, not lifetime bounds LL | T: ?'a, | ^ -error: `?const` may only modify trait bounds, not lifetime bounds +error: `~const` may only modify trait bounds, not lifetime bounds --> $DIR/bounds-type.rs:15:8 | -LL | T: ?const 'a, +LL | T: ~const 'a, | ^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/trait-object-delimiters.rs b/src/test/ui/parser/trait-object-delimiters.rs index 650ab5722618..b5258eebb90a 100644 --- a/src/test/ui/parser/trait-object-delimiters.rs +++ b/src/test/ui/parser/trait-object-delimiters.rs @@ -6,7 +6,7 @@ fn foo1(_: &dyn Drop + AsRef) {} //~ ERROR ambiguous `+` in a type fn foo2(_: &dyn (Drop + AsRef)) {} //~ ERROR incorrect braces around trait bounds fn foo3(_: &dyn {Drop + AsRef}) {} //~ ERROR expected parameter name, found `{` -//~^ ERROR expected one of `!`, `(`, `)`, `,`, `?`, `for`, lifetime, or path, found `{` +//~^ ERROR expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `{` //~| ERROR at least one trait is required for an object type fn foo4(_: &dyn >) {} //~ ERROR expected identifier, found `<` diff --git a/src/test/ui/parser/trait-object-delimiters.stderr b/src/test/ui/parser/trait-object-delimiters.stderr index 1ae0205615cb..ee638d8a4f5e 100644 --- a/src/test/ui/parser/trait-object-delimiters.stderr +++ b/src/test/ui/parser/trait-object-delimiters.stderr @@ -22,11 +22,11 @@ error: expected parameter name, found `{` LL | fn foo3(_: &dyn {Drop + AsRef}) {} | ^ expected parameter name -error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, lifetime, or path, found `{` +error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `{` --> $DIR/trait-object-delimiters.rs:8:17 | LL | fn foo3(_: &dyn {Drop + AsRef}) {} - | -^ expected one of 8 possible tokens + | -^ expected one of 9 possible tokens | | | help: missing `,` diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs index 1dbd000afd73..228b5ed71e80 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs @@ -1,7 +1,5 @@ // FIXME(fee1-dead): this should have a better error message #![feature(const_trait_impl)] -#![feature(const_trait_bound_opt_out)] -#![allow(incomplete_features)] struct NonConstAdd(i32); @@ -14,7 +12,7 @@ impl std::ops::Add for NonConstAdd { } trait Foo { - type Bar: std::ops::Add; + type Bar: ~const std::ops::Add; } impl const Foo for NonConstAdd { @@ -23,7 +21,7 @@ impl const Foo for NonConstAdd { } trait Baz { - type Qux: ?const std::ops::Add; + type Qux: std::ops::Add; } impl const Baz for NonConstAdd { diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr index ada29ba3f8b4..b894092205e4 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr @@ -1,15 +1,15 @@ error[E0277]: cannot add `NonConstAdd` to `NonConstAdd` - --> $DIR/assoc-type.rs:21:5 + --> $DIR/assoc-type.rs:19:5 | LL | type Bar = NonConstAdd; | ^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd` | = help: the trait `Add` is not implemented for `NonConstAdd` note: required by a bound in `Foo::Bar` - --> $DIR/assoc-type.rs:17:15 + --> $DIR/assoc-type.rs:15:15 | -LL | type Bar: std::ops::Add; - | ^^^^^^^^^^^^^ required by this bound in `Foo::Bar` +LL | type Bar: ~const std::ops::Add; + | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar` help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | LL | impl const Foo for NonConstAdd where NonConstAdd: Add { diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs index 536c1d737402..4b706a190e65 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs @@ -6,7 +6,7 @@ trait MyPartialEq { fn eq(&self, other: &Self) -> bool; } -impl const MyPartialEq for T { +impl const MyPartialEq for T { fn eq(&self, other: &Self) -> bool { PartialEq::eq(self, other) } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs index f3391aa63468..adf8d4f9ea56 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs @@ -16,11 +16,11 @@ impl const PartialEq for S { } } -const fn equals_self(t: &T) -> bool { +const fn equals_self(t: &T) -> bool { *t == *t } -const fn equals_self_wrapper(t: &T) -> bool { +const fn equals_self_wrapper(t: &T) -> bool { equals_self(t) } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr index 4b2fc56aaa78..818c58286963 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr @@ -1,5 +1,5 @@ error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants - --> $DIR/call-generic-method-fail.rs:7:5 + --> $DIR/call-generic-method-fail.rs:5:5 | LL | *t == *t | ^^^^^^^^ diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs index 8343974f8c7e..6881db0aa02c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs @@ -9,7 +9,7 @@ impl PartialEq for S { } } -const fn equals_self(t: &T) -> bool { +const fn equals_self(t: &T) -> bool { true } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index 7cc54e0129a5..9b9bda7c90ec 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -8,8 +8,8 @@ LL | pub const EQ: bool = equals_self(&S); note: required by a bound in `equals_self` --> $DIR/call-generic-method-nonconst.rs:12:25 | -LL | const fn equals_self(t: &T) -> bool { - | ^^^^^^^^^ required by this bound in `equals_self` +LL | const fn equals_self(t: &T) -> bool { + | ^^^^^^^^^^^^^^^^ required by this bound in `equals_self` error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs index aee88d6053ee..aa9bd4d824e1 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs @@ -16,7 +16,7 @@ impl const PartialEq for S { } } -const fn equals_self(t: &T) -> bool { +const fn equals_self(t: &T) -> bool { *t == *t } diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.stderr new file mode 100644 index 000000000000..0a91719e1f15 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/impl-tilde-const-trait.stderr @@ -0,0 +1,8 @@ +error: expected a trait, found type + --> $DIR/impl-tilde-const-trait.rs:6:6 + | +LL | impl ~const T for S {} + | ^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr index 834f6a409f5b..8c55627031d1 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr @@ -1,5 +1,5 @@ error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:9:12 + --> $DIR/inherent-impl.rs:7:12 | LL | impl const S {} | ----- ^ inherent impl for this type @@ -9,7 +9,7 @@ LL | impl const S {} = note: only trait implementations may be annotated with `const` error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:12:12 + --> $DIR/inherent-impl.rs:10:12 | LL | impl const T {} | ----- ^ inherent impl for this type diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs index a8912705d945..b4302f3e75fd 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -17,22 +17,13 @@ fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } fn apit_assoc_bound(_: impl IntoIterator) {} //~^ ERROR `~const` is not allowed -fn generic() {} +fn generic() {} //~^ ERROR `~const` is not allowed -fn where_clause() where T: ~const T {} +fn where_clause

() where P: ~const T {} //~^ ERROR `~const` is not allowed -impl ~const T {} -//~^ ERROR `~const` is not allowed - -fn trait_object() -> &'static dyn ~const T { &S } -//~^ ERROR `~const` is not allowed - -fn trait_object_in_apit(_: impl IntoIterator>) {} -//~^ ERROR `~const` is not allowed - -struct S(std::marker::PhantomData); +struct TildeQuestion(std::marker::PhantomData); //~^ ERROR `~const` and `?` are mutually exclusive fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr new file mode 100644 index 000000000000..b026099f6829 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -0,0 +1,56 @@ +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:8:19 + | +LL | fn rpit() -> impl ~const T { S } + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:11:17 + | +LL | fn apit(_: impl ~const T) {} + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:14:50 + | +LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:17:48 + | +LL | fn apit_assoc_bound(_: impl IntoIterator) {} + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:20:15 + | +LL | fn generic() {} + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` is not allowed here + --> $DIR/tilde-const-invalid-places.rs:23:31 + | +LL | fn where_clause

() where P: ~const T {} + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types, const fns, const impls and its associated functions + +error: `~const` and `?` are mutually exclusive + --> $DIR/tilde-const-invalid-places.rs:26:25 + | +LL | struct TildeQuestion(std::marker::PhantomData); + | ^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + From c75aeaac0bb2af593b9819cfeae6d518617d48cc Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 26 Aug 2021 17:58:28 +0000 Subject: [PATCH 186/269] Fix #88155 --- .../src/transform/check_consts/check.rs | 82 +++++++++++-------- .../rfc-2632-const-trait-impl/issue-88155.rs | 13 +++ .../issue-88155.stderr | 9 ++ 3 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-88155.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-88155.stderr diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs index 0361ddc915d4..0de6d743a7a7 100644 --- a/compiler/rustc_mir/src/transform/check_consts/check.rs +++ b/compiler/rustc_mir/src/transform/check_consts/check.rs @@ -805,6 +805,8 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { } }; + let mut nonconst_call_permission = false; + // Attempting to call a trait method? if let Some(trait_id) = tcx.trait_of_item(callee) { trace!("attempting to call a trait method"); @@ -824,18 +826,44 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { ); let implsrc = tcx.infer_ctxt().enter(|infcx| { - let mut selcx = SelectionContext::new(&infcx); - selcx.select(&obligation).unwrap() + let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const); + selcx.select(&obligation) }); - // If the method is provided via a where-clause that does not use the `?const` - // opt-out, the call is allowed. - if let Some(ImplSource::Param(_, hir::Constness::Const)) = implsrc { - debug!( - "const_trait_impl: provided {:?} via where-clause in {:?}", - trait_ref, param_env - ); - return; + match implsrc { + Ok(Some(ImplSource::Param(_, hir::Constness::Const))) => { + debug!( + "const_trait_impl: provided {:?} via where-clause in {:?}", + trait_ref, param_env + ); + return; + } + Ok(Some(ImplSource::UserDefined(data))) => { + let callee_name = tcx.item_name(callee); + if let Some(&did) = tcx.associated_item_def_ids(data.impl_def_id).iter().find(|did| tcx.item_name(**did) == callee_name) { + callee = did; + } + } + _ => { + if !tcx.is_const_fn_raw(callee) { + // At this point, it is only legal when the caller is marked with + // #[default_method_body_is_const], and the callee is in the same + // trait. + let callee_trait = tcx.trait_of_item(callee); + if callee_trait.is_some() { + if tcx.has_attr(caller, sym::default_method_body_is_const) { + if tcx.trait_of_item(caller) == callee_trait { + nonconst_call_permission = true; + } + } + } + + if !nonconst_call_permission { + self.check_op(ops::FnCallNonConst); + return; + } + } + } } // Resolve a trait method call to its concrete implementation, which may be in a @@ -875,34 +903,16 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { let is_intrinsic = tcx.fn_sig(callee).abi() == RustIntrinsic; if !tcx.is_const_fn_raw(callee) { - let mut permitted = false; - - let callee_trait = tcx.trait_of_item(callee); - if let Some(trait_id) = callee_trait { - if tcx.has_attr(caller, sym::default_method_body_is_const) { - // permit call to non-const fn when caller has default_method_body_is_const.. - if tcx.trait_of_item(caller) == callee_trait { - // ..and caller and callee are in the same trait. - permitted = true; - } - } - if !permitted { - // if trait's impls are all const, permit the call. - let mut const_impls = true; - tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| { - if const_impls { - if let hir::Constness::NotConst = tcx.impl_constness(imp) { - const_impls = false; - } - } - }); - if const_impls { - permitted = true; - } - } + if tcx.trait_of_item(callee).is_some() { + if tcx.has_attr(callee, sym::default_method_body_is_const) { + // To get to here we must have already found a const impl for the + // trait, but for it to still be non-const can be that the impl is + // using default method bodies. + nonconst_call_permission = true; + } } - if !permitted { + if !nonconst_call_permission { self.check_op(ops::FnCallNonConst); return; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-88155.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-88155.rs new file mode 100644 index 000000000000..157005bba7b7 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-88155.rs @@ -0,0 +1,13 @@ +#![feature(const_fn_trait_bound)] +#![feature(const_trait_impl)] + +pub trait A { + fn assoc() -> bool; +} + +pub const fn foo() -> bool { + T::assoc() + //~^ ERROR calls in constant functions are limited +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-88155.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-88155.stderr new file mode 100644 index 000000000000..931baac5389e --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-88155.stderr @@ -0,0 +1,9 @@ +error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-88155.rs:9:5 + | +LL | T::assoc() + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`. From 80e1ee5aeeadf6b1bd5f272a9c94f67ba57d6248 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 27 Aug 2021 05:02:23 +0000 Subject: [PATCH 187/269] Add `ty::BoundConstness` --- compiler/rustc_middle/src/traits/mod.rs | 3 +- compiler/rustc_middle/src/ty/error.rs | 4 +-- compiler/rustc_middle/src/ty/mod.rs | 35 +++++++++++++----- compiler/rustc_middle/src/ty/relate.rs | 8 ++--- .../rustc_middle/src/ty/structural_impls.rs | 6 ++-- compiler/rustc_middle/src/ty/sty.rs | 2 +- .../src/borrow_check/type_check/canonical.rs | 3 +- .../src/transform/check_consts/check.rs | 4 +-- .../src/traits/auto_trait.rs | 2 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/select/confirmation.rs | 5 ++- .../src/traits/select/mod.rs | 36 ++++++++++--------- compiler/rustc_typeck/src/astconv/mod.rs | 17 ++++----- compiler/rustc_typeck/src/bounds.rs | 3 +- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 4 --- compiler/rustc_typeck/src/collect.rs | 19 ++++------ .../src/impl_wf_check/min_specialization.rs | 5 ++- compiler/rustc_typeck/src/lib.rs | 2 +- 18 files changed, 80 insertions(+), 80 deletions(-) diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 457e80c1663a..676cb7fe41d9 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -17,7 +17,6 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::Constness; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; @@ -497,7 +496,7 @@ pub enum ImplSource<'tcx, N> { /// for some type parameter. The `Vec` represents the /// obligations incurred from normalizing the where-clause (if /// any). - Param(Vec, Constness), + Param(Vec, ty::BoundConstness), /// Virtual calls through an object. Object(ImplSourceObjectData<'tcx, N>), diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index ecbe9ca41759..796ca650bdd7 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -33,7 +33,7 @@ impl ExpectedFound { #[derive(Clone, Debug, TypeFoldable)] pub enum TypeError<'tcx> { Mismatch, - ConstnessMismatch(ExpectedFound), + ConstnessMismatch(ExpectedFound), UnsafetyMismatch(ExpectedFound), AbiMismatch(ExpectedFound), Mutability, @@ -102,7 +102,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { CyclicConst(_) => write!(f, "encountered a self-referencing constant"), Mismatch => write!(f, "types differ"), ConstnessMismatch(values) => { - write!(f, "expected {} fn, found {} fn", values.expected, values.found) + write!(f, "expected {} bound, found {} bound", values.expected, values.found) } UnsafetyMismatch(values) => { write!(f, "expected {} fn, found {} fn", values.expected, values.found) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index c8ca08f9762b..8aa27d4ca53e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -37,7 +37,7 @@ use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX}; -use rustc_hir::{Constness, Node}; +use rustc_hir::Node; use rustc_macros::HashStable; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::Span; @@ -181,6 +181,25 @@ pub enum Visibility { Invisible, } +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)] +pub enum BoundConstness { + /// `T: Trait` + NotConst, + /// `T: ~const Trait` + /// + /// Requires resolving to const only when we are in a const context. + ConstIfConst, +} + +impl fmt::Display for BoundConstness { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::NotConst => f.write_str("normal"), + Self::ConstIfConst => f.write_str("`~const`"), + } + } +} + #[derive( Clone, Debug, @@ -628,9 +647,7 @@ impl<'tcx> Predicate<'tcx> { pub struct TraitPredicate<'tcx> { pub trait_ref: TraitRef<'tcx>, - /// A trait predicate will have `Constness::Const` if it originates - /// from a bound marked with `~const`. - pub constness: hir::Constness, + pub constness: BoundConstness, } pub type PolyTraitPredicate<'tcx> = ty::Binder<'tcx, TraitPredicate<'tcx>>; @@ -1299,7 +1316,7 @@ impl<'tcx> ParamEnv<'tcx> { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)] pub struct ConstnessAnd { - pub constness: Constness, + pub constness: BoundConstness, pub value: T, } @@ -1307,18 +1324,18 @@ pub struct ConstnessAnd { // the constness of trait bounds is being propagated correctly. pub trait WithConstness: Sized { #[inline] - fn with_constness(self, constness: Constness) -> ConstnessAnd { + fn with_constness(self, constness: BoundConstness) -> ConstnessAnd { ConstnessAnd { constness, value: self } } #[inline] - fn with_const(self) -> ConstnessAnd { - self.with_constness(Constness::Const) + fn with_const_if_const(self) -> ConstnessAnd { + self.with_constness(BoundConstness::ConstIfConst) } #[inline] fn without_const(self) -> ConstnessAnd { - self.with_constness(Constness::NotConst) + self.with_constness(BoundConstness::NotConst) } } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 4a2c8349fdc6..44981f171d50 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -200,12 +200,12 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { } } -impl<'tcx> Relate<'tcx> for ast::Constness { +impl<'tcx> Relate<'tcx> for ty::BoundConstness { fn relate>( relation: &mut R, - a: ast::Constness, - b: ast::Constness, - ) -> RelateResult<'tcx, ast::Constness> { + a: ty::BoundConstness, + b: ty::BoundConstness, + ) -> RelateResult<'tcx, ty::BoundConstness> { if a != b { Err(TypeError::ConstnessMismatch(expected_found(relation, a, b))) } else { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 2ab25c839704..89ad99d9f079 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -8,7 +8,6 @@ use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::{self, InferConst, Lift, Ty, TyCtxt}; use rustc_data_structures::functor::IdFunctor; -use rustc_hir as hir; use rustc_hir::def::Namespace; use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_index::vec::{Idx, IndexVec}; @@ -155,8 +154,8 @@ impl fmt::Debug for ty::ParamConst { impl fmt::Debug for ty::TraitPredicate<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if let hir::Constness::Const = self.constness { - write!(f, "const ")?; + if let ty::BoundConstness::ConstIfConst = self.constness { + write!(f, "~const ")?; } write!(f, "TraitPredicate({:?})", self.trait_ref) } @@ -241,6 +240,7 @@ TrivialTypeFoldableAndLiftImpls! { crate::traits::Reveal, crate::ty::adjustment::AutoBorrowMutability, crate::ty::AdtKind, + crate::ty::BoundConstness, // Including `BoundRegionKind` is a *bit* dubious, but direct // references to bound region appear in `ty::Error`, and aren't // really meant to be folded. In general, we can only fold a fully diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 8b893b779c0a..65dd61b63295 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -878,7 +878,7 @@ impl<'tcx> PolyTraitRef<'tcx> { pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> { self.map_bound(|trait_ref| ty::TraitPredicate { trait_ref, - constness: hir::Constness::NotConst, + constness: ty::BoundConstness::NotConst, }) } } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs b/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs index 9fafcfafe67c..b501716a8997 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs @@ -1,6 +1,5 @@ use std::fmt; -use rustc_hir as hir; use rustc_infer::infer::canonical::Canonical; use rustc_infer::traits::query::NoSolution; use rustc_middle::mir::ConstraintCategory; @@ -88,7 +87,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.prove_predicates( Some(ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, - constness: hir::Constness::NotConst, + constness: ty::BoundConstness::NotConst, })), locations, category, diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs index 0de6d743a7a7..944b5ca89860 100644 --- a/compiler/rustc_mir/src/transform/check_consts/check.rs +++ b/compiler/rustc_mir/src/transform/check_consts/check.rs @@ -821,7 +821,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { param_env, Binder::dummy(TraitPredicate { trait_ref, - constness: hir::Constness::Const, + constness: ty::BoundConstness::ConstIfConst, }), ); @@ -831,7 +831,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { }); match implsrc { - Ok(Some(ImplSource::Param(_, hir::Constness::Const))) => { + Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => { debug!( "const_trait_impl: provided {:?} via where-clause in {:?}", trait_ref, param_env diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 282502cfa0d3..622c9edc4345 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -285,7 +285,7 @@ impl AutoTraitFinder<'tcx> { def_id: trait_did, substs: infcx.tcx.mk_substs_trait(ty, &[]), }, - constness: hir::Constness::NotConst, + constness: ty::BoundConstness::NotConst, })); let computed_preds = param_env.caller_bounds().iter(); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 554b2950263e..cec07281d2ab 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -778,7 +778,7 @@ pub fn vtable_trait_upcasting_coercion_new_vptr_slot( let obligation = Obligation::new( ObligationCause::dummy(), ty::ParamEnv::reveal_all(), - ty::Binder::dummy(ty::TraitPredicate { trait_ref, constness: hir::Constness::NotConst }), + ty::Binder::dummy(ty::TraitPredicate { trait_ref, constness: ty::BoundConstness::NotConst }), ); let implsrc = tcx.infer_ctxt().enter(|infcx| { diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index c571a1d62842..6fae8173985b 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -8,7 +8,6 @@ //! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::lang_items::LangItem; -use rustc_hir::Constness; use rustc_index::bit_set::GrowableBitSet; use rustc_infer::infer::InferOk; use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType; @@ -75,7 +74,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ProjectionCandidate(idx) => { let obligations = self.confirm_projection_candidate(obligation, idx)?; // FIXME(jschievink): constness - Ok(ImplSource::Param(obligations, Constness::NotConst)) + Ok(ImplSource::Param(obligations, ty::BoundConstness::NotConst)) } ObjectCandidate(idx) => { @@ -113,7 +112,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // This indicates something like `Trait + Send: Send`. In this case, we know that // this holds because that's what the object type is telling us, and there's really // no additional obligations to prove and no types in particular to unify, etc. - Ok(ImplSource::Param(Vec::new(), Constness::NotConst)) + Ok(ImplSource::Param(Vec::new(), ty::BoundConstness::NotConst)) } BuiltinUnsizeCandidate => { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 1580562a92f3..40e413847e03 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -32,7 +32,6 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::Constness; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::dep_graph::{DepKind, DepNodeIndex}; use rustc_middle::mir::abstract_const::NotConstEvaluatable; @@ -130,8 +129,8 @@ pub struct SelectionContext<'cx, 'tcx> { /// and a negative impl allow_negative_impls: bool, - /// Do we only want const impls when we have a const trait predicate? - const_impls_required: bool, + /// Are we in a const context that needs `~const` bounds to be const? + is_in_const_context: bool, /// The mode that trait queries run in, which informs our error handling /// policy. In essence, canonicalized queries need their errors propagated @@ -224,7 +223,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { intercrate: false, intercrate_ambiguity_causes: None, allow_negative_impls: false, - const_impls_required: false, + is_in_const_context: false, query_mode: TraitQueryMode::Standard, } } @@ -236,7 +235,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { intercrate: true, intercrate_ambiguity_causes: None, allow_negative_impls: false, - const_impls_required: false, + is_in_const_context: false, query_mode: TraitQueryMode::Standard, } } @@ -252,7 +251,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { intercrate: false, intercrate_ambiguity_causes: None, allow_negative_impls, - const_impls_required: false, + is_in_const_context: false, query_mode: TraitQueryMode::Standard, } } @@ -268,7 +267,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { intercrate: false, intercrate_ambiguity_causes: None, allow_negative_impls: false, - const_impls_required: false, + is_in_const_context: false, query_mode, } } @@ -283,7 +282,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { intercrate: false, intercrate_ambiguity_causes: None, allow_negative_impls: false, - const_impls_required: matches!(constness, hir::Constness::Const), + is_in_const_context: matches!(constness, hir::Constness::Const), query_mode: TraitQueryMode::Standard, } } @@ -316,14 +315,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.infcx.tcx } + /// Returns `true` if the trait predicate is considerd `const` to this selection context. + pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool { + match pred.constness { + ty::BoundConstness::ConstIfConst if self.is_in_const_context => true, + _ => false + } + } + /// Returns `true` if the predicate is considered `const` to /// this selection context. pub fn is_predicate_const(&self, pred: ty::Predicate<'_>) -> bool { match pred.kind().skip_binder() { - ty::PredicateKind::Trait(ty::TraitPredicate { - constness: hir::Constness::Const, - .. - }) if self.const_impls_required => true, + ty::PredicateKind::Trait(pred) => self.is_trait_predicate_const(pred), _ => false, } } @@ -1074,8 +1078,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> SelectionResult<'tcx, SelectionCandidate<'tcx>> { let tcx = self.tcx(); // Respect const trait obligations - if self.const_impls_required { - if let hir::Constness::Const = obligation.predicate.skip_binder().constness { + if self.is_trait_predicate_const(obligation.predicate.skip_binder()) { if Some(obligation.predicate.skip_binder().trait_ref.def_id) != tcx.lang_items().sized_trait() // const Sized bounds are skipped @@ -1086,7 +1089,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if tcx.impl_constness(def_id) == hir::Constness::Const => {} // const param ParamCandidate(ty::ConstnessAnd { - constness: hir::Constness::Const, + constness: ty::BoundConstness::ConstIfConst, .. }) => {} // auto trait impl @@ -1100,7 +1103,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } } - } } // Treat negative impls as unimplemented, and reservation impls as ambiguity. if let ImplCandidate(def_id) = candidate { @@ -1495,7 +1497,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // probably best characterized as a "hack", since we might prefer to just do our // best to *not* create essentially duplicate candidates in the first place. other.value.bound_vars().len() <= victim.value.bound_vars().len() - } else if other.value == victim.value && victim.constness == Constness::NotConst { + } else if other.value == victim.value && victim.constness == ty::BoundConstness::NotConst { // Drop otherwise equivalent non-const candidates in favor of const candidates. true } else { diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index b7054d156268..059e0cadd190 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -20,7 +20,7 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_generics, Visitor as _}; use rustc_hir::lang_items::LangItem; -use rustc_hir::{Constness, GenericArg, GenericArgs}; +use rustc_hir::{GenericArg, GenericArgs}; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::{self, Const, DefIdTree, Ty, TyCtxt, TypeFoldable}; @@ -47,8 +47,6 @@ pub trait AstConv<'tcx> { fn item_def_id(&self) -> Option; - fn default_constness_for_trait_bounds(&self) -> Constness; - /// Returns predicates in scope of the form `X: Foo`, where `X` /// is a type parameter `X` with the given id `def_id` and T /// matches `assoc_name`. This is a subset of the full set of @@ -724,7 +722,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { &self, trait_ref: &hir::TraitRef<'_>, span: Span, - constness: Constness, + constness: ty::BoundConstness, self_ty: Ty<'tcx>, bounds: &mut Bounds<'tcx>, speculative: bool, @@ -795,7 +793,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let bound_vars = tcx.late_bound_vars(hir_id); let poly_trait_ref = ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars); - bounds.trait_bounds.push((poly_trait_ref, span, Constness::NotConst)); + bounds.trait_bounds.push((poly_trait_ref, span, ty::BoundConstness::NotConst)); let mut dup_bindings = FxHashMap::default(); for binding in assoc_bindings { @@ -920,14 +918,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { bounds: &mut Bounds<'tcx>, bound_vars: &'tcx ty::List, ) { - let constness = self.default_constness_for_trait_bounds(); for ast_bound in ast_bounds { match *ast_bound { hir::GenericBound::Trait(ref b, hir::TraitBoundModifier::None) => { self.instantiate_poly_trait_ref( &b.trait_ref, b.span, - Constness::NotConst, + ty::BoundConstness::NotConst, param_ty, bounds, false, @@ -937,7 +934,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.instantiate_poly_trait_ref( &b.trait_ref, b.span, - constness, + ty::BoundConstness::ConstIfConst, param_ty, bounds, false, @@ -1251,7 +1248,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } = self.instantiate_poly_trait_ref( &trait_bound.trait_ref, trait_bound.span, - Constness::NotConst, + ty::BoundConstness::NotConst, dummy_self, &mut bounds, false, @@ -1330,7 +1327,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id())); for (base_trait_ref, span, constness) in regular_traits_refs_spans { - assert_eq!(constness, Constness::NotConst); + assert_eq!(constness, ty::BoundConstness::NotConst); for obligation in traits::elaborate_trait_ref(tcx, base_trait_ref) { debug!( diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs index 5d2006407226..24474e163b9d 100644 --- a/compiler/rustc_typeck/src/bounds.rs +++ b/compiler/rustc_typeck/src/bounds.rs @@ -1,7 +1,6 @@ //! Bounds are restrictions applied to some types after they've been converted into the //! `ty` form from the HIR. -use rustc_hir::Constness; use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness}; use rustc_span::Span; @@ -30,7 +29,7 @@ pub struct Bounds<'tcx> { /// A list of trait bounds. So if you had `T: Debug` this would be /// `T: Debug`. Note that the self-type is explicit here. - pub trait_bounds: Vec<(ty::PolyTraitRef<'tcx>, Span, Constness)>, + pub trait_bounds: Vec<(ty::PolyTraitRef<'tcx>, Span, ty::BoundConstness)>, /// A list of projection equality bounds. So if you had `T: /// Iterator` this would include ` AstConv<'tcx> for FnCtxt<'a, 'tcx> { None } - fn default_constness_for_trait_bounds(&self) -> hir::Constness { - self.tcx.hir().get(self.body_id).constness_for_typeck() - } - fn get_type_parameter_bounds( &self, _: Span, diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 3ae26c3eb78e..f0f7f15a0a6c 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -365,10 +365,6 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { Some(self.item_def_id) } - fn default_constness_for_trait_bounds(&self) -> hir::Constness { - self.node().constness_for_typeck() - } - fn get_type_parameter_bounds( &self, span: Span, @@ -664,7 +660,6 @@ impl ItemCtxt<'tcx> { only_self_bounds: OnlySelfBounds, assoc_name: Option, ) -> Vec<(ty::Predicate<'tcx>, Span)> { - let constness = self.default_constness_for_trait_bounds(); let from_ty_params = ast_generics .params .iter() @@ -677,7 +672,7 @@ impl ItemCtxt<'tcx> { Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name), None => true, }) - .flat_map(|b| predicates_from_bound(self, ty, b, constness)); + .flat_map(|b| predicates_from_bound(self, ty, b)); let from_where_clauses = ast_generics .where_clause @@ -703,7 +698,7 @@ impl ItemCtxt<'tcx> { }) .filter_map(move |b| bt.map(|bt| (bt, b))) }) - .flat_map(|(bt, b)| predicates_from_bound(self, bt, b, constness)); + .flat_map(|(bt, b)| predicates_from_bound(self, bt, b)); from_ty_params.chain(from_where_clauses).collect() } @@ -2031,7 +2026,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let mut is_default_impl_trait = None; let icx = ItemCtxt::new(tcx, def_id); - let constness = icx.default_constness_for_trait_bounds(); const NO_GENERICS: &hir::Generics<'_> = &hir::Generics::empty(); @@ -2227,8 +2221,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP match bound { hir::GenericBound::Trait(poly_trait_ref, modifier) => { let constness = match modifier { - hir::TraitBoundModifier::None => hir::Constness::NotConst, - hir::TraitBoundModifier::MaybeConst => constness, + hir::TraitBoundModifier::None => ty::BoundConstness::NotConst, + hir::TraitBoundModifier::MaybeConst => ty::BoundConstness::ConstIfConst, // We ignore `where T: ?Sized`, it is already part of // type parameter `T`. hir::TraitBoundModifier::Maybe => continue, @@ -2491,14 +2485,13 @@ fn predicates_from_bound<'tcx>( astconv: &dyn AstConv<'tcx>, param_ty: Ty<'tcx>, bound: &'tcx hir::GenericBound<'tcx>, - constness: hir::Constness, ) -> Vec<(ty::Predicate<'tcx>, Span)> { match *bound { hir::GenericBound::Trait(ref tr, modifier) => { let constness = match modifier { hir::TraitBoundModifier::Maybe => return vec![], - hir::TraitBoundModifier::MaybeConst => constness, - hir::TraitBoundModifier::None => hir::Constness::NotConst, + hir::TraitBoundModifier::MaybeConst => ty::BoundConstness::ConstIfConst, + hir::TraitBoundModifier::None => ty::BoundConstness::NotConst, }; let mut bounds = Bounds::default(); diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index d3e4be128a8d..8ecd6034ad69 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -68,7 +68,6 @@ use crate::constrained_generic_params as cgp; use rustc_data_structures::fx::FxHashSet; -use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::{InferCtxt, RegionckMode, TyCtxtInferExt}; @@ -368,7 +367,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc // items. ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, - constness: hir::Constness::NotConst, + constness: ty::BoundConstness::NotConst, }) => { if !matches!( trait_predicate_kind(tcx, predicate), @@ -399,7 +398,7 @@ fn trait_predicate_kind<'tcx>( match predicate.kind().skip_binder() { ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, - constness: hir::Constness::NotConst, + constness: ty::BoundConstness::NotConst, }) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind), ty::PredicateKind::Trait(_) | ty::PredicateKind::RegionOutlives(_) diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 638a46fec36f..749f681e92ed 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -548,7 +548,7 @@ pub fn hir_trait_to_predicates<'tcx>( &item_cx, hir_trait, DUMMY_SP, - hir::Constness::NotConst, + ty::BoundConstness::NotConst, self_ty, &mut bounds, true, From 580ca930ac6423dd1dc6a1d90f9d899c8fb5e562 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 27 Aug 2021 07:12:40 +0000 Subject: [PATCH 188/269] Fix UI test --- .../call-generic-method-dup-bound.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs index 5853b66b868a..7185376b440c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs @@ -16,7 +16,9 @@ impl const PartialEq for S { // This duplicate bound should not result in ambiguities. It should be equivalent to a single ~const // bound. -const fn equals_self(t: &T) -> bool { +// const fn equals_self(t: &T) -> bool { +// FIXME(fee1-dead)^ why should the order matter here? +const fn equals_self(t: &T) -> bool { *t == *t } From f3d96e939185e1fd35f80a25656bb8c53a0885b9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 27 Aug 2021 08:09:00 +0000 Subject: [PATCH 189/269] fmt --- .../src/transform/check_consts/check.rs | 13 +++-- .../rustc_trait_selection/src/traits/mod.rs | 5 +- .../src/traits/select/mod.rs | 50 ++++++++++--------- compiler/rustc_typeck/src/collect.rs | 4 +- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_consts/check.rs b/compiler/rustc_mir/src/transform/check_consts/check.rs index 944b5ca89860..2b748062cdf2 100644 --- a/compiler/rustc_mir/src/transform/check_consts/check.rs +++ b/compiler/rustc_mir/src/transform/check_consts/check.rs @@ -826,7 +826,8 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { ); let implsrc = tcx.infer_ctxt().enter(|infcx| { - let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const); + let mut selcx = + SelectionContext::with_constness(&infcx, hir::Constness::Const); selcx.select(&obligation) }); @@ -834,13 +835,17 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => { debug!( "const_trait_impl: provided {:?} via where-clause in {:?}", - trait_ref, param_env + trait_ref, param_env ); return; } Ok(Some(ImplSource::UserDefined(data))) => { let callee_name = tcx.item_name(callee); - if let Some(&did) = tcx.associated_item_def_ids(data.impl_def_id).iter().find(|did| tcx.item_name(**did) == callee_name) { + if let Some(&did) = tcx + .associated_item_def_ids(data.impl_def_id) + .iter() + .find(|did| tcx.item_name(**did) == callee_name) + { callee = did; } } @@ -909,7 +914,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { // trait, but for it to still be non-const can be that the impl is // using default method bodies. nonconst_call_permission = true; - } + } } if !nonconst_call_permission { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index cec07281d2ab..17a4184c3c9e 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -778,7 +778,10 @@ pub fn vtable_trait_upcasting_coercion_new_vptr_slot( let obligation = Obligation::new( ObligationCause::dummy(), ty::ParamEnv::reveal_all(), - ty::Binder::dummy(ty::TraitPredicate { trait_ref, constness: ty::BoundConstness::NotConst }), + ty::Binder::dummy(ty::TraitPredicate { + trait_ref, + constness: ty::BoundConstness::NotConst, + }), ); let implsrc = tcx.infer_ctxt().enter(|infcx| { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 40e413847e03..6cf1dabad859 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -319,7 +319,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool { match pred.constness { ty::BoundConstness::ConstIfConst if self.is_in_const_context => true, - _ => false + _ => false, } } @@ -1079,30 +1079,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.tcx(); // Respect const trait obligations if self.is_trait_predicate_const(obligation.predicate.skip_binder()) { - if Some(obligation.predicate.skip_binder().trait_ref.def_id) - != tcx.lang_items().sized_trait() - // const Sized bounds are skipped - { - match candidate { - // const impl - ImplCandidate(def_id) - if tcx.impl_constness(def_id) == hir::Constness::Const => {} - // const param - ParamCandidate(ty::ConstnessAnd { - constness: ty::BoundConstness::ConstIfConst, - .. - }) => {} - // auto trait impl - AutoImplCandidate(..) => {} - // generator, this will raise error in other places - // or ignore error with const_async_blocks feature - GeneratorCandidate => {} - _ => { - // reject all other types of candidates - return Err(Unimplemented); - } + if Some(obligation.predicate.skip_binder().trait_ref.def_id) + != tcx.lang_items().sized_trait() + // const Sized bounds are skipped + { + match candidate { + // const impl + ImplCandidate(def_id) + if tcx.impl_constness(def_id) == hir::Constness::Const => {} + // const param + ParamCandidate(ty::ConstnessAnd { + constness: ty::BoundConstness::ConstIfConst, + .. + }) => {} + // auto trait impl + AutoImplCandidate(..) => {} + // generator, this will raise error in other places + // or ignore error with const_async_blocks feature + GeneratorCandidate => {} + _ => { + // reject all other types of candidates + return Err(Unimplemented); } } + } } // Treat negative impls as unimplemented, and reservation impls as ambiguity. if let ImplCandidate(def_id) = candidate { @@ -1497,7 +1497,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // probably best characterized as a "hack", since we might prefer to just do our // best to *not* create essentially duplicate candidates in the first place. other.value.bound_vars().len() <= victim.value.bound_vars().len() - } else if other.value == victim.value && victim.constness == ty::BoundConstness::NotConst { + } else if other.value == victim.value + && victim.constness == ty::BoundConstness::NotConst + { // Drop otherwise equivalent non-const candidates in favor of const candidates. true } else { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index f0f7f15a0a6c..b514176ad529 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2222,7 +2222,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP hir::GenericBound::Trait(poly_trait_ref, modifier) => { let constness = match modifier { hir::TraitBoundModifier::None => ty::BoundConstness::NotConst, - hir::TraitBoundModifier::MaybeConst => ty::BoundConstness::ConstIfConst, + hir::TraitBoundModifier::MaybeConst => { + ty::BoundConstness::ConstIfConst + } // We ignore `where T: ?Sized`, it is already part of // type parameter `T`. hir::TraitBoundModifier::Maybe => continue, From 83d986aa28619820e446279c5304a1ea2bd587e0 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 25 Aug 2021 14:51:22 +0300 Subject: [PATCH 190/269] rustc_target: add lifetime parameter to `LayoutOf`. --- .../rustc_codegen_cranelift/src/common.rs | 4 ++-- compiler/rustc_codegen_llvm/src/builder.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- .../rustc_codegen_ssa/src/traits/backend.rs | 9 ++++++-- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 22 ++++++++----------- .../rustc_mir/src/interpret/eval_context.rs | 2 +- .../rustc_mir/src/transform/const_prop.rs | 2 +- compiler/rustc_passes/src/layout_test.rs | 2 +- compiler/rustc_target/src/abi/call/aarch64.rs | 8 +++---- compiler/rustc_target/src/abi/call/amdgpu.rs | 6 ++--- compiler/rustc_target/src/abi/call/arm.rs | 8 +++---- compiler/rustc_target/src/abi/call/mips.rs | 17 ++++++-------- compiler/rustc_target/src/abi/call/mips64.rs | 8 +++---- compiler/rustc_target/src/abi/call/mod.rs | 4 ++-- .../rustc_target/src/abi/call/powerpc64.rs | 8 +++---- compiler/rustc_target/src/abi/call/riscv.rs | 10 ++++----- compiler/rustc_target/src/abi/call/s390x.rs | 12 ++++------ compiler/rustc_target/src/abi/call/sparc.rs | 17 ++++++-------- compiler/rustc_target/src/abi/call/sparc64.rs | 8 +++---- compiler/rustc_target/src/abi/call/wasm.rs | 8 +++---- compiler/rustc_target/src/abi/call/x86.rs | 4 ++-- compiler/rustc_target/src/abi/call/x86_64.rs | 6 ++--- compiler/rustc_target/src/abi/mod.rs | 19 ++++++---------- 24 files changed, 88 insertions(+), 102 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 892ccf27f6df..03f462a63b31 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -256,7 +256,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) inline_asm_index: u32, } -impl<'tcx> LayoutOf for FunctionCx<'_, '_, 'tcx> { +impl<'tcx> LayoutOf<'tcx> for FunctionCx<'_, '_, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; @@ -364,7 +364,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { pub(crate) struct RevealAllLayoutCx<'tcx>(pub(crate) TyCtxt<'tcx>); -impl<'tcx> LayoutOf for RevealAllLayoutCx<'tcx> { +impl<'tcx> LayoutOf<'tcx> for RevealAllLayoutCx<'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 13538683e05a..47529f719b51 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -88,7 +88,7 @@ impl HasTargetSpec for Builder<'_, '_, 'tcx> { } } -impl abi::LayoutOf for Builder<'_, '_, 'tcx> { +impl abi::LayoutOf<'tcx> for Builder<'_, '_, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 35c866d48a41..45da18d4a24f 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -835,7 +835,7 @@ impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> { } } -impl LayoutOf for CodegenCx<'ll, 'tcx> { +impl LayoutOf<'tcx> for CodegenCx<'ll, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index dc4146ec7b58..1393fc71d6bc 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -39,12 +39,17 @@ pub trait BackendTypes { } pub trait Backend<'tcx>: - Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + Sized + + BackendTypes + + HasTyCtxt<'tcx> + + LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> { } impl<'tcx, T> Backend<'tcx> for T where - Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + Self: BackendTypes + + HasTyCtxt<'tcx> + + LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> { } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index c2a46e997df4..6c622a430158 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -1059,7 +1059,7 @@ impl<'tcx> LateContext<'tcx> { } } -impl<'tcx> LayoutOf for LateContext<'tcx> { +impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = Result, LayoutError<'tcx>>; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 5068ace58b46..b388f71d9f29 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2054,7 +2054,7 @@ impl<'tcx, T: HasTyCtxt<'tcx>> HasTyCtxt<'tcx> for LayoutCx<'tcx, T> { pub type TyAndLayout<'tcx> = rustc_target::abi::TyAndLayout<'tcx, Ty<'tcx>>; -impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { +impl LayoutOf<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> { type Ty = Ty<'tcx>; type TyAndLayout = Result, LayoutError<'tcx>>; @@ -2066,7 +2066,7 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { } } -impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { +impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { type Ty = Ty<'tcx>; type TyAndLayout = Result, LayoutError<'tcx>>; @@ -2080,9 +2080,7 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { impl<'tcx, C> TyAndLayoutMethods<'tcx, C> for Ty<'tcx> where - C: LayoutOf, TyAndLayout: MaybeResult>> - + HasTyCtxt<'tcx> - + HasParamEnv<'tcx>, + C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, { fn for_variant( this: TyAndLayout<'tcx>, @@ -2135,21 +2133,19 @@ where } fn field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { - enum TyMaybeWithLayout { + enum TyMaybeWithLayout<'tcx, C: LayoutOf<'tcx>> { Ty(C::Ty), TyAndLayout(C::TyAndLayout), } fn ty_and_layout_kind< - C: LayoutOf, TyAndLayout: MaybeResult>> - + HasTyCtxt<'tcx> - + HasParamEnv<'tcx>, + C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, >( this: TyAndLayout<'tcx>, cx: &C, i: usize, ty: C::Ty, - ) -> TyMaybeWithLayout { + ) -> TyMaybeWithLayout<'tcx, C> { let tcx = cx.tcx(); let tag_layout = |tag: &Scalar| -> C::TyAndLayout { let layout = Layout::scalar(cx, tag.clone()); @@ -2538,7 +2534,7 @@ impl<'tcx> ty::Instance<'tcx> { pub trait FnAbiExt<'tcx, C> where - C: LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + C: LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> + HasDataLayout + HasTargetSpec + HasTyCtxt<'tcx> @@ -2725,7 +2721,7 @@ pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv { impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>> where - C: LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + C: LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> + HasDataLayout + HasTargetSpec + HasTyCtxt<'tcx> @@ -3006,7 +3002,7 @@ where fn make_thin_self_ptr<'tcx, C>(cx: &C, mut layout: TyAndLayout<'tcx>) -> TyAndLayout<'tcx> where - C: LayoutOf, TyAndLayout = TyAndLayout<'tcx>> + C: LayoutOf<'tcx, Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, { diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 516ef4f4e53c..347359e1456b 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -312,7 +312,7 @@ where } } -impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> { +impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf<'tcx> for InterpCx<'mir, 'tcx, M> { type Ty = Ty<'tcx>; type TyAndLayout = InterpResult<'tcx, TyAndLayout<'tcx>>; diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 1932cd5de29b..c17c88973a97 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -330,7 +330,7 @@ struct ConstPropagator<'mir, 'tcx> { source_info: Option, } -impl<'mir, 'tcx> LayoutOf for ConstPropagator<'mir, 'tcx> { +impl<'mir, 'tcx> LayoutOf<'tcx> for ConstPropagator<'mir, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = Result, LayoutError<'tcx>>; diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 43a3a3062e77..64ea4ee570e8 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -113,7 +113,7 @@ struct UnwrapLayoutCx<'tcx> { param_env: ParamEnv<'tcx>, } -impl LayoutOf for UnwrapLayoutCx<'tcx> { +impl LayoutOf<'tcx> for UnwrapLayoutCx<'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; diff --git a/compiler/rustc_target/src/abi/call/aarch64.rs b/compiler/rustc_target/src/abi/call/aarch64.rs index a5e985d47127..02006e3fd693 100644 --- a/compiler/rustc_target/src/abi/call/aarch64.rs +++ b/compiler/rustc_target/src/abi/call/aarch64.rs @@ -4,7 +4,7 @@ use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; @@ -27,7 +27,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -49,7 +49,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(32); @@ -71,7 +71,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/amdgpu.rs b/compiler/rustc_target/src/abi/call/amdgpu.rs index 0b4f279fece4..404702ae94b1 100644 --- a/compiler/rustc_target/src/abi/call/amdgpu.rs +++ b/compiler/rustc_target/src/abi/call/amdgpu.rs @@ -4,7 +4,7 @@ use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); } @@ -12,7 +12,7 @@ where fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); } @@ -20,7 +20,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/arm.rs b/compiler/rustc_target/src/abi/call/arm.rs index b560e11fe1c5..55bcdba7aaa5 100644 --- a/compiler/rustc_target/src/abi/call/arm.rs +++ b/compiler/rustc_target/src/abi/call/arm.rs @@ -5,7 +5,7 @@ use crate::spec::HasTargetSpec; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { let size = arg.layout.size; @@ -28,7 +28,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -54,7 +54,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(32); @@ -76,7 +76,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { // If this is a target with a hard-float ABI, and the function is not explicitly // `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates. diff --git a/compiler/rustc_target/src/abi/call/mips.rs b/compiler/rustc_target/src/abi/call/mips.rs index 733a7328bd3a..cc443197680e 100644 --- a/compiler/rustc_target/src/abi/call/mips.rs +++ b/compiler/rustc_target/src/abi/call/mips.rs @@ -1,10 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, Size, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, Size}; -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_ret(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -14,10 +13,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_arg(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { let dl = cx.data_layout(); let size = arg.layout.size; @@ -35,10 +33,9 @@ where *offset = offset.align_to(align) + size.align_to(align); } -pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) +pub fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { let mut offset = Size::ZERO; if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/mips64.rs b/compiler/rustc_target/src/abi/call/mips64.rs index a630c84142b4..1b03024e3290 100644 --- a/compiler/rustc_target/src/abi/call/mips64.rs +++ b/compiler/rustc_target/src/abi/call/mips64.rs @@ -20,7 +20,7 @@ fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match ret.layout.field(cx, i).abi { abi::Abi::Scalar(ref scalar) => match scalar.value { @@ -35,7 +35,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { extend_integer_width_mips(ret, 64); @@ -75,7 +75,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { extend_integer_width_mips(arg, 64); @@ -145,7 +145,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 6e0e14037403..452e700d5c20 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -317,7 +317,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn homogeneous_aggregate(&self, cx: &C) -> Result where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = Self>, { match self.abi { Abi::Uninhabited => Err(Heterogeneous), @@ -604,7 +604,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { pub fn adjust_for_cabi(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String> where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if abi == spec::abi::Abi::X86Interrupt { if let Some(arg) = self.args.first_mut() { diff --git a/compiler/rustc_target/src/abi/call/powerpc64.rs b/compiler/rustc_target/src/abi/call/powerpc64.rs index 8c2a9d09a3d9..662a0b44af5c 100644 --- a/compiler/rustc_target/src/abi/call/powerpc64.rs +++ b/compiler/rustc_target/src/abi/call/powerpc64.rs @@ -20,7 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>( ) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { // ELFv1 only passes one-member aggregates transparently. @@ -44,7 +44,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(64); @@ -87,7 +87,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(64); @@ -117,7 +117,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let abi = if cx.target_spec().env == "musl" { ELFv2 diff --git a/compiler/rustc_target/src/abi/call/riscv.rs b/compiler/rustc_target/src/abi/call/riscv.rs index 1ab881dd13d1..f1e7658aec61 100644 --- a/compiler/rustc_target/src/abi/call/riscv.rs +++ b/compiler/rustc_target/src/abi/call/riscv.rs @@ -44,7 +44,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( ) -> Result<(), CannotUseFpConv> where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { match arg_layout.abi { Abi::Scalar(ref scalar) => match scalar.value { @@ -131,7 +131,7 @@ fn should_use_fp_conv<'a, Ty, C>( ) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { let mut field1_kind = RegPassKind::Unknown; let mut field2_kind = RegPassKind::Unknown; @@ -150,7 +150,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) { match conv { @@ -213,7 +213,7 @@ fn classify_arg<'a, Ty, C>( avail_fprs: &mut u64, ) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf>, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { if !is_vararg { match should_use_fp_conv(cx, &arg.layout, xlen, flen) { @@ -321,7 +321,7 @@ fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) { pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let flen = match &cx.target_spec().llvm_abiname[..] { "ilp32f" | "lp64f" => 32, diff --git a/compiler/rustc_target/src/abi/call/s390x.rs b/compiler/rustc_target/src/abi/call/s390x.rs index 005dcc62dfdc..dea5d4605d13 100644 --- a/compiler/rustc_target/src/abi/call/s390x.rs +++ b/compiler/rustc_target/src/abi/call/s390x.rs @@ -4,11 +4,7 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg}; use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; -fn classify_ret<'a, Ty, C>(ret: &mut ArgAbi<'_, Ty>) -where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, -{ +fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 { ret.extend_integer_width_to(64); } else { @@ -19,7 +15,7 @@ where fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), @@ -37,7 +33,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 { arg.extend_integer_width_to(64); @@ -64,7 +60,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(&mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/sparc.rs b/compiler/rustc_target/src/abi/call/sparc.rs index 733a7328bd3a..cc443197680e 100644 --- a/compiler/rustc_target/src/abi/call/sparc.rs +++ b/compiler/rustc_target/src/abi/call/sparc.rs @@ -1,10 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, Size, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, Size}; -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_ret(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(32); @@ -14,10 +13,9 @@ where } } -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) +fn classify_arg(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { let dl = cx.data_layout(); let size = arg.layout.size; @@ -35,10 +33,9 @@ where *offset = offset.align_to(align) + size.align_to(align); } -pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) +pub fn compute_abi_info(cx: &C, fn_abi: &mut FnAbi<'_, Ty>) where - Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf + HasDataLayout, + C: HasDataLayout, { let mut offset = Size::ZERO; if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/sparc64.rs b/compiler/rustc_target/src/abi/call/sparc64.rs index a647675e0735..bdbce38e86ab 100644 --- a/compiler/rustc_target/src/abi/call/sparc64.rs +++ b/compiler/rustc_target/src/abi/call/sparc64.rs @@ -6,7 +6,7 @@ use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { // Ensure we have at most eight uniquely addressable members. @@ -27,7 +27,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { ret.extend_integer_width_to(64); @@ -53,7 +53,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { arg.extend_integer_width_to(64); @@ -77,7 +77,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/wasm.rs b/compiler/rustc_target/src/abi/call/wasm.rs index bf2c08bb1662..c3187dff7af1 100644 --- a/compiler/rustc_target/src/abi/call/wasm.rs +++ b/compiler/rustc_target/src/abi/call/wasm.rs @@ -4,7 +4,7 @@ use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if val.layout.is_aggregate() { if let Some(unit) = val.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()) { @@ -21,7 +21,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); if ret.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, ret) { @@ -32,7 +32,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); if arg.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, arg) { @@ -44,7 +44,7 @@ where pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { classify_ret(cx, &mut fn_abi.ret); diff --git a/compiler/rustc_target/src/abi/call/x86.rs b/compiler/rustc_target/src/abi/call/x86.rs index ff8849e1cf83..d27f1996a617 100644 --- a/compiler/rustc_target/src/abi/call/x86.rs +++ b/compiler/rustc_target/src/abi/call/x86.rs @@ -11,7 +11,7 @@ pub enum Flavor { fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), @@ -29,7 +29,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout + HasTargetSpec, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { if fn_abi.ret.layout.is_aggregate() { diff --git a/compiler/rustc_target/src/abi/call/x86_64.rs b/compiler/rustc_target/src/abi/call/x86_64.rs index a55658b7a3ec..da47396e2d1d 100644 --- a/compiler/rustc_target/src/abi/call/x86_64.rs +++ b/compiler/rustc_target/src/abi/call/x86_64.rs @@ -27,7 +27,7 @@ fn classify_arg<'a, Ty, C>( ) -> Result<[Option; MAX_EIGHTBYTES], Memory> where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { fn classify<'a, Ty, C>( cx: &C, @@ -37,7 +37,7 @@ where ) -> Result<(), Memory> where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !off.is_aligned(layout.align.abi) { if !layout.is_zst() { @@ -173,7 +173,7 @@ const MAX_SSE_REGS: usize = 8; // XMM0-7 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where Ty: TyAndLayoutMethods<'a, C> + Copy, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { let mut int_regs = MAX_INT_REGS; let mut sse_regs = MAX_SSE_REGS; diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 2820a486dfd4..1d1a34dc2484 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1174,9 +1174,9 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { } /// Trait for context types that can compute layouts of things. -pub trait LayoutOf { +pub trait LayoutOf<'a> { type Ty; - type TyAndLayout; + type TyAndLayout: MaybeResult>; fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout; fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyAndLayout { @@ -1184,9 +1184,6 @@ pub trait LayoutOf { } } -/// The `TyAndLayout` above will always be a `MaybeResult>`. -/// We can't add the bound due to the lifetime, but this trait is still useful when -/// writing code that's generic over the `LayoutOf` impl. pub trait MaybeResult { type Error; @@ -1239,7 +1236,7 @@ pub struct PointeeInfo { pub address_space: AddressSpace, } -pub trait TyAndLayoutMethods<'a, C: LayoutOf>: Sized { +pub trait TyAndLayoutMethods<'a, C: LayoutOf<'a, Ty = Self>>: Sized { fn for_variant( this: TyAndLayout<'a, Self>, cx: &C, @@ -1253,17 +1250,15 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn for_variant(self, cx: &C, variant_index: VariantIdx) -> Self where Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf, + C: LayoutOf<'a, Ty = Ty>, { Ty::for_variant(self, cx, variant_index) } - /// Callers might want to use `C: LayoutOf>` - /// to allow recursion (see `might_permit_zero_init` below for an example). pub fn field(self, cx: &C, i: usize) -> C::TyAndLayout where Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf, + C: LayoutOf<'a, Ty = Ty>, { Ty::field(self, cx, i) } @@ -1271,7 +1266,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn pointee_info_at(self, cx: &C, offset: Size) -> Option where Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf, + C: LayoutOf<'a, Ty = Ty>, { Ty::pointee_info_at(self, cx, offset) } @@ -1305,7 +1300,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { where Self: Copy, Ty: TyAndLayoutMethods<'a, C>, - C: LayoutOf> + HasDataLayout, + C: LayoutOf<'a, Ty = Ty, TyAndLayout: MaybeResult> + HasDataLayout, { let scalar_allows_raw_init = move |s: &Scalar| -> bool { if zero { From 8486571a10ce57b02ae19bfb1b31736fb2a1b4fe Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 25 Aug 2021 16:45:24 +0300 Subject: [PATCH 191/269] rustc_target: rename `TyAndLayoutMethods` to `TyAbiInterface`. --- compiler/rustc_codegen_llvm/src/type_of.rs | 7 +++-- compiler/rustc_middle/src/ty/layout.rs | 12 +++++--- compiler/rustc_target/src/abi/call/aarch64.rs | 10 +++---- compiler/rustc_target/src/abi/call/amdgpu.rs | 8 +++--- compiler/rustc_target/src/abi/call/arm.rs | 10 +++---- compiler/rustc_target/src/abi/call/mips64.rs | 10 +++---- compiler/rustc_target/src/abi/call/mod.rs | 6 ++-- .../rustc_target/src/abi/call/powerpc64.rs | 10 +++---- compiler/rustc_target/src/abi/call/riscv.rs | 12 ++++---- compiler/rustc_target/src/abi/call/s390x.rs | 8 +++--- compiler/rustc_target/src/abi/call/sparc64.rs | 10 +++---- compiler/rustc_target/src/abi/call/wasm.rs | 10 +++---- compiler/rustc_target/src/abi/call/x86.rs | 6 ++-- compiler/rustc_target/src/abi/call/x86_64.rs | 8 +++--- compiler/rustc_target/src/abi/mod.rs | 28 +++++++++++-------- 15 files changed, 84 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 85efe3e64836..9818905464dc 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, Ty, TypeFoldable}; use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape}; use rustc_target::abi::{Int, Pointer, F32, F64}; -use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants}; +use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAbiInterface, Variants}; use smallvec::{smallvec, SmallVec}; use tracing::debug; @@ -393,12 +393,15 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { } } + // FIXME(eddyb) this having the same name as `TyAndLayout::pointee_info_at` + // (the inherent method, which is lacking this caching logic) can result in + // the uncached version being called - not wrong, but potentially inefficient. fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size) -> Option { if let Some(&pointee) = cx.pointee_infos.borrow().get(&(self.ty, offset)) { return pointee; } - let result = Ty::pointee_info_at(*self, cx, offset); + let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset); cx.pointee_infos.borrow_mut().insert((self.ty, offset), result); result diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index b388f71d9f29..d8d1f4929adb 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2078,11 +2078,11 @@ impl LayoutOf<'tcx> for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { } } -impl<'tcx, C> TyAndLayoutMethods<'tcx, C> for Ty<'tcx> +impl<'tcx, C> TyAbiInterface<'tcx, C> for Ty<'tcx> where C: LayoutOf<'tcx, Ty = Ty<'tcx>> + HasTyCtxt<'tcx> + HasParamEnv<'tcx>, { - fn for_variant( + fn ty_and_layout_for_variant( this: TyAndLayout<'tcx>, cx: &C, variant_index: VariantIdx, @@ -2132,7 +2132,7 @@ where TyAndLayout { ty: this.ty, layout } } - fn field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { + fn ty_and_layout_field(this: TyAndLayout<'tcx>, cx: &C, i: usize) -> C::TyAndLayout { enum TyMaybeWithLayout<'tcx, C: LayoutOf<'tcx>> { Ty(C::Ty), TyAndLayout(C::TyAndLayout), @@ -2276,7 +2276,11 @@ where }) } - fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option { + fn ty_and_layout_pointee_info_at( + this: TyAndLayout<'tcx>, + cx: &C, + offset: Size, + ) -> Option { let addr_space_of_ty = |ty: Ty<'tcx>| { if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA } }; diff --git a/compiler/rustc_target/src/abi/call/aarch64.rs b/compiler/rustc_target/src/abi/call/aarch64.rs index 02006e3fd693..3d5ca0daca62 100644 --- a/compiler/rustc_target/src/abi/call/aarch64.rs +++ b/compiler/rustc_target/src/abi/call/aarch64.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -26,7 +26,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -48,7 +48,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -70,7 +70,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/amdgpu.rs b/compiler/rustc_target/src/abi/call/amdgpu.rs index 404702ae94b1..289de1406878 100644 --- a/compiler/rustc_target/src/abi/call/amdgpu.rs +++ b/compiler/rustc_target/src/abi/call/amdgpu.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); @@ -11,7 +11,7 @@ where fn classify_arg<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); @@ -19,7 +19,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/arm.rs b/compiler/rustc_target/src/abi/call/arm.rs index 55bcdba7aaa5..4498beaa2dd2 100644 --- a/compiler/rustc_target/src/abi/call/arm.rs +++ b/compiler/rustc_target/src/abi/call/arm.rs @@ -1,10 +1,10 @@ use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -27,7 +27,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -53,7 +53,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, vfp: bool) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -75,7 +75,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { // If this is a target with a hard-float ABI, and the function is not explicitly diff --git a/compiler/rustc_target/src/abi/call/mips64.rs b/compiler/rustc_target/src/abi/call/mips64.rs index 1b03024e3290..99e70f216b24 100644 --- a/compiler/rustc_target/src/abi/call/mips64.rs +++ b/compiler/rustc_target/src/abi/call/mips64.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; -use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips @@ -19,7 +19,7 @@ fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match ret.layout.field(cx, i).abi { @@ -34,7 +34,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -74,7 +74,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -144,7 +144,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 452e700d5c20..3c0309973908 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -1,5 +1,5 @@ use crate::abi::{self, Abi, Align, FieldsShape, Size}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::{self, HasTargetSpec}; mod aarch64; @@ -316,7 +316,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { /// specific targets. pub fn homogeneous_aggregate(&self, cx: &C) -> Result where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = Self>, { match self.abi { @@ -603,7 +603,7 @@ pub struct FnAbi<'a, Ty> { impl<'a, Ty> FnAbi<'a, Ty> { pub fn adjust_for_cabi(&mut self, cx: &C, abi: spec::abi::Abi) -> Result<(), String> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if abi == spec::abi::Abi::X86Interrupt { diff --git a/compiler/rustc_target/src/abi/call/powerpc64.rs b/compiler/rustc_target/src/abi/call/powerpc64.rs index 662a0b44af5c..62570a87f19a 100644 --- a/compiler/rustc_target/src/abi/call/powerpc64.rs +++ b/compiler/rustc_target/src/abi/call/powerpc64.rs @@ -3,7 +3,7 @@ // need to be fixed when PowerPC vector support is added. use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{Endian, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; #[derive(Debug, Clone, Copy, PartialEq)] @@ -19,7 +19,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>( abi: ABI, ) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -43,7 +43,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -86,7 +86,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -116,7 +116,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let abi = if cx.target_spec().env == "musl" { diff --git a/compiler/rustc_target/src/abi/call/riscv.rs b/compiler/rustc_target/src/abi/call/riscv.rs index f1e7658aec61..c29fc7a08c02 100644 --- a/compiler/rustc_target/src/abi/call/riscv.rs +++ b/compiler/rustc_target/src/abi/call/riscv.rs @@ -6,7 +6,7 @@ use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform}; use crate::abi::{ - self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods, + self, Abi, FieldsShape, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout, }; use crate::spec::HasTargetSpec; @@ -43,7 +43,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( field2_kind: &mut RegPassKind, ) -> Result<(), CannotUseFpConv> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { match arg_layout.abi { @@ -130,7 +130,7 @@ fn should_use_fp_conv<'a, Ty, C>( flen: u64, ) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { let mut field1_kind = RegPassKind::Unknown; @@ -149,7 +149,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u64) -> bool where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) { @@ -212,7 +212,7 @@ fn classify_arg<'a, Ty, C>( avail_gprs: &mut u64, avail_fprs: &mut u64, ) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>>, { if !is_vararg { @@ -320,7 +320,7 @@ fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) { pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { let flen = match &cx.target_spec().llvm_abiname[..] { diff --git a/compiler/rustc_target/src/abi/call/s390x.rs b/compiler/rustc_target/src/abi/call/s390x.rs index dea5d4605d13..bd4eff5e3217 100644 --- a/compiler/rustc_target/src/abi/call/s390x.rs +++ b/compiler/rustc_target/src/abi/call/s390x.rs @@ -2,7 +2,7 @@ // for a pre-z13 machine or using -mno-vx. use crate::abi::call::{ArgAbi, FnAbi, Reg}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 { @@ -14,7 +14,7 @@ fn classify_ret(ret: &mut ArgAbi<'_, Ty>) { fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { @@ -32,7 +32,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 { @@ -59,7 +59,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/sparc64.rs b/compiler/rustc_target/src/abi/call/sparc64.rs index bdbce38e86ab..1fe7b74c2bcf 100644 --- a/compiler/rustc_target/src/abi/call/sparc64.rs +++ b/compiler/rustc_target/src/abi/call/sparc64.rs @@ -1,11 +1,11 @@ // FIXME: This needs an audit for correctness and completeness. use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| { @@ -26,7 +26,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !ret.layout.is_aggregate() { @@ -52,7 +52,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !arg.layout.is_aggregate() { @@ -76,7 +76,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/wasm.rs b/compiler/rustc_target/src/abi/call/wasm.rs index c3187dff7af1..7f607ebead1d 100644 --- a/compiler/rustc_target/src/abi/call/wasm.rs +++ b/compiler/rustc_target/src/abi/call/wasm.rs @@ -1,9 +1,9 @@ use crate::abi::call::{ArgAbi, FnAbi, Uniform}; -use crate::abi::{HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; fn unwrap_trivial_aggregate<'a, Ty, C>(cx: &C, val: &mut ArgAbi<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if val.layout.is_aggregate() { @@ -20,7 +20,7 @@ where fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { ret.extend_integer_width_to(32); @@ -31,7 +31,7 @@ where fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { arg.extend_integer_width_to(32); @@ -43,7 +43,7 @@ where /// The purpose of this ABI is to match the C ABI (aka clang) exactly. pub fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/x86.rs b/compiler/rustc_target/src/abi/call/x86.rs index d27f1996a617..41e9e8420617 100644 --- a/compiler/rustc_target/src/abi/call/x86.rs +++ b/compiler/rustc_target/src/abi/call/x86.rs @@ -1,5 +1,5 @@ use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind}; -use crate::abi::{self, HasDataLayout, LayoutOf, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, HasDataLayout, LayoutOf, TyAbiInterface, TyAndLayout}; use crate::spec::HasTargetSpec; #[derive(PartialEq)] @@ -10,7 +10,7 @@ pub enum Flavor { fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { match layout.abi { @@ -28,7 +28,7 @@ where pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout + HasTargetSpec, { if !fn_abi.ret.is_ignore() { diff --git a/compiler/rustc_target/src/abi/call/x86_64.rs b/compiler/rustc_target/src/abi/call/x86_64.rs index da47396e2d1d..9146839b086a 100644 --- a/compiler/rustc_target/src/abi/call/x86_64.rs +++ b/compiler/rustc_target/src/abi/call/x86_64.rs @@ -2,7 +2,7 @@ // https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind}; -use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAndLayout, TyAndLayoutMethods}; +use crate::abi::{self, Abi, HasDataLayout, LayoutOf, Size, TyAbiInterface, TyAndLayout}; /// Classification of "eightbyte" components. // N.B., the order of the variants is from general to specific, @@ -26,7 +26,7 @@ fn classify_arg<'a, Ty, C>( arg: &ArgAbi<'a, Ty>, ) -> Result<[Option; MAX_EIGHTBYTES], Memory> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { fn classify<'a, Ty, C>( @@ -36,7 +36,7 @@ where off: Size, ) -> Result<(), Memory> where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { if !off.is_aligned(layout.align.abi) { @@ -172,7 +172,7 @@ const MAX_SSE_REGS: usize = 8; // XMM0-7 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) where - Ty: TyAndLayoutMethods<'a, C> + Copy, + Ty: TyAbiInterface<'a, C> + Copy, C: LayoutOf<'a, Ty = Ty, TyAndLayout = TyAndLayout<'a, Ty>> + HasDataLayout, { let mut int_regs = MAX_INT_REGS; diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 1d1a34dc2484..250afbecd58e 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1236,39 +1236,45 @@ pub struct PointeeInfo { pub address_space: AddressSpace, } -pub trait TyAndLayoutMethods<'a, C: LayoutOf<'a, Ty = Self>>: Sized { - fn for_variant( +/// Trait that needs to be implemented by the higher-level type representation +/// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality. +pub trait TyAbiInterface<'a, C: LayoutOf<'a, Ty = Self>>: Sized { + fn ty_and_layout_for_variant( this: TyAndLayout<'a, Self>, cx: &C, variant_index: VariantIdx, ) -> TyAndLayout<'a, Self>; - fn field(this: TyAndLayout<'a, Self>, cx: &C, i: usize) -> C::TyAndLayout; - fn pointee_info_at(this: TyAndLayout<'a, Self>, cx: &C, offset: Size) -> Option; + fn ty_and_layout_field(this: TyAndLayout<'a, Self>, cx: &C, i: usize) -> C::TyAndLayout; + fn ty_and_layout_pointee_info_at( + this: TyAndLayout<'a, Self>, + cx: &C, + offset: Size, + ) -> Option; } impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn for_variant(self, cx: &C, variant_index: VariantIdx) -> Self where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::for_variant(self, cx, variant_index) + Ty::ty_and_layout_for_variant(self, cx, variant_index) } pub fn field(self, cx: &C, i: usize) -> C::TyAndLayout where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::field(self, cx, i) + Ty::ty_and_layout_field(self, cx, i) } pub fn pointee_info_at(self, cx: &C, offset: Size) -> Option where - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty>, { - Ty::pointee_info_at(self, cx, offset) + Ty::ty_and_layout_pointee_info_at(self, cx, offset) } } @@ -1299,7 +1305,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { pub fn might_permit_raw_init(self, cx: &C, zero: bool) -> Result where Self: Copy, - Ty: TyAndLayoutMethods<'a, C>, + Ty: TyAbiInterface<'a, C>, C: LayoutOf<'a, Ty = Ty, TyAndLayout: MaybeResult> + HasDataLayout, { let scalar_allows_raw_init = move |s: &Scalar| -> bool { From 87d1fb747f8ed3dde3cd36c17d1ef735872a7bf9 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 25 Aug 2021 16:40:39 +0300 Subject: [PATCH 192/269] rustc_target: require `TyAbiInterface` in `LayoutOf`. --- compiler/rustc_lint/src/context.rs | 23 ++++++++++++++++++- compiler/rustc_middle/src/ty/layout.rs | 14 +++++++++++ .../rustc_mir/src/transform/const_prop.rs | 11 +++++++-- compiler/rustc_target/src/abi/mod.rs | 4 ++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 6c622a430158..7dbc3d60439c 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -41,7 +41,7 @@ use rustc_session::Session; use rustc_session::SessionLintStore; use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; -use rustc_target::abi::LayoutOf; +use rustc_target::abi::{self, LayoutOf}; use tracing::debug; use std::cell::Cell; @@ -1059,6 +1059,27 @@ impl<'tcx> LateContext<'tcx> { } } +impl<'tcx> abi::HasDataLayout for LateContext<'tcx> { + #[inline] + fn data_layout(&self) -> &abi::TargetDataLayout { + &self.tcx.data_layout + } +} + +impl<'tcx> ty::layout::HasTyCtxt<'tcx> for LateContext<'tcx> { + #[inline] + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } +} + +impl<'tcx> ty::layout::HasParamEnv<'tcx> for LateContext<'tcx> { + #[inline] + fn param_env(&self) -> ty::ParamEnv<'tcx> { + self.param_env + } +} + impl<'tcx> LayoutOf<'tcx> for LateContext<'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = Result, LayoutError<'tcx>>; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index d8d1f4929adb..df5e6b2da991 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -2034,6 +2034,20 @@ impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> { } } +impl<'tcx> HasDataLayout for ty::query::TyCtxtAt<'tcx> { + #[inline] + fn data_layout(&self) -> &TargetDataLayout { + &self.data_layout + } +} + +impl<'tcx> HasTyCtxt<'tcx> for ty::query::TyCtxtAt<'tcx> { + #[inline] + fn tcx(&self) -> TyCtxt<'tcx> { + **self + } +} + impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> { fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index c17c88973a97..5c51aa4ed679 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::{ Location, Operand, Place, Rvalue, SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutError, TyAndLayout}; +use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{ self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable, @@ -346,13 +346,20 @@ impl<'mir, 'tcx> HasDataLayout for ConstPropagator<'mir, 'tcx> { } } -impl<'mir, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { +impl<'mir, 'tcx> ty::layout::HasTyCtxt<'tcx> for ConstPropagator<'mir, 'tcx> { #[inline] fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } } +impl<'mir, 'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'mir, 'tcx> { + #[inline] + fn param_env(&self) -> ty::ParamEnv<'tcx> { + self.param_env + } +} + impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn new( body: &Body<'tcx>, diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 250afbecd58e..367071926fe6 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -1174,8 +1174,8 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> { } /// Trait for context types that can compute layouts of things. -pub trait LayoutOf<'a> { - type Ty; +pub trait LayoutOf<'a>: Sized { + type Ty: TyAbiInterface<'a, Self>; type TyAndLayout: MaybeResult>; fn layout_of(&self, ty: Self::Ty) -> Self::TyAndLayout; From 0a3a6087fb91d185700d18b13365ad5969c97eb9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 27 Aug 2021 08:26:35 +0000 Subject: [PATCH 193/269] Revive tests --- src/test/ui/rfc-2632-const-trait-impl/tilde-twice.rs | 6 ++++++ src/test/ui/rfc-2632-const-trait-impl/tilde-twice.stderr | 8 ++++++++ src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs | 6 ++++++ .../ui/rfc-2632-const-trait-impl/without-tilde.stderr | 8 ++++++++ 4 files changed, 28 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-twice.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-twice.stderr create mode 100644 src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.rs new file mode 100644 index 000000000000..06e4ede8b5e7 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.rs @@ -0,0 +1,6 @@ +// compile-flags: -Z parse-only + +#![feature(const_trait_impl)] + +struct S; +//~^ ERROR expected identifier, found `~` diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.stderr new file mode 100644 index 000000000000..928d23e8a424 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-twice.stderr @@ -0,0 +1,8 @@ +error: expected identifier, found `~` + --> $DIR/tilde-twice.rs:5:20 + | +LL | struct S; + | ^ expected identifier + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs new file mode 100644 index 000000000000..96ba393bd859 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs @@ -0,0 +1,6 @@ +// compiler-flags: -Z parse-only + +#![feature(const_trait_impl)] + +struct S; +//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path diff --git a/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr new file mode 100644 index 000000000000..b6b77ac4a2fb --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/without-tilde.stderr @@ -0,0 +1,8 @@ +error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found keyword `const` + --> $DIR/without-tilde.rs:5:13 + | +LL | struct S; + | ^^^^^ expected one of 10 possible tokens + +error: aborting due to previous error + From e6637284cca42cb497b6b767776136ede71c7119 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 27 Aug 2021 04:52:51 -0700 Subject: [PATCH 194/269] Remove vestigial rustfix tests. --- .../rustfix/closure-immutable-outer-variable.fixed | 10 ---------- src/test/rustfix/closure-immutable-outer-variable.rs | 10 ---------- src/test/rustfix/empty-no-fixes.fixed | 1 - src/test/rustfix/empty-no-fixes.rs | 1 - src/test/rustfix/empty-no-fixes.rs.fixed | 2 -- src/test/rustfix/issue-45562.fixed | 3 --- src/test/rustfix/issue-45562.rs | 3 --- ...d-extern-crate-rename-suggestion-formatting.fixed | 2 -- ...-bad-extern-crate-rename-suggestion-formatting.rs | 2 -- ...ue-46756-consider-borrowing-cast-or-binexpr.fixed | 12 ------------ ...issue-46756-consider-borrowing-cast-or-binexpr.rs | 12 ------------ src/test/rustfix/main-no-fixes.fixed | 1 - src/test/rustfix/main-no-fixes.rs | 1 - src/test/rustfix/main-no-fixes.rs.fixed | 1 - src/test/rustfix/missing-comma-in-match.fixed | 7 ------- src/test/rustfix/missing-comma-in-match.rs | 7 ------- src/test/rustfix/str-as-char.fixed | 3 --- src/test/rustfix/str-as-char.rs | 3 --- src/test/rustfix/tuple-float-index.fixed | 3 --- src/test/rustfix/tuple-float-index.rs | 3 --- 20 files changed, 87 deletions(-) delete mode 100644 src/test/rustfix/closure-immutable-outer-variable.fixed delete mode 100644 src/test/rustfix/closure-immutable-outer-variable.rs delete mode 100644 src/test/rustfix/empty-no-fixes.fixed delete mode 100644 src/test/rustfix/empty-no-fixes.rs delete mode 100644 src/test/rustfix/empty-no-fixes.rs.fixed delete mode 100644 src/test/rustfix/issue-45562.fixed delete mode 100644 src/test/rustfix/issue-45562.rs delete mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed delete mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs delete mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed delete mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs delete mode 100644 src/test/rustfix/main-no-fixes.fixed delete mode 100644 src/test/rustfix/main-no-fixes.rs delete mode 100644 src/test/rustfix/main-no-fixes.rs.fixed delete mode 100644 src/test/rustfix/missing-comma-in-match.fixed delete mode 100644 src/test/rustfix/missing-comma-in-match.rs delete mode 100644 src/test/rustfix/str-as-char.fixed delete mode 100644 src/test/rustfix/str-as-char.rs delete mode 100644 src/test/rustfix/tuple-float-index.fixed delete mode 100644 src/test/rustfix/tuple-float-index.rs diff --git a/src/test/rustfix/closure-immutable-outer-variable.fixed b/src/test/rustfix/closure-immutable-outer-variable.fixed deleted file mode 100644 index 05bbc13d714f..000000000000 --- a/src/test/rustfix/closure-immutable-outer-variable.fixed +++ /dev/null @@ -1,10 +0,0 @@ -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let mut y = true; - foo(Box::new(move || y = false) as Box<_>); -} diff --git a/src/test/rustfix/closure-immutable-outer-variable.rs b/src/test/rustfix/closure-immutable-outer-variable.rs deleted file mode 100644 index 6ed1bc12cb52..000000000000 --- a/src/test/rustfix/closure-immutable-outer-variable.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let y = true; - foo(Box::new(move || y = false) as Box<_>); -} diff --git a/src/test/rustfix/empty-no-fixes.fixed b/src/test/rustfix/empty-no-fixes.fixed deleted file mode 100644 index 3724a00ce7ce..000000000000 --- a/src/test/rustfix/empty-no-fixes.fixed +++ /dev/null @@ -1 +0,0 @@ -// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs b/src/test/rustfix/empty-no-fixes.rs deleted file mode 100644 index 3724a00ce7ce..000000000000 --- a/src/test/rustfix/empty-no-fixes.rs +++ /dev/null @@ -1 +0,0 @@ -// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs.fixed b/src/test/rustfix/empty-no-fixes.rs.fixed deleted file mode 100644 index e30d3ae0965a..000000000000 --- a/src/test/rustfix/empty-no-fixes.rs.fixed +++ /dev/null @@ -1,2 +0,0 @@ -// compile-flags:--crate-type lib -fn foo() {} diff --git a/src/test/rustfix/issue-45562.fixed b/src/test/rustfix/issue-45562.fixed deleted file mode 100644 index 955b2cbf899b..000000000000 --- a/src/test/rustfix/issue-45562.fixed +++ /dev/null @@ -1,3 +0,0 @@ -#[no_mangle] pub static RAH: usize = 5; - -fn main() {} diff --git a/src/test/rustfix/issue-45562.rs b/src/test/rustfix/issue-45562.rs deleted file mode 100644 index a1ac07044e2c..000000000000 --- a/src/test/rustfix/issue-45562.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[no_mangle] pub const RAH: usize = 5; - -fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed deleted file mode 100644 index b4ae4dc1ab2f..000000000000 --- a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed +++ /dev/null @@ -1,2 +0,0 @@ -extern crate std as other_std; -fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs deleted file mode 100644 index a202b6c389a8..000000000000 --- a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs +++ /dev/null @@ -1,2 +0,0 @@ -extern crate std; -fn main() {} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed deleted file mode 100644 index bedc8e15ace6..000000000000 --- a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(&(behold as usize)); - light_flows_our_war_of_mocking_words(&(with_tears + 4)); -} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs deleted file mode 100644 index 9c7ae9657c00..000000000000 --- a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(behold as usize); - light_flows_our_war_of_mocking_words(with_tears + 4); -} diff --git a/src/test/rustfix/main-no-fixes.fixed b/src/test/rustfix/main-no-fixes.fixed deleted file mode 100644 index f328e4d9d04c..000000000000 --- a/src/test/rustfix/main-no-fixes.fixed +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs b/src/test/rustfix/main-no-fixes.rs deleted file mode 100644 index f328e4d9d04c..000000000000 --- a/src/test/rustfix/main-no-fixes.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs.fixed b/src/test/rustfix/main-no-fixes.rs.fixed deleted file mode 100644 index f328e4d9d04c..000000000000 --- a/src/test/rustfix/main-no-fixes.rs.fixed +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/missing-comma-in-match.fixed b/src/test/rustfix/missing-comma-in-match.fixed deleted file mode 100644 index d4696ab9547a..000000000000 --- a/src/test/rustfix/missing-comma-in-match.fixed +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - match &Some(3) { - &None => 1, - &Some(2) => { 3 } - _ => 2 - }; -} diff --git a/src/test/rustfix/missing-comma-in-match.rs b/src/test/rustfix/missing-comma-in-match.rs deleted file mode 100644 index fed796cffe6f..000000000000 --- a/src/test/rustfix/missing-comma-in-match.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - match &Some(3) { - &None => 1 - &Some(2) => { 3 } - _ => 2 - }; -} diff --git a/src/test/rustfix/str-as-char.fixed b/src/test/rustfix/str-as-char.fixed deleted file mode 100644 index 900fee94653c..000000000000 --- a/src/test/rustfix/str-as-char.fixed +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("●●"); -} diff --git a/src/test/rustfix/str-as-char.rs b/src/test/rustfix/str-as-char.rs deleted file mode 100644 index b446551fefa2..000000000000 --- a/src/test/rustfix/str-as-char.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!('●●'); -} diff --git a/src/test/rustfix/tuple-float-index.fixed b/src/test/rustfix/tuple-float-index.fixed deleted file mode 100644 index 358a27d38782..000000000000 --- a/src/test/rustfix/tuple-float-index.fixed +++ /dev/null @@ -1,3 +0,0 @@ -fn main () { - ((1, (2, 3)).1).1; -} diff --git a/src/test/rustfix/tuple-float-index.rs b/src/test/rustfix/tuple-float-index.rs deleted file mode 100644 index 72612252a809..000000000000 --- a/src/test/rustfix/tuple-float-index.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main () { - (1, (2, 3)).1.1; -} From 2d7dbf2e05284aba0a99c40db007c512631872ca Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 27 Aug 2021 11:53:03 +0000 Subject: [PATCH 195/269] Fix rustfmt test --- src/tools/rustfmt/tests/source/type.rs | 24 +++++++++--------------- src/tools/rustfmt/tests/target/type.rs | 6 ------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/tools/rustfmt/tests/source/type.rs b/src/tools/rustfmt/tests/source/type.rs index 57f31dc901e7..61ef73a3cab1 100644 --- a/src/tools/rustfmt/tests/source/type.rs +++ b/src/tools/rustfmt/tests/source/type.rs @@ -140,29 +140,23 @@ fn foo(a: SomeLongComplexType, b: SomeOtherLongComplexType) -> Box Box>; -// Const opt-out +// Const bound -trait T: ? const Super {} +trait T: ~ const Super {} -const fn maybe_const() -> i32 { ::CONST } +const fn not_quite_const() -> i32 { ::CONST } -struct S(std::marker::PhantomData); +struct S(std::marker::PhantomData); -impl ? const T {} +impl ~ const T {} -fn trait_object() -> &'static dyn ? const T { &S } +fn apit(_: impl ~ const T) {} -fn i(_: impl IntoIterator>) {} - -fn apit(_: impl ?const T) {} - -fn rpit() -> impl ? const T { S } +fn rpit() -> impl ~ const T { S } pub struct Foo(T); -impl Foo { +impl Foo { fn new(t: T) -> Self { - // not calling methods on `t`, so we opt out of requiring - // `` to have const methods via `?const` Self(t) } } @@ -171,4 +165,4 @@ impl Foo { type T = typeof( 1); impl T for .. { -} \ No newline at end of file +} diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 9ab66944c8cc..38cf909c2587 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -157,12 +157,6 @@ struct S(std::marker::PhantomData); impl ~const T {} -fn trait_object() -> &'static dyn ~const T { - &S -} - -fn i(_: impl IntoIterator>) {} - fn apit(_: impl ~const T) {} fn rpit() -> impl ~const T { From 8fcfd6e136a31ea2a199b489e4df315a937fcd6a Mon Sep 17 00:00:00 2001 From: Roxane Date: Thu, 26 Aug 2021 20:56:45 -0400 Subject: [PATCH 196/269] Add missing const edge case --- compiler/rustc_typeck/src/expr_use_visitor.rs | 7 ++++ .../2229_closure_analysis/issue-88331.rs | 33 +++++++++++++++++++ .../2229_closure_analysis/issue-88331.stderr | 27 +++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/test/ui/closures/2229_closure_analysis/issue-88331.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/issue-88331.stderr diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index cd00d181ed04..e7c3a366cc43 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -267,6 +267,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { if let ty::Adt(def, _) = place_ty.kind() { if def.variants.len() > 1 { needs_to_be_read = true; + } else if let Some(variant) = def.variants.iter().next() { + // If the pat kind is a Path we want to check whether the + // variant contains at least one field. If that's the case, + // we want to borrow discr. + if matches!(pat.kind, PatKind::Path(..)) && variant.fields.len() > 0 { + needs_to_be_read = true; + } } } else { // If it is not ty::Adt, then it should be read diff --git a/src/test/ui/closures/2229_closure_analysis/issue-88331.rs b/src/test/ui/closures/2229_closure_analysis/issue-88331.rs new file mode 100644 index 000000000000..0a6d71c68ae8 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/issue-88331.rs @@ -0,0 +1,33 @@ +// edition:2021 + +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct Opcode(pub u8); + +impl Opcode { + pub const OP1: Opcode = Opcode(0x1); +} + +pub fn example1(msg_type: Opcode) -> impl FnMut(&[u8]) { + move |i| match msg_type { + //~^ ERROR: non-exhaustive patterns: `Opcode(0_u8)` and `Opcode(2_u8..=u8::MAX)` not covered + Opcode::OP1 => unimplemented!(), + } +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct Opcode2(Opcode); + +impl Opcode2 { + pub const OP2: Opcode2 = Opcode2(Opcode(0x1)); +} + + +pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) { + + move |i| match msg_type { + //~^ ERROR: non-exhaustive patterns: `Opcode2(Opcode(0_u8))` and `Opcode2(Opcode(2_u8..=u8::MAX))` not covered + Opcode2::OP2=> unimplemented!(), + } +} + +fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/issue-88331.stderr b/src/test/ui/closures/2229_closure_analysis/issue-88331.stderr new file mode 100644 index 000000000000..f02d23464f16 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/issue-88331.stderr @@ -0,0 +1,27 @@ +error[E0004]: non-exhaustive patterns: `Opcode(0_u8)` and `Opcode(2_u8..=u8::MAX)` not covered + --> $DIR/issue-88331.rs:11:20 + | +LL | pub struct Opcode(pub u8); + | -------------------------- `Opcode` defined here +... +LL | move |i| match msg_type { + | ^^^^^^^^ patterns `Opcode(0_u8)` and `Opcode(2_u8..=u8::MAX)` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `Opcode` + +error[E0004]: non-exhaustive patterns: `Opcode2(Opcode(0_u8))` and `Opcode2(Opcode(2_u8..=u8::MAX))` not covered + --> $DIR/issue-88331.rs:27:20 + | +LL | pub struct Opcode2(Opcode); + | --------------------------- `Opcode2` defined here +... +LL | move |i| match msg_type { + | ^^^^^^^^ patterns `Opcode2(Opcode(0_u8))` and `Opcode2(Opcode(2_u8..=u8::MAX))` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `Opcode2` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0004`. From 110a9b3b1ca1fddd34a3ecb8ec47fd8bb5ca7424 Mon Sep 17 00:00:00 2001 From: Roxane Date: Fri, 27 Aug 2021 09:00:50 -0400 Subject: [PATCH 197/269] Add comment and fix fmt issue --- compiler/rustc_typeck/src/expr_use_visitor.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index e7c3a366cc43..7c99a37f6e7f 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -268,10 +268,21 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { if def.variants.len() > 1 { needs_to_be_read = true; } else if let Some(variant) = def.variants.iter().next() { + // We need to handle `const` in match arms slightly differently + // as they are not processed the same way as other match arms. + // Consider this const `const OP1: Opcode = Opcode(0x1)`, this + // will generate a pattern with kind Path while if use Opcode(0x1) + // this will generate pattern TupleStruct and Lit. + // When dealing with pat kind Path we need to make additional checks + // to ensure we have all the info needed to make a decision on whether + // to borrow discr. + // // If the pat kind is a Path we want to check whether the // variant contains at least one field. If that's the case, // we want to borrow discr. - if matches!(pat.kind, PatKind::Path(..)) && variant.fields.len() > 0 { + if matches!(pat.kind, PatKind::Path(..)) + && variant.fields.len() > 0 + { needs_to_be_read = true; } } From 5eb960c8d9b33caade6fc637b8258f5a25572461 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 21 May 2021 10:11:40 +0800 Subject: [PATCH 198/269] add rustc-demangle assertion on mangled symbol --- compiler/rustc_symbol_mangling/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 7fb24ad1ed8e..bea6cc12ad85 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -250,10 +250,18 @@ fn compute_symbol_name( tcx.symbol_mangling_version(mangling_version_crate) }; - match mangling_version { + let symbol = match mangling_version { SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate), SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate), - } + }; + + debug_assert!( + rustc_demangle::try_demangle(&symbol).is_ok(), + "compute_symbol_name: `{}` cannot be demangled", + symbol + ); + + symbol } fn is_generic(substs: SubstsRef<'_>) -> bool { From 50da1eb1cddb6a6735d3601751f300d0773be65e Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Fri, 27 Aug 2021 14:25:29 +0100 Subject: [PATCH 199/269] Document `std::env::current_exe` rename behaviour It might not be obvious that the "path of the current running executable" may (or may not) mean "at the time it was loaded". --- library/std/src/env.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index a74652009555..e343073d2150 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -616,6 +616,9 @@ pub fn temp_dir() -> PathBuf { /// return the path of the symbolic link and other platforms will return the /// path of the symbolic link’s target. /// +/// If the executable is renamed while it is running, platforms may return the +/// path at the time it was loaded instead of the new path. +/// /// # Errors /// /// Acquiring the path of the current executable is a platform-specific operation From 92e30f608b3ec9498a08b6bcc42da16a5d3329e8 Mon Sep 17 00:00:00 2001 From: klensy Date: Fri, 27 Aug 2021 17:38:53 +0300 Subject: [PATCH 200/269] crossbeam-deque v0.7.3 -> v0.7.4: https://rustsec.org/advisories/RUSTSEC-2021-0093 https://github.com/crossbeam-rs/crossbeam/pull/728/files openssl-src v111.15.0+1.1.1k -> v111.16.0+1.1.1l: https://rustsec.org/advisories/RUSTSEC-2021-0097 https://rustsec.org/advisories/RUSTSEC-2021-0098 https://www.openssl.org/news/vulnerabilities-1.1.1.html tar v0.4.35 -> v0.4.37: https://rustsec.org/advisories/RUSTSEC-2021-0080 updated to 0.4.37 as there breaking change in 0.4.36: https://github.com/alexcrichton/tar-rs/pull/260 --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cef4f11da801..c861e020f591 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -765,9 +765,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" dependencies = [ "crossbeam-epoch", "crossbeam-utils 0.7.2", @@ -2368,9 +2368,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" -version = "111.15.0+1.1.1k" +version = "111.16.0+1.1.1l" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a" +checksum = "7ab2173f69416cf3ec12debb5823d244127d23a9b127d5a5189aa97c5fa2859f" dependencies = [ "cc", ] @@ -4967,9 +4967,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80" +checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c" dependencies = [ "filetime", "libc", From fb5fbaaab01f7612980e159316f45a31d25dfb05 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Fri, 27 Aug 2021 19:27:45 +0300 Subject: [PATCH 201/269] Tracking issue for UNSUPPORTED_CALLING_CONVENTIONS --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- src/test/ui/abi/unsupported.aarch64.stderr | 4 ++-- src/test/ui/abi/unsupported.x64.stderr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 1d978b6c8292..8fb678e2d20f 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3384,7 +3384,7 @@ declare_lint! { Warn, "use of unsupported calling convention", @future_incompatible = FutureIncompatibleInfo { - reference: "issue #00000 ", + reference: "issue #87678 ", }; } diff --git a/src/test/ui/abi/unsupported.aarch64.stderr b/src/test/ui/abi/unsupported.aarch64.stderr index 890174537592..fdeb79f93e9f 100644 --- a/src/test/ui/abi/unsupported.aarch64.stderr +++ b/src/test/ui/abi/unsupported.aarch64.stderr @@ -42,7 +42,7 @@ LL | extern "stdcall" fn stdcall() {} | = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #00000 + = note: for more information, see issue #87678 warning: use of calling convention not supported on this target --> $DIR/unsupported.rs:44:1 @@ -51,7 +51,7 @@ LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #00000 + = note: for more information, see issue #87678 error: aborting due to 6 previous errors; 2 warnings emitted diff --git a/src/test/ui/abi/unsupported.x64.stderr b/src/test/ui/abi/unsupported.x64.stderr index 5c68461e4fb3..60d067acf174 100644 --- a/src/test/ui/abi/unsupported.x64.stderr +++ b/src/test/ui/abi/unsupported.x64.stderr @@ -42,7 +42,7 @@ LL | extern "stdcall" fn stdcall() {} | = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #00000 + = note: for more information, see issue #87678 warning: use of calling convention not supported on this target --> $DIR/unsupported.rs:44:1 @@ -51,7 +51,7 @@ LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #00000 + = note: for more information, see issue #87678 error: aborting due to 6 previous errors; 2 warnings emitted From f34909d68f1410c89e3a97bdee04d7e6e7cfbe5e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Aug 2021 16:30:45 -0400 Subject: [PATCH 202/269] simplify the logic and document --- compiler/rustc_typeck/src/expr_use_visitor.rs | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index 7c99a37f6e7f..d999c17b579b 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -2,6 +2,7 @@ //! normal visitor, which just walks the entire body in one shot, the //! `ExprUseVisitor` determines how expressions are being used. +use hir::def::DefKind; // Export these here so that Clippy can use them. pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection}; @@ -14,7 +15,7 @@ use rustc_index::vec::Idx; use rustc_infer::infer::InferCtxt; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, adjustment, TyCtxt}; +use rustc_middle::ty::{self, adjustment, Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter; @@ -251,43 +252,34 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { needs_to_be_read = true; } } - PatKind::TupleStruct(..) - | PatKind::Path(..) - | PatKind::Struct(..) - | PatKind::Tuple(..) => { - // If the PatKind is a TupleStruct, Path, Struct or Tuple then we want to check - // whether the Variant is a MultiVariant or a SingleVariant. We only want - // to borrow discr if it is a MultiVariant. - // If it is a SingleVariant and creates a binding we will handle that when - // this callback gets called again. - - // Get the type of the Place after all projections have been applied - let place_ty = place.place.ty(); - - if let ty::Adt(def, _) = place_ty.kind() { - if def.variants.len() > 1 { + PatKind::Path(qpath) => { + // A `Path` pattern is just a name like `Foo`. This is either a + // named constant or else it refers to an ADT variant + + let res = self.mc.typeck_results.qpath_res(qpath, pat.hir_id); + match res { + Res::Def(DefKind::Const, _) + | Res::Def(DefKind::AssocConst, _) => { + // Named constants have to be equated with the value + // being matched, so that's a read of the value being matched. needs_to_be_read = true; - } else if let Some(variant) = def.variants.iter().next() { - // We need to handle `const` in match arms slightly differently - // as they are not processed the same way as other match arms. - // Consider this const `const OP1: Opcode = Opcode(0x1)`, this - // will generate a pattern with kind Path while if use Opcode(0x1) - // this will generate pattern TupleStruct and Lit. - // When dealing with pat kind Path we need to make additional checks - // to ensure we have all the info needed to make a decision on whether - // to borrow discr. - // - // If the pat kind is a Path we want to check whether the - // variant contains at least one field. If that's the case, - // we want to borrow discr. - if matches!(pat.kind, PatKind::Path(..)) - && variant.fields.len() > 0 - { - needs_to_be_read = true; - } } - } else { - // If it is not ty::Adt, then it should be read + _ => { + // Otherwise, this is a struct/enum variant, and so it's + // only a read if we need to read the discriminant. + needs_to_be_read = is_multivariant_adt(place.place.ty()); + } + } + } + PatKind::TupleStruct(..) | PatKind::Struct(..) | PatKind::Tuple(..) => { + // For `Foo(..)`, `Foo { ... }` and `(...)` patterns, check if we are matching + // against a multivariant enum or struct. In that case, we have to read + // the discriminant. Otherwise this kind of pattern doesn't actually + // read anything (we'll get invoked for the `...`, which may indeed + // perform some reads). + + let place_ty = place.place.ty(); + if is_multivariant_adt(place_ty) { needs_to_be_read = true; } } @@ -854,3 +846,7 @@ fn delegate_consume<'a, 'tcx>( } } } + +fn is_multivariant_adt(ty: Ty<'tcx>) -> bool { + if let ty::Adt(def, _) = ty.kind() { def.variants.len() > 1 } else { false } +} From 5c7400c12d462af2fe7507c24d88c837d35df9dd Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 17:48:51 -0300 Subject: [PATCH 203/269] Add nested TAIT inference test --- .../nested-tait-inference.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/nested-tait-inference.rs diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs b/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs new file mode 100644 index 000000000000..efb88dabf34c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type FooX = impl Debug; + +trait Foo { } + +impl Foo<()> for () { } + +fn foo() -> impl Foo { + () +} + +fn main() { } From d7a777f034ccc985def62f6dd08d9a8e68b3b15e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 17:51:46 -0300 Subject: [PATCH 204/269] Add nested TAIT inference test that fails --- .../nested-tait-inference2.rs | 19 +++++++++++++++++++ .../nested-tait-inference2.stderr | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs create mode 100644 src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs new file mode 100644 index 000000000000..9b26a6529785 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type FooX = impl Debug; +//~^ ERROR: could not find defining uses + +trait Foo {} + +impl Foo<()> for () {} +impl Foo for () {} + +fn foo() -> impl Foo { + //~^ ERROR: the trait bound `(): Foo` is not satisfied [E0277] + () +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr new file mode 100644 index 000000000000..7e24ee644b1c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `(): Foo` is not satisfied + --> $DIR/nested-tait-inference2.rs:14:13 + | +LL | fn foo() -> impl Foo { + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` + | + = help: the following implementations were found: + <() as Foo<()>> + <() as Foo> + +error: could not find defining uses + --> $DIR/nested-tait-inference2.rs:6:13 + | +LL | type FooX = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From c4dba5a64efe340a779d8a1ee8c332140c51180e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Aug 2021 17:13:41 -0400 Subject: [PATCH 205/269] use `|=` --- compiler/rustc_typeck/src/expr_use_visitor.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index d999c17b579b..1c60ef7bda0d 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -262,12 +262,14 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { | Res::Def(DefKind::AssocConst, _) => { // Named constants have to be equated with the value // being matched, so that's a read of the value being matched. + // + // FIXME: We don't actually reads for ZSTs. needs_to_be_read = true; } _ => { // Otherwise, this is a struct/enum variant, and so it's // only a read if we need to read the discriminant. - needs_to_be_read = is_multivariant_adt(place.place.ty()); + needs_to_be_read |= is_multivariant_adt(place.place.ty()); } } } @@ -279,9 +281,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // perform some reads). let place_ty = place.place.ty(); - if is_multivariant_adt(place_ty) { - needs_to_be_read = true; - } + needs_to_be_read |= is_multivariant_adt(place_ty); } PatKind::Lit(_) | PatKind::Range(..) => { // If the PatKind is a Lit or a Range then we want From 7a46ff5981bc6f27a1a325f564adf7cff161a8ec Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 27 Aug 2021 14:03:04 -0700 Subject: [PATCH 206/269] Fix formatting in release notes from 52a988344bce118347d6a6567e67e20b7e99dc25 --- RELEASES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index dd299ca936ac..a6c1b0f50ce7 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -70,7 +70,8 @@ Cargo - [The package definition in `cargo metadata` now includes the `"default_run"` field from the manifest.][cargo/9550] - [Added `cargo d` as an alias for `cargo doc`.][cargo/9680] -- [Added `{lib}` as formatting option for `cargo tree` to print the "lib_name" of packages.][cargo/9663] +- [Added `{lib}` as formatting option for `cargo tree` to print the `"lib_name"` + of packages.][cargo/9663] Rustdoc ------- @@ -119,6 +120,7 @@ Compatibility Notes [cargo/9675]: https://github.com/rust-lang/cargo/pull/9675 [cargo/9550]: https://github.com/rust-lang/cargo/pull/9550 [cargo/9680]: https://github.com/rust-lang/cargo/pull/9680 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [`array::map`]: https://doc.rust-lang.org/stable/std/primitive.array.html#method.map [`Bound::cloned`]: https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.cloned [`Drain::as_str`]: https://doc.rust-lang.org/stable/std/string/struct.Drain.html#method.as_str From 1ba86f2c34c30be09851b7fce3af27957d77b517 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 18:34:07 -0300 Subject: [PATCH 207/269] Add inference cycle TAIT test --- .../type-alias-impl-trait/inference-cycle.rs | 26 +++++++++++++ .../inference-cycle.stderr | 37 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/inference-cycle.rs create mode 100644 src/test/ui/type-alias-impl-trait/inference-cycle.stderr diff --git a/src/test/ui/type-alias-impl-trait/inference-cycle.rs b/src/test/ui/type-alias-impl-trait/inference-cycle.rs new file mode 100644 index 000000000000..c781e200bf8e --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/inference-cycle.rs @@ -0,0 +1,26 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + type Foo = impl std::fmt::Debug; + //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + + // Cycle: error today, but it'd be nice if it eventually worked + + pub fn foo() -> Foo { + is_send(bar()) + } + + pub fn bar() { + is_send(foo()); // Today: error + } + + fn baz() { + let f: Foo = 22_u32; + //~^ ERROR: mismatched types [E0308] + } + + fn is_send(_: T) {} +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/inference-cycle.stderr b/src/test/ui/type-alias-impl-trait/inference-cycle.stderr new file mode 100644 index 000000000000..ac0ca8e048cb --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/inference-cycle.stderr @@ -0,0 +1,37 @@ +error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:16 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires type-checking `m::bar`... + --> $DIR/inference-cycle.rs:14:5 + | +LL | pub fn bar() { + | ^^^^^^^^^^^^ + = note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`... + = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in module `m` + --> $DIR/inference-cycle.rs:4:1 + | +LL | mod m { + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/inference-cycle.rs:19:22 + | +LL | type Foo = impl std::fmt::Debug; + | -------------------- the expected opaque type +... +LL | let f: Foo = 22_u32; + | --- ^^^^^^ expected opaque type, found `u32` + | | + | expected due to this + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0391. +For more information about an error, try `rustc --explain E0308`. From 0d1d9788e5a98268472f6c8538f4c0d18c4986c6 Mon Sep 17 00:00:00 2001 From: Ryan Zoeller Date: Thu, 26 Aug 2021 23:37:36 -0500 Subject: [PATCH 208/269] Handle stack_t.ss_sp type change for DragonFlyBSD stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed. Changed in https://github.com/rust-lang/libc/commit/02922ef7504906589d02c2e4d97d1172fa247cc3. --- library/std/src/sys/unix/stack_overflow.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs index 81f47a779d33..e8747e39bcbf 100644 --- a/library/std/src/sys/unix/stack_overflow.rs +++ b/library/std/src/sys/unix/stack_overflow.rs @@ -161,24 +161,10 @@ mod imp { stackp.add(page_size()) } - #[cfg(any( - target_os = "linux", - target_os = "macos", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_os = "illumos" - ))] unsafe fn get_stack() -> libc::stack_t { libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ } } - #[cfg(target_os = "dragonfly")] - unsafe fn get_stack() -> libc::stack_t { - libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ } - } - pub unsafe fn make_handler() -> Handler { if !NEED_ALTSTACK.load(Ordering::Relaxed) { return Handler::null(); From f58289cc513c58682c84febd59806ac1bf9d69da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Wed, 18 Aug 2021 22:36:35 +0200 Subject: [PATCH 209/269] Update stacker and psm crates --- Cargo.lock | 10 +++++----- compiler/rustc_data_structures/Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cef4f11da801..aa033db8d8ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2729,9 +2729,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.11" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e0536f6528466dbbbbe6b986c34175a8d0ff25b794c4bacda22e068cd2f2c5" +checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69" dependencies = [ "cc", ] @@ -4812,12 +4812,12 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stacker" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ccb4c06ec57bc82d0f610f1a2963d7648700e43a6f513e564b9c89f7991786" +checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" dependencies = [ "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "psm", "winapi", diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 2063cb8c52bb..bc13ca26e2e2 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -25,7 +25,7 @@ rustc_index = { path = "../rustc_index", package = "rustc_index" } bitflags = "1.2.1" measureme = "9.1.0" libc = "0.2" -stacker = "0.1.12" +stacker = "0.1.14" tempfile = "3.2" [dependencies.parking_lot] From 672d370764862272735466346e9291dbf3163aeb Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 27 Aug 2021 18:28:22 -0500 Subject: [PATCH 210/269] Remove `Session.if_let_suggestions` We can instead if either the LHS or RHS types contain `TyKind::Error`. In addition to covering the case where we would have previously updated `if_let_suggestions`, this might also prevent redundant errors in other cases as well. --- compiler/rustc_resolve/src/late/diagnostics.rs | 1 - compiler/rustc_session/src/session.rs | 4 ---- compiler/rustc_typeck/src/check/expr.rs | 7 ++++--- src/test/ui/suggestions/if-let-typo.rs | 1 + src/test/ui/suggestions/if-let-typo.stderr | 13 ++++++++++++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 9d923599db76..b3601ecf1d3a 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -215,7 +215,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { "let ".to_string(), Applicability::MaybeIncorrect, ); - self.r.session.if_let_suggestions.borrow_mut().insert(*span); } _ => {} } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 20e94e32be61..18b933955879 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -209,9 +209,6 @@ pub struct Session { /// Set of enabled features for the current target. pub target_features: FxHashSet, - - /// `Span`s for `if` conditions that we have suggested turning into `if let`. - pub if_let_suggestions: Lock>, } pub struct PerfStats { @@ -1328,7 +1325,6 @@ pub fn build_session( miri_unleashed_features: Lock::new(Default::default()), asm_arch, target_features: FxHashSet::default(), - if_let_suggestions: Default::default(), }; validate_commandline_args_with_session_available(&sess); diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index ab927b794422..51c646e500ca 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -919,9 +919,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - if self.sess().if_let_suggestions.borrow().get(&expr.span).is_some() { - // We already emitted an `if let` suggestion due to an identifier not found. - err.delay_as_bug(); + // If the assignment expression itself is ill-formed, don't + // bother emitting another error + if lhs_ty.references_error() || rhs_ty.references_error() { + err.delay_as_bug() } else { err.emit(); } diff --git a/src/test/ui/suggestions/if-let-typo.rs b/src/test/ui/suggestions/if-let-typo.rs index 688b6e826582..b9714b67e588 100644 --- a/src/test/ui/suggestions/if-let-typo.rs +++ b/src/test/ui/suggestions/if-let-typo.rs @@ -10,4 +10,5 @@ fn main() { if Some(3) = foo {} //~ ERROR mismatched types //~^ ERROR destructuring assignments are unstable //~^^ ERROR invalid left-hand side of assignment + if x = 5 {} //~ ERROR cannot find value `x` in this scope } diff --git a/src/test/ui/suggestions/if-let-typo.stderr b/src/test/ui/suggestions/if-let-typo.stderr index 1e23ede7adc8..7f71cb485815 100644 --- a/src/test/ui/suggestions/if-let-typo.stderr +++ b/src/test/ui/suggestions/if-let-typo.stderr @@ -9,6 +9,17 @@ help: you might have meant to use pattern matching LL | if let Some(x) = foo {} | +++ +error[E0425]: cannot find value `x` in this scope + --> $DIR/if-let-typo.rs:13:8 + | +LL | if x = 5 {} + | ^ not found in this scope + | +help: you might have meant to use pattern matching + | +LL | if let x = 5 {} + | +++ + error[E0658]: destructuring assignments are unstable --> $DIR/if-let-typo.rs:4:16 | @@ -79,7 +90,7 @@ error[E0308]: mismatched types LL | if Some(3) = foo {} | ^^^^^^^^^^^^^ expected `bool`, found `()` -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0070, E0308, E0425, E0658. For more information about an error, try `rustc --explain E0070`. From 5ac46d7bd88cf992d108d14913b599903140ce9d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 18:42:28 -0300 Subject: [PATCH 211/269] Add auto trait leakage TAIT test --- .../auto-trait-leakage.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs new file mode 100644 index 000000000000..a1584581e6c4 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + type Foo = impl std::fmt::Debug; + + pub fn foo() -> Foo { + 22_u32 + } +} + +fn is_send(_: T) {} + +fn main() { + is_send(m::foo()); +} From d0e08dffcf2353af76de298cd9cb4b9d55f66199 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 21:59:49 -0300 Subject: [PATCH 212/269] Add auto trait that shouldn't leak TAIT test --- .../auto-trait-leakage2.rs | 19 ++++++++++++++++++ .../auto-trait-leakage2.stderr | 20 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs create mode 100644 src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs new file mode 100644 index 000000000000..745379efa6df --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + use std::rc::Rc; + + type Foo = impl std::fmt::Debug; + + pub fn foo() -> Foo { + Rc::new(22_u32) + } +} + +fn is_send(_: T) {} + +fn main() { + is_send(m::foo()); + //~^ ERROR: `Rc` cannot be sent between threads safely [E0277] +} diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr new file mode 100644 index 000000000000..d60be4b1ccf9 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Rc` cannot be sent between threads safely + --> $DIR/auto-trait-leakage2.rs:17:5 + | +LL | type Foo = impl std::fmt::Debug; + | -------------------- within this `impl Debug` +... +LL | is_send(m::foo()); + | ^^^^^^^ `Rc` cannot be sent between threads safely + | + = help: within `impl Debug`, the trait `Send` is not implemented for `Rc` + = note: required because it appears within the type `impl Debug` +note: required by a bound in `is_send` + --> $DIR/auto-trait-leakage2.rs:14:15 + | +LL | fn is_send(_: T) {} + | ^^^^ required by this bound in `is_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From c85529e6288028ecf62635ff001caf0603d67ac2 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 22:03:39 -0300 Subject: [PATCH 213/269] Add auto trait leakage TAIT test that should work but currently doesn't --- .../auto-trait-leakage3.rs | 21 ++++++++++++++++++ .../auto-trait-leakage3.stderr | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs create mode 100644 src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs new file mode 100644 index 000000000000..5fb7a9473d3d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs @@ -0,0 +1,21 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should compile, but it currently doesn't + +mod m { + type Foo = impl std::fmt::Debug; + //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + + pub fn foo() -> Foo { + 22_u32 + } + + pub fn bar() { + is_send(foo()); + } + + fn is_send(_: T) {} +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr new file mode 100644 index 000000000000..ac7bbd272c77 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -0,0 +1,22 @@ +error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:16 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires type-checking `m::bar`... + --> $DIR/auto-trait-leakage3.rs:14:5 + | +LL | pub fn bar() { + | ^^^^^^^^^^^^ + = note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`... + = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in module `m` + --> $DIR/auto-trait-leakage3.rs:6:1 + | +LL | mod m { + | ^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0391`. From 6ac223582f1d6f47c6eccf969613c50c80bd45ea Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 27 Aug 2021 22:40:23 -0300 Subject: [PATCH 214/269] Add weird return types TAIT test --- .../type-alias-impl-trait/weird-return-types.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/weird-return-types.rs diff --git a/src/test/ui/type-alias-impl-trait/weird-return-types.rs b/src/test/ui/type-alias-impl-trait/weird-return-types.rs new file mode 100644 index 000000000000..faad5ee956a1 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/weird-return-types.rs @@ -0,0 +1,16 @@ +// edition:2018 +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::future::Future; +use std::fmt::Debug; + +type Foo = impl Debug; + +fn f() -> impl Future { + async move { 22_u32 } +} + +fn main() {} From c9157efad6e3e7b1802a2c4f5122140e1752985d Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 27 Aug 2021 21:13:08 -0500 Subject: [PATCH 215/269] Don't use `guess_head_span` in `predicates_of` for foreign span Previously, the result of `predicates_of` for a foreign trait would depend on the *current* state of the corresponding source file in the foreign crate. This could lead to ICEs during incremental compilation, since the on-disk contents of the upstream source file could potentially change without the upstream crate being recompiled. Additionally, this ensure that that the metadata we produce for a crate only depends on its *compiled* upstream dependencies (e.g an rlib or rmeta file), *not* the current on-disk state of the upstream crate source files. --- compiler/rustc_span/src/source_map.rs | 11 ++++++++ compiler/rustc_typeck/src/collect.rs | 11 +++++++- .../run-make/incr-foreign-head-span/Makefile | 21 +++++++++++++++ .../incr-foreign-head-span/first_crate.rs | 1 + .../incr-foreign-head-span/second_crate.rs | 8 ++++++ .../bad-bounds-on-assoc-in-trait.stderr | 26 ++++++++++++++----- .../bounds-on-assoc-in-trait.stderr | 20 +++++++++++--- ...feature-gate-associated_type_bounds.stderr | 6 +++-- src/test/ui/traits/issue-85735.stderr | 8 ++++-- 9 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 src/test/run-make/incr-foreign-head-span/Makefile create mode 100644 src/test/run-make/incr-foreign-head-span/first_crate.rs create mode 100644 src/test/run-make/incr-foreign-head-span/second_crate.rs diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 2c3af802be55..c2de5ed2f583 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -567,6 +567,17 @@ impl SourceMap { } } + /// Returns whether or not this span points into a file + /// in the current crate. This may be `false` for spans + /// produced by a macro expansion, or for spans associated + /// with the definition of an item in a foreign crate + pub fn is_local_span(&self, sp: Span) -> bool { + let local_begin = self.lookup_byte_offset(sp.lo()); + let local_end = self.lookup_byte_offset(sp.hi()); + // This might be a weird span that covers multiple files + local_begin.sf.src.is_some() && local_end.sf.src.is_some() + } + /// Returns the source snippet as `String` corresponding to the given `Span`. pub fn span_to_snippet(&self, sp: Span) -> Result { self.span_to_source(sp, |src, start_index, end_index| { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index b514176ad529..51b8b8736a18 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2001,7 +2001,16 @@ fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> { // prove that the trait applies to the types that were // used, and adding the predicate into this list ensures // that this is done. - let span = tcx.sess.source_map().guess_head_span(tcx.def_span(def_id)); + let mut span = tcx.def_span(def_id); + if tcx.sess.source_map().is_local_span(span) { + // `guess_head_span` reads the actual source file from + // disk to try to determine the 'head' snippet of the span. + // Don't do this for a span that comes from a file outside + // of our crate, since this would make our query output + // (and overall crate metadata) dependent on the + // *current* state of an external file. + span = tcx.sess.source_map().guess_head_span(span); + } result.predicates = tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(tcx), diff --git a/src/test/run-make/incr-foreign-head-span/Makefile b/src/test/run-make/incr-foreign-head-span/Makefile new file mode 100644 index 000000000000..712965eaa883 --- /dev/null +++ b/src/test/run-make/incr-foreign-head-span/Makefile @@ -0,0 +1,21 @@ +include ../../run-make-fulldeps/tools.mk + +# ignore-none no-std is not supported +# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for 'std' + +# Ensure that modifying a crate on disk (without recompiling it) +# does not cause ICEs in downstream crates. +# Previously, we would call `SourceMap.guess_head_span` on a span +# from an external crate, which would cause us to read an upstream +# source file from disk during compilation of a downstream crate +# See #86480 for more details + +INCR=$(TMPDIR)/incr + +all: + cp first_crate.rs second_crate.rs $(TMPDIR) + $(RUSTC) $(TMPDIR)/first_crate.rs -C incremental=$(INCR) --target $(TARGET) --crate-type lib + $(RUSTC) $(TMPDIR)/second_crate.rs -C incremental=$(INCR) --target $(TARGET) --extern first-crate=$(TMPDIR) --crate-type lib + rm $(TMPDIR)/first_crate.rs + $(RUSTC) $(TMPDIR)/second_crate.rs -C incremental=$(INCR) --target $(TARGET) --cfg second_run --crate-type lib + diff --git a/src/test/run-make/incr-foreign-head-span/first_crate.rs b/src/test/run-make/incr-foreign-head-span/first_crate.rs new file mode 100644 index 000000000000..69dd103bfc02 --- /dev/null +++ b/src/test/run-make/incr-foreign-head-span/first_crate.rs @@ -0,0 +1 @@ +pub trait OtherTrait {} diff --git a/src/test/run-make/incr-foreign-head-span/second_crate.rs b/src/test/run-make/incr-foreign-head-span/second_crate.rs new file mode 100644 index 000000000000..102f6b26c8d7 --- /dev/null +++ b/src/test/run-make/incr-foreign-head-span/second_crate.rs @@ -0,0 +1,8 @@ +extern crate first_crate; +use first_crate::OtherTrait; + +#[cfg(not(second_run))] +trait Foo: OtherTrait {} + +#[cfg(second_run)] +trait Bar: OtherTrait {} diff --git a/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr b/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr index a694f88192ed..57aacf67e05f 100644 --- a/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr +++ b/src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr @@ -8,8 +8,10 @@ LL | type C: Clone + Iterator Lam<&'a u8 note: required by a bound in `Send` --> $SRC_DIR/core/src/marker.rs:LL:COL | -LL | pub unsafe auto trait Send { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Send` +LL | / pub unsafe auto trait Send { +LL | | // empty. +LL | | } + | |_^ required by this bound in `Send` help: consider further restricting the associated type | LL | trait Case1 where <::C as Iterator>::Item: Send { @@ -25,8 +27,14 @@ LL | type C: Clone + Iterator Lam<&'a u8 note: required by a bound in `Iterator` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | -LL | pub trait Iterator { - | ^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator` +LL | / pub trait Iterator { +LL | | /// The type of the elements being iterated over. +LL | | #[stable(feature = "rust1", since = "1.0.0")] +LL | | type Item; +... | +LL | | } +LL | | } + | |_^ required by this bound in `Iterator` help: consider further restricting the associated type | LL | trait Case1 where <::C as Iterator>::Item: Iterator { @@ -42,8 +50,14 @@ LL | type C: Clone + Iterator Lam<&'a u8 note: required by a bound in `Sync` --> $SRC_DIR/core/src/marker.rs:LL:COL | -LL | pub unsafe auto trait Sync { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Sync` +LL | / pub unsafe auto trait Sync { +LL | | // FIXME(estebank): once support to add notes in `rustc_on_unimplemented` +LL | | // lands in beta, and it has been extended to check whether a closure is +LL | | // anywhere in the requirement chain, extend it as such (#48534): +... | +LL | | // Empty +LL | | } + | |_^ required by this bound in `Sync` help: consider further restricting the associated type | LL | trait Case1 where <::C as Iterator>::Item: Sync { diff --git a/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.stderr b/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.stderr index 775fe28f00d8..4da5a2cbd41a 100644 --- a/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.stderr +++ b/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.stderr @@ -8,8 +8,14 @@ LL | type A: Iterator; note: required by a bound in `Debug` --> $SRC_DIR/core/src/fmt/mod.rs:LL:COL | -LL | pub trait Debug { - | ^^^^^^^^^^^^^^^ required by this bound in `Debug` +LL | / pub trait Debug { +LL | | /// Formats the value using the given formatter. +LL | | /// +LL | | /// # Examples +... | +LL | | fn fmt(&self, f: &mut Formatter<'_>) -> Result; +LL | | } + | |_^ required by this bound in `Debug` help: consider further restricting the associated type | LL | trait Case1 where <::A as Iterator>::Item: Debug { @@ -24,8 +30,14 @@ LL | pub trait Foo { type Out: Baz; } note: required by a bound in `Default` --> $SRC_DIR/core/src/default.rs:LL:COL | -LL | pub trait Default: Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Default` +LL | / pub trait Default: Sized { +LL | | /// Returns the "default value" for a type. +LL | | /// +LL | | /// Default values are often some kind of initial value, identity value, or anything else that +... | +LL | | fn default() -> Self; +LL | | } + | |_^ required by this bound in `Default` help: consider further restricting the associated type | LL | pub trait Foo where <::Out as Baz>::Assoc: Default { type Out: Baz; } diff --git a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr index f24c3d69a265..8df5fbcc7eba 100644 --- a/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr +++ b/src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr @@ -142,8 +142,10 @@ LL | type A: Iterator; note: required by a bound in `Copy` --> $SRC_DIR/core/src/marker.rs:LL:COL | -LL | pub trait Copy: Clone { - | ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Copy` +LL | / pub trait Copy: Clone { +LL | | // Empty. +LL | | } + | |_^ required by this bound in `Copy` help: consider further restricting the associated type | LL | trait _Tr3 where <::A as Iterator>::Item: Copy { diff --git a/src/test/ui/traits/issue-85735.stderr b/src/test/ui/traits/issue-85735.stderr index 7d7f6ea30ae3..1f81fa72547d 100644 --- a/src/test/ui/traits/issue-85735.stderr +++ b/src/test/ui/traits/issue-85735.stderr @@ -8,8 +8,12 @@ LL | T: FnMut(&'a ()), note: required by a bound in `FnMut` --> $SRC_DIR/core/src/ops/function.rs:LL:COL | -LL | pub trait FnMut: FnOnce { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `FnMut` +LL | / pub trait FnMut: FnOnce { +LL | | /// Performs the call operation. +LL | | #[unstable(feature = "fn_traits", issue = "29625")] +LL | | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; +LL | | } + | |_^ required by this bound in `FnMut` error: aborting due to previous error From 4c9896f279357896d31d811fddc2025d72259498 Mon Sep 17 00:00:00 2001 From: 12101111 Date: Mon, 26 Jul 2021 22:47:07 +0800 Subject: [PATCH 216/269] build llvm libunwind.a in rustbuild --- library/unwind/build.rs | 146 +++--------------------------- library/unwind/src/lib.rs | 12 +-- library/unwind/src/libunwind.rs | 35 +++++--- src/bootstrap/compile.rs | 14 ++- src/bootstrap/native.rs | 153 +++++++++++++++++++++++++++++++- 5 files changed, 204 insertions(+), 156 deletions(-) diff --git a/library/unwind/build.rs b/library/unwind/build.rs index 0529d24a2740..1d0b4a59a287 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -4,36 +4,18 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); let target = env::var("TARGET").expect("TARGET was not set"); - if cfg!(target_os = "linux") && cfg!(feature = "system-llvm-libunwind") { - // linking for Linux is handled in lib.rs - return; - } - - if cfg!(feature = "llvm-libunwind") - && ((target.contains("linux") && !target.contains("musl")) || target.contains("fuchsia")) - { - // Build the unwinding from libunwind C/C++ source code. - llvm_libunwind::compile(); - } else if target.contains("x86_64-fortanix-unknown-sgx") { - llvm_libunwind::compile(); - } else if target.contains("linux") { - // linking for Linux is handled in lib.rs - if target.contains("musl") { - llvm_libunwind::compile(); - } else if target.contains("android") { - let build = cc::Build::new(); + if target.contains("android") { + let build = cc::Build::new(); - // Since ndk r23 beta 3 `libgcc` was replaced with `libunwind` thus - // check if we have `libunwind` available and if so use it. Otherwise - // fall back to `libgcc` to support older ndk versions. - let has_unwind = - build.is_flag_supported("-lunwind").expect("Unable to invoke compiler"); + // Since ndk r23 beta 3 `libgcc` was replaced with `libunwind` thus + // check if we have `libunwind` available and if so use it. Otherwise + // fall back to `libgcc` to support older ndk versions. + let has_unwind = build.is_flag_supported("-lunwind").expect("Unable to invoke compiler"); - if has_unwind { - println!("cargo:rustc-link-lib=unwind"); - } else { - println!("cargo:rustc-link-lib=gcc"); - } + if has_unwind { + println!("cargo:rustc-link-lib=unwind"); + } else { + println!("cargo:rustc-link-lib=gcc"); } } else if target.contains("freebsd") { println!("cargo:rustc-link-lib=gcc_s"); @@ -63,111 +45,3 @@ fn main() { // redox is handled in lib.rs } } - -mod llvm_libunwind { - use std::env; - use std::path::Path; - - /// Compile the libunwind C/C++ source code. - pub fn compile() { - let target = env::var("TARGET").expect("TARGET was not set"); - let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); - let mut cc_cfg = cc::Build::new(); - let mut cpp_cfg = cc::Build::new(); - let root = Path::new("../../src/llvm-project/libunwind"); - - cpp_cfg.cpp(true); - cpp_cfg.cpp_set_stdlib(None); - cpp_cfg.flag("-nostdinc++"); - cpp_cfg.flag("-fno-exceptions"); - cpp_cfg.flag("-fno-rtti"); - cpp_cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); - - // Don't set this for clang - // By default, Clang builds C code in GNU C17 mode. - // By default, Clang builds C++ code according to the C++98 standard, - // with many C++11 features accepted as extensions. - if cpp_cfg.get_compiler().is_like_gnu() { - cpp_cfg.flag("-std=c++11"); - cc_cfg.flag("-std=c99"); - } - - if target.contains("x86_64-fortanix-unknown-sgx") || target_env == "musl" { - // use the same GCC C compiler command to compile C++ code so we do not need to setup the - // C++ compiler env variables on the builders. - // Don't set this for clang++, as clang++ is able to compile this without libc++. - if cpp_cfg.get_compiler().is_like_gnu() { - cpp_cfg.cpp(false); - } - } - - for cfg in [&mut cc_cfg, &mut cpp_cfg].iter_mut() { - cfg.warnings(false); - cfg.flag("-fstrict-aliasing"); - cfg.flag("-funwind-tables"); - cfg.flag("-fvisibility=hidden"); - cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); - cfg.include(root.join("include")); - cfg.cargo_metadata(false); - - if target.contains("x86_64-fortanix-unknown-sgx") { - cfg.static_flag(true); - cfg.opt_level(3); - cfg.flag("-fno-stack-protector"); - cfg.flag("-ffreestanding"); - cfg.flag("-fexceptions"); - - // easiest way to undefine since no API available in cc::Build to undefine - cfg.flag("-U_FORTIFY_SOURCE"); - cfg.define("_FORTIFY_SOURCE", "0"); - cfg.define("RUST_SGX", "1"); - cfg.define("__NO_STRING_INLINES", None); - cfg.define("__NO_MATH_INLINES", None); - cfg.define("_LIBUNWIND_IS_BAREMETAL", None); - cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); - cfg.define("NDEBUG", None); - } - } - - let mut c_sources = vec![ - "Unwind-sjlj.c", - "UnwindLevel1-gcc-ext.c", - "UnwindLevel1.c", - "UnwindRegistersRestore.S", - "UnwindRegistersSave.S", - ]; - - let cpp_sources = vec!["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"]; - let cpp_len = cpp_sources.len(); - - if target.contains("x86_64-fortanix-unknown-sgx") { - c_sources.push("UnwindRustSgx.c"); - } - - for src in c_sources { - cc_cfg.file(root.join("src").join(src).canonicalize().unwrap()); - } - - for src in cpp_sources { - cpp_cfg.file(root.join("src").join(src).canonicalize().unwrap()); - } - - let out_dir = env::var("OUT_DIR").unwrap(); - println!("cargo:rustc-link-search=native={}", &out_dir); - - cpp_cfg.compile("unwind-cpp"); - - let mut count = 0; - for entry in std::fs::read_dir(&out_dir).unwrap() { - let obj = entry.unwrap().path().canonicalize().unwrap(); - if let Some(ext) = obj.extension() { - if ext == "o" { - cc_cfg.object(&obj); - count += 1; - } - } - } - assert_eq!(cpp_len, count, "Can't get object files from {:?}", &out_dir); - cc_cfg.compile("unwind"); - } -} diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index 53b13b9043b3..06384b159264 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -1,6 +1,8 @@ #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] #![feature(link_cfg)] +#![feature(native_link_modifiers)] +#![feature(native_link_modifiers_bundle)] #![feature(nll)] #![feature(staged_api)] #![feature(static_nobundle)] @@ -42,14 +44,14 @@ cfg_if::cfg_if! { if #[cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind"))] { compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time"); } else if #[cfg(feature = "llvm-libunwind")] { - #[link(name = "unwind", kind = "static")] + #[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} } else if #[cfg(feature = "system-llvm-libunwind")] { - #[link(name = "unwind", kind = "static-nobundle", cfg(target_feature = "crt-static"))] + #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "unwind", cfg(not(target_feature = "crt-static")))] extern "C" {} } else { - #[link(name = "unwind", kind = "static", cfg(target_feature = "crt-static"))] + #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] extern "C" {} } @@ -77,10 +79,10 @@ extern "C" {} extern "C" {} #[cfg(target_os = "redox")] -#[link(name = "gcc_eh", kind = "static-nobundle", cfg(target_feature = "crt-static"))] +#[link(name = "gcc_eh", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] extern "C" {} #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] -#[link(name = "unwind", kind = "static")] +#[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index 196be74decba..5e15fe75a246 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -77,9 +77,18 @@ pub enum _Unwind_Context {} pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code, exception: *mut _Unwind_Exception); + +// FIXME: The `#[link]` attributes on `extern "C"` block marks those symbols declared in +// the block are reexported in dylib build of libstd. This is needed when build rustc with +// feature `llvm-libunwind', as no other cdylib will provided those _Unwind_* symbols. +// However the `link` attribute is duplicated multiple times and does not just export symbol, +// a better way to manually export symbol would be another attribute like `#[export]`. +// See the logic in function rustc_codegen_ssa::src::back::exported_symbols, module +// rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols +// and RFC 2841 #[cfg_attr( all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), - link(name = "unwind", kind = "static") + link(name = "unwind", kind = "static", modifiers = "-bundle") )] extern "C-unwind" { pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; @@ -106,9 +115,10 @@ if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))) } pub use _Unwind_Action::*; - #[cfg_attr(all(feature = "llvm-libunwind", - any(target_os = "fuchsia", target_os = "linux")), - link(name = "unwind", kind = "static"))] + #[cfg_attr( + all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), + link(name = "unwind", kind = "static", modifiers = "-bundle") + )] extern "C" { pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word; pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word); @@ -163,9 +173,10 @@ if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))) pub const UNWIND_SP_REG: c_int = 13; pub const UNWIND_IP_REG: c_int = 15; - #[cfg_attr(all(feature = "llvm-libunwind", - any(target_os = "fuchsia", target_os = "linux")), - link(name = "unwind", kind = "static"))] + #[cfg_attr( + all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), + link(name = "unwind", kind = "static", modifiers = "-bundle") + )] extern "C" { fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context, regclass: _Unwind_VRS_RegClass, @@ -228,9 +239,10 @@ if #[cfg(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))) cfg_if::cfg_if! { if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { // Not 32-bit iOS - #[cfg_attr(all(feature = "llvm-libunwind", - any(target_os = "fuchsia", target_os = "linux")), - link(name = "unwind", kind = "static"))] + #[cfg_attr( + all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), + link(name = "unwind", kind = "static", modifiers = "-bundle") + )] extern "C-unwind" { pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code; } @@ -241,9 +253,6 @@ if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { } } else { // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() - #[cfg_attr(all(feature = "llvm-libunwind", - any(target_os = "fuchsia", target_os = "linux")), - link(name = "unwind", kind = "static"))] extern "C-unwind" { pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index d25989954783..afddbc1da9e7 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -23,7 +23,7 @@ use serde::Deserialize; use crate::builder::Cargo; use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; use crate::cache::{Interned, INTERNER}; -use crate::config::TargetSelection; +use crate::config::{LlvmLibunwind, TargetSelection}; use crate::dist; use crate::native; use crate::tool::SourceType; @@ -234,6 +234,18 @@ fn copy_self_contained_objects( } } + if target.contains("musl") + || target.contains("x86_64-fortanix-unknown-sgx") + || builder.config.llvm_libunwind == LlvmLibunwind::InTree + && (target.contains("linux") || target.contains("fuchsia")) + { + let libunwind_path = builder.ensure(native::Libunwind { target }); + let libunwind_source = libunwind_path.join("libunwind.a"); + let libunwind_target = libdir_self_contained.join("libunwind.a"); + builder.copy(&libunwind_source, &libunwind_target); + target_deps.push((libunwind_target, DependencyType::TargetSelfContained)); + } + target_deps } diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 2172b01706d8..0a23d4fff6bd 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -10,7 +10,7 @@ use std::env; use std::env::consts::EXE_EXTENSION; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io; use std::path::{Path, PathBuf}; @@ -952,3 +952,154 @@ impl Step for CrtBeginEnd { out_dir } } + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct Libunwind { + pub target: TargetSelection, +} + +impl Step for Libunwind { + type Output = PathBuf; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.path("src/llvm-project/libunwind") + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(Libunwind { target: run.target }); + } + + /// Build linunwind.a + fn run(self, builder: &Builder<'_>) -> Self::Output { + if builder.config.dry_run { + return PathBuf::new(); + } + + let out_dir = builder.native_dir(self.target).join("libunwind"); + let root = builder.src.join("src/llvm-project/libunwind"); + + if up_to_date(&root, &out_dir.join("libunwind.a")) { + return out_dir; + } + + builder.info(&format!("Building libunwind.a for {}", self.target.triple)); + t!(fs::create_dir_all(&out_dir)); + + let mut cc_cfg = cc::Build::new(); + let mut cpp_cfg = cc::Build::new(); + + cpp_cfg.cpp(true); + cpp_cfg.cpp_set_stdlib(None); + cpp_cfg.flag("-nostdinc++"); + cpp_cfg.flag("-fno-exceptions"); + cpp_cfg.flag("-fno-rtti"); + cpp_cfg.flag_if_supported("-fvisibility-global-new-delete-hidden"); + + for cfg in [&mut cc_cfg, &mut cpp_cfg].iter_mut() { + if let Some(ar) = builder.ar(self.target) { + cfg.archiver(ar); + } + cfg.target(&self.target.triple); + cfg.host(&builder.config.build.triple); + cfg.warnings(false); + cfg.debug(false); + // get_compiler() need set opt_level first. + cfg.opt_level(3); + cfg.flag("-fstrict-aliasing"); + cfg.flag("-funwind-tables"); + cfg.flag("-fvisibility=hidden"); + cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None); + cfg.include(root.join("include")); + cfg.cargo_metadata(false); + cfg.out_dir(&out_dir); + + if self.target.contains("x86_64-fortanix-unknown-sgx") { + cfg.static_flag(true); + cfg.flag("-fno-stack-protector"); + cfg.flag("-ffreestanding"); + cfg.flag("-fexceptions"); + + // easiest way to undefine since no API available in cc::Build to undefine + cfg.flag("-U_FORTIFY_SOURCE"); + cfg.define("_FORTIFY_SOURCE", "0"); + cfg.define("RUST_SGX", "1"); + cfg.define("__NO_STRING_INLINES", None); + cfg.define("__NO_MATH_INLINES", None); + cfg.define("_LIBUNWIND_IS_BAREMETAL", None); + cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); + cfg.define("NDEBUG", None); + } + } + + cc_cfg.compiler(builder.cc(self.target)); + if let Ok(cxx) = builder.cxx(self.target) { + cpp_cfg.compiler(cxx); + } else { + cc_cfg.compiler(builder.cc(self.target)); + } + + // Don't set this for clang + // By default, Clang builds C code in GNU C17 mode. + // By default, Clang builds C++ code according to the C++98 standard, + // with many C++11 features accepted as extensions. + if cc_cfg.get_compiler().is_like_gnu() { + cc_cfg.flag("-std=c99"); + } + if cpp_cfg.get_compiler().is_like_gnu() { + cpp_cfg.flag("-std=c++11"); + } + + if self.target.contains("x86_64-fortanix-unknown-sgx") || self.target.contains("musl") { + // use the same GCC C compiler command to compile C++ code so we do not need to setup the + // C++ compiler env variables on the builders. + // Don't set this for clang++, as clang++ is able to compile this without libc++. + if cpp_cfg.get_compiler().is_like_gnu() { + cpp_cfg.cpp(false); + cpp_cfg.compiler(builder.cc(self.target)); + } + } + + let mut c_sources = vec![ + "Unwind-sjlj.c", + "UnwindLevel1-gcc-ext.c", + "UnwindLevel1.c", + "UnwindRegistersRestore.S", + "UnwindRegistersSave.S", + ]; + + let cpp_sources = vec!["Unwind-EHABI.cpp", "Unwind-seh.cpp", "libunwind.cpp"]; + let cpp_len = cpp_sources.len(); + + if self.target.contains("x86_64-fortanix-unknown-sgx") { + c_sources.push("UnwindRustSgx.c"); + } + + for src in c_sources { + cc_cfg.file(root.join("src").join(src).canonicalize().unwrap()); + } + + for src in &cpp_sources { + cpp_cfg.file(root.join("src").join(src).canonicalize().unwrap()); + } + + cpp_cfg.compile("unwind-cpp"); + + // FIXME: https://github.com/alexcrichton/cc-rs/issues/545#issuecomment-679242845 + let mut count = 0; + for entry in fs::read_dir(&out_dir).unwrap() { + let file = entry.unwrap().path().canonicalize().unwrap(); + if file.is_file() && file.extension() == Some(OsStr::new("o")) { + // file name starts with "Unwind-EHABI", "Unwind-seh" or "libunwind" + let file_name = file.file_name().unwrap().to_str().expect("UTF-8 file name"); + if cpp_sources.iter().any(|f| file_name.starts_with(&f[..f.len() - 4])) { + cc_cfg.object(&file); + count += 1; + } + } + } + assert_eq!(cpp_len, count, "Can't get object files from {:?}", &out_dir); + + cc_cfg.compile("unwind"); + out_dir + } +} From 2de6c14b25b63e30b37aa6124ac0c6beea131ed7 Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Fri, 27 Aug 2021 23:21:50 -0700 Subject: [PATCH 217/269] RELEASES.md: fix broken link --- RELEASES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASES.md b/RELEASES.md index dd299ca936ac..5b8193c7e9e8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -116,6 +116,7 @@ Compatibility Notes [79965]: https://github.com/rust-lang/rust/pull/79965 [87370]: https://github.com/rust-lang/rust/pull/87370 [87298]: https://github.com/rust-lang/rust/pull/87298 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [cargo/9675]: https://github.com/rust-lang/cargo/pull/9675 [cargo/9550]: https://github.com/rust-lang/cargo/pull/9550 [cargo/9680]: https://github.com/rust-lang/cargo/pull/9680 From 9a53d59b97951635e2b157a29f2dc3b61e8f393a Mon Sep 17 00:00:00 2001 From: 12101111 Date: Sat, 28 Aug 2021 14:40:17 +0800 Subject: [PATCH 218/269] fix evaluation of target_feature = "crt-static" --- src/test/ui/proc-macro/crt-static.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/ui/proc-macro/crt-static.rs b/src/test/ui/proc-macro/crt-static.rs index 4f11f81b00bf..8c1a9dc80265 100644 --- a/src/test/ui/proc-macro/crt-static.rs +++ b/src/test/ui/proc-macro/crt-static.rs @@ -1,12 +1,19 @@ // Test proc-macro crate can be built without additional RUSTFLAGS // on musl target // override -Ctarget-feature=-crt-static from compiletest -// compile-flags: -Ctarget-feature= +// compile-flags: --crate-type proc-macro -Ctarget-feature= // ignore-wasm32 // ignore-sgx no support for proc-macro crate type // build-pass #![crate_type = "proc-macro"] +// FIXME: This don't work when crate-type is specified by attribute +// `#![crate_type = "proc-macro"]`, not by `--crate-type=proc-macro` +// command line flag. This is beacuse the list of `cfg` symbols is generated +// before attributes are parsed. See rustc_interface::util::add_configuration +#[cfg(target_feature = "crt-static")] +compile_error!("crt-static is enabled"); + extern crate proc_macro; use proc_macro::TokenStream; From bf2f6656bca22c86a1f75efda468a8560c6a43b8 Mon Sep 17 00:00:00 2001 From: liudingming Date: Sat, 28 Aug 2021 14:45:24 +0800 Subject: [PATCH 219/269] Revert machine outliner disabling on LLVM 13 --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 0ca51bd28831..3b64ec1a9912 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -89,13 +89,14 @@ unsafe fn configure_llvm(sess: &Session) { add("-generate-arange-section", false); } - // FIXME(nagisa): disable the machine outliner by default in LLVM versions 11, where it was - // introduced and up. + // Disable the machine outliner by default in LLVM versions 11 and LLVM + // version 12, where it leads to miscompilation. // - // This should remain in place until https://reviews.llvm.org/D103167 is fixed. If LLVM - // has been upgraded since, consider adjusting the version check below to contain an upper - // bound. - if llvm_util::get_version() >= (11, 0, 0) { + // Ref: + // - https://github.com/rust-lang/rust/issues/85351 + // - https://reviews.llvm.org/D103167 + let llvm_version = llvm_util::get_version(); + if llvm_version >= (11, 0, 0) && llvm_version < (13, 0, 0) { add("-enable-machine-outliner=never", false); } From 8c62fa057527fc07afabb201bb31428409ef4d8a Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 30 Jul 2021 23:50:57 -0700 Subject: [PATCH 220/269] Treat macros as HIR items --- Cargo.lock | 1 + compiler/rustc_ast_lowering/src/item.rs | 30 +---- compiler/rustc_ast_lowering/src/lib.rs | 10 -- compiler/rustc_ast_pretty/src/pprust/state.rs | 48 +++++--- compiler/rustc_hir/src/arena.rs | 1 - compiler/rustc_hir/src/hir.rs | 34 +----- compiler/rustc_hir/src/intravisit.rs | 12 +- compiler/rustc_hir/src/stable_hash_impls.rs | 17 +-- compiler/rustc_hir/src/target.rs | 1 + compiler/rustc_hir_pretty/src/lib.rs | 5 + compiler/rustc_lint/src/builtin.rs | 19 +-- compiler/rustc_lint/src/late.rs | 4 - compiler/rustc_lint/src/levels.rs | 3 - compiler/rustc_metadata/src/rmeta/decoder.rs | 8 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 17 +-- .../rustc_middle/src/hir/map/collector.rs | 14 --- compiler/rustc_middle/src/hir/map/mod.rs | 13 +- .../rustc_mir/src/monomorphize/collector.rs | 1 + compiler/rustc_passes/src/check_attr.rs | 21 ++-- compiler/rustc_passes/src/diagnostic_items.rs | 4 - compiler/rustc_passes/src/hir_stats.rs | 5 - compiler/rustc_passes/src/lib_features.rs | 4 +- compiler/rustc_passes/src/reachable.rs | 1 + compiler/rustc_passes/src/stability.rs | 18 --- compiler/rustc_privacy/Cargo.toml | 1 + compiler/rustc_privacy/src/lib.rs | 114 ++++++++++-------- compiler/rustc_resolve/src/late/lifetimes.rs | 1 + compiler/rustc_save_analysis/src/sig.rs | 8 ++ compiler/rustc_typeck/src/collect.rs | 1 + compiler/rustc_typeck/src/collect/type_of.rs | 1 + .../clippy/clippy_lints/src/missing_doc.rs | 1 + 31 files changed, 162 insertions(+), 256 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cef4f11da801..af23324cbefd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4146,6 +4146,7 @@ dependencies = [ name = "rustc_privacy" version = "0.0.0" dependencies = [ + "rustc_ast", "rustc_attr", "rustc_data_structures", "rustc_errors", diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 3acf69ec2b7d..cc87078d54b3 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -170,7 +170,6 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_item_id_use_tree(use_tree, i.id, &mut vec); vec } - ItemKind::MacroDef(..) => SmallVec::new(), ItemKind::Fn(..) | ItemKind::Impl(box ImplKind { of_trait: None, .. }) => { smallvec![i.id] } @@ -212,28 +211,6 @@ impl<'hir> LoweringContext<'_, 'hir> { pub fn lower_item(&mut self, i: &Item) -> Option> { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); - - if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind { - if !macro_rules || self.sess.contains_name(&i.attrs, sym::macro_export) { - let hir_id = self.lower_node_id(i.id); - self.lower_attrs(hir_id, &i.attrs); - let body = P(self.lower_mac_args(body)); - self.insert_macro_def(hir::MacroDef { - ident, - vis, - def_id: hir_id.expect_owner(), - span: i.span, - ast: MacroDef { body, macro_rules }, - }); - } else { - for a in i.attrs.iter() { - let a = self.lower_attr(a); - self.non_exported_macro_attrs.push(a); - } - } - return None; - } - let hir_id = self.lower_node_id(i.id); let attrs = self.lower_attrs(hir_id, &i.attrs); let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind); @@ -465,7 +442,12 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_generics(generics, ImplTraitContext::disallowed()), self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), ), - ItemKind::MacroDef(..) | ItemKind::MacCall(..) => { + ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => { + let body = P(self.lower_mac_args(body)); + + hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }) + } + ItemKind::MacCall(..) => { panic!("`TyMac` should have been expanded by now") } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 948d74e3bf8e..bd2c9f41a537 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -103,7 +103,6 @@ struct LoweringContext<'a, 'hir: 'a> { /// The items being lowered are collected here. owners: IndexVec>>, bodies: BTreeMap>, - non_exported_macro_attrs: Vec, trait_impls: BTreeMap>, @@ -330,7 +329,6 @@ pub fn lower_crate<'a, 'hir>( trait_impls: BTreeMap::new(), modules: BTreeMap::new(), attrs: BTreeMap::default(), - non_exported_macro_attrs: Vec::new(), catch_scopes: Vec::new(), loop_scopes: Vec::new(), is_in_loop_condition: false, @@ -551,7 +549,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } let krate = hir::Crate { - non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs), owners: self.owners, bodies: self.bodies, body_ids, @@ -600,13 +597,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { id } - fn insert_macro_def(&mut self, item: hir::MacroDef<'hir>) { - let def_id = item.def_id; - let item = self.arena.alloc(item); - self.owners.ensure_contains_elem(def_id, || None); - self.owners[def_id] = Some(hir::OwnerNode::MacroDef(item)); - } - fn allocate_hir_id_counter(&mut self, owner: NodeId) -> hir::HirId { // Set up the counter if needed. self.item_local_id_counters.entry(owner).or_insert(0); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index b09c668273aa..f729973ddc62 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -578,6 +578,33 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } } + fn print_mac_def( + &mut self, + macro_def: &ast::MacroDef, + ident: &Ident, + sp: &Span, + print_visibility: impl FnOnce(&mut Self), + ) { + let (kw, has_bang) = if macro_def.macro_rules { + ("macro_rules", true) + } else { + print_visibility(self); + ("macro", false) + }; + self.print_mac_common( + Some(MacHeader::Keyword(kw)), + has_bang, + Some(*ident), + macro_def.body.delim(), + ¯o_def.body.inner_tokens(), + true, + *sp, + ); + if macro_def.body.need_semicolon() { + self.word(";"); + } + } + fn print_path(&mut self, path: &ast::Path, colons_before_params: bool, depth: usize) { self.maybe_print_comment(path.span.lo()); @@ -1305,24 +1332,9 @@ impl<'a> State<'a> { } } ast::ItemKind::MacroDef(ref macro_def) => { - let (kw, has_bang) = if macro_def.macro_rules { - ("macro_rules", true) - } else { - self.print_visibility(&item.vis); - ("macro", false) - }; - self.print_mac_common( - Some(MacHeader::Keyword(kw)), - has_bang, - Some(item.ident), - macro_def.body.delim(), - ¯o_def.body.inner_tokens(), - true, - item.span, - ); - if macro_def.body.need_semicolon() { - self.word(";"); - } + self.print_mac_def(macro_def, &item.ident, &item.span, |state| { + state.print_visibility(&item.vis) + }); } } self.ann.post(self, AnnNode::Item(item)) diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index c4cff79f6c52..0801a1bde226 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -35,7 +35,6 @@ macro_rules! arena_types { [few] inline_asm: rustc_hir::InlineAsm<$tcx>, [few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>, [] local: rustc_hir::Local<$tcx>, - [few] macro_def: rustc_hir::MacroDef<$tcx>, [few] mod_: rustc_hir::Mod<$tcx>, [] param: rustc_hir::Param<$tcx>, [] pat: rustc_hir::Pat<$tcx>, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 551e6a57b32b..a166337c0dfc 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -670,9 +670,6 @@ pub struct ModuleItems { /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html #[derive(Debug)] pub struct Crate<'hir> { - // Attributes from non-exported macros, kept only for collecting the library feature list. - pub non_exported_macro_attrs: &'hir [Attribute], - pub owners: IndexVec>>, pub bodies: BTreeMap>, pub trait_impls: BTreeMap>, @@ -768,32 +765,6 @@ impl Crate<'_> { _ => None, }) } - - pub fn exported_macros<'hir>(&'hir self) -> impl Iterator> + 'hir { - self.owners.iter().filter_map(|owner| match owner { - Some(OwnerNode::MacroDef(macro_def)) => Some(*macro_def), - _ => None, - }) - } -} - -/// A macro definition, in this crate or imported from another. -/// -/// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(Debug)] -pub struct MacroDef<'hir> { - pub ident: Ident, - pub vis: Visibility<'hir>, - pub def_id: LocalDefId, - pub span: Span, - pub ast: ast::MacroDef, -} - -impl MacroDef<'_> { - #[inline] - pub fn hir_id(&self) -> HirId { - HirId::make_owner(self.def_id) - } } /// A block of statements `{ .. }`, which may have a label (in this case the @@ -2602,7 +2573,7 @@ pub struct PolyTraitRef<'hir> { pub type Visibility<'hir> = Spanned>; -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub enum VisibilityKind<'hir> { Public, Crate(CrateSugar), @@ -2791,6 +2762,8 @@ pub enum ItemKind<'hir> { Const(&'hir Ty<'hir>, BodyId), /// A function declaration. Fn(FnSig<'hir>, Generics<'hir>, BodyId), + /// A MBE macro definition (`macro_rules!` or `macro`). + Macro(ast::MacroDef), /// A module. Mod(Mod<'hir>), /// An external module, e.g. `extern { .. }`. @@ -2856,6 +2829,7 @@ impl ItemKind<'_> { ItemKind::Static(..) => "static item", ItemKind::Const(..) => "constant item", ItemKind::Fn(..) => "function", + ItemKind::Macro(..) => "macro", ItemKind::Mod(..) => "module", ItemKind::ForeignMod { .. } => "extern block", ItemKind::GlobalAsm(..) => "global asm item", diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 7f153867596e..f4fbfd2692ca 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -466,9 +466,6 @@ pub trait Visitor<'v>: Sized { walk_assoc_type_binding(self, type_binding) } fn visit_attribute(&mut self, _id: HirId, _attr: &'v Attribute) {} - fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) { - walk_macro_def(self, macro_def) - } fn visit_vis(&mut self, vis: &'v Visibility<'v>) { walk_vis(self, vis) } @@ -484,7 +481,6 @@ pub trait Visitor<'v>: Sized { pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) { let top_mod = krate.module(); visitor.visit_mod(top_mod, top_mod.inner, CRATE_HIR_ID); - walk_list!(visitor, visit_macro_def, krate.exported_macros()); for (&id, attrs) in krate.attrs.iter() { for a in *attrs { visitor.visit_attribute(id, a) @@ -492,11 +488,6 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) { } } -pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) { - visitor.visit_id(macro_def.hir_id()); - visitor.visit_ident(macro_def.ident); -} - pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) { visitor.visit_id(mod_hir_id); for &item_id in module.item_ids { @@ -586,6 +577,9 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { item.span, item.hir_id(), ), + ItemKind::Macro(_) => { + visitor.visit_id(item.hir_id()); + } ItemKind::Mod(ref module) => { // `visit_mod()` takes care of visiting the `Item`'s `HirId`. visitor.visit_mod(module, item.span, item.hir_id()) diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index 560607528330..422a1064874c 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,8 +1,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use crate::hir::{ - BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, MacroDef, Mod, - TraitItem, TraitItemId, Ty, VisibilityKind, + BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, + TraitItemId, Ty, VisibilityKind, }; use crate::hir_id::{HirId, ItemLocalId}; use rustc_span::def_id::DefPathHash; @@ -190,16 +190,3 @@ impl HashStable for Item<'_> { }); } } - -impl HashStable for MacroDef<'_> { - fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - let MacroDef { ident, def_id: _, ref ast, ref vis, span } = *self; - - hcx.hash_hir_item_like(|hcx| { - ident.name.hash_stable(hcx, hasher); - ast.hash_stable(hcx, hasher); - vis.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }); - } -} diff --git a/compiler/rustc_hir/src/target.rs b/compiler/rustc_hir/src/target.rs index 473477bf22da..29c948fe3184 100644 --- a/compiler/rustc_hir/src/target.rs +++ b/compiler/rustc_hir/src/target.rs @@ -111,6 +111,7 @@ impl Target { ItemKind::Static(..) => Target::Static, ItemKind::Const(..) => Target::Const, ItemKind::Fn(..) => Target::Fn, + ItemKind::Macro(..) => Target::MacroDef, ItemKind::Mod(..) => Target::Mod, ItemKind::ForeignMod { .. } => Target::ForeignMod, ItemKind::GlobalAsm(..) => Target::GlobalAsm, diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 9c286ad5ccfe..89e7f8c1de6b 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -642,6 +642,11 @@ impl<'a> State<'a> { self.end(); // need to close a box self.ann.nested(self, Nested::Body(body)); } + hir::ItemKind::Macro(ref macro_def) => { + self.print_mac_def(macro_def, &item.ident, &item.span, |state| { + state.print_visibility(&item.vis) + }); + } hir::ItemKind::Mod(ref _mod) => { self.head(visibility_qualified(&item.vis, "mod")); self.print_ident(item.ident); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 8f848f54aad6..a5b4fa15921b 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -585,24 +585,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) { self.check_missing_docs_attrs(cx, CRATE_DEF_ID, krate.module().inner, "the", "crate"); - - for macro_def in krate.exported_macros() { - // Non exported macros should be skipped, since `missing_docs` only - // applies to externally visible items. - if !cx.access_levels.is_exported(macro_def.def_id) { - continue; - } - - let attrs = cx.tcx.hir().attrs(macro_def.hir_id()); - let has_doc = attrs.iter().any(has_doc); - if !has_doc { - cx.struct_span_lint( - MISSING_DOCS, - cx.tcx.sess.source_map().guess_head_span(macro_def.span), - |lint| lint.build("missing documentation for macro").emit(), - ); - } - } } fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { @@ -636,6 +618,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::TyAlias(..) | hir::ItemKind::Fn(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 052efa851f7c..30400da86b4b 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -453,10 +453,6 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) lint_callback!(cx, check_crate, krate); hir_visit::walk_crate(cx, krate); - for attr in krate.non_exported_macro_attrs { - // This HIR ID is a lie, since the macro ID isn't available. - cx.visit_attribute(hir::CRATE_HIR_ID, attr); - } lint_callback!(cx, check_crate_post, krate); }) diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index e6cbfa0c9e29..90bf34ee863b 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -37,9 +37,6 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true); builder.levels.register_id(hir::CRATE_HIR_ID); - for macro_def in krate.exported_macros() { - builder.levels.register_id(macro_def.hir_id()); - } intravisit::walk_crate(&mut builder, krate); builder.levels.pop(push); diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 4e591b28f608..dd44e0cb1fa9 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1100,7 +1100,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { let vis = self.get_visibility(child_index); let def_id = self.local_def_id(child_index); let res = Res::Def(kind, def_id); - callback(Export { res, ident, vis, span }); + + // FIXME: Macros are currently encoded twice, once as items and once as + // reexports. We ignore the items here and only use the reexports. + if !matches!(kind, DefKind::Macro(..)) { + callback(Export { res, ident, vis, span }); + } + // For non-re-export structs and variants add their constructors to children. // Re-export lists automatically contain constructors when necessary. match kind { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1c243f8bd514..2cd4fe3b7062 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -448,9 +448,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } krate.visit_all_item_likes(&mut self.as_deep_visitor()); - for macro_def in krate.exported_macros() { - self.visit_macro_def(macro_def); - } } fn encode_def_path_table(&mut self) { @@ -1385,6 +1382,9 @@ impl EncodeContext<'a, 'tcx> { EntryKind::Fn(self.lazy(data)) } + hir::ItemKind::Macro(ref macro_def) => { + EntryKind::MacroDef(self.lazy(macro_def.clone())) + } hir::ItemKind::Mod(ref m) => { return self.encode_info_for_mod(item.def_id, m); } @@ -1539,13 +1539,6 @@ impl EncodeContext<'a, 'tcx> { } } - /// Serialize the text of exported macros - fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) { - let def_id = macro_def.def_id.to_def_id(); - record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone()))); - self.encode_ident_span(def_id, macro_def.ident); - } - fn encode_info_for_generic_param(&mut self, def_id: DefId, kind: EntryKind, encode_type: bool) { record!(self.tables.kind[def_id] <- kind); if encode_type { @@ -1915,9 +1908,6 @@ impl Visitor<'tcx> for EncodeContext<'a, 'tcx> { intravisit::walk_generics(self, generics); self.encode_info_for_generics(generics); } - fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) { - self.encode_info_for_macro_def(macro_def); - } } impl EncodeContext<'a, 'tcx> { @@ -1972,6 +1962,7 @@ impl EncodeContext<'a, 'tcx> { hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | hir::ItemKind::Fn(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 5c166c74004a..1351b4950f14 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -394,20 +394,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } } - fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) { - // Exported macros are visited directly from the crate root, - // so they do not have `parent_node` set. - // Find the correct enclosing module from their DefKey. - let def_key = self.definitions.def_key(macro_def.def_id); - let parent = def_key.parent.map_or(hir::CRATE_HIR_ID, |local_def_index| { - self.definitions.local_def_id_to_hir_id(LocalDefId { local_def_index }) - }); - self.insert_owner(macro_def.def_id, OwnerNode::MacroDef(macro_def)); - self.with_parent(parent, |this| { - this.insert_nested(macro_def.def_id); - }); - } - fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics<'hir>, item_id: HirId) { self.insert(v.span, v.id, Node::Variant(v)); self.with_parent(v.id, |this| { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index c313146b0722..82c2f32b8241 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -10,7 +10,6 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_hir::intravisit; -use rustc_hir::intravisit::Visitor; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::*; use rustc_index::vec::Idx; @@ -218,6 +217,7 @@ impl<'hir> Map<'hir> { ItemKind::Static(..) => DefKind::Static, ItemKind::Const(..) => DefKind::Const, ItemKind::Fn(..) => DefKind::Fn, + ItemKind::Macro(..) => DefKind::Macro(MacroKind::Bang), ItemKind::Mod(..) => DefKind::Mod, ItemKind::OpaqueTy(..) => DefKind::OpaqueTy, ItemKind::TyAlias(..) => DefKind::TyAlias, @@ -543,15 +543,6 @@ impl<'hir> Map<'hir> { } } - pub fn visit_exported_macros_in_krate(&self, visitor: &mut V) - where - V: Visitor<'hir>, - { - for macro_def in self.krate().exported_macros() { - visitor.visit_macro_def(macro_def); - } - } - /// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// until the crate root is reached. Prefer this over your own loop using `get_parent_node`. pub fn parent_iter(&self, current_id: HirId) -> ParentHirIterator<'_, 'hir> { @@ -1013,7 +1004,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { source_file_names.hash_stable(&mut hcx, &mut stable_hasher); tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher); tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher); - tcx.untracked_crate.non_exported_macro_attrs.hash_stable(&mut hcx, &mut stable_hasher); let crate_hash: Fingerprint = stable_hasher.finish(); Svh::new(crate_hash.to_smaller_hash()) @@ -1062,6 +1052,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String { ItemKind::Static(..) => "static", ItemKind::Const(..) => "const", ItemKind::Fn(..) => "fn", + ItemKind::Macro(..) => "macro", ItemKind::Mod(..) => "mod", ItemKind::ForeignMod { .. } => "foreign mod", ItemKind::GlobalAsm(..) => "global asm", diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index f03036267acf..4cb362238c1c 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -1149,6 +1149,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { match item.kind { hir::ItemKind::ExternCrate(..) | hir::ItemKind::Use(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::TyAlias(..) | hir::ItemKind::Trait(..) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d0ddad1c1a33..d3dac35d2c9e 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1723,6 +1723,16 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { } fn visit_item(&mut self, item: &'tcx Item<'tcx>) { + // Historically we've run more checks on non-exported than exported macros, + // so this lets us continue to run them while maintaining backwards compatibility. + // In the long run, the checks should be harmonized. + if let ItemKind::Macro(ref macro_def) = item.kind { + let def_id = item.def_id.to_def_id(); + if macro_def.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) { + check_non_exported_macro_for_invalid_attrs(self.tcx, item); + } + } + let target = Target::from_item(item); self.check_attributes(item.hir_id(), &item.span, target, Some(ItemLike::Item(item))); intravisit::walk_item(self, item) @@ -1795,11 +1805,6 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { intravisit::walk_variant(self, variant, generics, item_id) } - fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) { - self.check_attributes(macro_def.hir_id(), ¯o_def.span, Target::MacroDef, None); - intravisit::walk_macro_def(self, macro_def); - } - fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { self.check_attributes(param.hir_id, ¶m.span, Target::Param, None); @@ -1848,7 +1853,9 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { } } -fn check_invalid_macro_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { +fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) { + let attrs = tcx.hir().attrs(item.hir_id()); + for attr in attrs { if attr.has_name(sym::inline) { struct_span_err!( @@ -1869,8 +1876,6 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { if module_def_id.is_top_level_module() { check_attr_visitor.check_attributes(CRATE_HIR_ID, &DUMMY_SP, Target::Mod, None); check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs()); - tcx.hir().visit_exported_macros_in_krate(check_attr_visitor); - check_invalid_macro_level_attr(tcx, tcx.hir().krate().non_exported_macro_attrs); } } diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index e43abda71335..3f12a744be0e 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -107,10 +107,6 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> FxHashMap hir_visit::Visitor<'v> for StatCollector<'v> { fn visit_attribute(&mut self, _: hir::HirId, attr: &'v ast::Attribute) { self.record("Attribute", Id::Attr(attr.id), attr); } - - fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) { - self.record("MacroDef", Id::Node(macro_def.hir_id()), macro_def); - hir_visit::walk_macro_def(self, macro_def) - } } impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 605b52f18913..7d15ca1e8f79 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -127,9 +127,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { fn get_lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); let krate = tcx.hir().krate(); - for attr in krate.non_exported_macro_attrs { - collector.visit_attribute(rustc_hir::CRATE_HIR_ID, attr); - } + intravisit::walk_crate(&mut collector, krate); collector.lib_features } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 5ca098c22878..7d22426609c1 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -263,6 +263,7 @@ impl<'tcx> ReachableContext<'tcx> { | hir::ItemKind::Use(..) | hir::ItemKind::OpaqueTy(..) | hir::ItemKind::TyAlias(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index b64dcb0bbf03..a88393cea828 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -538,19 +538,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { ); } - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.annotate( - md.def_id, - md.span, - None, - AnnotationKind::Required, - InheritDeprecation::Yes, - InheritConstStability::No, - InheritStability::No, - |_| {}, - ); - } - fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { let kind = match &p.kind { // Allow stability attributes on default generic arguments. @@ -662,11 +649,6 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { self.check_missing_stability(i.def_id, i.span); intravisit::walk_foreign_item(self, i); } - - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.check_missing_stability(md.def_id, md.span); - } - // Note that we don't need to `check_missing_stability` for default generic parameters, // as we assume that any default generic parameters without attributes are automatically // stable (assuming they have not inherited instability from their parent). diff --git a/compiler/rustc_privacy/Cargo.toml b/compiler/rustc_privacy/Cargo.toml index 85a53b1bde22..6ac2915c3452 100644 --- a/compiler/rustc_privacy/Cargo.toml +++ b/compiler/rustc_privacy/Cargo.toml @@ -5,6 +5,7 @@ edition = "2018" [dependencies] rustc_middle = { path = "../rustc_middle" } +rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 6fe68a0c17a5..079a9ed878a7 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -6,6 +6,7 @@ #![feature(associated_type_defaults)] #![recursion_limit = "256"] +use rustc_ast::MacroDef; use rustc_attr as attr; use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; @@ -26,7 +27,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, Const, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; use rustc_session::lint; use rustc_span::hygiene::Transparency; -use rustc_span::symbol::{kw, Ident}; +use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; use rustc_trait_selection::traits::const_evaluatable::{self, AbstractConst}; @@ -462,6 +463,43 @@ impl EmbargoVisitor<'tcx> { } } + // We have to make sure that the items that macros might reference + // are reachable, since they might be exported transitively. + fn update_reachability_from_macro(&mut self, local_def_id: LocalDefId, md: &MacroDef) { + // Non-opaque macros cannot make other items more accessible than they already are. + + let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id); + let attrs = self.tcx.hir().attrs(hir_id); + if attr::find_transparency(&attrs, md.macro_rules).0 != Transparency::Opaque { + return; + } + + let item_def_id = local_def_id.to_def_id(); + let macro_module_def_id = + ty::DefIdTree::parent(self.tcx, item_def_id).unwrap().expect_local(); + if self.tcx.hir().opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) { + // The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252). + return; + } + + if self.get(local_def_id).is_none() { + return; + } + + // Since we are starting from an externally visible module, + // all the parents in the loop below are also guaranteed to be modules. + let mut module_def_id = macro_module_def_id; + loop { + let changed_reachability = + self.update_macro_reachable(module_def_id, macro_module_def_id); + if changed_reachability || module_def_id == CRATE_DEF_ID { + break; + } + module_def_id = + ty::DefIdTree::parent(self.tcx, module_def_id.to_def_id()).unwrap().expect_local(); + } + } + /// Updates the item as being reachable through a macro defined in the given /// module. Returns `true` if the level has changed. fn update_macro_reachable( @@ -511,16 +549,26 @@ impl EmbargoVisitor<'tcx> { } match def_kind { // No type privacy, so can be directly marked as reachable. - DefKind::Const - | DefKind::Macro(_) - | DefKind::Static - | DefKind::TraitAlias - | DefKind::TyAlias => { + DefKind::Const | DefKind::Static | DefKind::TraitAlias | DefKind::TyAlias => { if vis.is_accessible_from(module.to_def_id(), self.tcx) { self.update(def_id, level); } } + // Hygine isn't really implemented for `macro_rules!` macros at the + // moment. Accordingly, marking them as reachable is unwise. `macro` macros + // have normal hygine, so we can treat them like other items without type + // privacy and mark them reachable. + DefKind::Macro(_) => { + let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); + let item = self.tcx.hir().expect_item(hir_id); + if let hir::ItemKind::Macro(MacroDef { macro_rules: false, .. }) = item.kind { + if vis.is_accessible_from(module.to_def_id(), self.tcx) { + self.update(def_id, level); + } + } + } + // We can't use a module name as the final segment of a path, except // in use statements. Since re-export checking doesn't consider // hygiene these don't need to be marked reachable. The contents of @@ -644,6 +692,12 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { hir::ItemKind::Impl { .. } => { Option::::of_impl(item.def_id, self.tcx, &self.access_levels) } + // Only exported `macro_rules!` items are public, but they always are. + hir::ItemKind::Macro(MacroDef { macro_rules: true, .. }) => { + let def_id = item.def_id.to_def_id(); + let is_macro_export = self.tcx.has_attr(def_id, sym::macro_export); + if is_macro_export { Some(AccessLevel::Public) } else { None } + } // Foreign modules inherit level from parents. hir::ItemKind::ForeignMod { .. } => self.prev_level, // Other `pub` items inherit levels from parents. @@ -652,6 +706,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { | hir::ItemKind::ExternCrate(..) | hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) @@ -708,6 +763,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } } + hir::ItemKind::Macro(ref macro_def) => { + self.update_reachability_from_macro(item.def_id, macro_def); + } hir::ItemKind::ForeignMod { items, .. } => { for foreign_item in items { if foreign_item.vis.node.is_pub() { @@ -715,6 +773,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } } + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Use(..) | hir::ItemKind::Static(..) @@ -730,7 +789,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { // Mark all items in interfaces of reachable items as reachable. match item.kind { // The interface is empty. - hir::ItemKind::ExternCrate(..) => {} + hir::ItemKind::Macro(..) | hir::ItemKind::ExternCrate(..) => {} // All nested items are checked by `visit_item`. hir::ItemKind::Mod(..) => {} // Re-exports are handled in `visit_mod`. However, in order to avoid looping over @@ -885,45 +944,6 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { intravisit::walk_mod(self, m, id); } - - fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - // Non-opaque macros cannot make other items more accessible than they already are. - let attrs = self.tcx.hir().attrs(md.hir_id()); - if attr::find_transparency(&attrs, md.ast.macro_rules).0 != Transparency::Opaque { - // `#[macro_export]`-ed `macro_rules!` are `Public` since they - // ignore their containing path to always appear at the crate root. - if md.ast.macro_rules { - self.update(md.def_id, Some(AccessLevel::Public)); - } - return; - } - - let macro_module_def_id = - ty::DefIdTree::parent(self.tcx, md.def_id.to_def_id()).unwrap().expect_local(); - if self.tcx.hir().opt_def_kind(macro_module_def_id) != Some(DefKind::Mod) { - // The macro's parent doesn't correspond to a `mod`, return early (#63164, #65252). - return; - } - - let level = if md.vis.node.is_pub() { self.get(macro_module_def_id) } else { None }; - let new_level = self.update(md.def_id, level); - if new_level.is_none() { - return; - } - - // Since we are starting from an externally visible module, - // all the parents in the loop below are also guaranteed to be modules. - let mut module_def_id = macro_module_def_id; - loop { - let changed_reachability = - self.update_macro_reachable(module_def_id, macro_module_def_id); - if changed_reachability || module_def_id == CRATE_DEF_ID { - break; - } - module_def_id = - ty::DefIdTree::parent(self.tcx, module_def_id.to_def_id()).unwrap().expect_local(); - } - } } impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> { @@ -1981,7 +2001,7 @@ impl<'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'tcx> { // Checked in resolve. hir::ItemKind::Use(..) => {} // No subitems. - hir::ItemKind::GlobalAsm(..) => {} + hir::ItemKind::Macro(..) | hir::ItemKind::GlobalAsm(..) => {} // Subitems of these items have inherited publicity. hir::ItemKind::Const(..) | hir::ItemKind::Static(..) diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 882d15cf8920..bc2c46ec0aa7 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -740,6 +740,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::GlobalAsm(..) => { diff --git a/compiler/rustc_save_analysis/src/sig.rs b/compiler/rustc_save_analysis/src/sig.rs index c3bc1c191ff0..7864b47ab0a7 100644 --- a/compiler/rustc_save_analysis/src/sig.rs +++ b/compiler/rustc_save_analysis/src/sig.rs @@ -416,6 +416,14 @@ impl<'hir> Sig for hir::Item<'hir> { Ok(sig) } + hir::ItemKind::Macro(_) => { + let mut text = "macro".to_owned(); + let name = self.ident.to_string(); + text.push_str(&name); + text.push_str(&"! {}"); + + Ok(text_sig(text)) + } hir::ItemKind::Mod(ref _mod) => { let mut text = "mod ".to_owned(); let name = self.ident.to_string(); diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index b514176ad529..145a0c5413bb 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -746,6 +746,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { // These don't define types. hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) + | hir::ItemKind::Macro(_) | hir::ItemKind::Mod(_) | hir::ItemKind::GlobalAsm(_) => {} hir::ItemKind::ForeignMod { items, .. } => { diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 9bce5ee0da26..41277b22da0e 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -427,6 +427,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } ItemKind::Trait(..) | ItemKind::TraitAlias(..) + | ItemKind::Macro(..) | ItemKind::Mod(..) | ItemKind::ForeignMod { .. } | ItemKind::GlobalAsm(..) diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index d358e9fb876a..da86d28ee0b2 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -123,6 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Mod(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) From 0299ed8bbb0b10c17489551c89c16794c7cd6edc Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 30 Jul 2021 23:10:32 -0700 Subject: [PATCH 221/269] Remove obsolete `MacroDef` variant of `OwnerNode` --- compiler/rustc_hir/src/hir.rs | 32 ++++-------------------- compiler/rustc_hir_pretty/src/lib.rs | 1 - compiler/rustc_middle/src/hir/map/mod.rs | 13 ---------- compiler/rustc_passes/src/reachable.rs | 3 +-- 4 files changed, 6 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a166337c0dfc..a9bd83a67c9d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -740,7 +740,7 @@ impl Crate<'_> { OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item), OwnerNode::ImplItem(item) => visitor.visit_impl_item(item), OwnerNode::TraitItem(item) => visitor.visit_trait_item(item), - OwnerNode::MacroDef(_) | OwnerNode::Crate(_) => {} + OwnerNode::Crate(_) => {} } } } @@ -755,7 +755,7 @@ impl Crate<'_> { Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item), Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item), Some(OwnerNode::TraitItem(item)) => visitor.visit_trait_item(item), - Some(OwnerNode::MacroDef(_)) | Some(OwnerNode::Crate(_)) | None => {} + Some(OwnerNode::Crate(_)) | None => {} }) } @@ -2970,7 +2970,6 @@ pub enum OwnerNode<'hir> { ForeignItem(&'hir ForeignItem<'hir>), TraitItem(&'hir TraitItem<'hir>), ImplItem(&'hir ImplItem<'hir>), - MacroDef(&'hir MacroDef<'hir>), Crate(&'hir Mod<'hir>), } @@ -2980,8 +2979,7 @@ impl<'hir> OwnerNode<'hir> { OwnerNode::Item(Item { ident, .. }) | OwnerNode::ForeignItem(ForeignItem { ident, .. }) | OwnerNode::ImplItem(ImplItem { ident, .. }) - | OwnerNode::TraitItem(TraitItem { ident, .. }) - | OwnerNode::MacroDef(MacroDef { ident, .. }) => Some(*ident), + | OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident), OwnerNode::Crate(..) => None, } } @@ -2992,7 +2990,6 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::ForeignItem(ForeignItem { span, .. }) | OwnerNode::ImplItem(ImplItem { span, .. }) | OwnerNode::TraitItem(TraitItem { span, .. }) - | OwnerNode::MacroDef(MacroDef { span, .. }) | OwnerNode::Crate(Mod { inner: span, .. }) => *span, } } @@ -3036,8 +3033,7 @@ impl<'hir> OwnerNode<'hir> { OwnerNode::Item(Item { def_id, .. }) | OwnerNode::TraitItem(TraitItem { def_id, .. }) | OwnerNode::ImplItem(ImplItem { def_id, .. }) - | OwnerNode::ForeignItem(ForeignItem { def_id, .. }) - | OwnerNode::MacroDef(MacroDef { def_id, .. }) => *def_id, + | OwnerNode::ForeignItem(ForeignItem { def_id, .. }) => *def_id, OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner, } } @@ -3069,13 +3065,6 @@ impl<'hir> OwnerNode<'hir> { _ => panic!(), } } - - pub fn expect_macro_def(self) -> &'hir MacroDef<'hir> { - match self { - OwnerNode::MacroDef(n) => n, - _ => panic!(), - } - } } impl<'hir> Into> for &'hir Item<'hir> { @@ -3102,12 +3091,6 @@ impl<'hir> Into> for &'hir TraitItem<'hir> { } } -impl<'hir> Into> for &'hir MacroDef<'hir> { - fn into(self) -> OwnerNode<'hir> { - OwnerNode::MacroDef(self) - } -} - impl<'hir> Into> for OwnerNode<'hir> { fn into(self) -> Node<'hir> { match self { @@ -3115,7 +3098,6 @@ impl<'hir> Into> for OwnerNode<'hir> { OwnerNode::ForeignItem(n) => Node::ForeignItem(n), OwnerNode::ImplItem(n) => Node::ImplItem(n), OwnerNode::TraitItem(n) => Node::TraitItem(n), - OwnerNode::MacroDef(n) => Node::MacroDef(n), OwnerNode::Crate(n) => Node::Crate(n), } } @@ -3141,7 +3123,6 @@ pub enum Node<'hir> { Arm(&'hir Arm<'hir>), Block(&'hir Block<'hir>), Local(&'hir Local<'hir>), - MacroDef(&'hir MacroDef<'hir>), /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants /// with synthesized constructors. @@ -3178,7 +3159,6 @@ impl<'hir> Node<'hir> { | Node::ForeignItem(ForeignItem { ident, .. }) | Node::Field(FieldDef { ident, .. }) | Node::Variant(Variant { ident, .. }) - | Node::MacroDef(MacroDef { ident, .. }) | Node::Item(Item { ident, .. }) | Node::PathSegment(PathSegment { ident, .. }) => Some(*ident), Node::Lifetime(lt) => Some(lt.name.ident()), @@ -3239,8 +3219,7 @@ impl<'hir> Node<'hir> { Node::Item(Item { def_id, .. }) | Node::TraitItem(TraitItem { def_id, .. }) | Node::ImplItem(ImplItem { def_id, .. }) - | Node::ForeignItem(ForeignItem { def_id, .. }) - | Node::MacroDef(MacroDef { def_id, .. }) => Some(HirId::make_owner(*def_id)), + | Node::ForeignItem(ForeignItem { def_id, .. }) => Some(HirId::make_owner(*def_id)), Node::Field(FieldDef { hir_id, .. }) | Node::AnonConst(AnonConst { hir_id, .. }) | Node::Expr(Expr { hir_id, .. }) @@ -3300,7 +3279,6 @@ impl<'hir> Node<'hir> { Node::ForeignItem(i) => Some(OwnerNode::ForeignItem(i)), Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)), Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)), - Node::MacroDef(i) => Some(OwnerNode::MacroDef(i)), Node::Crate(i) => Some(OwnerNode::Crate(i)), _ => None, } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 89e7f8c1de6b..42e51f4bb48c 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -120,7 +120,6 @@ impl<'a> State<'a> { // printing. Node::Ctor(..) => panic!("cannot print isolated Ctor"), Node::Local(a) => self.print_local_decl(&a), - Node::MacroDef(_) => panic!("cannot print MacroDef"), Node::Crate(..) => panic!("cannot print Crate"), } } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 82c2f32b8241..62d0374fb52e 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -266,7 +266,6 @@ impl<'hir> Map<'hir> { ExprKind::Closure(.., Some(_)) => DefKind::Generator, _ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)), }, - Node::MacroDef(_) => DefKind::Macro(MacroKind::Bang), Node::GenericParam(param) => match param.kind { GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam, GenericParamKind::Type { .. } => DefKind::TyParam, @@ -636,8 +635,6 @@ impl<'hir> Map<'hir> { /// in a module, trait, or impl. pub fn get_parent_item(&self, hir_id: HirId) -> HirId { if let Some((hir_id, _node)) = self.parent_owner_iter(hir_id).next() { - // A MacroDef does not have children. - debug_assert!(!matches!(_node, OwnerNode::MacroDef(_))); hir_id } else { CRATE_HIR_ID @@ -765,13 +762,6 @@ impl<'hir> Map<'hir> { } } - pub fn expect_macro_def(&self, id: HirId) -> &'hir MacroDef<'hir> { - match self.tcx.hir_owner(id.expect_owner()) { - Some(Owner { node: OwnerNode::MacroDef(macro_def) }) => macro_def, - _ => bug!("expected macro def, found {}", self.node_to_string(id)), - } - } - pub fn expect_expr(&self, id: HirId) -> &'hir Expr<'hir> { match self.find(id) { Some(Node::Expr(expr)) => expr, @@ -791,7 +781,6 @@ impl<'hir> Map<'hir> { Node::GenericParam(param) => param.name.ident().name, Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name, Node::Ctor(..) => self.name(self.get_parent_item(id)), - Node::MacroDef(md) => md.ident.name, _ => return None, }) } @@ -858,7 +847,6 @@ impl<'hir> Map<'hir> { Node::Infer(i) => i.span, Node::Visibility(v) => bug!("unexpected Visibility {:?}", v), Node::Local(local) => local.span, - Node::MacroDef(macro_def) => macro_def.span, Node::Crate(item) => item.inner, }; Some(span) @@ -1109,7 +1097,6 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId) -> String { Some(Node::Lifetime(_)) => node_str("lifetime"), Some(Node::GenericParam(ref param)) => format!("generic_param {:?}{}", param, id_str), Some(Node::Visibility(ref vis)) => format!("visibility {:?}{}", vis, id_str), - Some(Node::MacroDef(_)) => format!("macro {}{}", path_str(), id_str), Some(Node::Crate(..)) => String::from("root_crate"), None => format!("unknown node{}", id_str), } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 7d22426609c1..23f43233b79c 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -310,8 +310,7 @@ impl<'tcx> ReachableContext<'tcx> { | Node::Ctor(..) | Node::Field(_) | Node::Ty(_) - | Node::Crate(_) - | Node::MacroDef(_) => {} + | Node::Crate(_) => {} _ => { bug!( "found unexpected node kind in worklist: {} ({:?})", From 1f7bce012d7df14e3e5d8e595fb6f557b677bd92 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:58:46 -0700 Subject: [PATCH 222/269] Teach tools that macros are now HIR items --- src/librustdoc/clean/mod.rs | 23 +---- src/librustdoc/doctest.rs | 28 +++--- src/librustdoc/doctree.rs | 12 +-- src/librustdoc/visit_ast.rs | 91 +++++++++---------- .../clippy/clippy_lints/src/missing_doc.rs | 2 +- .../clippy/clippy_lints/src/missing_inline.rs | 1 + .../clippy_lints/src/utils/inspector.rs | 7 ++ 7 files changed, 72 insertions(+), 92 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b6ff3890c584..640acffb114d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -91,7 +91,6 @@ impl Clean for doctree::Module<'_> { items.extend(self.foreigns.iter().map(|x| x.clean(cx))); items.extend(self.mods.iter().map(|x| x.clean(cx))); items.extend(self.items.iter().map(|x| x.clean(cx)).flatten()); - items.extend(self.macros.iter().map(|x| x.clean(cx))); // determine if we should display the inner contents or // the outer `mod` item for the source code. @@ -1861,6 +1860,10 @@ impl Clean> for (&hir::Item<'_>, Option) { ItemKind::Fn(ref sig, ref generics, body_id) => { clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } + ItemKind::Macro(ref macro_def) => MacroItem(Macro { + source: display_macro_source(cx, name, ¯o_def, def_id, &item.vis), + imported_from: None, + }), ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => { let items = item_ids .iter() @@ -2138,24 +2141,6 @@ impl Clean for (&hir::ForeignItem<'_>, Option) { } } -impl Clean for (&hir::MacroDef<'_>, Option) { - fn clean(&self, cx: &mut DocContext<'_>) -> Item { - let (item, renamed) = self; - let name = renamed.unwrap_or(item.ident.name); - let def_id = item.def_id.to_def_id(); - - Item::from_hir_id_and_parts( - item.hir_id(), - Some(name), - MacroItem(Macro { - source: display_macro_source(cx, name, &item.ast, def_id, &item.vis), - imported_from: None, - }), - cx, - ) - } -} - impl Clean for hir::TypeBinding<'_> { fn clean(&self, cx: &mut DocContext<'_>) -> TypeBinding { TypeBinding { name: self.ident.name, kind: self.kind.clean(cx) } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 083d82cb414d..bf14a17c0769 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1171,10 +1171,21 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> } fn visit_item(&mut self, item: &'hir hir::Item<'_>) { - let name = if let hir::ItemKind::Impl(impl_) = &item.kind { - rustc_hir_pretty::id_to_string(&self.map, impl_.self_ty.hir_id) - } else { - item.ident.to_string() + let name = match &item.kind { + hir::ItemKind::Macro(ref macro_def) => { + // FIXME(#88038): Non exported macros have historically not been tested, + // but we really ought to start testing them. + let def_id = item.def_id.to_def_id(); + if macro_def.macro_rules && !self.tcx.has_attr(def_id, sym::macro_export) { + intravisit::walk_item(self, item); + return; + } + item.ident.to_string() + } + hir::ItemKind::Impl(impl_) => { + rustc_hir_pretty::id_to_string(&self.map, impl_.self_ty.hir_id) + } + _ => item.ident.to_string(), }; self.visit_testable(name, item.hir_id(), item.span, |this| { @@ -1216,15 +1227,6 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> intravisit::walk_field_def(this, f); }); } - - fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef<'_>) { - self.visit_testable( - macro_def.ident.to_string(), - macro_def.hir_id(), - macro_def.span, - |_| (), - ); - } } #[cfg(test)] diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index eadac89f79ef..8f1e8f277c5f 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -5,6 +5,7 @@ use rustc_span::{self, Span, Symbol}; use rustc_hir as hir; +#[derive(Debug)] crate struct Module<'hir> { crate name: Symbol, crate where_inner: Span, @@ -13,20 +14,11 @@ crate struct Module<'hir> { // (item, renamed) crate items: Vec<(&'hir hir::Item<'hir>, Option)>, crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option)>, - crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option)>, } impl Module<'hir> { crate fn new(name: Symbol, id: hir::HirId, where_inner: Span) -> Module<'hir> { - Module { - name, - id, - where_inner, - mods: Vec::new(), - items: Vec::new(), - foreigns: Vec::new(), - macros: Vec::new(), - } + Module { name, id, where_inner, mods: Vec::new(), items: Vec::new(), foreigns: Vec::new() } } crate fn where_outer(&self, tcx: TyCtxt<'_>) -> Span { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index e28910355357..897b9140fc8b 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -9,7 +9,7 @@ use rustc_hir::Node; use rustc_middle::middle::privacy::AccessLevel; use rustc_middle::ty::TyCtxt; use rustc_span; -use rustc_span::def_id::LOCAL_CRATE; +use rustc_span::def_id::{CRATE_DEF_ID, LOCAL_CRATE}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Symbol}; @@ -79,49 +79,23 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { &krate.module(), self.cx.tcx.crate_name(LOCAL_CRATE), ); - // Attach the crate's exported macros to the top-level module. - // In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as - // well (_e.g._, `Copy`), these are wrongly bundled in there too, so we need to fix that by - // moving them back to their correct locations. - 'exported_macros: for def in krate.exported_macros() { - // The `def` of a macro in `exported_macros` should correspond to either: - // - a `#[macro_export] macro_rules!` macro, - // - a built-in `derive` (or attribute) macro such as the ones in `::core`, - // - a `pub macro`. - // Only the last two need to be fixed, thus: - if def.ast.macro_rules { - top_level_module.macros.push((def, None)); - continue 'exported_macros; - } - let tcx = self.cx.tcx; - // Note: this is not the same as `.parent_module()`. Indeed, the latter looks - // for the closest module _ancestor_, which is not necessarily a direct parent - // (since a direct parent isn't necessarily a module, c.f. #77828). - let macro_parent_def_id = { - use rustc_middle::ty::DefIdTree; - tcx.parent(def.def_id.to_def_id()).unwrap() - }; - let macro_parent_path = tcx.def_path(macro_parent_def_id); - // HACK: rustdoc has no way to lookup `doctree::Module`s by their HirId. Instead, - // lookup the module by its name, by looking at each path segment one at a time. - let mut cur_mod = &mut top_level_module; - for path_segment in macro_parent_path.data { - // Path segments may refer to a module (in which case they belong to the type - // namespace), which is _necessary_ for the macro to be accessible outside it - // (no "associated macros" as of yet). Else we bail with an outer `continue`. - let path_segment_ty_ns = match path_segment.data { - rustc_hir::definitions::DefPathData::TypeNs(symbol) => symbol, - _ => continue 'exported_macros, - }; - // Descend into the child module that matches this path segment (if any). - match cur_mod.mods.iter_mut().find(|child| child.name == path_segment_ty_ns) { - Some(child_mod) => cur_mod = &mut *child_mod, - None => continue 'exported_macros, + + // `#[macro_export] macro_rules!` items are reexported at the top level of the + // crate, regardless of where they're defined. We want to document the + // top level rexport of the macro, not its original definition, since + // the rexport defines the path that a user will actually see. Accordingly, + // we add the rexport as an item here, and then skip over the original + // definition in `visit_item()` below. + for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) { + if let Res::Def(DefKind::Macro(_), def_id) = export.res { + if let Some(local_def_id) = def_id.as_local() { + if self.cx.tcx.has_attr(def_id, sym::macro_export) { + let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id); + let item = self.cx.tcx.hir().expect_item(hir_id); + top_level_module.items.push((item, None)); + } } } - let cur_mod_def_id = tcx.hir().local_def_id(cur_mod.id).to_def_id(); - assert_eq!(cur_mod_def_id, macro_parent_def_id); - cur_mod.macros.push((def, None)); } self.cx.cache.exact_paths = self.exact_paths; top_level_module @@ -238,10 +212,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { self.inlining = prev; true } - Node::MacroDef(def) if !glob => { - om.macros.push((def, renamed)); - true - } _ => false, }; self.view_item_stack.remove(&res_hir_id); @@ -257,7 +227,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { debug!("visiting item {:?}", item); let name = renamed.unwrap_or(item.ident.name); - if item.vis.node.is_pub() { + let def_id = item.def_id.to_def_id(); + let is_pub = item.vis.node.is_pub() || self.cx.tcx.has_attr(def_id, sym::macro_export); + + if is_pub { self.store_path(item.def_id.to_def_id()); } @@ -269,7 +242,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } // If we're inlining, skip private items. - _ if self.inlining && !item.vis.node.is_pub() => {} + _ if self.inlining && !is_pub => {} hir::ItemKind::GlobalAsm(..) => {} hir::ItemKind::Use(_, hir::UseKind::ListStem) => {} hir::ItemKind::Use(ref path, kind) => { @@ -285,7 +258,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { // If there was a private module in the current path then don't bother inlining // anything as it will probably be stripped anyway. - if item.vis.node.is_pub() && self.inside_public_path { + if is_pub && self.inside_public_path { let please_inline = attrs.iter().any(|item| match item.meta_item_list() { Some(ref list) if item.has_name(sym::doc) => { list.iter().any(|i| i.has_name(sym::inline)) @@ -307,6 +280,26 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.items.push((item, renamed)) } + hir::ItemKind::Macro(ref macro_def) => { + // `#[macro_export] macro_rules!` items are handled seperately in `visit()`, + // above, since they need to be documented at the module top level. Accordingly, + // we only want to handle macros if one of three conditions holds: + // + // 1. This macro was defined by `macro`, and thus isn't covered by the case + // above. + // 2. This macro isn't marked with `#[macro_export]`, and thus isn't covered + // by the case above. + // 3. We're inlining, since a reexport where inlining has been requested + // should be inlined even if it is also documented at the top level. + + let def_id = item.def_id.to_def_id(); + let is_macro_2_0 = !macro_def.macro_rules; + let nonexported = !self.cx.tcx.has_attr(def_id, sym::macro_export); + + if is_macro_2_0 || nonexported || self.inlining { + om.items.push((item, renamed)); + } + } hir::ItemKind::Mod(ref m) => { om.mods.push(self.visit_mod_contents(&item.vis, item.hir_id(), m, name)); } diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index da86d28ee0b2..940eee7a7889 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -122,8 +122,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { }, hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) - | hir::ItemKind::Mod(..) | hir::ItemKind::Macro(..) + | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 977e6d966e87..667cdd830252 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -118,6 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { }, hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) + | hir::ItemKind::Macro(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) diff --git a/src/tools/clippy/clippy_lints/src/utils/inspector.rs b/src/tools/clippy/clippy_lints/src/utils/inspector.rs index 6bf216cec167..e97983a2e145 100644 --- a/src/tools/clippy/clippy_lints/src/utils/inspector.rs +++ b/src/tools/clippy/clippy_lints/src/utils/inspector.rs @@ -381,6 +381,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { let item_ty = cx.tcx.type_of(did); println!("function of type {:#?}", item_ty); }, + hir::ItemKind::Macro(ref macro_def) => { + if macro_def.macro_rules { + println!("macro introduced by `macro_rules!`"); + } else { + println!("macro introduced by `macro`"); + } + }, hir::ItemKind::Mod(..) => println!("module"), hir::ItemKind::ForeignMod { abi, .. } => println!("foreign module with abi: {}", abi), hir::ItemKind::GlobalAsm(asm) => println!("global asm: {:?}", asm), From b5a41418f84b4d54b9137fe9c83c50f015161063 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:09:25 -0700 Subject: [PATCH 223/269] Update tests --- .../rustdoc-ui/deny-missing-docs-macro.stderr | 2 +- .../macro-document-private-duplicate.rs | 23 +++++++++++++++++++ src/test/rustdoc/macro-document-private.rs | 19 +++++++++++++++ src/test/rustdoc/macro-indirect-use.rs | 16 +++++++++++++ src/test/ui/lint/lint-level-macro-def-mod.rs | 17 ++++++++++++++ src/test/ui/lint/lint-level-macro-def.rs | 17 ++++++++++++++ src/test/ui/lint/missing-doc-private-macro.rs | 4 ++-- .../ui/lint/missing-doc-private-macro.stderr | 4 ++-- src/test/ui/macros/macro-stability-rpass.rs | 3 ++- 9 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src/test/rustdoc/macro-document-private-duplicate.rs create mode 100644 src/test/rustdoc/macro-document-private.rs create mode 100644 src/test/rustdoc/macro-indirect-use.rs create mode 100644 src/test/ui/lint/lint-level-macro-def-mod.rs create mode 100644 src/test/ui/lint/lint-level-macro-def.rs diff --git a/src/test/rustdoc-ui/deny-missing-docs-macro.stderr b/src/test/rustdoc-ui/deny-missing-docs-macro.stderr index a564006e74f4..0867b08183e2 100644 --- a/src/test/rustdoc-ui/deny-missing-docs-macro.stderr +++ b/src/test/rustdoc-ui/deny-missing-docs-macro.stderr @@ -1,4 +1,4 @@ -error: missing documentation for macro +error: missing documentation for a macro --> $DIR/deny-missing-docs-macro.rs:6:1 | LL | macro_rules! foo { diff --git a/src/test/rustdoc/macro-document-private-duplicate.rs b/src/test/rustdoc/macro-document-private-duplicate.rs new file mode 100644 index 000000000000..460785ed979d --- /dev/null +++ b/src/test/rustdoc/macro-document-private-duplicate.rs @@ -0,0 +1,23 @@ +// FIXME: If two macros in the same module have the same name +// (yes, that's a thing), rustdoc lists both of them on the index page, +// but only documents the first one on the page for the macro. +// Fortunately, this can only happen in document private items mode, +// but it still isn't ideal beahvior. +// +// See https://github.com/rust-lang/rust/pull/88019#discussion_r693920453 +// +// compile-flags: --document-private-items + +// @has macro_document_private_duplicate/index.html 'Doc 1.' +// @has macro_document_private_duplicate/macro.a_macro.html 'Doc 1.' +/// Doc 1. +macro_rules! a_macro { + () => () +} + +// @has macro_document_private_duplicate/index.html 'Doc 2.' +// @!has macro_document_private_duplicate/macro.a_macro.html 'Doc 2.' +/// Doc 2. +macro_rules! a_macro { + () => () +} diff --git a/src/test/rustdoc/macro-document-private.rs b/src/test/rustdoc/macro-document-private.rs new file mode 100644 index 000000000000..d2496913ffcf --- /dev/null +++ b/src/test/rustdoc/macro-document-private.rs @@ -0,0 +1,19 @@ +// Checks that private macros are documented when `--document-private-items` +// is present. +// +// This is a regression test for issue #73754. +// +// compile-flags: --document-private-items + +#![feature(decl_macro)] + + +// @has macro_document_private/macro.some_macro.html +macro some_macro { + (a: tt) => {} +} + +// @has macro_document_private/macro.another_macro.html +macro_rules! another_macro { + (a: tt) => {} +} diff --git a/src/test/rustdoc/macro-indirect-use.rs b/src/test/rustdoc/macro-indirect-use.rs new file mode 100644 index 000000000000..b2d9336cffc8 --- /dev/null +++ b/src/test/rustdoc/macro-indirect-use.rs @@ -0,0 +1,16 @@ +// Checks that it is possible to make a macro public through a `pub use` of its +// parent module. +// +// This is a regression test for issue #87257. + +#![feature(decl_macro)] + +mod outer { + pub mod inner { + pub macro some_macro() {} + } +} + +// @has macro_indirect_use/inner/index.html +// @has macro_indirect_use/inner/macro.some_macro.html +pub use outer::inner; diff --git a/src/test/ui/lint/lint-level-macro-def-mod.rs b/src/test/ui/lint/lint-level-macro-def-mod.rs new file mode 100644 index 000000000000..79f7d1206df2 --- /dev/null +++ b/src/test/ui/lint/lint-level-macro-def-mod.rs @@ -0,0 +1,17 @@ +// This checks that exported macros lint as part of their module of origin, not +// the root module. +// +// check-pass + +//! Top level documentation +#![deny(missing_docs)] + +#[allow(missing_docs)] +mod module { + #[macro_export] + macro_rules! hello { + () => () + } +} + +fn main() {} diff --git a/src/test/ui/lint/lint-level-macro-def.rs b/src/test/ui/lint/lint-level-macro-def.rs new file mode 100644 index 000000000000..720f4b453abf --- /dev/null +++ b/src/test/ui/lint/lint-level-macro-def.rs @@ -0,0 +1,17 @@ +// Checks that you can set a lint level specficially for a macro definition. +// +// This is a regression test for issue #59306. +// +// check-pass + + +#[deny(missing_docs)] +mod module { + #[allow(missing_docs)] + #[macro_export] + macro_rules! hello { + () => () + } +} + +fn main() {} diff --git a/src/test/ui/lint/missing-doc-private-macro.rs b/src/test/ui/lint/missing-doc-private-macro.rs index 8d1d5c568803..0d4332ed08b2 100644 --- a/src/test/ui/lint/missing-doc-private-macro.rs +++ b/src/test/ui/lint/missing-doc-private-macro.rs @@ -29,13 +29,13 @@ mod submodule { #[macro_export] macro_rules! exported_to_top_level { - //~^ ERROR missing documentation for macro + //~^ ERROR missing documentation for a macro () => () } } pub macro top_level_pub_macro { - //~^ ERROR missing documentation for macro + //~^ ERROR missing documentation for a macro () => () } diff --git a/src/test/ui/lint/missing-doc-private-macro.stderr b/src/test/ui/lint/missing-doc-private-macro.stderr index a5d39faf4056..979b007d0ecd 100644 --- a/src/test/ui/lint/missing-doc-private-macro.stderr +++ b/src/test/ui/lint/missing-doc-private-macro.stderr @@ -1,4 +1,4 @@ -error: missing documentation for macro +error: missing documentation for a macro --> $DIR/missing-doc-private-macro.rs:31:5 | LL | macro_rules! exported_to_top_level { @@ -10,7 +10,7 @@ note: the lint level is defined here LL | #![deny(missing_docs)] | ^^^^^^^^^^^^ -error: missing documentation for macro +error: missing documentation for a macro --> $DIR/missing-doc-private-macro.rs:37:1 | LL | pub macro top_level_pub_macro { diff --git a/src/test/ui/macros/macro-stability-rpass.rs b/src/test/ui/macros/macro-stability-rpass.rs index a5f538ba6b36..2d02b95288df 100644 --- a/src/test/ui/macros/macro-stability-rpass.rs +++ b/src/test/ui/macros/macro-stability-rpass.rs @@ -1,7 +1,8 @@ // run-pass // aux-build:unstable-macros.rs -#![feature(unstable_macros, local_unstable)] +#![unstable(feature = "one_two_three_testing", issue = "none")] +#![feature(staged_api, unstable_macros, local_unstable)] #[macro_use] extern crate unstable_macros; From 1c3aedd23ab89b03bae389ec501845d03da63015 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 28 Aug 2021 11:43:21 +0200 Subject: [PATCH 224/269] Fix code blocks color in ayu theme --- src/librustdoc/html/static/css/themes/ayu.css | 2 +- src/test/rustdoc-gui/src/test_docs/lib.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index dab6d655c6a8..f9ddef4120bb 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -40,7 +40,7 @@ h4 { .code-header { color: #e6e1cf; } -pre > code { +.docblock pre > code, pre > code { color: #e6e1cf; } span code { diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index bed72ccb9f92..af4f28047fc0 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -25,6 +25,8 @@ use std::fmt; /// ```ignore (it's a test) /// Let's say I'm just some text will ya? /// ``` +/// +/// An inlined `code`! pub fn foo() {} /// Just a normal struct. From 261ee26ac53c5fc034587d2a3710142991da8249 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 28 Aug 2021 11:43:55 +0200 Subject: [PATCH 225/269] Add test for code blocks color --- src/test/rustdoc-gui/ayu-code-tag-colors.goml | 13 -------- src/test/rustdoc-gui/code-color.goml | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) delete mode 100644 src/test/rustdoc-gui/ayu-code-tag-colors.goml create mode 100644 src/test/rustdoc-gui/code-color.goml diff --git a/src/test/rustdoc-gui/ayu-code-tag-colors.goml b/src/test/rustdoc-gui/ayu-code-tag-colors.goml deleted file mode 100644 index 50af36fa3d64..000000000000 --- a/src/test/rustdoc-gui/ayu-code-tag-colors.goml +++ /dev/null @@ -1,13 +0,0 @@ -// The ayu theme has a different color for the "" tags in the doc blocks. We need to -// check that the rule isn't applied on other "" elements. -goto: file://|DOC_PATH|/test_docs/enum.AnEnum.html -// We need to show the text, otherwise the colors aren't "computed" by the web browser. -show-text: true -// We set the theme to ayu. -local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"} -// We reload to get the text appearing and the theme applied. -reload: - -assert-css: (".docblock code", {"color": "rgb(255, 180, 84)"}, ALL) -// It includes variants and the "titles" as well (for example: "impl RefUnwindSafe for AnEnum"). -assert-css: ("div:not(.docblock) > code", {"color": "rgb(197, 197, 197)"}, ALL) diff --git a/src/test/rustdoc-gui/code-color.goml b/src/test/rustdoc-gui/code-color.goml new file mode 100644 index 000000000000..2f95bfb6b177 --- /dev/null +++ b/src/test/rustdoc-gui/code-color.goml @@ -0,0 +1,30 @@ +// The ayu theme has a different color for the "" tags in the doc blocks. We need to +// check that the rule isn't applied on other "" elements. +// +// While we're at it, we also check it for the other themes. +goto: file://|DOC_PATH|/test_docs/fn.foo.html +// If the text isn't displayed, the browser doesn't compute color style correctly... +show-text: true +// Set the theme to dark. +local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(221, 221, 221)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(221, 221, 221)"}, ALL) + +// Set the theme to ayu. +local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(230, 225, 207)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(255, 180, 84)"}, ALL) + +// Set the theme to light. +local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(0, 0, 0)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(0, 0, 0)"}, ALL) From acf0a0c3940e3b1589e93f868c4708f4f8c4f4eb Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Sat, 28 Aug 2021 13:28:35 +0200 Subject: [PATCH 226/269] Use wrapping shift for unsigned types --- library/core/src/num/saturating.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 2e84f0657131..b2705ca0cc47 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -141,7 +141,7 @@ macro_rules! sh_impl_unsigned { #[inline] fn shl(self, other: $f) -> Saturating<$t> { - Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32)) + Saturating(self.0.wrapping_shl(other as u32)) } } forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f, @@ -162,7 +162,7 @@ macro_rules! sh_impl_unsigned { #[inline] fn shr(self, other: $f) -> Saturating<$t> { - Saturating(self.0.shr((other & self::shift_max::$t as $f) as u32)) + Saturating(self.0.wrapping_shr(other as u32)) } } forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f, From 977ae5ac2c5f0a53c8b0e979bd1b2450d66e1030 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Sat, 28 Aug 2021 13:29:19 +0200 Subject: [PATCH 227/269] Fix mentions of wrapping operations --- library/core/src/num/saturating.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index b2705ca0cc47..75d7f24307e0 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -6,7 +6,7 @@ use crate::ops::{BitXor, BitXorAssign, Div, DivAssign}; use crate::ops::{Mul, MulAssign, Neg, Not, Rem, RemAssign}; use crate::ops::{Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign}; -/// Provides intentionally-wrapped arithmetic on `T`. +/// Provides intentionally-saturating arithmetic on `T`. /// /// Operations like `+` on `u32` values are intended to never overflow, /// and in some debug configurations overflow is detected and results @@ -741,7 +741,7 @@ macro_rules! saturating_int_impl { #[doc = concat!("assert_eq!(Saturating(3", stringify!($t), ").pow(4), Saturating(81));")] /// ``` /// - /// Results that are too large are wrapped: + /// Results that are too large are saturated: /// /// ``` /// #![feature(saturating_int_impl)] From ce636f25e55493f42e7339cb533cb523879b62a5 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Sat, 28 Aug 2021 13:39:09 +0200 Subject: [PATCH 228/269] Unimpl Shl{Assign} for signed Saturating types until the correct impl is clear --- library/core/src/num/saturating.rs | 122 +++++++++++++++-------------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 75d7f24307e0..f6dd3603c491 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -81,30 +81,32 @@ impl fmt::UpperHex for Saturating { #[allow(unused_macros)] macro_rules! sh_impl_signed { ($t:ident, $f:ident) => { - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl Shl<$f> for Saturating<$t> { - type Output = Saturating<$t>; - - #[inline] - fn shl(self, other: $f) -> Saturating<$t> { - if other < 0 { - Saturating(self.0.shr((-other & self::shift_max::$t as $f) as u32)) - } else { - Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32)) - } - } - } - forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f, - #[unstable(feature = "saturating_int_impl", issue = "87920")] } - - #[unstable(feature = "saturating_int_impl", issue = "87920")] - impl ShlAssign<$f> for Saturating<$t> { - #[inline] - fn shl_assign(&mut self, other: $f) { - *self = *self << other; - } - } - forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } + // FIXME what is the correct implementation here? see discussion https://github.com/rust-lang/rust/pull/87921#discussion_r695870065 + // + // #[unstable(feature = "saturating_int_impl", issue = "87920")] + // impl Shl<$f> for Saturating<$t> { + // type Output = Saturating<$t>; + // + // #[inline] + // fn shl(self, other: $f) -> Saturating<$t> { + // if other < 0 { + // Saturating(self.0.shr((-other & self::shift_max::$t as $f) as u32)) + // } else { + // Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32)) + // } + // } + // } + // forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f, + // #[unstable(feature = "saturating_int_impl", issue = "87920")] } + // + // #[unstable(feature = "saturating_int_impl", issue = "87920")] + // impl ShlAssign<$f> for Saturating<$t> { + // #[inline] + // fn shl_assign(&mut self, other: $f) { + // *self = *self << other; + // } + // } + // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } #[unstable(feature = "saturating_int_impl", issue = "87920")] impl Shr<$f> for Saturating<$t> { @@ -935,38 +937,40 @@ macro_rules! saturating_int_impl_unsigned { saturating_int_impl_unsigned! { usize u8 u16 u32 u64 u128 } -mod shift_max { - #![allow(non_upper_case_globals)] - - #[cfg(target_pointer_width = "16")] - mod platform { - pub const usize: u32 = super::u16; - pub const isize: u32 = super::i16; - } - - #[cfg(target_pointer_width = "32")] - mod platform { - pub const usize: u32 = super::u32; - pub const isize: u32 = super::i32; - } - - #[cfg(target_pointer_width = "64")] - mod platform { - pub const usize: u32 = super::u64; - pub const isize: u32 = super::i64; - } - - pub const i8: u32 = (1 << 3) - 1; - pub const i16: u32 = (1 << 4) - 1; - pub const i32: u32 = (1 << 5) - 1; - pub const i64: u32 = (1 << 6) - 1; - pub const i128: u32 = (1 << 7) - 1; - pub use self::platform::isize; - - pub const u8: u32 = i8; - pub const u16: u32 = i16; - pub const u32: u32 = i32; - pub const u64: u32 = i64; - pub const u128: u32 = i128; - pub use self::platform::usize; -} +// Related to potential Shl and ShlAssign implementation +// +// mod shift_max { +// #![allow(non_upper_case_globals)] +// +// #[cfg(target_pointer_width = "16")] +// mod platform { +// pub const usize: u32 = super::u16; +// pub const isize: u32 = super::i16; +// } +// +// #[cfg(target_pointer_width = "32")] +// mod platform { +// pub const usize: u32 = super::u32; +// pub const isize: u32 = super::i32; +// } +// +// #[cfg(target_pointer_width = "64")] +// mod platform { +// pub const usize: u32 = super::u64; +// pub const isize: u32 = super::i64; +// } +// +// pub const i8: u32 = (1 << 3) - 1; +// pub const i16: u32 = (1 << 4) - 1; +// pub const i32: u32 = (1 << 5) - 1; +// pub const i64: u32 = (1 << 6) - 1; +// pub const i128: u32 = (1 << 7) - 1; +// pub use self::platform::isize; +// +// pub const u8: u32 = i8; +// pub const u16: u32 = i16; +// pub const u32: u32 = i32; +// pub const u64: u32 = i64; +// pub const u128: u32 = i128; +// pub use self::platform::usize; +// } From 20de556a26dd1fb10a3cbaf9bc02c27015edb406 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:41:03 -0400 Subject: [PATCH 229/269] Handle match with non axhaustive variants in closures --- compiler/rustc_typeck/src/expr_use_visitor.rs | 19 ++++++- .../auxiliary/match_non_exhaustive_lib.rs | 10 ++++ .../non-exhaustive-match.rs | 54 +++++++++++++++++++ .../non-exhaustive-match.stderr | 50 +++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index a8be207dbb36..3d483e322a85 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -15,7 +15,7 @@ use rustc_index::vec::Idx; use rustc_infer::infer::InferCtxt; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, adjustment, Ty, TyCtxt}; +use rustc_middle::ty::{self, adjustment, AdtKind, Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter; @@ -845,5 +845,20 @@ fn delegate_consume<'a, 'tcx>( } fn is_multivariant_adt(ty: Ty<'tcx>) -> bool { - if let ty::Adt(def, _) = ty.kind() { def.variants.len() > 1 } else { false } + if let ty::Adt(def, _) = ty.kind() { + // Note that if a non-exhaustive SingleVariant is defined in another crate, we need + // to assume that more cases will be added to the variant in the future. This mean + // that we should handle non-exhaustive SingleVariant the same way we would handle + // a MultiVariant. + // If the variant is not local it must be defined in another crate. + let is_non_exhaustive = match def.adt_kind() { + AdtKind::Struct | AdtKind::Union => { + def.non_enum_variant().is_field_list_non_exhaustive() + } + AdtKind::Enum => def.is_variant_list_non_exhaustive(), + }; + def.variants.len() > 1 || (!def.did.is_local() && is_non_exhaustive) + } else { + false + } } diff --git a/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs b/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs new file mode 100644 index 000000000000..4060c409355a --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs @@ -0,0 +1,10 @@ +#[non_exhaustive] +pub enum E1 {} + +#[non_exhaustive] +pub enum E2 { A, B } + +#[non_exhaustive] +pub enum E3 { C } + +pub enum E4 { D } diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs new file mode 100644 index 000000000000..318673ef847e --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs @@ -0,0 +1,54 @@ +// edition:2021 + +// aux-build:match_non_exhaustive_lib.rs + +/* The error message for non-exhaustive matches on non-local enums + * marked as non-exhaustive should mention the fact that the enum + * is marked as non-exhaustive (issue #85227). + */ + +// Ignore non_exhaustive in the same crate +#[non_exhaustive] +enum L1 { A, B } +enum L2 { C } + +extern crate match_non_exhaustive_lib; +use match_non_exhaustive_lib::{E1, E2, E3, E4}; + +fn foo() -> (L1, L2) {todo!()} +fn bar() -> (E1, E2, E3, E4) {todo!()} + +fn main() { + let (l1, l2) = foo(); + // No error for enums defined in this crate + let _a = || { match l1 { L1::A => (), L1::B => () } }; + // (except if the match is already non-exhaustive) + let _b = || { match l1 { L1::A => () } }; + //~^ ERROR: non-exhaustive patterns: `B` not covered [E0004] + + // l2 should not be captured as it is a non-exhaustive SingleVariant + // defined in this crate + let _c = || { match l2 { L2::C => (), _ => () } }; + let mut mut_l2 = l2; + _c(); + + // E1 is not visibly uninhabited from here + let (e1, e2, e3, e4) = bar(); + let _d = || { match e1 {} }; + //~^ ERROR: non-exhaustive patterns: type `E1` is non-empty [E0004] + let _e = || { match e2 { E2::A => (), E2::B => () } }; + //~^ ERROR: non-exhaustive patterns: `_` not covered [E0004] + let _f = || { match e2 { E2::A => (), E2::B => (), _ => () } }; + + // e3 should be captured as it is a non-exhaustive SingleVariant + // defined in another crate + let _g = || { match e3 { E3::C => (), _ => () } }; + let mut mut_e3 = e3; + //~^ ERROR: cannot move out of `e3` because it is borrowed + _g(); + + // e4 should not be captured as it is a SingleVariant + let _h = || { match e4 { E4::D => (), _ => () } }; + let mut mut_e4 = e4; + _h(); +} diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr new file mode 100644 index 000000000000..91ffe1a47f41 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr @@ -0,0 +1,50 @@ +error[E0004]: non-exhaustive patterns: `B` not covered + --> $DIR/non-exhaustive-match.rs:26:25 + | +LL | enum L1 { A, B } + | ---------------- + | | | + | | not covered + | `L1` defined here +... +LL | let _b = || { match l1 { L1::A => () } }; + | ^^ pattern `B` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `L1` + +error[E0004]: non-exhaustive patterns: type `E1` is non-empty + --> $DIR/non-exhaustive-match.rs:37:25 + | +LL | let _d = || { match e1 {} }; + | ^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `E1`, which is marked as non-exhaustive + +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/non-exhaustive-match.rs:39:25 + | +LL | let _e = || { match e2 { E2::A => (), E2::B => () } }; + | ^^ pattern `_` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `E2`, which is marked as non-exhaustive + +error[E0505]: cannot move out of `e3` because it is borrowed + --> $DIR/non-exhaustive-match.rs:46:22 + | +LL | let _g = || { match e3 { E3::C => (), _ => () } }; + | -- -- borrow occurs due to use in closure + | | + | borrow of `e3` occurs here +LL | let mut mut_e3 = e3; + | ^^ move out of `e3` occurs here +LL | +LL | _g(); + | -- borrow later used here + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0004, E0505. +For more information about an error, try `rustc --explain E0004`. From cd35e251ea086e8637562323acfe65216b2c8051 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:41:19 -0400 Subject: [PATCH 230/269] Add additional match test case --- .../2229_closure_analysis/match-edge-cases.rs | 34 +++++++++++++++++++ .../match-edge-cases.stderr | 17 ++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs index 914ebbe26a57..f5330b07445a 100644 --- a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs +++ b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs @@ -41,4 +41,38 @@ pub fn edge_case_char(event: char) { }; } +enum SingleVariant { + A +} + +struct TestStruct { + x: i32, + y: i32, + z: i32, +} + +fn edge_case_if() { + let sv = SingleVariant::A; + let condition = true; + // sv should not be captured as it is a SingleVariant + let _a = || { + match sv { + SingleVariant::A if condition => (), + _ => () + } + }; + let mut mut_sv = sv; + _a(); + + // ts should be captured + let ts = TestStruct { x: 1, y: 1, z: 1 }; + let _b = || { match ts { + TestStruct{ x: 1, .. } => (), + _ => () + }}; + let mut mut_ts = ts; + //~^ ERROR: cannot move out of `ts` because it is borrowed + _b(); +} + fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr new file mode 100644 index 000000000000..b9d2316206ec --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr @@ -0,0 +1,17 @@ +error[E0505]: cannot move out of `ts` because it is borrowed + --> $DIR/match-edge-cases.rs:32:22 + | +LL | let _b = || { match ts { + | -- -- borrow occurs due to use in closure + | | + | borrow of `ts` occurs here +... +LL | let mut mut_ts = ts; + | ^^ move out of `ts` occurs here +LL | +LL | _b(); + | -- borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. From f7b0e3b441af1def0845ce6c52273d7fcf4aa2a3 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:57:05 -0400 Subject: [PATCH 231/269] Create a specific match folder for match tests --- .../{ => match}/auxiliary/match_non_exhaustive_lib.rs | 0 .../ui/closures/2229_closure_analysis/{ => match}/issue-87097.rs | 0 .../closures/2229_closure_analysis/{ => match}/issue-87097.stderr | 0 .../ui/closures/2229_closure_analysis/{ => match}/issue-87426.rs | 0 .../2229_closure_analysis/{ => match}/match-edge-cases.rs | 0 .../2229_closure_analysis/{ => match}/match-edge-cases.stderr | 0 .../2229_closure_analysis/{ => match}/non-exhaustive-match.rs | 0 .../2229_closure_analysis/{ => match}/non-exhaustive-match.stderr | 0 .../{ => match}/pattern-matching-should-fail.rs | 0 .../{ => match}/pattern-matching-should-fail.stderr | 0 .../{ => match}/patterns-capture-analysis.rs | 0 .../{ => match}/patterns-capture-analysis.stderr | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/closures/2229_closure_analysis/{ => match}/auxiliary/match_non_exhaustive_lib.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87097.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87097.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87426.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/match-edge-cases.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/match-edge-cases.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/non-exhaustive-match.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/non-exhaustive-match.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/pattern-matching-should-fail.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/pattern-matching-should-fail.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/patterns-capture-analysis.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/patterns-capture-analysis.stderr (100%) diff --git a/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs b/src/test/ui/closures/2229_closure_analysis/match/auxiliary/match_non_exhaustive_lib.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs rename to src/test/ui/closures/2229_closure_analysis/match/auxiliary/match_non_exhaustive_lib.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87097.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87097.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-87097.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87097.stderr b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87097.stderr rename to src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87426.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-87426.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87426.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-87426.rs diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs b/src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs rename to src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.rs diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr b/src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr rename to src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs rename to src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.rs diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr rename to src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs b/src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs rename to src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr b/src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr rename to src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr From 33817d2881843bb84a01551813c522891ce0c5c6 Mon Sep 17 00:00:00 2001 From: Roxane Date: Sat, 28 Aug 2021 19:54:12 -0400 Subject: [PATCH 232/269] Move match tests in match folder --- .../{ => match}/issue-87988.rs | 0 .../{ => match}/issue-88331.rs | 0 .../{ => match}/issue-88331.stderr | 0 ...ch-edge-cases.rs => match-edge-cases_1.rs} | 34 ----------------- .../match/match-edge-cases_2.rs | 37 +++++++++++++++++++ ...cases.stderr => match-edge-cases_2.stderr} | 2 +- 6 files changed, 38 insertions(+), 35 deletions(-) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87988.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-88331.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-88331.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/match/{match-edge-cases.rs => match-edge-cases_1.rs} (53%) create mode 100644 src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.rs rename src/test/ui/closures/2229_closure_analysis/match/{match-edge-cases.stderr => match-edge-cases_2.stderr} (92%) diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87988.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-87988.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87988.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-87988.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-88331.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-88331.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-88331.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-88331.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-88331.stderr b/src/test/ui/closures/2229_closure_analysis/match/issue-88331.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-88331.stderr rename to src/test/ui/closures/2229_closure_analysis/match/issue-88331.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_1.rs similarity index 53% rename from src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_1.rs index f5330b07445a..914ebbe26a57 100644 --- a/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs +++ b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_1.rs @@ -41,38 +41,4 @@ pub fn edge_case_char(event: char) { }; } -enum SingleVariant { - A -} - -struct TestStruct { - x: i32, - y: i32, - z: i32, -} - -fn edge_case_if() { - let sv = SingleVariant::A; - let condition = true; - // sv should not be captured as it is a SingleVariant - let _a = || { - match sv { - SingleVariant::A if condition => (), - _ => () - } - }; - let mut mut_sv = sv; - _a(); - - // ts should be captured - let ts = TestStruct { x: 1, y: 1, z: 1 }; - let _b = || { match ts { - TestStruct{ x: 1, .. } => (), - _ => () - }}; - let mut mut_ts = ts; - //~^ ERROR: cannot move out of `ts` because it is borrowed - _b(); -} - fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.rs b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.rs new file mode 100644 index 000000000000..ae724f9c3cc6 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.rs @@ -0,0 +1,37 @@ +// edition:2021 + +enum SingleVariant { + A +} + +struct TestStruct { + x: i32, + y: i32, + z: i32, +} + +fn edge_case_if() { + let sv = SingleVariant::A; + let condition = true; + // sv should not be captured as it is a SingleVariant + let _a = || { + match sv { + SingleVariant::A if condition => (), + _ => () + } + }; + let mut mut_sv = sv; + _a(); + + // ts should be captured + let ts = TestStruct { x: 1, y: 1, z: 1 }; + let _b = || { match ts { + TestStruct{ x: 1, .. } => (), + _ => () + }}; + let mut mut_ts = ts; + //~^ ERROR: cannot move out of `ts` because it is borrowed + _b(); +} + +fn main() {} diff --git a/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.stderr similarity index 92% rename from src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.stderr index b9d2316206ec..1e42d73c62bd 100644 --- a/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr +++ b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases_2.stderr @@ -1,5 +1,5 @@ error[E0505]: cannot move out of `ts` because it is borrowed - --> $DIR/match-edge-cases.rs:32:22 + --> $DIR/match-edge-cases_2.rs:32:22 | LL | let _b = || { match ts { | -- -- borrow occurs due to use in closure From d562848268e02d6cf342598551bc663fcd4ff341 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 28 Aug 2021 17:28:39 -0700 Subject: [PATCH 233/269] fix(rustc_parse): incorrect span information for macro block expr Old error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l $f(;) | ^ ^ New error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l ($f); | ^ ^ --- compiler/rustc_parse/src/parser/expr.rs | 2 +- src/test/ui/parser/issue-87812.rs | 13 +++++++++++++ src/test/ui/parser/issue-87812.stderr | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/issue-87812.rs create mode 100644 src/test/ui/parser/issue-87812.stderr diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 326c8f81ffbf..bb7e44b18d26 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr { let block = block.clone(); $p.bump(); return Ok($p.mk_expr( - $p.token.span, + $p.prev_token.span, ExprKind::Block(block, None), AttrVec::new(), )); diff --git a/src/test/ui/parser/issue-87812.rs b/src/test/ui/parser/issue-87812.rs new file mode 100644 index 000000000000..0ba87b995443 --- /dev/null +++ b/src/test/ui/parser/issue-87812.rs @@ -0,0 +1,13 @@ +#![deny(break_with_label_and_loop)] + +macro_rules! foo { + ( $f:block ) => { + '_l: loop { + break '_l $f; //~ERROR + } + }; +} + +fn main() { + let x = foo!({ 3 }); +} diff --git a/src/test/ui/parser/issue-87812.stderr b/src/test/ui/parser/issue-87812.stderr new file mode 100644 index 000000000000..d61ee23a50b5 --- /dev/null +++ b/src/test/ui/parser/issue-87812.stderr @@ -0,0 +1,22 @@ +error: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression + --> $DIR/issue-87812.rs:6:13 + | +LL | break '_l $f; + | ^^^^^^^^^^^^ +... +LL | let x = foo!({ 3 }); + | ----------- in this macro invocation + | +note: the lint level is defined here + --> $DIR/issue-87812.rs:1:9 + | +LL | #![deny(break_with_label_and_loop)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) +help: wrap this expression in parentheses + | +LL | break '_l ($f); + | + + + +error: aborting due to previous error + From f7c0566b1209fc7c29d9621cb482acdf58dabd65 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 28 Aug 2021 17:35:39 -0700 Subject: [PATCH 234/269] fix(rustc_parse): incorrect span information for macro path expr Old error output: 3 | let _: usize = $f; | ----- ^ expected `usize`, found struct `Baz` | | | expected due to this New error output: 3 | let _: usize = $f; | ----- ^^ expected `usize`, found struct `Baz` | | | expected due to this --- compiler/rustc_parse/src/parser/expr.rs | 2 +- src/test/ui/parser/issue-87812-path.rs | 11 +++++++++++ src/test/ui/parser/issue-87812-path.stderr | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/issue-87812-path.rs create mode 100644 src/test/ui/parser/issue-87812-path.stderr diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index bb7e44b18d26..eea6c482cf18 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr { let path = path.clone(); $p.bump(); return Ok($p.mk_expr( - $p.token.span, + $p.prev_token.span, ExprKind::Path(None, path), AttrVec::new(), )); diff --git a/src/test/ui/parser/issue-87812-path.rs b/src/test/ui/parser/issue-87812-path.rs new file mode 100644 index 000000000000..b88780876db0 --- /dev/null +++ b/src/test/ui/parser/issue-87812-path.rs @@ -0,0 +1,11 @@ +macro_rules! foo { + ( $f:path ) => {{ + let _: usize = $f; //~ERROR + }}; +} + +struct Baz; + +fn main() { + foo!(Baz); +} diff --git a/src/test/ui/parser/issue-87812-path.stderr b/src/test/ui/parser/issue-87812-path.stderr new file mode 100644 index 000000000000..0c8e6fdd3076 --- /dev/null +++ b/src/test/ui/parser/issue-87812-path.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/issue-87812-path.rs:3:24 + | +LL | let _: usize = $f; + | ----- ^^ expected `usize`, found struct `Baz` + | | + | expected due to this +... +LL | foo!(Baz); + | ---------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 3ee6d0b6b6c4e00b062cbb0ecfc6070972ad0f20 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Sun, 29 Aug 2021 00:07:42 -0700 Subject: [PATCH 235/269] Fix: don't document private macros by default --- src/librustdoc/passes/stripper.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4305268c9aab..819d7d323fd7 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -40,6 +40,7 @@ impl<'a> DocFolder for Stripper<'a> { | clean::UnionItem(..) | clean::AssocConstItem(..) | clean::TraitAliasItem(..) + | clean::MacroItem(..) | clean::ForeignTypeItem => { if i.def_id.is_local() { if !self.access_levels.is_exported(i.def_id.expect_def_id()) { @@ -70,8 +71,8 @@ impl<'a> DocFolder for Stripper<'a> { clean::ImplItem(..) => {} - // tymethods/macros have no control over privacy - clean::MacroItem(..) | clean::TyMethodItem(..) => {} + // tymethods have no control over privacy + clean::TyMethodItem(..) => {} // Proc-macros are always public clean::ProcMacroItem(..) => {} From 59013cdebe665377e0d733ea3906c84216bd33db Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 21 Aug 2021 00:29:08 +0300 Subject: [PATCH 236/269] ast_lowering: Introduce `lower_span` for catching all spans entering HIR --- compiler/rustc_ast_lowering/src/asm.rs | 13 +- compiler/rustc_ast_lowering/src/expr.rs | 184 +++++++++++++++++------- compiler/rustc_ast_lowering/src/item.rs | 101 ++++++++----- compiler/rustc_ast_lowering/src/lib.rs | 167 ++++++++++++--------- compiler/rustc_ast_lowering/src/pat.rs | 12 +- compiler/rustc_ast_lowering/src/path.rs | 22 ++- 6 files changed, 330 insertions(+), 169 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index b9b27855a0b8..7165b3bcb9fc 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -128,7 +128,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } } }; - (op, *op_sp) + (op, self.lower_span(*op_sp)) }) .collect(); @@ -384,7 +384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { late: true, expr: None, }, - abi_span, + self.lower_span(abi_span), )); } } @@ -392,8 +392,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let operands = self.arena.alloc_from_iter(operands); let template = self.arena.alloc_from_iter(asm.template.iter().cloned()); - let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned()); - let line_spans = self.arena.alloc_slice(&asm.line_spans[..]); + let template_strs = self.arena.alloc_from_iter( + asm.template_strs + .iter() + .map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))), + ); + let line_spans = + self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span))); let hir_asm = hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans }; self.arena.alloc(hir_asm) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index bf7589e84adc..80633e141fc6 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -58,7 +58,12 @@ impl<'hir> LoweringContext<'_, 'hir> { None, )); let args = self.lower_exprs(args); - hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span) + hir::ExprKind::MethodCall( + hir_seg, + self.lower_span(seg.ident.span), + args, + self.lower_span(span), + ) } ExprKind::Binary(binop, ref lhs, ref rhs) => { let binop = self.lower_binop(binop); @@ -71,7 +76,9 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::Unary(op, ohs) } - ExprKind::Lit(ref l) => hir::ExprKind::Lit(respan(l.span, l.kind.clone())), + ExprKind::Lit(ref l) => { + hir::ExprKind::Lit(respan(self.lower_span(l.span), l.kind.clone())) + } ExprKind::Cast(ref expr, ref ty) => { let expr = self.lower_expr(expr); let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); @@ -86,9 +93,11 @@ impl<'hir> LoweringContext<'_, 'hir> { let ohs = self.lower_expr(ohs); hir::ExprKind::AddrOf(k, m, ohs) } - ExprKind::Let(ref pat, ref scrutinee, span) => { - hir::ExprKind::Let(self.lower_pat(pat), self.lower_expr(scrutinee), span) - } + ExprKind::Let(ref pat, ref scrutinee, span) => hir::ExprKind::Let( + self.lower_pat(pat), + self.lower_expr(scrutinee), + self.lower_span(span), + ), ExprKind::If(ref cond, ref then, ref else_opt) => { self.lower_expr_if(cond, then, else_opt.as_deref()) } @@ -99,7 +108,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| { hir::ExprKind::Loop( this.lower_block(body, false), - opt_label, + this.lower_label(opt_label), hir::LoopSource::Loop, DUMMY_SP, ) @@ -147,6 +156,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } ExprKind::Block(ref blk, opt_label) => { + let opt_label = self.lower_label(opt_label); hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label) } ExprKind::Assign(ref el, ref er, span) => { @@ -157,7 +167,9 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_expr(el), self.lower_expr(er), ), - ExprKind::Field(ref el, ident) => hir::ExprKind::Field(self.lower_expr(el), ident), + ExprKind::Field(ref el, ident) => { + hir::ExprKind::Field(self.lower_expr(el), self.lower_ident(ident)) + } ExprKind::Index(ref el, ref er) => { hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er)) } @@ -234,7 +246,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut ex = self.lower_expr_mut(ex); // Include parens in span, but only if it is a super-span. if e.span.contains(ex.span) { - ex.span = e.span; + ex.span = self.lower_span(e.span); } // Merge attributes into the inner expression. if !e.attrs.is_empty() { @@ -262,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let hir_id = self.lower_node_id(e.id); self.lower_attrs(hir_id, &e.attrs); - hir::Expr { hir_id, kind, span: e.span } + hir::Expr { hir_id, kind, span: self.lower_span(e.span) } }) } @@ -296,7 +308,7 @@ impl<'hir> LoweringContext<'_, 'hir> { BinOpKind::Ge => hir::BinOpKind::Ge, BinOpKind::Gt => hir::BinOpKind::Gt, }, - span: b.span, + span: self.lower_span(b.span), } } @@ -478,7 +490,13 @@ impl<'hir> LoweringContext<'_, 'hir> { }); let hir_id = self.next_id(); self.lower_attrs(hir_id, &arm.attrs); - hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span } + hir::Arm { + hir_id, + pat, + guard, + body: self.lower_expr(&arm.body), + span: self.lower_span(arm.span), + } } /// Lower an `async` construct to a generator that is then wrapped so it implements `Future`. @@ -501,12 +519,16 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> hir::ExprKind<'hir> { let output = match ret_ty { Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())), - None => hir::FnRetTy::DefaultReturn(span), + None => hir::FnRetTy::DefaultReturn(self.lower_span(span)), }; // Resume argument type. We let the compiler infer this to simplify the lowering. It is // fully constrained by `future::from_generator`. - let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Infer, span }; + let input_ty = hir::Ty { + hir_id: self.next_id(), + kind: hir::TyKind::Infer, + span: self.lower_span(span), + }; // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`. let decl = self.arena.alloc(hir::FnDecl { @@ -522,7 +544,12 @@ impl<'hir> LoweringContext<'_, 'hir> { Ident::with_dummy_span(sym::_task_context), hir::BindingAnnotation::Mutable, ); - let param = hir::Param { hir_id: self.next_id(), pat, ty_span: span, span }; + let param = hir::Param { + hir_id: self.next_id(), + pat, + ty_span: self.lower_span(span), + span: self.lower_span(span), + }; let params = arena_vec![self; param]; let body_id = self.lower_body(move |this| { @@ -540,11 +567,14 @@ impl<'hir> LoweringContext<'_, 'hir> { capture_clause, decl, body_id, - span, + self.lower_span(span), Some(hir::Movability::Static), ); - let generator = - hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span }; + let generator = hir::Expr { + hir_id: self.lower_node_id(closure_node_id), + kind: generator_kind, + span: self.lower_span(span), + }; // `future::from_generator`: let unstable_span = @@ -681,8 +711,11 @@ impl<'hir> LoweringContext<'_, 'hir> { if let Some(task_context_hid) = self.task_context { let lhs = self.expr_ident(span, task_context_ident, task_context_hid); - let assign = - self.expr(span, hir::ExprKind::Assign(lhs, yield_expr, span), AttrVec::new()); + let assign = self.expr( + span, + hir::ExprKind::Assign(lhs, yield_expr, self.lower_span(span)), + AttrVec::new(), + ); self.stmt_expr(span, assign) } else { // Use of `await` outside of an async context. Return `yield_expr` so that we can @@ -696,8 +729,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // loop { .. } let loop_expr = self.arena.alloc(hir::Expr { hir_id: loop_hir_id, - kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span), - span, + kind: hir::ExprKind::Loop( + loop_block, + None, + hir::LoopSource::Loop, + self.lower_span(span), + ), + span: self.lower_span(span), }); // mut pinned => loop { ... } @@ -735,7 +773,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // Lower outside new scope to preserve `is_in_loop_condition`. let fn_decl = self.lower_fn_decl(decl, None, false, None); - hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, generator_option) + hir::ExprKind::Closure( + capture_clause, + fn_decl, + body_id, + self.lower_span(fn_decl_span), + generator_option, + ) } fn generator_movability_for_fn( @@ -821,7 +865,13 @@ impl<'hir> LoweringContext<'_, 'hir> { // closure argument types. let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None); - hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, None) + hir::ExprKind::Closure( + capture_clause, + fn_decl, + body_id, + self.lower_span(fn_decl_span), + None, + ) } /// Destructure the LHS of complex assignments. @@ -853,7 +903,11 @@ impl<'hir> LoweringContext<'_, 'hir> { } } if is_ordinary(self, lhs) { - return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span); + return hir::ExprKind::Assign( + self.lower_expr(lhs), + self.lower_expr(rhs), + self.lower_span(eq_sign_span), + ); } if !self.sess.features_untracked().destructuring_assignment { feature_err( @@ -878,7 +932,7 @@ impl<'hir> LoweringContext<'_, 'hir> { whole_span, Some(rhs), pat, - hir::LocalSource::AssignDesugar(eq_sign_span), + hir::LocalSource::AssignDesugar(self.lower_span(eq_sign_span)), ); // `a = lhs1; b = lhs2;`. @@ -978,10 +1032,10 @@ impl<'hir> LoweringContext<'_, 'hir> { let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments); hir::PatField { hir_id: self.next_id(), - ident: f.ident, + ident: self.lower_ident(f.ident), pat, is_shorthand: f.is_shorthand, - span: f.span, + span: self.lower_span(f.span), } })); let qpath = self.lower_qpath( @@ -1033,10 +1087,11 @@ impl<'hir> LoweringContext<'_, 'hir> { _ => {} } // Treat all other cases as normal lvalue. - let ident = Ident::new(sym::lhs, lhs.span); + let ident = Ident::new(sym::lhs, self.lower_span(lhs.span)); let (pat, binding) = self.pat_ident_mut(lhs.span, ident); let ident = self.expr_ident(lhs.span, ident, binding); - let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span); + let assign = + hir::ExprKind::Assign(self.lower_expr(lhs), ident, self.lower_span(eq_sign_span)); let expr = self.expr(lhs.span, assign, ThinVec::new()); assignments.push(self.stmt_expr(lhs.span, expr)); pat @@ -1076,7 +1131,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> { let e1 = self.lower_expr_mut(e1); let e2 = self.lower_expr_mut(e2); - let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, span); + let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, self.lower_span(span)); let fn_expr = self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path), ThinVec::new())); hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2]) @@ -1104,12 +1159,21 @@ impl<'hir> LoweringContext<'_, 'hir> { let fields = self.arena.alloc_from_iter( e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| { let expr = self.lower_expr(&e); - let ident = Ident::new(Symbol::intern(s), e.span); + let ident = Ident::new(Symbol::intern(s), self.lower_span(e.span)); self.expr_field(ident, expr, e.span) }), ); - hir::ExprKind::Struct(self.arena.alloc(hir::QPath::LangItem(lang_item, span)), fields, None) + hir::ExprKind::Struct( + self.arena.alloc(hir::QPath::LangItem(lang_item, self.lower_span(span))), + fields, + None, + ) + } + + fn lower_label(&self, opt_label: Option::Y]; | ^ cannot perform const operation using `A` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr index 0d84dca5b809..bffdeb9a336a 100644 --- a/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr +++ b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr @@ -5,7 +5,7 @@ LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there. | ^^^^^^^^ cannot perform const operation using `A` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr b/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr index 8f6e56826fa1..5312a22c2289 100644 --- a/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr +++ b/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr @@ -5,7 +5,7 @@ LL | struct ArithArrayLen([u32; 0 + N]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/array-size-in-generic-struct-param.rs:19:15 @@ -14,7 +14,7 @@ LL | arr: [u8; CFG.arr_size], | ^^^ cannot perform const operation using `CFG` | = help: const parameters may only be used as standalone arguments, i.e. `CFG` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: `Config` is forbidden as the type of a const generic parameter --> $DIR/array-size-in-generic-struct-param.rs:17:21 diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs index 576276d902d6..ff686c5e767d 100644 --- a/src/test/ui/const-generics/auxiliary/generics_of_parent.rs +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // library portion of regression test for #87674 diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs index 0d03f56854a7..bc3c304cfd88 100644 --- a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // library portion of testing that `impl Trait<{ expr }>` doesnt diff --git a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs index d1bffae0d94c..f01bda84bf51 100644 --- a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs +++ b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // This tests that the `conservative_is_privately_uninhabited` fn doesn't cause diff --git a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs index 96dbac1fbef4..c48830f01a96 100644 --- a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs +++ b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // This tests that the `conservative_is_privately_uninhabited` fn doesn't cause diff --git a/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr b/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr index bfa4ba306862..6805b4a187e2 100644 --- a/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr +++ b/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; foo::()]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:14:23 @@ -14,7 +14,7 @@ LL | let _: [u8; bar::()]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:24:23 @@ -23,7 +23,7 @@ LL | let _ = [0; bar::()]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:29:24 @@ -32,7 +32,7 @@ LL | let _: Foo<{ foo::() }>; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:30:24 @@ -41,7 +41,7 @@ LL | let _: Foo<{ bar::() }>; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:35:27 @@ -50,7 +50,7 @@ LL | let _ = Foo::<{ foo::() }>; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:36:27 @@ -59,7 +59,7 @@ LL | let _ = Foo::<{ bar::() }>; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:15:23 diff --git a/src/test/ui/const-generics/const-argument-if-length.min.stderr b/src/test/ui/const-generics/const-argument-if-length.min.stderr index cdbbbf2a99b3..ef6bb69e9973 100644 --- a/src/test/ui/const-generics/const-argument-if-length.min.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.min.stderr @@ -5,7 +5,7 @@ LL | pad: [u8; is_zst::()], | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/const-argument-if-length.rs:16:12 diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr b/src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr deleted file mode 100644 index 9f3d94bbd8ab..000000000000 --- a/src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/simple.rs:7:53 - | -LL | fn test() -> [u8; N - 1] where [u8; N - 1]: Default { - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/simple.rs:7:35 - | -LL | fn test() -> [u8; N - 1] where [u8; N - 1]: Default { - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple.rs b/src/test/ui/const-generics/const_evaluatable_checked/simple.rs deleted file mode 100644 index 94ad71b6c1ac..000000000000 --- a/src/test/ui/const-generics/const_evaluatable_checked/simple.rs +++ /dev/null @@ -1,16 +0,0 @@ -// [full] run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![feature(const_evaluatable_checked)] -#![allow(incomplete_features)] - -fn test() -> [u8; N - 1] where [u8; N - 1]: Default { - //[min]~^ ERROR generic parameters - //[min]~| ERROR generic parameters - Default::default() -} - -fn main() { - let x = test::<33>(); - assert_eq!(x, [0; 32]); -} diff --git a/src/test/ui/const-generics/defaults/cec-concrete-default.rs b/src/test/ui/const-generics/defaults/cec-concrete-default.rs index c2a41cf2ad7d..80359476d6cc 100644 --- a/src/test/ui/const-generics/defaults/cec-concrete-default.rs +++ b/src/test/ui/const-generics/defaults/cec-concrete-default.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked, const_generics_defaults)] +#![feature(const_generics, generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs b/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs index 15822dfac1c5..eb4a0cec0a6a 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs +++ b/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked, const_generics_defaults)] +#![feature(const_generics, generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/defaults/cec-generic-default.rs b/src/test/ui/const-generics/defaults/cec-generic-default.rs index 76ff7c7801b0..02f21adb0d59 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default.rs +++ b/src/test/ui/const-generics/defaults/cec-generic-default.rs @@ -1,4 +1,4 @@ -#![feature(const_evaluatable_checked, const_generics, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics, const_generics_defaults)] #![allow(incomplete_features)] pub struct Foo; diff --git a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr index 44df2ac9f40f..25004faee6f9 100644 --- a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr +++ b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-generic-default-expr.rs:10:62 @@ -14,7 +14,7 @@ LL | struct Bar() }>(T); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs b/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs index afef748ff469..eb272e3c9b49 100644 --- a/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs +++ b/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // This tests that during error handling for the "trait not implemented" error diff --git a/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr b/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr index d7a3f04a8da8..dd4de9bc1b7a 100644 --- a/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr +++ b/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr @@ -5,7 +5,7 @@ LL | fn bar() -> [u32; foo(N)] { | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/generic-function-call-in-array-length.rs:11:13 @@ -14,7 +14,7 @@ LL | [0; foo(N)] | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr b/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr index cff5a62193c3..d80d38cf8b10 100644 --- a/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr +++ b/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr @@ -5,7 +5,7 @@ LL | fn foo(bar: [usize; A + B]) {} | ^ cannot perform const operation using `A` | = help: const parameters may only be used as standalone arguments, i.e. `A` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/generic-sum-in-array-length.rs:6:57 @@ -14,7 +14,7 @@ LL | fn foo(bar: [usize; A + B]) {} | ^ cannot perform const operation using `B` | = help: const parameters may only be used as standalone arguments, i.e. `B` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-1.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs similarity index 87% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-1.rs rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs index 744a1c4de48c..4d7c4e003d00 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_evaluatable_checked, const_generics)] +#![feature(generic_const_exprs, const_generics)] #![allow(incomplete_features)] struct Foo([u8; N as usize]) diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs similarity index 93% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.rs rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs index 543774649ed5..08b46c4c4a35 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs @@ -1,4 +1,4 @@ -#![feature(const_evaluatable_checked, const_generics)] +#![feature(generic_const_exprs, const_generics)] #![allow(incomplete_features)] struct Evaluatable {} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.stderr b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-2.stderr rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs similarity index 96% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.rs rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs index 2ca06bd1cb71..0cb5410ed26e 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.stderr b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-3.stderr rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-4.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs similarity index 94% rename from src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-4.rs rename to src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs index 0bb4fcff4d0b..66afe517835d 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast-4.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_evaluatable_checked, const_generics)] +#![feature(generic_const_exprs, const_generics)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs similarity index 90% rename from src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs rename to src/test/ui/const-generics/generic_const_exprs/associated-consts.rs index 533fe55b45be..967d1b0f2acb 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/associated-consts.rs +++ b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] pub trait BlockCipher { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/auxiliary/const_evaluatable_lib.rs b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs similarity index 76% rename from src/test/ui/const-generics/const_evaluatable_checked/auxiliary/const_evaluatable_lib.rs rename to src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs index 9745dfed4608..ce92f908e067 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/auxiliary/const_evaluatable_lib.rs +++ b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] pub fn test1() -> [u8; std::mem::size_of::() - 1] diff --git a/src/test/ui/const-generics/const_evaluatable_checked/closures.rs b/src/test/ui/const-generics/generic_const_exprs/closures.rs similarity index 71% rename from src/test/ui/const-generics/const_evaluatable_checked/closures.rs rename to src/test/ui/const-generics/generic_const_exprs/closures.rs index 32f43591e37b..c682fee4fab6 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/closures.rs +++ b/src/test/ui/const-generics/generic_const_exprs/closures.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn test() -> [u8; N + (|| 42)()] {} //~^ ERROR overly complex generic constant diff --git a/src/test/ui/const-generics/const_evaluatable_checked/closures.stderr b/src/test/ui/const-generics/generic_const_exprs/closures.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/closures.stderr rename to src/test/ui/const-generics/generic_const_exprs/closures.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs similarity index 87% rename from src/test/ui/const-generics/const_evaluatable_checked/cross_crate.rs rename to src/test/ui/const-generics/generic_const_exprs/cross_crate.rs index 53b237843871..a8388fc541ca 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs @@ -1,6 +1,6 @@ // aux-build:const_evaluatable_lib.rs // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs similarity index 87% rename from src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs rename to src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs index e3a4d9a96aa1..4e3aeec9c5de 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs @@ -1,5 +1,5 @@ // aux-build:const_evaluatable_lib.rs -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr rename to src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs similarity index 84% rename from src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs rename to src/test/ui/const-generics/generic_const_exprs/different-fn.rs index 26c4295cd9b1..0dcafc6a789c 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/different-fn.rs +++ b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/different-fn.stderr b/src/test/ui/const-generics/generic_const_exprs/different-fn.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/different-fn.stderr rename to src/test/ui/const-generics/generic_const_exprs/different-fn.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/division.rs b/src/test/ui/const-generics/generic_const_exprs/division.rs similarity index 76% rename from src/test/ui/const-generics/const_evaluatable_checked/division.rs rename to src/test/ui/const-generics/generic_const_exprs/division.rs index 71a5f2d34720..c10ed834f0f7 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/division.rs +++ b/src/test/ui/const-generics/generic_const_exprs/division.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn with_bound() where [u8; N / 2]: Sized { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/dont-eagerly-error-in-is-const-evaluatable.rs b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/dont-eagerly-error-in-is-const-evaluatable.rs rename to src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs index 92a410afcb1a..c99cfa6f52ff 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/dont-eagerly-error-in-is-const-evaluatable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs @@ -1,6 +1,6 @@ // run-pass #![feature(const_generics)] -#![feature(const_evaluatable_checked)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This test is a repro for #82279. It checks that we don't error diff --git a/src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs similarity index 78% rename from src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs rename to src/test/ui/const-generics/generic_const_exprs/drop_impl.rs index 41fb5d70afd6..45f63bad6fee 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/drop_impl.rs +++ b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs @@ -1,5 +1,5 @@ //check-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] struct Foo diff --git a/src/test/ui/const-generics/const_evaluatable_checked/elaborate-trait-pred.rs b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs similarity index 88% rename from src/test/ui/const-generics/const_evaluatable_checked/elaborate-trait-pred.rs rename to src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs index 4a4fd1e33117..3c6f01b6160e 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/elaborate-trait-pred.rs +++ b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs @@ -1,7 +1,7 @@ // run-pass // Test that we use the elaborated predicates from traits // to satisfy const evaluatable predicates. -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs rename to src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs index 9f457fbd346c..f9d78fd708c8 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -1,5 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] pub struct Const; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr rename to src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/evaluated-to-ambig.rs b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/evaluated-to-ambig.rs rename to src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs index 0f36ce383a84..8acb7aaf34ee 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/evaluated-to-ambig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs @@ -4,7 +4,7 @@ // only contain generic parameters. This is incorrect as trying to unify `N > 1` with `M > 1` // should fail. #![allow(incomplete_features)] -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] enum Assert {} trait IsTrue {} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.full.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr similarity index 82% rename from src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.full.stderr rename to src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr index d6a54ead1316..26dfcff5d3e3 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.full.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr @@ -1,5 +1,5 @@ error: constant expression depends on a generic parameter - --> $DIR/feature-gate-const_evaluatable_checked.rs:8:30 + --> $DIR/feature-gate-generic_const_exprs.rs:8:30 | LL | fn test() -> Arr where Arr: Default { | ^^^^^^ diff --git a/src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.min.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr similarity index 63% rename from src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr index 7de4bfcdd058..fccd6ea144b0 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr @@ -1,11 +1,11 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-const_evaluatable_checked.rs:5:33 + --> $DIR/feature-gate-generic_const_exprs.rs:5:33 | LL | type Arr = [u8; N - 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.rs b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.rs rename to src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs diff --git a/src/test/ui/const-generics/const_evaluatable_checked/fn_call.rs b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/fn_call.rs rename to src/test/ui/const-generics/generic_const_exprs/fn_call.rs index c182f5ef81b7..a1b2a52a5a12 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/fn_call.rs +++ b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] const fn test_me(a: usize, b: usize) -> usize { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs similarity index 77% rename from src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.rs rename to src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs index 8167d785d7a8..db097567a152 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn test() -> [u8; N - 1] { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.stderr b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/from-sig-fail.stderr rename to src/test/ui/const-generics/generic_const_exprs/from-sig-fail.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/from-sig.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs similarity index 79% rename from src/test/ui/const-generics/const_evaluatable_checked/from-sig.rs rename to src/test/ui/const-generics/generic_const_exprs/from-sig.rs index 5c05a5acfe96..d2e672bae4d8 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/from-sig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs similarity index 87% rename from src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs rename to src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs index 193a365f9b65..d3f140755f7a 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/impl-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs similarity index 90% rename from src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs rename to src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs index cad06ea4004a..4c8fc7a3554c 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs +++ b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] use std::{mem, ptr}; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/less_than.rs b/src/test/ui/const-generics/generic_const_exprs/less_than.rs similarity index 81% rename from src/test/ui/const-generics/const_evaluatable_checked/less_than.rs rename to src/test/ui/const-generics/generic_const_exprs/less_than.rs index 907ea255abb0..31fe9a53f034 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/less_than.rs +++ b/src/test/ui/const-generics/generic_const_exprs/less_than.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.rs b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs similarity index 88% rename from src/test/ui/const-generics/const_evaluatable_checked/let-bindings.rs rename to src/test/ui/const-generics/generic_const_exprs/let-bindings.rs index a6bb39208a42..ea5c95a74446 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.rs +++ b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // We do not yet want to support let-bindings in abstract consts, diff --git a/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr b/src/test/ui/const-generics/generic_const_exprs/let-bindings.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr rename to src/test/ui/const-generics/generic_const_exprs/let-bindings.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs similarity index 88% rename from src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs rename to src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs index 0fe84c1cd2a7..e70bdad90847 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn callee() -> usize diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs similarity index 92% rename from src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs rename to src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs index 4f588238e23f..aed3f476f1df 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested-abstract-consts-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_evaluatable_checked, const_generics)] +#![feature(generic_const_exprs, const_generics)] #![allow(incomplete_features)] struct Generic; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs rename to src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs index 4d0b87efc77c..a86918adfa76 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn zero_init() -> Substs1 diff --git a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs similarity index 91% rename from src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs rename to src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs index be8219a74466..72fd39b96f88 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/nested_uneval_unification-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features, unused_parens, unused_braces)] fn zero_init() -> Substs1<{ (N) }> diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-ret.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs similarity index 86% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-ret.rs rename to src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs index 5be4b41784c2..81a634a41738 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-ret.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-ret.stderr b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-ret.stderr rename to src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-where-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs similarity index 89% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-where-bounds.rs rename to src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs index 5fbd4a5fa2e6..22ff9f41276b 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-where-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] #![deny(where_clauses_object_safety)] diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-where-bounds.stderr b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-err-where-bounds.stderr rename to src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok-infer-err.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs similarity index 74% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok-infer-err.rs rename to src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs index 9a95908d59d0..e421c43dd948 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok-infer-err.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] trait Foo { @@ -16,7 +16,7 @@ fn use_dyn(v: &dyn Foo) where [u8; N + 1]: Sized { } fn main() { - // FIXME(const_evaluatable_checked): Improve the error message here. + // FIXME(generic_const_exprs): Improve the error message here. use_dyn(&()); //~^ ERROR type annotations needed } diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok-infer-err.stderr b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok-infer-err.stderr rename to src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs similarity index 86% rename from src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok.rs rename to src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs index ae78b7936a28..0ab8be80f373 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/object-safety-ok.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] trait Foo { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr rename to src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr similarity index 73% rename from src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr index 1aa66f9a8ba8..f6192bbe9caf 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr @@ -5,7 +5,7 @@ LL | type Arr = [u8; N - 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/simple_fail.rs:10:48 @@ -14,7 +14,7 @@ LL | fn test() -> Arr where [u8; N - 1]: Sized { | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs similarity index 90% rename from src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs rename to src/test/ui/const-generics/generic_const_exprs/simple_fail.rs index f08d2495b4dd..db2f94b7fce1 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs @@ -1,6 +1,6 @@ // revisions: full min #![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, feature(const_evaluatable_checked))] +#![cfg_attr(full, feature(generic_const_exprs))] #![allow(incomplete_features)] type Arr = [u8; N - 1]; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/subexprs_are_const_evalutable.rs b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs similarity index 86% rename from src/test/ui/const-generics/const_evaluatable_checked/subexprs_are_const_evalutable.rs rename to src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs index 11c0760cdfe0..71c594657e03 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/subexprs_are_const_evalutable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn make_array() -> [(); M + 1] { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs similarity index 83% rename from src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs rename to src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs index 5c768a61be25..abb9df162884 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs +++ b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs @@ -1,6 +1,6 @@ // check-pass // Test that we correctly substitute generic arguments for type aliases. -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] type Alias = [T; N + 1]; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/unop.rs b/src/test/ui/const-generics/generic_const_exprs/unop.rs similarity index 82% rename from src/test/ui/const-generics/const_evaluatable_checked/unop.rs rename to src/test/ui/const-generics/generic_const_exprs/unop.rs index 8e0768b1c959..e0e373b62f94 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/unop.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unop.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/const_evaluatable_checked/unused-complex-default-expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs similarity index 65% rename from src/test/ui/const-generics/const_evaluatable_checked/unused-complex-default-expr.rs rename to src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs index 21f14f58ab5a..c0da46d6d5f7 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/unused-complex-default-expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, const_evaluatable_checked, const_generics_defaults)] +#![feature(const_generics, generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; struct Bar(Foo); diff --git a/src/test/ui/const-generics/const_evaluatable_checked/unused_expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs similarity index 89% rename from src/test/ui/const-generics/const_evaluatable_checked/unused_expr.rs rename to src/test/ui/const-generics/generic_const_exprs/unused_expr.rs index 9c603c57a481..44b6530f22e8 100644 --- a/src/test/ui/const-generics/const_evaluatable_checked/unused_expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] fn add() -> [u8; { N + 1; 5 }] { diff --git a/src/test/ui/const-generics/const_evaluatable_checked/unused_expr.stderr b/src/test/ui/const-generics/generic_const_exprs/unused_expr.stderr similarity index 100% rename from src/test/ui/const-generics/const_evaluatable_checked/unused_expr.stderr rename to src/test/ui/const-generics/generic_const_exprs/unused_expr.stderr diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index 8701d54f5c96..f1ea52825e03 100644 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -5,7 +5,7 @@ LL | T: Trait<{std::intrinsics::type_name::()}> | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/intrinsics-type_name-as-const-argument.rs:9:22 diff --git a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr b/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr index 36a0a37ae9c3..6d6bca4255ac 100644 --- a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr +++ b/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr @@ -5,7 +5,7 @@ LL | pub struct MyArray([u8; COUNT + 1]); | ^^^^^ cannot perform const operation using `COUNT` | = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-61522-array-len-succ.rs:11:30 @@ -14,7 +14,7 @@ LL | fn inner(&self) -> &[u8; COUNT + 1] { | ^^^^^ cannot perform const operation using `COUNT` | = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-61747.min.stderr b/src/test/ui/const-generics/issues/issue-61747.min.stderr index b85533ccb46f..cc8c4db9c396 100644 --- a/src/test/ui/const-generics/issues/issue-61747.min.stderr +++ b/src/test/ui/const-generics/issues/issue-61747.min.stderr @@ -5,7 +5,7 @@ LL | fn successor() -> Const<{C + 1}> { | ^ cannot perform const operation using `C` | = help: const parameters may only be used as standalone arguments, i.e. `C` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-61935.min.stderr b/src/test/ui/const-generics/issues/issue-61935.min.stderr index 9382dca31530..a635d5e84a2e 100644 --- a/src/test/ui/const-generics/issues/issue-61935.min.stderr +++ b/src/test/ui/const-generics/issues/issue-61935.min.stderr @@ -5,7 +5,7 @@ LL | Self:FooImpl<{N==0}> | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-62220.min.stderr b/src/test/ui/const-generics/issues/issue-62220.min.stderr index 72311d030cf0..54a93733f322 100644 --- a/src/test/ui/const-generics/issues/issue-62220.min.stderr +++ b/src/test/ui/const-generics/issues/issue-62220.min.stderr @@ -5,7 +5,7 @@ LL | pub type TruncatedVector = Vector; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-62456.min.stderr b/src/test/ui/const-generics/issues/issue-62456.min.stderr index 920318fa0ac3..1e90d0b3f502 100644 --- a/src/test/ui/const-generics/issues/issue-62456.min.stderr +++ b/src/test/ui/const-generics/issues/issue-62456.min.stderr @@ -5,7 +5,7 @@ LL | let _ = [0u64; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-64494.min.stderr b/src/test/ui/const-generics/issues/issue-64494.min.stderr index 846db0c91b6e..8cb9981a534c 100644 --- a/src/test/ui/const-generics/issues/issue-64494.min.stderr +++ b/src/test/ui/const-generics/issues/issue-64494.min.stderr @@ -5,7 +5,7 @@ LL | impl MyTrait for T where Is<{T::VAL == 5}>: True {} | ^^^^^^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-64494.rs:18:38 @@ -14,7 +14,7 @@ LL | impl MyTrait for T where Is<{T::VAL == 6}>: True {} | ^^^^^^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0119]: conflicting implementations of trait `MyTrait` --> $DIR/issue-64494.rs:18:1 diff --git a/src/test/ui/const-generics/issues/issue-66205.min.stderr b/src/test/ui/const-generics/issues/issue-66205.min.stderr index b41793b62d2d..1dd4baaa5b57 100644 --- a/src/test/ui/const-generics/issues/issue-66205.min.stderr +++ b/src/test/ui/const-generics/issues/issue-66205.min.stderr @@ -5,7 +5,7 @@ LL | fact::<{ N - 1 }>(); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-67375.min.stderr b/src/test/ui/const-generics/issues/issue-67375.min.stderr index be81fa921297..c005e03f20c3 100644 --- a/src/test/ui/const-generics/issues/issue-67375.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67375.min.stderr @@ -5,7 +5,7 @@ LL | inner: [(); { [|_: &T| {}; 0].len() }], | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `T` is never used --> $DIR/issue-67375.rs:6:12 diff --git a/src/test/ui/const-generics/issues/issue-67945-1.min.stderr b/src/test/ui/const-generics/issues/issue-67945-1.min.stderr index 074d36c8ef3e..70e2518ca2af 100644 --- a/src/test/ui/const-generics/issues/issue-67945-1.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-1.min.stderr @@ -5,7 +5,7 @@ LL | let x: S = MaybeUninit::uninit(); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-67945-1.rs:16:45 @@ -14,7 +14,7 @@ LL | let b = &*(&x as *const _ as *const S); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-1.rs:10:12 diff --git a/src/test/ui/const-generics/issues/issue-67945-2.min.stderr b/src/test/ui/const-generics/issues/issue-67945-2.min.stderr index c06df79f8428..24476d4fac8f 100644 --- a/src/test/ui/const-generics/issues/issue-67945-2.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-2.min.stderr @@ -5,7 +5,7 @@ LL | let x: S = MaybeUninit::uninit(); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-67945-2.rs:14:45 @@ -14,7 +14,7 @@ LL | let b = &*(&x as *const _ as *const S); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-2.rs:8:12 diff --git a/src/test/ui/const-generics/issues/issue-68366.min.stderr b/src/test/ui/const-generics/issues/issue-68366.min.stderr index da4cbd3081f8..9519b23b4844 100644 --- a/src/test/ui/const-generics/issues/issue-68366.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68366.min.stderr @@ -5,7 +5,7 @@ LL | impl Collatz<{Some(N)}> {} | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:11:13 diff --git a/src/test/ui/const-generics/issues/issue-68977.min.stderr b/src/test/ui/const-generics/issues/issue-68977.min.stderr index 0b3d5b9a760f..78da8412cdfb 100644 --- a/src/test/ui/const-generics/issues/issue-68977.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68977.min.stderr @@ -5,7 +5,7 @@ LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>; | ^^^^^^^^ cannot perform const operation using `INT_BITS` | = help: const parameters may only be used as standalone arguments, i.e. `INT_BITS` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-68977.rs:28:28 @@ -14,7 +14,7 @@ LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>; | ^^^^^^^^^ cannot perform const operation using `FRAC_BITS` | = help: const parameters may only be used as standalone arguments, i.e. `FRAC_BITS` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-72787.min.stderr b/src/test/ui/const-generics/issues/issue-72787.min.stderr index 86d1da052aee..6314650e0d8b 100644 --- a/src/test/ui/const-generics/issues/issue-72787.min.stderr +++ b/src/test/ui/const-generics/issues/issue-72787.min.stderr @@ -5,7 +5,7 @@ LL | Condition<{ LHS <= RHS }>: True | ^^^ cannot perform const operation using `LHS` | = help: const parameters may only be used as standalone arguments, i.e. `LHS` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-72787.rs:10:24 @@ -14,7 +14,7 @@ LL | Condition<{ LHS <= RHS }>: True | ^^^ cannot perform const operation using `RHS` | = help: const parameters may only be used as standalone arguments, i.e. `RHS` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-72787.rs:25:25 @@ -23,7 +23,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `I` | = help: const parameters may only be used as standalone arguments, i.e. `I` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-72787.rs:25:36 @@ -32,7 +32,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `J` | = help: const parameters may only be used as standalone arguments, i.e. `J` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0283]: type annotations needed --> $DIR/issue-72787.rs:21:26 diff --git a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr b/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr index 6646be47b31e..70adabea5610 100644 --- a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr +++ b/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr @@ -5,7 +5,7 @@ LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-73899.rs b/src/test/ui/const-generics/issues/issue-73899.rs index 2a3a5ab2a3bb..ece8eb2c9ec9 100644 --- a/src/test/ui/const-generics/issues/issue-73899.rs +++ b/src/test/ui/const-generics/issues/issue-73899.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_evaluatable_checked)] +#![feature(generic_const_exprs)] #![feature(const_generics)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/issues/issue-76595.rs b/src/test/ui/const-generics/issues/issue-76595.rs index 2d7051c3a245..6e9af5bbb305 100644 --- a/src/test/ui/const-generics/issues/issue-76595.rs +++ b/src/test/ui/const-generics/issues/issue-76595.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] struct Bool; diff --git a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr index 32f70fa30072..efff3f42a3e5 100644 --- a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr +++ b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr @@ -5,7 +5,7 @@ LL | fn ty_param() -> [u8; std::mem::size_of::()] { | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-76701-ty-param-in-const.rs:11:42 @@ -14,7 +14,7 @@ LL | fn const_param() -> [u8; N + 1] { | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs b/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs index 8f02bfb937a5..b0bd3d8a2c93 100644 --- a/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs +++ b/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // This test is a minimized reproduction for #79518 where diff --git a/src/test/ui/const-generics/issues/issue-80062.stderr b/src/test/ui/const-generics/issues/issue-80062.stderr index aad8907bda2d..c714253b909d 100644 --- a/src/test/ui/const-generics/issues/issue-80062.stderr +++ b/src/test/ui/const-generics/issues/issue-80062.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; sof::()]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-80375.stderr b/src/test/ui/const-generics/issues/issue-80375.stderr index 9765a639a48d..f80029680ff9 100644 --- a/src/test/ui/const-generics/issues/issue-80375.stderr +++ b/src/test/ui/const-generics/issues/issue-80375.stderr @@ -5,7 +5,7 @@ LL | struct MyArray([u8; COUNT + 1]); | ^^^^^ cannot perform const operation using `COUNT` | = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs b/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs index a34d74b29e9f..1b9967a7b49b 100644 --- a/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs +++ b/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // This tests that the correct `param_env` is used so that diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/issues/issue-83765.rs index f34badc693e7..e2b859c0f859 100644 --- a/src/test/ui/const-generics/issues/issue-83765.rs +++ b/src/test/ui/const-generics/issues/issue-83765.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] trait TensorDimension { diff --git a/src/test/ui/const-generics/issues/issue-84408.rs b/src/test/ui/const-generics/issues/issue-84408.rs index e1ba850a4c1c..fb49cba2a34c 100644 --- a/src/test/ui/const-generics/issues/issue-84408.rs +++ b/src/test/ui/const-generics/issues/issue-84408.rs @@ -1,7 +1,7 @@ // Regression test for #84408. // check-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] trait Melon { diff --git a/src/test/ui/const-generics/issues/issue-85848.rs b/src/test/ui/const-generics/issues/issue-85848.rs index 478719869b2c..4d75fdb7d1df 100644 --- a/src/test/ui/const-generics/issues/issue-85848.rs +++ b/src/test/ui/const-generics/issues/issue-85848.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_fn_trait_bound, const_evaluatable_checked)] +#![feature(const_generics, const_fn_trait_bound, generic_const_exprs)] #![allow(incomplete_features)] trait _Contains { diff --git a/src/test/ui/const-generics/macro_rules-braces.min.stderr b/src/test/ui/const-generics/macro_rules-braces.min.stderr index c2e8c2c9c05a..f6d8020f3fbb 100644 --- a/src/test/ui/const-generics/macro_rules-braces.min.stderr +++ b/src/test/ui/const-generics/macro_rules-braces.min.stderr @@ -27,7 +27,7 @@ LL | let _: foo!({{ N }}); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/macro_rules-braces.rs:40:19 @@ -36,7 +36,7 @@ LL | let _: bar!({ N }); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/macro_rules-braces.rs:45:20 @@ -45,7 +45,7 @@ LL | let _: baz!({{ N }}); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/macro_rules-braces.rs:50:19 @@ -54,7 +54,7 @@ LL | let _: biz!({ N }); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 6 previous errors diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr index 176692448491..8d9246fe56f4 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr +++ b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr @@ -5,7 +5,7 @@ LL | struct Break0([u8; { N + 1 }]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:12:40 @@ -14,7 +14,7 @@ LL | struct Break1([u8; { { N } }]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:16:17 @@ -23,7 +23,7 @@ LL | let _: [u8; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:21:17 @@ -32,7 +32,7 @@ LL | let _ = [0; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:25:45 @@ -41,7 +41,7 @@ LL | struct BreakTy0(T, [u8; { size_of::<*mut T>() }]); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:28:47 @@ -50,7 +50,7 @@ LL | struct BreakTy1(T, [u8; { { size_of::<*mut T>() } }]); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:32:32 @@ -59,7 +59,7 @@ LL | let _: [u8; size_of::<*mut T>() + 1]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions warning: cannot use constants which depend on generic parameters in types --> $DIR/complex-expression.rs:37:17 diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr index 4fdfb5fbcb1a..cc114f702392 100644 --- a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr +++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr @@ -5,7 +5,7 @@ LL | fn t1() -> [u8; std::mem::size_of::()]; | ^^^^ cannot perform const operation using `Self` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic `Self` types are currently not permitted in anonymous constants --> $DIR/self-ty-in-const-1.rs:12:41 diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-5.rs b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs index e5d487d89b9f..961aeefd5505 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-5.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // `N + 1` also depends on `T` here even if it doesn't use it. diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr index 5fa6423306c5..1c5ff9175f37 100644 --- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr @@ -13,7 +13,7 @@ LL | struct Foo()]>(T, U); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0128]: generic parameters with a default cannot use forward declared identifiers --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21 diff --git a/src/test/ui/const-generics/parent_generics_of_encoding.rs b/src/test/ui/const-generics/parent_generics_of_encoding.rs index 31be8e7d111c..4d94b789a6c9 100644 --- a/src/test/ui/const-generics/parent_generics_of_encoding.rs +++ b/src/test/ui/const-generics/parent_generics_of_encoding.rs @@ -1,6 +1,6 @@ // aux-build:generics_of_parent.rs // check-pass -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] extern crate generics_of_parent; diff --git a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs index 988777b1c90c..5ac5161ca8f7 100644 --- a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs +++ b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs @@ -1,5 +1,5 @@ // aux-build:generics_of_parent_impl_trait.rs -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] extern crate generics_of_parent_impl_trait; diff --git a/src/test/ui/const-generics/wf-misc.min.stderr b/src/test/ui/const-generics/wf-misc.min.stderr index 9967a2218f6e..bc4c3f01ea9c 100644 --- a/src/test/ui/const-generics/wf-misc.min.stderr +++ b/src/test/ui/const-generics/wf-misc.min.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/wf-misc.rs:16:21 @@ -14,7 +14,7 @@ LL | let _: Const::<{N + 1}>; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const_evaluatable/needs_where_clause.rs b/src/test/ui/const_evaluatable/needs_where_clause.rs index 498a2ae75336..e8a625101d6b 100644 --- a/src/test/ui/const_evaluatable/needs_where_clause.rs +++ b/src/test/ui/const_evaluatable/needs_where_clause.rs @@ -1,5 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] const fn complex_maths(n : usize) -> usize { diff --git a/src/test/ui/const_evaluatable/no_where_clause.rs b/src/test/ui/const_evaluatable/no_where_clause.rs index 12f4a22038ef..6ae517af0d5b 100644 --- a/src/test/ui/const_evaluatable/no_where_clause.rs +++ b/src/test/ui/const_evaluatable/no_where_clause.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_evaluatable_checked)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features, unused)] const fn complex_maths(n : usize) -> usize { diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr index 4d57765e13f5..c7677f81b5fa 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr @@ -5,7 +5,7 @@ LL | Some(T) = std::mem::size_of::(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr index f89be630eeb3..c3735658aa7d 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr @@ -5,7 +5,7 @@ LL | Some = std::mem::size_of::(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `T` is never used --> $DIR/issue-70453-generics-in-discr-ice.rs:7:20 diff --git a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr index 8c97af263b28..ee0c3525b62d 100644 --- a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr @@ -5,7 +5,7 @@ LL | Some(T) = core::mem::size_of::<*mut T>(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/enum/issue-67945-1.stderr b/src/test/ui/enum/issue-67945-1.stderr index 227899e75350..21f005aa49f0 100644 --- a/src/test/ui/enum/issue-67945-1.stderr +++ b/src/test/ui/enum/issue-67945-1.stderr @@ -5,7 +5,7 @@ LL | let x: S = 0; | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-1.rs:1:10 diff --git a/src/test/ui/enum/issue-67945-2.stderr b/src/test/ui/enum/issue-67945-2.stderr index 5a90f00c346d..8996df8ae10e 100644 --- a/src/test/ui/enum/issue-67945-2.stderr +++ b/src/test/ui/enum/issue-67945-2.stderr @@ -5,7 +5,7 @@ LL | Var = 0: S, | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-2.rs:3:10 diff --git a/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr b/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr index 41a0a03ff668..7ea12e74e1ed 100644 --- a/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr +++ b/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr @@ -5,7 +5,7 @@ LL | struct Foo()]>(T, U); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/issues/issue-39559.stderr b/src/test/ui/issues/issue-39559.stderr index 91e31ca0bd8b..d71844eafde2 100644 --- a/src/test/ui/issues/issue-39559.stderr +++ b/src/test/ui/issues/issue-39559.stderr @@ -5,7 +5,7 @@ LL | entries: [T; D::dim()], | ^^^^^^ cannot perform const operation using `D` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr b/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr index 5c167ea08342..fdbde21a4108 100644 --- a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr +++ b/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; sof::()]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/legacy-const-generics-bad.stderr b/src/test/ui/legacy-const-generics-bad.stderr index 5a44b8e70655..d65e9f05904b 100644 --- a/src/test/ui/legacy-const-generics-bad.stderr +++ b/src/test/ui/legacy-const-generics-bad.stderr @@ -13,7 +13,7 @@ LL | legacy_const_generics::foo(0, N + 1, 2); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions + = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/mir/issue-80742.rs b/src/test/ui/mir/issue-80742.rs index c06d182fd567..cfd87bd9769b 100644 --- a/src/test/ui/mir/issue-80742.rs +++ b/src/test/ui/mir/issue-80742.rs @@ -3,7 +3,7 @@ // This test used to cause an ICE in rustc_mir::interpret::step::eval_rvalue_into_place #![allow(incomplete_features)] -#![feature(const_evaluatable_checked)] +#![feature(generic_const_exprs)] #![feature(const_generics)] use std::fmt::Debug; diff --git a/src/test/ui/specialization/issue-51892.rs b/src/test/ui/specialization/issue-51892.rs index 3cd0711ae42c..e82d40d33cd7 100644 --- a/src/test/ui/specialization/issue-51892.rs +++ b/src/test/ui/specialization/issue-51892.rs @@ -1,6 +1,6 @@ #![allow(incomplete_features)] #![feature(const_generics)] -#![feature(const_evaluatable_checked)] +#![feature(generic_const_exprs)] #![feature(specialization)] pub trait Trait { diff --git a/src/tools/clippy/tests/ui/doc/doc.rs b/src/tools/clippy/tests/ui/doc/doc.rs index 8afef6b23d47..8b20997fdf8d 100644 --- a/src/tools/clippy/tests/ui/doc/doc.rs +++ b/src/tools/clippy/tests/ui/doc/doc.rs @@ -2,7 +2,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, const_generics, const_evaluatable_checked, const_option)] +#![feature(custom_inner_attributes, const_generics, generic_const_exprs, const_option)] #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) @@ -203,7 +203,7 @@ fn issue_2343() {} /// __|_ _|__||_| fn pulldown_cmark_crash() {} -// issue #7033 - const_evaluatable_checked ICE +// issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { arr: [T; N.checked_next_power_of_two().unwrap()], From c0e853f274c42665373b719a5bd7b3f95afe10c2 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 25 Aug 2021 13:31:18 +0100 Subject: [PATCH 248/269] remove lazy_normalization_consts --- compiler/rustc_feature/src/active.rs | 3 --- compiler/rustc_hir/src/def.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- .../const-equate-pred.rs | 2 +- .../backcompat}/trait-resolution-breakage.rs | 0 .../backcompat}/unevaluated-consts.rs | 0 .../feature-gate-lazy_normalization_consts.rs | 10 ---------- ...ture-gate-lazy_normalization_consts.stderr | 11 ----------- .../lazy_normalization_consts/issue-47814.rs | 16 ---------------- .../lazy_normalization_consts/issue-57739.rs | 17 ----------------- .../issue-57739.stderr | 19 ------------------- .../lazy_normalization_consts/issue-73980.rs | 16 ---------------- .../issue-73980.stderr | 12 ------------ .../polymorphization/promoted-function-2.rs | 4 ++-- .../promoted-function-2.stderr | 8 ++++---- 16 files changed, 10 insertions(+), 114 deletions(-) rename src/test/ui/{lazy_normalization_consts => const-generics/backcompat}/trait-resolution-breakage.rs (100%) rename src/test/ui/{lazy_normalization_consts => const-generics/backcompat}/unevaluated-consts.rs (100%) delete mode 100644 src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.rs delete mode 100644 src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr delete mode 100644 src/test/ui/lazy_normalization_consts/issue-47814.rs delete mode 100644 src/test/ui/lazy_normalization_consts/issue-57739.rs delete mode 100644 src/test/ui/lazy_normalization_consts/issue-57739.stderr delete mode 100644 src/test/ui/lazy_normalization_consts/issue-73980.rs delete mode 100644 src/test/ui/lazy_normalization_consts/issue-73980.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 0e09a3fe93e8..222b17615e2d 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -545,9 +545,6 @@ declare_features! ( /// Allows capturing variables in scope using format_args! (active, format_args_capture, "1.46.0", Some(67984), None), - /// Lazily evaluate constants. This allows constants to depend on type parameters. - (incomplete, lazy_normalization_consts, "1.46.0", Some(72219), None), - /// Allows `if let` guard in match arms. (active, if_let_guard, "1.47.0", Some(51114), None), diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 3816888db106..853415c4173b 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -307,7 +307,7 @@ pub enum Res { /// We do however allow `Self` in repeat expression even if it is generic to not break code /// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint. /// - /// FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable. + /// FIXME(generic_const_exprs): Remove this bodge once that feature is stable. SelfTy( /// Optionally, the trait associated with this `Self` type. Option, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index c3c28d700815..6a97a6c43c11 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -678,7 +678,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { fn const_equate(&mut self, _a: &'tcx Const<'tcx>, _b: &'tcx Const<'tcx>) { span_bug!( self.cause.span(self.infcx.tcx), - "lazy_normalization_consts: unreachable `const_equate`" + "generic_const_exprs: unreachable `const_equate`" ); } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 89542a1ebabe..a9ee921399ab 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1421,7 +1421,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn lazy_normalization(self) -> bool { let features = self.features(); // Note: We do not enable lazy normalization for `min_const_generics`. - features.const_generics || features.lazy_normalization_consts + features.const_generics || features.generic_const_exprs } #[inline] diff --git a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs index f4c5dcc72259..3345c8a3fe9c 100644 --- a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs +++ b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs @@ -1,5 +1,5 @@ #![crate_name = "foo"] -#![feature(lazy_normalization_consts)] +#![feature(const_generics, generic_const_exprs)] #![allow(incomplete_features)] // Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate, diff --git a/src/test/ui/lazy_normalization_consts/trait-resolution-breakage.rs b/src/test/ui/const-generics/backcompat/trait-resolution-breakage.rs similarity index 100% rename from src/test/ui/lazy_normalization_consts/trait-resolution-breakage.rs rename to src/test/ui/const-generics/backcompat/trait-resolution-breakage.rs diff --git a/src/test/ui/lazy_normalization_consts/unevaluated-consts.rs b/src/test/ui/const-generics/backcompat/unevaluated-consts.rs similarity index 100% rename from src/test/ui/lazy_normalization_consts/unevaluated-consts.rs rename to src/test/ui/const-generics/backcompat/unevaluated-consts.rs diff --git a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.rs b/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.rs deleted file mode 100644 index 46ae9403c03c..000000000000 --- a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub const fn sof() -> usize { - 10 -} - -fn test() { - let _: [u8; sof::()]; - //~^ ERROR generic parameters may not be used in const operations -} - -fn main() {} diff --git a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr b/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr deleted file mode 100644 index fdbde21a4108..000000000000 --- a/src/test/ui/lazy_normalization_consts/feature-gate-lazy_normalization_consts.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/feature-gate-lazy_normalization_consts.rs:6:23 - | -LL | let _: [u8; sof::()]; - | ^ cannot perform const operation using `T` - | - = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/lazy_normalization_consts/issue-47814.rs b/src/test/ui/lazy_normalization_consts/issue-47814.rs deleted file mode 100644 index 1fd0c45841b0..000000000000 --- a/src/test/ui/lazy_normalization_consts/issue-47814.rs +++ /dev/null @@ -1,16 +0,0 @@ -// check-pass -#![feature(lazy_normalization_consts)] -#![allow(incomplete_features)] -pub struct ArpIPv4<'a> { - _s: &'a u8 -} - -impl<'a> ArpIPv4<'a> { - const LENGTH: usize = 20; - - pub fn to_buffer() -> [u8; Self::LENGTH] { - unimplemented!() - } -} - -fn main() {} diff --git a/src/test/ui/lazy_normalization_consts/issue-57739.rs b/src/test/ui/lazy_normalization_consts/issue-57739.rs deleted file mode 100644 index 4607f3e99b51..000000000000 --- a/src/test/ui/lazy_normalization_consts/issue-57739.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(lazy_normalization_consts)] -//~^ WARN the feature `lazy_normalization_consts` is incomplete -trait ArraySizeTrait { - const SIZE: usize = 0; -} - -impl ArraySizeTrait for T { - const SIZE: usize = 1; -} - -struct SomeArray { - array: [u8; T::SIZE], - //~^ ERROR constant expression depends on a generic parameter - phantom: std::marker::PhantomData, -} - -fn main() {} diff --git a/src/test/ui/lazy_normalization_consts/issue-57739.stderr b/src/test/ui/lazy_normalization_consts/issue-57739.stderr deleted file mode 100644 index ce0495dd8b0c..000000000000 --- a/src/test/ui/lazy_normalization_consts/issue-57739.stderr +++ /dev/null @@ -1,19 +0,0 @@ -warning: the feature `lazy_normalization_consts` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-57739.rs:1:12 - | -LL | #![feature(lazy_normalization_consts)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #72219 for more information - -error: constant expression depends on a generic parameter - --> $DIR/issue-57739.rs:12:12 - | -LL | array: [u8; T::SIZE], - | ^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error; 1 warning emitted - diff --git a/src/test/ui/lazy_normalization_consts/issue-73980.rs b/src/test/ui/lazy_normalization_consts/issue-73980.rs deleted file mode 100644 index e10040652c78..000000000000 --- a/src/test/ui/lazy_normalization_consts/issue-73980.rs +++ /dev/null @@ -1,16 +0,0 @@ -// check-pass -#![feature(lazy_normalization_consts)] -#![allow(incomplete_features)] - -pub struct X(P, Q); -pub struct L(T); - -impl L { - const S: usize = 1; -} - -impl X::S]> {} -//~^ WARN cannot use constants which depend on generic parameters -//~| WARN this was previously accepted by the compiler but is being phased out - -fn main() {} diff --git a/src/test/ui/lazy_normalization_consts/issue-73980.stderr b/src/test/ui/lazy_normalization_consts/issue-73980.stderr deleted file mode 100644 index 5ed1ca362f41..000000000000 --- a/src/test/ui/lazy_normalization_consts/issue-73980.stderr +++ /dev/null @@ -1,12 +0,0 @@ -warning: cannot use constants which depend on generic parameters in types - --> $DIR/issue-73980.rs:12:9 - | -LL | impl X::S]> {} - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(const_evaluatable_unchecked)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #76200 - -warning: 1 warning emitted - diff --git a/src/test/ui/polymorphization/promoted-function-2.rs b/src/test/ui/polymorphization/promoted-function-2.rs index 2831f861f556..d2d0f3368124 100644 --- a/src/test/ui/polymorphization/promoted-function-2.rs +++ b/src/test/ui/polymorphization/promoted-function-2.rs @@ -1,8 +1,8 @@ // build-fail // compile-flags:-Zpolymorphize=on #![crate_type = "lib"] -#![feature(lazy_normalization_consts, rustc_attrs)] -//~^ WARN the feature `lazy_normalization_consts` is incomplete +#![feature(generic_const_exprs, rustc_attrs)] +//~^ WARN the feature `generic_const_exprs` is incomplete #[rustc_polymorphize_error] fn test() { diff --git a/src/test/ui/polymorphization/promoted-function-2.stderr b/src/test/ui/polymorphization/promoted-function-2.stderr index 38d4808c48c0..4d7bab6aaa0c 100644 --- a/src/test/ui/polymorphization/promoted-function-2.stderr +++ b/src/test/ui/polymorphization/promoted-function-2.stderr @@ -1,11 +1,11 @@ -warning: the feature `lazy_normalization_consts` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/promoted-function-2.rs:4:12 | -LL | #![feature(lazy_normalization_consts, rustc_attrs)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![feature(generic_const_exprs, rustc_attrs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #72219 for more information + = note: see issue #76560 for more information error: item has unused generic parameters --> $DIR/promoted-function-2.rs:8:4 From 0c28e028b6f45f33447f24de7dd762b8599b7a4e Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 27 Aug 2021 18:04:57 +0200 Subject: [PATCH 249/269] `feature(const_generics)` -> `feature(const_param_types)` --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast_passes/src/feature_gate.rs | 1 - .../src/error_codes/E0671.md | 2 - .../src/error_codes/E0741.md | 4 +- .../src/error_codes/E0770.md | 1 - .../src/error_codes/E0771.md | 4 +- compiler/rustc_feature/src/accepted.rs | 2 +- compiler/rustc_feature/src/active.rs | 8 +- compiler/rustc_feature/src/removed.rs | 3 + compiler/rustc_infer/src/infer/combine.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 4 +- compiler/rustc_resolve/src/diagnostics.rs | 3 +- .../rustc_resolve/src/late/diagnostics.rs | 4 +- compiler/rustc_resolve/src/late/lifetimes.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 6 +- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_typeck/src/check/wfcheck.rs | 4 +- compiler/rustc_typeck/src/collect.rs | 2 +- src/test/debuginfo/function-names.rs | 4 +- .../const-generics/hash-tyvid-regression-1.rs | 2 +- .../hash-tyvid-regression-1.stderr | 35 - .../const-generics/hash-tyvid-regression-2.rs | 2 +- .../hash-tyvid-regression-2.stderr | 11 - .../const-generics/hash-tyvid-regression-3.rs | 2 +- .../hash-tyvid-regression-3.stderr | 12 - .../const-generics/hash-tyvid-regression-4.rs | 2 +- .../hash-tyvid-regression-4.stderr | 12 - .../incremental/const-generics/issue-61338.rs | 2 - .../incremental/const-generics/issue-61516.rs | 2 - .../incremental/const-generics/issue-62536.rs | 3 - .../incremental/const-generics/issue-64087.rs | 2 - .../incremental/const-generics/issue-65623.rs | 2 - .../incremental/const-generics/issue-68477.rs | 4 +- .../issue-77708-1.rs | 2 +- .../issue-77708-2.rs | 2 +- .../issue-77708-3.rs | 2 +- .../issue-82034.rs | 2 +- .../issue-85031-1.rs | 2 +- .../issue-85031-2.rs | 2 +- .../issue-85031-3.rs | 2 +- .../issue-86953.rs | 2 +- .../issue-88022.rs | 2 +- src/test/rustdoc/const-generics/add-impl.rs | 1 - .../const-generics/const-generic-slice.rs | 1 - src/test/rustdoc/const-generics/const-impl.rs | 2 +- ...able-checked.rs => generic_const_exprs.rs} | 2 +- .../const-equate-pred.rs | 2 +- .../array-slice-vec/match_arr_unknown_len.rs | 3 - .../match_arr_unknown_len.stderr | 13 +- ...ociated-const-type-parameter-arrays.stderr | 2 +- .../associated-item-duplicate-bounds.stderr | 2 +- src/test/ui/async-await/issues/issue-78654.rs | 2 +- src/test/ui/binding/const-param.min.stderr | 9 - src/test/ui/binding/const-param.rs | 3 - ...t-param.full.stderr => const-param.stderr} | 2 +- .../const-generics/apit-with-const-param.rs | 4 - .../const-generics/argument_order.full.stderr | 4 +- .../const-generics/argument_order.min.stderr | 8 +- src/test/ui/const-generics/argument_order.rs | 3 +- ...y-size-in-generic-struct-param.full.stderr | 18 - .../array-wrapper-struct-ctor.rs | 3 - .../associated-type-bound-fail.min.stderr | 17 - .../associated-type-bound-fail.rs | 4 - ...derr => associated-type-bound-fail.stderr} | 4 +- .../const-generics/associated-type-bound.rs | 4 - .../auxiliary/const_generic_lib.rs | 3 - .../ui/const-generics/auxiliary/crayte.rs | 2 - .../auxiliary/generics_of_parent.rs | 2 +- .../generics_of_parent_impl_trait.rs | 2 +- src/test/ui/const-generics/broken-mir-1.rs | 5 - src/test/ui/const-generics/broken-mir-2.rs | 5 - .../cannot-infer-type-for-const-param.rs | 3 - .../closing-args-token.min.stderr | 52 -- .../ui/const-generics/coerce_unsized_array.rs | 5 - .../concrete-const-as-fn-arg.rs | 4 - .../concrete-const-impl-method.rs | 4 - .../condition-in-trait-const-arg.rs | 2 +- ...ly_uninhabited_uses_correct_param_env-1.rs | 2 +- ...ly_uninhabited_uses_correct_param_env-2.rs | 2 +- .../const-arg-in-const-arg.min.stderr | 78 +-- .../const-generics/const-arg-in-const-arg.rs | 2 +- src/test/ui/const-generics/const-arg-in-fn.rs | 5 - .../const-arg-type-arg-misordered.full.stderr | 9 - .../const-arg-type-arg-misordered.rs | 4 - ...r => const-arg-type-arg-misordered.stderr} | 2 +- ...t-argument-cross-crate-mismatch.min.stderr | 15 - .../const-argument-cross-crate-mismatch.rs | 3 - ...onst-argument-cross-crate-mismatch.stderr} | 4 +- .../const-argument-if-length.full.stderr | 29 +- .../const-argument-if-length.min.stderr | 6 +- .../const-argument-if-length.rs | 4 +- .../const-argument-non-static-lifetime.rs | 2 +- .../const-expression-parameter.min.stderr | 13 - .../const-fn-with-const-param.rs | 4 - .../const-generic-array-wrapper.rs | 19 - .../const-generics/const-generic-type_name.rs | 4 - .../const-param-after-const-literal-arg.rs | 4 - ...onst-param-before-other-params.full.stderr | 4 +- ...const-param-before-other-params.min.stderr | 30 +- .../const-param-before-other-params.rs | 8 +- .../const-param-elided-lifetime.full.stderr | 10 +- .../const-param-elided-lifetime.min.stderr | 30 +- .../const-param-elided-lifetime.rs | 3 +- .../const-param-from-outer-fn.min.stderr | 13 - .../ui/const-generics/const-param-in-async.rs | 3 - .../ui/const-generics/const-param-in-trait.rs | 11 - ...ram-type-depends-on-const-param.min.stderr | 4 +- ...const-param-type-depends-on-const-param.rs | 2 +- .../const-param-type-depends-on-type-param.rs | 2 +- .../const-parameter-uppercase-lint.min.stderr | 14 - .../const-parameter-uppercase-lint.rs | 5 - ... => const-parameter-uppercase-lint.stderr} | 4 +- src/test/ui/const-generics/const-types.rs | 18 - src/test/ui/const-generics/core-types.rs | 2 +- .../ui/const-generics/cross_crate_complex.rs | 4 - .../defaults/auxiliary/const_defaulty.rs | 2 - .../complex-generic-default-expr.min.stderr | 4 +- .../defaults/complex-generic-default-expr.rs | 2 +- .../defaults/complex-unord-param.rs | 2 +- .../const-generics/defaults/const-default.rs | 4 - .../defaults/default-annotation.rs | 7 +- .../defaults/default-on-impl.min.stderr | 8 - .../defaults/default-on-impl.rs | 3 - ...mpl.full.stderr => default-on-impl.stderr} | 2 +- .../ui/const-generics/defaults/external.rs | 3 - ...lt.rs => generic-expr-default-concrete.rs} | 2 +- ...r => generic-expr-default-concrete.stderr} | 2 +- ... generic-expr-default-mismatched-types.rs} | 2 +- ...eric-expr-default-mismatched-types.stderr} | 2 +- ...ric-default.rs => generic-expr-default.rs} | 2 +- ...ult.stderr => generic-expr-default.stderr} | 4 +- .../defaults/intermixed-lifetime.full.stderr | 4 +- .../defaults/intermixed-lifetime.min.stderr | 4 +- .../defaults/intermixed-lifetime.rs | 2 - .../defaults/mismatch.full.stderr | 58 -- .../ui/const-generics/defaults/mismatch.rs | 3 - .../{mismatch.min.stderr => mismatch.stderr} | 10 +- .../defaults/needs-feature.min.stderr | 2 +- .../defaults/needs-feature.none.stderr | 8 - .../const-generics/defaults/needs-feature.rs | 6 +- .../defaults/simple-defaults.rs | 3 - .../defaults/type-default-const-param-name.rs | 3 - .../defaults/wrong-order.min.stderr | 8 - .../ui/const-generics/defaults/wrong-order.rs | 3 - ...g-order.full.stderr => wrong-order.stderr} | 2 +- .../derive-debug-array-wrapper.rs | 13 - .../const-generics/different_byref.min.stderr | 11 - src/test/ui/const-generics/different_byref.rs | 14 - ...err => different_generic_args.full.stderr} | 2 +- ...derr => different_generic_args.min.stderr} | 2 +- ...ef_simple.rs => different_generic_args.rs} | 4 +- .../different_generic_args_array.rs | 11 + ...rr => different_generic_args_array.stderr} | 6 +- .../dont-evaluate-array-len-on-err-1.rs | 2 +- src/test/ui/const-generics/dyn-supertraits.rs | 4 - .../{ => early}/closing-args-token.rs | 5 - .../closing-args-token.stderr} | 10 +- .../{ => early}/const-expression-parameter.rs | 5 - .../const-expression-parameter.stderr} | 2 +- .../{ => early}/const-param-from-outer-fn.rs | 5 - .../const-param-from-outer-fn.stderr} | 2 +- .../{ => early}/const-param-hygiene.rs | 4 - .../{ => early}/const-param-shadowing.rs | 0 .../{ => early}/const-param-shadowing.stderr | 0 .../invalid-const-arguments.rs} | 2 - .../invalid-const-arguments.stderr} | 10 +- .../{ => early}/macro_rules-braces.rs | 20 +- .../macro_rules-braces.stderr} | 20 +- .../exhaustive-value.full.stderr | 21 - .../ui/const-generics/exhaustive-value.rs | 4 - ...lue.min.stderr => exhaustive-value.stderr} | 4 +- .../ui/const-generics/fn-const-param-call.rs | 2 +- .../ui/const-generics/fn-const-param-infer.rs | 2 +- .../fn-taking-const-generic-array.rs | 17 - ...rbid-non-structural_match-types.min.stderr | 27 - .../forbid-non-structural_match-types.rs | 8 +- ... forbid-non-structural_match-types.stderr} | 2 +- .../foreign-item-const-parameter.min.stderr | 19 - .../foreign-item-const-parameter.rs | 5 - ...rr => foreign-item-const-parameter.stderr} | 4 +- ...-function-call-in-array-length.full.stderr | 10 - ...c-function-call-in-array-length.min.stderr | 20 - .../generic-function-call-in-array-length.rs | 15 - .../generic-param-mismatch.min.stderr | 14 - .../const-generics/generic-param-mismatch.rs | 4 - ...l.stderr => generic-param-mismatch.stderr} | 2 +- .../generic-sum-in-array-length.full.stderr | 10 - .../generic-sum-in-array-length.min.stderr | 20 - .../generic-sum-in-array-length.rs | 11 - .../abstract-const-as-cast-1.rs | 2 +- .../abstract-const-as-cast-2.rs | 2 +- .../abstract-const-as-cast-3.rs | 2 +- .../abstract-const-as-cast-4.rs | 2 +- ...y-size-in-generic-struct-param.full.stderr | 18 + ...ay-size-in-generic-struct-param.min.stderr | 6 +- .../array-size-in-generic-struct-param.rs | 6 +- .../generic_const_exprs}/associated-const.rs | 0 .../generic_const_exprs/associated-consts.rs | 2 +- .../auxiliary/const_evaluatable_lib.rs | 2 +- .../generic_const_exprs/closures.rs | 2 +- .../generic_const_exprs/cross_crate.rs | 2 +- .../cross_crate_predicate.rs | 2 +- .../generic_const_exprs/different-fn.rs | 2 +- .../generic_const_exprs/division.rs | 2 +- ...t-eagerly-error-in-is-const-evaluatable.rs | 1 - .../generic_const_exprs/drop_impl.rs | 2 +- .../elaborate-trait-pred.rs | 2 +- .../generic_const_exprs/eval-privacy.rs | 2 +- .../generic_const_exprs/evaluated-to-ambig.rs | 2 +- ...ature-gate-generic_const_exprs.full.stderr | 10 - .../feature-gate-generic_const_exprs.rs | 7 +- ...> feature-gate-generic_const_exprs.stderr} | 4 +- .../generic_const_exprs/fn_call.rs | 2 +- .../generic_const_exprs/from-sig-fail.rs | 2 +- .../generic_const_exprs/from-sig.rs | 2 +- .../generic_const_exprs}/function-call.rs | 0 .../generic_const_exprs}/function-call.stderr | 0 .../generic_const_exprs/impl-bounds.rs | 2 +- .../generic_const_exprs/infer-too-generic.rs | 2 +- .../issue-62504.full.stderr | 4 +- .../issue-62504.min.stderr | 0 .../issue-62504.rs | 7 +- .../issue-69654.rs | 2 +- .../issue-69654.stderr | 0 .../issue-72787.min.stderr | 16 +- .../issue-72787.rs | 12 +- ...ue-72819-generic-in-const-eval.full.stderr | 21 + ...sue-72819-generic-in-const-eval.min.stderr | 2 +- .../issue-72819-generic-in-const-eval.rs | 7 +- .../issue-73899.rs | 1 - .../issue-74634.rs | 5 +- .../issue-76595.rs | 2 +- .../issue-76595.stderr | 0 ...9518-default_trait_method_normalization.rs | 2 +- ...-default_trait_method_normalization.stderr | 0 .../issue-80561-incorrect-param-env.rs | 2 +- .../generic_const_exprs}/issue-80742.rs | 1 - .../generic_const_exprs}/issue-80742.stderr | 14 +- .../issue-83765.rs | 2 +- .../issue-83765.stderr | 0 .../issue-84408.rs | 2 +- .../issue-85848.rs | 2 +- .../issue-85848.stderr | 0 .../generic_const_exprs/less_than.rs | 2 +- .../generic_const_exprs/let-bindings.rs | 2 +- .../needs_where_clause.rs | 2 +- .../needs_where_clause.stderr | 0 .../nested-abstract-consts-1.rs | 2 +- .../nested-abstract-consts-2.rs | 2 +- .../nested_uneval_unification-1.rs | 2 +- .../nested_uneval_unification-2.rs | 2 +- .../generic_const_exprs}/no_where_clause.rs | 2 +- .../no_where_clause.stderr | 0 .../object-safety-err-ret.rs | 2 +- .../object-safety-err-where-bounds.rs | 2 +- .../object-safety-ok-infer-err.rs | 2 +- .../generic_const_exprs/object-safety-ok.rs | 2 +- .../simple_fail.min.stderr | 20 - .../generic_const_exprs/simple_fail.rs | 10 +- ...le_fail.full.stderr => simple_fail.stderr} | 4 +- .../subexprs_are_const_evalutable.rs | 2 +- .../ty-alias-substitution.rs | 2 +- .../generic_const_exprs/unop.rs | 2 +- .../unused-complex-default-expr.rs | 2 +- .../generic_const_exprs/unused_expr.rs | 2 +- .../impl-const-generic-struct.rs | 5 - ...impl-trait-with-const-arguments.min.stderr | 9 - .../impl-trait-with-const-arguments.rs | 5 - ...=> impl-trait-with-const-arguments.stderr} | 2 +- .../incorrect-number-of-const-args.min.stderr | 35 - .../incorrect-number-of-const-args.rs | 5 - ... => incorrect-number-of-const-args.stderr} | 8 +- .../infer/cannot-infer-const-args.min.stderr | 14 - .../infer/cannot-infer-const-args.rs | 5 - ....stderr => cannot-infer-const-args.stderr} | 2 +- .../infer/method-chain.min.stderr | 14 - .../ui/const-generics/infer/method-chain.rs | 5 - ...-chain.full.stderr => method-chain.stderr} | 2 +- .../infer/one-param-uninferred.min.stderr | 14 - .../infer/one-param-uninferred.rs | 6 - ...ull.stderr => one-param-uninferred.stderr} | 2 +- .../infer/uninferred-consts.min.stderr | 14 - .../const-generics/infer/uninferred-consts.rs | 4 - ...s.full.stderr => uninferred-consts.stderr} | 2 +- .../ui/const-generics/infer_arg_from_pat.rs | 4 - .../const-generics/infer_arr_len_from_pat.rs | 4 - ...ger-literal-generic-arg-in-where-clause.rs | 4 - ...cs-type_name-as-const-argument.full.stderr | 10 - ...ics-type_name-as-const-argument.min.stderr | 8 +- .../intrinsics-type_name-as-const-argument.rs | 4 +- src/test/ui/const-generics/invalid-enum.rs | 2 +- .../auxiliary/const_generic_issues_lib.rs | 6 +- .../issues/auxiliary/impl-const.rs | 3 +- .../issues/issue-56445-1.full.stderr | 13 +- .../issues/issue-56445-1.min.stderr | 2 +- .../ui/const-generics/issues/issue-56445-1.rs | 3 +- ...ssue-60818-struct-constructors.full.stderr | 11 - .../issues/issue-60818-struct-constructors.rs | 2 - .../issues/issue-61336-1.full.stderr | 11 - .../ui/const-generics/issues/issue-61336-1.rs | 3 - .../issues/issue-61336-2.full.stderr | 24 - .../ui/const-generics/issues/issue-61336-2.rs | 3 - ...1336-2.min.stderr => issue-61336-2.stderr} | 2 +- .../issues/issue-61336.full.stderr | 24 - .../ui/const-generics/issues/issue-61336.rs | 3 - ...ue-61336.min.stderr => issue-61336.stderr} | 2 +- .../issues/issue-61422.full.stderr | 11 - .../ui/const-generics/issues/issue-61422.rs | 3 - .../issues/issue-61432.full.stderr | 11 - .../ui/const-generics/issues/issue-61432.rs | 7 - .../issue-61522-array-len-succ.full.stderr | 18 - .../issue-61522-array-len-succ.min.stderr | 20 - .../issues/issue-61522-array-len-succ.rs | 18 - .../issues/issue-61747.full.stderr | 19 - .../issues/issue-61747.min.stderr | 11 - .../ui/const-generics/issues/issue-61747.rs | 16 - .../issues/issue-61935.full.stderr | 10 - .../issues/issue-61935.min.stderr | 11 - .../ui/const-generics/issues/issue-61935.rs | 25 - ...sue-62187-encountered-polymorphic-const.rs | 5 - .../issues/issue-62220.full.stderr | 10 - .../issues/issue-62220.min.stderr | 11 - .../ui/const-generics/issues/issue-62220.rs | 24 - .../issues/issue-62456.full.stderr | 10 - .../issues/issue-62456.min.stderr | 11 - .../ui/const-generics/issues/issue-62456.rs | 11 - .../issues/issue-62579-no-match.min.stderr | 11 - .../issues/issue-62579-no-match.rs | 16 - .../issues/issue-62878.full.stderr | 10 +- .../issues/issue-62878.min.stderr | 2 +- .../ui/const-generics/issues/issue-62878.rs | 3 +- .../issues/issue-63322-forbid-dyn.min.stderr | 2 +- .../issues/issue-63322-forbid-dyn.rs | 2 +- .../issues/issue-64494.full.stderr | 18 - .../issues/issue-64494.min.stderr | 30 - .../ui/const-generics/issues/issue-64494.rs | 23 - .../ui/const-generics/issues/issue-64519.rs | 4 - .../const-generics/issues/issue-64519.stderr | 11 - .../issues/issue-66205.full.stderr | 10 - .../issues/issue-66205.min.stderr | 11 - .../ui/const-generics/issues/issue-66205.rs | 12 - ...ssue-66596-impl-trait-for-str-const-arg.rs | 9 +- .../ui/const-generics/issues/issue-66906.rs | 3 - .../ui/const-generics/issues/issue-67185-1.rs | 3 - .../issues/issue-67185-2.min.stderr | 111 --- .../ui/const-generics/issues/issue-67185-2.rs | 4 - ...185-2.full.stderr => issue-67185-2.stderr} | 20 +- .../issues/issue-67375.full.stderr | 16 +- .../issues/issue-67375.min.stderr | 6 +- .../ui/const-generics/issues/issue-67375.rs | 6 +- .../issues/issue-67739.full.stderr | 4 +- .../ui/const-generics/issues/issue-67739.rs | 5 +- .../issues/issue-67945-1.full.stderr | 4 +- .../issues/issue-67945-1.min.stderr | 10 +- .../ui/const-generics/issues/issue-67945-1.rs | 7 +- .../issues/issue-67945-2.full.stderr | 36 +- .../issues/issue-67945-2.min.stderr | 32 +- .../ui/const-generics/issues/issue-67945-2.rs | 16 +- .../issues/issue-67945-3.full.stderr | 16 - .../issues/issue-67945-3.min.stderr | 8 - .../ui/const-generics/issues/issue-67945-3.rs | 16 - .../issue-68104-print-stack-overflow.rs | 6 +- .../issues/issue-68366.min.stderr | 2 +- .../ui/const-generics/issues/issue-68366.rs | 2 +- .../ui/const-generics/issues/issue-68596.rs | 4 - .../issues/issue-68615-adt.min.stderr | 2 +- .../const-generics/issues/issue-68615-adt.rs | 2 +- .../issues/issue-68615-array.min.stderr | 2 +- .../issues/issue-68615-array.rs | 2 +- .../issues/issue-68977.full.stderr | 10 - .../issues/issue-68977.min.stderr | 20 - .../ui/const-generics/issues/issue-68977.rs | 43 -- .../issues/issue-69654-run-pass.rs | 7 +- .../issues/issue-69654-run-pass.stderr | 15 - .../ui/const-generics/issues/issue-70125-1.rs | 3 - .../ui/const-generics/issues/issue-70125-2.rs | 4 - .../ui/const-generics/issues/issue-70167.rs | 4 - .../issues/issue-70180-1-stalled_on.rs | 4 - .../issues/issue-70180-2-stalled_on.rs | 4 - .../ui/const-generics/issues/issue-70225.rs | 2 - .../issues/issue-70273-assoc-fn.rs | 3 - .../issues/issue-71169.full.stderr | 10 +- .../issues/issue-71169.min.stderr | 2 +- .../ui/const-generics/issues/issue-71169.rs | 3 +- .../ui/const-generics/issues/issue-71202.rs | 6 +- .../const-generics/issues/issue-71202.stderr | 33 + .../ui/const-generics/issues/issue-71381.rs | 2 +- .../ui/const-generics/issues/issue-71382.rs | 2 +- .../ui/const-generics/issues/issue-71611.rs | 2 +- .../ui/const-generics/issues/issue-71986.rs | 4 - .../ui/const-generics/issues/issue-72352.rs | 2 +- .../issues/issue-72787.full.stderr | 42 -- ...ue-72819-generic-in-const-eval.full.stderr | 10 - .../ui/const-generics/issues/issue-73120.rs | 3 +- .../ui/const-generics/issues/issue-73260.rs | 9 +- .../const-generics/issues/issue-73260.stderr | 14 +- .../issues/issue-73491.min.stderr | 2 +- .../ui/const-generics/issues/issue-73491.rs | 2 +- .../issues/issue-73508.full.stderr | 8 - .../issues/issue-73508.min.stderr | 8 - .../ui/const-generics/issues/issue-73508.rs | 8 - .../issues/issue-74101.min.stderr | 4 +- .../ui/const-generics/issues/issue-74101.rs | 2 +- .../issues/issue-74255.min.stderr | 2 +- .../ui/const-generics/issues/issue-74255.rs | 2 +- .../const-generics/issues/issue-74634.stderr | 10 - .../ui/const-generics/issues/issue-74906.rs | 4 +- .../issues/issue-74950.min.stderr | 10 +- .../ui/const-generics/issues/issue-74950.rs | 2 +- .../issues/issue-75047.min.stderr | 2 +- .../ui/const-generics/issues/issue-75047.rs | 2 +- .../ui/const-generics/issues/issue-75299.rs | 3 - .../ui/const-generics/issues/issue-75763.rs | 6 +- .../issue-76701-ty-param-in-const.full.stderr | 18 - .../issues/issue-76701-ty-param-in-const.rs | 10 +- ...r => issue-76701-ty-param-in-const.stderr} | 8 +- .../const-generics/issues/issue-80062.stderr | 2 +- .../const-generics/issues/issue-80375.stderr | 2 +- .../ui/const-generics/issues/issue-87076.rs | 2 +- .../late-bound-vars/in_closure.rs | 2 +- .../const-generics/late-bound-vars/simple.rs | 2 +- .../macro_rules-braces.full.stderr | 72 -- .../complex-expression.stderr | 14 +- .../min_const_generics/complex-types.stderr | 14 +- .../min_const_generics/const_default_first.rs | 1 - .../const_default_first.stderr | 2 +- .../forbid-non-static-lifetimes.rs | 2 +- .../forbid-non-static-lifetimes.stderr | 8 +- .../self-ty-in-const-1.stderr | 2 +- .../static-reference-array-const-param.stderr | 2 +- .../type_and_const_defaults.rs | 3 +- .../mut-ref-const-param-array.rs | 21 - .../ui/const-generics/nested-type.min.stderr | 2 +- src/test/ui/const-generics/nested-type.rs | 2 +- .../const-generics/occurs-check/bind-param.rs | 2 +- .../occurs-check/unify-fixpoint.rs | 10 +- .../occurs-check/unify-fixpoint.stderr | 28 +- .../occurs-check/unify-n-nplusone.rs | 7 +- .../occurs-check/unify-n-nplusone.stderr | 11 +- .../occurs-check/unused-substs-1.rs | 2 +- .../occurs-check/unused-substs-2.rs | 2 +- .../occurs-check/unused-substs-3.rs | 2 +- .../occurs-check/unused-substs-4.rs | 2 +- .../occurs-check/unused-substs-5.rs | 2 +- ...ams-in-ct-in-ty-param-lazy-norm.min.stderr | 2 +- .../params-in-ct-in-ty-param-lazy-norm.rs | 2 +- .../parent_generics_of_encoding.rs | 2 +- .../parent_generics_of_encoding_impl_trait.rs | 2 +- .../raw-ptr-const-param-deref.rs | 2 +- .../ui/const-generics/raw-ptr-const-param.rs | 2 +- .../slice-const-param-mismatch.min.stderr | 4 +- .../slice-const-param-mismatch.rs | 2 +- .../slice-const-param.min.stderr | 20 - .../ui/const-generics/slice-const-param.rs | 9 +- .../std/const-generics-range.min.stderr | 12 +- .../std/const-generics-range.rs | 2 +- ...truct-with-invalid-const-param.full.stderr | 9 - ...struct-with-invalid-const-param.min.stderr | 9 - .../struct-with-invalid-const-param.rs | 4 - .../struct-with-invalid-const-param.stderr | 13 +- .../ui/const-generics/trait-const-args.rs | 4 - ...te-const-param-static-reference.min.stderr | 2 +- .../transmute-const-param-static-reference.rs | 2 +- .../transparent-maybeunit-array-wrapper.rs | 2 +- .../ui/const-generics/type-after-const-ok.rs | 2 +- .../auxiliary/type_dependent_lib.rs | 3 - .../type-dependent/const-arg-in-const-arg.rs | 2 +- .../type-dependent/issue-61936.rs | 3 - .../type-dependent/issue-63695.rs | 3 - .../type-dependent/issue-67144-1.rs | 4 - .../type-dependent/issue-67144-2.rs | 4 - .../type-dependent/issue-69816.rs | 4 - .../type-dependent/issue-70217.rs | 4 - .../type-dependent/issue-70507.rs | 3 - .../type-dependent/issue-70586.rs | 4 - .../type-dependent/issue-71348.min.stderr | 4 +- .../type-dependent/issue-71348.rs | 2 +- .../type-dependent/issue-71382.min.stderr | 8 - .../type-dependent/issue-71382.rs | 4 - ...e-71382.full.stderr => issue-71382.stderr} | 2 +- .../type-dependent/issue-71805.rs | 4 - .../type-dependent/issue-73730.rs | 4 - .../type-dependent/non-local.rs | 4 - .../ui/const-generics/type-dependent/qpath.rs | 4 - .../const-generics/type-dependent/simple.rs | 4 - .../type-dependent/type-mismatch.full.stderr | 2 +- .../type-dependent/type-mismatch.min.stderr | 2 +- .../type-dependent/type-mismatch.rs | 3 - .../ui/const-generics/type_of_anon_const.rs | 5 - .../types-mismatch-const-args.full.stderr | 4 +- .../types-mismatch-const-args.min.stderr | 4 +- .../types-mismatch-const-args.rs | 4 +- .../uninferred-consts-during-codegen-1.rs | 3 - .../uninferred-consts-during-codegen-2.rs | 3 - .../ui/const-generics/unknown_adt.min.stderr | 9 - src/test/ui/const-generics/unknown_adt.rs | 5 - ...own_adt.full.stderr => unknown_adt.stderr} | 2 +- .../ui/const-generics/unused-const-param.rs | 4 - .../ui/const-generics/unused_braces.fixed | 4 - .../const-generics/unused_braces.full.stderr | 14 - src/test/ui/const-generics/unused_braces.rs | 5 - ...braces.min.stderr => unused_braces.stderr} | 4 +- .../ui/const-generics/wf-misc.full.stderr | 18 - src/test/ui/const-generics/wf-misc.min.stderr | 20 - src/test/ui/const-generics/wf-misc.rs | 21 - src/test/ui/const-generics/where-clauses.rs | 4 - .../ui/consts/const-needs_drop-monomorphic.rs | 4 +- .../const-needs_drop-monomorphic.stderr | 4 +- ...issue-70453-generics-in-discr-ice-2.stderr | 2 +- .../issue-70453-generics-in-discr-ice.stderr | 2 +- .../issue-70453-polymorphic-ctfe.stderr | 2 +- src/test/ui/enum/issue-67945-1.stderr | 2 +- src/test/ui/enum/issue-67945-2.stderr | 2 +- src/test/ui/error-codes/E0730.rs | 3 - src/test/ui/error-codes/E0730.stderr | 13 +- src/test/ui/error-codes/E0771.rs | 4 +- src/test/ui/error-codes/E0771.stderr | 6 +- .../feature-gate-const_generics.rs | 5 - .../feature-gate-const_generics.stderr | 11 - .../feature-gate-const_param_types.rs | 2 + .../feature-gate-const_param_types.stderr} | 8 +- .../param-in-ct-in-ty-param-default.stderr | 2 +- src/test/ui/hygiene/generic_params.rs | 3 +- src/test/ui/hygiene/generic_params.stderr | 11 - .../hygiene/issue-61574-const-parameters.rs | 2 - .../issue-61574-const-parameters.stderr | 11 - .../impl-trait/issue-55872-1.full_tait.stderr | 57 -- .../multiple-lifetimes/inverse-bounds.stderr | 19 - src/test/ui/issues/issue-39559.stderr | 2 +- src/test/ui/issues/issue-59508-1.rs | 5 +- src/test/ui/issues/issue-59508-1.stderr | 13 +- src/test/ui/legacy-const-generics-bad.stderr | 2 +- .../ui/mir/issue-75053.in_bindings.stderr | 11 - src/test/ui/obsolete-in-place/bad.bad.stderr | 19 - .../const_parameters/closures.rs | 4 +- .../const_parameters/closures.stderr | 8 +- .../const_parameters/functions.rs | 4 +- .../const_parameters/functions.stderr | 8 +- src/test/ui/polymorphization/generators.rs | 4 +- .../ui/polymorphization/generators.stderr | 8 +- ...issue-65035-static-with-parent-generics.rs | 3 - ...e-65035-static-with-parent-generics.stderr | 21 +- .../disallowed-positions.rs | 2 - .../disallowed-positions.stderr | 224 +++--- ...rbitrary-self-types-not-object-safe.stderr | 23 - src/test/ui/simd/simd-array-trait.rs | 4 +- src/test/ui/simd/simd-array-trait.stderr | 4 +- src/test/ui/specialization/issue-51892.rs | 1 - src/test/ui/specialization/issue-51892.stderr | 2 +- src/test/ui/symbol-names/basic.stderr | 14 - .../const-generics-str-demangling.rs | 2 +- .../const-generics-structural-demangling.rs | 2 +- .../type-alias-impl-trait/assoc-type-const.rs | 2 - .../assoc-type-const.stderr | 11 - .../bounds-are-checked-2.full_tait.stderr | 23 - .../generic_duplicate_param_use.rs | 2 - .../generic_duplicate_param_use.stderr | 12 +- ...eric_duplicate_param_use5.full_tait.stderr | 48 -- ...eric_duplicate_param_use6.full_tait.stderr | 36 - ...eric_duplicate_param_use8.full_tait.stderr | 36 - ...eric_duplicate_param_use9.full_tait.stderr | 60 -- .../generic_nondefining_use.rs | 2 - .../generic_nondefining_use.stderr | 12 +- .../generic_underconstrained.full_tait.stderr | 32 - ...generic_underconstrained2.full_tait.stderr | 52 -- .../issue-52843.full_tait.stderr | 23 - ...eck_type_placeholder_item.full_tait.stderr | 647 ------------------ src/tools/clippy/tests/ui/crashes/ice-4775.rs | 3 - src/tools/clippy/tests/ui/crashes/ice-5223.rs | 3 - src/tools/clippy/tests/ui/doc/doc.rs | 2 +- .../ui/missing_const_for_fn/cant_be_const.rs | 3 +- .../ui/missing_const_for_fn/could_be_const.rs | 1 - .../could_be_const.stderr | 18 +- 574 files changed, 849 insertions(+), 4305 deletions(-) delete mode 100644 src/test/incremental/const-generics/hash-tyvid-regression-1.stderr delete mode 100644 src/test/incremental/const-generics/hash-tyvid-regression-2.stderr delete mode 100644 src/test/incremental/const-generics/hash-tyvid-regression-3.stderr delete mode 100644 src/test/incremental/const-generics/hash-tyvid-regression-4.stderr rename src/test/rustdoc/const-generics/{const-evaluatable-checked.rs => generic_const_exprs.rs} (86%) delete mode 100644 src/test/ui/binding/const-param.min.stderr rename src/test/ui/binding/{const-param.full.stderr => const-param.stderr} (87%) delete mode 100644 src/test/ui/const-generics/array-size-in-generic-struct-param.full.stderr delete mode 100644 src/test/ui/const-generics/associated-type-bound-fail.min.stderr rename src/test/ui/const-generics/{associated-type-bound-fail.full.stderr => associated-type-bound-fail.stderr} (84%) delete mode 100644 src/test/ui/const-generics/closing-args-token.min.stderr delete mode 100644 src/test/ui/const-generics/const-arg-type-arg-misordered.full.stderr rename src/test/ui/const-generics/{const-arg-type-arg-misordered.min.stderr => const-arg-type-arg-misordered.stderr} (88%) delete mode 100644 src/test/ui/const-generics/const-argument-cross-crate-mismatch.min.stderr rename src/test/ui/const-generics/{const-argument-cross-crate-mismatch.full.stderr => const-argument-cross-crate-mismatch.stderr} (85%) delete mode 100644 src/test/ui/const-generics/const-expression-parameter.min.stderr delete mode 100644 src/test/ui/const-generics/const-generic-array-wrapper.rs delete mode 100644 src/test/ui/const-generics/const-param-from-outer-fn.min.stderr delete mode 100644 src/test/ui/const-generics/const-param-in-trait.rs delete mode 100644 src/test/ui/const-generics/const-parameter-uppercase-lint.min.stderr rename src/test/ui/const-generics/{const-parameter-uppercase-lint.full.stderr => const-parameter-uppercase-lint.stderr} (78%) delete mode 100644 src/test/ui/const-generics/const-types.rs delete mode 100644 src/test/ui/const-generics/defaults/default-on-impl.min.stderr rename src/test/ui/const-generics/defaults/{default-on-impl.full.stderr => default-on-impl.stderr} (85%) rename src/test/ui/const-generics/defaults/{cec-concrete-default.rs => generic-expr-default-concrete.rs} (77%) rename src/test/ui/const-generics/defaults/{cec-concrete-default.stderr => generic-expr-default-concrete.stderr} (86%) rename src/test/ui/const-generics/defaults/{cec-generic-default-mismatched-types.rs => generic-expr-default-mismatched-types.rs} (82%) rename src/test/ui/const-generics/defaults/{cec-generic-default-mismatched-types.stderr => generic-expr-default-mismatched-types.stderr} (84%) rename src/test/ui/const-generics/defaults/{cec-generic-default.rs => generic-expr-default.rs} (89%) rename src/test/ui/const-generics/defaults/{cec-generic-default.stderr => generic-expr-default.stderr} (88%) delete mode 100644 src/test/ui/const-generics/defaults/mismatch.full.stderr rename src/test/ui/const-generics/defaults/{mismatch.min.stderr => mismatch.stderr} (94%) delete mode 100644 src/test/ui/const-generics/defaults/needs-feature.none.stderr delete mode 100644 src/test/ui/const-generics/defaults/wrong-order.min.stderr rename src/test/ui/const-generics/defaults/{wrong-order.full.stderr => wrong-order.stderr} (83%) delete mode 100644 src/test/ui/const-generics/derive-debug-array-wrapper.rs delete mode 100644 src/test/ui/const-generics/different_byref.min.stderr delete mode 100644 src/test/ui/const-generics/different_byref.rs rename src/test/ui/const-generics/{different_byref_simple.min.stderr => different_generic_args.full.stderr} (89%) rename src/test/ui/const-generics/{different_byref_simple.full.stderr => different_generic_args.min.stderr} (89%) rename src/test/ui/const-generics/{different_byref_simple.rs => different_generic_args.rs} (65%) create mode 100644 src/test/ui/const-generics/different_generic_args_array.rs rename src/test/ui/const-generics/{different_byref.full.stderr => different_generic_args_array.stderr} (64%) rename src/test/ui/const-generics/{ => early}/closing-args-token.rs (82%) rename src/test/ui/const-generics/{closing-args-token.full.stderr => early/closing-args-token.stderr} (84%) rename src/test/ui/const-generics/{ => early}/const-expression-parameter.rs (71%) rename src/test/ui/const-generics/{const-expression-parameter.full.stderr => early/const-expression-parameter.stderr} (87%) rename src/test/ui/const-generics/{ => early}/const-param-from-outer-fn.rs (54%) rename src/test/ui/const-generics/{const-param-from-outer-fn.full.stderr => early/const-param-from-outer-fn.stderr} (90%) rename src/test/ui/const-generics/{ => early}/const-param-hygiene.rs (71%) rename src/test/ui/const-generics/{ => early}/const-param-shadowing.rs (100%) rename src/test/ui/const-generics/{ => early}/const-param-shadowing.stderr (100%) rename src/test/ui/const-generics/{diagnostics.rs => early/invalid-const-arguments.rs} (86%) rename src/test/ui/const-generics/{diagnostics.stderr => early/invalid-const-arguments.stderr} (89%) rename src/test/ui/const-generics/{ => early}/macro_rules-braces.rs (67%) rename src/test/ui/const-generics/{macro_rules-braces.min.stderr => early/macro_rules-braces.stderr} (68%) delete mode 100644 src/test/ui/const-generics/exhaustive-value.full.stderr rename src/test/ui/const-generics/{exhaustive-value.min.stderr => exhaustive-value.stderr} (88%) delete mode 100644 src/test/ui/const-generics/fn-taking-const-generic-array.rs delete mode 100644 src/test/ui/const-generics/forbid-non-structural_match-types.min.stderr rename src/test/ui/const-generics/{forbid-non-structural_match-types.full.stderr => forbid-non-structural_match-types.stderr} (85%) delete mode 100644 src/test/ui/const-generics/foreign-item-const-parameter.min.stderr rename src/test/ui/const-generics/{foreign-item-const-parameter.full.stderr => foreign-item-const-parameter.stderr} (86%) delete mode 100644 src/test/ui/const-generics/generic-function-call-in-array-length.full.stderr delete mode 100644 src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr delete mode 100644 src/test/ui/const-generics/generic-function-call-in-array-length.rs delete mode 100644 src/test/ui/const-generics/generic-param-mismatch.min.stderr rename src/test/ui/const-generics/{generic-param-mismatch.full.stderr => generic-param-mismatch.stderr} (91%) delete mode 100644 src/test/ui/const-generics/generic-sum-in-array-length.full.stderr delete mode 100644 src/test/ui/const-generics/generic-sum-in-array-length.min.stderr delete mode 100644 src/test/ui/const-generics/generic-sum-in-array-length.rs create mode 100644 src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr rename src/test/ui/const-generics/{ => generic_const_exprs}/array-size-in-generic-struct-param.min.stderr (80%) rename src/test/ui/const-generics/{ => generic_const_exprs}/array-size-in-generic-struct-param.rs (78%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/associated-const.rs (100%) delete mode 100644 src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr rename src/test/ui/const-generics/generic_const_exprs/{feature-gate-generic_const_exprs.min.stderr => feature-gate-generic_const_exprs.stderr} (64%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/function-call.rs (100%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/function-call.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-62504.full.stderr (79%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-62504.min.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-62504.rs (66%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-69654.rs (90%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-69654.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-72787.min.stderr (77%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-72787.rs (63%) create mode 100644 src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-72819-generic-in-const-eval.min.stderr (75%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-72819-generic-in-const-eval.rs (66%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-73899.rs (93%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-74634.rs (83%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-76595.rs (85%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-76595.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-79518-default_trait_method_normalization.rs (91%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-79518-default_trait_method_normalization.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-80561-incorrect-param-env.rs (89%) rename src/test/ui/{mir => const-generics/generic_const_exprs}/issue-80742.rs (95%) rename src/test/ui/{mir => const-generics/generic_const_exprs}/issue-80742.stderr (91%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-83765.rs (94%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-83765.stderr (100%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-84408.rs (93%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-85848.rs (90%) rename src/test/ui/const-generics/{issues => generic_const_exprs}/issue-85848.stderr (100%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/needs_where_clause.rs (83%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/needs_where_clause.stderr (100%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/no_where_clause.rs (90%) rename src/test/ui/{const_evaluatable => const-generics/generic_const_exprs}/no_where_clause.stderr (100%) delete mode 100644 src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr rename src/test/ui/const-generics/generic_const_exprs/{simple_fail.full.stderr => simple_fail.stderr} (90%) delete mode 100644 src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr rename src/test/ui/const-generics/{impl-trait-with-const-arguments.full.stderr => impl-trait-with-const-arguments.stderr} (86%) delete mode 100644 src/test/ui/const-generics/incorrect-number-of-const-args.min.stderr rename src/test/ui/const-generics/{incorrect-number-of-const-args.full.stderr => incorrect-number-of-const-args.stderr} (83%) delete mode 100644 src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr rename src/test/ui/const-generics/infer/{cannot-infer-const-args.full.stderr => cannot-infer-const-args.stderr} (89%) delete mode 100644 src/test/ui/const-generics/infer/method-chain.min.stderr rename src/test/ui/const-generics/infer/{method-chain.full.stderr => method-chain.stderr} (93%) delete mode 100644 src/test/ui/const-generics/infer/one-param-uninferred.min.stderr rename src/test/ui/const-generics/infer/{one-param-uninferred.full.stderr => one-param-uninferred.stderr} (91%) delete mode 100644 src/test/ui/const-generics/infer/uninferred-consts.min.stderr rename src/test/ui/const-generics/infer/{uninferred-consts.full.stderr => uninferred-consts.stderr} (91%) delete mode 100644 src/test/ui/const-generics/intrinsics-type_name-as-const-argument.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-60818-struct-constructors.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61336-1.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61336-2.full.stderr rename src/test/ui/const-generics/issues/{issue-61336-2.min.stderr => issue-61336-2.stderr} (93%) delete mode 100644 src/test/ui/const-generics/issues/issue-61336.full.stderr rename src/test/ui/const-generics/issues/{issue-61336.min.stderr => issue-61336.stderr} (94%) delete mode 100644 src/test/ui/const-generics/issues/issue-61422.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61432.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61522-array-len-succ.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61522-array-len-succ.rs delete mode 100644 src/test/ui/const-generics/issues/issue-61747.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61747.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61747.rs delete mode 100644 src/test/ui/const-generics/issues/issue-61935.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61935.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-61935.rs delete mode 100644 src/test/ui/const-generics/issues/issue-62220.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-62220.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-62220.rs delete mode 100644 src/test/ui/const-generics/issues/issue-62456.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-62456.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-62456.rs delete mode 100644 src/test/ui/const-generics/issues/issue-62579-no-match.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-62579-no-match.rs delete mode 100644 src/test/ui/const-generics/issues/issue-64494.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-64494.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-64494.rs delete mode 100644 src/test/ui/const-generics/issues/issue-64519.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-66205.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-66205.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-66205.rs delete mode 100644 src/test/ui/const-generics/issues/issue-67185-2.min.stderr rename src/test/ui/const-generics/issues/{issue-67185-2.full.stderr => issue-67185-2.stderr} (90%) delete mode 100644 src/test/ui/const-generics/issues/issue-67945-3.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-67945-3.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-67945-3.rs delete mode 100644 src/test/ui/const-generics/issues/issue-68977.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-68977.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-68977.rs delete mode 100644 src/test/ui/const-generics/issues/issue-69654-run-pass.stderr create mode 100644 src/test/ui/const-generics/issues/issue-71202.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-72787.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-73508.full.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-73508.min.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-73508.rs delete mode 100644 src/test/ui/const-generics/issues/issue-74634.stderr delete mode 100644 src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.full.stderr rename src/test/ui/const-generics/issues/{issue-76701-ty-param-in-const.min.stderr => issue-76701-ty-param-in-const.stderr} (65%) delete mode 100644 src/test/ui/const-generics/macro_rules-braces.full.stderr delete mode 100644 src/test/ui/const-generics/mut-ref-const-param-array.rs delete mode 100644 src/test/ui/const-generics/slice-const-param.min.stderr delete mode 100644 src/test/ui/const-generics/struct-with-invalid-const-param.full.stderr delete mode 100644 src/test/ui/const-generics/struct-with-invalid-const-param.min.stderr delete mode 100644 src/test/ui/const-generics/type-dependent/issue-71382.min.stderr rename src/test/ui/const-generics/type-dependent/{issue-71382.full.stderr => issue-71382.stderr} (86%) delete mode 100644 src/test/ui/const-generics/unknown_adt.min.stderr rename src/test/ui/const-generics/{unknown_adt.full.stderr => unknown_adt.stderr} (89%) delete mode 100644 src/test/ui/const-generics/unused_braces.full.stderr rename src/test/ui/const-generics/{unused_braces.min.stderr => unused_braces.stderr} (80%) delete mode 100644 src/test/ui/const-generics/wf-misc.full.stderr delete mode 100644 src/test/ui/const-generics/wf-misc.min.stderr delete mode 100644 src/test/ui/const-generics/wf-misc.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-const_generics.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-const_generics.stderr create mode 100644 src/test/ui/feature-gates/feature-gate-const_param_types.rs rename src/test/ui/{const-generics/issues/issue-66596-impl-trait-for-str-const-arg.min.stderr => feature-gates/feature-gate-const_param_types.stderr} (61%) delete mode 100644 src/test/ui/hygiene/generic_params.stderr delete mode 100644 src/test/ui/hygiene/issue-61574-const-parameters.stderr delete mode 100644 src/test/ui/impl-trait/issue-55872-1.full_tait.stderr delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.stderr delete mode 100644 src/test/ui/mir/issue-75053.in_bindings.stderr delete mode 100644 src/test/ui/obsolete-in-place/bad.bad.stderr delete mode 100644 src/test/ui/self/arbitrary-self-types-not-object-safe.stderr delete mode 100644 src/test/ui/symbol-names/basic.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/assoc-type-const.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/bounds-are-checked-2.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained2.full_tait.stderr delete mode 100644 src/test/ui/type-alias-impl-trait/issue-52843.full_tait.stderr delete mode 100644 src/test/ui/typeck/typeck_type_placeholder_item.full_tait.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 2b86128b3f79..d0a95ea130a4 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -332,7 +332,7 @@ pub type GenericBounds = Vec; pub enum ParamKindOrd { Lifetime, Type, - // `unordered` is only `true` if `sess.has_features().const_generics` + // `unordered` is only `true` if `sess.has_features().const_generics_defaults` // is active. Specifically, if it's only `min_const_generics`, it will still require // ordering consts after types. Const { unordered: bool }, diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 557271e32adb..1defb65ed879 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -687,7 +687,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { gate_all!(trait_alias, "trait aliases are experimental"); gate_all!(associated_type_bounds, "associated type bounds are unstable"); gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental"); - gate_all!(const_generics, "const generics are unstable"); gate_all!(decl_macro, "`macro` is experimental"); gate_all!(box_patterns, "box pattern syntax is experimental"); gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental"); diff --git a/compiler/rustc_error_codes/src/error_codes/E0671.md b/compiler/rustc_error_codes/src/error_codes/E0671.md index a993ce826a73..d4dbfb7a5d8e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0671.md +++ b/compiler/rustc_error_codes/src/error_codes/E0671.md @@ -4,8 +4,6 @@ Const parameters cannot depend on type parameters. The following is therefore invalid: ```compile_fail,E0770 -#![feature(const_generics)] - fn const_id() -> T { // error N } diff --git a/compiler/rustc_error_codes/src/error_codes/E0741.md b/compiler/rustc_error_codes/src/error_codes/E0741.md index 91379bfe05c6..510075dc779c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0741.md +++ b/compiler/rustc_error_codes/src/error_codes/E0741.md @@ -3,7 +3,7 @@ A non-structural-match type was used as the type of a const generic parameter. Erroneous code example: ```compile_fail,E0741 -#![feature(const_generics)] +#![feature(const_param_types)] struct A; @@ -16,7 +16,7 @@ may be used as the types of const generic parameters. To fix the previous code example, we derive `PartialEq` and `Eq`: ``` -#![feature(const_generics)] +#![feature(const_param_types)] #[derive(PartialEq, Eq)] // We derive both traits here. struct A; diff --git a/compiler/rustc_error_codes/src/error_codes/E0770.md b/compiler/rustc_error_codes/src/error_codes/E0770.md index b39163a9de3f..cd8fc481bf0c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0770.md +++ b/compiler/rustc_error_codes/src/error_codes/E0770.md @@ -3,7 +3,6 @@ The type of a const parameter references other generic parameters. Erroneous code example: ```compile_fail,E0770 -#![feature(const_generics)] fn foo() {} // error! ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0771.md b/compiler/rustc_error_codes/src/error_codes/E0771.md index 824a955f6b3f..c1e133673cad 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0771.md +++ b/compiler/rustc_error_codes/src/error_codes/E0771.md @@ -4,7 +4,7 @@ allowed. Erroneous code example: ```compile_fail,E0771 -#![feature(const_generics)] +#![feature(const_param_types)] fn function_with_str<'a, const STRING: &'a str>() {} // error! ``` @@ -13,7 +13,7 @@ To fix this issue, the lifetime in the const generic need to be changed to `'static`: ``` -#![feature(const_generics)] +#![feature(const_param_types)] fn function_with_str() {} // ok! ``` diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 18294dfad240..725f8b8763af 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -273,7 +273,7 @@ declare_features! ( /// Allows patterns with concurrent by-move and by-ref bindings. /// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref. (accepted, move_ref_pattern, "1.49.0", Some(68354), None), - /// The smallest useful subset of `const_generics`. + /// The smallest useful subset of const generics. (accepted, min_const_generics, "1.51.0", Some(74878), None), /// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block. (accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668), None), diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 222b17615e2d..e2c88835f524 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -71,7 +71,7 @@ macro_rules! declare_features { } pub fn unordered_const_ty_params(&self) -> bool { - self.const_generics || self.const_generics_defaults + self.const_generics_defaults } /// Some features are known to be incomplete and using them is likely to have @@ -453,9 +453,6 @@ declare_features! ( /// Allows using `#[ffi_returns_twice]` on foreign functions. (active, ffi_returns_twice, "1.34.0", Some(58314), None), - /// Allows const generic types (e.g. `struct Foo(...);`). - (incomplete, const_generics, "1.34.0", Some(44580), None), - /// Allows using `#[optimize(X)]`. (active, optimize_attribute, "1.34.0", Some(54882), None), @@ -676,6 +673,9 @@ declare_features! ( /// Allows non-trivial generic constants which have to have wfness manually propagated to callers (incomplete, generic_const_exprs, "1.56.0", Some(76560), None), + /// Allows additional const parameter types, such as `&'static str` or user defined types + (incomplete, const_param_types, "1.56.0", Some(44580), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 326daf21e40e..dd17b8ab22b4 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -102,6 +102,9 @@ declare_features! ( (removed, extern_in_paths, "1.33.0", Some(55600), None, Some("subsumed by `::foo::bar` paths")), (removed, quote, "1.33.0", Some(29601), None, None), + /// Allows const generic types (e.g. `struct Foo(...);`). + (removed, const_generics, "1.34.0", Some(44580), None, + Some("removed in favor of `#![feature(const_param_types]` and `#![feature(generic_const_exprs)]`")), /// Allows `[x; N]` where `x` is a constant (RFC 2203). (removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None, Some("removed due to causing promotable bugs")), diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 32308910aa7d..a0ee212bed0c 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -202,7 +202,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { /// A good example of this is the following: /// /// ```rust - /// #![feature(const_generics)] + /// #![feature(generic_const_exprs)] /// /// fn bind(value: [u8; N]) -> [u8; 3 + 4] { /// todo!() diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index a5b4fa15921b..88b9e92119f6 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2340,7 +2340,7 @@ declare_lint! { /// ### Example /// /// ```rust - /// #![feature(const_generics)] + /// #![feature(generic_const_exprs)] /// ``` /// /// {{produces}} diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a9ee921399ab..de7c6d9e0953 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1420,8 +1420,8 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn lazy_normalization(self) -> bool { let features = self.features(); - // Note: We do not enable lazy normalization for `min_const_generics`. - features.const_generics || features.generic_const_exprs + // Note: We only use lazy normalization for generic const expressions. + features.generic_const_exprs } #[inline] diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a4f754942381..0b1687d1bd8c 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -506,8 +506,7 @@ impl<'a> Resolver<'a> { if self.session.is_nightly_build() { err.help( - "use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` \ - to allow generic const expressions", + "use `#![feature(generic_const_exprs)]` to allow generic const expressions", ); } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index b3601ecf1d3a..45657f2d0f22 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2245,7 +2245,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { } /// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`. - /// This function will emit an error if `const_generics` is not enabled, the body identified by + /// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by /// `body_id` is an anonymous constant and `lifetime_ref` is non-static. crate fn maybe_emit_forbidden_non_static_lifetime_error( &self, @@ -2264,7 +2264,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { if !self.tcx.lazy_normalization() && is_anon_const && !is_allowed_lifetime { feature_err( &self.tcx.sess.parse_sess, - sym::const_generics, + sym::generic_const_exprs, lifetime_ref.span, "a non-static lifetime is not allowed in a `const`", ) diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index bc2c46ec0aa7..e901d4c00ab7 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -2301,7 +2301,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { match *scope { Scope::Body { id, s } => { // Non-static lifetimes are prohibited in anonymous constants without - // `const_generics`. + // `generic_const_exprs`. self.maybe_emit_forbidden_non_static_lifetime_error(id, lifetime_ref); outermost_body = Some(id); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index fc8fcf759adb..da3beac08196 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2734,8 +2734,7 @@ impl<'a> Resolver<'a> { ConstantItemRibKind(trivial, _) => { let features = self.session.features_untracked(); // HACK(min_const_generics): We currently only allow `N` or `{ N }`. - if !(trivial || features.const_generics || features.generic_const_exprs) - { + if !(trivial || features.generic_const_exprs) { // HACK(min_const_generics): If we encounter `Self` in an anonymous constant // we can't easily tell if it's generic at this stage, so we instead remember // this and then enforce the self type to be concrete later on. @@ -2807,8 +2806,7 @@ impl<'a> Resolver<'a> { ConstantItemRibKind(trivial, _) => { let features = self.session.features_untracked(); // HACK(min_const_generics): We currently only allow `N` or `{ N }`. - if !(trivial || features.const_generics || features.generic_const_exprs) - { + if !(trivial || features.generic_const_exprs) { if record_used { self.report_error( span, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 417d38e9f593..9968cd62d95f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -451,6 +451,7 @@ symbols! { const_mut_refs, const_panic, const_panic_fmt, + const_param_types, const_precise_live_drops, const_ptr, const_raw_ptr_deref, diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 5ade3828b726..761ea6df2e1e 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -290,7 +290,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { let err_ty_str; let mut is_ptr = true; - let err = if tcx.features().const_generics { + let err = if tcx.features().const_param_types { match ty.peel_refs().kind() { ty::FnPtr(_) => Some("function pointers"), ty::RawPtr(_) => Some("raw pointers"), @@ -328,7 +328,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { err.note("the only supported types are integers, `bool` and `char`"); if tcx.sess.is_nightly_build() { err.help( - "more complex types are supported with `#![feature(const_generics)]`", + "more complex types are supported with `#![feature(const_param_types)]`", ); } err.emit() diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index ff0b47abca9f..b8e8854847fb 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1489,7 +1489,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { } // HACK(eddyb) this provides the correct generics when - // `feature(const_generics)` is enabled, so that const expressions + // `feature(generic_const_expressions)` is enabled, so that const expressions // used with const generics, e.g. `Foo<{N+1}>`, can work at all. // // Note that we do not supply the parent generics when using diff --git a/src/test/debuginfo/function-names.rs b/src/test/debuginfo/function-names.rs index b9e59f8e8297..e962c18d8ec7 100644 --- a/src/test/debuginfo/function-names.rs +++ b/src/test/debuginfo/function-names.rs @@ -82,8 +82,8 @@ #![allow(unused_variables)] #![feature(omit_gdb_pretty_printer_section)] #![omit_gdb_pretty_printer_section] -#![feature(const_generics, generators, generator_trait)] -#![allow(incomplete_features)] // for const_generics +#![feature(const_param_types, generators, generator_trait)] +#![allow(incomplete_features)] use Mod1::TestTrait2; use std::ops::Generator; diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-1.rs b/src/test/incremental/const-generics/hash-tyvid-regression-1.rs index 4fe9dfc35bfd..7696bb7d331a 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-1.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-1.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs, const_param_types)] #![allow(incomplete_features)] // regression test for #77650 fn c() diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-1.stderr b/src/test/incremental/const-generics/hash-tyvid-regression-1.stderr deleted file mode 100644 index cb8ca3abd7f9..000000000000 --- a/src/test/incremental/const-generics/hash-tyvid-regression-1.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0277]: the trait bound `[T; _]: From<()>` is not satisfied - --> $DIR/hash-tyvid-regression-1.rs:9:5 - | -LL | <[T; N.get()]>::try_from(()) - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `[T; _]` - | - = note: required because of the requirements on the impl of `Into<[T; _]>` for `()` - = note: required because of the requirements on the impl of `TryFrom<()>` for `[T; _]` -note: required by `try_from` - --> $SRC_DIR/core/src/convert/mod.rs:LL:COL - | -LL | fn try_from(value: T) -> Result; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/hash-tyvid-regression-1.rs:9:5 - | -LL | <[T; N.get()]>::try_from(()) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found enum `Result` - | - = note: expected unit type `()` - found enum `Result<[T; _], Infallible>` -help: consider using a semicolon here - | -LL | <[T; N.get()]>::try_from(()); - | + -help: try adding a return type - | -LL | -> Result<[T; _], Infallible> where - | +++++++++++++++++++++++++++++ - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-2.rs b/src/test/incremental/const-generics/hash-tyvid-regression-2.rs index 32dbf0b45b9b..71d504d26a75 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-2.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-2.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs, const_param_types, const_generics_defaults)] #![allow(incomplete_features)] // regression test for #77650 struct C([T; N.get()]) diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-2.stderr b/src/test/incremental/const-generics/hash-tyvid-regression-2.stderr deleted file mode 100644 index 0e6040ef02e7..000000000000 --- a/src/test/incremental/const-generics/hash-tyvid-regression-2.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0277]: can't compare `[B; _]` with `&&[A]` - --> $DIR/hash-tyvid-regression-2.rs:12:16 - | -LL | self.0 == other - | ^^ no implementation for `[B; _] == &&[A]` - | - = help: the trait `PartialEq<&&[A]>` is not implemented for `[B; _]` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-3.rs b/src/test/incremental/const-generics/hash-tyvid-regression-3.rs index 9097d1e98f80..61f568f79ef9 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-3.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-3.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // regression test for #79251 struct Node diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-3.stderr b/src/test/incremental/const-generics/hash-tyvid-regression-3.stderr deleted file mode 100644 index 555d46756dcb..000000000000 --- a/src/test/incremental/const-generics/hash-tyvid-regression-3.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0599]: no method named `some_function` found for struct `SmallVec` in the current scope - --> $DIR/hash-tyvid-regression-3.rs:17:19 - | -LL | node.keys.some_function(); - | ^^^^^^^^^^^^^ method not found in `SmallVec<{ D * 2 }>` -... -LL | struct SmallVec {} - | ------------------------------- method `some_function` not found for this - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-4.rs b/src/test/incremental/const-generics/hash-tyvid-regression-4.rs index 9cfc0012576d..12e8ac7abadc 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-4.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-4.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // regression test for #79251 #[derive(Debug)] diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-4.stderr b/src/test/incremental/const-generics/hash-tyvid-regression-4.stderr deleted file mode 100644 index c9a6715e571c..000000000000 --- a/src/test/incremental/const-generics/hash-tyvid-regression-4.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0599]: no method named `push` found for struct `SmallVec` in the current scope - --> $DIR/hash-tyvid-regression-4.rs:23:19 - | -LL | node.keys.push(k); - | ^^^^ method not found in `SmallVec<_, { D * 2 }>` -... -LL | struct SmallVec { - | ---------------------------------- method `push` not found for this - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/incremental/const-generics/issue-61338.rs b/src/test/incremental/const-generics/issue-61338.rs index 00b3b29698be..e9d67fee2969 100644 --- a/src/test/incremental/const-generics/issue-61338.rs +++ b/src/test/incremental/const-generics/issue-61338.rs @@ -1,7 +1,5 @@ // revisions:rpass1 -#![feature(const_generics)] - struct Struct(T); impl Struct<[T; N]> { diff --git a/src/test/incremental/const-generics/issue-61516.rs b/src/test/incremental/const-generics/issue-61516.rs index a193bf998dc7..c781484d1e2e 100644 --- a/src/test/incremental/const-generics/issue-61516.rs +++ b/src/test/incremental/const-generics/issue-61516.rs @@ -1,7 +1,5 @@ // revisions:rpass1 -#![feature(const_generics)] - struct FakeArray(T); impl FakeArray { diff --git a/src/test/incremental/const-generics/issue-62536.rs b/src/test/incremental/const-generics/issue-62536.rs index 0eaeb910be64..93c1dbf44e93 100644 --- a/src/test/incremental/const-generics/issue-62536.rs +++ b/src/test/incremental/const-generics/issue-62536.rs @@ -1,7 +1,4 @@ // revisions:cfail1 -#![feature(const_generics)] -//[cfail1]~^ WARN the feature `const_generics` is incomplete - struct S([T; N]); fn f(x: T) -> S { panic!() } diff --git a/src/test/incremental/const-generics/issue-64087.rs b/src/test/incremental/const-generics/issue-64087.rs index 6b10c5404944..81c813531bd5 100644 --- a/src/test/incremental/const-generics/issue-64087.rs +++ b/src/test/incremental/const-generics/issue-64087.rs @@ -1,6 +1,4 @@ // revisions:cfail1 -#![feature(const_generics)] -//[cfail1]~^ WARN the feature `const_generics` is incomplete fn combinator() -> [T; S] {} //[cfail1]~^ ERROR mismatched types diff --git a/src/test/incremental/const-generics/issue-65623.rs b/src/test/incremental/const-generics/issue-65623.rs index 353e323e67b4..22bbcbcabed1 100644 --- a/src/test/incremental/const-generics/issue-65623.rs +++ b/src/test/incremental/const-generics/issue-65623.rs @@ -1,6 +1,4 @@ // revisions:rpass1 -#![feature(const_generics)] - pub struct Foo([T; 0]); impl Foo { diff --git a/src/test/incremental/const-generics/issue-68477.rs b/src/test/incremental/const-generics/issue-68477.rs index 925931bc4a63..9e35cf93d091 100644 --- a/src/test/incremental/const-generics/issue-68477.rs +++ b/src/test/incremental/const-generics/issue-68477.rs @@ -1,6 +1,8 @@ // edition:2018 // revisions:rpass1 -#![feature(const_generics)] + +// Needed to supply generic arguments to the anon const in `[(); FOO]`. +#![feature(generic_const_exprs)] const FOO: usize = 1; diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-1.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-1.rs index af77b1cedade..8262a2a211b7 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-1.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-1.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, unused_braces)] trait Delegates {} diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-2.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-2.rs index 46f18ce2309c..92bbcba4b38a 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-2.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-2.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Z; diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs index b01f31b91602..baca4562adef 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs, const_param_types)] #![allow(incomplete_features)] use std::{convert::TryFrom, num::NonZeroUsize}; diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-82034.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-82034.rs index 81b71cdf8813..c05d8355c280 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-82034.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-82034.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub trait IsTrue {} pub trait IsFalse {} diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-1.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-1.rs index b468fd071fe1..8886a556dbb2 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-1.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-1.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub struct Ref<'a, const NUM: usize>(&'a i32); diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-2.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-2.rs index 7c7d14a30c97..db1e2fc2af48 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-2.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-2.rs @@ -1,6 +1,6 @@ // revisions: cfail #![allow(incomplete_features)] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] pub struct Ref<'a>(&'a i32); diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-3.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-3.rs index b86ad01d99d8..5b2f5edc8500 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-3.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-85031-3.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test() {} diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-86953.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-86953.rs index 487154e7aba3..d659c5676336 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-86953.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-86953.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-88022.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-88022.rs index c28f6e17bef4..5f5435ba9f28 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-88022.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-88022.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, unused_braces)] struct Buffer diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs index 123dbaa406b8..7e38eb8369a8 100644 --- a/src/test/rustdoc/const-generics/add-impl.rs +++ b/src/test/rustdoc/const-generics/add-impl.rs @@ -1,4 +1,3 @@ -#![feature(const_generics)] #![crate_name = "foo"] use std::ops::Add; diff --git a/src/test/rustdoc/const-generics/const-generic-slice.rs b/src/test/rustdoc/const-generics/const-generic-slice.rs index 626a9e2b2109..b20663c6d68a 100644 --- a/src/test/rustdoc/const-generics/const-generic-slice.rs +++ b/src/test/rustdoc/const-generics/const-generic-slice.rs @@ -1,5 +1,4 @@ #![crate_name = "foo"] -#![feature(const_generics)] pub trait Array { type Item; diff --git a/src/test/rustdoc/const-generics/const-impl.rs b/src/test/rustdoc/const-generics/const-impl.rs index 7ddcb3a29f28..f0bc9bf7bdd7 100644 --- a/src/test/rustdoc/const-generics/const-impl.rs +++ b/src/test/rustdoc/const-generics/const-impl.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(const_param_types)] #![crate_name = "foo"] diff --git a/src/test/rustdoc/const-generics/const-evaluatable-checked.rs b/src/test/rustdoc/const-generics/generic_const_exprs.rs similarity index 86% rename from src/test/rustdoc/const-generics/const-evaluatable-checked.rs rename to src/test/rustdoc/const-generics/generic_const_exprs.rs index d435082e759f..35036a89360e 100644 --- a/src/test/rustdoc/const-generics/const-evaluatable-checked.rs +++ b/src/test/rustdoc/const-generics/generic_const_exprs.rs @@ -1,5 +1,5 @@ #![crate_name = "foo"] -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // make sure that `ConstEvaluatable` predicates dont cause rustdoc to ICE #77647 // @has foo/struct.Ice.html '//pre[@class="rust struct"]' \ diff --git a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs index 3345c8a3fe9c..4eac8e31e452 100644 --- a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs +++ b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs @@ -1,5 +1,5 @@ #![crate_name = "foo"] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // Checking if `Send` is implemented for `Hasher` requires us to evaluate a `ConstEquate` predicate, diff --git a/src/test/ui/array-slice-vec/match_arr_unknown_len.rs b/src/test/ui/array-slice-vec/match_arr_unknown_len.rs index 45b2889f1ca4..d190d7054fee 100644 --- a/src/test/ui/array-slice-vec/match_arr_unknown_len.rs +++ b/src/test/ui/array-slice-vec/match_arr_unknown_len.rs @@ -1,6 +1,3 @@ -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete - fn is_123(x: [u32; N]) -> bool { match x { [1, 2] => true, //~ ERROR mismatched types diff --git a/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr b/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr index 0ad05b3adeb8..1a14ab40b1f8 100644 --- a/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr +++ b/src/test/ui/array-slice-vec/match_arr_unknown_len.stderr @@ -1,14 +1,5 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/match_arr_unknown_len.rs:1:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - error[E0308]: mismatched types - --> $DIR/match_arr_unknown_len.rs:6:9 + --> $DIR/match_arr_unknown_len.rs:3:9 | LL | [1, 2] => true, | ^^^^^^ expected `2_usize`, found `N` @@ -16,6 +7,6 @@ LL | [1, 2] => true, = note: expected array `[u32; 2]` found array `[u32; N]` -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr b/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr index 3f97474d65f0..46a54a12d624 100644 --- a/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr +++ b/src/test/ui/associated-consts/associated-const-type-parameter-arrays.stderr @@ -5,7 +5,7 @@ LL | let _array: [u32; ::Y]; | ^ cannot perform const operation using `A` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr index bffdeb9a336a..f2e4ca524a43 100644 --- a/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr +++ b/src/test/ui/associated-item/associated-item-duplicate-bounds.stderr @@ -5,7 +5,7 @@ LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there. | ^^^^^^^^ cannot perform const operation using `A` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/async-await/issues/issue-78654.rs b/src/test/ui/async-await/issues/issue-78654.rs index 37ebb4ecac8b..24103390e090 100644 --- a/src/test/ui/async-await/issues/issue-78654.rs +++ b/src/test/ui/async-await/issues/issue-78654.rs @@ -1,7 +1,7 @@ // edition:2018 // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Foo; diff --git a/src/test/ui/binding/const-param.min.stderr b/src/test/ui/binding/const-param.min.stderr deleted file mode 100644 index 0200c6def246..000000000000 --- a/src/test/ui/binding/const-param.min.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0158]: const parameters cannot be referenced in patterns - --> $DIR/const-param.rs:8:9 - | -LL | N => {} - | ^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0158`. diff --git a/src/test/ui/binding/const-param.rs b/src/test/ui/binding/const-param.rs index 4aec801cb155..2d051808fe0b 100644 --- a/src/test/ui/binding/const-param.rs +++ b/src/test/ui/binding/const-param.rs @@ -1,7 +1,4 @@ // Identifier pattern referring to a const generic parameter is an error (issue #68853). -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] fn check() { match 1 { diff --git a/src/test/ui/binding/const-param.full.stderr b/src/test/ui/binding/const-param.stderr similarity index 87% rename from src/test/ui/binding/const-param.full.stderr rename to src/test/ui/binding/const-param.stderr index 0200c6def246..adda80810ead 100644 --- a/src/test/ui/binding/const-param.full.stderr +++ b/src/test/ui/binding/const-param.stderr @@ -1,5 +1,5 @@ error[E0158]: const parameters cannot be referenced in patterns - --> $DIR/const-param.rs:8:9 + --> $DIR/const-param.rs:5:9 | LL | N => {} | ^ diff --git a/src/test/ui/const-generics/apit-with-const-param.rs b/src/test/ui/const-generics/apit-with-const-param.rs index 3bc62141927a..2a04dc313e9b 100644 --- a/src/test/ui/const-generics/apit-with-const-param.rs +++ b/src/test/ui/const-generics/apit-with-const-param.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait Trait {} diff --git a/src/test/ui/const-generics/argument_order.full.stderr b/src/test/ui/const-generics/argument_order.full.stderr index e533d4f7fb83..9762748f441f 100644 --- a/src/test/ui/const-generics/argument_order.full.stderr +++ b/src/test/ui/const-generics/argument_order.full.stderr @@ -1,11 +1,11 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:11:32 + --> $DIR/argument_order.rs:10:32 | LL | struct AlsoBad { | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>` error[E0747]: lifetime provided when a type was expected - --> $DIR/argument_order.rs:19:23 + --> $DIR/argument_order.rs:18:23 | LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; | ^^^^^^^ diff --git a/src/test/ui/const-generics/argument_order.min.stderr b/src/test/ui/const-generics/argument_order.min.stderr index f23bc6d6a2bf..afd9ed1a7235 100644 --- a/src/test/ui/const-generics/argument_order.min.stderr +++ b/src/test/ui/const-generics/argument_order.min.stderr @@ -1,23 +1,23 @@ error: type parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:5:28 + --> $DIR/argument_order.rs:4:28 | LL | struct Bad { | -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `` error: lifetime parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:11:32 + --> $DIR/argument_order.rs:10:32 | LL | struct AlsoBad { | -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>` error: type parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:11:36 + --> $DIR/argument_order.rs:10:36 | LL | struct AlsoBad { | ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>` error[E0747]: lifetime provided when a type was expected - --> $DIR/argument_order.rs:19:23 + --> $DIR/argument_order.rs:18:23 | LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; | ^^^^^^^ diff --git a/src/test/ui/const-generics/argument_order.rs b/src/test/ui/const-generics/argument_order.rs index 95eaeea58184..97dd0f143522 100644 --- a/src/test/ui/const-generics/argument_order.rs +++ b/src/test/ui/const-generics/argument_order.rs @@ -1,6 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(full, feature(const_generics_defaults))] struct Bad { //[min]~^ ERROR type parameters must be declared prior to const parameters diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.full.stderr b/src/test/ui/const-generics/array-size-in-generic-struct-param.full.stderr deleted file mode 100644 index 0fb23e41b013..000000000000 --- a/src/test/ui/const-generics/array-size-in-generic-struct-param.full.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/array-size-in-generic-struct-param.rs:8:38 - | -LL | struct ArithArrayLen([u32; 0 + N]); - | ^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/array-size-in-generic-struct-param.rs:19:10 - | -LL | arr: [u8; CFG.arr_size], - | ^^^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/array-wrapper-struct-ctor.rs b/src/test/ui/const-generics/array-wrapper-struct-ctor.rs index 732a18714566..a712f691dbe2 100644 --- a/src/test/ui/const-generics/array-wrapper-struct-ctor.rs +++ b/src/test/ui/const-generics/array-wrapper-struct-ctor.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] #![allow(dead_code)] diff --git a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr b/src/test/ui/const-generics/associated-type-bound-fail.min.stderr deleted file mode 100644 index 7ab430ba830b..000000000000 --- a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 - | -LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` - | - = help: the following implementations were found: - > -note: required by a bound in `Foo::Assoc` - --> $DIR/associated-type-bound-fail.rs:8:17 - | -LL | type Assoc: Bar; - | ^^^^^^ required by this bound in `Foo::Assoc` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/associated-type-bound-fail.rs b/src/test/ui/const-generics/associated-type-bound-fail.rs index 83b267008057..937b8bcb6305 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.rs +++ b/src/test/ui/const-generics/associated-type-bound-fail.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - trait Bar {} trait Foo { diff --git a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr b/src/test/ui/const-generics/associated-type-bound-fail.stderr similarity index 84% rename from src/test/ui/const-generics/associated-type-bound-fail.full.stderr rename to src/test/ui/const-generics/associated-type-bound-fail.stderr index 7ab430ba830b..60e624fc6a8c 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 + --> $DIR/associated-type-bound-fail.rs:9:5 | LL | type Assoc = u16; | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` @@ -7,7 +7,7 @@ LL | type Assoc = u16; = help: the following implementations were found: > note: required by a bound in `Foo::Assoc` - --> $DIR/associated-type-bound-fail.rs:8:17 + --> $DIR/associated-type-bound-fail.rs:4:17 | LL | type Assoc: Bar; | ^^^^^^ required by this bound in `Foo::Assoc` diff --git a/src/test/ui/const-generics/associated-type-bound.rs b/src/test/ui/const-generics/associated-type-bound.rs index 02f77396c0b6..3044736b47e0 100644 --- a/src/test/ui/const-generics/associated-type-bound.rs +++ b/src/test/ui/const-generics/associated-type-bound.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - trait Bar {} trait Foo { diff --git a/src/test/ui/const-generics/auxiliary/const_generic_lib.rs b/src/test/ui/const-generics/auxiliary/const_generic_lib.rs index 8d4cd9c0d6b7..922f92d9feb7 100644 --- a/src/test/ui/const-generics/auxiliary/const_generic_lib.rs +++ b/src/test/ui/const-generics/auxiliary/const_generic_lib.rs @@ -1,6 +1,3 @@ -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub struct Struct(pub [u8; N]); pub type Alias = Struct<2>; diff --git a/src/test/ui/const-generics/auxiliary/crayte.rs b/src/test/ui/const-generics/auxiliary/crayte.rs index d9baab956c9f..19a8bb0f4eb2 100644 --- a/src/test/ui/const-generics/auxiliary/crayte.rs +++ b/src/test/ui/const-generics/auxiliary/crayte.rs @@ -1,6 +1,4 @@ // edition:2018 -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] pub trait Foo {} struct Local; diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs index ff686c5e767d..5c2b1f4bddf8 100644 --- a/src/test/ui/const-generics/auxiliary/generics_of_parent.rs +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // library portion of regression test for #87674 diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs index bc3c304cfd88..cd5b8161d08b 100644 --- a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // library portion of testing that `impl Trait<{ expr }>` doesnt diff --git a/src/test/ui/const-generics/broken-mir-1.rs b/src/test/ui/const-generics/broken-mir-1.rs index 34255fa9f588..6b6140e3a730 100644 --- a/src/test/ui/const-generics/broken-mir-1.rs +++ b/src/test/ui/const-generics/broken-mir-1.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub trait Foo { fn foo(&self); } diff --git a/src/test/ui/const-generics/broken-mir-2.rs b/src/test/ui/const-generics/broken-mir-2.rs index ac358b01672b..f9e03151374a 100644 --- a/src/test/ui/const-generics/broken-mir-2.rs +++ b/src/test/ui/const-generics/broken-mir-2.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - use std::fmt::Debug; #[derive(Debug)] diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs index 44aef859f2de..a6e767489b79 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs @@ -1,7 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] // This test confirms that the types can be inferred correctly for this example with const // generics. Previously this would ICE, and more recently error. diff --git a/src/test/ui/const-generics/closing-args-token.min.stderr b/src/test/ui/const-generics/closing-args-token.min.stderr deleted file mode 100644 index f4bb1e422076..000000000000 --- a/src/test/ui/const-generics/closing-args-token.min.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/closing-args-token.rs:10:9 - | -LL | S::<5 + 2 >> 7>; - | ^^^^^ - | -help: enclose the `const` expression in braces - | -LL | S::<{ 5 + 2 } >> 7>; - | + + - -error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:10:16 - | -LL | S::<5 + 2 >> 7>; - | ^ ^ - | -help: split the comparison into two - | -LL | S::<5 + 2 >> 7 && 7>; - | ++++ - -error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:16:20 - | -LL | S::<{ 5 + 2 } >> 7>; - | ^ ^ - | -help: split the comparison into two - | -LL | S::<{ 5 + 2 } >> 7 && 7>; - | ++++ - -error: expected expression, found `;` - --> $DIR/closing-args-token.rs:21:16 - | -LL | T::<0 >= 3>; - | ^ expected expression - -error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:27:12 - | -LL | T::>= 2 > 0>; - | ^^ ^ - | -help: split the comparison into two - | -LL | T::>= 2 && 2 > 0>; - | ++++ - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/const-generics/coerce_unsized_array.rs b/src/test/ui/const-generics/coerce_unsized_array.rs index 8e20df281039..ffd5eb9d462e 100644 --- a/src/test/ui/const-generics/coerce_unsized_array.rs +++ b/src/test/ui/const-generics/coerce_unsized_array.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn foo(v: &[u8; N]) -> &[u8] { v } diff --git a/src/test/ui/const-generics/concrete-const-as-fn-arg.rs b/src/test/ui/const-generics/concrete-const-as-fn-arg.rs index 8c31c8651a2b..372f0433e951 100644 --- a/src/test/ui/const-generics/concrete-const-as-fn-arg.rs +++ b/src/test/ui/const-generics/concrete-const-as-fn-arg.rs @@ -1,9 +1,5 @@ // Test that a concrete const type i.e. A<2>, can be used as an argument type in a function // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct A; // ok diff --git a/src/test/ui/const-generics/concrete-const-impl-method.rs b/src/test/ui/const-generics/concrete-const-impl-method.rs index 3d3bd2664c8b..53c9c0ead0f9 100644 --- a/src/test/ui/const-generics/concrete-const-impl-method.rs +++ b/src/test/ui/const-generics/concrete-const-impl-method.rs @@ -1,10 +1,6 @@ // Test that a method/associated non-method within an impl block of a concrete const type i.e. A<2>, // is callable. // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] pub struct A; diff --git a/src/test/ui/const-generics/condition-in-trait-const-arg.rs b/src/test/ui/const-generics/condition-in-trait-const-arg.rs index ad40b48afe5e..6f85237cf0aa 100644 --- a/src/test/ui/const-generics/condition-in-trait-const-arg.rs +++ b/src/test/ui/const-generics/condition-in-trait-const-arg.rs @@ -2,7 +2,7 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] trait IsZeroTrait{} diff --git a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs index f01bda84bf51..aa0f9131aa7f 100644 --- a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs +++ b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This tests that the `conservative_is_privately_uninhabited` fn doesn't cause diff --git a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs index c48830f01a96..d0864414cc1f 100644 --- a/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs +++ b/src/test/ui/const-generics/conservative_is_privately_uninhabited_uses_correct_param_env-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This tests that the `conservative_is_privately_uninhabited` fn doesn't cause diff --git a/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr b/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr index 6805b4a187e2..ac693426fbd9 100644 --- a/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr +++ b/src/test/ui/const-generics/const-arg-in-const-arg.min.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; foo::()]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:14:23 @@ -14,7 +14,7 @@ LL | let _: [u8; bar::()]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:24:23 @@ -23,7 +23,7 @@ LL | let _ = [0; bar::()]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:29:24 @@ -32,7 +32,7 @@ LL | let _: Foo<{ foo::() }>; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:30:24 @@ -41,7 +41,7 @@ LL | let _: Foo<{ bar::() }>; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:35:27 @@ -50,7 +50,7 @@ LL | let _ = Foo::<{ foo::() }>; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/const-arg-in-const-arg.rs:36:27 @@ -59,7 +59,7 @@ LL | let _ = Foo::<{ bar::() }>; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:15:23 @@ -67,8 +67,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: [u8; faz::<'a>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:16:23 @@ -76,8 +76,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: [u8; baz::<'a>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:17:23 @@ -85,8 +85,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: [u8; faz::<'b>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:18:23 @@ -94,8 +94,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: [u8; baz::<'b>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:25:23 @@ -103,8 +103,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = [0; faz::<'a>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:26:23 @@ -112,8 +112,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = [0; baz::<'a>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:27:23 @@ -121,8 +121,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = [0; faz::<'b>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:28:23 @@ -130,8 +130,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = [0; baz::<'b>(&())]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:31:24 @@ -139,8 +139,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: Foo<{ faz::<'a>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:32:24 @@ -148,8 +148,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: Foo<{ baz::<'a>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:33:24 @@ -157,8 +157,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: Foo<{ faz::<'b>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:34:24 @@ -166,8 +166,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _: Foo<{ baz::<'b>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:37:27 @@ -175,8 +175,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:38:27 @@ -184,8 +184,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = Foo::<{ baz::<'a>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:39:27 @@ -193,8 +193,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/const-arg-in-const-arg.rs:40:27 @@ -202,8 +202,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | let _ = Foo::<{ baz::<'b>(&()) }>; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error: aborting due to 23 previous errors diff --git a/src/test/ui/const-generics/const-arg-in-const-arg.rs b/src/test/ui/const-generics/const-arg-in-const-arg.rs index 8279f4a3f61e..39f0b2373302 100644 --- a/src/test/ui/const-generics/const-arg-in-const-arg.rs +++ b/src/test/ui/const-generics/const-arg-in-const-arg.rs @@ -1,5 +1,5 @@ // revisions: min -// FIXME(const_generics): This test currently causes an ICE because +// FIXME(generic_const_exprs): This test currently causes an ICE because // we don't yet correctly deal with lifetimes, reenable this test once // this is fixed. diff --git a/src/test/ui/const-generics/const-arg-in-fn.rs b/src/test/ui/const-generics/const-arg-in-fn.rs index 43ed12efb895..9b225b18d730 100644 --- a/src/test/ui/const-generics/const-arg-in-fn.rs +++ b/src/test/ui/const-generics/const-arg-in-fn.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn const_u32_identity() -> u32 { X } diff --git a/src/test/ui/const-generics/const-arg-type-arg-misordered.full.stderr b/src/test/ui/const-generics/const-arg-type-arg-misordered.full.stderr deleted file mode 100644 index d0ea51ea4173..000000000000 --- a/src/test/ui/const-generics/const-arg-type-arg-misordered.full.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0747]: constant provided when a type was expected - --> $DIR/const-arg-type-arg-misordered.rs:7:35 - | -LL | fn foo() -> Array { - | ^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/const-generics/const-arg-type-arg-misordered.rs b/src/test/ui/const-generics/const-arg-type-arg-misordered.rs index 5415791d21bb..8ee17e637aa3 100644 --- a/src/test/ui/const-generics/const-arg-type-arg-misordered.rs +++ b/src/test/ui/const-generics/const-arg-type-arg-misordered.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - type Array = [T; N]; fn foo() -> Array { diff --git a/src/test/ui/const-generics/const-arg-type-arg-misordered.min.stderr b/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr similarity index 88% rename from src/test/ui/const-generics/const-arg-type-arg-misordered.min.stderr rename to src/test/ui/const-generics/const-arg-type-arg-misordered.stderr index d7b7df0eb55b..104ee9b48b43 100644 --- a/src/test/ui/const-generics/const-arg-type-arg-misordered.min.stderr +++ b/src/test/ui/const-generics/const-arg-type-arg-misordered.stderr @@ -1,5 +1,5 @@ error[E0747]: constant provided when a type was expected - --> $DIR/const-arg-type-arg-misordered.rs:7:35 + --> $DIR/const-arg-type-arg-misordered.rs:3:35 | LL | fn foo() -> Array { | ^ diff --git a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.min.stderr b/src/test/ui/const-generics/const-argument-cross-crate-mismatch.min.stderr deleted file mode 100644 index 6ef698bd6a04..000000000000 --- a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.min.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/const-argument-cross-crate-mismatch.rs:9:67 - | -LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8])); - | ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements - -error[E0308]: mismatched types - --> $DIR/const-argument-cross-crate-mismatch.rs:11:65 - | -LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]); - | ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs b/src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs index a8f533eceaa6..d863d097d5ca 100644 --- a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs +++ b/src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs @@ -1,7 +1,4 @@ // aux-build:const_generic_lib.rs -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] extern crate const_generic_lib; diff --git a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.full.stderr b/src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr similarity index 85% rename from src/test/ui/const-generics/const-argument-cross-crate-mismatch.full.stderr rename to src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr index 6ef698bd6a04..aefd514f7a68 100644 --- a/src/test/ui/const-generics/const-argument-cross-crate-mismatch.full.stderr +++ b/src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr @@ -1,11 +1,11 @@ error[E0308]: mismatched types - --> $DIR/const-argument-cross-crate-mismatch.rs:9:67 + --> $DIR/const-argument-cross-crate-mismatch.rs:6:67 | LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8])); | ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements error[E0308]: mismatched types - --> $DIR/const-argument-cross-crate-mismatch.rs:11:65 + --> $DIR/const-argument-cross-crate-mismatch.rs:8:65 | LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]); | ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements diff --git a/src/test/ui/const-generics/const-argument-if-length.full.stderr b/src/test/ui/const-generics/const-argument-if-length.full.stderr index 8e62147eb7e3..8c5c3b17b5c4 100644 --- a/src/test/ui/const-generics/const-argument-if-length.full.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.full.stderr @@ -1,24 +1,5 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/const-argument-if-length.rs:7:28 - | -LL | pub const fn is_zst() -> usize { - | - this type parameter needs to be `std::marker::Sized` -LL | if std::mem::size_of::() == 0 { - | ^ doesn't have a size known at compile-time - | -note: required by a bound in `std::mem::size_of` - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | ^ required by this bound in `std::mem::size_of` -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - pub const fn is_zst() -> usize { -LL + pub const fn is_zst() -> usize { - | - -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/const-argument-if-length.rs:16:12 + --> $DIR/const-argument-if-length.rs:15:12 | LL | pub struct AtLeastByte { | - this type parameter needs to be `std::marker::Sized` @@ -41,6 +22,14 @@ help: the `Box` type always has a statically known size and allocates its conten LL | value: Box, | ++++ + +error: unconstrained generic constant + --> $DIR/const-argument-if-length.rs:17:10 + | +LL | pad: [u8; is_zst::()], + | ^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); is_zst::()]:` + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/const-argument-if-length.min.stderr b/src/test/ui/const-generics/const-argument-if-length.min.stderr index ef6bb69e9973..b123036bf250 100644 --- a/src/test/ui/const-generics/const-argument-if-length.min.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.min.stderr @@ -1,14 +1,14 @@ error: generic parameters may not be used in const operations - --> $DIR/const-argument-if-length.rs:18:24 + --> $DIR/const-argument-if-length.rs:17:24 | LL | pad: [u8; is_zst::()], | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/const-argument-if-length.rs:16:12 + --> $DIR/const-argument-if-length.rs:15:12 | LL | pub struct AtLeastByte { | - this type parameter needs to be `std::marker::Sized` diff --git a/src/test/ui/const-generics/const-argument-if-length.rs b/src/test/ui/const-generics/const-argument-if-length.rs index 67ed85f96afd..db1eafca2c72 100644 --- a/src/test/ui/const-generics/const-argument-if-length.rs +++ b/src/test/ui/const-generics/const-argument-if-length.rs @@ -1,11 +1,10 @@ // revisions: full min +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] pub const fn is_zst() -> usize { if std::mem::size_of::() == 0 { - //[full]~^ ERROR the size for values of type `T` cannot be known at compilation time 1 } else { 0 @@ -17,6 +16,7 @@ pub struct AtLeastByte { //~^ ERROR the size for values of type `T` cannot be known at compilation time pad: [u8; is_zst::()], //[min]~^ ERROR generic parameters may not be used in const operations + //[full]~^^ ERROR unconstrained generic constant } fn main() {} diff --git a/src/test/ui/const-generics/const-argument-non-static-lifetime.rs b/src/test/ui/const-generics/const-argument-non-static-lifetime.rs index dc34621b9050..2aca7bdeb9a1 100644 --- a/src/test/ui/const-generics/const-argument-non-static-lifetime.rs +++ b/src/test/ui/const-generics/const-argument-non-static-lifetime.rs @@ -2,7 +2,7 @@ // revisions: full // FIXME(#75323) Omitted min revision for now due to ICE. -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] #![allow(dead_code)] diff --git a/src/test/ui/const-generics/const-expression-parameter.min.stderr b/src/test/ui/const-generics/const-expression-parameter.min.stderr deleted file mode 100644 index 4ce0ecdf3aab..000000000000 --- a/src/test/ui/const-generics/const-expression-parameter.min.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-parameter.rs:15:20 - | -LL | i32_identity::<1 + 2>(); - | ^^^^^ - | -help: enclose the `const` expression in braces - | -LL | i32_identity::<{ 1 + 2 }>(); - | + + - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/const-fn-with-const-param.rs b/src/test/ui/const-generics/const-fn-with-const-param.rs index 5c1ee4e0d5a9..161bfaab48ad 100644 --- a/src/test/ui/const-generics/const-fn-with-const-param.rs +++ b/src/test/ui/const-generics/const-fn-with-const-param.rs @@ -1,9 +1,5 @@ // Checks that `const fn` with const params can be used. // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] const fn const_u32_identity() -> u32 { X diff --git a/src/test/ui/const-generics/const-generic-array-wrapper.rs b/src/test/ui/const-generics/const-generic-array-wrapper.rs deleted file mode 100644 index 224fc794e327..000000000000 --- a/src/test/ui/const-generics/const-generic-array-wrapper.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -struct Foo([T; N]); - -impl Foo { - fn foo(&self) -> usize { - N - } -} - -fn main() { - let foo = Foo([0u32; 21]); - assert_eq!(foo.0, [0u32; 21]); - assert_eq!(foo.foo(), 21); -} diff --git a/src/test/ui/const-generics/const-generic-type_name.rs b/src/test/ui/const-generics/const-generic-type_name.rs index 95632f798969..bb16be9c58c3 100644 --- a/src/test/ui/const-generics/const-generic-type_name.rs +++ b/src/test/ui/const-generics/const-generic-type_name.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] #[derive(Debug)] struct S; diff --git a/src/test/ui/const-generics/const-param-after-const-literal-arg.rs b/src/test/ui/const-generics/const-param-after-const-literal-arg.rs index 6c2b14f2770d..d8a0e076e0a4 100644 --- a/src/test/ui/const-generics/const-param-after-const-literal-arg.rs +++ b/src/test/ui/const-generics/const-param-after-const-literal-arg.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct Foo; diff --git a/src/test/ui/const-generics/const-param-before-other-params.full.stderr b/src/test/ui/const-generics/const-param-before-other-params.full.stderr index 09a4f66de39c..982417eb3c61 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.full.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.full.stderr @@ -1,8 +1,8 @@ error: lifetime parameters must be declared prior to const parameters --> $DIR/const-param-before-other-params.rs:5:21 | -LL | fn bar(_: &'a ()) { - | --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: ()>` +LL | fn bar(_: &'a ()) { + | --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: u8>` error: aborting due to previous error diff --git a/src/test/ui/const-generics/const-param-before-other-params.min.stderr b/src/test/ui/const-generics/const-param-before-other-params.min.stderr index a9349ce43c94..f439cd9d69fc 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.min.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.min.stderr @@ -1,32 +1,14 @@ error: lifetime parameters must be declared prior to const parameters --> $DIR/const-param-before-other-params.rs:5:21 | -LL | fn bar(_: &'a ()) { - | --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>` +LL | fn bar(_: &'a ()) { + | --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: u8>` error: type parameters must be declared prior to const parameters - --> $DIR/const-param-before-other-params.rs:10:21 + --> $DIR/const-param-before-other-params.rs:9:21 | -LL | fn foo(_: &T) {} - | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `` +LL | fn foo(_: &T) {} + | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `` -error: `()` is forbidden as the type of a const generic parameter - --> $DIR/const-param-before-other-params.rs:5:17 - | -LL | fn bar(_: &'a ()) { - | ^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: `()` is forbidden as the type of a const generic parameter - --> $DIR/const-param-before-other-params.rs:10:17 - | -LL | fn foo(_: &T) {} - | ^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index 508bb3e6a689..0a7b57fe626b 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -1,14 +1,12 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_generics_defaults))] #![cfg_attr(full, allow(incomplete_features))] -fn bar(_: &'a ()) { +fn bar(_: &'a ()) { //~^ ERROR lifetime parameters must be declared prior to const parameters - //[min]~^^ ERROR `()` is forbidden as the type of a const generic parameter } -fn foo(_: &T) {} +fn foo(_: &T) {} //[min]~^ ERROR type parameters must be declared prior to const parameters -//[min]~^^ ERROR `()` is forbidden as the type of a const generic parameter fn main() {} diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.full.stderr b/src/test/ui/const-generics/const-param-elided-lifetime.full.stderr index 119f932745b3..d6753a74f857 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.full.stderr +++ b/src/test/ui/const-generics/const-param-elided-lifetime.full.stderr @@ -1,29 +1,29 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:10:19 + --> $DIR/const-param-elided-lifetime.rs:9:19 | LL | struct A; | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:15:15 + --> $DIR/const-param-elided-lifetime.rs:14:15 | LL | impl A { | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:18:21 + --> $DIR/const-param-elided-lifetime.rs:17:21 | LL | fn foo(&self) {} | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:23:15 + --> $DIR/const-param-elided-lifetime.rs:22:15 | LL | impl B for A {} | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:27:17 + --> $DIR/const-param-elided-lifetime.rs:26:17 | LL | fn bar() {} | ^ explicit lifetime name needed here diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr b/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr index 613918f78f36..0f98adf2a6bc 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -1,77 +1,77 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:10:19 + --> $DIR/const-param-elided-lifetime.rs:9:19 | LL | struct A; | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:15:15 + --> $DIR/const-param-elided-lifetime.rs:14:15 | LL | impl A { | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:18:21 + --> $DIR/const-param-elided-lifetime.rs:17:21 | LL | fn foo(&self) {} | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:23:15 + --> $DIR/const-param-elided-lifetime.rs:22:15 | LL | impl B for A {} | ^ explicit lifetime name needed here error[E0637]: `&` without an explicit lifetime name cannot be used here - --> $DIR/const-param-elided-lifetime.rs:27:17 + --> $DIR/const-param-elided-lifetime.rs:26:17 | LL | fn bar() {} | ^ explicit lifetime name needed here error: `&'static u8` is forbidden as the type of a const generic parameter - --> $DIR/const-param-elided-lifetime.rs:10:19 + --> $DIR/const-param-elided-lifetime.rs:9:19 | LL | struct A; | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static u8` is forbidden as the type of a const generic parameter - --> $DIR/const-param-elided-lifetime.rs:15:15 + --> $DIR/const-param-elided-lifetime.rs:14:15 | LL | impl A { | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static u8` is forbidden as the type of a const generic parameter - --> $DIR/const-param-elided-lifetime.rs:18:21 + --> $DIR/const-param-elided-lifetime.rs:17:21 | LL | fn foo(&self) {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static u8` is forbidden as the type of a const generic parameter - --> $DIR/const-param-elided-lifetime.rs:23:15 + --> $DIR/const-param-elided-lifetime.rs:22:15 | LL | impl B for A {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static u8` is forbidden as the type of a const generic parameter - --> $DIR/const-param-elided-lifetime.rs:27:17 + --> $DIR/const-param-elided-lifetime.rs:26:17 | LL | fn bar() {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 10 previous errors diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.rs b/src/test/ui/const-generics/const-param-elided-lifetime.rs index 89715a7b8e9d..345e192f8db4 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.rs +++ b/src/test/ui/const-generics/const-param-elided-lifetime.rs @@ -3,8 +3,7 @@ // elided lifetimes within the type of a const generic parameters to be 'static, like elided // lifetimes within const/static items. // revisions: full min - -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct A; diff --git a/src/test/ui/const-generics/const-param-from-outer-fn.min.stderr b/src/test/ui/const-generics/const-param-from-outer-fn.min.stderr deleted file mode 100644 index c2ec7359c9f7..000000000000 --- a/src/test/ui/const-generics/const-param-from-outer-fn.min.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0401]: can't use generic parameters from outer function - --> $DIR/const-param-from-outer-fn.rs:8:9 - | -LL | fn foo() { - | - const parameter from outer function -LL | fn bar() -> u32 { - | --- try adding a local generic parameter in this method instead -LL | X - | ^ use of generic parameter from outer function - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0401`. diff --git a/src/test/ui/const-generics/const-param-in-async.rs b/src/test/ui/const-generics/const-param-in-async.rs index 9dc9c80241d5..f823431e69b9 100644 --- a/src/test/ui/const-generics/const-param-in-async.rs +++ b/src/test/ui/const-generics/const-param-in-async.rs @@ -1,8 +1,5 @@ // edition:2018 // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] async fn foo(arg: [u8; N]) -> usize { arg.len() } diff --git a/src/test/ui/const-generics/const-param-in-trait.rs b/src/test/ui/const-generics/const-param-in-trait.rs deleted file mode 100644 index 79b3ae2037ed..000000000000 --- a/src/test/ui/const-generics/const-param-in-trait.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Check that const parameters are permitted in traits. -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - - -trait Trait {} - -fn main() {} diff --git a/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr b/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr index 9804363f39a9..db3a04b8235d 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr @@ -17,7 +17,7 @@ LL | pub struct Dependent([(); N]); | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `[u8; _]` is forbidden as the type of a const generic parameter --> $DIR/const-param-type-depends-on-const-param.rs:15:35 @@ -26,7 +26,7 @@ LL | pub struct SelfDependent; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 4 previous errors diff --git a/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs index 62b146e016a1..07c86d2cf8ce 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] // Currently, const parameters cannot depend on other generic parameters, diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs index 910a96435022..6eb4b3735ffe 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] // Currently, const parameters cannot depend on other generic parameters, diff --git a/src/test/ui/const-generics/const-parameter-uppercase-lint.min.stderr b/src/test/ui/const-generics/const-parameter-uppercase-lint.min.stderr deleted file mode 100644 index 923964a4070a..000000000000 --- a/src/test/ui/const-generics/const-parameter-uppercase-lint.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: const parameter `x` should have an upper case name - --> $DIR/const-parameter-uppercase-lint.rs:8:15 - | -LL | fn noop() { - | ^ help: convert the identifier to upper case (notice the capitalization): `X` - | -note: the lint level is defined here - --> $DIR/const-parameter-uppercase-lint.rs:6:9 - | -LL | #![deny(non_upper_case_globals)] - | ^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/const-parameter-uppercase-lint.rs b/src/test/ui/const-generics/const-parameter-uppercase-lint.rs index 5d97907c2e7f..b08d62ccc7b1 100644 --- a/src/test/ui/const-generics/const-parameter-uppercase-lint.rs +++ b/src/test/ui/const-generics/const-parameter-uppercase-lint.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - #![deny(non_upper_case_globals)] fn noop() { diff --git a/src/test/ui/const-generics/const-parameter-uppercase-lint.full.stderr b/src/test/ui/const-generics/const-parameter-uppercase-lint.stderr similarity index 78% rename from src/test/ui/const-generics/const-parameter-uppercase-lint.full.stderr rename to src/test/ui/const-generics/const-parameter-uppercase-lint.stderr index 923964a4070a..efaa182852ac 100644 --- a/src/test/ui/const-generics/const-parameter-uppercase-lint.full.stderr +++ b/src/test/ui/const-generics/const-parameter-uppercase-lint.stderr @@ -1,11 +1,11 @@ error: const parameter `x` should have an upper case name - --> $DIR/const-parameter-uppercase-lint.rs:8:15 + --> $DIR/const-parameter-uppercase-lint.rs:3:15 | LL | fn noop() { | ^ help: convert the identifier to upper case (notice the capitalization): `X` | note: the lint level is defined here - --> $DIR/const-parameter-uppercase-lint.rs:6:9 + --> $DIR/const-parameter-uppercase-lint.rs:1:9 | LL | #![deny(non_upper_case_globals)] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/const-generics/const-types.rs b/src/test/ui/const-generics/const-types.rs deleted file mode 100644 index fb150f892edc..000000000000 --- a/src/test/ui/const-generics/const-types.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Check that arrays can be used with generic const and type. -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -#![allow(dead_code, unused_variables)] - -struct ConstArray { - array: [T; LEN], -} - -fn main() { - let arr = ConstArray:: { - array: [0; 8], - }; -} diff --git a/src/test/ui/const-generics/core-types.rs b/src/test/ui/const-generics/core-types.rs index b6fa478f48df..5e975c170431 100644 --- a/src/test/ui/const-generics/core-types.rs +++ b/src/test/ui/const-generics/core-types.rs @@ -2,7 +2,7 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct A; diff --git a/src/test/ui/const-generics/cross_crate_complex.rs b/src/test/ui/const-generics/cross_crate_complex.rs index 1d495c9562de..ebde155f7765 100644 --- a/src/test/ui/const-generics/cross_crate_complex.rs +++ b/src/test/ui/const-generics/cross_crate_complex.rs @@ -1,10 +1,6 @@ // aux-build:crayte.rs // edition:2018 // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] extern crate crayte; use crayte::*; diff --git a/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs b/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs index 6514409698e3..5c548740af23 100644 --- a/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs +++ b/src/test/ui/const-generics/defaults/auxiliary/const_defaulty.rs @@ -1,6 +1,4 @@ -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] pub struct Defaulted; impl Defaulted { diff --git a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr index 25004faee6f9..aa289ec07783 100644 --- a/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr +++ b/src/test/ui/const-generics/defaults/complex-generic-default-expr.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-generic-default-expr.rs:10:62 @@ -14,7 +14,7 @@ LL | struct Bar() }>(T); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs b/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs index d3558007977e..814c996fbad6 100644 --- a/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs +++ b/src/test/ui/const-generics/defaults/complex-generic-default-expr.rs @@ -1,6 +1,6 @@ // revisions: full min //[full] check-pass -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![feature(const_generics_defaults)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/defaults/complex-unord-param.rs b/src/test/ui/const-generics/defaults/complex-unord-param.rs index d24e403e017e..c27ed298afd1 100644 --- a/src/test/ui/const-generics/defaults/complex-unord-param.rs +++ b/src/test/ui/const-generics/defaults/complex-unord-param.rs @@ -1,7 +1,7 @@ // [full] run-pass // revisions: full min // Checks a complicated usage of unordered params -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_generics_defaults))] #![cfg_attr(full, allow(incomplete_features))] #![allow(dead_code)] diff --git a/src/test/ui/const-generics/defaults/const-default.rs b/src/test/ui/const-generics/defaults/const-default.rs index 4fa21b8b1fb7..e7cbf01a3017 100644 --- a/src/test/ui/const-generics/defaults/const-default.rs +++ b/src/test/ui/const-generics/defaults/const-default.rs @@ -1,9 +1,5 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] - pub struct ConstDefault; diff --git a/src/test/ui/const-generics/defaults/default-annotation.rs b/src/test/ui/const-generics/defaults/default-annotation.rs index 8eb8f368b12f..2b41dbb58873 100644 --- a/src/test/ui/const-generics/defaults/default-annotation.rs +++ b/src/test/ui/const-generics/defaults/default-annotation.rs @@ -1,13 +1,12 @@ // run-pass #![feature(staged_api)] - -#![feature(const_generics)] #![feature(const_generics_defaults)] #![allow(incomplete_features)] - +// FIXME(const_generics): It seems like we aren't testing the right thing here, +// I would assume that we want the attributes to apply to the const parameter defaults +// themselves. #![stable(feature = "const_default_test", since="none")] - #[unstable(feature = "const_default_stable", issue="none")] pub struct ConstDefaultUnstable; diff --git a/src/test/ui/const-generics/defaults/default-on-impl.min.stderr b/src/test/ui/const-generics/defaults/default-on-impl.min.stderr deleted file mode 100644 index c417a26842ed..000000000000 --- a/src/test/ui/const-generics/defaults/default-on-impl.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default-on-impl.rs:8:12 - | -LL | impl Foo {} - | ^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/defaults/default-on-impl.rs b/src/test/ui/const-generics/defaults/default-on-impl.rs index 735549defeaf..280d92f839f4 100644 --- a/src/test/ui/const-generics/defaults/default-on-impl.rs +++ b/src/test/ui/const-generics/defaults/default-on-impl.rs @@ -1,7 +1,4 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/defaults/default-on-impl.full.stderr b/src/test/ui/const-generics/defaults/default-on-impl.stderr similarity index 85% rename from src/test/ui/const-generics/defaults/default-on-impl.full.stderr rename to src/test/ui/const-generics/defaults/default-on-impl.stderr index c417a26842ed..0f85ceccc8a8 100644 --- a/src/test/ui/const-generics/defaults/default-on-impl.full.stderr +++ b/src/test/ui/const-generics/defaults/default-on-impl.stderr @@ -1,5 +1,5 @@ error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default-on-impl.rs:8:12 + --> $DIR/default-on-impl.rs:5:12 | LL | impl Foo {} | ^ diff --git a/src/test/ui/const-generics/defaults/external.rs b/src/test/ui/const-generics/defaults/external.rs index 32acf567cf2b..276e74355c25 100644 --- a/src/test/ui/const-generics/defaults/external.rs +++ b/src/test/ui/const-generics/defaults/external.rs @@ -1,9 +1,6 @@ // aux-build:const_defaulty.rs // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] extern crate const_defaulty; use const_defaulty::Defaulted; diff --git a/src/test/ui/const-generics/defaults/cec-concrete-default.rs b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs similarity index 77% rename from src/test/ui/const-generics/defaults/cec-concrete-default.rs rename to src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs index 80359476d6cc..52cea51aae15 100644 --- a/src/test/ui/const-generics/defaults/cec-concrete-default.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/defaults/cec-concrete-default.stderr b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.stderr similarity index 86% rename from src/test/ui/const-generics/defaults/cec-concrete-default.stderr rename to src/test/ui/const-generics/defaults/generic-expr-default-concrete.stderr index 090e507b7f34..905a285370a0 100644 --- a/src/test/ui/const-generics/defaults/cec-concrete-default.stderr +++ b/src/test/ui/const-generics/defaults/generic-expr-default-concrete.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/cec-concrete-default.rs:10:5 + --> $DIR/generic-expr-default-concrete.rs:10:5 | LL | Foo::<10, 12> | ^^^^^^^^^^^^^ expected `11_usize`, found `12_usize` diff --git a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs similarity index 82% rename from src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs rename to src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs index eb4a0cec0a6a..3a11631fc47f 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.stderr b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.stderr similarity index 84% rename from src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.stderr rename to src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.stderr index f97fc26a0732..d5a3071b77d1 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default-mismatched-types.stderr +++ b/src/test/ui/const-generics/defaults/generic-expr-default-mismatched-types.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/cec-generic-default-mismatched-types.rs:12:5 + --> $DIR/generic-expr-default-mismatched-types.rs:12:5 | LL | Foo:: | ^^^^^^^^^^^^^^^^^^^ expected `{ N + 1 }`, found `{ N + 2 }` diff --git a/src/test/ui/const-generics/defaults/cec-generic-default.rs b/src/test/ui/const-generics/defaults/generic-expr-default.rs similarity index 89% rename from src/test/ui/const-generics/defaults/cec-generic-default.rs rename to src/test/ui/const-generics/defaults/generic-expr-default.rs index 02f21adb0d59..0adbd5cdf317 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default.rs +++ b/src/test/ui/const-generics/defaults/generic-expr-default.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] pub struct Foo; diff --git a/src/test/ui/const-generics/defaults/cec-generic-default.stderr b/src/test/ui/const-generics/defaults/generic-expr-default.stderr similarity index 88% rename from src/test/ui/const-generics/defaults/cec-generic-default.stderr rename to src/test/ui/const-generics/defaults/generic-expr-default.stderr index 0234ea8b9a4a..ada1498d1c80 100644 --- a/src/test/ui/const-generics/defaults/cec-generic-default.stderr +++ b/src/test/ui/const-generics/defaults/generic-expr-default.stderr @@ -1,5 +1,5 @@ error: unconstrained generic constant - --> $DIR/cec-generic-default.rs:5:54 + --> $DIR/generic-expr-default.rs:5:54 | LL | pub fn needs_evaluatable_bound() -> Foo { | ^^^^^^^ @@ -7,7 +7,7 @@ LL | pub fn needs_evaluatable_bound() -> Foo { = help: try adding a `where` bound using this expression: `where [(); { N + 1 }]:` error: unconstrained generic constant - --> $DIR/cec-generic-default.rs:14:58 + --> $DIR/generic-expr-default.rs:14:58 | LL | fn needs_evaluatable_bound_alias() -> FooAlias | ^^^^^^^^^^^ diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr index 29d835e36c6e..725cc36b428c 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr @@ -1,11 +1,11 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/intermixed-lifetime.rs:7:28 + --> $DIR/intermixed-lifetime.rs:5:28 | LL | struct Foo(&'a (), T); | -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` error: lifetime parameters must be declared prior to type parameters - --> $DIR/intermixed-lifetime.rs:10:37 + --> $DIR/intermixed-lifetime.rs:8:37 | LL | struct Bar(&'a (), T); | --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr index 29d835e36c6e..725cc36b428c 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr @@ -1,11 +1,11 @@ error: lifetime parameters must be declared prior to const parameters - --> $DIR/intermixed-lifetime.rs:7:28 + --> $DIR/intermixed-lifetime.rs:5:28 | LL | struct Foo(&'a (), T); | -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` error: lifetime parameters must be declared prior to type parameters - --> $DIR/intermixed-lifetime.rs:10:37 + --> $DIR/intermixed-lifetime.rs:8:37 | LL | struct Bar(&'a (), T); | --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs index 307e3aaf1fbf..cc215ab0c251 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -1,8 +1,6 @@ // Checks that lifetimes cannot be interspersed between consts and types. // revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] struct Foo(&'a (), T); //~^ Error lifetime parameters must be declared prior to const parameters diff --git a/src/test/ui/const-generics/defaults/mismatch.full.stderr b/src/test/ui/const-generics/defaults/mismatch.full.stderr deleted file mode 100644 index 4aa8401ab221..000000000000 --- a/src/test/ui/const-generics/defaults/mismatch.full.stderr +++ /dev/null @@ -1,58 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/mismatch.rs:12:28 - | -LL | let e: Example::<13> = (); - | ------------- ^^ expected struct `Example`, found `()` - | | - | expected due to this - | - = note: expected struct `Example` - found unit type `()` - -error[E0308]: mismatched types - --> $DIR/mismatch.rs:15:34 - | -LL | let e: Example2:: = (); - | ------------------- ^^ expected struct `Example2`, found `()` - | | - | expected due to this - | - = note: expected struct `Example2` - found unit type `()` - -error[E0308]: mismatched types - --> $DIR/mismatch.rs:18:34 - | -LL | let e: Example3::<13, u32> = (); - | ------------------- ^^ expected struct `Example3`, found `()` - | | - | expected due to this - | - = note: expected struct `Example3` - found unit type `()` - -error[E0308]: mismatched types - --> $DIR/mismatch.rs:21:28 - | -LL | let e: Example3::<7> = (); - | ------------- ^^ expected struct `Example3`, found `()` - | | - | expected due to this - | - = note: expected struct `Example3<7_usize>` - found unit type `()` - -error[E0308]: mismatched types - --> $DIR/mismatch.rs:24:28 - | -LL | let e: Example4::<7> = (); - | ------------- ^^ expected struct `Example4`, found `()` - | | - | expected due to this - | - = note: expected struct `Example4<7_usize>` - found unit type `()` - -error: aborting due to 5 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/defaults/mismatch.rs b/src/test/ui/const-generics/defaults/mismatch.rs index 9d9a8793aaac..4ae93a9166d3 100644 --- a/src/test/ui/const-generics/defaults/mismatch.rs +++ b/src/test/ui/const-generics/defaults/mismatch.rs @@ -1,7 +1,4 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] pub struct Example; pub struct Example2(T); diff --git a/src/test/ui/const-generics/defaults/mismatch.min.stderr b/src/test/ui/const-generics/defaults/mismatch.stderr similarity index 94% rename from src/test/ui/const-generics/defaults/mismatch.min.stderr rename to src/test/ui/const-generics/defaults/mismatch.stderr index 4aa8401ab221..3c7f4fe3b28f 100644 --- a/src/test/ui/const-generics/defaults/mismatch.min.stderr +++ b/src/test/ui/const-generics/defaults/mismatch.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/mismatch.rs:12:28 + --> $DIR/mismatch.rs:9:28 | LL | let e: Example::<13> = (); | ------------- ^^ expected struct `Example`, found `()` @@ -10,7 +10,7 @@ LL | let e: Example::<13> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:15:34 + --> $DIR/mismatch.rs:12:34 | LL | let e: Example2:: = (); | ------------------- ^^ expected struct `Example2`, found `()` @@ -21,7 +21,7 @@ LL | let e: Example2:: = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:18:34 + --> $DIR/mismatch.rs:15:34 | LL | let e: Example3::<13, u32> = (); | ------------------- ^^ expected struct `Example3`, found `()` @@ -32,7 +32,7 @@ LL | let e: Example3::<13, u32> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:21:28 + --> $DIR/mismatch.rs:18:28 | LL | let e: Example3::<7> = (); | ------------- ^^ expected struct `Example3`, found `()` @@ -43,7 +43,7 @@ LL | let e: Example3::<7> = (); found unit type `()` error[E0308]: mismatched types - --> $DIR/mismatch.rs:24:28 + --> $DIR/mismatch.rs:21:28 | LL | let e: Example4::<7> = (); | ------------- ^^ expected struct `Example4`, found `()` diff --git a/src/test/ui/const-generics/defaults/needs-feature.min.stderr b/src/test/ui/const-generics/defaults/needs-feature.min.stderr index a4006203e4a2..158fa2ec1c8f 100644 --- a/src/test/ui/const-generics/defaults/needs-feature.min.stderr +++ b/src/test/ui/const-generics/defaults/needs-feature.min.stderr @@ -1,5 +1,5 @@ error: type parameters must be declared prior to const parameters - --> $DIR/needs-feature.rs:9:26 + --> $DIR/needs-feature.rs:7:26 | LL | struct A(T); | -----------------^----- help: reorder the parameters: lifetimes, then types, then consts: `` diff --git a/src/test/ui/const-generics/defaults/needs-feature.none.stderr b/src/test/ui/const-generics/defaults/needs-feature.none.stderr deleted file mode 100644 index a4006203e4a2..000000000000 --- a/src/test/ui/const-generics/defaults/needs-feature.none.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/needs-feature.rs:9:26 - | -LL | struct A(T); - | -----------------^----- help: reorder the parameters: lifetimes, then types, then consts: `` - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/defaults/needs-feature.rs b/src/test/ui/const-generics/defaults/needs-feature.rs index b58dee0712a7..9ba8184e0585 100644 --- a/src/test/ui/const-generics/defaults/needs-feature.rs +++ b/src/test/ui/const-generics/defaults/needs-feature.rs @@ -1,10 +1,8 @@ //[full] run-pass // Verifies that having generic parameters after constants is not permitted without the -// `const_generics` feature. +// `const_generics_defaults` feature. // revisions: min full - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![cfg_attr(full, feature(const_generics_defaults))] struct A(T); //[min]~^ ERROR type parameters must be declared prior diff --git a/src/test/ui/const-generics/defaults/simple-defaults.rs b/src/test/ui/const-generics/defaults/simple-defaults.rs index c003cb2c5a6e..bc01fe2656c9 100644 --- a/src/test/ui/const-generics/defaults/simple-defaults.rs +++ b/src/test/ui/const-generics/defaults/simple-defaults.rs @@ -1,9 +1,6 @@ // run-pass // Checks that type param defaults are allowed after const params. -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] #![allow(dead_code)] struct FixedOutput<'a, const N: usize, T=u32> { diff --git a/src/test/ui/const-generics/defaults/type-default-const-param-name.rs b/src/test/ui/const-generics/defaults/type-default-const-param-name.rs index e68075ee3c62..8b35c5860d94 100644 --- a/src/test/ui/const-generics/defaults/type-default-const-param-name.rs +++ b/src/test/ui/const-generics/defaults/type-default-const-param-name.rs @@ -1,8 +1,5 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] struct N; diff --git a/src/test/ui/const-generics/defaults/wrong-order.min.stderr b/src/test/ui/const-generics/defaults/wrong-order.min.stderr deleted file mode 100644 index eb0bcb282155..000000000000 --- a/src/test/ui/const-generics/defaults/wrong-order.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: generic parameters with a default must be trailing - --> $DIR/wrong-order.rs:6:10 - | -LL | struct A { - | ^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/defaults/wrong-order.rs b/src/test/ui/const-generics/defaults/wrong-order.rs index 88e9e96ba43f..33564a48448a 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.rs +++ b/src/test/ui/const-generics/defaults/wrong-order.rs @@ -1,7 +1,4 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] #![feature(const_generics_defaults)] -#![allow(incomplete_features)] struct A { //~^ ERROR generic parameters with a default must be trailing diff --git a/src/test/ui/const-generics/defaults/wrong-order.full.stderr b/src/test/ui/const-generics/defaults/wrong-order.stderr similarity index 83% rename from src/test/ui/const-generics/defaults/wrong-order.full.stderr rename to src/test/ui/const-generics/defaults/wrong-order.stderr index eb0bcb282155..47a2c6f3f419 100644 --- a/src/test/ui/const-generics/defaults/wrong-order.full.stderr +++ b/src/test/ui/const-generics/defaults/wrong-order.stderr @@ -1,5 +1,5 @@ error: generic parameters with a default must be trailing - --> $DIR/wrong-order.rs:6:10 + --> $DIR/wrong-order.rs:3:10 | LL | struct A { | ^ diff --git a/src/test/ui/const-generics/derive-debug-array-wrapper.rs b/src/test/ui/const-generics/derive-debug-array-wrapper.rs deleted file mode 100644 index ce1481d97e9b..000000000000 --- a/src/test/ui/const-generics/derive-debug-array-wrapper.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Check that deriving debug on struct with const is permitted. -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -#[derive(Debug)] -struct X { - a: [u32; N], -} - -fn main() {} diff --git a/src/test/ui/const-generics/different_byref.min.stderr b/src/test/ui/const-generics/different_byref.min.stderr deleted file mode 100644 index 93874fb1f5fe..000000000000 --- a/src/test/ui/const-generics/different_byref.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: `[usize; 1]` is forbidden as the type of a const generic parameter - --> $DIR/different_byref.rs:7:23 - | -LL | struct Const {} - | ^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/different_byref.rs b/src/test/ui/const-generics/different_byref.rs deleted file mode 100644 index 7977560ecbcf..000000000000 --- a/src/test/ui/const-generics/different_byref.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Check that different const types are different. -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -struct Const {} -//[min]~^ ERROR `[usize; 1]` is forbidden - -fn main() { - let mut x = Const::<{ [3] }> {}; - x = Const::<{ [4] }> {}; - //[full]~^ ERROR mismatched types -} diff --git a/src/test/ui/const-generics/different_byref_simple.min.stderr b/src/test/ui/const-generics/different_generic_args.full.stderr similarity index 89% rename from src/test/ui/const-generics/different_byref_simple.min.stderr rename to src/test/ui/const-generics/different_generic_args.full.stderr index 027e282c398d..a2dcc033627c 100644 --- a/src/test/ui/const-generics/different_byref_simple.min.stderr +++ b/src/test/ui/const-generics/different_generic_args.full.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/different_byref_simple.rs:11:9 + --> $DIR/different_generic_args.rs:11:9 | LL | u = ConstUsize::<4> {}; | ^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize` diff --git a/src/test/ui/const-generics/different_byref_simple.full.stderr b/src/test/ui/const-generics/different_generic_args.min.stderr similarity index 89% rename from src/test/ui/const-generics/different_byref_simple.full.stderr rename to src/test/ui/const-generics/different_generic_args.min.stderr index 027e282c398d..a2dcc033627c 100644 --- a/src/test/ui/const-generics/different_byref_simple.full.stderr +++ b/src/test/ui/const-generics/different_generic_args.min.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/different_byref_simple.rs:11:9 + --> $DIR/different_generic_args.rs:11:9 | LL | u = ConstUsize::<4> {}; | ^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize` diff --git a/src/test/ui/const-generics/different_byref_simple.rs b/src/test/ui/const-generics/different_generic_args.rs similarity index 65% rename from src/test/ui/const-generics/different_byref_simple.rs rename to src/test/ui/const-generics/different_generic_args.rs index b48189fc2cba..9ee0e0747c4c 100644 --- a/src/test/ui/const-generics/different_byref_simple.rs +++ b/src/test/ui/const-generics/different_generic_args.rs @@ -1,7 +1,7 @@ -// Check that different const types are different. +// Check that types with different const arguments are different. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] struct ConstUsize {} diff --git a/src/test/ui/const-generics/different_generic_args_array.rs b/src/test/ui/const-generics/different_generic_args_array.rs new file mode 100644 index 000000000000..cfe3a0a075a9 --- /dev/null +++ b/src/test/ui/const-generics/different_generic_args_array.rs @@ -0,0 +1,11 @@ +// Check that different const types are different. +#![feature(const_param_types)] +#![allow(incomplete_features)] + +struct Const {} + +fn main() { + let mut x = Const::<{ [3] }> {}; + x = Const::<{ [4] }> {}; + //~^ ERROR mismatched types +} diff --git a/src/test/ui/const-generics/different_byref.full.stderr b/src/test/ui/const-generics/different_generic_args_array.stderr similarity index 64% rename from src/test/ui/const-generics/different_byref.full.stderr rename to src/test/ui/const-generics/different_generic_args_array.stderr index d6b32323e2d0..c0709a996ce3 100644 --- a/src/test/ui/const-generics/different_byref.full.stderr +++ b/src/test/ui/const-generics/different_generic_args_array.stderr @@ -1,11 +1,11 @@ error[E0308]: mismatched types - --> $DIR/different_byref.rs:12:9 + --> $DIR/different_generic_args_array.rs:9:9 | LL | x = Const::<{ [4] }> {}; | ^^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize` | - = note: expected type `[3_usize]` - found type `[4_usize]` + = note: expected struct `Const<[3_usize]>` + found struct `Const<[4_usize]>` error: aborting due to previous error diff --git a/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs b/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs index eb272e3c9b49..6c4ee1af210b 100644 --- a/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs +++ b/src/test/ui/const-generics/dont-evaluate-array-len-on-err-1.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This tests that during error handling for the "trait not implemented" error diff --git a/src/test/ui/const-generics/dyn-supertraits.rs b/src/test/ui/const-generics/dyn-supertraits.rs index 73ed23521c30..3dee326a186e 100644 --- a/src/test/ui/const-generics/dyn-supertraits.rs +++ b/src/test/ui/const-generics/dyn-supertraits.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait Foo { fn myfun(&self) -> usize; diff --git a/src/test/ui/const-generics/closing-args-token.rs b/src/test/ui/const-generics/early/closing-args-token.rs similarity index 82% rename from src/test/ui/const-generics/closing-args-token.rs rename to src/test/ui/const-generics/early/closing-args-token.rs index a9b552ebed7a..cb4d6299ed65 100644 --- a/src/test/ui/const-generics/closing-args-token.rs +++ b/src/test/ui/const-generics/early/closing-args-token.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct S; struct T; diff --git a/src/test/ui/const-generics/closing-args-token.full.stderr b/src/test/ui/const-generics/early/closing-args-token.stderr similarity index 84% rename from src/test/ui/const-generics/closing-args-token.full.stderr rename to src/test/ui/const-generics/early/closing-args-token.stderr index f4bb1e422076..58fff3a85afe 100644 --- a/src/test/ui/const-generics/closing-args-token.full.stderr +++ b/src/test/ui/const-generics/early/closing-args-token.stderr @@ -1,5 +1,5 @@ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/closing-args-token.rs:10:9 + --> $DIR/closing-args-token.rs:5:9 | LL | S::<5 + 2 >> 7>; | ^^^^^ @@ -10,7 +10,7 @@ LL | S::<{ 5 + 2 } >> 7>; | + + error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:10:16 + --> $DIR/closing-args-token.rs:5:16 | LL | S::<5 + 2 >> 7>; | ^ ^ @@ -21,7 +21,7 @@ LL | S::<5 + 2 >> 7 && 7>; | ++++ error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:16:20 + --> $DIR/closing-args-token.rs:11:20 | LL | S::<{ 5 + 2 } >> 7>; | ^ ^ @@ -32,13 +32,13 @@ LL | S::<{ 5 + 2 } >> 7 && 7>; | ++++ error: expected expression, found `;` - --> $DIR/closing-args-token.rs:21:16 + --> $DIR/closing-args-token.rs:16:16 | LL | T::<0 >= 3>; | ^ expected expression error: comparison operators cannot be chained - --> $DIR/closing-args-token.rs:27:12 + --> $DIR/closing-args-token.rs:22:12 | LL | T::>= 2 > 0>; | ^^ ^ diff --git a/src/test/ui/const-generics/const-expression-parameter.rs b/src/test/ui/const-generics/early/const-expression-parameter.rs similarity index 71% rename from src/test/ui/const-generics/const-expression-parameter.rs rename to src/test/ui/const-generics/early/const-expression-parameter.rs index cb609a564161..4cf7ba86921c 100644 --- a/src/test/ui/const-generics/const-expression-parameter.rs +++ b/src/test/ui/const-generics/early/const-expression-parameter.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn i32_identity() -> i32 { 5 } diff --git a/src/test/ui/const-generics/const-expression-parameter.full.stderr b/src/test/ui/const-generics/early/const-expression-parameter.stderr similarity index 87% rename from src/test/ui/const-generics/const-expression-parameter.full.stderr rename to src/test/ui/const-generics/early/const-expression-parameter.stderr index 4ce0ecdf3aab..4ce1be25edb9 100644 --- a/src/test/ui/const-generics/const-expression-parameter.full.stderr +++ b/src/test/ui/const-generics/early/const-expression-parameter.stderr @@ -1,5 +1,5 @@ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-parameter.rs:15:20 + --> $DIR/const-expression-parameter.rs:10:20 | LL | i32_identity::<1 + 2>(); | ^^^^^ diff --git a/src/test/ui/const-generics/const-param-from-outer-fn.rs b/src/test/ui/const-generics/early/const-param-from-outer-fn.rs similarity index 54% rename from src/test/ui/const-generics/const-param-from-outer-fn.rs rename to src/test/ui/const-generics/early/const-param-from-outer-fn.rs index 27b9ca9c291e..c3b418ee3f8a 100644 --- a/src/test/ui/const-generics/const-param-from-outer-fn.rs +++ b/src/test/ui/const-generics/early/const-param-from-outer-fn.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn foo() { fn bar() -> u32 { X //~ ERROR can't use generic parameters from outer function diff --git a/src/test/ui/const-generics/const-param-from-outer-fn.full.stderr b/src/test/ui/const-generics/early/const-param-from-outer-fn.stderr similarity index 90% rename from src/test/ui/const-generics/const-param-from-outer-fn.full.stderr rename to src/test/ui/const-generics/early/const-param-from-outer-fn.stderr index c2ec7359c9f7..a9f9787d8759 100644 --- a/src/test/ui/const-generics/const-param-from-outer-fn.full.stderr +++ b/src/test/ui/const-generics/early/const-param-from-outer-fn.stderr @@ -1,5 +1,5 @@ error[E0401]: can't use generic parameters from outer function - --> $DIR/const-param-from-outer-fn.rs:8:9 + --> $DIR/const-param-from-outer-fn.rs:3:9 | LL | fn foo() { | - const parameter from outer function diff --git a/src/test/ui/const-generics/const-param-hygiene.rs b/src/test/ui/const-generics/early/const-param-hygiene.rs similarity index 71% rename from src/test/ui/const-generics/const-param-hygiene.rs rename to src/test/ui/const-generics/early/const-param-hygiene.rs index 9cafb05fbcb6..fd4e5b409eef 100644 --- a/src/test/ui/const-generics/const-param-hygiene.rs +++ b/src/test/ui/const-generics/early/const-param-hygiene.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] macro_rules! bar { ($($t:tt)*) => { impl $($t)* }; diff --git a/src/test/ui/const-generics/const-param-shadowing.rs b/src/test/ui/const-generics/early/const-param-shadowing.rs similarity index 100% rename from src/test/ui/const-generics/const-param-shadowing.rs rename to src/test/ui/const-generics/early/const-param-shadowing.rs diff --git a/src/test/ui/const-generics/const-param-shadowing.stderr b/src/test/ui/const-generics/early/const-param-shadowing.stderr similarity index 100% rename from src/test/ui/const-generics/const-param-shadowing.stderr rename to src/test/ui/const-generics/early/const-param-shadowing.stderr diff --git a/src/test/ui/const-generics/diagnostics.rs b/src/test/ui/const-generics/early/invalid-const-arguments.rs similarity index 86% rename from src/test/ui/const-generics/diagnostics.rs rename to src/test/ui/const-generics/early/invalid-const-arguments.rs index 1581af5ab275..6619c9758859 100644 --- a/src/test/ui/const-generics/diagnostics.rs +++ b/src/test/ui/const-generics/early/invalid-const-arguments.rs @@ -1,6 +1,4 @@ #![crate_type="lib"] -#![feature(min_const_generics)] -#![allow(incomplete_features)] struct A; trait Foo {} diff --git a/src/test/ui/const-generics/diagnostics.stderr b/src/test/ui/const-generics/early/invalid-const-arguments.stderr similarity index 89% rename from src/test/ui/const-generics/diagnostics.stderr rename to src/test/ui/const-generics/early/invalid-const-arguments.stderr index dd37d4e7a85a..b46e7e24f492 100644 --- a/src/test/ui/const-generics/diagnostics.stderr +++ b/src/test/ui/const-generics/early/invalid-const-arguments.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `N` in this scope - --> $DIR/diagnostics.rs:7:16 + --> $DIR/invalid-const-arguments.rs:5:16 | LL | struct A; | ---------------------- similarly named struct `A` defined here @@ -17,7 +17,7 @@ LL | impl Foo for A {} | +++ error[E0412]: cannot find type `T` in this scope - --> $DIR/diagnostics.rs:16:32 + --> $DIR/invalid-const-arguments.rs:14:32 | LL | struct A; | ---------------------- similarly named struct `A` defined here @@ -35,7 +35,7 @@ LL | impl Foo for C {} | +++ error[E0747]: unresolved item provided when a constant was expected - --> $DIR/diagnostics.rs:7:16 + --> $DIR/invalid-const-arguments.rs:5:16 | LL | impl Foo for A {} | ^ @@ -46,7 +46,7 @@ LL | impl Foo for A<{ N }> {} | + + error[E0747]: type provided when a constant was expected - --> $DIR/diagnostics.rs:12:19 + --> $DIR/invalid-const-arguments.rs:10:19 | LL | impl Foo for B {} | ^ @@ -57,7 +57,7 @@ LL | impl Foo for B {} | ~~~~~~~~~~~ error[E0747]: unresolved item provided when a constant was expected - --> $DIR/diagnostics.rs:16:32 + --> $DIR/invalid-const-arguments.rs:14:32 | LL | impl Foo for C {} | ^ diff --git a/src/test/ui/const-generics/macro_rules-braces.rs b/src/test/ui/const-generics/early/macro_rules-braces.rs similarity index 67% rename from src/test/ui/const-generics/macro_rules-braces.rs rename to src/test/ui/const-generics/early/macro_rules-braces.rs index 605a10880bbb..0ae914635995 100644 --- a/src/test/ui/const-generics/macro_rules-braces.rs +++ b/src/test/ui/const-generics/early/macro_rules-braces.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - mod m { pub const P: usize = 0; } @@ -12,42 +8,42 @@ fn test() { struct Foo; macro_rules! foo { ($x:expr) => { - [u8; $x] //[full]~ ERROR constant expression depends + [u8; $x] } } macro_rules! bar { ($x:expr) => { - [u8; { $x }] //[full]~ ERROR constant expression depends + [u8; { $x }] } } macro_rules! baz { ( $x:expr) => { - Foo<$x> //[full]~ ERROR constant expression depends + Foo<$x> } } macro_rules! biz { ($x:expr) => { - Foo<{ $x }> //[full]~ ERROR constant expression depends + Foo<{ $x }> }; } let _: foo!(N); let _: foo!({ N }); - let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not + let _: foo!({{ N }}); //~ ERROR generic parameters may not let _: foo!(Q); let _: foo!(m::P); let _: bar!(N); - let _: bar!({ N }); //[min]~ ERROR generic parameters may not + let _: bar!({ N }); //~ ERROR generic parameters may not let _: bar!(Q); let _: bar!(m::P); let _: baz!(N); let _: baz!({ N }); - let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not + let _: baz!({{ N }}); //~ ERROR generic parameters may not let _: baz!(Q); let _: baz!({ m::P }); let _: baz!(m::P); //~ ERROR expressions must be enclosed in braces let _: biz!(N); - let _: biz!({ N }); //[min]~ ERROR generic parameters may not + let _: biz!({ N }); //~ ERROR generic parameters may not let _: biz!(Q); let _: biz!(m::P); let _: foo!(3); diff --git a/src/test/ui/const-generics/macro_rules-braces.min.stderr b/src/test/ui/const-generics/early/macro_rules-braces.stderr similarity index 68% rename from src/test/ui/const-generics/macro_rules-braces.min.stderr rename to src/test/ui/const-generics/early/macro_rules-braces.stderr index f6d8020f3fbb..49382dbf0bd5 100644 --- a/src/test/ui/const-generics/macro_rules-braces.min.stderr +++ b/src/test/ui/const-generics/early/macro_rules-braces.stderr @@ -1,5 +1,5 @@ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/macro_rules-braces.rs:48:17 + --> $DIR/macro_rules-braces.rs:44:17 | LL | let _: baz!(m::P); | ^^^^ @@ -10,7 +10,7 @@ LL | let _: baz!({ m::P }); | + + error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/macro_rules-braces.rs:68:17 + --> $DIR/macro_rules-braces.rs:64:17 | LL | let _: baz!(10 + 7); | ^^^^^^ @@ -21,40 +21,40 @@ LL | let _: baz!({ 10 + 7 }); | + + error: generic parameters may not be used in const operations - --> $DIR/macro_rules-braces.rs:36:20 + --> $DIR/macro_rules-braces.rs:32:20 | LL | let _: foo!({{ N }}); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/macro_rules-braces.rs:40:19 + --> $DIR/macro_rules-braces.rs:36:19 | LL | let _: bar!({ N }); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/macro_rules-braces.rs:45:20 + --> $DIR/macro_rules-braces.rs:41:20 | LL | let _: baz!({{ N }}); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/macro_rules-braces.rs:50:19 + --> $DIR/macro_rules-braces.rs:46:19 | LL | let _: biz!({ N }); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 6 previous errors diff --git a/src/test/ui/const-generics/exhaustive-value.full.stderr b/src/test/ui/const-generics/exhaustive-value.full.stderr deleted file mode 100644 index 4e89e4a3b17e..000000000000 --- a/src/test/ui/const-generics/exhaustive-value.full.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/exhaustive-value.rs:266:5 - | -LL | <() as Foo>::test() - | ^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` - | - = help: the following implementations were found: - <() as Foo<0_u8>> - <() as Foo<100_u8>> - <() as Foo<101_u8>> - <() as Foo<102_u8>> - and 252 others -note: required by `Foo::test` - --> $DIR/exhaustive-value.rs:6:5 - | -LL | fn test() {} - | ^^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/exhaustive-value.rs b/src/test/ui/const-generics/exhaustive-value.rs index 921f9a467078..778d498343e0 100644 --- a/src/test/ui/const-generics/exhaustive-value.rs +++ b/src/test/ui/const-generics/exhaustive-value.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait Foo { fn test() {} } diff --git a/src/test/ui/const-generics/exhaustive-value.min.stderr b/src/test/ui/const-generics/exhaustive-value.stderr similarity index 88% rename from src/test/ui/const-generics/exhaustive-value.min.stderr rename to src/test/ui/const-generics/exhaustive-value.stderr index 4e89e4a3b17e..0c6aced4bc22 100644 --- a/src/test/ui/const-generics/exhaustive-value.min.stderr +++ b/src/test/ui/const-generics/exhaustive-value.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/exhaustive-value.rs:266:5 + --> $DIR/exhaustive-value.rs:262:5 | LL | <() as Foo>::test() | ^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` @@ -11,7 +11,7 @@ LL | <() as Foo>::test() <() as Foo<102_u8>> and 252 others note: required by `Foo::test` - --> $DIR/exhaustive-value.rs:6:5 + --> $DIR/exhaustive-value.rs:2:5 | LL | fn test() {} | ^^^^^^^^^ diff --git a/src/test/ui/const-generics/fn-const-param-call.rs b/src/test/ui/const-generics/fn-const-param-call.rs index 70a104e22227..5cd18f6d3598 100644 --- a/src/test/ui/const-generics/fn-const-param-call.rs +++ b/src/test/ui/const-generics/fn-const-param-call.rs @@ -1,7 +1,7 @@ // Check that functions cannot be used as const parameters. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] fn function() -> u32 { diff --git a/src/test/ui/const-generics/fn-const-param-infer.rs b/src/test/ui/const-generics/fn-const-param-infer.rs index d090479d4c30..596101596952 100644 --- a/src/test/ui/const-generics/fn-const-param-infer.rs +++ b/src/test/ui/const-generics/fn-const-param-infer.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Checked bool>; diff --git a/src/test/ui/const-generics/fn-taking-const-generic-array.rs b/src/test/ui/const-generics/fn-taking-const-generic-array.rs deleted file mode 100644 index 58c1b95893e7..000000000000 --- a/src/test/ui/const-generics/fn-taking-const-generic-array.rs +++ /dev/null @@ -1,17 +0,0 @@ -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -use std::fmt::Display; - -fn print_slice(slice: &[T; N]) { - for x in slice.iter() { - println!("{}", x); - } -} - -fn main() { - print_slice(&[1, 2, 3]); -} diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.min.stderr b/src/test/ui/const-generics/forbid-non-structural_match-types.min.stderr deleted file mode 100644 index 80eac994d55c..000000000000 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.min.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: `A` is forbidden as the type of a const generic parameter - --> $DIR/forbid-non-structural_match-types.rs:9:19 - | -LL | struct B; // ok - | ^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: `C` is forbidden as the type of a const generic parameter - --> $DIR/forbid-non-structural_match-types.rs:14:19 - | -LL | struct D; - | ^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error[E0741]: `C` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter - --> $DIR/forbid-non-structural_match-types.rs:14:19 - | -LL | struct D; - | ^ `C` doesn't derive both `PartialEq` and `Eq` - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0741`. diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.rs b/src/test/ui/const-generics/forbid-non-structural_match-types.rs index 0fdb3ed4a5a7..7884008b858b 100644 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.rs +++ b/src/test/ui/const-generics/forbid-non-structural_match-types.rs @@ -1,17 +1,13 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![feature(const_param_types)] +#![allow(incomplete_features)] #[derive(PartialEq, Eq)] struct A; struct B; // ok -//[min]~^ ERROR `A` is forbidden struct C; struct D; //~ ERROR `C` must be annotated with `#[derive(PartialEq, Eq)]` -//[min]~^ ERROR `C` is forbidden fn main() {} diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.full.stderr b/src/test/ui/const-generics/forbid-non-structural_match-types.stderr similarity index 85% rename from src/test/ui/const-generics/forbid-non-structural_match-types.full.stderr rename to src/test/ui/const-generics/forbid-non-structural_match-types.stderr index 5c0f17537fa5..81b9bdfbd602 100644 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.full.stderr +++ b/src/test/ui/const-generics/forbid-non-structural_match-types.stderr @@ -1,5 +1,5 @@ error[E0741]: `C` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter - --> $DIR/forbid-non-structural_match-types.rs:14:19 + --> $DIR/forbid-non-structural_match-types.rs:11:19 | LL | struct D; | ^ `C` doesn't derive both `PartialEq` and `Eq` diff --git a/src/test/ui/const-generics/foreign-item-const-parameter.min.stderr b/src/test/ui/const-generics/foreign-item-const-parameter.min.stderr deleted file mode 100644 index b827e482977b..000000000000 --- a/src/test/ui/const-generics/foreign-item-const-parameter.min.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0044]: foreign items may not have const parameters - --> $DIR/foreign-item-const-parameter.rs:7:5 - | -LL | fn foo(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't have const parameters - | - = help: replace the const parameters with concrete consts - -error[E0044]: foreign items may not have type or const parameters - --> $DIR/foreign-item-const-parameter.rs:9:5 - | -LL | fn bar(_: T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have type or const parameters - | - = help: replace the type or const parameters with concrete types or consts - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0044`. diff --git a/src/test/ui/const-generics/foreign-item-const-parameter.rs b/src/test/ui/const-generics/foreign-item-const-parameter.rs index 83caa89f0330..4fe377b5964f 100644 --- a/src/test/ui/const-generics/foreign-item-const-parameter.rs +++ b/src/test/ui/const-generics/foreign-item-const-parameter.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - extern "C" { fn foo(); //~ ERROR foreign items may not have const parameters diff --git a/src/test/ui/const-generics/foreign-item-const-parameter.full.stderr b/src/test/ui/const-generics/foreign-item-const-parameter.stderr similarity index 86% rename from src/test/ui/const-generics/foreign-item-const-parameter.full.stderr rename to src/test/ui/const-generics/foreign-item-const-parameter.stderr index b827e482977b..b02db8700cff 100644 --- a/src/test/ui/const-generics/foreign-item-const-parameter.full.stderr +++ b/src/test/ui/const-generics/foreign-item-const-parameter.stderr @@ -1,5 +1,5 @@ error[E0044]: foreign items may not have const parameters - --> $DIR/foreign-item-const-parameter.rs:7:5 + --> $DIR/foreign-item-const-parameter.rs:2:5 | LL | fn foo(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't have const parameters @@ -7,7 +7,7 @@ LL | fn foo(); = help: replace the const parameters with concrete consts error[E0044]: foreign items may not have type or const parameters - --> $DIR/foreign-item-const-parameter.rs:9:5 + --> $DIR/foreign-item-const-parameter.rs:4:5 | LL | fn bar(_: T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have type or const parameters diff --git a/src/test/ui/const-generics/generic-function-call-in-array-length.full.stderr b/src/test/ui/const-generics/generic-function-call-in-array-length.full.stderr deleted file mode 100644 index 2d19a58a1457..000000000000 --- a/src/test/ui/const-generics/generic-function-call-in-array-length.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/generic-function-call-in-array-length.rs:8:29 - | -LL | fn bar() -> [u32; foo(N)] { - | ^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr b/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr deleted file mode 100644 index dd4de9bc1b7a..000000000000 --- a/src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/generic-function-call-in-array-length.rs:8:39 - | -LL | fn bar() -> [u32; foo(N)] { - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/generic-function-call-in-array-length.rs:11:13 - | -LL | [0; foo(N)] - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/generic-function-call-in-array-length.rs b/src/test/ui/const-generics/generic-function-call-in-array-length.rs deleted file mode 100644 index a6d2bbd17eaa..000000000000 --- a/src/test/ui/const-generics/generic-function-call-in-array-length.rs +++ /dev/null @@ -1,15 +0,0 @@ -// revisions: full min - -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - -const fn foo(n: usize) -> usize { n * 2 } - -fn bar() -> [u32; foo(N)] { - //[min]~^ ERROR generic parameters may not be used in const operations - //[full]~^^ ERROR constant expression depends on a generic parameter - [0; foo(N)] - //[min]~^ ERROR generic parameters may not be used in const operations -} - -fn main() {} diff --git a/src/test/ui/const-generics/generic-param-mismatch.min.stderr b/src/test/ui/const-generics/generic-param-mismatch.min.stderr deleted file mode 100644 index aff8780fb0d1..000000000000 --- a/src/test/ui/const-generics/generic-param-mismatch.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/generic-param-mismatch.rs:6:5 - | -LL | fn test() -> [u8; M] { - | ------- expected `[u8; M]` because of return type -LL | [0; N] - | ^^^^^^ expected `M`, found `N` - | - = note: expected array `[u8; M]` - found array `[u8; N]` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/generic-param-mismatch.rs b/src/test/ui/const-generics/generic-param-mismatch.rs index 22fffe47dcc2..2e201e50a64e 100644 --- a/src/test/ui/const-generics/generic-param-mismatch.rs +++ b/src/test/ui/const-generics/generic-param-mismatch.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - fn test() -> [u8; M] { [0; N] //~ ERROR mismatched types } diff --git a/src/test/ui/const-generics/generic-param-mismatch.full.stderr b/src/test/ui/const-generics/generic-param-mismatch.stderr similarity index 91% rename from src/test/ui/const-generics/generic-param-mismatch.full.stderr rename to src/test/ui/const-generics/generic-param-mismatch.stderr index aff8780fb0d1..d0776d49d71b 100644 --- a/src/test/ui/const-generics/generic-param-mismatch.full.stderr +++ b/src/test/ui/const-generics/generic-param-mismatch.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/generic-param-mismatch.rs:6:5 + --> $DIR/generic-param-mismatch.rs:2:5 | LL | fn test() -> [u8; M] { | ------- expected `[u8; M]` because of return type diff --git a/src/test/ui/const-generics/generic-sum-in-array-length.full.stderr b/src/test/ui/const-generics/generic-sum-in-array-length.full.stderr deleted file mode 100644 index c13882e7fe11..000000000000 --- a/src/test/ui/const-generics/generic-sum-in-array-length.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/generic-sum-in-array-length.rs:6:45 - | -LL | fn foo(bar: [usize; A + B]) {} - | ^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr b/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr deleted file mode 100644 index d80d38cf8b10..000000000000 --- a/src/test/ui/const-generics/generic-sum-in-array-length.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/generic-sum-in-array-length.rs:6:53 - | -LL | fn foo(bar: [usize; A + B]) {} - | ^ cannot perform const operation using `A` - | - = help: const parameters may only be used as standalone arguments, i.e. `A` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/generic-sum-in-array-length.rs:6:57 - | -LL | fn foo(bar: [usize; A + B]) {} - | ^ cannot perform const operation using `B` - | - = help: const parameters may only be used as standalone arguments, i.e. `B` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/generic-sum-in-array-length.rs b/src/test/ui/const-generics/generic-sum-in-array-length.rs deleted file mode 100644 index 7ee0394ba14c..000000000000 --- a/src/test/ui/const-generics/generic-sum-in-array-length.rs +++ /dev/null @@ -1,11 +0,0 @@ -// revisions: full min - -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - -fn foo(bar: [usize; A + B]) {} -//[min]~^ ERROR generic parameters may not be used in const operations -//[min]~| ERROR generic parameters may not be used in const operations -//[full]~^^^ ERROR constant expression depends on a generic parameter - -fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs index 4d7c4e003d00..06f00de13a30 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-1.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo([u8; N as usize]) diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs index 08b46c4c4a35..3b5b87b2b3d6 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.rs @@ -1,4 +1,4 @@ -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Evaluatable {} diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs index 0cb5410ed26e..7561ae2febbd 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-3.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs index 66afe517835d..184263f899ab 100644 --- a/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs +++ b/src/test/ui/const-generics/generic_const_exprs/abstract-const-as-cast-4.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Trait {} diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr new file mode 100644 index 000000000000..deb6f3bd12c1 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr @@ -0,0 +1,18 @@ +error: unconstrained generic constant + --> $DIR/array-size-in-generic-struct-param.rs:8:38 + | +LL | struct ArithArrayLen([u32; 0 + N]); + | ^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); 0 + N]:` + +error: overly complex generic constant + --> $DIR/array-size-in-generic-struct-param.rs:19:15 + | +LL | arr: [u8; CFG.arr_size], + | ^^^^^^^^^^^^ unsupported projection + | + = help: consider moving this anonymous constant into a `const` function + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr similarity index 80% rename from src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr index 5312a22c2289..22e7ab1f7b12 100644 --- a/src/test/ui/const-generics/array-size-in-generic-struct-param.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr @@ -5,7 +5,7 @@ LL | struct ArithArrayLen([u32; 0 + N]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/array-size-in-generic-struct-param.rs:19:15 @@ -14,7 +14,7 @@ LL | arr: [u8; CFG.arr_size], | ^^^ cannot perform const operation using `CFG` | = help: const parameters may only be used as standalone arguments, i.e. `CFG` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: `Config` is forbidden as the type of a const generic parameter --> $DIR/array-size-in-generic-struct-param.rs:17:21 @@ -23,7 +23,7 @@ LL | struct B { | ^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 3 previous errors diff --git a/src/test/ui/const-generics/array-size-in-generic-struct-param.rs b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs similarity index 78% rename from src/test/ui/const-generics/array-size-in-generic-struct-param.rs rename to src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs index cd0a9742cd1a..68201b77dbf1 100644 --- a/src/test/ui/const-generics/array-size-in-generic-struct-param.rs +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs @@ -1,12 +1,12 @@ // Tests that array sizes that depend on const-params are checked using `ConstEvaluatable`. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs, const_param_types))] #![cfg_attr(full, allow(incomplete_features))] #[allow(dead_code)] struct ArithArrayLen([u32; 0 + N]); -//[full]~^ ERROR constant expression depends on a generic parameter +//[full]~^ ERROR unconstrained generic constant //[min]~^^ ERROR generic parameters may not be used in const operations #[derive(PartialEq, Eq)] @@ -17,7 +17,7 @@ struct Config { struct B { //[min]~^ ERROR `Config` is forbidden arr: [u8; CFG.arr_size], - //[full]~^ ERROR constant expression depends on a generic parameter + //[full]~^ ERROR overly complex generic constant //[min]~^^ ERROR generic parameters may not be used in const operations } diff --git a/src/test/ui/const_evaluatable/associated-const.rs b/src/test/ui/const-generics/generic_const_exprs/associated-const.rs similarity index 100% rename from src/test/ui/const_evaluatable/associated-const.rs rename to src/test/ui/const-generics/generic_const_exprs/associated-const.rs diff --git a/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs index 967d1b0f2acb..4d89f188ad77 100644 --- a/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs +++ b/src/test/ui/const-generics/generic_const_exprs/associated-consts.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub trait BlockCipher { diff --git a/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs index ce92f908e067..15d618caef4b 100644 --- a/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs +++ b/src/test/ui/const-generics/generic_const_exprs/auxiliary/const_evaluatable_lib.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub fn test1() -> [u8; std::mem::size_of::() - 1] diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.rs b/src/test/ui/const-generics/generic_const_exprs/closures.rs index c682fee4fab6..847843fe1a63 100644 --- a/src/test/ui/const-generics/generic_const_exprs/closures.rs +++ b/src/test/ui/const-generics/generic_const_exprs/closures.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test() -> [u8; N + (|| 42)()] {} //~^ ERROR overly complex generic constant diff --git a/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs index a8388fc541ca..dfc69e0b0689 100644 --- a/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate.rs @@ -1,6 +1,6 @@ // aux-build:const_evaluatable_lib.rs // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs index 4e3aeec9c5de..b08fffd6922b 100644 --- a/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs +++ b/src/test/ui/const-generics/generic_const_exprs/cross_crate_predicate.rs @@ -1,5 +1,5 @@ // aux-build:const_evaluatable_lib.rs -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate const_evaluatable_lib; diff --git a/src/test/ui/const-generics/generic_const_exprs/different-fn.rs b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs index 0dcafc6a789c..e8bc703bda61 100644 --- a/src/test/ui/const-generics/generic_const_exprs/different-fn.rs +++ b/src/test/ui/const-generics/generic_const_exprs/different-fn.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/generic_const_exprs/division.rs b/src/test/ui/const-generics/generic_const_exprs/division.rs index c10ed834f0f7..098fa9e0447a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/division.rs +++ b/src/test/ui/const-generics/generic_const_exprs/division.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn with_bound() where [u8; N / 2]: Sized { diff --git a/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs index c99cfa6f52ff..3543960c3ebd 100644 --- a/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/dont-eagerly-error-in-is-const-evaluatable.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_generics)] #![feature(generic_const_exprs)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs index 45f63bad6fee..077f77aa0f40 100644 --- a/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs +++ b/src/test/ui/const-generics/generic_const_exprs/drop_impl.rs @@ -1,5 +1,5 @@ //check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo diff --git a/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs index 3c6f01b6160e..e4111157ecdb 100644 --- a/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs +++ b/src/test/ui/const-generics/generic_const_exprs/elaborate-trait-pred.rs @@ -1,7 +1,7 @@ // run-pass // Test that we use the elaborated predicates from traits // to satisfy const evaluatable predicates. -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs index f9d78fd708c8..80d0662f1f49 100644 --- a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -1,5 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] pub struct Const; diff --git a/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs index 8acb7aaf34ee..340e35e1c65d 100644 --- a/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/evaluated-to-ambig.rs @@ -4,7 +4,7 @@ // only contain generic parameters. This is incorrect as trying to unify `N > 1` with `M > 1` // should fail. #![allow(incomplete_features)] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] enum Assert {} trait IsTrue {} diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr deleted file mode 100644 index 26dfcff5d3e3..000000000000 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/feature-gate-generic_const_exprs.rs:8:30 - | -LL | fn test() -> Arr where Arr: Default { - | ^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs index f49ca0251aa9..10ab2fd867cf 100644 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.rs @@ -1,12 +1,7 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - type Arr = [u8; N - 1]; -//[min]~^ ERROR generic parameters may not be used in const operations +//~^ ERROR generic parameters may not be used in const operations fn test() -> Arr where Arr: Default { - //[full]~^ ERROR constant expression depends Default::default() } diff --git a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr similarity index 64% rename from src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr index fccd6ea144b0..2d60ebaa83a1 100644 --- a/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/feature-gate-generic_const_exprs.stderr @@ -1,11 +1,11 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-generic_const_exprs.rs:5:33 + --> $DIR/feature-gate-generic_const_exprs.rs:1:33 | LL | type Arr = [u8; N - 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/generic_const_exprs/fn_call.rs b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs index a1b2a52a5a12..cbe4277df568 100644 --- a/src/test/ui/const-generics/generic_const_exprs/fn_call.rs +++ b/src/test/ui/const-generics/generic_const_exprs/fn_call.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] const fn test_me(a: usize, b: usize) -> usize { diff --git a/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs index db097567a152..90953145944f 100644 --- a/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig-fail.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn test() -> [u8; N - 1] { diff --git a/src/test/ui/const-generics/generic_const_exprs/from-sig.rs b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs index d2e672bae4d8..28de4f864671 100644 --- a/src/test/ui/const-generics/generic_const_exprs/from-sig.rs +++ b/src/test/ui/const-generics/generic_const_exprs/from-sig.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const_evaluatable/function-call.rs b/src/test/ui/const-generics/generic_const_exprs/function-call.rs similarity index 100% rename from src/test/ui/const_evaluatable/function-call.rs rename to src/test/ui/const-generics/generic_const_exprs/function-call.rs diff --git a/src/test/ui/const_evaluatable/function-call.stderr b/src/test/ui/const-generics/generic_const_exprs/function-call.stderr similarity index 100% rename from src/test/ui/const_evaluatable/function-call.stderr rename to src/test/ui/const-generics/generic_const_exprs/function-call.stderr diff --git a/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs index d3f140755f7a..7120d6ee2518 100644 --- a/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/impl-bounds.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::mem::size_of; diff --git a/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs index 4c8fc7a3554c..b8058c252e77 100644 --- a/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs +++ b/src/test/ui/const-generics/generic_const_exprs/infer-too-generic.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] use std::{mem, ptr}; diff --git a/src/test/ui/const-generics/issues/issue-62504.full.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr similarity index 79% rename from src/test/ui/const-generics/issues/issue-62504.full.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr index efbcdc3d2b78..f2ae361dc81d 100644 --- a/src/test/ui/const-generics/issues/issue-62504.full.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-62504.full.stderr @@ -7,13 +7,13 @@ LL | ArrayHolder([0; Self::SIZE]) = note: expected type `X` found type `Self::SIZE` -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/issue-62504.rs:18:25 | LL | ArrayHolder([0; Self::SIZE]) | ^^^^^^^^^^ | - = note: this may fail depending on what value the parameter takes + = help: try adding a `where` bound using this expression: `where [(); Self::SIZE]:` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-62504.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-62504.min.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-62504.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-62504.min.stderr diff --git a/src/test/ui/const-generics/issues/issue-62504.rs b/src/test/ui/const-generics/generic_const_exprs/issue-62504.rs similarity index 66% rename from src/test/ui/const-generics/issues/issue-62504.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-62504.rs index 1b70cd1c3766..a97f4b8ff313 100644 --- a/src/test/ui/const-generics/issues/issue-62504.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-62504.rs @@ -1,6 +1,6 @@ // revisions: full min #![allow(incomplete_features)] -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] trait HasSize { @@ -16,8 +16,9 @@ struct ArrayHolder([u32; X]); impl ArrayHolder { pub const fn new() -> Self { ArrayHolder([0; Self::SIZE]) - //~^ ERROR constant expression depends on a generic parameter - //~| ERROR mismatched types + //~^ ERROR mismatched types + //[full]~^^ ERROR unconstrained generic constant + //[min]~^^^ ERROR constant expression depends on a generic parameter } } diff --git a/src/test/ui/const-generics/issues/issue-69654.rs b/src/test/ui/const-generics/generic_const_exprs/issue-69654.rs similarity index 90% rename from src/test/ui/const-generics/issues/issue-69654.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-69654.rs index b1214b12a144..9b36699bbf11 100644 --- a/src/test/ui/const-generics/issues/issue-69654.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-69654.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Bar {} diff --git a/src/test/ui/const-generics/issues/issue-69654.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-69654.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-69654.stderr diff --git a/src/test/ui/const-generics/issues/issue-72787.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr similarity index 77% rename from src/test/ui/const-generics/issues/issue-72787.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr index 6314650e0d8b..3c7a740e8434 100644 --- a/src/test/ui/const-generics/issues/issue-72787.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr @@ -1,20 +1,20 @@ error: generic parameters may not be used in const operations - --> $DIR/issue-72787.rs:10:17 + --> $DIR/issue-72787.rs:11:17 | LL | Condition<{ LHS <= RHS }>: True | ^^^ cannot perform const operation using `LHS` | = help: const parameters may only be used as standalone arguments, i.e. `LHS` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/issue-72787.rs:10:24 + --> $DIR/issue-72787.rs:11:24 | LL | Condition<{ LHS <= RHS }>: True | ^^^ cannot perform const operation using `RHS` | = help: const parameters may only be used as standalone arguments, i.e. `RHS` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-72787.rs:25:25 @@ -23,7 +23,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `I` | = help: const parameters may only be used as standalone arguments, i.e. `I` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/issue-72787.rs:25:36 @@ -32,7 +32,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, | ^ cannot perform const operation using `J` | = help: const parameters may only be used as standalone arguments, i.e. `J` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0283]: type annotations needed --> $DIR/issue-72787.rs:21:26 @@ -42,7 +42,7 @@ LL | IsLessOrEqual: True, | = note: cannot satisfy `IsLessOrEqual: True` note: required by a bound in `True` - --> $DIR/issue-72787.rs:7:1 + --> $DIR/issue-72787.rs:8:1 | LL | pub trait True {} | ^^^^^^^^^^^^^^ required by this bound in `True` @@ -55,7 +55,7 @@ LL | IsLessOrEqual: True, | = note: cannot satisfy `IsLessOrEqual: True` note: required by a bound in `True` - --> $DIR/issue-72787.rs:7:1 + --> $DIR/issue-72787.rs:8:1 | LL | pub trait True {} | ^^^^^^^^^^^^^^ required by this bound in `True` diff --git a/src/test/ui/const-generics/issues/issue-72787.rs b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs similarity index 63% rename from src/test/ui/const-generics/issues/issue-72787.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-72787.rs index 16bc9470470f..77ad57f0640f 100644 --- a/src/test/ui/const-generics/issues/issue-72787.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72787.rs @@ -1,5 +1,6 @@ +// [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] pub struct IsLessOrEqual; @@ -8,8 +9,7 @@ pub trait True {} impl True for IsLessOrEqual where Condition<{ LHS <= RHS }>: True -//[full]~^ Error constant expression depends on a generic parameter -//[min]~^^ Error generic parameters may not be used in const operations +//[min]~^ Error generic parameters may not be used in const operations //[min]~| Error generic parameters may not be used in const operations { } @@ -23,11 +23,7 @@ where //[min]~| Error type annotations needed [E0283] IsLessOrEqual: True, IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, -//[full]~^ constant expression depends on a generic parameter -//[full]~| constant expression depends on a generic parameter -//[full]~| constant expression depends on a generic parameter -//[full]~| constant expression depends on a generic parameter -//[min]~^^^^^ Error generic parameters may not be used in const operations +//[min]~^ Error generic parameters may not be used in const operations //[min]~| Error generic parameters may not be used in const operations // Condition<{ 8 - I <= 8 - J }>: True, { diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr new file mode 100644 index 000000000000..d536f6fd1d55 --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/issue-72819-generic-in-const-eval.rs:20:12 + | +LL | let x: Arr<{usize::MAX}> = Arr {}; + | ^^^^^^^^^^^^^^^^^ expected `false`, found `true` + | + = note: expected type `false` + found type `true` + +error[E0308]: mismatched types + --> $DIR/issue-72819-generic-in-const-eval.rs:20:32 + | +LL | let x: Arr<{usize::MAX}> = Arr {}; + | ^^^ expected `false`, found `true` + | + = note: expected type `false` + found type `true` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr similarity index 75% rename from src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr index 70adabea5610..42671412fa77 100644 --- a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.min.stderr @@ -5,7 +5,7 @@ LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.rs b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs similarity index 66% rename from src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs index f612d8bd3f6b..7a5aa9e47d49 100644 --- a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.rs @@ -1,13 +1,12 @@ // Regression test for #72819: ICE due to failure in resolving the const generic in `Arr`'s type // bounds. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] struct Arr where Assert::<{N < usize::MAX / 2}>: IsTrue, -//[full]~^ ERROR constant expression depends on a generic parameter -//[min]~^^ ERROR generic parameters may not be used in const operations +//[min]~^ ERROR generic parameters may not be used in const operations { } @@ -19,4 +18,6 @@ impl IsTrue for Assert {} fn main() { let x: Arr<{usize::MAX}> = Arr {}; + //[full]~^ ERROR mismatched types + //[full]~| ERROR mismatched types } diff --git a/src/test/ui/const-generics/issues/issue-73899.rs b/src/test/ui/const-generics/generic_const_exprs/issue-73899.rs similarity index 93% rename from src/test/ui/const-generics/issues/issue-73899.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-73899.rs index ece8eb2c9ec9..d1ab1be04733 100644 --- a/src/test/ui/const-generics/issues/issue-73899.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-73899.rs @@ -1,6 +1,5 @@ // run-pass #![feature(generic_const_exprs)] -#![feature(const_generics)] #![allow(incomplete_features)] trait Foo {} diff --git a/src/test/ui/const-generics/issues/issue-74634.rs b/src/test/ui/const-generics/generic_const_exprs/issue-74634.rs similarity index 83% rename from src/test/ui/const-generics/issues/issue-74634.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-74634.rs index 0f23fa92c367..cd1f7a9da687 100644 --- a/src/test/ui/const-generics/issues/issue-74634.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-74634.rs @@ -1,4 +1,5 @@ -#![feature(const_generics)] +// check-pass +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait If {} @@ -12,7 +13,7 @@ struct True; struct False; impl IsZero for () -where (): If<{N == 0}> { //~ERROR constant expression +where (): If<{N == 0}> { type Answer = True; } diff --git a/src/test/ui/const-generics/issues/issue-76595.rs b/src/test/ui/const-generics/generic_const_exprs/issue-76595.rs similarity index 85% rename from src/test/ui/const-generics/issues/issue-76595.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-76595.rs index 6e9af5bbb305..faa8b3d10de4 100644 --- a/src/test/ui/const-generics/issues/issue-76595.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-76595.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Bool; diff --git a/src/test/ui/const-generics/issues/issue-76595.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-76595.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr diff --git a/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs similarity index 91% rename from src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs index b0bd3d8a2c93..2fa9a71fbb33 100644 --- a/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This test is a minimized reproduction for #79518 where diff --git a/src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-79518-default_trait_method_normalization.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr diff --git a/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs b/src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs similarity index 89% rename from src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs index 1b9967a7b49b..77d3c98dab92 100644 --- a/src/test/ui/const-generics/issues/issue-80561-incorrect-param-env.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80561-incorrect-param-env.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // This tests that the correct `param_env` is used so that diff --git a/src/test/ui/mir/issue-80742.rs b/src/test/ui/const-generics/generic_const_exprs/issue-80742.rs similarity index 95% rename from src/test/ui/mir/issue-80742.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-80742.rs index cfd87bd9769b..275f69953024 100644 --- a/src/test/ui/mir/issue-80742.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80742.rs @@ -4,7 +4,6 @@ #![allow(incomplete_features)] #![feature(generic_const_exprs)] -#![feature(const_generics)] use std::fmt::Debug; use std::marker::PhantomData; diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr similarity index 91% rename from src/test/ui/mir/issue-80742.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr index b2b40bea7082..56cb11bacbe6 100644 --- a/src/test/ui/mir/issue-80742.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr @@ -7,13 +7,13 @@ LL | intrinsics::size_of::() | size_of called on unsized type `dyn Debug` | inside `std::mem::size_of::` at $SRC_DIR/core/src/mem/mod.rs:LL:COL | - ::: $DIR/issue-80742.rs:23:10 + ::: $DIR/issue-80742.rs:22:10 | LL | [u8; size_of::() + 1]: , - | -------------- inside `Inline::::{constant#0}` at $DIR/issue-80742.rs:23:10 + | -------------- inside `Inline::::{constant#0}` at $DIR/issue-80742.rs:22:10 error[E0599]: the function or associated item `new` exists for struct `Inline`, but its trait bounds were not satisfied - --> $DIR/issue-80742.rs:31:36 + --> $DIR/issue-80742.rs:30:36 | LL | / struct Inline LL | | where @@ -44,20 +44,20 @@ LL | intrinsics::size_of::() | size_of called on unsized type `dyn Debug` | inside `std::mem::size_of::` at $SRC_DIR/core/src/mem/mod.rs:LL:COL | - ::: $DIR/issue-80742.rs:15:10 + ::: $DIR/issue-80742.rs:14:10 | LL | [u8; size_of::() + 1]: , - | -------------- inside `Inline::::{constant#0}` at $DIR/issue-80742.rs:15:10 + | -------------- inside `Inline::::{constant#0}` at $DIR/issue-80742.rs:14:10 error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/issue-80742.rs:31:15 + --> $DIR/issue-80742.rs:30:15 | LL | let dst = Inline::::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Debug` note: required by a bound in `Inline` - --> $DIR/issue-80742.rs:13:15 + --> $DIR/issue-80742.rs:12:15 | LL | struct Inline | ^ required by this bound in `Inline` diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/generic_const_exprs/issue-83765.rs similarity index 94% rename from src/test/ui/const-generics/issues/issue-83765.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-83765.rs index e2b859c0f859..fac811d1302f 100644 --- a/src/test/ui/const-generics/issues/issue-83765.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-83765.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait TensorDimension { diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-83765.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-83765.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-83765.stderr diff --git a/src/test/ui/const-generics/issues/issue-84408.rs b/src/test/ui/const-generics/generic_const_exprs/issue-84408.rs similarity index 93% rename from src/test/ui/const-generics/issues/issue-84408.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-84408.rs index fb49cba2a34c..fb2e5590d216 100644 --- a/src/test/ui/const-generics/issues/issue-84408.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-84408.rs @@ -1,7 +1,7 @@ // Regression test for #84408. // check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Melon { diff --git a/src/test/ui/const-generics/issues/issue-85848.rs b/src/test/ui/const-generics/generic_const_exprs/issue-85848.rs similarity index 90% rename from src/test/ui/const-generics/issues/issue-85848.rs rename to src/test/ui/const-generics/generic_const_exprs/issue-85848.rs index 4d75fdb7d1df..771e68b0db58 100644 --- a/src/test/ui/const-generics/issues/issue-85848.rs +++ b/src/test/ui/const-generics/generic_const_exprs/issue-85848.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, const_fn_trait_bound, generic_const_exprs)] +#![feature(const_fn_trait_bound, generic_const_exprs)] #![allow(incomplete_features)] trait _Contains { diff --git a/src/test/ui/const-generics/issues/issue-85848.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-85848.stderr similarity index 100% rename from src/test/ui/const-generics/issues/issue-85848.stderr rename to src/test/ui/const-generics/generic_const_exprs/issue-85848.stderr diff --git a/src/test/ui/const-generics/generic_const_exprs/less_than.rs b/src/test/ui/const-generics/generic_const_exprs/less_than.rs index 31fe9a53f034..2e9af1bf4f0b 100644 --- a/src/test/ui/const-generics/generic_const_exprs/less_than.rs +++ b/src/test/ui/const-generics/generic_const_exprs/less_than.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs index ea5c95a74446..cd5d76dd949d 100644 --- a/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs +++ b/src/test/ui/const-generics/generic_const_exprs/let-bindings.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // We do not yet want to support let-bindings in abstract consts, diff --git a/src/test/ui/const_evaluatable/needs_where_clause.rs b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs similarity index 83% rename from src/test/ui/const_evaluatable/needs_where_clause.rs rename to src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs index e8a625101d6b..2bd3c801fbf4 100644 --- a/src/test/ui/const_evaluatable/needs_where_clause.rs +++ b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.rs @@ -1,5 +1,5 @@ #![crate_type = "lib"] -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] const fn complex_maths(n : usize) -> usize { diff --git a/src/test/ui/const_evaluatable/needs_where_clause.stderr b/src/test/ui/const-generics/generic_const_exprs/needs_where_clause.stderr similarity index 100% rename from src/test/ui/const_evaluatable/needs_where_clause.stderr rename to src/test/ui/const-generics/generic_const_exprs/needs_where_clause.stderr diff --git a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs index e70bdad90847..7e5022817e41 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn callee() -> usize diff --git a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs index aed3f476f1df..769e3ae6895f 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested-abstract-consts-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(generic_const_exprs, const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Generic; diff --git a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs index a86918adfa76..316887e5e7fa 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-1.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn zero_init() -> Substs1 diff --git a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs index 72fd39b96f88..d45a6465b765 100644 --- a/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs +++ b/src/test/ui/const-generics/generic_const_exprs/nested_uneval_unification-2.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, unused_parens, unused_braces)] fn zero_init() -> Substs1<{ (N) }> diff --git a/src/test/ui/const_evaluatable/no_where_clause.rs b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs similarity index 90% rename from src/test/ui/const_evaluatable/no_where_clause.rs rename to src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs index 6ae517af0d5b..9c5de03170b1 100644 --- a/src/test/ui/const_evaluatable/no_where_clause.rs +++ b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, unused)] const fn complex_maths(n : usize) -> usize { diff --git a/src/test/ui/const_evaluatable/no_where_clause.stderr b/src/test/ui/const-generics/generic_const_exprs/no_where_clause.stderr similarity index 100% rename from src/test/ui/const_evaluatable/no_where_clause.stderr rename to src/test/ui/const-generics/generic_const_exprs/no_where_clause.stderr diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs index 81a634a41738..24d333aba0fd 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs index 22ff9f41276b..42c1cc507b5c 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] #![deny(where_clauses_object_safety)] diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs index e421c43dd948..c6c196db6f2a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Foo { diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs index 0ab8be80f373..f4c89f6235a0 100644 --- a/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs +++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-ok.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Foo { diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr deleted file mode 100644 index f6192bbe9caf..000000000000 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/simple_fail.rs:6:33 - | -LL | type Arr = [u8; N - 1]; - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/simple_fail.rs:10:48 - | -LL | fn test() -> Arr where [u8; N - 1]: Sized { - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs index db2f94b7fce1..c47a350c7fb4 100644 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.rs @@ -1,15 +1,11 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, feature(generic_const_exprs))] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] type Arr = [u8; N - 1]; -//[min]~^ ERROR generic parameters may not be used in const operations -//[full]~^^ ERROR evaluation of `Arr::<0_usize>::{constant#0}` failed +//~^ ERROR evaluation of `Arr::<0_usize>::{constant#0}` failed fn test() -> Arr where [u8; N - 1]: Sized { -//[min]~^ ERROR generic parameters may not be used in const operations -//[full]~^^ ERROR evaluation of `test::<0_usize>::{constant#0}` failed +//~^ ERROR evaluation of `test::<0_usize>::{constant#0}` failed todo!() } diff --git a/src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr b/src/test/ui/const-generics/generic_const_exprs/simple_fail.stderr similarity index 90% rename from src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr rename to src/test/ui/const-generics/generic_const_exprs/simple_fail.stderr index 1f2313a6028d..99fc92fb4f0a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/simple_fail.full.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/simple_fail.stderr @@ -1,11 +1,11 @@ error[E0080]: evaluation of `test::<0_usize>::{constant#0}` failed - --> $DIR/simple_fail.rs:10:48 + --> $DIR/simple_fail.rs:7:48 | LL | fn test() -> Arr where [u8; N - 1]: Sized { | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow error[E0080]: evaluation of `Arr::<0_usize>::{constant#0}` failed - --> $DIR/simple_fail.rs:6:33 + --> $DIR/simple_fail.rs:4:33 | LL | type Arr = [u8; N - 1]; | ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow diff --git a/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs index 71c594657e03..d6574a3aa2f8 100644 --- a/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs +++ b/src/test/ui/const-generics/generic_const_exprs/subexprs_are_const_evalutable.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn make_array() -> [(); M + 1] { diff --git a/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs index abb9df162884..d058b3638509 100644 --- a/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs +++ b/src/test/ui/const-generics/generic_const_exprs/ty-alias-substitution.rs @@ -1,6 +1,6 @@ // check-pass // Test that we correctly substitute generic arguments for type aliases. -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] type Alias = [T; N + 1]; diff --git a/src/test/ui/const-generics/generic_const_exprs/unop.rs b/src/test/ui/const-generics/generic_const_exprs/unop.rs index e0e373b62f94..c12fef083cc7 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unop.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unop.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs index c0da46d6d5f7..67fefd07ec0c 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused-complex-default-expr.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_generics, generic_const_exprs, const_generics_defaults)] +#![feature(generic_const_exprs, const_generics_defaults)] #![allow(incomplete_features)] struct Foo; struct Bar(Foo); diff --git a/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs index 44b6530f22e8..c1bf19e0f8d4 100644 --- a/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs +++ b/src/test/ui/const-generics/generic_const_exprs/unused_expr.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn add() -> [u8; { N + 1; 5 }] { diff --git a/src/test/ui/const-generics/impl-const-generic-struct.rs b/src/test/ui/const-generics/impl-const-generic-struct.rs index 1aa22698b640..7eb2c6a51fcf 100644 --- a/src/test/ui/const-generics/impl-const-generic-struct.rs +++ b/src/test/ui/const-generics/impl-const-generic-struct.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct S; impl S { diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr deleted file mode 100644 index ebc8f458f79c..000000000000 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.min.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/impl-trait-with-const-arguments.rs:23:20 - | -LL | assert_eq!(f::<4usize>(Usizable), 20usize); - | ^^^^^^ explicit generic argument not allowed - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0632`. diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.rs b/src/test/ui/const-generics/impl-trait-with-const-arguments.rs index 2e6e49b9c0aa..24ba393c17f2 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.rs +++ b/src/test/ui/const-generics/impl-trait-with-const-arguments.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - trait Usizer { fn m(self) -> usize; } diff --git a/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr b/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr similarity index 86% rename from src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr rename to src/test/ui/const-generics/impl-trait-with-const-arguments.stderr index ebc8f458f79c..6268a564b06b 100644 --- a/src/test/ui/const-generics/impl-trait-with-const-arguments.full.stderr +++ b/src/test/ui/const-generics/impl-trait-with-const-arguments.stderr @@ -1,5 +1,5 @@ error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position - --> $DIR/impl-trait-with-const-arguments.rs:23:20 + --> $DIR/impl-trait-with-const-arguments.rs:18:20 | LL | assert_eq!(f::<4usize>(Usizable), 20usize); | ^^^^^^ explicit generic argument not allowed diff --git a/src/test/ui/const-generics/incorrect-number-of-const-args.min.stderr b/src/test/ui/const-generics/incorrect-number-of-const-args.min.stderr deleted file mode 100644 index 7a12f3bdec27..000000000000 --- a/src/test/ui/const-generics/incorrect-number-of-const-args.min.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied - --> $DIR/incorrect-number-of-const-args.rs:11:5 - | -LL | foo::<0>(); - | ^^^ - supplied 1 generic argument - | | - | expected 2 generic arguments - | -note: function defined here, with 2 generic parameters: `X`, `Y` - --> $DIR/incorrect-number-of-const-args.rs:6:4 - | -LL | fn foo() -> usize { - | ^^^ - - -help: add missing generic argument - | -LL | foo::<0, Y>(); - | +++ - -error[E0107]: this function takes 2 generic arguments but 3 generic arguments were supplied - --> $DIR/incorrect-number-of-const-args.rs:14:5 - | -LL | foo::<0, 0, 0>(); - | ^^^ - help: remove this generic argument - | | - | expected 2 generic arguments - | -note: function defined here, with 2 generic parameters: `X`, `Y` - --> $DIR/incorrect-number-of-const-args.rs:6:4 - | -LL | fn foo() -> usize { - | ^^^ - - - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/const-generics/incorrect-number-of-const-args.rs b/src/test/ui/const-generics/incorrect-number-of-const-args.rs index 305559d93fda..de2d126afd75 100644 --- a/src/test/ui/const-generics/incorrect-number-of-const-args.rs +++ b/src/test/ui/const-generics/incorrect-number-of-const-args.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn foo() -> usize { 0 } diff --git a/src/test/ui/const-generics/incorrect-number-of-const-args.full.stderr b/src/test/ui/const-generics/incorrect-number-of-const-args.stderr similarity index 83% rename from src/test/ui/const-generics/incorrect-number-of-const-args.full.stderr rename to src/test/ui/const-generics/incorrect-number-of-const-args.stderr index 7a12f3bdec27..bf873dacd98e 100644 --- a/src/test/ui/const-generics/incorrect-number-of-const-args.full.stderr +++ b/src/test/ui/const-generics/incorrect-number-of-const-args.stderr @@ -1,5 +1,5 @@ error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied - --> $DIR/incorrect-number-of-const-args.rs:11:5 + --> $DIR/incorrect-number-of-const-args.rs:6:5 | LL | foo::<0>(); | ^^^ - supplied 1 generic argument @@ -7,7 +7,7 @@ LL | foo::<0>(); | expected 2 generic arguments | note: function defined here, with 2 generic parameters: `X`, `Y` - --> $DIR/incorrect-number-of-const-args.rs:6:4 + --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { | ^^^ - - @@ -17,7 +17,7 @@ LL | foo::<0, Y>(); | +++ error[E0107]: this function takes 2 generic arguments but 3 generic arguments were supplied - --> $DIR/incorrect-number-of-const-args.rs:14:5 + --> $DIR/incorrect-number-of-const-args.rs:9:5 | LL | foo::<0, 0, 0>(); | ^^^ - help: remove this generic argument @@ -25,7 +25,7 @@ LL | foo::<0, 0, 0>(); | expected 2 generic arguments | note: function defined here, with 2 generic parameters: `X`, `Y` - --> $DIR/incorrect-number-of-const-args.rs:6:4 + --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { | ^^^ - - diff --git a/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr b/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr deleted file mode 100644 index 01fb137dd6af..000000000000 --- a/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/cannot-infer-const-args.rs:11:5 - | -LL | foo(); - | ^^^ cannot infer the value of const parameter `X` declared on the function `foo` - | -help: consider specifying the const argument - | -LL | foo::(); - | ~~~~~~~~ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/infer/cannot-infer-const-args.rs b/src/test/ui/const-generics/infer/cannot-infer-const-args.rs index cc52892bd04b..f85a72910aff 100644 --- a/src/test/ui/const-generics/infer/cannot-infer-const-args.rs +++ b/src/test/ui/const-generics/infer/cannot-infer-const-args.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn foo() -> usize { 0 } diff --git a/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr b/src/test/ui/const-generics/infer/cannot-infer-const-args.stderr similarity index 89% rename from src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr rename to src/test/ui/const-generics/infer/cannot-infer-const-args.stderr index 01fb137dd6af..828f49724039 100644 --- a/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr +++ b/src/test/ui/const-generics/infer/cannot-infer-const-args.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/cannot-infer-const-args.rs:11:5 + --> $DIR/cannot-infer-const-args.rs:6:5 | LL | foo(); | ^^^ cannot infer the value of const parameter `X` declared on the function `foo` diff --git a/src/test/ui/const-generics/infer/method-chain.min.stderr b/src/test/ui/const-generics/infer/method-chain.min.stderr deleted file mode 100644 index 979d50b85f14..000000000000 --- a/src/test/ui/const-generics/infer/method-chain.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/method-chain.rs:20:33 - | -LL | Foo.bar().bar().bar().bar().baz(); - | ^^^ cannot infer the value of const parameter `N` declared on the associated function `baz` - | -help: consider specifying the const argument - | -LL | Foo.bar().bar().bar().bar().baz::(); - | ~~~~~~~~ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/infer/method-chain.rs b/src/test/ui/const-generics/infer/method-chain.rs index 8ac6a7d6267b..0c5eed4894cb 100644 --- a/src/test/ui/const-generics/infer/method-chain.rs +++ b/src/test/ui/const-generics/infer/method-chain.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct Foo; impl Foo { diff --git a/src/test/ui/const-generics/infer/method-chain.full.stderr b/src/test/ui/const-generics/infer/method-chain.stderr similarity index 93% rename from src/test/ui/const-generics/infer/method-chain.full.stderr rename to src/test/ui/const-generics/infer/method-chain.stderr index 979d50b85f14..53d92e5ae725 100644 --- a/src/test/ui/const-generics/infer/method-chain.full.stderr +++ b/src/test/ui/const-generics/infer/method-chain.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/method-chain.rs:20:33 + --> $DIR/method-chain.rs:15:33 | LL | Foo.bar().bar().bar().bar().baz(); | ^^^ cannot infer the value of const parameter `N` declared on the associated function `baz` diff --git a/src/test/ui/const-generics/infer/one-param-uninferred.min.stderr b/src/test/ui/const-generics/infer/one-param-uninferred.min.stderr deleted file mode 100644 index 31b7fc7ccf5a..000000000000 --- a/src/test/ui/const-generics/infer/one-param-uninferred.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/one-param-uninferred.rs:15:23 - | -LL | let _: [u8; 17] = foo(); - | ^^^ cannot infer the value of const parameter `M` declared on the function `foo` - | -help: consider specifying the const argument - | -LL | let _: [u8; 17] = foo::(); - | ~~~~~~~~ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/infer/one-param-uninferred.rs b/src/test/ui/const-generics/infer/one-param-uninferred.rs index 0e947131f4cd..d6018650f533 100644 --- a/src/test/ui/const-generics/infer/one-param-uninferred.rs +++ b/src/test/ui/const-generics/infer/one-param-uninferred.rs @@ -1,10 +1,4 @@ // Test that we emit an error if we cannot properly infer a constant. -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(min, feature(min_const_generics))] - fn foo() -> [u8; N] { todo!() } diff --git a/src/test/ui/const-generics/infer/one-param-uninferred.full.stderr b/src/test/ui/const-generics/infer/one-param-uninferred.stderr similarity index 91% rename from src/test/ui/const-generics/infer/one-param-uninferred.full.stderr rename to src/test/ui/const-generics/infer/one-param-uninferred.stderr index 31b7fc7ccf5a..acf59170c369 100644 --- a/src/test/ui/const-generics/infer/one-param-uninferred.full.stderr +++ b/src/test/ui/const-generics/infer/one-param-uninferred.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/one-param-uninferred.rs:15:23 + --> $DIR/one-param-uninferred.rs:9:23 | LL | let _: [u8; 17] = foo(); | ^^^ cannot infer the value of const parameter `M` declared on the function `foo` diff --git a/src/test/ui/const-generics/infer/uninferred-consts.min.stderr b/src/test/ui/const-generics/infer/uninferred-consts.min.stderr deleted file mode 100644 index bee4b693825f..000000000000 --- a/src/test/ui/const-generics/infer/uninferred-consts.min.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/uninferred-consts.rs:13:9 - | -LL | Foo.foo(); - | ^^^ cannot infer the value of const parameter `A` declared on the associated function `foo` - | -help: consider specifying the const argument - | -LL | Foo.foo::(); - | ~~~~~~~~ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/const-generics/infer/uninferred-consts.rs b/src/test/ui/const-generics/infer/uninferred-consts.rs index bcd9aadb78af..657f4b513042 100644 --- a/src/test/ui/const-generics/infer/uninferred-consts.rs +++ b/src/test/ui/const-generics/infer/uninferred-consts.rs @@ -1,8 +1,4 @@ // Test that we emit an error if we cannot properly infer a constant. -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] // taken from https://github.com/rust-lang/rust/issues/70507#issuecomment-615268893 struct Foo; diff --git a/src/test/ui/const-generics/infer/uninferred-consts.full.stderr b/src/test/ui/const-generics/infer/uninferred-consts.stderr similarity index 91% rename from src/test/ui/const-generics/infer/uninferred-consts.full.stderr rename to src/test/ui/const-generics/infer/uninferred-consts.stderr index bee4b693825f..a6c79fc058a4 100644 --- a/src/test/ui/const-generics/infer/uninferred-consts.full.stderr +++ b/src/test/ui/const-generics/infer/uninferred-consts.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/uninferred-consts.rs:13:9 + --> $DIR/uninferred-consts.rs:9:9 | LL | Foo.foo(); | ^^^ cannot infer the value of const parameter `A` declared on the associated function `foo` diff --git a/src/test/ui/const-generics/infer_arg_from_pat.rs b/src/test/ui/const-generics/infer_arg_from_pat.rs index 5e2a3eaff543..10317a1b98fc 100644 --- a/src/test/ui/const-generics/infer_arg_from_pat.rs +++ b/src/test/ui/const-generics/infer_arg_from_pat.rs @@ -1,10 +1,6 @@ // run-pass // // see issue #70529 -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct A { arr: [u8; N], diff --git a/src/test/ui/const-generics/infer_arr_len_from_pat.rs b/src/test/ui/const-generics/infer_arr_len_from_pat.rs index 0273383856fd..40f6f5b8d55c 100644 --- a/src/test/ui/const-generics/infer_arr_len_from_pat.rs +++ b/src/test/ui/const-generics/infer_arr_len_from_pat.rs @@ -1,10 +1,6 @@ // check-pass // // see issue #70529 -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] fn as_chunks() -> [u8; N] { loop {} diff --git a/src/test/ui/const-generics/integer-literal-generic-arg-in-where-clause.rs b/src/test/ui/const-generics/integer-literal-generic-arg-in-where-clause.rs index 96e5976e44b3..2b8731ba7096 100644 --- a/src/test/ui/const-generics/integer-literal-generic-arg-in-where-clause.rs +++ b/src/test/ui/const-generics/integer-literal-generic-arg-in-where-clause.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] fn takes_closure_of_array_3(f: F) where F: Fn([i32; 3]) { f([1, 2, 3]); diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.full.stderr b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.full.stderr deleted file mode 100644 index 3e90dbeece95..000000000000 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/intrinsics-type_name-as-const-argument.rs:14:8 - | -LL | T: Trait<{std::intrinsics::type_name::()}> - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index f1ea52825e03..604b4e8bddbf 100644 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -1,20 +1,20 @@ error: generic parameters may not be used in const operations - --> $DIR/intrinsics-type_name-as-const-argument.rs:14:44 + --> $DIR/intrinsics-type_name-as-const-argument.rs:15:44 | LL | T: Trait<{std::intrinsics::type_name::()}> | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/intrinsics-type_name-as-const-argument.rs:9:22 + --> $DIR/intrinsics-type_name-as-const-argument.rs:10:22 | LL | trait Trait {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs index f24dd42eb2da..eedc619e8054 100644 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs +++ b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs @@ -1,7 +1,8 @@ +// [full] check-pass // revisions: full min #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types, generic_const_exprs))] #![feature(core_intrinsics)] #![feature(const_type_name)] @@ -13,7 +14,6 @@ struct Bug where T: Trait<{std::intrinsics::type_name::()}> //[min]~^ ERROR generic parameters may not be used in const operations - //[full]~^^ ERROR constant expression depends on a generic parameter { t: T } diff --git a/src/test/ui/const-generics/invalid-enum.rs b/src/test/ui/const-generics/invalid-enum.rs index 32939dcd2861..65741d07d907 100644 --- a/src/test/ui/const-generics/invalid-enum.rs +++ b/src/test/ui/const-generics/invalid-enum.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(const_param_types, const_generics_defaults)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/issues/auxiliary/const_generic_issues_lib.rs b/src/test/ui/const-generics/issues/auxiliary/const_generic_issues_lib.rs index f59eb60cb38f..6a10ee267df9 100644 --- a/src/test/ui/const-generics/issues/auxiliary/const_generic_issues_lib.rs +++ b/src/test/ui/const-generics/issues/auxiliary/const_generic_issues_lib.rs @@ -1,5 +1,5 @@ -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] // All of these three items must be in `lib2` to reproduce the error @@ -10,6 +10,6 @@ pub trait TypeFn { pub struct GenericType; // Removing the braces around `42` resolves the crash -impl TypeFn for GenericType<{ 42 }> { +impl TypeFn for GenericType<{ 40 + 2 }> { type Output = (); } diff --git a/src/test/ui/const-generics/issues/auxiliary/impl-const.rs b/src/test/ui/const-generics/issues/auxiliary/impl-const.rs index 4a6b57842217..de3a40860252 100644 --- a/src/test/ui/const-generics/issues/auxiliary/impl-const.rs +++ b/src/test/ui/const-generics/issues/auxiliary/impl-const.rs @@ -1,5 +1,4 @@ -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![feature(generic_const_exprs)] pub struct Num; diff --git a/src/test/ui/const-generics/issues/issue-56445-1.full.stderr b/src/test/ui/const-generics/issues/issue-56445-1.full.stderr index 8416d64e1c2d..179643a75529 100644 --- a/src/test/ui/const-generics/issues/issue-56445-1.full.stderr +++ b/src/test/ui/const-generics/issues/issue-56445-1.full.stderr @@ -1,20 +1,11 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-56445-1.rs:3:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - error[E0771]: use of non-static lifetime `'a` in const generic - --> $DIR/issue-56445-1.rs:8:26 + --> $DIR/issue-56445-1.rs:9:26 | LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); | ^^ | = note: for more information, see issue #74052 -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0771`. diff --git a/src/test/ui/const-generics/issues/issue-56445-1.min.stderr b/src/test/ui/const-generics/issues/issue-56445-1.min.stderr index f7056f27cb37..179643a75529 100644 --- a/src/test/ui/const-generics/issues/issue-56445-1.min.stderr +++ b/src/test/ui/const-generics/issues/issue-56445-1.min.stderr @@ -1,5 +1,5 @@ error[E0771]: use of non-static lifetime `'a` in const generic - --> $DIR/issue-56445-1.rs:8:26 + --> $DIR/issue-56445-1.rs:9:26 | LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); | ^^ diff --git a/src/test/ui/const-generics/issues/issue-56445-1.rs b/src/test/ui/const-generics/issues/issue-56445-1.rs index bc9e1dee853e..7cd8e13c8f5f 100644 --- a/src/test/ui/const-generics/issues/issue-56445-1.rs +++ b/src/test/ui/const-generics/issues/issue-56445-1.rs @@ -1,6 +1,7 @@ // Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995. // revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete +#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, allow(incomplete_features))] #![crate_type = "lib"] use std::marker::PhantomData; diff --git a/src/test/ui/const-generics/issues/issue-60818-struct-constructors.full.stderr b/src/test/ui/const-generics/issues/issue-60818-struct-constructors.full.stderr deleted file mode 100644 index c03b7252a3c8..000000000000 --- a/src/test/ui/const-generics/issues/issue-60818-struct-constructors.full.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-60818-struct-constructors.rs:3:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-60818-struct-constructors.rs b/src/test/ui/const-generics/issues/issue-60818-struct-constructors.rs index 6e64c78cd8c9..0066490dfa37 100644 --- a/src/test/ui/const-generics/issues/issue-60818-struct-constructors.rs +++ b/src/test/ui/const-generics/issues/issue-60818-struct-constructors.rs @@ -1,6 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete struct Generic; diff --git a/src/test/ui/const-generics/issues/issue-61336-1.full.stderr b/src/test/ui/const-generics/issues/issue-61336-1.full.stderr deleted file mode 100644 index f18728eabbb4..000000000000 --- a/src/test/ui/const-generics/issues/issue-61336-1.full.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61336-1.rs:3:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-61336-1.rs b/src/test/ui/const-generics/issues/issue-61336-1.rs index c93b296dbb55..beb37e63b5e5 100644 --- a/src/test/ui/const-generics/issues/issue-61336-1.rs +++ b/src/test/ui/const-generics/issues/issue-61336-1.rs @@ -1,7 +1,4 @@ // build-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete - fn f(x: T) -> [T; N] { [x; N] } diff --git a/src/test/ui/const-generics/issues/issue-61336-2.full.stderr b/src/test/ui/const-generics/issues/issue-61336-2.full.stderr deleted file mode 100644 index 8f07d208091a..000000000000 --- a/src/test/ui/const-generics/issues/issue-61336-2.full.stderr +++ /dev/null @@ -1,24 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61336-2.rs:2:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-61336-2.rs:9:5 - | -LL | [x; { N }] - | ^^^^^^^^^^ the trait `Copy` is not implemented for `T` - | - = note: the `Copy` trait is required because the repeated element will be copied -help: consider restricting type parameter `T` - | -LL | fn g(x: T) -> [T; N] { - | +++++++++++++++++++ - -error: aborting due to previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/issues/issue-61336-2.rs b/src/test/ui/const-generics/issues/issue-61336-2.rs index a1cf641ff749..b7cd29f89323 100644 --- a/src/test/ui/const-generics/issues/issue-61336-2.rs +++ b/src/test/ui/const-generics/issues/issue-61336-2.rs @@ -1,6 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete - fn f(x: T) -> [T; N] { [x; { N }] } diff --git a/src/test/ui/const-generics/issues/issue-61336-2.min.stderr b/src/test/ui/const-generics/issues/issue-61336-2.stderr similarity index 93% rename from src/test/ui/const-generics/issues/issue-61336-2.min.stderr rename to src/test/ui/const-generics/issues/issue-61336-2.stderr index 9b62ffc93494..48aaaf5e5440 100644 --- a/src/test/ui/const-generics/issues/issue-61336-2.min.stderr +++ b/src/test/ui/const-generics/issues/issue-61336-2.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-61336-2.rs:9:5 + --> $DIR/issue-61336-2.rs:6:5 | LL | [x; { N }] | ^^^^^^^^^^ the trait `Copy` is not implemented for `T` diff --git a/src/test/ui/const-generics/issues/issue-61336.full.stderr b/src/test/ui/const-generics/issues/issue-61336.full.stderr deleted file mode 100644 index 4883463c2e67..000000000000 --- a/src/test/ui/const-generics/issues/issue-61336.full.stderr +++ /dev/null @@ -1,24 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61336.rs:2:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-61336.rs:9:5 - | -LL | [x; N] - | ^^^^^^ the trait `Copy` is not implemented for `T` - | - = note: the `Copy` trait is required because the repeated element will be copied -help: consider restricting type parameter `T` - | -LL | fn g(x: T) -> [T; N] { - | +++++++++++++++++++ - -error: aborting due to previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/issues/issue-61336.rs b/src/test/ui/const-generics/issues/issue-61336.rs index c0106ee38c20..80be1d8e5e54 100644 --- a/src/test/ui/const-generics/issues/issue-61336.rs +++ b/src/test/ui/const-generics/issues/issue-61336.rs @@ -1,6 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete - fn f(x: T) -> [T; N] { [x; N] } diff --git a/src/test/ui/const-generics/issues/issue-61336.min.stderr b/src/test/ui/const-generics/issues/issue-61336.stderr similarity index 94% rename from src/test/ui/const-generics/issues/issue-61336.min.stderr rename to src/test/ui/const-generics/issues/issue-61336.stderr index dc891842e138..665a1a677a1a 100644 --- a/src/test/ui/const-generics/issues/issue-61336.min.stderr +++ b/src/test/ui/const-generics/issues/issue-61336.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-61336.rs:9:5 + --> $DIR/issue-61336.rs:6:5 | LL | [x; N] | ^^^^^^ the trait `Copy` is not implemented for `T` diff --git a/src/test/ui/const-generics/issues/issue-61422.full.stderr b/src/test/ui/const-generics/issues/issue-61422.full.stderr deleted file mode 100644 index ac6c378295d3..000000000000 --- a/src/test/ui/const-generics/issues/issue-61422.full.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61422.rs:3:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-61422.rs b/src/test/ui/const-generics/issues/issue-61422.rs index 421f696f3fd8..0b9cf40d8555 100644 --- a/src/test/ui/const-generics/issues/issue-61422.rs +++ b/src/test/ui/const-generics/issues/issue-61422.rs @@ -1,7 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete - use std::mem; // Neither of the uninits below are currently accepted as not UB, however, diff --git a/src/test/ui/const-generics/issues/issue-61432.full.stderr b/src/test/ui/const-generics/issues/issue-61432.full.stderr deleted file mode 100644 index 82b36de45a2a..000000000000 --- a/src/test/ui/const-generics/issues/issue-61432.full.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61432.rs:3:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-61432.rs b/src/test/ui/const-generics/issues/issue-61432.rs index 97ab07daccef..6192af82afb2 100644 --- a/src/test/ui/const-generics/issues/issue-61432.rs +++ b/src/test/ui/const-generics/issues/issue-61432.rs @@ -1,13 +1,6 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete fn promote() { - // works: - // - // let n = N; - // let _ = &n; - let _ = &N; } diff --git a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.full.stderr b/src/test/ui/const-generics/issues/issue-61522-array-len-succ.full.stderr deleted file mode 100644 index 56deec16548f..000000000000 --- a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.full.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-61522-array-len-succ.rs:6:40 - | -LL | pub struct MyArray([u8; COUNT + 1]); - | ^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-61522-array-len-succ.rs:11:24 - | -LL | fn inner(&self) -> &[u8; COUNT + 1] { - | ^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr b/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr deleted file mode 100644 index 6d6bca4255ac..000000000000 --- a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-61522-array-len-succ.rs:6:45 - | -LL | pub struct MyArray([u8; COUNT + 1]); - | ^^^^^ cannot perform const operation using `COUNT` - | - = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/issue-61522-array-len-succ.rs:11:30 - | -LL | fn inner(&self) -> &[u8; COUNT + 1] { - | ^^^^^ cannot perform const operation using `COUNT` - | - = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.rs b/src/test/ui/const-generics/issues/issue-61522-array-len-succ.rs deleted file mode 100644 index d4a948b92597..000000000000 --- a/src/test/ui/const-generics/issues/issue-61522-array-len-succ.rs +++ /dev/null @@ -1,18 +0,0 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -pub struct MyArray([u8; COUNT + 1]); -//[full]~^ ERROR constant expression depends on a generic parameter -//[min]~^^ ERROR generic parameters may not be used - -impl MyArray { - fn inner(&self) -> &[u8; COUNT + 1] { - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used - &self.0 - } -} - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-61747.full.stderr b/src/test/ui/const-generics/issues/issue-61747.full.stderr deleted file mode 100644 index b7f66345c4aa..000000000000 --- a/src/test/ui/const-generics/issues/issue-61747.full.stderr +++ /dev/null @@ -1,19 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61747.rs:2:27 - | -LL | #![cfg_attr(full, feature(const_generics))] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error: constant expression depends on a generic parameter - --> $DIR/issue-61747.rs:7:23 - | -LL | fn successor() -> Const<{C + 1}> { - | ^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error; 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-61747.min.stderr b/src/test/ui/const-generics/issues/issue-61747.min.stderr deleted file mode 100644 index cc8c4db9c396..000000000000 --- a/src/test/ui/const-generics/issues/issue-61747.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-61747.rs:7:30 - | -LL | fn successor() -> Const<{C + 1}> { - | ^ cannot perform const operation using `C` - | - = help: const parameters may only be used as standalone arguments, i.e. `C` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-61747.rs b/src/test/ui/const-generics/issues/issue-61747.rs deleted file mode 100644 index 3aa2e6a5c31d..000000000000 --- a/src/test/ui/const-generics/issues/issue-61747.rs +++ /dev/null @@ -1,16 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] //[full]~WARN the feature `const_generics` is incomplete - -struct Const; - -impl Const<{C}> { - fn successor() -> Const<{C + 1}> { - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used - Const - } -} - -fn main() { - let _x: Const::<2> = Const::<1>::successor(); -} diff --git a/src/test/ui/const-generics/issues/issue-61935.full.stderr b/src/test/ui/const-generics/issues/issue-61935.full.stderr deleted file mode 100644 index b970f4e4c8e3..000000000000 --- a/src/test/ui/const-generics/issues/issue-61935.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-61935.rs:9:14 - | -LL | Self:FooImpl<{N==0}> - | ^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-61935.min.stderr b/src/test/ui/const-generics/issues/issue-61935.min.stderr deleted file mode 100644 index a635d5e84a2e..000000000000 --- a/src/test/ui/const-generics/issues/issue-61935.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-61935.rs:9:23 - | -LL | Self:FooImpl<{N==0}> - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-61935.rs b/src/test/ui/const-generics/issues/issue-61935.rs deleted file mode 100644 index ed861c63bf1e..000000000000 --- a/src/test/ui/const-generics/issues/issue-61935.rs +++ /dev/null @@ -1,25 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -trait Foo {} - -impl Foo for [(); N] - where - Self:FooImpl<{N==0}> -//[full]~^ERROR constant expression depends on a generic parameter -//[min]~^^ERROR generic parameters may not be used in const operations -{} - -trait FooImpl{} - -impl FooImpl for [(); 0] {} - -impl FooImpl for [();N] {} - -fn foo(_: impl Foo) {} - -fn main() { - foo([]); - foo([()]); -} diff --git a/src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.rs b/src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.rs index 1a0e46e599d9..fa76aeae901d 100644 --- a/src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.rs +++ b/src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.rs @@ -1,9 +1,4 @@ // run-pass - -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub trait BitLen: Sized { const BIT_LEN: usize; } diff --git a/src/test/ui/const-generics/issues/issue-62220.full.stderr b/src/test/ui/const-generics/issues/issue-62220.full.stderr deleted file mode 100644 index 373360c7ced6..000000000000 --- a/src/test/ui/const-generics/issues/issue-62220.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-62220.rs:12:27 - | -LL | pub fn trunc(self) -> (TruncatedVector, T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-62220.min.stderr b/src/test/ui/const-generics/issues/issue-62220.min.stderr deleted file mode 100644 index 54a93733f322..000000000000 --- a/src/test/ui/const-generics/issues/issue-62220.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-62220.rs:7:59 - | -LL | pub type TruncatedVector = Vector; - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-62220.rs b/src/test/ui/const-generics/issues/issue-62220.rs deleted file mode 100644 index c26784c9813c..000000000000 --- a/src/test/ui/const-generics/issues/issue-62220.rs +++ /dev/null @@ -1,24 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -pub struct Vector([T; N]); - -pub type TruncatedVector = Vector; -//[min]~^ ERROR generic parameters may not be used in const operations - -impl Vector { - /// Drop the last component and return the vector with one fewer dimension. - pub fn trunc(self) -> (TruncatedVector, T) { - //[full]~^ ERROR constant expression depends on a generic parameter - unimplemented!() - } -} - -fn vec4(a: T, b: T, c: T, d: T) -> Vector { - Vector([a, b, c, d]) -} - -fn main() { - let (_xyz, _w): (TruncatedVector, u32) = vec4(0u32, 1, 2, 3).trunc(); -} diff --git a/src/test/ui/const-generics/issues/issue-62456.full.stderr b/src/test/ui/const-generics/issues/issue-62456.full.stderr deleted file mode 100644 index 833e70ca6d38..000000000000 --- a/src/test/ui/const-generics/issues/issue-62456.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-62456.rs:6:20 - | -LL | let _ = [0u64; N + 1]; - | ^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-62456.min.stderr b/src/test/ui/const-generics/issues/issue-62456.min.stderr deleted file mode 100644 index 1e90d0b3f502..000000000000 --- a/src/test/ui/const-generics/issues/issue-62456.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-62456.rs:6:20 - | -LL | let _ = [0u64; N + 1]; - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-62456.rs b/src/test/ui/const-generics/issues/issue-62456.rs deleted file mode 100644 index e24cf36c8ce4..000000000000 --- a/src/test/ui/const-generics/issues/issue-62456.rs +++ /dev/null @@ -1,11 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -fn foo() { - let _ = [0u64; N + 1]; - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations -} - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-62579-no-match.min.stderr b/src/test/ui/const-generics/issues/issue-62579-no-match.min.stderr deleted file mode 100644 index 5c9387d4012d..000000000000 --- a/src/test/ui/const-generics/issues/issue-62579-no-match.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: `NoMatch` is forbidden as the type of a const generic parameter - --> $DIR/issue-62579-no-match.rs:9:17 - | -LL | fn foo() -> bool { - | ^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-62579-no-match.rs b/src/test/ui/const-generics/issues/issue-62579-no-match.rs deleted file mode 100644 index 46813f5256e5..000000000000 --- a/src/test/ui/const-generics/issues/issue-62579-no-match.rs +++ /dev/null @@ -1,16 +0,0 @@ -// [full] run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -#[derive(PartialEq, Eq)] -struct NoMatch; - -fn foo() -> bool { - //[min]~^ ERROR `NoMatch` is forbidden as the type of a const generic parameter - true -} - -fn main() { - foo::<{NoMatch}>(); -} diff --git a/src/test/ui/const-generics/issues/issue-62878.full.stderr b/src/test/ui/const-generics/issues/issue-62878.full.stderr index 08f6454fa2df..f074a65313f1 100644 --- a/src/test/ui/const-generics/issues/issue-62878.full.stderr +++ b/src/test/ui/const-generics/issues/issue-62878.full.stderr @@ -4,21 +4,13 @@ error[E0770]: the type of const parameters must not depend on other generic para LL | fn foo() {} | ^ the type must not depend on the parameter `N` -error: constant expression depends on a generic parameter - --> $DIR/issue-62878.rs:10:14 - | -LL | foo::<_, {[1]}>(); - | ^^^^^ - | - = note: this may fail depending on what value the parameter takes - error[E0308]: mismatched types --> $DIR/issue-62878.rs:10:15 | LL | foo::<_, {[1]}>(); | ^^^ expected `usize`, found array `[{integer}; 1]` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0308, E0770. For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-62878.min.stderr b/src/test/ui/const-generics/issues/issue-62878.min.stderr index e4a71fe06186..af3bd4124335 100644 --- a/src/test/ui/const-generics/issues/issue-62878.min.stderr +++ b/src/test/ui/const-generics/issues/issue-62878.min.stderr @@ -11,7 +11,7 @@ LL | fn foo() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-62878.rs b/src/test/ui/const-generics/issues/issue-62878.rs index fb6257696b96..8eaa31249aa9 100644 --- a/src/test/ui/const-generics/issues/issue-62878.rs +++ b/src/test/ui/const-generics/issues/issue-62878.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics, generic_arg_infer))] +#![cfg_attr(full, feature(const_param_types, generic_arg_infer))] #![cfg_attr(full, allow(incomplete_features))] fn foo() {} @@ -9,5 +9,4 @@ fn foo() {} fn main() { foo::<_, {[1]}>(); //[full]~^ ERROR mismatched types - //[full]~| ERROR constant expression } diff --git a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr index 2fb38addb2d8..dcb4c703895b 100644 --- a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr +++ b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr @@ -5,7 +5,7 @@ LL | fn test() { | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/issue-63322-forbid-dyn.rs:9:18 diff --git a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs index 334e2aac02a4..076a16821e54 100644 --- a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs +++ b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] trait A {} diff --git a/src/test/ui/const-generics/issues/issue-64494.full.stderr b/src/test/ui/const-generics/issues/issue-64494.full.stderr deleted file mode 100644 index abb26d6cf175..000000000000 --- a/src/test/ui/const-generics/issues/issue-64494.full.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-64494.rs:15:53 - | -LL | impl MyTrait for T where Is<{T::VAL == 5}>: True {} - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-64494.rs:18:53 - | -LL | impl MyTrait for T where Is<{T::VAL == 6}>: True {} - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-64494.min.stderr b/src/test/ui/const-generics/issues/issue-64494.min.stderr deleted file mode 100644 index 8cb9981a534c..000000000000 --- a/src/test/ui/const-generics/issues/issue-64494.min.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-64494.rs:15:38 - | -LL | impl MyTrait for T where Is<{T::VAL == 5}>: True {} - | ^^^^^^ cannot perform const operation using `T` - | - = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/issue-64494.rs:18:38 - | -LL | impl MyTrait for T where Is<{T::VAL == 6}>: True {} - | ^^^^^^ cannot perform const operation using `T` - | - = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error[E0119]: conflicting implementations of trait `MyTrait` - --> $DIR/issue-64494.rs:18:1 - | -LL | impl MyTrait for T where Is<{T::VAL == 5}>: True {} - | ------------------------------------ first implementation here -... -LL | impl MyTrait for T where Is<{T::VAL == 6}>: True {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0119`. diff --git a/src/test/ui/const-generics/issues/issue-64494.rs b/src/test/ui/const-generics/issues/issue-64494.rs deleted file mode 100644 index 96d19203109a..000000000000 --- a/src/test/ui/const-generics/issues/issue-64494.rs +++ /dev/null @@ -1,23 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -trait Foo { - const VAL: usize; -} - -trait MyTrait {} - -trait True {} -struct Is; -impl True for Is<{true}> {} - -impl MyTrait for T where Is<{T::VAL == 5}>: True {} -//[full]~^ ERROR constant expression depends on a generic parameter -//[min]~^^ ERROR generic parameters may not be used in const operations -impl MyTrait for T where Is<{T::VAL == 6}>: True {} -//[full]~^ ERROR constant expression depends on a generic parameter -//[min]~^^ ERROR generic parameters may not be used in const operations -//[min]~| ERROR conflicting implementations of trait `MyTrait` - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-64519.rs b/src/test/ui/const-generics/issues/issue-64519.rs index 8c603b74b907..969289b26e80 100644 --- a/src/test/ui/const-generics/issues/issue-64519.rs +++ b/src/test/ui/const-generics/issues/issue-64519.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct Foo { state: Option<[u8; D]>, } diff --git a/src/test/ui/const-generics/issues/issue-64519.stderr b/src/test/ui/const-generics/issues/issue-64519.stderr deleted file mode 100644 index 6552aea4ad1f..000000000000 --- a/src/test/ui/const-generics/issues/issue-64519.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-64519.rs:3:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/issues/issue-66205.full.stderr b/src/test/ui/const-generics/issues/issue-66205.full.stderr deleted file mode 100644 index 7e150f5f6db5..000000000000 --- a/src/test/ui/const-generics/issues/issue-66205.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-66205.rs:7:12 - | -LL | fact::<{ N - 1 }>(); - | ^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-66205.min.stderr b/src/test/ui/const-generics/issues/issue-66205.min.stderr deleted file mode 100644 index 1dd4baaa5b57..000000000000 --- a/src/test/ui/const-generics/issues/issue-66205.min.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-66205.rs:7:14 - | -LL | fact::<{ N - 1 }>(); - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-66205.rs b/src/test/ui/const-generics/issues/issue-66205.rs deleted file mode 100644 index 14249b62ceed..000000000000 --- a/src/test/ui/const-generics/issues/issue-66205.rs +++ /dev/null @@ -1,12 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] -#![allow(dead_code, unconditional_recursion)] - -fn fact() { - fact::<{ N - 1 }>(); - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations -} - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs b/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs index 2a741ba87a98..a506fceb4eff 100644 --- a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs +++ b/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs @@ -1,12 +1,9 @@ -//[full] check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +// check-pass +#![feature(const_param_types)] +#![allow(incomplete_features)] trait Trait { -//[min]~^ ERROR `&'static str` is forbidden type Assoc; } diff --git a/src/test/ui/const-generics/issues/issue-66906.rs b/src/test/ui/const-generics/issues/issue-66906.rs index a871b118dcc5..a0b3f9122071 100644 --- a/src/test/ui/const-generics/issues/issue-66906.rs +++ b/src/test/ui/const-generics/issues/issue-66906.rs @@ -1,7 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] pub struct Tuple; diff --git a/src/test/ui/const-generics/issues/issue-67185-1.rs b/src/test/ui/const-generics/issues/issue-67185-1.rs index ed35a5f7c0a8..69425b25eaee 100644 --- a/src/test/ui/const-generics/issues/issue-67185-1.rs +++ b/src/test/ui/const-generics/issues/issue-67185-1.rs @@ -1,7 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait Baz { type Quaks; diff --git a/src/test/ui/const-generics/issues/issue-67185-2.min.stderr b/src/test/ui/const-generics/issues/issue-67185-2.min.stderr deleted file mode 100644 index 19f419c82fdf..000000000000 --- a/src/test/ui/const-generics/issues/issue-67185-2.min.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:16:1 - | -LL | / trait Foo -LL | | -LL | | where -LL | | [::Quaks; 2]: Bar, -LL | | ::Quaks: Bar, -LL | | { -LL | | } - | |_^ the trait `Bar` is not implemented for `[u16; 3]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> - = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - -error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:16:1 - | -LL | / trait Foo -LL | | -LL | | where -LL | | [::Quaks; 2]: Bar, -LL | | ::Quaks: Bar, -LL | | { -LL | | } - | |_^ the trait `Bar` is not implemented for `[[u16; 3]; 2]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> - = help: see issue #48214 - = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - -error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:26:6 - | -LL | impl Foo for FooImpl {} - | ^^^ the trait `Bar` is not implemented for `[u16; 3]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> -note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:20:29 - | -LL | trait Foo - | --- required by a bound in this -... -LL | ::Quaks: Bar, - | ^^^ required by this bound in `Foo` - -error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:26:6 - | -LL | impl Foo for FooImpl {} - | ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> -note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:19:34 - | -LL | trait Foo - | --- required by a bound in this -... -LL | [::Quaks; 2]: Bar, - | ^^^ required by this bound in `Foo` - -error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:30:14 - | -LL | fn f(_: impl Foo) {} - | ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> -note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:19:34 - | -LL | trait Foo - | --- required by a bound in this -... -LL | [::Quaks; 2]: Bar, - | ^^^ required by this bound in `Foo` - -error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:30:14 - | -LL | fn f(_: impl Foo) {} - | ^^^ the trait `Bar` is not implemented for `[u16; 3]` - | - = help: the following implementations were found: - <[[u16; 3]; 3] as Bar> - <[u16; 4] as Bar> -note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:20:29 - | -LL | trait Foo - | --- required by a bound in this -... -LL | ::Quaks: Bar, - | ^^^ required by this bound in `Foo` - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/issues/issue-67185-2.rs b/src/test/ui/const-generics/issues/issue-67185-2.rs index 94a713d7cf95..c1a04e201474 100644 --- a/src/test/ui/const-generics/issues/issue-67185-2.rs +++ b/src/test/ui/const-generics/issues/issue-67185-2.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait Baz { type Quaks; } diff --git a/src/test/ui/const-generics/issues/issue-67185-2.full.stderr b/src/test/ui/const-generics/issues/issue-67185-2.stderr similarity index 90% rename from src/test/ui/const-generics/issues/issue-67185-2.full.stderr rename to src/test/ui/const-generics/issues/issue-67185-2.stderr index 19f419c82fdf..7167bea94bbb 100644 --- a/src/test/ui/const-generics/issues/issue-67185-2.full.stderr +++ b/src/test/ui/const-generics/issues/issue-67185-2.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:16:1 + --> $DIR/issue-67185-2.rs:12:1 | LL | / trait Foo LL | | @@ -17,7 +17,7 @@ LL | | } = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:16:1 + --> $DIR/issue-67185-2.rs:12:1 | LL | / trait Foo LL | | @@ -35,7 +35,7 @@ LL | | } = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:26:6 + --> $DIR/issue-67185-2.rs:22:6 | LL | impl Foo for FooImpl {} | ^^^ the trait `Bar` is not implemented for `[u16; 3]` @@ -44,7 +44,7 @@ LL | impl Foo for FooImpl {} <[[u16; 3]; 3] as Bar> <[u16; 4] as Bar> note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:20:29 + --> $DIR/issue-67185-2.rs:16:29 | LL | trait Foo | --- required by a bound in this @@ -53,7 +53,7 @@ LL | ::Quaks: Bar, | ^^^ required by this bound in `Foo` error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:26:6 + --> $DIR/issue-67185-2.rs:22:6 | LL | impl Foo for FooImpl {} | ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]` @@ -62,7 +62,7 @@ LL | impl Foo for FooImpl {} <[[u16; 3]; 3] as Bar> <[u16; 4] as Bar> note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:19:34 + --> $DIR/issue-67185-2.rs:15:34 | LL | trait Foo | --- required by a bound in this @@ -71,7 +71,7 @@ LL | [::Quaks; 2]: Bar, | ^^^ required by this bound in `Foo` error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:30:14 + --> $DIR/issue-67185-2.rs:26:14 | LL | fn f(_: impl Foo) {} | ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]` @@ -80,7 +80,7 @@ LL | fn f(_: impl Foo) {} <[[u16; 3]; 3] as Bar> <[u16; 4] as Bar> note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:19:34 + --> $DIR/issue-67185-2.rs:15:34 | LL | trait Foo | --- required by a bound in this @@ -89,7 +89,7 @@ LL | [::Quaks; 2]: Bar, | ^^^ required by this bound in `Foo` error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied - --> $DIR/issue-67185-2.rs:30:14 + --> $DIR/issue-67185-2.rs:26:14 | LL | fn f(_: impl Foo) {} | ^^^ the trait `Bar` is not implemented for `[u16; 3]` @@ -98,7 +98,7 @@ LL | fn f(_: impl Foo) {} <[[u16; 3]; 3] as Bar> <[u16; 4] as Bar> note: required by a bound in `Foo` - --> $DIR/issue-67185-2.rs:20:29 + --> $DIR/issue-67185-2.rs:16:29 | LL | trait Foo | --- required by a bound in this diff --git a/src/test/ui/const-generics/issues/issue-67375.full.stderr b/src/test/ui/const-generics/issues/issue-67375.full.stderr index 0fe65272f1b7..5386ef56a245 100644 --- a/src/test/ui/const-generics/issues/issue-67375.full.stderr +++ b/src/test/ui/const-generics/issues/issue-67375.full.stderr @@ -1,15 +1,15 @@ -warning: cannot use constants which depend on generic parameters in types - --> $DIR/issue-67375.rs:8:12 +error: overly complex generic constant + --> $DIR/issue-67375.rs:7:17 | LL | inner: [(); { [|_: &T| {}; 0].len() }], - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^----------^^^^^^^^^^^^ + | | + | unsupported rvalue | - = note: `#[warn(const_evaluatable_unchecked)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #76200 + = help: consider moving this anonymous constant into a `const` function error[E0392]: parameter `T` is never used - --> $DIR/issue-67375.rs:6:12 + --> $DIR/issue-67375.rs:5:12 | LL | struct Bug { | ^ unused parameter @@ -17,6 +17,6 @@ LL | struct Bug { = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` = help: if you intended `T` to be a const parameter, use `const T: usize` instead -error: aborting due to previous error; 1 warning emitted +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0392`. diff --git a/src/test/ui/const-generics/issues/issue-67375.min.stderr b/src/test/ui/const-generics/issues/issue-67375.min.stderr index c005e03f20c3..5256d96c8769 100644 --- a/src/test/ui/const-generics/issues/issue-67375.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67375.min.stderr @@ -1,14 +1,14 @@ error: generic parameters may not be used in const operations - --> $DIR/issue-67375.rs:8:25 + --> $DIR/issue-67375.rs:7:25 | LL | inner: [(); { [|_: &T| {}; 0].len() }], | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `T` is never used - --> $DIR/issue-67375.rs:6:12 + --> $DIR/issue-67375.rs:5:12 | LL | struct Bug { | ^ unused parameter diff --git a/src/test/ui/const-generics/issues/issue-67375.rs b/src/test/ui/const-generics/issues/issue-67375.rs index a8875b8b6bfc..b5b842a15ae0 100644 --- a/src/test/ui/const-generics/issues/issue-67375.rs +++ b/src/test/ui/const-generics/issues/issue-67375.rs @@ -1,14 +1,12 @@ // revisions: full min - #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] struct Bug { //~^ ERROR parameter `T` is never used inner: [(); { [|_: &T| {}; 0].len() }], //[min]~^ ERROR generic parameters may not be used in const operations - //[full]~^^ WARN cannot use constants which depend on generic parameters in types - //[full]~^^^ WARN this was previously accepted by the compiler + //[full]~^^ ERROR overly complex generic constant } fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-67739.full.stderr b/src/test/ui/const-generics/issues/issue-67739.full.stderr index dcbe5b94a628..f1a426c3c586 100644 --- a/src/test/ui/const-generics/issues/issue-67739.full.stderr +++ b/src/test/ui/const-generics/issues/issue-67739.full.stderr @@ -1,10 +1,10 @@ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/issue-67739.rs:11:15 | LL | [0u8; mem::size_of::()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this may fail depending on what value the parameter takes + = help: try adding a `where` bound using this expression: `where [(); mem::size_of::()]:` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-67739.rs b/src/test/ui/const-generics/issues/issue-67739.rs index e4960e56c9e4..de0eb7f509ae 100644 --- a/src/test/ui/const-generics/issues/issue-67739.rs +++ b/src/test/ui/const-generics/issues/issue-67739.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] use std::mem; @@ -9,7 +9,8 @@ pub trait Trait { fn associated_size(&self) -> usize { [0u8; mem::size_of::()]; - //~^ ERROR constant expression depends on a generic parameter + //[min]~^ ERROR constant expression depends on a generic parameter + //[full]~^^ ERROR unconstrained generic constant 0 } } diff --git a/src/test/ui/const-generics/issues/issue-67945-1.full.stderr b/src/test/ui/const-generics/issues/issue-67945-1.full.stderr index 63c50b5ca542..1edc7828caad 100644 --- a/src/test/ui/const-generics/issues/issue-67945-1.full.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-1.full.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-67945-1.rs:13:20 + --> $DIR/issue-67945-1.rs:10:20 | LL | struct Bug { | - this type parameter @@ -13,7 +13,7 @@ LL | let x: S = MaybeUninit::uninit(); found union `MaybeUninit<_>` error[E0392]: parameter `S` is never used - --> $DIR/issue-67945-1.rs:10:12 + --> $DIR/issue-67945-1.rs:7:12 | LL | struct Bug { | ^ unused parameter diff --git a/src/test/ui/const-generics/issues/issue-67945-1.min.stderr b/src/test/ui/const-generics/issues/issue-67945-1.min.stderr index 70e2518ca2af..eee04eb75a25 100644 --- a/src/test/ui/const-generics/issues/issue-67945-1.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-1.min.stderr @@ -1,23 +1,23 @@ error: generic parameters may not be used in const operations - --> $DIR/issue-67945-1.rs:13:16 + --> $DIR/issue-67945-1.rs:10:16 | LL | let x: S = MaybeUninit::uninit(); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/issue-67945-1.rs:16:45 + --> $DIR/issue-67945-1.rs:13:45 | LL | let b = &*(&x as *const _ as *const S); | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used - --> $DIR/issue-67945-1.rs:10:12 + --> $DIR/issue-67945-1.rs:7:12 | LL | struct Bug { | ^ unused parameter diff --git a/src/test/ui/const-generics/issues/issue-67945-1.rs b/src/test/ui/const-generics/issues/issue-67945-1.rs index 84737e4e9857..7b7e8428639c 100644 --- a/src/test/ui/const-generics/issues/issue-67945-1.rs +++ b/src/test/ui/const-generics/issues/issue-67945-1.rs @@ -1,11 +1,8 @@ // revisions: full min - #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - -use std::marker::PhantomData; +#![cfg_attr(full, feature(generic_const_exprs))] -use std::mem::{self, MaybeUninit}; +use std::mem::MaybeUninit; struct Bug { //~^ ERROR parameter `S` is never used diff --git a/src/test/ui/const-generics/issues/issue-67945-2.full.stderr b/src/test/ui/const-generics/issues/issue-67945-2.full.stderr index b90040602311..118cf447c01e 100644 --- a/src/test/ui/const-generics/issues/issue-67945-2.full.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-2.full.stderr @@ -1,27 +1,17 @@ -error[E0308]: mismatched types - --> $DIR/issue-67945-2.rs:11:20 +error: overly complex generic constant + --> $DIR/issue-67945-2.rs:7:13 | -LL | struct Bug { - | - this type parameter -... -LL | let x: S = MaybeUninit::uninit(); - | - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found union `MaybeUninit` - | | - | expected due to this +LL | A: [(); { + | _____________^ +LL | | +LL | | let x: Option> = None; + | | ---- unsupported rvalue +LL | | +LL | | 0 +LL | | }], + | |_____^ | - = note: expected type parameter `S` - found union `MaybeUninit<_>` + = help: consider moving this anonymous constant into a `const` function -error[E0392]: parameter `S` is never used - --> $DIR/issue-67945-2.rs:8:12 - | -LL | struct Bug { - | ^ unused parameter - | - = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` - = help: if you intended `S` to be a const parameter, use `const S: usize` instead - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0308, E0392. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-67945-2.min.stderr b/src/test/ui/const-generics/issues/issue-67945-2.min.stderr index 24476d4fac8f..6e07af1e672a 100644 --- a/src/test/ui/const-generics/issues/issue-67945-2.min.stderr +++ b/src/test/ui/const-generics/issues/issue-67945-2.min.stderr @@ -1,30 +1,8 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-67945-2.rs:11:16 +error: generic `Self` types are currently not permitted in anonymous constants + --> $DIR/issue-67945-2.rs:9:27 | -LL | let x: S = MaybeUninit::uninit(); - | ^ cannot perform const operation using `S` - | - = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/issue-67945-2.rs:14:45 - | -LL | let b = &*(&x as *const _ as *const S); - | ^ cannot perform const operation using `S` - | - = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error[E0392]: parameter `S` is never used - --> $DIR/issue-67945-2.rs:8:12 - | -LL | struct Bug { - | ^ unused parameter - | - = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` - = help: if you intended `S` to be a const parameter, use `const S: usize` instead +LL | let x: Option> = None; + | ^^^^ -error: aborting due to 3 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0392`. diff --git a/src/test/ui/const-generics/issues/issue-67945-2.rs b/src/test/ui/const-generics/issues/issue-67945-2.rs index 4a46786e9a9b..cbb4e14eccf7 100644 --- a/src/test/ui/const-generics/issues/issue-67945-2.rs +++ b/src/test/ui/const-generics/issues/issue-67945-2.rs @@ -1,20 +1,16 @@ // revisions: full min #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] -use std::mem::MaybeUninit; - -struct Bug { - //~^ ERROR parameter `S` is never used +struct Bug { A: [(); { - let x: S = MaybeUninit::uninit(); - //[min]~^ ERROR generic parameters may not be used in const operations - //[full]~^^ ERROR mismatched types - let b = &*(&x as *const _ as *const S); - //[min]~^ ERROR generic parameters may not be used in const operations + //[full]~^ ERROR overly complex generic constant + let x: Option> = None; + //[min]~^ ERROR generic `Self` types are currently not permitted in anonymous constants 0 }], + B: S } fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-67945-3.full.stderr b/src/test/ui/const-generics/issues/issue-67945-3.full.stderr deleted file mode 100644 index fa66252bd694..000000000000 --- a/src/test/ui/const-generics/issues/issue-67945-3.full.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-67945-3.rs:7:8 - | -LL | A: [(); { - | ________^ -LL | | -LL | | let x: Option> = None; -LL | | -LL | | 0 -LL | | }], - | |______^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-67945-3.min.stderr b/src/test/ui/const-generics/issues/issue-67945-3.min.stderr deleted file mode 100644 index 5c30429c8958..000000000000 --- a/src/test/ui/const-generics/issues/issue-67945-3.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: generic `Self` types are currently not permitted in anonymous constants - --> $DIR/issue-67945-3.rs:9:27 - | -LL | let x: Option> = None; - | ^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-67945-3.rs b/src/test/ui/const-generics/issues/issue-67945-3.rs deleted file mode 100644 index 5bad61cfc763..000000000000 --- a/src/test/ui/const-generics/issues/issue-67945-3.rs +++ /dev/null @@ -1,16 +0,0 @@ -// revisions: full min - -#![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_generics))] - -struct Bug { - A: [(); { - //[full]~^ ERROR constant expression depends on a generic parameter - let x: Option> = None; - //[min]~^ ERROR generic `Self` types are currently not permitted in anonymous constants - 0 - }], - B: S -} - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-68104-print-stack-overflow.rs b/src/test/ui/const-generics/issues/issue-68104-print-stack-overflow.rs index 43c3999133c6..ad5710baae2b 100644 --- a/src/test/ui/const-generics/issues/issue-68104-print-stack-overflow.rs +++ b/src/test/ui/const-generics/issues/issue-68104-print-stack-overflow.rs @@ -1,9 +1,7 @@ // aux-build:impl-const.rs // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] extern crate impl_const; diff --git a/src/test/ui/const-generics/issues/issue-68366.min.stderr b/src/test/ui/const-generics/issues/issue-68366.min.stderr index 9519b23b4844..9f370b0f510f 100644 --- a/src/test/ui/const-generics/issues/issue-68366.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68366.min.stderr @@ -5,7 +5,7 @@ LL | impl Collatz<{Some(N)}> {} | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates --> $DIR/issue-68366.rs:11:13 diff --git a/src/test/ui/const-generics/issues/issue-68366.rs b/src/test/ui/const-generics/issues/issue-68366.rs index 37afed62327d..4c2741ab4337 100644 --- a/src/test/ui/const-generics/issues/issue-68366.rs +++ b/src/test/ui/const-generics/issues/issue-68366.rs @@ -3,7 +3,7 @@ // type. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] struct Collatz>; diff --git a/src/test/ui/const-generics/issues/issue-68596.rs b/src/test/ui/const-generics/issues/issue-68596.rs index 0bb23be1eb4e..c3c9141e424d 100644 --- a/src/test/ui/const-generics/issues/issue-68596.rs +++ b/src/test/ui/const-generics/issues/issue-68596.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub struct S(u8); impl S { diff --git a/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr b/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr index 4782b1d98eba..040f65a8edaf 100644 --- a/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr @@ -5,7 +5,7 @@ LL | struct Const {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-68615-adt.rs b/src/test/ui/const-generics/issues/issue-68615-adt.rs index ddea3e8ab658..5d0f9ae0b1dc 100644 --- a/src/test/ui/const-generics/issues/issue-68615-adt.rs +++ b/src/test/ui/const-generics/issues/issue-68615-adt.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Const {} diff --git a/src/test/ui/const-generics/issues/issue-68615-array.min.stderr b/src/test/ui/const-generics/issues/issue-68615-array.min.stderr index d0c190b91b04..3f4153f3f351 100644 --- a/src/test/ui/const-generics/issues/issue-68615-array.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68615-array.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-68615-array.rs b/src/test/ui/const-generics/issues/issue-68615-array.rs index 56afd9b2a154..4dbc56b4bd2b 100644 --- a/src/test/ui/const-generics/issues/issue-68615-array.rs +++ b/src/test/ui/const-generics/issues/issue-68615-array.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Foo {} diff --git a/src/test/ui/const-generics/issues/issue-68977.full.stderr b/src/test/ui/const-generics/issues/issue-68977.full.stderr deleted file mode 100644 index 25dcd88a4afc..000000000000 --- a/src/test/ui/const-generics/issues/issue-68977.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-68977.rs:34:44 - | -LL | FxpStorageHelper: FxpStorage, - | ^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-68977.min.stderr b/src/test/ui/const-generics/issues/issue-68977.min.stderr deleted file mode 100644 index 78da8412cdfb..000000000000 --- a/src/test/ui/const-generics/issues/issue-68977.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/issue-68977.rs:28:17 - | -LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>; - | ^^^^^^^^ cannot perform const operation using `INT_BITS` - | - = help: const parameters may only be used as standalone arguments, i.e. `INT_BITS` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/issue-68977.rs:28:28 - | -LL | PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>; - | ^^^^^^^^^ cannot perform const operation using `FRAC_BITS` - | - = help: const parameters may only be used as standalone arguments, i.e. `FRAC_BITS` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-68977.rs b/src/test/ui/const-generics/issues/issue-68977.rs deleted file mode 100644 index a0ffcc84c7a3..000000000000 --- a/src/test/ui/const-generics/issues/issue-68977.rs +++ /dev/null @@ -1,43 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -struct PhantomU8; - -trait FxpStorage { - type SInt; // Add arithmetic traits as needed. -} - -macro_rules! fxp_storage_impls { - ($($($n:literal)|+ => $sint:ty),* $(,)?) => { - $($(impl FxpStorage for PhantomU8<$n> { - type SInt = $sint; - })*)* - } -} - -fxp_storage_impls! { - 1 => i8, - 2 => i16, - 3 | 4 => i32, - 5 | 6 | 7 | 8 => i64, - 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => i128, -} - -type FxpStorageHelper = - PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>; - //[min]~^ ERROR generic parameters may not be used in const operations - //[min]~| ERROR generic parameters may not be used in const operations - -struct Fxp -where - FxpStorageHelper: FxpStorage, - //[full]~^ ERROR constant expression depends on a generic parameter -{ - storage: as FxpStorage>::SInt, -} - -fn main() { - Fxp::<1, 15> { storage: 0i16 }; - Fxp::<2, 15> { storage: 0i32 }; -} diff --git a/src/test/ui/const-generics/issues/issue-69654-run-pass.rs b/src/test/ui/const-generics/issues/issue-69654-run-pass.rs index 45318ca68fcc..63d7fde78ac8 100644 --- a/src/test/ui/const-generics/issues/issue-69654-run-pass.rs +++ b/src/test/ui/const-generics/issues/issue-69654-run-pass.rs @@ -1,8 +1,6 @@ -#![feature(const_generics)] -#![allow(incomplete_features, unused_braces)] - +// run-pass trait Bar {} -impl Bar for [u8; {7}] {} +impl Bar for [u8; 7] {} struct Foo {} impl Foo @@ -14,5 +12,4 @@ where fn main() { Foo::foo(); - //~^ ERROR the function or associated item } diff --git a/src/test/ui/const-generics/issues/issue-69654-run-pass.stderr b/src/test/ui/const-generics/issues/issue-69654-run-pass.stderr deleted file mode 100644 index a82a60696b36..000000000000 --- a/src/test/ui/const-generics/issues/issue-69654-run-pass.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0599]: the function or associated item `foo` exists for struct `Foo<{_: usize}>`, but its trait bounds were not satisfied - --> $DIR/issue-69654-run-pass.rs:16:10 - | -LL | struct Foo {} - | -------------------------- function or associated item `foo` not found for this -... -LL | Foo::foo(); - | ^^^ function or associated item cannot be called on `Foo<{_: usize}>` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `[u8; _]: Bar<[(); _]>` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/const-generics/issues/issue-70125-1.rs b/src/test/ui/const-generics/issues/issue-70125-1.rs index 5c118d245a1e..0027cd46a519 100644 --- a/src/test/ui/const-generics/issues/issue-70125-1.rs +++ b/src/test/ui/const-generics/issues/issue-70125-1.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] const L: usize = 4; diff --git a/src/test/ui/const-generics/issues/issue-70125-2.rs b/src/test/ui/const-generics/issues/issue-70125-2.rs index f82131262d6e..cfd5e784ec40 100644 --- a/src/test/ui/const-generics/issues/issue-70125-2.rs +++ b/src/test/ui/const-generics/issues/issue-70125-2.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn main() { <()>::foo(); } diff --git a/src/test/ui/const-generics/issues/issue-70167.rs b/src/test/ui/const-generics/issues/issue-70167.rs index 9e912b691773..3961941f81fa 100644 --- a/src/test/ui/const-generics/issues/issue-70167.rs +++ b/src/test/ui/const-generics/issues/issue-70167.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub trait Trait: From<>::Item> { type Item; } diff --git a/src/test/ui/const-generics/issues/issue-70180-1-stalled_on.rs b/src/test/ui/const-generics/issues/issue-70180-1-stalled_on.rs index f0554823273a..2ec37cc3a1be 100644 --- a/src/test/ui/const-generics/issues/issue-70180-1-stalled_on.rs +++ b/src/test/ui/const-generics/issues/issue-70180-1-stalled_on.rs @@ -1,8 +1,4 @@ // build-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] pub fn works() { let array/*: [_; _]*/ = default_array(); diff --git a/src/test/ui/const-generics/issues/issue-70180-2-stalled_on.rs b/src/test/ui/const-generics/issues/issue-70180-2-stalled_on.rs index 21cefc09c253..95e548428747 100644 --- a/src/test/ui/const-generics/issues/issue-70180-2-stalled_on.rs +++ b/src/test/ui/const-generics/issues/issue-70180-2-stalled_on.rs @@ -1,8 +1,4 @@ // build-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] fn works() { let array/*: [u8; _]*/ = default_byte_array(); diff --git a/src/test/ui/const-generics/issues/issue-70225.rs b/src/test/ui/const-generics/issues/issue-70225.rs index 8f8d753d0a75..d458d7b2e871 100644 --- a/src/test/ui/const-generics/issues/issue-70225.rs +++ b/src/test/ui/const-generics/issues/issue-70225.rs @@ -1,6 +1,4 @@ // check-pass -#![feature(const_generics)] -#![allow(incomplete_features)] #![deny(dead_code)] // We previously incorrectly linted `L` as unused here. diff --git a/src/test/ui/const-generics/issues/issue-70273-assoc-fn.rs b/src/test/ui/const-generics/issues/issue-70273-assoc-fn.rs index 189a32570f76..a76488249173 100644 --- a/src/test/ui/const-generics/issues/issue-70273-assoc-fn.rs +++ b/src/test/ui/const-generics/issues/issue-70273-assoc-fn.rs @@ -1,7 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait T { fn f(); diff --git a/src/test/ui/const-generics/issues/issue-71169.full.stderr b/src/test/ui/const-generics/issues/issue-71169.full.stderr index 7b1a2f98dfeb..1f5880f368ee 100644 --- a/src/test/ui/const-generics/issues/issue-71169.full.stderr +++ b/src/test/ui/const-generics/issues/issue-71169.full.stderr @@ -4,14 +4,6 @@ error[E0770]: the type of const parameters must not depend on other generic para LL | fn foo() {} | ^^^ the type must not depend on the parameter `LEN` -error: constant expression depends on a generic parameter - --> $DIR/issue-71169.rs:10:14 - | -LL | foo::<4, DATA>(); - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0770`. diff --git a/src/test/ui/const-generics/issues/issue-71169.min.stderr b/src/test/ui/const-generics/issues/issue-71169.min.stderr index 1c6e08adffdf..ed360c96f289 100644 --- a/src/test/ui/const-generics/issues/issue-71169.min.stderr +++ b/src/test/ui/const-generics/issues/issue-71169.min.stderr @@ -11,7 +11,7 @@ LL | fn foo() {} | ^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-71169.rs b/src/test/ui/const-generics/issues/issue-71169.rs index a574da4b6b31..f949bc979ba6 100644 --- a/src/test/ui/const-generics/issues/issue-71169.rs +++ b/src/test/ui/const-generics/issues/issue-71169.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] fn foo() {} @@ -8,5 +8,4 @@ fn foo() {} fn main() { const DATA: [u8; 4] = *b"ABCD"; foo::<4, DATA>(); - //[full]~^ ERROR constant expression depends on } diff --git a/src/test/ui/const-generics/issues/issue-71202.rs b/src/test/ui/const-generics/issues/issue-71202.rs index 78dee1717f1f..57fd72b12846 100644 --- a/src/test/ui/const-generics/issues/issue-71202.rs +++ b/src/test/ui/const-generics/issues/issue-71202.rs @@ -1,6 +1,4 @@ -// check-pass - -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features, const_evaluatable_unchecked)] use std::marker::PhantomData; @@ -10,7 +8,7 @@ struct DataHolder { } impl DataHolder { - const ITEM_IS_COPY: [(); 1 - { + const ITEM_IS_COPY: [(); 1 - { //~ ERROR unconstrained generic constant trait NotCopy { const VALUE: bool = false; } diff --git a/src/test/ui/const-generics/issues/issue-71202.stderr b/src/test/ui/const-generics/issues/issue-71202.stderr new file mode 100644 index 000000000000..277540610864 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-71202.stderr @@ -0,0 +1,33 @@ +error: unconstrained generic constant + --> $DIR/issue-71202.rs:11:5 + | +LL | / const ITEM_IS_COPY: [(); 1 - { +LL | | trait NotCopy { +LL | | const VALUE: bool = false; +LL | | } +... | +LL | | >::VALUE +LL | | } as usize] = []; + | |_____________________^ + | + = help: try adding a `where` bound using this expression: `where [(); 1 - { + trait NotCopy { + const VALUE: bool = false; + } + + impl<__Type: ?Sized> NotCopy for __Type {} + + struct IsCopy<__Type: ?Sized>(PhantomData<__Type>); + + impl<__Type> IsCopy<__Type> + where + __Type: Sized + Copy, + { + const VALUE: bool = true; + } + + >::VALUE + } as usize]:` + +error: aborting due to previous error + diff --git a/src/test/ui/const-generics/issues/issue-71381.rs b/src/test/ui/const-generics/issues/issue-71381.rs index f015d6946954..b24bc241d42c 100644 --- a/src/test/ui/const-generics/issues/issue-71381.rs +++ b/src/test/ui/const-generics/issues/issue-71381.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Test(*const usize); diff --git a/src/test/ui/const-generics/issues/issue-71382.rs b/src/test/ui/const-generics/issues/issue-71382.rs index 3a56db937de0..5663012dc637 100644 --- a/src/test/ui/const-generics/issues/issue-71382.rs +++ b/src/test/ui/const-generics/issues/issue-71382.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Test(); diff --git a/src/test/ui/const-generics/issues/issue-71611.rs b/src/test/ui/const-generics/issues/issue-71611.rs index 6468d0b6bdae..c82916e85a28 100644 --- a/src/test/ui/const-generics/issues/issue-71611.rs +++ b/src/test/ui/const-generics/issues/issue-71611.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] fn func(outer: A) { diff --git a/src/test/ui/const-generics/issues/issue-71986.rs b/src/test/ui/const-generics/issues/issue-71986.rs index 6bfdba5711ef..6f0a98ead887 100644 --- a/src/test/ui/const-generics/issues/issue-71986.rs +++ b/src/test/ui/const-generics/issues/issue-71986.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] pub trait Foo {} pub fn bar>() {} diff --git a/src/test/ui/const-generics/issues/issue-72352.rs b/src/test/ui/const-generics/issues/issue-72352.rs index 9cd95c11026d..8e292356f7e2 100644 --- a/src/test/ui/const-generics/issues/issue-72352.rs +++ b/src/test/ui/const-generics/issues/issue-72352.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] use std::ffi::{CStr, CString}; diff --git a/src/test/ui/const-generics/issues/issue-72787.full.stderr b/src/test/ui/const-generics/issues/issue-72787.full.stderr deleted file mode 100644 index fbb7ae59bef7..000000000000 --- a/src/test/ui/const-generics/issues/issue-72787.full.stderr +++ /dev/null @@ -1,42 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-72787.rs:10:32 - | -LL | Condition<{ LHS <= RHS }>: True - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-72787.rs:25:42 - | -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-72787.rs:25:42 - | -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-72787.rs:25:42 - | -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-72787.rs:25:42 - | -LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True, - | ^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 5 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.full.stderr b/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.full.stderr deleted file mode 100644 index 82f9b9d346dd..000000000000 --- a/src/test/ui/const-generics/issues/issue-72819-generic-in-const-eval.full.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-72819-generic-in-const-eval.rs:8:39 - | -LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, - | ^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-73120.rs b/src/test/ui/const-generics/issues/issue-73120.rs index c153a93cdef4..050dc9bde64b 100644 --- a/src/test/ui/const-generics/issues/issue-73120.rs +++ b/src/test/ui/const-generics/issues/issue-73120.rs @@ -1,6 +1,7 @@ -// revisions: full min // check-pass // aux-build:const_generic_issues_lib.rs +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] extern crate const_generic_issues_lib as lib2; fn unused_function( _: as lib2::TypeFn>::Output diff --git a/src/test/ui/const-generics/issues/issue-73260.rs b/src/test/ui/const-generics/issues/issue-73260.rs index 04e4e9cd52b0..d762f9c8b262 100644 --- a/src/test/ui/const-generics/issues/issue-73260.rs +++ b/src/test/ui/const-generics/issues/issue-73260.rs @@ -1,11 +1,10 @@ // compile-flags: -Zsave-analysis - -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Arr -where Assert::<{N < usize::MAX / 2}>: IsTrue, //~ ERROR constant expression -{ -} +where + Assert::<{N < usize::MAX / 2}>: IsTrue, +{} enum Assert {} diff --git a/src/test/ui/const-generics/issues/issue-73260.stderr b/src/test/ui/const-generics/issues/issue-73260.stderr index 6a912ffc3c01..f1fc50e6e591 100644 --- a/src/test/ui/const-generics/issues/issue-73260.stderr +++ b/src/test/ui/const-generics/issues/issue-73260.stderr @@ -1,13 +1,5 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-73260.rs:6:39 - | -LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, - | ^^^^^^ - | - = note: this may fail depending on what value the parameter takes - error[E0308]: mismatched types - --> $DIR/issue-73260.rs:17:12 + --> $DIR/issue-73260.rs:16:12 | LL | let x: Arr<{usize::MAX}> = Arr {}; | ^^^^^^^^^^^^^^^^^ expected `false`, found `true` @@ -16,7 +8,7 @@ LL | let x: Arr<{usize::MAX}> = Arr {}; found type `true` error[E0308]: mismatched types - --> $DIR/issue-73260.rs:17:32 + --> $DIR/issue-73260.rs:16:32 | LL | let x: Arr<{usize::MAX}> = Arr {}; | ^^^ expected `false`, found `true` @@ -24,6 +16,6 @@ LL | let x: Arr<{usize::MAX}> = Arr {}; = note: expected type `false` found type `true` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-73491.min.stderr b/src/test/ui/const-generics/issues/issue-73491.min.stderr index c8f2e0dadc1a..2b470f5eaecd 100644 --- a/src/test/ui/const-generics/issues/issue-73491.min.stderr +++ b/src/test/ui/const-generics/issues/issue-73491.min.stderr @@ -5,7 +5,7 @@ LL | fn hoge() {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-73491.rs b/src/test/ui/const-generics/issues/issue-73491.rs index c7cb92baf30a..2108661ab251 100644 --- a/src/test/ui/const-generics/issues/issue-73491.rs +++ b/src/test/ui/const-generics/issues/issue-73491.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] const LEN: usize = 1024; diff --git a/src/test/ui/const-generics/issues/issue-73508.full.stderr b/src/test/ui/const-generics/issues/issue-73508.full.stderr deleted file mode 100644 index 81691a14ef67..000000000000 --- a/src/test/ui/const-generics/issues/issue-73508.full.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: using raw pointers as const generic parameters is forbidden - --> $DIR/issue-73508.rs:5:33 - | -LL | pub const fn func_name() {} - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-73508.min.stderr b/src/test/ui/const-generics/issues/issue-73508.min.stderr deleted file mode 100644 index 81691a14ef67..000000000000 --- a/src/test/ui/const-generics/issues/issue-73508.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: using raw pointers as const generic parameters is forbidden - --> $DIR/issue-73508.rs:5:33 - | -LL | pub const fn func_name() {} - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-73508.rs b/src/test/ui/const-generics/issues/issue-73508.rs deleted file mode 100644 index f02c4161dc10..000000000000 --- a/src/test/ui/const-generics/issues/issue-73508.rs +++ /dev/null @@ -1,8 +0,0 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -pub const fn func_name() {} -//~^ ERROR using raw pointers - -fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-74101.min.stderr b/src/test/ui/const-generics/issues/issue-74101.min.stderr index a7f0ecf0a269..b8fe9736ba5b 100644 --- a/src/test/ui/const-generics/issues/issue-74101.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74101.min.stderr @@ -5,7 +5,7 @@ LL | fn test() {} | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `[u8; _]` is forbidden as the type of a const generic parameter --> $DIR/issue-74101.rs:9:21 @@ -14,7 +14,7 @@ LL | struct Foo; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-74101.rs b/src/test/ui/const-generics/issues/issue-74101.rs index d4fd72eb6daa..f976912e11cf 100644 --- a/src/test/ui/const-generics/issues/issue-74101.rs +++ b/src/test/ui/const-generics/issues/issue-74101.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] fn test() {} diff --git a/src/test/ui/const-generics/issues/issue-74255.min.stderr b/src/test/ui/const-generics/issues/issue-74255.min.stderr index 62ad43974f4d..9099b61e63bd 100644 --- a/src/test/ui/const-generics/issues/issue-74255.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74255.min.stderr @@ -5,7 +5,7 @@ LL | fn ice_struct_fn() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-74255.rs b/src/test/ui/const-generics/issues/issue-74255.rs index 75a876c27e59..cfb2b703ddce 100644 --- a/src/test/ui/const-generics/issues/issue-74255.rs +++ b/src/test/ui/const-generics/issues/issue-74255.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/issues/issue-74634.stderr b/src/test/ui/const-generics/issues/issue-74634.stderr deleted file mode 100644 index 091a1ac7b998..000000000000 --- a/src/test/ui/const-generics/issues/issue-74634.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-74634.rs:15:11 - | -LL | where (): If<{N == 0}> { - | ^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/issues/issue-74906.rs b/src/test/ui/const-generics/issues/issue-74906.rs index dc3c33736dab..cc1f2853fb2a 100644 --- a/src/test/ui/const-generics/issues/issue-74906.rs +++ b/src/test/ui/const-generics/issues/issue-74906.rs @@ -1,8 +1,6 @@ // edition:2018 // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] + const SIZE: usize = 16; diff --git a/src/test/ui/const-generics/issues/issue-74950.min.stderr b/src/test/ui/const-generics/issues/issue-74950.min.stderr index 4e640ff857ea..eaf02e1bd471 100644 --- a/src/test/ui/const-generics/issues/issue-74950.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74950.min.stderr @@ -5,7 +5,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -14,7 +14,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -23,7 +23,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -32,7 +32,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -41,7 +41,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 5 previous errors diff --git a/src/test/ui/const-generics/issues/issue-74950.rs b/src/test/ui/const-generics/issues/issue-74950.rs index 91e5cc776fac..941335518a8b 100644 --- a/src/test/ui/const-generics/issues/issue-74950.rs +++ b/src/test/ui/const-generics/issues/issue-74950.rs @@ -1,6 +1,6 @@ // [full] build-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] diff --git a/src/test/ui/const-generics/issues/issue-75047.min.stderr b/src/test/ui/const-generics/issues/issue-75047.min.stderr index 3c1c3ea97b54..7a8c817c0d6a 100644 --- a/src/test/ui/const-generics/issues/issue-75047.min.stderr +++ b/src/test/ui/const-generics/issues/issue-75047.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo::value()]>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-75047.rs b/src/test/ui/const-generics/issues/issue-75047.rs index 97437748177e..e8be1e300516 100644 --- a/src/test/ui/const-generics/issues/issue-75047.rs +++ b/src/test/ui/const-generics/issues/issue-75047.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Bar(T); diff --git a/src/test/ui/const-generics/issues/issue-75299.rs b/src/test/ui/const-generics/issues/issue-75299.rs index 9d3f25b3b47f..83ef09af88e3 100644 --- a/src/test/ui/const-generics/issues/issue-75299.rs +++ b/src/test/ui/const-generics/issues/issue-75299.rs @@ -1,8 +1,5 @@ // compile-flags: -Zmir-opt-level=4 // run-pass - -#![feature(const_generics)] -#![allow(incomplete_features)] fn main() { fn foo() -> [u8; N] { [0; N] diff --git a/src/test/ui/const-generics/issues/issue-75763.rs b/src/test/ui/const-generics/issues/issue-75763.rs index c311de05a1cf..400c034a9276 100644 --- a/src/test/ui/const-generics/issues/issue-75763.rs +++ b/src/test/ui/const-generics/issues/issue-75763.rs @@ -1,15 +1,15 @@ // ignore-test // FIXME(const_generics): This test causes an ICE after reverting #76030. - +#![feature(const_param_types)] #![allow(incomplete_features)] -#![feature(const_generics)] + struct Bug; fn main() { let b: Bug::<{ unsafe { - // FIXME(const_generics): Decide on how to deal with invalid values as const params. + // FIXME(const_param_types): Decide on how to deal with invalid values as const params. std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) } }>; diff --git a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.full.stderr b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.full.stderr deleted file mode 100644 index 88b8ff89ffe1..000000000000 --- a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.full.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/issue-76701-ty-param-in-const.rs:5:21 - | -LL | fn ty_param() -> [u8; std::mem::size_of::()] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/issue-76701-ty-param-in-const.rs:11:37 - | -LL | fn const_param() -> [u8; N + 1] { - | ^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.rs b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.rs index 994898265635..2e6b0223656a 100644 --- a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.rs +++ b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.rs @@ -1,16 +1,10 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn ty_param() -> [u8; std::mem::size_of::()] { - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations + //~^ ERROR generic parameters may not be used in const operations todo!() } fn const_param() -> [u8; N + 1] { - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations + //~^ ERROR generic parameters may not be used in const operations todo!() } diff --git a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.stderr similarity index 65% rename from src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr rename to src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.stderr index efff3f42a3e5..3b53e18e6f56 100644 --- a/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.min.stderr +++ b/src/test/ui/const-generics/issues/issue-76701-ty-param-in-const.stderr @@ -1,20 +1,20 @@ error: generic parameters may not be used in const operations - --> $DIR/issue-76701-ty-param-in-const.rs:5:46 + --> $DIR/issue-76701-ty-param-in-const.rs:1:46 | LL | fn ty_param() -> [u8; std::mem::size_of::()] { | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/issue-76701-ty-param-in-const.rs:11:42 + --> $DIR/issue-76701-ty-param-in-const.rs:6:42 | LL | fn const_param() -> [u8; N + 1] { | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-80062.stderr b/src/test/ui/const-generics/issues/issue-80062.stderr index c714253b909d..754f18d5cc42 100644 --- a/src/test/ui/const-generics/issues/issue-80062.stderr +++ b/src/test/ui/const-generics/issues/issue-80062.stderr @@ -5,7 +5,7 @@ LL | let _: [u8; sof::()]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-80375.stderr b/src/test/ui/const-generics/issues/issue-80375.stderr index f80029680ff9..5409002a9fde 100644 --- a/src/test/ui/const-generics/issues/issue-80375.stderr +++ b/src/test/ui/const-generics/issues/issue-80375.stderr @@ -5,7 +5,7 @@ LL | struct MyArray([u8; COUNT + 1]); | ^^^^^ cannot perform const operation using `COUNT` | = help: const parameters may only be used as standalone arguments, i.e. `COUNT` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-87076.rs b/src/test/ui/const-generics/issues/issue-87076.rs index 5dfda943bf69..05ba266d2d87 100644 --- a/src/test/ui/const-generics/issues/issue-87076.rs +++ b/src/test/ui/const-generics/issues/issue-87076.rs @@ -1,6 +1,6 @@ // build-pass -#![feature(const_generics)] +#![feature(const_param_types)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/late-bound-vars/in_closure.rs b/src/test/ui/const-generics/late-bound-vars/in_closure.rs index 0aaeaffb4cb9..5294cc3b5f42 100644 --- a/src/test/ui/const-generics/late-bound-vars/in_closure.rs +++ b/src/test/ui/const-generics/late-bound-vars/in_closure.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] const fn inner<'a>() -> usize where &'a (): Sized { diff --git a/src/test/ui/const-generics/late-bound-vars/simple.rs b/src/test/ui/const-generics/late-bound-vars/simple.rs index 2c411a3bdc5f..6da5395ef83c 100644 --- a/src/test/ui/const-generics/late-bound-vars/simple.rs +++ b/src/test/ui/const-generics/late-bound-vars/simple.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] const fn inner<'a>() -> usize where &'a (): Sized { diff --git a/src/test/ui/const-generics/macro_rules-braces.full.stderr b/src/test/ui/const-generics/macro_rules-braces.full.stderr deleted file mode 100644 index b29e853510b1..000000000000 --- a/src/test/ui/const-generics/macro_rules-braces.full.stderr +++ /dev/null @@ -1,72 +0,0 @@ -error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/macro_rules-braces.rs:48:17 - | -LL | let _: baz!(m::P); - | ^^^^ - | -help: enclose the `const` expression in braces - | -LL | let _: baz!({ m::P }); - | + + - -error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/macro_rules-braces.rs:68:17 - | -LL | let _: baz!(10 + 7); - | ^^^^^^ - | -help: enclose the `const` expression in braces - | -LL | let _: baz!({ 10 + 7 }); - | + + - -error: constant expression depends on a generic parameter - --> $DIR/macro_rules-braces.rs:15:13 - | -LL | [u8; $x] - | ^^^^^^^^ -... -LL | let _: foo!({{ N }}); - | ------------- in this macro invocation - | - = note: this may fail depending on what value the parameter takes - = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: constant expression depends on a generic parameter - --> $DIR/macro_rules-braces.rs:20:13 - | -LL | [u8; { $x }] - | ^^^^^^^^^^^^ -... -LL | let _: bar!({ N }); - | ----------- in this macro invocation - | - = note: this may fail depending on what value the parameter takes - = note: this error originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: constant expression depends on a generic parameter - --> $DIR/macro_rules-braces.rs:25:13 - | -LL | Foo<$x> - | ^^^^^^^ -... -LL | let _: baz!({{ N }}); - | ------------- in this macro invocation - | - = note: this may fail depending on what value the parameter takes - = note: this error originates in the macro `baz` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: constant expression depends on a generic parameter - --> $DIR/macro_rules-braces.rs:30:13 - | -LL | Foo<{ $x }> - | ^^^^^^^^^^^ -... -LL | let _: biz!({ N }); - | ----------- in this macro invocation - | - = note: this may fail depending on what value the parameter takes - = note: this error originates in the macro `biz` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 6 previous errors - diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr index 8d9246fe56f4..bf0d0f352ebc 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr +++ b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr @@ -5,7 +5,7 @@ LL | struct Break0([u8; { N + 1 }]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:12:40 @@ -14,7 +14,7 @@ LL | struct Break1([u8; { { N } }]); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:16:17 @@ -23,7 +23,7 @@ LL | let _: [u8; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:21:17 @@ -32,7 +32,7 @@ LL | let _ = [0; N + 1]; | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:25:45 @@ -41,7 +41,7 @@ LL | struct BreakTy0(T, [u8; { size_of::<*mut T>() }]); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:28:47 @@ -50,7 +50,7 @@ LL | struct BreakTy1(T, [u8; { { size_of::<*mut T>() } }]); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations --> $DIR/complex-expression.rs:32:32 @@ -59,7 +59,7 @@ LL | let _: [u8; size_of::<*mut T>() + 1]; | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions warning: cannot use constants which depend on generic parameters in types --> $DIR/complex-expression.rs:37:17 diff --git a/src/test/ui/const-generics/min_const_generics/complex-types.stderr b/src/test/ui/const-generics/min_const_generics/complex-types.stderr index a658a7b39568..12ffbd53ab0a 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-types.stderr +++ b/src/test/ui/const-generics/min_const_generics/complex-types.stderr @@ -5,7 +5,7 @@ LL | struct Foo; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:6:21 @@ -14,7 +14,7 @@ LL | struct Bar; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `No` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:11:21 @@ -23,7 +23,7 @@ LL | struct Fez; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:14:21 @@ -32,7 +32,7 @@ LL | struct Faz; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `!` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:17:21 @@ -41,7 +41,7 @@ LL | struct Fiz; | ^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:20:19 @@ -50,7 +50,7 @@ LL | enum Goo { A, B } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:23:20 @@ -59,7 +59,7 @@ LL | union Boo { a: () } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 7 previous errors diff --git a/src/test/ui/const-generics/min_const_generics/const_default_first.rs b/src/test/ui/const-generics/min_const_generics/const_default_first.rs index ae82c85eb7e4..bba4e68d4cce 100644 --- a/src/test/ui/const-generics/min_const_generics/const_default_first.rs +++ b/src/test/ui/const-generics/min_const_generics/const_default_first.rs @@ -1,5 +1,4 @@ #![crate_type = "lib"] -#![feature(const_generics)] #![feature(const_generics_defaults)] #![allow(incomplete_features, dead_code)] diff --git a/src/test/ui/const-generics/min_const_generics/const_default_first.stderr b/src/test/ui/const-generics/min_const_generics/const_default_first.stderr index f7a2e484fc61..1a333642f0c3 100644 --- a/src/test/ui/const-generics/min_const_generics/const_default_first.stderr +++ b/src/test/ui/const-generics/min_const_generics/const_default_first.stderr @@ -1,5 +1,5 @@ error: generic parameters with a default must be trailing - --> $DIR/const_default_first.rs:6:19 + --> $DIR/const_default_first.rs:5:19 | LL | struct Both { | ^ diff --git a/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.rs b/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.rs index 881f8b98aad0..6215b7d936cf 100644 --- a/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.rs +++ b/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.rs @@ -1,5 +1,5 @@ // This test checks that non-static lifetimes are prohibited under `min_const_generics`. It -// currently emits an error with `min_const_generics`. This will ICE under `const_generics`. +// currently emits an error with `min_const_generics`. fn test() {} diff --git a/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.stderr b/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.stderr index 5def54ca26d9..5f641b070951 100644 --- a/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.stderr +++ b/src/test/ui/const-generics/min_const_generics/forbid-non-static-lifetimes.stderr @@ -4,8 +4,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | test::<{ let _: &'a (); 3 },>(); | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error[E0658]: a non-static lifetime is not allowed in a `const` --> $DIR/forbid-non-static-lifetimes.rs:21:16 @@ -13,8 +13,8 @@ error[E0658]: a non-static lifetime is not allowed in a `const` LL | [(); (|_: &'a u8| (), 0).1]; | ^^ | - = note: see issue #44580 for more information - = help: add `#![feature(const_generics)]` to the crate attributes to enable + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr index cc114f702392..16a7687c00b5 100644 --- a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr +++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr @@ -5,7 +5,7 @@ LL | fn t1() -> [u8; std::mem::size_of::()]; | ^^^^ cannot perform const operation using `Self` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic `Self` types are currently not permitted in anonymous constants --> $DIR/self-ty-in-const-1.rs:12:41 diff --git a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr index 647ef5400cb2..13e1a232b3aa 100644 --- a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr +++ b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr @@ -5,7 +5,7 @@ LL | fn a() {} | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs b/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs index 435a63a52834..2adfa9a8c4be 100644 --- a/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs +++ b/src/test/ui/const-generics/min_const_generics/type_and_const_defaults.rs @@ -1,7 +1,6 @@ // run-pass -#![feature(const_generics)] #![feature(const_generics_defaults)] -#![allow(incomplete_features, dead_code)] +#![allow(dead_code)] struct Both { arr: [T; N] diff --git a/src/test/ui/const-generics/mut-ref-const-param-array.rs b/src/test/ui/const-generics/mut-ref-const-param-array.rs deleted file mode 100644 index 6a5739db3aef..000000000000 --- a/src/test/ui/const-generics/mut-ref-const-param-array.rs +++ /dev/null @@ -1,21 +0,0 @@ -// run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - - -use std::ops::AddAssign; - -fn inc(v: &mut [T; N]) -> &mut [T; N] { - for x in v.iter_mut() { - *x += x.clone(); - } - v -} - -fn main() { - let mut v = [1, 2, 3]; - inc(&mut v); - assert_eq!(v, [2, 4, 6]); -} diff --git a/src/test/ui/const-generics/nested-type.min.stderr b/src/test/ui/const-generics/nested-type.min.stderr index 6defd393ba06..c435344580a7 100644 --- a/src/test/ui/const-generics/nested-type.min.stderr +++ b/src/test/ui/const-generics/nested-type.min.stderr @@ -12,7 +12,7 @@ LL | | }]>; | |__^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants --> $DIR/nested-type.rs:15:5 diff --git a/src/test/ui/const-generics/nested-type.rs b/src/test/ui/const-generics/nested-type.rs index be8ebb7f401f..b3d62d64f3b4 100644 --- a/src/test/ui/const-generics/nested-type.rs +++ b/src/test/ui/const-generics/nested-type.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Foo(value: [u8; N + 2]) -> [u8; N * 2] { - //~^ ERROR constant expression depends on a generic parameter - //~| ERROR constant expression depends on a generic parameter todo!() } diff --git a/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr index 671f1103dcca..f9b56bd387ae 100644 --- a/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr +++ b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr @@ -1,27 +1,11 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/unify-fixpoint.rs:1:12 +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/unify-fixpoint.rs:2:12 | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #76560 for more information -error: constant expression depends on a generic parameter - --> $DIR/unify-fixpoint.rs:9:32 - | -LL | fn bind(value: [u8; N + 2]) -> [u8; N * 2] { - | ^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/unify-fixpoint.rs:9:48 - | -LL | fn bind(value: [u8; N + 2]) -> [u8; N * 2] { - | ^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors; 1 warning emitted +warning: 1 warning emitted diff --git a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs index 552b1b2a66ac..c6324bca124c 100644 --- a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs +++ b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.rs @@ -1,10 +1,9 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] -// This test would try to unify `N` with `N + 1` which must fail the occurs check. +// This test would tries to unify `N` with `N + 1` which must fail the occurs check. fn bind(value: [u8; N]) -> [u8; N + 1] { - //~^ ERROR constant expression depends on a generic parameter todo!() } @@ -12,6 +11,6 @@ fn sink(_: [u8; 5]) {} fn main() { let mut arr = Default::default(); - arr = bind(arr); + arr = bind(arr); //~ ERROR mismatched types sink(arr); } diff --git a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr index c1ac7eec1e7d..6b8e688fba8d 100644 --- a/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr +++ b/src/test/ui/const-generics/occurs-check/unify-n-nplusone.stderr @@ -1,10 +1,9 @@ -error: constant expression depends on a generic parameter - --> $DIR/unify-n-nplusone.rs:6:44 +error[E0308]: mismatched types + --> $DIR/unify-n-nplusone.rs:14:11 | -LL | fn bind(value: [u8; N]) -> [u8; N + 1] { - | ^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes +LL | arr = bind(arr); + | ^^^^^^^^^ encountered a self-referencing constant error: aborting due to previous error +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-1.rs b/src/test/ui/const-generics/occurs-check/unused-substs-1.rs index 6ded9f13bc4f..9d12250c9143 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-1.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-1.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] trait Bar {} diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-2.rs b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs index 2d00141fbf70..9a73f1a53e52 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-2.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst. diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-3.rs b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs index 2e306f8c4c88..0d38bd393519 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-3.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst. diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-4.rs b/src/test/ui/const-generics/occurs-check/unused-substs-4.rs index 9c7f5ab91edb..03c2f54861b4 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-4.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-4.rs @@ -1,4 +1,4 @@ -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] fn bind(value: [u8; N]) -> [u8; 3 + 4] { diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-5.rs b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs index 961aeefd5505..383ab4cd8c92 100644 --- a/src/test/ui/const-generics/occurs-check/unused-substs-5.rs +++ b/src/test/ui/const-generics/occurs-check/unused-substs-5.rs @@ -1,4 +1,4 @@ -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] // `N + 1` also depends on `T` here even if it doesn't use it. diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr index 1c5ff9175f37..17defbe86aa6 100644 --- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.min.stderr @@ -13,7 +13,7 @@ LL | struct Foo()]>(T, U); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0128]: generic parameters with a default cannot use forward declared identifiers --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21 diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs index 76c1b84aef55..b24a7afabd90 100644 --- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] struct Foo()]>(T, U); diff --git a/src/test/ui/const-generics/parent_generics_of_encoding.rs b/src/test/ui/const-generics/parent_generics_of_encoding.rs index 4d94b789a6c9..b87e3960fc92 100644 --- a/src/test/ui/const-generics/parent_generics_of_encoding.rs +++ b/src/test/ui/const-generics/parent_generics_of_encoding.rs @@ -1,6 +1,6 @@ // aux-build:generics_of_parent.rs // check-pass -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate generics_of_parent; diff --git a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs index 5ac5161ca8f7..ed81c01bb172 100644 --- a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs +++ b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs @@ -1,5 +1,5 @@ // aux-build:generics_of_parent_impl_trait.rs -#![feature(const_generics, generic_const_exprs)] +#![feature(generic_const_exprs)] #![allow(incomplete_features)] extern crate generics_of_parent_impl_trait; diff --git a/src/test/ui/const-generics/raw-ptr-const-param-deref.rs b/src/test/ui/const-generics/raw-ptr-const-param-deref.rs index ca7d33c0eb98..302dd47e9b7f 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param-deref.rs +++ b/src/test/ui/const-generics/raw-ptr-const-param-deref.rs @@ -1,7 +1,7 @@ // Checks that pointers must not be used as the type of const params. // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] const A: u32 = 3; diff --git a/src/test/ui/const-generics/raw-ptr-const-param.rs b/src/test/ui/const-generics/raw-ptr-const-param.rs index a04c6d5e64e1..35ff7768a910 100644 --- a/src/test/ui/const-generics/raw-ptr-const-param.rs +++ b/src/test/ui/const-generics/raw-ptr-const-param.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Const; //~ ERROR: using raw pointers as const generic parameters diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr b/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr index 166a35ee4556..0a4581afc29f 100644 --- a/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr +++ b/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr @@ -5,7 +5,7 @@ LL | struct ConstString; | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static [u8]` is forbidden as the type of a const generic parameter --> $DIR/slice-const-param-mismatch.rs:9:28 @@ -14,7 +14,7 @@ LL | struct ConstBytes; | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.rs b/src/test/ui/const-generics/slice-const-param-mismatch.rs index f020e2bf66fb..7f740005e04e 100644 --- a/src/test/ui/const-generics/slice-const-param-mismatch.rs +++ b/src/test/ui/const-generics/slice-const-param-mismatch.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] diff --git a/src/test/ui/const-generics/slice-const-param.min.stderr b/src/test/ui/const-generics/slice-const-param.min.stderr deleted file mode 100644 index ed39a0c56b48..000000000000 --- a/src/test/ui/const-generics/slice-const-param.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param.rs:7:40 - | -LL | pub fn function_with_str() -> &'static str { - | ^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: `&'static [u8]` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param.rs:12:41 - | -LL | pub fn function_with_bytes() -> &'static [u8] { - | ^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/slice-const-param.rs b/src/test/ui/const-generics/slice-const-param.rs index bf1bf8af9222..3a7eb4646309 100644 --- a/src/test/ui/const-generics/slice-const-param.rs +++ b/src/test/ui/const-generics/slice-const-param.rs @@ -1,16 +1,13 @@ -//[full] run-pass -// revisions: min full +// run-pass -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] +#![feature(const_param_types)] +#![allow(incomplete_features)] pub fn function_with_str() -> &'static str { - //[min]~^ ERROR `&'static str` is forbidden STRING } pub fn function_with_bytes() -> &'static [u8] { - //[min]~^ ERROR `&'static [u8]` is forbidden BYTES } diff --git a/src/test/ui/const-generics/std/const-generics-range.min.stderr b/src/test/ui/const-generics/std/const-generics-range.min.stderr index 86e6159fdb57..1af866694ab3 100644 --- a/src/test/ui/const-generics/std/const-generics-range.min.stderr +++ b/src/test/ui/const-generics/std/const-generics-range.min.stderr @@ -5,7 +5,7 @@ LL | struct _Range>; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `RangeFrom` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:12:28 @@ -14,7 +14,7 @@ LL | struct _RangeFrom>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `RangeFull` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:17:28 @@ -23,7 +23,7 @@ LL | struct _RangeFull; | ^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `RangeInclusive` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:23:33 @@ -32,7 +32,7 @@ LL | struct _RangeInclusive>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `RangeTo` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:28:26 @@ -41,7 +41,7 @@ LL | struct _RangeTo>; | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `RangeToInclusive` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:33:35 @@ -50,7 +50,7 @@ LL | struct _RangeToInclusive>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 6 previous errors diff --git a/src/test/ui/const-generics/std/const-generics-range.rs b/src/test/ui/const-generics/std/const-generics-range.rs index deaab830e91d..21e0bb48cd87 100644 --- a/src/test/ui/const-generics/std/const-generics-range.rs +++ b/src/test/ui/const-generics/std/const-generics-range.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] // `Range` should be usable within const generics: diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.full.stderr b/src/test/ui/const-generics/struct-with-invalid-const-param.full.stderr deleted file mode 100644 index db998033c0a2..000000000000 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.full.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0573]: expected type, found const parameter `C` - --> $DIR/struct-with-invalid-const-param.rs:7:23 - | -LL | struct S(C); - | ^ not a type - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.min.stderr b/src/test/ui/const-generics/struct-with-invalid-const-param.min.stderr deleted file mode 100644 index db998033c0a2..000000000000 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.min.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0573]: expected type, found const parameter `C` - --> $DIR/struct-with-invalid-const-param.rs:7:23 - | -LL | struct S(C); - | ^ not a type - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.rs b/src/test/ui/const-generics/struct-with-invalid-const-param.rs index 32970ccaa5db..be1c4b0e8e80 100644 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.rs +++ b/src/test/ui/const-generics/struct-with-invalid-const-param.rs @@ -1,8 +1,4 @@ // Checks that a const param cannot be stored in a struct. -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct S(C); //~ ERROR expected type, found const parameter diff --git a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr index 47617c7849f4..67f497af5050 100644 --- a/src/test/ui/const-generics/struct-with-invalid-const-param.stderr +++ b/src/test/ui/const-generics/struct-with-invalid-const-param.stderr @@ -1,18 +1,9 @@ error[E0573]: expected type, found const parameter `C` - --> $DIR/struct-with-invalid-const-param.rs:4:23 + --> $DIR/struct-with-invalid-const-param.rs:3:23 | LL | struct S(C); | ^ not a type -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/struct-with-invalid-const-param.rs:1:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0573`. diff --git a/src/test/ui/const-generics/trait-const-args.rs b/src/test/ui/const-generics/trait-const-args.rs index 30d05c708e14..2cdef3fb452c 100644 --- a/src/test/ui/const-generics/trait-const-args.rs +++ b/src/test/ui/const-generics/trait-const-args.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct Const; trait Foo {} diff --git a/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr b/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr index f735be9c24e0..14af8d77a5f9 100644 --- a/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr +++ b/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr @@ -5,7 +5,7 @@ LL | struct Const; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/transmute-const-param-static-reference.rs b/src/test/ui/const-generics/transmute-const-param-static-reference.rs index 3147d61ec9bd..1a63bec7b6f0 100644 --- a/src/test/ui/const-generics/transmute-const-param-static-reference.rs +++ b/src/test/ui/const-generics/transmute-const-param-static-reference.rs @@ -1,7 +1,7 @@ // revisions: full min //[full] check-pass -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Const; diff --git a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs index bf855d4dcaac..8c990577f3dc 100644 --- a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs +++ b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs @@ -1,7 +1,7 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] use std::mem::MaybeUninit; diff --git a/src/test/ui/const-generics/type-after-const-ok.rs b/src/test/ui/const-generics/type-after-const-ok.rs index 920c067dc1a7..68d1940160c4 100644 --- a/src/test/ui/const-generics/type-after-const-ok.rs +++ b/src/test/ui/const-generics/type-after-const-ok.rs @@ -1,7 +1,7 @@ // [full] run-pass // revisions: full min // Verifies that having generic parameters after constants is permitted -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_generics_defaults))] #![cfg_attr(full, allow(incomplete_features))] #[allow(dead_code)] diff --git a/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs b/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs index cd9c3ae7bbc0..5dfcbba0e595 100644 --- a/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs +++ b/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs @@ -1,6 +1,3 @@ -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - pub struct Struct(()); impl Struct { diff --git a/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs b/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs index 4997d493bbb4..e844148346fb 100644 --- a/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs +++ b/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs @@ -1,6 +1,6 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![allow(incomplete_features)] struct Foo; diff --git a/src/test/ui/const-generics/type-dependent/issue-61936.rs b/src/test/ui/const-generics/type-dependent/issue-61936.rs index 417fe2501ae3..7216b25f0df8 100644 --- a/src/test/ui/const-generics/type-dependent/issue-61936.rs +++ b/src/test/ui/const-generics/type-dependent/issue-61936.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait SliceExt { fn array_windows_example<'a, const N: usize>(&'a self) -> ArrayWindowsExample<'a, T, N>; diff --git a/src/test/ui/const-generics/type-dependent/issue-63695.rs b/src/test/ui/const-generics/type-dependent/issue-63695.rs index 2ece25bb41b2..08b6d4bf554a 100644 --- a/src/test/ui/const-generics/type-dependent/issue-63695.rs +++ b/src/test/ui/const-generics/type-dependent/issue-63695.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait T { fn test(&self) -> i32 { A } diff --git a/src/test/ui/const-generics/type-dependent/issue-67144-1.rs b/src/test/ui/const-generics/type-dependent/issue-67144-1.rs index 4a2c303095e5..27dd51de2417 100644 --- a/src/test/ui/const-generics/type-dependent/issue-67144-1.rs +++ b/src/test/ui/const-generics/type-dependent/issue-67144-1.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct X; impl X { diff --git a/src/test/ui/const-generics/type-dependent/issue-67144-2.rs b/src/test/ui/const-generics/type-dependent/issue-67144-2.rs index a1163fca8d4e..b26f551eb867 100644 --- a/src/test/ui/const-generics/type-dependent/issue-67144-2.rs +++ b/src/test/ui/const-generics/type-dependent/issue-67144-2.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct A; struct X; diff --git a/src/test/ui/const-generics/type-dependent/issue-69816.rs b/src/test/ui/const-generics/type-dependent/issue-69816.rs index 75ddd839f664..cbb6b398e015 100644 --- a/src/test/ui/const-generics/type-dependent/issue-69816.rs +++ b/src/test/ui/const-generics/type-dependent/issue-69816.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait IterExt: Sized + Iterator { fn default_for_size(self) -> [Self::Item; N] where diff --git a/src/test/ui/const-generics/type-dependent/issue-70217.rs b/src/test/ui/const-generics/type-dependent/issue-70217.rs index b3585d5fc107..933ca0276098 100644 --- a/src/test/ui/const-generics/type-dependent/issue-70217.rs +++ b/src/test/ui/const-generics/type-dependent/issue-70217.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct Struct; diff --git a/src/test/ui/const-generics/type-dependent/issue-70507.rs b/src/test/ui/const-generics/type-dependent/issue-70507.rs index df7c277f605b..c72d9fbec2d8 100644 --- a/src/test/ui/const-generics/type-dependent/issue-70507.rs +++ b/src/test/ui/const-generics/type-dependent/issue-70507.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] trait ConstChunksExactTrait { fn const_chunks_exact(&self) -> ConstChunksExact<'_, T, {N}>; diff --git a/src/test/ui/const-generics/type-dependent/issue-70586.rs b/src/test/ui/const-generics/type-dependent/issue-70586.rs index 5fb571f2394d..346ac4b72cc7 100644 --- a/src/test/ui/const-generics/type-dependent/issue-70586.rs +++ b/src/test/ui/const-generics/type-dependent/issue-70586.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - use std::marker::PhantomData; // This namespace is necessary for the ICE to trigger diff --git a/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr b/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr index f3516d1de96b..d845bc610cfa 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -5,7 +5,7 @@ LL | trait Get<'a, const N: &'static str> { | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:18:25 @@ -14,7 +14,7 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a >::Ta | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/type-dependent/issue-71348.rs b/src/test/ui/const-generics/type-dependent/issue-71348.rs index 33735ef87c5a..638e7a88d678 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71348.rs +++ b/src/test/ui/const-generics/type-dependent/issue-71348.rs @@ -1,6 +1,6 @@ // [full] run-pass // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(const_param_types))] #![cfg_attr(full, allow(incomplete_features))] struct Foo { diff --git a/src/test/ui/const-generics/type-dependent/issue-71382.min.stderr b/src/test/ui/const-generics/type-dependent/issue-71382.min.stderr deleted file mode 100644 index 8ac9bab63208..000000000000 --- a/src/test/ui/const-generics/type-dependent/issue-71382.min.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71382.rs:16:23 - | -LL | fn test u8>(&self) -> u8 { - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/const-generics/type-dependent/issue-71382.rs b/src/test/ui/const-generics/type-dependent/issue-71382.rs index b3677613dbc8..1c4073e36683 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71382.rs +++ b/src/test/ui/const-generics/type-dependent/issue-71382.rs @@ -1,7 +1,3 @@ -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct Test; fn pass() -> u8 { diff --git a/src/test/ui/const-generics/type-dependent/issue-71382.full.stderr b/src/test/ui/const-generics/type-dependent/issue-71382.stderr similarity index 86% rename from src/test/ui/const-generics/type-dependent/issue-71382.full.stderr rename to src/test/ui/const-generics/type-dependent/issue-71382.stderr index 8ac9bab63208..ad522aead905 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71382.full.stderr +++ b/src/test/ui/const-generics/type-dependent/issue-71382.stderr @@ -1,5 +1,5 @@ error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71382.rs:16:23 + --> $DIR/issue-71382.rs:12:23 | LL | fn test u8>(&self) -> u8 { | ^^^^^^^^^^ diff --git a/src/test/ui/const-generics/type-dependent/issue-71805.rs b/src/test/ui/const-generics/type-dependent/issue-71805.rs index 3701e14eadcf..060b899648e6 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71805.rs +++ b/src/test/ui/const-generics/type-dependent/issue-71805.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - use std::mem::MaybeUninit; trait CollectSlice<'a>: Iterator { diff --git a/src/test/ui/const-generics/type-dependent/issue-73730.rs b/src/test/ui/const-generics/type-dependent/issue-73730.rs index 5d7dcb9c458a..5e1b8c635372 100644 --- a/src/test/ui/const-generics/type-dependent/issue-73730.rs +++ b/src/test/ui/const-generics/type-dependent/issue-73730.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait Foo<'a, A>: Iterator { fn bar(&mut self) -> *const [A; N]; } diff --git a/src/test/ui/const-generics/type-dependent/non-local.rs b/src/test/ui/const-generics/type-dependent/non-local.rs index 9e4afba31140..b755de30b9ce 100644 --- a/src/test/ui/const-generics/type-dependent/non-local.rs +++ b/src/test/ui/const-generics/type-dependent/non-local.rs @@ -1,9 +1,5 @@ // aux-build:type_dependent_lib.rs // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - extern crate type_dependent_lib; use type_dependent_lib::*; diff --git a/src/test/ui/const-generics/type-dependent/qpath.rs b/src/test/ui/const-generics/type-dependent/qpath.rs index b61e970cfb37..2d678d0acd3f 100644 --- a/src/test/ui/const-generics/type-dependent/qpath.rs +++ b/src/test/ui/const-generics/type-dependent/qpath.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct A; impl A { fn foo() -> usize { N + 1 } diff --git a/src/test/ui/const-generics/type-dependent/simple.rs b/src/test/ui/const-generics/type-dependent/simple.rs index a4776a43b211..1b13133b5b97 100644 --- a/src/test/ui/const-generics/type-dependent/simple.rs +++ b/src/test/ui/const-generics/type-dependent/simple.rs @@ -1,8 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct R; impl R { diff --git a/src/test/ui/const-generics/type-dependent/type-mismatch.full.stderr b/src/test/ui/const-generics/type-dependent/type-mismatch.full.stderr index a0a14558490d..02108d859603 100644 --- a/src/test/ui/const-generics/type-dependent/type-mismatch.full.stderr +++ b/src/test/ui/const-generics/type-dependent/type-mismatch.full.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/type-mismatch.rs:11:27 + --> $DIR/type-mismatch.rs:8:27 | LL | assert_eq!(R.method::<1u16>(), 1); | ^^^^ expected `u8`, found `u16` diff --git a/src/test/ui/const-generics/type-dependent/type-mismatch.min.stderr b/src/test/ui/const-generics/type-dependent/type-mismatch.min.stderr index a0a14558490d..02108d859603 100644 --- a/src/test/ui/const-generics/type-dependent/type-mismatch.min.stderr +++ b/src/test/ui/const-generics/type-dependent/type-mismatch.min.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/type-mismatch.rs:11:27 + --> $DIR/type-mismatch.rs:8:27 | LL | assert_eq!(R.method::<1u16>(), 1); | ^^^^ expected `u8`, found `u16` diff --git a/src/test/ui/const-generics/type-dependent/type-mismatch.rs b/src/test/ui/const-generics/type-dependent/type-mismatch.rs index 7fba1afe9189..3335ab870f49 100644 --- a/src/test/ui/const-generics/type-dependent/type-mismatch.rs +++ b/src/test/ui/const-generics/type-dependent/type-mismatch.rs @@ -1,7 +1,4 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - struct R; impl R { diff --git a/src/test/ui/const-generics/type_of_anon_const.rs b/src/test/ui/const-generics/type_of_anon_const.rs index 9a2e9f09319d..fb0d688a8abf 100644 --- a/src/test/ui/const-generics/type_of_anon_const.rs +++ b/src/test/ui/const-generics/type_of_anon_const.rs @@ -1,9 +1,4 @@ // run-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait T { fn l() -> usize; fn r() -> bool; diff --git a/src/test/ui/const-generics/types-mismatch-const-args.full.stderr b/src/test/ui/const-generics/types-mismatch-const-args.full.stderr index 480ecdb38734..565c9ba1ff1f 100644 --- a/src/test/ui/const-generics/types-mismatch-const-args.full.stderr +++ b/src/test/ui/const-generics/types-mismatch-const-args.full.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:14:41 | -LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2_u32`, found `4_u32` +LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {2u32 + 2u32}, {3u32}> { data: PhantomData }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2_u32`, found `4_u32` | = note: expected type `2_u32` found type `4_u32` diff --git a/src/test/ui/const-generics/types-mismatch-const-args.min.stderr b/src/test/ui/const-generics/types-mismatch-const-args.min.stderr index c19c8db737a1..ec9221d2486a 100644 --- a/src/test/ui/const-generics/types-mismatch-const-args.min.stderr +++ b/src/test/ui/const-generics/types-mismatch-const-args.min.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:14:41 | -LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData }; - | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2_u32`, found `4_u32` +LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {2u32 + 2u32}, {3u32}> { data: PhantomData }; + | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2_u32`, found `4_u32` | | | expected due to this | diff --git a/src/test/ui/const-generics/types-mismatch-const-args.rs b/src/test/ui/const-generics/types-mismatch-const-args.rs index 14cef083d837..c2092c4268e8 100644 --- a/src/test/ui/const-generics/types-mismatch-const-args.rs +++ b/src/test/ui/const-generics/types-mismatch-const-args.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_generics))] +#![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] // tests the diagnostic output of type mismatches for types that have const generics arguments. @@ -11,7 +11,7 @@ struct A<'a, T, const X: u32, const Y: u32> { } fn a<'a, 'b>() { - let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData }; + let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {2u32 + 2u32}, {3u32}> { data: PhantomData }; //~^ ERROR mismatched types let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData }; //~^ ERROR mismatched types diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs index 9592f2662307..c7270e835c5a 100644 --- a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] use std::fmt; diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs index 4bab2bb5a77f..191caa78f9e3 100644 --- a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs @@ -1,7 +1,4 @@ // run-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] use std::fmt; diff --git a/src/test/ui/const-generics/unknown_adt.min.stderr b/src/test/ui/const-generics/unknown_adt.min.stderr deleted file mode 100644 index b8b2e90aa66c..000000000000 --- a/src/test/ui/const-generics/unknown_adt.min.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0412]: cannot find type `UnknownStruct` in this scope - --> $DIR/unknown_adt.rs:7:12 - | -LL | let _: UnknownStruct<7>; - | ^^^^^^^^^^^^^ not found in this scope - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0412`. diff --git a/src/test/ui/const-generics/unknown_adt.rs b/src/test/ui/const-generics/unknown_adt.rs index 977f90aad116..8cdd28a8c609 100644 --- a/src/test/ui/const-generics/unknown_adt.rs +++ b/src/test/ui/const-generics/unknown_adt.rs @@ -1,8 +1,3 @@ -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - fn main() { let _: UnknownStruct<7>; //~^ ERROR cannot find type `UnknownStruct` diff --git a/src/test/ui/const-generics/unknown_adt.full.stderr b/src/test/ui/const-generics/unknown_adt.stderr similarity index 89% rename from src/test/ui/const-generics/unknown_adt.full.stderr rename to src/test/ui/const-generics/unknown_adt.stderr index b8b2e90aa66c..0f462dd4728f 100644 --- a/src/test/ui/const-generics/unknown_adt.full.stderr +++ b/src/test/ui/const-generics/unknown_adt.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `UnknownStruct` in this scope - --> $DIR/unknown_adt.rs:7:12 + --> $DIR/unknown_adt.rs:2:12 | LL | let _: UnknownStruct<7>; | ^^^^^^^^^^^^^ not found in this scope diff --git a/src/test/ui/const-generics/unused-const-param.rs b/src/test/ui/const-generics/unused-const-param.rs index 2918e399dc8e..c7f74cfac7d6 100644 --- a/src/test/ui/const-generics/unused-const-param.rs +++ b/src/test/ui/const-generics/unused-const-param.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] struct A; // ok diff --git a/src/test/ui/const-generics/unused_braces.fixed b/src/test/ui/const-generics/unused_braces.fixed index 836f26efc960..d080c210e6bd 100644 --- a/src/test/ui/const-generics/unused_braces.fixed +++ b/src/test/ui/const-generics/unused_braces.fixed @@ -1,11 +1,7 @@ // check-pass // run-rustfix - -#![allow(incomplete_features)] #![warn(unused_braces)] -#![feature(const_generics)] - struct A; fn main() { diff --git a/src/test/ui/const-generics/unused_braces.full.stderr b/src/test/ui/const-generics/unused_braces.full.stderr deleted file mode 100644 index 8899139aa6bb..000000000000 --- a/src/test/ui/const-generics/unused_braces.full.stderr +++ /dev/null @@ -1,14 +0,0 @@ -warning: unnecessary braces around const expression - --> $DIR/unused_braces.rs:14:14 - | -LL | let _: A<{ 7 }>; - | ^^^^^ help: remove these braces - | -note: the lint level is defined here - --> $DIR/unused_braces.rs:7:9 - | -LL | #![warn(unused_braces)] - | ^^^^^^^^^^^^^ - -warning: 1 warning emitted - diff --git a/src/test/ui/const-generics/unused_braces.rs b/src/test/ui/const-generics/unused_braces.rs index 0348bbacaabd..47f0f8c1c96c 100644 --- a/src/test/ui/const-generics/unused_braces.rs +++ b/src/test/ui/const-generics/unused_braces.rs @@ -1,12 +1,7 @@ // check-pass // run-rustfix -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] #![warn(unused_braces)] - struct A; fn main() { diff --git a/src/test/ui/const-generics/unused_braces.min.stderr b/src/test/ui/const-generics/unused_braces.stderr similarity index 80% rename from src/test/ui/const-generics/unused_braces.min.stderr rename to src/test/ui/const-generics/unused_braces.stderr index 8899139aa6bb..5e1bace54924 100644 --- a/src/test/ui/const-generics/unused_braces.min.stderr +++ b/src/test/ui/const-generics/unused_braces.stderr @@ -1,11 +1,11 @@ warning: unnecessary braces around const expression - --> $DIR/unused_braces.rs:14:14 + --> $DIR/unused_braces.rs:9:14 | LL | let _: A<{ 7 }>; | ^^^^^ help: remove these braces | note: the lint level is defined here - --> $DIR/unused_braces.rs:7:9 + --> $DIR/unused_braces.rs:3:9 | LL | #![warn(unused_braces)] | ^^^^^^^^^^^^^ diff --git a/src/test/ui/const-generics/wf-misc.full.stderr b/src/test/ui/const-generics/wf-misc.full.stderr deleted file mode 100644 index dfb593a9507d..000000000000 --- a/src/test/ui/const-generics/wf-misc.full.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: constant expression depends on a generic parameter - --> $DIR/wf-misc.rs:8:12 - | -LL | let _: [u8; N + 1]; - | ^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: constant expression depends on a generic parameter - --> $DIR/wf-misc.rs:16:12 - | -LL | let _: Const::<{N + 1}>; - | ^^^^^^^^^^^^^^^^ - | - = note: this may fail depending on what value the parameter takes - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/wf-misc.min.stderr b/src/test/ui/const-generics/wf-misc.min.stderr deleted file mode 100644 index bc4c3f01ea9c..000000000000 --- a/src/test/ui/const-generics/wf-misc.min.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: generic parameters may not be used in const operations - --> $DIR/wf-misc.rs:8:17 - | -LL | let _: [u8; N + 1]; - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: generic parameters may not be used in const operations - --> $DIR/wf-misc.rs:16:21 - | -LL | let _: Const::<{N + 1}>; - | ^ cannot perform const operation using `N` - | - = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/const-generics/wf-misc.rs b/src/test/ui/const-generics/wf-misc.rs deleted file mode 100644 index 8a5b6ddfe266..000000000000 --- a/src/test/ui/const-generics/wf-misc.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Tests miscellaneous well-formedness examples. -// revisions: full min - -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - -pub fn arr_len() { - let _: [u8; N + 1]; - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations -} - -struct Const; - -pub fn func_call() { - let _: Const::<{N + 1}>; - //[full]~^ ERROR constant expression depends on a generic parameter - //[min]~^^ ERROR generic parameters may not be used in const operations -} - -fn main() {} diff --git a/src/test/ui/const-generics/where-clauses.rs b/src/test/ui/const-generics/where-clauses.rs index dc09cad3180b..aa3ca1cf6de7 100644 --- a/src/test/ui/const-generics/where-clauses.rs +++ b/src/test/ui/const-generics/where-clauses.rs @@ -1,8 +1,4 @@ // check-pass -// revisions: full min -#![cfg_attr(full, feature(const_generics))] -#![cfg_attr(full, allow(incomplete_features))] - trait Bar { fn bar() {} } trait Foo: Bar {} diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.rs b/src/test/ui/consts/const-needs_drop-monomorphic.rs index 9f66e3cfa23c..7402c680985b 100644 --- a/src/test/ui/consts/const-needs_drop-monomorphic.rs +++ b/src/test/ui/consts/const-needs_drop-monomorphic.rs @@ -1,5 +1,5 @@ // Check that evaluation of needs_drop fails when T is not monomorphic. -#![feature(const_generics)] +#![feature(generic_const_exprs)] #![allow(const_evaluatable_unchecked)] #![allow(incomplete_features)] @@ -10,7 +10,7 @@ impl Bool { fn f() { Bool::<{ std::mem::needs_drop::() }>::assert(); //~^ ERROR no function or associated item named `assert` found - //~| ERROR constant expression depends on a generic parameter + //~| ERROR unconstrained generic constant } fn main() { f::(); diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.stderr b/src/test/ui/consts/const-needs_drop-monomorphic.stderr index 0770d06e15be..6e56d20c39d7 100644 --- a/src/test/ui/consts/const-needs_drop-monomorphic.stderr +++ b/src/test/ui/consts/const-needs_drop-monomorphic.stderr @@ -7,13 +7,13 @@ LL | struct Bool {} LL | Bool::<{ std::mem::needs_drop::() }>::assert(); | ^^^^^^ function or associated item cannot be called on `Bool<{ std::mem::needs_drop::() }>` due to unsatisfied trait bounds -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/const-needs_drop-monomorphic.rs:11:5 | LL | Bool::<{ std::mem::needs_drop::() }>::assert(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: this may fail depending on what value the parameter takes + = help: try adding a `where` bound using this expression: `where [(); { std::mem::needs_drop::() }]:` error: aborting due to 2 previous errors diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr index c7677f81b5fa..e4e10468d534 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.stderr @@ -5,7 +5,7 @@ LL | Some(T) = std::mem::size_of::(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr index c3735658aa7d..7ea8a39129ea 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr @@ -5,7 +5,7 @@ LL | Some = std::mem::size_of::(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `T` is never used --> $DIR/issue-70453-generics-in-discr-ice.rs:7:20 diff --git a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr index ee0c3525b62d..0a7a631606ee 100644 --- a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr @@ -5,7 +5,7 @@ LL | Some(T) = core::mem::size_of::<*mut T>(), | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/enum/issue-67945-1.stderr b/src/test/ui/enum/issue-67945-1.stderr index 21f005aa49f0..8f1b5b38e4c3 100644 --- a/src/test/ui/enum/issue-67945-1.stderr +++ b/src/test/ui/enum/issue-67945-1.stderr @@ -5,7 +5,7 @@ LL | let x: S = 0; | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-1.rs:1:10 diff --git a/src/test/ui/enum/issue-67945-2.stderr b/src/test/ui/enum/issue-67945-2.stderr index 8996df8ae10e..4f5e236a37b4 100644 --- a/src/test/ui/enum/issue-67945-2.stderr +++ b/src/test/ui/enum/issue-67945-2.stderr @@ -5,7 +5,7 @@ LL | Var = 0: S, | ^ cannot perform const operation using `S` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0392]: parameter `S` is never used --> $DIR/issue-67945-2.rs:3:10 diff --git a/src/test/ui/error-codes/E0730.rs b/src/test/ui/error-codes/E0730.rs index 30745814b4a7..04f5e5d42574 100644 --- a/src/test/ui/error-codes/E0730.rs +++ b/src/test/ui/error-codes/E0730.rs @@ -1,6 +1,3 @@ -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete - fn is_123(x: [u32; N]) -> bool { match x { [1, 2, ..] => true, //~ ERROR cannot pattern-match on an array without a fixed length diff --git a/src/test/ui/error-codes/E0730.stderr b/src/test/ui/error-codes/E0730.stderr index f915f6edef52..067e8c57cd63 100644 --- a/src/test/ui/error-codes/E0730.stderr +++ b/src/test/ui/error-codes/E0730.stderr @@ -1,18 +1,9 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/E0730.rs:1:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - error[E0730]: cannot pattern-match on an array without a fixed length - --> $DIR/E0730.rs:6:9 + --> $DIR/E0730.rs:3:9 | LL | [1, 2, ..] => true, | ^^^^^^^^^^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0730`. diff --git a/src/test/ui/error-codes/E0771.rs b/src/test/ui/error-codes/E0771.rs index ba3592719408..75c9fa6c98d1 100644 --- a/src/test/ui/error-codes/E0771.rs +++ b/src/test/ui/error-codes/E0771.rs @@ -1,5 +1,5 @@ -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete +#![feature(const_param_types)] +//~^ WARN the feature `const_param_types` is incomplete fn function_with_str<'a, const STRING: &'a str>() {} //~ ERROR E0771 diff --git a/src/test/ui/error-codes/E0771.stderr b/src/test/ui/error-codes/E0771.stderr index 60220be6b57b..9860df3352ad 100644 --- a/src/test/ui/error-codes/E0771.stderr +++ b/src/test/ui/error-codes/E0771.stderr @@ -1,8 +1,8 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `const_param_types` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/E0771.rs:1:12 | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ +LL | #![feature(const_param_types)] + | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #44580 for more information diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.rs b/src/test/ui/feature-gates/feature-gate-const_generics.rs deleted file mode 100644 index 06364eebef91..000000000000 --- a/src/test/ui/feature-gates/feature-gate-const_generics.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn foo() {} //~ ERROR `()` is forbidden as the type of a const generic parameter - -struct Foo([(); X]); - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-const_generics.stderr b/src/test/ui/feature-gates/feature-gate-const_generics.stderr deleted file mode 100644 index ed19109b38b4..000000000000 --- a/src/test/ui/feature-gates/feature-gate-const_generics.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: `()` is forbidden as the type of a const generic parameter - --> $DIR/feature-gate-const_generics.rs:1:17 - | -LL | fn foo() {} - | ^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` - -error: aborting due to previous error - diff --git a/src/test/ui/feature-gates/feature-gate-const_param_types.rs b/src/test/ui/feature-gates/feature-gate-const_param_types.rs new file mode 100644 index 000000000000..8a3bcf25963f --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-const_param_types.rs @@ -0,0 +1,2 @@ +struct Foo; //~ ERROR `&'static str` is forbidden +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.min.stderr b/src/test/ui/feature-gates/feature-gate-const_param_types.stderr similarity index 61% rename from src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.min.stderr rename to src/test/ui/feature-gates/feature-gate-const_param_types.stderr index e96b9e703526..5452186a3aeb 100644 --- a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.min.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_param_types.stderr @@ -1,11 +1,11 @@ error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/issue-66596-impl-trait-for-str-const-arg.rs:8:25 + --> $DIR/feature-gate-const_param_types.rs:1:24 | -LL | trait Trait { - | ^^^^^^^^^^^^ +LL | struct Foo; + | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_generics)]` + = help: more complex types are supported with `#![feature(const_param_types)]` error: aborting due to previous error diff --git a/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr b/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr index 7ea12e74e1ed..ab09ebcae719 100644 --- a/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr +++ b/src/test/ui/generics/param-in-ct-in-ty-param-default.stderr @@ -5,7 +5,7 @@ LL | struct Foo()]>(T, U); | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/hygiene/generic_params.rs b/src/test/ui/hygiene/generic_params.rs index d319ae6403fc..3b6216c3e637 100644 --- a/src/test/ui/hygiene/generic_params.rs +++ b/src/test/ui/hygiene/generic_params.rs @@ -3,8 +3,7 @@ // check-pass // ignore-pretty pretty-printing is unhygienic -#![feature(decl_macro, rustc_attrs, const_generics)] -//~^ WARNING the feature `const_generics` is incomplete +#![feature(decl_macro, rustc_attrs)] mod type_params { macro m($T:ident) { diff --git a/src/test/ui/hygiene/generic_params.stderr b/src/test/ui/hygiene/generic_params.stderr deleted file mode 100644 index 4ca6d1998353..000000000000 --- a/src/test/ui/hygiene/generic_params.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_params.rs:6:37 - | -LL | #![feature(decl_macro, rustc_attrs, const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/hygiene/issue-61574-const-parameters.rs b/src/test/ui/hygiene/issue-61574-const-parameters.rs index 81e9b1b36e06..3634ee004f7f 100644 --- a/src/test/ui/hygiene/issue-61574-const-parameters.rs +++ b/src/test/ui/hygiene/issue-61574-const-parameters.rs @@ -3,8 +3,6 @@ // check-pass -#![feature(const_generics)] //~ WARNING `const_generics` is incomplete - use std::ops::Add; struct VectorLike([T; {SIZE}]); diff --git a/src/test/ui/hygiene/issue-61574-const-parameters.stderr b/src/test/ui/hygiene/issue-61574-const-parameters.stderr deleted file mode 100644 index b351b8b73a0e..000000000000 --- a/src/test/ui/hygiene/issue-61574-const-parameters.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-61574-const-parameters.rs:6:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/impl-trait/issue-55872-1.full_tait.stderr b/src/test/ui/impl-trait/issue-55872-1.full_tait.stderr deleted file mode 100644 index 50eab7dcc978..000000000000 --- a/src/test/ui/impl-trait/issue-55872-1.full_tait.stderr +++ /dev/null @@ -1,57 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-55872-1.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0276]: impl has stricter requirements than trait - --> $DIR/issue-55872-1.rs:17:5 - | -LL | fn foo() -> Self::E; - | ----------------------- definition of `foo` from trait -... -LL | fn foo() -> Self::E { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Default` - -error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)` - --> $DIR/issue-55872-1.rs:13:14 - | -LL | type E = impl Copy; - | ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S` - | - = note: required because it appears within the type `(S, T)` -help: consider further restricting this bound - | -LL | impl Bar for S { - | +++++++++++++++++++ - -error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)` - --> $DIR/issue-55872-1.rs:13:14 - | -LL | type E = impl Copy; - | ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T` - | - = note: required because it appears within the type `(S, T)` -help: consider further restricting this bound - | -LL | fn foo() -> Self::E { - | +++++++++++++++++++ - -error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias - --> $DIR/issue-55872-1.rs:17:37 - | -LL | fn foo() -> Self::E { - | _____________________________________^ -LL | | -LL | | -LL | | (S::default(), T::default()) -LL | | } - | |_____^ - -error: aborting due to 4 previous errors; 1 warning emitted - -Some errors have detailed explanations: E0276, E0277. -For more information about an error, try `rustc --explain E0276`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.stderr b/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.stderr deleted file mode 100644 index 4de872e8441e..000000000000 --- a/src/test/ui/impl-trait/multiple-lifetimes/inverse-bounds.stderr +++ /dev/null @@ -1,19 +0,0 @@ -warning[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/inverse-bounds.rs:16:70 - | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Invert<'a>, b: Invert<'b>) -> impl Trait<'d, 'e> - | ^^^^^^^^^^^^^^^^^^ - | - = note: hidden type `Invert<'_>` captures lifetime '_#8r - = warning: this error has been downgraded to a warning for backwards compatibility with previous releases - = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future - = note: for more information, try `rustc --explain E0729` - -warning: the feature `pin` has been stable since 1.33.0 and no longer requires an attribute to enable - --> $DIR/inverse-bounds.rs:4:60 - | -LL | #![feature(arbitrary_self_types, async_await, await_macro, pin)] - | ^^^ - | - = note: #[warn(stable_features)] on by default - diff --git a/src/test/ui/issues/issue-39559.stderr b/src/test/ui/issues/issue-39559.stderr index d71844eafde2..7626f827fc5e 100644 --- a/src/test/ui/issues/issue-39559.stderr +++ b/src/test/ui/issues/issue-39559.stderr @@ -5,7 +5,7 @@ LL | entries: [T; D::dim()], | ^^^^^^ cannot perform const operation using `D` | = note: type parameters may not be used in const expressions - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to previous error diff --git a/src/test/ui/issues/issue-59508-1.rs b/src/test/ui/issues/issue-59508-1.rs index a687a9e3be12..6376c429b287 100644 --- a/src/test/ui/issues/issue-59508-1.rs +++ b/src/test/ui/issues/issue-59508-1.rs @@ -1,9 +1,8 @@ #![allow(dead_code)] -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete +#![feature(const_generics_defaults)] // This test checks that generic parameter re-ordering diagnostic suggestions mention that -// consts come after types and lifetimes when the `const_generics` feature is enabled. +// consts come after types and lifetimes when the `const_generics_defaults` feature is enabled. // We cannot run rustfix on this test because of the above const generics warning. struct A; diff --git a/src/test/ui/issues/issue-59508-1.stderr b/src/test/ui/issues/issue-59508-1.stderr index 5e97339f148c..df244f02dce6 100644 --- a/src/test/ui/issues/issue-59508-1.stderr +++ b/src/test/ui/issues/issue-59508-1.stderr @@ -1,17 +1,8 @@ error: lifetime parameters must be declared prior to type parameters - --> $DIR/issue-59508-1.rs:12:25 + --> $DIR/issue-59508-1.rs:11:25 | LL | pub fn do_things() { | ----^^--^^----- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b: 'a, T>` -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-59508-1.rs:2:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error: aborting due to previous error; 1 warning emitted +error: aborting due to previous error diff --git a/src/test/ui/legacy-const-generics-bad.stderr b/src/test/ui/legacy-const-generics-bad.stderr index d65e9f05904b..3c78dd6c7802 100644 --- a/src/test/ui/legacy-const-generics-bad.stderr +++ b/src/test/ui/legacy-const-generics-bad.stderr @@ -13,7 +13,7 @@ LL | legacy_const_generics::foo(0, N + 1, 2); | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` - = help: use `#![feature(const_generics)]` and `#![feature(generic_const_exprs)]` to allow generic const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error: aborting due to 2 previous errors diff --git a/src/test/ui/mir/issue-75053.in_bindings.stderr b/src/test/ui/mir/issue-75053.in_bindings.stderr deleted file mode 100644 index d75996bf0b3a..000000000000 --- a/src/test/ui/mir/issue-75053.in_bindings.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0557]: feature has been removed - --> $DIR/issue-75053.rs:7:34 - | -LL | #![cfg_attr(in_bindings, feature(impl_trait_in_bindings))] - | ^^^^^^^^^^^^^^^^^^^^^^ feature has been removed - | - = note: removed due to being incomplete and unstable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0557`. diff --git a/src/test/ui/obsolete-in-place/bad.bad.stderr b/src/test/ui/obsolete-in-place/bad.bad.stderr deleted file mode 100644 index d895981050ae..000000000000 --- a/src/test/ui/obsolete-in-place/bad.bad.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: expected expression, found keyword `in` - --> $DIR/bad.rs:10:5 - | -LL | in(foo) { bar }; - | ^^ expected expression - -error[E0282]: type annotations needed - --> $DIR/bad.rs:9:8 - | -LL | let (x, y, foo, bar); - | ---------------- consider giving the pattern a type -LL | x <- y; - | ^^^ cannot infer type - | - = note: type must be known at this point - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/polymorphization/const_parameters/closures.rs b/src/test/ui/polymorphization/const_parameters/closures.rs index f20605e1b9a6..2f41beeb9691 100644 --- a/src/test/ui/polymorphization/const_parameters/closures.rs +++ b/src/test/ui/polymorphization/const_parameters/closures.rs @@ -1,7 +1,7 @@ // build-fail // compile-flags:-Zpolymorphize=on -#![feature(const_generics, rustc_attrs)] -//~^ WARN the feature `const_generics` is incomplete +#![feature(generic_const_exprs, rustc_attrs)] +//~^ WARN the feature `generic_const_exprs` is incomplete // This test checks that the polymorphization analysis correctly detects unused const // parameters in closures. diff --git a/src/test/ui/polymorphization/const_parameters/closures.stderr b/src/test/ui/polymorphization/const_parameters/closures.stderr index 266b6e62afd0..d0ee89329965 100644 --- a/src/test/ui/polymorphization/const_parameters/closures.stderr +++ b/src/test/ui/polymorphization/const_parameters/closures.stderr @@ -1,11 +1,11 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/closures.rs:3:12 | -LL | #![feature(const_generics, rustc_attrs)] - | ^^^^^^^^^^^^^^ +LL | #![feature(generic_const_exprs, rustc_attrs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #76560 for more information error: item has unused generic parameters --> $DIR/closures.rs:19:19 diff --git a/src/test/ui/polymorphization/const_parameters/functions.rs b/src/test/ui/polymorphization/const_parameters/functions.rs index 04c279de29e6..cbc1b63fbc4e 100644 --- a/src/test/ui/polymorphization/const_parameters/functions.rs +++ b/src/test/ui/polymorphization/const_parameters/functions.rs @@ -1,7 +1,7 @@ // build-fail // compile-flags:-Zpolymorphize=on -#![feature(const_generics, rustc_attrs)] -//~^ WARN the feature `const_generics` is incomplete +#![feature(generic_const_exprs, rustc_attrs)] +//~^ WARN the feature `generic_const_exprs` is incomplete // This test checks that the polymorphization analysis correctly detects unused const // parameters in functions. diff --git a/src/test/ui/polymorphization/const_parameters/functions.stderr b/src/test/ui/polymorphization/const_parameters/functions.stderr index e379e32c1fce..03d0bbb6afe6 100644 --- a/src/test/ui/polymorphization/const_parameters/functions.stderr +++ b/src/test/ui/polymorphization/const_parameters/functions.stderr @@ -1,11 +1,11 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/functions.rs:3:12 | -LL | #![feature(const_generics, rustc_attrs)] - | ^^^^^^^^^^^^^^ +LL | #![feature(generic_const_exprs, rustc_attrs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #76560 for more information error: item has unused generic parameters --> $DIR/functions.rs:15:8 diff --git a/src/test/ui/polymorphization/generators.rs b/src/test/ui/polymorphization/generators.rs index 9eb34fb73490..f295cf15d08c 100644 --- a/src/test/ui/polymorphization/generators.rs +++ b/src/test/ui/polymorphization/generators.rs @@ -1,7 +1,7 @@ // build-fail // compile-flags:-Zpolymorphize=on -#![feature(const_generics, generators, generator_trait, rustc_attrs)] -//~^ WARN the feature `const_generics` is incomplete +#![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)] +//~^ WARN the feature `generic_const_exprs` is incomplete use std::marker::Unpin; use std::ops::{Generator, GeneratorState}; diff --git a/src/test/ui/polymorphization/generators.stderr b/src/test/ui/polymorphization/generators.stderr index c59055ba9d65..c4e566a42d0c 100644 --- a/src/test/ui/polymorphization/generators.stderr +++ b/src/test/ui/polymorphization/generators.stderr @@ -1,11 +1,11 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/generators.rs:3:12 | -LL | #![feature(const_generics, generators, generator_trait, rustc_attrs)] - | ^^^^^^^^^^^^^^ +LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)] + | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #76560 for more information error: item has unused generic parameters --> $DIR/generators.rs:36:5 diff --git a/src/test/ui/resolve/issue-65035-static-with-parent-generics.rs b/src/test/ui/resolve/issue-65035-static-with-parent-generics.rs index f09ab3bf9198..f96c04841dd2 100644 --- a/src/test/ui/resolve/issue-65035-static-with-parent-generics.rs +++ b/src/test/ui/resolve/issue-65035-static-with-parent-generics.rs @@ -1,6 +1,3 @@ -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete - fn f() { extern "C" { static a: *const T; diff --git a/src/test/ui/resolve/issue-65035-static-with-parent-generics.stderr b/src/test/ui/resolve/issue-65035-static-with-parent-generics.stderr index 7f8151db06f5..7ed572f80b89 100644 --- a/src/test/ui/resolve/issue-65035-static-with-parent-generics.stderr +++ b/src/test/ui/resolve/issue-65035-static-with-parent-generics.stderr @@ -1,5 +1,5 @@ error[E0401]: can't use generic parameters from outer function - --> $DIR/issue-65035-static-with-parent-generics.rs:6:26 + --> $DIR/issue-65035-static-with-parent-generics.rs:3:26 | LL | fn f() { | - type parameter from outer function @@ -8,7 +8,7 @@ LL | static a: *const T; | ^ use of generic parameter from outer function error[E0401]: can't use generic parameters from outer function - --> $DIR/issue-65035-static-with-parent-generics.rs:12:22 + --> $DIR/issue-65035-static-with-parent-generics.rs:9:22 | LL | fn g() { | - type parameter from outer function @@ -16,7 +16,7 @@ LL | static a: *const T = Default::default(); | ^ use of generic parameter from outer function error[E0401]: can't use generic parameters from outer function - --> $DIR/issue-65035-static-with-parent-generics.rs:18:24 + --> $DIR/issue-65035-static-with-parent-generics.rs:15:24 | LL | fn h() { | - const parameter from outer function @@ -25,7 +25,7 @@ LL | static a: [u8; N]; | ^ use of generic parameter from outer function error[E0401]: can't use generic parameters from outer function - --> $DIR/issue-65035-static-with-parent-generics.rs:24:20 + --> $DIR/issue-65035-static-with-parent-generics.rs:21:20 | LL | fn i() { | - const parameter from outer function @@ -33,22 +33,13 @@ LL | static a: [u8; N] = [0; N]; | ^ use of generic parameter from outer function error[E0401]: can't use generic parameters from outer function - --> $DIR/issue-65035-static-with-parent-generics.rs:24:29 + --> $DIR/issue-65035-static-with-parent-generics.rs:21:29 | LL | fn i() { | - const parameter from outer function LL | static a: [u8; N] = [0; N]; | ^ use of generic parameter from outer function -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-65035-static-with-parent-generics.rs:1:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -error: aborting due to 5 previous errors; 1 warning emitted +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0401`. diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs index b3c9246486eb..b0b3464c6101 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs @@ -17,8 +17,6 @@ // // To that end, we check some positions which is not part of the language above. -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete #![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test. //~^ WARN the feature `let_chains` is incomplete diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr index b48915adc683..5ec4352919ea 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -1,5 +1,5 @@ error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/disallowed-positions.rs:235:9 + --> $DIR/disallowed-positions.rs:233:9 | LL | true && let 1 = 1 | ^^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | { true && let 1 = 1 } | + + error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:32:9 + --> $DIR/disallowed-positions.rs:30:9 | LL | if &let 0 = 0 {} | ^^^^^^^^^ @@ -19,7 +19,7 @@ LL | if &let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:35:9 + --> $DIR/disallowed-positions.rs:33:9 | LL | if !let 0 = 0 {} | ^^^^^^^^^ @@ -28,7 +28,7 @@ LL | if !let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:36:9 + --> $DIR/disallowed-positions.rs:34:9 | LL | if *let 0 = 0 {} | ^^^^^^^^^ @@ -37,7 +37,7 @@ LL | if *let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:38:9 + --> $DIR/disallowed-positions.rs:36:9 | LL | if -let 0 = 0 {} | ^^^^^^^^^ @@ -46,7 +46,7 @@ LL | if -let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:46:9 + --> $DIR/disallowed-positions.rs:44:9 | LL | if (let 0 = 0)? {} | ^^^^^^^^^ @@ -55,7 +55,7 @@ LL | if (let 0 = 0)? {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:50:16 + --> $DIR/disallowed-positions.rs:48:16 | LL | if true || let 0 = 0 {} | ^^^^^^^^^ @@ -64,7 +64,7 @@ LL | if true || let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:51:17 + --> $DIR/disallowed-positions.rs:49:17 | LL | if (true || let 0 = 0) {} | ^^^^^^^^^ @@ -73,7 +73,7 @@ LL | if (true || let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:52:25 + --> $DIR/disallowed-positions.rs:50:25 | LL | if true && (true || let 0 = 0) {} | ^^^^^^^^^ @@ -82,7 +82,7 @@ LL | if true && (true || let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:53:25 + --> $DIR/disallowed-positions.rs:51:25 | LL | if true || (true && let 0 = 0) {} | ^^^^^^^^^ @@ -91,7 +91,7 @@ LL | if true || (true && let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:56:12 + --> $DIR/disallowed-positions.rs:54:12 | LL | if x = let 0 = 0 {} | ^^^^^^^^^ @@ -100,7 +100,7 @@ LL | if x = let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:59:15 + --> $DIR/disallowed-positions.rs:57:15 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^ @@ -109,7 +109,7 @@ LL | if true..(let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:61:11 + --> $DIR/disallowed-positions.rs:59:11 | LL | if ..(let 0 = 0) {} | ^^^^^^^^^ @@ -118,7 +118,7 @@ LL | if ..(let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:63:9 + --> $DIR/disallowed-positions.rs:61:9 | LL | if (let 0 = 0).. {} | ^^^^^^^^^ @@ -127,7 +127,7 @@ LL | if (let 0 = 0).. {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:67:8 + --> $DIR/disallowed-positions.rs:65:8 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +136,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:71:8 + --> $DIR/disallowed-positions.rs:69:8 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:78:8 + --> $DIR/disallowed-positions.rs:76:8 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +154,7 @@ LL | if let Range { start: F, end } = F..|| true {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:86:8 + --> $DIR/disallowed-positions.rs:84:8 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +163,7 @@ LL | if let Range { start: true, end } = t..&&false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:92:19 + --> $DIR/disallowed-positions.rs:90:19 | LL | if let true = let true = true {} | ^^^^^^^^^^^^^^^ @@ -172,7 +172,7 @@ LL | if let true = let true = true {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:96:12 + --> $DIR/disallowed-positions.rs:94:12 | LL | while &let 0 = 0 {} | ^^^^^^^^^ @@ -181,7 +181,7 @@ LL | while &let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:99:12 + --> $DIR/disallowed-positions.rs:97:12 | LL | while !let 0 = 0 {} | ^^^^^^^^^ @@ -190,7 +190,7 @@ LL | while !let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:100:12 + --> $DIR/disallowed-positions.rs:98:12 | LL | while *let 0 = 0 {} | ^^^^^^^^^ @@ -199,7 +199,7 @@ LL | while *let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:102:12 + --> $DIR/disallowed-positions.rs:100:12 | LL | while -let 0 = 0 {} | ^^^^^^^^^ @@ -208,7 +208,7 @@ LL | while -let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:110:12 + --> $DIR/disallowed-positions.rs:108:12 | LL | while (let 0 = 0)? {} | ^^^^^^^^^ @@ -217,7 +217,7 @@ LL | while (let 0 = 0)? {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:114:19 + --> $DIR/disallowed-positions.rs:112:19 | LL | while true || let 0 = 0 {} | ^^^^^^^^^ @@ -226,7 +226,7 @@ LL | while true || let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:115:20 + --> $DIR/disallowed-positions.rs:113:20 | LL | while (true || let 0 = 0) {} | ^^^^^^^^^ @@ -235,7 +235,7 @@ LL | while (true || let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:116:28 + --> $DIR/disallowed-positions.rs:114:28 | LL | while true && (true || let 0 = 0) {} | ^^^^^^^^^ @@ -244,7 +244,7 @@ LL | while true && (true || let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:117:28 + --> $DIR/disallowed-positions.rs:115:28 | LL | while true || (true && let 0 = 0) {} | ^^^^^^^^^ @@ -253,7 +253,7 @@ LL | while true || (true && let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:120:15 + --> $DIR/disallowed-positions.rs:118:15 | LL | while x = let 0 = 0 {} | ^^^^^^^^^ @@ -262,7 +262,7 @@ LL | while x = let 0 = 0 {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:123:18 + --> $DIR/disallowed-positions.rs:121:18 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^ @@ -271,7 +271,7 @@ LL | while true..(let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:125:14 + --> $DIR/disallowed-positions.rs:123:14 | LL | while ..(let 0 = 0) {} | ^^^^^^^^^ @@ -280,7 +280,7 @@ LL | while ..(let 0 = 0) {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:127:12 + --> $DIR/disallowed-positions.rs:125:12 | LL | while (let 0 = 0).. {} | ^^^^^^^^^ @@ -289,7 +289,7 @@ LL | while (let 0 = 0).. {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:131:11 + --> $DIR/disallowed-positions.rs:129:11 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -298,7 +298,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:135:11 + --> $DIR/disallowed-positions.rs:133:11 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -307,7 +307,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:142:11 + --> $DIR/disallowed-positions.rs:140:11 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -316,7 +316,7 @@ LL | while let Range { start: F, end } = F..|| true {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:150:11 + --> $DIR/disallowed-positions.rs:148:11 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +325,7 @@ LL | while let Range { start: true, end } = t..&&false {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:156:22 + --> $DIR/disallowed-positions.rs:154:22 | LL | while let true = let true = true {} | ^^^^^^^^^^^^^^^ @@ -334,7 +334,7 @@ LL | while let true = let true = true {} = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:170:6 + --> $DIR/disallowed-positions.rs:168:6 | LL | &let 0 = 0; | ^^^^^^^^^ @@ -343,7 +343,7 @@ LL | &let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:172:6 + --> $DIR/disallowed-positions.rs:170:6 | LL | !let 0 = 0; | ^^^^^^^^^ @@ -352,7 +352,7 @@ LL | !let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:173:6 + --> $DIR/disallowed-positions.rs:171:6 | LL | *let 0 = 0; | ^^^^^^^^^ @@ -361,7 +361,7 @@ LL | *let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:175:6 + --> $DIR/disallowed-positions.rs:173:6 | LL | -let 0 = 0; | ^^^^^^^^^ @@ -370,7 +370,7 @@ LL | -let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:183:6 + --> $DIR/disallowed-positions.rs:181:6 | LL | (let 0 = 0)?; | ^^^^^^^^^ @@ -379,7 +379,7 @@ LL | (let 0 = 0)?; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:187:13 + --> $DIR/disallowed-positions.rs:185:13 | LL | true || let 0 = 0; | ^^^^^^^^^ @@ -388,7 +388,7 @@ LL | true || let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:188:14 + --> $DIR/disallowed-positions.rs:186:14 | LL | (true || let 0 = 0); | ^^^^^^^^^ @@ -397,7 +397,7 @@ LL | (true || let 0 = 0); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:189:22 + --> $DIR/disallowed-positions.rs:187:22 | LL | true && (true || let 0 = 0); | ^^^^^^^^^ @@ -406,7 +406,7 @@ LL | true && (true || let 0 = 0); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:192:9 + --> $DIR/disallowed-positions.rs:190:9 | LL | x = let 0 = 0; | ^^^^^^^^^ @@ -415,7 +415,7 @@ LL | x = let 0 = 0; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:194:12 + --> $DIR/disallowed-positions.rs:192:12 | LL | true..(let 0 = 0); | ^^^^^^^^^ @@ -424,7 +424,7 @@ LL | true..(let 0 = 0); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:195:8 + --> $DIR/disallowed-positions.rs:193:8 | LL | ..(let 0 = 0); | ^^^^^^^^^ @@ -433,7 +433,7 @@ LL | ..(let 0 = 0); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:196:6 + --> $DIR/disallowed-positions.rs:194:6 | LL | (let 0 = 0)..; | ^^^^^^^^^ @@ -442,7 +442,7 @@ LL | (let 0 = 0)..; = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:198:6 + --> $DIR/disallowed-positions.rs:196:6 | LL | (let Range { start: _, end: _ } = true..true || false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -451,7 +451,7 @@ LL | (let Range { start: _, end: _ } = true..true || false); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:202:6 + --> $DIR/disallowed-positions.rs:200:6 | LL | (let true = let true = true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -460,7 +460,7 @@ LL | (let true = let true = true); = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:206:6 + --> $DIR/disallowed-positions.rs:204:6 | LL | &let 0 = 0 | ^^^^^^^^^ @@ -469,7 +469,7 @@ LL | &let 0 = 0 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:217:17 + --> $DIR/disallowed-positions.rs:215:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -478,7 +478,7 @@ LL | true && let 1 = 1 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:221:17 + --> $DIR/disallowed-positions.rs:219:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -487,7 +487,7 @@ LL | true && let 1 = 1 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:225:17 + --> $DIR/disallowed-positions.rs:223:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -496,7 +496,7 @@ LL | true && let 1 = 1 = note: as well as when nested within `&&` and parenthesis in those conditions error: `let` expressions are not supported here - --> $DIR/disallowed-positions.rs:235:17 + --> $DIR/disallowed-positions.rs:233:17 | LL | true && let 1 = 1 | ^^^^^^^^^ @@ -504,25 +504,17 @@ LL | true && let 1 = 1 = note: only supported directly in conditions of `if`- and `while`-expressions = note: as well as when nested within `&&` and parenthesis in those conditions -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/disallowed-positions.rs:20:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - warning: the feature `let_chains` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/disallowed-positions.rs:22:12 + --> $DIR/disallowed-positions.rs:20:12 | LL | #![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test. | ^^^^^^^^^^ | + = note: `#[warn(incomplete_features)]` on by default = note: see issue #53667 for more information error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:32:8 + --> $DIR/disallowed-positions.rs:30:8 | LL | if &let 0 = 0 {} | ^^^^^^^^^^ expected `bool`, found `&bool` @@ -534,19 +526,19 @@ LL + if let 0 = 0 {} | error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:36:8 + --> $DIR/disallowed-positions.rs:34:8 | LL | if *let 0 = 0 {} | ^^^^^^^^^^ error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:38:8 + --> $DIR/disallowed-positions.rs:36:8 | LL | if -let 0 = 0 {} | ^^^^^^^^^^ cannot apply unary operator `-` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:46:8 + --> $DIR/disallowed-positions.rs:44:8 | LL | if (let 0 = 0)? {} | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` @@ -559,7 +551,7 @@ LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:46:19 + --> $DIR/disallowed-positions.rs:44:19 | LL | / fn nested_within_if_expr() { LL | | if &let 0 = 0 {} @@ -581,7 +573,7 @@ LL | fn from_residual(residual: R) -> Self; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:56:8 + --> $DIR/disallowed-positions.rs:54:8 | LL | if x = let 0 = 0 {} | ^^^^^^^^^^^^^ expected `bool`, found `()` @@ -592,7 +584,7 @@ LL | if x == let 0 = 0 {} | ~~ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:59:8 + --> $DIR/disallowed-positions.rs:57:8 | LL | if true..(let 0 = 0) {} | ^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -601,7 +593,7 @@ LL | if true..(let 0 = 0) {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:61:8 + --> $DIR/disallowed-positions.rs:59:8 | LL | if ..(let 0 = 0) {} | ^^^^^^^^^^^^^ expected `bool`, found struct `RangeTo` @@ -610,7 +602,7 @@ LL | if ..(let 0 = 0) {} found struct `RangeTo` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:63:8 + --> $DIR/disallowed-positions.rs:61:8 | LL | if (let 0 = 0).. {} | ^^^^^^^^^^^^^ expected `bool`, found struct `RangeFrom` @@ -619,7 +611,7 @@ LL | if (let 0 = 0).. {} found struct `RangeFrom` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:67:12 + --> $DIR/disallowed-positions.rs:65:12 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -630,7 +622,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:67:8 + --> $DIR/disallowed-positions.rs:65:8 | LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -639,7 +631,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:71:12 + --> $DIR/disallowed-positions.rs:69:12 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -650,7 +642,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:71:8 + --> $DIR/disallowed-positions.rs:69:8 | LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -659,7 +651,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:78:12 + --> $DIR/disallowed-positions.rs:76:12 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found struct `std::ops::Range` @@ -668,16 +660,16 @@ LL | if let Range { start: F, end } = F..|| true {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:78:41 + --> $DIR/disallowed-positions.rs:76:41 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^ expected `bool`, found closure | = note: expected type `bool` - found closure `[closure@$DIR/disallowed-positions.rs:78:41: 78:48]` + found closure `[closure@$DIR/disallowed-positions.rs:76:41: 76:48]` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:78:8 + --> $DIR/disallowed-positions.rs:76:8 | LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -686,7 +678,7 @@ LL | if let Range { start: F, end } = F..|| true {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:86:12 + --> $DIR/disallowed-positions.rs:84:12 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` @@ -697,13 +689,13 @@ LL | if let Range { start: true, end } = t..&&false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:86:44 + --> $DIR/disallowed-positions.rs:84:44 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^ expected `bool`, found `&&bool` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:86:8 + --> $DIR/disallowed-positions.rs:84:8 | LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -712,7 +704,7 @@ LL | if let Range { start: true, end } = t..&&false {} found struct `std::ops::Range` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:42:20 + --> $DIR/disallowed-positions.rs:40:20 | LL | if let 0 = 0? {} | ^^ the `?` operator cannot be applied to type `{integer}` @@ -725,7 +717,7 @@ LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:96:11 + --> $DIR/disallowed-positions.rs:94:11 | LL | while &let 0 = 0 {} | ^^^^^^^^^^ expected `bool`, found `&bool` @@ -737,19 +729,19 @@ LL + while let 0 = 0 {} | error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:100:11 + --> $DIR/disallowed-positions.rs:98:11 | LL | while *let 0 = 0 {} | ^^^^^^^^^^ error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:102:11 + --> $DIR/disallowed-positions.rs:100:11 | LL | while -let 0 = 0 {} | ^^^^^^^^^^ cannot apply unary operator `-` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:110:11 + --> $DIR/disallowed-positions.rs:108:11 | LL | while (let 0 = 0)? {} | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` @@ -762,7 +754,7 @@ LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:110:22 + --> $DIR/disallowed-positions.rs:108:22 | LL | / fn nested_within_while_expr() { LL | | while &let 0 = 0 {} @@ -784,7 +776,7 @@ LL | fn from_residual(residual: R) -> Self; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:120:11 + --> $DIR/disallowed-positions.rs:118:11 | LL | while x = let 0 = 0 {} | ^^^^^^^^^^^^^ expected `bool`, found `()` @@ -795,7 +787,7 @@ LL | while x == let 0 = 0 {} | ~~ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:123:11 + --> $DIR/disallowed-positions.rs:121:11 | LL | while true..(let 0 = 0) {} | ^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -804,7 +796,7 @@ LL | while true..(let 0 = 0) {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:125:11 + --> $DIR/disallowed-positions.rs:123:11 | LL | while ..(let 0 = 0) {} | ^^^^^^^^^^^^^ expected `bool`, found struct `RangeTo` @@ -813,7 +805,7 @@ LL | while ..(let 0 = 0) {} found struct `RangeTo` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:127:11 + --> $DIR/disallowed-positions.rs:125:11 | LL | while (let 0 = 0).. {} | ^^^^^^^^^^^^^ expected `bool`, found struct `RangeFrom` @@ -822,7 +814,7 @@ LL | while (let 0 = 0).. {} found struct `RangeFrom` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:131:15 + --> $DIR/disallowed-positions.rs:129:15 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -833,7 +825,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:131:11 + --> $DIR/disallowed-positions.rs:129:11 | LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -842,7 +834,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:135:15 + --> $DIR/disallowed-positions.rs:133:15 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -853,7 +845,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:135:11 + --> $DIR/disallowed-positions.rs:133:11 | LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -862,7 +854,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:142:15 + --> $DIR/disallowed-positions.rs:140:15 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found struct `std::ops::Range` @@ -871,16 +863,16 @@ LL | while let Range { start: F, end } = F..|| true {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:142:44 + --> $DIR/disallowed-positions.rs:140:44 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^ expected `bool`, found closure | = note: expected type `bool` - found closure `[closure@$DIR/disallowed-positions.rs:142:44: 142:51]` + found closure `[closure@$DIR/disallowed-positions.rs:140:44: 140:51]` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:142:11 + --> $DIR/disallowed-positions.rs:140:11 | LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -889,7 +881,7 @@ LL | while let Range { start: F, end } = F..|| true {} found struct `std::ops::Range` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:150:15 + --> $DIR/disallowed-positions.rs:148:15 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool` @@ -900,13 +892,13 @@ LL | while let Range { start: true, end } = t..&&false {} found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:150:47 + --> $DIR/disallowed-positions.rs:148:47 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^ expected `bool`, found `&&bool` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:150:11 + --> $DIR/disallowed-positions.rs:148:11 | LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range` @@ -915,7 +907,7 @@ LL | while let Range { start: true, end } = t..&&false {} found struct `std::ops::Range` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:106:23 + --> $DIR/disallowed-positions.rs:104:23 | LL | while let 0 = 0? {} | ^^ the `?` operator cannot be applied to type `{integer}` @@ -928,19 +920,19 @@ LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0614]: type `bool` cannot be dereferenced - --> $DIR/disallowed-positions.rs:173:5 + --> $DIR/disallowed-positions.rs:171:5 | LL | *let 0 = 0; | ^^^^^^^^^^ error[E0600]: cannot apply unary operator `-` to type `bool` - --> $DIR/disallowed-positions.rs:175:5 + --> $DIR/disallowed-positions.rs:173:5 | LL | -let 0 = 0; | ^^^^^^^^^^ cannot apply unary operator `-` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:183:5 + --> $DIR/disallowed-positions.rs:181:5 | LL | (let 0 = 0)?; | ^^^^^^^^^^^^ the `?` operator cannot be applied to type `bool` @@ -953,7 +945,7 @@ LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) - --> $DIR/disallowed-positions.rs:183:16 + --> $DIR/disallowed-positions.rs:181:16 | LL | / fn outside_if_and_while_expr() { LL | | &let 0 = 0; @@ -975,7 +967,7 @@ LL | fn from_residual(residual: R) -> Self; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:198:10 + --> $DIR/disallowed-positions.rs:196:10 | LL | (let Range { start: _, end: _ } = true..true || false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ---- this expression has type `bool` @@ -986,7 +978,7 @@ LL | (let Range { start: _, end: _ } = true..true || false); found struct `std::ops::Range<_>` error[E0308]: mismatched types - --> $DIR/disallowed-positions.rs:206:5 + --> $DIR/disallowed-positions.rs:204:5 | LL | fn outside_if_and_while_expr() { | - help: try adding a return type: `-> &bool` @@ -995,7 +987,7 @@ LL | &let 0 = 0 | ^^^^^^^^^^ expected `()`, found `&bool` error[E0277]: the `?` operator can only be applied to values that implement `Try` - --> $DIR/disallowed-positions.rs:179:17 + --> $DIR/disallowed-positions.rs:177:17 | LL | let 0 = 0?; | ^^ the `?` operator cannot be applied to type `{integer}` @@ -1007,7 +999,7 @@ note: required by `branch` LL | fn branch(self) -> ControlFlow; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 103 previous errors; 2 warnings emitted +error: aborting due to 103 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0308, E0600, E0614. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/self/arbitrary-self-types-not-object-safe.stderr b/src/test/ui/self/arbitrary-self-types-not-object-safe.stderr deleted file mode 100644 index 353da8fd20b2..000000000000 --- a/src/test/ui/self/arbitrary-self-types-not-object-safe.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/arbitrary-self-types-not-object-safe.rs:29:32 - | -LL | fn foo(self: &Rc) -> usize; - | --- method `foo`'s `self` parameter cannot be dispatched on -... -LL | let x = Rc::new(5usize) as Rc; - | ^^^^^^^^^^^ the trait `Foo` cannot be made into an object - -error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/arbitrary-self-types-not-object-safe.rs:29:13 - | -LL | fn foo(self: &Rc) -> usize; - | --- method `foo`'s `self` parameter cannot be dispatched on -... -LL | let x = Rc::new(5usize) as Rc; - | ^^^^^^^^^^^^^^^ the trait `Foo` cannot be made into an object - | - = note: required because of the requirements on the impl of `std::ops::CoerceUnsized>` for `std::rc::Rc` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0038`. diff --git a/src/test/ui/simd/simd-array-trait.rs b/src/test/ui/simd/simd-array-trait.rs index d6ed5f61a000..45c10b378160 100644 --- a/src/test/ui/simd/simd-array-trait.rs +++ b/src/test/ui/simd/simd-array-trait.rs @@ -4,7 +4,7 @@ // pretty-expanded FIXME #23616 -#![feature(repr_simd, platform_intrinsics, const_generics)] +#![feature(repr_simd, platform_intrinsics, generic_const_exprs)] #![allow(non_camel_case_types, incomplete_features)] pub trait Simd { @@ -21,7 +21,7 @@ impl Simd for i32x4 { #[repr(simd)] #[derive(Copy, Clone)] pub struct T([S::Lane; S::SIZE]); -//~^ ERROR constant expression depends on a generic parameter +//~^ ERROR unconstrained generic constant extern "platform-intrinsic" { fn simd_insert(x: T, idx: u32, y: E) -> T; diff --git a/src/test/ui/simd/simd-array-trait.stderr b/src/test/ui/simd/simd-array-trait.stderr index c100e020c549..0e02883f67a4 100644 --- a/src/test/ui/simd/simd-array-trait.stderr +++ b/src/test/ui/simd/simd-array-trait.stderr @@ -1,10 +1,10 @@ -error: constant expression depends on a generic parameter +error: unconstrained generic constant --> $DIR/simd-array-trait.rs:23:23 | LL | pub struct T([S::Lane; S::SIZE]); | ^^^^^^^^^^^^^^^^^^ | - = note: this may fail depending on what value the parameter takes + = help: try adding a `where` bound using this expression: `where [(); S::SIZE]:` error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-51892.rs b/src/test/ui/specialization/issue-51892.rs index e82d40d33cd7..5c06254143d0 100644 --- a/src/test/ui/specialization/issue-51892.rs +++ b/src/test/ui/specialization/issue-51892.rs @@ -1,5 +1,4 @@ #![allow(incomplete_features)] -#![feature(const_generics)] #![feature(generic_const_exprs)] #![feature(specialization)] diff --git a/src/test/ui/specialization/issue-51892.stderr b/src/test/ui/specialization/issue-51892.stderr index 10a39a491477..cb46db83606b 100644 --- a/src/test/ui/specialization/issue-51892.stderr +++ b/src/test/ui/specialization/issue-51892.stderr @@ -1,5 +1,5 @@ error: unconstrained generic constant - --> $DIR/issue-51892.rs:15:17 + --> $DIR/issue-51892.rs:14:17 | LL | type Type = [u8; std::mem::size_of::<::Type>()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/symbol-names/basic.stderr b/src/test/ui/symbol-names/basic.stderr deleted file mode 100644 index 7539cbada8b7..000000000000 --- a/src/test/ui/symbol-names/basic.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: symbol-name(_ZN5basic4main17hd72940ef9669d526E) - --> $DIR/basic.rs:3:1 - | -LL | #[rustc_symbol_name] - | ^^^^^^^^^^^^^^^^^^^^ - -error: def-path(main) - --> $DIR/basic.rs:4:1 - | -LL | #[rustc_def_path] - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/symbol-names/const-generics-str-demangling.rs b/src/test/ui/symbol-names/const-generics-str-demangling.rs index af111dd39fac..906350f51036 100644 --- a/src/test/ui/symbol-names/const-generics-str-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-str-demangling.rs @@ -1,6 +1,6 @@ // build-fail // compile-flags: -Z symbol-mangling-version=v0 --crate-name=c -#![feature(const_generics, rustc_attrs)] +#![feature(const_param_types, rustc_attrs)] #![allow(incomplete_features)] pub struct Str; diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.rs b/src/test/ui/symbol-names/const-generics-structural-demangling.rs index 9da6a0f18e69..ec677e46b55d 100644 --- a/src/test/ui/symbol-names/const-generics-structural-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.rs @@ -6,7 +6,7 @@ // normalize-stderr-test: "Cs[0-9a-zA-Z]+_4core" -> "Cs$$HASH_4core" // normalize-stderr-test: "core\[[0-9a-f]+\]" -> "core[$$HASH_HEX]" -#![feature(const_generics, decl_macro, rustc_attrs)] +#![feature(const_param_types, decl_macro, rustc_attrs)] #![allow(incomplete_features)] pub struct RefByte; diff --git a/src/test/ui/type-alias-impl-trait/assoc-type-const.rs b/src/test/ui/type-alias-impl-trait/assoc-type-const.rs index d53f562e99f4..0ade36dafa4f 100644 --- a/src/test/ui/type-alias-impl-trait/assoc-type-const.rs +++ b/src/test/ui/type-alias-impl-trait/assoc-type-const.rs @@ -3,8 +3,6 @@ // check-pass #![feature(type_alias_impl_trait)] -#![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete trait UnwrapItemsExt<'a, const C: usize> { type Iter; diff --git a/src/test/ui/type-alias-impl-trait/assoc-type-const.stderr b/src/test/ui/type-alias-impl-trait/assoc-type-const.stderr deleted file mode 100644 index e0c1b0238612..000000000000 --- a/src/test/ui/type-alias-impl-trait/assoc-type-const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/assoc-type-const.rs:6:12 - | -LL | #![feature(const_generics)] - | ^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information - -warning: 1 warning emitted - diff --git a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.full_tait.stderr b/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.full_tait.stderr deleted file mode 100644 index 3ba04af9046d..000000000000 --- a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.full_tait.stderr +++ /dev/null @@ -1,23 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/bounds-are-checked-2.rs:6:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/bounds-are-checked-2.rs:9:13 - | -LL | type X = impl Clone; - | ^^^^^^^^^^ the trait `Clone` is not implemented for `T` - | -help: consider restricting type parameter `T` - | -LL | type X = impl Clone; - | +++++++++++++++++++ - -error: aborting due to previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs index e45950c4926b..a4e40f516dce 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -1,6 +1,4 @@ -#![feature(const_generics)] #![feature(type_alias_impl_trait)] -#![allow(incomplete_features)] use std::fmt::Debug; diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index 7ea5efd4e6b0..641cce26d994 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -1,35 +1,35 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:14:30 + --> $DIR/generic_duplicate_param_use.rs:12:30 | LL | fn one_ty(t: T) -> TwoTys { | ^^^^^^^^^^^^ | note: type used multiple times - --> $DIR/generic_duplicate_param_use.rs:10:13 + --> $DIR/generic_duplicate_param_use.rs:8:13 | LL | type TwoTys = impl Debug; | ^ ^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:19:36 + --> $DIR/generic_duplicate_param_use.rs:17:36 | LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { | ^^^^^^^^^^^^^^^^^^^^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_param_use.rs:11:19 + --> $DIR/generic_duplicate_param_use.rs:9:19 | LL | type TwoLifetimes<'a, 'b> = impl Debug; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:24:50 + --> $DIR/generic_duplicate_param_use.rs:22:50 | LL | fn one_const(t: *mut [u8; N]) -> TwoConsts { | ^^^^^^^^^^^^^^^ | note: constant used multiple times - --> $DIR/generic_duplicate_param_use.rs:12:22 + --> $DIR/generic_duplicate_param_use.rs:10:22 | LL | type TwoConsts = impl Debug; | ^ ^ diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.full_tait.stderr deleted file mode 100644 index 918121cce9db..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.full_tait.stderr +++ /dev/null @@ -1,48 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_duplicate_param_use5.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use5.rs:19:1 - | -LL | fn three(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(T, U)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use5.rs:15:1 - | -LL | fn two(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:11:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(T, U)` -help: consider restricting type parameter `T` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:11:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(T, U)` -help: consider restricting type parameter `U` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error: aborting due to 3 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.full_tait.stderr deleted file mode 100644 index 394b4280ab95..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.full_tait.stderr +++ /dev/null @@ -1,36 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_duplicate_param_use6.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use6.rs:18:1 - | -LL | fn three(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(T, T)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use6.rs:14:1 - | -LL | fn two(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use6.rs:11:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(T, T)` -help: consider restricting type parameter `T` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error: aborting due to 2 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.full_tait.stderr deleted file mode 100644 index 8c6ea3b34219..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.full_tait.stderr +++ /dev/null @@ -1,36 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_duplicate_param_use8.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use8.rs:17:1 - | -LL | fn three(_: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(T, u32)`, got `(U, u32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use8.rs:13:1 - | -LL | fn two(t: T, _: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use8.rs:10:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(T, u32)` -help: consider restricting type parameter `T` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error: aborting due to 2 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.full_tait.stderr deleted file mode 100644 index d0176b1e36d7..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.full_tait.stderr +++ /dev/null @@ -1,60 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_duplicate_param_use9.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use9.rs:24:1 - | -LL | fn three(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(A, B, ::Bar)`, got `(A, B, i32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use9.rs:20:1 - | -LL | fn two(t: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: the trait bound `A: Foo` is not satisfied in `(A, B, ::Bar)` - --> $DIR/generic_duplicate_param_use9.rs:10:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ within `(A, B, ::Bar)`, the trait `Foo` is not implemented for `A` - | - = note: required because it appears within the type `(A, B, ::Bar)` -help: consider restricting type parameter `A` - | -LL | type Two = impl Debug; - | +++++ - -error[E0277]: `A` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:10:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(A, B, ::Bar)` -help: consider restricting type parameter `A` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error[E0277]: `B` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:10:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | - = note: required because of the requirements on the impl of `Debug` for `(A, B, ::Bar)` -help: consider restricting type parameter `B` - | -LL | type Two = impl Debug; - | +++++++++++++++++ - -error: aborting due to 4 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs index 9f1bffff77c9..7ee5f7b068f4 100644 --- a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs @@ -1,6 +1,4 @@ -#![feature(const_generics)] #![feature(type_alias_impl_trait)] -#![allow(incomplete_features)] use std::fmt::Debug; diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr index eb0c296bb626..5b42f10a6ee3 100644 --- a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -1,17 +1,17 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:15:21 + --> $DIR/generic_nondefining_use.rs:13:21 | LL | fn concrete_ty() -> OneTy { | ^^^^^^^^^^ | note: used non-generic type `u32` for generic parameter - --> $DIR/generic_nondefining_use.rs:9:12 + --> $DIR/generic_nondefining_use.rs:7:12 | LL | type OneTy = impl Debug; | ^ error: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:20:27 + --> $DIR/generic_nondefining_use.rs:18:27 | LL | type OneLifetime<'a> = impl Debug; | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type @@ -20,13 +20,13 @@ LL | fn concrete_lifetime() -> OneLifetime<'static> { | ^^^^^^^^^^^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:25:24 + --> $DIR/generic_nondefining_use.rs:23:24 | LL | fn concrete_const() -> OneConst<{ 123 }> { | ^^^^^^^^^^^^^^^^^ | -note: used non-generic constant `{ 123 }` for generic parameter - --> $DIR/generic_nondefining_use.rs:11:21 +note: used non-generic constant `123_usize` for generic parameter + --> $DIR/generic_nondefining_use.rs:9:21 | LL | type OneConst = impl Debug; | ^ diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained.full_tait.stderr deleted file mode 100644 index 74d5c0c96886..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_underconstrained.full_tait.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_underconstrained.rs:9:35 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^^^^^^ - -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_underconstrained.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/generic_underconstrained.rs:13:31 - | -LL | type Underconstrained = impl 'static; - | ----- required by this bound in `Underconstrained` -... -LL | fn underconstrain(_: T) -> Underconstrained { - | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` - | -help: consider restricting type parameter `T` - | -LL | fn underconstrain(_: T) -> Underconstrained { - | +++++++ - -error: aborting due to 2 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.full_tait.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.full_tait.stderr deleted file mode 100644 index 348563b94de1..000000000000 --- a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.full_tait.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:8:45 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^^^^^^ - -error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:17:46 - | -LL | type Underconstrained2 = impl 'static; - | ^^^^^^^^^^^^ - -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/generic_underconstrained2.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:12:33 - | -LL | type Underconstrained = impl 'static; - | --------------- required by this bound in `Underconstrained` -... -LL | fn underconstrained(_: U) -> Underconstrained { - | ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | -help: consider restricting type parameter `U` - | -LL | fn underconstrained(_: U) -> Underconstrained { - | +++++++++++++++++ - -error[E0277]: `V` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:21:43 - | -LL | type Underconstrained2 = impl 'static; - | --------------- required by this bound in `Underconstrained2` -... -LL | fn underconstrained2(_: U, _: V) -> Underconstrained2 { - | ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug` - | -help: consider restricting type parameter `V` - | -LL | fn underconstrained2(_: U, _: V) -> Underconstrained2 { - | +++++++++++++++++ - -error: aborting due to 4 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-52843.full_tait.stderr b/src/test/ui/type-alias-impl-trait/issue-52843.full_tait.stderr deleted file mode 100644 index 16b1830e9851..000000000000 --- a/src/test/ui/type-alias-impl-trait/issue-52843.full_tait.stderr +++ /dev/null @@ -1,23 +0,0 @@ -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-52843.rs:3:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0277]: the trait bound `T: Default` is not satisfied - --> $DIR/issue-52843.rs:6:15 - | -LL | type Foo = impl Default; - | ^^^^^^^^^^^^ the trait `Default` is not implemented for `T` - | -help: consider restricting type parameter `T` - | -LL | type Foo = impl Default; - | +++++++++++++++++++++++ - -error: aborting due to previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.full_tait.stderr b/src/test/ui/typeck/typeck_type_placeholder_item.full_tait.stderr deleted file mode 100644 index 6ba28c3463ad..000000000000 --- a/src/test/ui/typeck/typeck_type_placeholder_item.full_tait.stderr +++ /dev/null @@ -1,647 +0,0 @@ -error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:157:18 - | -LL | struct BadStruct<_>(_); - | ^ expected identifier, found reserved identifier - -error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:160:16 - | -LL | trait BadTrait<_> {} - | ^ expected identifier, found reserved identifier - -error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:170:19 - | -LL | struct BadStruct1<_, _>(_); - | ^ expected identifier, found reserved identifier - -error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:170:22 - | -LL | struct BadStruct1<_, _>(_); - | ^ expected identifier, found reserved identifier - -error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:175:19 - | -LL | struct BadStruct2<_, T>(_, T); - | ^ expected identifier, found reserved identifier - -error: associated constant in `impl` without body - --> $DIR/typeck_type_placeholder_item.rs:208:5 - | -LL | const C: _; - | ^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` - -error[E0403]: the name `_` is already used for a generic parameter in this item's generic parameters - --> $DIR/typeck_type_placeholder_item.rs:170:22 - | -LL | struct BadStruct1<_, _>(_); - | - ^ already used - | | - | first use of `_` - -warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/typeck_type_placeholder_item.rs:5:32 - | -LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait))] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - = note: see issue #63063 for more information - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:10:14 - | -LL | fn test() -> _ { 5 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:13:16 - | -LL | fn test2() -> (_, _) { (5, 5) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:16:15 - | -LL | static TEST3: _ = "test"; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `&str` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:19:15 - | -LL | static TEST4: _ = 145; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:22:15 - | -LL | static TEST5: (_, _) = (1, 2); - | ^^^^^^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:25:13 - | -LL | fn test6(_: _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6(_: T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:28:18 - | -LL | fn test6_b(_: _, _: T) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6_b(_: U, _: T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:31:30 - | -LL | fn test6_c(_: _, _: (T, K, L, A, B)) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6_c(_: U, _: (T, K, L, A, B)) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:34:13 - | -LL | fn test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test7(x: T) { let _x: usize = x; } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:37:22 - | -LL | fn test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:37:22 - | -LL | fn test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test8(_f: fn() -> T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:51:26 - | -LL | fn test11(x: &usize) -> &_ { - | -^ - | || - | |not allowed in type signatures - | help: replace with the correct return type: `&'static &'static usize` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:56:52 - | -LL | unsafe fn test12(x: *const usize) -> *const *const _ { - | --------------^ - | | | - | | not allowed in type signatures - | help: replace with the correct return type: `*const *const usize` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:70:8 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct Test10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), - | - -error: missing type for `static` item - --> $DIR/typeck_type_placeholder_item.rs:76:12 - | -LL | static A = 42; - | ^ help: provide a type for the static variable: `A: i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:78:15 - | -LL | static B: _ = 42; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:80:15 - | -LL | static C: Option<_> = Some(42); - | ^^^^^^^^^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:82:21 - | -LL | fn fn_test() -> _ { 5 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:85:23 - | -LL | fn fn_test2() -> (_, _) { (5, 5) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:88:22 - | -LL | static FN_TEST3: _ = "test"; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `&str` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:91:22 - | -LL | static FN_TEST4: _ = 145; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:94:22 - | -LL | static FN_TEST5: (_, _) = (1, 2); - | ^^^^^^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:97:20 - | -LL | fn fn_test6(_: _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test6(_: T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:100:20 - | -LL | fn fn_test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test7(x: T) { let _x: usize = x; } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:103:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:103:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test8(_f: fn() -> T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:126:12 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct FnTest10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), - | - -error[E0282]: type annotations needed - --> $DIR/typeck_type_placeholder_item.rs:131:18 - | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ cannot infer type - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:131:28 - | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:135:30 - | -LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:138:33 - | -LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } - | ------^- - | | | - | | not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:157:21 - | -LL | struct BadStruct<_>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct(T); - | ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for implementations - --> $DIR/typeck_type_placeholder_item.rs:162:15 - | -LL | impl BadTrait<_> for BadStruct<_> {} - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | impl BadTrait for BadStruct {} - | +++ ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:165:34 - | -LL | fn impl_trait() -> impl BadTrait<_> { - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:170:25 - | -LL | struct BadStruct1<_, _>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct1(T); - | ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:175:25 - | -LL | struct BadStruct2<_, T>(_, T); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct2(U, T); - | ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:179:14 - | -LL | type X = Box<_>; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for opaque types - --> $DIR/typeck_type_placeholder_item.rs:185:21 - | -LL | type Y = impl Trait<_>; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:219:31 - | -LL | fn value() -> Option<&'static _> { - | ----------------^- - | | | - | | not allowed in type signatures - | help: replace with the correct return type: `Option<&'static u8>` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:224:10 - | -LL | const _: Option<_> = map(value); - | ^^^^^^^^^ - | | - | not allowed in type signatures - | help: replace with the correct type: `Option` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:143:31 - | -LL | fn method_test1(&self, x: _); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test1(&self, x: T); - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:145:31 - | -LL | fn method_test2(&self, x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test2(&self, x: T) -> T; - | +++ ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:147:31 - | -LL | fn method_test3(&self) -> _; - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test3(&self) -> T; - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:149:26 - | -LL | fn assoc_fn_test1(x: _); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test1(x: T); - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:151:26 - | -LL | fn assoc_fn_test2(x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test2(x: T) -> T; - | +++ ~ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:153:28 - | -LL | fn assoc_fn_test3() -> _; - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test3() -> T; - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:193:14 - | -LL | type B = _; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:195:14 - | -LL | const C: _; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:197:14 - | -LL | const D: _ = 42; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:200:26 - | -LL | type F: std::ops::Fn(_); - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:44:24 - | -LL | fn test9(&self) -> _ { () } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `()` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:47:27 - | -LL | fn test10(&self, _x : _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test10(&self, _x : T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:62:24 - | -LL | fn clone(&self) -> _ { Test9 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `Test9` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:65:37 - | -LL | fn clone_from(&mut self, other: _) { *self = Test9; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn clone_from(&mut self, other: T) { *self = Test9; } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:110:31 - | -LL | fn fn_test9(&self) -> _ { () } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `()` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:113:34 - | -LL | fn fn_test10(&self, _x : _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test10(&self, _x : T) { } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:118:28 - | -LL | fn clone(&self) -> _ { FnTest9 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `FnTest9` - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:121:41 - | -LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn clone_from(&mut self, other: T) { *self = FnTest9; } - | +++ ~ - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:204:14 - | -LL | type A = _; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:206:14 - | -LL | type B = _; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:208:14 - | -LL | const C: _; - | ^ not allowed in type signatures - -error[E0121]: the type placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:211:14 - | -LL | const D: _ = 42; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error: aborting due to 69 previous errors; 1 warning emitted - -Some errors have detailed explanations: E0121, E0282, E0403. -For more information about an error, try `rustc --explain E0121`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-4775.rs b/src/tools/clippy/tests/ui/crashes/ice-4775.rs index 31e53e846d54..405e3039e7d0 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-4775.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-4775.rs @@ -1,6 +1,3 @@ -#![feature(const_generics)] -#![allow(incomplete_features)] - pub struct ArrayWrapper([usize; N]); impl ArrayWrapper<{ N }> { diff --git a/src/tools/clippy/tests/ui/crashes/ice-5223.rs b/src/tools/clippy/tests/ui/crashes/ice-5223.rs index 9bb2e227fc12..e3b3b27a6fc3 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5223.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-5223.rs @@ -1,7 +1,4 @@ // Regression test for #5233 - -#![feature(const_generics)] -#![allow(incomplete_features)] #![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)] pub struct KotomineArray { diff --git a/src/tools/clippy/tests/ui/doc/doc.rs b/src/tools/clippy/tests/ui/doc/doc.rs index 8b20997fdf8d..8b0c0f304fce 100644 --- a/src/tools/clippy/tests/ui/doc/doc.rs +++ b/src/tools/clippy/tests/ui/doc/doc.rs @@ -2,7 +2,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, const_generics, generic_const_exprs, const_option)] +#![feature(custom_inner_attributes, generic_const_exprs, const_option)] #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs index 6d2cbb6ad96f..aa60d0504e5e 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -5,8 +5,7 @@ // aux-build:helper.rs #![warn(clippy::missing_const_for_fn)] -#![allow(incomplete_features)] -#![feature(start, const_generics)] +#![feature(start)] #![feature(custom_inner_attributes)] extern crate helper; diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs index 0accb516f5f6..baa7eec05462 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs @@ -1,6 +1,5 @@ #![warn(clippy::missing_const_for_fn)] #![allow(incomplete_features, clippy::let_and_return)] -#![feature(const_generics)] #![feature(custom_inner_attributes)] use std::mem::transmute; diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr index 63c211f39fa1..b89cc6451bb5 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -1,5 +1,5 @@ error: this could be a `const fn` - --> $DIR/could_be_const.rs:14:5 + --> $DIR/could_be_const.rs:13:5 | LL | / pub fn new() -> Self { LL | | Self { guess: 42 } @@ -9,7 +9,7 @@ LL | | } = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` error: this could be a `const fn` - --> $DIR/could_be_const.rs:18:5 + --> $DIR/could_be_const.rs:17:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { LL | | b @@ -17,7 +17,7 @@ LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:24:1 + --> $DIR/could_be_const.rs:23:1 | LL | / fn one() -> i32 { LL | | 1 @@ -25,7 +25,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:29:1 + --> $DIR/could_be_const.rs:28:1 | LL | / fn two() -> i32 { LL | | let abc = 2; @@ -34,7 +34,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:35:1 + --> $DIR/could_be_const.rs:34:1 | LL | / fn string() -> String { LL | | String::new() @@ -42,7 +42,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:40:1 + --> $DIR/could_be_const.rs:39:1 | LL | / unsafe fn four() -> i32 { LL | | 4 @@ -50,7 +50,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:45:1 + --> $DIR/could_be_const.rs:44:1 | LL | / fn generic(t: T) -> T { LL | | t @@ -58,7 +58,7 @@ LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:68:9 + --> $DIR/could_be_const.rs:67:9 | LL | / pub fn b(self, a: &A) -> B { LL | | B @@ -66,7 +66,7 @@ LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:78:5 + --> $DIR/could_be_const.rs:77:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { LL | | byte.is_ascii_digit(); From 4747cbb3bbb1dd7a9f8a5bdb2eee073f8e4c43ef Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 26 Aug 2021 21:12:02 +0200 Subject: [PATCH 250/269] allow unordered const/ty params if any cg feature is active --- compiler/rustc_ast/src/ast.rs | 4 ++-- compiler/rustc_ast_passes/src/ast_validation.rs | 2 +- compiler/rustc_feature/src/active.rs | 2 +- .../params-in-ct-in-ty-param-lazy-norm.full.stderr | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index d0a95ea130a4..e1ea464dedb1 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -332,8 +332,8 @@ pub type GenericBounds = Vec; pub enum ParamKindOrd { Lifetime, Type, - // `unordered` is only `true` if `sess.has_features().const_generics_defaults` - // is active. Specifically, if it's only `min_const_generics`, it will still require + // `unordered` is only `true` if `sess.unordered_const_ty_params()` + // returns true. Specifically, if it's only `min_const_generics`, it will still require // ordering consts after types. Const { unordered: bool }, // `Infer` is not actually constructed directly from the AST, but is implicitly constructed diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index c0ea710fdcb4..73abd2bb83b9 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1351,7 +1351,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } fn visit_generics(&mut self, generics: &'a Generics) { - let cg_defaults = self.session.features_untracked().const_generics_defaults; + let cg_defaults = self.session.features_untracked().unordered_const_ty_params(); let mut prev_param_default = None; for param in &generics.params { diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index e2c88835f524..79a1f4e0c5cf 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -71,7 +71,7 @@ macro_rules! declare_features { } pub fn unordered_const_ty_params(&self) -> bool { - self.const_generics_defaults + self.const_generics_defaults || self.generic_const_exprs || self.const_param_types } /// Some features are known to be incomplete and using them is likely to have diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.full.stderr b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.full.stderr index e8fd9e7769b7..9f0b2efae96c 100644 --- a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.full.stderr +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.full.stderr @@ -3,8 +3,6 @@ error: generic parameters with a default must be trailing | LL | struct Bar(T); | ^ - | - = note: using type defaults and const parameters in the same parameter list is currently not permitted error[E0128]: generic parameters with a default cannot use forward declared identifiers --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21 From 87e781799a160129169b838e900aaef8ecb3a9dd Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 30 Aug 2021 10:59:53 +0200 Subject: [PATCH 251/269] `feature(const_param_types)` -> `feature(adt_const_params)` --- .../rustc_error_codes/src/error_codes/E0741.md | 4 ++-- .../rustc_error_codes/src/error_codes/E0771.md | 4 ++-- compiler/rustc_feature/src/active.rs | 4 ++-- compiler/rustc_feature/src/removed.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_typeck/src/check/wfcheck.rs | 4 ++-- src/test/debuginfo/function-names.rs | 2 +- .../const-generics/hash-tyvid-regression-1.rs | 2 +- .../const-generics/hash-tyvid-regression-2.rs | 2 +- .../issue-77708-3.rs | 2 +- src/test/rustdoc/const-generics/const-impl.rs | 2 +- src/test/ui/async-await/issues/issue-78654.rs | 2 +- .../const-param-elided-lifetime.min.stderr | 10 +++++----- .../const-generics/const-param-elided-lifetime.rs | 2 +- ...st-param-type-depends-on-const-param.min.stderr | 4 ++-- .../const-param-type-depends-on-const-param.rs | 2 +- .../const-param-type-depends-on-type-param.rs | 2 +- src/test/ui/const-generics/core-types.rs | 2 +- .../const-generics/different_generic_args_array.rs | 2 +- src/test/ui/const-generics/fn-const-param-call.rs | 2 +- src/test/ui/const-generics/fn-const-param-infer.rs | 2 +- .../forbid-non-structural_match-types.rs | 2 +- .../array-size-in-generic-struct-param.min.stderr | 2 +- .../array-size-in-generic-struct-param.rs | 2 +- ...trinsics-type_name-as-const-argument.min.stderr | 2 +- .../intrinsics-type_name-as-const-argument.rs | 2 +- src/test/ui/const-generics/invalid-enum.rs | 2 +- src/test/ui/const-generics/issues/issue-56445-1.rs | 2 +- .../const-generics/issues/issue-62878.min.stderr | 2 +- src/test/ui/const-generics/issues/issue-62878.rs | 2 +- .../issues/issue-63322-forbid-dyn.min.stderr | 2 +- .../issues/issue-63322-forbid-dyn.rs | 2 +- .../issue-66596-impl-trait-for-str-const-arg.rs | 2 +- .../issues/issue-68615-adt.min.stderr | 2 +- .../ui/const-generics/issues/issue-68615-adt.rs | 2 +- .../issues/issue-68615-array.min.stderr | 2 +- .../ui/const-generics/issues/issue-68615-array.rs | 2 +- .../const-generics/issues/issue-71169.min.stderr | 2 +- src/test/ui/const-generics/issues/issue-71169.rs | 2 +- src/test/ui/const-generics/issues/issue-71381.rs | 2 +- src/test/ui/const-generics/issues/issue-71382.rs | 2 +- src/test/ui/const-generics/issues/issue-71611.rs | 2 +- src/test/ui/const-generics/issues/issue-72352.rs | 2 +- .../const-generics/issues/issue-73491.min.stderr | 2 +- src/test/ui/const-generics/issues/issue-73491.rs | 2 +- .../const-generics/issues/issue-74101.min.stderr | 4 ++-- src/test/ui/const-generics/issues/issue-74101.rs | 2 +- .../const-generics/issues/issue-74255.min.stderr | 2 +- src/test/ui/const-generics/issues/issue-74255.rs | 2 +- .../const-generics/issues/issue-74950.min.stderr | 10 +++++----- src/test/ui/const-generics/issues/issue-74950.rs | 2 +- .../const-generics/issues/issue-75047.min.stderr | 2 +- src/test/ui/const-generics/issues/issue-75047.rs | 2 +- src/test/ui/const-generics/issues/issue-75763.rs | 4 ++-- src/test/ui/const-generics/issues/issue-87076.rs | 2 +- .../min_const_generics/complex-types.stderr | 14 +++++++------- .../static-reference-array-const-param.stderr | 2 +- src/test/ui/const-generics/nested-type.min.stderr | 2 +- src/test/ui/const-generics/nested-type.rs | 2 +- .../ui/const-generics/raw-ptr-const-param-deref.rs | 2 +- src/test/ui/const-generics/raw-ptr-const-param.rs | 2 +- .../slice-const-param-mismatch.min.stderr | 4 ++-- .../const-generics/slice-const-param-mismatch.rs | 2 +- src/test/ui/const-generics/slice-const-param.rs | 2 +- .../std/const-generics-range.min.stderr | 12 ++++++------ .../ui/const-generics/std/const-generics-range.rs | 2 +- ...ansmute-const-param-static-reference.min.stderr | 2 +- .../transmute-const-param-static-reference.rs | 2 +- .../transparent-maybeunit-array-wrapper.rs | 2 +- .../type-dependent/issue-71348.min.stderr | 4 ++-- .../const-generics/type-dependent/issue-71348.rs | 2 +- src/test/ui/error-codes/E0771.rs | 4 ++-- src/test/ui/error-codes/E0771.stderr | 6 +++--- ...m_types.rs => feature-gate-adt_const_params.rs} | 0 ...stderr => feature-gate-adt_const_params.stderr} | 4 ++-- .../symbol-names/const-generics-str-demangling.rs | 2 +- .../const-generics-structural-demangling.rs | 2 +- 77 files changed, 108 insertions(+), 108 deletions(-) rename src/test/ui/feature-gates/{feature-gate-const_param_types.rs => feature-gate-adt_const_params.rs} (100%) rename src/test/ui/feature-gates/{feature-gate-const_param_types.stderr => feature-gate-adt_const_params.stderr} (67%) diff --git a/compiler/rustc_error_codes/src/error_codes/E0741.md b/compiler/rustc_error_codes/src/error_codes/E0741.md index 510075dc779c..70d963cd41f2 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0741.md +++ b/compiler/rustc_error_codes/src/error_codes/E0741.md @@ -3,7 +3,7 @@ A non-structural-match type was used as the type of a const generic parameter. Erroneous code example: ```compile_fail,E0741 -#![feature(const_param_types)] +#![feature(adt_const_params)] struct A; @@ -16,7 +16,7 @@ may be used as the types of const generic parameters. To fix the previous code example, we derive `PartialEq` and `Eq`: ``` -#![feature(const_param_types)] +#![feature(adt_const_params)] #[derive(PartialEq, Eq)] // We derive both traits here. struct A; diff --git a/compiler/rustc_error_codes/src/error_codes/E0771.md b/compiler/rustc_error_codes/src/error_codes/E0771.md index c1e133673cad..a2a1a20f2303 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0771.md +++ b/compiler/rustc_error_codes/src/error_codes/E0771.md @@ -4,7 +4,7 @@ allowed. Erroneous code example: ```compile_fail,E0771 -#![feature(const_param_types)] +#![feature(adt_const_params)] fn function_with_str<'a, const STRING: &'a str>() {} // error! ``` @@ -13,7 +13,7 @@ To fix this issue, the lifetime in the const generic need to be changed to `'static`: ``` -#![feature(const_param_types)] +#![feature(adt_const_params)] fn function_with_str() {} // ok! ``` diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 79a1f4e0c5cf..1ff2c75966ab 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -71,7 +71,7 @@ macro_rules! declare_features { } pub fn unordered_const_ty_params(&self) -> bool { - self.const_generics_defaults || self.generic_const_exprs || self.const_param_types + self.const_generics_defaults || self.generic_const_exprs || self.adt_const_params } /// Some features are known to be incomplete and using them is likely to have @@ -674,7 +674,7 @@ declare_features! ( (incomplete, generic_const_exprs, "1.56.0", Some(76560), None), /// Allows additional const parameter types, such as `&'static str` or user defined types - (incomplete, const_param_types, "1.56.0", Some(44580), None), + (incomplete, adt_const_params, "1.56.0", Some(44580), None), // ------------------------------------------------------------------------- // feature-group-end: actual feature gates diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index dd17b8ab22b4..8e498a5446ea 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -104,7 +104,7 @@ declare_features! ( (removed, quote, "1.33.0", Some(29601), None, None), /// Allows const generic types (e.g. `struct Foo(...);`). (removed, const_generics, "1.34.0", Some(44580), None, - Some("removed in favor of `#![feature(const_param_types]` and `#![feature(generic_const_exprs)]`")), + Some("removed in favor of `#![feature(adt_const_params]` and `#![feature(generic_const_exprs)]`")), /// Allows `[x; N]` where `x` is a constant (RFC 2203). (removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None, Some("removed due to causing promotable bugs")), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9968cd62d95f..19c02ba45c44 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -284,6 +284,7 @@ symbols! { add_assign, add_with_overflow, address, + adt_const_params, advanced_slice_patterns, adx_target_feature, alias, @@ -451,7 +452,6 @@ symbols! { const_mut_refs, const_panic, const_panic_fmt, - const_param_types, const_precise_live_drops, const_ptr, const_raw_ptr_deref, diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 761ea6df2e1e..17716afe3208 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -290,7 +290,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { let err_ty_str; let mut is_ptr = true; - let err = if tcx.features().const_param_types { + let err = if tcx.features().adt_const_params { match ty.peel_refs().kind() { ty::FnPtr(_) => Some("function pointers"), ty::RawPtr(_) => Some("raw pointers"), @@ -328,7 +328,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { err.note("the only supported types are integers, `bool` and `char`"); if tcx.sess.is_nightly_build() { err.help( - "more complex types are supported with `#![feature(const_param_types)]`", + "more complex types are supported with `#![feature(adt_const_params)]`", ); } err.emit() diff --git a/src/test/debuginfo/function-names.rs b/src/test/debuginfo/function-names.rs index e962c18d8ec7..dec25bb4c203 100644 --- a/src/test/debuginfo/function-names.rs +++ b/src/test/debuginfo/function-names.rs @@ -82,7 +82,7 @@ #![allow(unused_variables)] #![feature(omit_gdb_pretty_printer_section)] #![omit_gdb_pretty_printer_section] -#![feature(const_param_types, generators, generator_trait)] +#![feature(adt_const_params, generators, generator_trait)] #![allow(incomplete_features)] use Mod1::TestTrait2; diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-1.rs b/src/test/incremental/const-generics/hash-tyvid-regression-1.rs index 7696bb7d331a..b5a0108a0a39 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-1.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-1.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(generic_const_exprs, const_param_types)] +#![feature(generic_const_exprs, adt_const_params)] #![allow(incomplete_features)] // regression test for #77650 fn c() diff --git a/src/test/incremental/const-generics/hash-tyvid-regression-2.rs b/src/test/incremental/const-generics/hash-tyvid-regression-2.rs index 71d504d26a75..bba22bf5dc16 100644 --- a/src/test/incremental/const-generics/hash-tyvid-regression-2.rs +++ b/src/test/incremental/const-generics/hash-tyvid-regression-2.rs @@ -1,5 +1,5 @@ // revisions: cfail -#![feature(generic_const_exprs, const_param_types, const_generics_defaults)] +#![feature(generic_const_exprs, adt_const_params, const_generics_defaults)] #![allow(incomplete_features)] // regression test for #77650 struct C([T; N.get()]) diff --git a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs index baca4562adef..fc114f224a2f 100644 --- a/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs +++ b/src/test/incremental/const-generics/try_unify_abstract_const_regression_tests/issue-77708-3.rs @@ -1,5 +1,5 @@ // revisions: rpass -#![feature(generic_const_exprs, const_param_types)] +#![feature(generic_const_exprs, adt_const_params)] #![allow(incomplete_features)] use std::{convert::TryFrom, num::NonZeroUsize}; diff --git a/src/test/rustdoc/const-generics/const-impl.rs b/src/test/rustdoc/const-generics/const-impl.rs index f0bc9bf7bdd7..fed37f6c9a2d 100644 --- a/src/test/rustdoc/const-generics/const-impl.rs +++ b/src/test/rustdoc/const-generics/const-impl.rs @@ -1,4 +1,4 @@ -#![feature(const_param_types)] +#![feature(adt_const_params)] #![crate_name = "foo"] diff --git a/src/test/ui/async-await/issues/issue-78654.rs b/src/test/ui/async-await/issues/issue-78654.rs index 24103390e090..cc6dc3834690 100644 --- a/src/test/ui/async-await/issues/issue-78654.rs +++ b/src/test/ui/async-await/issues/issue-78654.rs @@ -1,7 +1,7 @@ // edition:2018 // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Foo; diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr b/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr index 0f98adf2a6bc..48d85e7ff64e 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/src/test/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -35,7 +35,7 @@ LL | struct A; | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:14:15 @@ -44,7 +44,7 @@ LL | impl A { | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:17:21 @@ -53,7 +53,7 @@ LL | fn foo(&self) {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:22:15 @@ -62,7 +62,7 @@ LL | impl B for A {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:26:17 @@ -71,7 +71,7 @@ LL | fn bar() {} | ^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 10 previous errors diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.rs b/src/test/ui/const-generics/const-param-elided-lifetime.rs index 345e192f8db4..487b82dbf4ac 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.rs +++ b/src/test/ui/const-generics/const-param-elided-lifetime.rs @@ -3,7 +3,7 @@ // elided lifetimes within the type of a const generic parameters to be 'static, like elided // lifetimes within const/static items. // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct A; diff --git a/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr b/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr index db3a04b8235d..a7b78b80ca5e 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr @@ -17,7 +17,7 @@ LL | pub struct Dependent([(); N]); | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `[u8; _]` is forbidden as the type of a const generic parameter --> $DIR/const-param-type-depends-on-const-param.rs:15:35 @@ -26,7 +26,7 @@ LL | pub struct SelfDependent; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 4 previous errors diff --git a/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs index 07c86d2cf8ce..9d50f9a47ff6 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-const-param.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] // Currently, const parameters cannot depend on other generic parameters, diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs index 6eb4b3735ffe..71d91fd7e7f4 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] // Currently, const parameters cannot depend on other generic parameters, diff --git a/src/test/ui/const-generics/core-types.rs b/src/test/ui/const-generics/core-types.rs index 5e975c170431..91410c4afdf7 100644 --- a/src/test/ui/const-generics/core-types.rs +++ b/src/test/ui/const-generics/core-types.rs @@ -2,7 +2,7 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct A; diff --git a/src/test/ui/const-generics/different_generic_args_array.rs b/src/test/ui/const-generics/different_generic_args_array.rs index cfe3a0a075a9..4d225dfdd873 100644 --- a/src/test/ui/const-generics/different_generic_args_array.rs +++ b/src/test/ui/const-generics/different_generic_args_array.rs @@ -1,5 +1,5 @@ // Check that different const types are different. -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] struct Const {} diff --git a/src/test/ui/const-generics/fn-const-param-call.rs b/src/test/ui/const-generics/fn-const-param-call.rs index 5cd18f6d3598..dc516fb71c4b 100644 --- a/src/test/ui/const-generics/fn-const-param-call.rs +++ b/src/test/ui/const-generics/fn-const-param-call.rs @@ -1,7 +1,7 @@ // Check that functions cannot be used as const parameters. // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] fn function() -> u32 { diff --git a/src/test/ui/const-generics/fn-const-param-infer.rs b/src/test/ui/const-generics/fn-const-param-infer.rs index 596101596952..22f5f529c76a 100644 --- a/src/test/ui/const-generics/fn-const-param-infer.rs +++ b/src/test/ui/const-generics/fn-const-param-infer.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Checked bool>; diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.rs b/src/test/ui/const-generics/forbid-non-structural_match-types.rs index 7884008b858b..6ae9d5cfbb54 100644 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.rs +++ b/src/test/ui/const-generics/forbid-non-structural_match-types.rs @@ -1,4 +1,4 @@ -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr index 22e7ab1f7b12..18e9135d0723 100644 --- a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.min.stderr @@ -23,7 +23,7 @@ LL | struct B { | ^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 3 previous errors diff --git a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs index 68201b77dbf1..7d3fe413c170 100644 --- a/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs +++ b/src/test/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.rs @@ -1,7 +1,7 @@ // Tests that array sizes that depend on const-params are checked using `ConstEvaluatable`. // revisions: full min -#![cfg_attr(full, feature(generic_const_exprs, const_param_types))] +#![cfg_attr(full, feature(generic_const_exprs, adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] #[allow(dead_code)] diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index 604b4e8bddbf..b8a1027c9ebd 100644 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -14,7 +14,7 @@ LL | trait Trait {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs index eedc619e8054..147a00cb26bf 100644 --- a/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs +++ b/src/test/ui/const-generics/intrinsics-type_name-as-const-argument.rs @@ -2,7 +2,7 @@ // revisions: full min #![cfg_attr(full, allow(incomplete_features))] -#![cfg_attr(full, feature(const_param_types, generic_const_exprs))] +#![cfg_attr(full, feature(adt_const_params, generic_const_exprs))] #![feature(core_intrinsics)] #![feature(const_type_name)] diff --git a/src/test/ui/const-generics/invalid-enum.rs b/src/test/ui/const-generics/invalid-enum.rs index 65741d07d907..bc3c09238f25 100644 --- a/src/test/ui/const-generics/invalid-enum.rs +++ b/src/test/ui/const-generics/invalid-enum.rs @@ -1,4 +1,4 @@ -#![feature(const_param_types, const_generics_defaults)] +#![feature(adt_const_params, const_generics_defaults)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/issues/issue-56445-1.rs b/src/test/ui/const-generics/issues/issue-56445-1.rs index 7cd8e13c8f5f..aeef778991f0 100644 --- a/src/test/ui/const-generics/issues/issue-56445-1.rs +++ b/src/test/ui/const-generics/issues/issue-56445-1.rs @@ -1,6 +1,6 @@ // Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995. // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] #![crate_type = "lib"] diff --git a/src/test/ui/const-generics/issues/issue-62878.min.stderr b/src/test/ui/const-generics/issues/issue-62878.min.stderr index af3bd4124335..af029a6516bc 100644 --- a/src/test/ui/const-generics/issues/issue-62878.min.stderr +++ b/src/test/ui/const-generics/issues/issue-62878.min.stderr @@ -11,7 +11,7 @@ LL | fn foo() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-62878.rs b/src/test/ui/const-generics/issues/issue-62878.rs index 8eaa31249aa9..38f5ff77b56a 100644 --- a/src/test/ui/const-generics/issues/issue-62878.rs +++ b/src/test/ui/const-generics/issues/issue-62878.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types, generic_arg_infer))] +#![cfg_attr(full, feature(adt_const_params, generic_arg_infer))] #![cfg_attr(full, allow(incomplete_features))] fn foo() {} diff --git a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr index dcb4c703895b..b1141cf3bdfb 100644 --- a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr +++ b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr @@ -5,7 +5,7 @@ LL | fn test() { | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/issue-63322-forbid-dyn.rs:9:18 diff --git a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs index 076a16821e54..01a6caa130f3 100644 --- a/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs +++ b/src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] trait A {} diff --git a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs b/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs index a506fceb4eff..091419f0c52e 100644 --- a/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs +++ b/src/test/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs @@ -1,5 +1,5 @@ // check-pass -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] diff --git a/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr b/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr index 040f65a8edaf..df04c4896b45 100644 --- a/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68615-adt.min.stderr @@ -5,7 +5,7 @@ LL | struct Const {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-68615-adt.rs b/src/test/ui/const-generics/issues/issue-68615-adt.rs index 5d0f9ae0b1dc..3ef1ad45edfd 100644 --- a/src/test/ui/const-generics/issues/issue-68615-adt.rs +++ b/src/test/ui/const-generics/issues/issue-68615-adt.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Const {} diff --git a/src/test/ui/const-generics/issues/issue-68615-array.min.stderr b/src/test/ui/const-generics/issues/issue-68615-array.min.stderr index 3f4153f3f351..1b4517087e22 100644 --- a/src/test/ui/const-generics/issues/issue-68615-array.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68615-array.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-68615-array.rs b/src/test/ui/const-generics/issues/issue-68615-array.rs index 4dbc56b4bd2b..93477be41b59 100644 --- a/src/test/ui/const-generics/issues/issue-68615-array.rs +++ b/src/test/ui/const-generics/issues/issue-68615-array.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Foo {} diff --git a/src/test/ui/const-generics/issues/issue-71169.min.stderr b/src/test/ui/const-generics/issues/issue-71169.min.stderr index ed360c96f289..87ed2d4f8da8 100644 --- a/src/test/ui/const-generics/issues/issue-71169.min.stderr +++ b/src/test/ui/const-generics/issues/issue-71169.min.stderr @@ -11,7 +11,7 @@ LL | fn foo() {} | ^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-71169.rs b/src/test/ui/const-generics/issues/issue-71169.rs index f949bc979ba6..617149a84189 100644 --- a/src/test/ui/const-generics/issues/issue-71169.rs +++ b/src/test/ui/const-generics/issues/issue-71169.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] fn foo() {} diff --git a/src/test/ui/const-generics/issues/issue-71381.rs b/src/test/ui/const-generics/issues/issue-71381.rs index b24bc241d42c..66f819dbe06e 100644 --- a/src/test/ui/const-generics/issues/issue-71381.rs +++ b/src/test/ui/const-generics/issues/issue-71381.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Test(*const usize); diff --git a/src/test/ui/const-generics/issues/issue-71382.rs b/src/test/ui/const-generics/issues/issue-71382.rs index 5663012dc637..4392d72e5668 100644 --- a/src/test/ui/const-generics/issues/issue-71382.rs +++ b/src/test/ui/const-generics/issues/issue-71382.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Test(); diff --git a/src/test/ui/const-generics/issues/issue-71611.rs b/src/test/ui/const-generics/issues/issue-71611.rs index c82916e85a28..fbb91ca18aa4 100644 --- a/src/test/ui/const-generics/issues/issue-71611.rs +++ b/src/test/ui/const-generics/issues/issue-71611.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] fn func(outer: A) { diff --git a/src/test/ui/const-generics/issues/issue-72352.rs b/src/test/ui/const-generics/issues/issue-72352.rs index 8e292356f7e2..2fa1d7a53378 100644 --- a/src/test/ui/const-generics/issues/issue-72352.rs +++ b/src/test/ui/const-generics/issues/issue-72352.rs @@ -1,5 +1,5 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] use std::ffi::{CStr, CString}; diff --git a/src/test/ui/const-generics/issues/issue-73491.min.stderr b/src/test/ui/const-generics/issues/issue-73491.min.stderr index 2b470f5eaecd..f2b58e59f731 100644 --- a/src/test/ui/const-generics/issues/issue-73491.min.stderr +++ b/src/test/ui/const-generics/issues/issue-73491.min.stderr @@ -5,7 +5,7 @@ LL | fn hoge() {} | ^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-73491.rs b/src/test/ui/const-generics/issues/issue-73491.rs index 2108661ab251..f15c1f2d4552 100644 --- a/src/test/ui/const-generics/issues/issue-73491.rs +++ b/src/test/ui/const-generics/issues/issue-73491.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] const LEN: usize = 1024; diff --git a/src/test/ui/const-generics/issues/issue-74101.min.stderr b/src/test/ui/const-generics/issues/issue-74101.min.stderr index b8fe9736ba5b..82ffb2332404 100644 --- a/src/test/ui/const-generics/issues/issue-74101.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74101.min.stderr @@ -5,7 +5,7 @@ LL | fn test() {} | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `[u8; _]` is forbidden as the type of a const generic parameter --> $DIR/issue-74101.rs:9:21 @@ -14,7 +14,7 @@ LL | struct Foo; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-74101.rs b/src/test/ui/const-generics/issues/issue-74101.rs index f976912e11cf..6b606b9460fe 100644 --- a/src/test/ui/const-generics/issues/issue-74101.rs +++ b/src/test/ui/const-generics/issues/issue-74101.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] fn test() {} diff --git a/src/test/ui/const-generics/issues/issue-74255.min.stderr b/src/test/ui/const-generics/issues/issue-74255.min.stderr index 9099b61e63bd..b462d84487ee 100644 --- a/src/test/ui/const-generics/issues/issue-74255.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74255.min.stderr @@ -5,7 +5,7 @@ LL | fn ice_struct_fn() {} | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-74255.rs b/src/test/ui/const-generics/issues/issue-74255.rs index cfb2b703ddce..0e523926fb0b 100644 --- a/src/test/ui/const-generics/issues/issue-74255.rs +++ b/src/test/ui/const-generics/issues/issue-74255.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/issues/issue-74950.min.stderr b/src/test/ui/const-generics/issues/issue-74950.min.stderr index eaf02e1bd471..729ecc2022c9 100644 --- a/src/test/ui/const-generics/issues/issue-74950.min.stderr +++ b/src/test/ui/const-generics/issues/issue-74950.min.stderr @@ -5,7 +5,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -14,7 +14,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -23,7 +23,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -32,7 +32,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `Inner` is forbidden as the type of a const generic parameter --> $DIR/issue-74950.rs:17:23 @@ -41,7 +41,7 @@ LL | struct Outer; | ^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 5 previous errors diff --git a/src/test/ui/const-generics/issues/issue-74950.rs b/src/test/ui/const-generics/issues/issue-74950.rs index 941335518a8b..3e1ca4735db6 100644 --- a/src/test/ui/const-generics/issues/issue-74950.rs +++ b/src/test/ui/const-generics/issues/issue-74950.rs @@ -1,6 +1,6 @@ // [full] build-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] diff --git a/src/test/ui/const-generics/issues/issue-75047.min.stderr b/src/test/ui/const-generics/issues/issue-75047.min.stderr index 7a8c817c0d6a..7798ae796298 100644 --- a/src/test/ui/const-generics/issues/issue-75047.min.stderr +++ b/src/test/ui/const-generics/issues/issue-75047.min.stderr @@ -5,7 +5,7 @@ LL | struct Foo::value()]>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/issues/issue-75047.rs b/src/test/ui/const-generics/issues/issue-75047.rs index e8be1e300516..ee3dcf9ecec5 100644 --- a/src/test/ui/const-generics/issues/issue-75047.rs +++ b/src/test/ui/const-generics/issues/issue-75047.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Bar(T); diff --git a/src/test/ui/const-generics/issues/issue-75763.rs b/src/test/ui/const-generics/issues/issue-75763.rs index 400c034a9276..214a04b8a6be 100644 --- a/src/test/ui/const-generics/issues/issue-75763.rs +++ b/src/test/ui/const-generics/issues/issue-75763.rs @@ -1,6 +1,6 @@ // ignore-test // FIXME(const_generics): This test causes an ICE after reverting #76030. -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] @@ -9,7 +9,7 @@ struct Bug; fn main() { let b: Bug::<{ unsafe { - // FIXME(const_param_types): Decide on how to deal with invalid values as const params. + // FIXME(adt_const_params): Decide on how to deal with invalid values as const params. std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) } }>; diff --git a/src/test/ui/const-generics/issues/issue-87076.rs b/src/test/ui/const-generics/issues/issue-87076.rs index 05ba266d2d87..8a567678b824 100644 --- a/src/test/ui/const-generics/issues/issue-87076.rs +++ b/src/test/ui/const-generics/issues/issue-87076.rs @@ -1,6 +1,6 @@ // build-pass -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] #[derive(PartialEq, Eq)] diff --git a/src/test/ui/const-generics/min_const_generics/complex-types.stderr b/src/test/ui/const-generics/min_const_generics/complex-types.stderr index 12ffbd53ab0a..4ddbadb54661 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-types.stderr +++ b/src/test/ui/const-generics/min_const_generics/complex-types.stderr @@ -5,7 +5,7 @@ LL | struct Foo; | ^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:6:21 @@ -14,7 +14,7 @@ LL | struct Bar; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `No` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:11:21 @@ -23,7 +23,7 @@ LL | struct Fez; | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static u8` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:14:21 @@ -32,7 +32,7 @@ LL | struct Faz; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `!` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:17:21 @@ -41,7 +41,7 @@ LL | struct Fiz; | ^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:20:19 @@ -50,7 +50,7 @@ LL | enum Goo { A, B } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `()` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:23:20 @@ -59,7 +59,7 @@ LL | union Boo { a: () } | ^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 7 previous errors diff --git a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr index 13e1a232b3aa..f30693221a51 100644 --- a/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr +++ b/src/test/ui/const-generics/min_const_generics/static-reference-array-const-param.stderr @@ -5,7 +5,7 @@ LL | fn a() {} | ^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/nested-type.min.stderr b/src/test/ui/const-generics/nested-type.min.stderr index c435344580a7..4f32284ecb1e 100644 --- a/src/test/ui/const-generics/nested-type.min.stderr +++ b/src/test/ui/const-generics/nested-type.min.stderr @@ -12,7 +12,7 @@ LL | | }]>; | |__^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants --> $DIR/nested-type.rs:15:5 diff --git a/src/test/ui/const-generics/nested-type.rs b/src/test/ui/const-generics/nested-type.rs index b3d62d64f3b4..039f996de96d 100644 --- a/src/test/ui/const-generics/nested-type.rs +++ b/src/test/ui/const-generics/nested-type.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Foo; //~ ERROR: using raw pointers as const generic parameters diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr b/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr index 0a4581afc29f..fed802f6adc6 100644 --- a/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr +++ b/src/test/ui/const-generics/slice-const-param-mismatch.min.stderr @@ -5,7 +5,7 @@ LL | struct ConstString; | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static [u8]` is forbidden as the type of a const generic parameter --> $DIR/slice-const-param-mismatch.rs:9:28 @@ -14,7 +14,7 @@ LL | struct ConstBytes; | ^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.rs b/src/test/ui/const-generics/slice-const-param-mismatch.rs index 7f740005e04e..7127323e5bab 100644 --- a/src/test/ui/const-generics/slice-const-param-mismatch.rs +++ b/src/test/ui/const-generics/slice-const-param-mismatch.rs @@ -1,6 +1,6 @@ // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] diff --git a/src/test/ui/const-generics/slice-const-param.rs b/src/test/ui/const-generics/slice-const-param.rs index 3a7eb4646309..05d21e08d745 100644 --- a/src/test/ui/const-generics/slice-const-param.rs +++ b/src/test/ui/const-generics/slice-const-param.rs @@ -1,6 +1,6 @@ // run-pass -#![feature(const_param_types)] +#![feature(adt_const_params)] #![allow(incomplete_features)] pub fn function_with_str() -> &'static str { diff --git a/src/test/ui/const-generics/std/const-generics-range.min.stderr b/src/test/ui/const-generics/std/const-generics-range.min.stderr index 1af866694ab3..d4b2ad6fd0c7 100644 --- a/src/test/ui/const-generics/std/const-generics-range.min.stderr +++ b/src/test/ui/const-generics/std/const-generics-range.min.stderr @@ -5,7 +5,7 @@ LL | struct _Range>; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `RangeFrom` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:12:28 @@ -14,7 +14,7 @@ LL | struct _RangeFrom>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `RangeFull` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:17:28 @@ -23,7 +23,7 @@ LL | struct _RangeFull; | ^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `RangeInclusive` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:23:33 @@ -32,7 +32,7 @@ LL | struct _RangeInclusive>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `RangeTo` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:28:26 @@ -41,7 +41,7 @@ LL | struct _RangeTo>; | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `RangeToInclusive` is forbidden as the type of a const generic parameter --> $DIR/const-generics-range.rs:33:35 @@ -50,7 +50,7 @@ LL | struct _RangeToInclusive>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 6 previous errors diff --git a/src/test/ui/const-generics/std/const-generics-range.rs b/src/test/ui/const-generics/std/const-generics-range.rs index 21e0bb48cd87..46c06f312b98 100644 --- a/src/test/ui/const-generics/std/const-generics-range.rs +++ b/src/test/ui/const-generics/std/const-generics-range.rs @@ -1,6 +1,6 @@ // [full] check-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] // `Range` should be usable within const generics: diff --git a/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr b/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr index 14af8d77a5f9..039c4276c8b7 100644 --- a/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr +++ b/src/test/ui/const-generics/transmute-const-param-static-reference.min.stderr @@ -5,7 +5,7 @@ LL | struct Const; | ^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/const-generics/transmute-const-param-static-reference.rs b/src/test/ui/const-generics/transmute-const-param-static-reference.rs index 1a63bec7b6f0..6b443c8bd907 100644 --- a/src/test/ui/const-generics/transmute-const-param-static-reference.rs +++ b/src/test/ui/const-generics/transmute-const-param-static-reference.rs @@ -1,7 +1,7 @@ // revisions: full min //[full] check-pass -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Const; diff --git a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs index 8c990577f3dc..926e807feb0b 100644 --- a/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs +++ b/src/test/ui/const-generics/transparent-maybeunit-array-wrapper.rs @@ -1,7 +1,7 @@ // run-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] use std::mem::MaybeUninit; diff --git a/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr b/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr index d845bc610cfa..b8fbb3979799 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/src/test/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -5,7 +5,7 @@ LL | trait Get<'a, const N: &'static str> { | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:18:25 @@ -14,7 +14,7 @@ LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a >::Ta | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/type-dependent/issue-71348.rs b/src/test/ui/const-generics/type-dependent/issue-71348.rs index 638e7a88d678..2ef2f066a6f6 100644 --- a/src/test/ui/const-generics/type-dependent/issue-71348.rs +++ b/src/test/ui/const-generics/type-dependent/issue-71348.rs @@ -1,6 +1,6 @@ // [full] run-pass // revisions: full min -#![cfg_attr(full, feature(const_param_types))] +#![cfg_attr(full, feature(adt_const_params))] #![cfg_attr(full, allow(incomplete_features))] struct Foo { diff --git a/src/test/ui/error-codes/E0771.rs b/src/test/ui/error-codes/E0771.rs index 75c9fa6c98d1..67e7d106a1fc 100644 --- a/src/test/ui/error-codes/E0771.rs +++ b/src/test/ui/error-codes/E0771.rs @@ -1,5 +1,5 @@ -#![feature(const_param_types)] -//~^ WARN the feature `const_param_types` is incomplete +#![feature(adt_const_params)] +//~^ WARN the feature `adt_const_params` is incomplete fn function_with_str<'a, const STRING: &'a str>() {} //~ ERROR E0771 diff --git a/src/test/ui/error-codes/E0771.stderr b/src/test/ui/error-codes/E0771.stderr index 9860df3352ad..730a7ef1284b 100644 --- a/src/test/ui/error-codes/E0771.stderr +++ b/src/test/ui/error-codes/E0771.stderr @@ -1,8 +1,8 @@ -warning: the feature `const_param_types` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/E0771.rs:1:12 | -LL | #![feature(const_param_types)] - | ^^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params)] + | ^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #44580 for more information diff --git a/src/test/ui/feature-gates/feature-gate-const_param_types.rs b/src/test/ui/feature-gates/feature-gate-adt_const_params.rs similarity index 100% rename from src/test/ui/feature-gates/feature-gate-const_param_types.rs rename to src/test/ui/feature-gates/feature-gate-adt_const_params.rs diff --git a/src/test/ui/feature-gates/feature-gate-const_param_types.stderr b/src/test/ui/feature-gates/feature-gate-adt_const_params.stderr similarity index 67% rename from src/test/ui/feature-gates/feature-gate-const_param_types.stderr rename to src/test/ui/feature-gates/feature-gate-adt_const_params.stderr index 5452186a3aeb..d8f089a28b7e 100644 --- a/src/test/ui/feature-gates/feature-gate-const_param_types.stderr +++ b/src/test/ui/feature-gates/feature-gate-adt_const_params.stderr @@ -1,11 +1,11 @@ error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/feature-gate-const_param_types.rs:1:24 + --> $DIR/feature-gate-adt_const_params.rs:1:24 | LL | struct Foo; | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` - = help: more complex types are supported with `#![feature(const_param_types)]` + = help: more complex types are supported with `#![feature(adt_const_params)]` error: aborting due to previous error diff --git a/src/test/ui/symbol-names/const-generics-str-demangling.rs b/src/test/ui/symbol-names/const-generics-str-demangling.rs index 906350f51036..f450dfef575b 100644 --- a/src/test/ui/symbol-names/const-generics-str-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-str-demangling.rs @@ -1,6 +1,6 @@ // build-fail // compile-flags: -Z symbol-mangling-version=v0 --crate-name=c -#![feature(const_param_types, rustc_attrs)] +#![feature(adt_const_params, rustc_attrs)] #![allow(incomplete_features)] pub struct Str; diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.rs b/src/test/ui/symbol-names/const-generics-structural-demangling.rs index ec677e46b55d..fa3884860c33 100644 --- a/src/test/ui/symbol-names/const-generics-structural-demangling.rs +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.rs @@ -6,7 +6,7 @@ // normalize-stderr-test: "Cs[0-9a-zA-Z]+_4core" -> "Cs$$HASH_4core" // normalize-stderr-test: "core\[[0-9a-f]+\]" -> "core[$$HASH_HEX]" -#![feature(const_param_types, decl_macro, rustc_attrs)] +#![feature(adt_const_params, decl_macro, rustc_attrs)] #![allow(incomplete_features)] pub struct RefByte; From 1a2fe87b09d377fa469b2848ab173a91360c9163 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 30 Aug 2021 13:09:38 +0200 Subject: [PATCH 252/269] Remove unused arena macro args --- compiler/rustc_arena/src/lib.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_hir/src/arena.rs | 4 ++-- compiler/rustc_middle/src/arena.rs | 6 +++--- compiler/rustc_middle/src/ty/codec.rs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index 2e8022d9880b..6d5f47aceeb9 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -635,7 +635,7 @@ pub macro which_arena_for_type { } #[rustc_macro_transparency = "semitransparent"] -pub macro declare_arena([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) { +pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) { #[derive(Default)] pub struct Arena<$tcx> { pub dropless: $crate::DroplessArena, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index b71fcb7a349c..0133acfee100 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -84,7 +84,7 @@ mod path; const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; -rustc_hir::arena_types!(rustc_arena::declare_arena, [], 'tcx); +rustc_hir::arena_types!(rustc_arena::declare_arena, 'tcx); struct LoweringContext<'a, 'hir: 'a> { /// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes. diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index 0801a1bde226..3e8b98e9f549 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -9,8 +9,8 @@ /// where `T` is the type listed. These impls will appear in the implement_ty_decoder! macro. #[macro_export] macro_rules! arena_types { - ($macro:path, $args:tt, $tcx:lifetime) => ( - $macro!($args, [ + ($macro:path, $tcx:lifetime) => ( + $macro!([ // HIR types [few] hir_krate: rustc_hir::Crate<$tcx>, [] arm: rustc_hir::Arm<$tcx>, diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index a89d00e26ac1..59db2c6636ff 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -9,8 +9,8 @@ /// listed. These impls will appear in the implement_ty_decoder! macro. #[macro_export] macro_rules! arena_types { - ($macro:path, $args:tt, $tcx:lifetime) => ( - $macro!($args, [ + ($macro:path, $tcx:lifetime) => ( + $macro!([ [] layouts: rustc_target::abi::Layout, // AdtDef are interned and compared by address [] adt_def: rustc_middle::ty::AdtDef, @@ -109,4 +109,4 @@ macro_rules! arena_types { ) } -arena_types!(rustc_arena::declare_arena, [], 'tcx); +arena_types!(rustc_arena::declare_arena, 'tcx); diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 36db258e92d2..4edb6a327b03 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -437,15 +437,15 @@ macro_rules! impl_arena_allocatable_decoder { } macro_rules! impl_arena_allocatable_decoders { - ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { + ([$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { $( impl_arena_allocatable_decoder!($a [[$name: $ty], $tcx]); )* } } -rustc_hir::arena_types!(impl_arena_allocatable_decoders, [], 'tcx); -arena_types!(impl_arena_allocatable_decoders, [], 'tcx); +rustc_hir::arena_types!(impl_arena_allocatable_decoders, 'tcx); +arena_types!(impl_arena_allocatable_decoders, 'tcx); #[macro_export] macro_rules! implement_ty_decoder { From 388d90ac4cb3f646934e5fa77a1a3182a54e9846 Mon Sep 17 00:00:00 2001 From: HTG-YT Date: Tue, 17 Aug 2021 09:42:23 +0800 Subject: [PATCH 253/269] make edition 2021 stable --- compiler/rustc_span/src/edition.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/edition.rs b/compiler/rustc_span/src/edition.rs index 8544acd6d05e..485d7cb0d674 100644 --- a/compiler/rustc_span/src/edition.rs +++ b/compiler/rustc_span/src/edition.rs @@ -66,7 +66,7 @@ impl Edition { match *self { Edition::Edition2015 => true, Edition::Edition2018 => true, - Edition::Edition2021 => false, + Edition::Edition2021 => true, } } } From 4bed11a109dbecc167298f163543ecfcd2abab63 Mon Sep 17 00:00:00 2001 From: HTG-YT Date: Wed, 18 Aug 2021 09:05:48 +0800 Subject: [PATCH 254/269] update rustc cmdargs markdown section --- src/doc/rustc/src/command-line-arguments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 7d3cad7988c8..7f482f0f2b1a 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -93,7 +93,7 @@ This informs `rustc` of the name of your crate. ## `--edition`: specify the edition to use -This flag takes a value of `2015` or `2018`. The default is `2015`. More +This flag takes a value of `2015`, `2018` or `2021`. The default is `2015`. More information about editions may be found in the [edition guide]. [edition guide]: ../edition-guide/introduction.html From 6adbbb6be744a4af51b981826a11ada75b9666a7 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 15:33:09 +0200 Subject: [PATCH 255/269] Update LATEST_STABLE_EDITION to 2021. --- compiler/rustc_span/src/edition.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/edition.rs b/compiler/rustc_span/src/edition.rs index 485d7cb0d674..511c2e866269 100644 --- a/compiler/rustc_span/src/edition.rs +++ b/compiler/rustc_span/src/edition.rs @@ -32,7 +32,7 @@ pub const EDITION_NAME_LIST: &str = "2015|2018|2021"; pub const DEFAULT_EDITION: Edition = Edition::Edition2015; -pub const LATEST_STABLE_EDITION: Edition = Edition::Edition2018; +pub const LATEST_STABLE_EDITION: Edition = Edition::Edition2021; impl fmt::Display for Edition { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { From 3e61c53917e144b10fdc6ea45aabe64cb393fc29 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 Aug 2021 11:12:39 -0400 Subject: [PATCH 256/269] update miri --- src/tools/miri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri b/src/tools/miri index 042cbf175bfd..09cadcbb62a3 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 042cbf175bfdad6524fd00d7570b2297a0426063 +Subproject commit 09cadcbb62a3529801d0463d9878db3f0b5060c7 From 403b80d32e4536088e482f8e36e0d2132a6f031a Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 30 Aug 2021 17:23:08 +0200 Subject: [PATCH 257/269] Use MaybeUninit::write in functor.rs MaybeUninit::write is stable as of 1.55.0. --- compiler/rustc_data_structures/src/functor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_data_structures/src/functor.rs b/compiler/rustc_data_structures/src/functor.rs index fe7a256d2100..5b83ae312476 100644 --- a/compiler/rustc_data_structures/src/functor.rs +++ b/compiler/rustc_data_structures/src/functor.rs @@ -26,7 +26,7 @@ impl IdFunctor for Box { // inverse of `Box::assume_init()` and should be safe. let mut raw: Box> = Box::from_raw(raw.cast()); // SAFETY: Write the mapped value back into the `Box`. - ptr::write(raw.as_mut_ptr(), f(value)); + raw.write(f(value)); // SAFETY: We just initialized `raw`. raw.assume_init() } From a4f6d3e5c27e09f9fab591c19391b53a4175b666 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:01:34 +0200 Subject: [PATCH 258/269] Fix lifetime generics in >::try_from suggestion. --- .../src/check/method/prelude2021.rs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b5bc9d3599ac..0ab64170e4c2 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -239,16 +239,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let trait_path = self.trait_path_or_bare_name(span, expr_id, pick.item.container.id()); let trait_generics = self.tcx.generics_of(pick.item.container.id()); - let parameter_count = trait_generics.count() - (trait_generics.has_self as usize); - let trait_name = if parameter_count == 0 { - trait_path - } else { - format!( - "{}<{}>", - trait_path, - std::iter::repeat("_").take(parameter_count).collect::>().join(", ") - ) - }; + let trait_name = + if trait_generics.params.len() <= trait_generics.has_self as usize { + trait_path + } else { + let counts = trait_generics.own_counts(); + format!( + "{}<{}>", + trait_path, + std::iter::repeat("'_") + .take(counts.lifetimes) + .chain(std::iter::repeat("_").take( + counts.types + counts.consts - trait_generics.has_self as usize + )) + .collect::>() + .join(", ") + ) + }; let mut lint = lint.build(&format!( "trait-associated function `{}` will become ambiguous in Rust 2021", From e2abf0689035a6ace7bdb2801ee1e53cb3ee2c75 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:01:34 +0200 Subject: [PATCH 259/269] Fix lifetime generics in as Trait>::try_from suggestion. --- .../src/check/method/prelude2021.rs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index 0ab64170e4c2..69dada98dc3b 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -262,31 +262,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { method_name.name )); - let self_ty_name = self + let mut self_ty_name = self .sess() .source_map() .span_to_snippet(self_ty_span) .unwrap_or_else(|_| self_ty.to_string()); - let self_ty_generics_count = match self_ty.kind() { - // Get the number of generics the self type has (if an Adt) unless we can determine that - // the user has written the self type with generics already which we (naively) do by looking - // for a "<" in `self_ty_name`. - Adt(def, _) if !self_ty_name.contains('<') => self.tcx.generics_of(def.did).count(), - _ => 0, - }; - let self_ty_generics = if self_ty_generics_count > 0 { - format!("<{}>", vec!["_"; self_ty_generics_count].join(", ")) - } else { - String::new() - }; + // Get the number of generics the self type has (if an Adt) unless we can determine that + // the user has written the self type with generics already which we (naively) do by looking + // for a "<" in `self_ty_name`. + if !self_ty_name.contains('<') { + if let Adt(def, _) = self_ty.kind() { + let generics = self.tcx.generics_of(def.did); + if !generics.params.is_empty() { + let counts = generics.own_counts(); + self_ty_name += &format!( + "<{}>", + std::iter::repeat("'_") + .take(counts.lifetimes) + .chain(std::iter::repeat("_").take(counts.types + counts.consts)) + .collect::>() + .join(", ") + ); + } + } + } lint.span_suggestion( span, "disambiguate the associated function", - format!( - "<{}{} as {}>::{}", - self_ty_name, self_ty_generics, trait_name, method_name.name, - ), + format!("<{} as {}>::{}", self_ty_name, trait_name, method_name.name,), Applicability::MachineApplicable, ); From 78a7d1c652149c08cc60d3a91dabb66f41807d28 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:02:29 +0200 Subject: [PATCH 260/269] Add and update tests. --- ...ture-prelude-collision-generic-trait.fixed | 30 +++++++++++++++++++ .../future-prelude-collision-generic-trait.rs | 30 +++++++++++++++++++ ...ure-prelude-collision-generic-trait.stderr | 16 ++++++++++ .../future-prelude-collision-generic.fixed | 16 +++++----- .../future-prelude-collision-generic.rs | 14 ++++----- .../future-prelude-collision-generic.stderr | 10 +++---- 6 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed create mode 100644 src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs create mode 100644 src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed new file mode 100644 index 000000000000..a1b6f5b16baf --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed @@ -0,0 +1,30 @@ +// See https://github.com/rust-lang/rust/issues/88470 +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(dead_code)] +#![allow(unused_imports)] + +pub trait PyTryFrom<'v, T>: Sized { + fn try_from(value: V) -> Result<&'v Self, T>; +} + +pub trait PyTryInto: Sized { + fn try_into(&self) -> Result<&T, i32>; +} + +struct Foo; + +impl PyTryInto for Foo +where + U: for<'v> PyTryFrom<'v, i32>, +{ + fn try_into(&self) -> Result<&U, i32> { + >::try_from(self) + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| this is accepted in the current edition (Rust 2018) + } +} + +fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs new file mode 100644 index 000000000000..142ba552002f --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs @@ -0,0 +1,30 @@ +// See https://github.com/rust-lang/rust/issues/88470 +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(dead_code)] +#![allow(unused_imports)] + +pub trait PyTryFrom<'v, T>: Sized { + fn try_from(value: V) -> Result<&'v Self, T>; +} + +pub trait PyTryInto: Sized { + fn try_into(&self) -> Result<&T, i32>; +} + +struct Foo; + +impl PyTryInto for Foo +where + U: for<'v> PyTryFrom<'v, i32>, +{ + fn try_into(&self) -> Result<&U, i32> { + U::try_from(self) + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| this is accepted in the current edition (Rust 2018) + } +} + +fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr new file mode 100644 index 000000000000..14ad9b017b69 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr @@ -0,0 +1,16 @@ +warning: trait-associated function `try_from` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-generic-trait.rs:24:9 + | +LL | U::try_from(self) + | ^^^^^^^^^^^ help: disambiguate the associated function: `>::try_from` + | +note: the lint level is defined here + --> $DIR/future-prelude-collision-generic-trait.rs:5:9 + | +LL | #![warn(rust_2021_prelude_collisions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: 1 warning emitted + diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.fixed b/src/test/ui/rust-2021/future-prelude-collision-generic.fixed index f0d8cb944cf8..1bb9ba377740 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.fixed +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.fixed @@ -6,32 +6,32 @@ #![allow(dead_code)] #![allow(unused_imports)] -struct Generic(T, U); +struct Generic<'a, U>(&'a U); trait MyFromIter { fn from_iter(_: i32) -> Self; } -impl MyFromIter for Generic { - fn from_iter(x: i32) -> Self { - Self(x, x) +impl MyFromIter for Generic<'static, i32> { + fn from_iter(_: i32) -> Self { + todo!() } } -impl std::iter::FromIterator for Generic { +impl std::iter::FromIterator for Generic<'static, i32> { fn from_iter>(_: T) -> Self { todo!() } } fn main() { - as MyFromIter>::from_iter(1); + as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - as MyFromIter>::from_iter(1); + as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - as MyFromIter>::from_iter(1); + as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) } diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.rs b/src/test/ui/rust-2021/future-prelude-collision-generic.rs index 198405370598..d7f8affc61ad 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.rs +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.rs @@ -6,19 +6,19 @@ #![allow(dead_code)] #![allow(unused_imports)] -struct Generic(T, U); +struct Generic<'a, U>(&'a U); trait MyFromIter { fn from_iter(_: i32) -> Self; } -impl MyFromIter for Generic { - fn from_iter(x: i32) -> Self { - Self(x, x) +impl MyFromIter for Generic<'static, i32> { + fn from_iter(_: i32) -> Self { + todo!() } } -impl std::iter::FromIterator for Generic { +impl std::iter::FromIterator for Generic<'static, i32> { fn from_iter>(_: T) -> Self { todo!() } @@ -28,10 +28,10 @@ fn main() { Generic::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - Generic::::from_iter(1); + Generic::<'static, i32>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - Generic::<_, _>::from_iter(1); + Generic::<'_, _>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) } diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr index 0a722baa185c..e1d3f3c0a462 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr @@ -2,7 +2,7 @@ warning: trait-associated function `from_iter` will become ambiguous in Rust 202 --> $DIR/future-prelude-collision-generic.rs:28:5 | LL | Generic::from_iter(1); - | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` | note: the lint level is defined here --> $DIR/future-prelude-collision-generic.rs:5:9 @@ -15,8 +15,8 @@ LL | #![warn(rust_2021_prelude_collisions)] warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 --> $DIR/future-prelude-collision-generic.rs:31:5 | -LL | Generic::::from_iter(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` +LL | Generic::<'static, i32>::from_iter(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` | = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see @@ -24,8 +24,8 @@ LL | Generic::::from_iter(1); warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 --> $DIR/future-prelude-collision-generic.rs:34:5 | -LL | Generic::<_, _>::from_iter(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` +LL | Generic::<'_, _>::from_iter(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as MyFromIter>::from_iter` | = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see From 51e4fbaed15ca5e2c534cc4a3b4e992116044cdb Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:21:22 +0200 Subject: [PATCH 261/269] Fix prelude collision suggestions for glob imported traits. --- compiler/rustc_typeck/src/check/method/prelude2021.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b5bc9d3599ac..e8bafc5f2c66 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -7,7 +7,7 @@ use rustc_hir as hir; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{Adt, Ref, Ty}; use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS; -use rustc_span::symbol::kw::Underscore; +use rustc_span::symbol::kw::{Empty, Underscore}; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; use rustc_trait_selection::infer::InferCtxtExt; @@ -322,7 +322,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None }) .next(); if let Some(any_id) = any_id { - return Some(format!("{}", any_id)); + if any_id.name == Empty { + // Glob import, so just use its name. + return None; + } else { + return Some(format!("{}", any_id)); + } } // All that is left is `_`! We need to use the full path. It doesn't matter which one we pick, From 89a98675aafaebbc62fa9b76383902553124085c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:21:40 +0200 Subject: [PATCH 262/269] Add test for glob imported prelude collision trait. --- .../rust-2021/future-prelude-collision-imported.fixed | 11 +++++++++++ .../ui/rust-2021/future-prelude-collision-imported.rs | 11 +++++++++++ .../future-prelude-collision-imported.stderr | 11 ++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed index c5ff0b4bcd0f..15ccff7496e0 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = TryIntoU32::try_into(3u8).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.rs b/src/test/ui/rust-2021/future-prelude-collision-imported.rs index cd39eec47f2a..cdffcaf75454 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.rs +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.rs @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = 3u8.try_into().unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr index fbda5d61f36d..56abb8abd4d1 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr @@ -30,5 +30,14 @@ LL | let _: u32 = 3u8.try_into().unwrap(); = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see -warning: 3 warnings emitted +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-imported.rs:64:22 + | +LL | let _: u32 = 3u8.try_into().unwrap(); + | ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: 4 warnings emitted From ab369274d69e87eaa18654f7f209c21fee377fef Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 15:41:26 +0200 Subject: [PATCH 263/269] Update test output for stable Rust 2021. --- .../edition-deny-async-fns-2015.stderr | 18 +++++++++--------- .../suggest-switching-edition-on-await.rs | 8 ++++---- .../suggest-switching-edition-on-await.stderr | 8 ++++---- src/test/ui/editions/async-block-2015.rs | 6 +++--- src/test/ui/editions/async-block-2015.stderr | 6 +++--- .../ui/impl-trait/issues/issue-79099.stderr | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr index 43364a8e8589..8fb570d67562 100644 --- a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr +++ b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr @@ -4,7 +4,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn foo() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -13,7 +13,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | fn baz() { async fn foo() {} } | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -22,7 +22,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn async_baz() { | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -31,7 +31,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn bar() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -40,7 +40,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn foo() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -49,7 +49,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn foo() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -58,7 +58,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn bar() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -67,7 +67,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn foo() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0670]: `async fn` is not permitted in Rust 2015 @@ -76,7 +76,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn bar() {} | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0706]: functions in traits cannot be declared `async` diff --git a/src/test/ui/async-await/suggest-switching-edition-on-await.rs b/src/test/ui/async-await/suggest-switching-edition-on-await.rs index 1402f1ca92ba..f2e0fb19c631 100644 --- a/src/test/ui/async-await/suggest-switching-edition-on-await.rs +++ b/src/test/ui/async-await/suggest-switching-edition-on-await.rs @@ -10,7 +10,7 @@ fn await_on_struct_missing() { //~^ ERROR no field `await` on type //~| NOTE unknown field //~| NOTE to `.await` a `Future`, switch to Rust 2018 - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide } @@ -23,7 +23,7 @@ fn await_on_struct_similar() { //~^ ERROR no field `await` on type //~| HELP a field with a similar name exists //~| NOTE to `.await` a `Future`, switch to Rust 2018 - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide } @@ -32,7 +32,7 @@ fn await_on_63533(x: Pin<&mut dyn Future>) { //~^ ERROR no field `await` on type //~| NOTE unknown field //~| NOTE to `.await` a `Future`, switch to Rust 2018 - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide } @@ -40,6 +40,6 @@ fn await_on_apit(x: impl Future) { x.await; //~^ ERROR no field `await` on type //~| NOTE to `.await` a `Future`, switch to Rust 2018 - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide } diff --git a/src/test/ui/async-await/suggest-switching-edition-on-await.stderr b/src/test/ui/async-await/suggest-switching-edition-on-await.stderr index 9ac2bc5cc896..b38c897fc744 100644 --- a/src/test/ui/async-await/suggest-switching-edition-on-await.stderr +++ b/src/test/ui/async-await/suggest-switching-edition-on-await.stderr @@ -5,7 +5,7 @@ LL | x.await; | ^^^^^ unknown field | = note: to `.await` a `Future`, switch to Rust 2018 or later - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `await_on_struct_similar::S` @@ -15,7 +15,7 @@ LL | x.await; | ^^^^^ help: a field with a similar name exists: `awai` | = note: to `.await` a `Future`, switch to Rust 2018 or later - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `Pin<&mut dyn Future>` @@ -25,7 +25,7 @@ LL | x.await; | ^^^^^ unknown field | = note: to `.await` a `Future`, switch to Rust 2018 or later - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `impl Future` @@ -35,7 +35,7 @@ LL | x.await; | ^^^^^ | = note: to `.await` a `Future`, switch to Rust 2018 or later - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error: aborting due to 4 previous errors diff --git a/src/test/ui/editions/async-block-2015.rs b/src/test/ui/editions/async-block-2015.rs index 92eae9e3c14f..24112c9855ac 100644 --- a/src/test/ui/editions/async-block-2015.rs +++ b/src/test/ui/editions/async-block-2015.rs @@ -1,7 +1,7 @@ async fn foo() { //~^ ERROR `async fn` is not permitted in Rust 2015 //~| NOTE to use `async fn`, switch to Rust 2018 or later -//~| HELP set `edition = "2018"` in `Cargo.toml` +//~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide let x = async {}; @@ -11,7 +11,7 @@ async fn foo() { let x = 42; //~^ ERROR expected identifier, found keyword `let` //~| NOTE expected identifier, found keyword - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide 42 }; @@ -19,7 +19,7 @@ async fn foo() { 42 //~^ ERROR expected identifier, found `42` //~| NOTE expected identifier - //~| HELP set `edition = "2018"` in `Cargo.toml` + //~| HELP set `edition = "2021"` in `Cargo.toml` //~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide }; y.await; diff --git a/src/test/ui/editions/async-block-2015.stderr b/src/test/ui/editions/async-block-2015.stderr index e42747c804c7..da8412ddcb33 100644 --- a/src/test/ui/editions/async-block-2015.stderr +++ b/src/test/ui/editions/async-block-2015.stderr @@ -4,7 +4,7 @@ error[E0670]: `async fn` is not permitted in Rust 2015 LL | async fn foo() { | ^^^^^ to use `async fn`, switch to Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error: expected identifier, found keyword `let` @@ -15,7 +15,7 @@ LL | let y = async { LL | let x = 42; | ^^^ expected identifier, found keyword | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error: expected identifier, found `42` @@ -26,7 +26,7 @@ LL | let z = async { LL | 42 | ^^ expected identifier | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0422]: cannot find struct, variant or union type `async` in this scope diff --git a/src/test/ui/impl-trait/issues/issue-79099.stderr b/src/test/ui/impl-trait/issues/issue-79099.stderr index 121536d3f685..394b697a2504 100644 --- a/src/test/ui/impl-trait/issues/issue-79099.stderr +++ b/src/test/ui/impl-trait/issues/issue-79099.stderr @@ -6,7 +6,7 @@ LL | let f: impl core::future::Future = async { 1 }; | | | `async` blocks are only allowed in Rust 2018 or later | - = help: set `edition = "2018"` in `Cargo.toml` + = help: set `edition = "2021"` in `Cargo.toml` = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0562]: `impl Trait` not allowed outside of function and method return types From 10eed8f0c59d3c3e40f5a6c25dd5e187d81cf5e6 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 15:42:45 +0200 Subject: [PATCH 264/269] No longer pass -Z unstable-options for edition 2021 in test. --- src/test/ui/rust-2021/reserved-prefixes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/rust-2021/reserved-prefixes.rs b/src/test/ui/rust-2021/reserved-prefixes.rs index 5882c7d83d8b..1994f25b6a51 100644 --- a/src/test/ui/rust-2021/reserved-prefixes.rs +++ b/src/test/ui/rust-2021/reserved-prefixes.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z unstable-options --edition 2021 +// edition:2021 macro_rules! demo2 { ( $a:tt $b:tt ) => { println!("two tokens") }; From 336f31432df03e4dbd635dddedad1c9e67271a0c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 21:19:24 +0200 Subject: [PATCH 265/269] Warn when [T; N].into_iter() is ambiguous in the new edition. --- Cargo.lock | 1 + compiler/rustc_lint/src/lib.rs | 2 ++ compiler/rustc_typeck/Cargo.toml | 1 + .../src/check/method/prelude2021.rs | 27 +++++++++++++++---- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74a316ed5f04..f47704bbf684 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4405,6 +4405,7 @@ dependencies = [ "rustc_hir_pretty", "rustc_index", "rustc_infer", + "rustc_lint", "rustc_macros", "rustc_middle", "rustc_session", diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 24ac723f2c91..ef4bda666ba0 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -62,6 +62,8 @@ mod traits; mod types; mod unused; +pub use array_into_iter::ARRAY_INTO_ITER; + use rustc_ast as ast; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; diff --git a/compiler/rustc_typeck/Cargo.toml b/compiler/rustc_typeck/Cargo.toml index fa5ef63f5c52..dd76a5e4b99b 100644 --- a/compiler/rustc_typeck/Cargo.toml +++ b/compiler/rustc_typeck/Cargo.toml @@ -26,3 +26,4 @@ rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_ty_utils = { path = "../rustc_ty_utils" } +rustc_lint = { path = "../rustc_lint" } diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b5bc9d3599ac..d5881ad8a512 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -5,7 +5,7 @@ use rustc_ast::Mutability; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::{Adt, Ref, Ty}; +use rustc_middle::ty::{Adt, Array, Ref, Ty}; use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS; use rustc_span::symbol::kw::Underscore; use rustc_span::symbol::{sym, Ident}; @@ -38,11 +38,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } - // These are the method names that were added to prelude in Rust 2021 - if !matches!(segment.ident.name, sym::try_into) { + // `try_into` was added to the prelude in Rust 2021. + // `into_iter` wasn't, but `[T; N].into_iter()` doesn't resolve to + // IntoIterator::into_iter before Rust 2021, which results in the same + // problem. + if !matches!(segment.ident.name, sym::try_into | sym::into_iter) { return; } + let prelude_or_array_lint = if segment.ident.name == sym::into_iter { + // The `into_iter` problem is only a thing for arrays. + if let Array(..) = self_ty.kind() { + // In this case, it wasn't really a prelude addition that was the problem. + // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021. + rustc_lint::ARRAY_INTO_ITER + } else { + // No problem in this case. + return; + } + } else { + RUST_2021_PRELUDE_COLLISIONS + }; + // No need to lint if method came from std/core, as that will now be in the prelude if matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) { return; @@ -69,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Inherent impls only require not relying on autoref and autoderef in order to // ensure that the trait implementation won't be used self.tcx.struct_span_lint_hir( - RUST_2021_PRELUDE_COLLISIONS, + prelude_or_array_lint, self_expr.hir_id, self_expr.span, |lint| { @@ -130,7 +147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // trait implementations require full disambiguation to not clash with the new prelude // additions (i.e. convert from dot-call to fully-qualified call) self.tcx.struct_span_lint_hir( - RUST_2021_PRELUDE_COLLISIONS, + prelude_or_array_lint, call_expr.hir_id, call_expr.span, |lint| { From 756ef3bff619e1d67620b1dfc80f1246cd6aac48 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 21:23:56 +0200 Subject: [PATCH 266/269] Add test for 2021 ambiguous [T; N].into_iter(). --- .../rust-2021/array-into-iter-ambiguous.fixed | 27 +++++++++++++++++++ .../ui/rust-2021/array-into-iter-ambiguous.rs | 27 +++++++++++++++++++ .../array-into-iter-ambiguous.stderr | 16 +++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/test/ui/rust-2021/array-into-iter-ambiguous.fixed create mode 100644 src/test/ui/rust-2021/array-into-iter-ambiguous.rs create mode 100644 src/test/ui/rust-2021/array-into-iter-ambiguous.stderr diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed b/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed new file mode 100644 index 000000000000..76f661baed75 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed @@ -0,0 +1,27 @@ +// See https://github.com/rust-lang/rust/issues/88475 +// run-rustfix +// edition:2018 +// check-pass +#![warn(array_into_iter)] +#![allow(unused)] + +struct FooIter; + +trait MyIntoIter { + fn into_iter(self) -> FooIter; +} + +impl MyIntoIter for [T; N] { + fn into_iter(self) -> FooIter { + FooIter + } +} + +struct Point; + +pub fn main() { + let points: [Point; 1] = [Point]; + let y = MyIntoIter::into_iter(points); + //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 + //~| WARNING this changes meaning in Rust 2021 +} diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.rs b/src/test/ui/rust-2021/array-into-iter-ambiguous.rs new file mode 100644 index 000000000000..83fbf8f6c218 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.rs @@ -0,0 +1,27 @@ +// See https://github.com/rust-lang/rust/issues/88475 +// run-rustfix +// edition:2018 +// check-pass +#![warn(array_into_iter)] +#![allow(unused)] + +struct FooIter; + +trait MyIntoIter { + fn into_iter(self) -> FooIter; +} + +impl MyIntoIter for [T; N] { + fn into_iter(self) -> FooIter { + FooIter + } +} + +struct Point; + +pub fn main() { + let points: [Point; 1] = [Point]; + let y = points.into_iter(); + //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 + //~| WARNING this changes meaning in Rust 2021 +} diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr new file mode 100644 index 000000000000..fac8d21c7b48 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr @@ -0,0 +1,16 @@ +warning: trait method `into_iter` will become ambiguous in Rust 2021 + --> $DIR/array-into-iter-ambiguous.rs:24:13 + | +LL | let y = points.into_iter(); + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyIntoIter::into_iter(points)` + | +note: the lint level is defined here + --> $DIR/array-into-iter-ambiguous.rs:5:9 + | +LL | #![warn(array_into_iter)] + | ^^^^^^^^^^^^^^^ + = warning: this changes meaning in Rust 2021 + = note: for more information, see + +warning: 1 warning emitted + From 23d2cb8435e15ceec1d6499252ac9aef98c5f6fe Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 22:34:34 +0200 Subject: [PATCH 267/269] Don't suggest extra <> in dyn suggestion. --- compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 25d1c8706e87..17e0c42440c2 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -914,7 +914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); if result.is_ok() { - self.maybe_lint_bare_trait(qpath, hir_id); + self.maybe_lint_bare_trait(qpath, hir_id, span); self.register_wf_obligation(ty.into(), qself.span, traits::WellFormed(None)); } @@ -927,7 +927,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) } - fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId) { + fn maybe_lint_bare_trait(&self, qpath: &QPath<'_>, hir_id: hir::HirId, span: Span) { if let QPath::TypeRelative(self_ty, _) = qpath { if let TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) = self_ty.kind @@ -935,10 +935,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let msg = "trait objects without an explicit `dyn` are deprecated"; let (sugg, app) = match self.tcx.sess.source_map().span_to_snippet(self_ty.span) { Ok(s) if poly_trait_ref.trait_ref.path.is_global() => { - (format!("", s), Applicability::MachineApplicable) + (format!("dyn ({})", s), Applicability::MachineApplicable) } - Ok(s) => (format!("", s), Applicability::MachineApplicable), - Err(_) => (">".to_string(), Applicability::HasPlaceholders), + Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable), + Err(_) => ("dyn ".to_string(), Applicability::HasPlaceholders), + }; + // Wrap in `<..>` if it isn't already. + let sugg = match self.tcx.sess.source_map().span_to_snippet(span) { + Ok(s) if s.starts_with('<') => sugg, + _ => format!("<{}>", sugg), }; let replace = String::from("use `dyn`"); if self.sess().edition() >= Edition::Edition2021 { From f8beb8f7f71d6067997cbbb3b9dd2da3769fb020 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 22:34:46 +0200 Subject: [PATCH 268/269] Add test for extra <> in dyn suggestion. --- .../ui/dyn-keyword/dyn-angle-brackets.fixed | 23 +++++++++++++++++ src/test/ui/dyn-keyword/dyn-angle-brackets.rs | 23 +++++++++++++++++ .../ui/dyn-keyword/dyn-angle-brackets.stderr | 25 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/test/ui/dyn-keyword/dyn-angle-brackets.fixed create mode 100644 src/test/ui/dyn-keyword/dyn-angle-brackets.rs create mode 100644 src/test/ui/dyn-keyword/dyn-angle-brackets.stderr diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed new file mode 100644 index 000000000000..25caa6a8030f --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed @@ -0,0 +1,23 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + ::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.rs b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs new file mode 100644 index 000000000000..cf72da2b61ec --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs @@ -0,0 +1,23 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + ::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr new file mode 100644 index 000000000000..ef0f5b7f59db --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr @@ -0,0 +1,25 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | ::fmt(self, f) + | ^^^^^^^^^^ help: use `dyn`: `dyn fmt::Debug` + | +note: the lint level is defined here + --> $DIR/dyn-angle-brackets.rs:4:9 + | +LL | #![deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | ::fmt(self, f) + | ^^^^^^^^^^ help: use `dyn`: `dyn fmt::Debug` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +error: aborting due to 2 previous errors + From ac93ca3b94fefb2ac4844722d4b3222e2f331046 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 23:57:16 +0200 Subject: [PATCH 269/269] Turn to ifs into a match. --- .../src/check/method/prelude2021.rs | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index d5881ad8a512..063c8e555677 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -38,26 +38,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } - // `try_into` was added to the prelude in Rust 2021. - // `into_iter` wasn't, but `[T; N].into_iter()` doesn't resolve to - // IntoIterator::into_iter before Rust 2021, which results in the same - // problem. - if !matches!(segment.ident.name, sym::try_into | sym::into_iter) { - return; - } - - let prelude_or_array_lint = if segment.ident.name == sym::into_iter { - // The `into_iter` problem is only a thing for arrays. - if let Array(..) = self_ty.kind() { + let prelude_or_array_lint = match segment.ident.name { + // `try_into` was added to the prelude in Rust 2021. + sym::try_into => RUST_2021_PRELUDE_COLLISIONS, + // `into_iter` wasn't added to the prelude, + // but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter + // before Rust 2021, which results in the same problem. + // It is only a problem for arrays. + sym::into_iter if let Array(..) = self_ty.kind() => { // In this case, it wasn't really a prelude addition that was the problem. // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021. rustc_lint::ARRAY_INTO_ITER - } else { - // No problem in this case. - return; } - } else { - RUST_2021_PRELUDE_COLLISIONS + _ => return, }; // No need to lint if method came from std/core, as that will now be in the prelude