Skip to content

Commit

Permalink
Auto merge of #57520 - alexreg:tidy-copyright-lint, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Add lint for copyright headers to 'tidy' tool

r? @Mark-Simulacrum

CC @Centril
  • Loading branch information
bors committed Jan 17, 2019
2 parents 722b4d6 + 4d18023 commit 6599946
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 176 files
2 changes: 1 addition & 1 deletion src/doc/reference
29 changes: 14 additions & 15 deletions src/libcore/slice/memchr.rs
@@ -1,5 +1,4 @@
//
// Original implementation taken from rust-memchr
// Original implementation taken from rust-memchr.
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch

use cmp;
Expand All @@ -8,13 +7,13 @@ use mem;
const LO_U64: u64 = 0x0101010101010101;
const HI_U64: u64 = 0x8080808080808080;

// use truncation
// Use truncation.
const LO_USIZE: usize = LO_U64 as usize;
const HI_USIZE: usize = HI_U64 as usize;

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

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

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

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

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

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

// find the byte before the point the body loop stopped
// Find the byte before the point the body loop stopped.
text[..offset].iter().rposition(|elt| *elt == x)
}
2 changes: 1 addition & 1 deletion src/libserialize/json.rs
@@ -1,4 +1,4 @@
// Rust JSON serialization library
// Rust JSON serialization library.
// Copyright (c) 2011 Google Inc.

#![forbid(non_camel_case_types)]
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/memchr.rs
@@ -1,5 +1,4 @@
//
// Original implementation taken from rust-memchr
// Original implementation taken from rust-memchr.
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch

/// A safe interface to `memchr`.
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/cloudabi/abi/cloudabi.rs
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Nuxi (https://nuxi.nl/) and contributors.
// Copyright (c) 2016-2017 Nuxi <https://nuxi.nl/> and contributors.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys/redox/memchr.rs
@@ -1,5 +1,4 @@
//
// Original implementation taken from rust-memchr
// Original implementation taken from rust-memchr.
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch

pub use core::slice::memchr::{memchr, memrchr};
3 changes: 1 addition & 2 deletions src/libstd/sys/unix/memchr.rs
@@ -1,5 +1,4 @@
//
// Original implementation taken from rust-memchr
// Original implementation taken from rust-memchr.
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch

pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
Expand Down
5 changes: 2 additions & 3 deletions src/libstd/sys/windows/memchr.rs
@@ -1,6 +1,5 @@
//
// Original implementation taken from rust-memchr
// Original implementation taken from rust-memchr.
// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch

// Fallback memchr is fastest on windows
// Fallback memchr is fastest on Windows.
pub use core::slice::memchr::{memchr, memrchr};
2 changes: 1 addition & 1 deletion src/libsyntax/json.rs
Expand Up @@ -7,7 +7,7 @@
//! The format of the JSON output should be considered *unstable*. For now the
//! structs at the end of this file (Diagnostic*) specify the error format.

// FIXME spec the JSON output properly.
// FIXME: spec the JSON output properly.

use source_map::{SourceMap, FilePathMapping};
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
Expand Down
10 changes: 0 additions & 10 deletions src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs
@@ -1,13 +1,3 @@
// 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 http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// force-host

#![feature(plugin_registrar)]
Expand Down
10 changes: 0 additions & 10 deletions src/test/rustdoc-ui/deny-missing-docs-crate.rs
@@ -1,13 +1,3 @@
// Copyright 2018 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.

#![deny(missing_docs)] //~ ERROR

pub struct Foo; //~ ERROR
6 changes: 3 additions & 3 deletions src/test/rustdoc-ui/deny-missing-docs-crate.stderr
@@ -1,19 +1,19 @@
error: missing documentation for crate
--> $DIR/deny-missing-docs-crate.rs:11:1
--> $DIR/deny-missing-docs-crate.rs:1:1
|
LL | / #![deny(missing_docs)] //~ ERROR
LL | |
LL | | pub struct Foo; //~ ERROR
| |_______________^
|
note: lint level defined here
--> $DIR/deny-missing-docs-crate.rs:11:9
--> $DIR/deny-missing-docs-crate.rs:1:9
|
LL | #![deny(missing_docs)] //~ ERROR
| ^^^^^^^^^^^^

error: missing documentation for a struct
--> $DIR/deny-missing-docs-crate.rs:13:1
--> $DIR/deny-missing-docs-crate.rs:3:1
|
LL | pub struct Foo; //~ ERROR
| ^^^^^^^^^^^^^^^
Expand Down
10 changes: 0 additions & 10 deletions src/test/rustdoc-ui/deny-missing-docs-macro.rs
@@ -1,13 +1,3 @@
// Copyright 2018 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.

//! foo

#![deny(missing_docs)]
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/deny-missing-docs-macro.stderr
@@ -1,11 +1,11 @@
error: missing documentation for macro
--> $DIR/deny-missing-docs-macro.rs:16:1
--> $DIR/deny-missing-docs-macro.rs:6:1
|
LL | macro_rules! foo { //~ ERROR
| ^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/deny-missing-docs-macro.rs:13:9
--> $DIR/deny-missing-docs-macro.rs:3:9
|
LL | #![deny(missing_docs)]
| ^^^^^^^^^^^^
Expand Down
3 changes: 0 additions & 3 deletions src/test/rustdoc/auxiliary/enum_primitive.rs
Expand Up @@ -19,7 +19,6 @@
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


//! This crate exports a macro `enum_from_primitive!` that wraps an
//! `enum` declaration and automatically adds an implementation of
//! `num::FromPrimitive` (reexported here), to allow conversion from
Expand Down Expand Up @@ -52,7 +51,6 @@
//! }
//! ```


pub mod num_traits {
pub trait FromPrimitive: Sized {
fn from_i64(n: i64) -> Option<Self>;
Expand Down Expand Up @@ -207,4 +205,3 @@ macro_rules! enum_from_primitive {
enum_from_primitive_impl! { $name, $( $( $variant )+ )+ }
};
}

10 changes: 0 additions & 10 deletions src/test/rustdoc/no-crate-filter.rs
@@ -1,13 +1,3 @@
// Copyright 2018 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.

#![crate_name = "foo"]

// compile-flags: -Z unstable-options --disable-per-crate-search
Expand Down
10 changes: 0 additions & 10 deletions src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs
@@ -1,13 +1,3 @@
// Copyright 2018 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.

enum Foo {
Bar(i32),
Baz { i: i32 },
Expand Down
@@ -1,29 +1,29 @@
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:13
--> $DIR/feature-gate-type_alias_enum_variants.rs:9:13
|
LL | let t = Alias::Bar(0);
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable

error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:21:13
--> $DIR/feature-gate-type_alias_enum_variants.rs:11:13
|
LL | let t = Alias::Baz { i: 0 };
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable

error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:24:9
--> $DIR/feature-gate-type_alias_enum_variants.rs:14:9
|
LL | Alias::Bar(_i) => {}
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable

error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
--> $DIR/feature-gate-type_alias_enum_variants.rs:16:9
|
LL | Alias::Baz { i: _i } => {}
| ^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions src/tools/tidy/src/bins.rs
Expand Up @@ -2,12 +2,12 @@
//! by accident.
//!
//! In the past we've accidentally checked in test binaries and such which add a
//! huge amount of bloat to the git history, so it's good to just ensure we
//! don't do that again :)
//! huge amount of bloat to the Git history, so it's good to just ensure we
//! don't do that again.

use std::path::Path;

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

Expand Down
26 changes: 14 additions & 12 deletions src/tools/tidy/src/cargo.rs
Expand Up @@ -13,7 +13,7 @@ pub fn check(path: &Path, bad: &mut bool) {
return
}
for entry in t!(path.read_dir(), path).map(|e| t!(e)) {
// Look for `Cargo.toml` with a sibling `src/lib.rs` or `lib.rs`
// Look for `Cargo.toml` with a sibling `src/lib.rs` or `lib.rs`.
if entry.file_name().to_str() == Some("Cargo.toml") {
if path.join("src/lib.rs").is_file() {
verify(&entry.path(), &path.join("src/lib.rs"), bad)
Expand All @@ -27,8 +27,8 @@ pub fn check(path: &Path, bad: &mut bool) {
}
}

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

// "Poor man's TOML parser", just assume we use one syntax for now
// "Poor man's TOML parser" -- just assume we use one syntax for now.
//
// We just look for:
//
// [dependencies]
// name = ...
// name2 = ...
// name3 = ...
// ````
// [dependencies]
// name = ...
// name2 = ...
// name3 = ...
// ```
//
// If we encounter a line starting with `[` then we assume it's the end of
// the dependency section and bail out.
Expand All @@ -63,14 +65,14 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
continue
}

// Don't worry about depending on core/std but not saying `extern crate
// core/std`, that's intentional.
// Don't worry about depending on core/std while not writing `extern crate
// core/std` -- that's intentional.
if krate == "core" || krate == "std" {
continue
}

// This is intentional, this dependency just makes the crate available
// for others later on. Cover cases
// This is intentional -- this dependency just makes the crate available
// for others later on.
let whitelisted = krate.starts_with("panic");
if toml.contains("name = \"std\"") && whitelisted {
continue
Expand Down

0 comments on commit 6599946

Please sign in to comment.