mirror of https://github.com/rust-lang/rust.git
Rename AstConv to HIR ty lowering
This includes updating astconv-related items and a few local variables.
This commit is contained in:
parent
b57a10c39d
commit
05d48b936f
|
@ -12,13 +12,13 @@ use rustc_trait_selection::traits;
|
||||||
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter};
|
use crate::astconv::{HirTyLowerer, OnlySelfBounds, PredicateFilter};
|
||||||
use crate::bounds::Bounds;
|
use crate::bounds::Bounds;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
|
||||||
impl<'tcx> dyn AstConv<'tcx> + '_ {
|
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
/// Sets `implicitly_sized` to true on `Bounds` if necessary
|
/// Sets `implicitly_sized` to true on `Bounds` if necessary
|
||||||
pub(crate) fn add_implicitly_sized(
|
pub(crate) fn add_sized_bound(
|
||||||
&self,
|
&self,
|
||||||
bounds: &mut Bounds<'tcx>,
|
bounds: &mut Bounds<'tcx>,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
|
@ -117,7 +117,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
|
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
|
||||||
/// for more details.
|
/// for more details.
|
||||||
#[instrument(level = "debug", skip(self, ast_bounds, bounds))]
|
#[instrument(level = "debug", skip(self, ast_bounds, bounds))]
|
||||||
pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
|
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
|
||||||
&self,
|
&self,
|
||||||
param_ty: Ty<'tcx>,
|
param_ty: Ty<'tcx>,
|
||||||
ast_bounds: I,
|
ast_bounds: I,
|
||||||
|
@ -145,7 +145,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
hir::TraitBoundModifier::Maybe => continue,
|
hir::TraitBoundModifier::Maybe => continue,
|
||||||
};
|
};
|
||||||
let _ = self.instantiate_poly_trait_ref(
|
let _ = self.lower_poly_trait_ref(
|
||||||
&poly_trait_ref.trait_ref,
|
&poly_trait_ref.trait_ref,
|
||||||
poly_trait_ref.span,
|
poly_trait_ref.span,
|
||||||
constness,
|
constness,
|
||||||
|
@ -156,7 +156,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
hir::GenericBound::Outlives(lifetime) => {
|
hir::GenericBound::Outlives(lifetime) => {
|
||||||
let region = self.ast_region_to_region(lifetime, None);
|
let region = self.lower_lifetime(lifetime, None);
|
||||||
bounds.push_region_bound(
|
bounds.push_region_bound(
|
||||||
self.tcx(),
|
self.tcx(),
|
||||||
ty::Binder::bind_with_vars(
|
ty::Binder::bind_with_vars(
|
||||||
|
@ -186,7 +186,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`.
|
/// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`.
|
||||||
///
|
///
|
||||||
/// `span` should be the declaration size of the parameter.
|
/// `span` should be the declaration size of the parameter.
|
||||||
pub(crate) fn compute_bounds(
|
pub(crate) fn lower_mono_bounds(
|
||||||
&self,
|
&self,
|
||||||
param_ty: Ty<'tcx>,
|
param_ty: Ty<'tcx>,
|
||||||
ast_bounds: &[hir::GenericBound<'tcx>],
|
ast_bounds: &[hir::GenericBound<'tcx>],
|
||||||
|
@ -201,7 +201,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => OnlySelfBounds(true),
|
PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => OnlySelfBounds(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.add_bounds(
|
self.lower_poly_bounds(
|
||||||
param_ty,
|
param_ty,
|
||||||
ast_bounds.iter().filter(|bound| match filter {
|
ast_bounds.iter().filter(|bound| match filter {
|
||||||
PredicateFilter::All
|
PredicateFilter::All
|
||||||
|
@ -234,7 +234,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside*
|
/// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside*
|
||||||
/// the binder (e.g., `&'a u32`) and hence may reference bound regions.
|
/// the binder (e.g., `&'a u32`) and hence may reference bound regions.
|
||||||
#[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))]
|
#[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))]
|
||||||
pub(super) fn add_predicates_for_ast_type_binding(
|
pub(super) fn lower_assoc_item_binding(
|
||||||
&self,
|
&self,
|
||||||
hir_ref_id: hir::HirId,
|
hir_ref_id: hir::HirId,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
|
@ -272,7 +272,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
ty::AssocKind::Type
|
ty::AssocKind::Type
|
||||||
};
|
};
|
||||||
|
|
||||||
let candidate = if self.trait_defines_associated_item_named(
|
let candidate = if self.probe_trait_that_defines_assoc_item(
|
||||||
trait_ref.def_id(),
|
trait_ref.def_id(),
|
||||||
assoc_kind,
|
assoc_kind,
|
||||||
binding.ident,
|
binding.ident,
|
||||||
|
@ -282,7 +282,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we have to walk through the supertraits to find
|
// Otherwise, we have to walk through the supertraits to find
|
||||||
// one that does define it.
|
// one that does define it.
|
||||||
self.one_bound_for_assoc_item(
|
self.probe_single_bound_for_assoc_item(
|
||||||
|| traits::supertraits(tcx, trait_ref),
|
|| traits::supertraits(tcx, trait_ref),
|
||||||
trait_ref.skip_binder().print_only_trait_name(),
|
trait_ref.skip_binder().print_only_trait_name(),
|
||||||
None,
|
None,
|
||||||
|
@ -417,7 +417,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
infer_args: false,
|
infer_args: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let alias_args = self.create_args_for_associated_item(
|
let alias_args = self.lower_generic_args_of_assoc_item(
|
||||||
path_span,
|
path_span,
|
||||||
assoc_item.def_id,
|
assoc_item.def_id,
|
||||||
&item_segment,
|
&item_segment,
|
||||||
|
@ -451,7 +451,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
hir::TypeBindingKind::Equality { term } => {
|
hir::TypeBindingKind::Equality { term } => {
|
||||||
let term = match term {
|
let term = match term {
|
||||||
hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(),
|
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
|
||||||
hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(),
|
hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// for the `Self` type.
|
// for the `Self` type.
|
||||||
if !only_self_bounds.0 {
|
if !only_self_bounds.0 {
|
||||||
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
|
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
|
||||||
self.add_bounds(
|
self.lower_poly_bounds(
|
||||||
param_ty,
|
param_ty,
|
||||||
ast_bounds.iter(),
|
ast_bounds.iter(),
|
||||||
bounds,
|
bounds,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::astconv::AstConv;
|
use crate::astconv::HirTyLowerer;
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
self, AssocTypeBindingNotAllowed, ManualImplementation, MissingTypeParams,
|
self, AssocTypeBindingNotAllowed, ManualImplementation, MissingTypeParams,
|
||||||
ParenthesizedFnTraitExpansion,
|
ParenthesizedFnTraitExpansion,
|
||||||
|
@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||||
use rustc_trait_selection::traits::object_safety_violations_for_assoc_item;
|
use rustc_trait_selection::traits::object_safety_violations_for_assoc_item;
|
||||||
|
|
||||||
impl<'tcx> dyn AstConv<'tcx> + '_ {
|
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
/// On missing type parameters, emit an E0393 error and provide a structured suggestion using
|
/// On missing type parameters, emit an E0393 error and provide a structured suggestion using
|
||||||
/// the type parameter's name as a placeholder.
|
/// the type parameter's name as a placeholder.
|
||||||
pub(crate) fn complain_about_missing_type_params(
|
pub(crate) fn complain_about_missing_type_params(
|
||||||
|
@ -311,7 +311,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// FIXME(associated_const_equality): This has quite a few false positives and negatives.
|
// FIXME(associated_const_equality): This has quite a few false positives and negatives.
|
||||||
let wrap_in_braces_sugg = if let Some(binding) = binding
|
let wrap_in_braces_sugg = if let Some(binding) = binding
|
||||||
&& let hir::TypeBindingKind::Equality { term: hir::Term::Ty(hir_ty) } = binding.kind
|
&& let hir::TypeBindingKind::Equality { term: hir::Term::Ty(hir_ty) } = binding.kind
|
||||||
&& let ty = self.ast_ty_to_ty(hir_ty)
|
&& let ty = self.lower_ty(hir_ty)
|
||||||
&& (ty.is_enum() || ty.references_error())
|
&& (ty.is_enum() || ty.references_error())
|
||||||
&& tcx.features().associated_const_equality
|
&& tcx.features().associated_const_equality
|
||||||
{
|
{
|
||||||
|
@ -349,7 +349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn report_ambiguous_associated_type(
|
pub(super) fn report_ambiguous_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
types: &[String],
|
types: &[String],
|
||||||
|
@ -458,7 +458,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
reported
|
reported
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn complain_about_ambiguous_inherent_assoc_type(
|
pub(crate) fn complain_about_ambiguous_inherent_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
candidates: Vec<DefId>,
|
candidates: Vec<DefId>,
|
||||||
|
@ -471,14 +471,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
"multiple applicable items in scope"
|
"multiple applicable items in scope"
|
||||||
);
|
);
|
||||||
err.span_label(name.span, format!("multiple `{name}` found"));
|
err.span_label(name.span, format!("multiple `{name}` found"));
|
||||||
self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span);
|
self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span);
|
||||||
let reported = err.emit();
|
let reported = err.emit();
|
||||||
self.set_tainted_by_errors(reported);
|
self.set_tainted_by_errors(reported);
|
||||||
reported
|
reported
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
|
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
|
||||||
fn note_ambiguous_inherent_assoc_type(
|
fn note_ambiguous_inherent_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
candidates: Vec<DefId>,
|
candidates: Vec<DefId>,
|
||||||
|
@ -521,7 +521,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(inherent_associated_types): Find similarly named associated types and suggest them.
|
// FIXME(inherent_associated_types): Find similarly named associated types and suggest them.
|
||||||
pub(crate) fn complain_about_inherent_assoc_type_not_found(
|
pub(crate) fn complain_about_inherent_assoc_ty_not_found(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
|
@ -697,7 +697,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// reasonable suggestion on how to write it. For the case of multiple associated types in the
|
/// reasonable suggestion on how to write it. For the case of multiple associated types in the
|
||||||
/// same trait bound have the same name (as they come from different supertraits), we instead
|
/// same trait bound have the same name (as they come from different supertraits), we instead
|
||||||
/// emit a generic note suggesting using a `where` clause to constraint instead.
|
/// emit a generic note suggesting using a `where` clause to constraint instead.
|
||||||
pub(crate) fn complain_about_missing_associated_types(
|
pub(crate) fn complain_about_missing_assoc_tys(
|
||||||
&self,
|
&self,
|
||||||
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
|
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
|
||||||
potential_assoc_types: Vec<Span>,
|
potential_assoc_types: Vec<Span>,
|
||||||
|
@ -1027,7 +1027,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emits an error regarding forbidden type binding associations
|
/// Emits an error regarding forbidden type binding associations
|
||||||
pub fn prohibit_assoc_ty_binding(
|
pub fn prohibit_assoc_item_binding(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
segment: Option<(&hir::PathSegment<'_>, Span)>,
|
segment: Option<(&hir::PathSegment<'_>, Span)>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::IsMethodCall;
|
use super::IsMethodCall;
|
||||||
use crate::astconv::{
|
use crate::astconv::{
|
||||||
errors::prohibit_assoc_ty_binding, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound,
|
errors::prohibit_assoc_item_binding, ExplicitLateBound, GenericArgCountMismatch,
|
||||||
GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
|
GenericArgCountResult, GenericArgPosition, GenericArgsLowerer,
|
||||||
};
|
};
|
||||||
use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs};
|
use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs};
|
||||||
use rustc_ast::ast::ParamKindOrd;
|
use rustc_ast::ast::ParamKindOrd;
|
||||||
|
@ -172,14 +172,14 @@ fn generic_arg_mismatch_err(
|
||||||
/// instantiate a `GenericArg`.
|
/// instantiate a `GenericArg`.
|
||||||
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
|
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
|
||||||
/// creates a suitable inference variable.
|
/// creates a suitable inference variable.
|
||||||
pub fn create_args_for_parent_generic_args<'tcx: 'a, 'a>(
|
pub fn lower_generic_args<'tcx: 'a, 'a>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
parent_args: &[ty::GenericArg<'tcx>],
|
parent_args: &[ty::GenericArg<'tcx>],
|
||||||
has_self: bool,
|
has_self: bool,
|
||||||
self_ty: Option<Ty<'tcx>>,
|
self_ty: Option<Ty<'tcx>>,
|
||||||
arg_count: &GenericArgCountResult,
|
arg_count: &GenericArgCountResult,
|
||||||
ctx: &mut impl CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>,
|
ctx: &mut impl GenericArgsLowerer<'a, 'tcx>,
|
||||||
) -> GenericArgsRef<'tcx> {
|
) -> GenericArgsRef<'tcx> {
|
||||||
// Collect the segments of the path; we need to instantiate arguments
|
// Collect the segments of the path; we need to instantiate arguments
|
||||||
// for parameters throughout the entire path (wherever there are
|
// for parameters throughout the entire path (wherever there are
|
||||||
|
@ -456,7 +456,7 @@ pub(crate) fn check_generic_arg_count(
|
||||||
if gen_pos != GenericArgPosition::Type
|
if gen_pos != GenericArgPosition::Type
|
||||||
&& let Some(b) = gen_args.bindings.first()
|
&& let Some(b) = gen_args.bindings.first()
|
||||||
{
|
{
|
||||||
prohibit_assoc_ty_binding(tcx, b.span, None);
|
prohibit_assoc_item_binding(tcx, b.span, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let explicit_late_bound =
|
let explicit_late_bound =
|
||||||
|
|
|
@ -6,9 +6,9 @@ use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
|
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
|
||||||
|
|
||||||
use super::AstConv;
|
use super::HirTyLowerer;
|
||||||
|
|
||||||
impl<'tcx> dyn AstConv<'tcx> + '_ {
|
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
/// Make sure that we are in the condition to suggest the blanket implementation.
|
/// Make sure that we are in the condition to suggest the blanket implementation.
|
||||||
pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>(
|
pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -8,8 +8,8 @@ pub mod generics;
|
||||||
mod lint;
|
mod lint;
|
||||||
mod object_safety;
|
mod object_safety;
|
||||||
|
|
||||||
use crate::astconv::errors::prohibit_assoc_ty_binding;
|
use crate::astconv::errors::prohibit_assoc_item_binding;
|
||||||
use crate::astconv::generics::{check_generic_arg_count, create_args_for_parent_generic_args};
|
use crate::astconv::generics::{check_generic_arg_count, lower_generic_args};
|
||||||
use crate::bounds::Bounds;
|
use crate::bounds::Bounds;
|
||||||
use crate::collect::HirPlaceholderCollector;
|
use crate::collect::HirPlaceholderCollector;
|
||||||
use crate::errors::AmbiguousLifetimeBound;
|
use crate::errors::AmbiguousLifetimeBound;
|
||||||
|
@ -44,7 +44,7 @@ use std::fmt::Display;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PathSeg(pub DefId, pub usize);
|
pub struct GenericPathSegment(pub DefId, pub usize);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct OnlySelfBounds(pub bool);
|
pub struct OnlySelfBounds(pub bool);
|
||||||
|
@ -67,7 +67,7 @@ pub enum PredicateFilter {
|
||||||
SelfAndAssociatedTypeBounds,
|
SelfAndAssociatedTypeBounds,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AstConv<'tcx> {
|
pub trait HirTyLowerer<'tcx> {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx>;
|
fn tcx(&self) -> TyCtxt<'tcx>;
|
||||||
|
|
||||||
fn item_def_id(&self) -> DefId;
|
fn item_def_id(&self) -> DefId;
|
||||||
|
@ -84,7 +84,7 @@ pub trait AstConv<'tcx> {
|
||||||
/// but this can lead to cycle errors. The problem is that we have
|
/// but this can lead to cycle errors. The problem is that we have
|
||||||
/// to do this resolution *in order to create the predicates in
|
/// to do this resolution *in order to create the predicates in
|
||||||
/// the first place*. Hence, we have this "special pass".
|
/// the first place*. Hence, we have this "special pass".
|
||||||
fn get_type_parameter_bounds(
|
fn probe_ty_param_bounds(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
|
@ -99,7 +99,7 @@ pub trait AstConv<'tcx> {
|
||||||
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
|
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
|
||||||
|
|
||||||
/// Returns `true` if `_` is allowed in type signatures in the current context.
|
/// Returns `true` if `_` is allowed in type signatures in the current context.
|
||||||
fn allow_ty_infer(&self) -> bool;
|
fn allow_infer(&self) -> bool;
|
||||||
|
|
||||||
/// Returns the const to use when a const is omitted.
|
/// Returns the const to use when a const is omitted.
|
||||||
fn ct_infer(
|
fn ct_infer(
|
||||||
|
@ -116,7 +116,7 @@ pub trait AstConv<'tcx> {
|
||||||
/// signatures for that reason. In a function body, we can always
|
/// signatures for that reason. In a function body, we can always
|
||||||
/// handle it because we can use inference variables to remove the
|
/// handle it because we can use inference variables to remove the
|
||||||
/// late-bound regions.
|
/// late-bound regions.
|
||||||
fn projected_ty_from_poly_trait_ref(
|
fn lower_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
|
@ -139,7 +139,7 @@ pub trait AstConv<'tcx> {
|
||||||
|
|
||||||
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
|
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
|
||||||
|
|
||||||
fn astconv(&self) -> &dyn AstConv<'tcx>
|
fn lowerer(&self) -> &dyn HirTyLowerer<'tcx>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
@ -197,7 +197,7 @@ pub struct GenericArgCountResult {
|
||||||
pub correct: Result<(), GenericArgCountMismatch>,
|
pub correct: Result<(), GenericArgCountMismatch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> {
|
pub trait GenericArgsLowerer<'a, 'tcx> {
|
||||||
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool);
|
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool);
|
||||||
|
|
||||||
fn provided_kind(
|
fn provided_kind(
|
||||||
|
@ -214,9 +214,9 @@ pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> {
|
||||||
) -> ty::GenericArg<'tcx>;
|
) -> ty::GenericArg<'tcx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> dyn AstConv<'tcx> + '_ {
|
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
pub fn ast_region_to_region(
|
pub fn lower_lifetime(
|
||||||
&self,
|
&self,
|
||||||
lifetime: &hir::Lifetime,
|
lifetime: &hir::Lifetime,
|
||||||
def: Option<&ty::GenericParamDef>,
|
def: Option<&ty::GenericParamDef>,
|
||||||
|
@ -273,13 +273,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
/// Given a path `path` that refers to an item `I` with the declared generics `decl_generics`,
|
/// Given a path `path` that refers to an item `I` with the declared generics `decl_generics`,
|
||||||
/// returns an appropriate set of generic arguments for this particular reference to `I`.
|
/// returns an appropriate set of generic arguments for this particular reference to `I`.
|
||||||
pub fn ast_path_args_for_ty(
|
pub fn lower_generic_args_of_path_segment(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
item_segment: &hir::PathSegment<'tcx>,
|
item_segment: &hir::PathSegment<'tcx>,
|
||||||
) -> GenericArgsRef<'tcx> {
|
) -> GenericArgsRef<'tcx> {
|
||||||
let (args, _) = self.create_args_for_ast_path(
|
let (args, _) = self.lower_generic_args_of_path(
|
||||||
span,
|
span,
|
||||||
def_id,
|
def_id,
|
||||||
&[],
|
&[],
|
||||||
|
@ -288,9 +288,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
ty::BoundConstness::NotConst,
|
ty::BoundConstness::NotConst,
|
||||||
);
|
);
|
||||||
if let Some(b) = item_segment.args().bindings.first() {
|
if let Some(b) = item_segment.args().bindings.first() {
|
||||||
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span)));
|
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
|
||||||
}
|
}
|
||||||
|
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +327,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// type itself: `['a]`. The returned `GenericArgsRef` concatenates these two
|
/// type itself: `['a]`. The returned `GenericArgsRef` concatenates these two
|
||||||
/// lists: `[Vec<u8>, u8, 'a]`.
|
/// lists: `[Vec<u8>, u8, 'a]`.
|
||||||
#[instrument(level = "debug", skip(self, span), ret)]
|
#[instrument(level = "debug", skip(self, span), ret)]
|
||||||
fn create_args_for_ast_path(
|
fn lower_generic_args_of_path(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
|
@ -381,8 +380,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
return (tcx.mk_args(parent_args), arg_count);
|
return (tcx.mk_args(parent_args), arg_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InstantiationsForAstPathCtxt<'a, 'tcx> {
|
struct GenericArgsCtxt<'a, 'tcx> {
|
||||||
astconv: &'a dyn AstConv<'tcx>,
|
lowerer: &'a dyn HirTyLowerer<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
generic_args: &'a GenericArgs<'tcx>,
|
generic_args: &'a GenericArgs<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -390,9 +389,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
infer_args: bool,
|
infer_args: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>
|
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
|
||||||
for InstantiationsForAstPathCtxt<'a, 'tcx>
|
|
||||||
{
|
|
||||||
fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool) {
|
fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool) {
|
||||||
if did == self.def_id {
|
if did == self.def_id {
|
||||||
(Some(self.generic_args), self.infer_args)
|
(Some(self.generic_args), self.infer_args)
|
||||||
|
@ -407,7 +404,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
param: &ty::GenericParamDef,
|
param: &ty::GenericParamDef,
|
||||||
arg: &GenericArg<'tcx>,
|
arg: &GenericArg<'tcx>,
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
let tcx = self.astconv.tcx();
|
let tcx = self.lowerer.tcx();
|
||||||
|
|
||||||
let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| {
|
let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| {
|
||||||
if has_default {
|
if has_default {
|
||||||
|
@ -426,17 +423,17 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) {
|
if let (hir::TyKind::Infer, false) = (&ty.kind, self.lowerer.allow_infer()) {
|
||||||
self.inferred_params.push(ty.span);
|
self.inferred_params.push(ty.span);
|
||||||
Ty::new_misc_error(tcx).into()
|
Ty::new_misc_error(tcx).into()
|
||||||
} else {
|
} else {
|
||||||
self.astconv.ast_ty_to_ty(ty).into()
|
self.lowerer.lower_ty(ty).into()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match (¶m.kind, arg) {
|
match (¶m.kind, arg) {
|
||||||
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
||||||
self.astconv.ast_region_to_region(lt, Some(param)).into()
|
self.lowerer.lower_lifetime(lt, Some(param)).into()
|
||||||
}
|
}
|
||||||
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
|
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
|
||||||
handle_ty_args(has_default, ty)
|
handle_ty_args(has_default, ty)
|
||||||
|
@ -455,8 +452,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.type_of(param.def_id)
|
.type_of(param.def_id)
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic");
|
.expect("const parameter types cannot be generic");
|
||||||
if self.astconv.allow_ty_infer() {
|
if self.lowerer.allow_infer() {
|
||||||
self.astconv.ct_infer(ty, Some(param), inf.span).into()
|
self.lowerer.ct_infer(ty, Some(param), inf.span).into()
|
||||||
} else {
|
} else {
|
||||||
self.inferred_params.push(inf.span);
|
self.inferred_params.push(inf.span);
|
||||||
ty::Const::new_misc_error(tcx, ty).into()
|
ty::Const::new_misc_error(tcx, ty).into()
|
||||||
|
@ -475,10 +472,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
param: &ty::GenericParamDef,
|
param: &ty::GenericParamDef,
|
||||||
infer_args: bool,
|
infer_args: bool,
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
let tcx = self.astconv.tcx();
|
let tcx = self.lowerer.tcx();
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamDefKind::Lifetime => self
|
GenericParamDefKind::Lifetime => self
|
||||||
.astconv
|
.lowerer
|
||||||
.re_infer(Some(param), self.span)
|
.re_infer(Some(param), self.span)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
debug!(?param, "unelided lifetime in signature");
|
debug!(?param, "unelided lifetime in signature");
|
||||||
|
@ -504,7 +501,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into()
|
tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into()
|
||||||
} else if infer_args {
|
} else if infer_args {
|
||||||
self.astconv.ty_infer(Some(param), self.span).into()
|
self.lowerer.ty_infer(Some(param), self.span).into()
|
||||||
} else {
|
} else {
|
||||||
// We've already errored above about the mismatch.
|
// We've already errored above about the mismatch.
|
||||||
Ty::new_misc_error(tcx).into()
|
Ty::new_misc_error(tcx).into()
|
||||||
|
@ -526,7 +523,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else {
|
||||||
if infer_args {
|
if infer_args {
|
||||||
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
self.lowerer.ct_infer(ty, Some(param), self.span).into()
|
||||||
} else {
|
} else {
|
||||||
// We've already errored above about the mismatch.
|
// We've already errored above about the mismatch.
|
||||||
ty::Const::new_misc_error(tcx, ty).into()
|
ty::Const::new_misc_error(tcx, ty).into()
|
||||||
|
@ -537,8 +534,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut args_ctx = InstantiationsForAstPathCtxt {
|
let mut args_ctx = GenericArgsCtxt {
|
||||||
astconv: self,
|
lowerer: self,
|
||||||
def_id,
|
def_id,
|
||||||
span,
|
span,
|
||||||
generic_args: segment.args(),
|
generic_args: segment.args(),
|
||||||
|
@ -557,7 +554,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
arg_count.correct =
|
arg_count.correct =
|
||||||
Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] });
|
Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] });
|
||||||
}
|
}
|
||||||
let args = create_args_for_parent_generic_args(
|
let args = lower_generic_args(
|
||||||
tcx,
|
tcx,
|
||||||
def_id,
|
def_id,
|
||||||
parent_args,
|
parent_args,
|
||||||
|
@ -570,7 +567,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
(args, arg_count)
|
(args, arg_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_args_for_associated_item(
|
pub fn lower_generic_args_of_assoc_item(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
|
@ -581,7 +578,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
"create_args_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
|
"create_args_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
|
||||||
span, item_def_id, item_segment
|
span, item_def_id, item_segment
|
||||||
);
|
);
|
||||||
let (args, _) = self.create_args_for_ast_path(
|
let (args, _) = self.lower_generic_args_of_path(
|
||||||
span,
|
span,
|
||||||
item_def_id,
|
item_def_id,
|
||||||
parent_args,
|
parent_args,
|
||||||
|
@ -589,9 +586,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
None,
|
None,
|
||||||
ty::BoundConstness::NotConst,
|
ty::BoundConstness::NotConst,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(b) = item_segment.args().bindings.first() {
|
if let Some(b) = item_segment.args().bindings.first() {
|
||||||
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span)));
|
prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span)));
|
||||||
}
|
}
|
||||||
|
|
||||||
args
|
args
|
||||||
|
@ -603,14 +599,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
///
|
///
|
||||||
/// If the `projections` argument is `None`, then assoc type bindings like `Foo<T = X>`
|
/// If the `projections` argument is `None`, then assoc type bindings like `Foo<T = X>`
|
||||||
/// are disallowed. Otherwise, they are pushed onto the vector given.
|
/// are disallowed. Otherwise, they are pushed onto the vector given.
|
||||||
pub fn instantiate_mono_trait_ref(
|
pub fn lower_impl_trait_ref(
|
||||||
&self,
|
&self,
|
||||||
trait_ref: &hir::TraitRef<'tcx>,
|
trait_ref: &hir::TraitRef<'tcx>,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
) -> ty::TraitRef<'tcx> {
|
) -> ty::TraitRef<'tcx> {
|
||||||
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
|
self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
|
||||||
|
|
||||||
self.ast_path_to_mono_trait_ref(
|
self.lower_mono_trait_ref(
|
||||||
trait_ref.path.span,
|
trait_ref.path.span,
|
||||||
trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
|
trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
|
||||||
self_ty,
|
self_ty,
|
||||||
|
@ -640,7 +636,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
|
/// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
|
||||||
/// however.
|
/// however.
|
||||||
#[instrument(level = "debug", skip(self, span, constness, bounds))]
|
#[instrument(level = "debug", skip(self, span, constness, bounds))]
|
||||||
pub(crate) fn instantiate_poly_trait_ref(
|
pub(crate) fn lower_poly_trait_ref(
|
||||||
&self,
|
&self,
|
||||||
trait_ref: &hir::TraitRef<'tcx>,
|
trait_ref: &hir::TraitRef<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -653,10 +649,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
|
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
|
||||||
let trait_segment = trait_ref.path.segments.last().unwrap();
|
let trait_segment = trait_ref.path.segments.last().unwrap();
|
||||||
|
|
||||||
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
|
self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
|
||||||
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, false);
|
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, false);
|
||||||
|
|
||||||
let (generic_args, arg_count) = self.create_args_for_ast_path(
|
let (generic_args, arg_count) = self.lower_generic_args_of_path(
|
||||||
trait_ref.path.span,
|
trait_ref.path.span,
|
||||||
trait_def_id,
|
trait_def_id,
|
||||||
&[],
|
&[],
|
||||||
|
@ -691,7 +687,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specify type to assert that error was already reported in `Err` case.
|
// Specify type to assert that error was already reported in `Err` case.
|
||||||
let _: Result<_, ErrorGuaranteed> = self.add_predicates_for_ast_type_binding(
|
let _: Result<_, ErrorGuaranteed> = self.lower_assoc_item_binding(
|
||||||
trait_ref.hir_ref_id,
|
trait_ref.hir_ref_id,
|
||||||
poly_trait_ref,
|
poly_trait_ref,
|
||||||
binding,
|
binding,
|
||||||
|
@ -706,7 +702,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
arg_count
|
arg_count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ast_path_to_mono_trait_ref(
|
fn lower_mono_trait_ref(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
|
@ -718,7 +714,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
) -> ty::TraitRef<'tcx> {
|
) -> ty::TraitRef<'tcx> {
|
||||||
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
|
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
|
||||||
|
|
||||||
let (generic_args, _) = self.create_args_for_ast_path(
|
let (generic_args, _) = self.lower_generic_args_of_path(
|
||||||
span,
|
span,
|
||||||
trait_def_id,
|
trait_def_id,
|
||||||
&[],
|
&[],
|
||||||
|
@ -727,12 +723,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
constness,
|
constness,
|
||||||
);
|
);
|
||||||
if let Some(b) = trait_segment.args().bindings.first() {
|
if let Some(b) = trait_segment.args().bindings.first() {
|
||||||
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span)));
|
prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span)));
|
||||||
}
|
}
|
||||||
ty::TraitRef::new(self.tcx(), trait_def_id, generic_args)
|
ty::TraitRef::new(self.tcx(), trait_def_id, generic_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trait_defines_associated_item_named(
|
fn probe_trait_that_defines_assoc_item(
|
||||||
&self,
|
&self,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
assoc_kind: ty::AssocKind,
|
assoc_kind: ty::AssocKind,
|
||||||
|
@ -744,14 +740,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.is_some()
|
.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ast_path_to_ty(
|
fn lower_path_segment(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
item_segment: &hir::PathSegment<'tcx>,
|
item_segment: &hir::PathSegment<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let args = self.ast_path_args_for_ty(span, did, item_segment);
|
let args = self.lower_generic_args_of_path_segment(span, did, item_segment);
|
||||||
|
|
||||||
if let DefKind::TyAlias = tcx.def_kind(did)
|
if let DefKind::TyAlias = tcx.def_kind(did)
|
||||||
&& tcx.type_alias_is_lazy(did)
|
&& tcx.type_alias_is_lazy(did)
|
||||||
|
@ -770,7 +766,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// given by `assoc_name`. `ty_param_def_id` is the `DefId` of the type parameter
|
// given by `assoc_name`. `ty_param_def_id` is the `DefId` of the type parameter
|
||||||
// This function will fail if there are no suitable bounds or there is
|
// This function will fail if there are no suitable bounds or there is
|
||||||
// any ambiguity.
|
// any ambiguity.
|
||||||
fn find_bound_for_assoc_item(
|
fn probe_single_ty_param_bound_for_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
ty_param_def_id: LocalDefId,
|
ty_param_def_id: LocalDefId,
|
||||||
assoc_name: Ident,
|
assoc_name: Ident,
|
||||||
|
@ -783,13 +779,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
ty_param_def_id, assoc_name, span,
|
ty_param_def_id, assoc_name, span,
|
||||||
);
|
);
|
||||||
|
|
||||||
let predicates =
|
let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name).predicates;
|
||||||
&self.get_type_parameter_bounds(span, ty_param_def_id, assoc_name).predicates;
|
|
||||||
|
|
||||||
debug!("find_bound_for_assoc_item: predicates={:#?}", predicates);
|
debug!("find_bound_for_assoc_item: predicates={:#?}", predicates);
|
||||||
|
|
||||||
let param_name = tcx.hir().ty_param_name(ty_param_def_id);
|
let param_name = tcx.hir().ty_param_name(ty_param_def_id);
|
||||||
self.one_bound_for_assoc_item(
|
self.probe_single_bound_for_assoc_item(
|
||||||
|| {
|
|| {
|
||||||
traits::transitive_bounds_that_define_assoc_item(
|
traits::transitive_bounds_that_define_assoc_item(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -811,7 +806,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// Checks that `bounds` contains exactly one element and reports appropriate
|
// Checks that `bounds` contains exactly one element and reports appropriate
|
||||||
// errors otherwise.
|
// errors otherwise.
|
||||||
#[instrument(level = "debug", skip(self, all_candidates, ty_param_name, binding), ret)]
|
#[instrument(level = "debug", skip(self, all_candidates, ty_param_name, binding), ret)]
|
||||||
fn one_bound_for_assoc_item<I>(
|
fn probe_single_bound_for_assoc_item<I>(
|
||||||
&self,
|
&self,
|
||||||
all_candidates: impl Fn() -> I,
|
all_candidates: impl Fn() -> I,
|
||||||
ty_param_name: impl Display,
|
ty_param_name: impl Display,
|
||||||
|
@ -827,7 +822,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
let mut matching_candidates = all_candidates().filter(|r| {
|
let mut matching_candidates = all_candidates().filter(|r| {
|
||||||
self.trait_defines_associated_item_named(r.def_id(), assoc_kind, assoc_name)
|
self.probe_trait_that_defines_assoc_item(r.def_id(), assoc_kind, assoc_name)
|
||||||
});
|
});
|
||||||
|
|
||||||
let Some(bound) = matching_candidates.next() else {
|
let Some(bound) = matching_candidates.next() else {
|
||||||
|
@ -886,7 +881,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
match binding.kind {
|
match binding.kind {
|
||||||
hir::TypeBindingKind::Equality { term } => {
|
hir::TypeBindingKind::Equality { term } => {
|
||||||
let term: ty::Term<'_> = match term {
|
let term: ty::Term<'_> = match term {
|
||||||
hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(),
|
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
|
||||||
hir::Term::Const(ct) => {
|
hir::Term::Const(ct) => {
|
||||||
ty::Const::from_anon_const(tcx, ct.def_id).into()
|
ty::Const::from_anon_const(tcx, ct.def_id).into()
|
||||||
}
|
}
|
||||||
|
@ -941,7 +936,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// NOTE: When this function starts resolving `Trait::AssocTy` successfully
|
// NOTE: When this function starts resolving `Trait::AssocTy` successfully
|
||||||
// it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
|
// it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
|
||||||
#[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)]
|
#[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)]
|
||||||
pub fn associated_path_to_ty(
|
pub fn lower_assoc_path(
|
||||||
&self,
|
&self,
|
||||||
hir_ref_id: hir::HirId,
|
hir_ref_id: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -969,7 +964,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
if let Some(variant_def) = variant_def {
|
if let Some(variant_def) = variant_def {
|
||||||
if permit_variants {
|
if permit_variants {
|
||||||
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
|
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
|
||||||
self.prohibit_generics(slice::from_ref(assoc_segment).iter(), |err| {
|
self.prohibit_generic_args(slice::from_ref(assoc_segment).iter(), |err| {
|
||||||
err.note("enum variants can't have type parameters");
|
err.note("enum variants can't have type parameters");
|
||||||
let type_name = tcx.item_name(adt_def.did());
|
let type_name = tcx.item_name(adt_def.did());
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
|
@ -1069,7 +1064,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((ty, did)) = self.lookup_inherent_assoc_ty(
|
if let Some((ty, did)) = self.probe_inherent_assoc_ty(
|
||||||
assoc_ident,
|
assoc_ident,
|
||||||
assoc_segment,
|
assoc_segment,
|
||||||
adt_def.did(),
|
adt_def.did(),
|
||||||
|
@ -1092,7 +1087,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
tcx.dcx().span_bug(span, "expected cycle error");
|
tcx.dcx().span_bug(span, "expected cycle error");
|
||||||
};
|
};
|
||||||
|
|
||||||
self.one_bound_for_assoc_item(
|
self.probe_single_bound_for_assoc_item(
|
||||||
|| {
|
|| {
|
||||||
traits::supertraits(
|
traits::supertraits(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -1110,7 +1105,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
(
|
(
|
||||||
&ty::Param(_),
|
&ty::Param(_),
|
||||||
Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did),
|
Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did),
|
||||||
) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?,
|
) => self.probe_single_ty_param_bound_for_assoc_ty(
|
||||||
|
param_did.expect_local(),
|
||||||
|
assoc_ident,
|
||||||
|
span,
|
||||||
|
)?,
|
||||||
_ => {
|
_ => {
|
||||||
let reported = if variant_resolution.is_some() {
|
let reported = if variant_resolution.is_some() {
|
||||||
// Variant in type position
|
// Variant in type position
|
||||||
|
@ -1172,7 +1171,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
self.probe_traits_that_match_assoc_ty(qself_ty, assoc_ident);
|
self.probe_traits_that_match_assoc_ty(qself_ty, assoc_ident);
|
||||||
|
|
||||||
// Don't print `ty::Error` to the user.
|
// Don't print `ty::Error` to the user.
|
||||||
self.report_ambiguous_associated_type(
|
self.report_ambiguous_assoc_ty(
|
||||||
span,
|
span,
|
||||||
&[qself_ty.to_string()],
|
&[qself_ty.to_string()],
|
||||||
&traits,
|
&traits,
|
||||||
|
@ -1185,8 +1184,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
};
|
};
|
||||||
|
|
||||||
let trait_did = bound.def_id();
|
let trait_did = bound.def_id();
|
||||||
let assoc_ty_did = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap();
|
let assoc_ty_did = self.probe_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap();
|
||||||
let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound);
|
let ty = self.lower_assoc_ty(span, assoc_ty_did, assoc_segment, bound);
|
||||||
|
|
||||||
if let Some(variant_def_id) = variant_resolution {
|
if let Some(variant_def_id) = variant_resolution {
|
||||||
tcx.node_span_lint(
|
tcx.node_span_lint(
|
||||||
|
@ -1220,7 +1219,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
Ok((ty, DefKind::AssocTy, assoc_ty_did))
|
Ok((ty, DefKind::AssocTy, assoc_ty_did))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_inherent_assoc_ty(
|
fn probe_inherent_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
segment: &hir::PathSegment<'tcx>,
|
segment: &hir::PathSegment<'tcx>,
|
||||||
|
@ -1243,7 +1242,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
let candidates: Vec<_> = tcx
|
let candidates: Vec<_> = tcx
|
||||||
.inherent_impls(adt_did)?
|
.inherent_impls(adt_did)?
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&impl_| Some((impl_, self.lookup_assoc_ty_unchecked(name, block, impl_)?)))
|
.filter_map(|&impl_| Some((impl_, self.probe_assoc_ty_unchecked(name, block, impl_)?)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if candidates.is_empty() {
|
if candidates.is_empty() {
|
||||||
|
@ -1293,7 +1292,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// `create_args_for_associated_item`. Modify the latter instead (or sth. similar) to
|
// `create_args_for_associated_item`. Modify the latter instead (or sth. similar) to
|
||||||
// not require the parent args logic.
|
// not require the parent args logic.
|
||||||
let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_);
|
let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_);
|
||||||
let args = self.create_args_for_associated_item(span, assoc_item, segment, parent_args);
|
let args = self.lower_generic_args_of_assoc_item(span, assoc_item, segment, parent_args);
|
||||||
let args = tcx.mk_args_from_iter(
|
let args = tcx.mk_args_from_iter(
|
||||||
std::iter::once(ty::GenericArg::from(self_ty))
|
std::iter::once(ty::GenericArg::from(self_ty))
|
||||||
.chain(args.into_iter().skip(parent_args.len())),
|
.chain(args.into_iter().skip(parent_args.len())),
|
||||||
|
@ -1356,7 +1355,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match &applicable_candidates[..] {
|
match &applicable_candidates[..] {
|
||||||
&[] => Err(self.complain_about_inherent_assoc_type_not_found(
|
&[] => Err(self.complain_about_inherent_assoc_ty_not_found(
|
||||||
name,
|
name,
|
||||||
self_ty,
|
self_ty,
|
||||||
candidates,
|
candidates,
|
||||||
|
@ -1366,7 +1365,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
&[applicable_candidate] => Ok(applicable_candidate),
|
&[applicable_candidate] => Ok(applicable_candidate),
|
||||||
|
|
||||||
&[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_type(
|
&[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_ty(
|
||||||
name,
|
name,
|
||||||
applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(),
|
applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(),
|
||||||
span,
|
span,
|
||||||
|
@ -1374,19 +1373,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_assoc_ty(
|
fn probe_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
block: hir::HirId,
|
block: hir::HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
scope: DefId,
|
scope: DefId,
|
||||||
) -> Option<DefId> {
|
) -> Option<DefId> {
|
||||||
let (item, def_scope) = self.lookup_assoc_ty_unchecked(name, block, scope)?;
|
let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?;
|
||||||
self.check_assoc_ty(item, name, def_scope, block, span);
|
self.check_assoc_ty(item, name, def_scope, block, span);
|
||||||
Some(item)
|
Some(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_assoc_ty_unchecked(
|
fn probe_assoc_ty_unchecked(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
block: hir::HirId,
|
block: hir::HirId,
|
||||||
|
@ -1491,7 +1490,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn qpath_to_ty(
|
fn lower_qpath(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
opt_self_ty: Option<Ty<'tcx>>,
|
opt_self_ty: Option<Ty<'tcx>>,
|
||||||
|
@ -1545,7 +1544,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// FIXME: also look at `tcx.generics_of(self.item_def_id()).params` any that
|
// FIXME: also look at `tcx.generics_of(self.item_def_id()).params` any that
|
||||||
// references the trait. Relevant for the first case in
|
// references the trait. Relevant for the first case in
|
||||||
// `src/test/ui/associated-types/associated-types-in-ambiguous-context.rs`
|
// `src/test/ui/associated-types/associated-types-in-ambiguous-context.rs`
|
||||||
let reported = self.report_ambiguous_associated_type(
|
let reported = self.report_ambiguous_assoc_ty(
|
||||||
span,
|
span,
|
||||||
&type_names,
|
&type_names,
|
||||||
&[path_str],
|
&[path_str],
|
||||||
|
@ -1556,24 +1555,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
debug!("qpath_to_ty: self_type={:?}", self_ty);
|
debug!("qpath_to_ty: self_type={:?}", self_ty);
|
||||||
|
|
||||||
let trait_ref = self.ast_path_to_mono_trait_ref(
|
let trait_ref =
|
||||||
span,
|
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false, constness);
|
||||||
trait_def_id,
|
|
||||||
self_ty,
|
|
||||||
trait_segment,
|
|
||||||
false,
|
|
||||||
constness,
|
|
||||||
);
|
|
||||||
|
|
||||||
let item_args =
|
let item_args =
|
||||||
self.create_args_for_associated_item(span, item_def_id, item_segment, trait_ref.args);
|
self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
|
||||||
|
|
||||||
debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
|
debug!("qpath_to_ty: trait_ref={:?}", trait_ref);
|
||||||
|
|
||||||
Ty::new_projection(tcx, item_def_id, item_args)
|
Ty::new_projection(tcx, item_def_id, item_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prohibit_generics<'a>(
|
pub fn prohibit_generic_args<'a>(
|
||||||
&self,
|
&self,
|
||||||
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
|
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
|
||||||
extend: impl Fn(&mut Diag<'_>),
|
extend: impl Fn(&mut Diag<'_>),
|
||||||
|
@ -1676,7 +1669,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
for segment in segments {
|
for segment in segments {
|
||||||
// Only emit the first error to avoid overloading the user with error messages.
|
// Only emit the first error to avoid overloading the user with error messages.
|
||||||
if let Some(b) = segment.args().bindings.first() {
|
if let Some(b) = segment.args().bindings.first() {
|
||||||
prohibit_assoc_ty_binding(self.tcx(), b.span, None);
|
prohibit_assoc_item_binding(self.tcx(), b.span, None);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1684,14 +1677,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb, varkor) handle type paths here too, not just value ones.
|
// FIXME(eddyb, varkor) handle type paths here too, not just value ones.
|
||||||
pub fn def_ids_for_value_path_segments(
|
pub fn probe_generic_path_segments(
|
||||||
&self,
|
&self,
|
||||||
segments: &[hir::PathSegment<'_>],
|
segments: &[hir::PathSegment<'_>],
|
||||||
self_ty: Option<Ty<'tcx>>,
|
self_ty: Option<Ty<'tcx>>,
|
||||||
kind: DefKind,
|
kind: DefKind,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Vec<PathSeg> {
|
) -> Vec<GenericPathSegment> {
|
||||||
// We need to extract the type parameters supplied by the user in
|
// We need to extract the type parameters supplied by the user in
|
||||||
// the path `path`. Due to the current setup, this is a bit of a
|
// the path `path`. Due to the current setup, this is a bit of a
|
||||||
// tricky-process; the problem is that resolve only tells us the
|
// tricky-process; the problem is that resolve only tells us the
|
||||||
|
@ -1742,7 +1735,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
assert!(!segments.is_empty());
|
assert!(!segments.is_empty());
|
||||||
let last = segments.len() - 1;
|
let last = segments.len() - 1;
|
||||||
|
|
||||||
let mut path_segs = vec![];
|
let mut generic_segments = vec![];
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
// Case 1. Reference to a struct constructor.
|
// Case 1. Reference to a struct constructor.
|
||||||
|
@ -1753,7 +1746,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// Variant and struct constructors use the
|
// Variant and struct constructors use the
|
||||||
// generics of their parent type definition.
|
// generics of their parent type definition.
|
||||||
let generics_def_id = generics.parent.unwrap_or(def_id);
|
let generics_def_id = generics.parent.unwrap_or(def_id);
|
||||||
path_segs.push(PathSeg(generics_def_id, last));
|
generic_segments.push(GenericPathSegment(generics_def_id, last));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 2. Reference to a variant constructor.
|
// Case 2. Reference to a variant constructor.
|
||||||
|
@ -1786,33 +1779,33 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// generics of their parent type definition.
|
// generics of their parent type definition.
|
||||||
(generics.parent.unwrap_or(def_id), last)
|
(generics.parent.unwrap_or(def_id), last)
|
||||||
};
|
};
|
||||||
path_segs.push(PathSeg(generics_def_id, index));
|
generic_segments.push(GenericPathSegment(generics_def_id, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 3. Reference to a top-level value.
|
// Case 3. Reference to a top-level value.
|
||||||
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
|
DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
|
||||||
path_segs.push(PathSeg(def_id, last));
|
generic_segments.push(GenericPathSegment(def_id, last));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 4. Reference to a method or associated const.
|
// Case 4. Reference to a method or associated const.
|
||||||
DefKind::AssocFn | DefKind::AssocConst => {
|
DefKind::AssocFn | DefKind::AssocConst => {
|
||||||
if segments.len() >= 2 {
|
if segments.len() >= 2 {
|
||||||
let generics = tcx.generics_of(def_id);
|
let generics = tcx.generics_of(def_id);
|
||||||
path_segs.push(PathSeg(generics.parent.unwrap(), last - 1));
|
generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1));
|
||||||
}
|
}
|
||||||
path_segs.push(PathSeg(def_id, last));
|
generic_segments.push(GenericPathSegment(def_id, last));
|
||||||
}
|
}
|
||||||
|
|
||||||
kind => bug!("unexpected definition kind {:?} for {:?}", kind, def_id),
|
kind => bug!("unexpected definition kind {:?} for {:?}", kind, def_id),
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("path_segs = {:?}", path_segs);
|
debug!("path_segs = {:?}", generic_segments);
|
||||||
|
|
||||||
path_segs
|
generic_segments
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check a type `Path` and convert it to a `Ty`.
|
/// Check a type `Path` and convert it to a `Ty`.
|
||||||
pub fn res_to_ty(
|
pub fn lower_path(
|
||||||
&self,
|
&self,
|
||||||
opt_self_ty: Option<Ty<'tcx>>,
|
opt_self_ty: Option<Ty<'tcx>>,
|
||||||
path: &hir::Path<'tcx>,
|
path: &hir::Path<'tcx>,
|
||||||
|
@ -1832,10 +1825,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// Check for desugared `impl Trait`.
|
// Check for desugared `impl Trait`.
|
||||||
assert!(tcx.is_type_alias_impl_trait(did));
|
assert!(tcx.is_type_alias_impl_trait(did));
|
||||||
let item_segment = path.segments.split_last().unwrap();
|
let item_segment = path.segments.split_last().unwrap();
|
||||||
self.prohibit_generics(item_segment.1.iter(), |err| {
|
self.prohibit_generic_args(item_segment.1.iter(), |err| {
|
||||||
err.note("`impl Trait` types can't have type parameters");
|
err.note("`impl Trait` types can't have type parameters");
|
||||||
});
|
});
|
||||||
let args = self.ast_path_args_for_ty(span, did, item_segment.0);
|
let args = self.lower_generic_args_of_path_segment(span, did, item_segment.0);
|
||||||
Ty::new_opaque(tcx, did, args)
|
Ty::new_opaque(tcx, did, args)
|
||||||
}
|
}
|
||||||
Res::Def(
|
Res::Def(
|
||||||
|
@ -1847,44 +1840,44 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
did,
|
did,
|
||||||
) => {
|
) => {
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments.split_last().unwrap().1.iter(), |_| {});
|
self.prohibit_generic_args(path.segments.split_last().unwrap().1.iter(), |_| {});
|
||||||
self.ast_path_to_ty(span, did, path.segments.last().unwrap())
|
self.lower_path_segment(span, did, path.segments.last().unwrap())
|
||||||
}
|
}
|
||||||
Res::Def(kind @ DefKind::Variant, def_id) if permit_variants => {
|
Res::Def(kind @ DefKind::Variant, def_id) if permit_variants => {
|
||||||
// Convert "variant type" as if it were a real type.
|
// Convert "variant type" as if it were a real type.
|
||||||
// The resulting `Ty` is type of the variant's enum for now.
|
// The resulting `Ty` is type of the variant's enum for now.
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
|
|
||||||
let path_segs =
|
let generic_segments =
|
||||||
self.def_ids_for_value_path_segments(path.segments, None, kind, def_id, span);
|
self.probe_generic_path_segments(path.segments, None, kind, def_id, span);
|
||||||
let generic_segs: FxHashSet<_> =
|
let indices: FxHashSet<_> =
|
||||||
path_segs.iter().map(|PathSeg(_, index)| index).collect();
|
generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
|
||||||
self.prohibit_generics(
|
self.prohibit_generic_args(
|
||||||
path.segments.iter().enumerate().filter_map(|(index, seg)| {
|
path.segments.iter().enumerate().filter_map(|(index, seg)| {
|
||||||
if !generic_segs.contains(&index) { Some(seg) } else { None }
|
if !indices.contains(&index) { Some(seg) } else { None }
|
||||||
}),
|
}),
|
||||||
|err| {
|
|err| {
|
||||||
err.note("enum variants can't have type parameters");
|
err.note("enum variants can't have type parameters");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let PathSeg(def_id, index) = path_segs.last().unwrap();
|
let GenericPathSegment(def_id, index) = generic_segments.last().unwrap();
|
||||||
self.ast_path_to_ty(span, *def_id, &path.segments[*index])
|
self.lower_path_segment(span, *def_id, &path.segments[*index])
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, def_id) => {
|
Res::Def(DefKind::TyParam, def_id) => {
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments.iter(), |err| {
|
self.prohibit_generic_args(path.segments.iter(), |err| {
|
||||||
if let Some(span) = tcx.def_ident_span(def_id) {
|
if let Some(span) = tcx.def_ident_span(def_id) {
|
||||||
let name = tcx.item_name(def_id);
|
let name = tcx.item_name(def_id);
|
||||||
err.span_note(span, format!("type parameter `{name}` defined here"));
|
err.span_note(span, format!("type parameter `{name}` defined here"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.hir_id_to_bound_ty(hir_id)
|
self.lower_ty_param(hir_id)
|
||||||
}
|
}
|
||||||
Res::SelfTyParam { .. } => {
|
Res::SelfTyParam { .. } => {
|
||||||
// `Self` in trait or type alias.
|
// `Self` in trait or type alias.
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments.iter(), |err| {
|
self.prohibit_generic_args(path.segments.iter(), |err| {
|
||||||
if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments {
|
if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
ident.span.shrink_to_hi().to(args.span_ext),
|
ident.span.shrink_to_hi().to(args.span_ext),
|
||||||
|
@ -1902,7 +1895,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// Try to evaluate any array length constants.
|
// Try to evaluate any array length constants.
|
||||||
let ty = tcx.at(span).type_of(def_id).instantiate_identity();
|
let ty = tcx.at(span).type_of(def_id).instantiate_identity();
|
||||||
let span_of_impl = tcx.span_of_impl(def_id);
|
let span_of_impl = tcx.span_of_impl(def_id);
|
||||||
self.prohibit_generics(path.segments.iter(), |err| {
|
self.prohibit_generic_args(path.segments.iter(), |err| {
|
||||||
let def_id = match *ty.kind() {
|
let def_id = match *ty.kind() {
|
||||||
ty::Adt(self_def, _) => self_def.did(),
|
ty::Adt(self_def, _) => self_def.did(),
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -2000,14 +1993,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::AssocTy, def_id) => {
|
Res::Def(DefKind::AssocTy, def_id) => {
|
||||||
debug_assert!(path.segments.len() >= 2);
|
debug_assert!(path.segments.len() >= 2);
|
||||||
self.prohibit_generics(path.segments[..path.segments.len() - 2].iter(), |_| {});
|
self.prohibit_generic_args(path.segments[..path.segments.len() - 2].iter(), |_| {});
|
||||||
// HACK: until we support `<Type as ~const Trait>`, assume all of them are.
|
// HACK: until we support `<Type as ~const Trait>`, assume all of them are.
|
||||||
let constness = if tcx.has_attr(tcx.parent(def_id), sym::const_trait) {
|
let constness = if tcx.has_attr(tcx.parent(def_id), sym::const_trait) {
|
||||||
ty::BoundConstness::ConstIfConst
|
ty::BoundConstness::ConstIfConst
|
||||||
} else {
|
} else {
|
||||||
ty::BoundConstness::NotConst
|
ty::BoundConstness::NotConst
|
||||||
};
|
};
|
||||||
self.qpath_to_ty(
|
self.lower_qpath(
|
||||||
span,
|
span,
|
||||||
opt_self_ty,
|
opt_self_ty,
|
||||||
def_id,
|
def_id,
|
||||||
|
@ -2018,7 +2011,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
Res::PrimTy(prim_ty) => {
|
Res::PrimTy(prim_ty) => {
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments.iter(), |err| {
|
self.prohibit_generic_args(path.segments.iter(), |err| {
|
||||||
let name = prim_ty.name_str();
|
let name = prim_ty.name_str();
|
||||||
for segment in path.segments {
|
for segment in path.segments {
|
||||||
if let Some(args) = segment.args {
|
if let Some(args) = segment.args {
|
||||||
|
@ -2054,7 +2047,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
// Converts a hir id corresponding to a type parameter to
|
// Converts a hir id corresponding to a type parameter to
|
||||||
// a early-bound `ty::Param` or late-bound `ty::Bound`.
|
// a early-bound `ty::Param` or late-bound `ty::Bound`.
|
||||||
pub(crate) fn hir_id_to_bound_ty(&self, hir_id: hir::HirId) -> Ty<'tcx> {
|
pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
match tcx.named_bound_var(hir_id) {
|
match tcx.named_bound_var(hir_id) {
|
||||||
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
|
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
|
||||||
|
@ -2079,11 +2072,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
// Converts a hir id corresponding to a const parameter to
|
// Converts a hir id corresponding to a const parameter to
|
||||||
// a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`.
|
// a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`.
|
||||||
pub(crate) fn hir_id_to_bound_const(
|
pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
&self,
|
|
||||||
hir_id: hir::HirId,
|
|
||||||
param_ty: Ty<'tcx>,
|
|
||||||
) -> Const<'tcx> {
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
match tcx.named_bound_var(hir_id) {
|
match tcx.named_bound_var(hir_id) {
|
||||||
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
||||||
|
@ -2105,14 +2094,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
/// Parses the programmer's textual representation of a type into our
|
/// Parses the programmer's textual representation of a type into our
|
||||||
/// internal notion of a type.
|
/// internal notion of a type.
|
||||||
pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
pub fn lower_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
||||||
self.ast_ty_to_ty_inner(ast_ty, false, false)
|
self.lower_ty_common(ast_ty, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the programmer's textual representation of a type into our
|
/// Parses the programmer's textual representation of a type into our
|
||||||
/// internal notion of a type. This is meant to be used within a path.
|
/// internal notion of a type. This is meant to be used within a path.
|
||||||
pub fn ast_ty_to_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
pub fn lower_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
||||||
self.ast_ty_to_ty_inner(ast_ty, false, true)
|
self.lower_ty_common(ast_ty, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_delegation_constraints(&self, sig_id: DefId, span: Span, emit: bool) -> bool {
|
fn check_delegation_constraints(&self, sig_id: DefId, span: Span, emit: bool) -> bool {
|
||||||
|
@ -2179,7 +2168,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
error_occured
|
error_occured
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_from_delegation(
|
fn lower_delegation_ty(
|
||||||
&self,
|
&self,
|
||||||
sig_id: DefId,
|
sig_id: DefId,
|
||||||
idx: hir::InferDelegationKind,
|
idx: hir::InferDelegationKind,
|
||||||
|
@ -2226,31 +2215,26 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
/// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait
|
/// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait
|
||||||
/// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors.
|
/// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors.
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
fn ast_ty_to_ty_inner(
|
fn lower_ty_common(&self, ast_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
|
||||||
&self,
|
|
||||||
ast_ty: &hir::Ty<'tcx>,
|
|
||||||
borrowed: bool,
|
|
||||||
in_path: bool,
|
|
||||||
) -> Ty<'tcx> {
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
let result_ty = match &ast_ty.kind {
|
let result_ty = match &ast_ty.kind {
|
||||||
hir::TyKind::InferDelegation(sig_id, idx) => {
|
hir::TyKind::InferDelegation(sig_id, idx) => {
|
||||||
self.ty_from_delegation(*sig_id, *idx, ast_ty.span)
|
self.lower_delegation_ty(*sig_id, *idx, ast_ty.span)
|
||||||
}
|
}
|
||||||
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)),
|
hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
|
||||||
hir::TyKind::Ptr(mt) => {
|
hir::TyKind::Ptr(mt) => {
|
||||||
Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
|
Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.lower_ty(mt.ty), mutbl: mt.mutbl })
|
||||||
}
|
}
|
||||||
hir::TyKind::Ref(region, mt) => {
|
hir::TyKind::Ref(region, mt) => {
|
||||||
let r = self.ast_region_to_region(region, None);
|
let r = self.lower_lifetime(region, None);
|
||||||
debug!(?r);
|
debug!(?r);
|
||||||
let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
|
let t = self.lower_ty_common(mt.ty, true, false);
|
||||||
Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
|
Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl })
|
||||||
}
|
}
|
||||||
hir::TyKind::Never => tcx.types.never,
|
hir::TyKind::Never => tcx.types.never,
|
||||||
hir::TyKind::Tup(fields) => {
|
hir::TyKind::Tup(fields) => {
|
||||||
Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.ast_ty_to_ty(t)))
|
Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t)))
|
||||||
}
|
}
|
||||||
hir::TyKind::AnonAdt(item_id) => {
|
hir::TyKind::AnonAdt(item_id) => {
|
||||||
let did = item_id.owner_id.def_id;
|
let did = item_id.owner_id.def_id;
|
||||||
|
@ -2270,7 +2254,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
Ty::new_fn_ptr(
|
Ty::new_fn_ptr(
|
||||||
tcx,
|
tcx,
|
||||||
self.ty_of_fn(ast_ty.hir_id, bf.unsafety, bf.abi, bf.decl, None, Some(ast_ty)),
|
self.lower_fn_ty(
|
||||||
|
ast_ty.hir_id,
|
||||||
|
bf.unsafety,
|
||||||
|
bf.abi,
|
||||||
|
bf.decl,
|
||||||
|
None,
|
||||||
|
Some(ast_ty),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
|
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
|
||||||
|
@ -2280,7 +2271,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
TraitObjectSyntax::DynStar => ty::DynStar,
|
TraitObjectSyntax::DynStar => ty::DynStar,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.conv_object_ty_poly_trait_ref(
|
self.lower_trait_object_ty(
|
||||||
ast_ty.span,
|
ast_ty.span,
|
||||||
ast_ty.hir_id,
|
ast_ty.hir_id,
|
||||||
bounds,
|
bounds,
|
||||||
|
@ -2291,8 +2282,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
|
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
|
||||||
debug!(?maybe_qself, ?path);
|
debug!(?maybe_qself, ?path);
|
||||||
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself));
|
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
|
||||||
self.res_to_ty(opt_self_ty, path, ast_ty.hir_id, false)
|
self.lower_path(opt_self_ty, path, ast_ty.hir_id, false)
|
||||||
}
|
}
|
||||||
&hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
|
&hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
|
||||||
let opaque_ty = tcx.hir().item(item_id);
|
let opaque_ty = tcx.hir().item(item_id);
|
||||||
|
@ -2308,21 +2299,21 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
} else {
|
} else {
|
||||||
local_def_id.to_def_id()
|
local_def_id.to_def_id()
|
||||||
};
|
};
|
||||||
self.impl_trait_ty_to_ty(def_id, lifetimes, in_trait)
|
self.lower_opaque_ty(def_id, lifetimes, in_trait)
|
||||||
}
|
}
|
||||||
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
|
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
|
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
|
||||||
debug!(?qself, ?segment);
|
debug!(?qself, ?segment);
|
||||||
let ty = self.ast_ty_to_ty_inner(qself, false, true);
|
let ty = self.lower_ty_common(qself, false, true);
|
||||||
self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
|
self.lower_assoc_path(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
|
||||||
.map(|(ty, _, _)| ty)
|
.map(|(ty, _, _)| ty)
|
||||||
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
|
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
|
||||||
}
|
}
|
||||||
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => {
|
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => {
|
||||||
let def_id = tcx.require_lang_item(lang_item, Some(span));
|
let def_id = tcx.require_lang_item(lang_item, Some(span));
|
||||||
let (args, _) = self.create_args_for_ast_path(
|
let (args, _) = self.lower_generic_args_of_path(
|
||||||
span,
|
span,
|
||||||
def_id,
|
def_id,
|
||||||
&[],
|
&[],
|
||||||
|
@ -2340,7 +2331,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length)
|
Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
|
||||||
}
|
}
|
||||||
hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(),
|
hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(),
|
||||||
hir::TyKind::Infer => {
|
hir::TyKind::Infer => {
|
||||||
|
@ -2358,7 +2349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
fn impl_trait_ty_to_ty(
|
fn lower_opaque_ty(
|
||||||
&self,
|
&self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
lifetimes: &[hir::GenericArg<'_>],
|
lifetimes: &[hir::GenericArg<'_>],
|
||||||
|
@ -2390,7 +2381,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
&lifetimes[i]
|
&lifetimes[i]
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.ast_region_to_region(lifetime, None).into()
|
self.lower_lifetime(lifetime, None).into()
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_param_from_def(param)
|
tcx.mk_param_from_def(param)
|
||||||
}
|
}
|
||||||
|
@ -2404,18 +2395,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ty_of_arg(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
|
pub fn lower_arg_ty(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
hir::TyKind::Infer if let Some(expected_ty) = expected_ty => {
|
hir::TyKind::Infer if let Some(expected_ty) = expected_ty => {
|
||||||
self.record_ty(ty.hir_id, expected_ty, ty.span);
|
self.record_ty(ty.hir_id, expected_ty, ty.span);
|
||||||
expected_ty
|
expected_ty
|
||||||
}
|
}
|
||||||
_ => self.ast_ty_to_ty(ty),
|
_ => self.lower_ty(ty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
|
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
|
||||||
pub fn ty_of_fn(
|
pub fn lower_fn_ty(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
unsafety: hir::Unsafety,
|
unsafety: hir::Unsafety,
|
||||||
|
@ -2448,7 +2439,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, a)| {
|
.map(|(i, a)| {
|
||||||
if let hir::TyKind::Infer = a.kind
|
if let hir::TyKind::Infer = a.kind
|
||||||
&& !self.allow_ty_infer()
|
&& !self.allow_infer()
|
||||||
{
|
{
|
||||||
if let Some(suggested_ty) =
|
if let Some(suggested_ty) =
|
||||||
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i))
|
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i))
|
||||||
|
@ -2464,14 +2455,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
// Only visit the type looking for `_` if we didn't fix the type above
|
// Only visit the type looking for `_` if we didn't fix the type above
|
||||||
visitor.visit_ty(a);
|
visitor.visit_ty(a);
|
||||||
self.ty_of_arg(a, None)
|
self.lower_arg_ty(a, None)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let output_ty = match decl.output {
|
let output_ty = match decl.output {
|
||||||
hir::FnRetTy::Return(output) => {
|
hir::FnRetTy::Return(output) => {
|
||||||
if let hir::TyKind::Infer = output.kind
|
if let hir::TyKind::Infer = output.kind
|
||||||
&& !self.allow_ty_infer()
|
&& !self.allow_infer()
|
||||||
&& let Some(suggested_ty) =
|
&& let Some(suggested_ty) =
|
||||||
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None)
|
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None)
|
||||||
{
|
{
|
||||||
|
@ -2479,7 +2470,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string())
|
Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string())
|
||||||
} else {
|
} else {
|
||||||
visitor.visit_ty(output);
|
visitor.visit_ty(output);
|
||||||
self.ast_ty_to_ty(output)
|
self.lower_ty(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx),
|
hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx),
|
||||||
|
@ -2490,7 +2481,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
|
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi);
|
||||||
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
|
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
|
||||||
|
|
||||||
if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {
|
if !self.allow_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) {
|
||||||
// We always collect the spans for placeholder types when evaluating `fn`s, but we
|
// We always collect the spans for placeholder types when evaluating `fn`s, but we
|
||||||
// only want to emit an error complaining about them if infer types (`_`) are not
|
// only want to emit an error complaining about them if infer types (`_`) are not
|
||||||
// allowed. `allow_ty_infer` gates this behavior. We check for the presence of
|
// allowed. `allow_ty_infer` gates this behavior. We check for the presence of
|
||||||
|
@ -2562,8 +2553,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
};
|
};
|
||||||
let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
|
let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
|
||||||
|
|
||||||
let trait_ref =
|
let trait_ref = self.lower_impl_trait_ref(i.of_trait.as_ref()?, self.lower_ty(i.self_ty));
|
||||||
self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty));
|
|
||||||
|
|
||||||
let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind(
|
let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind(
|
||||||
tcx,
|
tcx,
|
||||||
|
|
|
@ -11,14 +11,14 @@ use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_middle::ty::{DynKind, ToPredicate};
|
use rustc_middle::ty::{DynKind, ToPredicate};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
|
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
|
||||||
use rustc_trait_selection::traits::{self, astconv_object_safety_violations};
|
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
use super::AstConv;
|
use super::HirTyLowerer;
|
||||||
|
|
||||||
impl<'tcx> dyn AstConv<'tcx> + '_ {
|
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
pub(super) fn conv_object_ty_poly_trait_ref(
|
pub(super) fn lower_trait_object_ty(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
|
@ -37,7 +37,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
correct:
|
correct:
|
||||||
Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }),
|
Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }),
|
||||||
..
|
..
|
||||||
} = self.instantiate_poly_trait_ref(
|
} = self.lower_poly_trait_ref(
|
||||||
&trait_bound.trait_ref,
|
&trait_bound.trait_ref,
|
||||||
trait_bound.span,
|
trait_bound.span,
|
||||||
ty::BoundConstness::NotConst,
|
ty::BoundConstness::NotConst,
|
||||||
|
@ -133,7 +133,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
// to avoid ICEs.
|
// to avoid ICEs.
|
||||||
for item in ®ular_traits {
|
for item in ®ular_traits {
|
||||||
let object_safety_violations =
|
let object_safety_violations =
|
||||||
astconv_object_safety_violations(tcx, item.trait_ref().def_id());
|
hir_ty_lowering_object_safety_violations(tcx, item.trait_ref().def_id());
|
||||||
if !object_safety_violations.is_empty() {
|
if !object_safety_violations.is_empty() {
|
||||||
let reported = report_object_safety_error(
|
let reported = report_object_safety_error(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -231,7 +231,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id));
|
def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.complain_about_missing_associated_types(
|
self.complain_about_missing_assoc_tys(
|
||||||
associated_types,
|
associated_types,
|
||||||
potential_assoc_types,
|
potential_assoc_types,
|
||||||
hir_trait_bounds,
|
hir_trait_bounds,
|
||||||
|
@ -362,11 +362,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
// Use explicitly-specified region bound.
|
// Use explicitly-specified region bound.
|
||||||
let region_bound = if !lifetime.is_elided() {
|
let region_bound = if !lifetime.is_elided() {
|
||||||
self.ast_region_to_region(lifetime, None)
|
self.lower_lifetime(lifetime, None)
|
||||||
} else {
|
} else {
|
||||||
self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| {
|
self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| {
|
||||||
if tcx.named_bound_var(lifetime.hir_id).is_some() {
|
if tcx.named_bound_var(lifetime.hir_id).is_some() {
|
||||||
self.ast_region_to_region(lifetime, None)
|
self.lower_lifetime(lifetime, None)
|
||||||
} else {
|
} else {
|
||||||
self.re_infer(None, span).unwrap_or_else(|| {
|
self.re_infer(None, span).unwrap_or_else(|| {
|
||||||
let err = struct_span_code_err!(
|
let err = struct_span_code_err!(
|
||||||
|
|
|
@ -1866,7 +1866,7 @@ fn check_variances_for_type_defn<'tcx>(
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|predicate| match predicate {
|
.filter_map(|predicate| match predicate {
|
||||||
hir::WherePredicate::BoundPredicate(predicate) => {
|
hir::WherePredicate::BoundPredicate(predicate) => {
|
||||||
match icx.to_ty(predicate.bounded_ty).kind() {
|
match icx.lower_ty(predicate.bounded_ty).kind() {
|
||||||
ty::Param(data) => Some(Parameter(data.index)),
|
ty::Param(data) => Some(Parameter(data.index)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ use std::cell::Cell;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::Bound;
|
use std::ops::Bound;
|
||||||
|
|
||||||
use crate::astconv::AstConv;
|
use crate::astconv::HirTyLowerer;
|
||||||
use crate::check::intrinsic::intrinsic_operation_unsafety;
|
use crate::check::intrinsic::intrinsic_operation_unsafety;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
pub use type_of::test_opaque_hidden_types;
|
pub use type_of::test_opaque_hidden_types;
|
||||||
|
@ -277,7 +277,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||||
convert_item(self.tcx, item.item_id());
|
lower_item(self.tcx, item.item_id());
|
||||||
reject_placeholder_type_signatures_in_item(self.tcx, item);
|
reject_placeholder_type_signatures_in_item(self.tcx, item);
|
||||||
intravisit::walk_item(self, item);
|
intravisit::walk_item(self, item);
|
||||||
}
|
}
|
||||||
|
@ -315,12 +315,12 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||||
convert_trait_item(self.tcx, trait_item.trait_item_id());
|
lower_trait_item(self.tcx, trait_item.trait_item_id());
|
||||||
intravisit::walk_trait_item(self, trait_item);
|
intravisit::walk_trait_item(self, trait_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||||
convert_impl_item(self.tcx, impl_item.impl_item_id());
|
lower_impl_item(self.tcx, impl_item.impl_item_id());
|
||||||
intravisit::walk_impl_item(self, impl_item);
|
intravisit::walk_impl_item(self, impl_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,8 +344,8 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||||
ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) }
|
ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
pub fn lower_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
||||||
self.astconv().ast_ty_to_ty(ast_ty)
|
self.lowerer().lower_ty(ast_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hir_id(&self) -> hir::HirId {
|
pub fn hir_id(&self) -> hir::HirId {
|
||||||
|
@ -364,7 +364,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
||||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
@ -373,7 +373,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||||
self.item_def_id.to_def_id()
|
self.item_def_id.to_def_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type_parameter_bounds(
|
fn probe_ty_param_bounds(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
|
@ -386,7 +386,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allow_ty_infer(&self) -> bool {
|
fn allow_infer(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||||
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
|
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn projected_ty_from_poly_trait_ref(
|
fn lower_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
|
@ -412,7 +412,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||||
poly_trait_ref: ty::PolyTraitRef<'tcx>,
|
poly_trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
|
if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
|
||||||
let item_args = self.astconv().create_args_for_associated_item(
|
let item_args = self.lowerer().lower_generic_args_of_assoc_item(
|
||||||
span,
|
span,
|
||||||
item_def_id,
|
item_def_id,
|
||||||
item_segment,
|
item_segment,
|
||||||
|
@ -547,7 +547,7 @@ fn get_new_lifetime_name<'tcx>(
|
||||||
(1..).flat_map(a_to_z_repeat_n).find(|lt| !existing_lifetimes.contains(lt.as_str())).unwrap()
|
(1..).flat_map(a_to_z_repeat_n).find(|lt| !existing_lifetimes.contains(lt.as_str())).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||||
let it = tcx.hir().item(item_id);
|
let it = tcx.hir().item(item_id);
|
||||||
debug!("convert: item {} with id {}", it.ident, it.hir_id());
|
debug!("convert: item {} with id {}", it.ident, it.hir_id());
|
||||||
let def_id = item_id.owner_id.def_id;
|
let def_id = item_id.owner_id.def_id;
|
||||||
|
@ -591,7 +591,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
tcx.ensure().type_of(def_id);
|
tcx.ensure().type_of(def_id);
|
||||||
tcx.ensure().predicates_of(def_id);
|
tcx.ensure().predicates_of(def_id);
|
||||||
convert_enum_variant_types(tcx, def_id.to_def_id());
|
lower_enum_variant_types(tcx, def_id.to_def_id());
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl { .. } => {
|
hir::ItemKind::Impl { .. } => {
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
|
@ -625,7 +625,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||||
convert_variant_ctor(tcx, ctor_def_id);
|
lower_variant_ctor(tcx, ctor_def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -668,7 +668,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
||||||
let trait_item = tcx.hir().trait_item(trait_item_id);
|
let trait_item = tcx.hir().trait_item(trait_item_id);
|
||||||
let def_id = trait_item_id.owner_id;
|
let def_id = trait_item_id.owner_id;
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
|
@ -717,7 +717,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
||||||
tcx.ensure().predicates_of(def_id);
|
tcx.ensure().predicates_of(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||||
let def_id = impl_item_id.owner_id;
|
let def_id = impl_item_id.owner_id;
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
tcx.ensure().type_of(def_id);
|
tcx.ensure().type_of(def_id);
|
||||||
|
@ -746,13 +746,13 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
tcx.ensure().generics_of(def_id);
|
tcx.ensure().generics_of(def_id);
|
||||||
tcx.ensure().type_of(def_id);
|
tcx.ensure().type_of(def_id);
|
||||||
tcx.ensure().predicates_of(def_id);
|
tcx.ensure().predicates_of(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||||
let def = tcx.adt_def(def_id);
|
let def = tcx.adt_def(def_id);
|
||||||
let repr_type = def.repr().discr_type();
|
let repr_type = def.repr().discr_type();
|
||||||
let initial = repr_type.initial_discriminant(tcx);
|
let initial = repr_type.initial_discriminant(tcx);
|
||||||
|
@ -788,7 +788,7 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||||
// Convert the ctor, if any. This also registers the variant as
|
// Convert the ctor, if any. This also registers the variant as
|
||||||
// an item.
|
// an item.
|
||||||
if let Some(ctor_def_id) = variant.ctor_def_id() {
|
if let Some(ctor_def_id) = variant.ctor_def_id() {
|
||||||
convert_variant_ctor(tcx, ctor_def_id.expect_local());
|
lower_variant_ctor(tcx, ctor_def_id.expect_local());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -975,7 +975,7 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_variant(
|
fn lower_variant(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
variant_did: Option<LocalDefId>,
|
variant_did: Option<LocalDefId>,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
|
@ -1060,7 +1060,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||||
};
|
};
|
||||||
distance_from_explicit += 1;
|
distance_from_explicit += 1;
|
||||||
|
|
||||||
convert_variant(
|
lower_variant(
|
||||||
tcx,
|
tcx,
|
||||||
Some(v.def_id),
|
Some(v.def_id),
|
||||||
v.ident,
|
v.ident,
|
||||||
|
@ -1080,7 +1080,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
||||||
ItemKind::Struct(..) => AdtKind::Struct,
|
ItemKind::Struct(..) => AdtKind::Struct,
|
||||||
_ => AdtKind::Union,
|
_ => AdtKind::Union,
|
||||||
};
|
};
|
||||||
let variants = std::iter::once(convert_variant(
|
let variants = std::iter::once(lower_variant(
|
||||||
tcx,
|
tcx,
|
||||||
None,
|
None,
|
||||||
item.ident,
|
item.ident,
|
||||||
|
@ -1284,7 +1284,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
|
||||||
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id)
|
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id)
|
||||||
&& i.of_trait.is_some()
|
&& i.of_trait.is_some()
|
||||||
{
|
{
|
||||||
icx.astconv().ty_of_fn(
|
icx.lowerer().lower_fn_ty(
|
||||||
hir_id,
|
hir_id,
|
||||||
sig.header.unsafety,
|
sig.header.unsafety,
|
||||||
sig.header.abi,
|
sig.header.abi,
|
||||||
|
@ -1301,9 +1301,14 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<
|
||||||
kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _),
|
kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _),
|
||||||
generics,
|
generics,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => icx.lowerer().lower_fn_ty(
|
||||||
icx.astconv().ty_of_fn(hir_id, header.unsafety, header.abi, decl, Some(generics), None)
|
hir_id,
|
||||||
}
|
header.unsafety,
|
||||||
|
header.abi,
|
||||||
|
decl,
|
||||||
|
Some(generics),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
|
||||||
ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => {
|
||||||
let abi = tcx.hir().get_foreign_abi(hir_id);
|
let abi = tcx.hir().get_foreign_abi(hir_id);
|
||||||
|
@ -1411,7 +1416,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => icx.astconv().ty_of_fn(
|
None => icx.lowerer().lower_fn_ty(
|
||||||
hir_id,
|
hir_id,
|
||||||
sig.header.unsafety,
|
sig.header.unsafety,
|
||||||
sig.header.abi,
|
sig.header.abi,
|
||||||
|
@ -1554,9 +1559,9 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai
|
||||||
segments: tcx.hir_arena.alloc_slice(&path_segments),
|
segments: tcx.hir_arena.alloc_slice(&path_segments),
|
||||||
};
|
};
|
||||||
let trait_ref = tcx.hir_arena.alloc(hir::TraitRef { path: tcx.hir_arena.alloc(path), hir_ref_id: ast_trait_ref.hir_ref_id });
|
let trait_ref = tcx.hir_arena.alloc(hir::TraitRef { path: tcx.hir_arena.alloc(path), hir_ref_id: ast_trait_ref.hir_ref_id });
|
||||||
icx.astconv().instantiate_mono_trait_ref(trait_ref, selfty)
|
icx.lowerer().lower_impl_trait_ref(trait_ref, selfty)
|
||||||
} else {
|
} else {
|
||||||
icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty)
|
icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty)
|
||||||
};
|
};
|
||||||
ty::ImplTraitHeader {
|
ty::ImplTraitHeader {
|
||||||
trait_ref: ty::EarlyBinder::bind(trait_ref),
|
trait_ref: ty::EarlyBinder::bind(trait_ref),
|
||||||
|
@ -1678,7 +1683,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||||
};
|
};
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||||
let fty =
|
let fty =
|
||||||
ItemCtxt::new(tcx, def_id).astconv().ty_of_fn(hir_id, unsafety, abi, decl, None, None);
|
ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, unsafety, abi, decl, None, None);
|
||||||
|
|
||||||
// Feature gate SIMD types in FFI, since I am not sure that the
|
// Feature gate SIMD types in FFI, since I am not sure that the
|
||||||
// ABIs are handled at all correctly. -huonw
|
// ABIs are handled at all correctly. -huonw
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::ItemCtxt;
|
use super::ItemCtxt;
|
||||||
use crate::astconv::{AstConv, PredicateFilter};
|
use crate::astconv::{HirTyLowerer, PredicateFilter};
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::traits::util;
|
use rustc_infer::traits::util;
|
||||||
|
@ -29,9 +29,9 @@ fn associated_type_bounds<'tcx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
|
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
|
||||||
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, filter);
|
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, ast_bounds, filter);
|
||||||
// Associated types are implicitly sized unless a `?Sized` bound is found
|
// Associated types are implicitly sized unless a `?Sized` bound is found
|
||||||
icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span);
|
icx.lowerer().add_sized_bound(&mut bounds, item_ty, ast_bounds, None, span);
|
||||||
|
|
||||||
let trait_def_id = tcx.local_parent(assoc_item_def_id);
|
let trait_def_id = tcx.local_parent(assoc_item_def_id);
|
||||||
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id);
|
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id);
|
||||||
|
@ -69,9 +69,9 @@ fn opaque_type_bounds<'tcx>(
|
||||||
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
|
||||||
ty::print::with_reduced_queries!({
|
ty::print::with_reduced_queries!({
|
||||||
let icx = ItemCtxt::new(tcx, opaque_def_id);
|
let icx = ItemCtxt::new(tcx, opaque_def_id);
|
||||||
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, filter);
|
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, ast_bounds, filter);
|
||||||
// Opaque types are implicitly sized unless a `?Sized` bound is found
|
// Opaque types are implicitly sized unless a `?Sized` bound is found
|
||||||
icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span);
|
icx.lowerer().add_sized_bound(&mut bounds, item_ty, ast_bounds, None, span);
|
||||||
debug!(?bounds);
|
debug!(?bounds);
|
||||||
|
|
||||||
tcx.arena.alloc_from_iter(bounds.clauses())
|
tcx.arena.alloc_from_iter(bounds.clauses())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter};
|
use crate::astconv::{HirTyLowerer, OnlySelfBounds, PredicateFilter};
|
||||||
use crate::bounds::Bounds;
|
use crate::bounds::Bounds;
|
||||||
use crate::collect::ItemCtxt;
|
use crate::collect::ItemCtxt;
|
||||||
use crate::constrained_generic_params as cgp;
|
use crate::constrained_generic_params as cgp;
|
||||||
|
@ -149,8 +149,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
// like `trait Foo: A + B + C`.
|
// like `trait Foo: A + B + C`.
|
||||||
if let Some(self_bounds) = is_trait {
|
if let Some(self_bounds) = is_trait {
|
||||||
predicates.extend(
|
predicates.extend(
|
||||||
icx.astconv()
|
icx.lowerer()
|
||||||
.compute_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All)
|
.lower_mono_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All)
|
||||||
.clauses(),
|
.clauses(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -175,10 +175,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
// We already dealt with early bound lifetimes above.
|
// We already dealt with early bound lifetimes above.
|
||||||
GenericParamKind::Lifetime { .. } => (),
|
GenericParamKind::Lifetime { .. } => (),
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
let param_ty = icx.astconv().hir_id_to_bound_ty(param.hir_id);
|
let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
|
||||||
let mut bounds = Bounds::default();
|
let mut bounds = Bounds::default();
|
||||||
// Params are implicitly sized unless a `?Sized` bound is found
|
// Params are implicitly sized unless a `?Sized` bound is found
|
||||||
icx.astconv().add_implicitly_sized(
|
icx.lowerer().add_sized_bound(
|
||||||
&mut bounds,
|
&mut bounds,
|
||||||
param_ty,
|
param_ty,
|
||||||
&[],
|
&[],
|
||||||
|
@ -194,7 +194,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
.type_of(param.def_id.to_def_id())
|
.type_of(param.def_id.to_def_id())
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameters cannot be generic");
|
.expect("const parameters cannot be generic");
|
||||||
let ct = icx.astconv().hir_id_to_bound_const(param.hir_id, ct_ty);
|
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
|
||||||
predicates.insert((
|
predicates.insert((
|
||||||
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
|
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),
|
||||||
param.span,
|
param.span,
|
||||||
|
@ -208,7 +208,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
for predicate in ast_generics.predicates {
|
for predicate in ast_generics.predicates {
|
||||||
match predicate {
|
match predicate {
|
||||||
hir::WherePredicate::BoundPredicate(bound_pred) => {
|
hir::WherePredicate::BoundPredicate(bound_pred) => {
|
||||||
let ty = icx.to_ty(bound_pred.bounded_ty);
|
let ty = icx.lower_ty(bound_pred.bounded_ty);
|
||||||
let bound_vars = tcx.late_bound_vars(bound_pred.hir_id);
|
let bound_vars = tcx.late_bound_vars(bound_pred.hir_id);
|
||||||
// Keep the type around in a dummy predicate, in case of no bounds.
|
// Keep the type around in a dummy predicate, in case of no bounds.
|
||||||
// That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
|
// That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
|
||||||
|
@ -232,7 +232,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bounds = Bounds::default();
|
let mut bounds = Bounds::default();
|
||||||
icx.astconv().add_bounds(
|
icx.lowerer().lower_poly_bounds(
|
||||||
ty,
|
ty,
|
||||||
bound_pred.bounds.iter(),
|
bound_pred.bounds.iter(),
|
||||||
&mut bounds,
|
&mut bounds,
|
||||||
|
@ -243,11 +243,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::WherePredicate::RegionPredicate(region_pred) => {
|
hir::WherePredicate::RegionPredicate(region_pred) => {
|
||||||
let r1 = icx.astconv().ast_region_to_region(region_pred.lifetime, None);
|
let r1 = icx.lowerer().lower_lifetime(region_pred.lifetime, None);
|
||||||
predicates.extend(region_pred.bounds.iter().map(|bound| {
|
predicates.extend(region_pred.bounds.iter().map(|bound| {
|
||||||
let (r2, span) = match bound {
|
let (r2, span) = match bound {
|
||||||
hir::GenericBound::Outlives(lt) => {
|
hir::GenericBound::Outlives(lt) => {
|
||||||
(icx.astconv().ast_region_to_region(lt, None), lt.ident.span)
|
(icx.lowerer().lower_lifetime(lt, None), lt.ident.span)
|
||||||
}
|
}
|
||||||
bound => {
|
bound => {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
|
@ -601,9 +601,9 @@ pub(super) fn implied_predicates_with_filter(
|
||||||
let icx = ItemCtxt::new(tcx, trait_def_id);
|
let icx = ItemCtxt::new(tcx, trait_def_id);
|
||||||
|
|
||||||
let self_param_ty = tcx.types.self_param;
|
let self_param_ty = tcx.types.self_param;
|
||||||
let superbounds = icx.astconv().compute_bounds(self_param_ty, bounds, filter);
|
let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter);
|
||||||
|
|
||||||
let where_bounds_that_match = icx.type_parameter_bounds_in_generics(
|
let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics(
|
||||||
generics,
|
generics,
|
||||||
item.owner_id.def_id,
|
item.owner_id.def_id,
|
||||||
self_param_ty,
|
self_param_ty,
|
||||||
|
@ -676,7 +676,7 @@ pub(super) fn type_param_predicates(
|
||||||
let mut result = parent
|
let mut result = parent
|
||||||
.map(|parent| {
|
.map(|parent| {
|
||||||
let icx = ItemCtxt::new(tcx, parent);
|
let icx = ItemCtxt::new(tcx, parent);
|
||||||
icx.get_type_parameter_bounds(DUMMY_SP, def_id, assoc_name)
|
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name)
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let mut extend = None;
|
let mut extend = None;
|
||||||
|
@ -696,7 +696,7 @@ pub(super) fn type_param_predicates(
|
||||||
|
|
||||||
let icx = ItemCtxt::new(tcx, item_def_id);
|
let icx = ItemCtxt::new(tcx, item_def_id);
|
||||||
let extra_predicates = extend.into_iter().chain(
|
let extra_predicates = extend.into_iter().chain(
|
||||||
icx.type_parameter_bounds_in_generics(
|
icx.probe_ty_param_bounds_in_generics(
|
||||||
ast_generics,
|
ast_generics,
|
||||||
def_id,
|
def_id,
|
||||||
ty,
|
ty,
|
||||||
|
@ -719,7 +719,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||||
/// would create artificial cycles. Instead, we can only convert the
|
/// would create artificial cycles. Instead, we can only convert the
|
||||||
/// bounds for a type parameter `X` if `X::Foo` is used.
|
/// bounds for a type parameter `X` if `X::Foo` is used.
|
||||||
#[instrument(level = "trace", skip(self, ast_generics))]
|
#[instrument(level = "trace", skip(self, ast_generics))]
|
||||||
fn type_parameter_bounds_in_generics(
|
fn probe_ty_param_bounds_in_generics(
|
||||||
&self,
|
&self,
|
||||||
ast_generics: &'tcx hir::Generics<'tcx>,
|
ast_generics: &'tcx hir::Generics<'tcx>,
|
||||||
param_def_id: LocalDefId,
|
param_def_id: LocalDefId,
|
||||||
|
@ -750,13 +750,13 @@ impl<'tcx> ItemCtxt<'tcx> {
|
||||||
let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) {
|
let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) {
|
||||||
ty
|
ty
|
||||||
} else if matches!(filter, PredicateFilter::All) {
|
} else if matches!(filter, PredicateFilter::All) {
|
||||||
self.to_ty(predicate.bounded_ty)
|
self.lower_ty(predicate.bounded_ty)
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
|
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
|
||||||
self.astconv().add_bounds(
|
self.lowerer().lower_poly_bounds(
|
||||||
bound_ty,
|
bound_ty,
|
||||||
predicate.bounds.iter().filter(|bound| {
|
predicate.bounds.iter().filter(|bound| {
|
||||||
assoc_name
|
assoc_name
|
||||||
|
|
|
@ -1923,12 +1923,12 @@ fn is_late_bound_map(
|
||||||
/// We must therefore "look into" the `Alias` to see whether we should consider `'a` constrained or not.
|
/// We must therefore "look into" the `Alias` to see whether we should consider `'a` constrained or not.
|
||||||
///
|
///
|
||||||
/// See #100508 #85533 #47511 for additional context
|
/// See #100508 #85533 #47511 for additional context
|
||||||
struct ConstrainedCollectorPostAstConv {
|
struct ConstrainedCollectorPostHirTyLowering {
|
||||||
arg_is_constrained: Box<[bool]>,
|
arg_is_constrained: Box<[bool]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
use ty::Ty;
|
use ty::Ty;
|
||||||
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostAstConv {
|
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostHirTyLowering {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) {
|
fn visit_ty(&mut self, t: Ty<'tcx>) {
|
||||||
match t.kind() {
|
match t.kind() {
|
||||||
ty::Param(param_ty) => {
|
ty::Param(param_ty) => {
|
||||||
|
@ -1973,7 +1973,7 @@ fn is_late_bound_map(
|
||||||
// See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider
|
// See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider
|
||||||
// args to be unconstrained.
|
// args to be unconstrained.
|
||||||
let generics = self.tcx.generics_of(alias_def);
|
let generics = self.tcx.generics_of(alias_def);
|
||||||
let mut walker = ConstrainedCollectorPostAstConv {
|
let mut walker = ConstrainedCollectorPostHirTyLowering {
|
||||||
arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(),
|
arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(),
|
||||||
};
|
};
|
||||||
walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity());
|
walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity());
|
||||||
|
|
|
@ -108,7 +108,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.def_id;
|
.def_id;
|
||||||
let ty = ItemCtxt::new(tcx, item_def_id).to_ty(hir_ty);
|
let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty);
|
||||||
|
|
||||||
// Iterate through the generics of the projection to find the one that corresponds to
|
// Iterate through the generics of the projection to find the one that corresponds to
|
||||||
// the def_id that this query was called with. We filter to only type and const args here
|
// the def_id that this query was called with. We filter to only type and const args here
|
||||||
|
@ -369,8 +369,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| icx.to_ty(ty)),
|
.unwrap_or_else(|| icx.lower_ty(ty)),
|
||||||
TraitItemKind::Type(_, Some(ty)) => icx.to_ty(ty),
|
TraitItemKind::Type(_, Some(ty)) => icx.lower_ty(ty),
|
||||||
TraitItemKind::Type(_, None) => {
|
TraitItemKind::Type(_, None) => {
|
||||||
span_bug!(item.span, "associated type missing default");
|
span_bug!(item.span, "associated type missing default");
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
"associated constant",
|
"associated constant",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
icx.to_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImplItemKind::Type(ty) => {
|
ImplItemKind::Type(ty) => {
|
||||||
|
@ -400,7 +400,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
check_feature_inherent_assoc_ty(tcx, item.span);
|
check_feature_inherent_assoc_ty(tcx, item.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
icx.to_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -416,17 +416,17 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
"static variable",
|
"static variable",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
icx.to_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::Const(ty, _, body_id) => {
|
ItemKind::Const(ty, _, body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
|
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
|
||||||
} else {
|
} else {
|
||||||
icx.to_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
|
ItemKind::TyAlias(self_ty, _) => icx.lower_ty(self_ty),
|
||||||
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
|
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
|
||||||
spans if spans.len() > 0 => {
|
spans if spans.len() > 0 => {
|
||||||
let guar = tcx
|
let guar = tcx
|
||||||
|
@ -434,7 +434,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () });
|
.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () });
|
||||||
Ty::new_error(tcx, guar)
|
Ty::new_error(tcx, guar)
|
||||||
}
|
}
|
||||||
_ => icx.to_ty(*self_ty),
|
_ => icx.lower_ty(*self_ty),
|
||||||
},
|
},
|
||||||
ItemKind::Fn(..) => {
|
ItemKind::Fn(..) => {
|
||||||
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
||||||
|
@ -466,7 +466,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
|
||||||
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
|
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
|
||||||
}
|
}
|
||||||
ForeignItemKind::Static(t, _) => icx.to_ty(t),
|
ForeignItemKind::Static(t, _) => icx.lower_ty(t),
|
||||||
ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()),
|
ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Node::Field(field) => icx.to_ty(field.ty),
|
Node::Field(field) => icx.lower_ty(field.ty),
|
||||||
|
|
||||||
Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => {
|
Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => {
|
||||||
tcx.typeck(def_id).node_type(hir_id)
|
tcx.typeck(def_id).node_type(hir_id)
|
||||||
|
@ -495,7 +495,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
||||||
|
|
||||||
Node::GenericParam(param) => match ¶m.kind {
|
Node::GenericParam(param) => match ¶m.kind {
|
||||||
GenericParamKind::Type { default: Some(ty), .. }
|
GenericParamKind::Type { default: Some(ty), .. }
|
||||||
| GenericParamKind::Const { ty, .. } => icx.to_ty(ty),
|
| GenericParamKind::Const { ty, .. } => icx.lower_ty(ty),
|
||||||
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
|
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ fn diagnostic_hir_wf_check<'tcx>(
|
||||||
let infcx = self.tcx.infer_ctxt().build();
|
let infcx = self.tcx.infer_ctxt().build();
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
|
|
||||||
let tcx_ty = self.icx.to_ty(ty);
|
let tcx_ty = self.icx.lower_ty(ty);
|
||||||
// This visitor can walk into binders, resulting in the `tcx_ty` to
|
// This visitor can walk into binders, resulting in the `tcx_ty` to
|
||||||
// potentially reference escaping bound variables. We simply erase
|
// potentially reference escaping bound variables. We simply erase
|
||||||
// those here.
|
// those here.
|
||||||
|
|
|
@ -213,10 +213,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
|
|
||||||
/// A quasi-deprecated helper used in rustdoc and clippy to get
|
/// A quasi-deprecated helper used in rustdoc and clippy to get
|
||||||
/// the type from a HIR node.
|
/// the type from a HIR node.
|
||||||
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
||||||
// In case there are any projections, etc., find the "environment"
|
// In case there are any projections, etc., find the "environment"
|
||||||
// def-ID that will be used to determine the traits/predicates in
|
// def-ID that will be used to determine the traits/predicates in
|
||||||
// scope. This is derived from the enclosing item-like thing.
|
// scope. This is derived from the enclosing item-like thing.
|
||||||
let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id);
|
let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id);
|
||||||
collect::ItemCtxt::new(tcx, env_def_id.def_id).to_ty(hir_ty)
|
collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use super::{check_fn, CoroutineTypes, Expectation, FnCtxt};
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
|
||||||
use rustc_infer::infer::{InferOk, InferResult};
|
use rustc_infer::infer::{InferOk, InferResult};
|
||||||
|
@ -784,7 +784,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
decl: &hir::FnDecl<'tcx>,
|
decl: &hir::FnDecl<'tcx>,
|
||||||
closure_kind: hir::ClosureKind,
|
closure_kind: hir::ClosureKind,
|
||||||
) -> ty::PolyFnSig<'tcx> {
|
) -> ty::PolyFnSig<'tcx> {
|
||||||
let astconv = self.astconv();
|
let lowerer = self.lowerer();
|
||||||
|
|
||||||
trace!("decl = {:#?}", decl);
|
trace!("decl = {:#?}", decl);
|
||||||
debug!(?closure_kind);
|
debug!(?closure_kind);
|
||||||
|
@ -793,9 +793,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let bound_vars = self.tcx.late_bound_vars(hir_id);
|
let bound_vars = self.tcx.late_bound_vars(hir_id);
|
||||||
|
|
||||||
// First, convert the types that the user supplied (if any).
|
// First, convert the types that the user supplied (if any).
|
||||||
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
|
let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a));
|
||||||
let supplied_return = match decl.output {
|
let supplied_return = match decl.output {
|
||||||
hir::FnRetTy::Return(ref output) => astconv.ast_ty_to_ty(output),
|
hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output),
|
||||||
hir::FnRetTy::DefaultReturn(_) => match closure_kind {
|
hir::FnRetTy::DefaultReturn(_) => match closure_kind {
|
||||||
// In the case of the async block that we create for a function body,
|
// In the case of the async block that we create for a function body,
|
||||||
// we expect the return type of the block to match that of the enclosing
|
// we expect the return type of the block to match that of the enclosing
|
||||||
|
@ -813,7 +813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// easily (and locally) prove that we
|
// easily (and locally) prove that we
|
||||||
// *have* reported an
|
// *have* reported an
|
||||||
// error. --nikomatsakis
|
// error. --nikomatsakis
|
||||||
astconv.ty_infer(None, decl.output.span())
|
lowerer.ty_infer(None, decl.output.span())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// All `gen {}` and `async gen {}` must return unit.
|
// All `gen {}` and `async gen {}` must return unit.
|
||||||
|
@ -832,7 +832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
| hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
|
| hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_))
|
||||||
| hir::ClosureKind::Closure
|
| hir::ClosureKind::Closure
|
||||||
| hir::ClosureKind::CoroutineClosure(_) => {
|
| hir::ClosureKind::CoroutineClosure(_) => {
|
||||||
astconv.ty_infer(None, decl.output.span())
|
lowerer.ty_infer(None, decl.output.span())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -989,17 +989,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
decl: &hir::FnDecl<'tcx>,
|
decl: &hir::FnDecl<'tcx>,
|
||||||
guar: ErrorGuaranteed,
|
guar: ErrorGuaranteed,
|
||||||
) -> ty::PolyFnSig<'tcx> {
|
) -> ty::PolyFnSig<'tcx> {
|
||||||
let astconv = self.astconv();
|
let lowerer = self.lowerer();
|
||||||
let err_ty = Ty::new_error(self.tcx, guar);
|
let err_ty = Ty::new_error(self.tcx, guar);
|
||||||
|
|
||||||
let supplied_arguments = decl.inputs.iter().map(|a| {
|
let supplied_arguments = decl.inputs.iter().map(|a| {
|
||||||
// Convert the types that the user supplied (if any), but ignore them.
|
// Convert the types that the user supplied (if any), but ignore them.
|
||||||
astconv.ast_ty_to_ty(a);
|
lowerer.lower_ty(a);
|
||||||
err_ty
|
err_ty
|
||||||
});
|
});
|
||||||
|
|
||||||
if let hir::FnRetTy::Return(ref output) = decl.output {
|
if let hir::FnRetTy::Return(ref output) = decl.output {
|
||||||
astconv.ast_ty_to_ty(output);
|
lowerer.lower_ty(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(
|
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(
|
||||||
|
|
|
@ -41,7 +41,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::Expr;
|
use rustc_hir::Expr;
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
|
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
|
||||||
use rustc_infer::traits::TraitEngine;
|
use rustc_infer::traits::TraitEngine;
|
||||||
|
|
|
@ -35,7 +35,7 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{ExprKind, HirId, QPath};
|
use rustc_hir::{ExprKind, HirId, QPath};
|
||||||
use rustc_hir_analysis::astconv::AstConv as _;
|
use rustc_hir_analysis::astconv::HirTyLowerer as _;
|
||||||
use rustc_hir_analysis::check::ty_kind_suggestion;
|
use rustc_hir_analysis::check::ty_kind_suggestion;
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
|
@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr),
|
ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr),
|
||||||
ExprKind::Type(e, t) => {
|
ExprKind::Type(e, t) => {
|
||||||
let ascribed_ty = self.to_ty_saving_user_provided_ty(t);
|
let ascribed_ty = self.lower_ty_saving_user_provided_ty(t);
|
||||||
let ty = self.check_expr_with_hint(e, ascribed_ty);
|
let ty = self.check_expr_with_hint(e, ascribed_ty);
|
||||||
self.demand_eqtype(e.span, ascribed_ty, ty);
|
self.demand_eqtype(e.span, ascribed_ty, ty);
|
||||||
ascribed_ty
|
ascribed_ty
|
||||||
|
@ -1375,7 +1375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
// Find the type of `e`. Supply hints based on the type we are casting to,
|
// Find the type of `e`. Supply hints based on the type we are casting to,
|
||||||
// if appropriate.
|
// if appropriate.
|
||||||
let t_cast = self.to_ty_saving_user_provided_ty(t);
|
let t_cast = self.lower_ty_saving_user_provided_ty(t);
|
||||||
let t_cast = self.resolve_vars_if_possible(t_cast);
|
let t_cast = self.resolve_vars_if_possible(t_cast);
|
||||||
let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
|
let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
|
||||||
let t_expr = self.resolve_vars_if_possible(t_expr);
|
let t_expr = self.resolve_vars_if_possible(t_expr);
|
||||||
|
@ -1503,7 +1503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let count = self.array_length_to_const(count);
|
let count = self.lower_array_length(count);
|
||||||
if let Some(count) = count.try_eval_target_usize(tcx, self.param_env) {
|
if let Some(count) = count.try_eval_target_usize(tcx, self.param_env) {
|
||||||
self.suggest_array_len(expr, count);
|
self.suggest_array_len(expr, count);
|
||||||
}
|
}
|
||||||
|
@ -3283,7 +3283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fields: &[Ident],
|
fields: &[Ident],
|
||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let container = self.to_ty(container).normalized;
|
let container = self.lower_ty(container).normalized;
|
||||||
|
|
||||||
if let Some(ident_2) = fields.get(1)
|
if let Some(ident_2) = fields.get(1)
|
||||||
&& !self.tcx.features().offset_of_nested
|
&& !self.tcx.features().offset_of_nested
|
||||||
|
|
|
@ -11,12 +11,10 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{ExprKind, GenericArg, Node, QPath};
|
use rustc_hir::{ExprKind, GenericArg, Node, QPath};
|
||||||
use rustc_hir_analysis::astconv::generics::{
|
use rustc_hir_analysis::astconv::generics::{check_generic_arg_count_for_call, lower_generic_args};
|
||||||
check_generic_arg_count_for_call, create_args_for_parent_generic_args,
|
|
||||||
};
|
|
||||||
use rustc_hir_analysis::astconv::{
|
use rustc_hir_analysis::astconv::{
|
||||||
AstConv, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
|
ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer,
|
||||||
GenericArgCountResult, IsMethodCall, PathSeg,
|
GenericPathSegment, HirTyLowerer, IsMethodCall,
|
||||||
};
|
};
|
||||||
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
|
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
|
||||||
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
||||||
|
@ -394,14 +392,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
|
pub fn lower_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
|
||||||
let t = self.astconv().ast_ty_to_ty(ast_t);
|
let t = self.lowerer().lower_ty(ast_t);
|
||||||
self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None));
|
self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None));
|
||||||
LoweredTy::from_raw(self, ast_t.span, t)
|
LoweredTy::from_raw(self, ast_t.span, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
pub fn lower_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
||||||
let ty = self.to_ty(ast_ty);
|
let ty = self.lower_ty(ast_ty);
|
||||||
debug!("to_ty_saving_user_provided_ty: ty={:?}", ty);
|
debug!("to_ty_saving_user_provided_ty: ty={:?}", ty);
|
||||||
|
|
||||||
if Self::can_contain_user_lifetime_bounds(ty.raw) {
|
if Self::can_contain_user_lifetime_bounds(ty.raw) {
|
||||||
|
@ -424,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
|
pub fn lower_array_length(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
|
||||||
match length {
|
match length {
|
||||||
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
|
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
|
||||||
hir::ArrayLen::Body(anon_const) => {
|
hir::ArrayLen::Body(anon_const) => {
|
||||||
|
@ -436,11 +434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_arg_to_const(
|
pub fn lower_const_arg(&self, ast_c: &hir::AnonConst, param_def_id: DefId) -> ty::Const<'tcx> {
|
||||||
&self,
|
|
||||||
ast_c: &hir::AnonConst,
|
|
||||||
param_def_id: DefId,
|
|
||||||
) -> ty::Const<'tcx> {
|
|
||||||
let did = ast_c.def_id;
|
let did = ast_c.def_id;
|
||||||
self.tcx.feed_anon_const_type(did, self.tcx.type_of(param_def_id));
|
self.tcx.feed_anon_const_type(did, self.tcx.type_of(param_def_id));
|
||||||
let c = ty::Const::from_anon_const(self.tcx, did);
|
let c = ty::Const::from_anon_const(self.tcx, did);
|
||||||
|
@ -827,7 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
QPath::Resolved(ref opt_qself, path) => {
|
QPath::Resolved(ref opt_qself, path) => {
|
||||||
return (
|
return (
|
||||||
path.res,
|
path.res,
|
||||||
opt_qself.as_ref().map(|qself| self.to_ty(qself)),
|
opt_qself.as_ref().map(|qself| self.lower_ty(qself)),
|
||||||
path.segments,
|
path.segments,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -841,7 +835,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// to be object-safe.
|
// to be object-safe.
|
||||||
// We manually call `register_wf_obligation` in the success path
|
// We manually call `register_wf_obligation` in the success path
|
||||||
// below.
|
// below.
|
||||||
let ty = self.astconv().ast_ty_to_ty_in_path(qself);
|
let ty = self.lowerer().lower_ty_in_path(qself);
|
||||||
(LoweredTy::from_raw(self, span, ty), qself, segment)
|
(LoweredTy::from_raw(self, span, ty), qself, segment)
|
||||||
}
|
}
|
||||||
QPath::LangItem(..) => {
|
QPath::LangItem(..) => {
|
||||||
|
@ -1119,9 +1113,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> (Ty<'tcx>, Res) {
|
) -> (Ty<'tcx>, Res) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
let path_segs = match res {
|
let generic_segments = match res {
|
||||||
Res::Local(_) | Res::SelfCtor(_) => vec![],
|
Res::Local(_) | Res::SelfCtor(_) => vec![],
|
||||||
Res::Def(kind, def_id) => self.astconv().def_ids_for_value_path_segments(
|
Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments(
|
||||||
segments,
|
segments,
|
||||||
self_ty.map(|ty| ty.raw),
|
self_ty.map(|ty| ty.raw),
|
||||||
kind,
|
kind,
|
||||||
|
@ -1178,14 +1172,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// provided (if any) into their appropriate spaces. We'll also report
|
// provided (if any) into their appropriate spaces. We'll also report
|
||||||
// errors if type parameters are provided in an inappropriate place.
|
// errors if type parameters are provided in an inappropriate place.
|
||||||
|
|
||||||
let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect();
|
let indices: FxHashSet<_> =
|
||||||
let generics_has_err = self.astconv().prohibit_generics(
|
generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
|
||||||
|
let generics_has_err = self.lowerer().prohibit_generic_args(
|
||||||
segments.iter().enumerate().filter_map(|(index, seg)| {
|
segments.iter().enumerate().filter_map(|(index, seg)| {
|
||||||
if !generic_segs.contains(&index) || is_alias_variant_ctor {
|
if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None }
|
||||||
Some(seg)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|_| {},
|
|_| {},
|
||||||
);
|
);
|
||||||
|
@ -1212,7 +1203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let mut infer_args_for_err = FxHashSet::default();
|
let mut infer_args_for_err = FxHashSet::default();
|
||||||
|
|
||||||
let mut explicit_late_bound = ExplicitLateBound::No;
|
let mut explicit_late_bound = ExplicitLateBound::No;
|
||||||
for &PathSeg(def_id, index) in &path_segs {
|
for &GenericPathSegment(def_id, index) in &generic_segments {
|
||||||
let seg = &segments[index];
|
let seg = &segments[index];
|
||||||
let generics = tcx.generics_of(def_id);
|
let generics = tcx.generics_of(def_id);
|
||||||
|
|
||||||
|
@ -1233,8 +1224,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let has_self =
|
let has_self = generic_segments
|
||||||
path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self);
|
.last()
|
||||||
|
.is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self);
|
||||||
|
|
||||||
let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res {
|
let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res {
|
||||||
let ty = LoweredTy::from_raw(
|
let ty = LoweredTy::from_raw(
|
||||||
|
@ -1294,22 +1286,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CreateCtorInstantiationsContext<'a, 'tcx> {
|
struct CtorGenericArgsCtxt<'a, 'tcx> {
|
||||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
path_segs: &'a [PathSeg],
|
generic_segments: &'a [GenericPathSegment],
|
||||||
infer_args_for_err: &'a FxHashSet<usize>,
|
infer_args_for_err: &'a FxHashSet<usize>,
|
||||||
segments: &'tcx [hir::PathSegment<'tcx>],
|
segments: &'tcx [hir::PathSegment<'tcx>],
|
||||||
}
|
}
|
||||||
impl<'tcx, 'a> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>
|
impl<'tcx, 'a> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> {
|
||||||
for CreateCtorInstantiationsContext<'a, 'tcx>
|
|
||||||
{
|
|
||||||
fn args_for_def_id(
|
fn args_for_def_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
|
) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
|
||||||
if let Some(&PathSeg(_, index)) =
|
if let Some(&GenericPathSegment(_, index)) =
|
||||||
self.path_segs.iter().find(|&PathSeg(did, _)| *did == def_id)
|
self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id)
|
||||||
{
|
{
|
||||||
// If we've encountered an `impl Trait`-related error, we're just
|
// If we've encountered an `impl Trait`-related error, we're just
|
||||||
// going to infer the arguments for better error messages.
|
// going to infer the arguments for better error messages.
|
||||||
|
@ -1332,13 +1322,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
match (¶m.kind, arg) {
|
match (¶m.kind, arg) {
|
||||||
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
||||||
self.fcx.astconv().ast_region_to_region(lt, Some(param)).into()
|
self.fcx.lowerer().lower_lifetime(lt, Some(param)).into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
|
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
|
||||||
self.fcx.to_ty(ty).raw.into()
|
self.fcx.lower_ty(ty).raw.into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
||||||
self.fcx.const_arg_to_const(&ct.value, param.def_id).into()
|
self.fcx.lower_const_arg(&ct.value, param.def_id).into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
|
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
|
||||||
self.fcx.ty_infer(Some(param), inf.span).into()
|
self.fcx.ty_infer(Some(param), inf.span).into()
|
||||||
|
@ -1420,17 +1410,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let args_raw = self_ctor_args.unwrap_or_else(|| {
|
let args_raw = self_ctor_args.unwrap_or_else(|| {
|
||||||
create_args_for_parent_generic_args(
|
lower_generic_args(
|
||||||
tcx,
|
tcx,
|
||||||
def_id,
|
def_id,
|
||||||
&[],
|
&[],
|
||||||
has_self,
|
has_self,
|
||||||
self_ty.map(|s| s.raw),
|
self_ty.map(|s| s.raw),
|
||||||
&arg_count,
|
&arg_count,
|
||||||
&mut CreateCtorInstantiationsContext {
|
&mut CtorGenericArgsCtxt {
|
||||||
fcx: self,
|
fcx: self,
|
||||||
span,
|
span,
|
||||||
path_segs: &path_segs,
|
generic_segments: &generic_segments,
|
||||||
infer_args_for_err: &infer_args_for_err,
|
infer_args_for_err: &infer_args_for_err,
|
||||||
segments,
|
segments,
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::{ExprKind, Node, QPath};
|
use rustc_hir::{ExprKind, Node, QPath};
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
||||||
use rustc_hir_analysis::check::potentially_plural_count;
|
use rustc_hir_analysis::check::potentially_plural_count;
|
||||||
use rustc_hir_analysis::structured_errors::StructuredDiag;
|
use rustc_hir_analysis::structured_errors::StructuredDiag;
|
||||||
|
@ -1961,16 +1961,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
) -> (Res, LoweredTy<'tcx>) {
|
) -> (Res, LoweredTy<'tcx>) {
|
||||||
match *qpath {
|
match *qpath {
|
||||||
QPath::Resolved(ref maybe_qself, path) => {
|
QPath::Resolved(ref maybe_qself, path) => {
|
||||||
let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw);
|
let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself).raw);
|
||||||
let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true);
|
let ty = self.lowerer().lower_path(self_ty, path, hir_id, true);
|
||||||
(path.res, LoweredTy::from_raw(self, path_span, ty))
|
(path.res, LoweredTy::from_raw(self, path_span, ty))
|
||||||
}
|
}
|
||||||
QPath::TypeRelative(qself, segment) => {
|
QPath::TypeRelative(qself, segment) => {
|
||||||
let ty = self.to_ty(qself);
|
let ty = self.lower_ty(qself);
|
||||||
|
|
||||||
let result = self
|
let result = self
|
||||||
.astconv()
|
.lowerer()
|
||||||
.associated_path_to_ty(hir_id, path_span, ty.raw, qself, segment, true);
|
.lower_assoc_path(hir_id, path_span, ty.raw, qself, segment, true);
|
||||||
let ty = result
|
let ty = result
|
||||||
.map(|(ty, _, _)| ty)
|
.map(|(ty, _, _)| ty)
|
||||||
.unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
|
.unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
|
||||||
|
|
|
@ -12,7 +12,7 @@ use hir::def_id::CRATE_DEF_ID;
|
||||||
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
|
use rustc_errors::{DiagCtxt, ErrorGuaranteed};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
|
use rustc_infer::infer::error_reporting::sub_relations::SubRelations;
|
||||||
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
use rustc_infer::infer::error_reporting::TypeErrCtxt;
|
||||||
|
@ -212,7 +212,7 @@ impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||||
self.tcx
|
self.tcx
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
self.body_id.to_def_id()
|
self.body_id.to_def_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type_parameter_bounds(
|
fn probe_ty_param_bounds(
|
||||||
&self,
|
&self,
|
||||||
_: Span,
|
_: Span,
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
|
@ -256,7 +256,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
Some(self.next_region_var(v))
|
Some(self.next_region_var(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allow_ty_infer(&self) -> bool {
|
fn allow_infer(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn projected_ty_from_poly_trait_ref(
|
fn lower_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
|
@ -305,7 +305,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
poly_trait_ref,
|
poly_trait_ref,
|
||||||
);
|
);
|
||||||
|
|
||||||
let item_args = self.astconv().create_args_for_associated_item(
|
let item_args = self.lowerer().lower_generic_args_of_assoc_item(
|
||||||
span,
|
span,
|
||||||
item_def_id,
|
item_def_id,
|
||||||
item_segment,
|
item_segment,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use rustc_hir::{
|
||||||
CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node,
|
CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node,
|
||||||
Path, QPath, Stmt, StmtKind, TyKind, WherePredicate,
|
Path, QPath, Stmt, StmtKind, TyKind, WherePredicate,
|
||||||
};
|
};
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_infer::traits::{self};
|
use rustc_infer::traits::{self};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::middle::stability::EvalResult;
|
use rustc_middle::middle::stability::EvalResult;
|
||||||
|
@ -877,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Only point to return type if the expected type is the return type, as if they
|
// Only point to return type if the expected type is the return type, as if they
|
||||||
// are not, the expectation must have been caused by something else.
|
// are not, the expectation must have been caused by something else.
|
||||||
debug!("return type {:?}", hir_ty);
|
debug!("return type {:?}", hir_ty);
|
||||||
let ty = self.astconv().ast_ty_to_ty(hir_ty);
|
let ty = self.lowerer().lower_ty(hir_ty);
|
||||||
debug!("return type {:?}", ty);
|
debug!("return type {:?}", ty);
|
||||||
debug!("expected type {:?}", expected);
|
debug!("expected type {:?}", expected);
|
||||||
let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());
|
let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());
|
||||||
|
@ -958,7 +958,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
// FIXME: Maybe these calls to `ast_ty_to_ty` can be removed (and the ones below)
|
// FIXME: Maybe these calls to `ast_ty_to_ty` can be removed (and the ones below)
|
||||||
let ty = self.astconv().ast_ty_to_ty(bounded_ty);
|
let ty = self.lowerer().lower_ty(bounded_ty);
|
||||||
Some((ty, bounds))
|
Some((ty, bounds))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -996,7 +996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let all_bounds_str = all_matching_bounds_strs.join(" + ");
|
let all_bounds_str = all_matching_bounds_strs.join(" + ");
|
||||||
|
|
||||||
let ty_param_used_in_fn_params = fn_parameters.iter().any(|param| {
|
let ty_param_used_in_fn_params = fn_parameters.iter().any(|param| {
|
||||||
let ty = self.astconv().ast_ty_to_ty( param);
|
let ty = self.lowerer().lower_ty( param);
|
||||||
matches!(ty.kind(), ty::Param(fn_param_ty_param) if expected_ty_as_param == fn_param_ty_param)
|
matches!(ty.kind(), ty::Param(fn_param_ty_param) if expected_ty_as_param == fn_param_ty_param)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1071,7 +1071,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
let can_return = match fn_decl.output {
|
let can_return = match fn_decl.output {
|
||||||
hir::FnRetTy::Return(ty) => {
|
hir::FnRetTy::Return(ty) => {
|
||||||
let ty = self.astconv().ast_ty_to_ty(ty);
|
let ty = self.lowerer().lower_ty(ty);
|
||||||
let bound_vars = self.tcx.late_bound_vars(fn_id);
|
let bound_vars = self.tcx.late_bound_vars(fn_id);
|
||||||
let ty = self
|
let ty = self
|
||||||
.tcx
|
.tcx
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
||||||
fn declare(&mut self, decl: Declaration<'tcx>) {
|
fn declare(&mut self, decl: Declaration<'tcx>) {
|
||||||
let local_ty = match decl.ty {
|
let local_ty = match decl.ty {
|
||||||
Some(ref ty) => {
|
Some(ref ty) => {
|
||||||
let o_ty = self.fcx.to_ty(ty);
|
let o_ty = self.fcx.lower_ty(ty);
|
||||||
|
|
||||||
let c_ty =
|
let c_ty =
|
||||||
self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw));
|
self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw));
|
||||||
|
|
|
@ -57,7 +57,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::{HirIdMap, Node};
|
use rustc_hir::{HirIdMap, Node};
|
||||||
use rustc_hir_analysis::astconv::AstConv;
|
use rustc_hir_analysis::astconv::HirTyLowerer;
|
||||||
use rustc_hir_analysis::check::check_abi;
|
use rustc_hir_analysis::check::check_abi;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||||
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
|
||||||
|
@ -178,7 +178,7 @@ fn typeck_with_fallback<'tcx>(
|
||||||
|
|
||||||
if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
|
if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
|
||||||
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
|
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
|
||||||
fcx.astconv().ty_of_fn(id, header.unsafety, header.abi, decl, None, None)
|
fcx.lowerer().lower_fn_ty(id, header.unsafety, header.abi, decl, None, None)
|
||||||
} else {
|
} else {
|
||||||
tcx.fn_sig(def_id).instantiate_identity()
|
tcx.fn_sig(def_id).instantiate_identity()
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,10 +4,8 @@ use crate::{callee, FnCtxt};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::GenericArg;
|
use rustc_hir::GenericArg;
|
||||||
use rustc_hir_analysis::astconv::generics::{
|
use rustc_hir_analysis::astconv::generics::{check_generic_arg_count_for_call, lower_generic_args};
|
||||||
check_generic_arg_count_for_call, create_args_for_parent_generic_args,
|
use rustc_hir_analysis::astconv::{GenericArgsLowerer, HirTyLowerer, IsMethodCall};
|
||||||
};
|
|
||||||
use rustc_hir_analysis::astconv::{AstConv, CreateInstantiationsForGenericArgsCtxt, IsMethodCall};
|
|
||||||
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
|
||||||
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
|
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
|
||||||
|
@ -366,14 +364,12 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
// combining parameters from the type and those from the method.
|
// combining parameters from the type and those from the method.
|
||||||
assert_eq!(generics.parent_count, parent_args.len());
|
assert_eq!(generics.parent_count, parent_args.len());
|
||||||
|
|
||||||
struct MethodInstantiationsCtxt<'a, 'tcx> {
|
struct GenericArgsCtxt<'a, 'tcx> {
|
||||||
cfcx: &'a ConfirmContext<'a, 'tcx>,
|
cfcx: &'a ConfirmContext<'a, 'tcx>,
|
||||||
pick: &'a probe::Pick<'tcx>,
|
pick: &'a probe::Pick<'tcx>,
|
||||||
seg: &'a hir::PathSegment<'tcx>,
|
seg: &'a hir::PathSegment<'tcx>,
|
||||||
}
|
}
|
||||||
impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>
|
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
|
||||||
for MethodInstantiationsCtxt<'a, 'tcx>
|
|
||||||
{
|
|
||||||
fn args_for_def_id(
|
fn args_for_def_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
|
@ -393,13 +389,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
match (¶m.kind, arg) {
|
match (¶m.kind, arg) {
|
||||||
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
||||||
self.cfcx.fcx.astconv().ast_region_to_region(lt, Some(param)).into()
|
self.cfcx.fcx.lowerer().lower_lifetime(lt, Some(param)).into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
|
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
|
||||||
self.cfcx.to_ty(ty).raw.into()
|
self.cfcx.lower_ty(ty).raw.into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
||||||
self.cfcx.const_arg_to_const(&ct.value, param.def_id).into()
|
self.cfcx.lower_const_arg(&ct.value, param.def_id).into()
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
|
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
|
||||||
self.cfcx.ty_infer(Some(param), inf.span).into()
|
self.cfcx.ty_infer(Some(param), inf.span).into()
|
||||||
|
@ -432,14 +428,14 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let args = create_args_for_parent_generic_args(
|
let args = lower_generic_args(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
pick.item.def_id,
|
pick.item.def_id,
|
||||||
parent_args,
|
parent_args,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
&arg_count_correct,
|
&arg_count_correct,
|
||||||
&mut MethodInstantiationsCtxt { cfcx: self, pick, seg },
|
&mut GenericArgsCtxt { cfcx: self, pick, seg },
|
||||||
);
|
);
|
||||||
|
|
||||||
// When the method is confirmed, the `args` includes
|
// When the method is confirmed, the `args` includes
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub use self::coherence::{IsFirstInputType, OrphanCheckErr, OverlapResult};
|
||||||
pub use self::engine::{ObligationCtxt, TraitEngineExt};
|
pub use self::engine::{ObligationCtxt, TraitEngineExt};
|
||||||
pub use self::fulfill::{FulfillmentContext, PendingPredicateObligation};
|
pub use self::fulfill::{FulfillmentContext, PendingPredicateObligation};
|
||||||
pub use self::normalize::NormalizeExt;
|
pub use self::normalize::NormalizeExt;
|
||||||
pub use self::object_safety::astconv_object_safety_violations;
|
pub use self::object_safety::hir_ty_lowering_object_safety_violations;
|
||||||
pub use self::object_safety::is_vtable_safe_method;
|
pub use self::object_safety::is_vtable_safe_method;
|
||||||
pub use self::object_safety::object_safety_violations_for_assoc_item;
|
pub use self::object_safety::object_safety_violations_for_assoc_item;
|
||||||
pub use self::object_safety::ObjectSafetyViolation;
|
pub use self::object_safety::ObjectSafetyViolation;
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation};
|
||||||
/// astconv -- currently, `Self` in supertraits. This is needed
|
/// astconv -- currently, `Self` in supertraits. This is needed
|
||||||
/// because `object_safety_violations` can't be used during
|
/// because `object_safety_violations` can't be used during
|
||||||
/// type collection.
|
/// type collection.
|
||||||
pub fn astconv_object_safety_violations(
|
pub fn hir_ty_lowering_object_safety_violations(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
) -> Vec<ObjectSafetyViolation> {
|
) -> Vec<ObjectSafetyViolation> {
|
||||||
|
|
|
@ -20,7 +20,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
|
||||||
use rustc_hir::PredicateOrigin;
|
use rustc_hir::PredicateOrigin;
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
|
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
|
||||||
use rustc_middle::metadata::Reexport;
|
use rustc_middle::metadata::Reexport;
|
||||||
use rustc_middle::middle::resolve_bound_vars as rbv;
|
use rustc_middle::middle::resolve_bound_vars as rbv;
|
||||||
|
@ -1260,12 +1260,8 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
|
||||||
hir::TraitItemKind::Type(bounds, Some(default)) => {
|
hir::TraitItemKind::Type(bounds, Some(default)) => {
|
||||||
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
|
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
|
||||||
let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
|
let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
|
||||||
let item_type = clean_middle_ty(
|
let item_type =
|
||||||
ty::Binder::dummy(hir_ty_to_ty(cx.tcx, default)),
|
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, default)), cx, None, None);
|
||||||
cx,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
AssocTypeItem(
|
AssocTypeItem(
|
||||||
Box::new(TypeAlias {
|
Box::new(TypeAlias {
|
||||||
type_: clean_ty(default, cx),
|
type_: clean_ty(default, cx),
|
||||||
|
@ -1306,12 +1302,8 @@ pub(crate) fn clean_impl_item<'tcx>(
|
||||||
hir::ImplItemKind::Type(hir_ty) => {
|
hir::ImplItemKind::Type(hir_ty) => {
|
||||||
let type_ = clean_ty(hir_ty, cx);
|
let type_ = clean_ty(hir_ty, cx);
|
||||||
let generics = clean_generics(impl_.generics, cx);
|
let generics = clean_generics(impl_.generics, cx);
|
||||||
let item_type = clean_middle_ty(
|
let item_type =
|
||||||
ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)),
|
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None);
|
||||||
cx,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
AssocTypeItem(
|
AssocTypeItem(
|
||||||
Box::new(TypeAlias {
|
Box::new(TypeAlias {
|
||||||
type_,
|
type_,
|
||||||
|
@ -1690,7 +1682,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
|
||||||
}
|
}
|
||||||
hir::QPath::Resolved(Some(qself), p) => {
|
hir::QPath::Resolved(Some(qself), p) => {
|
||||||
// Try to normalize `<X as Y>::T` to a type
|
// Try to normalize `<X as Y>::T` to a type
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = lower_ty(cx.tcx, hir_ty);
|
||||||
// `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>`
|
// `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>`
|
||||||
if !ty.has_escaping_bound_vars()
|
if !ty.has_escaping_bound_vars()
|
||||||
&& let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty))
|
&& let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty))
|
||||||
|
@ -1716,7 +1708,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
hir::QPath::TypeRelative(qself, segment) => {
|
hir::QPath::TypeRelative(qself, segment) => {
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = lower_ty(cx.tcx, hir_ty);
|
||||||
let self_type = clean_ty(qself, cx);
|
let self_type = clean_ty(qself, cx);
|
||||||
|
|
||||||
let (trait_, should_show_cast) = match ty.kind() {
|
let (trait_, should_show_cast) = match ty.kind() {
|
||||||
|
@ -2742,12 +2734,8 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||||
ItemKind::TyAlias(hir_ty, generics) => {
|
ItemKind::TyAlias(hir_ty, generics) => {
|
||||||
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
|
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
|
||||||
let rustdoc_ty = clean_ty(hir_ty, cx);
|
let rustdoc_ty = clean_ty(hir_ty, cx);
|
||||||
let type_ = clean_middle_ty(
|
let type_ =
|
||||||
ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)),
|
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None);
|
||||||
cx,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
let generics = clean_generics(generics, cx);
|
let generics = clean_generics(generics, cx);
|
||||||
if let Some(count) = cx.current_type_aliases.get_mut(&def_id) {
|
if let Some(count) = cx.current_type_aliases.get_mut(&def_id) {
|
||||||
*count -= 1;
|
*count -= 1;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_errors::Diag;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor};
|
use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor};
|
||||||
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
|
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::ty::{Ty, TypeckResults};
|
use rustc_middle::ty::{Ty, TypeckResults};
|
||||||
|
@ -227,7 +227,7 @@ impl<'tcx> ImplicitHasherType<'tcx> {
|
||||||
.collect();
|
.collect();
|
||||||
let params_len = params.len();
|
let params_len = params.len();
|
||||||
|
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = lower_ty(cx.tcx, hir_ty);
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 {
|
if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 {
|
||||||
Some(ImplicitHasherType::HashMap(
|
Some(ImplicitHasherType::HashMap(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_hir::{
|
||||||
GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding,
|
GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding,
|
||||||
WherePredicate,
|
WherePredicate,
|
||||||
};
|
};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt};
|
use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
|
@ -146,7 +146,7 @@ fn try_resolve_type<'tcx>(
|
||||||
index: usize,
|
index: usize,
|
||||||
) -> Option<Ty<'tcx>> {
|
) -> Option<Ty<'tcx>> {
|
||||||
match args.get(index - 1) {
|
match args.get(index - 1) {
|
||||||
Some(GenericArg::Type(ty)) => Some(hir_ty_to_ty(tcx, ty)),
|
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
|
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use clippy_utils::{path_def_id, qpath_generic_tys};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{self as hir, QPath, TyKind};
|
use rustc_hir::{self as hir, QPath, TyKind};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty::TypeVisitableExt;
|
use rustc_middle::ty::TypeVisitableExt;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
|
@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath:
|
||||||
// Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use
|
// Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use
|
||||||
// here because `mod.rs` guarantees this lint is only run on types outside of bodies and
|
// here because `mod.rs` guarantees this lint is only run on types outside of bodies and
|
||||||
// is not run on locals.
|
// is not run on locals.
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = lower_ty(cx.tcx, hir_ty);
|
||||||
if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) {
|
if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind};
|
use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::TypeVisitableExt;
|
use rustc_middle::ty::TypeVisitableExt;
|
||||||
|
@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(
|
||||||
&& let Some(GenericArg::Type(boxed_ty)) = last.args.first()
|
&& let Some(GenericArg::Type(boxed_ty)) = last.args.first()
|
||||||
// extract allocator from the Box for later
|
// extract allocator from the Box for later
|
||||||
&& let boxed_alloc_ty = last.args.get(1)
|
&& let boxed_alloc_ty = last.args.get(1)
|
||||||
&& let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty)
|
&& let ty_ty = lower_ty(cx.tcx, boxed_ty)
|
||||||
&& !ty_ty.has_escaping_bound_vars()
|
&& !ty_ty.has_escaping_bound_vars()
|
||||||
&& ty_ty.is_sized(cx.tcx, cx.param_env)
|
&& ty_ty.is_sized(cx.tcx, cx.param_env)
|
||||||
&& let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes())
|
&& let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes())
|
||||||
|
@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) =>
|
(Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) =>
|
||||||
hir_ty_to_ty(cx.tcx, l) == hir_ty_to_ty(cx.tcx, r),
|
lower_ty(cx.tcx, l) == lower_ty(cx.tcx, r),
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor};
|
use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor};
|
||||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind};
|
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
|
@ -74,7 +74,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op
|
||||||
match qpath {
|
match qpath {
|
||||||
QPath::Resolved(_, path) => path.res.opt_def_id(),
|
QPath::Resolved(_, path) => path.res.opt_def_id(),
|
||||||
QPath::TypeRelative(_, _) => {
|
QPath::TypeRelative(_, _) => {
|
||||||
let ty = hir_ty_to_ty(tcx, &hir_ty);
|
let ty = lower_ty(tcx, &hir_ty);
|
||||||
|
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Alias(ty::Projection, proj) => {
|
ty::Alias(ty::Projection, proj) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use clippy_utils::diagnostics::span_lint;
|
use clippy_utils::diagnostics::span_lint;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp};
|
use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
|
@ -71,7 +71,7 @@ impl LateLintPass<'_> for UninhabitedReferences {
|
||||||
}
|
}
|
||||||
if let FnRetTy::Return(hir_ty) = fndecl.output
|
if let FnRetTy::Return(hir_ty) = fndecl.output
|
||||||
&& let TyKind::Ref(_, mut_ty) = hir_ty.kind
|
&& let TyKind::Ref(_, mut_ty) = hir_ty.kind
|
||||||
&& hir_ty_to_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env)
|
&& lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env)
|
||||||
{
|
{
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use rustc_hir::{
|
||||||
self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl,
|
self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl,
|
||||||
ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind,
|
ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind,
|
||||||
};
|
};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::Ty as MiddleTy;
|
use rustc_middle::ty::Ty as MiddleTy;
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
|
@ -224,7 +224,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
&& let ty = if in_body > 0 {
|
&& let ty = if in_body > 0 {
|
||||||
cx.typeck_results().node_type(hir_ty.hir_id)
|
cx.typeck_results().node_type(hir_ty.hir_id)
|
||||||
} else {
|
} else {
|
||||||
hir_ty_to_ty(cx.tcx, hir_ty)
|
lower_ty(cx.tcx, hir_ty)
|
||||||
}
|
}
|
||||||
&& let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity()
|
&& let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity()
|
||||||
&& same_type_and_consts(ty, impl_ty)
|
&& same_type_and_consts(ty, impl_ty)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use clippy_utils::diagnostics::span_lint_and_help;
|
use clippy_utils::diagnostics::span_lint_and_help;
|
||||||
use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item};
|
use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item};
|
||||||
use rustc_hir::{self as hir, HirId, ItemKind, Node};
|
use rustc_hir::{self as hir, HirId, ItemKind, Node};
|
||||||
use rustc_hir_analysis::hir_ty_to_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::layout::LayoutOf as _;
|
use rustc_middle::ty::layout::LayoutOf as _;
|
||||||
use rustc_middle::ty::{Adt, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{Adt, Ty, TypeVisitableExt};
|
||||||
|
@ -91,5 +91,5 @@ fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'t
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| hir_ty_to_ty(cx.tcx, hir_ty))
|
.unwrap_or_else(|| lower_ty(cx.tcx, hir_ty))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue