Skip to content

Commit 5eb7b26

Browse files
authored
Merge pull request #489 from jackh726/fn_def_binder
Add binders around inputs/outputs for FnDefDatum
2 parents 8679dfe + 6de10c1 commit 5eb7b26

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

chalk-integration/src/lowering.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,15 @@ impl LowerFnDefn for FnDefn {
10301030
let where_clauses = self.lower_where_clauses(env)?;
10311031
let return_type = self.return_type.lower(env)?;
10321032

1033+
let inputs_and_output = env.in_binders(vec![], |_| {
1034+
Ok(rust_ir::FnDefInputsAndOutputDatum {
1035+
argument_types: args?,
1036+
return_type,
1037+
})
1038+
})?;
10331039
Ok(rust_ir::FnDefDatumBound {
1034-
argument_types: args?,
1040+
inputs_and_output,
10351041
where_clauses,
1036-
return_type,
10371042
})
10381043
})?;
10391044

chalk-solve/src/rust_ir.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ pub struct FnDefDatum<I: Interner> {
121121
pub binders: Binders<FnDefDatumBound<I>>,
122122
}
123123

124+
/// Represents the inputs and outputs on a `FnDefDatum`. This is split
125+
/// from the where clauses, since these can contain bound lifetimes.
124126
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
125-
/// Represents the bounds on a `FnDefDatum`, including
126-
/// the function definition's type signature and where clauses.
127-
pub struct FnDefDatumBound<I: Interner> {
127+
pub struct FnDefInputsAndOutputDatum<I: Interner> {
128128
/// Types of the function's arguments
129129
/// ```ignore
130130
/// fn foo<T>(bar: i32, baz: T);
@@ -138,6 +138,26 @@ pub struct FnDefDatumBound<I: Interner> {
138138
/// ^^^
139139
/// ```
140140
pub return_type: Ty<I>,
141+
}
142+
143+
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
144+
/// Represents the bounds on a `FnDefDatum`, including
145+
/// the function definition's type signature and where clauses.
146+
pub struct FnDefDatumBound<I: Interner> {
147+
/// Inputs and outputs defined on a function
148+
/// These are needed for late-bound regions in rustc. For example the
149+
/// lifetime `'a` in
150+
/// ```ignore
151+
/// fn foo<'a, T>(&'a T);
152+
/// ^^
153+
/// ```
154+
/// Rustc doesn't pass in late-bound the regions in substs, but the inputs
155+
/// and outputs may use them. `where_clauses` don't need an extra set of
156+
/// `Binders`, since any lifetimes found in where clauses are not late-bound.
157+
///
158+
/// For more information, see [this rustc-dev-guide chapter](https://rustc-dev-guide.rust-lang.org/early-late-bound.html).
159+
pub inputs_and_output: Binders<FnDefInputsAndOutputDatum<I>>,
160+
141161
/// Where clauses defined on the function
142162
/// ```ignore
143163
/// fn foo<T>() where T: Eq;

0 commit comments

Comments
 (0)