Skip to content

Commit 99c49d9

Browse files
committed
Auto merge of rust-lang#109517 - matthiaskrgr:rollup-m3orqzd, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#108541 (Suppress `opaque_hidden_inferred_bound` for nested RPITs) - rust-lang#109137 (resolve: Querify most cstore access methods (subset 2)) - rust-lang#109380 (add `known-bug` test for unsoundness issue) - rust-lang#109462 (Make alias-eq have a relation direction (and rename it to alias-relate)) - rust-lang#109475 (Simpler checked shifts in MIR building) - rust-lang#109504 (Stabilize `arc_into_inner` and `rc_into_inner`.) - rust-lang#109506 (make param bound vars visibly bound vars with -Zverbose) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9a6b0c3 + 477ce58 commit 99c49d9

File tree

54 files changed

+730
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+730
-246
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13361336
ty::Clause::RegionOutlives(_) | ty::Clause::ConstArgHasType(..) => bug!(),
13371337
},
13381338
ty::PredicateKind::WellFormed(_)
1339-
| ty::PredicateKind::AliasEq(..)
1339+
| ty::PredicateKind::AliasRelate(..)
13401340
| ty::PredicateKind::ObjectSafe(_)
13411341
| ty::PredicateKind::ClosureKind(_, _, _)
13421342
| ty::PredicateKind::Subtype(_)

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fn trait_predicate_kind<'tcx>(
528528
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
529529
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
530530
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
531-
| ty::PredicateKind::AliasEq(..)
531+
| ty::PredicateKind::AliasRelate(..)
532532
| ty::PredicateKind::WellFormed(_)
533533
| ty::PredicateKind::Subtype(_)
534534
| ty::PredicateKind::Coerce(_)

compiler/rustc_hir_analysis/src/outlives/explicit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5656
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
5757
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
5858
| ty::PredicateKind::WellFormed(..)
59-
| ty::PredicateKind::AliasEq(..)
59+
| ty::PredicateKind::AliasRelate(..)
6060
| ty::PredicateKind::ObjectSafe(..)
6161
| ty::PredicateKind::ClosureKind(..)
6262
| ty::PredicateKind::Subtype(..)

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
666666
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
667667
| ty::PredicateKind::WellFormed(..)
668668
| ty::PredicateKind::ObjectSafe(..)
669-
| ty::PredicateKind::AliasEq(..)
669+
| ty::PredicateKind::AliasRelate(..)
670670
| ty::PredicateKind::ConstEvaluatable(..)
671671
| ty::PredicateKind::ConstEquate(..)
672672
// N.B., this predicate is created by breaking down a

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
838838
| ty::PredicateKind::ConstEvaluatable(..)
839839
| ty::PredicateKind::ConstEquate(..)
840840
| ty::PredicateKind::Ambiguous
841-
| ty::PredicateKind::AliasEq(..)
841+
| ty::PredicateKind::AliasRelate(..)
842842
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
843843
}
844844
});

compiler/rustc_infer/src/infer/combine.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> InferCtxt<'tcx> {
128128
(_, ty::Alias(AliasKind::Projection, _)) | (ty::Alias(AliasKind::Projection, _), _)
129129
if self.tcx.trait_solver_next() =>
130130
{
131-
relation.register_type_equate_obligation(a, b);
131+
relation.register_type_relate_obligation(a, b);
132132
Ok(a)
133133
}
134134

@@ -842,23 +842,25 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
842842
let (a, b) = if self.a_is_expected() { (a, b) } else { (b, a) };
843843

844844
self.register_predicates([ty::Binder::dummy(if self.tcx().trait_solver_next() {
845-
ty::PredicateKind::AliasEq(a.into(), b.into())
845+
ty::PredicateKind::AliasRelate(a.into(), b.into(), ty::AliasRelationDirection::Equate)
846846
} else {
847847
ty::PredicateKind::ConstEquate(a, b)
848848
})]);
849849
}
850850

851-
/// Register an obligation that both types must be equal to each other.
852-
///
853-
/// If they aren't equal then the relation doesn't hold.
854-
fn register_type_equate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
855-
let (a, b) = if self.a_is_expected() { (a, b) } else { (b, a) };
856-
857-
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasEq(
851+
/// Register an obligation that both types must be related to each other according to
852+
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
853+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
854+
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
858855
a.into(),
859856
b.into(),
857+
self.alias_relate_direction(),
860858
))]);
861859
}
860+
861+
/// Relation direction emitted for `AliasRelate` predicates, corresponding to the direction
862+
/// of the relation.
863+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection;
862864
}
863865

864866
fn int_unification_error<'tcx>(

compiler/rustc_infer/src/infer/equate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,8 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Equate<'_, '_, 'tcx> {
210210
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
211211
self.fields.register_obligations(obligations);
212212
}
213+
214+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
215+
ty::AliasRelationDirection::Equate
216+
}
213217
}

compiler/rustc_infer/src/infer/glb.rs

+5
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,9 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
155155
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
156156
self.fields.register_obligations(obligations);
157157
}
158+
159+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
160+
// FIXME(deferred_projection_equality): This isn't right, I think?
161+
ty::AliasRelationDirection::Equate
162+
}
158163
}

compiler/rustc_infer/src/infer/lub.rs

+5
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,9 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
155155
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
156156
self.fields.register_obligations(obligations)
157157
}
158+
159+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
160+
// FIXME(deferred_projection_equality): This isn't right, I think?
161+
ty::AliasRelationDirection::Equate
162+
}
158163
}

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,34 @@ where
711711
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
712712
self.delegate.register_obligations(obligations);
713713
}
714+
715+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
716+
unreachable!("manually overridden to handle ty::Variance::Contravariant ambient variance")
717+
}
718+
719+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
720+
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
721+
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(
722+
a.into(),
723+
b.into(),
724+
ty::AliasRelationDirection::Subtype,
725+
),
726+
// a :> b is b <: a
727+
ty::Variance::Contravariant => ty::PredicateKind::AliasRelate(
728+
b.into(),
729+
a.into(),
730+
ty::AliasRelationDirection::Subtype,
731+
),
732+
ty::Variance::Invariant => ty::PredicateKind::AliasRelate(
733+
a.into(),
734+
b.into(),
735+
ty::AliasRelationDirection::Equate,
736+
),
737+
// FIXME(deferred_projection_equality): Implement this when we trigger it.
738+
// Probably just need to do nothing here.
739+
ty::Variance::Bivariant => unreachable!(),
740+
})]);
741+
}
714742
}
715743

716744
/// When we encounter a binder like `for<..> fn(..)`, we actually have

compiler/rustc_infer/src/infer/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn explicit_outlives_bounds<'tcx>(
2222
ty::PredicateKind::Clause(ty::Clause::Projection(..))
2323
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
2424
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
25-
| ty::PredicateKind::AliasEq(..)
25+
| ty::PredicateKind::AliasRelate(..)
2626
| ty::PredicateKind::Coerce(..)
2727
| ty::PredicateKind::Subtype(..)
2828
| ty::PredicateKind::WellFormed(..)

compiler/rustc_infer/src/infer/projection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'tcx> InferCtxt<'tcx> {
2626
// completely change the normalization routine with the new solver.
2727
//
2828
// The new solver correctly handles projection equality so this hack
29-
// is not necessary. if re-enabled it should emit `PredicateKind::AliasEq`
29+
// is not necessary. if re-enabled it should emit `PredicateKind::AliasRelate`
3030
// not `PredicateKind::Clause(Clause::Projection(..))` as in the new solver
3131
// `Projection` is used as `normalizes-to` which will fail for `<T as Trait>::Assoc eq ?0`.
3232
return projection_ty.to_ty(self.tcx);

compiler/rustc_infer/src/infer/sub.rs

+4
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,8 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Sub<'_, '_, 'tcx> {
236236
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
237237
self.fields.register_obligations(obligations);
238238
}
239+
240+
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
241+
ty::AliasRelationDirection::Subtype
242+
}
239243
}

compiler/rustc_infer/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'tcx> Elaborator<'tcx> {
293293
// Nothing to elaborate
294294
}
295295
ty::PredicateKind::Ambiguous => {}
296-
ty::PredicateKind::AliasEq(..) => {
296+
ty::PredicateKind::AliasRelate(..) => {
297297
// No
298298
}
299299
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
16001600
// Ignore projections, as they can only be global
16011601
// if the trait bound is global
16021602
Clause(Clause::Projection(..)) |
1603-
AliasEq(..) |
1603+
AliasRelate(..) |
16041604
// Ignore bounds that a user can't type
16051605
WellFormed(..) |
16061606
ObjectSafe(..) |

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare_lint! {
2727
/// ### Example
2828
///
2929
/// ```rust
30+
/// #![feature(type_alias_impl_trait)]
31+
///
3032
/// trait Duh {}
3133
///
3234
/// impl Duh for i32 {}
@@ -41,7 +43,9 @@ declare_lint! {
4143
/// type Assoc = F;
4244
/// }
4345
///
44-
/// fn test() -> impl Trait<Assoc = impl Sized> {
46+
/// type Tait = impl Sized;
47+
///
48+
/// fn test() -> impl Trait<Assoc = Tait> {
4549
/// 42
4650
/// }
4751
/// ```
@@ -54,7 +58,7 @@ declare_lint! {
5458
///
5559
/// Although the hidden type, `i32` does satisfy this bound, we do not
5660
/// consider the return type to be well-formed with this lint. It can be
57-
/// fixed by changing `impl Sized` into `impl Sized + Send`.
61+
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Send`.
5862
pub OPAQUE_HIDDEN_INFERRED_BOUND,
5963
Warn,
6064
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"
@@ -64,7 +68,7 @@ declare_lint_pass!(OpaqueHiddenInferredBound => [OPAQUE_HIDDEN_INFERRED_BOUND]);
6468

6569
impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
6670
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
67-
let hir::ItemKind::OpaqueTy(_) = &item.kind else { return; };
71+
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else { return; };
6872
let def_id = item.owner_id.def_id.to_def_id();
6973
let infcx = &cx.tcx.infer_ctxt().build();
7074
// For every projection predicate in the opaque type's explicit bounds,
@@ -81,6 +85,17 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
8185
// have opaques in them anyways.
8286
let Some(proj_term) = proj.term.ty() else { continue };
8387

88+
// HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"...
89+
if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind()
90+
&& cx.tcx.parent(opaque_ty.def_id) == def_id
91+
&& matches!(
92+
opaque.origin,
93+
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_)
94+
)
95+
{
96+
continue;
97+
}
98+
8499
let proj_ty =
85100
cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs);
86101
// For every instance of the projection type in the bounds,

compiler/rustc_metadata/src/rmeta/decoder.rs

-4
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
925925
tcx.mk_adt_def(did, adt_kind, variants, repr)
926926
}
927927

928-
fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics {
929-
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
930-
}
931-
932928
fn get_visibility(self, id: DefIndex) -> Visibility<DefId> {
933929
self.root
934930
.tables

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

-12
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ impl CStore {
545545
self.get_crate_data(def.krate).def_kind(def.index)
546546
}
547547

548-
pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
549-
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
550-
}
551-
552548
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
553549
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
554550
}
@@ -560,14 +556,6 @@ impl CStore {
560556
self.get_crate_data(cnum).num_def_ids()
561557
}
562558

563-
pub fn item_attrs_untracked<'a>(
564-
&'a self,
565-
def_id: DefId,
566-
sess: &'a Session,
567-
) -> impl Iterator<Item = ast::Attribute> + 'a {
568-
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess)
569-
}
570-
571559
pub fn get_proc_macro_quoted_span_untracked(
572560
&self,
573561
cnum: CrateNum,

compiler/rustc_middle/src/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl FlagComputation {
288288
self.add_ty(ty);
289289
}
290290
ty::PredicateKind::Ambiguous => {}
291-
ty::PredicateKind::AliasEq(t1, t2) => {
291+
ty::PredicateKind::AliasRelate(t1, t2, _) => {
292292
self.add_term(t1);
293293
self.add_term(t2);
294294
}

compiler/rustc_middle/src/ty/mod.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'tcx> Predicate<'tcx> {
543543
| PredicateKind::Clause(Clause::TypeOutlives(_))
544544
| PredicateKind::Clause(Clause::Projection(_))
545545
| PredicateKind::Clause(Clause::ConstArgHasType(..))
546-
| PredicateKind::AliasEq(..)
546+
| PredicateKind::AliasRelate(..)
547547
| PredicateKind::ObjectSafe(_)
548548
| PredicateKind::ClosureKind(_, _, _)
549549
| PredicateKind::Subtype(_)
@@ -640,7 +640,23 @@ pub enum PredicateKind<'tcx> {
640640
/// This predicate requires two terms to be equal to eachother.
641641
///
642642
/// Only used for new solver
643-
AliasEq(Term<'tcx>, Term<'tcx>),
643+
AliasRelate(Term<'tcx>, Term<'tcx>, AliasRelationDirection),
644+
}
645+
646+
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
647+
#[derive(HashStable, Debug)]
648+
pub enum AliasRelationDirection {
649+
Equate,
650+
Subtype,
651+
}
652+
653+
impl std::fmt::Display for AliasRelationDirection {
654+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
655+
match self {
656+
AliasRelationDirection::Equate => write!(f, " == "),
657+
AliasRelationDirection::Subtype => write!(f, " <: "),
658+
}
659+
}
644660
}
645661

646662
/// The crate outlives map is computed during typeck and contains the
@@ -976,11 +992,11 @@ impl<'tcx> Term<'tcx> {
976992
}
977993
}
978994

979-
/// This function returns `None` for `AliasKind::Opaque`.
995+
/// This function returns the inner `AliasTy` if this term is a projection.
980996
///
981997
/// FIXME: rename `AliasTy` to `AliasTerm` and make sure we correctly
982998
/// deal with constants.
983-
pub fn to_alias_term_no_opaque(&self, tcx: TyCtxt<'tcx>) -> Option<AliasTy<'tcx>> {
999+
pub fn to_projection_term(&self, tcx: TyCtxt<'tcx>) -> Option<AliasTy<'tcx>> {
9841000
match self.unpack() {
9851001
TermKind::Ty(ty) => match ty.kind() {
9861002
ty::Alias(kind, alias_ty) => match kind {
@@ -1206,7 +1222,7 @@ impl<'tcx> Predicate<'tcx> {
12061222
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
12071223
PredicateKind::Clause(Clause::Projection(..))
12081224
| PredicateKind::Clause(Clause::ConstArgHasType(..))
1209-
| PredicateKind::AliasEq(..)
1225+
| PredicateKind::AliasRelate(..)
12101226
| PredicateKind::Subtype(..)
12111227
| PredicateKind::Coerce(..)
12121228
| PredicateKind::Clause(Clause::RegionOutlives(..))
@@ -1227,7 +1243,7 @@ impl<'tcx> Predicate<'tcx> {
12271243
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
12281244
PredicateKind::Clause(Clause::Trait(..))
12291245
| PredicateKind::Clause(Clause::ConstArgHasType(..))
1230-
| PredicateKind::AliasEq(..)
1246+
| PredicateKind::AliasRelate(..)
12311247
| PredicateKind::Subtype(..)
12321248
| PredicateKind::Coerce(..)
12331249
| PredicateKind::Clause(Clause::RegionOutlives(..))
@@ -1249,7 +1265,7 @@ impl<'tcx> Predicate<'tcx> {
12491265
PredicateKind::Clause(Clause::Trait(..))
12501266
| PredicateKind::Clause(Clause::ConstArgHasType(..))
12511267
| PredicateKind::Clause(Clause::Projection(..))
1252-
| PredicateKind::AliasEq(..)
1268+
| PredicateKind::AliasRelate(..)
12531269
| PredicateKind::Subtype(..)
12541270
| PredicateKind::Coerce(..)
12551271
| PredicateKind::Clause(Clause::RegionOutlives(..))

compiler/rustc_middle/src/ty/print/pretty.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,11 @@ pub trait PrettyPrinter<'tcx>:
704704
ty::BoundTyKind::Anon(bv) => {
705705
self.pretty_print_bound_var(debruijn, ty::BoundVar::from_u32(bv))?
706706
}
707-
ty::BoundTyKind::Param(_, s) => p!(write("{}", s)),
707+
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
708+
true if debruijn == ty::INNERMOST => p!(write("^{}", s)),
709+
true => p!(write("^{}_{}", debruijn.index(), s)),
710+
false => p!(write("{}", s)),
711+
},
708712
},
709713
ty::Adt(def, substs) => {
710714
p!(print_def_path(def.did(), substs));
@@ -2847,7 +2851,7 @@ define_print_and_forward_display! {
28472851
p!("the type `", print(ty), "` is found in the environment")
28482852
}
28492853
ty::PredicateKind::Ambiguous => p!("ambiguous"),
2850-
ty::PredicateKind::AliasEq(t1, t2) => p!(print(t1), " == ", print(t2)),
2854+
ty::PredicateKind::AliasRelate(t1, t2, dir) => p!(print(t1), write(" {} ", dir), print(t2)),
28512855
}
28522856
}
28532857

0 commit comments

Comments
 (0)