@@ -120,6 +120,44 @@ 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 these fns
135+ /// fn smell(&self); //
136+ /// }
137+ ///
138+ /// struct Water;
139+ /// impl Potable for Water {
140+ /// fn drink(&self) {}
141+ /// fn smell(&self) {}
142+ /// }
143+ ///
144+ /// struct Cup<L>;
145+ /// impl<L> Potable for Cup<L> // <-- env has `L` in scope
146+ /// where
147+ /// L: Potable, // <-- `impl_assumptions`
148+ /// {
149+ /// fn drink(&self) {} // <-- `ii_fn`
150+ /// fn smell(&self) {} // not currently being checked
151+ /// }
152+ /// ```
153+ ///
154+ /// # Parameters
155+ ///
156+ /// * `env`, the environment from the impl header
157+ /// * `impl_assumptions`, where-clauses declared on the impl
158+ /// * `trait_items`, items declared in the trait that is being implemented
159+ /// (we search this to find the corresponding declaration of the method)
160+ /// * `ii_fn`, the fn as declared in the impl
123161 fn check_fn_in_impl (
124162 & self ,
125163 env : & Env ,
@@ -149,12 +187,14 @@ impl super::Check<'_> {
149187
150188 let mut env = env. clone ( ) ;
151189 let (
190+ // ii_: the signature of the function as found in the impl item (ii)
152191 FnBoundData {
153192 input_tys : ii_input_tys,
154193 output_ty : ii_output_ty,
155194 where_clauses : ii_where_clauses,
156195 body : _,
157196 } ,
197+ // ti_: the signature of the function as found in the trait item (ti)
158198 FnBoundData {
159199 input_tys : ti_input_tys,
160200 output_ty : ti_output_ty,
@@ -169,6 +209,7 @@ impl super::Check<'_> {
169209 & ii_where_clauses,
170210 ) ?;
171211
212+ // Must have same number of arguments as declared in the trait
172213 if ii_input_tys. len ( ) != ti_input_tys. len ( ) {
173214 bail ! (
174215 "impl has {} function arguments but trait has {} function arguments" ,
0 commit comments