about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorGurinder Singh <frederick.the.fool@gmail.com>2024-03-06 16:51:17 +0530
committerGurinder Singh <frederick.the.fool@gmail.com>2024-03-06 16:51:17 +0530
commitace436743fff6dcfd21d8194acdd43a94c1611ec (patch)
treeb2cca76c8ae5fe3877f49211ebd32535bf10d429 /compiler
parenta09d91b04a32def152afee94ed47933c03a84d0c (diff)
downloadrust-ace436743fff6dcfd21d8194acdd43a94c1611ec.tar.gz
rust-ace436743fff6dcfd21d8194acdd43a94c1611ec.zip
Check that return type is WF in typeck
Without it non-WF types could pass typeck and then
later fail in MIR/const eval
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/lib.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs
index 70ddd6b2f4c..d86b4912c89 100644
--- a/compiler/rustc_hir_typeck/src/lib.rs
+++ b/compiler/rustc_hir_typeck/src/lib.rs
@@ -61,7 +61,7 @@ use rustc_hir::{HirIdMap, Node};
 use rustc_hir_analysis::astconv::AstConv;
 use rustc_hir_analysis::check::check_abi;
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc_infer::traits::ObligationInspector;
+use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
 use rustc_middle::query::Providers;
 use rustc_middle::traits;
 use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -253,6 +253,10 @@ fn typeck_with_fallback<'tcx>(
         let expected_type = expected_type.unwrap_or_else(fallback);
 
         let expected_type = fcx.normalize(body.value.span, expected_type);
+
+        let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id)));
+        fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code);
+
         fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
 
         // Gather locals in statics (because of block expressions).