From c92342d58ddb8b653deaeda8eb7d775017291f9d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 2 Jun 2023 03:21:26 +0000 Subject: [PATCH 1/2] Erase regions even if normalization fails in writeback --- compiler/rustc_hir_typeck/src/writeback.rs | 11 ++++++-- ...0605.stderr => issue-20605.current.stderr} | 2 +- tests/ui/issues/issue-20605.next.stderr | 25 +++++++++++++++++++ tests/ui/issues/issue-20605.rs | 5 ++++ 4 files changed, 40 insertions(+), 3 deletions(-) rename tests/ui/issues/{issue-20605.stderr => issue-20605.current.stderr} (95%) create mode 100644 tests/ui/issues/issue-20605.next.stderr diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index a395858262f04..29abe921bbdcd 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -136,7 +136,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) { debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty); - assert!(!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions()); + assert!( + !ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(), + "{ty} can't be put into typeck results" + ); self.typeck_results.node_types_mut().insert(hir_id, ty); } @@ -803,7 +806,11 @@ impl<'cx, 'tcx> TypeFolder> for Resolver<'cx, 'tcx> { // We must normalize erasing regions here, since later lints // expect that types that show up in the typeck are fully // normalized. - self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t).unwrap_or(t) + if let Ok(t) = self.fcx.tcx.try_normalize_erasing_regions(self.fcx.param_env, t) { + t + } else { + EraseEarlyRegions { tcx: self.fcx.tcx }.fold_ty(t) + } } Ok(t) => { // Do not anonymize late-bound regions diff --git a/tests/ui/issues/issue-20605.stderr b/tests/ui/issues/issue-20605.current.stderr similarity index 95% rename from tests/ui/issues/issue-20605.stderr rename to tests/ui/issues/issue-20605.current.stderr index e1858b6398932..b9a53cbd4fcb2 100644 --- a/tests/ui/issues/issue-20605.stderr +++ b/tests/ui/issues/issue-20605.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `dyn Iterator` cannot be known at compilation time - --> $DIR/issue-20605.rs:2:17 + --> $DIR/issue-20605.rs:5:17 | LL | for item in *things { *item = 0 } | ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator` diff --git a/tests/ui/issues/issue-20605.next.stderr b/tests/ui/issues/issue-20605.next.stderr new file mode 100644 index 0000000000000..5362a68c834a3 --- /dev/null +++ b/tests/ui/issues/issue-20605.next.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `dyn Iterator: IntoIterator` is not satisfied + --> $DIR/issue-20605.rs:5:17 + | +LL | for item in *things { *item = 0 } + | ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator` + +error[E0277]: the size for values of type ` as IntoIterator>::IntoIter` cannot be known at compilation time + --> $DIR/issue-20605.rs:5:17 + | +LL | for item in *things { *item = 0 } + | ^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for ` as IntoIterator>::IntoIter` + = note: all local variables must have a statically known size + = help: unsized locals are gated as an unstable feature + +error: the type `<_ as IntoIterator>::IntoIter` is not well-formed + --> $DIR/issue-20605.rs:5:17 + | +LL | for item in *things { *item = 0 } + | ^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/issues/issue-20605.rs b/tests/ui/issues/issue-20605.rs index 17b7d32ebf59b..66bdc52e6b1a2 100644 --- a/tests/ui/issues/issue-20605.rs +++ b/tests/ui/issues/issue-20605.rs @@ -1,6 +1,11 @@ +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + fn changer<'a>(mut things: Box>) { for item in *things { *item = 0 } //~^ ERROR the size for values of type +//[next]~^^ ERROR the type `<_ as IntoIterator>::IntoIter` is not well-formed +//[next]~| ERROR the trait bound `dyn Iterator: IntoIterator` is not satisfied } fn main() {} From 7ff79cf4aa45cf79365606fd652b821e366d3c86 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 2 Jun 2023 03:26:14 +0000 Subject: [PATCH 2/2] Move test --- src/tools/tidy/src/ui_tests.rs | 2 +- tests/ui/{issues => for}/issue-20605.current.stderr | 0 tests/ui/{issues => for}/issue-20605.next.stderr | 0 tests/ui/for/issue-20605.rs | 11 +++++++++++ tests/ui/issues/issue-20605.rs | 11 ----------- 5 files changed, 12 insertions(+), 12 deletions(-) rename tests/ui/{issues => for}/issue-20605.current.stderr (100%) rename tests/ui/{issues => for}/issue-20605.next.stderr (100%) create mode 100644 tests/ui/for/issue-20605.rs delete mode 100644 tests/ui/issues/issue-20605.rs diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 5c6a94877884d..55bf38110a6d5 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; const ENTRY_LIMIT: usize = 900; // FIXME: The following limits should be reduced eventually. -const ISSUES_ENTRY_LIMIT: usize = 1898; +const ISSUES_ENTRY_LIMIT: usize = 1896; const ROOT_ENTRY_LIMIT: usize = 870; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ diff --git a/tests/ui/issues/issue-20605.current.stderr b/tests/ui/for/issue-20605.current.stderr similarity index 100% rename from tests/ui/issues/issue-20605.current.stderr rename to tests/ui/for/issue-20605.current.stderr diff --git a/tests/ui/issues/issue-20605.next.stderr b/tests/ui/for/issue-20605.next.stderr similarity index 100% rename from tests/ui/issues/issue-20605.next.stderr rename to tests/ui/for/issue-20605.next.stderr diff --git a/tests/ui/for/issue-20605.rs b/tests/ui/for/issue-20605.rs new file mode 100644 index 0000000000000..499271fa92fa9 --- /dev/null +++ b/tests/ui/for/issue-20605.rs @@ -0,0 +1,11 @@ +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +fn changer<'a>(mut things: Box>) { + for item in *things { *item = 0 } + //~^ ERROR the size for values of type + //[next]~^^ ERROR the type `<_ as IntoIterator>::IntoIter` is not well-formed + //[next]~| ERROR the trait bound `dyn Iterator: IntoIterator` is not satisfied +} + +fn main() {} diff --git a/tests/ui/issues/issue-20605.rs b/tests/ui/issues/issue-20605.rs deleted file mode 100644 index 66bdc52e6b1a2..0000000000000 --- a/tests/ui/issues/issue-20605.rs +++ /dev/null @@ -1,11 +0,0 @@ -// revisions: current next -//[next] compile-flags: -Ztrait-solver=next - -fn changer<'a>(mut things: Box>) { - for item in *things { *item = 0 } -//~^ ERROR the size for values of type -//[next]~^^ ERROR the type `<_ as IntoIterator>::IntoIter` is not well-formed -//[next]~| ERROR the trait bound `dyn Iterator: IntoIterator` is not satisfied -} - -fn main() {}