Skip to content

Commit 88336ea

Browse files
author
Alexander Regueiro
committed
Cosmetic improvements
1 parent 2cf736f commit 88336ea

File tree

21 files changed

+144
-144
lines changed

21 files changed

+144
-144
lines changed

src/libcore/slice/memchr.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// Original implementation taken from rust-memchr
1+
// Original implementation taken from rust-memchr.
32
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
43

54
use cmp;
@@ -8,13 +7,13 @@ use mem;
87
const LO_U64: u64 = 0x0101010101010101;
98
const HI_U64: u64 = 0x8080808080808080;
109

11-
// use truncation
10+
// Use truncation.
1211
const LO_USIZE: usize = LO_U64 as usize;
1312
const HI_USIZE: usize = HI_U64 as usize;
1413

15-
/// Return `true` if `x` contains any zero byte.
14+
/// Returns whether `x` contains any zero byte.
1615
///
17-
/// From *Matters Computational*, J. Arndt
16+
/// From *Matters Computational*, J. Arndt:
1817
///
1918
/// "The idea is to subtract one from each of the bytes and then look for
2019
/// bytes where the borrow propagated all the way to the most significant
@@ -36,7 +35,7 @@ fn repeat_byte(b: u8) -> usize {
3635
(b as usize) * (::usize::MAX / 255)
3736
}
3837

39-
/// Return the first index matching the byte `x` in `text`.
38+
/// Returns the first index matching the byte `x` in `text`.
4039
pub fn memchr(x: u8, text: &[u8]) -> Option<usize> {
4140
// Scan for a single byte value by reading two `usize` words at a time.
4241
//
@@ -77,18 +76,18 @@ pub fn memchr(x: u8, text: &[u8]) -> Option<usize> {
7776
}
7877
}
7978

80-
// find the byte after the point the body loop stopped
79+
// Find the byte after the point the body loop stopped.
8180
text[offset..].iter().position(|elt| *elt == x).map(|i| offset + i)
8281
}
8382

84-
/// Return the last index matching the byte `x` in `text`.
83+
/// Returns the last index matching the byte `x` in `text`.
8584
pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
8685
// Scan for a single byte value by reading two `usize` words at a time.
8786
//
88-
// Split `text` in three parts
89-
// - unaligned tail, after the last word aligned address in text
90-
// - body, scan by 2 words at a time
91-
// - the first remaining bytes, < 2 word size
87+
// Split `text` in three parts:
88+
// - unaligned tail, after the last word aligned address in text,
89+
// - body, scanned by 2 words at a time,
90+
// - the first remaining bytes, < 2 word size.
9291
let len = text.len();
9392
let ptr = text.as_ptr();
9493
type Chunk = usize;
@@ -105,7 +104,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
105104
return Some(offset + index);
106105
}
107106

108-
// search the body of the text, make sure we don't cross min_aligned_offset.
107+
// Search the body of the text, make sure we don't cross min_aligned_offset.
109108
// offset is always aligned, so just testing `>` is sufficient and avoids possible
110109
// overflow.
111110
let repeated_x = repeat_byte(x);
@@ -116,7 +115,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
116115
let u = *(ptr.offset(offset as isize - 2 * chunk_bytes as isize) as *const Chunk);
117116
let v = *(ptr.offset(offset as isize - chunk_bytes as isize) as *const Chunk);
118117

119-
// break if there is a matching byte
118+
// Break if there is a matching byte.
120119
let zu = contains_zero_byte(u ^ repeated_x);
121120
let zv = contains_zero_byte(v ^ repeated_x);
122121
if zu || zv {
@@ -126,6 +125,6 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
126125
offset -= 2 * chunk_bytes;
127126
}
128127

129-
// find the byte before the point the body loop stopped
128+
// Find the byte before the point the body loop stopped.
130129
text[..offset].iter().rposition(|elt| *elt == x)
131130
}

src/libserialize/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Rust JSON serialization library
1+
// Rust JSON serialization library.
22
// Copyright (c) 2011 Google Inc.
33

44
#![forbid(non_camel_case_types)]

src/libstd/memchr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// Original implementation taken from rust-memchr
1+
// Original implementation taken from rust-memchr.
32
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
43

54
/// A safe interface to `memchr`.

src/libstd/sys/cloudabi/abi/cloudabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016-2017 Nuxi (https://nuxi.nl/) and contributors.
1+
// Copyright (c) 2016-2017 Nuxi <https://nuxi.nl/> and contributors.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions

src/libstd/sys/redox/memchr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// Original implementation taken from rust-memchr
1+
// Original implementation taken from rust-memchr.
32
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
43

54
pub use core::slice::memchr::{memchr, memrchr};

src/libstd/sys/unix/memchr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// Original implementation taken from rust-memchr
1+
// Original implementation taken from rust-memchr.
32
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
43

54
pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {

src/libstd/sys/windows/memchr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//
2-
// Original implementation taken from rust-memchr
1+
// Original implementation taken from rust-memchr.
32
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
43

5-
// Fallback memchr is fastest on windows
4+
// Fallback memchr is fastest on Windows.
65
pub use core::slice::memchr::{memchr, memrchr};

src/libsyntax/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! The format of the JSON output should be considered *unstable*. For now the
88
//! structs at the end of this file (Diagnostic*) specify the error format.
99
10-
// FIXME spec the JSON output properly.
10+
// FIXME: spec the JSON output properly.
1111

1212
use source_map::{SourceMap, FilePathMapping};
1313
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};

src/test/rustdoc/auxiliary/enum_primitive.rs

-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2020
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22-
2322
//! This crate exports a macro `enum_from_primitive!` that wraps an
2423
//! `enum` declaration and automatically adds an implementation of
2524
//! `num::FromPrimitive` (reexported here), to allow conversion from
@@ -52,7 +51,6 @@
5251
//! }
5352
//! ```
5453
55-
5654
pub mod num_traits {
5755
pub trait FromPrimitive: Sized {
5856
fn from_i64(n: i64) -> Option<Self>;
@@ -207,4 +205,3 @@ macro_rules! enum_from_primitive {
207205
enum_from_primitive_impl! { $name, $( $( $variant )+ )+ }
208206
};
209207
}
210-

src/tools/tidy/src/bins.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
//! by accident.
33
//!
44
//! In the past we've accidentally checked in test binaries and such which add a
5-
//! huge amount of bloat to the git history, so it's good to just ensure we
6-
//! don't do that again :)
5+
//! huge amount of bloat to the Git history, so it's good to just ensure we
6+
//! don't do that again.
77
88
use std::path::Path;
99

10-
// All files are executable on Windows, so just check on Unix
10+
// All files are executable on Windows, so just check on Unix.
1111
#[cfg(windows)]
1212
pub fn check(_path: &Path, _bad: &mut bool) {}
1313

src/tools/tidy/src/cargo.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn check(path: &Path, bad: &mut bool) {
1313
return
1414
}
1515
for entry in t!(path.read_dir(), path).map(|e| t!(e)) {
16-
// Look for `Cargo.toml` with a sibling `src/lib.rs` or `lib.rs`
16+
// Look for `Cargo.toml` with a sibling `src/lib.rs` or `lib.rs`.
1717
if entry.file_name().to_str() == Some("Cargo.toml") {
1818
if path.join("src/lib.rs").is_file() {
1919
verify(&entry.path(), &path.join("src/lib.rs"), bad)
@@ -27,8 +27,8 @@ pub fn check(path: &Path, bad: &mut bool) {
2727
}
2828
}
2929

30-
// Verify that the dependencies in Cargo.toml at `tomlfile` are sync'd with the
31-
// `extern crate` annotations in the lib.rs at `libfile`.
30+
/// Verifies that the dependencies in Cargo.toml at `tomlfile` are synced with
31+
/// the `extern crate` annotations in the lib.rs at `libfile`.
3232
fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
3333
let toml = t!(fs::read_to_string(&tomlfile));
3434
let librs = t!(fs::read_to_string(&libfile));
@@ -37,14 +37,16 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
3737
return
3838
}
3939

40-
// "Poor man's TOML parser", just assume we use one syntax for now
40+
// "Poor man's TOML parser" -- just assume we use one syntax for now.
4141
//
4242
// We just look for:
4343
//
44-
// [dependencies]
45-
// name = ...
46-
// name2 = ...
47-
// name3 = ...
44+
// ````
45+
// [dependencies]
46+
// name = ...
47+
// name2 = ...
48+
// name3 = ...
49+
// ```
4850
//
4951
// If we encounter a line starting with `[` then we assume it's the end of
5052
// the dependency section and bail out.
@@ -63,14 +65,14 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
6365
continue
6466
}
6567

66-
// Don't worry about depending on core/std but not saying `extern crate
67-
// core/std`, that's intentional.
68+
// Don't worry about depending on core/std while not writing `extern crate
69+
// core/std` -- that's intentional.
6870
if krate == "core" || krate == "std" {
6971
continue
7072
}
7173

72-
// This is intentional, this dependency just makes the crate available
73-
// for others later on. Cover cases
74+
// This is intentional -- this dependency just makes the crate available
75+
// for others later on.
7476
let whitelisted = krate.starts_with("panic");
7577
if toml.contains("name = \"std\"") && whitelisted {
7678
continue

src/tools/tidy/src/deps.rs

+27-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Check license of third-party deps by inspecting vendor
1+
//! Checks the licenses of third-party dependencies by inspecting vendors.
22
33
use std::collections::{BTreeSet, HashSet, HashMap};
44
use std::fs;
@@ -21,7 +21,7 @@ const LICENSES: &[&str] = &[
2121
/// These are exceptions to Rust's permissive licensing policy, and
2222
/// should be considered bugs. Exceptions are only allowed in Rust
2323
/// tooling. It is _crucial_ that no exception crates be dependencies
24-
/// of the Rust runtime (std / test).
24+
/// of the Rust runtime (std/test).
2525
const EXCEPTIONS: &[&str] = &[
2626
"mdbook", // MPL2, mdbook
2727
"openssl", // BSD+advertising clause, cargo, mdbook
@@ -39,11 +39,11 @@ const EXCEPTIONS: &[&str] = &[
3939
"colored", // MPL-2.0, rustfmt
4040
"ordslice", // Apache-2.0, rls
4141
"cloudabi", // BSD-2-Clause, (rls -> crossbeam-channel 0.2 -> rand 0.5)
42-
"ryu", // Apache-2.0, rls/cargo/... (b/c of serde)
42+
"ryu", // Apache-2.0, rls/cargo/... (because of serde)
4343
"bytesize", // Apache-2.0, cargo
4444
"im-rc", // MPL-2.0+, cargo
4545
"adler32", // BSD-3-Clause AND Zlib, cargo dep that isn't used
46-
"fortanix-sgx-abi", // MPL-2.0+, libstd but only for sgx target
46+
"fortanix-sgx-abi", // MPL-2.0+, libstd but only for `sgx` target
4747
];
4848

4949
/// Which crates to check against the whitelist?
@@ -156,7 +156,7 @@ const WHITELIST: &[Crate] = &[
156156
Crate("wincolor"),
157157
];
158158

159-
// Some types for Serde to deserialize the output of `cargo metadata` to...
159+
// Some types for Serde to deserialize the output of `cargo metadata` to.
160160

161161
#[derive(Deserialize)]
162162
struct Output {
@@ -174,9 +174,9 @@ struct ResolveNode {
174174
dependencies: Vec<String>,
175175
}
176176

177-
/// A unique identifier for a crate
177+
/// A unique identifier for a crate.
178178
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Hash)]
179-
struct Crate<'a>(&'a str); // (name,)
179+
struct Crate<'a>(&'a str); // (name)
180180

181181
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Hash)]
182182
struct CrateVersion<'a>(&'a str, &'a str); // (name, version)
@@ -188,7 +188,7 @@ impl<'a> Crate<'a> {
188188
}
189189

190190
impl<'a> CrateVersion<'a> {
191-
/// Returns the struct and whether or not the dep is in-tree
191+
/// Returns the struct and whether or not the dependency is in-tree.
192192
pub fn from_str(s: &'a str) -> (Self, bool) {
193193
let mut parts = s.split(' ');
194194
let name = parts.next().unwrap();
@@ -215,15 +215,15 @@ impl<'a> From<CrateVersion<'a>> for Crate<'a> {
215215
///
216216
/// Specifically, this checks that the license is correct.
217217
pub fn check(path: &Path, bad: &mut bool) {
218-
// Check licences
218+
// Check licences.
219219
let path = path.join("../vendor");
220220
assert!(path.exists(), "vendor directory missing");
221221
let mut saw_dir = false;
222222
for dir in t!(path.read_dir()) {
223223
saw_dir = true;
224224
let dir = t!(dir);
225225

226-
// skip our exceptions
226+
// Skip our exceptions.
227227
let is_exception = EXCEPTIONS.iter().any(|exception| {
228228
dir.path()
229229
.to_str()
@@ -240,18 +240,18 @@ pub fn check(path: &Path, bad: &mut bool) {
240240
assert!(saw_dir, "no vendored source");
241241
}
242242

243-
/// Checks the dependency of WHITELIST_CRATES at the given path. Changes `bad` to `true` if a check
244-
/// failed.
243+
/// Checks the dependency of `WHITELIST_CRATES` at the given path. Changes `bad` to `true` if a
244+
/// check failed.
245245
///
246-
/// Specifically, this checks that the dependencies are on the WHITELIST.
246+
/// Specifically, this checks that the dependencies are on the `WHITELIST`.
247247
pub fn check_whitelist(path: &Path, cargo: &Path, bad: &mut bool) {
248-
// Get dependencies from cargo metadata
248+
// Get dependencies from Cargo metadata.
249249
let resolve = get_deps(path, cargo);
250250

251-
// Get the whitelist into a convenient form
251+
// Get the whitelist in a convenient form.
252252
let whitelist: HashSet<_> = WHITELIST.iter().cloned().collect();
253253

254-
// Check dependencies
254+
// Check dependencies.
255255
let mut visited = BTreeSet::new();
256256
let mut unapproved = BTreeSet::new();
257257
for &krate in WHITELIST_CRATES.iter() {
@@ -308,9 +308,9 @@ fn extract_license(line: &str) -> String {
308308
}
309309
}
310310

311-
/// Get the dependencies of the crate at the given path using `cargo metadata`.
311+
/// Gets the dependencies of the crate at the given path using `cargo metadata`.
312312
fn get_deps(path: &Path, cargo: &Path) -> Resolve {
313-
// Run `cargo metadata` to get the set of dependencies
313+
// Run `cargo metadata` to get the set of dependencies.
314314
let output = Command::new(cargo)
315315
.arg("metadata")
316316
.arg("--format-version")
@@ -335,25 +335,25 @@ fn check_crate_whitelist<'a, 'b>(
335335
krate: CrateVersion<'a>,
336336
must_be_on_whitelist: bool,
337337
) -> BTreeSet<Crate<'a>> {
338-
// Will contain bad deps
338+
// This will contain bad deps.
339339
let mut unapproved = BTreeSet::new();
340340

341-
// Check if we have already visited this crate
341+
// Check if we have already visited this crate.
342342
if visited.contains(&krate) {
343343
return unapproved;
344344
}
345345

346346
visited.insert(krate);
347347

348-
// If this path is in-tree, we don't require it to be on the whitelist
348+
// If this path is in-tree, we don't require it to be on the whitelist.
349349
if must_be_on_whitelist {
350-
// If this dependency is not on the WHITELIST, add to bad set
350+
// If this dependency is not on `WHITELIST`, add to bad set.
351351
if !whitelist.contains(&krate.into()) {
352352
unapproved.insert(krate.into());
353353
}
354354
}
355355

356-
// Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!)
356+
// Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!).
357357
let to_check = resolve
358358
.nodes
359359
.iter()
@@ -372,9 +372,10 @@ fn check_crate_whitelist<'a, 'b>(
372372

373373
fn check_crate_duplicate(resolve: &Resolve, bad: &mut bool) {
374374
const FORBIDDEN_TO_HAVE_DUPLICATES: &[&str] = &[
375-
// These two crates take quite a long time to build, let's not let two
376-
// versions of them accidentally sneak into our dependency graph to
377-
// ensure we keep our CI times under control
375+
// These two crates take quite a long time to build, so don't allow two versions of them
376+
// to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
377+
// under control.
378+
378379
// "cargo", // FIXME(#53005)
379380
"rustc-ap-syntax",
380381
];

0 commit comments

Comments
 (0)