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 #82045

Merged
merged 30 commits into from
Feb 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
86a4b27
Increment `self.index` before calling `Iterator::self.a.__iterator_ge…
sdroege Feb 4, 2021
55ca27f
use rwlock for accessing ENV
the8472 Feb 6, 2021
406fd3a
silence dead code warnings on windows
the8472 Feb 7, 2021
c7d9bff
HWASan support
Jan 23, 2021
9c34c14
HWASan documentation
Feb 8, 2021
2200cf1
avoid &mut on the read path since it now allows concurrent readers
the8472 Feb 8, 2021
44abad5
introduce StaticRWLock wrapper to make methods safe
the8472 Feb 8, 2021
1d9ac3c
Fix const generics in GAT
BoxyUwU Feb 9, 2021
4fc181d
split guard into read and write types
the8472 Feb 9, 2021
2c4337a
Comments :3
BoxyUwU Feb 10, 2021
0422745
Fix comment smol mistakes
BoxyUwU Feb 10, 2021
0ffa2da
comma...
BoxyUwU Feb 10, 2021
d64b749
Allow casting mut array ref to mut ptr
osa1 Jan 28, 2021
7ca96ed
rewrite the comments
BoxyUwU Feb 10, 2021
02ffe9e
Fix injected errors when running doctests on a crate named after a ke…
jyn514 Dec 6, 2020
fda71d6
Push a `char` instead of a `str` with len one into a String
LingMan Feb 12, 2021
f546633
Remove unnecessary lint allow attrs on example
MikailBag Feb 12, 2021
de21cdf
update documents
VillSnow Jan 31, 2021
afdc8c7
stabilize partition_point
VillSnow Jan 14, 2021
fde59a8
Use `Iterator::all` instead of open-coding it
LingMan Feb 12, 2021
ab3f4f0
Rollup merge of #79775 - jyn514:doctest, r=GuillaumeGomez
Dylan-DPC Feb 12, 2021
8280abc
Rollup merge of #81012 - VillSnow:stabilize_partition_point, r=matklad
Dylan-DPC Feb 12, 2021
fc93e26
Rollup merge of #81479 - osa1:issue24151, r=lcnr
Dylan-DPC Feb 12, 2021
58d72ae
Rollup merge of #81506 - vo4:hwasan, r=nagisa
Dylan-DPC Feb 12, 2021
0cfba2f
Rollup merge of #81741 - sdroege:zip-trusted-random-access-specializa…
Dylan-DPC Feb 12, 2021
354f19c
Rollup merge of #81850 - the8472:env-rwlock, r=m-ou-se
Dylan-DPC Feb 12, 2021
b67be3a
Rollup merge of #81911 - BoxyUwU:constgenericgaticefix, r=nikomatsakis
Dylan-DPC Feb 12, 2021
ef7c45a
Rollup merge of #82022 - LingMan:single_char, r=jonas-schievink
Dylan-DPC Feb 12, 2021
54013fe
Rollup merge of #82023 - MikailBag:boxed-docs-unallow, r=jyn514
Dylan-DPC Feb 12, 2021
1ef566f
Rollup merge of #82030 - LingMan:init_directly, r=varkor
Dylan-DPC Feb 12, 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
33 changes: 21 additions & 12 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
@@ -29,20 +29,28 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
let parent_node = tcx.hir().get(parent_node_id);

match parent_node {
// This matches on types who's paths couldn't be resolved without typeck'ing e.g.
// This match arm is for when the def_id appears in a GAT whose
// path can't be resolved without typechecking e.g.
//
// trait Foo {
// type Assoc<const N1: usize>;
// type Assoc<const N: usize>;
// fn foo() -> Self::Assoc<3>;
// // note: if the def_id argument is the 3 then in this example
// // parent_node would be the node for Self::Assoc<_>
// }
// We didnt write <Self as Foo>::Assoc so the Self::Assoc<_> is lowered to QPath::TypeRelative.
//
// In the above code we would call this query with the def_id of 3 and
// the parent_node we match on would be the hir node for Self::Assoc<3>
//
// `Self::Assoc<3>` cant be resolved without typchecking here as we
// didnt write <Self as Foo>::Assoc<3>. If we did then another match
// arm would handle this.
//
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
Node::Ty(hir_ty @ Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
// Walk up from the parent_node to find an item so that
// we can resolve the relative path to an actual associated type.
// For the code example above, this item would be the Foo trait.
// Find the Item containing the associated type so we can create an ItemCtxt.
// Using the ItemCtxt convert the HIR for the unresolved assoc type into a
// ty which is a fully resolved projection.
// For the code example above, this would mean converting Self::Assoc<3>
// into a ty::Projection(<Self as Foo>::Assoc<3>)
let item_hir_id = tcx
.hir()
.parent_iter(hir_id)
@@ -52,11 +60,12 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
.unwrap();
let item_did = tcx.hir().local_def_id(item_hir_id).to_def_id();
let item_ctxt = &ItemCtxt::new(tcx, item_did) as &dyn crate::astconv::AstConv<'_>;

// This ty will be the actual associated type so that we can
// go through its generics to find which param our def_id corresponds to.
// For the code example above, this ty would be the Assoc<const N1: usize>.
let ty = item_ctxt.ast_ty_to_ty(hir_ty);

// Iterate through the generics of the projection to find the one that corresponds to
// the def_id that this query was called with. We filter to only const args here as a
// precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
// but it can't hurt to be safe ^^
if let ty::Projection(projection) = ty.kind() {
let generics = tcx.generics_of(projection.item_def_id);