Skip to content

Commit ea64ab7

Browse files
committed
Use def span for conflicting impls and recursive fn
1 parent 3cc68ba commit ea64ab7

15 files changed

+111
-221
lines changed

src/librustc/traits/specialize/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,28 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
341341
}),
342342
if used_to_be_allowed { " (E0119)" } else { "" }
343343
);
344+
let impl_span = tcx.sess.codemap().def_span(
345+
tcx.span_of_impl(impl_def_id).unwrap()
346+
);
344347
let mut err = if used_to_be_allowed {
345348
tcx.struct_span_lint_node(
346349
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
347350
tcx.hir.as_local_node_id(impl_def_id).unwrap(),
348-
tcx.span_of_impl(impl_def_id).unwrap(),
351+
impl_span,
349352
&msg)
350353
} else {
351354
struct_span_err!(tcx.sess,
352-
tcx.span_of_impl(impl_def_id).unwrap(),
355+
impl_span,
353356
E0119,
354357
"{}",
355358
msg)
356359
};
357360

358361
match tcx.span_of_impl(overlap.with_impl) {
359362
Ok(span) => {
360-
err.span_label(span, format!("first implementation here"));
361-
err.span_label(tcx.span_of_impl(impl_def_id).unwrap(),
363+
err.span_label(tcx.sess.codemap().def_span(span),
364+
format!("first implementation here"));
365+
err.span_label(impl_span,
362366
format!("conflicting implementation{}",
363367
overlap.self_desc
364368
.map_or(String::new(),

src/librustc_lint/builtin.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl MissingDoc {
352352
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.check_name("doc"));
353353
if !has_doc {
354354
cx.span_lint(MISSING_DOCS,
355-
sp,
355+
cx.tcx.sess.codemap().def_span(sp),
356356
&format!("missing documentation for {}", desc));
357357
}
358358
}
@@ -914,15 +914,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
914914
// no break */ }`) shouldn't be linted unless it actually
915915
// recurs.
916916
if !reached_exit_without_self_call && !self_call_spans.is_empty() {
917+
let sp = cx.tcx.sess.codemap().def_span(sp);
917918
let mut db = cx.struct_span_lint(UNCONDITIONAL_RECURSION,
918919
sp,
919920
"function cannot return without recurring");
921+
db.span_label(sp, "cannot return without recurring");
920922
// offer some help to the programmer.
921923
for call in &self_call_spans {
922-
db.span_note(*call, "recursive call site");
924+
db.span_label(*call, "recursive call site");
923925
}
924-
db.help("a `loop` may express intention \
925-
better if this is on purpose");
926+
db.help("a `loop` may express intention better if this is on purpose");
926927
db.emit();
927928
}
928929

src/test/ui/coherence-overlap-downstream.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ error[E0119]: conflicting implementations of trait `Sweet`:
22
--> $DIR/coherence-overlap-downstream.rs:18:1
33
|
44
17 | impl<T:Sugar> Sweet for T { }
5-
| ----------------------------- first implementation here
5+
| ------------------------- first implementation here
66
18 | impl<T:Fruit> Sweet for T { }
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
88

99
error[E0119]: conflicting implementations of trait `Foo<_>` for type `i32`:
1010
--> $DIR/coherence-overlap-downstream.rs:24:1
1111
|
1212
23 | impl<X, T> Foo<X> for T where T: Bar<X> {}
13-
| ------------------------------------------ first implementation here
13+
| --------------------------------------- first implementation here
1414
24 | impl<X> Foo<X> for i32 {}
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
15+
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
1616
|
1717
= note: downstream crates may implement trait `Bar<_>` for type `i32`
1818

src/test/ui/coherence-overlap-issue-23516.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `Sweet` for type `std::boxed:
22
--> $DIR/coherence-overlap-issue-23516.rs:18:1
33
|
44
17 | impl<T:Sugar> Sweet for T { }
5-
| ----------------------------- first implementation here
5+
| ------------------------- first implementation here
66
18 | impl<U:Sugar> Sweet for Box<U> { }
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
88
|
99
= note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
1010

src/test/ui/coherence-overlap-upstream.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `Foo` for type `i16`:
22
--> $DIR/coherence-overlap-upstream.rs:22:1
33
|
44
21 | impl<T> Foo for T where T: Remote {}
5-
| ------------------------------------ first implementation here
5+
| --------------------------------- first implementation here
66
22 | impl Foo for i16 {}
7-
| ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
7+
| ^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
88
|
99
= note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions
1010

src/test/ui/e0119/complex-impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0119]: conflicting implementations of trait `complex_impl_support::Extern
22
--> $DIR/complex-impl.rs:19:1
33
|
44
19 | impl<R> External for (Q, R) {} //~ ERROR must be used
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: conflicting implementation in crate `complex_impl_support`:
88
- impl<'a, 'b, 'c, T, U, V, W> complex_impl_support::External for (T, complex_impl_support::M<'a, 'b, 'c, std::boxed::Box<U>, V, W>)

src/test/ui/e0119/conflict-with-std.stderr

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>`:
22
--> $DIR/conflict-with-std.rs:17:1
33
|
4-
17 | / impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
5-
18 | | fn as_ref(&self) -> &Q {
6-
19 | | &**self
7-
20 | | }
8-
21 | | }
9-
| |_^
4+
17 | impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
106
|
117
= note: conflicting implementation in crate `alloc`:
128
- impl<T> std::convert::AsRef<T> for std::boxed::Box<T>
@@ -15,26 +11,17 @@ error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for
1511
error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`:
1612
--> $DIR/conflict-with-std.rs:24:1
1713
|
18-
24 | / impl From<S> for S { //~ ERROR conflicting implementations
19-
25 | | fn from(s: S) -> S {
20-
26 | | s
21-
27 | | }
22-
28 | | }
23-
| |_^
14+
24 | impl From<S> for S { //~ ERROR conflicting implementations
15+
| ^^^^^^^^^^^^^^^^^^
2416
|
2517
= note: conflicting implementation in crate `core`:
2618
- impl<T> std::convert::From<T> for T;
2719

2820
error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X`:
2921
--> $DIR/conflict-with-std.rs:31:1
3022
|
31-
31 | / impl TryFrom<X> for X { //~ ERROR conflicting implementations
32-
32 | | type Error = ();
33-
33 | | fn try_from(u: X) -> Result<X, ()> {
34-
34 | | Ok(u)
35-
35 | | }
36-
36 | | }
37-
| |_^
23+
31 | impl TryFrom<X> for X { //~ ERROR conflicting implementations
24+
| ^^^^^^^^^^^^^^^^^^^^^
3825
|
3926
= note: conflicting implementation in crate `core`:
4027
- impl<T, U> std::convert::TryFrom<U> for T

src/test/ui/e0119/issue-23563.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0119]: conflicting implementations of trait `a::LolFrom<&[_]>` for type `LocalType<_>`:
22
--> $DIR/issue-23563.rs:23:1
33
|
4-
23 | / impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { //~ ERROR conflicting implementations of trait
5-
24 | | fn from(_: &'a [T]) -> LocalType<T> { LocalType(None) }
6-
25 | | }
7-
| |_^
4+
23 | impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { //~ ERROR conflicting implementations of trait
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
|
97
= note: conflicting implementation in crate `issue_23563_a`:
108
- impl<T, U> a::LolFrom<T> for U

src/test/ui/e0119/issue-27403.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
error[E0119]: conflicting implementations of trait `std::convert::Into<_>` for type `GenX<_>`:
22
--> $DIR/issue-27403.rs:15:1
33
|
4-
15 | / impl<S> Into<S> for GenX<S> { //~ ERROR conflicting implementations
5-
16 | | fn into(self) -> S {
6-
17 | | self.inner
7-
18 | | }
8-
19 | | }
9-
| |_^
4+
15 | impl<S> Into<S> for GenX<S> { //~ ERROR conflicting implementations
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
106
|
117
= note: conflicting implementation in crate `core`:
128
- impl<T, U> std::convert::Into<U> for T

src/test/ui/e0119/issue-28981.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0119]: conflicting implementations of trait `std::ops::Deref` for type `&
22
--> $DIR/issue-28981.rs:15:1
33
|
44
15 | impl<Foo> Deref for Foo { } //~ ERROR must be used
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: conflicting implementation in crate `core`:
88
- impl<'a, T> std::ops::Deref for &'a T

src/test/ui/e0119/so-37347311.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
error[E0119]: conflicting implementations of trait `std::convert::From<MyError<_>>` for type `MyError<_>`:
22
--> $DIR/so-37347311.rs:21:1
33
|
4-
21 | / impl<S: Storage> From<S::Error> for MyError<S> { //~ ERROR conflicting implementations
5-
22 | | fn from(error: S::Error) -> MyError<S> {
6-
23 | | MyError::StorageProblem(error)
7-
24 | | }
8-
25 | | }
9-
| |_^
4+
21 | impl<S: Storage> From<S::Error> for MyError<S> { //~ ERROR conflicting implementations
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106
|
117
= note: conflicting implementation in crate `core`:
128
- impl<T> std::convert::From<T> for T;

src/test/ui/feature-gate-overlapping_marker_traits.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `MyMarker`:
22
--> $DIR/feature-gate-overlapping_marker_traits.rs:16:1
33
|
44
15 | impl<T: Display> MyMarker for T {}
5-
| ---------------------------------- first implementation here
5+
| ------------------------------- first implementation here
66
16 | impl<T: Debug> MyMarker for T {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
88

99
error: aborting due to previous error
1010

src/test/ui/issue-28568.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `MyStruct`:
22
--> $DIR/issue-28568.rs:17:1
33
|
4-
13 | / impl Drop for MyStruct {
5-
14 | | fn drop(&mut self) { }
6-
15 | | }
7-
| |_- first implementation here
8-
16 |
9-
17 | / impl Drop for MyStruct {
10-
18 | | //~^ ERROR conflicting implementations of trait
11-
19 | | fn drop(&mut self) { }
12-
20 | | }
13-
| |_^ conflicting implementation for `MyStruct`
4+
13 | impl Drop for MyStruct {
5+
| ---------------------- first implementation here
6+
...
7+
17 | impl Drop for MyStruct {
8+
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyStruct`
149

1510
error: aborting due to previous error
1611

0 commit comments

Comments
 (0)