Skip to content

Commit b952ada

Browse files
committed
Use ty::Error for opaque types with errors in its bounds.
This reduces unhelpful diagnostics down the road.
1 parent 34de78f commit b952ada

File tree

7 files changed

+10
-38
lines changed

7 files changed

+10
-38
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10221022
if let ty::PredicateKind::Projection(projection) = predicate.kind().skip_binder() {
10231023
if projection.ty.references_error() {
10241024
// No point on adding these obligations since there's a type error involved.
1025-
return ty_var;
1025+
return tcx.ty_error();
10261026
}
10271027
}
10281028
// Change the predicate to refer to the type variable,

src/test/ui/async-await/issues/issue-65159.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ async fn copy() -> Result<()>
66
//~^ ERROR this enum takes 2 generic arguments
77
{
88
Ok(())
9-
//~^ ERROR type annotations needed
109
}
1110

1211
fn main() { }

src/test/ui/async-await/issues/issue-65159.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ help: add missing generic argument
1616
LL | async fn copy() -> Result<(), E>
1717
| +++
1818

19-
error[E0282]: type annotations needed
20-
--> $DIR/issue-65159.rs:8:5
21-
|
22-
LL | Ok(())
23-
| ^^ cannot infer type for type parameter `E` declared on the enum `Result`
24-
25-
error: aborting due to 2 previous errors
19+
error: aborting due to previous error
2620

27-
Some errors have detailed explanations: E0107, E0282.
28-
For more information about an error, try `rustc --explain E0107`.
21+
For more information about this error, try `rustc --explain E0107`.

src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
1717
//~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
1818
//~^^ ERROR this struct takes 1 generic argument but 0 generic arguments were supplied
1919
LockedMarket(generator.lock().unwrap().buy())
20-
//~^ ERROR cannot return value referencing temporary value
2120
}
2221

2322
struct LockedMarket<T>(T);

src/test/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr

+4-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_>
77
| expected 0 lifetime arguments
88
|
99
note: struct defined here, with 0 lifetime parameters
10-
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8
10+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8
1111
|
1212
LL | struct LockedMarket<T>(T);
1313
| ^^^^^^^^^^^^
@@ -19,7 +19,7 @@ LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_>
1919
| ^^^^^^^^^^^^ expected 1 generic argument
2020
|
2121
note: struct defined here, with 1 generic parameter: `T`
22-
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:23:8
22+
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:22:8
2323
|
2424
LL | struct LockedMarket<T>(T);
2525
| ^^^^^^^^^^^^ -
@@ -28,16 +28,6 @@ help: add missing generic argument
2828
LL | async fn buy_lock(generator: &Mutex<MarketMultiplier>) -> LockedMarket<'_, T> {
2929
| +++
3030

31-
error[E0515]: cannot return value referencing temporary value
32-
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:19:5
33-
|
34-
LL | LockedMarket(generator.lock().unwrap().buy())
35-
| ^^^^^^^^^^^^^-------------------------^^^^^^^
36-
| | |
37-
| | temporary value created here
38-
| returns a value referencing data owned by the current function
39-
40-
error: aborting due to 3 previous errors
31+
error: aborting due to 2 previous errors
4132

42-
Some errors have detailed explanations: E0107, E0515.
43-
For more information about an error, try `rustc --explain E0107`.
33+
For more information about this error, try `rustc --explain E0107`.

src/test/ui/impl-trait/issue-72911.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint>
1616

1717
fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
1818
//~^ ERROR: failed to resolve
19-
//~| ERROR: `()` is not an iterator
2019
unimplemented!()
2120
}
2221

src/test/ui/impl-trait/issue-72911.stderr

+3-11
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ LL | fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = L
2828
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
2929
| -------------------------------------- returning this opaque type `FlatMap<impl Iterator, [type error], [closure@$DIR/issue-72911.rs:9:27: 9:51]>`
3030

31-
error[E0277]: `()` is not an iterator
32-
--> $DIR/issue-72911.rs:17:20
33-
|
34-
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
36-
|
37-
= help: the trait `Iterator` is not implemented for `()`
38-
39-
error: aborting due to 4 previous errors
31+
error: aborting due to 3 previous errors
4032

41-
Some errors have detailed explanations: E0277, E0433, E0720.
42-
For more information about an error, try `rustc --explain E0277`.
33+
Some errors have detailed explanations: E0433, E0720.
34+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)