Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #47195

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2535804
Allow underscores in camel-case between non-alphabetic characters
varkor Dec 21, 2017
e4c02e5
Adjust the rules for underscores
varkor Dec 21, 2017
c1aa017
Add tests
varkor Dec 21, 2017
a8d107b
Correct a few stability attributes
ollie27 Dec 27, 2017
838fb4a
Disable printing of error message on file descriptor 2 on CloudABI.
EdSchouten Dec 27, 2017
c661e38
Build the right platform module on CloudABI.
EdSchouten Dec 31, 2017
4fe167a
Use the right TLS model for CloudABI.
EdSchouten Jan 1, 2018
3dff918
Remove dependency on regex
varkor Jan 2, 2018
2b9add2
Return None from Span::join if in different files
dtolnay Jan 3, 2018
000e907
Span::resolved_at and Span::located_at to combine behavior of two spans
dtolnay Jan 3, 2018
48f2f71
Implement TrustedRandomAccess for slice::{Chunks, ChunksMut, Windows}
sdroege Jan 2, 2018
a56a3fc
Add unit test for zipping slice::{Chunks, ChunksMut, Windows} iterators
sdroege Jan 3, 2018
3f29e2b
Fix compilation of TrustedRandomAccess impl for slice::Chunks
sdroege Jan 3, 2018
47e18e0
This isn't in Rust 1.23
steveklabnik Jan 3, 2018
50989cd
This is an unstable feature
steveklabnik Jan 3, 2018
05949b0
Explain why local-exec is used by CloudABI.
EdSchouten Jan 3, 2018
d7bbd30
Remove outdated LLVMRustBuildLandingPad() wrapper
dotdash Dec 8, 2017
493c29d
Remove unused function LLVMRustGetValueContext()
dotdash Dec 8, 2017
7e522b2
Simplify LLVMRustModuleCost()
dotdash Dec 8, 2017
b69c124
Fix potential overflow in TrustedRandomAccess impl for slice::{Chunks…
sdroege Jan 4, 2018
922f061
Make examples equivalent
aheart Jan 4, 2018
ba11790
Rollup merge of #46907 - varkor:contrib-8, r=nagisa
kennytm Jan 4, 2018
f2d9035
Rollup merge of #47030 - ollie27:stab, r=alexcrichton
kennytm Jan 4, 2018
b583e17
Rollup merge of #47033 - EdSchouten:cloudabi-oom, r=kennytm
kennytm Jan 4, 2018
9e5787d
Rollup merge of #47110 - EdSchouten:cloudabi-tls, r=kennytm
kennytm Jan 4, 2018
dc8254e
Rollup merge of #47142 - sdroege:trusted-random-access-chunks, r=kennytm
kennytm Jan 4, 2018
8eca1b3
Rollup merge of #47149 - dtolnay:spans, r=jseyfried
kennytm Jan 4, 2018
e3e54d9
Rollup merge of #47150 - dtolnay:join, r=jseyfried
kennytm Jan 4, 2018
891a901
Rollup merge of #47160 - rust-lang:steveklabnik-patch-1, r=alexcrichton
kennytm Jan 4, 2018
a4e4899
Rollup merge of #47173 - dotdash:cleanup, r=michaelwoerister
kennytm Jan 4, 2018
1791414
Rollup merge of #47182 - aheart:master, r=steveklabnik
kennytm Jan 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove dependency on regex
  • Loading branch information
varkor committed Jan 2, 2018
commit 3dff918c6c3748104bf83db1b27fd13d51d587be
8 changes: 0 additions & 8 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/librustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ version = "0.0.0"
[lib]
name = "rustc_lint"
path = "lib.rs"
crate-types = ["rlib", "dylib"]
crate-type = ["dylib"]
test = false

[dependencies]
@@ -15,5 +15,3 @@ rustc = { path = "../librustc" }
rustc_const_eval = { path = "../librustc_const_eval" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
lazy_static = "1.0"
regex = "0.2.3"
55 changes: 32 additions & 23 deletions src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
@@ -21,13 +21,6 @@ use syntax_pos::Span;
use rustc::hir::{self, PatKind};
use rustc::hir::intravisit::FnKind;

use regex::Regex;

lazy_static! {
static ref ALPHABETIC_UNDERSCORE: Regex =
Regex::new("([[:alpha:]])_+|_+([[:alpha:]])").unwrap();
}

#[derive(PartialEq)]
pub enum MethodLateContext {
TraitAutoImpl,
@@ -60,6 +53,10 @@ pub struct NonCamelCaseTypes;

impl NonCamelCaseTypes {
fn check_case(&self, cx: &LateContext, sort: &str, name: ast::Name, span: Span) {
fn char_has_case(c: char) -> bool {
c.is_lowercase() || c.is_uppercase()
}

fn is_camel_case(name: ast::Name) -> bool {
let name = name.as_str();
if name.is_empty() {
@@ -70,25 +67,37 @@ impl NonCamelCaseTypes {
// start with a non-lowercase letter rather than non-uppercase
// ones (some scripts don't have a concept of upper/lowercase)
!name.is_empty() && !name.chars().next().unwrap().is_lowercase() &&
!name.contains("__") && !ALPHABETIC_UNDERSCORE.is_match(name)
!name.contains("__") && !name.chars().collect::<Vec<_>>().windows(2).any(|pair| {
// contains a capitalisable character followed by, or preceded by, an underscore
char_has_case(pair[0]) && pair[1] == '_' ||
char_has_case(pair[1]) && pair[0] == '_'
})
}

fn to_camel_case(s: &str) -> String {
let s = s.trim_matches('_')
.split('_')
.map(|word| {
word.chars().enumerate().map(|(i, c)| if i == 0 {
c.to_uppercase().collect::<String>()
} else {
c.to_lowercase().collect()
})
.collect::<Vec<_>>()
.concat()
})
.filter(|x| !x.is_empty())
.collect::<Vec<_>>()
.join("_");
ALPHABETIC_UNDERSCORE.replace_all(s.as_str(), "$1$2").to_string()
s.trim_matches('_')
.split('_')
.map(|word| {
word.chars().enumerate().map(|(i, c)| if i == 0 {
c.to_uppercase().collect::<String>()
} else {
c.to_lowercase().collect()
})
.collect::<Vec<_>>()
.concat()
})
.filter(|x| !x.is_empty())
.collect::<Vec<_>>()
.iter().fold((String::new(), None), |(acc, prev): (String, Option<&String>), next| {
// separate two components with an underscore if their boundary cannot
// be distinguished using a uppercase/lowercase case distinction
let join = if let Some(prev) = prev {
let l = prev.chars().last().unwrap();
let f = next.chars().next().unwrap();
!char_has_case(l) && !char_has_case(f)
} else { false };
(acc + if join { "_" } else { "" } + next, Some(next))
}).0
}

if !is_camel_case(name) {
3 changes: 0 additions & 3 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
@@ -41,9 +41,6 @@ extern crate rustc;
extern crate log;
extern crate rustc_const_eval;
extern crate syntax_pos;
#[macro_use]
extern crate lazy_static;
extern crate regex;

use rustc::lint;
use rustc::middle;