2023-09-13 18:58:47 +00:00
|
|
|
//@aux-build:proc_macros.rs
|
2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::redundant_field_names)]
|
2023-02-10 13:01:19 +00:00
|
|
|
#![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)]
|
2018-03-05 08:30:07 +00:00
|
|
|
|
2018-03-11 04:57:28 +00:00
|
|
|
#[macro_use]
|
2023-09-13 18:58:47 +00:00
|
|
|
extern crate proc_macros;
|
2018-03-11 04:57:28 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
|
2018-02-10 20:13:17 +00:00
|
|
|
|
|
|
|
mod foo {
|
|
|
|
pub const BAR: u8 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Person {
|
|
|
|
gender: u8,
|
|
|
|
age: u8,
|
2018-02-11 09:50:19 +00:00
|
|
|
name: u8,
|
2018-02-10 20:13:17 +00:00
|
|
|
buzz: u64,
|
|
|
|
foo: u8,
|
|
|
|
}
|
|
|
|
|
2018-03-11 04:57:28 +00:00
|
|
|
pub struct S {
|
2024-03-07 12:19:33 +00:00
|
|
|
v: usize,
|
2018-03-11 04:57:28 +00:00
|
|
|
}
|
|
|
|
|
2018-02-10 20:13:17 +00:00
|
|
|
fn main() {
|
|
|
|
let gender: u8 = 42;
|
|
|
|
let age = 0;
|
|
|
|
let fizz: u64 = 0;
|
2018-02-11 09:50:19 +00:00
|
|
|
let name: u8 = 0;
|
2018-02-10 20:13:17 +00:00
|
|
|
|
|
|
|
let me = Person {
|
|
|
|
gender: gender,
|
|
|
|
age: age,
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
name, //should be ok
|
|
|
|
buzz: fizz, //should be ok
|
2018-02-10 20:13:17 +00:00
|
|
|
foo: foo::BAR, //should be ok
|
|
|
|
};
|
2018-03-05 05:31:37 +00:00
|
|
|
|
2018-03-05 08:30:07 +00:00
|
|
|
// Range expressions
|
2018-03-05 05:31:37 +00:00
|
|
|
let (start, end) = (0, 0);
|
|
|
|
|
|
|
|
let _ = start..;
|
|
|
|
let _ = ..end;
|
|
|
|
let _ = start..end;
|
|
|
|
|
|
|
|
let _ = ..=end;
|
|
|
|
let _ = start..=end;
|
|
|
|
|
2018-08-14 05:27:56 +00:00
|
|
|
// Issue #2799
|
|
|
|
let _: Vec<_> = (start..end).collect();
|
|
|
|
|
2018-03-05 08:30:07 +00:00
|
|
|
// hand-written Range family structs are linted
|
|
|
|
let _ = RangeFrom { start: start };
|
|
|
|
let _ = RangeTo { end: end };
|
|
|
|
let _ = Range { start: start, end: end };
|
2018-05-03 13:52:44 +00:00
|
|
|
let _ = RangeInclusive::new(start, end);
|
2018-03-05 08:30:07 +00:00
|
|
|
let _ = RangeToInclusive { end: end };
|
2023-09-13 18:58:47 +00:00
|
|
|
|
|
|
|
external! {
|
2024-03-07 12:19:33 +00:00
|
|
|
let v = 1;
|
2023-09-13 18:58:47 +00:00
|
|
|
let _ = S {
|
|
|
|
v: v
|
|
|
|
};
|
|
|
|
}
|
2024-03-07 12:19:33 +00:00
|
|
|
|
|
|
|
let v = 2;
|
|
|
|
macro_rules! internal {
|
|
|
|
($i:ident) => {
|
|
|
|
let _ = S { v: v };
|
|
|
|
let _ = S { $i: v };
|
|
|
|
let _ = S { v: $i };
|
|
|
|
let _ = S { $i: $i };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
internal!(v);
|
2018-02-10 20:13:17 +00:00
|
|
|
}
|
2018-12-11 14:33:23 +00:00
|
|
|
|
|
|
|
fn issue_3476() {
|
2018-12-27 15:17:45 +00:00
|
|
|
fn foo<T>() {}
|
2018-12-11 14:33:23 +00:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
foo: fn(),
|
|
|
|
}
|
|
|
|
|
|
|
|
S { foo: foo::<i32> };
|
|
|
|
}
|
2022-10-23 13:18:45 +00:00
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.16"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_16() {
|
|
|
|
let start = 0;
|
|
|
|
let _ = RangeFrom { start: start };
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.17"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_17() {
|
|
|
|
let start = 0;
|
|
|
|
let _ = RangeFrom { start: start };
|
|
|
|
}
|