mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-01 07:13:24 +03:00
Remove expansion restriction + fix doc and tests naming
This commit is contained in:
@@ -725,6 +725,7 @@
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// In an impl block:
|
||||
/// ```rust
|
||||
/// # struct Foo;
|
||||
/// # struct NotAFoo;
|
||||
@@ -737,25 +738,40 @@
|
||||
///
|
||||
/// ```rust
|
||||
/// # struct Foo;
|
||||
/// # struct FooError;
|
||||
/// struct Bar(Foo);
|
||||
/// impl Foo {
|
||||
/// // Good. Return type contains `Self`
|
||||
/// fn new() -> Result<Foo, FooError> {
|
||||
/// # Ok(Foo)
|
||||
/// // Bad. The type name must contain `Self`
|
||||
/// fn new() -> Bar {
|
||||
/// # Bar(Foo)
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```rust
|
||||
/// # struct Foo;
|
||||
/// struct Bar(Foo);
|
||||
/// # struct FooError;
|
||||
/// impl Foo {
|
||||
/// // Bad. The type name must contain `Self`.
|
||||
/// fn new() -> Bar {
|
||||
/// # Bar(Foo)
|
||||
/// // Good. Return type contains `Self`
|
||||
/// fn new() -> Result<Foo, FooError> {
|
||||
/// # Ok(Foo)
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Or in a trait definition:
|
||||
/// ```rust
|
||||
/// 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,
|
||||
style,
|
||||
"not returning type containing `Self` in a `new` method"
|
||||
@@ -1679,8 +1695,6 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
||||
|
||||
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;
|
||||
|
||||
@@ -137,9 +137,9 @@ pub fn new() -> *mut Self {
|
||||
}
|
||||
}
|
||||
|
||||
struct MutPointerReturnerOk2;
|
||||
struct ConstPointerReturnerOk2;
|
||||
|
||||
impl MutPointerReturnerOk2 {
|
||||
impl ConstPointerReturnerOk2 {
|
||||
// should not trigger lint
|
||||
pub fn new() -> *const Self {
|
||||
unimplemented!();
|
||||
@@ -283,7 +283,7 @@ fn new() -> *mut Self
|
||||
}
|
||||
}
|
||||
|
||||
trait MutPointerReturnerOk2 {
|
||||
trait ConstPointerReturnerOk2 {
|
||||
// should not trigger lint
|
||||
fn new() -> *const Self
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user