Skip to content

Commit 64490ff

Browse files
committed
Rollup merge of #48990 - ExpHP:dont-drop-the-bomb, r=estebank
Fix ICE on malformed plugin attributes See #48941 for some discussion. This bug had several duplicate reports which were never closed as dupes: Fixes #47612 Fixes #48387 Fixes #48941 Fixes #48982
2 parents 6fbd033 + dc96467 commit 64490ff

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/libsyntax/ext/expand.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
484484

485485
match *ext {
486486
MultiModifier(ref mac) => {
487-
let meta = attr.parse_meta(self.cx.parse_sess).ok()?;
487+
let meta = attr.parse_meta(self.cx.parse_sess)
488+
.map_err(|mut e| { e.emit(); }).ok()?;
488489
let item = mac.expand(self.cx, attr.span, &meta, item);
489490
Some(kind.expect_from_annotatables(item))
490491
}
491492
MultiDecorator(ref mac) => {
492493
let mut items = Vec::new();
493-
let meta = attr.parse_meta(self.cx.parse_sess).ok()?;
494+
let meta = attr.parse_meta(self.cx.parse_sess)
495+
.expect("derive meta should already have been parsed");
494496
mac.expand(self.cx, attr.span, &meta, &item, &mut |item| items.push(item));
495497
items.push(item);
496498
Some(kind.expect_from_annotatables(items))

src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub fn plugin_registrar(reg: &mut Registry) {
3737
reg.register_syntax_extension(
3838
Symbol::intern("into_multi_foo"),
3939
MultiModifier(Box::new(expand_into_foo_multi)));
40+
reg.register_syntax_extension(
41+
Symbol::intern("noop_attribute"),
42+
MultiModifier(Box::new(expand_noop_attribute)));
4043
reg.register_syntax_extension(
4144
Symbol::intern("duplicate"),
4245
MultiDecorator(Box::new(expand_duplicate)));
@@ -93,6 +96,13 @@ fn expand_into_foo_multi(cx: &mut ExtCtxt,
9396
}
9497
}
9598

99+
fn expand_noop_attribute(_cx: &mut ExtCtxt,
100+
_sp: Span,
101+
_attr: &MetaItem,
102+
it: Annotatable) -> Annotatable {
103+
it
104+
}
105+
96106
// Create a duplicate of the annotatable, based on the MetaItem
97107
fn expand_duplicate(cx: &mut ExtCtxt,
98108
_sp: Span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This is a regression test against an ICE that used to occur
12+
// on malformed attributes for a custom MultiModifier.
13+
14+
// aux-build:macro_crate_test.rs
15+
// ignore-stage1
16+
17+
#![feature(plugin)]
18+
#![plugin(macro_crate_test)]
19+
20+
#[noop_attribute"x"] //~ ERROR expected one of
21+
fn night() { }
22+
23+
#[noop_attribute("hi"), rank = 2] //~ ERROR unexpected token
24+
fn knight() { }
25+
26+
#[noop_attribute("/user", data= = "<user")] //~ ERROR literal or identifier
27+
fn nite() { }
28+
29+
fn main() {}

0 commit comments

Comments
 (0)