Skip to content

Avoid unwrapping in libterm #29992

Closed
Closed
@frewsxcv

Description

@frewsxcv

Instead of this:

                        if !stack.is_empty() {
                            match stack.pop().unwrap() {
                                ...
                            }
                        } else {
                            ...
                        }

do:

                        match stack.pop() {
                            Some(..) => ...
                            None => ...
                        }

Similarly, instead of this:

                        if stack.len() > 1 {
                            match (stack.pop().unwrap(), stack.pop().unwrap()) {
                                (Number(y), Number(x)) => ...
                                _ => ...
                            }
                        } else {
                            ...
                        }

do:

                        match (stack.pop(), stack.pop()) {
                            (Some(Number(y)), Some(Number(x))) => ...
                            (Some(_), Some(_) => ...
                            _ => ...
                        }

There are multiple instances of these patterns in this file so make sure to clean up all of them

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions