diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-09-06 08:36:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-06 08:36:08 +0900 |
| commit | c3faa2250c67ac040fba77828b7e042940412110 (patch) | |
| tree | b79676cb6e9b3bbd7eb11d0f40ca203141bebe4b | |
| parent | c633b0a72c6e1d58b7251e2011b5b8d7a1fff4b1 (diff) | |
| parent | 3b3c7063c23d43b30077fb5f997456e60e5806a6 (diff) | |
| download | rust-c3faa2250c67ac040fba77828b7e042940412110.tar.gz rust-c3faa2250c67ac040fba77828b7e042940412110.zip | |
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.
| -rw-r--r-- | compiler/rustc_typeck/src/check/fn_ctxt/checks.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/typeck/point-at-type-param-in-path-expr.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/typeck/point-at-type-param-in-path-expr.stderr | 17 |
3 files changed, 33 insertions, 10 deletions
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 9157b83330d..311fcaadaa9 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -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, ..) => { diff --git a/src/test/ui/typeck/point-at-type-param-in-path-expr.rs b/src/test/ui/typeck/point-at-type-param-in-path-expr.rs new file mode 100644 index 00000000000..9a21536f9b1 --- /dev/null +++ b/src/test/ui/typeck/point-at-type-param-in-path-expr.rs @@ -0,0 +1,6 @@ +fn foo<T: std::fmt::Display>() {} + +fn main() { + let x = foo::<()>; + //~^ ERROR `()` doesn't implement `std::fmt::Display` +} diff --git a/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr b/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr new file mode 100644 index 00000000000..1feaa0508bf --- /dev/null +++ b/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr @@ -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`. |
