1 #![deny(clippy::borrowed_box)]
2 #![allow(dead_code, unused_variables)]
3 #![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
7 pub fn test1(foo: &mut Box<bool>) {
8 // Although this function could be changed to "&mut bool",
9 // avoiding the Box, mutable references to boxes are not
10 // flagged by this lint.
12 // This omission is intentional: By passing a mutable Box,
13 // the memory location of the pointed-to object could be
14 // modified. By passing a mutable reference, the contents
15 // could change, but not the location.
28 fn test4(a: &Box<bool>);
31 impl<'a> Test4 for Test3<'a> {
32 fn test4(a: &Box<bool>) {
39 pub fn test5(foo: &mut Box<dyn Any>) {
44 let foo: &Box<dyn Any>;
48 foo: &'a Box<dyn Any>,
52 fn test8(a: &Box<dyn Any>);
55 impl<'a> Test8 for Test7<'a> {
56 fn test8(a: &Box<dyn Any>) {
61 pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
66 let foo: &Box<dyn Any + Send + 'static>;
70 foo: &'a Box<dyn Any + Send>,
74 fn test4(a: &Box<dyn Any + 'static>);
77 impl<'a> Test12 for Test11<'a> {
78 fn test4(a: &Box<dyn Any + 'static>) {
83 pub fn test13(boxed_slice: &mut Box<[i32]>) {
84 // Unconditionally replaces the box pointer.
86 // This cannot be accomplished if "&mut [i32]" is passed,
87 // and provides a test case where passing a reference to
89 let mut data = vec![12];
90 *boxed_slice = data.into_boxed_slice();
93 // The suggestion should include proper parentheses to avoid a syntax error.
94 pub fn test14(_display: &Box<dyn Display>) {}
95 pub fn test15(_display: &Box<dyn Display + Send>) {}
96 pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
98 pub fn test17(_display: &Box<impl Display>) {}
99 pub fn test18(_display: &Box<impl Display + Send>) {}
100 pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
102 // This exists only to check what happens when parentheses are already present.
103 // Even though the current implementation doesn't put extra parentheses,
104 // it's fine that unnecessary parentheses appear in the future for some reason.
105 pub fn test20(_display: &Box<(dyn Display + Send)>) {}
108 test1(&mut Box::new(false));
110 test5(&mut (Box::new(false) as Box<dyn Any>));
112 test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));