diff --git a/compiler/rustc_error_messages/locales/en-US/typeck.ftl b/compiler/rustc_error_messages/locales/en-US/typeck.ftl index a6b2b1dbd6a5..4122464a4a2f 100644 --- a/compiler/rustc_error_messages/locales/en-US/typeck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/typeck.ftl @@ -122,3 +122,8 @@ typeck-missing-type-params = *[other] references } to {$parameters} .note = because of the default `Self` reference, type parameters must be specified on object types + +typeck-manual-implementation = + manual implementations of `{$trait_name}` are experimental + .label = manual implementations of `{$trait_name}` are experimental + .help = add `#![feature(unboxed_closures)]` to the crate attributes to enable diff --git a/compiler/rustc_typeck/src/astconv/errors.rs b/compiler/rustc_typeck/src/astconv/errors.rs index 5cfed81017f0..8fe89c66389c 100644 --- a/compiler/rustc_typeck/src/astconv/errors.rs +++ b/compiler/rustc_typeck/src/astconv/errors.rs @@ -1,5 +1,5 @@ use crate::astconv::AstConv; -use crate::errors::MissingTypeParams; +use crate::errors::{ManualImplementation, MissingTypeParams}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{pluralize, struct_span_err, Applicability, ErrorGuaranteed}; use rustc_hir as hir; @@ -121,19 +121,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if is_impl { let trait_name = self.tcx().def_path_str(trait_def_id); - struct_span_err!( - self.tcx().sess, - span, - E0183, - "manual implementations of `{}` are experimental", - trait_name, - ) - .span_label( - span, - format!("manual implementations of `{}` are experimental", trait_name), - ) - .help("add `#![feature(unboxed_closures)]` to the crate attributes to enable") - .emit(); + self.tcx().sess.emit_err(ManualImplementation { span, trait_name }); } } diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 93900ae24bba..1cb112e68ce7 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -313,3 +313,13 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams { err } } + +#[derive(SessionDiagnostic)] +#[error(code = "E0183", slug = "typeck-manual-implementation")] +#[help] +pub struct ManualImplementation { + #[primary_span] + #[label] + pub span: Span, + pub trait_name: String, +}