Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some diagnostic issues with const_generics_defaults feature gate #85800

Merged
merged 4 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,11 @@ fn validate_generic_param_order(
}
GenericParamKind::Type { default: None } => (),
GenericParamKind::Lifetime => (),
// FIXME(const_generics_defaults)
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (),
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
ordered_params += " = ";
ordered_params += &pprust::expr_to_string(&*default.value);
}
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
}
first = false;
}
Expand All @@ -959,7 +962,7 @@ fn validate_generic_param_order(
span,
&format!(
"reorder the parameters: lifetimes, {}",
if sess.features_untracked().const_generics {
if sess.features_untracked().unordered_const_ty_params() {
"then consts and types"
} else {
"then types, then consts"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'tcx> TyS<'tcx> {
/// ADTs with no type arguments.
pub fn is_simple_text(&self) -> bool {
match self.kind() {
Adt(_, substs) => substs.types().next().is_none(),
Adt(_, substs) => substs.types().next().is_none() && substs.consts().next().is_none(),
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
Ref(_, ty, _) => ty.is_simple_text(),
_ => self.is_simple_ty(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error: lifetime parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:7:28
|
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
--> $DIR/intermixed-lifetime.rs:10:37
|
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

8 changes: 7 additions & 1 deletion src/test/ui/const-generics/defaults/mismatch.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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:14:34
Expand Down Expand Up @@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:22:28
--> $DIR/mismatch.rs:20: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

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/const-generics/defaults/mismatch.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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:14:34
Expand Down Expand Up @@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:22:28
--> $DIR/mismatch.rs:20: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

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/const-generics/defaults/mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fn main() {
//~^ Error: mismatched types
let e: Example3::<7> = ();
//~^ Error: mismatched types
// FIXME(const_generics_defaults): There should be a note for the error below, but it is
// missing.
let e: Example4::<7> = ();
//~^ Error: mismatched types
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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