Skip to content

Commit

Permalink
Rollup merge of rust-lang#101425 - compiler-errors:point-at-ty-param,…
Browse files Browse the repository at this point in the history
… r=spastorino

Point at type parameter in plain path expr

Slightly better error message for a kinda unique use case.
  • Loading branch information
JohnTitor authored Sep 5, 2022
2 parents bcd5f19 + 3b3c706 commit 8f1ac8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
20 changes: 10 additions & 10 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,16 +1812,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true;
}
}
// Notably, we only point to params that are local to the
// item we're checking, since those are the ones we are able
// to look in the final `hir::PathSegment` for. Everything else
// would require a deeper search into the `qpath` than I think
// is worthwhile.
if let Some(param_to_point_at) = param_to_point_at
&& self.point_at_path_if_possible(error, def_id, param_to_point_at, qpath)
{
return true;
}
}
// Notably, we only point to params that are local to the
// item we're checking, since those are the ones we are able
// to look in the final `hir::PathSegment` for. Everything else
// would require a deeper search into the `qpath` than I think
// is worthwhile.
if let Some(param_to_point_at) = param_to_point_at
&& self.point_at_path_if_possible(error, def_id, param_to_point_at, qpath)
{
return true;
}
}
hir::ExprKind::MethodCall(segment, receiver, args, ..) => {
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/typeck/point-at-type-param-in-path-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn foo<T: std::fmt::Display>() {}

fn main() {
let x = foo::<()>;
//~^ ERROR `()` doesn't implement `std::fmt::Display`
}
17 changes: 17 additions & 0 deletions src/test/ui/typeck/point-at-type-param-in-path-expr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/point-at-type-param-in-path-expr.rs:4:19
|
LL | let x = foo::<()>;
| ^^ `()` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `foo`
--> $DIR/point-at-type-param-in-path-expr.rs:1:11
|
LL | fn foo<T: std::fmt::Display>() {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to previous error

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

0 comments on commit 8f1ac8c

Please sign in to comment.