mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Merge pull request #3458 from topecongiro/issue-3457
Avoid panic on macro inside deeply nested block
This commit is contained in:
@@ -228,6 +228,10 @@ pub fn block(&self) -> Shape {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn saturating_sub_width(&self, width: usize) -> Shape {
|
||||
self.sub_width(width).unwrap_or(Shape { width: 0, ..*self })
|
||||
}
|
||||
|
||||
pub fn sub_width(&self, width: usize) -> Option<Shape> {
|
||||
Some(Shape {
|
||||
width: self.width.checked_sub(width)?,
|
||||
|
||||
+1
-1
@@ -536,7 +536,7 @@ fn visit_mac(&mut self, mac: &ast::Mac, ident: Option<ast::Ident>, pos: MacroPos
|
||||
skip_out_of_file_lines_range_visitor!(self, mac.span);
|
||||
|
||||
// 1 = ;
|
||||
let shape = self.shape().sub_width(1).unwrap();
|
||||
let shape = self.shape().saturating_sub_width(1);
|
||||
let rewrite = self.with_context(|ctx| rewrite_macro(mac, ident, ctx, shape, pos));
|
||||
self.push_rewrite(mac.span, rewrite);
|
||||
}
|
||||
|
||||
@@ -479,3 +479,56 @@ fn issue3226() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #3457
|
||||
fn issue3457() {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
println!("Test");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,3 +562,56 @@ fn issue3226() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #3457
|
||||
fn issue3457() {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
println!("Test");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user