Skip to content

Commit

Permalink
Implement "method matching". Similar to trait matching, but with the …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
nikomatsakis committed Oct 21, 2014
1 parent 04386f4 commit e6a1936
Show file tree
Hide file tree
Showing 3 changed files with 422 additions and 50 deletions.
7 changes: 7 additions & 0 deletions src/librustc/middle/traits/doc.rs
Expand Up @@ -272,4 +272,11 @@ nested obligation `int : Bar<U>` to find out that `U=uint`.
It would be good to only do *just as much* nested resolution as
necessary. Currently, though, we just do a full resolution.
## Method matching
Method dispach follows a slightly different path than normal trait
selection. This is because it must account for the transformed self
type of the receiver and various other complications. The procedure is
described in `select.rs` in the "METHOD MATCHING" section.
*/
18 changes: 2 additions & 16 deletions src/librustc/middle/traits/mod.rs
Expand Up @@ -24,6 +24,8 @@ use syntax::codemap::{Span, DUMMY_SP};
pub use self::fulfill::FulfillmentContext;
pub use self::select::SelectionContext;
pub use self::select::SelectionCache;
pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
pub use self::select::{MethodMatchedData}; // intentionally don't export variants
pub use self::util::supertraits;
pub use self::util::transitive_bounds;
pub use self::util::Supertraits;
Expand Down Expand Up @@ -219,22 +221,6 @@ pub struct VtableParamData {
pub bound: Rc<ty::TraitRef>,
}

pub fn evaluate_obligation<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
param_env: &ty::ParameterEnvironment,
obligation: &Obligation,
typer: &Typer<'tcx>)
-> bool
{
/*!
* Attempts to resolve the obligation given. Returns `None` if
* we are unable to resolve, either because of ambiguity or
* due to insufficient inference.
*/

let mut selcx = select::SelectionContext::new(infcx, param_env, typer);
selcx.evaluate_obligation(obligation)
}

pub fn select_inherent_impl<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
param_env: &ty::ParameterEnvironment,
typer: &Typer<'tcx>,
Expand Down

0 comments on commit e6a1936

Please sign in to comment.