diff options
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs (renamed from compiler/rustc_typeck/src/lib.rs) | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index b1ce972e1..525cd2419 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -64,15 +64,13 @@ This API is completely unstable and subject to change. #![feature(if_let_guard)] #![feature(is_sorted)] #![feature(iter_intersperse)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(once_cell)] #![feature(slice_partition_dedup)] #![feature(try_blocks)] -#![feature(is_some_with)] +#![feature(is_some_and)] #![feature(type_alias_impl_trait)] #![recursion_limit = "256"] @@ -84,20 +82,19 @@ extern crate rustc_middle; // These are used by Clippy. pub mod check; -pub mod expr_use_visitor; -mod astconv; +pub mod astconv; mod bounds; mod check_unused; mod coherence; -mod collect; +// FIXME: This module shouldn't be public. +pub mod collect; mod constrained_generic_params; mod errors; pub mod hir_wf_check; mod impl_wf_check; -mod mem_categorization; mod outlives; -mod structured_errors; +pub mod structured_errors; mod variance; use rustc_errors::{struct_span_err, ErrorGuaranteed}; @@ -112,7 +109,7 @@ use rustc_middle::util; use rustc_session::config::EntryFnType; use rustc_span::{symbol::sym, Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; -use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; +use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _; use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode}; use std::iter; @@ -143,24 +140,23 @@ fn require_same_types<'tcx>( expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> bool { - tcx.infer_ctxt().enter(|ref infcx| { - let param_env = ty::ParamEnv::empty(); - let errors = match infcx.at(cause, param_env).eq(expected, actual) { - Ok(InferOk { obligations, .. }) => traits::fully_solve_obligations(infcx, obligations), - Err(err) => { - infcx.report_mismatched_types(cause, expected, actual, err).emit(); - return false; - } - }; + let infcx = &tcx.infer_ctxt().build(); + let param_env = ty::ParamEnv::empty(); + let errors = match infcx.at(cause, param_env).eq(expected, actual) { + Ok(InferOk { obligations, .. }) => traits::fully_solve_obligations(infcx, obligations), + Err(err) => { + infcx.err_ctxt().report_mismatched_types(cause, expected, actual, err).emit(); + return false; + } + }; - match &errors[..] { - [] => true, - errors => { - infcx.report_fulfillment_errors(errors, None, false); - false - } + match &errors[..] { + [] => true, + errors => { + infcx.err_ctxt().report_fulfillment_errors(errors, None, false); + false } - }) + } } fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { @@ -307,23 +303,22 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { error = true; } let return_ty = return_ty.skip_binder(); - tcx.infer_ctxt().enter(|infcx| { - // Main should have no WC, so empty param env is OK here. - let param_env = ty::ParamEnv::empty(); - let cause = traits::ObligationCause::new( - return_ty_span, - main_diagnostics_hir_id, - ObligationCauseCode::MainFunctionType, - ); - let ocx = traits::ObligationCtxt::new(&infcx); - let norm_return_ty = ocx.normalize(cause.clone(), param_env, return_ty); - ocx.register_bound(cause, param_env, norm_return_ty, term_did); - let errors = ocx.select_all_or_error(); - if !errors.is_empty() { - infcx.report_fulfillment_errors(&errors, None, false); - error = true; - } - }); + let infcx = tcx.infer_ctxt().build(); + // Main should have no WC, so empty param env is OK here. + let param_env = ty::ParamEnv::empty(); + let cause = traits::ObligationCause::new( + return_ty_span, + main_diagnostics_hir_id, + ObligationCauseCode::MainFunctionType, + ); + let ocx = traits::ObligationCtxt::new(&infcx); + let norm_return_ty = ocx.normalize(cause.clone(), param_env, return_ty); + ocx.register_bound(cause, param_env, norm_return_ty, term_did); + let errors = ocx.select_all_or_error(); + if !errors.is_empty() { + infcx.err_ctxt().report_fulfillment_errors(&errors, None, false); + error = true; + } // now we can take the return type of the given main function expected_return_type = main_fnsig.output(); } else { @@ -386,7 +381,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { error = true; } if let hir::IsAsync::Async = sig.header.asyncness { - let span = tcx.def_span(it.def_id); + let span = tcx.def_span(it.owner_id); struct_span_err!( tcx.sess, span, |