Skip to content

Commit 9549350

Browse files
pnkfelixManishearth
authored andcommitted
Refactor signaling of E0223 to avoid multiple span_errs for same code.
1 parent 2651823 commit 9549350

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,17 @@ fn trait_ref_to_object_type<'tcx>(this: &AstConv<'tcx>,
991991
result
992992
}
993993

994+
fn report_ambiguous_associated_type(tcx: &ty::ctxt,
995+
span: Span,
996+
type_str: &str,
997+
trait_str: &str,
998+
name: &str) {
999+
span_err!(tcx.sess, span, E0223,
1000+
"ambiguous associated type; specify the type using the syntax \
1001+
`<{} as {}>::{}`",
1002+
type_str, trait_str, name);
1003+
}
1004+
9941005
fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
9951006
span: Span,
9961007
ty: Ty<'tcx>,
@@ -1011,10 +1022,8 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
10111022
let ty_param_node_id = if is_param {
10121023
ty_path_def.local_node_id()
10131024
} else {
1014-
span_err!(tcx.sess, span, E0223,
1015-
"ambiguous associated type; specify the type using the syntax \
1016-
`<{} as Trait>::{}`",
1017-
ty.user_string(tcx), token::get_name(assoc_name));
1025+
report_ambiguous_associated_type(
1026+
tcx, span, &ty.user_string(tcx), "Trait", &token::get_name(assoc_name));
10181027
return (tcx.types.err, ty_path_def);
10191028
};
10201029

@@ -1109,10 +1118,8 @@ fn qpath_to_ty<'tcx>(this: &AstConv<'tcx>,
11091118
ty
11101119
} else {
11111120
let path_str = ty::item_path_str(tcx, trait_def_id);
1112-
span_err!(tcx.sess, span, E0223,
1113-
"ambiguous associated type; specify the type using the syntax \
1114-
`<Type as {}>::{}`",
1115-
path_str, &token::get_ident(item_segment.identifier));
1121+
report_ambiguous_associated_type(
1122+
tcx, span, "Type", &path_str, &token::get_ident(item_segment.identifier));
11161123
return tcx.types.err;
11171124
};
11181125

0 commit comments

Comments
 (0)