about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/llvm_module_flags.rs7
-rw-r--r--tests/ui-fulldeps/stable-mir/projections.rs173
-rw-r--r--tests/ui/impl-trait/auto-trait-coherence.next.stderr2
-rw-r--r--tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr2
-rw-r--r--tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr2
-rw-r--r--tests/ui/methods/method-ambiguity-no-rcvr.rs14
-rw-r--r--tests/ui/methods/method-ambiguity-no-rcvr.stderr32
-rw-r--r--tests/ui/nll/ty-outlives/impl-trait-captures.stderr10
8 files changed, 235 insertions, 7 deletions
diff --git a/tests/codegen/llvm_module_flags.rs b/tests/codegen/llvm_module_flags.rs
new file mode 100644
index 00000000000..acc035086de
--- /dev/null
+++ b/tests/codegen/llvm_module_flags.rs
@@ -0,0 +1,7 @@
+// Test for -Z llvm_module_flags
+// compile-flags: -Z llvm_module_flag=foo:u32:123:error -Z llvm_module_flag=bar:u32:42:max
+
+fn main() {}
+
+// CHECK: !{i32 1, !"foo", i32 123}
+// CHECK: !{i32 7, !"bar", i32 42}
diff --git a/tests/ui-fulldeps/stable-mir/projections.rs b/tests/ui-fulldeps/stable-mir/projections.rs
new file mode 100644
index 00000000000..9c649a2effc
--- /dev/null
+++ b/tests/ui-fulldeps/stable-mir/projections.rs
@@ -0,0 +1,173 @@
+// run-pass
+// Tests the Stable MIR projections API
+
+// ignore-stage1
+// ignore-cross-compile
+// ignore-remote
+// ignore-windows-gnu mingw has troubles with linking https://github.com/rust-lang/rust/pull/116837
+// edition: 2021
+
+#![feature(rustc_private)]
+#![feature(assert_matches)]
+#![feature(control_flow_enum)]
+
+extern crate rustc_hir;
+extern crate rustc_middle;
+#[macro_use]
+extern crate rustc_smir;
+extern crate rustc_driver;
+extern crate rustc_interface;
+extern crate stable_mir;
+
+use rustc_hir::def::DefKind;
+use rustc_middle::ty::TyCtxt;
+use rustc_smir::rustc_internal;
+use stable_mir::mir::{ProjectionElem, Rvalue, StatementKind};
+use stable_mir::ty::{RigidTy, TyKind};
+use std::assert_matches::assert_matches;
+use std::io::Write;
+use std::ops::ControlFlow;
+
+const CRATE_NAME: &str = "input";
+
+/// Tests projections within Place objects
+fn test_place_projections(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
+    let items = stable_mir::all_local_items();
+    let body = get_item(&items, (DefKind::Fn, "projections")).unwrap().body();
+    assert_eq!(body.blocks.len(), 4);
+    // The first statement assigns `&s.c` to a local. The projections include a deref for `s`, since
+    // `s` is passed as a reference argument, and a field access for field `c`.
+    match &body.blocks[0].statements[0].kind {
+        StatementKind::Assign(
+            stable_mir::mir::Place { local: _, projection: local_proj },
+            Rvalue::Ref(_, _, stable_mir::mir::Place { local: _, projection: r_proj }),
+        ) => {
+            // We can't match on vecs, only on slices. Comparing statements for equality wouldn't be
+            // any easier since we'd then have to add in the expected local and region values
+            // instead of matching on wildcards.
+            assert!(local_proj.is_empty());
+            match &r_proj[..] {
+                // Similarly we can't match against a type, only against its kind.
+                [ProjectionElem::Deref, ProjectionElem::Field(2, ty)] => assert_matches!(
+                    ty.kind(),
+                    TyKind::RigidTy(RigidTy::Uint(stable_mir::ty::UintTy::U8))
+                ),
+                other => panic!(
+                    "Unable to match against expected rvalue projection. Expected the projection \
+                     for `s.c`, which is a Deref and u8 Field. Got: {:?}",
+                    other
+                ),
+            };
+        }
+        other => panic!(
+            "Unable to match against expected Assign statement with a Ref rvalue. Expected the \
+             statement to assign `&s.c` to a local. Got: {:?}",
+            other
+        ),
+    };
+    // This statement assigns `slice[1]` to a local. The projections include a deref for `slice`,
+    // since `slice` is a reference, and an index.
+    match &body.blocks[2].statements[0].kind {
+        StatementKind::Assign(
+            stable_mir::mir::Place { local: _, projection: local_proj },
+            Rvalue::Use(stable_mir::mir::Operand::Copy(stable_mir::mir::Place {
+                local: _,
+                projection: r_proj,
+            })),
+        ) => {
+            // We can't match on vecs, only on slices. Comparing for equality wouldn't be any easier
+            // since we'd then have to add in the expected local values instead of matching on
+            // wildcards.
+            assert!(local_proj.is_empty());
+            assert_matches!(r_proj[..], [ProjectionElem::Deref, ProjectionElem::Index(_)]);
+        }
+        other => panic!(
+            "Unable to match against expected Assign statement with a Use rvalue. Expected the \
+             statement to assign `slice[1]` to a local. Got: {:?}",
+            other
+        ),
+    };
+    // The first terminator gets a slice of an array via the Index operation. Specifically it
+    // performs `&vals[1..3]`. There are no projections in this case, the arguments are just locals.
+    match &body.blocks[0].terminator.kind {
+        stable_mir::mir::TerminatorKind::Call { args, .. } =>
+        // We can't match on vecs, only on slices. Comparing for equality wouldn't be any easier
+        // since we'd then have to add in the expected local values instead of matching on
+        // wildcards.
+        {
+            match &args[..] {
+                [
+                    stable_mir::mir::Operand::Move(stable_mir::mir::Place {
+                        local: _,
+                        projection: arg1_proj,
+                    }),
+                    stable_mir::mir::Operand::Move(stable_mir::mir::Place {
+                        local: _,
+                        projection: arg2_proj,
+                    }),
+                ] => {
+                    assert!(arg1_proj.is_empty());
+                    assert!(arg2_proj.is_empty());
+                }
+                other => {
+                    panic!(
+                        "Unable to match against expected arguments to Index call. Expected two \
+                         move operands. Got: {:?}",
+                        other
+                    )
+                }
+            }
+        }
+        other => panic!(
+            "Unable to match against expected Call terminator. Expected a terminator that calls \
+             the Index operation. Got: {:?}",
+            other
+        ),
+    };
+
+    ControlFlow::Continue(())
+}
+
+// Use internal API to find a function in a crate.
+fn get_item<'a>(
+    items: &'a stable_mir::CrateItems,
+    item: (DefKind, &str),
+) -> Option<&'a stable_mir::CrateItem> {
+    items.iter().find(|crate_item| {
+        crate_item.kind().to_string() == format!("{:?}", item.0) && crate_item.name() == item.1
+    })
+}
+
+/// This test will generate and analyze a dummy crate using the stable mir.
+/// For that, it will first write the dummy crate into a file.
+/// Then it will create a `StableMir` using custom arguments and then
+/// it will run the compiler.
+fn main() {
+    let path = "input.rs";
+    generate_input(&path).unwrap();
+    let args = vec![
+        "rustc".to_string(),
+        "--crate-type=lib".to_string(),
+        "--crate-name".to_string(),
+        CRATE_NAME.to_string(),
+        path.to_string(),
+    ];
+    run!(args, tcx, test_place_projections(tcx)).unwrap();
+}
+
+fn generate_input(path: &str) -> std::io::Result<()> {
+    let mut file = std::fs::File::create(path)?;
+    write!(
+        file,
+        r#"
+    pub struct Struct1 {{ _a: u8, _b: u16, c: u8 }}
+
+    pub fn projections(s: &Struct1) -> u8 {{
+        let v = &s.c;
+        let vals = [1, 2, 3, 4];
+        let slice = &vals[1..3];
+        v + slice[1]
+    }}"#
+    )?;
+    Ok(())
+}
diff --git a/tests/ui/impl-trait/auto-trait-coherence.next.stderr b/tests/ui/impl-trait/auto-trait-coherence.next.stderr
index 7833ac688ba..cee359997b4 100644
--- a/tests/ui/impl-trait/auto-trait-coherence.next.stderr
+++ b/tests/ui/impl-trait/auto-trait-coherence.next.stderr
@@ -6,6 +6,8 @@ LL | impl<T: Send> AnotherTrait for T {}
 ...
 LL | impl AnotherTrait for D<OpaqueType> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
+   |
+   = note: upstream crates may add a new impl of trait `std::marker::Send` for type `OpaqueType` in future versions
 
 error: aborting due to previous error
 
diff --git a/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr b/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr
index 84b61dc5044..4cd4febc4f0 100644
--- a/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr
+++ b/tests/ui/impl-trait/erased-regions-in-hidden-ty.current.stderr
@@ -1,4 +1,4 @@
-error: {foo<ReEarlyBound(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()}
+error: {foo<ReEarlyParam(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()}
   --> $DIR/erased-regions-in-hidden-ty.rs:11:36
    |
 LL | fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static {
diff --git a/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr b/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr
index 84b61dc5044..4cd4febc4f0 100644
--- a/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr
+++ b/tests/ui/impl-trait/erased-regions-in-hidden-ty.next.stderr
@@ -1,4 +1,4 @@
-error: {foo<ReEarlyBound(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()}
+error: {foo<ReEarlyParam(DefId(..), 0, 'a)>::{closure#0} closure_kind_ty=i8 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(()) upvar_tys=()}
   --> $DIR/erased-regions-in-hidden-ty.rs:11:36
    |
 LL | fn foo<'a: 'a>(x: &'a Vec<i32>) -> impl Fn() + 'static {
diff --git a/tests/ui/methods/method-ambiguity-no-rcvr.rs b/tests/ui/methods/method-ambiguity-no-rcvr.rs
new file mode 100644
index 00000000000..8f36011d41f
--- /dev/null
+++ b/tests/ui/methods/method-ambiguity-no-rcvr.rs
@@ -0,0 +1,14 @@
+struct Qux;
+
+trait Foo {
+    fn foo();
+}
+
+trait FooBar {
+    fn foo() {}
+}
+
+fn main() {
+    Qux.foo();
+    //~^ ERROR no method named `foo` found for struct `Qux` in the current scope
+}
diff --git a/tests/ui/methods/method-ambiguity-no-rcvr.stderr b/tests/ui/methods/method-ambiguity-no-rcvr.stderr
new file mode 100644
index 00000000000..95c9d7ebac0
--- /dev/null
+++ b/tests/ui/methods/method-ambiguity-no-rcvr.stderr
@@ -0,0 +1,32 @@
+error[E0599]: no method named `foo` found for struct `Qux` in the current scope
+  --> $DIR/method-ambiguity-no-rcvr.rs:12:9
+   |
+LL | struct Qux;
+   | ---------- method `foo` not found for this struct
+...
+LL |     Qux.foo();
+   |         ^^^ this is an associated function, not a method
+   |
+   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
+note: candidate #1 is defined in the trait `Foo`
+  --> $DIR/method-ambiguity-no-rcvr.rs:4:5
+   |
+LL |     fn foo();
+   |     ^^^^^^^^^
+note: candidate #2 is defined in the trait `FooBar`
+  --> $DIR/method-ambiguity-no-rcvr.rs:8:5
+   |
+LL |     fn foo() {}
+   |     ^^^^^^^^
+help: disambiguate the associated function for candidate #1
+   |
+LL |     <Qux as Foo>::foo(Qux);
+   |     ~~~~~~~~~~~~~~~~~~~~~~
+help: disambiguate the associated function for candidate #2
+   |
+LL |     <Qux as FooBar>::foo(Qux);
+   |     ~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/nll/ty-outlives/impl-trait-captures.stderr b/tests/ui/nll/ty-outlives/impl-trait-captures.stderr
index ba885d1b97e..320f529624f 100644
--- a/tests/ui/nll/ty-outlives/impl-trait-captures.stderr
+++ b/tests/ui/nll/ty-outlives/impl-trait-captures.stderr
@@ -1,17 +1,17 @@
-error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyBound(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyBound(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a)])` captures lifetime that does not appear in bounds
+error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a)])` captures lifetime that does not appear in bounds
   --> $DIR/impl-trait-captures.rs:11:5
    |
 LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
    |                  --     ------------ opaque type defined here
    |                  |
-   |                  hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) T` captures the anonymous lifetime defined here
+   |                  hidden type `&ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) T` captures the anonymous lifetime defined here
 LL |     x
    |     ^
    |
-help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyBound(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyBound(DefId(0:14 ~ impl_trait_captures[aeb9]::foo::{opaque#0}::'a), 2, 'a)])` captures `ReFree(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))` lifetime bound
+help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [ReEarlyParam(DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a), 0, 'a), T, ReEarlyParam(DefId(0:14 ~ impl_trait_captures[aeb9]::foo::{opaque#0}::'a), 2, 'a)])` captures `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`, you can add an explicit `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))` lifetime bound
    |
-LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) {
-   |                                      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) {
+   |                                      +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 error: aborting due to previous error