Skip to content

Commit 4528b8e

Browse files
committed
collector: limit pme context note to user-defd fns
rustc adds notes to errors which happen post-monomorphization to provide the user with helpful context (as these errors may rely on the specific instantiations). To prevent this note being added where it is not appropriate, the node is checked to originate outwith the current crate. However, when polymorphization is enabled, this can result in some errors (produced by `optimized_mir`) to occur earlier in compilation than they normally would, during the collection of shims. Some shims have ids that originate in the standard library, but these should not receive the PME note, so instances for compiler-generated functions no longer receive this note. Signed-off-by: David Wood <[email protected]>
1 parent da2b69b commit 4528b8e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/rustc_middle/src/mir/mono.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ pub enum MonoItem<'tcx> {
4747
}
4848

4949
impl<'tcx> MonoItem<'tcx> {
50+
/// Returns `true` if the mono item is user-defined (i.e. not compiler-generated, like shims).
51+
pub fn is_user_defined(&self) -> bool {
52+
match *self {
53+
MonoItem::Fn(instance) => matches!(instance.def, InstanceDef::Item(..)),
54+
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => true,
55+
}
56+
}
57+
5058
pub fn size_estimate(&self, tcx: TyCtxt<'tcx>) -> usize {
5159
match *self {
5260
MonoItem::Fn(instance) => {

compiler/rustc_monomorphize/src/collector.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ fn collect_items_rec<'tcx>(
450450
// involving a dependency, and the lack of context is confusing) in this MVP, we focus on
451451
// diagnostics on edges crossing a crate boundary: the collected mono items which are not
452452
// defined in the local crate.
453-
if tcx.sess.diagnostic().err_count() > error_count && starting_point.node.krate() != LOCAL_CRATE
453+
if tcx.sess.diagnostic().err_count() > error_count
454+
&& starting_point.node.krate() != LOCAL_CRATE
455+
&& starting_point.node.is_user_defined()
454456
{
455457
let formatted_item = with_no_trimmed_paths(|| starting_point.node.to_string());
456458
tcx.sess.span_note_without_error(

0 commit comments

Comments
 (0)