summaryrefslogtreecommitdiff
path: root/compiler/rustc_middle/src/ty
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-25 19:21:42 +0000
committerbors <bors@rust-lang.org>2023-04-25 19:21:42 +0000
commit458d4dae845ec155b285681a5b88305641abb868 (patch)
treedb8180fa895d4969d18064a0f4ef03e72ab4f3c6 /compiler/rustc_middle/src/ty
parent666fee2a5fb3a4ec75953b9e6622662ae10b9ae5 (diff)
parent77752a0db3d4720caf9f3f133599bffb1e0e265b (diff)
downloadrust-458d4dae845ec155b285681a5b88305641abb868.tar.gz
Auto merge of #110821 - matthiaskrgr:rollup-mzxrvw7, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #110556 (Switch to `EarlyBinder` for `explicit_item_bounds`) - #110615 (Add `impl_tag!` macro to implement `Tag` for tagged pointer easily) - #110649 (Fix no_global_oom_handling build) - #110671 (Consider polarity in new solver) - #110783 (Fix ICE on --print=... i/o errors) - #110796 (Updating Wake example to use new 'pin!' macro) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_middle/src/ty')
-rw-r--r--compiler/rustc_middle/src/ty/context.rs2
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs34
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs2
-rw-r--r--compiler/rustc_middle/src/ty/subst.rs12
-rw-r--r--compiler/rustc_middle/src/ty/util.rs7
5 files changed, 25 insertions, 32 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 4a4f6770fc4..7df4be263d5 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1603,7 +1603,7 @@ impl<'tcx> TyCtxt<'tcx> {
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
let future_trait = self.require_lang_item(LangItem::Future, None);
- self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
+ self.explicit_item_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| {
let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() else {
return false;
};
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 17647d13f99..8e4e708b73c 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -861,6 +861,11 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
pub fn is_const_if_const(self) -> bool {
self.skip_binder().is_const_if_const()
}
+
+ #[inline]
+ pub fn polarity(self) -> ImplPolarity {
+ self.skip_binder().polarity
+ }
}
/// `A: B`
@@ -1497,29 +1502,12 @@ struct ParamTag {
constness: hir::Constness,
}
-unsafe impl rustc_data_structures::tagged_ptr::Tag for ParamTag {
- const BITS: u32 = 2;
-
- #[inline]
- fn into_usize(self) -> usize {
- match self {
- Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } => 0,
- Self { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } => 1,
- Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } => 2,
- Self { reveal: traits::Reveal::All, constness: hir::Constness::Const } => 3,
- }
- }
-
- #[inline]
- unsafe fn from_usize(ptr: usize) -> Self {
- match ptr {
- 0 => Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst },
- 1 => Self { reveal: traits::Reveal::All, constness: hir::Constness::NotConst },
- 2 => Self { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const },
- 3 => Self { reveal: traits::Reveal::All, constness: hir::Constness::Const },
- _ => std::hint::unreachable_unchecked(),
- }
- }
+impl_tag! {
+ impl Tag for ParamTag;
+ ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst },
+ ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst },
+ ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const },
+ ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::Const },
}
impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index 4c95d0f8415..1c1432ecd5a 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -914,7 +914,7 @@ pub trait PrettyPrinter<'tcx>:
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the projections associated with the def_id.
- let bounds = tcx.bound_explicit_item_bounds(def_id);
+ let bounds = tcx.explicit_item_bounds(def_id);
let mut traits = FxIndexMap::default();
let mut fn_traits = FxIndexMap::default();
diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs
index a439211ca33..63b2acdbe4e 100644
--- a/compiler/rustc_middle/src/ty/subst.rs
+++ b/compiler/rustc_middle/src/ty/subst.rs
@@ -612,6 +612,12 @@ where
) -> SubstIter<'s, 'tcx, I> {
SubstIter { it: self.0.into_iter(), tcx, substs }
}
+
+ /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
+ /// but on an iterator of `TypeFoldable` values.
+ pub fn subst_identity_iter(self) -> I::IntoIter {
+ self.0.into_iter()
+ }
}
pub struct SubstIter<'s, 'tcx, I: IntoIterator> {
@@ -664,6 +670,12 @@ where
) -> SubstIterCopied<'s, 'tcx, I> {
SubstIterCopied { it: self.0.into_iter(), tcx, substs }
}
+
+ /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
+ /// but on an iterator of values that deref to a `TypeFoldable`.
+ pub fn subst_identity_iter_copied(self) -> impl Iterator<Item = <I::Item as Deref>::Target> {
+ self.0.into_iter().map(|v| *v)
+ }
}
pub struct SubstIterCopied<'a, 'tcx, I: IntoIterator> {
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs
index 7127fdbf26a..4c346b00256 100644
--- a/compiler/rustc_middle/src/ty/util.rs
+++ b/compiler/rustc_middle/src/ty/util.rs
@@ -701,13 +701,6 @@ impl<'tcx> TyCtxt<'tcx> {
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
}
- pub fn bound_explicit_item_bounds(
- self,
- def_id: DefId,
- ) -> ty::EarlyBinder<&'tcx [(ty::Predicate<'tcx>, rustc_span::Span)]> {
- ty::EarlyBinder(self.explicit_item_bounds(def_id))
- }
-
/// Returns names of captured upvars for closures and generators.
///
/// Here are some examples: