1 #![deny(clippy::borrowed_box)]
2 #![allow(clippy::disallowed_names)]
3 #![allow(unused_variables)]
8 pub fn test1(foo: &mut Box<bool>) {
9 // Although this function could be changed to "&mut bool",
10 // avoiding the Box, mutable references to boxes are not
11 // flagged by this lint.
13 // This omission is intentional: By passing a mutable Box,
14 // the memory location of the pointed-to object could be
15 // modified. By passing a mutable reference, the contents
16 // could change, but not the location.
29 fn test4(a: &Box<bool>);
32 impl<'a> Test4 for Test3<'a> {
33 fn test4(a: &Box<bool>) {
40 pub fn test5(foo: &mut Box<dyn Any>) {
45 let foo: &Box<dyn Any>;
49 foo: &'a Box<dyn Any>,
53 fn test8(a: &Box<dyn Any>);
56 impl<'a> Test8 for Test7<'a> {
57 fn test8(a: &Box<dyn Any>) {
62 pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
67 let foo: &Box<dyn Any + Send + 'static>;
71 foo: &'a Box<dyn Any + Send>,
75 fn test4(a: &Box<dyn Any + 'static>);
78 impl<'a> Test12 for Test11<'a> {
79 fn test4(a: &Box<dyn Any + 'static>) {
84 pub fn test13(boxed_slice: &mut Box<[i32]>) {
85 // Unconditionally replaces the box pointer.
87 // This cannot be accomplished if "&mut [i32]" is passed,
88 // and provides a test case where passing a reference to
90 let mut data = vec![12];
91 *boxed_slice = data.into_boxed_slice();
94 // The suggestion should include proper parentheses to avoid a syntax error.
95 pub fn test14(_display: &Box<dyn Display>) {}
96 pub fn test15(_display: &Box<dyn Display + Send>) {}
97 pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
99 pub fn test17(_display: &Box<impl Display>) {}
100 pub fn test18(_display: &Box<impl Display + Send>) {}
101 pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
103 // This exists only to check what happens when parentheses are already present.
104 // Even though the current implementation doesn't put extra parentheses,
105 // it's fine that unnecessary parentheses appear in the future for some reason.
106 pub fn test20(_display: &Box<(dyn Display + Send)>) {}
109 test1(&mut Box::new(false));
111 test5(&mut (Box::new(false) as Box<dyn Any>));
113 test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));