Skip to content

Commit b6163f9

Browse files
authored
Merge pull request #142 from Sylfrena/lin-fix-unwrap
rust: module.rs: Replace unwrap() with expect()
2 parents c295df9 + 243acc5 commit b6163f9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

rust/module.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> String {
4242
}
4343

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

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

8686
fn expect_type(it: &mut token_stream::IntoIter) -> ParamType {
87-
if let TokenTree::Ident(ident) = it.next().unwrap() {
87+
if let TokenTree::Ident(ident) = it
88+
.next()
89+
.expect("Reached end of token stream for param type")
90+
{
8891
match ident.to_string().as_ref() {
8992
"ArrayParam" => expect_array_fields(it),
9093
_ => ParamType::Ident(ident.to_string()),
@@ -576,7 +579,8 @@ pub fn module(ts: TokenStream) -> TokenStream {
576579
));
577580
}
578581

579-
let file = std::env::var("RUST_MODFILE").unwrap();
582+
let file =
583+
std::env::var("RUST_MODFILE").expect("Unable to fetch RUST_MODFILE environmental variable");
580584

581585
format!(
582586
"
@@ -672,5 +676,5 @@ pub fn module(ts: TokenStream) -> TokenStream {
672676
params_modinfo = params_modinfo,
673677
generated_array_types = generated_array_types,
674678
initcall_section = ".initcall6.init"
675-
).parse().unwrap()
679+
).parse().expect("Error parsing formatted string into token stream.")
676680
}

0 commit comments

Comments
 (0)