@@ -555,7 +555,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
555
555
}
556
556
} )
557
557
. collect :: < Vec < _ > > ( ) ;
558
- let crate_def_id = CRATE_DEF_ID . to_def_id ( ) ;
559
558
// Try to filter out intrinsics candidates, as long as we have
560
559
// some other candidates to suggest.
561
560
let intrinsic_candidates: Vec < _ > = candidates
@@ -566,8 +565,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
566
565
. collect ( ) ;
567
566
if candidates. is_empty ( ) {
568
567
// Put them back if we have no more candidates to suggest...
569
- candidates. extend ( intrinsic_candidates) ;
568
+ candidates = intrinsic_candidates;
570
569
}
570
+ let crate_def_id = CRATE_DEF_ID . to_def_id ( ) ;
571
571
if candidates. is_empty ( ) && is_expected ( Res :: Def ( DefKind :: Enum , crate_def_id) ) {
572
572
let mut enum_candidates: Vec < _ > = self
573
573
. r
@@ -1180,37 +1180,34 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1180
1180
/// return the span of whole call and the span for all arguments expect the first one (`self`).
1181
1181
fn call_has_self_arg ( & self , source : PathSource < ' _ > ) -> Option < ( Span , Option < Span > ) > {
1182
1182
let mut has_self_arg = None ;
1183
- if let PathSource :: Expr ( Some ( parent) ) = source {
1184
- match & parent. kind {
1185
- ExprKind :: Call ( _, args) if !args. is_empty ( ) => {
1186
- let mut expr_kind = & args[ 0 ] . kind ;
1187
- loop {
1188
- match expr_kind {
1189
- ExprKind :: Path ( _, arg_name) if arg_name. segments . len ( ) == 1 => {
1190
- if arg_name. segments [ 0 ] . ident . name == kw:: SelfLower {
1191
- let call_span = parent. span ;
1192
- let tail_args_span = if args. len ( ) > 1 {
1193
- Some ( Span :: new (
1194
- args[ 1 ] . span . lo ( ) ,
1195
- args. last ( ) . unwrap ( ) . span . hi ( ) ,
1196
- call_span. ctxt ( ) ,
1197
- None ,
1198
- ) )
1199
- } else {
1200
- None
1201
- } ;
1202
- has_self_arg = Some ( ( call_span, tail_args_span) ) ;
1203
- }
1204
- break ;
1183
+ if let PathSource :: Expr ( Some ( parent) ) = source
1184
+ && let ExprKind :: Call ( _, args) = & parent. kind
1185
+ && !args. is_empty ( ) {
1186
+ let mut expr_kind = & args[ 0 ] . kind ;
1187
+ loop {
1188
+ match expr_kind {
1189
+ ExprKind :: Path ( _, arg_name) if arg_name. segments . len ( ) == 1 => {
1190
+ if arg_name. segments [ 0 ] . ident . name == kw:: SelfLower {
1191
+ let call_span = parent. span ;
1192
+ let tail_args_span = if args. len ( ) > 1 {
1193
+ Some ( Span :: new (
1194
+ args[ 1 ] . span . lo ( ) ,
1195
+ args. last ( ) . unwrap ( ) . span . hi ( ) ,
1196
+ call_span. ctxt ( ) ,
1197
+ None ,
1198
+ ) )
1199
+ } else {
1200
+ None
1201
+ } ;
1202
+ has_self_arg = Some ( ( call_span, tail_args_span) ) ;
1205
1203
}
1206
- ExprKind :: AddrOf ( _, _, expr) => expr_kind = & expr. kind ,
1207
- _ => break ,
1204
+ break ;
1208
1205
}
1206
+ ExprKind :: AddrOf ( _, _, expr) => expr_kind = & expr. kind ,
1207
+ _ => break ,
1209
1208
}
1210
1209
}
1211
- _ => ( ) ,
1212
- }
1213
- } ;
1210
+ }
1214
1211
has_self_arg
1215
1212
}
1216
1213
@@ -1220,15 +1217,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1220
1217
// where a brace being opened means a block is being started. Look
1221
1218
// ahead for the next text to see if `span` is followed by a `{`.
1222
1219
let sm = self . r . tcx . sess . source_map ( ) ;
1223
- let sp = sm. span_look_ahead ( span, None , Some ( 50 ) ) ;
1224
- let followed_by_brace = matches ! ( sm . span_to_snippet ( sp ) , Ok ( ref snippet ) if snippet == "{" ) ;
1225
- // In case this could be a struct literal that needs to be surrounded
1226
- // by parentheses, find the appropriate span.
1227
- let closing_span = sm . span_look_ahead ( span , Some ( "}" ) , Some ( 50 ) ) ;
1228
- let closing_brace : Option < Span > = sm
1229
- . span_to_snippet ( closing_span )
1230
- . map_or ( None , |s| if s == "}" { Some ( span . to ( closing_span ) ) } else { None } ) ;
1231
- ( followed_by_brace , closing_brace )
1220
+ if let Some ( followed_brace_span ) = sm. span_look_ahead ( span, "{" , Some ( 50 ) ) {
1221
+ // In case this could be a struct literal that needs to be surrounded
1222
+ // by parentheses, find the appropriate span.
1223
+ let close_brace_span = sm . span_look_ahead ( followed_brace_span , "}" , Some ( 50 ) ) ;
1224
+ let closing_brace = close_brace_span . map ( |sp| span . to ( sp ) ) ;
1225
+ ( true , closing_brace )
1226
+ } else {
1227
+ ( false , None )
1228
+ }
1232
1229
}
1233
1230
1234
1231
/// Provides context-dependent help for errors reported by the `smart_resolve_path_fragment`
0 commit comments