@@ -105,17 +105,24 @@ use syntax::ast::{m_const, m_mutbl, m_imm};
105105use syntax:: ast;
106106use syntax:: ast_map;
107107
108+ #[ deriving_eq]
109+ pub enum CheckTraitsFlag {
110+ CheckTraitsOnly ,
111+ CheckTraitsAndInherentMethods ,
112+ }
113+
108114pub fn lookup (
109115 fcx : @mut FnCtxt ,
110116
111117 // In a call `a.b::<X, Y, ...>(...)`:
112- expr : @ast:: expr , // The expression `a.b`.
113- self_expr : @ast:: expr , // The expression `a`.
114- callee_id : node_id , // Where to store the type of `a.b`
115- m_name : ast:: ident , // The ident `b`.
116- self_ty : ty:: t , // The type of `a`.
117- supplied_tps : & [ ty:: t ] , // The list of types X, Y, ... .
118- deref_args : check:: DerefArgs ) // Whether we autopointer first.
118+ expr : @ast:: expr , // The expression `a.b`.
119+ self_expr : @ast:: expr , // The expression `a`.
120+ callee_id : node_id , // Where to store the type of `a.b`
121+ m_name : ast:: ident , // The ident `b`.
122+ self_ty : ty:: t , // The type of `a`.
123+ supplied_tps : & [ ty:: t ] , // The list of types X, Y, ... .
124+ deref_args : check:: DerefArgs , // Whether we autopointer first.
125+ check_traits : CheckTraitsFlag ) // Whether we check traits only.
119126 -> Option < method_map_entry >
120127{
121128 let lcx = LookupContext {
@@ -129,6 +136,7 @@ pub fn lookup(
129136 inherent_candidates : @mut ~[ ] ,
130137 extension_candidates : @mut ~[ ] ,
131138 deref_args : deref_args,
139+ check_traits : check_traits,
132140 } ;
133141 let mme = lcx. do_lookup ( self_ty) ;
134142 debug ! ( "method lookup for %s yielded %?" ,
@@ -147,6 +155,7 @@ pub struct LookupContext {
147155 inherent_candidates : @mut ~[ Candidate ] ,
148156 extension_candidates : @mut ~[ Candidate ] ,
149157 deref_args : check:: DerefArgs ,
158+ check_traits : CheckTraitsFlag ,
150159}
151160
152161/**
@@ -299,7 +308,9 @@ pub impl LookupContext/&self {
299308 self_ty, self_did, & substs) ;
300309 }
301310 ty_enum( did, _) | ty_struct( did, _) => {
302- self . push_inherent_impl_candidates_for_type ( did) ;
311+ if self . check_traits == CheckTraitsAndInherentMethods {
312+ self . push_inherent_impl_candidates_for_type ( did) ;
313+ }
303314 }
304315 _ => { /* No inherent methods in these types */ }
305316 }
0 commit comments