Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/lower.rs')
-rw-r--r--crates/hir-ty/src/lower.rs84
1 files changed, 23 insertions, 61 deletions
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index 0c197b2703..b18d713c41 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -25,14 +25,14 @@ use chalk_ir::{
use either::Either;
use hir_def::{
AdtId, AssocItemId, ConstId, ConstParamId, EnumId, EnumVariantId, FunctionId, GenericDefId,
- GenericParamId, ItemContainerId, LocalFieldId, Lookup, StaticId, StructId, TypeAliasId,
- TypeOrConstParamId, UnionId, VariantId,
+ GenericParamId, LocalFieldId, Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId,
+ UnionId, VariantId,
builtin_type::BuiltinType,
expr_store::{ExpressionStore, path::Path},
hir::generics::{GenericParamDataRef, TypeOrConstParamData, WherePredicate},
lang_item::LangItem,
resolver::{HasResolver, LifetimeNs, Resolver, TypeNs},
- signatures::{FunctionSignature, TraitFlags},
+ signatures::TraitFlags,
type_ref::{
ConstRef, LifetimeRefId, LiteralConstRef, PathId, TraitBoundModifier, TypeBound, TypeRef,
TypeRefId,
@@ -49,7 +49,7 @@ use crate::{
ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, LifetimeData, LifetimeOutlives,
QuantifiedWhereClause, QuantifiedWhereClauses, Substitution, TraitRef, TraitRefExt, Ty,
TyBuilder, TyKind, WhereClause, all_super_traits,
- consteval::{intern_const_ref, path_to_const, unknown_const, unknown_const_as_generic},
+ consteval_chalk::{intern_const_ref, path_to_const, unknown_const, unknown_const_as_generic},
db::HirDatabase,
error_lifetime,
generics::{Generics, generics, trait_self_param_idx},
@@ -86,7 +86,7 @@ impl ImplTraitLoweringState {
pub(crate) struct PathDiagnosticCallbackData(pub(crate) TypeRefId);
#[derive(Debug, Clone)]
-pub enum LifetimeElisionKind {
+pub(crate) enum LifetimeElisionKind {
/// Create a new anonymous lifetime parameter and reference it.
///
/// If `report_in_path`, report an error when encountering lifetime elision in a path:
@@ -111,40 +111,12 @@ pub enum LifetimeElisionKind {
/// error on default object bounds (e.g., `Box<dyn Foo>`).
AnonymousReportError,
- /// Resolves elided lifetimes to `'static` if there are no other lifetimes in scope,
- /// otherwise give a warning that the previous behavior of introducing a new early-bound
- /// lifetime is a bug and will be removed (if `only_lint` is enabled).
- StaticIfNoLifetimeInScope { only_lint: bool },
-
- /// Signal we cannot find which should be the anonymous lifetime.
- ElisionFailure,
-
/// Infer all elided lifetimes.
Infer,
}
impl LifetimeElisionKind {
#[inline]
- pub(crate) fn for_const(const_parent: ItemContainerId) -> LifetimeElisionKind {
- match const_parent {
- ItemContainerId::ExternBlockId(_) | ItemContainerId::ModuleId(_) => {
- LifetimeElisionKind::Elided(static_lifetime())
- }
- ItemContainerId::ImplId(_) => {
- LifetimeElisionKind::StaticIfNoLifetimeInScope { only_lint: true }
- }
- ItemContainerId::TraitId(_) => {
- LifetimeElisionKind::StaticIfNoLifetimeInScope { only_lint: false }
- }
- }
- }
-
- #[inline]
- pub(crate) fn for_fn_params(data: &FunctionSignature) -> LifetimeElisionKind {
- LifetimeElisionKind::AnonymousCreateParameter { report_in_path: data.is_async() }
- }
-
- #[inline]
pub(crate) fn for_fn_ret() -> LifetimeElisionKind {
// FIXME: We should use the elided lifetime here, or `ElisionFailure`.
LifetimeElisionKind::Elided(error_lifetime())
@@ -152,7 +124,7 @@ impl LifetimeElisionKind {
}
#[derive(Debug)]
-pub struct TyLoweringContext<'db> {
+pub(crate) struct TyLoweringContext<'db> {
pub db: &'db dyn HirDatabase,
resolver: &'db Resolver<'db>,
store: &'db ExpressionStore,
@@ -172,7 +144,7 @@ pub struct TyLoweringContext<'db> {
}
impl<'db> TyLoweringContext<'db> {
- pub fn new(
+ pub(crate) fn new(
db: &'db dyn HirDatabase,
resolver: &'db Resolver<'db>,
store: &'db ExpressionStore,
@@ -197,7 +169,7 @@ impl<'db> TyLoweringContext<'db> {
}
}
- pub fn with_debruijn<T>(
+ pub(crate) fn with_debruijn<T>(
&mut self,
debruijn: DebruijnIndex,
f: impl FnOnce(&mut TyLoweringContext<'_>) -> T,
@@ -208,7 +180,7 @@ impl<'db> TyLoweringContext<'db> {
result
}
- pub fn with_shifted_in<T>(
+ pub(crate) fn with_shifted_in<T>(
&mut self,
debruijn: DebruijnIndex,
f: impl FnOnce(&mut TyLoweringContext<'_>) -> T,
@@ -227,25 +199,15 @@ impl<'db> TyLoweringContext<'db> {
result
}
- pub fn with_impl_trait_mode(self, impl_trait_mode: ImplTraitLoweringMode) -> Self {
+ pub(crate) fn with_impl_trait_mode(self, impl_trait_mode: ImplTraitLoweringMode) -> Self {
Self { impl_trait_mode: ImplTraitLoweringState::new(impl_trait_mode), ..self }
}
- pub fn with_type_param_mode(self, type_param_mode: ParamLoweringMode) -> Self {
+ pub(crate) fn with_type_param_mode(self, type_param_mode: ParamLoweringMode) -> Self {
Self { type_param_mode, ..self }
}
- pub fn impl_trait_mode(&mut self, impl_trait_mode: ImplTraitLoweringMode) -> &mut Self {
- self.impl_trait_mode = ImplTraitLoweringState::new(impl_trait_mode);
- self
- }
-
- pub fn type_param_mode(&mut self, type_param_mode: ParamLoweringMode) -> &mut Self {
- self.type_param_mode = type_param_mode;
- self
- }
-
- pub fn push_diagnostic(&mut self, type_ref: TypeRefId, kind: TyLoweringDiagnosticKind) {
+ pub(crate) fn push_diagnostic(&mut self, type_ref: TypeRefId, kind: TyLoweringDiagnosticKind) {
self.diagnostics.push(TyLoweringDiagnostic { source: type_ref, kind });
}
}
@@ -268,12 +230,12 @@ pub enum ParamLoweringMode {
Variable,
}
-impl<'a> TyLoweringContext<'a> {
- pub fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty {
+impl<'db> TyLoweringContext<'db> {
+ pub(crate) fn lower_ty(&mut self, type_ref: TypeRefId) -> Ty {
self.lower_ty_ext(type_ref).0
}
- pub fn lower_const(&mut self, const_ref: &ConstRef, const_type: Ty) -> Const {
+ pub(crate) fn lower_const(&mut self, const_ref: &ConstRef, const_type: Ty) -> Const {
let const_ref = &self.store[const_ref.expr];
match const_ref {
hir_def::hir::Expr::Path(path) => path_to_const(
@@ -328,7 +290,7 @@ impl<'a> TyLoweringContext<'a> {
}
}
- pub fn lower_path_as_const(&mut self, path: &Path, const_type: Ty) -> Const {
+ pub(crate) fn lower_path_as_const(&mut self, path: &Path, const_type: Ty) -> Const {
path_to_const(
self.db,
self.resolver,
@@ -345,7 +307,7 @@ impl<'a> TyLoweringContext<'a> {
self.generics.get_or_init(|| generics(self.db, self.def))
}
- pub fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty, Option<TypeNs>) {
+ pub(crate) fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty, Option<TypeNs>) {
let mut res = None;
let type_ref = &self.store[type_ref_id];
let ty = match type_ref {
@@ -512,7 +474,7 @@ impl<'a> TyLoweringContext<'a> {
}
#[inline]
- fn on_path_diagnostic_callback(type_ref: TypeRefId) -> PathDiagnosticCallback<'static> {
+ fn on_path_diagnostic_callback<'a>(type_ref: TypeRefId) -> PathDiagnosticCallback<'a, 'db> {
PathDiagnosticCallback {
data: Either::Left(PathDiagnosticCallbackData(type_ref)),
callback: |data, this, diag| {
@@ -523,7 +485,7 @@ impl<'a> TyLoweringContext<'a> {
}
#[inline]
- fn at_path(&mut self, path_id: PathId) -> PathLoweringContext<'_, 'a> {
+ fn at_path(&mut self, path_id: PathId) -> PathLoweringContext<'_, 'db> {
PathLoweringContext::new(
self,
Self::on_path_diagnostic_callback(path_id.type_ref()),
@@ -559,7 +521,7 @@ impl<'a> TyLoweringContext<'a> {
&mut self,
path_id: PathId,
explicit_self_ty: Ty,
- ) -> Option<(TraitRef, PathLoweringContext<'_, 'a>)> {
+ ) -> Option<(TraitRef, PathLoweringContext<'_, 'db>)> {
let mut ctx = self.at_path(path_id);
let resolved = match ctx.resolve_path_in_type_ns_fully()? {
// FIXME(trait_alias): We need to handle trait alias here.
@@ -576,7 +538,7 @@ impl<'a> TyLoweringContext<'a> {
&'b mut self,
where_predicate: &'b WherePredicate,
ignore_bindings: bool,
- ) -> impl Iterator<Item = QuantifiedWhereClause> + use<'a, 'b> {
+ ) -> impl Iterator<Item = QuantifiedWhereClause> + use<'db, 'b> {
match where_predicate {
WherePredicate::ForLifetime { target, bound, .. }
| WherePredicate::TypeBound { target, bound } => {
@@ -598,7 +560,7 @@ impl<'a> TyLoweringContext<'a> {
bound: &'b TypeBound,
self_ty: Ty,
ignore_bindings: bool,
- ) -> impl Iterator<Item = QuantifiedWhereClause> + use<'b, 'a> {
+ ) -> impl Iterator<Item = QuantifiedWhereClause> + use<'b, 'db> {
let mut assoc_bounds = None;
let mut clause = None;
match bound {
@@ -794,7 +756,7 @@ impl<'a> TyLoweringContext<'a> {
ImplTrait { bounds: crate::make_single_type_binders(predicates) }
}
- pub fn lower_lifetime(&self, lifetime: LifetimeRefId) -> Lifetime {
+ pub(crate) fn lower_lifetime(&self, lifetime: LifetimeRefId) -> Lifetime {
match self.resolver.resolve_lifetime(&self.store[lifetime]) {
Some(resolution) => match resolution {
LifetimeNs::Static => static_lifetime(),