Auto merge of #136429 - fmease:gci-fix-def-site-checks, r= · rust-lang/rust@ea1cdda (original) (raw)

File tree

7 files changed

lines changed

7 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -307,7 +307,11 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
307 307 check_item_type(tcx, def_id, ty.span, UnsizedHandling::Forbid)
308 308 }
309 309 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 +}))
311 315 }
312 316 hir::ItemKind::Struct(_, hir_generics) => {
313 317 let res = check_type_defn(tcx, item, false);
Original file line number Diff line number Diff line change
@@ -97,9 +97,8 @@ use rustc_abi::ExternAbi;
97 97 use rustc_hir as hir;
98 98 use rustc_hir::def::DefKind;
99 99 use rustc_middle::middle;
100 -use rustc_middle::mir::interpret::GlobalId;
101 100 use rustc_middle::query::Providers;
102 -use rustc_middle::ty::{self, Const, Ty, TyCtxt};
101 +use rustc_middle::ty::{Const, Ty, TyCtxt};
103 102 use rustc_span::Span;
104 103 use rustc_trait_selection::traits;
105 104
@@ -168,11 +167,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
168 167 let def_kind = tcx.def_kind(item_def_id);
169 168 match def_kind {
170 169 DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id),
171 -DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
172 -let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
173 -let cid = GlobalId { instance, promoted: None };
174 -let typing_env = ty::TypingEnv::fully_monomorphized();
175 - tcx.ensure().eval_to_const_value_raw(typing_env.as_query_input(cid));
170 +DefKind::Const if !tcx.generics_of(item_def_id).requires_monomorphization(tcx) => {
171 + tcx.ensure().const_eval_poly(item_def_id.into())
176 172 }
177 173 _ => (),
178 174 }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1 1 error[E0080]: evaluation of `_::<'_>` failed
2 - --> $DIR/def-site-eval.rs:14:20
2 + --> $DIR/def-site-eval.rs:13:20
3 3 |
4 4 LL | const _<'_a>: () = panic!();
5 - | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/def-site-eval.rs:14:20
5 + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/def-site-eval.rs:13:20
6 6 |
7 7 = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
8 8
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
4 4 #![allow(incomplete_features)]
5 5
6 6 //@ revisions: fail pass
7 -//@[fail] build-fail (we require monomorphization)
8 7 //@[pass] build-pass (we require monomorphization)
9 8
10 9 const _<_T>: () = panic!();
Original file line number Diff line number Diff 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 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 |
16 +LL |
17 + |
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 number Diff line number Diff 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 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 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 |
26 +LL |
27 + |
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 number Diff line number Diff 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 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 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() {}