From 137f20c11265ea70e3ed3ed7798662b9abfbaad2 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Thu, 18 Aug 2022 15:51:47 -0600 Subject: rebased: convert rustc_monomorphize errors to SessionDiagnostic --- compiler/rustc_monomorphize/src/polymorphize.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_monomorphize/src/polymorphize.rs') diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 394843e510d..88f8e24fbd5 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -22,6 +22,8 @@ use rustc_span::symbol::sym; use std::convert::TryInto; use std::ops::ControlFlow; +use crate::errors::UnusedGenericParams; + /// Provide implementations of queries relating to polymorphization analysis. pub fn provide(providers: &mut Providers) { providers.unused_generic_params = unused_generic_params; @@ -206,22 +208,28 @@ fn emit_unused_generic_params_error<'tcx>( _ => tcx.def_span(def_id), }; - let mut err = tcx.sess.struct_span_err(fn_span, "item has unused generic parameters"); - + let mut param_spans = Vec::new(); + let mut param_names = Vec::new(); let mut next_generics = Some(generics); while let Some(generics) = next_generics { for param in &generics.params { if unused_parameters.contains(param.index).unwrap_or(false) { debug!(?param); let def_span = tcx.def_span(param.def_id); - err.span_label(def_span, &format!("generic parameter `{}` is unused", param.name)); + // 🤔 The docs say + // + // Any attribute applied to a Vec will be repeated for each element of the vector. + // + // But they don't say what template variable to use to substitute each value into the message!? + param_spans.push(def_span); + param_names.push(param.name.to_string()); } } next_generics = generics.parent.map(|did| tcx.generics_of(did)); } - err.emit(); + tcx.sess.emit_err(UnusedGenericParams { span: fn_span, param_spans, param_names }); } /// Visitor used to aggregate generic parameter uses. -- cgit 1.4.1-3-g733a5 From a19139f9ff8a303e3a26ff6c441e9c8032f19568 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Fri, 26 Aug 2022 11:45:09 -0600 Subject: remove unnecessary comment --- compiler/rustc_monomorphize/src/polymorphize.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'compiler/rustc_monomorphize/src/polymorphize.rs') diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 88f8e24fbd5..6e4ab2a35c3 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -216,11 +216,6 @@ fn emit_unused_generic_params_error<'tcx>( if unused_parameters.contains(param.index).unwrap_or(false) { debug!(?param); let def_span = tcx.def_span(param.def_id); - // 🤔 The docs say - // - // Any attribute applied to a Vec will be repeated for each element of the vector. - // - // But they don't say what template variable to use to substitute each value into the message!? param_spans.push(def_span); param_names.push(param.name.to_string()); } -- cgit 1.4.1-3-g733a5