Skip to content

Commit b545492

Browse files
committed
replace try! macro and move definitions to top of fn body
1 parent 1a25d8e commit b545492

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ pub fn glob(pattern: &str) -> Result<Paths, PatternError> {
167167
/// Paths are yielded in alphabetical order.
168168
pub fn glob_with(pattern: &str, options: &MatchOptions)
169169
-> Result<Paths, PatternError> {
170-
// make sure that the pattern is valid first, else early return with error
171-
let _compiled = try!(Pattern::new(pattern));
172-
173170
#[cfg(windows)]
174171
fn check_windows_verbatim(p: &Path) -> bool {
175172
use std::path::Prefix;
@@ -193,6 +190,12 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
193190
p.to_path_buf()
194191
}
195192

193+
// make sure that the pattern is valid first, else early return with error
194+
if let Err(err) = Pattern::new(pattern) {
195+
return Err(err);
196+
}
197+
198+
196199
let mut components = Path::new(pattern).components().peekable();
197200
loop {
198201
match components.peek() {
@@ -232,8 +235,7 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
232235
.split_terminator(path::is_separator);
233236

234237
for component in components {
235-
let compiled = try!(Pattern::new(component));
236-
dir_patterns.push(compiled);
238+
dir_patterns.push(Pattern::new(component)?);
237239
}
238240

239241
if root_len == pattern.len() {

0 commit comments

Comments
 (0)