Skip to content

Commit 48fd666

Browse files
committed
allocate string only when error will be emitted
Signed-off-by: Miguel Guarniz <[email protected]>
1 parent f77658b commit 48fd666

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_passes/src/check_const.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,26 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
9898
.unwrap_or(false);
9999

100100
if !is_implemented {
101-
to_implement.push(tcx.item_name(trait_item_id).to_string());
101+
to_implement.push(trait_item_id);
102102
}
103103
}
104104
}
105105

106106
// all nonconst trait functions (not marked with #[default_method_body_is_const])
107107
// must be implemented
108108
if !to_implement.is_empty() {
109+
let not_implemented = to_implement
110+
.into_iter()
111+
.map(|did| tcx.item_name(did).to_string())
112+
.collect::<Vec<_>>()
113+
.join("`, `");
109114
tcx
110115
.sess
111116
.struct_span_err(
112117
item.span,
113118
"const trait implementations may not use non-const default functions",
114119
)
115-
.note(&format!("`{}` not implemented", to_implement.join("`, `")))
120+
.note(&format!("`{}` not implemented", not_implemented))
116121
.emit();
117122
}
118123
}

0 commit comments

Comments
 (0)