From a0bf7d2cd3751de2b49ec66701aaa7cc41345c35 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Thu, 5 Aug 2021 06:41:08 -0700 Subject: Avoid ICE caused by suggestion When suggesting dereferencing something that can be iterable in a `for` loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region constraints already solved' panic. Fix #87657. --- src/test/ui/suggestions/for-i-in-vec.fixed | 9 +++++++++ src/test/ui/suggestions/for-i-in-vec.rs | 9 +++++++++ src/test/ui/suggestions/for-i-in-vec.stderr | 13 ++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/ui/suggestions/for-i-in-vec.fixed b/src/test/ui/suggestions/for-i-in-vec.fixed index 223ddf0f0ad..4f2007befff 100644 --- a/src/test/ui/suggestions/for-i-in-vec.fixed +++ b/src/test/ui/suggestions/for-i-in-vec.fixed @@ -15,4 +15,13 @@ impl Foo { } } +const LOADERS: &Vec<&'static u8> = &Vec::new(); + +pub fn break_code() -> Option<&'static u8> { + for loader in &*LOADERS { //~ ERROR cannot move out of a shared reference + return Some(loader); + } + None +} + fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.rs b/src/test/ui/suggestions/for-i-in-vec.rs index 7942698cc8e..55fc7ad4e37 100644 --- a/src/test/ui/suggestions/for-i-in-vec.rs +++ b/src/test/ui/suggestions/for-i-in-vec.rs @@ -15,4 +15,13 @@ impl Foo { } } +const LOADERS: &Vec<&'static u8> = &Vec::new(); + +pub fn break_code() -> Option<&'static u8> { + for loader in *LOADERS { //~ ERROR cannot move out of a shared reference + return Some(loader); + } + None +} + fn main() {} diff --git a/src/test/ui/suggestions/for-i-in-vec.stderr b/src/test/ui/suggestions/for-i-in-vec.stderr index 49cee6abc4e..c39363f762b 100644 --- a/src/test/ui/suggestions/for-i-in-vec.stderr +++ b/src/test/ui/suggestions/for-i-in-vec.stderr @@ -20,6 +20,17 @@ help: consider iterating over a slice of the `HashMap`'s content LL | for _ in &self.h { | + -error: aborting due to 2 previous errors +error[E0507]: cannot move out of a shared reference + --> $DIR/for-i-in-vec.rs:21:19 + | +LL | for loader in *LOADERS { + | ^^^^^^^^ move occurs because value has type `Vec<&u8>`, which does not implement the `Copy` trait + | +help: consider iterating over a slice of the `Vec<&u8>`'s content + | +LL | for loader in &*LOADERS { + | + + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0507`. -- cgit 1.4.1-3-g733a5