Auto merge of #74831 - Manishearth:rollup-ugw4pt4, r=Manishearth

Rollup of 4 pull requests

Successful merges:

 - #73858 (Make more primitive integer methods const)
 - #74487 (Forbid generic parameters in anon consts inside of type defaults)
 - #74803 (rustbuild: fix bad usage of UNIX exec() in rustc wrapper)
 - #74822 (More ensure stack to avoid segfault with increased `recursion_limit`)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-07-27 16:21:09 +00:00
commit efc02b03d1
17 changed files with 209 additions and 94 deletions

View file

@ -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<i32> {
use std::os::unix::process::CommandExt;
Err(cmd.exec())
}
#[cfg(not(unix))]
fn exec_cmd(cmd: &mut Command) -> io::Result<i32> {
fn status_code(cmd: &mut Command) -> io::Result<i32> {
cmd.status().map(|status| status.code().unwrap())
}

View file

@ -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 {

View file

@ -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)]

View file

@ -87,7 +87,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), 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<Self> {
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<Self> {
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<Self> {
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<Self> {
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')

View file

@ -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,

View file

@ -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_rib(TypeNS, ConstantItemRibKind, |this| {
this.with_label_rib(ConstantItemRibKind, f);
})
});
}

View file

@ -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<T, U = [u8; std::mem::size_of::<T>()]>`
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<T, U = [u8; std::mem::size_of::<T>()]>`
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;

View file

@ -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) {
// #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);
// #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);
// #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!(

View file

@ -0,0 +1,11 @@
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(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 = [u8; N], const N: usize>(T);
//~^ ERROR constant values inside of type parameter defaults
//~| ERROR type parameters with a default
fn main() {}

View file

@ -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 = [u8; N], const N: usize>(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 = [u8; std::mem::size_of::<T>()]>(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 = [u8; N], const N: usize>(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 <https://github.com/rust-lang/rust/issues/44580> for more information
error: aborting due to 3 previous errors; 1 warning emitted

View file

@ -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]; )* ) => {
$(

View file

@ -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};

View file

@ -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);

View file

@ -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();

View file

@ -1,7 +1,5 @@
// run-pass
#![feature(const_nonzero_int_methods)]
use std::num::NonZeroU8;
const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };

View file

@ -0,0 +1,4 @@
struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
//~^ ERROR constant values inside of type parameter defaults
fn main() {}

View file

@ -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 = [u8; std::mem::size_of::<T>()]>(T, U);
| ^ the anonymous constant must not depend on the parameter `T`
error: aborting due to previous error