Skip to content

Commit

Permalink
Ensure that generic arguments don't end up in attribute paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Aug 22, 2017
1 parent 469a6f9 commit d54a6d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -1776,7 +1776,13 @@ impl<'a> Parser<'a> {

pub fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool)
-> PResult<'a, ast::Path> {
maybe_whole!(self, NtPath, |x| x);
maybe_whole!(self, NtPath, |path| {
if style == PathStyle::Mod &&
path.segments.iter().any(|segment| segment.parameters.is_some()) {
self.diagnostic().span_err(path.span, "unexpected generic arguments in path");
}
path
});

let lo = self.meta_var_span.unwrap_or(self.span);
let mut segments = Vec::new();
Expand Down
22 changes: 22 additions & 0 deletions src/test/compile-fail/issue-43424.rs
@@ -0,0 +1,22 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unused)]

macro_rules! m {
($attr_path: path) => {
#[$attr_path]
fn f() {}
}
}

m!(inline<u8>); //~ ERROR: unexpected generic arguments in path

fn main() {}

0 comments on commit d54a6d9

Please sign in to comment.