From 27fe959c2c99207828cedfe19dbf96debd3be591 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 14 May 2021 23:19:59 +0200 Subject: Check for raw pointer dereference in THIR unsafeck --- compiler/rustc_mir_build/src/check_unsafety.rs | 6 +++++- .../issue-45729-unsafe-in-generator.mir.stderr | 11 +++++++++++ .../ui/generator/issue-45729-unsafe-in-generator.rs | 3 +++ .../generator/issue-45729-unsafe-in-generator.stderr | 11 ----------- .../issue-45729-unsafe-in-generator.thir.stderr | 11 +++++++++++ src/test/ui/issues/issue-47412.mir.stderr | 19 +++++++++++++++++++ src/test/ui/issues/issue-47412.rs | 6 +++++- src/test/ui/issues/issue-47412.stderr | 19 ------------------- src/test/ui/issues/issue-47412.thir.stderr | 11 +++++++++++ src/test/ui/traits/safety-fn-body.mir.stderr | 11 +++++++++++ src/test/ui/traits/safety-fn-body.rs | 3 +++ src/test/ui/traits/safety-fn-body.stderr | 11 ----------- src/test/ui/traits/safety-fn-body.thir.stderr | 11 +++++++++++ .../unsafe/issue-45087-unreachable-unsafe.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs | 3 +++ .../ui/unsafe/issue-45087-unreachable-unsafe.stderr | 11 ----------- .../unsafe/issue-45087-unreachable-unsafe.thir.stderr | 11 +++++++++++ .../ui/unsafe/unsafe-fn-assign-deref-ptr.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.rs | 3 +++ src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.stderr | 11 ----------- .../ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr | 11 +++++++++++ src/test/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/unsafe-fn-deref-ptr.rs | 3 +++ src/test/ui/unsafe/unsafe-fn-deref-ptr.stderr | 11 ----------- src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr | 11 +++++++++++ .../ui/unsafe/unsafe-unstable-const-fn.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/unsafe-unstable-const-fn.rs | 3 +++ src/test/ui/unsafe/unsafe-unstable-const-fn.stderr | 11 ----------- .../ui/unsafe/unsafe-unstable-const-fn.thir.stderr | 11 +++++++++++ 29 files changed, 190 insertions(+), 87 deletions(-) create mode 100644 src/test/ui/generator/issue-45729-unsafe-in-generator.mir.stderr delete mode 100644 src/test/ui/generator/issue-45729-unsafe-in-generator.stderr create mode 100644 src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr create mode 100644 src/test/ui/issues/issue-47412.mir.stderr delete mode 100644 src/test/ui/issues/issue-47412.stderr create mode 100644 src/test/ui/issues/issue-47412.thir.stderr create mode 100644 src/test/ui/traits/safety-fn-body.mir.stderr delete mode 100644 src/test/ui/traits/safety-fn-body.stderr create mode 100644 src/test/ui/traits/safety-fn-body.thir.stderr create mode 100644 src/test/ui/unsafe/issue-45087-unreachable-unsafe.mir.stderr delete mode 100644 src/test/ui/unsafe/issue-45087-unreachable-unsafe.stderr create mode 100644 src/test/ui/unsafe/issue-45087-unreachable-unsafe.thir.stderr create mode 100644 src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.mir.stderr delete mode 100644 src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.stderr create mode 100644 src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr create mode 100644 src/test/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr delete mode 100644 src/test/ui/unsafe/unsafe-fn-deref-ptr.stderr create mode 100644 src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr create mode 100644 src/test/ui/unsafe/unsafe-unstable-const-fn.mir.stderr delete mode 100644 src/test/ui/unsafe/unsafe-unstable-const-fn.stderr create mode 100644 src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 8c2c81c8628..c1866b9a437 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -153,6 +153,11 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => { self.requires_unsafe(expr.span, UseOfInlineAssembly); } + ExprKind::Deref { arg } => { + if self.thir[arg].ty.is_unsafe_ptr() { + self.requires_unsafe(expr.span, DerefOfRawPointer); + } + } _ => {} } @@ -203,7 +208,6 @@ enum UnsafeOpKind { UseOfMutableStatic, #[allow(dead_code)] // FIXME UseOfExternStatic, - #[allow(dead_code)] // FIXME DerefOfRawPointer, #[allow(dead_code)] // FIXME AssignToDroppingUnionField, diff --git a/src/test/ui/generator/issue-45729-unsafe-in-generator.mir.stderr b/src/test/ui/generator/issue-45729-unsafe-in-generator.mir.stderr new file mode 100644 index 00000000000..3afbea07931 --- /dev/null +++ b/src/test/ui/generator/issue-45729-unsafe-in-generator.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-45729-unsafe-in-generator.rs:8:9 + | +LL | *(1 as *mut u32) = 42; + | ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/generator/issue-45729-unsafe-in-generator.rs b/src/test/ui/generator/issue-45729-unsafe-in-generator.rs index 638a1994bb5..379c36d2ca3 100644 --- a/src/test/ui/generator/issue-45729-unsafe-in-generator.rs +++ b/src/test/ui/generator/issue-45729-unsafe-in-generator.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![feature(generators)] fn main() { diff --git a/src/test/ui/generator/issue-45729-unsafe-in-generator.stderr b/src/test/ui/generator/issue-45729-unsafe-in-generator.stderr deleted file mode 100644 index 0bd3dbf6863..00000000000 --- a/src/test/ui/generator/issue-45729-unsafe-in-generator.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/issue-45729-unsafe-in-generator.rs:5:9 - | -LL | *(1 as *mut u32) = 42; - | ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr b/src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr new file mode 100644 index 00000000000..a0905f98ca7 --- /dev/null +++ b/src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-45729-unsafe-in-generator.rs:8:9 + | +LL | *(1 as *mut u32) = 42; + | ^^^^^^^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-47412.mir.stderr b/src/test/ui/issues/issue-47412.mir.stderr new file mode 100644 index 00000000000..96e50ba6799 --- /dev/null +++ b/src/test/ui/issues/issue-47412.mir.stderr @@ -0,0 +1,19 @@ +error[E0133]: access to union field is unsafe and requires unsafe function or block + --> $DIR/issue-47412.rs:14:11 + | +LL | match u.void {} + | ^^^^^^ access to union field + | + = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior + +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-47412.rs:21:11 + | +LL | match *ptr {} + | ^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-47412.rs b/src/test/ui/issues/issue-47412.rs index 2d1ea72280b..d395285eee0 100644 --- a/src/test/ui/issues/issue-47412.rs +++ b/src/test/ui/issues/issue-47412.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #[derive(Copy, Clone)] enum Void {} @@ -9,7 +12,8 @@ fn union_field() { union Union { unit: (), void: Void } let u = Union { unit: () }; match u.void {} - //~^ ERROR access to union field is unsafe + //[mir]~^ ERROR access to union field is unsafe + // FIXME(thir-unsafeck): AccessToUnionField unimplemented } fn raw_ptr_deref() { diff --git a/src/test/ui/issues/issue-47412.stderr b/src/test/ui/issues/issue-47412.stderr deleted file mode 100644 index aebcbf07463..00000000000 --- a/src/test/ui/issues/issue-47412.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-47412.rs:11:11 - | -LL | match u.void {} - | ^^^^^^ access to union field - | - = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior - -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/issue-47412.rs:17:11 - | -LL | match *ptr {} - | ^^^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-47412.thir.stderr b/src/test/ui/issues/issue-47412.thir.stderr new file mode 100644 index 00000000000..2d6004b7911 --- /dev/null +++ b/src/test/ui/issues/issue-47412.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-47412.rs:21:11 + | +LL | match *ptr {} + | ^^^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/traits/safety-fn-body.mir.stderr b/src/test/ui/traits/safety-fn-body.mir.stderr new file mode 100644 index 00000000000..ea7b2048e83 --- /dev/null +++ b/src/test/ui/traits/safety-fn-body.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/safety-fn-body.rs:14:9 + | +LL | *self += 1; + | ^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/traits/safety-fn-body.rs b/src/test/ui/traits/safety-fn-body.rs index df527747305..2cc4fe1b344 100644 --- a/src/test/ui/traits/safety-fn-body.rs +++ b/src/test/ui/traits/safety-fn-body.rs @@ -1,6 +1,9 @@ // Check that an unsafe impl does not imply that unsafe actions are // legal in the methods. +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + unsafe trait UnsafeTrait : Sized { fn foo(self) { } } diff --git a/src/test/ui/traits/safety-fn-body.stderr b/src/test/ui/traits/safety-fn-body.stderr deleted file mode 100644 index 0aeb186828e..00000000000 --- a/src/test/ui/traits/safety-fn-body.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/safety-fn-body.rs:11:9 - | -LL | *self += 1; - | ^^^^^^^^^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/traits/safety-fn-body.thir.stderr b/src/test/ui/traits/safety-fn-body.thir.stderr new file mode 100644 index 00000000000..94a1a2a03cd --- /dev/null +++ b/src/test/ui/traits/safety-fn-body.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/safety-fn-body.rs:14:9 + | +LL | *self += 1; + | ^^^^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.mir.stderr b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.mir.stderr new file mode 100644 index 00000000000..33f762ccf63 --- /dev/null +++ b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-45087-unreachable-unsafe.rs:6:5 + | +LL | *(1 as *mut u32) = 42; + | ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs index 5edf7a47e2f..071cea8fbd7 100644 --- a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs +++ b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + fn main() { return; *(1 as *mut u32) = 42; diff --git a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.stderr b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.stderr deleted file mode 100644 index 88322c3a0a6..00000000000 --- a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/issue-45087-unreachable-unsafe.rs:3:5 - | -LL | *(1 as *mut u32) = 42; - | ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.thir.stderr b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.thir.stderr new file mode 100644 index 00000000000..b89401ce837 --- /dev/null +++ b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/issue-45087-unreachable-unsafe.rs:6:5 + | +LL | *(1 as *mut u32) = 42; + | ^^^^^^^^^^^^^^^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.mir.stderr b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.mir.stderr new file mode 100644 index 00000000000..fee645e4118 --- /dev/null +++ b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-fn-assign-deref-ptr.rs:5:5 + | +LL | *p = 0; + | ^^^^^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.rs b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.rs index 91264e790c8..a94e94375ae 100644 --- a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.rs +++ b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + fn f(p: *mut u8) { *p = 0; //~ ERROR dereference of raw pointer is unsafe return; diff --git a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.stderr b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.stderr deleted file mode 100644 index b2a30f81e05..00000000000 --- a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-fn-assign-deref-ptr.rs:2:5 - | -LL | *p = 0; - | ^^^^^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr new file mode 100644 index 00000000000..498d26d30ff --- /dev/null +++ b/src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-fn-assign-deref-ptr.rs:5:5 + | +LL | *p = 0; + | ^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr b/src/test/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr new file mode 100644 index 00000000000..a2614992445 --- /dev/null +++ b/src/test/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-fn-deref-ptr.rs:5:12 + | +LL | return *p; + | ^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-deref-ptr.rs b/src/test/ui/unsafe/unsafe-fn-deref-ptr.rs index 46445aa261d..dc989535bd6 100644 --- a/src/test/ui/unsafe/unsafe-fn-deref-ptr.rs +++ b/src/test/ui/unsafe/unsafe-fn-deref-ptr.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + fn f(p: *const u8) -> u8 { return *p; //~ ERROR dereference of raw pointer is unsafe } diff --git a/src/test/ui/unsafe/unsafe-fn-deref-ptr.stderr b/src/test/ui/unsafe/unsafe-fn-deref-ptr.stderr deleted file mode 100644 index 98cb7b876f8..00000000000 --- a/src/test/ui/unsafe/unsafe-fn-deref-ptr.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-fn-deref-ptr.rs:2:12 - | -LL | return *p; - | ^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr b/src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr new file mode 100644 index 00000000000..6897e4e691a --- /dev/null +++ b/src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-fn-deref-ptr.rs:5:12 + | +LL | return *p; + | ^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-unstable-const-fn.mir.stderr b/src/test/ui/unsafe/unsafe-unstable-const-fn.mir.stderr new file mode 100644 index 00000000000..99808495ea6 --- /dev/null +++ b/src/test/ui/unsafe/unsafe-unstable-const-fn.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-unstable-const-fn.rs:11:5 + | +LL | *a == b + | ^^ dereference of raw pointer + | + = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-unstable-const-fn.rs b/src/test/ui/unsafe/unsafe-unstable-const-fn.rs index c7120e05007..0476759ca6d 100644 --- a/src/test/ui/unsafe/unsafe-unstable-const-fn.rs +++ b/src/test/ui/unsafe/unsafe-unstable-const-fn.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![stable(feature = "foo", since = "1.33.0")] #![feature(staged_api)] #![feature(const_raw_ptr_deref)] diff --git a/src/test/ui/unsafe/unsafe-unstable-const-fn.stderr b/src/test/ui/unsafe/unsafe-unstable-const-fn.stderr deleted file mode 100644 index 410d8d3fb40..00000000000 --- a/src/test/ui/unsafe/unsafe-unstable-const-fn.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-unstable-const-fn.rs:8:5 - | -LL | *a == b - | ^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr b/src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr new file mode 100644 index 00000000000..49d6a96860b --- /dev/null +++ b/src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/unsafe-unstable-const-fn.rs:11:5 + | +LL | *a == b + | ^^ dereference of raw pointer + | + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. -- cgit 1.4.1-3-g733a5 From d7787bbaeffefc4c89910b1aac2cd370c2c27955 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 14 May 2021 23:52:34 +0200 Subject: Check for calls to functions with `#[target_feature]` in THIR unsafeck --- compiler/rustc_mir_build/src/check_unsafety.rs | 31 ++++++-- .../rfcs/rfc-2396-target_feature-11/check-pass.rs | 2 + .../closures-inherit-target_feature.rs | 2 + .../rfc-2396-target_feature-11/fn-ptr.mir.stderr | 18 +++++ .../ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs | 2 + .../rfcs/rfc-2396-target_feature-11/fn-ptr.stderr | 18 ----- .../rfc-2396-target_feature-11/fn-ptr.thir.stderr | 18 +++++ .../safe-calls.mir.stderr | 83 ++++++++++++++++++++++ .../rfcs/rfc-2396-target_feature-11/safe-calls.rs | 2 + .../rfc-2396-target_feature-11/safe-calls.stderr | 83 ---------------------- .../safe-calls.thir.stderr | 83 ++++++++++++++++++++++ 11 files changed, 237 insertions(+), 105 deletions(-) create mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr delete mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr create mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr create mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.mir.stderr delete mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr create mode 100644 src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.thir.stderr diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index c1866b9a437..3c2d770390d 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -7,6 +7,7 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint::builtin::{UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE}; use rustc_session::lint::Level; use rustc_span::def_id::{DefId, LocalDefId}; +use rustc_span::symbol::Symbol; use rustc_span::Span; struct UnsafetyVisitor<'a, 'tcx> { @@ -19,6 +20,9 @@ struct UnsafetyVisitor<'a, 'tcx> { /// `unsafe` block, and whether it has been used. safety_context: SafetyContext, body_unsafety: BodyUnsafety, + /// The `#[target_feature]` attributes of the body. Used for checking + /// calls to functions with `#[target_feature]` (RFC 2396). + body_target_features: &'tcx Vec, } impl<'tcx> UnsafetyVisitor<'_, 'tcx> { @@ -148,6 +152,18 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { ExprKind::Call { fun, ty: _, args: _, from_hir_call: _, fn_span: _ } => { if self.thir[fun].ty.fn_sig(self.tcx).unsafety() == hir::Unsafety::Unsafe { self.requires_unsafe(expr.span, CallToUnsafeFunction); + } else if let &ty::FnDef(func_did, _) = self.thir[fun].ty.kind() { + // If the called function has target features the calling function hasn't, + // the call requires `unsafe`. + if !self + .tcx + .codegen_fn_attrs(func_did) + .target_features + .iter() + .all(|feature| self.body_target_features.contains(feature)) + { + self.requires_unsafe(expr.span, CallToFunctionWith); + } } } ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => { @@ -217,7 +233,6 @@ enum UnsafeOpKind { MutationOfLayoutConstrainedField, #[allow(dead_code)] // FIXME BorrowOfLayoutConstrainedField, - #[allow(dead_code)] // FIXME CallToFunctionWith, } @@ -291,6 +306,7 @@ pub fn check_unsafety<'tcx>( tcx: TyCtxt<'tcx>, thir: &Thir<'tcx>, expr: ExprId, + def_id: LocalDefId, hir_id: hir::HirId, ) { let body_unsafety = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(BodyUnsafety::Safe, |fn_sig| { @@ -300,10 +316,17 @@ pub fn check_unsafety<'tcx>( BodyUnsafety::Safe } }); + let body_target_features = &tcx.codegen_fn_attrs(def_id).target_features; let safety_context = if body_unsafety.is_unsafe() { SafetyContext::UnsafeFn } else { SafetyContext::Safe }; - let mut visitor = - UnsafetyVisitor { tcx, thir, safety_context, hir_context: hir_id, body_unsafety }; + let mut visitor = UnsafetyVisitor { + tcx, + thir, + safety_context, + hir_context: hir_id, + body_unsafety, + body_target_features, + }; visitor.visit_expr(&thir[expr]); } @@ -315,7 +338,7 @@ crate fn thir_check_unsafety_inner<'tcx>( let body_id = tcx.hir().body_owned_by(hir_id); let body = tcx.hir().body(body_id); let (thir, expr) = cx::build_thir(tcx, def, &body.value); - check_unsafety(tcx, &thir, expr, hir_id); + check_unsafety(tcx, &thir, expr, def.did, hir_id); } crate fn thir_check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) { diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs b/src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs index 58a2c271ecf..e0842bfa4cd 100644 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs @@ -8,6 +8,8 @@ // check-pass // only-x86_64 +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck #![feature(target_feature_11)] diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs b/src/test/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs index af35bc2014b..a59d7c2d784 100644 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs @@ -1,6 +1,8 @@ // Tests #73631: closures inherit `#[target_feature]` annotations // check-pass +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck // only-x86_64 #![feature(target_feature_11)] diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr new file mode 100644 index 00000000000..cf5815df56e --- /dev/null +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.mir.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/fn-ptr.rs:11:21 + | +LL | #[target_feature(enable = "sse2")] + | ---------------------------------- `#[target_feature]` added here +... +LL | let foo: fn() = foo; + | ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers + | | + | expected due to this + | + = note: expected fn pointer `fn()` + found fn item `fn() {foo}` + = note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs index 3ecea5c5313..c95d4a08e48 100644 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs @@ -1,3 +1,5 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck // only-x86_64 #![feature(target_feature_11)] diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr deleted file mode 100644 index 06cfdde3fb9..00000000000 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/fn-ptr.rs:9:21 - | -LL | #[target_feature(enable = "sse2")] - | ---------------------------------- `#[target_feature]` added here -... -LL | let foo: fn() = foo; - | ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers - | | - | expected due to this - | - = note: expected fn pointer `fn()` - found fn item `fn() {foo}` - = note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr new file mode 100644 index 00000000000..cf5815df56e --- /dev/null +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/fn-ptr.rs:11:21 + | +LL | #[target_feature(enable = "sse2")] + | ---------------------------------- `#[target_feature]` added here +... +LL | let foo: fn() = foo; + | ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers + | | + | expected due to this + | + = note: expected fn pointer `fn()` + found fn item `fn() {foo}` + = note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.mir.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.mir.stderr new file mode 100644 index 00000000000..79273a1dcbf --- /dev/null +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.mir.stderr @@ -0,0 +1,83 @@ +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:23:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:24:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:25:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:30:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:31:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:36:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:37:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:38:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:44:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:47:18 + | +LL | const name: () = sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs index 8da3affc447..de0b89f46ba 100644 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs @@ -1,3 +1,5 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck // only-x86_64 #![feature(target_feature_11)] diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr deleted file mode 100644 index b9f748640b5..00000000000 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr +++ /dev/null @@ -1,83 +0,0 @@ -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:21:5 - | -LL | sse2(); - | ^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:22:5 - | -LL | avx_bmi2(); - | ^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:23:5 - | -LL | Quux.avx_bmi2(); - | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:28:5 - | -LL | avx_bmi2(); - | ^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:29:5 - | -LL | Quux.avx_bmi2(); - | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:34:5 - | -LL | sse2(); - | ^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:35:5 - | -LL | avx_bmi2(); - | ^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:36:5 - | -LL | Quux.avx_bmi2(); - | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:42:5 - | -LL | sse2(); - | ^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block - --> $DIR/safe-calls.rs:45:18 - | -LL | const name: () = sse2(); - | ^^^^^^ call to function with `#[target_feature]` - | - = note: can only be called if the required target features are available - -error: aborting due to 10 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.thir.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.thir.stderr new file mode 100644 index 00000000000..79273a1dcbf --- /dev/null +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.thir.stderr @@ -0,0 +1,83 @@ +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:23:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:24:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:25:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:30:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:31:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:36:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:37:5 + | +LL | avx_bmi2(); + | ^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:38:5 + | +LL | Quux.avx_bmi2(); + | ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:44:5 + | +LL | sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block + --> $DIR/safe-calls.rs:47:18 + | +LL | const name: () = sse2(); + | ^^^^^^ call to function with `#[target_feature]` + | + = note: can only be called if the required target features are available + +error: aborting due to 10 previous errors + +For more information about this error, try `rustc --explain E0133`. -- cgit 1.4.1-3-g733a5 From b8909fc3c42effb78603c6e8c9d2920b098e75af Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 May 2021 12:45:25 +0200 Subject: Reset "focusedByTab" field when doing another search --- src/librustdoc/html/static/search.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js index 01cfffc5429..c95136d40d3 100644 --- a/src/librustdoc/html/static/search.js +++ b/src/librustdoc/html/static/search.js @@ -885,12 +885,12 @@ window.initSearch = function(rawSearchIndex) { focusSearchResult(); } - // focus the first search result on the active tab, or the result that + // Focus the first search result on the active tab, or the result that // was focused last time this tab was active. function focusSearchResult() { var target = searchState.focusedByTab[searchState.currentTab] || - document.querySelectorAll(".search-results.active a").item(0) || - document.querySelectorAll("#titles > button").item(searchState.currentTab); + document.querySelectorAll(".search-results.active a").item(0) || + document.querySelectorAll("#titles > button").item(searchState.currentTab); if (target) { target.focus(); } @@ -1076,6 +1076,8 @@ window.initSearch = function(rawSearchIndex) { ret_others[0] + ret_in_args[0] + ret_returned[0] + ""; search.innerHTML = output; + // Reset focused elements. + searchState.focusedByTab = [null, null, null]; searchState.showResults(search); var elems = document.getElementById("titles").childNodes; elems[0].onclick = function() { printTab(0); }; @@ -1365,7 +1367,6 @@ window.initSearch = function(rawSearchIndex) { if (e.which === 38) { // up var previous = document.activeElement.previousElementSibling; if (previous) { - console.log("previousElementSibling", previous); previous.focus(); } else { searchState.focus(); -- cgit 1.4.1-3-g733a5 From aee054d05d8b795d35c0b448a4b731b6507aa459 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 21 May 2021 15:50:55 +0200 Subject: Remove dead toggle JS code --- src/librustdoc/html/static/main.js | 158 ------------------------------------- 1 file changed, 158 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1ed94ec109c..1e28056bb68 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -764,138 +764,6 @@ function hideThemeButtonState() { innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed); } - function collapseDocs(toggle, mode) { - if (!toggle || !toggle.parentNode) { - return; - } - - function adjustToggle(arg) { - return function(e) { - if (hasClass(e, "toggle-label")) { - if (arg) { - e.style.display = "inline-block"; - } else { - e.style.display = "none"; - } - } - if (hasClass(e, "inner")) { - e.innerHTML = labelForToggleButton(arg); - } - }; - } - - function implHider(addOrRemove, fullHide) { - return function(n) { - var shouldHide = - fullHide || - hasClass(n, "method") || - hasClass(n, "associatedconstant"); - if (shouldHide || hasClass(n, "type")) { - if (shouldHide) { - if (addOrRemove) { - addClass(n, "hidden-by-impl-hider"); - } else { - removeClass(n, "hidden-by-impl-hider"); - } - } - var ns = n.nextElementSibling; - while (ns && (hasClass(ns, "docblock") || hasClass(ns, "item-info"))) { - if (addOrRemove) { - addClass(ns, "hidden-by-impl-hider"); - } else { - removeClass(ns, "hidden-by-impl-hider"); - } - ns = ns.nextElementSibling; - } - } - }; - } - - var relatedDoc; - var action = mode; - if (!hasClass(toggle.parentNode, "impl")) { - relatedDoc = toggle.parentNode.nextElementSibling; - if (hasClass(relatedDoc, "item-info")) { - relatedDoc = relatedDoc.nextElementSibling; - } - if (hasClass(relatedDoc, "docblock")) { - if (mode === "toggle") { - if (hasClass(relatedDoc, "hidden-by-usual-hider")) { - action = "show"; - } else { - action = "hide"; - } - } - if (action === "hide") { - addClass(relatedDoc, "hidden-by-usual-hider"); - onEachLazy(toggle.childNodes, adjustToggle(true)); - addClass(toggle.parentNode, "collapsed"); - } else if (action === "show") { - removeClass(relatedDoc, "hidden-by-usual-hider"); - removeClass(toggle.parentNode, "collapsed"); - onEachLazy(toggle.childNodes, adjustToggle(false)); - } - } - } else { - // we are collapsing the impl block(s). - - var parentElem = toggle.parentNode; - relatedDoc = parentElem; - var docblock = relatedDoc.nextElementSibling; - - while (!hasClass(relatedDoc, "impl-items")) { - relatedDoc = relatedDoc.nextElementSibling; - } - - if (!relatedDoc && !hasClass(docblock, "docblock")) { - return; - } - - // Hide all functions, but not associated types/consts. - - if (mode === "toggle") { - if (hasClass(relatedDoc, "fns-now-collapsed") || - hasClass(docblock, "hidden-by-impl-hider")) { - action = "show"; - } else { - action = "hide"; - } - } - - var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main"; - if (action === "show") { - removeClass(relatedDoc, "fns-now-collapsed"); - // Stability/deprecation/portability information is never hidden. - if (!hasClass(docblock, "item-info")) { - removeClass(docblock, "hidden-by-usual-hider"); - } - onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule)); - onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule)); - } else if (action === "hide") { - addClass(relatedDoc, "fns-now-collapsed"); - // Stability/deprecation/portability information should be shown even when detailed - // info is hidden. - if (!hasClass(docblock, "item-info")) { - addClass(docblock, "hidden-by-usual-hider"); - } - onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule)); - onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule)); - } - } - } - - function collapseNonInherent(e) { - // inherent impl ids are like "impl" or impl-'. - // they will never be hidden by default. - var n = e.parentElement; - if (n.id.match(/^impl(?:-\d+)?$/) === null) { - // Automatically minimize all non-inherent impls - if (hasClass(n, "impl")) { - collapseDocs(e, "hide"); - } - } - } - function insertAfter(newNode, referenceNode) { referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } @@ -910,20 +778,6 @@ function hideThemeButtonState() { var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false"; var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false"; - var impl_list = document.getElementById("trait-implementations-list"); - if (impl_list !== null) { - onEachLazy(impl_list.getElementsByClassName("rustdoc-toggle"), function(e) { - collapseNonInherent(e); - }); - } - - var blanket_list = document.getElementById("blanket-implementations-list"); - if (blanket_list !== null) { - onEachLazy(blanket_list.getElementsByClassName("rustdoc-toggle"), function(e) { - collapseNonInherent(e); - }); - } - onEachLazy(document.getElementsByTagName("details"), function (e) { var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle"); var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle"); @@ -936,18 +790,6 @@ function hideThemeButtonState() { }); - var currentType = document.getElementsByClassName("type-decl")[0]; - if (currentType) { - currentType = currentType.getElementsByClassName("rust")[0]; - if (currentType) { - onEachLazy(currentType.classList, function(item) { - if (item !== "main") { - return true; - } - }); - } - } - var pageId = getPageId(); if (pageId !== null) { expandSection(pageId); -- cgit 1.4.1-3-g733a5 From b3218d3d5d4aeed5f08bf761bbeabdbadb922f02 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 21 May 2021 10:48:36 -0400 Subject: facepalm: operator precedence fail on my part. This bug was only visible on mac. Also, print_step_rusage is a relatively new internal feature, that is not heavily used, and has no tests. All of these factors contributed to how this went uncaught this long. Thanks to Josh Triplett for pointing it out! --- src/bootstrap/bin/rustc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index d462dc4d116..4b98abfb308 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -305,7 +305,7 @@ fn format_rusage_data(_child: Child) -> Option { }; // Mac OS X reports the maxrss in bytes, not kb. let divisor = if env::consts::OS == "macos" { 1024 } else { 1 }; - let maxrss = rusage.ru_maxrss + (divisor - 1) / divisor; + let maxrss = (rusage.ru_maxrss + (divisor - 1)) / divisor; let mut init_str = format!( "user: {USER_SEC}.{USER_USEC:03} \ -- cgit 1.4.1-3-g733a5 From 592fecbafb9c2fe7f793bdb0529fcb25032bda6e Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 15 May 2021 15:26:28 +0200 Subject: Check for initialization of layout-restricted types --- compiler/rustc_mir_build/src/check_unsafety.rs | 14 +++++++++++++- src/test/ui/unsafe/ranged_ints.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/ranged_ints.rs | 3 +++ src/test/ui/unsafe/ranged_ints.stderr | 11 ----------- src/test/ui/unsafe/ranged_ints.thir.stderr | 11 +++++++++++ src/test/ui/unsafe/ranged_ints_const.mir.stderr | 11 +++++++++++ src/test/ui/unsafe/ranged_ints_const.rs | 3 +++ src/test/ui/unsafe/ranged_ints_const.stderr | 11 ----------- src/test/ui/unsafe/ranged_ints_const.thir.stderr | 11 +++++++++++ src/test/ui/unsafe/ranged_ints_macro.rs | 3 +++ 10 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/unsafe/ranged_ints.mir.stderr delete mode 100644 src/test/ui/unsafe/ranged_ints.stderr create mode 100644 src/test/ui/unsafe/ranged_ints.thir.stderr create mode 100644 src/test/ui/unsafe/ranged_ints_const.mir.stderr delete mode 100644 src/test/ui/unsafe/ranged_ints_const.stderr create mode 100644 src/test/ui/unsafe/ranged_ints_const.thir.stderr diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 3c2d770390d..2eae6ec9e3b 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -10,6 +10,8 @@ use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::symbol::Symbol; use rustc_span::Span; +use std::ops::Bound; + struct UnsafetyVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, thir: &'a Thir<'tcx>, @@ -174,6 +176,17 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { self.requires_unsafe(expr.span, DerefOfRawPointer); } } + ExprKind::Adt { + adt_def, + variant_index: _, + substs: _, + user_ty: _, + fields: _, + base: _, + } => match self.tcx.layout_scalar_valid_range(adt_def.did) { + (Bound::Unbounded, Bound::Unbounded) => {} + _ => self.requires_unsafe(expr.span, InitializingTypeWith), + }, _ => {} } @@ -216,7 +229,6 @@ impl BodyUnsafety { enum UnsafeOpKind { CallToUnsafeFunction, UseOfInlineAssembly, - #[allow(dead_code)] // FIXME InitializingTypeWith, #[allow(dead_code)] // FIXME CastOfPointerToInt, diff --git a/src/test/ui/unsafe/ranged_ints.mir.stderr b/src/test/ui/unsafe/ranged_ints.mir.stderr new file mode 100644 index 00000000000..f9ef7834e1e --- /dev/null +++ b/src/test/ui/unsafe/ranged_ints.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block + --> $DIR/ranged_ints.rs:10:14 + | +LL | let _x = NonZero(0); + | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr + | + = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints.rs b/src/test/ui/unsafe/ranged_ints.rs index 0fa2da917e9..05efe87ba6e 100644 --- a/src/test/ui/unsafe/ranged_ints.rs +++ b/src/test/ui/unsafe/ranged_ints.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![feature(rustc_attrs)] #[rustc_layout_scalar_valid_range_start(1)] diff --git a/src/test/ui/unsafe/ranged_ints.stderr b/src/test/ui/unsafe/ranged_ints.stderr deleted file mode 100644 index 4e43df495c0..00000000000 --- a/src/test/ui/unsafe/ranged_ints.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints.rs:7:14 - | -LL | let _x = NonZero(0); - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints.thir.stderr b/src/test/ui/unsafe/ranged_ints.thir.stderr new file mode 100644 index 00000000000..f9ef7834e1e --- /dev/null +++ b/src/test/ui/unsafe/ranged_ints.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block + --> $DIR/ranged_ints.rs:10:14 + | +LL | let _x = NonZero(0); + | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr + | + = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints_const.mir.stderr b/src/test/ui/unsafe/ranged_ints_const.mir.stderr new file mode 100644 index 00000000000..33d134c7ce5 --- /dev/null +++ b/src/test/ui/unsafe/ranged_ints_const.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block + --> $DIR/ranged_ints_const.rs:11:34 + | +LL | const fn foo() -> NonZero { NonZero(0) } + | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr + | + = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints_const.rs b/src/test/ui/unsafe/ranged_ints_const.rs index 8477772867e..472b0968150 100644 --- a/src/test/ui/unsafe/ranged_ints_const.rs +++ b/src/test/ui/unsafe/ranged_ints_const.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![feature(rustc_attrs)] #[rustc_layout_scalar_valid_range_start(1)] diff --git a/src/test/ui/unsafe/ranged_ints_const.stderr b/src/test/ui/unsafe/ranged_ints_const.stderr deleted file mode 100644 index 584ad40a92b..00000000000 --- a/src/test/ui/unsafe/ranged_ints_const.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block - --> $DIR/ranged_ints_const.rs:8:34 - | -LL | const fn foo() -> NonZero { NonZero(0) } - | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr - | - = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints_const.thir.stderr b/src/test/ui/unsafe/ranged_ints_const.thir.stderr new file mode 100644 index 00000000000..33d134c7ce5 --- /dev/null +++ b/src/test/ui/unsafe/ranged_ints_const.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block + --> $DIR/ranged_ints_const.rs:11:34 + | +LL | const fn foo() -> NonZero { NonZero(0) } + | ^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr + | + = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/unsafe/ranged_ints_macro.rs b/src/test/ui/unsafe/ranged_ints_macro.rs index 9192ecfe196..8293d029951 100644 --- a/src/test/ui/unsafe/ranged_ints_macro.rs +++ b/src/test/ui/unsafe/ranged_ints_macro.rs @@ -1,4 +1,7 @@ // build-pass +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![feature(rustc_attrs)] macro_rules! apply { -- cgit 1.4.1-3-g733a5 From 6b327aaa08aea817e51640585b4d63cf4017965f Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 15 May 2021 16:29:57 +0200 Subject: Check for ptr-to-int casts in const functions in THIR unsafeck --- compiler/rustc_mir_build/src/check_unsafety.rs | 18 ++++++++++++- src/test/ui/cast/cast-ptr-to-int-const.mir.stderr | 19 ++++++++++++++ src/test/ui/cast/cast-ptr-to-int-const.rs | 20 +++++---------- src/test/ui/cast/cast-ptr-to-int-const.thir.stderr | 19 ++++++++++++++ .../feature-gate-const_raw_ptr_to_usize_cast.rs | 13 ++++++++++ ...feature-gate-const_raw_ptr_to_usize_cast.stderr | 30 ++++++++++++++++++++++ 6 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 src/test/ui/cast/cast-ptr-to-int-const.mir.stderr create mode 100644 src/test/ui/cast/cast-ptr-to-int-const.thir.stderr create mode 100644 src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.rs create mode 100644 src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.stderr diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 2eae6ec9e3b..66b30679ccb 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -25,6 +25,7 @@ struct UnsafetyVisitor<'a, 'tcx> { /// The `#[target_feature]` attributes of the body. Used for checking /// calls to functions with `#[target_feature]` (RFC 2396). body_target_features: &'tcx Vec, + is_const: bool, } impl<'tcx> UnsafetyVisitor<'_, 'tcx> { @@ -187,6 +188,16 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { (Bound::Unbounded, Bound::Unbounded) => {} _ => self.requires_unsafe(expr.span, InitializingTypeWith), }, + ExprKind::Cast { source } => { + let source = &self.thir[source]; + if self.tcx.features().const_raw_ptr_to_usize_cast + && self.is_const + && (source.ty.is_unsafe_ptr() || source.ty.is_fn_ptr()) + && expr.ty.is_integral() + { + self.requires_unsafe(expr.span, CastOfPointerToInt); + } + } _ => {} } @@ -230,7 +241,6 @@ enum UnsafeOpKind { CallToUnsafeFunction, UseOfInlineAssembly, InitializingTypeWith, - #[allow(dead_code)] // FIXME CastOfPointerToInt, #[allow(dead_code)] // FIXME UseOfMutableStatic, @@ -331,6 +341,11 @@ pub fn check_unsafety<'tcx>( let body_target_features = &tcx.codegen_fn_attrs(def_id).target_features; let safety_context = if body_unsafety.is_unsafe() { SafetyContext::UnsafeFn } else { SafetyContext::Safe }; + let is_const = match tcx.hir().body_owner_kind(hir_id) { + hir::BodyOwnerKind::Closure => false, + hir::BodyOwnerKind::Fn => tcx.is_const_fn_raw(def_id.to_def_id()), + hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => true, + }; let mut visitor = UnsafetyVisitor { tcx, thir, @@ -338,6 +353,7 @@ pub fn check_unsafety<'tcx>( hir_context: hir_id, body_unsafety, body_target_features, + is_const, }; visitor.visit_expr(&thir[expr]); } diff --git a/src/test/ui/cast/cast-ptr-to-int-const.mir.stderr b/src/test/ui/cast/cast-ptr-to-int-const.mir.stderr new file mode 100644 index 00000000000..dcc9a243f0f --- /dev/null +++ b/src/test/ui/cast/cast-ptr-to-int-const.mir.stderr @@ -0,0 +1,19 @@ +error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block + --> $DIR/cast-ptr-to-int-const.rs:10:9 + | +LL | &Y as *const u32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int + | + = note: casting pointers to integers in constants + +error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block + --> $DIR/cast-ptr-to-int-const.rs:17:5 + | +LL | &0 as *const i32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int + | + = note: casting pointers to integers in constants + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/cast/cast-ptr-to-int-const.rs b/src/test/ui/cast/cast-ptr-to-int-const.rs index aed099a53ea..01ea627679d 100644 --- a/src/test/ui/cast/cast-ptr-to-int-const.rs +++ b/src/test/ui/cast/cast-ptr-to-int-const.rs @@ -1,25 +1,19 @@ -// gate-test-const_raw_ptr_to_usize_cast -// revisions: with_feature without_feature +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck -#![cfg_attr(with_feature, feature(const_raw_ptr_to_usize_cast))] +#![feature(const_raw_ptr_to_usize_cast)] fn main() { - const X: usize = unsafe { - main as usize //[without_feature]~ ERROR casting pointers to integers in constants is unstable - }; const Y: u32 = 0; - const Z: usize = unsafe { - &Y as *const u32 as usize //[without_feature]~ ERROR is unstable - }; // Cast in `const` without `unsafe` block const SAFE: usize = { - &Y as *const u32 as usize //[without_feature]~ ERROR is unstable - //[with_feature]~^ ERROR cast of pointer to int is unsafe and requires unsafe + &Y as *const u32 as usize + //~^ ERROR cast of pointer to int is unsafe and requires unsafe }; } // Cast in `const fn` without `unsafe` block const fn test() -> usize { - &0 as *const i32 as usize //[without_feature]~ ERROR is unstable - //[with_feature]~^ ERROR cast of pointer to int is unsafe and requires unsafe + &0 as *const i32 as usize + //~^ ERROR cast of pointer to int is unsafe and requires unsafe } diff --git a/src/test/ui/cast/cast-ptr-to-int-const.thir.stderr b/src/test/ui/cast/cast-ptr-to-int-const.thir.stderr new file mode 100644 index 00000000000..dcc9a243f0f --- /dev/null +++ b/src/test/ui/cast/cast-ptr-to-int-const.thir.stderr @@ -0,0 +1,19 @@ +error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block + --> $DIR/cast-ptr-to-int-const.rs:10:9 + | +LL | &Y as *const u32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int + | + = note: casting pointers to integers in constants + +error[E0133]: cast of pointer to int is unsafe and requires unsafe function or block + --> $DIR/cast-ptr-to-int-const.rs:17:5 + | +LL | &0 as *const i32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cast of pointer to int + | + = note: casting pointers to integers in constants + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.rs b/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.rs new file mode 100644 index 00000000000..03e99eb7527 --- /dev/null +++ b/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.rs @@ -0,0 +1,13 @@ +fn main() { + const X: usize = unsafe { + main as usize //~ ERROR casting pointers to integers in constants is unstable + }; + const Y: u32 = 0; + const Z: usize = unsafe { + &Y as *const u32 as usize //~ ERROR is unstable + }; +} + +const fn test() -> usize { + &0 as *const i32 as usize //~ ERROR is unstable +} diff --git a/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.stderr b/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.stderr new file mode 100644 index 00000000000..4a0b424e181 --- /dev/null +++ b/src/test/ui/cast/feature-gate-const_raw_ptr_to_usize_cast.stderr @@ -0,0 +1,30 @@ +error[E0658]: casting pointers to integers in constants is unstable + --> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:3:9 + | +LL | main as usize + | ^^^^^^^^^^^^^ + | + = note: see issue #51910 for more information + = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable + +error[E0658]: casting pointers to integers in constants is unstable + --> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:7:9 + | +LL | &Y as *const u32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #51910 for more information + = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable + +error[E0658]: casting pointers to integers in constant functions is unstable + --> $DIR/feature-gate-const_raw_ptr_to_usize_cast.rs:12:5 + | +LL | &0 as *const i32 as usize + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #51910 for more information + = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. -- cgit 1.4.1-3-g733a5 From 0e1afc4501eae89862a50ab24961a8d12ece0a37 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Mon, 17 May 2021 00:29:54 +0200 Subject: Check for use of mutable/extern statics in THIR unsafeck --- compiler/rustc_mir_build/src/check_unsafety.rs | 16 ++++++---- src/test/ui/intrinsics/issue-28575.mir.stderr | 11 +++++++ src/test/ui/intrinsics/issue-28575.rs | 3 ++ src/test/ui/intrinsics/issue-28575.stderr | 11 ------- src/test/ui/intrinsics/issue-28575.thir.stderr | 11 +++++++ src/test/ui/issues/issue-14227.mir.stderr | 11 +++++++ src/test/ui/issues/issue-14227.rs | 3 ++ src/test/ui/issues/issue-14227.stderr | 11 ------- src/test/ui/issues/issue-14227.thir.stderr | 11 +++++++ src/test/ui/issues/issue-16538.mir.stderr | 27 +++++++++++++++++ src/test/ui/issues/issue-16538.rs | 3 ++ src/test/ui/issues/issue-16538.stderr | 27 ----------------- src/test/ui/issues/issue-16538.thir.stderr | 27 +++++++++++++++++ src/test/ui/issues/issue-28324.mir.stderr | 11 +++++++ src/test/ui/issues/issue-28324.rs | 3 ++ src/test/ui/issues/issue-28324.stderr | 11 ------- src/test/ui/issues/issue-28324.thir.stderr | 11 +++++++ src/test/ui/safe-extern-statics-mut.mir.stderr | 35 ++++++++++++++++++++++ src/test/ui/safe-extern-statics-mut.rs | 2 ++ src/test/ui/safe-extern-statics-mut.stderr | 35 ---------------------- src/test/ui/safe-extern-statics-mut.thir.stderr | 35 ++++++++++++++++++++++ src/test/ui/safe-extern-statics.mir.stderr | 35 ++++++++++++++++++++++ src/test/ui/safe-extern-statics.rs | 2 ++ src/test/ui/safe-extern-statics.stderr | 35 ---------------------- src/test/ui/safe-extern-statics.thir.stderr | 35 ++++++++++++++++++++++ .../static-mut-foreign-requires-unsafe.mir.stderr | 27 +++++++++++++++++ .../static/static-mut-foreign-requires-unsafe.rs | 3 ++ .../static-mut-foreign-requires-unsafe.stderr | 27 ----------------- .../static-mut-foreign-requires-unsafe.thir.stderr | 27 +++++++++++++++++ .../static/static-mut-requires-unsafe.mir.stderr | 27 +++++++++++++++++ src/test/ui/static/static-mut-requires-unsafe.rs | 3 ++ .../ui/static/static-mut-requires-unsafe.stderr | 27 ----------------- .../static/static-mut-requires-unsafe.thir.stderr | 27 +++++++++++++++++ src/tools/tidy/src/ui_tests.rs | 4 +-- 34 files changed, 402 insertions(+), 192 deletions(-) create mode 100644 src/test/ui/intrinsics/issue-28575.mir.stderr delete mode 100644 src/test/ui/intrinsics/issue-28575.stderr create mode 100644 src/test/ui/intrinsics/issue-28575.thir.stderr create mode 100644 src/test/ui/issues/issue-14227.mir.stderr delete mode 100644 src/test/ui/issues/issue-14227.stderr create mode 100644 src/test/ui/issues/issue-14227.thir.stderr create mode 100644 src/test/ui/issues/issue-16538.mir.stderr delete mode 100644 src/test/ui/issues/issue-16538.stderr create mode 100644 src/test/ui/issues/issue-16538.thir.stderr create mode 100644 src/test/ui/issues/issue-28324.mir.stderr delete mode 100644 src/test/ui/issues/issue-28324.stderr create mode 100644 src/test/ui/issues/issue-28324.thir.stderr create mode 100644 src/test/ui/safe-extern-statics-mut.mir.stderr delete mode 100644 src/test/ui/safe-extern-statics-mut.stderr create mode 100644 src/test/ui/safe-extern-statics-mut.thir.stderr create mode 100644 src/test/ui/safe-extern-statics.mir.stderr delete mode 100644 src/test/ui/safe-extern-statics.stderr create mode 100644 src/test/ui/safe-extern-statics.thir.stderr create mode 100644 src/test/ui/static/static-mut-foreign-requires-unsafe.mir.stderr delete mode 100644 src/test/ui/static/static-mut-foreign-requires-unsafe.stderr create mode 100644 src/test/ui/static/static-mut-foreign-requires-unsafe.thir.stderr create mode 100644 src/test/ui/static/static-mut-requires-unsafe.mir.stderr delete mode 100644 src/test/ui/static/static-mut-requires-unsafe.stderr create mode 100644 src/test/ui/static/static-mut-requires-unsafe.thir.stderr diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 66b30679ccb..aa8193dab5d 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -169,14 +169,20 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } } } - ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => { - self.requires_unsafe(expr.span, UseOfInlineAssembly); - } ExprKind::Deref { arg } => { - if self.thir[arg].ty.is_unsafe_ptr() { + if let ExprKind::StaticRef { def_id, .. } = self.thir[arg].kind { + if self.tcx.is_mutable_static(def_id) { + self.requires_unsafe(expr.span, UseOfMutableStatic); + } else if self.tcx.is_foreign_item(def_id) { + self.requires_unsafe(expr.span, UseOfExternStatic); + } + } else if self.thir[arg].ty.is_unsafe_ptr() { self.requires_unsafe(expr.span, DerefOfRawPointer); } } + ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => { + self.requires_unsafe(expr.span, UseOfInlineAssembly); + } ExprKind::Adt { adt_def, variant_index: _, @@ -242,9 +248,7 @@ enum UnsafeOpKind { UseOfInlineAssembly, InitializingTypeWith, CastOfPointerToInt, - #[allow(dead_code)] // FIXME UseOfMutableStatic, - #[allow(dead_code)] // FIXME UseOfExternStatic, DerefOfRawPointer, #[allow(dead_code)] // FIXME diff --git a/src/test/ui/intrinsics/issue-28575.mir.stderr b/src/test/ui/intrinsics/issue-28575.mir.stderr new file mode 100644 index 00000000000..c42498390c7 --- /dev/null +++ b/src/test/ui/intrinsics/issue-28575.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-28575.rs:11:5 + | +LL | FOO() + | ^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/intrinsics/issue-28575.rs b/src/test/ui/intrinsics/issue-28575.rs index 141136d25b2..410f664f89d 100644 --- a/src/test/ui/intrinsics/issue-28575.rs +++ b/src/test/ui/intrinsics/issue-28575.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + #![feature(intrinsics)] extern "C" { diff --git a/src/test/ui/intrinsics/issue-28575.stderr b/src/test/ui/intrinsics/issue-28575.stderr deleted file mode 100644 index 66369decf42..00000000000 --- a/src/test/ui/intrinsics/issue-28575.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-28575.rs:8:5 - | -LL | FOO() - | ^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/intrinsics/issue-28575.thir.stderr b/src/test/ui/intrinsics/issue-28575.thir.stderr new file mode 100644 index 00000000000..c42498390c7 --- /dev/null +++ b/src/test/ui/intrinsics/issue-28575.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-28575.rs:11:5 + | +LL | FOO() + | ^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-14227.mir.stderr b/src/test/ui/issues/issue-14227.mir.stderr new file mode 100644 index 00000000000..8e7a2514dd6 --- /dev/null +++ b/src/test/ui/issues/issue-14227.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-14227.rs:7:21 + | +LL | static CRASH: u32 = symbol; + | ^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-14227.rs b/src/test/ui/issues/issue-14227.rs index a1fde14600a..5f866ec9061 100644 --- a/src/test/ui/issues/issue-14227.rs +++ b/src/test/ui/issues/issue-14227.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + extern "C" { pub static symbol: u32; } diff --git a/src/test/ui/issues/issue-14227.stderr b/src/test/ui/issues/issue-14227.stderr deleted file mode 100644 index f9cdbe452df..00000000000 --- a/src/test/ui/issues/issue-14227.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-14227.rs:4:21 - | -LL | static CRASH: u32 = symbol; - | ^^^^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-14227.thir.stderr b/src/test/ui/issues/issue-14227.thir.stderr new file mode 100644 index 00000000000..8e7a2514dd6 --- /dev/null +++ b/src/test/ui/issues/issue-14227.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-14227.rs:7:21 + | +LL | static CRASH: u32 = symbol; + | ^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-16538.mir.stderr b/src/test/ui/issues/issue-16538.mir.stderr new file mode 100644 index 00000000000..d7e8c08bb01 --- /dev/null +++ b/src/test/ui/issues/issue-16538.mir.stderr @@ -0,0 +1,27 @@ +error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-16538.rs:14:27 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: `*const usize` cannot be shared between threads safely + --> $DIR/issue-16538.rs:14:1 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `*const usize` + = note: shared static variables must have a type that implements `Sync` + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:14:34 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0015, E0133, E0277. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-16538.rs b/src/test/ui/issues/issue-16538.rs index 7d6eefa5b1e..1e8ecf015c8 100644 --- a/src/test/ui/issues/issue-16538.rs +++ b/src/test/ui/issues/issue-16538.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + mod Y { pub type X = usize; extern "C" { diff --git a/src/test/ui/issues/issue-16538.stderr b/src/test/ui/issues/issue-16538.stderr deleted file mode 100644 index 81a91db3711..00000000000 --- a/src/test/ui/issues/issue-16538.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants - --> $DIR/issue-16538.rs:11:27 - | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: `*const usize` cannot be shared between threads safely - --> $DIR/issue-16538.rs:11:1 - | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely - | - = help: the trait `Sync` is not implemented for `*const usize` - = note: shared static variables must have a type that implements `Sync` - -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-16538.rs:11:34 - | -LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); - | ^^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0015, E0133, E0277. -For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-16538.thir.stderr b/src/test/ui/issues/issue-16538.thir.stderr new file mode 100644 index 00000000000..d7e8c08bb01 --- /dev/null +++ b/src/test/ui/issues/issue-16538.thir.stderr @@ -0,0 +1,27 @@ +error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-16538.rs:14:27 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: `*const usize` cannot be shared between threads safely + --> $DIR/issue-16538.rs:14:1 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `*const usize` + = note: shared static variables must have a type that implements `Sync` + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-16538.rs:14:34 + | +LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); + | ^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0015, E0133, E0277. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/issues/issue-28324.mir.stderr b/src/test/ui/issues/issue-28324.mir.stderr new file mode 100644 index 00000000000..aff8bf7927d --- /dev/null +++ b/src/test/ui/issues/issue-28324.mir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-28324.rs:8:24 + | +LL | pub static BAZ: u32 = *&error_message_count; + | ^^^^^^^^^^^^^^^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-28324.rs b/src/test/ui/issues/issue-28324.rs index f74726e8166..fbe83e325ed 100644 --- a/src/test/ui/issues/issue-28324.rs +++ b/src/test/ui/issues/issue-28324.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + extern "C" { static error_message_count: u32; } diff --git a/src/test/ui/issues/issue-28324.stderr b/src/test/ui/issues/issue-28324.stderr deleted file mode 100644 index d7dad992152..00000000000 --- a/src/test/ui/issues/issue-28324.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/issue-28324.rs:5:24 - | -LL | pub static BAZ: u32 = *&error_message_count; - | ^^^^^^^^^^^^^^^^^^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/issues/issue-28324.thir.stderr b/src/test/ui/issues/issue-28324.thir.stderr new file mode 100644 index 00000000000..c696c359830 --- /dev/null +++ b/src/test/ui/issues/issue-28324.thir.stderr @@ -0,0 +1,11 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/issue-28324.rs:8:25 + | +LL | pub static BAZ: u32 = *&error_message_count; + | ^^^^^^^^^^^^^^^^^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics-mut.mir.stderr b/src/test/ui/safe-extern-statics-mut.mir.stderr new file mode 100644 index 00000000000..cec5f9d9c9f --- /dev/null +++ b/src/test/ui/safe-extern-statics-mut.mir.stderr @@ -0,0 +1,35 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:13:13 + | +LL | let b = B; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:14:14 + | +LL | let rb = &B; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:15:14 + | +LL | let xb = XB; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:16:15 + | +LL | let xrb = &XB; + | ^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics-mut.rs b/src/test/ui/safe-extern-statics-mut.rs index 324fa443aa5..389a4589a71 100644 --- a/src/test/ui/safe-extern-statics-mut.rs +++ b/src/test/ui/safe-extern-statics-mut.rs @@ -1,4 +1,6 @@ // aux-build:extern-statics.rs +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck extern crate extern_statics; use extern_statics::*; diff --git a/src/test/ui/safe-extern-statics-mut.stderr b/src/test/ui/safe-extern-statics-mut.stderr deleted file mode 100644 index 38803883414..00000000000 --- a/src/test/ui/safe-extern-statics-mut.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics-mut.rs:11:13 - | -LL | let b = B; - | ^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics-mut.rs:12:14 - | -LL | let rb = &B; - | ^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics-mut.rs:13:14 - | -LL | let xb = XB; - | ^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics-mut.rs:14:15 - | -LL | let xrb = &XB; - | ^^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics-mut.thir.stderr b/src/test/ui/safe-extern-statics-mut.thir.stderr new file mode 100644 index 00000000000..8e6d2805a0b --- /dev/null +++ b/src/test/ui/safe-extern-statics-mut.thir.stderr @@ -0,0 +1,35 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:13:13 + | +LL | let b = B; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:14:15 + | +LL | let rb = &B; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:15:14 + | +LL | let xb = XB; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics-mut.rs:16:16 + | +LL | let xrb = &XB; + | ^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics.mir.stderr b/src/test/ui/safe-extern-statics.mir.stderr new file mode 100644 index 00000000000..102abd0816f --- /dev/null +++ b/src/test/ui/safe-extern-statics.mir.stderr @@ -0,0 +1,35 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:13:13 + | +LL | let a = A; + | ^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:14:14 + | +LL | let ra = &A; + | ^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:15:14 + | +LL | let xa = XA; + | ^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:16:15 + | +LL | let xra = &XA; + | ^^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics.rs b/src/test/ui/safe-extern-statics.rs index 6fa4c4aaca5..0aa90c442ea 100644 --- a/src/test/ui/safe-extern-statics.rs +++ b/src/test/ui/safe-extern-statics.rs @@ -1,4 +1,6 @@ // aux-build:extern-statics.rs +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck extern crate extern_statics; use extern_statics::*; diff --git a/src/test/ui/safe-extern-statics.stderr b/src/test/ui/safe-extern-statics.stderr deleted file mode 100644 index b42572ea3ee..00000000000 --- a/src/test/ui/safe-extern-statics.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics.rs:11:13 - | -LL | let a = A; - | ^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics.rs:12:14 - | -LL | let ra = &A; - | ^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics.rs:13:14 - | -LL | let xa = XA; - | ^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error[E0133]: use of extern static is unsafe and requires unsafe function or block - --> $DIR/safe-extern-statics.rs:14:15 - | -LL | let xra = &XA; - | ^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/safe-extern-statics.thir.stderr b/src/test/ui/safe-extern-statics.thir.stderr new file mode 100644 index 00000000000..7fd2182c4c6 --- /dev/null +++ b/src/test/ui/safe-extern-statics.thir.stderr @@ -0,0 +1,35 @@ +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:13:13 + | +LL | let a = A; + | ^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:14:15 + | +LL | let ra = &A; + | ^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:15:14 + | +LL | let xa = XA; + | ^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error[E0133]: use of extern static is unsafe and requires unsafe function or block + --> $DIR/safe-extern-statics.rs:16:16 + | +LL | let xra = &XA; + | ^^ use of extern static + | + = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-foreign-requires-unsafe.mir.stderr b/src/test/ui/static/static-mut-foreign-requires-unsafe.mir.stderr new file mode 100644 index 00000000000..a4659bc8712 --- /dev/null +++ b/src/test/ui/static/static-mut-foreign-requires-unsafe.mir.stderr @@ -0,0 +1,27 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:9:5 + | +LL | a += 3; + | ^^^^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:10:5 + | +LL | a = 4; + | ^^^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:11:14 + | +LL | let _b = a; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-foreign-requires-unsafe.rs b/src/test/ui/static/static-mut-foreign-requires-unsafe.rs index 90aa2537a82..4f96acb3375 100644 --- a/src/test/ui/static/static-mut-foreign-requires-unsafe.rs +++ b/src/test/ui/static/static-mut-foreign-requires-unsafe.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + extern "C" { static mut a: i32; } diff --git a/src/test/ui/static/static-mut-foreign-requires-unsafe.stderr b/src/test/ui/static/static-mut-foreign-requires-unsafe.stderr deleted file mode 100644 index e7ed0b710b2..00000000000 --- a/src/test/ui/static/static-mut-foreign-requires-unsafe.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-foreign-requires-unsafe.rs:6:5 - | -LL | a += 3; - | ^^^^^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-foreign-requires-unsafe.rs:7:5 - | -LL | a = 4; - | ^^^^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-foreign-requires-unsafe.rs:8:14 - | -LL | let _b = a; - | ^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-foreign-requires-unsafe.thir.stderr b/src/test/ui/static/static-mut-foreign-requires-unsafe.thir.stderr new file mode 100644 index 00000000000..2c62d4d8f3b --- /dev/null +++ b/src/test/ui/static/static-mut-foreign-requires-unsafe.thir.stderr @@ -0,0 +1,27 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:9:5 + | +LL | a += 3; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:10:5 + | +LL | a = 4; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-foreign-requires-unsafe.rs:11:14 + | +LL | let _b = a; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-requires-unsafe.mir.stderr b/src/test/ui/static/static-mut-requires-unsafe.mir.stderr new file mode 100644 index 00000000000..0d4ce056fc2 --- /dev/null +++ b/src/test/ui/static/static-mut-requires-unsafe.mir.stderr @@ -0,0 +1,27 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:7:5 + | +LL | a += 3; + | ^^^^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:8:5 + | +LL | a = 4; + | ^^^^^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:9:14 + | +LL | let _b = a; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-requires-unsafe.rs b/src/test/ui/static/static-mut-requires-unsafe.rs index 413b97e431d..ea3ba095007 100644 --- a/src/test/ui/static/static-mut-requires-unsafe.rs +++ b/src/test/ui/static/static-mut-requires-unsafe.rs @@ -1,3 +1,6 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + static mut a: isize = 3; fn main() { diff --git a/src/test/ui/static/static-mut-requires-unsafe.stderr b/src/test/ui/static/static-mut-requires-unsafe.stderr deleted file mode 100644 index 85e468b333c..00000000000 --- a/src/test/ui/static/static-mut-requires-unsafe.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-requires-unsafe.rs:4:5 - | -LL | a += 3; - | ^^^^^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-requires-unsafe.rs:5:5 - | -LL | a = 4; - | ^^^^^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-mut-requires-unsafe.rs:6:14 - | -LL | let _b = a; - | ^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0133`. diff --git a/src/test/ui/static/static-mut-requires-unsafe.thir.stderr b/src/test/ui/static/static-mut-requires-unsafe.thir.stderr new file mode 100644 index 00000000000..1a1cf14271a --- /dev/null +++ b/src/test/ui/static/static-mut-requires-unsafe.thir.stderr @@ -0,0 +1,27 @@ +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:7:5 + | +LL | a += 3; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:8:5 + | +LL | a = 4; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error[E0133]: use of mutable static is unsafe and requires unsafe function or block + --> $DIR/static-mut-requires-unsafe.rs:9:14 + | +LL | let _b = a; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0133`. diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 7b42de0ec43..3f983884460 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,8 +7,8 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 1370; -const ISSUES_ENTRY_LIMIT: usize = 2555; +const ROOT_ENTRY_LIMIT: usize = 1371; +const ISSUES_ENTRY_LIMIT: usize = 2558; fn check_entries(path: &Path, bad: &mut bool) { let dirs = walkdir::WalkDir::new(&path.join("test/ui")) -- cgit 1.4.1-3-g733a5