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

Add fix to error msg which relied on order #75444

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,8 @@ pub struct GenericParamCount {
pub lifetimes: usize,
pub types: usize,
pub consts: usize,

pub type_defaults: usize,
}

/// Information about the formal type/lifetime parameters associated
Expand Down Expand Up @@ -861,7 +863,10 @@ impl<'tcx> Generics {
for param in &self.params {
match param.kind {
GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
GenericParamDefKind::Type { .. } => own_counts.types += 1,
GenericParamDefKind::Type { has_default, .. } => {
own_counts.types += 1;
own_counts.type_defaults += has_default as usize;
}
GenericParamDefKind::Const => own_counts.consts += 1,
};
}
Expand Down
394 changes: 249 additions & 145 deletions compiler/rustc_typeck/src/astconv/generics.rs

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/test/ui/const-generics/defaults/intermixed-correct-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Check that ordering of errors is correctly reported even with consts preceding types.

#![feature(const_generics)]
#![allow(incomplete_features)]

struct Example<'a, const N: usize, T=f32> {
s: &'a T,
}

type Consts = Example<3, 3, 3>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of const arguments
type Types = Example<f32, f32, f32>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of const arguments
//~| ERROR wrong number of type arguments
type Lifetimes = Example<'static, 'static, 'static>;
//~^ ERROR wrong number of const arguments
//~| ERROR misplaced type arguments
//~| wrong number of lifetime

type LtConst1 = Example<'static, 3, 3>;
//~^ ERROR wrong number of const arguments
type LtConst2 = Example<3, 'static, 3>;
//~^ ERROR wrong number of const arguments
type LtConst3 = Example<3, 3, 'static>;
//~^ ERROR misplaced type arguments

type LtTy1 = Example<'static, f32, f32>;
//~^ ERROR wrong number of const arguments
//~| ERROR wrong number of type arguments
type LtTy2 = Example<f32, 'static, f32>;
//~^ ERROR wrong number of const arguments
//~| ERROR wrong number of type arguments
type LtTy3 = Example<f32, f32, 'static>;
//~^ ERROR wrong number of const arguments
//~| ERROR wrong number of type arguments

type ConstTy1 = Example<3, f32, f32>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of type arguments
type ConstTy2 = Example<f32, 3, f32>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of type arguments
type ConstTy3 = Example<f32, f32, 3>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of type arguments

type ConstLt1 = Example<3, 'static, 'static>;
//~^ ERROR wrong number of lifetime
type ConstLt2 = Example<'static, 3, 'static>;
//~^ ERROR wrong number of lifetime
type ConstLt3 = Example<'static, 'static, 3>;
//~^ ERROR wrong number of lifetime

type TyLt1 = Example<f32, 'static, 'static>;
//~^ ERROR wrong number of lifetime
//~| ERROR wrong number of const
//~| ERROR misplaced type arguments
type TyLt2 = Example<'static, f32, 'static>;
//~^ ERROR wrong number of lifetime
//~| ERROR wrong number of const
//~| ERROR misplaced type arguments
type TyLt3 = Example<'static, 'static, f32>;
//~^ ERROR wrong number of const
//~| ERROR wrong number of lifetime

type TyConst1 = Example<f32, 3, 3>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of const
//~| ERROR misplaced type arguments
type TyConst2 = Example<3, f32, 3>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of const
type TyConst3 = Example<3, 3, f32>;
//~^ ERROR missing lifetime specifier
//~| ERROR wrong number of const
//~| ERROR misplaced type arguments

type Intermixed1 = Example<'static, 3, f32>; // ok


type Intermixed2 = Example<f32, 'static, 3>;
//~^ ERROR type provided when a constant was expected
type Intermixed3 = Example<3, f32, 'static>;
//~^ ERROR constant provided when a lifetime

fn main() {}
Loading