Skip to content

Commit

Permalink
Shorten def_span for more items.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jul 1, 2022
1 parent 09f5df5 commit d5e33d3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
9 changes: 5 additions & 4 deletions clippy_lints/src/operators/numeric_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ impl Context {
}

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

match cx.tcx.hir().body_owner_kind(body_owner) {
match cx.tcx.hir().body_owner_kind(body_owner_def_id) {
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const => {
let body_span = cx.tcx.def_span(body_owner);
let body_span = cx.tcx.hir().span_with_body(body_owner);

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

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

if let Some(span) = self.const_span {
if span.contains(body_span) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/ice-6252.rs:10:1
|
LL | const VAL: T;
| ------------- `VAL` from trait
| ------------ `VAL` from trait
...
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
Expand Down
16 changes: 4 additions & 12 deletions tests/ui/derive_hash_xor_eq.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ LL | #[derive(Hash)]
note: `PartialEq` implemented here
--> $DIR/derive_hash_xor_eq.rs:15:1
|
LL | / impl PartialEq for Bar {
LL | | fn eq(&self, _: &Bar) -> bool {
LL | | true
LL | | }
LL | | }
| |_^
LL | impl PartialEq for Bar {
| ^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: you are implementing `Hash` explicitly but have derived `PartialEq`
Expand Down
16 changes: 4 additions & 12 deletions tests/ui/derive_ord_xor_partial_ord.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ LL | #[derive(Ord, PartialEq, Eq)]
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:24:1
|
LL | / impl PartialOrd for DeriveOrd {
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
LL | | Some(other.cmp(self))
LL | | }
LL | | }
| |_^
LL | impl PartialOrd for DeriveOrd {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: you are implementing `Ord` explicitly but have derived `PartialOrd`
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/needless_pass_by_value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ help: consider marking this type as `Copy`
--> $DIR/needless_pass_by_value.rs:123:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^

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

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

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

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

0 comments on commit d5e33d3

Please sign in to comment.