]> git.lizzy.rs Git - rust.git/commitdiff
collector: limit pme context note to user-defd fns
authorDavid Wood <david.wood@huawei.com>
Fri, 1 Oct 2021 16:23:07 +0000 (16:23 +0000)
committerDavid Wood <david.wood@huawei.com>
Fri, 1 Oct 2021 16:34:18 +0000 (16:34 +0000)
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 <david.wood@huawei.com>
compiler/rustc_middle/src/mir/mono.rs
compiler/rustc_monomorphize/src/collector.rs

index 776cf002c170311a3be270f90f7f53d2a3e78208..1c0b274f0631bcdcd4fc435ba5b82d2144a2254b 100644 (file)
@@ -47,6 +47,14 @@ pub enum MonoItem<'tcx> {
 }
 
 impl<'tcx> MonoItem<'tcx> {
+    /// Returns `true` if the mono item is user-defined (i.e. not compiler-generated, like shims).
+    pub fn is_user_defined(&self) -> bool {
+        match *self {
+            MonoItem::Fn(instance) => matches!(instance.def, InstanceDef::Item(..)),
+            MonoItem::Static(..) | MonoItem::GlobalAsm(..) => true,
+        }
+    }
+
     pub fn size_estimate(&self, tcx: TyCtxt<'tcx>) -> usize {
         match *self {
             MonoItem::Fn(instance) => {
index 1e39b1bd5e80e6a3461c4381c5277ddbe7d36fbf..5ccf8997d28ce0ae7a2f1c3ba8f67bcc870481c4 100644 (file)
@@ -450,7 +450,9 @@ fn collect_items_rec<'tcx>(
     // involving a dependency, and the lack of context is confusing) in this MVP, we focus on
     // diagnostics on edges crossing a crate boundary: the collected mono items which are not
     // defined in the local crate.
-    if tcx.sess.diagnostic().err_count() > error_count && starting_point.node.krate() != LOCAL_CRATE
+    if tcx.sess.diagnostic().err_count() > error_count
+        && starting_point.node.krate() != LOCAL_CRATE
+        && starting_point.node.is_user_defined()
     {
         let formatted_item = with_no_trimmed_paths(|| starting_point.node.to_string());
         tcx.sess.span_note_without_error(