Rollup merge of #85800 - BoxyUwU:const-param-default-diagnostics, r=oli-obk
Fix some diagnostic issues with const_generics_defaults feature gate This PR makes a few changes: - print out const param defaults in "lifetime ordering" errors rather than discarding them - update `is_simple_text` to account for const params when checking if a type has no generics, this was causing a note to be failed to add to an error message - fixes some diagnostic wording that incorrectly said there was ordering restrictions between type/const params despite the `const_generics_defaults` feature gate is active
This commit is contained in:
commit
3b47d337e0
8 changed files with 47 additions and 16 deletions
|
@ -938,8 +938,11 @@ fn validate_generic_param_order(
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { default: None } => (),
|
GenericParamKind::Type { default: None } => (),
|
||||||
GenericParamKind::Lifetime => (),
|
GenericParamKind::Lifetime => (),
|
||||||
// FIXME(const_generics_defaults)
|
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
|
||||||
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (),
|
ordered_params += " = ";
|
||||||
|
ordered_params += &pprust::expr_to_string(&*default.value);
|
||||||
|
}
|
||||||
|
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
@ -959,7 +962,7 @@ fn validate_generic_param_order(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"reorder the parameters: lifetimes, {}",
|
"reorder the parameters: lifetimes, {}",
|
||||||
if sess.features_untracked().const_generics {
|
if sess.features_untracked().unordered_const_ty_params() {
|
||||||
"then consts and types"
|
"then consts and types"
|
||||||
} else {
|
} else {
|
||||||
"then types, then consts"
|
"then types, then consts"
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl<'tcx> TyS<'tcx> {
|
||||||
/// ADTs with no type arguments.
|
/// ADTs with no type arguments.
|
||||||
pub fn is_simple_text(&self) -> bool {
|
pub fn is_simple_text(&self) -> bool {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
Adt(_, substs) => substs.types().next().is_none(),
|
Adt(_, substs) => substs.non_erasable_generics().next().is_none(),
|
||||||
Ref(_, ty, _) => ty.is_simple_text(),
|
Ref(_, ty, _) => ty.is_simple_text(),
|
||||||
_ => self.is_simple_ty(),
|
_ => self.is_simple_ty(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ error: lifetime parameters must be declared prior to const parameters
|
||||||
--> $DIR/intermixed-lifetime.rs:7:28
|
--> $DIR/intermixed-lifetime.rs:7:28
|
||||||
|
|
|
|
||||||
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
| -----------------^^---------- 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
|
error: lifetime parameters must be declared prior to type parameters
|
||||||
--> $DIR/intermixed-lifetime.rs:10:37
|
--> $DIR/intermixed-lifetime.rs:10:37
|
||||||
|
|
|
|
||||||
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
||||||
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,12 @@ LL | let e: Example::<13> = ();
|
||||||
| ------------- ^^ expected struct `Example`, found `()`
|
| ------------- ^^ expected struct `Example`, found `()`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected struct `Example`
|
||||||
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:14:34
|
--> $DIR/mismatch.rs:15:34
|
||||||
|
|
|
|
||||||
LL | let e: Example2::<u32, 13> = ();
|
LL | let e: Example2::<u32, 13> = ();
|
||||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||||
|
@ -18,7 +21,7 @@ LL | let e: Example2::<u32, 13> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:16:34
|
--> $DIR/mismatch.rs:18:34
|
||||||
|
|
|
|
||||||
LL | let e: Example3::<13, u32> = ();
|
LL | let e: Example3::<13, u32> = ();
|
||||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||||
|
@ -29,7 +32,7 @@ LL | let e: Example3::<13, u32> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:18:28
|
--> $DIR/mismatch.rs:21:28
|
||||||
|
|
|
|
||||||
LL | let e: Example3::<7> = ();
|
LL | let e: Example3::<7> = ();
|
||||||
| ------------- ^^ expected struct `Example3`, found `()`
|
| ------------- ^^ expected struct `Example3`, found `()`
|
||||||
|
@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:22:28
|
--> $DIR/mismatch.rs:24:28
|
||||||
|
|
|
|
||||||
LL | let e: Example4::<7> = ();
|
LL | let e: Example4::<7> = ();
|
||||||
| ------------- ^^ expected struct `Example4`, found `()`
|
| ------------- ^^ expected struct `Example4`, found `()`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected struct `Example4<7_usize>`
|
||||||
|
found unit type `()`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,12 @@ LL | let e: Example::<13> = ();
|
||||||
| ------------- ^^ expected struct `Example`, found `()`
|
| ------------- ^^ expected struct `Example`, found `()`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected struct `Example`
|
||||||
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:14:34
|
--> $DIR/mismatch.rs:15:34
|
||||||
|
|
|
|
||||||
LL | let e: Example2::<u32, 13> = ();
|
LL | let e: Example2::<u32, 13> = ();
|
||||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||||
|
@ -18,7 +21,7 @@ LL | let e: Example2::<u32, 13> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:16:34
|
--> $DIR/mismatch.rs:18:34
|
||||||
|
|
|
|
||||||
LL | let e: Example3::<13, u32> = ();
|
LL | let e: Example3::<13, u32> = ();
|
||||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||||
|
@ -29,7 +32,7 @@ LL | let e: Example3::<13, u32> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:18:28
|
--> $DIR/mismatch.rs:21:28
|
||||||
|
|
|
|
||||||
LL | let e: Example3::<7> = ();
|
LL | let e: Example3::<7> = ();
|
||||||
| ------------- ^^ expected struct `Example3`, found `()`
|
| ------------- ^^ expected struct `Example3`, found `()`
|
||||||
|
@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
|
||||||
found unit type `()`
|
found unit type `()`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/mismatch.rs:22:28
|
--> $DIR/mismatch.rs:24:28
|
||||||
|
|
|
|
||||||
LL | let e: Example4::<7> = ();
|
LL | let e: Example4::<7> = ();
|
||||||
| ------------- ^^ expected struct `Example4`, found `()`
|
| ------------- ^^ expected struct `Example4`, found `()`
|
||||||
| |
|
| |
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
||||||
|
= note: expected struct `Example4<7_usize>`
|
||||||
|
found unit type `()`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,17 @@ pub struct Example4<const N: usize=13, const M: usize=4>;
|
||||||
fn main() {
|
fn main() {
|
||||||
let e: Example::<13> = ();
|
let e: Example::<13> = ();
|
||||||
//~^ Error: mismatched types
|
//~^ Error: mismatched types
|
||||||
|
//~| expected struct `Example`
|
||||||
let e: Example2::<u32, 13> = ();
|
let e: Example2::<u32, 13> = ();
|
||||||
//~^ Error: mismatched types
|
//~^ Error: mismatched types
|
||||||
|
//~| expected struct `Example2`
|
||||||
let e: Example3::<13, u32> = ();
|
let e: Example3::<13, u32> = ();
|
||||||
//~^ Error: mismatched types
|
//~^ Error: mismatched types
|
||||||
|
//~| expected struct `Example3`
|
||||||
let e: Example3::<7> = ();
|
let e: Example3::<7> = ();
|
||||||
//~^ Error: mismatched types
|
//~^ Error: mismatched types
|
||||||
// FIXME(const_generics_defaults): There should be a note for the error below, but it is
|
//~| expected struct `Example3<7_usize>`
|
||||||
// missing.
|
|
||||||
let e: Example4::<7> = ();
|
let e: Example4::<7> = ();
|
||||||
//~^ Error: mismatched types
|
//~^ Error: mismatched types
|
||||||
|
//~| expected struct `Example4<7_usize>`
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#![feature(const_generics_defaults)]
|
||||||
|
struct Foo<const M: usize = 10, 'a>(&'a u32);
|
||||||
|
//~^ Error lifetime parameters must be declared prior to const parameters
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,8 @@
|
||||||
|
error: lifetime parameters must be declared prior to const parameters
|
||||||
|
--> $DIR/param-order-err-pretty-prints-default.rs:2:33
|
||||||
|
|
|
||||||
|
LL | struct Foo<const M: usize = 10, 'a>(&'a u32);
|
||||||
|
| ----------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const M: usize = 10>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue