From a0f277b39dc1eae29d1734b67240a90eb64dbece Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 21 Jul 2019 13:51:27 +0800 Subject: HIR Typecheck - Short-circuit when method name is found on a trait object --- src/hir_typeck/expr_cs.cpp | 1 + src/hir_typeck/helpers.cpp | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index ecaae208..eb0ccbdb 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2867,6 +2867,7 @@ namespace { if( possible_methods.size() != 1 && possible_methods.front().second.m_data.is_UfcsKnown() ) { DEBUG("- Multiple options, deferring"); + // TODO: If the type is fully known, then this is an error. return; } auto& ad_borrow = possible_methods.front().first; diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 663818e2..c2e95fd6 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -4021,6 +4021,12 @@ bool TraitResolution::find_method(const Span& sp, rv = true; } } + + // If the method was found on the trait object, prefer that over all others. + if( !possibilities.empty() ) + { + return rv; + } } // 3. Mutually exclusive searches -- cgit v1.2.3