Skip to content

Commit 1c580bc

Browse files
committedMar 7, 2024
Auto merge of rust-lang#122139 - GuillaumeGomez:rollup-37vtwsc, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - rust-lang#121863 (silence mismatched types errors for implied projections) - rust-lang#122043 (Apply `EarlyBinder` only to `TraitRef` in `ImplTraitHeader`) - rust-lang#122066 (Add proper cfgs for struct HirIdValidator used only with debug-assert) - rust-lang#122104 (Rust is a proper name: rust → Rust) - rust-lang#122110 (Make `x t miri` respect `MIRI_TEMP`) - rust-lang#122114 (Make not finding core a fatal error) - rust-lang#122115 (Cancel parsing ever made during recovery) - rust-lang#122123 (Don't require specifying unrelated assoc types when trait alias is in `dyn` type) - rust-lang#122126 (Fix `tidy --bless` on ̶X̶e̶n̶i̶x̶ Windows) - rust-lang#122129 (Set `RustcDocs` to only run on host) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 52f8aec + ce9a6ad commit 1c580bc

File tree

62 files changed

+547
-315
lines changed

Some content is hidden

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

62 files changed

+547
-315
lines changed
 

‎compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1612,10 +1612,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16121612
.any(|impl_def_id| {
16131613
let impl_header = tcx.impl_trait_header(impl_def_id);
16141614
impl_header.is_some_and(|header| {
1615-
let header = header.instantiate(
1615+
let trait_ref = header.trait_ref.instantiate(
16161616
tcx,
16171617
infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
16181618
);
1619+
16191620
let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
16201621
// FIXME: Don't bother dealing with non-lifetime binders here...
16211622
if value.has_escaping_bound_vars() {
@@ -1624,7 +1625,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16241625
infcx
16251626
.can_eq(
16261627
ty::ParamEnv::empty(),
1627-
header.trait_ref.self_ty(),
1628+
trait_ref.self_ty(),
16281629
value,
16291630
) && header.polarity != ty::ImplPolarity::Negative
16301631
})
@@ -1677,9 +1678,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16771678
.filter(|header| {
16781679
// Consider only accessible traits
16791680
tcx.visibility(trait_def_id).is_accessible_from(self.item_def_id(), tcx)
1680-
&& header.skip_binder().polarity != ty::ImplPolarity::Negative
1681+
&& header.polarity != ty::ImplPolarity::Negative
16811682
})
1682-
.map(|header| header.instantiate_identity().trait_ref.self_ty())
1683+
.map(|header| header.trait_ref.instantiate_identity().self_ty())
16831684
// We don't care about blanket impls.
16841685
.filter(|self_ty| !self_ty.has_non_region_param())
16851686
.map(|self_ty| tcx.erase_regions(self_ty).to_string())

‎compiler/rustc_hir_analysis/src/astconv/object_safety.rs

+36-44
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
4545
dummy_self,
4646
&mut bounds,
4747
false,
48-
// FIXME: This should be `true`, but we don't really handle
49-
// associated type bounds or type aliases in objects in a way
50-
// that makes this meaningful, I think.
51-
OnlySelfBounds(false),
48+
// True so we don't populate `bounds` with associated type bounds, even
49+
// though they're disallowed from object types.
50+
OnlySelfBounds(true),
5251
) {
5352
potential_assoc_types.extend(cur_potential_assoc_types);
5453
}
@@ -83,9 +82,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
8382
let expanded_traits =
8483
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b)| (a, b)));
8584

86-
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
87-
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
88-
.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id()));
85+
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) =
86+
expanded_traits.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id()));
8987
if regular_traits.len() > 1 {
9088
let first_trait = &regular_traits[0];
9189
let additional_trait = &regular_traits[1];
@@ -158,7 +156,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
158156

159157
for (base_trait_ref, span) in regular_traits_refs_spans {
160158
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
161-
for pred in traits::elaborate(tcx, [base_pred]) {
159+
for pred in traits::elaborate(tcx, [base_pred]).filter_only_self() {
162160
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);
163161

164162
let bound_predicate = pred.kind();
@@ -312,45 +310,39 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
312310
})
313311
});
314312

315-
let existential_projections = projection_bounds
316-
.iter()
317-
// We filter out traits that don't have `Self` as their self type above,
318-
// we need to do the same for projections.
319-
.filter(|(bound, _)| bound.skip_binder().self_ty() == dummy_self)
320-
.map(|(bound, _)| {
321-
bound.map_bound(|mut b| {
322-
assert_eq!(b.projection_ty.self_ty(), dummy_self);
313+
let existential_projections = projection_bounds.iter().map(|(bound, _)| {
314+
bound.map_bound(|mut b| {
315+
assert_eq!(b.projection_ty.self_ty(), dummy_self);
323316

324-
// Like for trait refs, verify that `dummy_self` did not leak inside default type
325-
// parameters.
326-
let references_self = b.projection_ty.args.iter().skip(1).any(|arg| {
327-
if arg.walk().any(|arg| arg == dummy_self.into()) {
328-
return true;
329-
}
330-
false
331-
});
332-
if references_self {
333-
let guar = tcx.dcx().span_delayed_bug(
334-
span,
335-
"trait object projection bounds reference `Self`",
336-
);
337-
let args: Vec<_> = b
338-
.projection_ty
339-
.args
340-
.iter()
341-
.map(|arg| {
342-
if arg.walk().any(|arg| arg == dummy_self.into()) {
343-
return Ty::new_error(tcx, guar).into();
344-
}
345-
arg
346-
})
347-
.collect();
348-
b.projection_ty.args = tcx.mk_args(&args);
317+
// Like for trait refs, verify that `dummy_self` did not leak inside default type
318+
// parameters.
319+
let references_self = b.projection_ty.args.iter().skip(1).any(|arg| {
320+
if arg.walk().any(|arg| arg == dummy_self.into()) {
321+
return true;
349322
}
323+
false
324+
});
325+
if references_self {
326+
let guar = tcx
327+
.dcx()
328+
.span_delayed_bug(span, "trait object projection bounds reference `Self`");
329+
let args: Vec<_> = b
330+
.projection_ty
331+
.args
332+
.iter()
333+
.map(|arg| {
334+
if arg.walk().any(|arg| arg == dummy_self.into()) {
335+
return Ty::new_error(tcx, guar).into();
336+
}
337+
arg
338+
})
339+
.collect();
340+
b.projection_ty.args = tcx.mk_args(&args);
341+
}
350342

351-
ty::ExistentialProjection::erase_self_ty(tcx, b)
352-
})
353-
});
343+
ty::ExistentialProjection::erase_self_ty(tcx, b)
344+
})
345+
});
354346

355347
let regular_trait_predicates = existential_trait_refs
356348
.map(|trait_ref| trait_ref.map_bound(ty::ExistentialPredicate::Trait));

0 commit comments

Comments
 (0)
Please sign in to comment.