1
Fork 0

Auto merge of #86460 - JohnTitor:use-static-in-pattern-err, r=oli-obk

Refactor `PatternError` structure

Now we emit the `StaticInPattern` error precisely.
Fixes #68395
r? `@oli-obk`
This commit is contained in:
bors 2021-06-19 19:46:02 +00:00
commit 150fad30ea
9 changed files with 51 additions and 54 deletions

View file

@ -423,6 +423,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
_ => {
let pattern_error = match res {
Res::Def(DefKind::ConstParam, _) => PatternError::ConstParamInPattern(span),
Res::Def(DefKind::Static, _) => PatternError::StaticInPattern(span),
_ => PatternError::NonConstPath(span),
};
self.errors.push(pattern_error);
@ -468,11 +469,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
let instance = match ty::Instance::resolve(self.tcx, param_env_reveal_all, def_id, substs) {
Ok(Some(i)) => i,
Ok(None) => {
self.errors.push(if is_associated_const {
PatternError::AssocConstInPattern(span)
} else {
PatternError::StaticInPattern(span)
});
// It should be assoc consts if there's no error but we cannot resolve it.
debug_assert!(is_associated_const);
self.errors.push(PatternError::AssocConstInPattern(span));
return pat_from_kind(PatKind::Wild);
}