2022-12-17 13:12:54 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2018-10-03 03:11:56 +00:00
|
|
|
#![warn(clippy::new_ret_no_self)]
|
2020-04-03 01:46:01 +00:00
|
|
|
#![allow(dead_code)]
|
2018-10-03 03:11:56 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn main() {}
|
2018-10-03 03:11:56 +00:00
|
|
|
|
2018-10-03 10:55:31 +00:00
|
|
|
trait R {
|
|
|
|
type Item;
|
|
|
|
}
|
|
|
|
|
2018-10-05 02:01:04 +00:00
|
|
|
trait Q {
|
|
|
|
type Item;
|
|
|
|
type Item2;
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:55:31 +00:00
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl R for S {
|
|
|
|
type Item = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new() -> impl R<Item = Self> {
|
|
|
|
S
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S2;
|
|
|
|
|
|
|
|
impl R for S2 {
|
|
|
|
type Item = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S2 {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new(_: String) -> impl R<Item = Self> {
|
|
|
|
S2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 11:59:14 +00:00
|
|
|
struct S3;
|
|
|
|
|
|
|
|
impl R for S3 {
|
|
|
|
type Item = u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S3 {
|
2018-10-05 02:01:04 +00:00
|
|
|
// should trigger the lint
|
2018-10-03 11:59:14 +00:00
|
|
|
pub fn new(_: String) -> impl R<Item = u32> {
|
|
|
|
S3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 02:01:04 +00:00
|
|
|
struct S4;
|
|
|
|
|
|
|
|
impl Q for S4 {
|
|
|
|
type Item = u32;
|
|
|
|
type Item2 = Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl S4 {
|
|
|
|
// should not trigger the lint
|
|
|
|
pub fn new(_: String) -> impl Q<Item = u32, Item2 = Self> {
|
|
|
|
S4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 10:55:31 +00:00
|
|
|
struct T;
|
|
|
|
|
|
|
|
impl T {
|
|
|
|
// should not trigger lint
|
|
|
|
pub fn new() -> Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 03:11:56 +00:00
|
|
|
|
|
|
|
struct U;
|
|
|
|
|
|
|
|
impl U {
|
|
|
|
// should trigger lint
|
|
|
|
pub fn new() -> u32 {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct V;
|
|
|
|
|
|
|
|
impl V {
|
|
|
|
// should trigger lint
|
|
|
|
pub fn new(_: String) -> u32 {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2018-10-19 11:55:06 +00:00
|
|
|
|
|
|
|
struct TupleReturnerOk;
|
|
|
|
|
|
|
|
impl TupleReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> (Self, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 11:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerOk2;
|
|
|
|
|
|
|
|
impl TupleReturnerOk2 {
|
|
|
|
// should not trigger lint (it doesn't matter which element in the tuple is Self)
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> (u32, Self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 11:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerOk3;
|
|
|
|
|
|
|
|
impl TupleReturnerOk3 {
|
|
|
|
// should not trigger lint (tuple can contain multiple Self)
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> (Self, Self) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 11:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleReturnerBad;
|
|
|
|
|
|
|
|
impl TupleReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> (u32, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 11:55:06 +00:00
|
|
|
}
|
2018-10-19 12:20:33 +00:00
|
|
|
|
|
|
|
struct MutPointerReturnerOk;
|
|
|
|
|
|
|
|
impl MutPointerReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> *mut Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 14:10:16 +00:00
|
|
|
struct ConstPointerReturnerOk2;
|
2018-10-19 12:20:33 +00:00
|
|
|
|
2020-08-28 14:10:16 +00:00
|
|
|
impl ConstPointerReturnerOk2 {
|
2018-10-19 12:20:33 +00:00
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> *const Self {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 12:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MutPointerReturnerBad;
|
|
|
|
|
|
|
|
impl MutPointerReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> *mut V {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-19 12:20:33 +00:00
|
|
|
}
|
2018-10-20 13:29:17 +00:00
|
|
|
|
|
|
|
struct GenericReturnerOk;
|
|
|
|
|
|
|
|
impl GenericReturnerOk {
|
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Option<Self> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct GenericReturnerBad;
|
|
|
|
|
|
|
|
impl GenericReturnerBad {
|
|
|
|
// should trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Option<u32> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NestedReturnerOk;
|
|
|
|
|
|
|
|
impl NestedReturnerOk {
|
2018-10-24 13:43:21 +00:00
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> (Option<Self>, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-20 13:29:17 +00:00
|
|
|
}
|
2018-10-24 13:43:21 +00:00
|
|
|
|
|
|
|
struct NestedReturnerOk2;
|
|
|
|
|
|
|
|
impl NestedReturnerOk2 {
|
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> ((Self, u32), u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-24 13:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NestedReturnerOk3;
|
|
|
|
|
|
|
|
impl NestedReturnerOk3 {
|
|
|
|
// should not trigger lint
|
2018-12-09 22:26:16 +00:00
|
|
|
pub fn new() -> Option<(Self, u32)> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
2018-10-24 13:43:21 +00:00
|
|
|
}
|
2020-04-25 08:43:41 +00:00
|
|
|
|
|
|
|
struct WithLifetime<'a> {
|
|
|
|
cat: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> WithLifetime<'a> {
|
|
|
|
// should not trigger the lint, because the lifetimes are different
|
|
|
|
pub fn new<'b: 'a>(s: &'b str) -> WithLifetime<'b> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2020-08-28 14:10:16 +00:00
|
|
|
|
|
|
|
mod issue5435 {
|
|
|
|
struct V;
|
|
|
|
|
|
|
|
pub trait TraitRetSelf {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait TraitRet {
|
|
|
|
// should trigger lint as we are in trait definition
|
|
|
|
fn new() -> String;
|
|
|
|
}
|
|
|
|
pub struct StructRet;
|
|
|
|
impl TraitRet for StructRet {
|
|
|
|
// should not trigger lint as we are in the impl block
|
|
|
|
fn new() -> String {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait TraitRet2 {
|
|
|
|
// should trigger lint
|
|
|
|
fn new(_: String) -> String;
|
|
|
|
}
|
|
|
|
|
|
|
|
trait TupleReturnerOk {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> (Self, u32)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait TupleReturnerOk2 {
|
|
|
|
// should not trigger lint (it doesn't matter which element in the tuple is Self)
|
|
|
|
fn new() -> (u32, Self)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait TupleReturnerOk3 {
|
|
|
|
// should not trigger lint (tuple can contain multiple Self)
|
|
|
|
fn new() -> (Self, Self)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait TupleReturnerBad {
|
|
|
|
// should trigger lint
|
|
|
|
fn new() -> (u32, u32) {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait MutPointerReturnerOk {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> *mut Self
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait ConstPointerReturnerOk2 {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> *const Self
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait MutPointerReturnerBad {
|
|
|
|
// should trigger lint
|
|
|
|
fn new() -> *mut V {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait GenericReturnerOk {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> Option<Self>
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait NestedReturnerOk {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> (Option<Self>, u32)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait NestedReturnerOk2 {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> ((Self, u32), u32)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait NestedReturnerOk3 {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new() -> Option<(Self, u32)>
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 18:29:11 +00:00
|
|
|
|
|
|
|
// issue #1724
|
|
|
|
struct RetOtherSelf<T>(T);
|
|
|
|
struct RetOtherSelfWrapper<T>(T);
|
|
|
|
|
|
|
|
impl RetOtherSelf<T> {
|
|
|
|
fn new(t: T) -> RetOtherSelf<RetOtherSelfWrapper<T>> {
|
|
|
|
RetOtherSelf(RetOtherSelfWrapper(t))
|
|
|
|
}
|
|
|
|
}
|
2022-11-21 19:34:47 +00:00
|
|
|
|
|
|
|
mod issue7344 {
|
|
|
|
struct RetImplTraitSelf<T>(T);
|
|
|
|
|
|
|
|
impl<T> RetImplTraitSelf<T> {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new(t: T) -> impl Into<Self> {
|
|
|
|
Self(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RetImplTraitNoSelf<T>(T);
|
|
|
|
|
|
|
|
impl<T> RetImplTraitNoSelf<T> {
|
|
|
|
// should trigger lint
|
|
|
|
fn new(t: T) -> impl Into<i32> {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait2<T, U> {}
|
|
|
|
impl<T, U> Trait2<T, U> for () {}
|
|
|
|
|
|
|
|
struct RetImplTraitSelf2<T>(T);
|
|
|
|
|
|
|
|
impl<T> RetImplTraitSelf2<T> {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new(t: T) -> impl Trait2<(), Self> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RetImplTraitNoSelf2<T>(T);
|
|
|
|
|
|
|
|
impl<T> RetImplTraitNoSelf2<T> {
|
|
|
|
// should trigger lint
|
|
|
|
fn new(t: T) -> impl Trait2<(), i32> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RetImplTraitSelfAdt<'a>(&'a str);
|
|
|
|
|
|
|
|
impl<'a> RetImplTraitSelfAdt<'a> {
|
|
|
|
// should not trigger lint
|
|
|
|
fn new<'b: 'a>(s: &'b str) -> impl Into<RetImplTraitSelfAdt<'b>> {
|
|
|
|
RetImplTraitSelfAdt(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|