Skip to content

Commit 5a8ee9b

Browse files
committed
GCI: Check where-clauses at the def site for well-formedness
1 parent c98f662 commit 5a8ee9b

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
307307
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
308308
}
309309
hir::ItemKind::Const(ty, ..) => {
310-
check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
310+
let res = check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid);
311+
res.and(enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
312+
check_where_clauses(wfcx, item.span, def_id);
313+
Ok(())
314+
}))
311315
}
312316
hir::ItemKind::Struct(_, hir_generics) => {
313317
let res = check_type_defn(tcx, item, false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/def-site-predicates-wf.rs:11:5
3+
|
4+
LL | <Vec<str> as Discard>::Output:;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `str`
8+
note: required by an implicit `Sized` bound in `Vec`
9+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
10+
11+
error[E0080]: evaluation of constant value failed
12+
--> $DIR/def-site-predicates-wf.rs:9:1
13+
|
14+
LL | / const _: () = ()
15+
LL | | where
16+
LL | | <Vec<str> as Discard>::Output:;
17+
| |___________________________________^ entering unreachable code
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0080, E0277.
22+
For more information about an error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/def-site-predicates-wf.rs:11:5
3+
|
4+
LL | <Vec<str> as Discard>::Output:;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `str`
8+
note: required by an implicit `Sized` bound in `Vec`
9+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
10+
11+
error[E0277]: the size for values of type `str` cannot be known at compilation time
12+
--> $DIR/def-site-predicates-wf.rs:17:36
13+
|
14+
LL | <Vec<str> as Discard>::Output: Sized;
15+
| ^^^^^ doesn't have a size known at compile-time
16+
|
17+
= help: the trait `Sized` is not implemented for `str`
18+
note: required by an implicit `Sized` bound in `Vec`
19+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
20+
21+
error[E0080]: evaluation of constant value failed
22+
--> $DIR/def-site-predicates-wf.rs:9:1
23+
|
24+
LL | / const _: () = ()
25+
LL | | where
26+
LL | | <Vec<str> as Discard>::Output:;
27+
| |___________________________________^ entering unreachable code
28+
29+
error: aborting due to 3 previous errors
30+
31+
Some errors have detailed explanations: E0080, E0277.
32+
For more information about an error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Ensure that we check the predicates at the definition site for well-formedness.
2+
#![feature(generic_const_items)]
3+
#![allow(incomplete_features)]
4+
5+
//@ revisions: current next
6+
//@[next] compile-flags: -Znext-solver
7+
//@ ignore-compare-mode-next-solver (explicit revisions)
8+
9+
const _: () = ()
10+
where
11+
<Vec<str> as Discard>::Output:; //~ ERROR the size for values of type `str` cannot be known at compilation time
12+
//~^^^ ERROR evaluation of constant value failed
13+
14+
// FIXME(#100041): This should error in the current solver, too.
15+
const _: () = ()
16+
where
17+
<Vec<str> as Discard>::Output: Sized; //[next]~ ERROR the size for values of type `str` cannot be known at compilation time
18+
19+
trait Discard { type Output; }
20+
impl<T> Discard for T { type Output = (); }
21+
22+
fn main() {}

0 commit comments

Comments
 (0)