Skip to content

Commit e6a1936

Browse files
committed
Implement "method matching". Similar to trait matching, but with the twist that we
have to take the transformed self type into account, and allow for coercion between the receiver and the actual type declared on the impl.
1 parent 04386f4 commit e6a1936

File tree

3 files changed

+422
-50
lines changed

3 files changed

+422
-50
lines changed

src/librustc/middle/traits/doc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,11 @@ nested obligation `int : Bar<U>` to find out that `U=uint`.
272272
It would be good to only do *just as much* nested resolution as
273273
necessary. Currently, though, we just do a full resolution.
274274
275+
## Method matching
276+
277+
Method dispach follows a slightly different path than normal trait
278+
selection. This is because it must account for the transformed self
279+
type of the receiver and various other complications. The procedure is
280+
described in `select.rs` in the "METHOD MATCHING" section.
281+
275282
*/

src/librustc/middle/traits/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use syntax::codemap::{Span, DUMMY_SP};
2424
pub use self::fulfill::FulfillmentContext;
2525
pub use self::select::SelectionContext;
2626
pub use self::select::SelectionCache;
27+
pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
28+
pub use self::select::{MethodMatchedData}; // intentionally don't export variants
2729
pub use self::util::supertraits;
2830
pub use self::util::transitive_bounds;
2931
pub use self::util::Supertraits;
@@ -219,22 +221,6 @@ pub struct VtableParamData {
219221
pub bound: Rc<ty::TraitRef>,
220222
}
221223

222-
pub fn evaluate_obligation<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
223-
param_env: &ty::ParameterEnvironment,
224-
obligation: &Obligation,
225-
typer: &Typer<'tcx>)
226-
-> bool
227-
{
228-
/*!
229-
* Attempts to resolve the obligation given. Returns `None` if
230-
* we are unable to resolve, either because of ambiguity or
231-
* due to insufficient inference.
232-
*/
233-
234-
let mut selcx = select::SelectionContext::new(infcx, param_env, typer);
235-
selcx.evaluate_obligation(obligation)
236-
}
237-
238224
pub fn select_inherent_impl<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
239225
param_env: &ty::ParameterEnvironment,
240226
typer: &Typer<'tcx>,

0 commit comments

Comments
 (0)