about summary refs log tree commit diff
path: root/src/test/ui/binding
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-15 15:40:10 +0100
committerGitHub <noreply@github.com>2020-03-15 15:40:10 +0100
commitd986a706bdaa861d2644ce297b658ec96110f2aa (patch)
tree9281e3bbf92f206c25a3f36a0232ff55db298a79 /src/test/ui/binding
parent8bca839fdfd654581468019a3a69cc6987b585ea (diff)
parent78f01eca3f4d6843125199578d3f2186655ddf62 (diff)
downloadrust-d986a706bdaa861d2644ce297b658ec96110f2aa.tar.gz
rust-d986a706bdaa861d2644ce297b658ec96110f2aa.zip
Rollup merge of #70006 - petrochenkov:fresh, r=Centril
resolve: Fix two issues in fresh binding disambiguation

Prevent fresh bindings from shadowing ambiguity items.
Fixes https://github.com/rust-lang/rust/issues/46079

Correctly treat const generic parameters in fresh binding disambiguation.
Fixes https://github.com/rust-lang/rust/issues/68853
Diffstat (limited to 'src/test/ui/binding')
-rw-r--r--src/test/ui/binding/ambiguity-item.rs18
-rw-r--r--src/test/ui/binding/ambiguity-item.stderr41
-rw-r--r--src/test/ui/binding/const-param.rs12
-rw-r--r--src/test/ui/binding/const-param.stderr17
4 files changed, 88 insertions, 0 deletions
diff --git a/src/test/ui/binding/ambiguity-item.rs b/src/test/ui/binding/ambiguity-item.rs
new file mode 100644
index 00000000000..10613cc6164
--- /dev/null
+++ b/src/test/ui/binding/ambiguity-item.rs
@@ -0,0 +1,18 @@
+// Identifier pattern referring to an ambiguity item is an error (issue #46079).
+
+mod m {
+    pub fn f() {}
+}
+use m::*;
+
+mod n {
+    pub fn f() {}
+}
+use n::*; // OK, no conflict with `use m::*;`
+
+fn main() {
+    let v = f; //~ ERROR `f` is ambiguous
+    match v {
+        f => {} //~ ERROR `f` is ambiguous
+    }
+}
diff --git a/src/test/ui/binding/ambiguity-item.stderr b/src/test/ui/binding/ambiguity-item.stderr
new file mode 100644
index 00000000000..615193c0d02
--- /dev/null
+++ b/src/test/ui/binding/ambiguity-item.stderr
@@ -0,0 +1,41 @@
+error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
+  --> $DIR/ambiguity-item.rs:14:13
+   |
+LL |     let v = f;
+   |             ^ ambiguous name
+   |
+note: `f` could refer to the function imported here
+  --> $DIR/ambiguity-item.rs:6:5
+   |
+LL | use m::*;
+   |     ^^^^
+   = help: consider adding an explicit import of `f` to disambiguate
+note: `f` could also refer to the function imported here
+  --> $DIR/ambiguity-item.rs:11:5
+   |
+LL | use n::*; // OK, no conflict with `use m::*;`
+   |     ^^^^
+   = help: consider adding an explicit import of `f` to disambiguate
+
+error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
+  --> $DIR/ambiguity-item.rs:16:9
+   |
+LL |         f => {}
+   |         ^ ambiguous name
+   |
+note: `f` could refer to the function imported here
+  --> $DIR/ambiguity-item.rs:6:5
+   |
+LL | use m::*;
+   |     ^^^^
+   = help: consider adding an explicit import of `f` to disambiguate
+note: `f` could also refer to the function imported here
+  --> $DIR/ambiguity-item.rs:11:5
+   |
+LL | use n::*; // OK, no conflict with `use m::*;`
+   |     ^^^^
+   = help: consider adding an explicit import of `f` to disambiguate
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0659`.
diff --git a/src/test/ui/binding/const-param.rs b/src/test/ui/binding/const-param.rs
new file mode 100644
index 00000000000..3c7f4d071f6
--- /dev/null
+++ b/src/test/ui/binding/const-param.rs
@@ -0,0 +1,12 @@
+// Identifier pattern referring to a const generic parameter is an error (issue #68853).
+
+#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
+
+fn check<const N: usize>() {
+    match 1 {
+        N => {} //~ ERROR const parameters cannot be referenced in patterns
+        _ => {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/binding/const-param.stderr b/src/test/ui/binding/const-param.stderr
new file mode 100644
index 00000000000..25b1c75c9a0
--- /dev/null
+++ b/src/test/ui/binding/const-param.stderr
@@ -0,0 +1,17 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/const-param.rs:3:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0158]: const parameters cannot be referenced in patterns
+  --> $DIR/const-param.rs:7:9
+   |
+LL |         N => {}
+   |         ^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0158`.