Merge commit '3e4179766b' into sync-from-clippy

This commit is contained in:
Manish Goregaokar 2021-02-02 20:43:30 -08:00
parent b56b751055
commit c8cb90abbd
35 changed files with 526 additions and 134 deletions

95
tests/ui/doc_panics.rs Normal file
View file

@ -0,0 +1,95 @@
#![warn(clippy::missing_panics_doc)]
#![allow(clippy::option_map_unit_fn)]
fn main() {}
/// This needs to be documented
pub fn unwrap() {
let result = Err("Hi");
result.unwrap()
}
/// This needs to be documented
pub fn panic() {
panic!("This function panics")
}
/// This needs to be documented
pub fn todo() {
todo!()
}
/// This needs to be documented
pub fn inner_body(opt: Option<u32>) {
opt.map(|x| {
if x == 10 {
panic!()
}
});
}
/// This is documented
///
/// # Panics
///
/// Panics if `result` if an error
pub fn unwrap_documented() {
let result = Err("Hi");
result.unwrap()
}
/// This is documented
///
/// # Panics
///
/// Panics just because
pub fn panic_documented() {
panic!("This function panics")
}
/// This is documented
///
/// # Panics
///
/// Panics if `opt` is Just(10)
pub fn inner_body_documented(opt: Option<u32>) {
opt.map(|x| {
if x == 10 {
panic!()
}
});
}
/// This is documented
///
/// # Panics
///
/// We still need to do this part
pub fn todo_documented() {
todo!()
}
/// This is okay because it is private
fn unwrap_private() {
let result = Err("Hi");
result.unwrap()
}
/// This is okay because it is private
fn panic_private() {
panic!("This function panics")
}
/// This is okay because it is private
fn todo_private() {
todo!()
}
/// This is okay because it is private
fn inner_body_private(opt: Option<u32>) {
opt.map(|x| {
if x == 10 {
panic!()
}
});
}

View file

@ -0,0 +1,67 @@
error: docs for function which may panic missing `# Panics` section
--> $DIR/doc_panics.rs:7:1
|
LL | / pub fn unwrap() {
LL | | let result = Err("Hi");
LL | | result.unwrap()
LL | | }
| |_^
|
= note: `-D clippy::missing-panics-doc` implied by `-D warnings`
note: first possible panic found here
--> $DIR/doc_panics.rs:9:5
|
LL | result.unwrap()
| ^^^^^^^^^^^^^^^
error: docs for function which may panic missing `# Panics` section
--> $DIR/doc_panics.rs:13:1
|
LL | / pub fn panic() {
LL | | panic!("This function panics")
LL | | }
| |_^
|
note: first possible panic found here
--> $DIR/doc_panics.rs:14:5
|
LL | panic!("This function panics")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: docs for function which may panic missing `# Panics` section
--> $DIR/doc_panics.rs:18:1
|
LL | / pub fn todo() {
LL | | todo!()
LL | | }
| |_^
|
note: first possible panic found here
--> $DIR/doc_panics.rs:19:5
|
LL | todo!()
| ^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: docs for function which may panic missing `# Panics` section
--> $DIR/doc_panics.rs:23:1
|
LL | / pub fn inner_body(opt: Option<u32>) {
LL | | opt.map(|x| {
LL | | if x == 10 {
LL | | panic!()
LL | | }
LL | | });
LL | | }
| |_^
|
note: first possible panic found here
--> $DIR/doc_panics.rs:26:13
|
LL | panic!()
| ^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors

View file

@ -56,27 +56,36 @@ pub mod enums {
pub mod structs {
#[non_exhaustive]
pub struct Exhaustive {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
// no warning, already non_exhaustive
#[non_exhaustive]
pub struct NonExhaustive {
foo: u8,
pub foo: u8,
pub bar: String,
}
// no warning, private fields
pub struct ExhaustivePrivateFieldTuple(u8);
// no warning, private fields
pub struct ExhaustivePrivateField {
pub foo: u8,
bar: String,
}
// no warning, private
struct ExhaustivePrivate {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
// no warning, private
#[non_exhaustive]
struct NonExhaustivePrivate {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
}

View file

@ -53,27 +53,36 @@ pub mod enums {
pub mod structs {
pub struct Exhaustive {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
// no warning, already non_exhaustive
#[non_exhaustive]
pub struct NonExhaustive {
foo: u8,
pub foo: u8,
pub bar: String,
}
// no warning, private fields
pub struct ExhaustivePrivateFieldTuple(u8);
// no warning, private fields
pub struct ExhaustivePrivateField {
pub foo: u8,
bar: String,
}
// no warning, private
struct ExhaustivePrivate {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
// no warning, private
#[non_exhaustive]
struct NonExhaustivePrivate {
foo: u8,
bar: String,
pub foo: u8,
pub bar: String,
}
}

View file

@ -41,8 +41,8 @@ error: exported structs should not be exhaustive
--> $DIR/exhaustive_items.rs:55:5
|
LL | / pub struct Exhaustive {
LL | | foo: u8,
LL | | bar: String,
LL | | pub foo: u8,
LL | | pub bar: String,
LL | | }
| |_____^
|

View file

@ -117,7 +117,11 @@ mod no_lint_if_stmt_borrows {
fn drop(&mut self) {}
}
impl Foo<'_> {
impl<'a> Foo<'a> {
fn new(inner: &'a Inner) -> Self {
Self { inner }
}
fn value(&self) -> i32 {
42
}
@ -132,6 +136,12 @@ mod no_lint_if_stmt_borrows {
let value = some_foo(&x).value();
value
}
fn test2() -> i32 {
let x = Inner {};
let value = Foo::new(&x).value();
value
}
}
}

View file

@ -28,7 +28,7 @@ LL | 5
|
error: returning the result of a `let` binding from a block
--> $DIR/let_and_return.rs:154:13
--> $DIR/let_and_return.rs:164:13
|
LL | let clone = Arc::clone(&self.foo);
| ---------------------------------- unnecessary `let` binding

View file

@ -57,6 +57,36 @@ fn overlapping() {
_ => (),
}
match 42 {
5..7 => println!("5 .. 7"),
0..10 => println!("0 .. 10"),
_ => (),
}
match 42 {
5..10 => println!("5 .. 10"),
0..=10 => println!("0 ... 10"),
_ => (),
}
match 42 {
0..14 => println!("0 .. 14"),
5..10 => println!("5 .. 10"),
_ => (),
}
match 42 {
5..14 => println!("5 .. 14"),
0..=10 => println!("0 ... 10"),
_ => (),
}
match 42 {
0..7 => println!("0 .. 7"),
0..=10 => println!("0 ... 10"),
_ => (),
}
/*
// FIXME(JohnTitor): uncomment this once rustfmt knows half-open patterns
match 42 {

View file

@ -23,30 +23,6 @@ note: overlaps with this
LL | FOO..=11 => println!("0 ... 11"),
| ^^^^^^^^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:26:9
|
LL | 0..=5 => println!("0 ... 5"),
| ^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:25:9
|
LL | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:32:9
|
LL | 0..=2 => println!("0 ... 2"),
| ^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:31:9
|
LL | 2 => println!("2"),
| ^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:55:9
|
@ -59,5 +35,29 @@ note: overlaps with this
LL | 0..=11 => println!("0 ... 11"),
| ^^^^^^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:80:9
|
LL | 0..=10 => println!("0 ... 10"),
| ^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:79:9
|
LL | 5..14 => println!("5 .. 14"),
| ^^^^^
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:85:9
|
LL | 0..7 => println!("0 .. 7"),
| ^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:86:9
|
LL | 0..=10 => println!("0 ... 10"),
| ^^^^^^
error: aborting due to 5 previous errors

View file

@ -8,7 +8,8 @@
clippy::unused_self,
clippy::needless_lifetimes,
clippy::missing_safety_doc,
clippy::wrong_self_convention
clippy::wrong_self_convention,
clippy::missing_panics_doc
)]
use std::ops::Mul;

View file

@ -8,7 +8,8 @@
clippy::unused_self,
clippy::needless_lifetimes,
clippy::missing_safety_doc,
clippy::wrong_self_convention
clippy::wrong_self_convention,
clippy::missing_panics_doc
)]
use std::ops::Mul;

View file

@ -1,5 +1,5 @@
error: method `add` can be confused for the standard trait method `std::ops::Add::add`
--> $DIR/method_list_1.rs:25:5
--> $DIR/method_list_1.rs:26:5
|
LL | / pub fn add(self, other: T) -> T {
LL | | unimplemented!()
@ -10,7 +10,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name
error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut`
--> $DIR/method_list_1.rs:29:5
--> $DIR/method_list_1.rs:30:5
|
LL | / pub fn as_mut(&mut self) -> &mut T {
LL | | unimplemented!()
@ -20,7 +20,7 @@ LL | | }
= help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name
error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref`
--> $DIR/method_list_1.rs:33:5
--> $DIR/method_list_1.rs:34:5
|
LL | / pub fn as_ref(&self) -> &T {
LL | | unimplemented!()
@ -30,7 +30,7 @@ LL | | }
= help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name
error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand`
--> $DIR/method_list_1.rs:37:5
--> $DIR/method_list_1.rs:38:5
|
LL | / pub fn bitand(self, rhs: T) -> T {
LL | | unimplemented!()
@ -40,7 +40,7 @@ LL | | }
= help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name
error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor`
--> $DIR/method_list_1.rs:41:5
--> $DIR/method_list_1.rs:42:5
|
LL | / pub fn bitor(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -50,7 +50,7 @@ LL | | }
= help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name
error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor`
--> $DIR/method_list_1.rs:45:5
--> $DIR/method_list_1.rs:46:5
|
LL | / pub fn bitxor(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -60,7 +60,7 @@ LL | | }
= help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name
error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow`
--> $DIR/method_list_1.rs:49:5
--> $DIR/method_list_1.rs:50:5
|
LL | / pub fn borrow(&self) -> &str {
LL | | unimplemented!()
@ -70,7 +70,7 @@ LL | | }
= help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name
error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut`
--> $DIR/method_list_1.rs:53:5
--> $DIR/method_list_1.rs:54:5
|
LL | / pub fn borrow_mut(&mut self) -> &mut str {
LL | | unimplemented!()
@ -80,7 +80,7 @@ LL | | }
= help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name
error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone`
--> $DIR/method_list_1.rs:57:5
--> $DIR/method_list_1.rs:58:5
|
LL | / pub fn clone(&self) -> Self {
LL | | unimplemented!()
@ -90,7 +90,7 @@ LL | | }
= help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name
error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp`
--> $DIR/method_list_1.rs:61:5
--> $DIR/method_list_1.rs:62:5
|
LL | / pub fn cmp(&self, other: &Self) -> Self {
LL | | unimplemented!()
@ -100,7 +100,7 @@ LL | | }
= help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name
error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref`
--> $DIR/method_list_1.rs:69:5
--> $DIR/method_list_1.rs:70:5
|
LL | / pub fn deref(&self) -> &Self {
LL | | unimplemented!()
@ -110,7 +110,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name
error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut`
--> $DIR/method_list_1.rs:73:5
--> $DIR/method_list_1.rs:74:5
|
LL | / pub fn deref_mut(&mut self) -> &mut Self {
LL | | unimplemented!()
@ -120,7 +120,7 @@ LL | | }
= help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name
error: method `div` can be confused for the standard trait method `std::ops::Div::div`
--> $DIR/method_list_1.rs:77:5
--> $DIR/method_list_1.rs:78:5
|
LL | / pub fn div(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -130,7 +130,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name
error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop`
--> $DIR/method_list_1.rs:81:5
--> $DIR/method_list_1.rs:82:5
|
LL | / pub fn drop(&mut self) {
LL | | unimplemented!()

View file

@ -8,7 +8,8 @@
clippy::unused_self,
clippy::needless_lifetimes,
clippy::missing_safety_doc,
clippy::wrong_self_convention
clippy::wrong_self_convention,
clippy::missing_panics_doc
)]
use std::ops::Mul;

View file

@ -1,5 +1,5 @@
error: method `eq` can be confused for the standard trait method `std::cmp::PartialEq::eq`
--> $DIR/method_list_2.rs:26:5
--> $DIR/method_list_2.rs:27:5
|
LL | / pub fn eq(&self, other: &Self) -> bool {
LL | | unimplemented!()
@ -10,7 +10,7 @@ LL | | }
= help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name
error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter`
--> $DIR/method_list_2.rs:30:5
--> $DIR/method_list_2.rs:31:5
|
LL | / pub fn from_iter<T>(iter: T) -> Self {
LL | | unimplemented!()
@ -20,7 +20,7 @@ LL | | }
= help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name
error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str`
--> $DIR/method_list_2.rs:34:5
--> $DIR/method_list_2.rs:35:5
|
LL | / pub fn from_str(s: &str) -> Result<Self, Self> {
LL | | unimplemented!()
@ -30,7 +30,7 @@ LL | | }
= help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name
error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash`
--> $DIR/method_list_2.rs:38:5
--> $DIR/method_list_2.rs:39:5
|
LL | / pub fn hash(&self, state: &mut T) {
LL | | unimplemented!()
@ -40,7 +40,7 @@ LL | | }
= help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name
error: method `index` can be confused for the standard trait method `std::ops::Index::index`
--> $DIR/method_list_2.rs:42:5
--> $DIR/method_list_2.rs:43:5
|
LL | / pub fn index(&self, index: usize) -> &Self {
LL | | unimplemented!()
@ -50,7 +50,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name
error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut`
--> $DIR/method_list_2.rs:46:5
--> $DIR/method_list_2.rs:47:5
|
LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self {
LL | | unimplemented!()
@ -60,7 +60,7 @@ LL | | }
= help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name
error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter`
--> $DIR/method_list_2.rs:50:5
--> $DIR/method_list_2.rs:51:5
|
LL | / pub fn into_iter(self) -> Self {
LL | | unimplemented!()
@ -70,7 +70,7 @@ LL | | }
= help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name
error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul`
--> $DIR/method_list_2.rs:54:5
--> $DIR/method_list_2.rs:55:5
|
LL | / pub fn mul(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -80,7 +80,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name
error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg`
--> $DIR/method_list_2.rs:58:5
--> $DIR/method_list_2.rs:59:5
|
LL | / pub fn neg(self) -> Self {
LL | | unimplemented!()
@ -90,7 +90,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name
error: method `next` can be confused for the standard trait method `std::iter::Iterator::next`
--> $DIR/method_list_2.rs:62:5
--> $DIR/method_list_2.rs:63:5
|
LL | / pub fn next(&mut self) -> Option<Self> {
LL | | unimplemented!()
@ -100,7 +100,7 @@ LL | | }
= help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name
error: method `not` can be confused for the standard trait method `std::ops::Not::not`
--> $DIR/method_list_2.rs:66:5
--> $DIR/method_list_2.rs:67:5
|
LL | / pub fn not(self) -> Self {
LL | | unimplemented!()
@ -110,7 +110,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name
error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem`
--> $DIR/method_list_2.rs:70:5
--> $DIR/method_list_2.rs:71:5
|
LL | / pub fn rem(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -120,7 +120,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name
error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl`
--> $DIR/method_list_2.rs:74:5
--> $DIR/method_list_2.rs:75:5
|
LL | / pub fn shl(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -130,7 +130,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name
error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr`
--> $DIR/method_list_2.rs:78:5
--> $DIR/method_list_2.rs:79:5
|
LL | / pub fn shr(self, rhs: Self) -> Self {
LL | | unimplemented!()
@ -140,7 +140,7 @@ LL | | }
= help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name
error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub`
--> $DIR/method_list_2.rs:82:5
--> $DIR/method_list_2.rs:83:5
|
LL | / pub fn sub(self, rhs: Self) -> Self {
LL | | unimplemented!()