Skip to content

Commit 4df69cb

Browse files
committed
Pass generics through to existential impl Trait lowering
1 parent 953da9d commit 4df69cb

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/librustc/hir/lowering.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ enum ImplTraitContext<'a> {
181181
/// We store a DefId here so we can look up necessary information later
182182
///
183183
/// All generics of the surrounding function must go into the generated existential type
184-
Existential(DefId, &'a [hir::TyParam]),
184+
Existential(DefId, &'a [hir::TyParam], &'a hir::Generics),
185185

186186
/// `impl Trait` is not accepted in this position.
187187
Disallowed,
@@ -192,7 +192,7 @@ impl<'a> ImplTraitContext<'a> {
192192
use self::ImplTraitContext::*;
193193
match self {
194194
Universal(did, params) => Universal(*did, params),
195-
Existential(did, params) => Existential(*did, params),
195+
Existential(did, params, generics) => Existential(*did, params, generics),
196196
Disallowed => Disallowed,
197197
}
198198
}
@@ -809,7 +809,7 @@ impl<'a> LoweringContext<'a> {
809809
f: F,
810810
) -> (hir::Generics, T)
811811
where
812-
F: FnOnce(&mut LoweringContext, &mut Vec<hir::TyParam>) -> T,
812+
F: FnOnce(&mut LoweringContext, &mut Vec<hir::TyParam>, &hir::Generics) -> T,
813813
{
814814
let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs(
815815
generics.params.iter().filter_map(|p| match p {
@@ -823,7 +823,7 @@ impl<'a> LoweringContext<'a> {
823823
generics,
824824
ImplTraitContext::Universal(parent_id, &mut params),
825825
);
826-
let res = f(this, &mut params);
826+
let res = f(this, &mut params, &generics);
827827
(params, (generics, res))
828828
})
829829
},
@@ -1142,7 +1142,7 @@ impl<'a> LoweringContext<'a> {
11421142
TyKind::ImplTrait(exist_ty_node_id, ref bounds) => {
11431143
let span = t.span;
11441144
match itctx {
1145-
ImplTraitContext::Existential(fn_def_id, _) => {
1145+
ImplTraitContext::Existential(fn_def_id, _, _) => {
11461146
// Make sure we know that some funky desugaring has been going on here.
11471147
// This is a first: there is code in other places like for loop
11481148
// desugaring that explicitly states that we don't want to track that.
@@ -1848,7 +1848,7 @@ impl<'a> LoweringContext<'a> {
18481848
fn lower_fn_decl(
18491849
&mut self,
18501850
decl: &FnDecl,
1851-
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::TyParam>)>,
1851+
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::TyParam>, &hir::Generics)>,
18521852
impl_trait_return_allow: bool,
18531853
) -> P<hir::FnDecl> {
18541854
// NOTE: The two last parameters here have to do with impl Trait. If fn_def_id is Some,
@@ -1862,7 +1862,7 @@ impl<'a> LoweringContext<'a> {
18621862
inputs: decl.inputs
18631863
.iter()
18641864
.map(|arg| {
1865-
if let Some((def_id, ibty)) = in_band_ty_params.as_mut() {
1865+
if let Some((def_id, ibty, _)) = in_band_ty_params.as_mut() {
18661866
self.lower_ty(&arg.ty, ImplTraitContext::Universal(*def_id, ibty))
18671867
} else {
18681868
self.lower_ty(&arg.ty, ImplTraitContext::Disallowed)
@@ -1871,8 +1871,12 @@ impl<'a> LoweringContext<'a> {
18711871
.collect(),
18721872
output: match decl.output {
18731873
FunctionRetTy::Ty(ref ty) => match in_band_ty_params {
1874-
Some((def_id, ref mut ibty)) if impl_trait_return_allow => {
1875-
hir::Return(self.lower_ty(ty, ImplTraitContext::Existential(def_id, ibty)))
1874+
Some((def_id, ref mut ibty, generics)) if impl_trait_return_allow => {
1875+
hir::Return(self.lower_ty(ty, ImplTraitContext::Existential(
1876+
def_id,
1877+
ibty,
1878+
generics,
1879+
)))
18761880
}
18771881
_ => hir::Return(self.lower_ty(ty, ImplTraitContext::Disallowed)),
18781882
},
@@ -2321,7 +2325,11 @@ impl<'a> LoweringContext<'a> {
23212325
generics,
23222326
fn_def_id,
23232327
AnonymousLifetimeMode::PassThrough,
2324-
|this, idty| this.lower_fn_decl(decl, Some((fn_def_id, idty)), true),
2328+
|this, idty, generics| this.lower_fn_decl(
2329+
decl,
2330+
Some((fn_def_id, idty, generics)),
2331+
true,
2332+
),
23252333
);
23262334

23272335
hir::ItemFn(
@@ -2393,7 +2401,7 @@ impl<'a> LoweringContext<'a> {
23932401
ast_generics,
23942402
def_id,
23952403
AnonymousLifetimeMode::CreateParameter,
2396-
|this, _| {
2404+
|this, _, _| {
23972405
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
23982406
this.lower_trait_ref(trait_ref, ImplTraitContext::Disallowed)
23992407
});
@@ -2891,7 +2899,7 @@ impl<'a> LoweringContext<'a> {
28912899
generics,
28922900
def_id,
28932901
AnonymousLifetimeMode::PassThrough,
2894-
|this, _| {
2902+
|this, _, _| {
28952903
(
28962904
// Disallow impl Trait in foreign items
28972905
this.lower_fn_decl(fdec, None, false),
@@ -2926,9 +2934,9 @@ impl<'a> LoweringContext<'a> {
29262934
generics,
29272935
fn_def_id,
29282936
AnonymousLifetimeMode::PassThrough,
2929-
|this, idty| this.lower_fn_decl(
2937+
|this, idty, generics| this.lower_fn_decl(
29302938
&sig.decl,
2931-
Some((fn_def_id, idty)),
2939+
Some((fn_def_id, idty, generics)),
29322940
impl_trait_return_allow,
29332941
),
29342942
);

0 commit comments

Comments
 (0)