Rollup merge of #125158 - Nilstrieb:block-indent, r=compiler-errors

hir pretty: fix block indent

before:
```rust
fn main() {
        {
                {
                        ::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
                    };
            }
    }
```
after:
```rust
fn main() {
    {
        {
            ::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
        };
    }
}
```

AST pretty does the same.
This commit is contained in:
Matthias Krüger 2024-05-21 00:47:02 +02:00 committed by GitHub
commit 4b26045b92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 53 additions and 53 deletions

View File

@ -1454,7 +1454,7 @@ impl<'a> State<'a> {
self.word_space(":"); self.word_space(":");
} }
// containing cbox, will be closed by print-block at `}` // containing cbox, will be closed by print-block at `}`
self.cbox(INDENT_UNIT); self.cbox(0);
// head-box, will be closed by print-block after `{` // head-box, will be closed by print-block after `{`
self.ibox(0); self.ibox(0);
self.print_block(blk); self.print_block(blk);

View File

@ -11,15 +11,15 @@ extern crate std;
fn foo(_: [i32; (3 as usize)]) ({ } as ()) fn foo(_: [i32; (3 as usize)]) ({ } as ())
fn bar() ({ fn bar() ({
const FOO: usize = ((5 as usize) - (4 as usize) as usize); const FOO: usize = ((5 as usize) - (4 as usize) as usize);
let _: [(); (FOO as usize)] = ([(() as ())] as [(); 1]); let _: [(); (FOO as usize)] = ([(() as ())] as [(); 1]);
let _: [(); (1 as usize)] = ([(() as ())] as [(); 1]); let _: [(); (1 as usize)] = ([(() as ())] as [(); 1]);
let _ = let _ =
(((&([(1 as i32), (2 as i32), (3 as i32)] as [i32; 3]) as (((&([(1 as i32), (2 as i32), (3 as i32)] as [i32; 3]) as &[i32; 3])
&[i32; 3]) as *const _ as *const [i32; 3]) as as *const _ as *const [i32; 3]) as *const [i32; (3 as usize)]
*const [i32; (3 as usize)] as *const [i32; 3]); as *const [i32; 3]);
@ -29,17 +29,17 @@ fn bar() ({
({ ({
let res = let res =
((::alloc::fmt::format as ((::alloc::fmt::format as
for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const
as as
fn(&[&'static str]) -> Arguments<'_> {Arguments::<'_>::new_const})((&([("test" fn(&[&'static str]) -> Arguments<'_> {Arguments::<'_>::new_const})((&([("test"
as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>)) as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>))
as String); as String);
(res as String) (res as String)
} as String); } as String);
} as ()) } as ())
type Foo = [i32; (3 as usize)]; type Foo = [i32; (3 as usize)];
struct Bar { struct Bar {
x: [i32; (3 as usize)], x: [i32; (3 as usize)],
@ -48,9 +48,9 @@ struct TupleBar([i32; (4 as usize)]);
enum Baz { BazVariant([i32; (5 as usize)]), } enum Baz { BazVariant([i32; (5 as usize)]), }
fn id<T>(x: T) -> T ({ (x as T) } as T) fn id<T>(x: T) -> T ({ (x as T) } as T)
fn use_id() ({ fn use_id() ({
let _ = let _ =
((id::<[i32; (3 as usize)]> as ((id::<[i32; (3 as usize)]> as
fn([i32; 3]) -> [i32; 3] {id::<[i32; 3]>})(([(1 as i32), fn([i32; 3]) -> [i32; 3] {id::<[i32; 3]>})(([(1 as i32),
(2 as i32), (3 as i32)] as [i32; 3])) as [i32; 3]); (2 as i32), (3 as i32)] as [i32; 3])) as [i32; 3]);
} as ()) } as ())
fn main() ({ } as ()) fn main() ({ } as ())

View File

@ -7,10 +7,10 @@ extern crate std;
//@ check-pass //@ check-pass
fn main() ({ fn main() ({
(if (true as bool) (if (true as bool)
({ } as ({ } as
()) else if (let Some(a) = ()) else if (let Some(a) =
((Some as ((Some as
fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as
Option<i32>) as bool) ({ } as ()) as ()) Option<i32>) as bool) ({ } as ()) as ())
} as ()) } as ())

View File

@ -25,8 +25,8 @@ LL + let str::as_bytes;
| |
error[E0533]: expected unit struct, unit variant or constant, found associated function `str<{ error[E0533]: expected unit struct, unit variant or constant, found associated function `str<{
fn str() { let (/*ERROR*/); } fn str() { let (/*ERROR*/); }
}, T>::as_bytes` }, T>::as_bytes`
--> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:9 --> $DIR/ensure-overriding-bindings-in-pattern-with-ty-err-doesnt-ice.rs:2:9
| |
LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes; LL | let str::<{fn str() { let str::T>>::as_bytes; }}, T>::as_bytes;

View File

@ -10,5 +10,5 @@ extern crate std;
trait Animal { } trait Animal { }
fn main() { fn main() {
type ServeFut = /*impl Trait*/; type ServeFut = /*impl Trait*/;
} }

View File

@ -7,5 +7,5 @@ extern crate std;
// In #100948 this caused an ICE with -Zunpretty=hir. // In #100948 this caused an ICE with -Zunpretty=hir.
fn main() { fn main() {
<bad-literal>; <bad-literal>;
} }

View File

@ -8,7 +8,7 @@ use ::std::prelude::rust_2015::*;
extern crate std; extern crate std;
fn main() { fn main() {
let _ = let _ =
#[rustc_box] #[rustc_box]
Box::new(1); Box::new(1);
} }

View File

@ -6,10 +6,10 @@ extern crate std;
//@ check-pass //@ check-pass
fn main() { fn main() {
let x = 1; let x = 1;
// Should flatten to println!("a 123 b {x} xyz\n"): // Should flatten to println!("a 123 b {x} xyz\n"):
{ {
::std::io::_print(format_arguments::new_v1(&["a 123 b ", ::std::io::_print(format_arguments::new_v1(&["a 123 b ", " xyz\n"],
" xyz\n"], &[format_argument::new_display(&x)])); &[format_argument::new_display(&x)]));
}; };
} }

View File

@ -9,10 +9,10 @@ extern crate std;
fn foo(x: fn foo(x:
Option<u32>) { Option<u32>) {
let Some(_) = x else let Some(_) = x else
{ {
{ ::std::rt::begin_panic("explicit panic") } { ::std::rt::begin_panic("explicit panic") }
}; };
} }
fn main() { } fn main() { }