@@ -12,7 +12,7 @@ use crate::check::fatally_break_rust;
1212use crate :: check:: report_unexpected_variant_res;
1313use crate :: check:: Needs ;
1414use crate :: check:: TupleArgumentsFlag :: DontTupleArguments ;
15- use crate :: check:: method:: { probe, SelfSource } ;
15+ use crate :: check:: method:: { probe, SelfSource , MethodError } ;
1616use crate :: util:: common:: ErrorReported ;
1717use crate :: util:: nodemap:: FxHashMap ;
1818use crate :: astconv:: AstConv as _;
@@ -29,6 +29,7 @@ use rustc::hir::def::{CtorKind, Res, DefKind};
2929use rustc:: hir:: ptr:: P ;
3030use rustc:: infer;
3131use rustc:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
32+ use rustc:: middle:: lang_items;
3233use rustc:: mir:: interpret:: GlobalId ;
3334use rustc:: ty;
3435use rustc:: ty:: adjustment:: {
@@ -775,51 +776,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775776 // no need to check for bot/err -- callee does that
776777 let rcvr_t = self . structurally_resolved_type ( args[ 0 ] . span , rcvr_t) ;
777778
778- let try_alt_rcvr = |err : & mut DiagnosticBuilder < ' _ > , new_rcvr_t| {
779- if let Ok ( pick) = self . lookup_probe (
780- span,
781- segment. ident ,
782- new_rcvr_t,
783- rcvr,
784- probe:: ProbeScope :: AllTraits ,
785- ) {
786- err. span_label (
787- pick. item . ident . span ,
788- & format ! ( "the method is available for `{}` here" , new_rcvr_t) ,
789- ) ;
790- }
791- } ;
792-
793779 let method = match self . lookup_method ( rcvr_t, segment, span, expr, rcvr) {
794780 Ok ( method) => {
795781 self . write_method_call ( expr. hir_id , method) ;
796782 Ok ( method)
797783 }
798784 Err ( error) => {
799785 if segment. ident . name != kw:: Invalid {
800- if let Some ( mut err) = self . report_method_error (
801- span,
802- rcvr_t,
803- segment. ident ,
804- SelfSource :: MethodCall ( rcvr) ,
805- error,
806- Some ( args) ,
807- ) {
808- if let ty:: Adt ( ..) = rcvr_t. sty {
809- // Try alternative arbitrary self types that could fulfill this call.
810- // FIXME: probe for all types that *could* be arbitrary self-types, not
811- // just this whitelist.
812- let box_rcvr_t = self . tcx . mk_box ( rcvr_t) ;
813- try_alt_rcvr ( & mut err, box_rcvr_t) ;
814- let pin_rcvr_t = self . tcx . mk_pin ( rcvr_t) ;
815- try_alt_rcvr ( & mut err, pin_rcvr_t) ;
816- let arc_rcvr_t = self . tcx . mk_arc ( rcvr_t) ;
817- try_alt_rcvr ( & mut err, arc_rcvr_t) ;
818- let rc_rcvr_t = self . tcx . mk_rc ( rcvr_t) ;
819- try_alt_rcvr ( & mut err, rc_rcvr_t) ;
820- }
821- err. emit ( ) ;
822- }
786+ self . report_extended_method_error ( segment, span, args, rcvr_t, error) ;
823787 }
824788 Err ( ( ) )
825789 }
@@ -836,6 +800,58 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
836800 )
837801 }
838802
803+ fn report_extended_method_error (
804+ & self ,
805+ segment : & hir:: PathSegment ,
806+ span : Span ,
807+ args : & ' tcx [ hir:: Expr ] ,
808+ rcvr_t : Ty < ' tcx > ,
809+ error : MethodError < ' tcx >
810+ ) {
811+ let rcvr = & args[ 0 ] ;
812+ let try_alt_rcvr = |err : & mut DiagnosticBuilder < ' _ > , new_rcvr_t| {
813+ if let Ok ( pick) = self . lookup_probe (
814+ span,
815+ segment. ident ,
816+ new_rcvr_t,
817+ rcvr,
818+ probe:: ProbeScope :: AllTraits ,
819+ ) {
820+ err. span_label (
821+ pick. item . ident . span ,
822+ & format ! ( "the method is available for `{}` here" , new_rcvr_t) ,
823+ ) ;
824+ }
825+ } ;
826+
827+ if let Some ( mut err) = self . report_method_error (
828+ span,
829+ rcvr_t,
830+ segment. ident ,
831+ SelfSource :: MethodCall ( rcvr) ,
832+ error,
833+ Some ( args) ,
834+ ) {
835+ if let ty:: Adt ( ..) = rcvr_t. sty {
836+ // Try alternative arbitrary self types that could fulfill this call.
837+ // FIXME: probe for all types that *could* be arbitrary self-types, not
838+ // just this whitelist.
839+ let box_rcvr_t = self . tcx . mk_box ( rcvr_t) ;
840+ try_alt_rcvr ( & mut err, box_rcvr_t) ;
841+ let pin_rcvr_t = self . tcx . mk_lang_item (
842+ rcvr_t,
843+ lang_items:: PinTypeLangItem ,
844+ ) ;
845+ try_alt_rcvr ( & mut err, pin_rcvr_t) ;
846+ let arc_rcvr_t = self . tcx . mk_lang_item ( rcvr_t, lang_items:: Arc ) ;
847+ try_alt_rcvr ( & mut err, arc_rcvr_t) ;
848+ let rc_rcvr_t = self . tcx . mk_lang_item ( rcvr_t, lang_items:: Rc ) ;
849+ try_alt_rcvr ( & mut err, rc_rcvr_t) ;
850+ }
851+ err. emit ( ) ;
852+ }
853+ }
854+
839855 fn check_expr_cast (
840856 & self ,
841857 e : & ' tcx hir:: Expr ,
0 commit comments