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

Merge TraitItem & ImplItem into AssocItem` #67131

Merged
merged 26 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c4bbe9c
Alias `TraitItem` & `ImplItem`.
Centril Nov 30, 2019
73557fa
Use `Option` in `ImplItemKind::Const`.
Centril Dec 1, 2019
f6403c6
Use `Option` in `ImplItemKind::Method`.
Centril Dec 1, 2019
c02fd31
`TraitItemKind::Type` -> `TraitItemKind::TyAlias`.
Centril Dec 1, 2019
3907376
Unify `{Trait,Impl}ItemKind::TyAlias` structures.
Centril Dec 1, 2019
92a372b
Unify `{Impl,Trait}Item` as `AssocItem`.
Centril Dec 1, 2019
2d92aa5
Fuse associated constant parsing.
Centril Dec 1, 2019
10270bc
Fuse associated type parsing.
Centril Dec 1, 2019
7672bff
Unify associated function parsing.
Centril Dec 1, 2019
63a9030
Unify associated item parsing.
Centril Dec 1, 2019
fa828d7
Relocate `is_const_item`.
Centril Dec 1, 2019
404013e
Leave a FIXME re. `allow_plus`.
Centril Dec 1, 2019
34d9170
parse: refactor fun ret ty & param ty
Centril Dec 1, 2019
9193d7a
Unify associated item pretty printing.
Centril Dec 1, 2019
76576d4
Unify associated item mut visitors.
Centril Dec 1, 2019
c6c17e3
Simplify `nt_to_tokenstream`.
Centril Dec 1, 2019
0d8a9d7
Unify associated item visitor.
Centril Dec 1, 2019
51ccdeb
Unify associated item parsing more.
Centril Dec 1, 2019
b499a88
Unify assoc item visitors more.
Centril Dec 2, 2019
0d41d0f
Move `allow_c_varadic` logic to `ast_validation`.
Centril Dec 2, 2019
3a57a2c
`ast_validation`: move trait item logic to proper place.
Centril Dec 2, 2019
35e9e09
More c-variadic errors as semantic restrictions.
Centril Dec 2, 2019
abf2e7a
Remove `ast::{Impl,Trait}{Item,ItemKind}`.
Centril Dec 7, 2019
e52f902
`AssocImplKind::{Method -> Fn}`.
Centril Dec 7, 2019
74d4fbc
De-fatalize `...` parsing.
Centril Dec 8, 2019
054458b
make visitor uses more robust
Centril Dec 11, 2019
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
83 changes: 36 additions & 47 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,11 @@ impl<'a> LoweringContext<'a> {
});
}

fn visit_trait_item(&mut self, item: &'tcx TraitItem) {
fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
self.lctx.allocate_hir_id_counter(item.id);

match item.kind {
TraitItemKind::Method(_, None) => {
AssocItemKind::Fn(_, None) => {
// Ignore patterns in trait methods without bodies
self.with_hir_id_owner(None, |this| {
visit::walk_trait_item(this, item)
Expand All @@ -493,7 +493,7 @@ impl<'a> LoweringContext<'a> {
}
}

fn visit_impl_item(&mut self, item: &'tcx ImplItem) {
fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
self.lctx.allocate_hir_id_counter(item.id);
self.with_hir_id_owner(Some(item.id), |this| {
visit::walk_impl_item(this, item);
Expand Down Expand Up @@ -1211,7 +1211,7 @@ impl<'a> LoweringContext<'a> {
let ct = self.with_new_scopes(|this| {
hir::AnonConst {
hir_id: this.lower_node_id(node_id),
body: this.lower_const_body(&path_expr),
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
}
});
return GenericArg::Const(ConstArg {
Expand Down Expand Up @@ -1253,6 +1253,14 @@ impl<'a> LoweringContext<'a> {
ty
}

fn ty(&mut self, span: Span, kind: hir::TyKind) -> hir::Ty {
hir::Ty { hir_id: self.next_id(), kind, span }
}

fn ty_tup(&mut self, span: Span, tys: HirVec<hir::Ty>) -> hir::Ty {
self.ty(span, hir::TyKind::Tup(tys))
}

fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_>) -> hir::Ty {
let kind = match t.kind {
TyKind::Infer => hir::TyKind::Infer,
Expand Down Expand Up @@ -1418,7 +1426,13 @@ impl<'a> LoweringContext<'a> {
}
}
TyKind::Mac(_) => bug!("`TyKind::Mac` should have been expanded by now"),
TyKind::CVarArgs => bug!("`TyKind::CVarArgs` should have been handled elsewhere"),
TyKind::CVarArgs => {
self.sess.delay_span_bug(
t.span,
"`TyKind::CVarArgs` should have been handled elsewhere",
);
hir::TyKind::Err
}
};

hir::Ty {
Expand Down Expand Up @@ -2084,32 +2098,19 @@ impl<'a> LoweringContext<'a> {
.iter()
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
.collect();
let mk_tup = |this: &mut Self, tys, span| {
hir::Ty { kind: hir::TyKind::Tup(tys), hir_id: this.next_id(), span }
let output_ty = match output {
FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
FunctionRetTy::Default(_) => P(this.ty_tup(span, hir::HirVec::new())),
};
let args = hir_vec![GenericArg::Type(this.ty_tup(span, inputs))];
let binding = hir::TypeBinding {
hir_id: this.next_id(),
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
span: output_ty.span,
kind: hir::TypeBindingKind::Equality { ty: output_ty },
};
(
hir::GenericArgs {
args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
bindings: hir_vec![
hir::TypeBinding {
hir_id: this.next_id(),
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
kind: hir::TypeBindingKind::Equality {
ty: output
.as_ref()
.map(|ty| this.lower_ty(
&ty,
ImplTraitContext::disallowed()
))
.unwrap_or_else(||
P(mk_tup(this, hir::HirVec::new(), span))
),
},
span: output.as_ref().map_or(span, |ty| ty.span),
}
],
parenthesized: true,
},
hir::GenericArgs { args, bindings: hir_vec![binding], parenthesized: true },
false,
)
}
Expand Down Expand Up @@ -2474,17 +2475,13 @@ impl<'a> LoweringContext<'a> {
})
);

// Create the `Foo<...>` refernece itself. Note that the `type
// Create the `Foo<...>` reference itself. Note that the `type
// Foo = impl Trait` is, internally, created as a child of the
// async fn, so the *type parameters* are inherited. It's
// only the lifetime parameters that we must supply.
let opaque_ty_ref = hir::TyKind::Def(hir::ItemId { id: opaque_ty_id }, generic_args.into());

hir::FunctionRetTy::Return(P(hir::Ty {
kind: opaque_ty_ref,
span: opaque_ty_span,
hir_id: self.next_id(),
}))
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FunctionRetTy::Return(P(opaque_ty))
}

/// Transforms `-> T` into `Future<Output = T>`
Expand All @@ -2496,16 +2493,8 @@ impl<'a> LoweringContext<'a> {
) -> hir::GenericBound {
// Compute the `T` in `Future<Output = T>` from the return type.
let output_ty = match output {
FunctionRetTy::Ty(ty) => {
self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id)))
}
FunctionRetTy::Default(ret_ty_span) => {
P(hir::Ty {
hir_id: self.next_id(),
kind: hir::TyKind::Tup(hir_vec![]),
span: *ret_ty_span,
})
}
FunctionRetTy::Ty(ty) => self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id))),
FunctionRetTy::Default(ret_ty_span) => P(self.ty_tup(*ret_ty_span, hir_vec![])),
};

// "<Output = T>"
Expand Down Expand Up @@ -3003,7 +2992,7 @@ impl<'a> LoweringContext<'a> {
self.with_new_scopes(|this| {
hir::AnonConst {
hir_id: this.lower_node_id(c.id),
body: this.lower_const_body(&c.value),
body: this.lower_const_body(c.value.span, Some(&c.value)),
}
})
}
Expand Down
Loading