Skip to content

Commit 7e0ed43

Browse files
committed
Auto merge of #123202 - estebank:issue-123009, r=compiler-errors
Do not attempt to write `ty::Err` on binding that isn't from current HIR Owner Fix #123009. Follow up to #122119.
2 parents 50e3d62 + d54e983 commit 7e0ed43

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1916,18 +1916,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19161916
pat: &'tcx hir::Pat<'tcx>,
19171917
ty: Ty<'tcx>,
19181918
) {
1919-
struct V<'tcx> {
1920-
tcx: TyCtxt<'tcx>,
1919+
struct V {
19211920
pat_hir_ids: Vec<hir::HirId>,
19221921
}
19231922

1924-
impl<'tcx> Visitor<'tcx> for V<'tcx> {
1925-
type NestedFilter = rustc_middle::hir::nested_filter::All;
1926-
1927-
fn nested_visit_map(&mut self) -> Self::Map {
1928-
self.tcx.hir()
1929-
}
1930-
1923+
impl<'tcx> Visitor<'tcx> for V {
19311924
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
19321925
self.pat_hir_ids.push(p.hir_id);
19331926
hir::intravisit::walk_pat(self, p);
@@ -1938,7 +1931,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19381931
let err = Ty::new_error(self.tcx, guar);
19391932
self.write_ty(hir_id, err);
19401933
self.write_ty(pat.hir_id, err);
1941-
let mut visitor = V { tcx: self.tcx, pat_hir_ids: vec![] };
1934+
let mut visitor = V { pat_hir_ids: vec![] };
19421935
hir::intravisit::walk_pat(&mut visitor, pat);
19431936
// Mark all the subpatterns as `{type error}` as well. This allows errors for specific
19441937
// subpatterns to be silenced.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
3+
//~^ ERROR expected a pattern, found an expression
4+
//~| ERROR cannot find type `T` in this scope
5+
//~| ERROR type and const arguments are not allowed on builtin type `str`
6+
//~| ERROR expected unit struct, unit variant or constant, found associated function `str<, T>::as_bytes`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: expected a pattern, found an expression
2+
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:31
3+
|
4+
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
5+
| ^^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
6+
7+
error[E0412]: cannot find type `T` in this scope
8+
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:55
9+
|
10+
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
11+
| ^ not found in this scope
12+
13+
error[E0109]: type and const arguments are not allowed on builtin type `str`
14+
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:15
15+
|
16+
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
17+
| --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ type and const arguments not allowed
18+
| |
19+
| not allowed on builtin type `str`
20+
|
21+
help: primitive type `str` doesn't have generic parameters
22+
|
23+
LL - let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
24+
LL + let str::as_bytes;
25+
|
26+
27+
error[E0533]: expected unit struct, unit variant or constant, found associated function `str<, T>::as_bytes`
28+
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:9
29+
|
30+
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant
32+
33+
error: aborting due to 4 previous errors
34+
35+
Some errors have detailed explanations: E0109, E0412, E0533.
36+
For more information about an error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)