about summary refs log tree commit diff
path: root/src/librustc_mir
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2020-07-16 17:52:23 +0100
committerDavid Wood <david@davidtw.co>2020-07-20 19:35:35 +0100
commitb1f8bd635696644f86bdb5ea69fb69ec50bc6d9b (patch)
treef4c081257834b91b3eb89613bf3507adcf22585f /src/librustc_mir
parent5ce29d3d6f8994a1d9db9b9f8aa076001f7b8d07 (diff)
downloadrust-b1f8bd635696644f86bdb5ea69fb69ec50bc6d9b.tar.gz
rust-b1f8bd635696644f86bdb5ea69fb69ec50bc6d9b.zip
mir: use attribute over `-Z polymorphize-errors`
This commit replaces the `-Z polymorphize-errors` debugging flag with a
`#[rustc_polymorphize_error]` attribute for use on functions.

Signed-off-by: David Wood <david@davidtw.co>
Diffstat (limited to 'src/librustc_mir')
-rw-r--r--src/librustc_mir/monomorphize/polymorphize.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_mir/monomorphize/polymorphize.rs b/src/librustc_mir/monomorphize/polymorphize.rs
index b06bf061d1f..2a1f8fb843f 100644
--- a/src/librustc_mir/monomorphize/polymorphize.rs
+++ b/src/librustc_mir/monomorphize/polymorphize.rs
@@ -16,6 +16,7 @@ use rustc_middle::ty::{
     query::Providers,
     Const, Ty, TyCtxt,
 };
+use rustc_span::symbol::sym;
 use std::convert::TryInto;
 
 /// Provide implementations of queries relating to polymorphization analysis.
@@ -77,7 +78,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> u64 {
 
     // Emit errors for debugging and testing if enabled.
     let is_full = unused_parameters == 0;
-    if tcx.sess.opts.debugging_opts.polymorphize_errors && !is_full {
+    if !is_full {
         emit_unused_generic_params_error(tcx, def_id, generics, unused_parameters);
     }
 
@@ -169,8 +170,8 @@ fn mark_used_by_predicates<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, used_paramete
     }
 }
 
-/// Emit an error for the function represented by `def_id`, labelling each generic parameter which
-/// was unused.
+/// Emit errors for the function annotated by `#[rustc_polymorphize_error]`, labelling each generic
+/// parameter which was unused.
 fn emit_unused_generic_params_error<'tcx>(
     tcx: TyCtxt<'tcx>,
     def_id: DefId,
@@ -178,7 +179,8 @@ fn emit_unused_generic_params_error<'tcx>(
     unused_parameters: u64,
 ) {
     debug!("emit_unused_generic_params_error: def_id={:?}", def_id);
-    if !def_id.is_local() {
+    let base_def_id = tcx.closure_base_def_id(def_id);
+    if !tcx.get_attrs(base_def_id).iter().any(|a| a.check_name(sym::rustc_polymorphize_error)) {
         return;
     }