Add fix suggestions for E0199, E0200, and E0569
This commit is contained in:
parent
dcb3761150
commit
770538ef9b
7 changed files with 84 additions and 0 deletions
|
@ -26,6 +26,12 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
"implementing the trait `{}` is not unsafe",
|
"implementing the trait `{}` is not unsafe",
|
||||||
trait_ref.print_only_trait_path()
|
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();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +43,18 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
"the trait `{}` requires an `unsafe impl` declaration",
|
"the trait `{}` requires an `unsafe impl` declaration",
|
||||||
trait_ref.print_only_trait_path()
|
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();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +66,18 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
|
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
|
||||||
attr_name
|
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();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,24 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe
|
||||||
|
|
|
|
||||||
LL | unsafe impl MySafeTrait for Foo {}
|
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
|
error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
|
||||||
--> $DIR/coherence-default-trait-impl.rs:13:1
|
--> $DIR/coherence-default-trait-impl.rs:13:1
|
||||||
|
|
|
|
||||||
LL | impl MyUnsafeTrait for Foo {}
|
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
|
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 | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
|
||||||
LL | | }
|
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
|
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
|
||||||
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:27:1
|
--> $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 | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
|
||||||
LL | | }
|
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
|
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 { }
|
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
|
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 { }
|
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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,12 @@ LL | | panic!();
|
||||||
LL | | }
|
LL | | }
|
||||||
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
|
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 { }
|
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
|
error[E0199]: implementing the trait `SafeTrait` is not unsafe
|
||||||
--> $DIR/safety-trait-impl.rs:16:1
|
--> $DIR/safety-trait-impl.rs:16:1
|
||||||
|
|
|
|
||||||
LL | unsafe impl SafeTrait for u32 { }
|
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
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue