Skip to content

Commit 59d0bff

Browse files
committed
Reduce follow-up errors that are not helpful
1 parent 6560d77 commit 59d0bff

27 files changed

+40
-210
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5858
) -> VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>> {
5959
opaque_ty_decls
6060
.into_iter()
61-
.filter_map(|(opaque_type_key, (concrete_type, decl_span, origin))| {
61+
.map(|(opaque_type_key, (concrete_type, decl_span, origin))| {
6262
let substs = opaque_type_key.substs;
6363
// FIXME: why are the spans in decl_span often DUMMY_SP?
6464
let span = decl_span.substitute_dummy(span);
@@ -112,8 +112,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
112112
span,
113113
);
114114

115-
check_opaque_type_parameter_valid(infcx.tcx, opaque_type_key, origin, span)
116-
.then_some((opaque_type_key, remapped_type))
115+
(
116+
opaque_type_key,
117+
if check_opaque_type_parameter_valid(infcx.tcx, opaque_type_key, origin, span) {
118+
remapped_type
119+
} else {
120+
infcx.tcx.ty_error()
121+
},
122+
)
117123
})
118124
.collect()
119125
}

src/test/ui/generic-associated-types/issue-88595.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct C;
1818
impl<'a> A<'a> for C {
1919
type B<'b> = impl Clone;
2020
//~^ ERROR: lifetime bound not satisfied
21-
//~| ERROR: unconstrained opaque type
2221

2322
fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope
2423
}

src/test/ui/generic-associated-types/issue-88595.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | type B<'b> = impl Clone;
1616
| ^^
1717

1818
error: non-defining opaque type use in defining scope
19-
--> $DIR/issue-88595.rs:23:35
19+
--> $DIR/issue-88595.rs:22:35
2020
|
2121
LL | fn a(&'a self) -> Self::B<'a> {}
2222
| ^^
@@ -29,14 +29,6 @@ LL | impl<'a> A<'a> for C {
2929
LL | type B<'b> = impl Clone;
3030
| ^^
3131

32-
error: unconstrained opaque type
33-
--> $DIR/issue-88595.rs:19:18
34-
|
35-
LL | type B<'b> = impl Clone;
36-
| ^^^^^^^^^^
37-
|
38-
= note: `B` must be used in combination with a concrete type within the same module
39-
40-
error: aborting due to 3 previous errors
32+
error: aborting due to 2 previous errors
4133

4234
For more information about this error, try `rustc --explain E0478`.

src/test/ui/type-alias-impl-trait/bound_reduction2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait TraitWithAssoc {
77
}
88

99
type Foo<V> = impl Trait<V>;
10-
//~^ ERROR unconstrained opaque type
1110

1211
trait Trait<U> {}
1312

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: non-defining opaque type use in defining scope
2-
--> $DIR/bound_reduction2.rs:17:5
2+
--> $DIR/bound_reduction2.rs:16:5
33
|
44
LL | ()
55
| ^^
@@ -10,13 +10,5 @@ note: used non-generic type `<T as TraitWithAssoc>::Assoc` for generic parameter
1010
LL | type Foo<V> = impl Trait<V>;
1111
| ^
1212

13-
error: unconstrained opaque type
14-
--> $DIR/bound_reduction2.rs:9:15
15-
|
16-
LL | type Foo<V> = impl Trait<V>;
17-
| ^^^^^^^^^^^^^
18-
|
19-
= note: `Foo` must be used in combination with a concrete type within the same module
20-
21-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2214

src/test/ui/type-alias-impl-trait/bounds-are-checked.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(type_alias_impl_trait)]
55

66
type X<'a> = impl Into<&'static str> + From<&'a str>;
7-
//~^ ERROR unconstrained opaque type
87

98
fn f<'a: 'static>(t: &'a str) -> X<'a> {
109
//~^ WARNING unnecessary lifetime parameter
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
warning: unnecessary lifetime parameter `'a`
2-
--> $DIR/bounds-are-checked.rs:9:6
2+
--> $DIR/bounds-are-checked.rs:8:6
33
|
44
LL | fn f<'a: 'static>(t: &'a str) -> X<'a> {
55
| ^^^^^^^^^^^
66
|
77
= help: you can use the `'static` lifetime directly, in place of `'a`
88

99
error: non-defining opaque type use in defining scope
10-
--> $DIR/bounds-are-checked.rs:11:5
10+
--> $DIR/bounds-are-checked.rs:10:5
1111
|
1212
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
1313
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
1414
...
1515
LL | t
1616
| ^
1717

18-
error: unconstrained opaque type
19-
--> $DIR/bounds-are-checked.rs:6:14
20-
|
21-
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23-
|
24-
= note: `X` must be used in combination with a concrete type within the same module
25-
26-
error: aborting due to 2 previous errors; 1 warning emitted
18+
error: aborting due to previous error; 1 warning emitted
2719

src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fn main() {}
44

55
type Two<'a, 'b> = impl std::fmt::Debug;
6-
//~^ ERROR unconstrained opaque type
6+
77

88
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
99
t

src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,5 @@ note: lifetime used multiple times
1010
LL | type Two<'a, 'b> = impl std::fmt::Debug;
1111
| ^^ ^^
1212

13-
error: unconstrained opaque type
14-
--> $DIR/generic_duplicate_lifetime_param.rs:5:20
15-
|
16-
LL | type Two<'a, 'b> = impl std::fmt::Debug;
17-
| ^^^^^^^^^^^^^^^^^^^^
18-
|
19-
= note: `Two` must be used in combination with a concrete type within the same module
20-
21-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2214

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ fn main() {}
66

77
// test that unused generic parameters are ok
88
type TwoTys<T, U> = impl Debug;
9-
//~^ ERROR unconstrained opaque type
9+
1010
type TwoLifetimes<'a, 'b> = impl Debug;
11-
//~^ ERROR unconstrained opaque type
11+
1212
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
13-
//~^ ERROR unconstrained opaque type
13+
1414

1515
fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
1616
t

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ note: type used multiple times
1010
LL | type TwoTys<T, U> = impl Debug;
1111
| ^ ^
1212

13-
error: unconstrained opaque type
14-
--> $DIR/generic_duplicate_param_use.rs:8:21
15-
|
16-
LL | type TwoTys<T, U> = impl Debug;
17-
| ^^^^^^^^^^
18-
|
19-
= note: `TwoTys` must be used in combination with a concrete type within the same module
20-
2113
error: non-defining opaque type use in defining scope
2214
--> $DIR/generic_duplicate_param_use.rs:21:5
2315
|
@@ -30,14 +22,6 @@ note: lifetime used multiple times
3022
LL | type TwoLifetimes<'a, 'b> = impl Debug;
3123
| ^^ ^^
3224

33-
error: unconstrained opaque type
34-
--> $DIR/generic_duplicate_param_use.rs:10:29
35-
|
36-
LL | type TwoLifetimes<'a, 'b> = impl Debug;
37-
| ^^^^^^^^^^
38-
|
39-
= note: `TwoLifetimes` must be used in combination with a concrete type within the same module
40-
4125
error: non-defining opaque type use in defining scope
4226
--> $DIR/generic_duplicate_param_use.rs:26:5
4327
|
@@ -50,13 +34,5 @@ note: constant used multiple times
5034
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
5135
| ^ ^
5236

53-
error: unconstrained opaque type
54-
--> $DIR/generic_duplicate_param_use.rs:12:50
55-
|
56-
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
57-
| ^^^^^^^^^^
58-
|
59-
= note: `TwoConsts` must be used in combination with a concrete type within the same module
60-
61-
error: aborting due to 6 previous errors
37+
error: aborting due to 3 previous errors
6238

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ fn main() {}
88
type Two<T, U> = impl Debug;
99
//~^ ERROR `T` doesn't implement `Debug`
1010

11-
fn one<T: Debug>(t: T) -> Two<T, T> {
12-
t
13-
//~^ ERROR non-defining opaque type use in defining scope
14-
}
15-
1611
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
1712
t
1813
}
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error: non-defining opaque type use in defining scope
2-
--> $DIR/generic_duplicate_param_use2.rs:12:5
3-
|
4-
LL | t
5-
| ^
6-
|
7-
note: type used multiple times
8-
--> $DIR/generic_duplicate_param_use2.rs:8:10
9-
|
10-
LL | type Two<T, U> = impl Debug;
11-
| ^ ^
12-
131
error[E0277]: `T` doesn't implement `Debug`
142
--> $DIR/generic_duplicate_param_use2.rs:8:18
153
|
@@ -21,6 +9,6 @@ help: consider restricting type parameter `T`
219
LL | type Two<T: std::fmt::Debug, U> = impl Debug;
2210
| +++++++++++++++++
2311

24-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
2513

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

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ fn main() {}
88
type Two<T, U> = impl Debug;
99
//~^ ERROR `T` doesn't implement `Debug`
1010

11-
fn one<T: Debug>(t: T) -> Two<T, T> {
12-
t
13-
//~^ ERROR non-defining opaque type use in defining scope
14-
}
15-
1611
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
1712
t
1813
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
error: non-defining opaque type use in defining scope
2-
--> $DIR/generic_duplicate_param_use3.rs:12:5
3-
|
4-
LL | t
5-
| ^
6-
|
7-
note: type used multiple times
8-
--> $DIR/generic_duplicate_param_use3.rs:8:10
9-
|
10-
LL | type Two<T, U> = impl Debug;
11-
| ^ ^
12-
131
error: concrete type differs from previous defining opaque type use
14-
--> $DIR/generic_duplicate_param_use3.rs:20:1
2+
--> $DIR/generic_duplicate_param_use3.rs:15:1
153
|
164
LL | fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
175
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `T`, got `U`
186
|
197
note: previous use here
20-
--> $DIR/generic_duplicate_param_use3.rs:16:1
8+
--> $DIR/generic_duplicate_param_use3.rs:11:1
219
|
2210
LL | fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
2311
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -33,6 +21,6 @@ help: consider restricting type parameter `T`
3321
LL | type Two<T: std::fmt::Debug, U> = impl Debug;
3422
| +++++++++++++++++
3523

36-
error: aborting due to 3 previous errors
24+
error: aborting due to 2 previous errors
3725

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

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ fn main() {}
88
type Two<T, U> = impl Debug;
99
//~^ ERROR `U` doesn't implement `Debug`
1010

11-
fn one<T: Debug>(t: T) -> Two<T, T> {
12-
t
13-
//~^ ERROR non-defining opaque type use in defining scope
14-
}
15-
1611
fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
1712
u
1813
}
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error: non-defining opaque type use in defining scope
2-
--> $DIR/generic_duplicate_param_use4.rs:12:5
3-
|
4-
LL | t
5-
| ^
6-
|
7-
note: type used multiple times
8-
--> $DIR/generic_duplicate_param_use4.rs:8:10
9-
|
10-
LL | type Two<T, U> = impl Debug;
11-
| ^ ^
12-
131
error[E0277]: `U` doesn't implement `Debug`
142
--> $DIR/generic_duplicate_param_use4.rs:8:18
153
|
@@ -21,6 +9,6 @@ help: consider restricting type parameter `U`
219
LL | type Two<T, U: std::fmt::Debug> = impl Debug;
2210
| +++++++++++++++++
2311

24-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
2513

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

src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::fmt::Debug;
55
fn main() {}
66

77
type OneTy<T> = impl Debug;
8-
//~^ ERROR unconstrained opaque type
8+
99
type OneLifetime<'a> = impl Debug;
10-
//~^ ERROR unconstrained opaque type
10+
1111
type OneConst<const X: usize> = impl Debug;
12-
//~^ ERROR unconstrained opaque type
12+
1313

1414
// Not defining uses, because they doesn't define *all* possible generics.
1515

src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ note: used non-generic type `u32` for generic parameter
1010
LL | type OneTy<T> = impl Debug;
1111
| ^
1212

13-
error: unconstrained opaque type
14-
--> $DIR/generic_nondefining_use.rs:7:17
15-
|
16-
LL | type OneTy<T> = impl Debug;
17-
| ^^^^^^^^^^
18-
|
19-
= note: `OneTy` must be used in combination with a concrete type within the same module
20-
2113
error: non-defining opaque type use in defining scope
2214
--> $DIR/generic_nondefining_use.rs:22:5
2315
|
@@ -27,14 +19,6 @@ LL | type OneLifetime<'a> = impl Debug;
2719
LL | 6u32
2820
| ^^^^
2921

30-
error: unconstrained opaque type
31-
--> $DIR/generic_nondefining_use.rs:9:24
32-
|
33-
LL | type OneLifetime<'a> = impl Debug;
34-
| ^^^^^^^^^^
35-
|
36-
= note: `OneLifetime` must be used in combination with a concrete type within the same module
37-
3822
error: non-defining opaque type use in defining scope
3923
--> $DIR/generic_nondefining_use.rs:27:5
4024
|
@@ -47,13 +31,5 @@ note: used non-generic constant `123_usize` for generic parameter
4731
LL | type OneConst<const X: usize> = impl Debug;
4832
| ^
4933

50-
error: unconstrained opaque type
51-
--> $DIR/generic_nondefining_use.rs:11:33
52-
|
53-
LL | type OneConst<const X: usize> = impl Debug;
54-
| ^^^^^^^^^^
55-
|
56-
= note: `OneConst` must be used in combination with a concrete type within the same module
57-
58-
error: aborting due to 6 previous errors
34+
error: aborting due to 3 previous errors
5935

src/test/ui/type-alias-impl-trait/issue-60564.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ trait IterBits {
66
}
77

88
type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
9-
//~^ ERROR unconstrained opaque type
109

1110
impl<T: Copy, E> IterBits for T
1211
where

0 commit comments

Comments
 (0)