2023-07-27 08:23:04 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-06-03 21:58:27 -05:00
|
|
|
#![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)]
|
|
|
|
#![warn(clippy::redundant_locals)]
|
2024-02-05 08:41:59 -06:00
|
|
|
#![feature(async_closure, coroutines)]
|
2023-06-03 21:58:27 -05:00
|
|
|
|
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::{external, with_span};
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
fn immutable() {
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mutable() {
|
|
|
|
let mut x = 1;
|
|
|
|
let mut x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn upgraded_mutability() {
|
|
|
|
let x = 1;
|
|
|
|
let mut x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn downgraded_mutability() {
|
|
|
|
let mut x = 1;
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
|
2023-08-10 21:42:59 -05:00
|
|
|
// see #11290
|
|
|
|
fn shadow_mutation() {
|
|
|
|
let mut x = 1;
|
|
|
|
{
|
|
|
|
let mut x = x;
|
|
|
|
x = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 21:58:27 -05:00
|
|
|
fn coercion(par: &mut i32) {
|
|
|
|
let par: &i32 = par;
|
|
|
|
|
|
|
|
let x: &mut i32 = &mut 1;
|
|
|
|
let x: &i32 = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parameter(x: i32) {
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn many() {
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
let x = x;
|
|
|
|
let x = x;
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn interleaved() {
|
|
|
|
let a = 1;
|
|
|
|
let b = 2;
|
|
|
|
let a = a;
|
|
|
|
let b = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn block() {
|
|
|
|
{
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn closure() {
|
|
|
|
|| {
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
};
|
|
|
|
|x: i32| {
|
|
|
|
let x = x;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn consequential_drop_order() {
|
|
|
|
use std::sync::Mutex;
|
|
|
|
|
|
|
|
let mutex = Mutex::new(1);
|
|
|
|
let guard = mutex.lock().unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
let guard = guard;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn inconsequential_drop_order() {
|
|
|
|
let x = 1;
|
|
|
|
|
|
|
|
{
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn macros() {
|
|
|
|
macro_rules! rebind {
|
|
|
|
($x:ident) => {
|
|
|
|
let $x = 1;
|
|
|
|
let $x = $x;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
rebind!(x);
|
|
|
|
|
|
|
|
external! {
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
}
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
}
|
2023-10-06 04:22:32 -05:00
|
|
|
|
|
|
|
let x = 10;
|
|
|
|
macro_rules! rebind_outer_macro {
|
|
|
|
($x:ident) => {
|
|
|
|
let x = x;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
rebind_outer_macro!(y);
|
2023-06-03 21:58:27 -05:00
|
|
|
}
|
2023-10-03 07:22:54 -05:00
|
|
|
|
|
|
|
struct WithDrop(usize);
|
|
|
|
impl Drop for WithDrop {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
|
2023-10-03 10:13:53 -05:00
|
|
|
struct InnerDrop(WithDrop);
|
|
|
|
|
|
|
|
struct ComposeDrop {
|
|
|
|
d: WithDrop,
|
|
|
|
}
|
|
|
|
|
2023-10-03 07:22:54 -05:00
|
|
|
struct WithoutDrop(usize);
|
|
|
|
|
|
|
|
fn drop_trait() {
|
|
|
|
let a = WithDrop(1);
|
|
|
|
let b = WithDrop(2);
|
|
|
|
let a = a;
|
2023-10-03 10:13:53 -05:00
|
|
|
}
|
2023-10-03 07:22:54 -05:00
|
|
|
|
2023-10-03 10:13:53 -05:00
|
|
|
fn without_drop() {
|
|
|
|
let a = WithoutDrop(1);
|
|
|
|
let b = WithoutDrop(2);
|
|
|
|
let a = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn drop_inner() {
|
|
|
|
let a = InnerDrop(WithDrop(1));
|
|
|
|
let b = InnerDrop(WithDrop(2));
|
|
|
|
let a = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn drop_compose() {
|
|
|
|
let a = ComposeDrop { d: WithDrop(1) };
|
|
|
|
let b = ComposeDrop { d: WithDrop(1) };
|
|
|
|
let a = a;
|
2023-10-03 07:22:54 -05:00
|
|
|
}
|
2024-02-04 13:12:15 -06:00
|
|
|
|
|
|
|
fn issue12225() {
|
|
|
|
fn assert_static<T: 'static>(_: T) {}
|
|
|
|
|
|
|
|
let v1 = String::new();
|
|
|
|
let v2 = String::new();
|
|
|
|
let v3 = String::new();
|
|
|
|
let v4 = String::new();
|
2024-02-05 08:41:59 -06:00
|
|
|
let v5 = String::new();
|
|
|
|
let v6 = String::new();
|
2024-02-04 13:12:15 -06:00
|
|
|
|
|
|
|
assert_static(|| {
|
|
|
|
let v1 = v1;
|
|
|
|
dbg!(&v1);
|
|
|
|
});
|
|
|
|
assert_static(async {
|
|
|
|
let v2 = v2;
|
|
|
|
dbg!(&v2);
|
|
|
|
});
|
|
|
|
assert_static(|| async {
|
|
|
|
let v3 = v3;
|
|
|
|
dbg!(&v3);
|
|
|
|
});
|
|
|
|
assert_static(async || {
|
|
|
|
let v4 = v4;
|
|
|
|
dbg!(&v4);
|
|
|
|
});
|
2024-02-05 08:41:59 -06:00
|
|
|
assert_static(static || {
|
|
|
|
let v5 = v5;
|
|
|
|
yield;
|
|
|
|
});
|
|
|
|
assert_static(|| {
|
|
|
|
let v6 = v6;
|
|
|
|
yield;
|
|
|
|
});
|
2024-02-04 13:12:15 -06:00
|
|
|
|
|
|
|
fn foo(a: &str, b: &str) {}
|
|
|
|
|
|
|
|
let do_not_move = String::new();
|
|
|
|
let things_to_move = vec!["a".to_string(), "b".to_string()];
|
|
|
|
let futures = things_to_move.into_iter().map(|move_me| async {
|
|
|
|
let move_me = move_me;
|
|
|
|
foo(&do_not_move, &move_me)
|
|
|
|
});
|
|
|
|
}
|