Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let maybe_uneval = match constant.const_ {
Const::Ty(_, ct) => match ct.kind() {
ty::ConstKind::Alias(_, alias_const) => match alias_const.kind {
ty::AliasConstKind::EvidenceProjection { .. } => {
bug!("evidence projection in a MIR constant operand")
}
ty::AliasConstKind::Projection { def_id }
| ty::AliasConstKind::InherentSelf { def_id }
| ty::AliasConstKind::InherentImpl { def_id }
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

ty::Alias(
_,
alias @ ty::AliasTy { kind: ty::EvidenceProjection { projection }, .. },
) => self.print_def_path(projection.item_def_id, alias.full_args(self.tcx)),

ty::FnDef(def_id, args) => self.print_def_path(def_id, args.no_bound_vars().unwrap()),
ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
bug!("type_name: unexpected free alias")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ fn param_env_with_gat_bounds<'tcx>(
.into()
}
GenericParamDefKind::Const { .. } => {
let bound_var = ty::BoundVariableKind::Const;
let bound_var = ty::BoundVariableKind::Const(None);
bound_vars.push(bound_var);
ty::Const::new_bound(
tcx,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ impl<'tcx> InherentCollect<'tcx> {
ty::Alias(
_,
ty::AliasTy {
kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. },
kind:
ty::Projection { .. }
| ty::EvidenceProjection { .. }
| ty::Inherent { .. }
| ty::Opaque { .. },
..
},
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub(crate) fn orphan_check_impl(
// type This = T;
// }
// impl<T: ?Sized> AutoTrait for <T as Id>::This {}
ty::Projection { .. } => "associated type",
ty::Projection { .. } | ty::EvidenceProjection { .. } => "associated type",
// type Foo = (impl Sized, bool)
// impl AutoTrait for Foo {}
ty::Free { .. } => "type alias",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MapAndCompressBoundVars<'tcx> {
mapped.expect_const()
} else {
let var = ty::BoundVar::from_usize(self.still_bound_vars.len());
self.still_bound_vars.push(ty::BoundVariableKind::Const);
self.still_bound_vars.push(ty::BoundVariableKind::Const(None));
let mapped =
ty::Const::new_bound(self.tcx, ty::INNERMOST, ty::BoundConst::new(var));
self.mapping.insert(old_bound.var, mapped.into());
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableK
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
}
GenericParamKind::Type { .. } => ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id)),
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const(None),
}
}

Expand All @@ -313,7 +313,7 @@ fn generic_param_def_as_bound_arg<'tcx>(
ty::GenericParamDefKind::Type { .. } => {
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id))
}
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const(None),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
ty::Alias(
_,
ty::AliasTy {
kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. },
kind:
ty::Projection { .. }
| ty::EvidenceProjection { .. }
| ty::Inherent { .. }
| ty::Opaque { .. },
..
},
) if !self.include_nonconstraining => {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_invariant_args(current, args, variance);
}

ty::Alias(_, alias @ ty::AliasTy { kind: ty::EvidenceProjection { .. }, .. }) => {
self.add_constraints_from_invariant_args(
current,
alias.full_args(self.tcx()),
variance,
);
}

ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
let ty = self.tcx().expand_free_alias_tys(ty);
self.add_constraints_from_ty(current, ty, variance);
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,12 @@ impl<'tcx> InferCtxt<'tcx> {
) -> ty::Term<'tcx> {
match alias_term.kind {
ty::AliasTermKind::ProjectionTy { .. }
| ty::AliasTermKind::EvidenceProjectionTy { .. }
| ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::OpaqueTy { .. }
| ty::AliasTermKind::FreeTy { .. } => self.next_ty_var(span).into(),
ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::EvidenceProjectionConst { .. }
| ty::AliasTermKind::InherentConstSelf { .. }
| ty::AliasTermKind::InherentConstImpl { .. }
| ty::AliasTermKind::AnonConst { .. }
Expand Down Expand Up @@ -1526,11 +1528,19 @@ impl<'tcx> InferCtxt<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
let bound_vars = value.bound_vars();
if bound_vars.iter().any(|kind| {
matches!(
kind,
ty::BoundVariableKind::Const(Some(_)) | ty::BoundVariableKind::Evidence(_)
)
}) {
bug!("dependent binders require telescope instantiation");
}
if let Some(_) = value.as_ref().no_bound_vars() {
return value.skip_binder();
}

let bound_vars = value.bound_vars();
let mut args = Vec::with_capacity(bound_vars.len());

for bound_var_kind in bound_vars {
Expand All @@ -1539,7 +1549,10 @@ impl<'tcx> InferCtxt<'tcx> {
ty::BoundVariableKind::Region(br) => {
self.next_region_var(RegionVariableOrigin::BoundRegion(span, br, lbrct)).into()
}
ty::BoundVariableKind::Const => self.next_const_var(span).into(),
ty::BoundVariableKind::Const(None) => self.next_const_var(span).into(),
ty::BoundVariableKind::Const(Some(_)) | ty::BoundVariableKind::Evidence(_) => {
unreachable!()
}
};
args.push(arg);
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ impl<'tcx> InferCtxt<'tcx> {
}
// The old solver only accepts projection predicates for associated types.
ty::AliasTermKind::InherentTy { .. }
| ty::AliasTermKind::EvidenceProjectionTy { .. }
| ty::AliasTermKind::FreeTy { .. }
| ty::AliasTermKind::OpaqueTy { .. } => {
return Err(TypeError::CyclicTy(source_term.expect_type()));
}
ty::AliasTermKind::InherentConstSelf { .. }
| ty::AliasTermKind::EvidenceProjectionConst { .. }
| ty::AliasTermKind::InherentConstImpl { .. }
| ty::AliasTermKind::FreeConst { .. }
| ty::AliasTermKind::AnonConst { .. } => {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_lint/src/types/improper_ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
| ty::Alias(
_,
ty::AliasTy {
kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
kind:
ty::Projection { .. }
| ty::EvidenceProjection { .. }
| ty::Inherent { .. }
| ty::Free { .. },
..
},
)
Expand Down
28 changes: 27 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(super) use cstore_impl::provide;
use rustc_ast as ast;
use rustc_crate_store::{CrateSource, ExternCrate};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::unhash::UnhashMap;
Expand All @@ -25,6 +25,7 @@ use rustc_hir::definitions::{DefPath, DefPathData};
use rustc_index::Idx;
use rustc_middle::middle::lib_features::LibFeatures;
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::traits::solve::TraitEvidence;
use rustc_middle::ty::codec::TyDecoder;
use rustc_middle::ty::{RestrictionKind, Visibility};
use rustc_middle::{bug, implement_ty_decoder};
Expand Down Expand Up @@ -228,6 +229,7 @@ impl<'a> LazyDecoder for BlobDecodeContext<'a> {
pub(super) struct MetadataDecodeContext<'a, 'tcx> {
blob_decoder: BlobDecodeContext<'a>,
cdata: &'a CrateMetadata,
trait_evidence_in_progress: FxHashSet<usize>,
tcx: TyCtxt<'tcx>,

// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
Expand Down Expand Up @@ -306,6 +308,7 @@ impl<'a, 'tcx> MetaDecoder for (&'a CrateMetadata, TyCtxt<'tcx>) {
MetadataDecodeContext {
blob_decoder: self.0.blob().decoder(pos),
cdata: self.0,
trait_evidence_in_progress: Default::default(),
tcx: self.1,
alloc_decoding_session: self.0.alloc_decoding_state.new_decoding_session(),
}
Expand Down Expand Up @@ -420,6 +423,29 @@ impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> {
ty
}

fn cached_trait_evidence_for_shorthand<F>(
&mut self,
shorthand: usize,
or_insert_with: F,
) -> TraitEvidence<'tcx>
where
F: FnOnce(&mut Self) -> TraitEvidence<'tcx>,
{
let tcx = self.tcx;
let key = ty::CReaderCacheKey { cnum: Some(self.cdata.cnum), pos: shorthand };
if let Some(&evidence) = tcx.caches.trait_evidence_rcache.borrow().get(&key) {
return evidence;
}

let evidence = or_insert_with(self);
tcx.caches.trait_evidence_rcache.borrow_mut().insert(key, evidence);
evidence
}

fn trait_evidence_in_progress(&mut self) -> &mut FxHashSet<usize> {
&mut self.trait_evidence_in_progress
}

fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_middle::dep_graph::WorkProductId;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::mir::interpret;
use rustc_middle::query::Providers;
use rustc_middle::traits::solve::TraitEvidence;
use rustc_middle::traits::specialization_graph;
use rustc_middle::ty::AssocContainer;
use rustc_middle::ty::codec::TyEncoder;
Expand Down Expand Up @@ -52,6 +53,7 @@ pub(super) struct EncodeContext<'a, 'tcx> {
lazy_state: LazyState,
span_shorthands: FxHashMap<Span, usize>,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
trait_evidence_shorthands: FxHashMap<TraitEvidence<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::PredicateKind<'tcx>, usize>,

interpret_allocs: FxIndexSet<interpret::AllocId>,
Expand Down Expand Up @@ -387,6 +389,10 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
&mut self.predicate_shorthands
}

fn trait_evidence_shorthands(&mut self) -> &mut FxHashMap<TraitEvidence<'tcx>, usize> {
&mut self.trait_evidence_shorthands
}

fn encode_alloc_id(&mut self, alloc_id: &rustc_middle::mir::interpret::AllocId) {
let (index, _) = self.interpret_allocs.insert_full(*alloc_id);

Expand Down Expand Up @@ -2582,6 +2588,7 @@ fn with_encode_metadata_header(
lazy_state: LazyState::NoNode,
span_shorthands: Default::default(),
type_shorthands: Default::default(),
trait_evidence_shorthands: Default::default(),
predicate_shorthands: Default::default(),
source_file_cache,
interpret_allocs: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ rustc_arena::declare_arena! {
>,
external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<TyCtxt<'tcx>>,
doc_link_resolutions: rustc_middle::middle::resolve::DocLinkResMap,
trait_evidence: rustc_type_ir::solve::TraitEvidenceData<TyCtxt<'tcx>>,
stripped_cfg_items: rustc_hir::attrs::StrippedCfgItem,
mod_child: rustc_middle::middle::resolve::ModChild,
features: rustc_feature::Features,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ impl<'tcx> TyCtxt<'tcx> {
| ty::AliasConstKind::InherentImpl { def_id }
| ty::AliasConstKind::Free { def_id }
| ty::AliasConstKind::Anon { def_id } => def_id,
ty::AliasConstKind::EvidenceProjection { .. } => {
return Err(ErrorHandled::TooGeneric(DUMMY_SP));
}
};

let cid = match ty::Instance::try_resolve(self, typing_env, def_id, ct.args) {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
| ty::AliasConstKind::InherentImpl { def_id }
| ty::AliasConstKind::Free { def_id }
| ty::AliasConstKind::Anon { def_id } => self.tcx.def_path_str(def_id),
ty::AliasConstKind::EvidenceProjection { projection } => {
self.tcx.def_path_str(projection.item_def_id)
}
};
format!("ty::AliasConst({}, {:?})", kind, alias_const.args)
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/query/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl<'tcx> QueryKey for ty::AliasTyKind<'tcx> {
| ty::AliasTyKind::Inherent { def_id }
| ty::AliasTyKind::Opaque { def_id }
| ty::AliasTyKind::Free { def_id } => def_id,
ty::AliasTyKind::EvidenceProjection { projection } => &projection.item_def_id,
};
tcx.def_span(*def_id)
}
Expand Down Expand Up @@ -451,6 +452,7 @@ fn def_id_of_type_cached<'a>(ty: Ty<'a>, visited: &mut SsoHashSet<Ty<'a>>) -> Op
| ty::AliasTyKind::Inherent { def_id }
| ty::AliasTyKind::Opaque { def_id }
| ty::AliasTyKind::Free { def_id } => Some(def_id),
ty::AliasTyKind::EvidenceProjection { projection } => Some(projection.item_def_id),
},

ty::Bool
Expand Down
Loading
Loading