file_name
large_stringlengths
4
69
prefix
large_stringlengths
0
26.7k
suffix
large_stringlengths
0
24.8k
middle
large_stringlengths
0
2.12k
fim_type
large_stringclasses
4 values
mod.rs
//! Utilities for handling shell surfaces with the `wl_shell` protocol //! //! This module provides automatic handling of shell surfaces objects, by being registered //! as a global handler for `wl_shell`. This protocol is deprecated in favor of `xdg_shell`, //! thus this module is provided as a compatibility layer wit...
compositor::with_states(&self.wl_surface, |states| { let mut data = states .data_map .get::<Mutex<ShellSurfaceAttributes>>() .unwrap() .lock() .unwrap(); if let Some(pending_ping) = data.pending_ping { ...
{ return Err(PingError::DeadSurface); }
conditional_block
mod.rs
//! Utilities for handling shell surfaces with the `wl_shell` protocol //! //! This module provides automatic handling of shell surfaces objects, by being registered //! as a global handler for `wl_shell`. This protocol is deprecated in favor of `xdg_shell`, //! thus this module is provided as a compatibility layer wit...
{ wl_surface: wl_surface::WlSurface, shell_surface: wl_shell_surface::WlShellSurface, } impl std::cmp::PartialEq for ShellSurface { fn eq(&self, other: &Self) -> bool { self.shell_surface == other.shell_surface } } impl ShellSurface { /// Is the shell surface referred by this handle still...
ShellSurface
identifier_name
fulfill.rs
http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according ...
<'tcx>(tcx: &ty::ctxt<'tcx>, t_a: Ty<'tcx>, r_b: ty::Region, cause: ObligationCause<'tcx>, region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>) { let region_oblig...
register_region_obligation
identifier_name
fulfill.rs
// http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except accordin...
if self.predicates.len() == count { // Nothing changed. break; } // Now go through all the successful ones, // registering any nested obligations for the future. for new_obligation in new_obligations { self.reg...
self.attempted_mark = self.predicates.len();
random_line_split
fulfill.rs
http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according ...
pub fn register_builtin_bound<'a>(&mut self, infcx: &InferCtxt<'a,'tcx>, ty: Ty<'tcx>, builtin_bound: ty::BuiltinBound, cause: ObligationCause<'tcx>) { ...
{ debug!("normalize_associated_type(projection_ty={})", projection_ty.repr(infcx.tcx)); assert!(!projection_ty.has_escaping_regions()); // FIXME(#20304) -- cache let mut selcx = SelectionContext::new(infcx, typer); let normalized = project::normalize_projection_...
identifier_body
game.rs
use std::ops::{AddAssign, Not}; use std::sync::Arc; // The two dimensional position is a number between 0 and 15, // the three dimensional position is a number between 0 and 63. // // But still, they should be differentiated and the type system must track this. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct P...
(&mut self, column: Position2) { let position = self.insert(column); let color =!self.current_color; self.update_victory_state(position, color); } // Panics, if the column is already full. // This does NOT update the victory state. Use `.execute` for this. pub fn insert(&mut self...
execute
identifier_name
game.rs
use std::ops::{AddAssign, Not}; use std::sync::Arc; // The two dimensional position is a number between 0 and 15, // the three dimensional position is a number between 0 and 63. // // But still, they should be differentiated and the type system must track this. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct P...
} pub struct Structure { // A vector of all Subsets, complete one to win the game. pub source: Vec<Subset>, // Contains a lookup table, given a Position3, this returns a vector of indices. // The indices tell you which Subsets contain the Position3. pub reverse: [Vec<usize>; 64], // The size o...
draws: 0, } }
random_line_split
tuple-style-enum.rs
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MI...
() { // In order to avoid endianness trouble all of the following test values consist of a single // repeated byte. This way each interpretation of the union should look the same, no matter if // this is a big or little endian machine. // 0b0111110001111100011111000111110001111100011111000111110001111...
main
identifier_name
tuple-style-enum.rs
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MI...
// In order to avoid endianness trouble all of the following test values consist of a single // repeated byte. This way each interpretation of the union should look the same, no matter if // this is a big or little endian machine. // 0b0111110001111100011111000111110001111100011111000111110001111100 = ...
fn main() {
random_line_split
load.rs
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MI...
(&mut self, vi: &ast::ViewItem, path: Path, symbol: String) { // Make sure the path contains a / or the linker will search for it. let path = os::make_absolute(&path).unwrap(); let lib = match DynamicLibrary::open(Some(&path)) { Ok(lib) => lib, // this is fatal: there ar...
dylink_registrar
identifier_name
load.rs
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MI...
}
random_line_split
load.rs
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MI...
self.plugins.macros.push(ExportedMacros { crate_name: name, macros: macros, }); match (lib, registrar_symbol) { (Some(lib), Some(symbol)) => self.dylink_registrar(vi, lib, symbol), ...
{ let mut plugin_phase = false; for attr in vi.attrs.iter().filter(|a| a.check_name("phase")) { let phases = attr.meta_item_list().unwrap_or(&[]); if attr::contains_name(phases, "plugin") { plugin_phase = true; ...
conditional_block
service.rs
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. use crate::proto::{Health, HealthCheckRequest, HealthCheckResponse, ServingStatus}; use futures_util::{FutureExt as _, SinkExt as _, Stream, StreamExt as _}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, ServerStreamingSink, UnarySink, WriteFlags}...
cast.broadcast(status); } /// Sets all serving status to NotServing, and configures the server to /// ignore all future status changes. /// /// This changes serving status for all services. pub fn shutdown(&self) { let mut inner = self.inner.lock().unwrap(); inner.shutd...
{ let cast = { let mut inner = self.inner.lock().unwrap(); if inner.shutdown { info!("health: status changing for {} to {:?} is ignored because health service is shutdown", service, status); return; } if let Some(val) = inner.statu...
identifier_body
service.rs
use futures_util::{FutureExt as _, SinkExt as _, Stream, StreamExt as _}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, ServerStreamingSink, UnarySink, WriteFlags}; use log::info; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::pin::Pin; use std::sync::atomic::{AtomicUsize, Ordering}...
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. use crate::proto::{Health, HealthCheckRequest, HealthCheckResponse, ServingStatus};
random_line_split
service.rs
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. use crate::proto::{Health, HealthCheckRequest, HealthCheckResponse, ServingStatus}; use futures_util::{FutureExt as _, SinkExt as _, Stream, StreamExt as _}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, ServerStreamingSink, UnarySink, WriteFlags}...
} Poll::Pending } } impl Drop for StatusSubscriber { fn drop(&mut self) { let mut subscribers = self.cast.subscribers.lock().unwrap(); subscribers.remove(&self.id); } } #[derive(Default)] struct Inner { id: u64, shutdown: bool, status: HashMap<String, ServingSt...
{ v.insert(cx.waker().clone()); }
conditional_block
service.rs
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0. use crate::proto::{Health, HealthCheckRequest, HealthCheckResponse, ServingStatus}; use futures_util::{FutureExt as _, SinkExt as _, Stream, StreamExt as _}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, ServerStreamingSink, UnarySink, WriteFlags}...
( &mut self, ctx: RpcContext, req: HealthCheckRequest, sink: UnarySink<HealthCheckResponse>, ) { let status = { let inner = self.inner.lock().unwrap(); inner.status.get(&req.service).cloned() }; if let Some(status) = status { ...
check
identifier_name
percentage.rs
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ //! Computed percentages. use std::fmt; use style_traits::{CssWriter, ToCss}; use values::{serialize_percentage, ...
/// A wrapper over a `Percentage`, whose value should be clamped to 0. pub type NonNegativePercentage = NonNegative<Percentage>; impl NonNegativePercentage { /// 0% #[inline] pub fn zero() -> Self { NonNegative(Percentage::zero()) } /// 100% #[inline] pub fn hundred() -> Self { ...
W: fmt::Write, { serialize_percentage(self.0, dest) } }
random_line_split
percentage.rs
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ //! Computed percentages. use std::fmt; use style_traits::{CssWriter, ToCss}; use values::{serialize_percentage, ...
() -> Self { Percentage(1.) } /// Returns the absolute value for this percentage. #[inline] pub fn abs(&self) -> Self { Percentage(self.0.abs()) } /// Clamps this percentage to a non-negative percentage. #[inline] pub fn clamp_to_non_negative(self) -> Self { Per...
hundred
identifier_name
percentage.rs
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ //! Computed percentages. use std::fmt; use style_traits::{CssWriter, ToCss}; use values::{serialize_percentage, ...
#[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { NonNegative(animated.clamp_to_non_negative()) } }
{ self.0 }
identifier_body
single_threaded.rs
#![deny(warnings)] extern crate futures; extern crate hyper; extern crate pretty_env_logger; extern crate tokio; use std::cell::Cell; use std::rc::Rc; use hyper::{Body, Response, Server}; use hyper::service::service_fn_ok; use hyper::rt::Future; use tokio::runtime::current_thread; fn main()
// to configure an Executor that can spawn!Send futures... let exec = current_thread::TaskExecutor::current(); let server = Server::bind(&addr) .executor(exec) .serve(new_service) .map_err(|e| eprintln!("server error: {}", e)); println!("Listening on http://{}", addr); curren...
{ pretty_env_logger::init(); let addr = ([127, 0, 0, 1], 3000).into(); // Using a !Send request counter is fine on 1 thread... let counter = Rc::new(Cell::new(0)); let new_service = move || { // For each connection, clone the counter to use in our service... let cnt = counter.clon...
identifier_body
single_threaded.rs
#![deny(warnings)] extern crate futures; extern crate hyper; extern crate pretty_env_logger; extern crate tokio; use std::cell::Cell; use std::rc::Rc; use hyper::{Body, Response, Server}; use hyper::service::service_fn_ok; use hyper::rt::Future; use tokio::runtime::current_thread; fn
() { pretty_env_logger::init(); let addr = ([127, 0, 0, 1], 3000).into(); // Using a!Send request counter is fine on 1 thread... let counter = Rc::new(Cell::new(0)); let new_service = move || { // For each connection, clone the counter to use in our service... let cnt = counter.cl...
main
identifier_name
single_threaded.rs
#![deny(warnings)] extern crate futures; extern crate hyper; extern crate pretty_env_logger; extern crate tokio; use std::cell::Cell; use std::rc::Rc; use hyper::{Body, Response, Server}; use hyper::service::service_fn_ok; use hyper::rt::Future; use tokio::runtime::current_thread; fn main() { pretty_env_logger::...
let exec = current_thread::TaskExecutor::current(); let server = Server::bind(&addr) .executor(exec) .serve(new_service) .map_err(|e| eprintln!("server error: {}", e)); println!("Listening on http://{}", addr); current_thread::Runtime::new() .expect("rt new") .spawn...
random_line_split
mod.rs
use crate::resource::IResource; use com_wrapper::ComWrapper; use winapi::um::d2d1::{ID2D1Image, ID2D1Resource}; use wio::com::ComPtr; pub use self::bitmap::{Bitmap, IBitmap}; pub use self::bitmap1::{Bitmap1, IBitmap1}; pub mod bitmap; pub mod bitmap1; #[repr(transparent)] #[derive(ComWrapper)] #[com(send, sync, deb...
{ ptr: ComPtr<ID2D1Image>, } pub unsafe trait IImage: IResource { unsafe fn raw_img(&self) -> &ID2D1Image; } unsafe impl IResource for Image { unsafe fn raw_resource(&self) -> &ID2D1Resource { &self.ptr } } unsafe impl IImage for Image { unsafe fn raw_img(&self) -> &ID2D1Image { ...
Image
identifier_name
mod.rs
use crate::resource::IResource; use com_wrapper::ComWrapper; use winapi::um::d2d1::{ID2D1Image, ID2D1Resource}; use wio::com::ComPtr; pub use self::bitmap::{Bitmap, IBitmap}; pub use self::bitmap1::{Bitmap1, IBitmap1}; pub mod bitmap; pub mod bitmap1; #[repr(transparent)] #[derive(ComWrapper)] #[com(send, sync, deb...
unsafe fn raw_img(&self) -> &ID2D1Image { &self.ptr } }
random_line_split
oop.rs
/// Ordinary object pointers and memory layouts. /// (I did try to come up with a better name but failed.) use super::gc::INFO_FRESH_TAG; use super::stackmap::OopStackMapOffsets; use ast::id::Id; use std::slice; use std::ptr; use std::ops::{Deref, DerefMut}; use std::marker::PhantomData; use std::mem::{size_of, trans...
pub fn new(ptr_payloads: u16, word_payloads: u16, arity: u16, kind: OopKind, name: &str) -> Self { InfoTable { ptr_payloads: ptr_payloads, word_payloads: word_payloads, arity: arity, ...
{ replace(self, o); }
identifier_body
oop.rs
/// Ordinary object pointers and memory layouts. /// (I did try to come up with a better name but failed.) use super::gc::INFO_FRESH_TAG; use super::stackmap::OopStackMapOffsets; use ast::id::Id; use std::slice; use std::ptr; use std::ops::{Deref, DerefMut}; use std::marker::PhantomData; use std::mem::{size_of, trans...
(&self) -> *mut OopHandle { self as *const _ as *const _ as *mut _ } unsafe fn new(oop: *mut A, head: &OopHandle) -> Box<Self> { let thiz = Box::new(RawHandle { oop: oop as Oop, prev: head.prev, next: head.as_ptr(), phantom_data: PhantomData, ...
as_ptr
identifier_name
oop.rs
/// Ordinary object pointers and memory layouts. /// (I did try to come up with a better name but failed.) use super::gc::INFO_FRESH_TAG; use super::stackmap::OopStackMapOffsets; use ast::id::Id; use std::slice; use std::ptr; use std::ops::{Deref, DerefMut}; use std::marker::PhantomData; use std::mem::{size_of, trans...
pub fn gc_mark_word(&self) -> &mut usize { unsafe { &mut *self.gc_mark_word.get() } } pub fn name(&self) -> &str { &*self.name.as_ref().unwrap() } pub unsafe fn from_entry<'a>(entry: usize) -> &'a mut Self { &mut *((entry - size_of::<Self>()) as *mut _) } pub fn e...
random_line_split
hash.rs
// Copyright 2015-2017 Parity Technologies // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except ...
assert_eq!(H128::from(0x1234567890abcdef), H128::from_str("00000000000000001234567890abcdef").unwrap()); assert_eq!(H64::from(0x1234567890abcdef), H64::from_str("1234567890abcdef").unwrap()); assert_eq!(H32::from(0x1234567890abcdef), H32::from_str("90abcdef").unwrap()); } #[test] fn from_str() { assert_eq!...
_u64() {
identifier_name
hash.rs
// Copyright 2015-2017 Parity Technologies // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except ...
else { s } } macro_rules! impl_hash { ($from: ident, $size: expr) => { #[repr(C)] /// Unformatted binary data of fixed length. pub struct $from (pub [u8; $size]); impl From<[u8; $size]> for $from { fn from(bytes: [u8; $size]) -> Self { $from(bytes) } } impl From<$from> for [u8; $size] { ...
{ &s[2..] }
conditional_block
hash.rs
// Copyright 2015-2017 Parity Technologies // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except ...
impl From<H256> for U256 { fn from(value: H256) -> U256 { U256::from(&value) } } impl<'a> From<&'a H256> for U256 { fn from(value: &'a H256) -> U256 { U256::from(value.as_ref() as &[u8]) } } impl From<H256> for H160 { fn from(value: H256) -> H160 { let mut ret = H160::new(); ret.0.copy_from_slice(&valu...
let mut ret: H256 = H256::new(); value.to_big_endian(&mut ret); ret } }
identifier_body
hash.rs
// Copyright 2015-2017 Parity Technologies // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except ...
let mut ret = H256::new(); ret.0[12..32].copy_from_slice(value); ret } } impl_hash!(H32, 4); impl_hash!(H64, 8); impl_hash!(H128, 16); impl_hash!(H160, 20); impl_hash!(H256, 32); impl_hash!(H264, 33); impl_hash!(H512, 64); impl_hash!(H520, 65); impl_hash!(H1024, 128); impl_hash!(H2048, 256); known_heap_size!(0...
impl<'a> From<&'a H160> for H256 { fn from(value: &'a H160) -> H256 {
random_line_split
problem11.rs
// In the 20×20 grid below, four numbers along a diagonal line have been marked in red. // The product of these numbers is 26 × 63 × 78 × 14 = 1788696. // // What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? fn main() { let range =...
check_horizontal(vals: &[[i64; 20]; 20], row: usize, col: usize, range: usize, curr_max: &mut i64) { if col <= vals[row].len() - range { let mut product: i64 = 1; for i in 0..range { product *= vals[col + i][row]; } if product > *curr_max { *curr_max = product...
if row <= vals.len() - range { let mut product: i64 = 1; for i in 0..range { product *= vals[col][row + i]; } if product > *curr_max { *curr_max = product; } } } fn
identifier_body
problem11.rs
// In the 20×20 grid below, four numbers along a diagonal line have been marked in red. // The product of these numbers is 26 × 63 × 78 × 14 = 1788696. // // What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? fn main() { let range =...
let mut product: i64 = 1; for i in 0..range { product *= vals[col + i][row - i]; } if product > *curr_max { *curr_max = product; } } } fn check_diagonal_right(vals: &[[i64; 20]; 20], row: usize, col: usize, range: usize, curr_max: &mut i64) { if r...
} } fn check_diagonal_left(vals: &[[i64; 20]; 20], row: usize, col: usize, range: usize, curr_max: &mut i64) { if col <= vals.len() - range && row >= range {
random_line_split
problem11.rs
// In the 20×20 grid below, four numbers along a diagonal line have been marked in red. // The product of these numbers is 26 × 63 × 78 × 14 = 1788696. // // What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? fn main() { let range =...
: &[[i64; 20]; 20], row: usize, col: usize, range: usize, curr_max: &mut i64) { if col <= vals.len() - range && row >= range { let mut product: i64 = 1; for i in 0..range { product *= vals[col + i][row - i]; } if product > *curr_max { *curr_max = product; ...
_diagonal_left(vals
identifier_name
problem11.rs
// In the 20×20 grid below, four numbers along a diagonal line have been marked in red. // The product of these numbers is 26 × 63 × 78 × 14 = 1788696. // // What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? fn main() { let range =...
n check_diagonal_right(vals: &[[i64; 20]; 20], row: usize, col: usize, range: usize, curr_max: &mut i64) { if row <= vals[col].len() - range && col <= vals.len() - range { let mut product: i64 = 1; for i in 0..range { product *= vals[col + i][row + i]; } if product > *cur...
let mut product: i64 = 1; for i in 0..range { product *= vals[col + i][row - i]; } if product > *curr_max { *curr_max = product; } } } f
conditional_block
borrowck-loan-of-static-data-issue-27616.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
fn evil(mut s: &'static mut String) { // create alias let alias: &'static mut String = s; let inner: &str = &alias; // free value *s = String::new(); //~ ERROR cannot assign let _spray = "0wned".to_owned(); //... and then use it println!("{}", inner); } fn main() { evil(leak(Box::...
{ // isn't this supposed to be safe? let inner = &mut *b as *mut _; mem::forget(b); unsafe { &mut *inner } }
identifier_body
borrowck-loan-of-static-data-issue-27616.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
<T>(mut b: Box<T>) -> &'static mut T { // isn't this supposed to be safe? let inner = &mut *b as *mut _; mem::forget(b); unsafe { &mut *inner } } fn evil(mut s: &'static mut String) { // create alias let alias: &'static mut String = s; let inner: &str = &alias; // free value *s = St...
leak
identifier_name
borrowck-loan-of-static-data-issue-27616.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
} fn evil(mut s: &'static mut String) { // create alias let alias: &'static mut String = s; let inner: &str = &alias; // free value *s = String::new(); //~ ERROR cannot assign let _spray = "0wned".to_owned(); //... and then use it println!("{}", inner); } fn main() { evil(leak(Box:...
fn leak<T>(mut b: Box<T>) -> &'static mut T { // isn't this supposed to be safe? let inner = &mut *b as *mut _; mem::forget(b); unsafe { &mut *inner }
random_line_split
main.rs
/* Aurélien DESBRIÈRES aurelien(at)hackers(dot)camp License GNU GPL latest */ // Rust experimentations // Iterator in Rust fn ma
{ let vec1 = vec![1, 2, 3]; let vec2 = vec![4, 5, 6]; // `iter()` for vec yields `&i32, Destructure to `i32` println!("2 in vec1: {}", vec1.iter() .any(|&x| x == 2)); // `into_iter()` for vecs yields `i32`, No destructuring required, println!("2 in vec2: {}", vec2.into_iter().any(| x| x == ...
in()
identifier_name
main.rs
/* Aurélien DESBRIÈRES aurelien(at)hackers(dot)camp License GNU GPL latest */ // Rust experimentations // Iterator in Rust fn main() {
let vec1 = vec![1, 2, 3]; let vec2 = vec![4, 5, 6]; // `iter()` for vec yields `&i32, Destructure to `i32` println!("2 in vec1: {}", vec1.iter() .any(|&x| x == 2)); // `into_iter()` for vecs yields `i32`, No destructuring required, println!("2 in vec2: {}", vec2.into_iter().any(| x| x == 2)...
identifier_body
main.rs
/* Aurélien DESBRIÈRES aurelien(at)hackers(dot)camp License GNU GPL latest */ // Rust experimentations // Iterator in Rust fn main() { let vec1 = vec![1, 2, 3]; let vec2 = vec![4, 5, 6]; // `iter()` for vec yields `&i32, Destructure to `i32` println!("2 in vec1: {}", vec1.iter() .any(|&x| x == 2))...
println!("2 in array1: {}", array1.iter() .any(|&x| x == 2)); // `into_iter()` for arrays unnusually yields `&i32` println!("2 in array2; {}", array2.into_iter().any(|&x| x == 2)); }
random_line_split
const-vecs-and-slices.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
{ println!("{}", x[1]); println!("{}", y[1]); println!("{}", z[1]); println!("{}", zz[1]); assert_eq!(x[1], 2); assert_eq!(x[3], 4); assert_eq!(x[3], y[3]); assert_eq!(z[1], 2); assert_eq!(z[3], 4); assert_eq!(z[3], y[3]); assert_eq!(zz[1], 2); assert_eq!(zz[3], 4); a...
identifier_body
const-vecs-and-slices.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
static z : &'static [isize; 4] = &[1,2,3,4]; static zz : &'static [isize] = &[1,2,3,4]; pub fn main() { println!("{}", x[1]); println!("{}", y[1]); println!("{}", z[1]); println!("{}", zz[1]); assert_eq!(x[1], 2); assert_eq!(x[3], 4); assert_eq!(x[3], y[3]); assert_eq!(z[1], 2); ass...
// option. This file may not be copied, modified, or distributed // except according to those terms. static x : [isize; 4] = [1,2,3,4]; static y : &'static [isize] = &[1,2,3,4];
random_line_split
const-vecs-and-slices.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
() { println!("{}", x[1]); println!("{}", y[1]); println!("{}", z[1]); println!("{}", zz[1]); assert_eq!(x[1], 2); assert_eq!(x[3], 4); assert_eq!(x[3], y[3]); assert_eq!(z[1], 2); assert_eq!(z[3], 4); assert_eq!(z[3], y[3]); assert_eq!(zz[1], 2); assert_eq!(zz[3], 4); ...
main
identifier_name
totaleq.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
const_nonmatching: true, combine_substructure: cs_equals } ] }; trait_def.expand(mitem, in_items) }
explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~["bool"])), inline: true,
random_line_split
lock.rs
// Zinc, the bare metal stack for rust. // Copyright 2014 Ben Gamari <bgamari@gmail.com> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2...
<'a>(&'a self) { unsafe { let crit = NoInterrupts::new(); *self.locked.get() = false; } } } #[unsafe_destructor] impl<'a> Drop for Guard<'a> { fn drop(&mut self) { let &Guard(ref lock) = self; lock.unlock(); } } impl Share for Lock { }
unlock
identifier_name
lock.rs
// Zinc, the bare metal stack for rust. // Copyright 2014 Ben Gamari <bgamari@gmail.com> //
// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language govern...
// Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at //
random_line_split
lock.rs
// Zinc, the bare metal stack for rust. // Copyright 2014 Ben Gamari <bgamari@gmail.com> // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2...
} } } fn unlock<'a>(&'a self) { unsafe { let crit = NoInterrupts::new(); *self.locked.get() = false; } } } #[unsafe_destructor] impl<'a> Drop for Guard<'a> { fn drop(&mut self) { let &Guard(ref lock) = self; lock.unlock(); } } impl Share for Lock { }
{ *locked = true; return Some(Guard(self)); }
conditional_block
variadic-ffi.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
check("42 42.500000 a %d %f %c %s\n\n", |s| { sprintf(s, c.as_ptr(), 42i, 42.5f64, 'a' as c_int, c.as_ptr()); }); // Make a function pointer let x: unsafe extern fn(*mut c_char, *const c_char,...) -> c_int = sprintf; // A function that takes a function pointer ...
// Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n");
random_line_split
variadic-ffi.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
() { unsafe { // Call with just the named parameter let c = CString::from_slice(b"Hello World\n"); check("Hello World\n", |s| sprintf(s, c.as_ptr())); // Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n"); check("42 42.500000 a %d %...
main
identifier_name
variadic-ffi.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
check("Hello World\n", |s| sprintf(s, c.as_ptr())); // Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n"); check("42 42.500000 a %d %f %c %s\n\n", |s| { sprintf(s, c.as_ptr(), 42i, 42.5f64, 'a' as c_int, c.as_ptr()); ...
{ unsafe { // Call with just the named parameter let c = CString::from_slice(b"Hello World\n"); check("Hello World\n", |s| sprintf(s, c.as_ptr())); // Call with variable number of arguments let c = CString::from_slice(b"%d %f %c %s\n"); check("42 42.500000 a %d %f %...
identifier_body
trait-bounds-on-structs-and-enums-xc1.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
{ let foo = Foo { //~^ ERROR not implemented x: 3i }; let bar: Bar<f64> = return; //~^ ERROR not implemented let _ = bar; }
identifier_body
trait-bounds-on-structs-and-enums-xc1.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT.
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // aux-build:trait_bounds_on_structs_and_enums_xc.rs extern crate trait_bounds_on_structs_and_enums_xc; use trait_bounds_on_structs_and_enums_xc::{Bar, ...
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
random_line_split
trait-bounds-on-structs-and-enums-xc1.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
() { let foo = Foo { //~^ ERROR not implemented x: 3i }; let bar: Bar<f64> = return; //~^ ERROR not implemented let _ = bar; }
main
identifier_name
issue-21726.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at
// option. This file may not be copied, modified, or distributed // except according to those terms. // Regression test for #21726: an issue arose around the rules for // subtyping of projection types that resulted in an unconstrained // region, yielding region inference failures. fn main() { } fn foo<'a>(s: &'a str...
// http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
random_line_split
issue-21726.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
(&self) -> P::T { self.0.clone() } }
get_short
identifier_name
issue-21726.rs
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
} struct B<'a, P: IntoRef<'a>>(P::T); impl<'a, P: IntoRef<'a>> B<'a, P> { fn new(s: &'a str, i: P) -> B<'a, P> { B(i.into_ref(s)) } fn get_short(&self) -> P::T { self.0.clone() } }
{ s }
identifier_body
lib.rs
/* * Copyright (c) 2018 Boucher, Antoni <bouanto@zoho.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy,...
<W: Clone + IsA<Object> + IsA<Widget> + WidgetExt + IsA<W>>(widget: &W) { wait_for_draw(widget, || { let allocation = widget.allocation(); mouse_move(widget, allocation.width() / 2, allocation.height() / 2); wait_for_relm_events(); }); } pub fn double_click<W: Clone + IsA<Object> + IsA...
mouse_move_to
identifier_name
lib.rs
/* * Copyright (c) 2018 Boucher, Antoni <bouanto@zoho.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy,...
} pub fn double_click<W: Clone + IsA<Object> + IsA<Widget> + WidgetExt>(widget: &W) { wait_for_draw(widget, || { let observer = gtk_observer_new!(widget, connect_button_release_event, |_, _| { Inhibit(false) }); let allocation = widget.allocation(); mouse_move(widget, al...
});
random_line_split
lib.rs
/* * Copyright (c) 2018 Boucher, Antoni <bouanto@zoho.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy,...
, } }
{ if let Some(char) = key.to_unicode() { Layout(char) } else { Raw(*key as u16) } }
conditional_block
lib.rs
/* * Copyright (c) 2018 Boucher, Antoni <bouanto@zoho.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy,...
pub fn key_release<W: Clone + IsA<Object> + IsA<Widget> + WidgetExt>(widget: &W, key: Key) { wait_for_draw(widget, || { let observer = gtk_observer_new!(widget, connect_key_release_event, |_, _| { Inhibit(false) }); focus(widget); let mut enigo = Enigo::new(); e...
{ wait_for_draw(widget, || { let observer = gtk_observer_new!(widget, connect_key_press_event, |_, _| { Inhibit(false) }); focus(widget); let mut enigo = Enigo::new(); enigo.key_down(gdk_key_to_enigo_key(key)); observer.wait(); wait_for_relm_event...
identifier_body
trainer.rs
extern crate csv; extern crate getopts; extern crate gnuplot; use gnuplot::{Figure, Caption, Color}; use getopts::Options; use std::f32; mod common; fn train_thetas(learn_rate: f32, theta0: f32, theta1: f32, norm_data: &Vec<(f32, f32)>) -> (f32, f32) { let m = norm_data.len() as f32; let mut...
(file: &str, min: f32, max: f32) { let mut wtr = csv::Writer::from_file(file).unwrap(); let result = wtr.encode(("min", "max")); assert!(result.is_ok()); let result = wtr.encode((min, max)); assert!(result.is_ok()); } fn min_tuple0(data: &Vec<(f32, f32)>) -> f32 { let mut ret = f32::MAX; ...
save_min_max
identifier_name
trainer.rs
extern crate csv; extern crate getopts; extern crate gnuplot; use gnuplot::{Figure, Caption, Color}; use getopts::Options; use std::f32; mod common; fn train_thetas(learn_rate: f32, theta0: f32, theta1: f32, norm_data: &Vec<(f32, f32)>) -> (f32, f32) { let m = norm_data.len() as f32; let mut...
fn min_tuple0(data: &Vec<(f32, f32)>) -> f32 { let mut ret = f32::MAX; for &(val, _) in data { if val < ret { ret = val; } } ret } fn max_tuple0(data: &Vec<(f32, f32)>) -> f32 { let mut ret = f32::MIN; for &(val, _) in data { if val > ret { re...
{ let mut wtr = csv::Writer::from_file(file).unwrap(); let result = wtr.encode(("min", "max")); assert!(result.is_ok()); let result = wtr.encode((min, max)); assert!(result.is_ok()); }
identifier_body
trainer.rs
extern crate csv; extern crate getopts; extern crate gnuplot; use gnuplot::{Figure, Caption, Color}; use getopts::Options; use std::f32; mod common; fn train_thetas(learn_rate: f32, theta0: f32, theta1: f32, norm_data: &Vec<(f32, f32)>) -> (f32, f32) { let m = norm_data.len() as f32; let mut...
let mut wtr = csv::Writer::from_file(file).unwrap(); let result = wtr.encode(("min", "max")); assert!(result.is_ok()); let result = wtr.encode((min, max)); assert!(result.is_ok()); } fn min_tuple0(data: &Vec<(f32, f32)>) -> f32 { let mut ret = f32::MAX; for &(val, _) in data { i...
assert!(result.is_ok()); } fn save_min_max(file: &str, min: f32, max: f32) {
random_line_split
trainer.rs
extern crate csv; extern crate getopts; extern crate gnuplot; use gnuplot::{Figure, Caption, Color}; use getopts::Options; use std::f32; mod common; fn train_thetas(learn_rate: f32, theta0: f32, theta1: f32, norm_data: &Vec<(f32, f32)>) -> (f32, f32) { let m = norm_data.len() as f32; let mut...
Err(f) => { panic!(f.to_string()) } }; if matches.opt_present("h") { print_usage(&program, opts); return; } let filename = matches.opt_str("d").unwrap(); let mut rdr = csv::Reader::from_file(filename).unwrap(); let data = rdr.decode().collect::<csv::Result<Vec<(f32, f3...
{ m }
conditional_block
tcp-accept-stress.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
test(); let (tx, rx) = channel(); TaskBuilder::new().native().spawn(proc() { tx.send(test()); }); rx.recv(); } fn test() { let mut l = TcpListener::bind("127.0.0.1", 0).unwrap(); let addr = l.socket_name().unwrap(); let mut a = l.listen().unwrap(); let cnt = Arc::new(atomic...
green_start!(main) fn main() {
random_line_split
tcp-accept-stress.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
() { test(); let (tx, rx) = channel(); TaskBuilder::new().native().spawn(proc() { tx.send(test()); }); rx.recv(); } fn test() { let mut l = TcpListener::bind("127.0.0.1", 0).unwrap(); let addr = l.socket_name().unwrap(); let mut a = l.listen().unwrap(); let cnt = Arc::new(a...
main
identifier_name
tcp-accept-stress.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
} Err(ref e) if e.kind == EndOfFile => break, Err(e) => fail!("{}", e), } } srv_tx.send(()); }); } for _ in range(0, N) { let cli_tx = cli_tx.clone(); spawn(proc() { for _ in ...
{ let mut l = TcpListener::bind("127.0.0.1", 0).unwrap(); let addr = l.socket_name().unwrap(); let mut a = l.listen().unwrap(); let cnt = Arc::new(atomic::AtomicUint::new(0)); let (srv_tx, srv_rx) = channel(); let (cli_tx, cli_rx) = channel(); for _ in range(0, N) { let a = a.clone(...
identifier_body
error.rs
// Copyright (c) 2015, The Radare Project. All rights reserved. // See the COPYING file at the top-level directory of this distribution. // Licensed under the BSD 3-Clause License: // <http://opensource.org/licenses/BSD-3-Clause> // This file may not be copied, modified, or distributed // except according to those term...
SSAErr::InvalidType(ref e) => { format!("Expected type: {}.", e) } SSAErr::InvalidControl(bi, ei) => { format!("Block {:?} has invalid outgoing edge: {:?}", bi, ei) } SSAErr::WrongNumOperands(n, e, f) => { forma...
{ format!("Found Block with index: {:?}.", ni) }
conditional_block
error.rs
// Copyright (c) 2015, The Radare Project. All rights reserved. // See the COPYING file at the top-level directory of this distribution. // Licensed under the BSD 3-Clause License: // <http://opensource.org/licenses/BSD-3-Clause> // This file may not be copied, modified, or distributed // except according to those term...
(&self) -> Option<&error::Error> { None } }
cause
identifier_name
error.rs
// Copyright (c) 2015, The Radare Project. All rights reserved. // See the COPYING file at the top-level directory of this distribution. // Licensed under the BSD 3-Clause License: // <http://opensource.org/licenses/BSD-3-Clause> // This file may not be copied, modified, or distributed // except according to those term...
}
{ None }
identifier_body
error.rs
// Copyright (c) 2015, The Radare Project. All rights reserved. // See the COPYING file at the top-level directory of this distribution. // Licensed under the BSD 3-Clause License: // <http://opensource.org/licenses/BSD-3-Clause> // This file may not be copied, modified, or distributed // except according to those term...
} SSAErr::UnreachableBlock(bi) => { format!("Unreachable block found: {:?}", bi) } SSAErr::InvalidExpr(ni) => { format!("Found an invalid expression: {:?}", ni) } SSAErr::IncompatibleWidth(ni, e, f) => { ...
SSAErr::UnexpectedSelector(bi, ni) => { format!("Block {:?} expected no selector, found: {:?}", bi, ni)
random_line_split
num.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
/// A decimal (base 10) radix #[deriving(Clone, PartialEq)] struct Decimal; /// A hexadecimal (base 16) radix, formatted with lower-case characters #[deriving(Clone, PartialEq)] struct LowerHex; /// A hexadecimal (base 16) radix, formatted with upper-case characters #[deriving(Clone, PartialEq)] pub struct UpperHex;...
/// An octal (base 8) radix #[deriving(Clone, PartialEq)] struct Octal;
random_line_split
num.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
; // No more digits left to accumulate. } } else { // Do the same as above, but accounting for two's complement. for byte in buf.iter_mut().rev() { let n = zero - (x % base); // Get the current place value. x = ...
{ break }
conditional_block
num.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
(&self) -> &'static str { "" } /// Converts an integer to corresponding radix digit. fn digit(&self, x: u8) -> u8; /// Format an integer using the radix using a formatter. fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result { // The radix can be as low as 2, so we need a...
prefix
identifier_name
test_unistd.rs
extern crate tempdir; use nix::fcntl; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::wait::*; use nix::sys::stat; use std::{self, env, iter}; use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::unix::prelude::*; use tempfile::tempfile; use tempdir::TempDir; use libc::{_exit, o...
#[test] fn test_mkstemp_directory() { // mkstemp should fail if a directory is given assert!(mkstemp(&env::temp_dir()).is_err()); } #[test] fn test_mkfifo() { let tempdir = TempDir::new("nix-test_mkfifo").unwrap(); let mkfifo_fifo = tempdir.path().join("mkfifo_fifo"); mkfifo(&mkfifo_fifo, stat::...
{ let mut path = env::temp_dir(); path.push("nix_tempfile.XXXXXX"); let result = mkstemp(&path); match result { Ok((fd, path)) => { close(fd).unwrap(); unlink(path.as_path()).unwrap(); }, Err(e) => panic!("mkstemp failed: {}", e) } }
identifier_body
test_unistd.rs
extern crate tempdir; use nix::fcntl; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::wait::*; use nix::sys::stat; use std::{self, env, iter}; use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::unix::prelude::*; use tempfile::tempfile; use tempdir::TempDir; use libc::{_exit, o...
() { let pid: ::libc::pid_t = getpid().into(); let ppid: ::libc::pid_t = getppid().into(); assert!(pid > 0); assert!(ppid > 0); } #[cfg(any(target_os = "linux", target_os = "android"))] mod linux_android { use nix::unistd::gettid; #[test] fn test_gettid() { let tid: ::libc::pid_t =...
test_getpid
identifier_name
test_unistd.rs
extern crate tempdir; use nix::fcntl; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::wait::*; use nix::sys::stat; use std::{self, env, iter}; use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::unix::prelude::*; use tempfile::tempfile; use tempdir::TempDir; use libc::{_exit, o...
match fork().unwrap() { Child => { // Close stdout. close(1).unwrap(); // Make `writer` be the stdout of the new process. dup(writer).unwrap(); // exec! $syscall( $exe, ...
let (reader, writer) = pipe().unwrap(); // Safe: Child calls `exit`, `dup`, `close` and the provided `exec*` family function. // NOTE: Technically, this makes the macro unsafe to use because you could pass anything. // The tests make sure not to do that, though.
random_line_split
item.rs
use std::any::Any; use std::any::TypeId; use std::fmt; use std::str::from_utf8; use typeable::Typeable; use super::cell::{OptCell, PtrMapCell}; use header::{Header, HeaderFormat}; #[derive(Clone)] pub struct Item { raw: OptCell<Vec<Vec<u8>>>, typed: PtrMapCell<HeaderFormat + Send + Sync> } impl Item { ...
#[inline] pub fn mut_raw(&mut self) -> &mut Vec<Vec<u8>> { self.typed = PtrMapCell::new(); unsafe { self.raw.get_mut() } } pub fn raw(&self) -> &[Vec<u8>] { if let Some(ref raw) = *self.raw { return &raw[..]; } let raw = vec![un...
{ let map = PtrMapCell::new(); unsafe { map.insert((*ty).get_type(), ty); } Item { raw: OptCell::new(None), typed: map, } }
identifier_body
item.rs
use std::any::Any; use std::any::TypeId; use std::fmt; use std::str::from_utf8; use typeable::Typeable; use super::cell::{OptCell, PtrMapCell}; use header::{Header, HeaderFormat}; #[derive(Clone)] pub struct Item { raw: OptCell<Vec<Vec<u8>>>, typed: PtrMapCell<HeaderFormat + Send + Sync> } impl Item { ...
<H: Header + HeaderFormat + Any>(&self) -> Option<&H> { let tid = TypeId::of::<H>(); match self.typed.get(tid) { Some(val) => Some(val), None => { match parse::<H>(self.raw.as_ref().expect("item.raw must exist")) { Ok(typed) => { ...
typed
identifier_name
item.rs
use std::any::Any; use std::any::TypeId; use std::fmt; use std::str::from_utf8; use typeable::Typeable; use super::cell::{OptCell, PtrMapCell}; use header::{Header, HeaderFormat}; #[derive(Clone)] pub struct Item { raw: OptCell<Vec<Vec<u8>>>, typed: PtrMapCell<HeaderFormat + Send + Sync> } impl Item { ...
#[inline] fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> ::Result<Box<HeaderFormat + Send + Sync>> { Header::parse_header(&raw[..]).map(|h: H| { // FIXME: Use Type ascription let h: Box<HeaderFormat + Send + Sync> = Box::new(h); h }) } impl fmt::Display for Item { fn fmt...
self.typed.get_mut(tid).map(|typed| unsafe { typed.downcast_mut_unchecked() }) } }
random_line_split
expr-match-generic.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
(t1: Pair, t2: Pair) -> bool { t1.a == t2.a && t1.b == t2.b } test_generic::<Pair>(Pair {a: 1, b: 2}, compare_rec); } pub fn main() { test_bool(); test_rec(); }
compare_rec
identifier_name
expr-match-generic.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
#[deriving(Clone)] struct Pair { a: int, b: int, } fn test_rec() { fn compare_rec(t1: Pair, t2: Pair) -> bool { t1.a == t2.a && t1.b == t2.b } test_generic::<Pair>(Pair {a: 1, b: 2}, compare_rec); } pub fn main() { test_bool(); test_rec(); }
{ fn compare_bool(b1: bool, b2: bool) -> bool { return b1 == b2; } test_generic::<bool>(true, compare_bool); }
identifier_body
expr-match-generic.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT.
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. // xfail-fast //...
random_line_split
issue-85454.rs
// aux-build:issue-85454.rs // build-aux-docs #![crate_name = "foo"] extern crate issue_85454; // @has foo/trait.FromResidual.html // @has - '//pre[@class="rust trait"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }' pub trait FromResidual<R = <Self as Try>::Residual>...
Break(B), } pub mod reexport { // @has foo/reexport/trait.FromResidual.html // @has - '//pre[@class="rust trait"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }' pub use issue_85454::*; }
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>; } pub enum ControlFlow<B, C = ()> { Continue(C),
random_line_split
issue-85454.rs
// aux-build:issue-85454.rs // build-aux-docs #![crate_name = "foo"] extern crate issue_85454; // @has foo/trait.FromResidual.html // @has - '//pre[@class="rust trait"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }' pub trait FromResidual<R = <Self as Try>::Residual>...
<B, C = ()> { Continue(C), Break(B), } pub mod reexport { // @has foo/reexport/trait.FromResidual.html // @has - '//pre[@class="rust trait"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }' pub use issue_85454::*; }
ControlFlow
identifier_name
idcode.rs
use std::fmt::{self, Display}; use std::str::FromStr; use crate::InvalidData; /// An ID used within the file to refer to a particular variable. #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct IdCode(u64); const ID_CHAR_MIN: u8 = b'!'; const ID_CHAR_MAX: u8 = b'~'; const NUM_ID_CHARS: u...
"n999999999" ); assert!("n9999999999".parse::<IdCode>().is_err()); }
{ let mut id = IdCode::FIRST; for i in 0..10000 { println!("{} {}", i, id); assert_eq!(id.to_string().parse::<IdCode>().unwrap(), id); id = id.next(); } assert_eq!("!".parse::<IdCode>().unwrap().to_string(), "!"); assert_eq!( "!!!!!!!!!!".parse::<IdCode>().unwrap().t...
identifier_body
idcode.rs
use std::fmt::{self, Display}; use std::str::FromStr; use crate::InvalidData; /// An ID used within the file to refer to a particular variable. #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct IdCode(u64); const ID_CHAR_MIN: u8 = b'!'; const ID_CHAR_MAX: u8 = b'~'; const NUM_ID_CHARS: u...
(s: &str) -> Result<Self, Self::Err> { IdCode::new(s.as_bytes()) } } impl From<u32> for IdCode { fn from(i: u32) -> IdCode { IdCode(i as u64) } } impl From<u64> for IdCode { fn from(i: u64) -> IdCode { IdCode(i) } } impl Display for IdCode { fn fmt(&self, f: &mut fmt::...
from_str
identifier_name
idcode.rs
use std::fmt::{self, Display}; use std::str::FromStr; use crate::InvalidData; /// An ID used within the file to refer to a particular variable. #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct IdCode(u64); const ID_CHAR_MIN: u8 = b'!'; const ID_CHAR_MAX: u8 = b'~'; const NUM_ID_CHARS: u...
let mut result = 0u64; for &i in v.iter().rev() { if i < ID_CHAR_MIN || i > ID_CHAR_MAX { return Err(InvalidData("invalid characters in ID")); } let c = ((i - ID_CHAR_MIN) as u64) + 1; result = result .checked_mul(NUM_ID_CHA...
{ return Err(InvalidData("ID cannot be empty")); }
conditional_block
idcode.rs
use std::fmt::{self, Display}; use std::str::FromStr; use crate::InvalidData; /// An ID used within the file to refer to a particular variable. #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] pub struct IdCode(u64); const ID_CHAR_MIN: u8 = b'!'; const ID_CHAR_MAX: u8 = b'~'; const NUM_ID_CHARS: u...
#[test] fn test_id_code() { let mut id = IdCode::FIRST; for i in 0..10000 { println!("{} {}", i, id); assert_eq!(id.to_string().parse::<IdCode>().unwrap(), id); id = id.next(); } assert_eq!("!".parse::<IdCode>().unwrap().to_string(), "!"); assert_eq!( "!!!!!!!!!!".p...
random_line_split
check_static_recursion.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
}, ast::ItemEnum(ref enum_def, ref generics) => { // We could process the whole enum, but handling the variants // with discriminant expressions one by one gives more specific, // less redundant output. for variant in &enum_def.vari...
ast::ItemStatic(..) | ast::ItemConst(..) => { let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span); recursion_visitor.visit_item(it);
random_line_split
check_static_recursion.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
(&mut self, ii: &'ast ast::ImplItem) { self.with_item_id_pushed(ii.id, |v| visit::walk_impl_item(v, ii)); } fn visit_expr(&mut self, e: &'ast ast::Expr) { match e.node { ast::ExprPath(..) => { match self.def_map.borrow().get(&e.id).map(|d| d.base_def) { ...
visit_impl_item
identifier_name
check_static_recursion.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
fn visit_impl_item(&mut self, ii: &'ast ast::ImplItem) { self.with_item_id_pushed(ii.id, |v| visit::walk_impl_item(v, ii)); } fn visit_expr(&mut self, e: &'ast ast::Expr) { match e.node { ast::ExprPath(..) => { match self.def_map.borrow().get(&e.id).map(|d| d.b...
{ self.with_item_id_pushed(ti.id, |v| visit::walk_trait_item(v, ti)); }
identifier_body
borrowck-loan-rcvr.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
fn c() { // Loaning @mut as & is considered legal due to dynamic checks... let q = @mut point {x: 3, y: 4}; q.impurem(); //...but we still detect errors statically when we can. q.blockm(|| { q.x = 10; //~ ERROR cannot assign }) } fn main() { }
{ let mut p = point {x: 3, y: 4}; // Here I create an outstanding loan and check that we get conflicts: let l = &mut p; p.impurem(); //~ ERROR cannot borrow l.x += 1; }
identifier_body
borrowck-loan-rcvr.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
{ x: int, y: int } trait methods { fn impurem(&self); fn blockm(&self, f: ||); } impl methods for point { fn impurem(&self) { } fn blockm(&self, f: ||) { f() } } fn a() { let mut p = point {x: 3, y: 4}; // Here: it's ok to call even though receiver is mutable, because we // can loa...
point
identifier_name
borrowck-loan-rcvr.rs
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
}) } fn main() { }
q.blockm(|| { q.x = 10; //~ ERROR cannot assign
random_line_split
unreachable-in-call.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
() -> u8 { 1 } fn call(_: u8, _: u8) { } fn diverge_first() { call(diverge(), get_u8()); //~ ERROR unreachable expression } fn diverge_second() { call( //~ ERROR unreachable expression get_u8(), diverge()); } fn main() {}
get_u8
identifier_name
unreachable-in-call.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// option. This file may not be copied, modified, or distributed // except according to those terms. #![allow(dead_code)] #![deny(unreachable_code)] fn diverge() ->! { panic!() } fn get_u8() -> u8 { 1 } fn call(_: u8, _: u8) { } fn diverge_first() { call(diverge(), get_u8()); //~ ERROR unreachable ...
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
random_line_split
unreachable-in-call.rs
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or ...
fn diverge_first() { call(diverge(), get_u8()); //~ ERROR unreachable expression } fn diverge_second() { call( //~ ERROR unreachable expression get_u8(), diverge()); } fn main() {}
{ }
identifier_body
mod.rs
/* Copyright (C) 2017-2019 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free * Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY...
* version 2 along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ // written by Pierre Chifflier <chifflier@wzdftpd.net> extern crate snmp_parser; pub mod snmp; pub mod log; pub mod detect;
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License
random_line_split