Don't ICE on operator trait methods with generic methods
Emit a fatal error instead.
This commit is contained in:
parent
cc9b259b5e
commit
cedaaa640e
5 changed files with 50 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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![];
|
||||
|
|
23
src/test/ui/traits/invalid_operator_trait.rs
Normal file
23
src/test/ui/traits/invalid_operator_trait.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
#![crate_type = "lib"]
|
||||
#![feature(lang_items)]
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
|
||||
#[lang="sized"]
|
||||
pub trait Sized {
|
||||
// Empty.
|
||||
}
|
||||
|
||||
#[lang = "add"]
|
||||
trait Add<RHS=Self> {
|
||||
type Output;
|
||||
|
||||
fn add<Y>(self, _: RHS) -> Self::Output;
|
||||
//~^ ERROR `add` must not have any generic parameters
|
||||
}
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
fn ice(a: usize) {
|
||||
let r = loop {};
|
||||
r = r + a;
|
||||
}
|
8
src/test/ui/traits/invalid_operator_trait.stderr
Normal file
8
src/test/ui/traits/invalid_operator_trait.stderr
Normal file
|
@ -0,0 +1,8 @@
|
|||
error: `add` must not have any generic parameters
|
||||
--> $DIR/invalid_operator_trait.rs:15:5
|
||||
|
|
||||
LL | fn add<Y>(self, _: RHS) -> Self::Output;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Add table
Reference in a new issue