Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #82263

Merged
merged 30 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dfa581f
Fix pretty printing of generic associated type constraints
matthewjasper Feb 11, 2021
9bbd3e0
Remove ProjectionTy::from_ref_and_name
matthewjasper Feb 11, 2021
0bf1d73
Don't go through TraitRef to relate projections
matthewjasper Feb 12, 2021
9526c0c
Avoid `trait_ref` when lowering ExistentialProjections
matthewjasper Feb 12, 2021
79f6f11
Remove some unnecessary `trait_ref` calls
matthewjasper Feb 12, 2021
dfee89f
Make ProjectionTy::trait_ref truncate substs again
matthewjasper Feb 12, 2021
d785c8c
Remove unnecessary function parameters project.rs
matthewjasper Feb 12, 2021
eeb82e4
Add more tests for generic associated type bounds
matthewjasper Feb 12, 2021
7e368e5
the environment round here is awfully empty
BoxyUwU Feb 15, 2021
0f04875
replace if-let and while-let with `if let` and `while let`
TaKO8Ki Feb 17, 2021
43aed74
[libtest] Run the test synchronously when hitting thread limit
Jan 29, 2021
2a66685
Make sure pdbs are copied along with exe and dlls when bootstrapping
rylev Feb 17, 2021
32c97da
In some limited cases, suggest `where` bounds for non-type params
estebank Feb 16, 2021
ec50a20
avoid converting types into themselves (clippy::useless_conversion)
matthiaskrgr Feb 17, 2021
5ae392f
Add long explanation for E0549
jesusprubio Feb 18, 2021
5112cf0
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
0e01c41
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
3c4fe1e
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
6165d1c
Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.
eddyb Feb 18, 2021
8a5c568
nhwn: optimize counting digits in line numbers
nhwn Feb 18, 2021
55ab2e3
Rollup merge of #81546 - hyd-dev:libtest-run-out-of-threads, r=Mark-S…
Dylan-DPC Feb 18, 2021
66211f6
Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Dylan-DPC Feb 18, 2021
928819a
Rollup merge of #82112 - BoxyUwU:tumbleweed, r=varkor
Dylan-DPC Feb 18, 2021
f01b339
Rollup merge of #82194 - estebank:arbitrary-bounds-suggestion, r=petr…
Dylan-DPC Feb 18, 2021
b3d3251
Rollup merge of #82215 - TaKO8Ki:replace-if-let-while-let, r=varkor
Dylan-DPC Feb 18, 2021
01104b5
Rollup merge of #82218 - rylev:copy-pdbs, r=Mark-Simulacrum
Dylan-DPC Feb 18, 2021
04df75a
Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514
Dylan-DPC Feb 18, 2021
5ca94cd
Rollup merge of #82246 - jesusprubio:add-long-explanation-e0549, r=Gu…
Dylan-DPC Feb 18, 2021
555db2d
Rollup merge of #82248 - nhwn:optimize-counting-digits, r=varkor
Dylan-DPC Feb 18, 2021
efdcb43
Rollup merge of #82256 - eddyb:time-passes-stderr, r=varkor
Dylan-DPC Feb 18, 2021
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
Prev Previous commit
Next Next commit
Avoid trait_ref when lowering ExistentialProjections
  • Loading branch information
matthewjasper committed Feb 13, 2021
commit 9526c0c6e83f37deb1d48e9761ee9bee2ae94f60
23 changes: 18 additions & 5 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
/// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`,
/// then this function would return a `exists T. T: Iterator` existential trait
/// reference.
pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::ExistentialTraitRef<'tcx> {
// FIXME(generic_associated_types): substs is the substs of the
// associated type, which should be truncated to get the correct substs
// for the trait.
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> {
let def_id = tcx.associated_item(self.item_def_id).container.id();
ty::ExistentialTraitRef { def_id, substs: self.substs }
let subst_count = tcx.generics_of(def_id).count() - 1;
let substs = tcx.intern_substs(&self.substs[..subst_count]);
ty::ExistentialTraitRef { def_id, substs }
}

pub fn with_self_ty(
Expand All @@ -1501,6 +1500,20 @@ impl<'tcx> ExistentialProjection<'tcx> {
ty: self.ty,
}
}

pub fn erase_self_ty(
tcx: TyCtxt<'tcx>,
projection_predicate: ty::ProjectionPredicate<'tcx>,
) -> Self {
// Assert there is a Self.
projection_predicate.projection_ty.substs.type_at(0);

Self {
item_def_id: projection_predicate.projection_ty.item_def_id,
substs: tcx.intern_substs(&projection_predicate.projection_ty.substs[1..]),
ty: projection_predicate.ty,
}
}
}

impl<'tcx> PolyExistentialProjection<'tcx> {
Expand Down
57 changes: 26 additions & 31 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
//
// We want to produce `<B as SuperTrait<i32>>::T == foo`.

debug!(
"add_predicates_for_ast_type_binding(hir_ref_id {:?}, trait_ref {:?}, binding {:?}, bounds {:?}",
hir_ref_id, trait_ref, binding, bounds
);
debug!(?hir_ref_id, ?trait_ref, ?binding, ?bounds, "add_predicates_for_ast_type_binding",);
let tcx = self.tcx();

let candidate =
Expand Down Expand Up @@ -1326,37 +1323,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("regular_traits: {:?}", regular_traits);
debug!("auto_traits: {:?}", auto_traits);

// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
// removing the dummy `Self` type (`trait_object_dummy_self`).
let trait_ref_to_existential = |trait_ref: ty::TraitRef<'tcx>| {
if trait_ref.self_ty() != dummy_self {
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
// which picks up non-supertraits where clauses - but also, the object safety
// completely ignores trait aliases, which could be object safety hazards. We
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
// disabled. (#66420)
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"trait_ref_to_existential called on {:?} with non-dummy Self",
trait_ref,
),
);
}
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
};

// Erase the `dummy_self` (`trait_object_dummy_self`) used above.
let existential_trait_refs =
regular_traits.iter().map(|i| i.trait_ref().map_bound(trait_ref_to_existential));
let existential_trait_refs = regular_traits.iter().map(|i| {
i.trait_ref().map_bound(|trait_ref: ty::TraitRef<'tcx>| {
if trait_ref.self_ty() != dummy_self {
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
// which picks up non-supertraits where clauses - but also, the object safety
// completely ignores trait aliases, which could be object safety hazards. We
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
// disabled. (#66420)
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"trait_ref_to_existential called on {:?} with non-dummy Self",
trait_ref,
),
);
}
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
})
});
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
bound.map_bound(|b| {
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx));
ty::ExistentialProjection {
ty: b.ty,
item_def_id: b.projection_ty.item_def_id,
substs: trait_ref.substs,
if b.projection_ty.self_ty() != dummy_self {
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!("trait_ref_to_existential called on {:?} with non-dummy Self", b),
);
}
ty::ExistentialProjection::erase_self_ty(tcx, b)
})
});

Expand Down