Skip to content

Commit 6fc50da

Browse files
authored
Rollup merge of #112197 - compiler-errors:next-solver-erase, r=lcnr
Erase regions even if normalization fails in writeback (in new solver) Or else we ICE during writeback on some programs that error
2 parents 6330daa + 7ff79cf commit 6fc50da

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

compiler/rustc_hir_typeck/src/writeback.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
136136

137137
fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) {
138138
debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
139-
assert!(!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions());
139+
assert!(
140+
!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
141+
"{ty} can't be put into typeck results"
142+
);
140143
self.typeck_results.node_types_mut().insert(hir_id, ty);
141144
}
142145

@@ -803,7 +806,11 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
803806
// We must normalize erasing regions here, since later lints
804807
// expect that types that show up in the typeck are fully
805808
// normalized.
806-
self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t).unwrap_or(t)
809+
if let Ok(t) = self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t) {
810+
t
811+
} else {
812+
EraseEarlyRegions { tcx: self.fcx.tcx }.fold_ty(t)
813+
}
807814
}
808815
Ok(t) => {
809816
// Do not anonymize late-bound regions

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
1010

1111
const ENTRY_LIMIT: usize = 900;
1212
// FIXME: The following limits should be reduced eventually.
13-
const ISSUES_ENTRY_LIMIT: usize = 1898;
13+
const ISSUES_ENTRY_LIMIT: usize = 1896;
1414
const ROOT_ENTRY_LIMIT: usize = 870;
1515

1616
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[

tests/ui/issues/issue-20605.stderr renamed to tests/ui/for/issue-20605.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the size for values of type `dyn Iterator<Item = &'a mut u8>` cannot be known at compilation time
2-
--> $DIR/issue-20605.rs:2:17
2+
--> $DIR/issue-20605.rs:5:17
33
|
44
LL | for item in *things { *item = 0 }
55
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`

tests/ui/for/issue-20605.next.stderr

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0277]: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
2+
--> $DIR/issue-20605.rs:5:17
3+
|
4+
LL | for item in *things { *item = 0 }
5+
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
6+
7+
error[E0277]: the size for values of type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` cannot be known at compilation time
8+
--> $DIR/issue-20605.rs:5:17
9+
|
10+
LL | for item in *things { *item = 0 }
11+
| ^^^^^^^ doesn't have a size known at compile-time
12+
|
13+
= help: the trait `Sized` is not implemented for `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter`
14+
= note: all local variables must have a statically known size
15+
= help: unsized locals are gated as an unstable feature
16+
17+
error: the type `<_ as IntoIterator>::IntoIter` is not well-formed
18+
--> $DIR/issue-20605.rs:5:17
19+
|
20+
LL | for item in *things { *item = 0 }
21+
| ^^^^^^^
22+
23+
error: aborting due to 3 previous errors
24+
25+
For more information about this error, try `rustc --explain E0277`.

tests/ui/for/issue-20605.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
4+
fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
5+
for item in *things { *item = 0 }
6+
//~^ ERROR the size for values of type
7+
//[next]~^^ ERROR the type `<_ as IntoIterator>::IntoIter` is not well-formed
8+
//[next]~| ERROR the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
9+
}
10+
11+
fn main() {}

tests/ui/issues/issue-20605.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)