about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-11 10:36:33 +0100
committerGitHub <noreply@github.com>2020-03-11 10:36:33 +0100
commit6a8683fcd0f51eb3e17c464f9c68967c71a62de5 (patch)
treed1c781bd7041e9f7d374d93281f64d6803cbd9cd
parenta05bab59259fb8baec236363d7f40925644e17ec (diff)
parent6b27e8d2a631183babfb25c5aac008b263ba4978 (diff)
downloadrust-6a8683fcd0f51eb3e17c464f9c68967c71a62de5.tar.gz
rust-6a8683fcd0f51eb3e17c464f9c68967c71a62de5.zip
Rollup merge of #69896 - petrochenkov:reqname2, r=Centril
parse: Tweak the function parameter edition check

Follow-up to https://github.com/rust-lang/rust/pull/69801.

Edition of a code fragment is inferred from "the place where the code is written".
For individual tokens like edition-specific keywords it may be the span of the token itself ("uninterpolated" span), but for larger code fragments it's probably not, in the test example the trait method is obviously written in "2015 edition code".

r? @Centril
-rw-r--r--src/librustc_parse/parser/item.rs4
-rw-r--r--src/test/ui/anon-params/anon-params-denied-2018.rs (renamed from src/test/ui/anon-params-denied-2018.rs)0
-rw-r--r--src/test/ui/anon-params/anon-params-denied-2018.stderr (renamed from src/test/ui/anon-params-denied-2018.stderr)0
-rw-r--r--src/test/ui/anon-params/anon-params-deprecated.fixed (renamed from src/test/ui/anon-params-deprecated.fixed)0
-rw-r--r--src/test/ui/anon-params/anon-params-deprecated.rs (renamed from src/test/ui/anon-params-deprecated.rs)0
-rw-r--r--src/test/ui/anon-params/anon-params-deprecated.stderr (renamed from src/test/ui/anon-params-deprecated.stderr)0
-rw-r--r--src/test/ui/anon-params/anon-params-edition-hygiene.rs10
-rw-r--r--src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs12
8 files changed, 23 insertions, 3 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs
index 126686c8def..a9c4de04c0a 100644
--- a/src/librustc_parse/parser/item.rs
+++ b/src/librustc_parse/parser/item.rs
@@ -1544,9 +1544,7 @@ impl<'a> Parser<'a> {
 
         let is_name_required = match self.token.kind {
             token::DotDotDot => false,
-            // FIXME: Consider using interpolated token for this edition check,
-            // it should match the intent of edition hygiene better.
-            _ => req_name(self.token.uninterpolate().span.edition()),
+            _ => req_name(self.token.span.edition()),
         };
         let (pat, ty) = if is_name_required || self.is_named_param() {
             debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
diff --git a/src/test/ui/anon-params-denied-2018.rs b/src/test/ui/anon-params/anon-params-denied-2018.rs
index 5721f5d2357..5721f5d2357 100644
--- a/src/test/ui/anon-params-denied-2018.rs
+++ b/src/test/ui/anon-params/anon-params-denied-2018.rs
diff --git a/src/test/ui/anon-params-denied-2018.stderr b/src/test/ui/anon-params/anon-params-denied-2018.stderr
index e7a806a8468..e7a806a8468 100644
--- a/src/test/ui/anon-params-denied-2018.stderr
+++ b/src/test/ui/anon-params/anon-params-denied-2018.stderr
diff --git a/src/test/ui/anon-params-deprecated.fixed b/src/test/ui/anon-params/anon-params-deprecated.fixed
index fe42113eb2e..fe42113eb2e 100644
--- a/src/test/ui/anon-params-deprecated.fixed
+++ b/src/test/ui/anon-params/anon-params-deprecated.fixed
diff --git a/src/test/ui/anon-params-deprecated.rs b/src/test/ui/anon-params/anon-params-deprecated.rs
index dc0357721ec..dc0357721ec 100644
--- a/src/test/ui/anon-params-deprecated.rs
+++ b/src/test/ui/anon-params/anon-params-deprecated.rs
diff --git a/src/test/ui/anon-params-deprecated.stderr b/src/test/ui/anon-params/anon-params-deprecated.stderr
index 4520559845f..4520559845f 100644
--- a/src/test/ui/anon-params-deprecated.stderr
+++ b/src/test/ui/anon-params/anon-params-deprecated.stderr
diff --git a/src/test/ui/anon-params/anon-params-edition-hygiene.rs b/src/test/ui/anon-params/anon-params-edition-hygiene.rs
new file mode 100644
index 00000000000..14e11c5696f
--- /dev/null
+++ b/src/test/ui/anon-params/anon-params-edition-hygiene.rs
@@ -0,0 +1,10 @@
+// check-pass
+// edition:2018
+// aux-build:anon-params-edition-hygiene.rs
+
+#[macro_use]
+extern crate anon_params_edition_hygiene;
+
+generate_trait_2015!(u8);
+
+fn main() {}
diff --git a/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs b/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs
new file mode 100644
index 00000000000..aa4221becc2
--- /dev/null
+++ b/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs
@@ -0,0 +1,12 @@
+// edition:2015
+
+#[macro_export]
+macro_rules! generate_trait_2015 {
+    ($Type: ident) => {
+        trait Trait {
+            fn method($Type) {}
+        }
+    };
+}
+
+fn main() {}