Skip to content

Commit 5d828d2

Browse files
Rollup merge of rust-lang#106353 - lukas-code:reduce-red-lines-in-my-ide, r=wesleywiser
Reduce spans for `unsafe impl` errors Because huge spans aren't great for IDEs. Prior art: rust-lang#103749
2 parents dc5247b + 035d854 commit 5d828d2

File tree

7 files changed

+15
-29
lines changed

7 files changed

+15
-29
lines changed

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
2121
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
2222
struct_span_err!(
2323
tcx.sess,
24-
item.span,
24+
tcx.def_span(def_id),
2525
E0199,
2626
"implementing the trait `{}` is not unsafe",
2727
trait_ref.print_only_trait_path()
@@ -38,7 +38,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
3838
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
3939
struct_span_err!(
4040
tcx.sess,
41-
item.span,
41+
tcx.def_span(def_id),
4242
E0200,
4343
"the trait `{}` requires an `unsafe impl` declaration",
4444
trait_ref.print_only_trait_path()
@@ -61,7 +61,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
6161
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, hir::ImplPolarity::Positive) => {
6262
struct_span_err!(
6363
tcx.sess,
64-
item.span,
64+
tcx.def_span(def_id),
6565
E0569,
6666
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
6767
attr_name

src/test/ui/coherence/coherence-default-trait-impl.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe
22
--> $DIR/coherence-default-trait-impl.rs:8:1
33
|
44
LL | unsafe impl MySafeTrait for Foo {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
help: remove `unsafe` from this trait implementation
88
|
@@ -14,7 +14,7 @@ error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
1414
--> $DIR/coherence-default-trait-impl.rs:13:1
1515
|
1616
LL | impl MyUnsafeTrait for Foo {}
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
|
1919
= 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
2020
help: add `unsafe` to this trait implementation

src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
22
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:21:1
33
|
4-
LL | / impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
5-
LL | |
6-
LL | |
7-
LL | | // (unsafe to access self.1 due to #[may_dangle] on A)
8-
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
9-
LL | | }
10-
| |_^
4+
LL | impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116
|
127
= 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
138
help: add `unsafe` to this trait implementation
@@ -18,13 +13,8 @@ LL | unsafe impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
1813
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
1914
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:27:1
2015
|
21-
LL | / impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
22-
LL | |
23-
LL | |
24-
LL | | // (unsafe to access self.1 due to #[may_dangle] on 'a)
25-
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
26-
LL | | }
27-
| |_^
16+
LL | impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2818
|
2919
= 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
3020
help: add `unsafe` to this trait implementation

src/test/ui/error-codes/E0199.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0199]: implementing the trait `Bar` is not unsafe
22
--> $DIR/E0199.rs:6:1
33
|
44
LL | unsafe impl Bar for Foo { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
help: remove `unsafe` from this trait implementation
88
|

src/test/ui/error-codes/E0200.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
22
--> $DIR/E0200.rs:5:1
33
|
44
LL | impl Bar for Foo { }
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^
66
|
77
= 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
88
help: add `unsafe` to this trait implementation

src/test/ui/traits/safety-trait-impl-cc.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
error[E0200]: the trait `Foo` requires an `unsafe impl` declaration
22
--> $DIR/safety-trait-impl-cc.rs:9:1
33
|
4-
LL | / impl lib::Foo for Bar {
5-
LL | | fn foo(&self) -> isize {
6-
LL | | panic!();
7-
LL | | }
8-
LL | | }
9-
| |_^
4+
LL | impl lib::Foo for Bar {
5+
| ^^^^^^^^^^^^^^^^^^^^^
106
|
117
= 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
128
help: add `unsafe` to this trait implementation

src/test/ui/traits/safety-trait-impl.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
22
--> $DIR/safety-trait-impl.rs:14:1
33
|
44
LL | impl UnsafeTrait for u16 { }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= 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
88
help: add `unsafe` to this trait implementation
@@ -14,7 +14,7 @@ error[E0199]: implementing the trait `SafeTrait` is not unsafe
1414
--> $DIR/safety-trait-impl.rs:16:1
1515
|
1616
LL | unsafe impl SafeTrait for u32 { }
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
|
1919
help: remove `unsafe` from this trait implementation
2020
|

0 commit comments

Comments
 (0)