Skip to content

add more crash tests #131447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/crashes/130956.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//@ known-bug: #130956

mod impl_trait_mod {
use super::*;
pub type OpaqueBlock = impl Trait;
pub type OpaqueIf = impl Trait;

pub struct BlockWrapper(OpaqueBlock);
pub struct IfWrapper(pub OpaqueIf);

pub fn if_impl() -> Parser<OpaqueIf> {
bind(option(block()), |_| block())
}
}
use impl_trait_mod::*;

pub trait Trait {
type Assoc;
}
pub struct Parser<P>(P);
pub struct Bind<P, F>(P, F);
impl<P, F> Trait for Bind<P, F> { type Assoc = (); }
impl Trait for BlockWrapper { type Assoc = (); }
impl Trait for IfWrapper { type Assoc = (); }

pub fn block() -> Parser<BlockWrapper> {
loop {}
}
pub fn option<P: Trait>(arg: Parser<P>) -> Parser<impl Trait> {
bind(arg, |_| block())
}
fn bind<P: Trait, P2, F: Fn(P::Assoc) -> Parser<P2>>(_: Parser<P>, _: F) -> Parser<Bind<P, F>>
{ loop {} }

fn main() {
if_impl().0;
}
13 changes: 13 additions & 0 deletions tests/crashes/130967.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ known-bug: #130967

trait Producer {
type Produced;
fn make_one() -> Self::Produced;
}

impl<E: ?Sized> Producer for () {
type Produced = Option<E>;
fn make_one() -> Self::Produced {
loop {}
}
}
15 changes: 15 additions & 0 deletions tests/crashes/131046.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ known-bug: #131046

trait Owner {
const C<const N: u32>: u32;
}

impl Owner for () {
const C<const N: u32>: u32 = N;
}

fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}

fn main() {
take0::<128>(());
}
7 changes: 7 additions & 0 deletions tests/crashes/131048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ known-bug: #131048

impl<A> std::ops::CoerceUnsized<A> for A {}

fn main() {
format_args!("Hello, world!");
}
27 changes: 27 additions & 0 deletions tests/crashes/131050.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ known-bug: #131050
//@ compile-flags: --edition=2021

fn query_as<D>() {}

async fn create_user() {
query_as();
}

async fn post_user_filter() -> impl Filter {
AndThen(&(), || async { create_user().await })
}

async fn get_app() -> impl Send {
post_user_filter().await
}

trait Filter {}

struct AndThen<T, F>(T, F);

impl<T, F, R> Filter for AndThen<T, F>
where
F: Fn() -> R,
R: Send,
{
}
8 changes: 8 additions & 0 deletions tests/crashes/131052.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ known-bug: #131052
#![feature(adt_const_params)]

struct ConstBytes<const T: &'static [*mut u8; 3]>;

pub fn main() {
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
}
12 changes: 12 additions & 0 deletions tests/crashes/131101.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ known-bug: #131101
trait Foo<const N: u8> {
fn do_x(&self) -> [u8; N];
}

struct Bar;

impl Foo<const 3> for Bar {
fn do_x(&self) -> [u8; 3] {
[0u8; 3]
}
}
4 changes: 4 additions & 0 deletions tests/crashes/131102.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//@ known-bug: #131102
pub struct Blorb<const N: u16>([String; N]);
pub struct Wrap(Blorb<0>);
pub const fn i(_: Wrap) {}
6 changes: 6 additions & 0 deletions tests/crashes/131103.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ known-bug: #131103
struct Struct<const N: i128>(pub [u8; N]);

pub fn function(value: Struct<3>) -> u8 {
value.0[0]
}
19 changes: 19 additions & 0 deletions tests/crashes/131190.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ known-bug: #131190
//@ compile-flags: -Cinstrument-coverage --edition=2018

use std::future::Future;

pub fn block_on<T>(fut: impl Future<Output = T>) -> T {}

async fn call_once(f: impl async FnOnce(DropMe)) {
f(DropMe("world")).await;
}

struct DropMe(&'static str);

pub fn main() {
block_on(async {
let async_closure = async move |a: DropMe| {};
call_once(async_closure).await;
});
}
16 changes: 16 additions & 0 deletions tests/crashes/131227.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: #131227
//@ compile-flags: -Zmir-opt-level=3

static mut G: () = ();

fn myfunc() -> i32 {
let var = &raw mut G;
if var.is_null() {
return 0;
}
0
}

fn main() {
myfunc();
}
7 changes: 7 additions & 0 deletions tests/crashes/131292.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ known-bug: #131292
//@ only-x86_64
use std::arch::asm;

unsafe fn f6() {
asm!(concat!(r#"lJ𐏿Æ�.𐏿�"#, "{}/day{:02}.txt"));
}
25 changes: 25 additions & 0 deletions tests/crashes/131294-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ known-bug: #131294
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir -Zcross-crate-inline-threshold=always

// https://github.com/rust-lang/rust/issues/131294#issuecomment-2395088049 second comment
struct Rows;

impl Iterator for Rows {
type Item = String;

fn next() -> Option<String> {
let args = format_args!("Hello world");

{
match args.as_str() {
Some(t) => t.to_owned(),
None => String::new(),
}
}
.into()
}
}

fn main() {
Rows.next();
}
16 changes: 16 additions & 0 deletions tests/crashes/131294.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: #131294
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir -Zcross-crate-inline-threshold=always

struct Rows;

impl Iterator for Rows {
type Item = String;

fn next() -> Option<Self::Item> {
std::fmt::format(format_args!("Hello world")).into()
}
}

fn main() {
Rows.next();
}
9 changes: 9 additions & 0 deletions tests/crashes/131295.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ known-bug: #131295

#![feature(generic_const_exprs)]

async fn foo<'a>() -> [(); {
let _y: &'a ();
4
}] {
}
12 changes: 12 additions & 0 deletions tests/crashes/131298.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ known-bug: #131298

fn dyn_hoops<T>() -> *const dyn Iterator<Item = impl Captures> {
loop {}
}

mod typeck {
type Opaque = impl Sized;
fn define() -> Opaque {
let _: Opaque = super::dyn_hoops::<u8>();
}
}
40 changes: 40 additions & 0 deletions tests/crashes/131342-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//@ known-bug: #131342
// see also: 131342.rs

fn main() {
problem_thingy(Once);
}

struct Once;

impl Iterator for Once {
type Item = ();
}

fn problem_thingy(items: impl Iterator) {
let peeker = items.peekable();
problem_thingy(&peeker);
}

trait Iterator {
type Item;

fn peekable(self) -> Peekable<Self>
where
Self: Sized,
{
loop {}
}
}

struct Peekable<I: Iterator> {
_peeked: I::Item,
}

impl<I: Iterator> Iterator for Peekable<I> {
type Item = I::Item;
}

impl<I: Iterator + ?Sized> Iterator for &I {
type Item = I::Item;
}
16 changes: 16 additions & 0 deletions tests/crashes/131342.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: #131342
// see also: 131342-2.rs

fn main() {
let mut items = vec![1, 2, 3, 4, 5].into_iter();
problem_thingy(&mut items);
}

fn problem_thingy(items: &mut impl Iterator<Item = u8>) {
let mut peeker = items.peekable();
match peeker.peek() {
Some(_) => (),
None => return (),
}
problem_thingy(&mut peeker);
}
9 changes: 9 additions & 0 deletions tests/crashes/131347.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ known-bug: #131347
//@ compile-flags: -Zmir-opt-level=5 -Zvalidate-mir

struct S;
static STUFF: [i8] = [0; S::N];

fn main() {
assert_eq!(STUFF, [0; 63]);
}
33 changes: 33 additions & 0 deletions tests/crashes/131373.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@ known-bug: #131373

trait LockReference: 'static {
type Ref<'a>;
}

struct SliceRef<'a, T: ?Sized> {
_x: &'a T,
}

impl<'a, T: ?Sized, SR: LockReference> IntoIterator for SliceRef<'a, T>
where
&'a T: IntoIterator<Item = &'a SR>,
{
type Item = SR::Ref<'a>;
type IntoIter = std::iter::Map<<&'a T as IntoIterator>::IntoIter,
for<'c> fn(&'c SR) -> SR::Ref<'c>>;
fn into_iter(self) -> Self::IntoIter {
loop {}
}
}

impl LockReference for () {
type Ref<'a> = ();
}

fn locked() -> SliceRef<'static, [()]> {
loop {}
}

fn main() {
let _ = locked().into_iter();
}
12 changes: 12 additions & 0 deletions tests/crashes/131406.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ known-bug: #131406

trait Owner {
const C<const N: u32>: u32 = N;
}

impl Owner for () {}
fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}

fn main() {
take0::<128>(());
}