@@ -120,6 +120,46 @@ impl super::Check<'_> {
120120 }
121121 }
122122
123+ /// Check that function `ii_fn` that appears in an impl is valid.
124+ /// This includes the core check from [`Self::check_fn`],
125+ /// but also additional checks to ensure that the signature in the impl
126+ /// matches what is declared in the trait.
127+ ///
128+ /// # Example
129+ ///
130+ /// Suppose we are checking `<Cup<L> as Potable>::drink` in this example...
131+ ///
132+ /// ```rust,ignore
133+ /// trait Potable {
134+ /// fn drink(&self) // `trait_items` includes both fn drink and fn smell
135+ /// where Self: Copy; // <-- ti_where_clauses
136+ /// fn smell(&self);
137+ /// }
138+ ///
139+ /// struct Water;
140+ /// impl Potable for Water {
141+ /// fn drink(&self) {}
142+ /// fn smell(&self) {}
143+ /// }
144+ ///
145+ /// struct Cup<L>;
146+ /// impl<L> Potable for Cup<L> // <-- env has `L` in scope
147+ /// where
148+ /// L: Potable, // <-- `impl_assumptions`
149+ /// {
150+ /// fn drink(&self) {} // <-- `ii_fn`
151+ /// where (Cup<L>,): Copy; // <-- ii_where_clauses, implied by ti_where_clauses, Cup<L>: Copy, ok
152+ /// fn smell(&self) {} // not currently being checked
153+ /// }
154+ /// ```
155+ ///
156+ /// # Parameters
157+ ///
158+ /// * `env`, the environment from the impl header
159+ /// * `impl_assumptions`, where-clauses declared on the impl
160+ /// * `trait_items`, items declared in the trait that is being implemented
161+ /// (we search this to find the corresponding declaration of the method)
162+ /// * `ii_fn`, the fn as declared in the impl
123163 fn check_fn_in_impl (
124164 & self ,
125165 env : & Env ,
@@ -149,12 +189,14 @@ impl super::Check<'_> {
149189
150190 let mut env = env. clone ( ) ;
151191 let (
192+ // ii_: the signature of the function as found in the impl item (ii)
152193 FnBoundData {
153194 input_tys : ii_input_tys,
154195 output_ty : ii_output_ty,
155196 where_clauses : ii_where_clauses,
156197 body : _,
157198 } ,
199+ // ti_: the signature of the function as found in the trait item (ti)
158200 FnBoundData {
159201 input_tys : ti_input_tys,
160202 output_ty : ti_output_ty,
@@ -169,6 +211,7 @@ impl super::Check<'_> {
169211 & ii_where_clauses,
170212 ) ?;
171213
214+ // Must have same number of arguments as declared in the trait
172215 if ii_input_tys. len ( ) != ti_input_tys. len ( ) {
173216 bail ! (
174217 "impl has {} function arguments but trait has {} function arguments" ,
0 commit comments