mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
Apply nits
This commit is contained in:
parent
3bcdf3058e
commit
fa84018c2e
@ -421,9 +421,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
);
|
);
|
||||||
debug!(?alias_args);
|
debug!(?alias_args);
|
||||||
|
|
||||||
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
|
|
||||||
// *constants* to represent *const projections*. Alias *term* would be a more
|
|
||||||
// appropriate name but alas.
|
|
||||||
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args)
|
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -625,22 +625,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
let bound_predicate = pred.kind();
|
let bound_predicate = pred.kind();
|
||||||
match bound_predicate.skip_binder() {
|
match bound_predicate.skip_binder() {
|
||||||
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
|
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
|
||||||
let pred = bound_predicate.rebind(pred);
|
|
||||||
// `<Foo as Iterator>::Item = String`.
|
// `<Foo as Iterator>::Item = String`.
|
||||||
let projection_term = pred.skip_binder().projection_term;
|
let projection_term = pred.projection_term;
|
||||||
|
let quiet_projection_term =
|
||||||
let args_with_infer_self = tcx.mk_args_from_iter(
|
projection_term.with_self_ty(tcx, Ty::new_var(tcx, ty::TyVid::ZERO));
|
||||||
std::iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
|
|
||||||
.chain(projection_term.args.iter().skip(1)),
|
|
||||||
);
|
|
||||||
|
|
||||||
let quiet_projection_ty =
|
|
||||||
ty::AliasTerm::new(tcx, projection_term.def_id, args_with_infer_self);
|
|
||||||
|
|
||||||
let term = pred.skip_binder().term;
|
|
||||||
|
|
||||||
|
let term = pred.term;
|
||||||
let obligation = format!("{projection_term} = {term}");
|
let obligation = format!("{projection_term} = {term}");
|
||||||
let quiet = format!("{quiet_projection_ty} = {term}");
|
let quiet = format!("{quiet_projection_term} = {term}");
|
||||||
|
|
||||||
bound_span_label(projection_term.self_ty(), &obligation, &quiet);
|
bound_span_label(projection_term.self_ty(), &obligation, &quiet);
|
||||||
Some((obligation, projection_term.self_ty()))
|
Some((obligation, projection_term.self_ty()))
|
||||||
|
@ -258,23 +258,20 @@ fn unconstrained_parent_impl_args<'tcx>(
|
|||||||
// unconstrained parameters.
|
// unconstrained parameters.
|
||||||
for (clause, _) in impl_generic_predicates.predicates.iter() {
|
for (clause, _) in impl_generic_predicates.predicates.iter() {
|
||||||
if let ty::ClauseKind::Projection(proj) = clause.kind().skip_binder() {
|
if let ty::ClauseKind::Projection(proj) = clause.kind().skip_binder() {
|
||||||
let projection_term = proj.projection_term;
|
let unbound_trait_ref = proj.projection_term.trait_ref(tcx);
|
||||||
let projected_term = proj.term;
|
|
||||||
|
|
||||||
let unbound_trait_ref = projection_term.trait_ref(tcx);
|
|
||||||
if Some(unbound_trait_ref) == impl_trait_ref {
|
if Some(unbound_trait_ref) == impl_trait_ref {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unconstrained_parameters.extend(cgp::parameters_for(tcx, projection_term, true));
|
unconstrained_parameters.extend(cgp::parameters_for(tcx, proj.projection_term, true));
|
||||||
|
|
||||||
for param in cgp::parameters_for(tcx, projected_term, false) {
|
for param in cgp::parameters_for(tcx, proj.term, false) {
|
||||||
if !unconstrained_parameters.contains(¶m) {
|
if !unconstrained_parameters.contains(¶m) {
|
||||||
constrained_params.insert(param.0);
|
constrained_params.insert(param.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unconstrained_parameters.extend(cgp::parameters_for(tcx, projected_term, true));
|
unconstrained_parameters.extend(cgp::parameters_for(tcx, proj.term, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ use std::borrow::Cow;
|
|||||||
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
||||||
use super::{CandidateSource, MethodError, NoMatchData};
|
use super::{CandidateSource, MethodError, NoMatchData};
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use std::iter;
|
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||||
@ -788,14 +787,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let pred = bound_predicate.rebind(pred);
|
let pred = bound_predicate.rebind(pred);
|
||||||
// `<Foo as Iterator>::Item = String`.
|
// `<Foo as Iterator>::Item = String`.
|
||||||
let projection_term = pred.skip_binder().projection_term;
|
let projection_term = pred.skip_binder().projection_term;
|
||||||
|
|
||||||
let args_with_infer_self = tcx.mk_args_from_iter(
|
|
||||||
iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
|
|
||||||
.chain(projection_term.args.iter().skip(1)),
|
|
||||||
);
|
|
||||||
|
|
||||||
let quiet_projection_term =
|
let quiet_projection_term =
|
||||||
ty::AliasTerm::new(tcx, projection_term.def_id, args_with_infer_self);
|
projection_term.with_self_ty(tcx, Ty::new_var(tcx, ty::TyVid::ZERO));
|
||||||
|
|
||||||
let term = pred.skip_binder().term;
|
let term = pred.skip_binder().term;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ pub enum ProjectionCacheEntry<'tcx> {
|
|||||||
Ambiguous,
|
Ambiguous,
|
||||||
Recur,
|
Recur,
|
||||||
Error,
|
Error,
|
||||||
NormalizedTy {
|
NormalizedTerm {
|
||||||
ty: NormalizedTerm<'tcx>,
|
ty: NormalizedTerm<'tcx>,
|
||||||
/// If we were able to successfully evaluate the
|
/// If we were able to successfully evaluate the
|
||||||
/// corresponding cache entry key during predicate
|
/// corresponding cache entry key during predicate
|
||||||
@ -186,7 +186,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let fresh_key =
|
let fresh_key =
|
||||||
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty: value, complete: None });
|
map.insert(key, ProjectionCacheEntry::NormalizedTerm { ty: value, complete: None });
|
||||||
assert!(!fresh_key, "never started projecting `{key:?}`");
|
assert!(!fresh_key, "never started projecting `{key:?}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,13 +197,16 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||||||
pub fn complete(&mut self, key: ProjectionCacheKey<'tcx>, result: EvaluationResult) {
|
pub fn complete(&mut self, key: ProjectionCacheKey<'tcx>, result: EvaluationResult) {
|
||||||
let mut map = self.map();
|
let mut map = self.map();
|
||||||
match map.get(&key) {
|
match map.get(&key) {
|
||||||
Some(ProjectionCacheEntry::NormalizedTy { ty, complete: _ }) => {
|
Some(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
|
||||||
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
|
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
|
||||||
let mut ty = ty.clone();
|
let mut ty = ty.clone();
|
||||||
if result.must_apply_considering_regions() {
|
if result.must_apply_considering_regions() {
|
||||||
ty.obligations = vec![];
|
ty.obligations = vec![];
|
||||||
}
|
}
|
||||||
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty, complete: Some(result) });
|
map.insert(
|
||||||
|
key,
|
||||||
|
ProjectionCacheEntry::NormalizedTerm { ty, complete: Some(result) },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
ref value => {
|
ref value => {
|
||||||
// Type inference could "strand behind" old cache entries. Leave
|
// Type inference could "strand behind" old cache entries. Leave
|
||||||
@ -215,7 +218,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||||||
|
|
||||||
pub fn is_complete(&mut self, key: ProjectionCacheKey<'tcx>) -> Option<EvaluationResult> {
|
pub fn is_complete(&mut self, key: ProjectionCacheKey<'tcx>) -> Option<EvaluationResult> {
|
||||||
self.map().get(&key).and_then(|res| match res {
|
self.map().get(&key).and_then(|res| match res {
|
||||||
ProjectionCacheEntry::NormalizedTy { ty: _, complete } => *complete,
|
ProjectionCacheEntry::NormalizedTerm { ty: _, complete } => *complete,
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,6 @@ impl<'tcx> Term<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function returns the inner `AliasTy` for a `ty::Alias` or `ConstKind::Unevaluated`.
|
|
||||||
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
|
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
|
||||||
match self.unpack() {
|
match self.unpack() {
|
||||||
TermKind::Ty(ty) => match *ty.kind() {
|
TermKind::Ty(ty) => match *ty.kind() {
|
||||||
|
@ -3216,7 +3216,8 @@ define_print_and_forward_display! {
|
|||||||
ty::AliasTermKind::ProjectionTy
|
ty::AliasTermKind::ProjectionTy
|
||||||
| ty::AliasTermKind::WeakTy
|
| ty::AliasTermKind::WeakTy
|
||||||
| ty::AliasTermKind::OpaqueTy
|
| ty::AliasTermKind::OpaqueTy
|
||||||
| ty::AliasTermKind::UnevaluatedConst => {
|
| ty::AliasTermKind::UnevaluatedConst
|
||||||
|
| ty::AliasTermKind::ProjectionConst => {
|
||||||
// If we're printing verbosely, or don't want to invoke queries
|
// If we're printing verbosely, or don't want to invoke queries
|
||||||
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
|
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
|
||||||
// This is likely what you want if you're debugging the compiler anyways.
|
// This is likely what you want if you're debugging the compiler anyways.
|
||||||
|
@ -10,7 +10,6 @@ use crate::ty::{
|
|||||||
GenericArgKind, GenericArgsRef, ImplSubject, Term, TermKind, Ty, TyCtxt, TypeFoldable,
|
GenericArgKind, GenericArgsRef, ImplSubject, Term, TermKind, Ty, TyCtxt, TypeFoldable,
|
||||||
};
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_macros::TypeVisitable;
|
use rustc_macros::TypeVisitable;
|
||||||
use rustc_target::spec::abi;
|
use rustc_target::spec::abi;
|
||||||
@ -227,8 +226,8 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
|
|||||||
if a.def_id != b.def_id {
|
if a.def_id != b.def_id {
|
||||||
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
|
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
|
||||||
} else {
|
} else {
|
||||||
let args = match relation.tcx().def_kind(a.def_id) {
|
let args = match a.kind(relation.tcx()) {
|
||||||
DefKind::OpaqueTy => relate_args_with_variances(
|
ty::Opaque => relate_args_with_variances(
|
||||||
relation,
|
relation,
|
||||||
a.def_id,
|
a.def_id,
|
||||||
relation.tcx().variances_of(a.def_id),
|
relation.tcx().variances_of(a.def_id),
|
||||||
@ -236,10 +235,9 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
|
|||||||
b.args,
|
b.args,
|
||||||
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
||||||
)?,
|
)?,
|
||||||
DefKind::AssocTy | DefKind::AssocConst | DefKind::TyAlias => {
|
ty::Projection | ty::Weak | ty::Inherent => {
|
||||||
relate_args_invariantly(relation, a.args, b.args)?
|
relate_args_invariantly(relation, a.args, b.args)?
|
||||||
}
|
}
|
||||||
def => bug!("unknown alias DefKind: {def:?}"),
|
|
||||||
};
|
};
|
||||||
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
|
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
|
||||||
}
|
}
|
||||||
@ -255,8 +253,8 @@ impl<'tcx> Relate<'tcx> for ty::AliasTerm<'tcx> {
|
|||||||
if a.def_id != b.def_id {
|
if a.def_id != b.def_id {
|
||||||
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
|
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
|
||||||
} else {
|
} else {
|
||||||
let args = match relation.tcx().def_kind(a.def_id) {
|
let args = match a.kind(relation.tcx()) {
|
||||||
DefKind::OpaqueTy => relate_args_with_variances(
|
ty::AliasTermKind::OpaqueTy => relate_args_with_variances(
|
||||||
relation,
|
relation,
|
||||||
a.def_id,
|
a.def_id,
|
||||||
relation.tcx().variances_of(a.def_id),
|
relation.tcx().variances_of(a.def_id),
|
||||||
@ -264,10 +262,13 @@ impl<'tcx> Relate<'tcx> for ty::AliasTerm<'tcx> {
|
|||||||
b.args,
|
b.args,
|
||||||
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
|
||||||
)?,
|
)?,
|
||||||
DefKind::AssocTy | DefKind::AssocConst | DefKind::TyAlias => {
|
ty::AliasTermKind::ProjectionTy
|
||||||
|
| ty::AliasTermKind::WeakTy
|
||||||
|
| ty::AliasTermKind::InherentTy
|
||||||
|
| ty::AliasTermKind::UnevaluatedConst
|
||||||
|
| ty::AliasTermKind::ProjectionConst => {
|
||||||
relate_args_invariantly(relation, a.args, b.args)?
|
relate_args_invariantly(relation, a.args, b.args)?
|
||||||
}
|
}
|
||||||
def => bug!("unknown alias DefKind: {def:?}"),
|
|
||||||
};
|
};
|
||||||
Ok(ty::AliasTerm::new(relation.tcx(), a.def_id, args))
|
Ok(ty::AliasTerm::new(relation.tcx(), a.def_id, args))
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Symbol};
|
|||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||||
use rustc_target::spec::abi::{self, Abi};
|
use rustc_target::spec::abi::{self, Abi};
|
||||||
use std::assert_matches::{assert_matches, debug_assert_matches};
|
use std::assert_matches::debug_assert_matches;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::ops::{ControlFlow, Deref, Range};
|
use std::ops::{ControlFlow, Deref, Range};
|
||||||
@ -1137,8 +1137,8 @@ pub struct AliasTerm<'tcx> {
|
|||||||
/// aka. `tcx.parent(def_id)`.
|
/// aka. `tcx.parent(def_id)`.
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
|
|
||||||
/// This field exists to prevent the creation of `AliasTy` without using
|
/// This field exists to prevent the creation of `AliasTerm` without using
|
||||||
/// [AliasTy::new].
|
/// [AliasTerm::new].
|
||||||
_use_alias_term_new_instead: (),
|
_use_alias_term_new_instead: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1202,13 +1202,15 @@ impl<'tcx> AliasTerm<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_ty(self, tcx: TyCtxt<'tcx>) -> AliasTy<'tcx> {
|
pub fn expect_ty(self, tcx: TyCtxt<'tcx>) -> AliasTy<'tcx> {
|
||||||
assert_matches!(
|
match self.kind(tcx) {
|
||||||
self.kind(tcx),
|
|
||||||
ty::AliasTermKind::ProjectionTy
|
ty::AliasTermKind::ProjectionTy
|
||||||
| ty::AliasTermKind::OpaqueTy
|
| ty::AliasTermKind::InherentTy
|
||||||
| ty::AliasTermKind::WeakTy
|
| ty::AliasTermKind::OpaqueTy
|
||||||
| ty::AliasTermKind::InherentTy
|
| ty::AliasTermKind::WeakTy => {}
|
||||||
);
|
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst => {
|
||||||
|
bug!("Cannot turn `UnevaluatedConst` into `AliasTy`")
|
||||||
|
}
|
||||||
|
}
|
||||||
ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }
|
ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1223,13 +1225,14 @@ impl<'tcx> AliasTerm<'tcx> {
|
|||||||
}
|
}
|
||||||
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
|
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
|
||||||
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
|
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
|
||||||
DefKind::AssocConst | DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
|
DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
|
||||||
|
DefKind::AssocConst => ty::AliasTermKind::ProjectionConst,
|
||||||
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
|
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The following methods work only with (trait) associated type projections.
|
/// The following methods work only with (trait) associated item projections.
|
||||||
impl<'tcx> AliasTerm<'tcx> {
|
impl<'tcx> AliasTerm<'tcx> {
|
||||||
pub fn self_ty(self) -> Ty<'tcx> {
|
pub fn self_ty(self) -> Ty<'tcx> {
|
||||||
self.args.type_at(0)
|
self.args.type_at(0)
|
||||||
@ -1269,7 +1272,6 @@ impl<'tcx> AliasTerm<'tcx> {
|
|||||||
self,
|
self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
||||||
debug_assert!(matches!(tcx.def_kind(self.def_id), DefKind::AssocTy | DefKind::AssocConst));
|
|
||||||
let trait_def_id = self.trait_def_id(tcx);
|
let trait_def_id = self.trait_def_id(tcx);
|
||||||
let trait_generics = tcx.generics_of(trait_def_id);
|
let trait_generics = tcx.generics_of(trait_def_id);
|
||||||
(
|
(
|
||||||
@ -1304,12 +1306,14 @@ impl<'tcx> AliasTerm<'tcx> {
|
|||||||
AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () },
|
AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () },
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
ty::AliasTermKind::UnevaluatedConst => ty::Const::new_unevaluated(
|
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst => {
|
||||||
tcx,
|
ty::Const::new_unevaluated(
|
||||||
ty::UnevaluatedConst::new(self.def_id, self.args),
|
tcx,
|
||||||
tcx.type_of(self.def_id).instantiate(tcx, self.args),
|
ty::UnevaluatedConst::new(self.def_id, self.args),
|
||||||
)
|
tcx.type_of(self.def_id).instantiate(tcx, self.args),
|
||||||
.into(),
|
)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1358,7 +1362,7 @@ pub struct AliasTy<'tcx> {
|
|||||||
/// aka. `tcx.parent(def_id)`.
|
/// aka. `tcx.parent(def_id)`.
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
|
|
||||||
/// This field exists to prevent the creation of `AliasTy` without using
|
/// This field exists to prevent the creation of `AliasT` without using
|
||||||
/// [AliasTy::new].
|
/// [AliasTy::new].
|
||||||
_use_alias_ty_new_instead: (),
|
_use_alias_ty_new_instead: (),
|
||||||
}
|
}
|
||||||
@ -1422,7 +1426,6 @@ impl<'tcx> AliasTy<'tcx> {
|
|||||||
self,
|
self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
||||||
debug_assert!(matches!(tcx.def_kind(self.def_id), DefKind::AssocTy | DefKind::AssocConst));
|
|
||||||
let trait_def_id = self.trait_def_id(tcx);
|
let trait_def_id = self.trait_def_id(tcx);
|
||||||
let trait_generics = tcx.generics_of(trait_def_id);
|
let trait_generics = tcx.generics_of(trait_def_id);
|
||||||
(
|
(
|
||||||
|
@ -723,9 +723,9 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
|
|||||||
type T = stable_mir::ty::ProjectionPredicate;
|
type T = stable_mir::ty::ProjectionPredicate;
|
||||||
|
|
||||||
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
|
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
|
||||||
let ty::ProjectionPredicate { projection_term: projection_ty, term } = self;
|
let ty::ProjectionPredicate { projection_term, term } = self;
|
||||||
stable_mir::ty::ProjectionPredicate {
|
stable_mir::ty::ProjectionPredicate {
|
||||||
projection_term: projection_ty.stable(tables),
|
projection_term: projection_term.stable(tables),
|
||||||
term: term.unpack().stable(tables),
|
term: term.unpack().stable(tables),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
|
|||||||
/// ```
|
/// ```
|
||||||
/// If successful, this may result in additional obligations.
|
/// If successful, this may result in additional obligations.
|
||||||
///
|
///
|
||||||
/// See [poly_project_and_unify_type] for an explanation of the return value.
|
/// See [poly_project_and_unify_term] for an explanation of the return value.
|
||||||
#[instrument(level = "debug", skip(selcx))]
|
#[instrument(level = "debug", skip(selcx))]
|
||||||
fn project_and_unify_term<'cx, 'tcx>(
|
fn project_and_unify_term<'cx, 'tcx>(
|
||||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||||
@ -395,7 +395,7 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
|
|||||||
debug!("recur cache");
|
debug!("recur cache");
|
||||||
return Err(InProgress);
|
return Err(InProgress);
|
||||||
}
|
}
|
||||||
Err(ProjectionCacheEntry::NormalizedTy { ty, complete: _ }) => {
|
Err(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
|
||||||
// This is the hottest path in this function.
|
// This is the hottest path in this function.
|
||||||
//
|
//
|
||||||
// If we find the value in the cache, then return it along
|
// If we find the value in the cache, then return it along
|
||||||
@ -522,7 +522,7 @@ fn normalize_to_error<'a, 'tcx>(
|
|||||||
| ty::AliasTermKind::InherentTy
|
| ty::AliasTermKind::InherentTy
|
||||||
| ty::AliasTermKind::OpaqueTy
|
| ty::AliasTermKind::OpaqueTy
|
||||||
| ty::AliasTermKind::WeakTy => selcx.infcx.next_ty_var(cause.span).into(),
|
| ty::AliasTermKind::WeakTy => selcx.infcx.next_ty_var(cause.span).into(),
|
||||||
ty::AliasTermKind::UnevaluatedConst => selcx
|
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst => selcx
|
||||||
.infcx
|
.infcx
|
||||||
.next_const_var(
|
.next_const_var(
|
||||||
selcx
|
selcx
|
||||||
|
@ -437,31 +437,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||||||
/// Pushes the obligations required for an alias (except inherent) to be WF
|
/// Pushes the obligations required for an alias (except inherent) to be WF
|
||||||
/// into `self.out`.
|
/// into `self.out`.
|
||||||
fn compute_alias_ty(&mut self, data: ty::AliasTy<'tcx>) {
|
fn compute_alias_ty(&mut self, data: ty::AliasTy<'tcx>) {
|
||||||
// A projection is well-formed if
|
self.compute_alias_term(data.into());
|
||||||
//
|
|
||||||
// (a) its predicates hold (*)
|
|
||||||
// (b) its args are wf
|
|
||||||
//
|
|
||||||
// (*) The predicates of an associated type include the predicates of
|
|
||||||
// the trait that it's contained in. For example, given
|
|
||||||
//
|
|
||||||
// trait A<T>: Clone {
|
|
||||||
// type X where T: Copy;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// The predicates of `<() as A<i32>>::X` are:
|
|
||||||
// [
|
|
||||||
// `(): Sized`
|
|
||||||
// `(): Clone`
|
|
||||||
// `(): A<i32>`
|
|
||||||
// `i32: Sized`
|
|
||||||
// `i32: Clone`
|
|
||||||
// `i32: Copy`
|
|
||||||
// ]
|
|
||||||
let obligations = self.nominal_obligations(data.def_id, data.args);
|
|
||||||
self.out.extend(obligations);
|
|
||||||
|
|
||||||
self.compute_projection_args(data.args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pushes the obligations required for an alias (except inherent) to be WF
|
/// Pushes the obligations required for an alias (except inherent) to be WF
|
||||||
|
@ -320,14 +320,17 @@ pub enum AliasTermKind {
|
|||||||
/// Currently only used if the type alias references opaque types.
|
/// Currently only used if the type alias references opaque types.
|
||||||
/// Can always be normalized away.
|
/// Can always be normalized away.
|
||||||
WeakTy,
|
WeakTy,
|
||||||
/// UwU
|
/// An unevaluated const coming from a generic const expression.
|
||||||
UnevaluatedConst,
|
UnevaluatedConst,
|
||||||
|
/// An unevaluated const coming from an associated const.
|
||||||
|
ProjectionConst,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AliasTermKind {
|
impl AliasTermKind {
|
||||||
pub fn descr(self) -> &'static str {
|
pub fn descr(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
AliasTermKind::ProjectionTy => "associated type",
|
AliasTermKind::ProjectionTy => "associated type",
|
||||||
|
AliasTermKind::ProjectionConst => "associated const",
|
||||||
AliasTermKind::InherentTy => "inherent associated type",
|
AliasTermKind::InherentTy => "inherent associated type",
|
||||||
AliasTermKind::OpaqueTy => "opaque type",
|
AliasTermKind::OpaqueTy => "opaque type",
|
||||||
AliasTermKind::WeakTy => "type alias",
|
AliasTermKind::WeakTy => "type alias",
|
||||||
|
@ -320,11 +320,11 @@ fn is_mixed_projection_predicate<'tcx>(
|
|||||||
&& (term_param_ty.index as usize) < generics.parent_count
|
&& (term_param_ty.index as usize) < generics.parent_count
|
||||||
{
|
{
|
||||||
// The inner-most self type is a type parameter from the current function.
|
// The inner-most self type is a type parameter from the current function.
|
||||||
let mut projection_ty = projection_predicate.projection_term;
|
let mut projection_term = projection_predicate.projection_term;
|
||||||
loop {
|
loop {
|
||||||
match *projection_ty.self_ty().kind() {
|
match *projection_term.self_ty().kind() {
|
||||||
ty::Alias(ty::Projection, inner_projection_ty) => {
|
ty::Alias(ty::Projection, inner_projection_ty) => {
|
||||||
projection_ty = inner_projection_ty.into();
|
projection_term = inner_projection_ty.into();
|
||||||
},
|
},
|
||||||
ty::Param(param_ty) => {
|
ty::Param(param_ty) => {
|
||||||
return (param_ty.index as usize) >= generics.parent_count;
|
return (param_ty.index as usize) >= generics.parent_count;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//@ aux-crate:assoc_const_equality=assoc-const-equality.rs
|
//@ aux-crate:assoc_const_equality=assoc-const-equality.rs
|
||||||
//@ edition:2021
|
//@ edition:2021
|
||||||
|
//@ ignore-test (FIXME: #125092)
|
||||||
|
|
||||||
#![crate_name = "user"]
|
#![crate_name = "user"]
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ impl TraitWAssocConst for impl Demo { //~ ERROR E0404
|
|||||||
fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
|
fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
|
||||||
foo::<Demo>()();
|
foo::<Demo>()();
|
||||||
//~^ ERROR is not satisfied
|
//~^ ERROR is not satisfied
|
||||||
//~| ERROR type mismatch
|
|
||||||
//~| ERROR expected function, found `()`
|
//~| ERROR expected function, found `()`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,6 +18,5 @@ fn main<A: TraitWAssocConst<A=32>>() {
|
|||||||
//~^ ERROR E0658
|
//~^ ERROR E0658
|
||||||
//~| ERROR E0131
|
//~| ERROR E0131
|
||||||
foo::<Demo>();
|
foo::<Demo>();
|
||||||
//~^ ERROR type mismatch
|
//~^ ERROR is not satisfied
|
||||||
//~| ERROR is not satisfied
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
|||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error[E0658]: associated const equality is incomplete
|
error[E0658]: associated const equality is incomplete
|
||||||
--> $DIR/issue-105330.rs:18:29
|
--> $DIR/issue-105330.rs:17:29
|
||||||
|
|
|
|
||||||
LL | fn main<A: TraitWAssocConst<A=32>>() {
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
|
||||||
| ^^^^
|
| ^^^^
|
||||||
@ -44,7 +44,7 @@ LL | impl TraitWAssocConst for impl Demo {
|
|||||||
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
|
||||||
|
|
||||||
error[E0131]: `main` function is not allowed to have generic parameters
|
error[E0131]: `main` function is not allowed to have generic parameters
|
||||||
--> $DIR/issue-105330.rs:18:8
|
--> $DIR/issue-105330.rs:17:8
|
||||||
|
|
|
|
||||||
LL | fn main<A: TraitWAssocConst<A=32>>() {
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
|
||||||
@ -61,20 +61,6 @@ note: required by a bound in `foo`
|
|||||||
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
||||||
|
|
||||||
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
|
|
||||||
--> $DIR/issue-105330.rs:12:11
|
|
||||||
|
|
|
||||||
LL | foo::<Demo>()();
|
|
||||||
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
|
|
||||||
|
|
|
||||||
= note: expected constant `32`
|
|
||||||
found constant `<Demo as TraitWAssocConst>::A`
|
|
||||||
note: required by a bound in `foo`
|
|
||||||
--> $DIR/issue-105330.rs:11:28
|
|
||||||
|
|
|
||||||
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
|
||||||
| ^^^^ required by this bound in `foo`
|
|
||||||
|
|
||||||
error[E0618]: expected function, found `()`
|
error[E0618]: expected function, found `()`
|
||||||
--> $DIR/issue-105330.rs:12:5
|
--> $DIR/issue-105330.rs:12:5
|
||||||
|
|
|
|
||||||
@ -86,7 +72,7 @@ LL | foo::<Demo>()();
|
|||||||
| call expression requires function
|
| call expression requires function
|
||||||
|
|
||||||
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
|
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
|
||||||
--> $DIR/issue-105330.rs:21:11
|
--> $DIR/issue-105330.rs:20:11
|
||||||
|
|
|
|
||||||
LL | foo::<Demo>();
|
LL | foo::<Demo>();
|
||||||
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
||||||
@ -97,21 +83,7 @@ note: required by a bound in `foo`
|
|||||||
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
|
||||||
|
|
||||||
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
|
error: aborting due to 9 previous errors
|
||||||
--> $DIR/issue-105330.rs:21:11
|
|
||||||
|
|
|
||||||
LL | foo::<Demo>();
|
|
||||||
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
|
|
||||||
|
|
|
||||||
= note: expected constant `32`
|
|
||||||
found constant `<Demo as TraitWAssocConst>::A`
|
|
||||||
note: required by a bound in `foo`
|
|
||||||
--> $DIR/issue-105330.rs:11:28
|
|
||||||
|
|
|
||||||
LL | fn foo<A: TraitWAssocConst<A=32>>() {
|
|
||||||
| ^^^^ required by this bound in `foo`
|
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
Some errors have detailed explanations: E0131, E0277, E0404, E0562, E0618, E0658.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0131, E0271, E0277, E0404, E0562, E0618, E0658.
|
|
||||||
For more information about an error, try `rustc --explain E0131`.
|
For more information about an error, try `rustc --explain E0131`.
|
||||||
|
Loading…
Reference in New Issue
Block a user