about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/ui-fulldeps/issue-81357-unsound-file-methods.rs81
-rw-r--r--src/test/ui/asm/issue-99122-2.rs21
-rw-r--r--src/test/ui/asm/issue-99122.rs13
-rw-r--r--src/test/ui/asm/issue-99122.stderr11
-rw-r--r--src/test/ui/generic-associated-types/issue-91139.rs1
-rw-r--r--src/test/ui/generic-associated-types/issue-91139.stderr14
-rw-r--r--src/test/ui/lifetimes/bare-trait-object-borrowck.rs24
-rw-r--r--src/test/ui/lifetimes/bare-trait-object.rs25
-rw-r--r--src/test/ui/nll/issue-98693.rs21
-rw-r--r--src/test/ui/nll/issue-98693.stderr17
10 files changed, 227 insertions, 1 deletions
diff --git a/src/test/ui-fulldeps/issue-81357-unsound-file-methods.rs b/src/test/ui-fulldeps/issue-81357-unsound-file-methods.rs
new file mode 100644
index 00000000000..fdf1150f8d2
--- /dev/null
+++ b/src/test/ui-fulldeps/issue-81357-unsound-file-methods.rs
@@ -0,0 +1,81 @@
+// run-fail
+// only-windows
+
+fn main() {
+    use std::fs;
+    use std::io::prelude::*;
+    use std::os::windows::prelude::*;
+    use std::ptr;
+    use std::sync::Arc;
+    use std::thread;
+    use std::time::Duration;
+
+    const FILE_FLAG_OVERLAPPED: u32 = 0x40000000;
+
+    fn create_pipe_server(path: &str) -> fs::File {
+        let mut path0 = path.as_bytes().to_owned();
+        path0.push(0);
+        extern "system" {
+            fn CreateNamedPipeA(
+                lpName: *const u8,
+                dwOpenMode: u32,
+                dwPipeMode: u32,
+                nMaxInstances: u32,
+                nOutBufferSize: u32,
+                nInBufferSize: u32,
+                nDefaultTimeOut: u32,
+                lpSecurityAttributes: *mut u8,
+            ) -> RawHandle;
+        }
+
+        unsafe {
+            let h = CreateNamedPipeA(path0.as_ptr(), 3, 0, 1, 0, 0, 0, ptr::null_mut());
+            assert_ne!(h as isize, -1);
+            fs::File::from_raw_handle(h)
+        }
+    }
+
+    let path = "\\\\.\\pipe\\repro";
+    let mut server = create_pipe_server(path);
+
+    let client = Arc::new(
+        fs::OpenOptions::new().custom_flags(FILE_FLAG_OVERLAPPED).read(true).open(path).unwrap(),
+    );
+
+    let spawn_read = |is_first: bool| {
+        thread::spawn({
+            let f = client.clone();
+            move || {
+                let mut buf = [0xcc; 1];
+                let mut f = f.as_ref();
+                f.read(&mut buf).unwrap();
+                if is_first {
+                    assert_ne!(buf[0], 0xcc);
+                } else {
+                    let b = buf[0]; // capture buf[0]
+                    thread::sleep(Duration::from_millis(200));
+
+                    // Check the buffer hasn't been written to after read.
+                    dbg!(buf[0], b);
+                    assert_eq!(buf[0], b);
+                }
+            }
+        })
+    };
+
+    let t1 = spawn_read(true);
+    thread::sleep(Duration::from_millis(20));
+    let t2 = spawn_read(false);
+    thread::sleep(Duration::from_millis(100));
+    let _ = server.write(b"x");
+    thread::sleep(Duration::from_millis(100));
+    let _ = server.write(b"y");
+
+    // This is run fail because we need to test for the `abort`.
+    // That failing to run is the success case.
+    if t1.join().is_err() || t2.join().is_err() {
+        return;
+    } else {
+        panic!("success");
+    }
+}
diff --git a/src/test/ui/asm/issue-99122-2.rs b/src/test/ui/asm/issue-99122-2.rs
new file mode 100644
index 00000000000..cfb9fd90a55
--- /dev/null
+++ b/src/test/ui/asm/issue-99122-2.rs
@@ -0,0 +1,21 @@
+// check-pass
+// needs-asm-support
+// only-x86_64
+
+// This demonstrates why we need to erase regions before sized check in intrinsicck
+
+struct NoCopy;
+
+struct Wrap<'a, T, Tail: ?Sized>(&'a T, Tail);
+
+pub unsafe fn test() {
+    let i = NoCopy;
+    let j = Wrap(&i, ());
+    let pointer = &j as *const _;
+    core::arch::asm!(
+        "nop",
+        in("eax") pointer,
+    );
+}
+
+fn main() {}
diff --git a/src/test/ui/asm/issue-99122.rs b/src/test/ui/asm/issue-99122.rs
new file mode 100644
index 00000000000..744a563d3d1
--- /dev/null
+++ b/src/test/ui/asm/issue-99122.rs
@@ -0,0 +1,13 @@
+// needs-asm-support
+// only-x86_64
+
+pub unsafe fn test() {
+    let pointer = 1u32 as *const _;
+    //~^ ERROR cannot cast to a pointer of an unknown kind
+    core::arch::asm!(
+        "nop",
+        in("eax") pointer,
+    );
+}
+
+fn main() {}
diff --git a/src/test/ui/asm/issue-99122.stderr b/src/test/ui/asm/issue-99122.stderr
new file mode 100644
index 00000000000..2758a4ac437
--- /dev/null
+++ b/src/test/ui/asm/issue-99122.stderr
@@ -0,0 +1,11 @@
+error[E0641]: cannot cast to a pointer of an unknown kind
+  --> $DIR/issue-99122.rs:5:27
+   |
+LL |     let pointer = 1u32 as *const _;
+   |                           ^^^^^^^^ needs more type information
+   |
+   = note: the type information given here is insufficient to check whether the pointer cast is valid
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0641`.
diff --git a/src/test/ui/generic-associated-types/issue-91139.rs b/src/test/ui/generic-associated-types/issue-91139.rs
index 092fa939c30..40eef11f058 100644
--- a/src/test/ui/generic-associated-types/issue-91139.rs
+++ b/src/test/ui/generic-associated-types/issue-91139.rs
@@ -22,6 +22,7 @@ fn foo<T>() {
     //~| ERROR `T` does not live long enough
     //~| ERROR `T` does not live long enough
     //~| ERROR `T` does not live long enough
+    //~| ERROR `T` may not live long enough
     //
     // FIXME: This error is bogus, but it arises because we try to validate
     // that `<() as Foo<T>>::Type<'a>` is valid, which requires proving
diff --git a/src/test/ui/generic-associated-types/issue-91139.stderr b/src/test/ui/generic-associated-types/issue-91139.stderr
index 6c5092978c8..b789b3a42f3 100644
--- a/src/test/ui/generic-associated-types/issue-91139.stderr
+++ b/src/test/ui/generic-associated-types/issue-91139.stderr
@@ -34,6 +34,17 @@ error: `T` does not live long enough
 LL |     let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| ();
    |                                                          ^^^^^^^^^
 
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/issue-91139.rs:16:58
+   |
+LL |     let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| ();
+   |                                                          ^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound...
+   |
+LL | fn foo<T: 'static>() {
+   |         +++++++++
+
 error: `T` does not live long enough
   --> $DIR/issue-91139.rs:16:58
    |
@@ -46,5 +57,6 @@ error: `T` does not live long enough
 LL |     let _: for<'a> fn(<() as Foo<T>>::Type<'a>, &'a T) = |_, _| ();
    |                                                          ^^^^^^^^^
 
-error: aborting due to 8 previous errors
+error: aborting due to 9 previous errors
 
+For more information about this error, try `rustc --explain E0310`.
diff --git a/src/test/ui/lifetimes/bare-trait-object-borrowck.rs b/src/test/ui/lifetimes/bare-trait-object-borrowck.rs
new file mode 100644
index 00000000000..45f5e4ae129
--- /dev/null
+++ b/src/test/ui/lifetimes/bare-trait-object-borrowck.rs
@@ -0,0 +1,24 @@
+#![allow(bare_trait_objects)]
+// check-pass
+pub struct FormatWith<'a, I, F> {
+    sep: &'a str,
+    /// FormatWith uses interior mutability because Display::fmt takes &self.
+    inner: RefCell<Option<(I, F)>>,
+}
+
+use std::cell::RefCell;
+use std::fmt;
+
+struct Layout;
+
+pub fn new_format<'a, I, F>(iter: I, separator: &'a str, f: F) -> FormatWith<'a, I, F>
+where
+    I: Iterator,
+    F: FnMut(I::Item, &mut FnMut(&fmt::Display) -> fmt::Result) -> fmt::Result,
+{
+    FormatWith { sep: separator, inner: RefCell::new(Some((iter, f))) }
+}
+
+fn main() {
+    let _ = new_format(0..32, " | ", |i, f| f(&format_args!("0x{:x}", i)));
+}
diff --git a/src/test/ui/lifetimes/bare-trait-object.rs b/src/test/ui/lifetimes/bare-trait-object.rs
new file mode 100644
index 00000000000..9eff618c734
--- /dev/null
+++ b/src/test/ui/lifetimes/bare-trait-object.rs
@@ -0,0 +1,25 @@
+// Verify that lifetime resolution correctly accounts for `Fn` bare trait objects.
+// check-pass
+#![allow(bare_trait_objects)]
+
+// This should work as: fn next_u32(fill_buf: &mut dyn FnMut(&mut [u8]))
+fn next_u32(fill_buf: &mut FnMut(&mut [u8])) {
+    let mut buf: [u8; 4] = [0; 4];
+    fill_buf(&mut buf);
+}
+
+fn explicit(fill_buf: &mut dyn FnMut(&mut [u8])) {
+    let mut buf: [u8; 4] = [0; 4];
+    fill_buf(&mut buf);
+}
+
+fn main() {
+    let _: fn(&mut FnMut(&mut [u8])) = next_u32;
+    let _: &dyn Fn(&mut FnMut(&mut [u8])) = &next_u32;
+    let _: fn(&mut FnMut(&mut [u8])) = explicit;
+    let _: &dyn Fn(&mut FnMut(&mut [u8])) = &explicit;
+    let _: fn(&mut dyn FnMut(&mut [u8])) = next_u32;
+    let _: &dyn Fn(&mut dyn FnMut(&mut [u8])) = &next_u32;
+    let _: fn(&mut dyn FnMut(&mut [u8])) = explicit;
+    let _: &dyn Fn(&mut dyn FnMut(&mut [u8])) = &explicit;
+}
diff --git a/src/test/ui/nll/issue-98693.rs b/src/test/ui/nll/issue-98693.rs
new file mode 100644
index 00000000000..18e6ec63046
--- /dev/null
+++ b/src/test/ui/nll/issue-98693.rs
@@ -0,0 +1,21 @@
+// Regression test for #98693.
+//
+// The closure encounters an obligation that `T` must outlive `!U1`,
+// a placeholder from universe U1. We were ignoring this placeholder
+// when promoting the constraint to the enclosing function, and
+// thus incorrectly judging the closure to be safe.
+
+fn assert_static<T>()
+where
+    for<'a> T: 'a,
+{
+}
+
+fn test<T>() {
+    || {
+        //~^ ERROR the parameter type `T` may not live long enough
+        assert_static::<T>();
+    };
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/issue-98693.stderr b/src/test/ui/nll/issue-98693.stderr
new file mode 100644
index 00000000000..31689620c64
--- /dev/null
+++ b/src/test/ui/nll/issue-98693.stderr
@@ -0,0 +1,17 @@
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/issue-98693.rs:15:5
+   |
+LL | /     || {
+LL | |
+LL | |         assert_static::<T>();
+LL | |     };
+   | |_____^ ...so that the type `T` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound...
+   |
+LL | fn test<T: 'static>() {
+   |          +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0310`.