Skip to content

Commit 8f6acb0

Browse files
authored
Rollup merge of #101425 - compiler-errors:point-at-ty-param, r=spastorino
Point at type parameter in plain path expr Slightly better error message for a kinda unique use case.
2 parents c95bb36 + 3b3c706 commit 8f6acb0

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1811,16 +1811,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18111811
return true;
18121812
}
18131813
}
1814-
// Notably, we only point to params that are local to the
1815-
// item we're checking, since those are the ones we are able
1816-
// to look in the final `hir::PathSegment` for. Everything else
1817-
// would require a deeper search into the `qpath` than I think
1818-
// is worthwhile.
1819-
if let Some(param_to_point_at) = param_to_point_at
1820-
&& self.point_at_path_if_possible(error, def_id, param_to_point_at, qpath)
1821-
{
1822-
return true;
1823-
}
1814+
}
1815+
// Notably, we only point to params that are local to the
1816+
// item we're checking, since those are the ones we are able
1817+
// to look in the final `hir::PathSegment` for. Everything else
1818+
// would require a deeper search into the `qpath` than I think
1819+
// is worthwhile.
1820+
if let Some(param_to_point_at) = param_to_point_at
1821+
&& self.point_at_path_if_possible(error, def_id, param_to_point_at, qpath)
1822+
{
1823+
return true;
18241824
}
18251825
}
18261826
hir::ExprKind::MethodCall(segment, args, ..) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo<T: std::fmt::Display>() {}
2+
3+
fn main() {
4+
let x = foo::<()>;
5+
//~^ ERROR `()` doesn't implement `std::fmt::Display`
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `()` doesn't implement `std::fmt::Display`
2+
--> $DIR/point-at-type-param-in-path-expr.rs:4:19
3+
|
4+
LL | let x = foo::<()>;
5+
| ^^ `()` cannot be formatted with the default formatter
6+
|
7+
= help: the trait `std::fmt::Display` is not implemented for `()`
8+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
9+
note: required by a bound in `foo`
10+
--> $DIR/point-at-type-param-in-path-expr.rs:1:11
11+
|
12+
LL | fn foo<T: std::fmt::Display>() {}
13+
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)