Rollup merge of #47876 - GuillaumeGomez:associated-const-error, r=nikomatsakis
Update associated constants error message Fixes #47570.
This commit is contained in:
commit
38587a7bd9
@ -127,13 +127,16 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
fn report_inlining_errors(&self, pat_span: Span) {
|
||||
for error in &self.errors {
|
||||
match *error {
|
||||
PatternError::StaticInPattern(span) => {
|
||||
span_err!(self.tcx.sess, span, E0158,
|
||||
"statics cannot be referenced in patterns");
|
||||
self.span_e0158(span, "statics cannot be referenced in patterns")
|
||||
}
|
||||
PatternError::AssociatedConstInPattern(span) => {
|
||||
self.span_e0158(span, "associated consts cannot be referenced in patterns")
|
||||
}
|
||||
PatternError::ConstEval(ref err) => {
|
||||
err.report(self.tcx, pat_span, "pattern");
|
||||
@ -141,6 +144,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn span_e0158(&self, span: Span, text: &str) {
|
||||
span_err!(self.tcx.sess, span, E0158, "{}", text)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
|
||||
|
@ -27,6 +27,7 @@ use syntax_pos::Span;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum PatternError<'tcx> {
|
||||
AssociatedConstInPattern(Span),
|
||||
StaticInPattern(Span),
|
||||
ConstEval(ConstEvalErr<'tcx>),
|
||||
}
|
||||
@ -635,6 +636,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
-> Pattern<'tcx> {
|
||||
let ty = self.tables.node_id_to_type(id);
|
||||
let def = self.tables.qpath_def(qpath, id);
|
||||
let is_associated_const = match def {
|
||||
Def::AssociatedConst(_) => true,
|
||||
_ => false,
|
||||
};
|
||||
let kind = match def {
|
||||
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
|
||||
let substs = self.tables.node_substs(id);
|
||||
@ -656,7 +661,11 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
return pat;
|
||||
}
|
||||
None => {
|
||||
self.errors.push(PatternError::StaticInPattern(span));
|
||||
self.errors.push(if is_associated_const {
|
||||
PatternError::AssociatedConstInPattern(span)
|
||||
} else {
|
||||
PatternError::StaticInPattern(span)
|
||||
});
|
||||
PatternKind::Wild
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ pub trait Foo {
|
||||
}
|
||||
|
||||
struct Abc;
|
||||
|
||||
impl Foo for Abc {
|
||||
const X: EFoo = EFoo::B;
|
||||
}
|
||||
@ -27,8 +28,10 @@ impl Foo for Def {
|
||||
|
||||
pub fn test<A: Foo, B: Foo>(arg: EFoo) {
|
||||
match arg {
|
||||
A::X => println!("A::X"), //~ error: statics cannot be referenced in patterns [E0158]
|
||||
B::X => println!("B::X"), //~ error: statics cannot be referenced in patterns [E0158]
|
||||
A::X => println!("A::X"),
|
||||
//~^ error: associated consts cannot be referenced in patterns [E0158]
|
||||
B::X => println!("B::X"),
|
||||
//~^ error: associated consts cannot be referenced in patterns [E0158]
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user