mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Auto merge of #5790 - flip1995:rustup, r=flip1995
Rustup r? @ghost changelog: none
This commit is contained in:
commit
fa4a737fba
@ -72,7 +72,7 @@ declare_clippy_lint! {
|
|||||||
/// **What it does:** Checks for `extern crate` and `use` items annotated with
|
/// **What it does:** Checks for `extern crate` and `use` items annotated with
|
||||||
/// lint attributes.
|
/// lint attributes.
|
||||||
///
|
///
|
||||||
/// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
|
/// This lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
|
||||||
/// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
|
/// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
|
||||||
/// `extern crate` items with a `#[macro_use]` attribute.
|
/// `extern crate` items with a `#[macro_use]` attribute.
|
||||||
///
|
///
|
||||||
@ -319,7 +319,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||||||
if let Some(ident) = attr.ident() {
|
if let Some(ident) = attr.ident() {
|
||||||
match &*ident.as_str() {
|
match &*ident.as_str() {
|
||||||
"allow" | "warn" | "deny" | "forbid" => {
|
"allow" | "warn" | "deny" | "forbid" => {
|
||||||
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
|
// permit `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
|
||||||
// and `unused_imports` for `extern crate` items with `macro_use`
|
// and `unused_imports` for `extern crate` items with `macro_use`
|
||||||
for lint in lint_list {
|
for lint in lint_list {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
|
@ -16,7 +16,7 @@ declare_clippy_lint! {
|
|||||||
/// **Known problems:** False negatives: We had some false positives regarding
|
/// **Known problems:** False negatives: We had some false positives regarding
|
||||||
/// calls (notably [racer](https://github.com/phildawes/racer) had one instance
|
/// calls (notably [racer](https://github.com/phildawes/racer) had one instance
|
||||||
/// of `x.pop() && x.pop()`), so we removed matching any function or method
|
/// of `x.pop() && x.pop()`), so we removed matching any function or method
|
||||||
/// calls. We may introduce a whitelist of known pure functions in the future.
|
/// calls. We may introduce a list of known pure functions in the future.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
|||||||
|
|
||||||
// Allow `Borrow` or functions to be taken by value
|
// Allow `Borrow` or functions to be taken by value
|
||||||
let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT));
|
let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT));
|
||||||
let whitelisted_traits = [
|
let allowed_traits = [
|
||||||
need!(cx.tcx.lang_items().fn_trait()),
|
need!(cx.tcx.lang_items().fn_trait()),
|
||||||
need!(cx.tcx.lang_items().fn_once_trait()),
|
need!(cx.tcx.lang_items().fn_once_trait()),
|
||||||
need!(cx.tcx.lang_items().fn_mut_trait()),
|
need!(cx.tcx.lang_items().fn_mut_trait()),
|
||||||
@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
|||||||
if !is_self(arg);
|
if !is_self(arg);
|
||||||
if !ty.is_mutable_ptr();
|
if !ty.is_mutable_ptr();
|
||||||
if !is_copy(cx, ty);
|
if !is_copy(cx, ty);
|
||||||
if !whitelisted_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
|
if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
|
||||||
if !implements_borrow_trait;
|
if !implements_borrow_trait;
|
||||||
if !all_borrowable_trait;
|
if !all_borrowable_trait;
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ struct ExistingName {
|
|||||||
interned: SymbolStr,
|
interned: SymbolStr,
|
||||||
span: Span,
|
span: Span,
|
||||||
len: usize,
|
len: usize,
|
||||||
whitelist: &'static [&'static str],
|
exemptions: &'static [&'static str],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SimilarNamesLocalVisitor<'a, 'tcx> {
|
struct SimilarNamesLocalVisitor<'a, 'tcx> {
|
||||||
@ -117,7 +117,7 @@ impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> {
|
|||||||
// this list contains lists of names that are allowed to be similar
|
// this list contains lists of names that are allowed to be similar
|
||||||
// the assumption is that no name is ever contained in multiple lists.
|
// the assumption is that no name is ever contained in multiple lists.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
const WHITELIST: &[&[&str]] = &[
|
const ALLOWED_TO_BE_SIMILAR: &[&[&str]] = &[
|
||||||
&["parsed", "parser"],
|
&["parsed", "parser"],
|
||||||
&["lhs", "rhs"],
|
&["lhs", "rhs"],
|
||||||
&["tx", "rx"],
|
&["tx", "rx"],
|
||||||
@ -156,17 +156,17 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn get_whitelist(interned_name: &str) -> Option<&'static [&'static str]> {
|
fn get_exemptions(interned_name: &str) -> Option<&'static [&'static str]> {
|
||||||
for &allow in WHITELIST {
|
for &list in ALLOWED_TO_BE_SIMILAR {
|
||||||
if whitelisted(interned_name, allow) {
|
if allowed_to_be_similar(interned_name, list) {
|
||||||
return Some(allow);
|
return Some(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn whitelisted(interned_name: &str, list: &[&str]) -> bool {
|
fn allowed_to_be_similar(interned_name: &str, list: &[&str]) -> bool {
|
||||||
list.iter()
|
list.iter()
|
||||||
.any(|&name| interned_name.starts_with(name) || interned_name.ends_with(name))
|
.any(|&name| interned_name.starts_with(name) || interned_name.ends_with(name))
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for existing_name in &self.0.names {
|
for existing_name in &self.0.names {
|
||||||
if whitelisted(&interned_name, existing_name.whitelist) {
|
if allowed_to_be_similar(&interned_name, existing_name.exemptions) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut split_at = None;
|
let mut split_at = None;
|
||||||
@ -301,7 +301,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.0.names.push(ExistingName {
|
self.0.names.push(ExistingName {
|
||||||
whitelist: get_whitelist(&interned_name).unwrap_or(&[]),
|
exemptions: get_exemptions(&interned_name).unwrap_or(&[]),
|
||||||
interned: interned_name,
|
interned: interned_name,
|
||||||
span: ident.span,
|
span: ident.span,
|
||||||
len: count,
|
len: count,
|
||||||
|
@ -5,7 +5,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass};
|
|||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
|
|
||||||
const ODD_FUNCTIONS_WHITELIST: [&str; 14] = [
|
const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [
|
||||||
"asin",
|
"asin",
|
||||||
"asinh",
|
"asinh",
|
||||||
"atan",
|
"atan",
|
||||||
@ -109,7 +109,7 @@ impl EarlyLintPass for Precedence {
|
|||||||
if let ExprKind::Lit(ref lit) = slf.kind {
|
if let ExprKind::Lit(ref lit) = slf.kind {
|
||||||
match lit.kind {
|
match lit.kind {
|
||||||
LitKind::Int(..) | LitKind::Float(..) => {
|
LitKind::Int(..) | LitKind::Float(..) => {
|
||||||
if ODD_FUNCTIONS_WHITELIST
|
if ALLOWED_ODD_FUNCTIONS
|
||||||
.iter()
|
.iter()
|
||||||
.any(|odd_function| **odd_function == *path_segment_str)
|
.any(|odd_function| **odd_function == *path_segment_str)
|
||||||
{
|
{
|
||||||
|
@ -1246,7 +1246,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast
|
|||||||
// don't lint for the result of methods that always return non-negative values
|
// don't lint for the result of methods that always return non-negative values
|
||||||
if let ExprKind::MethodCall(ref path, _, _, _) = op.kind {
|
if let ExprKind::MethodCall(ref path, _, _, _) = op.kind {
|
||||||
let mut method_name = path.ident.name.as_str();
|
let mut method_name = path.ident.name.as_str();
|
||||||
let whitelisted_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
|
let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if method_name == "unwrap";
|
if method_name == "unwrap";
|
||||||
@ -1257,7 +1257,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if whitelisted_methods.iter().any(|&name| method_name == name) {
|
if allowed_methods.iter().any(|&name| method_name == name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,14 +57,6 @@ LL | | t
|
|||||||
LL | | }
|
LL | | }
|
||||||
| |_^
|
| |_^
|
||||||
|
|
||||||
error: this could be a `const fn`
|
|
||||||
--> $DIR/could_be_const.rs:48:1
|
|
||||||
|
|
|
||||||
LL | / fn sub(x: u32) -> usize {
|
|
||||||
LL | | unsafe { transmute(&x) }
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
||||||
error: this could be a `const fn`
|
error: this could be a `const fn`
|
||||||
--> $DIR/could_be_const.rs:67:9
|
--> $DIR/could_be_const.rs:67:9
|
||||||
|
|
|
|
||||||
@ -73,5 +65,5 @@ LL | | B
|
|||||||
LL | | }
|
LL | | }
|
||||||
| |_________^
|
| |_________^
|
||||||
|
|
||||||
error: aborting due to 9 previous errors
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ extern "C" fn ext(x: MaybeUninit<usize>) -> usize {
|
|||||||
unsafe { x.assume_init() }
|
unsafe { x.assume_init() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// whitelist RangeArgument
|
// exempt RangeArgument
|
||||||
fn range<T: ::std::ops::RangeBounds<usize>>(range: T) {
|
fn range<T: ::std::ops::RangeBounds<usize>>(range: T) {
|
||||||
let _ = range.start_bound();
|
let _ = range.start_bound();
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,6 @@ fn main() {
|
|||||||
// The macro always negates the result of the given comparison in its
|
// The macro always negates the result of the given comparison in its
|
||||||
// internal check which automatically triggered the lint. As it's an
|
// internal check which automatically triggered the lint. As it's an
|
||||||
// external macro there was no chance to do anything about it which led
|
// external macro there was no chance to do anything about it which led
|
||||||
// to a whitelisting of all external macros.
|
// to an exempting of all external macros.
|
||||||
assert!(a_value < another_value);
|
assert!(a_value < another_value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user