Unverified Commit 7f2b398a authored by Christian Duerr's avatar Christian Duerr Committed by GitHub

Remove all instances of unwrap() from config

Unwrapping inside the config file parsing can lead to some issues that
prevent us from falling back to a default configuration file.

One instance of that issue was mentioned in #1135.

Now all instances of `unwrap()` have been removed and replaced with
proper error handling. This will make the config more robust and
prevents live reload from silently breaking while alacritty is running.

This also fixes a few currently existing clippy issues.
Clippy added an additonal lint which complains about `MyStruct { field:
field }`.

These issues have been fixed, except for some false-positives and issues
in external macros which will probably be fixed with future updates (rust-lang-nursery/bitflags#149)
parent 475ebecf
This diff is collapsed.
......@@ -65,7 +65,7 @@ fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
if next!() != Some('/') { return None; }
let b = parse_hex!();
Some(Rgb { r: r, g: g, b: b})
Some(Rgb { r, g, b })
}
Some('#') => {
Some(Rgb {
......@@ -128,8 +128,8 @@ impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
) -> Performer<'b, H, W> {
Performer {
_state: state,
handler: handler,
writer: writer,
handler,
writer,
}
}
}
......
......@@ -214,7 +214,7 @@ impl<'a> Shell<'a> {
{
Shell {
program: program.into(),
args: args
args,
}
}
......@@ -678,9 +678,9 @@ struct RawBinding {
impl RawBinding {
fn into_mouse_binding(self) -> ::std::result::Result<MouseBinding, Self> {
if self.mouse.is_some() {
if let Some(mouse) = self.mouse {
Ok(Binding {
trigger: self.mouse.unwrap(),
trigger: mouse,
mods: self.mods,
action: self.action,
mode: self.mode,
......@@ -692,9 +692,9 @@ impl RawBinding {
}
fn into_key_binding(self) -> ::std::result::Result<KeyBinding, Self> {
if self.key.is_some() {
if let Some(key) = self.key {
Ok(KeyBinding {
trigger: self.key.unwrap(),
trigger: key,
mods: self.mods,
action: self.action,
mode: self.mode,
......@@ -865,12 +865,12 @@ impl<'a> de::Deserialize<'a> for RawBinding {
}
Ok(RawBinding {
mode: mode,
mode,
notmode: not_mode,
action: action,
key: key,
mouse: mouse,
mods: mods,
action,
key,
mouse,
mods,
})
}
}
......@@ -977,8 +977,8 @@ impl CursorOrPrimaryColors {
fn into_cursor_colors(self) -> CursorColors {
match self {
CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors {
text: text,
cursor: cursor
text,
cursor,
},
CursorOrPrimaryColors::Primary { foreground, background } => {
// Must print in config since logger isn't setup yet.
......@@ -1124,12 +1124,12 @@ impl FromStr for Rgb {
macro_rules! component {
($($c:ident),*) => {
$(
match chars.next().unwrap().to_digit(16) {
match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c = (val as u8) << 4,
None => return Err(())
}
match chars.next().unwrap().to_digit(16) {
match chars.next().and_then(|c| c.to_digit(16)) {
Some(val) => rgb.$c |= val as u8,
None => return Err(())
}
......@@ -1137,9 +1137,9 @@ impl FromStr for Rgb {
}
}
match chars.next().unwrap() {
'0' => if chars.next().unwrap() != 'x' { return Err(()); },
'#' => (),
match chars.next() {
Some('0') => if chars.next() != Some('x') { return Err(()); },
Some('#') => (),
_ => return Err(()),
}
......@@ -1429,8 +1429,8 @@ impl Default for Dimensions {
impl Dimensions {
pub fn new(columns: Column, lines: Line) -> Self {
Dimensions {
columns: columns,
lines: lines
columns,
lines,
}
}
......@@ -1668,7 +1668,8 @@ impl Monitor {
_thread: ::util::thread::spawn_named("config watcher", move || {
let (tx, rx) = mpsc::channel();
// The Duration argument is a debouncing period.
let mut watcher = watcher(tx, Duration::from_millis(10)).unwrap();
let mut watcher = watcher(tx, Duration::from_millis(10))
.expect("Unable to spawn file watcher");
let config_path = ::std::fs::canonicalize(path)
.expect("canonicalize config path");
......@@ -1742,7 +1743,6 @@ enum Key {
Key8,
Key9,
Key0,
A,
B,
C,
......@@ -1769,9 +1769,7 @@ enum Key {
X,
Y,
Z,
Escape,
F1,
F2,
F3,
......@@ -1787,7 +1785,6 @@ enum Key {
F13,
F14,
F15,
Snapshot,
Scroll,
Pause,
......@@ -1797,7 +1794,6 @@ enum Key {
End,
PageDown,
PageUp,
Left,
Up,
Right,
......@@ -1817,7 +1813,6 @@ enum Key {
Numpad7,
Numpad8,
Numpad9,
AbntC1,
AbntC2,
Add,
......
......@@ -198,15 +198,15 @@ impl Display {
});
Ok(Display {
window: window,
renderer: renderer,
glyph_cache: glyph_cache,
render_timer: render_timer,
tx: tx,
rx: rx,
window,
renderer,
glyph_cache,
render_timer,
tx,
rx,
meter: Meter::new(),
font_size: font::Size::new(0.),
size_info: size_info,
size_info,
last_background_color: background_color,
})
}
......
......@@ -227,12 +227,12 @@ impl<N: Notify> Processor<N> {
mouse_config: config.mouse().to_owned(),
print_events: options.print_events,
wait_for_event: true,
notifier: notifier,
resize_tx: resize_tx,
ref_test: ref_test,
notifier,
resize_tx,
ref_test,
mouse: Default::default(),
selection: None,
size_info: size_info,
size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
received_count: 0,
......
......@@ -179,12 +179,12 @@ impl<Io> EventLoop<Io>
let (tx, rx) = channel::channel();
EventLoop {
poll: mio::Poll::new().expect("create mio Poll"),
pty: pty,
tx: tx,
rx: rx,
terminal: terminal,
display: display,
ref_test: ref_test,
pty,
tx,
rx,
terminal,
display,
ref_test,
}
}
......
......@@ -82,9 +82,9 @@ impl<T: Clone> Grid<T> {
}
Grid {
raw: raw,
cols: cols,
lines: lines,
raw,
cols,
lines,
}
}
......
......@@ -35,7 +35,7 @@ pub struct Point {
impl Point {
pub fn new(line: Line, col: Column) -> Point {
Point { line: line, col: col }
Point { line, col }
}
}
......
......@@ -32,7 +32,7 @@ impl<T: Send + io::Write> Logger<T> {
#[cfg_attr(feature = "clippy", allow(new_ret_no_self))]
pub fn new(output: T, level: log::LevelFilter) -> Logger<io::LineWriter<T>> {
Logger {
level: level,
level,
output: sync::Mutex::new(io::LineWriter::new(output))
}
}
......
......@@ -62,7 +62,7 @@ pub struct Sampler<'a> {
impl<'a> Sampler<'a> {
fn new(meter: &'a mut Meter) -> Sampler<'a> {
Sampler {
meter: meter,
meter,
created_at: Instant::now(),
}
}
......
......@@ -188,13 +188,13 @@ impl GlyphCache {
let mut cache = GlyphCache {
cache: HashMap::default(),
rasterizer: rasterizer,
rasterizer,
font_size: font.size(),
font_key: regular,
bold_key: bold,
italic_key: italic,
glyph_offset: *font.glyph_offset(),
metrics: metrics
metrics,
};
cache.load_glyphs_for_font(regular, loader);
......@@ -214,7 +214,7 @@ impl GlyphCache {
self.get(&GlyphKey {
font_key: font,
c: i as char,
size: size
size,
}, loader);
}
}
......@@ -262,7 +262,7 @@ impl GlyphCache {
let style = if let Some(ref spec) = desc.style {
font::Style::Specific(spec.to_owned())
} else {
font::Style::Description {slant:slant, weight:weight}
font::Style::Description { slant, weight }
};
FontDesc::new(&desc.family[..], style)
}
......@@ -606,11 +606,11 @@ impl QuadRenderer {
}
let mut renderer = QuadRenderer {
program: program,
vao: vao,
vbo: vbo,
ebo: ebo,
vbo_instance: vbo_instance,
program,
vao,
vbo,
ebo,
vbo_instance,
atlas: Vec::new(),
current_atlas: 0,
active_tex: 0,
......@@ -662,7 +662,7 @@ impl QuadRenderer {
current_atlas: &mut self.current_atlas,
program: &mut self.program,
visual_bell_intensity: visual_bell_intensity as _,
config: config,
config,
});
unsafe {
......@@ -789,9 +789,9 @@ impl<'a> RenderApi<'a> {
let cells = string.chars()
.enumerate()
.map(|(i, c)| RenderableCell {
line: line,
line,
column: col + i,
c: c,
c,
bg: color,
fg: Rgb { r: 0, g: 0, b: 0 },
flags: cell::Flags::empty(),
......@@ -835,7 +835,7 @@ impl<'a> RenderApi<'a> {
}
let glyph_key = GlyphKey {
font_key: font_key,
font_key,
size: glyph_cache.font_size,
c: cell.c
};
......@@ -851,7 +851,7 @@ impl<'a> RenderApi<'a> {
// easy, clean hack.
if cell.flags.contains(cell::Flags::UNDERLINE) {
let glyph_key = GlyphKey {
font_key: font_key,
font_key,
size: glyph_cache.font_size,
c: '_'
};
......@@ -1332,7 +1332,7 @@ impl Atlas {
}
Atlas {
id: id,
id,
width: size,
height: size,
row_extent: 0,
......@@ -1424,10 +1424,10 @@ impl Atlas {
width: width as f32,
height: height as f32,
left: glyph.left as f32,
uv_bot: uv_bot,
uv_left: uv_left,
uv_width: uv_width,
uv_height: uv_height,
uv_bot,
uv_left,
uv_width,
uv_height,
}
}
......
......@@ -75,7 +75,7 @@ pub struct Anchor {
impl Anchor {
fn new(point: Point, side: Side) -> Anchor {
Anchor { point: point, side: side }
Anchor { point, side }
}
}
......@@ -114,8 +114,8 @@ impl Selection {
end: point,
},
initial_expansion: Region {
start: start,
end: end
start,
end,
}
}
}
......@@ -248,10 +248,10 @@ impl Selection {
return None;
} else {
return Some(Span {
cols: cols,
cols,
ty: SpanType::Inclusive,
front: front,
tail: tail
front,
tail,
});
}
}
......@@ -266,30 +266,30 @@ impl Selection {
Some(match (front_side, tail_side) {
// [FX][XX][XT]
(Side::Left, Side::Right) => Span {
cols: cols,
front: front,
tail: tail,
cols,
front,
tail,
ty: SpanType::Inclusive
},
// [ F][XX][T ]
(Side::Right, Side::Left) => Span {
cols: cols,
front: front,
tail: tail,
cols,
front,
tail,
ty: SpanType::Exclusive
},
// [FX][XX][T ]
(Side::Left, Side::Left) => Span {
cols: cols,
front: front,
tail: tail,
cols,
front,
tail,
ty: SpanType::ExcludeTail
},
// [ F][XX][XT]
(Side::Right, Side::Right) => Span {
cols: cols,
front: front,
tail: tail,
cols,
front,
tail,
ty: SpanType::ExcludeFront
},
})
......
......@@ -92,9 +92,9 @@ impl Cell {
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
Cell {
c: c,
bg: bg,
fg: fg,
c,
bg,
fg,
flags: Flags::empty(),
}
}
......
......@@ -123,15 +123,15 @@ impl<'a> RenderableCellsIter<'a> {
let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0);
RenderableCellsIter {
grid: grid,
cursor: cursor,
cursor_index: cursor_index,
mode: mode,
grid,
cursor,
cursor_index,
mode,
line: Line(0),
column: Column(0),
selection: selection,
config: config,
colors: colors,
selection,
config,
colors,
cursor_cells: ArrayDeque::new(),
}.initialize(cursor_style)
}
......@@ -396,13 +396,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
}
return Some(RenderableCell {
line: line,
column: column,
line,
column,
flags: cell.flags,
c: cell.c,
fg: fg_rgb,
bg: bg_rgb,
bg_alpha: bg_alpha,
bg_alpha,
})
}
......@@ -816,7 +816,7 @@ impl Term {
visual_bell: VisualBell::new(config),
next_is_urgent: None,
input_needs_wrap: false,
grid: grid,
grid,
alt_grid: alt,
alt: false,
font_size: config.font().size(),
......@@ -825,9 +825,9 @@ impl Term {
cursor: Default::default(),
cursor_save: Default::default(),
cursor_save_alt: Default::default(),
tabs: tabs,
tabs,
mode: Default::default(),
scroll_region: scroll_region,
scroll_region,
size_info: size,
colors: color::List::from(config.colors()),
color_modified: [false; color::COUNT],
......
......@@ -216,8 +216,8 @@ impl Window {
}
let window = Window {
event_loop: event_loop,
window: window,
event_loop,
window,
cursor_visible: true,
is_focused: true,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment