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

0 commit comments

Comments
 (0)