From 9f497008b0d17cf6b0036eb06eff94fa3850e840 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Apr 2025 19:15:18 +1000 Subject: [PATCH 1/2] Add a pretty printing test involving a never pattern. This currently prints badly, with unclosed indentation. --- tests/pretty/never-pattern.pp | 18 ++++++++++++++++++ tests/pretty/never-pattern.rs | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/pretty/never-pattern.pp create mode 100644 tests/pretty/never-pattern.rs diff --git a/tests/pretty/never-pattern.pp b/tests/pretty/never-pattern.pp new file mode 100644 index 0000000000000..fe40008b971d3 --- /dev/null +++ b/tests/pretty/never-pattern.pp @@ -0,0 +1,18 @@ +#![feature(prelude_import)] +#![no_std] +//@ pretty-mode:expanded +//@ pp-exact:never-pattern.pp +//@ only-x86_64 + +#![allow(incomplete_features)] +#![feature(never_patterns)] +#![feature(never_type)] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; + +fn f(x: Result) { + _ = match x { Ok(x) => x, Err(!) , }; } + + fn main() {} diff --git a/tests/pretty/never-pattern.rs b/tests/pretty/never-pattern.rs new file mode 100644 index 0000000000000..fe170bafc666a --- /dev/null +++ b/tests/pretty/never-pattern.rs @@ -0,0 +1,16 @@ +//@ pretty-mode:expanded +//@ pp-exact:never-pattern.pp +//@ only-x86_64 + +#![allow(incomplete_features)] +#![feature(never_patterns)] +#![feature(never_type)] + +fn f(x: Result) { + _ = match x { + Ok(x) => x, + Err(!), + }; +} + +fn main() {} From 49ca89dc36be65872e721bde11ac8efd3ebdd7a1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Apr 2025 19:21:04 +1000 Subject: [PATCH 2/2] Fix pretty printing of never pattern match arms. --- compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 1 + tests/pretty/never-pattern.pp | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index df848a26d390a..4aeb7c0099526 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -876,6 +876,7 @@ impl<'a> State<'a> { } } } else { + self.end(); // Close the ibox for the pattern. self.word(","); } self.end(); // Close enclosing cbox. diff --git a/tests/pretty/never-pattern.pp b/tests/pretty/never-pattern.pp index fe40008b971d3..923ad9b82c7a7 100644 --- a/tests/pretty/never-pattern.pp +++ b/tests/pretty/never-pattern.pp @@ -12,7 +12,6 @@ #[macro_use] extern crate std; -fn f(x: Result) { - _ = match x { Ok(x) => x, Err(!) , }; } +fn f(x: Result) { _ = match x { Ok(x) => x, Err(!) , }; } - fn main() {} +fn main() {}