Skip to content

Commit

Permalink
reduce spans for unsafe impl errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Jan 1, 2023
1 parent bb6e76d commit 035d854
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 29 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/coherence/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
struct_span_err!(
tcx.sess,
item.span,
tcx.def_span(def_id),
E0199,
"implementing the trait `{}` is not unsafe",
trait_ref.print_only_trait_path()
Expand All @@ -38,7 +38,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
struct_span_err!(
tcx.sess,
item.span,
tcx.def_span(def_id),
E0200,
"the trait `{}` requires an `unsafe impl` declaration",
trait_ref.print_only_trait_path()
Expand All @@ -61,7 +61,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, hir::ImplPolarity::Positive) => {
struct_span_err!(
tcx.sess,
item.span,
tcx.def_span(def_id),
E0569,
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
attr_name
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence/coherence-default-trait-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe
--> $DIR/coherence-default-trait-impl.rs:8:1
|
LL | unsafe impl MySafeTrait for Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove `unsafe` from this trait implementation
|
Expand All @@ -14,7 +14,7 @@ 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
Expand Down
18 changes: 4 additions & 14 deletions src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:21:1
|
LL | / impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
LL | |
LL | |
LL | | // (unsafe to access self.1 due to #[may_dangle] on A)
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
LL | | }
| |_^
LL | impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
Expand All @@ -18,13 +13,8 @@ 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
|
LL | / impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
LL | |
LL | |
LL | | // (unsafe to access self.1 due to #[may_dangle] on 'a)
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
LL | | }
| |_^
LL | impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0199.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0199]: implementing the trait `Bar` is not unsafe
--> $DIR/E0199.rs:6:1
|
LL | unsafe impl Bar for Foo { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove `unsafe` from this trait implementation
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0200.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
--> $DIR/E0200.rs:5:1
|
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
Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/traits/safety-trait-impl-cc.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
error[E0200]: the trait `Foo` requires an `unsafe impl` declaration
--> $DIR/safety-trait-impl-cc.rs:9:1
|
LL | / impl lib::Foo for Bar {
LL | | fn foo(&self) -> isize {
LL | | panic!();
LL | | }
LL | | }
| |_^
LL | impl lib::Foo for Bar {
| ^^^^^^^^^^^^^^^^^^^^^
|
= 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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/traits/safety-trait-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
--> $DIR/safety-trait-impl.rs:14:1
|
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
Expand All @@ -14,7 +14,7 @@ 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
|
Expand Down

0 comments on commit 035d854

Please sign in to comment.