Skip to content

Commit

Permalink
Avoid follow up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 10, 2024
1 parent 972c95a commit 0e82aae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
15 changes: 15 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ impl TaitConstraintLocator<'_> {
debug!("no constraint: no typeck results");
return;
}

if let Some(hir_sig) = self.tcx.hir_node_by_def_id(item_def_id).fn_decl() {
if hir_sig.output.get_infer_ret_ty().is_some() {
let guar = self.tcx.dcx().span_delayed_bug(
hir_sig.output.span(),
"inferring return types and opaque types do not mix well",
);
self.found = Some(ty::OpaqueHiddenType {
span: DUMMY_SP,
ty: Ty::new_error(self.tcx, guar),
});
return;
}
}

// Calling `mir_borrowck` can lead to cycle errors through
// const-checking, avoid calling it if we don't have to.
// ```rust
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/type-alias-impl-trait/issue-77179.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ type Pointer<T> = impl std::ops::Deref<Target = T>;

fn test() -> Pointer<_> {
//~^ ERROR: the placeholder `_` is not allowed within types
//~| ERROR: non-defining opaque type use in defining scope
Box::new(1)
//~^ ERROR expected generic type parameter, found `i32`
}

fn main() {
Expand Down
26 changes: 2 additions & 24 deletions tests/ui/type-alias-impl-trait/issue-77179.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,6 @@ LL | fn test() -> Pointer<_> {
| | not allowed in type signatures
| help: replace with the correct return type: `Pointer<i32>`

error[E0792]: non-defining opaque type use in defining scope
--> $DIR/issue-77179.rs:7:14
|
LL | fn test() -> Pointer<_> {
| ^^^^^^^^^^ argument `i32` is not a generic parameter
|
note: for this opaque type
--> $DIR/issue-77179.rs:5:19
|
LL | type Pointer<T> = impl std::ops::Deref<Target = T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0792]: expected generic type parameter, found `i32`
--> $DIR/issue-77179.rs:10:5
|
LL | type Pointer<T> = impl std::ops::Deref<Target = T>;
| - this generic parameter must be used with a generic type parameter
...
LL | Box::new(1)
| ^^^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0121, E0792.
For more information about an error, try `rustc --explain E0121`.
For more information about this error, try `rustc --explain E0121`.

0 comments on commit 0e82aae

Please sign in to comment.