diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/crashes | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/crashes')
121 files changed, 1812 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/crashes/associated-constant-ice.rs b/src/tools/clippy/tests/ui/crashes/associated-constant-ice.rs new file mode 100644 index 000000000..948deba3e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/associated-constant-ice.rs @@ -0,0 +1,13 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/1698 + +pub trait Trait { + const CONSTANT: u8; +} + +impl Trait for u8 { + const CONSTANT: u8 = 2; +} + +fn main() { + println!("{}", u8::CONSTANT * 10); +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-4727-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-4727-aux.rs new file mode 100644 index 000000000..58a20caf6 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-4727-aux.rs @@ -0,0 +1,9 @@ +pub trait Trait { + fn fun(par: &str) -> &str; +} + +impl Trait for str { + fn fun(par: &str) -> &str { + &par[0..1] + } +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7272-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7272-aux.rs new file mode 100644 index 000000000..780797e3c --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7272-aux.rs @@ -0,0 +1,14 @@ +pub fn warn<T>(_: T) {} + +macro_rules! define_macro { + ($d:tt $lower:ident $upper:ident) => { + #[macro_export] + macro_rules! $upper { + ($arg:tt) => { + $crate::$lower($arg) + }; + } + }; +} + +define_macro! {$ warn WARNING} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs new file mode 100644 index 000000000..bee29894b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs @@ -0,0 +1,3 @@ +fn zero() { + unsafe { 0 }; +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7934-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7934-aux.rs new file mode 100644 index 000000000..4afbf027b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7934-aux.rs @@ -0,0 +1,4 @@ +fn zero() { + // SAFETY: + unsafe { 0 }; +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-8681-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-8681-aux.rs new file mode 100644 index 000000000..95b631513 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-8681-aux.rs @@ -0,0 +1,6 @@ +pub fn foo(x: &u32) -> u32 { + /* Safety: + * This is totally ok. + */ + unsafe { *(x as *const u32) } +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs new file mode 100644 index 000000000..5ff2af7cd --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs @@ -0,0 +1,38 @@ +// compile-flags: --emit=link +// no-prefer-dynamic +// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro +// crates. If we don't set this, compiletest will override the `crate_type` attribute below and +// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't +// contain a proc-macro. + +#![feature(repr128)] +#![allow(incomplete_features)] +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; + +#[proc_macro] +pub fn macro_test(input_stream: TokenStream) -> TokenStream { + let first_token = input_stream.into_iter().next().unwrap(); + let span = first_token.span(); + + TokenStream::from_iter(vec![ + TokenTree::Ident(Ident::new("fn", Span::call_site())), + TokenTree::Ident(Ident::new("code", Span::call_site())), + TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())), + TokenTree::Group(Group::new(Delimiter::Brace, { + let mut clause = Group::new(Delimiter::Brace, TokenStream::new()); + clause.set_span(span); + + TokenStream::from_iter(vec![ + TokenTree::Ident(Ident::new("if", Span::call_site())), + TokenTree::Ident(Ident::new("true", Span::call_site())), + TokenTree::Group(clause.clone()), + TokenTree::Ident(Ident::new("else", Span::call_site())), + TokenTree::Group(clause), + ]) + })), + ]) +} diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/use_self_macro.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/use_self_macro.rs new file mode 100644 index 000000000..a8a85b4ba --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/use_self_macro.rs @@ -0,0 +1,15 @@ +macro_rules! use_self { + ( + impl $ty:ident { + fn func(&$this:ident) { + [fields($($field:ident)*)] + } + } + ) => ( + impl $ty { + fn func(&$this) { + let $ty { $($field),* } = $this; + } + } + ) +} diff --git a/src/tools/clippy/tests/ui/crashes/cc_seme.rs b/src/tools/clippy/tests/ui/crashes/cc_seme.rs new file mode 100644 index 000000000..98588be9c --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/cc_seme.rs @@ -0,0 +1,27 @@ +#[allow(dead_code)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/478 + +enum Baz { + One, + Two, +} + +struct Test { + t: Option<usize>, + b: Baz, +} + +fn main() {} + +pub fn foo() { + use Baz::*; + let x = Test { t: Some(0), b: One }; + + match x { + Test { t: Some(_), b: One } => unreachable!(), + Test { t: Some(42), b: Two } => unreachable!(), + Test { t: None, .. } => unreachable!(), + Test { .. } => unreachable!(), + } +} diff --git a/src/tools/clippy/tests/ui/crashes/enum-glob-import-crate.rs b/src/tools/clippy/tests/ui/crashes/enum-glob-import-crate.rs new file mode 100644 index 000000000..dca32aa3b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/enum-glob-import-crate.rs @@ -0,0 +1,6 @@ +#![deny(clippy::all)] +#![allow(unused_imports)] + +use std::*; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-1588.rs b/src/tools/clippy/tests/ui/crashes/ice-1588.rs new file mode 100644 index 000000000..b0a3d11bc --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-1588.rs @@ -0,0 +1,13 @@ +#![allow(clippy::all)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/1588 + +fn main() { + match 1 { + 1 => {}, + 2 => { + [0; 1]; + }, + _ => {}, + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-1782.rs b/src/tools/clippy/tests/ui/crashes/ice-1782.rs new file mode 100644 index 000000000..81af88962 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-1782.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused_variables)] + +/// Should not trigger an ICE in `SpanlessEq` / `consts::constant` +/// +/// Issue: https://github.com/rust-lang/rust-clippy/issues/1782 +use std::{mem, ptr}; + +fn spanless_eq_ice() { + let txt = "something"; + match txt { + "something" => unsafe { + ptr::write( + ptr::null_mut() as *mut u32, + mem::transmute::<[u8; 4], _>([0, 0, 0, 255]), + ) + }, + _ => unsafe { + ptr::write( + ptr::null_mut() as *mut u32, + mem::transmute::<[u8; 4], _>([13, 246, 24, 255]), + ) + }, + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-1969.rs b/src/tools/clippy/tests/ui/crashes/ice-1969.rs new file mode 100644 index 000000000..96a8fe6c2 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-1969.rs @@ -0,0 +1,13 @@ +#![allow(clippy::all)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/1969 + +fn main() {} + +pub trait Convert { + type Action: From<*const f64>; + + fn convert(val: *const f64) -> Self::Action { + val.into() + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2499.rs b/src/tools/clippy/tests/ui/crashes/ice-2499.rs new file mode 100644 index 000000000..45b3b1869 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2499.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, clippy::char_lit_as_u8, clippy::needless_bool)] + +/// Should not trigger an ICE in `SpanlessHash` / `consts::constant` +/// +/// Issue: https://github.com/rust-lang/rust-clippy/issues/2499 + +fn f(s: &[u8]) -> bool { + let t = s[0] as char; + + match t { + 'E' | 'W' => {}, + 'T' => { + if s[0..4] != ['0' as u8; 4] { + return false; + } else { + return true; + } + }, + _ => { + return false; + }, + } + true +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2594.rs b/src/tools/clippy/tests/ui/crashes/ice-2594.rs new file mode 100644 index 000000000..3f3986b6f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2594.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused_variables)] + +/// Should not trigger an ICE in `SpanlessHash` / `consts::constant` +/// +/// Issue: https://github.com/rust-lang/rust-clippy/issues/2594 + +fn spanless_hash_ice() { + let txt = "something"; + let empty_header: [u8; 1] = [1; 1]; + + match txt { + "something" => { + let mut headers = [empty_header; 1]; + }, + "" => (), + _ => (), + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2727.rs b/src/tools/clippy/tests/ui/crashes/ice-2727.rs new file mode 100644 index 000000000..56024abc8 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2727.rs @@ -0,0 +1,7 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/2727 + +pub fn f(new: fn()) { + new(); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2760.rs b/src/tools/clippy/tests/ui/crashes/ice-2760.rs new file mode 100644 index 000000000..f1a229f3f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2760.rs @@ -0,0 +1,23 @@ +#![allow( + unused_variables, + clippy::blacklisted_name, + clippy::needless_pass_by_value, + dead_code +)] + +/// This should not compile-fail with: +/// +/// error[E0277]: the trait bound `T: Foo` is not satisfied +// See rust-lang/rust-clippy#2760. + +trait Foo { + type Bar; +} + +struct Baz<T: Foo> { + bar: T::Bar, +} + +fn take<T: Foo>(baz: Baz<T>) {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.rs b/src/tools/clippy/tests/ui/crashes/ice-2774.rs new file mode 100644 index 000000000..88cfa1f92 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2774.rs @@ -0,0 +1,27 @@ +use std::collections::HashSet; + +// See rust-lang/rust-clippy#2774. + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Bar { + foo: Foo, +} + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Foo; + +#[allow(clippy::implicit_hasher)] +// This should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +#[allow(clippy::implicit_hasher)] +// Also, this should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) { + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr new file mode 100644 index 000000000..0c2d48f93 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr @@ -0,0 +1,10 @@ +error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) + --> $DIR/ice-2774.rs:15:1 + | +LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-2862.rs b/src/tools/clippy/tests/ui/crashes/ice-2862.rs new file mode 100644 index 000000000..8326e3663 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2862.rs @@ -0,0 +1,16 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/2862 + +pub trait FooMap { + fn map<B, F: Fn() -> B>(&self, f: F) -> B; +} + +impl FooMap for bool { + fn map<B, F: Fn() -> B>(&self, f: F) -> B { + f() + } +} + +fn main() { + let a = true; + a.map(|| false); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2865.rs b/src/tools/clippy/tests/ui/crashes/ice-2865.rs new file mode 100644 index 000000000..c62981396 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2865.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, clippy::extra_unused_lifetimes)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/2865 + +struct Ice { + size: String, +} + +impl<'a> From<String> for Ice { + fn from(_: String) -> Self { + let text = || "iceberg".to_string(); + Self { size: text() } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3151.rs b/src/tools/clippy/tests/ui/crashes/ice-3151.rs new file mode 100644 index 000000000..268ba86fc --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3151.rs @@ -0,0 +1,15 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/3151 + +#[derive(Clone)] +pub struct HashMap<V, S> { + hash_builder: S, + table: RawTable<V>, +} + +#[derive(Clone)] +pub struct RawTable<V> { + size: usize, + val: V, +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3462.rs b/src/tools/clippy/tests/ui/crashes/ice-3462.rs new file mode 100644 index 000000000..02c49aa0d --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3462.rs @@ -0,0 +1,23 @@ +#![warn(clippy::all)] +#![allow(clippy::blacklisted_name, clippy::equatable_if_let)] +#![allow(unused)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/3462 + +enum Foo { + Bar, + Baz, +} + +fn bar(foo: Foo) { + macro_rules! baz { + () => { + if let Foo::Bar = foo {} + }; + } + + baz!(); + baz!(); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-360.rs b/src/tools/clippy/tests/ui/crashes/ice-360.rs new file mode 100644 index 000000000..6555c19ca --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-360.rs @@ -0,0 +1,12 @@ +fn main() {} + +fn no_panic<T>(slice: &[T]) { + let mut iter = slice.iter(); + loop { + let _ = match iter.next() { + Some(ele) => ele, + None => break, + }; + loop {} + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-360.stderr b/src/tools/clippy/tests/ui/crashes/ice-360.stderr new file mode 100644 index 000000000..0eb7bb12b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-360.stderr @@ -0,0 +1,25 @@ +error: this loop could be written as a `while let` loop + --> $DIR/ice-360.rs:5:5 + | +LL | / loop { +LL | | let _ = match iter.next() { +LL | | Some(ele) => ele, +LL | | None => break, +LL | | }; +LL | | loop {} +LL | | } + | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` + | + = note: `-D clippy::while-let-loop` implied by `-D warnings` + +error: empty `loop {}` wastes CPU cycles + --> $DIR/ice-360.rs:10:9 + | +LL | loop {} + | ^^^^^^^ + | + = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui/crashes/ice-3717.rs b/src/tools/clippy/tests/ui/crashes/ice-3717.rs new file mode 100644 index 000000000..f50714643 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3717.rs @@ -0,0 +1,10 @@ +#![deny(clippy::implicit_hasher)] + +use std::collections::HashSet; + +fn main() {} + +pub fn ice_3717(_: &HashSet<usize>) { + let _ = [0u8; 0]; + let _: HashSet<usize> = HashSet::new(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3717.stderr b/src/tools/clippy/tests/ui/crashes/ice-3717.stderr new file mode 100644 index 000000000..4d3d617b6 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3717.stderr @@ -0,0 +1,22 @@ +error: parameter of type `HashSet` should be generalized over different hashers + --> $DIR/ice-3717.rs:7:21 + | +LL | pub fn ice_3717(_: &HashSet<usize>) { + | ^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/ice-3717.rs:1:9 + | +LL | #![deny(clippy::implicit_hasher)] + | ^^^^^^^^^^^^^^^^^^^^^^^ +help: consider adding a type parameter + | +LL | pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) { + | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~ +help: ...and use generic constructor + | +LL | let _: HashSet<usize> = HashSet::default(); + | ~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-3741.rs b/src/tools/clippy/tests/ui/crashes/ice-3741.rs new file mode 100644 index 000000000..1253ddcfa --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3741.rs @@ -0,0 +1,10 @@ +// aux-build:proc_macro_crash.rs + +#![warn(clippy::suspicious_else_formatting)] + +extern crate proc_macro_crash; +use proc_macro_crash::macro_test; + +fn main() { + macro_test!(2); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3747.rs b/src/tools/clippy/tests/ui/crashes/ice-3747.rs new file mode 100644 index 000000000..cdf018cbc --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3747.rs @@ -0,0 +1,17 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/3747 + +macro_rules! a { + ( $pub:tt $($attr:tt)* ) => { + $($attr)* $pub fn say_hello() {} + }; +} + +macro_rules! b { + () => { + a! { pub } + }; +} + +b! {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3891.rs b/src/tools/clippy/tests/ui/crashes/ice-3891.rs new file mode 100644 index 000000000..05c5134c8 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3891.rs @@ -0,0 +1,3 @@ +fn main() { + 1x; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3891.stderr b/src/tools/clippy/tests/ui/crashes/ice-3891.stderr new file mode 100644 index 000000000..59469ec58 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3891.stderr @@ -0,0 +1,10 @@ +error: invalid suffix `x` for number literal + --> $DIR/ice-3891.rs:2:5 + | +LL | 1x; + | ^^ invalid suffix `x` + | + = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.) + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-3969.rs b/src/tools/clippy/tests/ui/crashes/ice-3969.rs new file mode 100644 index 000000000..9b68cac7f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3969.rs @@ -0,0 +1,50 @@ +// https://github.com/rust-lang/rust-clippy/issues/3969 +// used to crash: error: internal compiler error: +// src/librustc_traits/normalize_erasing_regions.rs:43: could not fully normalize `<i32 as +// std::iter::Iterator>::Item test from rustc ./ui/trivial-bounds/trivial-bounds-inconsistent.rs + +// Check that tautalogically false bounds are accepted, and are used +// in type inference. +#![feature(trivial_bounds)] +#![allow(unused)] +trait A {} + +impl A for i32 {} + +struct Dst<X: ?Sized> { + x: X, +} + +struct TwoStrs(str, str) +where + str: Sized; + +fn unsized_local() +where + for<'a> Dst<dyn A + 'a>: Sized, +{ + let x: Dst<dyn A> = *(Box::new(Dst { x: 1 }) as Box<Dst<dyn A>>); +} + +fn return_str() -> str +where + str: Sized, +{ + *"Sized".to_string().into_boxed_str() +} + +fn use_op(s: String) -> String +where + String: ::std::ops::Neg<Output = String>, +{ + -s +} + +fn use_for() +where + i32: Iterator, +{ + for _ in 2i32 {} +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3969.stderr b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr new file mode 100644 index 000000000..790180808 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr @@ -0,0 +1,34 @@ +error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters + --> $DIR/ice-3969.rs:20:10 + | +LL | str: Sized; + | ^^^^^ + | + = note: `-D trivial-bounds` implied by `-D warnings` + +error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters + --> $DIR/ice-3969.rs:24:30 + | +LL | for<'a> Dst<dyn A + 'a>: Sized, + | ^^^^^ + +error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters + --> $DIR/ice-3969.rs:31:10 + | +LL | str: Sized, + | ^^^^^ + +error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters + --> $DIR/ice-3969.rs:38:13 + | +LL | String: ::std::ops::Neg<Output = String>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters + --> $DIR/ice-3969.rs:45:10 + | +LL | i32: Iterator, + | ^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/src/tools/clippy/tests/ui/crashes/ice-4121.rs b/src/tools/clippy/tests/ui/crashes/ice-4121.rs new file mode 100644 index 000000000..e1a142fdc --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4121.rs @@ -0,0 +1,13 @@ +use std::mem; + +pub struct Foo<A, B>(A, B); + +impl<A, B> Foo<A, B> { + const HOST_SIZE: usize = mem::size_of::<B>(); + + pub fn crash() -> bool { + Self::HOST_SIZE == 0 + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4545.rs b/src/tools/clippy/tests/ui/crashes/ice-4545.rs new file mode 100644 index 000000000..d9c9c2096 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4545.rs @@ -0,0 +1,14 @@ +fn repro() { + trait Foo { + type Bar; + } + + #[allow(dead_code)] + struct Baz<T: Foo> { + field: T::Bar, + } +} + +fn main() { + repro(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4579.rs b/src/tools/clippy/tests/ui/crashes/ice-4579.rs new file mode 100644 index 000000000..2e7e279f8 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4579.rs @@ -0,0 +1,13 @@ +#![allow(clippy::single_match)] + +use std::ptr; + +fn main() { + match Some(0_usize) { + Some(_) => { + let s = "012345"; + unsafe { ptr::read(s.as_ptr().offset(1) as *const [u8; 5]) }; + }, + _ => (), + }; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4671.rs b/src/tools/clippy/tests/ui/crashes/ice-4671.rs new file mode 100644 index 000000000..64e8e7769 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4671.rs @@ -0,0 +1,21 @@ +#![warn(clippy::use_self)] + +#[macro_use] +#[path = "auxiliary/use_self_macro.rs"] +mod use_self_macro; + +struct Foo { + a: u32, +} + +use_self! { + impl Foo { + fn func(&self) { + [fields( + a + )] + } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4727.rs b/src/tools/clippy/tests/ui/crashes/ice-4727.rs new file mode 100644 index 000000000..2a4bc83f5 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4727.rs @@ -0,0 +1,6 @@ +#![warn(clippy::use_self)] + +#[path = "auxiliary/ice-4727-aux.rs"] +mod aux; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4760.rs b/src/tools/clippy/tests/ui/crashes/ice-4760.rs new file mode 100644 index 000000000..08b069617 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4760.rs @@ -0,0 +1,9 @@ +const COUNT: usize = 2; +struct Thing; +trait Dummy {} + +const _: () = { + impl Dummy for Thing where [i32; COUNT]: Sized {} +}; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4775.rs b/src/tools/clippy/tests/ui/crashes/ice-4775.rs new file mode 100644 index 000000000..405e3039e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4775.rs @@ -0,0 +1,11 @@ +pub struct ArrayWrapper<const N: usize>([usize; N]); + +impl<const N: usize> ArrayWrapper<{ N }> { + pub fn ice(&self) { + for i in self.0.iter() { + println!("{}", i); + } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-4968.rs b/src/tools/clippy/tests/ui/crashes/ice-4968.rs new file mode 100644 index 000000000..e0510d942 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-4968.rs @@ -0,0 +1,21 @@ +// check-pass + +// Test for https://github.com/rust-lang/rust-clippy/issues/4968 + +#![warn(clippy::unsound_collection_transmute)] +#![allow(clippy::transmute_undefined_repr)] + +trait Trait { + type Assoc; +} + +use std::mem::{self, ManuallyDrop}; + +#[allow(unused)] +fn func<T: Trait>(slice: Vec<T::Assoc>) { + unsafe { + let _: Vec<ManuallyDrop<T::Assoc>> = mem::transmute(slice); + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5207.rs b/src/tools/clippy/tests/ui/crashes/ice-5207.rs new file mode 100644 index 000000000..f463f78a9 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5207.rs @@ -0,0 +1,5 @@ +// Regression test for https://github.com/rust-lang/rust-clippy/issues/5207 + +pub async fn bar<'a, T: 'a>(_: T) {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5223.rs b/src/tools/clippy/tests/ui/crashes/ice-5223.rs new file mode 100644 index 000000000..e3b3b27a6 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5223.rs @@ -0,0 +1,15 @@ +// Regression test for #5233 +#![warn(clippy::indexing_slicing, clippy::iter_cloned_collect)] + +pub struct KotomineArray<T, const N: usize> { + arr: [T; N], +} + +impl<T: std::clone::Clone, const N: usize> KotomineArray<T, N> { + pub fn ice(self) { + let _ = self.arr[..]; + let _ = self.arr.iter().cloned().collect::<Vec<_>>(); + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5238.rs b/src/tools/clippy/tests/ui/crashes/ice-5238.rs new file mode 100644 index 000000000..989eb6d44 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5238.rs @@ -0,0 +1,9 @@ +// Regression test for #5238 / https://github.com/rust-lang/rust/pull/69562 + +#![feature(generators, generator_trait)] + +fn main() { + let _ = || { + yield; + }; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5389.rs b/src/tools/clippy/tests/ui/crashes/ice-5389.rs new file mode 100644 index 000000000..de2621990 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5389.rs @@ -0,0 +1,13 @@ +#![allow(clippy::explicit_counter_loop)] + +fn main() { + let v = vec![1, 2, 3]; + let mut i = 0; + let max_storage_size = [0; 128 * 1024]; + for item in &v { + bar(i, *item); + i += 1; + } +} + +fn bar(_: usize, _: u32) {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5497.rs b/src/tools/clippy/tests/ui/crashes/ice-5497.rs new file mode 100644 index 000000000..0769bce5f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5497.rs @@ -0,0 +1,11 @@ +// reduced from rustc issue-69020-assoc-const-arith-overflow.rs +pub fn main() {} + +pub trait Foo { + const OOB: i32; +} + +impl<T: Foo> Foo for Vec<T> { + const OOB: i32 = [1][1] + T::OOB; + //~^ ERROR operation will panic +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5497.stderr b/src/tools/clippy/tests/ui/crashes/ice-5497.stderr new file mode 100644 index 000000000..e75e7dc91 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5497.stderr @@ -0,0 +1,10 @@ +error: this operation will panic at runtime + --> $DIR/ice-5497.rs:9:22 + | +LL | const OOB: i32 = [1][1] + T::OOB; + | ^^^^^^ index out of bounds: the length is 1 but the index is 1 + | + = note: `#[deny(unconditional_panic)]` on by default + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-5579.rs b/src/tools/clippy/tests/ui/crashes/ice-5579.rs new file mode 100644 index 000000000..e1842c73f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5579.rs @@ -0,0 +1,17 @@ +trait IsErr { + fn is_err(&self, err: &str) -> bool; +} + +impl<T> IsErr for Option<T> { + fn is_err(&self, _err: &str) -> bool { + true + } +} + +fn main() { + let t = Some(1); + + if t.is_err("") { + t.unwrap(); + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5835.rs b/src/tools/clippy/tests/ui/crashes/ice-5835.rs new file mode 100644 index 000000000..5e99cb432 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5835.rs @@ -0,0 +1,9 @@ +#[rustfmt::skip] +pub struct Foo { + /// 位 + /// ^ Do not remove this tab character. + /// It was required to trigger the ICE. + pub bar: u8, +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5835.stderr b/src/tools/clippy/tests/ui/crashes/ice-5835.stderr new file mode 100644 index 000000000..c972bcb60 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5835.stderr @@ -0,0 +1,10 @@ +error: using tabs in doc comments is not recommended + --> $DIR/ice-5835.rs:3:10 + | +LL | /// 位 + | ^^^^ help: consider using four spaces per tab + | + = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-5872.rs b/src/tools/clippy/tests/ui/crashes/ice-5872.rs new file mode 100644 index 000000000..68afa8f8c --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5872.rs @@ -0,0 +1,5 @@ +#![warn(clippy::needless_collect)] + +fn main() { + let _ = vec![1, 2, 3].into_iter().collect::<Vec<_>>().is_empty(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5872.stderr b/src/tools/clippy/tests/ui/crashes/ice-5872.stderr new file mode 100644 index 000000000..a60ca345c --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5872.stderr @@ -0,0 +1,10 @@ +error: avoid using `collect()` when not needed + --> $DIR/ice-5872.rs:4:39 + | +LL | let _ = vec![1, 2, 3].into_iter().collect::<Vec<_>>().is_empty(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` + | + = note: `-D clippy::needless-collect` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-5944.rs b/src/tools/clippy/tests/ui/crashes/ice-5944.rs new file mode 100644 index 000000000..ce46bc1ac --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5944.rs @@ -0,0 +1,14 @@ +#![warn(clippy::repeat_once)] +#![allow(clippy::let_unit_value)] + +trait Repeat { + fn repeat(&self) {} +} + +impl Repeat for usize { + fn repeat(&self) {} +} + +fn main() { + let _ = 42.repeat(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6139.rs b/src/tools/clippy/tests/ui/crashes/ice-6139.rs new file mode 100644 index 000000000..f3966e47f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6139.rs @@ -0,0 +1,7 @@ +trait T<'a> {} + +fn foo(_: Vec<Box<dyn T<'_>>>) {} + +fn main() { + foo(vec![]); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6153.rs b/src/tools/clippy/tests/ui/crashes/ice-6153.rs new file mode 100644 index 000000000..9f73f39f1 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6153.rs @@ -0,0 +1,9 @@ +pub struct S<'a, 'e>(&'a str, &'e str); + +pub type T<'a, 'e> = std::collections::HashMap<S<'a, 'e>, ()>; + +impl<'e, 'a: 'e> S<'a, 'e> { + pub fn foo(_a: &str, _b: &str, _map: &T) {} +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6179.rs b/src/tools/clippy/tests/ui/crashes/ice-6179.rs new file mode 100644 index 000000000..4fe92d356 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6179.rs @@ -0,0 +1,21 @@ +//! This is a minimal reproducer for the ICE in https://github.com/rust-lang/rust-clippy/pull/6179. +//! The ICE is mainly caused by using `hir_ty_to_ty`. See the discussion in the PR for details. + +#![warn(clippy::use_self)] +#![allow(dead_code)] + +struct Foo; + +impl Foo { + fn new() -> Self { + impl Foo { + fn bar() {} + } + + let _: _ = 1; + + Self {} + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.rs b/src/tools/clippy/tests/ui/crashes/ice-6250.rs new file mode 100644 index 000000000..c33580ff6 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6250.rs @@ -0,0 +1,16 @@ +// originally from glacier/fixed/77218.rs +// ice while adjusting... + +pub struct Cache { + data: Vec<i32>, +} + +pub fn list_data(cache: &Cache, key: usize) { + for reference in vec![1, 2, 3] { + if + /* let */ + Some(reference) = cache.data.get(key) { + unimplemented!() + } + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr new file mode 100644 index 000000000..878897c41 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr @@ -0,0 +1,30 @@ +error[E0601]: `main` function not found in crate `ice_6250` + --> $DIR/ice-6250.rs:16:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/ice-6250.rs` + +error[E0308]: mismatched types + --> $DIR/ice-6250.rs:12:14 + | +LL | for reference in vec![1, 2, 3] { + | --------- expected due to the type of this binding +... +LL | Some(reference) = cache.data.get(key) { + | ^^^^^^^^^ expected integer, found `&i32` + | +help: consider dereferencing the borrow + | +LL | Some(*reference) = cache.data.get(key) { + | + + +error[E0308]: mismatched types + --> $DIR/ice-6250.rs:12:9 + | +LL | Some(reference) = cache.data.get(key) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0601. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.rs b/src/tools/clippy/tests/ui/crashes/ice-6251.rs new file mode 100644 index 000000000..6aa779aae --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6251.rs @@ -0,0 +1,6 @@ +// originally from glacier/fixed/77329.rs +// assertion failed: `(left == right) ; different DefIds + +fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { + std::iter::empty() +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr new file mode 100644 index 000000000..8da2965c6 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr @@ -0,0 +1,41 @@ +error[E0601]: `main` function not found in crate `ice_6251` + --> $DIR/ice-6251.rs:6:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/ice-6251.rs` + +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/ice-6251.rs:4:45 + | +LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { + | ^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `[u8]` + = help: unsized fn params are gated as an unstable feature +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: &[u8]| x }]> { + | + + +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/ice-6251.rs:4:54 + | +LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { + | ^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `[u8]` + = note: the return type of a function must have a statically known size + +error[E0308]: mismatched types + --> $DIR/ice-6251.rs:4:44 + | +LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { + | ^^^^^^^^^^^ expected `usize`, found closure + | + = note: expected type `usize` + found closure `[closure@$DIR/ice-6251.rs:4:44: 4:53]` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0277, E0308, E0601. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.rs b/src/tools/clippy/tests/ui/crashes/ice-6252.rs new file mode 100644 index 000000000..0ccf0aae9 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6252.rs @@ -0,0 +1,14 @@ +// originally from glacier fixed/77919.rs +// encountered errors resolving bounds after type-checking +trait TypeVal<T> { + const VAL: T; +} +struct Five; +struct Multiply<N, M> { + _n: PhantomData, +} +impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {} + +fn main() { + [1; <Multiply<Five, Five>>::VAL]; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr new file mode 100644 index 000000000..638e4a548 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr @@ -0,0 +1,36 @@ +error[E0412]: cannot find type `PhantomData` in this scope + --> $DIR/ice-6252.rs:8:9 + | +LL | _n: PhantomData, + | ^^^^^^^^^^^ not found in this scope + | +help: consider importing one of these items + | +LL | use core::marker::PhantomData; + | +LL | use serde::__private::PhantomData; + | +LL | use std::marker::PhantomData; + | + +error[E0412]: cannot find type `VAL` in this scope + --> $DIR/ice-6252.rs:10:63 + | +LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {} + | - ^^^ not found in this scope + | | + | help: you might be missing a type parameter: `, VAL` + +error[E0046]: not all trait items implemented, missing: `VAL` + --> $DIR/ice-6252.rs:10:1 + | +LL | const VAL: T; + | ------------ `VAL` from trait +... +LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0046, E0412. +For more information about an error, try `rustc --explain E0046`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.rs b/src/tools/clippy/tests/ui/crashes/ice-6254.rs new file mode 100644 index 000000000..a2a60a169 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6254.rs @@ -0,0 +1,16 @@ +// originally from ./src/test/ui/pattern/usefulness/consts-opaque.rs +// panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', +// compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5 + +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(PartialEq)] +struct Foo(i32); +const FOO_REF_REF: &&Foo = &&Foo(42); + +fn main() { + // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) + match FOO_REF_REF { + FOO_REF_REF => {}, + Foo(_) => {}, + } +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr new file mode 100644 index 000000000..f37ab2e9b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr @@ -0,0 +1,12 @@ +error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]` + --> $DIR/ice-6254.rs:13:9 + | +LL | FOO_REF_REF => {}, + | ^^^^^^^^^^^ + | + = note: `-D indirect-structural-match` implied by `-D warnings` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411> + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-6255.rs b/src/tools/clippy/tests/ui/crashes/ice-6255.rs new file mode 100644 index 000000000..bd4a81d98 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6255.rs @@ -0,0 +1,15 @@ +// originally from rustc ./src/test/ui/macros/issue-78325-inconsistent-resolution.rs +// inconsistent resolution for a macro + +macro_rules! define_other_core { + ( ) => { + extern crate std as core; + //~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern` + }; +} + +fn main() { + core::panic!(); +} + +define_other_core!(); diff --git a/src/tools/clippy/tests/ui/crashes/ice-6255.stderr b/src/tools/clippy/tests/ui/crashes/ice-6255.stderr new file mode 100644 index 000000000..db0cb25e3 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6255.stderr @@ -0,0 +1,13 @@ +error: macro-expanded `extern crate` items cannot shadow names passed with `--extern` + --> $DIR/ice-6255.rs:6:9 + | +LL | extern crate std as core; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | define_other_core!(); + | -------------------- in this macro invocation + | + = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.rs b/src/tools/clippy/tests/ui/crashes/ice-6256.rs new file mode 100644 index 000000000..67308263d --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6256.rs @@ -0,0 +1,15 @@ +// originally from rustc ./src/test/ui/regions/issue-78262.rs +// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig() +#![allow(clippy::upper_case_acronyms)] + +trait TT {} + +impl dyn TT { + fn func(&self) {} +} + +#[rustfmt::skip] +fn main() { + let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types + //[nll]~^ ERROR: borrowed data escapes outside of closure +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.stderr b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr new file mode 100644 index 000000000..9cfcccf1e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr @@ -0,0 +1,14 @@ +error[E0521]: borrowed data escapes outside of closure + --> $DIR/ice-6256.rs:13:26 + | +LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types + | - - ^^^^^^^^ + | | | | + | | | `x` escapes the closure body here + | | | argument requires that `'1` must outlive `'static` + | | let's call the lifetime of this reference `'1` + | `x` is a reference that is only valid in the closure body + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0521`. diff --git a/src/tools/clippy/tests/ui/crashes/ice-6332.rs b/src/tools/clippy/tests/ui/crashes/ice-6332.rs new file mode 100644 index 000000000..9dc92aa50 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6332.rs @@ -0,0 +1,11 @@ +fn cmark_check() { + let mut link_err = false; + macro_rules! cmark_error { + ($bad:expr) => { + *$bad = true; + }; + } + cmark_error!(&mut link_err); +} + +pub fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6539.rs b/src/tools/clippy/tests/ui/crashes/ice-6539.rs new file mode 100644 index 000000000..ac6c3e4ab --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6539.rs @@ -0,0 +1,16 @@ +// The test for the ICE 6539: https://github.com/rust-lang/rust-clippy/issues/6539. +// The cause is that `zero_sized_map_values` used `layout_of` with types from type aliases, +// which is essentially the same as the ICE 4968. +// Note that only type aliases with associated types caused the crash this time, +// not others such as trait impls. + +use std::collections::{BTreeMap, HashMap}; + +pub trait Trait { + type Assoc; +} + +type TypeAlias<T> = HashMap<(), <T as Trait>::Assoc>; +type TypeAlias2<T> = BTreeMap<(), <T as Trait>::Assoc>; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6792.rs b/src/tools/clippy/tests/ui/crashes/ice-6792.rs new file mode 100644 index 000000000..9cbafc716 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6792.rs @@ -0,0 +1,20 @@ +//! This is a reproducer for the ICE 6792: https://github.com/rust-lang/rust-clippy/issues/6792. +//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`. + +trait Trait { + type Ty; + + fn broken() -> Self::Ty; +} + +struct Foo; + +impl Trait for Foo { + type Ty = Foo; + + fn broken() -> Self::Ty { + Self::Ty {} + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6793.rs b/src/tools/clippy/tests/ui/crashes/ice-6793.rs new file mode 100644 index 000000000..12a4a0d25 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6793.rs @@ -0,0 +1,23 @@ +//! This is a reproducer for the ICE 6793: https://github.com/rust-lang/rust-clippy/issues/6793. +//! The ICE is caused by using `TyCtxt::type_of(assoc_type_id)`, which is the same as the ICE 6792. + +trait Trait { + type Ty: 'static + Clone; + + fn broken() -> Self::Ty; +} + +#[derive(Clone)] +struct MyType { + x: i32, +} + +impl Trait for MyType { + type Ty = MyType; + + fn broken() -> Self::Ty { + Self::Ty { x: 1 } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-6840.rs b/src/tools/clippy/tests/ui/crashes/ice-6840.rs new file mode 100644 index 000000000..d789f60c5 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-6840.rs @@ -0,0 +1,31 @@ +//! This is a reproducer for the ICE 6840: https://github.com/rust-lang/rust-clippy/issues/6840. +//! The ICE is caused by `TyCtxt::layout_of` and `is_normalizable` not being strict enough +#![allow(dead_code)] +use std::collections::HashMap; + +pub trait Rule { + type DependencyKey; +} + +pub struct RuleEdges<R: Rule> { + dependencies: R::DependencyKey, +} + +type RuleDependencyEdges<R> = HashMap<u32, RuleEdges<R>>; + +// reproducer from the GitHub issue ends here +// but check some additional variants +type RuleDependencyEdgesArray<R> = HashMap<u32, [RuleEdges<R>; 8]>; +type RuleDependencyEdgesSlice<R> = HashMap<u32, &'static [RuleEdges<R>]>; +type RuleDependencyEdgesRef<R> = HashMap<u32, &'static RuleEdges<R>>; +type RuleDependencyEdgesRaw<R> = HashMap<u32, *const RuleEdges<R>>; +type RuleDependencyEdgesTuple<R> = HashMap<u32, (RuleEdges<R>, RuleEdges<R>)>; + +// and an additional checks to make sure fix doesn't have stack-overflow issue +// on self-containing types +pub struct SelfContaining { + inner: Box<SelfContaining>, +} +type SelfContainingEdges = HashMap<u32, SelfContaining>; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-700.rs b/src/tools/clippy/tests/ui/crashes/ice-700.rs new file mode 100644 index 000000000..0cbceedbd --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-700.rs @@ -0,0 +1,9 @@ +#![deny(clippy::all)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/700 + +fn core() {} + +fn main() { + core(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7012.rs b/src/tools/clippy/tests/ui/crashes/ice-7012.rs new file mode 100644 index 000000000..60bdbc4f1 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7012.rs @@ -0,0 +1,17 @@ +#![allow(clippy::all)] + +enum _MyOption { + None, + Some(()), +} + +impl _MyOption { + fn _foo(&self) { + match self { + &Self::Some(_) => {}, + _ => {}, + } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7126.rs b/src/tools/clippy/tests/ui/crashes/ice-7126.rs new file mode 100644 index 000000000..ca563ba09 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7126.rs @@ -0,0 +1,14 @@ +// This test requires a feature gated const fn and will stop working in the future. + +#![feature(const_btree_new)] + +use std::collections::BTreeMap; + +struct Foo(BTreeMap<i32, i32>); +impl Foo { + fn new() -> Self { + Self(BTreeMap::new()) + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.rs b/src/tools/clippy/tests/ui/crashes/ice-7169.rs new file mode 100644 index 000000000..82095febc --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7169.rs @@ -0,0 +1,9 @@ +#[derive(Default)] +struct A<T> { + a: Vec<A<T>>, + b: T, +} + +fn main() { + if let Ok(_) = Ok::<_, ()>(A::<String>::default()) {} +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr new file mode 100644 index 000000000..5a9cd3238 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr @@ -0,0 +1,10 @@ +error: redundant pattern matching, consider using `is_ok()` + --> $DIR/ice-7169.rs:8:12 + | +LL | if let Ok(_) = Ok::<_, ()>(A::<String>::default()) {} + | -------^^^^^-------------------------------------- help: try this: `if Ok::<_, ()>(A::<String>::default()).is_ok()` + | + = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-7231.rs b/src/tools/clippy/tests/ui/crashes/ice-7231.rs new file mode 100644 index 000000000..4ad0d3513 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7231.rs @@ -0,0 +1,9 @@ +#![allow(clippy::never_loop)] + +async fn f() { + loop { + break; + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7272.rs b/src/tools/clippy/tests/ui/crashes/ice-7272.rs new file mode 100644 index 000000000..57ab6ca14 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7272.rs @@ -0,0 +1,12 @@ +// aux-build:ice-7272-aux.rs + +#![allow(clippy::no_effect)] + +extern crate ice_7272_aux; + +use ice_7272_aux::*; + +pub fn main() { + || WARNING!("Style changed!"); + || "}{"; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7340.rs b/src/tools/clippy/tests/ui/crashes/ice-7340.rs new file mode 100644 index 000000000..7d2351d60 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7340.rs @@ -0,0 +1,6 @@ +#![allow(clippy::no_effect)] + +fn main() { + const CONSTANT: usize = 8; + [1; 1 % CONSTANT]; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7410.rs b/src/tools/clippy/tests/ui/crashes/ice-7410.rs new file mode 100644 index 000000000..85fa42103 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7410.rs @@ -0,0 +1,32 @@ +// compile-flags: -Clink-arg=-nostartfiles +// ignore-macos +// ignore-windows + +#![feature(lang_items, start, libc)] +#![no_std] +#![allow(clippy::if_same_then_else)] +#![allow(clippy::redundant_pattern_matching)] + +use core::panic::PanicInfo; + +struct S; + +impl Drop for S { + fn drop(&mut self) {} +} + +#[start] +fn main(argc: isize, argv: *const *const u8) -> isize { + if let Some(_) = Some(S) { + } else { + } + 0 +} + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7423.rs b/src/tools/clippy/tests/ui/crashes/ice-7423.rs new file mode 100644 index 000000000..31340b012 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7423.rs @@ -0,0 +1,13 @@ +pub trait Trait { + fn f(); +} + +impl Trait for usize { + fn f() { + extern "C" { + fn g() -> usize; + } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7868.rs b/src/tools/clippy/tests/ui/crashes/ice-7868.rs new file mode 100644 index 000000000..c6932164e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7868.rs @@ -0,0 +1,7 @@ +#![warn(clippy::undocumented_unsafe_blocks)] +#![allow(clippy::no_effect)] + +#[path = "auxiliary/ice-7868-aux.rs"] +mod zero; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7868.stderr b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr new file mode 100644 index 000000000..1a33e6475 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr @@ -0,0 +1,11 @@ +error: unsafe block missing a safety comment + --> $DIR/auxiliary/ice-7868-aux.rs:2:5 + | +LL | unsafe { 0 }; + | ^^^^^^^^^^^^ + | + = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: consider adding a safety comment on the preceding line + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-7869.rs b/src/tools/clippy/tests/ui/crashes/ice-7869.rs new file mode 100644 index 000000000..8f97a063a --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7869.rs @@ -0,0 +1,7 @@ +enum Tila { + TyöAlkoi, + TyöKeskeytyi, + TyöValmis, +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7869.stderr b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr new file mode 100644 index 000000000..4fa9fb27e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr @@ -0,0 +1,15 @@ +error: all variants have the same prefix: `Työ` + --> $DIR/ice-7869.rs:1:1 + | +LL | / enum Tila { +LL | | TyöAlkoi, +LL | | TyöKeskeytyi, +LL | | TyöValmis, +LL | | } + | |_^ + | + = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: remove the prefixes and use full paths to the variants instead of glob imports + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-7934.rs b/src/tools/clippy/tests/ui/crashes/ice-7934.rs new file mode 100644 index 000000000..a4691c413 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7934.rs @@ -0,0 +1,7 @@ +#![warn(clippy::undocumented_unsafe_blocks)] +#![allow(clippy::no_effect)] + +#[path = "auxiliary/ice-7934-aux.rs"] +mod zero; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.rs b/src/tools/clippy/tests/ui/crashes/ice-8250.rs new file mode 100644 index 000000000..d9a5ee116 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8250.rs @@ -0,0 +1,6 @@ +fn _f(s: &str) -> Option<()> { + let _ = s[1..].splitn(2, '.').next()?; + Some(()) +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.stderr b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr new file mode 100644 index 000000000..8ed8f3b3a --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr @@ -0,0 +1,10 @@ +error: unnecessary use of `splitn` + --> $DIR/ice-8250.rs:2:13 + | +LL | let _ = s[1..].splitn(2, '.').next()?; + | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s[1..].split('.')` + | + = note: `-D clippy::needless-splitn` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-8386.rs b/src/tools/clippy/tests/ui/crashes/ice-8386.rs new file mode 100644 index 000000000..3e38b1408 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8386.rs @@ -0,0 +1,3 @@ +fn f(x: u32, mut arg: &String) {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8681.rs b/src/tools/clippy/tests/ui/crashes/ice-8681.rs new file mode 100644 index 000000000..ee14f011f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8681.rs @@ -0,0 +1,10 @@ +// aux-build: ice-8681-aux.rs + +#![warn(clippy::undocumented_unsafe_blocks)] + +#[path = "auxiliary/ice-8681-aux.rs"] +mod ice_8681_aux; + +fn main() { + let _ = ice_8681_aux::foo(&0u32); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8821.rs b/src/tools/clippy/tests/ui/crashes/ice-8821.rs new file mode 100644 index 000000000..fb87b79ae --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8821.rs @@ -0,0 +1,8 @@ +#![warn(clippy::let_unit_value)] + +fn f() {} +static FN: fn() = f; + +fn main() { + let _: () = FN(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8821.stderr b/src/tools/clippy/tests/ui/crashes/ice-8821.stderr new file mode 100644 index 000000000..486096e0a --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8821.stderr @@ -0,0 +1,10 @@ +error: this let-binding has unit value + --> $DIR/ice-8821.rs:7:5 + | +LL | let _: () = FN(); + | ^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `FN();` + | + = note: `-D clippy::let-unit-value` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-8850.rs b/src/tools/clippy/tests/ui/crashes/ice-8850.rs new file mode 100644 index 000000000..f2747ab22 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8850.rs @@ -0,0 +1,27 @@ +fn fn_pointer_static() -> usize { + static FN: fn() -> usize = || 1; + let res = FN() + 1; + res +} + +fn fn_pointer_const() -> usize { + const FN: fn() -> usize = || 1; + let res = FN() + 1; + res +} + +fn deref_to_dyn_fn() -> usize { + struct Derefs; + impl std::ops::Deref for Derefs { + type Target = dyn Fn() -> usize; + + fn deref(&self) -> &Self::Target { + &|| 2 + } + } + static FN: Derefs = Derefs; + let res = FN() + 1; + res +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8850.stderr b/src/tools/clippy/tests/ui/crashes/ice-8850.stderr new file mode 100644 index 000000000..620fd1eda --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8850.stderr @@ -0,0 +1,45 @@ +error: returning the result of a `let` binding from a block + --> $DIR/ice-8850.rs:4:5 + | +LL | let res = FN() + 1; + | ------------------- unnecessary `let` binding +LL | res + | ^^^ + | + = note: `-D clippy::let-and-return` implied by `-D warnings` +help: return the expression directly + | +LL ~ +LL ~ FN() + 1 + | + +error: returning the result of a `let` binding from a block + --> $DIR/ice-8850.rs:10:5 + | +LL | let res = FN() + 1; + | ------------------- unnecessary `let` binding +LL | res + | ^^^ + | +help: return the expression directly + | +LL ~ +LL ~ FN() + 1 + | + +error: returning the result of a `let` binding from a block + --> $DIR/ice-8850.rs:24:5 + | +LL | let res = FN() + 1; + | ------------------- unnecessary `let` binding +LL | res + | ^^^ + | +help: return the expression directly + | +LL ~ +LL ~ FN() + 1 + | + +error: aborting due to 3 previous errors + diff --git a/src/tools/clippy/tests/ui/crashes/ice-9041.rs b/src/tools/clippy/tests/ui/crashes/ice-9041.rs new file mode 100644 index 000000000..55cc9bc99 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-9041.rs @@ -0,0 +1,8 @@ +pub struct Thing; + +pub fn has_thing(things: &[Thing]) -> bool { + let is_thing_ready = |_peer: &Thing| -> bool { todo!() }; + things.iter().find(|p| is_thing_ready(p)).is_some() +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-9041.stderr b/src/tools/clippy/tests/ui/crashes/ice-9041.stderr new file mode 100644 index 000000000..f5038f0a8 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-9041.stderr @@ -0,0 +1,10 @@ +error: called `is_some()` after searching an `Iterator` with `find` + --> $DIR/ice-9041.rs:5:19 + | +LL | things.iter().find(|p| is_thing_ready(p)).is_some() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|p| is_thing_ready(&p))` + | + = note: `-D clippy::search-is-some` implied by `-D warnings` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-9238.rs b/src/tools/clippy/tests/ui/crashes/ice-9238.rs new file mode 100644 index 000000000..ee6abd519 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-9238.rs @@ -0,0 +1,12 @@ +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] +#![warn(clippy::branches_sharing_code)] + +const fn f() -> usize { + 2 +} +const C: [f64; f()] = [0f64; f()]; + +fn main() { + let _ = if true { C[0] } else { C[1] }; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-9242.rs b/src/tools/clippy/tests/ui/crashes/ice-9242.rs new file mode 100644 index 000000000..0099e6e2f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-9242.rs @@ -0,0 +1,8 @@ +enum E { + X(), + Y, +} + +fn main() { + let _ = if let E::X() = E::X() { 1 } else { 2 }; +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.rs b/src/tools/clippy/tests/ui/crashes/ice-96721.rs new file mode 100644 index 000000000..4b3fb7640 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-96721.rs @@ -0,0 +1,10 @@ +macro_rules! foo { + () => { + "bar.rs" + }; +} + +#[path = foo!()] //~ ERROR malformed `path` attribute +mod abc {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.stderr b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr new file mode 100644 index 000000000..78c567b8e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr @@ -0,0 +1,8 @@ +error: malformed `path` attribute input + --> $DIR/ice-96721.rs:7:1 + | +LL | #[path = foo!()] //~ ERROR malformed `path` attribute + | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs b/src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs new file mode 100644 index 000000000..30e4b11ec --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs @@ -0,0 +1,19 @@ +#![deny(clippy::all)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/1336 + +#[allow(dead_code)] +struct Foo; + +impl Iterator for Foo { + type Item = (); + + fn next(&mut self) -> Option<()> { + let _ = self.len() == 0; + unimplemented!() + } +} + +impl ExactSizeIterator for Foo {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/if_same_then_else.rs b/src/tools/clippy/tests/ui/crashes/if_same_then_else.rs new file mode 100644 index 000000000..2f9132929 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/if_same_then_else.rs @@ -0,0 +1,16 @@ +#![allow(clippy::comparison_chain)] +#![deny(clippy::if_same_then_else)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/2426 + +fn main() {} + +pub fn foo(a: i32, b: i32) -> Option<&'static str> { + if a == b { + None + } else if a > b { + Some("a pfeil b") + } else { + None + } +} diff --git a/src/tools/clippy/tests/ui/crashes/implements-trait.rs b/src/tools/clippy/tests/ui/crashes/implements-trait.rs new file mode 100644 index 000000000..4502b0147 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/implements-trait.rs @@ -0,0 +1,5 @@ +#[allow(clippy::needless_borrowed_reference)] +fn main() { + let mut v = Vec::<String>::new(); + let _ = v.iter_mut().filter(|&ref a| a.is_empty()); +} diff --git a/src/tools/clippy/tests/ui/crashes/inherent_impl.rs b/src/tools/clippy/tests/ui/crashes/inherent_impl.rs new file mode 100644 index 000000000..aeb27b5ba --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/inherent_impl.rs @@ -0,0 +1,26 @@ +#![deny(clippy::multiple_inherent_impl)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/4578 + +macro_rules! impl_foo { + ($struct:ident) => { + impl $struct { + fn foo() {} + } + }; +} + +macro_rules! impl_bar { + ($struct:ident) => { + impl $struct { + fn bar() {} + } + }; +} + +struct MyStruct; + +impl_foo!(MyStruct); +impl_bar!(MyStruct); + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/issue-825.rs b/src/tools/clippy/tests/ui/crashes/issue-825.rs new file mode 100644 index 000000000..05696e3d7 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/issue-825.rs @@ -0,0 +1,25 @@ +#![allow(warnings)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/825 + +// this should compile in a reasonable amount of time +fn rust_type_id(name: &str) { + if "bool" == &name[..] + || "uint" == &name[..] + || "u8" == &name[..] + || "u16" == &name[..] + || "u32" == &name[..] + || "f32" == &name[..] + || "f64" == &name[..] + || "i8" == &name[..] + || "i16" == &name[..] + || "i32" == &name[..] + || "i64" == &name[..] + || "Self" == &name[..] + || "str" == &name[..] + { + unreachable!(); + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/issues_loop_mut_cond.rs b/src/tools/clippy/tests/ui/crashes/issues_loop_mut_cond.rs new file mode 100644 index 000000000..bb238c81e --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/issues_loop_mut_cond.rs @@ -0,0 +1,28 @@ +#![allow(dead_code)] + +/// Issue: https://github.com/rust-lang/rust-clippy/issues/2596 +pub fn loop_on_block_condition(u: &mut isize) { + while { *u < 0 } { + *u += 1; + } +} + +/// https://github.com/rust-lang/rust-clippy/issues/2584 +fn loop_with_unsafe_condition(ptr: *const u8) { + let mut len = 0; + while unsafe { *ptr.offset(len) } != 0 { + len += 1; + } +} + +/// https://github.com/rust-lang/rust-clippy/issues/2710 +static mut RUNNING: bool = true; +fn loop_on_static_condition() { + unsafe { + while RUNNING { + RUNNING = false; + } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/match_same_arms_const.rs b/src/tools/clippy/tests/ui/crashes/match_same_arms_const.rs new file mode 100644 index 000000000..94c939665 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/match_same_arms_const.rs @@ -0,0 +1,18 @@ +#![deny(clippy::match_same_arms)] + +/// Test for https://github.com/rust-lang/rust-clippy/issues/2427 + +const PRICE_OF_SWEETS: u32 = 5; +const PRICE_OF_KINDNESS: u32 = 0; +const PRICE_OF_DRINKS: u32 = 5; + +pub fn price(thing: &str) -> u32 { + match thing { + "rolo" => PRICE_OF_SWEETS, + "advice" => PRICE_OF_KINDNESS, + "juice" => PRICE_OF_DRINKS, + _ => panic!(), + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs b/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs new file mode 100644 index 000000000..a238e7896 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs @@ -0,0 +1,34 @@ +#![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)] +#![allow(dead_code)] + +// FIXME: compiletest + extern crates doesn't work together. To make this test work, it would need +// the following three lines and the lazy_static crate. +// +// #[macro_use] +// extern crate lazy_static; +// use std::collections::HashMap; + +/// ensure that we don't suggest `is_nan` and `is_null` inside constants +/// FIXME: once const fn is stable, suggest these functions again in constants + +const BAA: *const i32 = 0 as *const i32; +static mut BAR: *const i32 = BAA; +static mut FOO: *const i32 = 0 as *const i32; +static mut BUH: bool = 42.0 < f32::NAN; + +#[allow(unused_variables, unused_mut)] +fn main() { + /* + lazy_static! { + static ref MUT_MAP : HashMap<usize, &'static str> = { + let mut m = HashMap::new(); + m.insert(0, "zero"); + m + }; + static ref MUT_COUNT : usize = MUT_MAP.len(); + } + assert_eq!(*MUT_COUNT, 1); + */ + // FIXME: don't lint in array length, requires `check_body` + //let _ = [""; (42.0 < f32::NAN) as usize]; +} diff --git a/src/tools/clippy/tests/ui/crashes/needless_borrow_fp.rs b/src/tools/clippy/tests/ui/crashes/needless_borrow_fp.rs new file mode 100644 index 000000000..4f61c7682 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/needless_borrow_fp.rs @@ -0,0 +1,7 @@ +#[deny(clippy::all)] +#[derive(Debug)] +pub enum Error { + Type(&'static str), +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs new file mode 100644 index 000000000..376ff97ba --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -0,0 +1,20 @@ +#![deny(clippy::needless_lifetimes)] +#![allow(dead_code)] + +trait Foo {} + +struct Bar; + +struct Baz<'a> { + bar: &'a Bar, +} + +impl<'a> Foo for Baz<'a> {} + +impl Bar { + fn baz<'a>(&'a self) -> impl Foo + 'a { + Baz { bar: self } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr new file mode 100644 index 000000000..d68bbe788 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr @@ -0,0 +1,14 @@ +error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) + --> $DIR/needless_lifetimes_impl_trait.rs:15:5 + | +LL | fn baz<'a>(&'a self) -> impl Foo + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/needless_lifetimes_impl_trait.rs:1:9 + | +LL | #![deny(clippy::needless_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/regressions.rs b/src/tools/clippy/tests/ui/crashes/regressions.rs new file mode 100644 index 000000000..6f9d98bbf --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/regressions.rs @@ -0,0 +1,11 @@ +#![allow(clippy::blacklisted_name)] + +pub fn foo(bar: *const u8) { + println!("{:#p}", bar); +} + +// Regression test for https://github.com/rust-lang/rust-clippy/issues/4917 +/// <foo +struct A; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/returns.rs b/src/tools/clippy/tests/ui/crashes/returns.rs new file mode 100644 index 000000000..8021ed460 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/returns.rs @@ -0,0 +1,23 @@ +/// Test for https://github.com/rust-lang/rust-clippy/issues/1346 + +#[deny(warnings)] +fn cfg_return() -> i32 { + #[cfg(unix)] + return 1; + #[cfg(not(unix))] + return 2; +} + +#[deny(warnings)] +fn cfg_let_and_return() -> i32 { + #[cfg(unix)] + let x = 1; + #[cfg(not(unix))] + let x = 2; + x +} + +fn main() { + cfg_return(); + cfg_let_and_return(); +} diff --git a/src/tools/clippy/tests/ui/crashes/shadow.rs b/src/tools/clippy/tests/ui/crashes/shadow.rs new file mode 100644 index 000000000..843e8ef64 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/shadow.rs @@ -0,0 +1,6 @@ +fn main() { + let x: [i32; { + let u = 2; + 4 + }] = [2; { 4 }]; +} diff --git a/src/tools/clippy/tests/ui/crashes/single-match-else.rs b/src/tools/clippy/tests/ui/crashes/single-match-else.rs new file mode 100644 index 000000000..1ba7ac082 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/single-match-else.rs @@ -0,0 +1,11 @@ +#![warn(clippy::single_match_else)] + +//! Test for https://github.com/rust-lang/rust-clippy/issues/1588 + +fn main() { + let n = match (42, 43) { + (42, n) => n, + _ => panic!("typeck error"), + }; + assert_eq!(n, 43); +} diff --git a/src/tools/clippy/tests/ui/crashes/third-party/clippy.toml b/src/tools/clippy/tests/ui/crashes/third-party/clippy.toml new file mode 100644 index 000000000..9f87de20b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/third-party/clippy.toml @@ -0,0 +1,3 @@ +# this is ignored by Clippy, but allowed for other tools like clippy-service +[third-party] +clippy-feature = "nightly" diff --git a/src/tools/clippy/tests/ui/crashes/third-party/conf_allowlisted.rs b/src/tools/clippy/tests/ui/crashes/third-party/conf_allowlisted.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/third-party/conf_allowlisted.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/trivial_bounds.rs b/src/tools/clippy/tests/ui/crashes/trivial_bounds.rs new file mode 100644 index 000000000..60105a821 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/trivial_bounds.rs @@ -0,0 +1,11 @@ +#![feature(trivial_bounds)] +#![allow(unused, trivial_bounds)] + +fn test_trivial_bounds() +where + i32: Iterator, +{ + for _ in 2i32 {} +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/used_underscore_binding_macro.rs b/src/tools/clippy/tests/ui/crashes/used_underscore_binding_macro.rs new file mode 100644 index 000000000..901eb4e50 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/used_underscore_binding_macro.rs @@ -0,0 +1,16 @@ +use serde::Deserialize; + +/// Tests that we do not lint for unused underscores in a `MacroAttribute` +/// expansion +#[deny(clippy::used_underscore_binding)] +#[derive(Deserialize)] +struct MacroAttributesTest { + _foo: u32, +} + +#[test] +fn macro_attributes_test() { + let _ = MacroAttributesTest { _foo: 0 }; +} + +fn main() {} |