Skip to content
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
17 changes: 17 additions & 0 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,23 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
},
));
}
ty::Array(elem_ty, _len) => {
let field_vals = val.to_branch();
let cause = self.cause(ObligationCauseCode::WellFormed(None));

self.out.extend(field_vals.iter().map(|&field_val| {
let predicate = ty::PredicateKind::Clause(
ty::ClauseKind::ConstArgHasType(field_val, *elem_ty),
);
traits::Obligation::with_depth(
tcx,
cause.clone(),
self.recursion_depth,
self.param_env,
predicate,
)
}));
}
_ => {}
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/const-generics/mgca/array-expr-type-missmatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![expect(incomplete_features)]
#![feature(min_generic_const_args, adt_const_params)]

use std::marker::ConstParamTy;

#[derive(Eq, PartialEq, ConstParamTy)]
struct Foo;
struct Bar;

fn takes_array<const A: [Foo; 1]>() {}

fn main() {
takes_array::<{ [Bar] }>();
//~^ ERROR: the constant `Bar` is not of type `Foo`
}
8 changes: 8 additions & 0 deletions tests/ui/const-generics/mgca/array-expr-type-missmatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: the constant `Bar` is not of type `Foo`
--> $DIR/array-expr-type-missmatch.rs:13:21
|
LL | takes_array::<{ [Bar] }>();
| ^^^^^ expected `Foo`, found `Bar`

error: aborting due to 1 previous error

Loading