diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-11-09 22:00:13 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2022-11-09 22:01:58 +0100 |
| commit | cedaaa640edfa2854ea213148a7c0f5ee5dd2f74 (patch) | |
| tree | 5458f9c1616aa2b152541873164500e75f6818dc /compiler | |
| parent | cc9b259b5e94e4543b96dca236e3a1af5ec496c9 (diff) | |
| download | rust-cedaaa640edfa2854ea213148a7c0f5ee5dd2f74.tar.gz rust-cedaaa640edfa2854ea213148a7c0f5ee5dd2f74.zip | |
Don't ICE on operator trait methods with generic methods
Emit a fatal error instead.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/mod.rs | 9 |
3 files changed, 19 insertions, 1 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl index 74088f4dfbe..d27edd47470 100644 --- a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl +++ b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl @@ -150,3 +150,6 @@ hir_analysis_const_bound_for_non_const_trait = hir_analysis_self_in_impl_self = `Self` is not valid in the self type of an impl block .note = replace `Self` with a different type + +hir_analysis_op_trait_generic_params = + `{$method_name}` must not have any generic parameters diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index cfb408396da..afac6e7d94a 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -125,3 +125,11 @@ pub struct AddMissingParenthesesInRange { #[suggestion_part(code = ")")] pub right: Span, } + +#[derive(Diagnostic)] +#[diag(hir_analysis_op_trait_generic_params)] +pub struct OpMethodGenericParams { + #[primary_span] + pub span: Span, + pub method_name: String, +} diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 2c7b3bbf31c..4a8b7749365 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -10,6 +10,7 @@ mod suggest; pub use self::suggest::SelfSource; pub use self::MethodError::*; +use crate::errors::OpMethodGenericParams; use crate::{Expectation, FnCtxt}; use rustc_data_structures::sync::Lrc; use rustc_errors::{Applicability, Diagnostic}; @@ -443,7 +444,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let def_id = method_item.def_id; let generics = tcx.generics_of(def_id); - assert_eq!(generics.params.len(), 0); + + if generics.params.len() != 0 { + tcx.sess.emit_fatal(OpMethodGenericParams { + span: tcx.def_span(method_item.def_id), + method_name: m_name.to_string(), + }); + } debug!("lookup_in_trait_adjusted: method_item={:?}", method_item); let mut obligations = vec![]; |
