Skip to content

Implement #[deprecated_safe] #95025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add ui tests (better organization needed)
  • Loading branch information
User1785604260 committed Apr 15, 2022
commit dceec513df97cd03b2af1a48e82e86cb56ef6489
61 changes: 61 additions & 0 deletions src/test/ui/deprecated-safe/auxiliary/deprecated-safe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#![feature(deprecated_safe)]
#![feature(staged_api)]
#![stable(feature = "deprecated-safe-test", since = "1.61.0")]
#![warn(unused_unsafe)]

use std::ffi::OsStr;

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
pub unsafe fn depr_safe() {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
pub unsafe fn depr_safe_params(_: u32, _: u64) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
pub unsafe fn depr_safe_generic<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2015")]
pub unsafe fn depr_safe_2015() {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2018")]
pub unsafe fn depr_safe_2018() {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
pub unsafe trait DeprSafe {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2015")]
pub unsafe trait DeprSafe2015 {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2018")]
pub unsafe trait DeprSafe2018 {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
pub trait DeprSafeFns {
#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
unsafe fn depr_safe_fn(&self) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
unsafe fn depr_safe_params(&self, _: u32, _: u64) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason")]
unsafe fn depr_safe_fn_generic<K: AsRef<OsStr>, V: AsRef<OsStr>>(&self, key: K, value: V) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2015")]
unsafe fn depr_safe_fn_2015(&self) {}

#[stable(feature = "deprecated-safe-test", since = "1.61.0")]
#[deprecated_safe(since = "1.61.0", note = "reason", unsafe_edition = "2018")]
unsafe fn depr_safe_fn_2018(&self) {}
}
76 changes: 76 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-attr.mir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:15:1
|
LL | #[deprecated_safe(since = "1.61.0", unsafe_edition = "2015", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:18:1
|
LL | #[deprecated_safe(since = "1.61.0", unsafe_edition = "BAD", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:21:1
|
LL | #[deprecated_safe(since = "TBD", unsafe_edition = "BAD", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: multiple `deprecated_safe` attributes
--> $DIR/deprecated-safe-attr.rs:37:1
|
LL | #[deprecated_safe(note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/deprecated-safe-attr.rs:36:1
|
LL | #[deprecated_safe(since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0541]: unknown meta item 'extra'
--> $DIR/deprecated-safe-attr.rs:40:37
|
LL | #[deprecated_safe(since = "1.61.0", extra = "")]
| ^^^^^^^^^^

error[E0538]: multiple 'since' items
--> $DIR/deprecated-safe-attr.rs:43:1
|
LL | #[deprecated_safe(since = "1.61.0", since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0551]: incorrect meta item 'since'
--> $DIR/deprecated-safe-attr.rs:46:19
|
LL | #[deprecated_safe(since)]
| ^^^^^

error[E0565]: literal in `deprecated_safe` value must be a string
--> $DIR/deprecated-safe-attr.rs:49:27
|
LL | #[deprecated_safe(since = 1_61_0)]
| ^^^^^^

error[E0565]: item in `deprecated_safe` must be a key/value pair
--> $DIR/deprecated-safe-attr.rs:52:19
|
LL | #[deprecated_safe(1_61_0)]
| ^^^^^^

error[E0543]: this `#[deprecated_safe]` annotation has no effect
--> $DIR/deprecated-safe-attr.rs:55:1
|
LL | #[deprecated_safe(since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: this `#[deprecated_safe]` annotation has no effect
--> $DIR/deprecated-safe-attr.rs:60:5
|
LL | #[deprecated_safe(since = "1.61.0", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0538, E0541, E0543, E0551, E0565.
For more information about an error, try `rustc --explain E0538`.
64 changes: 64 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// aux-build:deprecated-safe.rs
// revisions: mir thir
// NOTE(skippy) these tests output many duplicates, so deduplicate or they become brittle to changes
// [mir]compile-flags: -Zdeduplicate-diagnostics=yes
// [thir]compile-flags: -Z thir-unsafeck -Zdeduplicate-diagnostics=yes

#![feature(deprecated_safe)]
#![feature(type_alias_impl_trait)]
#![warn(unused_unsafe)]

extern crate deprecated_safe;

use deprecated_safe::DeprSafeFns;

#[deprecated_safe(since = "1.61.0", unsafe_edition = "2015", note = "reason")] //~ ERROR 'unsafe_edition' is invalid outside of rustc
unsafe fn foo0() {}

#[deprecated_safe(since = "1.61.0", unsafe_edition = "BAD", note = "reason")] //~ ERROR 'unsafe_edition' is invalid outside of rustc
unsafe fn foo1() {}

#[deprecated_safe(since = "TBD", unsafe_edition = "BAD", note = "reason")] //~ ERROR 'unsafe_edition' is invalid outside of rustc
unsafe fn foo2() {}

#[deprecated_safe]
unsafe fn foo3() {}

#[deprecated_safe = "hi"]
unsafe fn foo4() {}

#[deprecated_safe(since = "1.61.0")]
unsafe fn foo5() {}

#[deprecated_safe(note = "reason")]
unsafe fn foo6() {}

#[deprecated_safe(since = "1.61.0")]
#[deprecated_safe(note = "reason")] //~ ERROR multiple `deprecated_safe` attributes
unsafe fn foo7() {}

#[deprecated_safe(since = "1.61.0", extra = "")] //~ ERROR unknown meta item 'extra'
unsafe fn foo8() {}

#[deprecated_safe(since = "1.61.0", since = "1.61.0")] //~ ERROR multiple 'since' items
unsafe fn foo9() {}

#[deprecated_safe(since)] //~ ERROR incorrect meta item
unsafe fn foo10() {}

#[deprecated_safe(since = 1_61_0)] //~ ERROR literal in `deprecated_safe` value must be a string
unsafe fn foo11() {}

#[deprecated_safe(1_61_0)] //~ ERROR item in `deprecated_safe` must be a key/value pair
unsafe fn foo12() {}

#[deprecated_safe(since = "1.61.0")] //~ ERROR this `#[deprecated_safe]` annotation has no effect
static FOO0: u32 = 0;

struct BadAnnotation;
impl DeprSafeFns for BadAnnotation {
#[deprecated_safe(since = "1.61.0", note = "reason")] //~ ERROR this `#[deprecated_safe]` annotation has no effect
unsafe fn depr_safe_fn(&self) {}
}

fn main() {}
76 changes: 76 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-attr.thir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:15:1
|
LL | #[deprecated_safe(since = "1.61.0", unsafe_edition = "2015", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:18:1
|
LL | #[deprecated_safe(since = "1.61.0", unsafe_edition = "BAD", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: 'unsafe_edition' is invalid outside of rustc
--> $DIR/deprecated-safe-attr.rs:21:1
|
LL | #[deprecated_safe(since = "TBD", unsafe_edition = "BAD", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: multiple `deprecated_safe` attributes
--> $DIR/deprecated-safe-attr.rs:37:1
|
LL | #[deprecated_safe(note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/deprecated-safe-attr.rs:36:1
|
LL | #[deprecated_safe(since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0541]: unknown meta item 'extra'
--> $DIR/deprecated-safe-attr.rs:40:37
|
LL | #[deprecated_safe(since = "1.61.0", extra = "")]
| ^^^^^^^^^^

error[E0538]: multiple 'since' items
--> $DIR/deprecated-safe-attr.rs:43:1
|
LL | #[deprecated_safe(since = "1.61.0", since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0551]: incorrect meta item 'since'
--> $DIR/deprecated-safe-attr.rs:46:19
|
LL | #[deprecated_safe(since)]
| ^^^^^

error[E0565]: literal in `deprecated_safe` value must be a string
--> $DIR/deprecated-safe-attr.rs:49:27
|
LL | #[deprecated_safe(since = 1_61_0)]
| ^^^^^^

error[E0565]: item in `deprecated_safe` must be a key/value pair
--> $DIR/deprecated-safe-attr.rs:52:19
|
LL | #[deprecated_safe(1_61_0)]
| ^^^^^^

error[E0543]: this `#[deprecated_safe]` annotation has no effect
--> $DIR/deprecated-safe-attr.rs:55:1
|
LL | #[deprecated_safe(since = "1.61.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: this `#[deprecated_safe]` annotation has no effect
--> $DIR/deprecated-safe-attr.rs:60:5
|
LL | #[deprecated_safe(since = "1.61.0", note = "reason")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0538, E0541, E0543, E0551, E0565.
For more information about an error, try `rustc --explain E0538`.
21 changes: 21 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-mismatch.mir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:12:1
|
LL | fn foo0() {}
| ^^^^^^^^^^^^

error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:15:1
|
LL | trait PreviouslySafeTrait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:19:5
|
LL | fn foo0();
| ^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0543`.
22 changes: 22 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// revisions: mir thir
// NOTE(skippy) these tests output many duplicates, so deduplicate or they become brittle to changes
// [mir]compile-flags: -Zdeduplicate-diagnostics=yes
// [thir]compile-flags: -Z thir-unsafeck -Zdeduplicate-diagnostics=yes

#![feature(deprecated_safe)]
#![warn(unused_unsafe)]

use std::ffi::{OsStr, OsString};

#[deprecated_safe(since = "1.61.0", note = "reason")]
fn foo0() {} //~ ERROR item must be marked unsafe

#[deprecated_safe(since = "1.61.0", note = "reason")]
trait PreviouslySafeTrait {} //~ ERROR item must be marked unsafe

trait PreviouslySafeFunctions {
#[deprecated_safe(since = "1.61.0", note = "reason")]
fn foo0(); //~ ERROR item must be marked unsafe
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-mismatch.thir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:12:1
|
LL | fn foo0() {}
| ^^^^^^^^^^^^

error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:15:1
|
LL | trait PreviouslySafeTrait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0543]: item must be marked unsafe
--> $DIR/deprecated-safe-mismatch.rs:19:5
|
LL | fn foo0();
| ^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0543`.
43 changes: 43 additions & 0 deletions src/test/ui/deprecated-safe/deprecated-safe-trait-fn.mir.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
warning: use of associated function `deprecated_safe::DeprSafeFns::depr_safe_fn` without an `unsafe fn` declaration has been deprecated as it is now an unsafe associated function
--> $DIR/deprecated-safe-trait-fn.rs:17:5
|
LL | fn depr_safe_fn(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated_safe)]` on by default
= note: this associated function was previously not marked unsafe, but has been marked unsafe since 1.61.0
= note: consult the associated function's documentation for information on how to avoid undefined behavior
= note: reason

warning: use of associated function `deprecated_safe::DeprSafeFns::depr_safe_fn_generic` without an `unsafe fn` declaration has been deprecated as it is now an unsafe associated function
--> $DIR/deprecated-safe-trait-fn.rs:18:5
|
LL | fn depr_safe_fn_generic<K: AsRef<OsStr>, V: AsRef<OsStr>>(&self, key: K, value: V) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this associated function was previously not marked unsafe, but has been marked unsafe since 1.61.0
= note: consult the associated function's documentation for information on how to avoid undefined behavior
= note: reason

error[E0053]: method `depr_safe_fn_2015` has an incompatible type for trait
--> $DIR/deprecated-safe-trait-fn.rs:19:5
|
LL | fn depr_safe_fn_2015(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected unsafe fn, found normal fn
|
= note: expected fn pointer `unsafe fn(&BadImpls)`
found fn pointer `fn(&BadImpls)`

warning: use of associated function `deprecated_safe::DeprSafeFns::depr_safe_fn_2018` without an `unsafe fn` declaration has been deprecated as it is now an unsafe associated function
--> $DIR/deprecated-safe-trait-fn.rs:20:5
|
LL | fn depr_safe_fn_2018(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this associated function was previously not marked unsafe, but has been marked unsafe since 1.61.0
= note: consult the associated function's documentation for information on how to avoid undefined behavior
= note: reason

error: aborting due to previous error; 3 warnings emitted

For more information about this error, try `rustc --explain E0053`.
Loading