diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index fd36cd9bd8beb..af75faf698ecd 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -153,7 +153,7 @@ fn main() { e => e, }; println!("\nDid not run successfully: {:?}\n{:?}\n-------------", e, cmd); - exec_cmd(&mut on_fail).expect("could not run the backup command"); + status_code(&mut on_fail).expect("could not run the backup command"); std::process::exit(1); } @@ -182,17 +182,10 @@ fn main() { } } - let code = exec_cmd(&mut cmd).unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd)); + let code = status_code(&mut cmd).unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd)); std::process::exit(code); } -#[cfg(unix)] -fn exec_cmd(cmd: &mut Command) -> io::Result { - use std::os::unix::process::CommandExt; - Err(cmd.exec()) -} - -#[cfg(not(unix))] -fn exec_cmd(cmd: &mut Command) -> io::Result { +fn status_code(cmd: &mut Command) -> io::Result { cmd.status().map(|status| status.code().unwrap()) } diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 72555d781ed38..2603ecf428c7d 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -1226,7 +1226,7 @@ impl char { /// assert!(!esc.is_ascii_alphabetic()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_alphabetic(&self) -> bool { match *self { @@ -1262,7 +1262,7 @@ impl char { /// assert!(!esc.is_ascii_uppercase()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_uppercase(&self) -> bool { match *self { @@ -1298,7 +1298,7 @@ impl char { /// assert!(!esc.is_ascii_lowercase()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_lowercase(&self) -> bool { match *self { @@ -1337,7 +1337,7 @@ impl char { /// assert!(!esc.is_ascii_alphanumeric()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_alphanumeric(&self) -> bool { match *self { @@ -1373,7 +1373,7 @@ impl char { /// assert!(!esc.is_ascii_digit()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_digit(&self) -> bool { match *self { @@ -1412,7 +1412,7 @@ impl char { /// assert!(!esc.is_ascii_hexdigit()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_hexdigit(&self) -> bool { match *self { @@ -1452,7 +1452,7 @@ impl char { /// assert!(!esc.is_ascii_punctuation()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_punctuation(&self) -> bool { match *self { @@ -1488,7 +1488,7 @@ impl char { /// assert!(!esc.is_ascii_graphic()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_graphic(&self) -> bool { match *self { @@ -1541,7 +1541,7 @@ impl char { /// assert!(!esc.is_ascii_whitespace()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_whitespace(&self) -> bool { match *self { @@ -1579,7 +1579,7 @@ impl char { /// assert!(esc.is_ascii_control()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_control(&self) -> bool { match *self { diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2e443064706d2..edc3fdceb4ff9 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -70,13 +70,11 @@ #![feature(bound_cloned)] #![feature(cfg_target_has_atomic)] #![feature(concat_idents)] -#![feature(const_ascii_ctype_on_intrinsics)] #![feature(const_alloc_layout)] #![feature(const_discriminant)] #![feature(const_checked_int_methods)] #![feature(const_euclidean_int_methods)] #![feature(const_overflowing_int_methods)] -#![feature(const_saturating_int_methods)] #![feature(const_int_unchecked_arith)] #![feature(const_int_pow)] #![feature(constctlz)] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 8e9a903522802..048c9c5ddaaee 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -87,7 +87,7 @@ assert_eq!(size_of::>(), size_of::<", s /// Creates a non-zero if the given value is not zero. #[$stability] - #[rustc_const_unstable(feature = "const_nonzero_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_nonzero_int_methods", since = "1.47.0")] #[inline] pub const fn new(n: $Int) -> Option { if n != 0 { @@ -747,7 +747,7 @@ assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -791,7 +791,7 @@ assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -835,7 +835,7 @@ assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -993,7 +993,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_neg(), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[inline] pub const fn checked_neg(self) -> Option { let (a, b) = self.overflowing_neg(); @@ -1015,7 +1015,7 @@ assert_eq!(0x1", stringify!($SelfT), ".checked_shl(129), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1039,7 +1039,7 @@ assert_eq!(0x10", stringify!($SelfT), ".checked_shr(128), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1064,7 +1064,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.checked_abs(), None);", $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[inline] pub const fn checked_abs(self) -> Option { if self.is_negative() { @@ -1134,7 +1134,7 @@ $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1160,7 +1160,7 @@ assert_eq!(", stringify!($SelfT), "::MAX.saturating_sub(-1), ", stringify!($Self $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1188,7 +1188,7 @@ $EndFeature, " ```"), #[stable(feature = "saturating_neg", since = "1.45.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[inline] pub const fn saturating_neg(self) -> Self { intrinsics::saturating_sub(0, self) @@ -1214,7 +1214,7 @@ $EndFeature, " ```"), #[stable(feature = "saturating_neg", since = "1.45.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[inline] pub const fn saturating_abs(self) -> Self { if self.is_negative() { @@ -1241,7 +1241,7 @@ assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($Self $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2203,7 +2203,7 @@ assert_eq!((-10", stringify!($SelfT), ").signum(), -1);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_int_sign", issue = "53718")] + #[rustc_const_stable(feature = "const_int_sign", since = "1.47.0")] #[inline] pub const fn signum(self) -> Self { match self { @@ -2985,7 +2985,7 @@ Basic usage: assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3027,7 +3027,7 @@ Basic usage: assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3069,7 +3069,7 @@ Basic usage: assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);", $EndFeature, " ```"), #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3222,7 +3222,7 @@ Basic usage: assert_eq!(1", stringify!($SelfT), ".checked_neg(), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[inline] pub const fn checked_neg(self) -> Option { let (a, b) = self.overflowing_neg(); @@ -3243,7 +3243,7 @@ Basic usage: assert_eq!(0x10", stringify!($SelfT), ".checked_shl(129), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3266,7 +3266,7 @@ Basic usage: assert_eq!(0x10", stringify!($SelfT), ".checked_shr(129), None);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_checked_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -3334,7 +3334,7 @@ $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[inline] pub const fn saturating_add(self, rhs: Self) -> Self { intrinsics::saturating_add(self, rhs) @@ -3356,7 +3356,7 @@ assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);", $EndFeature, " #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[inline] pub const fn saturating_sub(self, rhs: Self) -> Self { intrinsics::saturating_sub(self, rhs) @@ -3378,7 +3378,7 @@ assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($Se "::MAX);", $EndFeature, " ```"), #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_unstable(feature = "const_saturating_int_methods", issue = "53718")] + #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -4672,7 +4672,7 @@ impl u8 { /// assert!(!esc.is_ascii_alphabetic()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_alphabetic(&self) -> bool { matches!(*self, b'A'..=b'Z' | b'a'..=b'z') @@ -4705,7 +4705,7 @@ impl u8 { /// assert!(!esc.is_ascii_uppercase()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_uppercase(&self) -> bool { matches!(*self, b'A'..=b'Z') @@ -4738,7 +4738,7 @@ impl u8 { /// assert!(!esc.is_ascii_lowercase()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_lowercase(&self) -> bool { matches!(*self, b'a'..=b'z') @@ -4774,7 +4774,7 @@ impl u8 { /// assert!(!esc.is_ascii_alphanumeric()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_alphanumeric(&self) -> bool { matches!(*self, b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z') @@ -4807,7 +4807,7 @@ impl u8 { /// assert!(!esc.is_ascii_digit()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_digit(&self) -> bool { matches!(*self, b'0'..=b'9') @@ -4843,7 +4843,7 @@ impl u8 { /// assert!(!esc.is_ascii_hexdigit()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_hexdigit(&self) -> bool { matches!(*self, b'0'..=b'9' | b'A'..=b'F' | b'a'..=b'f') @@ -4880,7 +4880,7 @@ impl u8 { /// assert!(!esc.is_ascii_punctuation()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_punctuation(&self) -> bool { matches!(*self, b'!'..=b'/' | b':'..=b'@' | b'['..=b'`' | b'{'..=b'~') @@ -4913,7 +4913,7 @@ impl u8 { /// assert!(!esc.is_ascii_graphic()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_graphic(&self) -> bool { matches!(*self, b'!'..=b'~') @@ -4963,7 +4963,7 @@ impl u8 { /// assert!(!esc.is_ascii_whitespace()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_whitespace(&self) -> bool { matches!(*self, b'\t' | b'\n' | b'\x0C' | b'\r' | b' ') @@ -4998,7 +4998,7 @@ impl u8 { /// assert!(esc.is_ascii_control()); /// ``` #[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")] - #[rustc_const_unstable(feature = "const_ascii_ctype_on_intrinsics", issue = "68983")] + #[rustc_const_stable(feature = "const_ascii_ctype_on_intrinsics", since = "1.47.0")] #[inline] pub const fn is_ascii_control(&self) -> bool { matches!(*self, b'\0'..=b'\x1F' | b'\x7F') diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index a7a005bdeb9f2..81e29047dc5e2 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -442,7 +442,7 @@ impl<'a> Resolver<'a> { ); err } - ResolutionError::ParamInTyOfConstArg(name) => { + ResolutionError::ParamInTyOfConstParam(name) => { let mut err = struct_span_err!( self.session, span, @@ -455,6 +455,17 @@ impl<'a> Resolver<'a> { ); err } + ResolutionError::ParamInAnonConstInTyDefault(name) => { + let mut err = self.session.struct_span_err( + span, + "constant values inside of type parameter defaults must not depend on generic parameters", + ); + err.span_label( + span, + format!("the anonymous constant must not depend on the parameter `{}`", name), + ); + err + } ResolutionError::SelfInTyParamDefault => { let mut err = struct_span_err!( self.session, diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 4b5ab03df4327..bcd2c6c1f1c27 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -570,7 +570,15 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { if let Some(ref ty) = default { self.ribs[TypeNS].push(default_ban_rib); - self.visit_ty(ty); + self.with_rib(ValueNS, ForwardTyParamBanRibKind, |this| { + // HACK: We use an empty `ForwardTyParamBanRibKind` here which + // is only used to forbid the use of const parameters inside of + // type defaults. + // + // While the rib name doesn't really fit here, it does allow us to use the same + // code for both const and type parameters. + this.visit_ty(ty); + }); default_ban_rib = self.ribs[TypeNS].pop().unwrap(); } @@ -1081,7 +1089,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { fn with_constant_rib(&mut self, f: impl FnOnce(&mut Self)) { debug!("with_constant_rib"); self.with_rib(ValueNS, ConstantItemRibKind, |this| { - this.with_label_rib(ConstantItemRibKind, f); + this.with_rib(TypeNS, ConstantItemRibKind, |this| { + this.with_label_rib(ConstantItemRibKind, f); + }) }); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index dfc50a30c121e..234fcd789eee4 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -215,7 +215,9 @@ enum ResolutionError<'a> { /// Error E0128: type parameters with a default cannot use forward-declared identifiers. ForwardDeclaredTyParam, // FIXME(const_generics:defaults) /// ERROR E0770: the type of const parameters must not depend on other generic parameters. - ParamInTyOfConstArg(Symbol), + ParamInTyOfConstParam(Symbol), + /// constant values inside of type parameter defaults must not depend on generic parameters. + ParamInAnonConstInTyDefault(Symbol), /// Error E0735: type parameters with a default cannot use `Self` SelfInTyParamDefault, /// Error E0767: use of unreachable label @@ -2514,7 +2516,7 @@ impl<'a> Resolver<'a> { } ConstParamTyRibKind => { if record_used { - self.report_error(span, ParamInTyOfConstArg(rib_ident.name)); + self.report_error(span, ParamInTyOfConstParam(rib_ident.name)); } return Res::Err; } @@ -2526,18 +2528,40 @@ impl<'a> Resolver<'a> { } } Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) => { + let mut in_ty_param_default = false; for rib in ribs { let has_generic_params = match rib.kind { NormalRibKind | ClosureOrAsyncRibKind | AssocItemRibKind | ModuleRibKind(..) - | MacroDefinition(..) - | ForwardTyParamBanRibKind - | ConstantItemRibKind => { + | MacroDefinition(..) => { // Nothing to do. Continue. continue; } + + // We only forbid constant items if we are inside of type defaults, + // for example `struct Foo()]>` + ForwardTyParamBanRibKind => { + in_ty_param_default = true; + continue; + } + ConstantItemRibKind => { + if in_ty_param_default { + if record_used { + self.report_error( + span, + ResolutionError::ParamInAnonConstInTyDefault( + rib_ident.name, + ), + ); + } + return Res::Err; + } else { + continue; + } + } + // This was an attempt to use a type parameter outside its scope. ItemRibKind(has_generic_params) => has_generic_params, FnItemRibKind => HasGenericParams::Yes, @@ -2545,7 +2569,7 @@ impl<'a> Resolver<'a> { if record_used { self.report_error( span, - ResolutionError::ParamInTyOfConstArg(rib_ident.name), + ResolutionError::ParamInTyOfConstParam(rib_ident.name), ); } return Res::Err; @@ -2572,22 +2596,45 @@ impl<'a> Resolver<'a> { // (spuriously) conflicting with the const param. ribs.next(); } + + let mut in_ty_param_default = false; for rib in ribs { let has_generic_params = match rib.kind { NormalRibKind | ClosureOrAsyncRibKind | AssocItemRibKind | ModuleRibKind(..) - | MacroDefinition(..) - | ForwardTyParamBanRibKind - | ConstantItemRibKind => continue, + | MacroDefinition(..) => continue, + + // We only forbid constant items if we are inside of type defaults, + // for example `struct Foo()]>` + ForwardTyParamBanRibKind => { + in_ty_param_default = true; + continue; + } + ConstantItemRibKind => { + if in_ty_param_default { + if record_used { + self.report_error( + span, + ResolutionError::ParamInAnonConstInTyDefault( + rib_ident.name, + ), + ); + } + return Res::Err; + } else { + continue; + } + } + ItemRibKind(has_generic_params) => has_generic_params, FnItemRibKind => HasGenericParams::Yes, ConstParamTyRibKind => { if record_used { self.report_error( span, - ResolutionError::ParamInTyOfConstArg(rib_ident.name), + ResolutionError::ParamInTyOfConstParam(rib_ident.name), ); } return Res::Err; diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 0632ce2319aee..432abee6d1cf9 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -7,6 +7,7 @@ use crate::autoderef::Autoderef; use crate::infer::InferCtxt; use crate::traits::normalize_projection_type; +use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Style}; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -1912,12 +1913,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); if !self.is_recursive_obligation(obligated_types, &data.parent_code) { - self.note_obligation_cause_code( - err, - &parent_predicate, - &data.parent_code, - obligated_types, - ); + // #74711: avoid a stack overflow + ensure_sufficient_stack(|| { + self.note_obligation_cause_code( + err, + &parent_predicate, + &data.parent_code, + obligated_types, + ) + }); } } ObligationCauseCode::ImplDerivedObligation(ref data) => { @@ -1928,22 +1932,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { parent_trait_ref.skip_binder().self_ty() )); let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); - self.note_obligation_cause_code( - err, - &parent_predicate, - &data.parent_code, - obligated_types, - ); + // #74711: avoid a stack overflow + ensure_sufficient_stack(|| { + self.note_obligation_cause_code( + err, + &parent_predicate, + &data.parent_code, + obligated_types, + ) + }); } ObligationCauseCode::DerivedObligation(ref data) => { let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); - self.note_obligation_cause_code( - err, - &parent_predicate, - &data.parent_code, - obligated_types, - ); + // #74711: avoid a stack overflow + ensure_sufficient_stack(|| { + self.note_obligation_cause_code( + err, + &parent_predicate, + &data.parent_code, + obligated_types, + ) + }); } ObligationCauseCode::CompareImplMethodObligation { .. } => { err.note(&format!( 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 new file mode 100644 index 0000000000000..84bbea5b88057 --- /dev/null +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs @@ -0,0 +1,11 @@ +#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete + +struct Foo()]>(T, U); +//~^ ERROR constant values inside of type parameter defaults + +// FIXME(const_generics:defaults): We still don't know how to we deal with type defaults. +struct Bar(T); +//~^ ERROR constant values inside of type parameter defaults +//~| ERROR type parameters with a default + +fn main() {} diff --git a/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.stderr b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.stderr new file mode 100644 index 0000000000000..571be91683b7c --- /dev/null +++ b/src/test/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.stderr @@ -0,0 +1,31 @@ +error: type parameters with a default must be trailing + --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:7:12 + | +LL | struct Bar(T); + | ^ + | + = note: using type defaults and const parameters in the same parameter list is currently not permitted + +error: constant values inside of type parameter defaults must not depend on generic parameters + --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:3:44 + | +LL | struct Foo()]>(T, U); + | ^ the anonymous constant must not depend on the parameter `T` + +error: constant values inside of type parameter defaults must not depend on generic parameters + --> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:7:21 + | +LL | struct Bar(T); + | ^ the anonymous constant must not depend on the parameter `N` + +warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/params-in-ct-in-ty-param-lazy-norm.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 3 previous errors; 1 warning emitted + diff --git a/src/test/ui/consts/ascii_ctype.rs b/src/test/ui/consts/ascii_ctype.rs index 25b270ee49cae..ef2f7322f2718 100644 --- a/src/test/ui/consts/ascii_ctype.rs +++ b/src/test/ui/consts/ascii_ctype.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(const_ascii_ctype_on_intrinsics)] - macro_rules! suite { ( $( $fn:ident => [$a:ident, $A:ident, $nine:ident, $dot:ident, $space:ident]; )* ) => { $( diff --git a/src/test/ui/consts/const-int-arithmetic.rs b/src/test/ui/consts/const-int-arithmetic.rs index 9c94551f7440e..9b2e30961aae6 100644 --- a/src/test/ui/consts/const-int-arithmetic.rs +++ b/src/test/ui/consts/const-int-arithmetic.rs @@ -3,7 +3,6 @@ #![feature(const_checked_int_methods)] #![feature(const_euclidean_int_methods)] #![feature(const_overflowing_int_methods)] -#![feature(const_saturating_int_methods)] #![feature(const_wrapping_int_methods)] use std::{i8, i128}; diff --git a/src/test/ui/consts/const-int-saturating-arith.rs b/src/test/ui/consts/const-int-saturating-arith.rs index 4718120a51bd3..7edbdd4cec5a5 100644 --- a/src/test/ui/consts/const-int-saturating-arith.rs +++ b/src/test/ui/consts/const-int-saturating-arith.rs @@ -1,5 +1,4 @@ // run-pass -#![feature(const_saturating_int_methods)] const INT_U32_NO: u32 = (42 as u32).saturating_add(2); const INT_U32: u32 = u32::MAX.saturating_add(1); diff --git a/src/test/ui/consts/const-int-sign-rpass.rs b/src/test/ui/consts/const-int-sign-rpass.rs index dc46fce39a93c..63c191d422716 100644 --- a/src/test/ui/consts/const-int-sign-rpass.rs +++ b/src/test/ui/consts/const-int-sign-rpass.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(const_int_sign)] - const NEGATIVE_A: bool = (-10i32).is_negative(); const NEGATIVE_B: bool = 10i32.is_negative(); const POSITIVE_A: bool = (-10i32).is_positive(); diff --git a/src/test/ui/consts/const-nonzero.rs b/src/test/ui/consts/const-nonzero.rs index 2160bad48074d..cf6f8c8d69a26 100644 --- a/src/test/ui/consts/const-nonzero.rs +++ b/src/test/ui/consts/const-nonzero.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(const_nonzero_int_methods)] - use std::num::NonZeroU8; const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) }; diff --git a/src/test/ui/generic/param-in-ct-in-ty-param-default.rs b/src/test/ui/generic/param-in-ct-in-ty-param-default.rs new file mode 100644 index 0000000000000..dd89bc0f7a0ff --- /dev/null +++ b/src/test/ui/generic/param-in-ct-in-ty-param-default.rs @@ -0,0 +1,4 @@ +struct Foo()]>(T, U); +//~^ ERROR constant values inside of type parameter defaults + +fn main() {} diff --git a/src/test/ui/generic/param-in-ct-in-ty-param-default.stderr b/src/test/ui/generic/param-in-ct-in-ty-param-default.stderr new file mode 100644 index 0000000000000..ea867240269ef --- /dev/null +++ b/src/test/ui/generic/param-in-ct-in-ty-param-default.stderr @@ -0,0 +1,8 @@ +error: constant values inside of type parameter defaults must not depend on generic parameters + --> $DIR/param-in-ct-in-ty-param-default.rs:1:44 + | +LL | struct Foo()]>(T, U); + | ^ the anonymous constant must not depend on the parameter `T` + +error: aborting due to previous error +