Skip to content

Commit ee97564

Browse files
committed
Auto merge of #125001 - compiler-errors:uplift-trait-predicate, r=lcnr
Uplift various `*Predicate` types into `rustc_type_ir` Uplifts `ProjectionPredicate`, `ExistentialTraitRef`, `ExistentialProjection`, `TraitPredicate`, `NormalizesTo`, `CoercePredicate`, and `SubtypePredicate`. Adds `rustc_type_ir_macros`, which semi-duplicates the derive for `TypeVisitable`, `TypeFoldable`, and `Lift`, but in a way that is interner-agnostic. Moves `rustc_type_ir::trait_ref` to `rustc_type_ir::predicate`. The specific placement of all these structs doesn't matter b/c of glob imports, tho.
2 parents 8b64adc + d13e5c4 commit ee97564

File tree

30 files changed

+886
-813
lines changed

30 files changed

+886
-813
lines changed

Diff for: Cargo.lock

+11
Original file line numberDiff line numberDiff line change
@@ -4837,9 +4837,20 @@ dependencies = [
48374837
"rustc_macros",
48384838
"rustc_serialize",
48394839
"rustc_span",
4840+
"rustc_type_ir_macros",
48404841
"smallvec",
48414842
]
48424843

4844+
[[package]]
4845+
name = "rustc_type_ir_macros"
4846+
version = "0.0.0"
4847+
dependencies = [
4848+
"proc-macro2",
4849+
"quote",
4850+
"syn 2.0.62",
4851+
"synstructure",
4852+
]
4853+
48434854
[[package]]
48444855
name = "rustc_version"
48454856
version = "0.4.0"

Diff for: compiler/rustc_errors/src/diagnostic_impls.rs

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {
100100
}
101101
}
102102

103+
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::ExistentialTraitRef<I> {
104+
fn into_diag_arg(self) -> DiagArgValue {
105+
self.to_string().into_diag_arg()
106+
}
107+
}
108+
103109
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
104110

105111
impl IntoDiagArg for bool {

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::def_id::DefId;
88
use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
99
use rustc_middle::ty::fold::BottomUpFolder;
10-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
10+
use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable};
1111
use rustc_middle::ty::{DynKind, ToPredicate};
1212
use rustc_span::{ErrorGuaranteed, Span};
1313
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;

Diff for: compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use rustc_hir as hir;
22
use rustc_infer::infer::TyCtxtInferExt;
33
use rustc_macros::{LintDiagnostic, Subdiagnostic};
4-
use rustc_middle::ty::{
5-
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable,
6-
};
4+
use rustc_middle::ty::print::{PrintTraitPredicateExt as _, TraitPredPrintModifiersAndPath};
5+
use rustc_middle::ty::{self, fold::BottomUpFolder, Ty, TypeFoldable};
76
use rustc_session::{declare_lint, declare_lint_pass};
87
use rustc_span::{symbol::kw, Span};
98
use rustc_trait_selection::traits;

Diff for: compiler/rustc_middle/src/ty/context.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::traits::solve;
2626
use crate::traits::solve::{
2727
ExternalConstraints, ExternalConstraintsData, PredefinedOpaques, PredefinedOpaquesData,
2828
};
29+
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
2930
use crate::ty::{
3031
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, ConstData,
3132
GenericParamDefKind, ImplPolarity, List, ListWithCachedTypeInfo, ParamConst, ParamTy, Pattern,
@@ -99,17 +100,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
99100
type CanonicalVars = CanonicalVarInfos<'tcx>;
100101

101102
type Ty = Ty<'tcx>;
102-
type Pat = Pattern<'tcx>;
103103
type Tys = &'tcx List<Ty<'tcx>>;
104104
type AliasTy = ty::AliasTy<'tcx>;
105105
type ParamTy = ParamTy;
106106
type BoundTy = ty::BoundTy;
107107
type PlaceholderTy = ty::PlaceholderType;
108-
109108
type ErrorGuaranteed = ErrorGuaranteed;
109+
110110
type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
111111
type PolyFnSig = PolyFnSig<'tcx>;
112112
type AllocId = crate::mir::interpret::AllocId;
113+
type Pat = Pattern<'tcx>;
113114

114115
type Const = ty::Const<'tcx>;
115116
type AliasConst = ty::UnevaluatedConst<'tcx>;
@@ -121,8 +122,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
121122

122123
type Region = Region<'tcx>;
123124
type EarlyParamRegion = ty::EarlyParamRegion;
124-
type BoundRegion = ty::BoundRegion;
125125
type LateParamRegion = ty::LateParamRegion;
126+
type BoundRegion = ty::BoundRegion;
126127
type InferRegion = ty::RegionVid;
127128
type PlaceholderRegion = ty::PlaceholderRegion;
128129

@@ -146,13 +147,21 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
146147
self.generics_of(def_id)
147148
}
148149

150+
fn mk_args(self, args: &[Self::GenericArg]) -> Self::GenericArgs {
151+
self.mk_args(args)
152+
}
153+
149154
fn check_and_mk_args(
150155
self,
151156
def_id: DefId,
152157
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
153158
) -> ty::GenericArgsRef<'tcx> {
154159
self.check_and_mk_args(def_id, args)
155160
}
161+
162+
fn parent(self, def_id: Self::DefId) -> Self::DefId {
163+
self.parent(def_id)
164+
}
156165
}
157166

158167
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;

Diff for: compiler/rustc_middle/src/ty/mod.rs

+7-62
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ pub use self::list::{List, ListWithCachedTypeInfo};
9696
pub use self::parameterized::ParameterizedOverTcx;
9797
pub use self::pattern::{Pattern, PatternKind};
9898
pub use self::predicate::{
99-
Clause, ClauseKind, CoercePredicate, ExistentialPredicate, ExistentialProjection,
100-
ExistentialTraitRef, NormalizesTo, OutlivesPredicate, PolyCoercePredicate,
101-
PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef,
102-
PolyProjectionPredicate, PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate,
103-
PolyTraitRef, PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
104-
RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitPredicate,
105-
TraitRef, TypeOutlivesPredicate,
99+
Clause, ClauseKind, CoercePredicate, ExistentialPredicate, ExistentialPredicateStableCmpExt,
100+
ExistentialProjection, ExistentialTraitRef, NormalizesTo, OutlivesPredicate,
101+
PolyCoercePredicate, PolyExistentialPredicate, PolyExistentialProjection,
102+
PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate,
103+
PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate,
104+
PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef,
105+
ToPredicate, TraitPredicate, TraitRef, TypeOutlivesPredicate,
106106
};
107107
pub use self::region::{
108108
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,
@@ -275,61 +275,6 @@ pub enum ImplSubject<'tcx> {
275275
Inherent(Ty<'tcx>),
276276
}
277277

278-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
279-
#[derive(TypeFoldable, TypeVisitable)]
280-
pub enum ImplPolarity {
281-
/// `impl Trait for Type`
282-
Positive,
283-
/// `impl !Trait for Type`
284-
Negative,
285-
/// `#[rustc_reservation_impl] impl Trait for Type`
286-
///
287-
/// This is a "stability hack", not a real Rust feature.
288-
/// See #64631 for details.
289-
Reservation,
290-
}
291-
292-
impl fmt::Display for ImplPolarity {
293-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
294-
match self {
295-
Self::Positive => f.write_str("positive"),
296-
Self::Negative => f.write_str("negative"),
297-
Self::Reservation => f.write_str("reservation"),
298-
}
299-
}
300-
}
301-
302-
/// Polarity for a trait predicate. May either be negative or positive.
303-
/// Distinguished from [`ImplPolarity`] since we never compute goals with
304-
/// "reservation" level.
305-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
306-
#[derive(TypeFoldable, TypeVisitable)]
307-
pub enum PredicatePolarity {
308-
/// `Type: Trait`
309-
Positive,
310-
/// `Type: !Trait`
311-
Negative,
312-
}
313-
314-
impl PredicatePolarity {
315-
/// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
316-
pub fn flip(&self) -> PredicatePolarity {
317-
match self {
318-
PredicatePolarity::Positive => PredicatePolarity::Negative,
319-
PredicatePolarity::Negative => PredicatePolarity::Positive,
320-
}
321-
}
322-
}
323-
324-
impl fmt::Display for PredicatePolarity {
325-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
326-
match self {
327-
Self::Positive => f.write_str("positive"),
328-
Self::Negative => f.write_str("negative"),
329-
}
330-
}
331-
}
332-
333278
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
334279
#[derive(TypeFoldable, TypeVisitable)]
335280
pub enum Asyncness {

0 commit comments

Comments
 (0)