about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-07-27 15:41:45 +0000
committerbors <bors@rust-lang.org>2019-07-27 15:41:45 +0000
commita5e7bb3e2bae3e8d31c10de66e91cdcea42a97df (patch)
tree3bda6c31bb326cb96e871a1d751a0d9756e8a7b6 /src/test
parent0e9b465d729d07101b29b4d096d83edf9be82df0 (diff)
parent51769b3012b3f2819bbcde05a574e6f3015b7d37 (diff)
downloadrust-a5e7bb3e2bae3e8d31c10de66e91cdcea42a97df.tar.gz
rust-a5e7bb3e2bae3e8d31c10de66e91cdcea42a97df.zip
Auto merge of #63043 - Centril:rollup-f4baee4, r=Centril
Rollup of 6 pull requests

Successful merges:

 - #62423 (Fix cycle error with existential types)
 - #62979 (Cleanup save-analysis JsonDumper)
 - #62982 (Don't access a static just for its size and alignment)
 - #63013 (add `repr(transparent)` to `IoSliceMut` where missing)
 - #63014 (Stop bare trait lint applying to macro call sites)
 - #63036 (Add lib section to rustc_lexer's Cargo.toml)

Failed merges:

r? @ghost
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/static-cycle-error.rs11
-rw-r--r--src/test/ui/existential_types/existential-types-with-cycle-error.rs2
-rw-r--r--src/test/ui/existential_types/existential-types-with-cycle-error.stderr24
-rw-r--r--src/test/ui/existential_types/existential-types-with-cycle-error2.rs2
-rw-r--r--src/test/ui/existential_types/existential-types-with-cycle-error2.stderr24
-rw-r--r--src/test/ui/existential_types/existential_type_const.rs20
-rw-r--r--src/test/ui/existential_types/existential_type_const.stderr6
-rw-r--r--src/test/ui/existential_types/existential_type_fns.rs27
-rw-r--r--src/test/ui/existential_types/existential_type_tuple.rs33
-rw-r--r--src/test/ui/existential_types/no_inferrable_concrete_type.rs6
-rw-r--r--src/test/ui/existential_types/no_inferrable_concrete_type.stderr21
-rw-r--r--src/test/ui/suggestions/auxiliary/issue-61963-1.rs40
-rw-r--r--src/test/ui/suggestions/auxiliary/issue-61963.rs41
-rw-r--r--src/test/ui/suggestions/issue-61963.rs24
-rw-r--r--src/test/ui/suggestions/issue-61963.stderr14
15 files changed, 224 insertions, 71 deletions
diff --git a/src/test/ui/consts/static-cycle-error.rs b/src/test/ui/consts/static-cycle-error.rs
new file mode 100644
index 00000000000..9ce050aae21
--- /dev/null
+++ b/src/test/ui/consts/static-cycle-error.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+struct Foo {
+    foo: Option<&'static Foo>
+}
+
+static FOO: Foo = Foo {
+    foo: Some(&FOO),
+};
+
+fn main() {}
diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error.rs b/src/test/ui/existential_types/existential-types-with-cycle-error.rs
index 3f0190892eb..38fcabb5cc1 100644
--- a/src/test/ui/existential_types/existential-types-with-cycle-error.rs
+++ b/src/test/ui/existential_types/existential-types-with-cycle-error.rs
@@ -1,7 +1,7 @@
 #![feature(existential_type)]
 
 existential type Foo: Fn() -> Foo;
-//~^ ERROR: cycle detected when processing `Foo`
+//~^ ERROR: could not find defining uses
 
 fn crash(x: Foo) -> Foo {
     x
diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error.stderr b/src/test/ui/existential_types/existential-types-with-cycle-error.stderr
index 56057a9caa4..98a269d5271 100644
--- a/src/test/ui/existential_types/existential-types-with-cycle-error.stderr
+++ b/src/test/ui/existential_types/existential-types-with-cycle-error.stderr
@@ -1,30 +1,8 @@
-error[E0391]: cycle detected when processing `Foo`
+error: could not find defining uses
   --> $DIR/existential-types-with-cycle-error.rs:3:1
    |
 LL | existential type Foo: Fn() -> Foo;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: ...which requires processing `crash`...
-  --> $DIR/existential-types-with-cycle-error.rs:6:25
-   |
-LL |   fn crash(x: Foo) -> Foo {
-   |  _________________________^
-LL | |     x
-LL | | }
-   | |_^
-   = note: ...which again requires processing `Foo`, completing the cycle
-note: cycle used when collecting item types in top-level module
-  --> $DIR/existential-types-with-cycle-error.rs:1:1
-   |
-LL | / #![feature(existential_type)]
-LL | |
-LL | | existential type Foo: Fn() -> Foo;
-LL | |
-...  |
-LL | |
-LL | | }
-   | |_^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error2.rs b/src/test/ui/existential_types/existential-types-with-cycle-error2.rs
index 29410309ef2..f9e6bdb67d4 100644
--- a/src/test/ui/existential_types/existential-types-with-cycle-error2.rs
+++ b/src/test/ui/existential_types/existential-types-with-cycle-error2.rs
@@ -5,7 +5,7 @@ pub trait Bar<T> {
 }
 
 existential type Foo: Bar<Foo, Item = Foo>;
-//~^ ERROR: cycle detected when processing `Foo`
+//~^ ERROR: could not find defining uses
 
 fn crash(x: Foo) -> Foo {
     x
diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr b/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr
index 8c7bf52470a..830305d8631 100644
--- a/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr
+++ b/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr
@@ -1,30 +1,8 @@
-error[E0391]: cycle detected when processing `Foo`
+error: could not find defining uses
   --> $DIR/existential-types-with-cycle-error2.rs:7:1
    |
 LL | existential type Foo: Bar<Foo, Item = Foo>;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: ...which requires processing `crash`...
-  --> $DIR/existential-types-with-cycle-error2.rs:10:25
-   |
-LL |   fn crash(x: Foo) -> Foo {
-   |  _________________________^
-LL | |     x
-LL | | }
-   | |_^
-   = note: ...which again requires processing `Foo`, completing the cycle
-note: cycle used when collecting item types in top-level module
-  --> $DIR/existential-types-with-cycle-error2.rs:1:1
-   |
-LL | / #![feature(existential_type)]
-LL | |
-LL | | pub trait Bar<T> {
-LL | |     type Item;
-...  |
-LL | |
-LL | | }
-   | |_^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/existential_types/existential_type_const.rs b/src/test/ui/existential_types/existential_type_const.rs
new file mode 100644
index 00000000000..646e9a73424
--- /dev/null
+++ b/src/test/ui/existential_types/existential_type_const.rs
@@ -0,0 +1,20 @@
+// check-pass
+
+#![feature(existential_type)]
+// Currently, the `existential_type` feature implicitly
+// depends on `impl_trait_in_bindings` in order to work properly.
+// Specifically, this line requires `impl_trait_in_bindings` to be enabled:
+// https://github.com/rust-lang/rust/blob/481068a707679257e2a738b40987246e0420e787/src/librustc_typeck/check/mod.rs#L856
+#![feature(impl_trait_in_bindings)]
+//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
+
+// Ensures that `const` items can constrain an `existential type`.
+
+use std::fmt::Debug;
+
+pub existential type Foo: Debug;
+
+const _FOO: Foo = 5;
+
+fn main() {
+}
diff --git a/src/test/ui/existential_types/existential_type_const.stderr b/src/test/ui/existential_types/existential_type_const.stderr
new file mode 100644
index 00000000000..049b4f75dd2
--- /dev/null
+++ b/src/test/ui/existential_types/existential_type_const.stderr
@@ -0,0 +1,6 @@
+warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
+  --> $DIR/existential_type_const.rs:8:12
+   |
+LL | #![feature(impl_trait_in_bindings)]
+   |            ^^^^^^^^^^^^^^^^^^^^^^
+
diff --git a/src/test/ui/existential_types/existential_type_fns.rs b/src/test/ui/existential_types/existential_type_fns.rs
new file mode 100644
index 00000000000..6f22eef2849
--- /dev/null
+++ b/src/test/ui/existential_types/existential_type_fns.rs
@@ -0,0 +1,27 @@
+// check-pass
+
+#![feature(existential_type)]
+
+// Regression test for issue #61863
+
+pub trait MyTrait {}
+
+#[derive(Debug)]
+pub struct MyStruct {
+  v: u64
+}
+
+impl MyTrait for MyStruct {}
+
+pub fn bla() -> TE {
+    return MyStruct {v:1}
+}
+
+pub fn bla2() -> TE {
+    bla()
+}
+
+
+existential type TE: MyTrait;
+
+fn main() {}
diff --git a/src/test/ui/existential_types/existential_type_tuple.rs b/src/test/ui/existential_types/existential_type_tuple.rs
new file mode 100644
index 00000000000..0f134a52897
--- /dev/null
+++ b/src/test/ui/existential_types/existential_type_tuple.rs
@@ -0,0 +1,33 @@
+// check-pass
+
+#![feature(existential_type)]
+#![allow(dead_code)]
+
+pub trait MyTrait {}
+
+impl MyTrait for bool {}
+
+struct Blah {
+    my_foo: Foo,
+    my_u8: u8
+}
+
+impl Blah {
+    fn new() -> Blah {
+        Blah {
+            my_foo: make_foo(),
+            my_u8: 12
+        }
+    }
+    fn into_inner(self) -> (Foo, u8) {
+        (self.my_foo, self.my_u8)
+    }
+}
+
+fn make_foo() -> Foo {
+    true
+}
+
+existential type Foo: MyTrait;
+
+fn main() {}
diff --git a/src/test/ui/existential_types/no_inferrable_concrete_type.rs b/src/test/ui/existential_types/no_inferrable_concrete_type.rs
index 6bbe8bdc0cd..eec8a4be63d 100644
--- a/src/test/ui/existential_types/no_inferrable_concrete_type.rs
+++ b/src/test/ui/existential_types/no_inferrable_concrete_type.rs
@@ -1,9 +1,9 @@
-// Issue 52985: Cause cycle error if user code provides no use case that allows an existential type
-// to be inferred to a concrete type. This results in an infinite cycle during type normalization.
+// Issue 52985: user code provides no use case that allows an existential type
+// We now emit a 'could not find defining uses' error
 
 #![feature(existential_type)]
 
-existential type Foo: Copy; //~ cycle detected
+existential type Foo: Copy; //~ could not find defining uses
 
 // make compiler happy about using 'Foo'
 fn bar(x: Foo) -> Foo { x }
diff --git a/src/test/ui/existential_types/no_inferrable_concrete_type.stderr b/src/test/ui/existential_types/no_inferrable_concrete_type.stderr
index 4605332ef5b..bc9a883c836 100644
--- a/src/test/ui/existential_types/no_inferrable_concrete_type.stderr
+++ b/src/test/ui/existential_types/no_inferrable_concrete_type.stderr
@@ -1,27 +1,8 @@
-error[E0391]: cycle detected when processing `Foo`
+error: could not find defining uses
   --> $DIR/no_inferrable_concrete_type.rs:6:1
    |
 LL | existential type Foo: Copy;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: ...which requires processing `bar`...
-  --> $DIR/no_inferrable_concrete_type.rs:9:23
-   |
-LL | fn bar(x: Foo) -> Foo { x }
-   |                       ^^^^^
-   = note: ...which again requires processing `Foo`, completing the cycle
-note: cycle used when collecting item types in top-level module
-  --> $DIR/no_inferrable_concrete_type.rs:4:1
-   |
-LL | / #![feature(existential_type)]
-LL | |
-LL | | existential type Foo: Copy;
-LL | |
-...  |
-LL | |     let _: Foo = std::mem::transmute(0u8);
-LL | | }
-   | |_^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/suggestions/auxiliary/issue-61963-1.rs b/src/test/ui/suggestions/auxiliary/issue-61963-1.rs
new file mode 100644
index 00000000000..6c2df7e84e0
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/issue-61963-1.rs
@@ -0,0 +1,40 @@
+// force-host
+// no-prefer-dynamic
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{Group, TokenStream, TokenTree};
+
+// This macro exists as part of a reproduction of #61963 but without using quote/syn/proc_macro2.
+
+#[proc_macro_derive(DomObject)]
+pub fn expand_token_stream(input: TokenStream) -> TokenStream {
+    // Construct a dummy span - `#0 bytes(0..0)` - which is present in the input because
+    // of the specially crafted generated tokens in the `attribute-crate` proc-macro.
+    let dummy_span = input.clone().into_iter().nth(0).unwrap().span();
+
+    // Define what the macro would output if constructed properly from the source using syn/quote.
+    let output: TokenStream = "impl Bar for ((), Qux<Qux<Baz> >) { }
+    impl Bar for ((), Box<Bar>) { }".parse().unwrap();
+
+    let mut tokens: Vec<_> = output.into_iter().collect();
+    // Adjust token spans to match the original crate (which would use `quote`). Some of the
+    // generated tokens point to the dummy span.
+    for token in tokens.iter_mut() {
+        if let TokenTree::Group(group) = token {
+            let mut tokens: Vec<_> = group.stream().into_iter().collect();
+            for token in tokens.iter_mut().skip(2) {
+                token.set_span(dummy_span);
+            }
+
+            let mut stream = TokenStream::new();
+            stream.extend(tokens);
+            *group = Group::new(group.delimiter(), stream);
+        }
+    }
+
+    let mut output = TokenStream::new();
+    output.extend(tokens);
+    output
+}
diff --git a/src/test/ui/suggestions/auxiliary/issue-61963.rs b/src/test/ui/suggestions/auxiliary/issue-61963.rs
new file mode 100644
index 00000000000..e86f1610ab0
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/issue-61963.rs
@@ -0,0 +1,41 @@
+// force-host
+// no-prefer-dynamic
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{Group, Spacing, Punct, TokenTree, TokenStream};
+
+// This macro exists as part of a reproduction of #61963 but without using quote/syn/proc_macro2.
+
+#[proc_macro_attribute]
+pub fn dom_struct(_: TokenStream, input: TokenStream) -> TokenStream {
+    // Construct the expected output tokens - the input but with a `#[derive(DomObject)]` applied.
+    let attributes: TokenStream =
+        "#[derive(DomObject)]".to_string().parse().unwrap();
+    let output: TokenStream = attributes.into_iter()
+        .chain(input.into_iter()).collect();
+
+    let mut tokens: Vec<_> = output.into_iter().collect();
+    // Adjust the spacing of `>` tokens to match what `quote` would produce.
+    for token in tokens.iter_mut() {
+        if let TokenTree::Group(group) = token {
+            let mut tokens: Vec<_> = group.stream().into_iter().collect();
+            for token in tokens.iter_mut() {
+                if let TokenTree::Punct(p) = token {
+                    if p.as_char() == '>' {
+                        *p = Punct::new('>', Spacing::Alone);
+                    }
+                }
+            }
+
+            let mut stream = TokenStream::new();
+            stream.extend(tokens);
+            *group = Group::new(group.delimiter(), stream);
+        }
+    }
+
+    let mut output = TokenStream::new();
+    output.extend(tokens);
+    output
+}
diff --git a/src/test/ui/suggestions/issue-61963.rs b/src/test/ui/suggestions/issue-61963.rs
new file mode 100644
index 00000000000..c9d738f5a28
--- /dev/null
+++ b/src/test/ui/suggestions/issue-61963.rs
@@ -0,0 +1,24 @@
+// aux-build:issue-61963.rs
+// aux-build:issue-61963-1.rs
+#![deny(bare_trait_objects)]
+
+#[macro_use]
+extern crate issue_61963;
+#[macro_use]
+extern crate issue_61963_1;
+
+// This test checks that the bare trait object lint does not trigger on macro attributes that
+// generate code which would trigger the lint.
+
+pub struct Baz;
+pub trait Bar { }
+pub struct Qux<T>(T);
+
+#[dom_struct]
+pub struct Foo {
+    qux: Qux<Qux<Baz>>,
+    bar: Box<Bar>,
+    //~^ ERROR trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-61963.stderr b/src/test/ui/suggestions/issue-61963.stderr
new file mode 100644
index 00000000000..46943f40066
--- /dev/null
+++ b/src/test/ui/suggestions/issue-61963.stderr
@@ -0,0 +1,14 @@
+error: trait objects without an explicit `dyn` are deprecated
+  --> $DIR/issue-61963.rs:20:14
+   |
+LL |     bar: Box<Bar>,
+   |              ^^^ help: use `dyn`: `dyn Bar`
+   |
+note: lint level defined here
+  --> $DIR/issue-61963.rs:3:9
+   |
+LL | #![deny(bare_trait_objects)]
+   |         ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+