Skip to content

Commit a7408c4

Browse files
authored
Rollup merge of rust-lang#135833 - lqd:add-ice-test, r=compiler-errors
Add fixme and test for issue rust-lang#135289 This PR: - adds a test minimizing issue rust-lang#135289 for PR rust-lang#135310 - adds a fixme about the suboptimal fix for the ICE I've verified the test indeed ICEs with 3f2f695 reverted. r? `@estebank`
2 parents 60cb6c4 + 9bad0da commit a7408c4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,12 @@ fn find_fallback_pattern_typo<'tcx>(
10861086
let vis = cx.tcx.visibility(item.owner_id);
10871087
if vis.is_accessible_from(parent, cx.tcx) {
10881088
accessible.push(item_name);
1089+
// FIXME: the line below from PR #135310 is a workaround for the ICE in issue
1090+
// #135289, where a macro in a dependency can create unreachable patterns in the
1091+
// current crate. Path trimming expects diagnostics for a typoed const, but no
1092+
// diagnostics are emitted and we ICE. See
1093+
// `tests/ui/resolve/const-with-typo-in-pattern-binding-ice-135289.rs` for a
1094+
// test that reproduces the ICE if we don't use `with_no_trimmed_paths!`.
10891095
let path = with_no_trimmed_paths!(cx.tcx.def_path_str(item.owner_id));
10901096
accessible_path.push(path);
10911097
} else if name == item_name {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Helper for test tests/ui/resolve/const-with-typo-in-pattern-binding-ice-135289.rs
2+
3+
//@ edition: 2018
4+
5+
#[macro_export]
6+
macro_rules! assert_matches {
7+
( $e:expr , $($pat:pat)|+ ) => {
8+
match $e {
9+
$($pat)|+ => (),
10+
_ => (),
11+
}
12+
};
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This is a non-regression test for issue 135289, where the "const with typo in pattern" diagnostic
2+
// caused an ICE when unexpectedly pretty printing a type for unreachable arms via a macro defined
3+
// in a dependency.
4+
5+
#![warn(unreachable_patterns)] // needed to reproduce the ICE described in #135289
6+
7+
//@ check-pass
8+
//@ aux-build: fake_matches.rs
9+
extern crate fake_matches;
10+
11+
const _A: u64 = 0;
12+
pub fn f() -> u64 {
13+
0
14+
}
15+
fn main() {
16+
fake_matches::assert_matches!(f(), _non_existent);
17+
}

0 commit comments

Comments
 (0)