Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

ices/97381.rs: fixed with errors #1293

Merged
merged 1 commit into from
Jun 9, 2022
Merged

ices/97381.rs: fixed with errors #1293

merged 1 commit into from
Jun 9, 2022

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 9, 2022

Issue: rust-lang/rust#97381

use std::ops::Deref;

trait MyTrait: Deref<Target = u32> {}

struct MyStruct(u32);

impl MyTrait for MyStruct {}

impl Deref for MyStruct {
    type Target = u32;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn get_concrete_value(i: u32) -> MyStruct {
    MyStruct(i)
}

fn get_boxed_value(i: u32) -> Box<dyn MyTrait> {
    Box::new(get_concrete_value(i))
}

fn main() {
    let v = [1, 2, 3]
        .iter()
        .map(|i| get_boxed_value(*i))
        .collect::<Vec<_>>();

    let el = &v[0];

    for _ in v {
        // this triggers bug
        println!("{}", ***el > 0);
    }
}
=== stdout ===
=== stderr ===
error[E0505]: cannot move out of `v` because it is borrowed
  --> /home/runner/work/glacier/glacier/ices/97381.rs:33:14
   |
31 |     let el = &v[0];
   |               - borrow of `v` occurs here
32 | 
33 |     for _ in v {
   |              ^ move out of `v` occurs here
34 |         // this triggers bug
35 |         println!("{}", ***el > 0);
   |                         ---- borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0505`.
==============

=== stdout ===
=== stderr ===
error[E0505]: cannot move out of `v` because it is borrowed
  --> /home/runner/work/glacier/glacier/ices/97381.rs:33:14
   |
31 |     let el = &v[0];
   |               - borrow of `v` occurs here
32 | 
33 |     for _ in v {
   |              ^ move out of `v` occurs here
34 |         // this triggers bug
35 |         println!("{}", ***el > 0);
   |                         ---- borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0505`.
==============
@JohnTitor JohnTitor merged commit bd1a3f5 into master Jun 9, 2022
@JohnTitor JohnTitor deleted the autofix/ices/97381.rs branch June 9, 2022 09:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants