Skip to content

Commit 7c076fc

Browse files
jseyfriedalexcrichton
authored andcommitted
Ensure that generic arguments don't end up in attribute paths.
1 parent c5beaac commit 7c076fc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/libsyntax/parse/parser.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,13 @@ impl<'a> Parser<'a> {
17511751
fn parse_path_common(&mut self, mode: PathStyle, parse_generics: bool)
17521752
-> PResult<'a, ast::Path>
17531753
{
1754-
maybe_whole!(self, NtPath, |x| x);
1754+
maybe_whole!(self, NtPath, |path| {
1755+
if style == PathStyle::Mod &&
1756+
path.segments.iter().any(|segment| segment.parameters.is_some()) {
1757+
self.diagnostic().span_err(path.span, "unexpected generic arguments in path");
1758+
}
1759+
path
1760+
});
17551761

17561762
let lo = self.meta_var_span.unwrap_or(self.span);
17571763
let is_global = self.eat(&token::ModSep);

src/test/compile-fail/issue-43424.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017 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+
#![allow(unused)]
12+
13+
macro_rules! m {
14+
($attr_path: path) => {
15+
#[$attr_path]
16+
fn f() {}
17+
}
18+
}
19+
20+
m!(inline<u8>); //~ ERROR: unexpected generic arguments in path
21+
22+
fn main() {}

0 commit comments

Comments
 (0)