Skip to content

rust: module.rs: Replace unwrap() with expect() #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions rust/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> String {
}

fn expect_punct(it: &mut token_stream::IntoIter) -> char {
if let TokenTree::Punct(punct) = it.next().unwrap() {
if let TokenTree::Punct(punct) = it.next().expect("Reached end of token stream for Punct") {
punct.as_char()
} else {
panic!("Expected Punct");
Expand All @@ -54,7 +54,7 @@ fn expect_literal(it: &mut token_stream::IntoIter) -> String {
}

fn expect_group(it: &mut token_stream::IntoIter) -> Group {
if let TokenTree::Group(group) = it.next().unwrap() {
if let TokenTree::Group(group) = it.next().expect("Reached end of token stream for Group") {
group
} else {
panic!("Expected Group");
Expand Down Expand Up @@ -84,7 +84,10 @@ fn expect_array_fields(it: &mut token_stream::IntoIter) -> ParamType {
}

fn expect_type(it: &mut token_stream::IntoIter) -> ParamType {
if let TokenTree::Ident(ident) = it.next().unwrap() {
if let TokenTree::Ident(ident) = it
.next()
.expect("Reached end of token stream for param type")
{
match ident.to_string().as_ref() {
"ArrayParam" => expect_array_fields(it),
_ => ParamType::Ident(ident.to_string()),
Expand Down Expand Up @@ -576,7 +579,8 @@ pub fn module(ts: TokenStream) -> TokenStream {
));
}

let file = std::env::var("RUST_MODFILE").unwrap();
let file =
std::env::var("RUST_MODFILE").expect("Unable to fetch RUST_MODFILE environmental variable");

format!(
"
Expand Down Expand Up @@ -672,5 +676,5 @@ pub fn module(ts: TokenStream) -> TokenStream {
params_modinfo = params_modinfo,
generated_array_types = generated_array_types,
initcall_section = ".initcall6.init"
).parse().unwrap()
).parse().expect("Error parsing formatted string into token stream.")
}