Skip to content

Refactor PatternError structure #86460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 0 additions & 10 deletions src/test/ui/issues/issue-27895.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/issues/issue-27895.stderr

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/ui/non-constant-in-const-path.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/non-constant-in-const-path.stderr

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/pattern/issue-68394-let-pat-runtime-value.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/pattern/issue-68394-let-pat-runtime-value.stderr

This file was deleted.

18 changes: 18 additions & 0 deletions src/test/ui/pattern/non-constant-in-const-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Checks if we emit `PatternError`s correctly.
// This is also a regression test for #27895 and #68394.

static FOO: u8 = 10;

fn main() {
let x = 0;
let 0u8..=x = 0;
//~^ ERROR: runtime values cannot be referenced in patterns
let 0u8..=FOO = 0;
//~^ ERROR: statics cannot be referenced in patterns
match 1 {
0 ..= x => {}
//~^ ERROR: runtime values cannot be referenced in patterns
0 ..= FOO => {}
//~^ ERROR: statics cannot be referenced in patterns
};
}
28 changes: 28 additions & 0 deletions src/test/ui/pattern/non-constant-in-const-path.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0080]: runtime values cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:8:15
|
LL | let 0u8..=x = 0;
| ^

error[E0158]: statics cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:10:15
|
LL | let 0u8..=FOO = 0;
| ^^^

error[E0080]: runtime values cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:13:15
|
LL | 0 ..= x => {}
| ^

error[E0158]: statics cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:15:15
|
LL | 0 ..= FOO => {}
| ^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0080, E0158.
For more information about an error, try `rustc --explain E0080`.