diff options
| author | Nick Cameron <nrc@ncameron.org> | 2019-01-07 17:39:05 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-07 17:39:05 +1300 |
| commit | 2c204c11d160cb2bee0802e4e9235fca0ffae421 (patch) | |
| tree | 1767e4bd63060acdb4a91a66d519b813e08da750 | |
| parent | c357eee8bbd35719ca65e9d53b119eeacd8cae9a (diff) | |
| parent | 49568d7f76226aac5f7a641848a2251618079230 (diff) | |
Merge pull request #3260 from topecongiro/issue-3004
Do not modify original source code inside macro call
| -rw-r--r-- | src/closures.rs | 3 | ||||
| -rw-r--r-- | src/types.rs | 8 | ||||
| -rw-r--r-- | tests/source/macros.rs | 5 | ||||
| -rw-r--r-- | tests/target/macros.rs | 5 |
4 files changed, 19 insertions, 2 deletions
diff --git a/src/closures.rs b/src/closures.rs index e29a412a515..008b884bcb2 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -59,7 +59,7 @@ pub fn rewrite_closure( } let result = match fn_decl.output { - ast::FunctionRetTy::Default(_) => { + ast::FunctionRetTy::Default(_) if !context.inside_macro() => { try_rewrite_without_block(body, &prefix, context, shape, body_shape) } _ => None, @@ -306,6 +306,7 @@ pub fn rewrite_last_closure( let body = match body.node { ast::ExprKind::Block(ref block, _) if !is_unsafe_block(block) + && !context.inside_macro() && is_simple_block(block, Some(&body.attrs), context.source_map) => { stmt_expr(&block.stmts[0]).unwrap_or(body) diff --git a/src/types.rs b/src/types.rs index d27d1f13f98..8cfba778a48 100644 --- a/src/types.rs +++ b/src/types.rs @@ -583,7 +583,13 @@ impl Rewrite for ast::Ty { let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn; // 4 is length of 'dyn ' let shape = if is_dyn { shape.offset_left(4)? } else { shape }; - let res = bounds.rewrite(context, shape)?; + let mut res = bounds.rewrite(context, shape)?; + // We may have falsely removed a trailing `+` inside macro call. + if context.inside_macro() && bounds.len() == 1 { + if context.snippet(self.span).ends_with('+') && !res.ends_with('+') { + res.push('+'); + } + } if is_dyn { Some(format!("dyn {}", res)) } else { diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 07934255bac..29d8f066126 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -466,3 +466,8 @@ static ROOTED_TRACEABLES: RefCell<RootedTraceableSet> = RefCell::new(RootedTraceableSet::new(1234)) ; ] ; + +fn issue3004() { + foo!(|_| { ( ) }); + stringify!(( foo+ )); +} diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 061d1746422..bc15a86cf34 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -1043,3 +1043,8 @@ thread_local![ static ROOTED_TRACEABLES: RefCell<RootedTraceableSet> = RefCell::new(RootedTraceableSet::new(1234)); ]; + +fn issue3004() { + foo!(|_| { () }); + stringify!((foo+)); +} |
