Skip to content

Commit d5e33d3

Browse files
committed
Shorten def_span for more items.
1 parent 09f5df5 commit d5e33d3

File tree

5 files changed

+18
-33
lines changed

5 files changed

+18
-33
lines changed

clippy_lints/src/operators/numeric_arithmetic.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ impl Context {
9696
}
9797

9898
pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
99-
let body_owner = cx.tcx.hir().body_owner_def_id(body.id());
99+
let body_owner = cx.tcx.hir().body_owner(body.id());
100+
let body_owner_def_id = cx.tcx.hir().local_def_id(body_owner);
100101

101-
match cx.tcx.hir().body_owner_kind(body_owner) {
102+
match cx.tcx.hir().body_owner_kind(body_owner_def_id) {
102103
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => {
103-
let body_span = cx.tcx.def_span(body_owner);
104+
let body_span = cx.tcx.hir().span_with_body(body_owner);
104105

105106
if let Some(span) = self.const_span {
106107
if span.contains(body_span) {
@@ -115,7 +116,7 @@ impl Context {
115116

116117
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
117118
let body_owner = cx.tcx.hir().body_owner(body.id());
118-
let body_span = cx.tcx.hir().span(body_owner);
119+
let body_span = cx.tcx.hir().span_with_body(body_owner);
119120

120121
if let Some(span) = self.const_span {
121122
if span.contains(body_span) {

tests/ui/crashes/ice-6252.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error[E0046]: not all trait items implemented, missing: `VAL`
2525
--> $DIR/ice-6252.rs:10:1
2626
|
2727
LL | const VAL: T;
28-
| ------------- `VAL` from trait
28+
| ------------ `VAL` from trait
2929
...
3030
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation

tests/ui/derive_hash_xor_eq.stderr

+4-12
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ LL | #[derive(Hash)]
88
note: `PartialEq` implemented here
99
--> $DIR/derive_hash_xor_eq.rs:15:1
1010
|
11-
LL | / impl PartialEq for Bar {
12-
LL | | fn eq(&self, _: &Bar) -> bool {
13-
LL | | true
14-
LL | | }
15-
LL | | }
16-
| |_^
11+
LL | impl PartialEq for Bar {
12+
| ^^^^^^^^^^^^^^^^^^^^^^
1713
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
1814

1915
error: you are deriving `Hash` but have implemented `PartialEq` explicitly
@@ -25,12 +21,8 @@ LL | #[derive(Hash)]
2521
note: `PartialEq` implemented here
2622
--> $DIR/derive_hash_xor_eq.rs:24:1
2723
|
28-
LL | / impl PartialEq<Baz> for Baz {
29-
LL | | fn eq(&self, _: &Baz) -> bool {
30-
LL | | true
31-
LL | | }
32-
LL | | }
33-
| |_^
24+
LL | impl PartialEq<Baz> for Baz {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3426
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
3527

3628
error: you are implementing `Hash` explicitly but have derived `PartialEq`

tests/ui/derive_ord_xor_partial_ord.stderr

+4-12
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ LL | #[derive(Ord, PartialEq, Eq)]
88
note: `PartialOrd` implemented here
99
--> $DIR/derive_ord_xor_partial_ord.rs:24:1
1010
|
11-
LL | / impl PartialOrd for DeriveOrd {
12-
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
13-
LL | | Some(other.cmp(self))
14-
LL | | }
15-
LL | | }
16-
| |_^
11+
LL | impl PartialOrd for DeriveOrd {
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1713
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
1814

1915
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
@@ -25,12 +21,8 @@ LL | #[derive(Ord, PartialEq, Eq)]
2521
note: `PartialOrd` implemented here
2622
--> $DIR/derive_ord_xor_partial_ord.rs:33:1
2723
|
28-
LL | / impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
29-
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
30-
LL | | Some(other.cmp(self))
31-
LL | | }
32-
LL | | }
33-
| |_^
24+
LL | impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3426
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
3527

3628
error: you are implementing `Ord` explicitly but have derived `PartialOrd`

tests/ui/needless_pass_by_value.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ help: consider marking this type as `Copy`
124124
--> $DIR/needless_pass_by_value.rs:123:1
125125
|
126126
LL | struct CopyWrapper(u32);
127-
| ^^^^^^^^^^^^^^^^^^^^^^^^
127+
| ^^^^^^^^^^^^^^^^^^
128128

129129
error: this argument is passed by value, but not consumed in the function body
130130
--> $DIR/needless_pass_by_value.rs:131:29
@@ -136,7 +136,7 @@ help: consider marking this type as `Copy`
136136
--> $DIR/needless_pass_by_value.rs:123:1
137137
|
138138
LL | struct CopyWrapper(u32);
139-
| ^^^^^^^^^^^^^^^^^^^^^^^^
139+
| ^^^^^^^^^^^^^^^^^^
140140

141141
error: this argument is passed by value, but not consumed in the function body
142142
--> $DIR/needless_pass_by_value.rs:131:45
@@ -148,7 +148,7 @@ help: consider marking this type as `Copy`
148148
--> $DIR/needless_pass_by_value.rs:123:1
149149
|
150150
LL | struct CopyWrapper(u32);
151-
| ^^^^^^^^^^^^^^^^^^^^^^^^
151+
| ^^^^^^^^^^^^^^^^^^
152152

153153
error: this argument is passed by value, but not consumed in the function body
154154
--> $DIR/needless_pass_by_value.rs:131:61
@@ -160,7 +160,7 @@ help: consider marking this type as `Copy`
160160
--> $DIR/needless_pass_by_value.rs:123:1
161161
|
162162
LL | struct CopyWrapper(u32);
163-
| ^^^^^^^^^^^^^^^^^^^^^^^^
163+
| ^^^^^^^^^^^^^^^^^^
164164

165165
error: this argument is passed by value, but not consumed in the function body
166166
--> $DIR/needless_pass_by_value.rs:143:40

0 commit comments

Comments
 (0)