Skip to main content Module wfcheck Copy item path Source use std::cell::LazyCell ; π use std::ops::ControlFlow ; π use std::ops::Deref ; π use hir::intravisit ; π use hir::intravisit::Visitor ; π use rustc_abi::ExternAbi ; π use rustc_abi::ScalableElt ; π use rustc_ast as ast; π use rustc_attr_ir::lang_items::LangItem ; π use rustc_attr_ir::EiiDecl ; π use rustc_attr_ir::EiiImpl ; π use rustc_attr_ir::EiiImplResolution ; π use rustc_attr_ir::find_attr ; π use rustc_data_structures::fx::FxHashSet ; π use rustc_data_structures::fx::FxIndexMap ; π use rustc_data_structures::fx::FxIndexSet ; π use rustc_data_structures::transitive_relation::TransitiveRelationBuilder ; π use rustc_errors::Applicability ; π use rustc_errors::ErrorGuaranteed ; π use rustc_errors::MultiSpan ; π use rustc_errors::msg ; π use rustc_errors::pluralize ; π use rustc_errors::struct_span_code_err ; π use rustc_hir as hir; π use rustc_hir::def::DefKind ; π use rustc_hir::def::Res ; π use rustc_hir::def_id::DefId ; π use rustc_hir::def_id::LocalDefId ; π use rustc_hir::AmbigArg ; π use rustc_hir::ItemKind ; π use rustc_infer::infer::outlives::env::OutlivesEnvironment ; π use rustc_infer::infer::BoundRegionConversionTime ; π use rustc_infer::infer::SolverRegionConstraint ; π use rustc_infer::infer::TyCtxtInferExt ; π use rustc_infer::traits::PredicateObligations ; π use rustc_infer::traits::TraitErrors ; π use rustc_lint_defs::builtin::REDUNDANT_LIFETIMES ; π use rustc_lint_defs::builtin::SHADOWING_SUPERTRAIT_ITEMS ; π use rustc_lint_defs::builtin::UNEVALUATED_DEFAULT_FIELD_VALUE ; π use rustc_macros::Diagnostic ; π use rustc_macros::TypeFoldable ; π use rustc_macros::TypeVisitable ; π use rustc_middle::mir::interpret::ErrorHandled ; π use rustc_middle::traits::solve::NoSolution ; π use rustc_middle::ty::print::with_no_trimmed_paths ; π use rustc_middle::ty::print::with_no_trimmed_paths ; π use rustc_middle::ty::region_constraint::And ; π use rustc_middle::ty::region_constraint::LeafRegionConstraint ; π use rustc_middle::ty::region_constraint::Or ; π use rustc_middle::ty::trait_def::TraitSpecializationKind ; π use rustc_middle::ty ; π use rustc_middle::ty::CallerBoundsIterator ; π use rustc_middle::ty::GenericArgKind ; π use rustc_middle::ty::GenericArgs ; π use rustc_middle::ty::GenericParamDefKind ; π use rustc_middle::ty::Ty ; π use rustc_middle::ty::TyCtxt ; π use rustc_middle::ty::TypeFlags ; π use rustc_middle::ty::TypeFoldable ; π use rustc_middle::ty::TypeSuperVisitable ; π use rustc_middle::ty::TypeVisitable ; π use rustc_middle::ty::TypeVisitableExt ; π use rustc_middle::ty::TypeVisitor ; π use rustc_middle::ty::TypingMode ; π use rustc_middle::ty::Unnormalized ; π use rustc_middle::ty::Upcast ; π use rustc_session::diagnostics::feature_err ; π use rustc_span::DUMMY_SP ; π use rustc_span::Span ; π use rustc_span::bug ; π use rustc_span::span_bug ; π use rustc_span::sym ; π use rustc_trait_selection::error_reporting::InferCtxtErrorExt ; π use rustc_trait_selection::regions::OutlivesEnvironmentBuildExt ; π use rustc_trait_selection::regions::region_known_to_outlive ; π use rustc_trait_selection::regions::ty_known_to_outlive ; π use rustc_trait_selection::traits::misc::ConstParamTyImplementationError ; π use rustc_trait_selection::traits::misc::type_allowed_to_implement_const_param_ty ; π use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; π use rustc_trait_selection::traits ; π use rustc_trait_selection::traits::FulfillmentError ; π use rustc_trait_selection::traits::Obligation ; π use rustc_trait_selection::traits::ObligationCause ; π use rustc_trait_selection::traits::ObligationCauseCode ; π use rustc_trait_selection::traits::ObligationCtxt ; π use rustc_trait_selection::traits::WellFormedLoc ; π use tracing::debug ; π use tracing::instrument ; π use tracing::instrument ; π use super::compare_eii::compare_eii_function_types ; π use super::compare_eii::compare_eii_statics ; π use crate::autoderef::Autoderef ; π use crate::constrained_generic_params::Parameter ; π use crate::constrained_generic_params::identify_constrained_generic_params ; π use crate::diagnostics ; π use crate::diagnostics::InvalidReceiverTyHint ; π use crate::diagnostics::ParamInTyOfConstParam ; π use crate::diagnostics::UnevaluatedDefaultFieldValue ; π use rustc_errors::codes ::*; π CollectUsageSpans π Collect usages of the param_def_id and Res::SelfTyAlias in the HIR. GATArgsCollector π TypeVisitor that looks for uses of GATs like
<P0 as Trait<P1..Pn>>::GAT<Pn..Pm> and adds the arguments P0..Pm into
the two vectors, regions and types (depending on their kind). For each
parameter Pi also track the index i. HasErrorDeep π Look for ErrorGuaranteed deeply within structsβ (unsubstituted) fields. IsProbablyCyclical π Detects cases where an ADT is trivially cyclical β we want to detect this so
we only mention that its parameters are used cyclically if the ADT is truly
cyclical. RedundantLifetimeArgsLint π TestBinderBody π TestBinderExists π TestBinderForall π WfCheckingCtxt π WithWhereClauses π ArbitrarySelfTypesLevel π The arbitrary_self_types_pointers feature implies arbitrary_self_types. ReceiverValidityError π Error cases which may be returned from receiver_is_valid. These error
cases are generated in this function as they may be unearthed as we explore
the autoderef chain, but theyβre converted to diagnostics in the caller. TestBinderItem π augment_param_env π Add a new set of predicates to the caller_bounds of an existing param_env. check_associated_item π check_associated_type_bounds π Checks all associated type defaults of trait trait_def_id. check_const_item π Runs checks common to both free consts and associated consts check_eiis_fn π check_eiis_static π check_fn_or_method π check_foreign_item π check_gat_where_clauses π Require that the user writes where clauses on GATs for the implicit
outlives bounds involving trait parameters in trait functions and
lifetimes passed as GAT args. See self-outlives-lint test. check_impl π check_item π Checks that the field types (in a struct defβn) or argument types (in an enum defβn) are
well-formed, meaning that they do not require any constraints not declared in the struct
definition itself. For example, this definition would be illegal: check_item_fn π check_method_receiver π check_param_wf π check_static_item π check_trait π check_trait_item π check_type_defn π In a type definition, we check that to ensure that the types of the fields are well-formed. check_type_wf π check_variances_for_type_defn π check_well_formed π check_where_clauses π Checks where-clauses and inline bounds that are declared on def_id. confirm_type_is_not_a_method_generic_param π Confirms that a type is not a type parameter referring to one of the
methodβs type params. enter_wf_checking_ctxt π gather_gat_bounds π We use the following trait as an example throughout this function.
Specifically, letβs assume that to_check here is the return type
of into_iter, and the GAT we are checking this for is Iter. legacy_receiver_is_implemented π lint_item_shadowing_supertrait_item π lint_redundant_lifetimes π receiver_is_valid π Returns whether receiver_ty would be considered a valid receiver type for self_ty. If
arbitrary_self_types is enabled, receiver_ty must transitively deref to self_ty, possibly
through a *const/mut T raw pointer if arbitrary_self_types_pointers is also enabled.
If neither feature is enabled, the requirements are more strict: receiver_ty must implement
Receiver and directly implement Deref<Target = self_ty>. report_bivariance π