Merge pull request #3458 from topecongiro/issue-3457

Avoid panic on macro inside deeply nested block
This commit is contained in:
Stéphane Campinas
2019-03-19 22:13:08 +01:00
committed by GitHub
4 changed files with 111 additions and 1 deletions
+4
View File
@@ -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
View File
@@ -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);
}
+53
View File
@@ -479,3 +479,56 @@ fn issue3226() {
}
}
}
// #3457
fn issue3457() {
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
println!("Test");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
+53
View File
@@ -562,3 +562,56 @@ fn issue3226() {
}
}
}
// #3457
fn issue3457() {
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
println!("Test");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}