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

ices/92004.rs: fixed with errors #1395

Merged
merged 1 commit into from
Aug 23, 2022
Merged

ices/92004.rs: fixed with errors #1395

merged 1 commit into from
Aug 23, 2022

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#92004

use std::vec::Vec;
use std::iter::Peekable;

pub fn main() {
    let packet = decode(vec![1,0,1,0]);
}

pub fn decode(bitstream: Vec<u64>) -> Packet {
    let mut bitstream_itr = bitstream.into_iter().peekable();
    return match decode_packet(&mut bitstream_itr) {
        Some(p) => p,
        None    => panic!("expected outer packet"),
    }
}

pub fn decode_packets<I: Iterator<Item = u64>>(itr: &mut Peekable<I>) -> Vec<Packet> {
    let mut res = Vec::new();
    loop {
        match decode_packet(itr) {
            Some(p) => { res.push(p); },
            None    => break
        }
    }

    return res;
}

pub fn decode_packet<I: Iterator<Item = u64>>(itr: &mut Peekable<I>) -> Option<Packet> {
    // get version digits
    let version = extend_number(0, itr, 3)?;
    let type_id = extend_number(0, itr, 3)?;
    return operator_packet(version, type_id, itr);
}

pub fn operator_packet<I: Iterator<Item = u64>>(version: u64, type_id: u64, itr: &mut Peekable<I>) -> Option<Packet> {
    let p = OperatorPacket {
        version: version,
        type_id: type_id,
        packets: decode_packets(&mut itr.take(0).peekable()),
    };

    return Some(Packet::Operator(p));
}

pub fn extend_number<I: Iterator<Item = u64>>(num: u64, itr: &mut Peekable<I>, take: u64) -> Option<u64> {
    let mut value = num;
    for _ in 0..take {
        value *= 2;
        value += itr.next()?;
    }

    return Some(value);
}

#[derive(Debug)]
pub enum Packet {
    Operator(OperatorPacket),
}

#[derive(Debug)]
pub struct OperatorPacket {
    version: u64,
    type_id: u64,
    packets: Vec<Packet>
}
=== stdout ===
=== stderr ===
warning: unused variable: `packet`
 --> /home/runner/work/glacier/glacier/ices/92004.rs:5:9
  |
5 |     let packet = decode(vec![1,0,1,0]);
  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_packet`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: fields `version`, `type_id` and `packets` are never read
  --> /home/runner/work/glacier/glacier/ices/92004.rs:62:5
   |
61 | pub struct OperatorPacket {
   |            -------------- fields in this struct
62 |     version: u64,
   |     ^^^^^^^
63 |     type_id: u64,
   |     ^^^^^^^
64 |     packets: Vec<Packet>
   |     ^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default
   = note: `OperatorPacket` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error[E0275]: overflow evaluating the requirement `<std::vec::IntoIter<u64> as Iterator>::Item`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`92004`)

error: aborting due to previous error; 2 warnings emitted

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

=== stdout ===
=== stderr ===
warning: unused variable: `packet`
 --> /home/runner/work/glacier/glacier/ices/92004.rs:5:9
  |
5 |     let packet = decode(vec![1,0,1,0]);
  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_packet`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: fields `version`, `type_id` and `packets` are never read
  --> /home/runner/work/glacier/glacier/ices/92004.rs:62:5
   |
61 | pub struct OperatorPacket {
   |            -------------- fields in this struct
62 |     version: u64,
   |     ^^^^^^^
63 |     type_id: u64,
   |     ^^^^^^^
64 |     packets: Vec<Packet>
   |     ^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default
   = note: `OperatorPacket` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error[E0275]: overflow evaluating the requirement `<std::vec::IntoIter<u64> as Iterator>::Item`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`92004`)

error: aborting due to previous error; 2 warnings emitted

For more information about this error, try `rustc --explain E0275`.
==============
@JohnTitor JohnTitor merged commit b09c24d into master Aug 23, 2022
@JohnTitor JohnTitor deleted the autofix/ices/92004.rs branch August 23, 2022 09:44
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