Skip to content

Commit 0382c00

Browse files
committed
Defining use errors yield the error type to reduce irrelevant follow-up diagnostics
1 parent d9d4a52 commit 0382c00

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11091109
} else {
11101110
// Don't emit multiple errors for the same set of substs
11111111
opaque_defn.substs.push(substs);
1112-
/*opaque_defn.concrete_ty = tcx.ty_error_with_message(
1112+
opaque_defn.concrete_ty = tcx.ty_error_with_message(
11131113
self.value_span,
11141114
"defining use generics differ from previous defining use",
1115-
);*/
1115+
);
11161116
tcx.sess
11171117
.struct_span_err(
11181118
self.value_span,

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(min_type_alias_impl_trait)]
66

77
type X<A, B> = impl Into<&'static A>;
8-
//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
98

109
fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
1110
//~^ ERROR defining use generics `[B, A]` differ from previous defining use
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
error: defining use generics `[B, A]` differ from previous defining use
2-
--> $DIR/multiple-def-uses-in-one-fn.rs:10:45
2+
--> $DIR/multiple-def-uses-in-one-fn.rs:9:45
33
|
44
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
note: previous defining use with different generics `[A, B]` found here
8-
--> $DIR/multiple-def-uses-in-one-fn.rs:10:45
8+
--> $DIR/multiple-def-uses-in-one-fn.rs:9:45
99
|
1010
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
1111
| ^^^^^^^^^^^^^^^^^^
1212

13-
error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied
14-
--> $DIR/multiple-def-uses-in-one-fn.rs:7:16
15-
|
16-
LL | type X<A, B> = impl Into<&'static A>;
17-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
18-
|
19-
= note: required because of the requirements on the impl of `Into<&'static B>` for `&A`
20-
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
21-
|
22-
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) where &'static B: From<&A> {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
2513
error: defining use generics `[B, A]` differ from previous defining use
26-
--> $DIR/multiple-def-uses-in-one-fn.rs:10:1
14+
--> $DIR/multiple-def-uses-in-one-fn.rs:9:1
2715
|
2816
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
2917
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3018
|
3119
note: previous defining use with different generics `[A, B]` found here
32-
--> $DIR/multiple-def-uses-in-one-fn.rs:10:1
20+
--> $DIR/multiple-def-uses-in-one-fn.rs:9:1
3321
|
3422
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
3523
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3624

37-
error: aborting due to 3 previous errors
25+
error: aborting due to 2 previous errors
3826

39-
For more information about this error, try `rustc --explain E0277`.

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>)
1313
}
1414

1515
fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
16+
//~^ ERROR concrete type differs from previous defining opaque type use
1617
(a, b) //~ ERROR mismatched types
1718
}
1819

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ LL | fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0308]: mismatched types
26-
--> $DIR/multiple-def-uses-in-one-fn3.rs:16:9
26+
--> $DIR/multiple-def-uses-in-one-fn3.rs:17:9
2727
|
2828
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
2929
| - - found type parameter
3030
| |
3131
| expected type parameter
32+
LL |
3233
LL | (a, b)
3334
| ^ expected type parameter `A`, found type parameter `B`
3435
|
@@ -37,6 +38,18 @@ LL | (a, b)
3738
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
3839
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
3940

40-
error: aborting due to 3 previous errors
41+
error: concrete type differs from previous defining opaque type use
42+
--> $DIR/multiple-def-uses-in-one-fn3.rs:15:1
43+
|
44+
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `A`
46+
|
47+
note: previous use here
48+
--> $DIR/multiple-def-uses-in-one-fn3.rs:9:1
49+
|
50+
LL | fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>) {
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
error: aborting due to 4 previous errors
4154

4255
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)