]> git.lizzy.rs Git - rust.git/commitdiff
Ensure that generic arguments don't end up in attribute paths.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 17 Aug 2017 18:44:28 +0000 (11:44 -0700)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 22 Aug 2017 22:50:19 +0000 (15:50 -0700)
src/libsyntax/parse/parser.rs
src/test/compile-fail/issue-43424.rs [new file with mode: 0644]

index 2b2f925306d9a9df100e70b9e7e0a30cffc4a832..90a635fdf44fe20006f90d1e81ae5bf9d8309747 100644 (file)
@@ -1776,7 +1776,13 @@ pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
 
     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();
diff --git a/src/test/compile-fail/issue-43424.rs b/src/test/compile-fail/issue-43424.rs
new file mode 100644 (file)
index 0000000..431fc8a
--- /dev/null
@@ -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() {}