Remove expansion restriction + fix doc and tests naming

This commit is contained in:
ThibsG 2020-08-25 09:16:08 +02:00
parent 2a3ee5fa85
commit 3cb75c2e5c
2 changed files with 27 additions and 13 deletions

View file

@ -725,6 +725,7 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// In an impl block:
/// ```rust
/// # struct Foo;
/// # struct NotAFoo;
@ -737,6 +738,17 @@ declare_clippy_lint! {
///
/// ```rust
/// # struct Foo;
/// struct Bar(Foo);
/// impl Foo {
/// // Bad. The type name must contain `Self`
/// fn new() -> Bar {
/// # Bar(Foo)
/// }
/// }
/// ```
///
/// ```rust
/// # struct Foo;
/// # struct FooError;
/// impl Foo {
/// // Good. Return type contains `Self`
@ -746,14 +758,18 @@ declare_clippy_lint! {
/// }
/// ```
///
/// Or in a trait definition:
/// ```rust
/// # struct Foo;
/// struct Bar(Foo);
/// impl Foo {
/// // Bad. The type name must contain `Self`.
/// fn new() -> Bar {
/// # Bar(Foo)
/// pub trait Trait {
/// // Bad. The type name must contain `Self`
/// fn new();
/// }
/// ```
///
/// ```rust
/// pub trait Trait {
/// // Good. Return type contains `Self`
/// fn new() -> Self;
/// }
/// ```
pub NEW_RET_NO_SELF,
@ -1679,8 +1695,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
if_chain! {
if !in_external_macro(cx.tcx.sess, item.span);
if !item.span.from_expansion();
if item.ident.name == sym!(new);
if let TraitItemKind::Fn(FnSig { decl, .. }, _) = &item.kind;
if let FnRetTy::Return(ret_ty) = &decl.output;

View file

@ -137,9 +137,9 @@ impl MutPointerReturnerOk {
}
}
struct MutPointerReturnerOk2;
struct ConstPointerReturnerOk2;
impl MutPointerReturnerOk2 {
impl ConstPointerReturnerOk2 {
// should not trigger lint
pub fn new() -> *const Self {
unimplemented!();
@ -283,7 +283,7 @@ mod issue5435 {
}
}
trait MutPointerReturnerOk2 {
trait ConstPointerReturnerOk2 {
// should not trigger lint
fn new() -> *const Self
where