Add fix suggestions for E0199, E0200, and E0569
This commit is contained in:
parent
dcb3761150
commit
770538ef9b
@ -26,6 +26,12 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
"implementing the trait `{}` is not unsafe",
|
||||
trait_ref.print_only_trait_path()
|
||||
)
|
||||
.span_suggestion_verbose(
|
||||
item.span.with_hi(item.span.lo() + rustc_span::BytePos(7)),
|
||||
"remove `unsafe` from this trait implementation",
|
||||
"",
|
||||
rustc_errors::Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
@ -37,6 +43,18 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
"the trait `{}` requires an `unsafe impl` declaration",
|
||||
trait_ref.print_only_trait_path()
|
||||
)
|
||||
.note(format!(
|
||||
"the trait `{}` enforces invariants that the compiler can't check. \
|
||||
Review the trait documentation and make sure this implementation \
|
||||
upholds those invariants before adding the `unsafe` keyword",
|
||||
trait_ref.print_only_trait_path()
|
||||
))
|
||||
.span_suggestion_verbose(
|
||||
item.span.shrink_to_lo(),
|
||||
"add `unsafe` to this trait implementation",
|
||||
"unsafe ",
|
||||
rustc_errors::Applicability::MaybeIncorrect,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
@ -48,6 +66,18 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
|
||||
attr_name
|
||||
)
|
||||
.note(format!(
|
||||
"the trait `{}` enforces invariants that the compiler can't check. \
|
||||
Review the trait documentation and make sure this implementation \
|
||||
upholds those invariants before adding the `unsafe` keyword",
|
||||
trait_ref.print_only_trait_path()
|
||||
))
|
||||
.span_suggestion_verbose(
|
||||
item.span.shrink_to_lo(),
|
||||
"add `unsafe` to this trait implementation",
|
||||
"unsafe ",
|
||||
rustc_errors::Applicability::MaybeIncorrect,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,24 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe
|
||||
|
|
||||
LL | unsafe impl MySafeTrait for Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove `unsafe` from this trait implementation
|
||||
|
|
||||
LL - unsafe impl MySafeTrait for Foo {}
|
||||
LL + impl MySafeTrait for Foo {}
|
||||
|
|
||||
|
||||
error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
|
||||
--> $DIR/coherence-default-trait-impl.rs:13:1
|
||||
|
|
||||
LL | impl MyUnsafeTrait for Foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the trait `MyUnsafeTrait` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl MyUnsafeTrait for Foo {}
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -8,6 +8,12 @@ LL | | // (unsafe to access self.1 due to #[may_dangle] on A)
|
||||
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: the trait `Drop` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
|
||||
| ++++++
|
||||
|
||||
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
|
||||
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:27:1
|
||||
@ -19,6 +25,12 @@ LL | | // (unsafe to access self.1 due to #[may_dangle] on 'a)
|
||||
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: the trait `Drop` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -3,6 +3,12 @@ error[E0199]: implementing the trait `Bar` is not unsafe
|
||||
|
|
||||
LL | unsafe impl Bar for Foo { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove `unsafe` from this trait implementation
|
||||
|
|
||||
LL - unsafe impl Bar for Foo { }
|
||||
LL + impl Bar for Foo { }
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -3,6 +3,12 @@ error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
|
||||
|
|
||||
LL | impl Bar for Foo { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl Bar for Foo { }
|
||||
| ++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -7,6 +7,12 @@ LL | | panic!();
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: the trait `Foo` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl lib::Foo for Bar {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -3,12 +3,24 @@ error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
|
||||
|
|
||||
LL | impl UnsafeTrait for u16 { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the trait `UnsafeTrait` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
|
||||
help: add `unsafe` to this trait implementation
|
||||
|
|
||||
LL | unsafe impl UnsafeTrait for u16 { }
|
||||
| ++++++
|
||||
|
||||
error[E0199]: implementing the trait `SafeTrait` is not unsafe
|
||||
--> $DIR/safety-trait-impl.rs:16:1
|
||||
|
|
||||
LL | unsafe impl SafeTrait for u32 { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove `unsafe` from this trait implementation
|
||||
|
|
||||
LL - unsafe impl SafeTrait for u32 { }
|
||||
LL + impl SafeTrait for u32 { }
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user