Skip to content

Use def span for conflicting impls and recursive fn #46804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,28 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
}),
if used_to_be_allowed { " (E0119)" } else { "" }
);
let impl_span = tcx.sess.codemap().def_span(
tcx.span_of_impl(impl_def_id).unwrap()
);
let mut err = if used_to_be_allowed {
tcx.struct_span_lint_node(
lint::builtin::INCOHERENT_FUNDAMENTAL_IMPLS,
tcx.hir.as_local_node_id(impl_def_id).unwrap(),
tcx.span_of_impl(impl_def_id).unwrap(),
impl_span,
&msg)
} else {
struct_span_err!(tcx.sess,
tcx.span_of_impl(impl_def_id).unwrap(),
impl_span,
E0119,
"{}",
msg)
};

match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
err.span_label(span, format!("first implementation here"));
err.span_label(tcx.span_of_impl(impl_def_id).unwrap(),
err.span_label(tcx.sess.codemap().def_span(span),
format!("first implementation here"));
err.span_label(impl_span,
format!("conflicting implementation{}",
overlap.self_desc
.map_or(String::new(),
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl MissingDoc {
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.check_name("doc"));
if !has_doc {
cx.span_lint(MISSING_DOCS,
sp,
cx.tcx.sess.codemap().def_span(sp),
&format!("missing documentation for {}", desc));
}
}
Expand Down Expand Up @@ -914,15 +914,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
// no break */ }`) shouldn't be linted unless it actually
// recurs.
if !reached_exit_without_self_call && !self_call_spans.is_empty() {
let sp = cx.tcx.sess.codemap().def_span(sp);
let mut db = cx.struct_span_lint(UNCONDITIONAL_RECURSION,
sp,
"function cannot return without recurring");
db.span_label(sp, "cannot return without recurring");
// offer some help to the programmer.
for call in &self_call_spans {
db.span_note(*call, "recursive call site");
db.span_label(*call, "recursive call site");
}
db.help("a `loop` may express intention \
better if this is on purpose");
db.help("a `loop` may express intention better if this is on purpose");
db.emit();
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/coherence-overlap-downstream.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ error[E0119]: conflicting implementations of trait `Sweet`:
--> $DIR/coherence-overlap-downstream.rs:18:1
|
17 | impl<T:Sugar> Sweet for T { }
| ----------------------------- first implementation here
| ------------------------- first implementation here
18 | impl<T:Fruit> Sweet for T { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence-overlap-issue-23516.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `Sweet` for type `std::boxed:
--> $DIR/coherence-overlap-issue-23516.rs:18:1
|
17 | impl<T:Sugar> Sweet for T { }
| ----------------------------- first implementation here
| ------------------------- first implementation here
18 | impl<U:Sugar> Sweet for Box<U> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
|
= note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence-overlap-upstream.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `Foo` for type `i16`:
--> $DIR/coherence-overlap-upstream.rs:22:1
|
21 | impl<T> Foo for T where T: Remote {}
| ------------------------------------ first implementation here
| --------------------------------- first implementation here
22 | impl Foo for i16 {}
| ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
| ^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
|
= note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/e0119/complex-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0119]: conflicting implementations of trait `complex_impl_support::Extern
--> $DIR/complex-impl.rs:19:1
|
19 | impl<R> External for (Q, R) {} //~ ERROR must be used
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `complex_impl_support`:
- 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>)
Expand Down
25 changes: 6 additions & 19 deletions src/test/ui/e0119/conflict-with-std.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>`:
--> $DIR/conflict-with-std.rs:17:1
|
17 | / impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
18 | | fn as_ref(&self) -> &Q {
19 | | &**self
20 | | }
21 | | }
| |_^
17 | impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `alloc`:
- impl<T> std::convert::AsRef<T> for std::boxed::Box<T>
Expand All @@ -15,26 +11,17 @@ error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for
error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`:
--> $DIR/conflict-with-std.rs:24:1
|
24 | / impl From<S> for S { //~ ERROR conflicting implementations
25 | | fn from(s: S) -> S {
26 | | s
27 | | }
28 | | }
| |_^
24 | impl From<S> for S { //~ ERROR conflicting implementations
| ^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;

error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X`:
--> $DIR/conflict-with-std.rs:31:1
|
31 | / impl TryFrom<X> for X { //~ ERROR conflicting implementations
32 | | type Error = ();
33 | | fn try_from(u: X) -> Result<X, ()> {
34 | | Ok(u)
35 | | }
36 | | }
| |_^
31 | impl TryFrom<X> for X { //~ ERROR conflicting implementations
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T, U> std::convert::TryFrom<U> for T
Expand Down
6 changes: 2 additions & 4 deletions src/test/ui/e0119/issue-23563.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0119]: conflicting implementations of trait `a::LolFrom<&[_]>` for type `LocalType<_>`:
--> $DIR/issue-23563.rs:23:1
|
23 | / impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { //~ ERROR conflicting implementations of trait
24 | | fn from(_: &'a [T]) -> LocalType<T> { LocalType(None) }
25 | | }
| |_^
23 | impl<'a, T> LolFrom<&'a [T]> for LocalType<T> { //~ ERROR conflicting implementations of trait
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `issue_23563_a`:
- impl<T, U> a::LolFrom<T> for U
Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/e0119/issue-27403.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
error[E0119]: conflicting implementations of trait `std::convert::Into<_>` for type `GenX<_>`:
--> $DIR/issue-27403.rs:15:1
|
15 | / impl<S> Into<S> for GenX<S> { //~ ERROR conflicting implementations
16 | | fn into(self) -> S {
17 | | self.inner
18 | | }
19 | | }
| |_^
15 | impl<S> Into<S> for GenX<S> { //~ ERROR conflicting implementations
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T, U> std::convert::Into<U> for T
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/e0119/issue-28981.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0119]: conflicting implementations of trait `std::ops::Deref` for type `&
--> $DIR/issue-28981.rs:15:1
|
15 | impl<Foo> Deref for Foo { } //~ ERROR must be used
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<'a, T> std::ops::Deref for &'a T
Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/e0119/so-37347311.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
error[E0119]: conflicting implementations of trait `std::convert::From<MyError<_>>` for type `MyError<_>`:
--> $DIR/so-37347311.rs:21:1
|
21 | / impl<S: Storage> From<S::Error> for MyError<S> { //~ ERROR conflicting implementations
22 | | fn from(error: S::Error) -> MyError<S> {
23 | | MyError::StorageProblem(error)
24 | | }
25 | | }
| |_^
21 | impl<S: Storage> From<S::Error> for MyError<S> { //~ ERROR conflicting implementations
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/feature-gate-overlapping_marker_traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0119]: conflicting implementations of trait `MyMarker`:
--> $DIR/feature-gate-overlapping_marker_traits.rs:16:1
|
15 | impl<T: Display> MyMarker for T {}
| ---------------------------------- first implementation here
| ------------------------------- first implementation here
16 | impl<T: Debug> MyMarker for T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to previous error

15 changes: 5 additions & 10 deletions src/test/ui/issue-28568.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `MyStruct`:
--> $DIR/issue-28568.rs:17:1
|
13 | / impl Drop for MyStruct {
14 | | fn drop(&mut self) { }
15 | | }
| |_- first implementation here
16 |
17 | / impl Drop for MyStruct {
18 | | //~^ ERROR conflicting implementations of trait
19 | | fn drop(&mut self) { }
20 | | }
| |_^ conflicting implementation for `MyStruct`
13 | impl Drop for MyStruct {
| ---------------------- first implementation here
...
17 | impl Drop for MyStruct {
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyStruct`

error: aborting due to previous error

Loading