Auto merge of #7987 - frewsxcv:clippy, r=Manishearth

Fix issues found by rust-clippy



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7987)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-12 18:33:30 -06:00
commit eb7039d04d
23 changed files with 106 additions and 121 deletions

View file

@ -756,7 +756,7 @@ fn is_zero_size_gradient(pattern: &Pattern) -> bool {
return true;
}
}
return false;
false
}
pub trait PointToi32 {

View file

@ -178,7 +178,7 @@ impl FontHandleMethods for FontHandle {
let max_advance_width = au_from_pt(bounding_rect.size.width as f64);
let average_advance = self.glyph_index('0')
.and_then(|idx| self.glyph_h_advance(idx))
.map(|advance| Au::from_f64_px(advance))
.map(Au::from_f64_px)
.unwrap_or(max_advance_width);
let metrics = FontMetrics {
@ -201,7 +201,7 @@ impl FontHandleMethods for FontHandle {
line_gap: Au::from_f64_px(line_gap),
};
debug!("Font metrics (@{} pt): {:?}", self.ctfont.pt_size() as f64, metrics);
return metrics;
metrics
}
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {

View file

@ -1479,7 +1479,7 @@ impl Fragment {
let character_breaking_strategy =
text_fragment_info.run.character_slices_in_range(&text_fragment_info.range);
flags.remove(RETRY_AT_CHARACTER_BOUNDARIES);
return self.calculate_split_position_using_breaking_strategy(
self.calculate_split_position_using_breaking_strategy(
character_breaking_strategy,
max_inline_size,
flags)
@ -1685,7 +1685,7 @@ impl Fragment {
/// Assigns replaced inline-size, padding, and margins for this fragment only if it is replaced
/// content per CSS 2.1 § 10.3.2.
pub fn assign_replaced_inline_size_if_necessary<'a>(&'a mut self, container_inline_size: Au) {
pub fn assign_replaced_inline_size_if_necessary(&mut self, container_inline_size: Au) {
match self.specific {
SpecificFragmentInfo::Generic |
SpecificFragmentInfo::GeneratedContent(_) |
@ -2257,7 +2257,7 @@ impl Fragment {
CharIndex(leading_whitespace_character_count),
-CharIndex(leading_whitespace_character_count));
return WhitespaceStrippingResult::RetainFragment
WhitespaceStrippingResult::RetainFragment
}
SpecificFragmentInfo::UnscannedText(ref mut unscanned_text_fragment_info) => {
let mut new_text_string = String::new();

View file

@ -184,11 +184,11 @@ impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
}
GeneratedContentInfo::ContentItem(ContentItem::Counter(ref counter_name,
counter_style)) => {
let mut temporary_counter = Counter::new();
let temporary_counter = Counter::new();
let counter = self.traversal
.counters
.get(&*counter_name)
.unwrap_or(&mut temporary_counter);
.unwrap_or(&temporary_counter);
new_info = counter.render(self.traversal.layout_context,
fragment.node,
fragment.pseudo.clone(),
@ -199,11 +199,11 @@ impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
GeneratedContentInfo::ContentItem(ContentItem::Counters(ref counter_name,
ref separator,
counter_style)) => {
let mut temporary_counter = Counter::new();
let temporary_counter = Counter::new();
let counter = self.traversal
.counters
.get(&*counter_name)
.unwrap_or(&mut temporary_counter);
.unwrap_or(&temporary_counter);
new_info = counter.render(self.traversal.layout_context,
fragment.node,
fragment.pseudo,

View file

@ -1452,7 +1452,7 @@ impl LayoutTask {
// Parallel mode.
self.solve_constraints_parallel(parallel,
&mut root_flow,
&mut *layout_context);
&*layout_context);
}
}
});

View file

@ -154,7 +154,7 @@ impl Cookie {
}
}
if self.cookie.secure && url.scheme != "https".to_owned() {
if self.cookie.secure && url.scheme != "https" {
return false;
}
if self.cookie.httponly && source == CookieSource::NonHTTP {

View file

@ -75,10 +75,9 @@ fn send_error(url: Url, err: String, start_chan: LoadConsumer) {
let mut metadata: Metadata = Metadata::default(url);
metadata.status = None;
match start_sending_opt(start_chan, metadata) {
Ok(p) => p.send(Done(Err(err))).unwrap(),
_ => {}
};
if let Ok(p) = start_sending_opt(start_chan, metadata) {
p.send(Done(Err(err))).unwrap();
}
}
enum ReadResult {
@ -157,8 +156,8 @@ pub trait HttpResponse: Read {
fn content_encoding(&self) -> Option<Encoding> {
self.headers().get::<ContentEncoding>().and_then(|h| {
match h {
&ContentEncoding(ref encodings) => {
match *h {
ContentEncoding(ref encodings) => {
if encodings.contains(&Encoding::Gzip) {
Some(Encoding::Gzip)
} else if encodings.contains(&Encoding::Deflate) {

View file

@ -173,7 +173,7 @@ impl ResourceChannelManager {
self.resource_manager.set_cookies_for_url(request, cookie_list, source)
}
ControlMsg::GetCookiesForUrl(url, consumer, source) => {
let ref cookie_jar = self.resource_manager.cookie_storage;
let cookie_jar = &self.resource_manager.cookie_storage;
let mut cookie_jar = cookie_jar.write().unwrap();
consumer.send(cookie_jar.cookies_for_url(&url, source)).unwrap();
}
@ -215,7 +215,7 @@ impl ResourceManager {
if let Ok(SetCookie(cookies)) = header {
for bare_cookie in cookies {
if let Some(cookie) = cookie::Cookie::new_wrapped(bare_cookie, &request, source) {
let ref cookie_jar = self.cookie_storage;
let cookie_jar = &self.cookie_storage;
let mut cookie_jar = cookie_jar.write().unwrap();
cookie_jar.push(cookie, source);
}

View file

@ -74,16 +74,11 @@ impl Profiler {
}
pub fn start(&mut self) {
loop {
match self.port.recv() {
Ok(msg) => {
while let Ok(msg) = self.port.recv() {
if !self.handle_msg(msg) {
break
}
}
_ => break
}
}
}
fn handle_msg(&mut self, msg: ProfilerMsg) -> bool {

View file

@ -22,9 +22,9 @@ pub trait Formattable {
impl Formattable for Option<TimerMetadata> {
fn format(&self) -> String {
match self {
match *self {
// TODO(cgaebel): Center-align in the format strings as soon as rustc supports it.
&Some(ref meta) => {
Some(ref meta) => {
let url = &*meta.url;
let url = if url.len() > 30 {
&url[..30]
@ -35,7 +35,7 @@ impl Formattable for Option<TimerMetadata> {
let iframe = if meta.iframe { " yes" } else { " no " };
format!(" {:14} {:9} {:30}", incremental, iframe, url)
},
&None =>
None =>
format!(" {:14} {:9} {:30}", " N/A", " N/A", " N/A")
}
}
@ -198,17 +198,11 @@ impl Profiler {
}
pub fn start(&mut self) {
loop {
let msg = self.port.recv();
match msg {
Ok(msg) => {
while let Ok(msg) = self.port.recv() {
if !self.handle_msg(msg) {
break
}
}
_ => break
}
}
}
fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), t: f64) {
@ -227,10 +221,9 @@ impl Profiler {
let ms = (t.1 - t.0) as f64 / 1000000f64;
self.find_or_insert(k, ms);
},
ProfilerMsg::Print => match self.last_msg {
ProfilerMsg::Print => if let Some(ProfilerMsg::Time(..)) = self.last_msg {
// only print if more data has arrived since the last printout
Some(ProfilerMsg::Time(..)) => self.print_buckets(),
_ => ()
self.print_buckets();
},
ProfilerMsg::Exit => {
heartbeats::cleanup();

View file

@ -112,5 +112,5 @@ pub fn profile<T, F>(category: ProfilerCategory,
profiler_chan.send(ProfilerMsg::Time((category, meta),
(start_time, end_time),
(start_energy, end_energy)));
return val;
val
}

View file

@ -95,7 +95,7 @@ impl ViewportLength {
}
impl FromMeta for Zoom {
fn from_meta<'a>(value: &'a str) -> Option<Zoom> {
fn from_meta(value: &str) -> Option<Zoom> {
Some(match value {
v if v.eq_ignore_ascii_case("yes") => Zoom::Number(1.),
v if v.eq_ignore_ascii_case("no") => Zoom::Number(0.1),
@ -113,7 +113,7 @@ impl FromMeta for Zoom {
}
impl FromMeta for UserZoom {
fn from_meta<'a>(value: &'a str) -> Option<UserZoom> {
fn from_meta(value: &str) -> Option<UserZoom> {
Some(match value {
v if v.eq_ignore_ascii_case("yes") => UserZoom::Zoom,
v if v.eq_ignore_ascii_case("no") => UserZoom::Fixed,
@ -377,13 +377,13 @@ impl ViewportRule {
start: usize)
-> Option<(&'a str, &'a str)>
{
fn end_of_token<'a>(iter: &mut Enumerate<Chars<'a>>) -> Option<(usize, char)> {
fn end_of_token(iter: &mut Enumerate<Chars>) -> Option<(usize, char)> {
iter.by_ref()
.skip_while(|&(_, c)| !is_whitespace_separator_or_equals(&c))
.next()
}
fn skip_whitespace<'a>(iter: &mut Enumerate<Chars<'a>>) -> Option<(usize, char)> {
fn skip_whitespace(iter: &mut Enumerate<Chars>) -> Option<(usize, char)> {
iter.by_ref()
.skip_while(|&(_, c)| WHITESPACE.contains(&c))
.next()

View file

@ -76,7 +76,7 @@ impl<K: Clone + PartialEq, V: Clone> LRUCache<K, V> {
self.entries[last_index].1.clone()
}
pub fn iter<'a>(&'a self) -> Iter<'a, (K, V)> {
pub fn iter(&self) -> Iter<(K, V)> {
self.entries.iter()
}

View file

@ -26,8 +26,8 @@ macro_rules! define_cursor {
impl ToCss for Cursor {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result where W: ::std::fmt::Write {
match self {
$( &Cursor::$variant => dest.write_str($css) ),+
match *self {
$( Cursor::$variant => dest.write_str($css) ),+
}
}
}

View file

@ -197,7 +197,7 @@ impl<T: Send + 'static> Worker<T> {
/// Gets access to the buffer pool that this worker is attached to. This can
/// be used to create more deques which share the same buffer pool as this
/// deque.
pub fn pool<'a>(&'a self) -> &'a BufferPool<T> {
pub fn pool(&self) -> &BufferPool<T> {
&self.deque.pool
}
}
@ -211,7 +211,7 @@ impl<T: Send + 'static> Stealer<T> {
/// Gets access to the buffer pool that this stealer is attached to. This
/// can be used to create more deques which share the same buffer pool as
/// this deque.
pub fn pool<'a>(&'a self) -> &'a BufferPool<T> {
pub fn pool(&self) -> &BufferPool<T> {
&self.deque.pool
}
}
@ -270,11 +270,11 @@ impl<T: Send + 'static> Deque<T> {
}
if self.top.compare_and_swap(t, t + 1, SeqCst) == t {
self.bottom.store(t + 1, SeqCst);
return Some(data);
Some(data)
} else {
self.bottom.store(t + 1, SeqCst);
forget(data); // someone else stole this value
return None;
None
}
}
@ -325,7 +325,7 @@ impl<T: Send + 'static> Deque<T> {
self.bottom.store(b, SeqCst);
}
self.pool.free(transmute(old));
return newbuf;
newbuf
}
}
@ -393,7 +393,7 @@ impl<T> Buffer<T> {
for i in t..b {
buf.put(i, self.get(i));
}
return buf;
buf
}
}

View file

@ -123,9 +123,9 @@ impl HeapSizeOf for url::Url {
impl HeapSizeOf for url::SchemeData {
fn heap_size_of_children(&self) -> usize {
match self {
&url::SchemeData::Relative(ref data) => data.heap_size_of_children(),
&url::SchemeData::NonRelative(ref str) => str.heap_size_of_children()
match *self {
url::SchemeData::Relative(ref data) => data.heap_size_of_children(),
url::SchemeData::NonRelative(ref str) => str.heap_size_of_children()
}
}
}
@ -147,9 +147,9 @@ impl HeapSizeOf for url::RelativeSchemeData {
impl HeapSizeOf for url::Host {
fn heap_size_of_children(&self) -> usize {
match self {
&url::Host::Domain(ref str) => str.heap_size_of_children(),
&url::Host::Ipv6(_) => 0
match *self {
url::Host::Domain(ref str) => str.heap_size_of_children(),
url::Host::Ipv6(_) => 0
}
}
}
@ -302,8 +302,8 @@ impl<T: Copy + GCMethods<T>> HeapSizeOf for Heap<T> {
impl HeapSizeOf for Method {
fn heap_size_of_children(&self) -> usize {
match self {
&Method::Extension(ref str) => str.heap_size_of_children(),
match *self {
Method::Extension(ref str) => str.heap_size_of_children(),
_ => 0
}
}
@ -311,9 +311,9 @@ impl HeapSizeOf for Method {
impl<T: HeapSizeOf, U: HeapSizeOf> HeapSizeOf for Result<T, U> {
fn heap_size_of_children(&self) -> usize {
match self {
&Result::Ok(ref ok) => ok.heap_size_of_children(),
&Result::Err(ref err) => err.heap_size_of_children()
match *self {
Result::Ok(ref ok) => ok.heap_size_of_children(),
Result::Err(ref err) => err.heap_size_of_children()
}
}
}
@ -341,13 +341,13 @@ impl HeapSizeOf for CompoundSelector {
impl HeapSizeOf for SimpleSelector {
fn heap_size_of_children(&self) -> usize {
match self {
&SimpleSelector::Negation(ref vec) => vec.heap_size_of_children(),
&SimpleSelector::AttrIncludes(_, ref str) | &SimpleSelector::AttrPrefixMatch(_, ref str) |
&SimpleSelector::AttrSubstringMatch(_, ref str) | &SimpleSelector::AttrSuffixMatch(_, ref str)
match *self {
SimpleSelector::Negation(ref vec) => vec.heap_size_of_children(),
SimpleSelector::AttrIncludes(_, ref str) | SimpleSelector::AttrPrefixMatch(_, ref str) |
SimpleSelector::AttrSubstringMatch(_, ref str) | SimpleSelector::AttrSuffixMatch(_, ref str)
=> str.heap_size_of_children(),
&SimpleSelector::AttrEqual(_, ref str, _) => str.heap_size_of_children(),
&SimpleSelector::AttrDashMatch(_, ref first, ref second) => first.heap_size_of_children()
SimpleSelector::AttrEqual(_, ref str, _) => str.heap_size_of_children(),
SimpleSelector::AttrDashMatch(_, ref first, ref second) => first.heap_size_of_children()
+ second.heap_size_of_children(),
// All other types come down to Atom, enum or i32, all 0
_ => 0
@ -372,8 +372,8 @@ impl HeapSizeOf for Mime {
impl HeapSizeOf for TopLevel {
fn heap_size_of_children(&self) -> usize {
match self {
&TopLevel::Ext(ref str) => str.heap_size_of_children(),
match *self {
TopLevel::Ext(ref str) => str.heap_size_of_children(),
_ => 0
}
}
@ -381,8 +381,8 @@ impl HeapSizeOf for TopLevel {
impl HeapSizeOf for SubLevel {
fn heap_size_of_children(&self) -> usize {
match self {
&SubLevel::Ext(ref str) => str.heap_size_of_children(),
match *self {
SubLevel::Ext(ref str) => str.heap_size_of_children(),
_ => 0
}
}
@ -390,8 +390,8 @@ impl HeapSizeOf for SubLevel {
impl HeapSizeOf for Attr {
fn heap_size_of_children(&self) -> usize {
match self {
&Attr::Ext(ref str) => str.heap_size_of_children(),
match *self {
Attr::Ext(ref str) => str.heap_size_of_children(),
_ => 0
}
}
@ -399,8 +399,8 @@ impl HeapSizeOf for Attr {
impl HeapSizeOf for Value {
fn heap_size_of_children(&self) -> usize {
match self {
&Value::Ext(ref str) => str.heap_size_of_children(),
match *self {
Value::Ext(ref str) => str.heap_size_of_children(),
_ => 0
}
}

View file

@ -257,7 +257,7 @@ pub struct DebugOptions {
impl DebugOptions {
pub fn new<'a>(debug_string: &'a str) -> Result<DebugOptions, &'a str> {
pub fn new(debug_string: &str) -> Result<DebugOptions, &str> {
let mut debug_options = DebugOptions::default();
for option in debug_string.split(',') {

View file

@ -49,7 +49,7 @@ impl<T> PersistentList<T> where T: Send + Sync {
}
#[inline]
pub fn iter<'a>(&'a self) -> PersistentListIterator<'a, T> {
pub fn iter(&self) -> PersistentListIterator<T> {
// This could clone (and would not need the lifetime if it did), but then it would incur
// atomic operations on every call to `.next()`. Bad.
PersistentListIterator {
@ -90,4 +90,3 @@ impl<'a, T> Iterator for PersistentListIterator<'a, T> where T: Send + Sync + 's
Some(value)
}
}

View file

@ -34,8 +34,8 @@ impl PrefValue {
}
pub fn as_boolean(&self) -> Option<bool> {
match self {
&PrefValue::Boolean(value) => {
match *self {
PrefValue::Boolean(value) => {
Some(value)
},
_ => None
@ -87,12 +87,12 @@ impl Pref {
}
pub fn value(&self) -> &Arc<PrefValue> {
match self {
&Pref::NoDefault(ref x) => x,
&Pref::WithDefault(ref default, ref override_value) => {
match override_value {
&Some(ref x) => x,
&None => default
match *self {
Pref::NoDefault(ref x) => x,
Pref::WithDefault(ref default, ref override_value) => {
match *override_value {
Some(ref x) => x,
None => default
}
}
}
@ -101,11 +101,11 @@ impl Pref {
fn set(&mut self, value: PrefValue) {
// TODO - this should error if we try to override a pref of one type
// with a value of a different type
match self {
&mut Pref::NoDefault(ref mut pref_value) => {
match *self {
Pref::NoDefault(ref mut pref_value) => {
*pref_value = Arc::new(value)
},
&mut Pref::WithDefault(_, ref mut override_value) => {
Pref::WithDefault(_, ref mut override_value) => {
*override_value = Some(Arc::new(value))
}
}

View file

@ -97,7 +97,7 @@ fn do_parse_integer<T: Iterator<Item=char>>(input: T) -> Option<i64> {
let value = read_numbers(input);
return value.and_then(|value| value.checked_mul(sign));
value.and_then(|value| value.checked_mul(sign))
}
/// Parse an integer according to
@ -244,9 +244,8 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
}
// Step 5.
match cssparser::parse_color_keyword(input) {
Ok(Color::RGBA(rgba)) => return Ok(rgba),
_ => {}
if let Ok(Color::RGBA(rgba)) = cssparser::parse_color_keyword(input) {
return Ok(rgba);
}
// Step 6.

View file

@ -52,7 +52,7 @@ impl<T> FullBinarySearchMethods<T> for [T] {
Ordering::Equal => return Some(mid),
}
}
return None;
None
}
}

View file

@ -259,13 +259,13 @@ impl<QueueData: Sync, WorkData: Send> WorkQueue<QueueData, WorkData> {
}
// Connect workers to one another.
for i in 0..thread_count {
for j in 0..thread_count {
for (i, mut thread) in threads.iter_mut().enumerate() {
for (j, info) in infos.iter().enumerate() {
if i != j {
threads[i].other_deques.push(infos[j].thief.clone())
thread.other_deques.push(info.thief.clone())
}
}
assert!(threads[i].other_deques.len() == thread_count - 1)
assert!(thread.other_deques.len() == thread_count - 1)
}
// Spawn threads.

View file

@ -88,16 +88,16 @@ impl WebDriverExtensionRoute for ServoExtensionRoute {
fn command(&self,
_captures: &Captures,
body_data: &Json) -> WebDriverResult<WebDriverCommand<ServoExtensionCommand>> {
let command = match self {
&ServoExtensionRoute::GetPrefs => {
let command = match *self {
ServoExtensionRoute::GetPrefs => {
let parameters: GetPrefsParameters = try!(Parameters::from_json(&body_data));
ServoExtensionCommand::GetPrefs(parameters)
}
&ServoExtensionRoute::SetPrefs => {
ServoExtensionRoute::SetPrefs => {
let parameters: SetPrefsParameters = try!(Parameters::from_json(&body_data));
ServoExtensionCommand::SetPrefs(parameters)
}
&ServoExtensionRoute::ResetPrefs => {
ServoExtensionRoute::ResetPrefs => {
let parameters: GetPrefsParameters = try!(Parameters::from_json(&body_data));
ServoExtensionCommand::ResetPrefs(parameters)
}
@ -115,10 +115,10 @@ enum ServoExtensionCommand {
impl WebDriverExtensionCommand for ServoExtensionCommand {
fn parameters_json(&self) -> Option<Json> {
match self {
&ServoExtensionCommand::GetPrefs(ref x) => Some(x.to_json()),
&ServoExtensionCommand::SetPrefs(ref x) => Some(x.to_json()),
&ServoExtensionCommand::ResetPrefs(ref x) => Some(x.to_json()),
match *self {
ServoExtensionCommand::GetPrefs(ref x) => Some(x.to_json()),
ServoExtensionCommand::SetPrefs(ref x) => Some(x.to_json()),
ServoExtensionCommand::ResetPrefs(ref x) => Some(x.to_json()),
}
}
}
@ -542,7 +542,7 @@ impl Handler {
"implicit" => self.implicit_wait_timeout = value,
"page load" => self.load_timeout = value,
"script" => self.script_timeout = value,
x @ _ => return Err(WebDriverError::new(ErrorStatus::InvalidSelector,
x => return Err(WebDriverError::new(ErrorStatus::InvalidSelector,
&format!("Unknown timeout type {}", x)))
}
Ok(WebDriverResponse::Void)
@ -708,10 +708,10 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
WebDriverCommand::SetTimeouts(ref x) => self.handle_set_timeouts(x),
WebDriverCommand::TakeScreenshot => self.handle_take_screenshot(),
WebDriverCommand::Extension(ref extension) => {
match extension {
&ServoExtensionCommand::GetPrefs(ref x) => self.handle_get_prefs(x),
&ServoExtensionCommand::SetPrefs(ref x) => self.handle_set_prefs(x),
&ServoExtensionCommand::ResetPrefs(ref x) => self.handle_reset_prefs(x),
match *extension {
ServoExtensionCommand::GetPrefs(ref x) => self.handle_get_prefs(x),
ServoExtensionCommand::SetPrefs(ref x) => self.handle_set_prefs(x),
ServoExtensionCommand::ResetPrefs(ref x) => self.handle_reset_prefs(x),
}
}
_ => Err(WebDriverError::new(ErrorStatus::UnsupportedOperation,