Skip to content

Commit d05fea6

Browse files
Account for relative paths
1 parent c005e76 commit d05fea6

File tree

18 files changed

+112
-56
lines changed

18 files changed

+112
-56
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16451645
}
16461646
})
16471647
});
1648-
16491648
let fallback_param_to_point_at = predicate_substs.types().find_map(|ty| {
16501649
ty.walk().find_map(|arg| {
16511650
if let ty::GenericArgKind::Type(ty) = arg.unpack()
@@ -1660,8 +1659,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16601659
});
16611660

16621661
let hir = self.tcx.hir();
1662+
16631663
match hir.get(hir_id) {
1664-
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(hir::QPath::Resolved(_, path)), hir_id, .. }) => {
1664+
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(qpath), hir_id, .. }) => {
16651665
if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Call(callee, args), hir_id: call_hir_id, .. })
16661666
= hir.get(hir.get_parent_node(*hir_id))
16671667
&& callee.hir_id == *hir_id
@@ -1677,12 +1677,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16771677
return;
16781678
}
16791679

1680-
if let Some(param_to_point_at) = param_to_point_at
1680+
if let hir::QPath::Resolved(_, path) = qpath
1681+
&& let Some(param_to_point_at) = param_to_point_at
16811682
&& let Some(segment) = path.segments.last()
16821683
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
16831684
{
16841685
return;
16851686
}
1687+
1688+
if let hir::QPath::TypeRelative(_, segment) = qpath
1689+
&& let Some(param_to_point_at) = param_to_point_at
1690+
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
1691+
{
1692+
return;
1693+
}
16861694
}
16871695
}
16881696
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::MethodCall(segment, args, ..), .. }) => {
@@ -1727,6 +1735,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17271735
.enumerate()
17281736
.filter(|(_, ty)| ty.walk().any(|arg| arg == param_to_point_at))
17291737
.collect();
1738+
17301739
if let [(idx, _)] = args_referencing_param.as_slice()
17311740
&& let Some(arg) = args.get(*idx)
17321741
{

src/test/ui/async-await/issue-72442.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0277]: the trait bound `Option<&str>: AsRef<Path>` is not satisfied
2-
--> $DIR/issue-72442.rs:12:25
2+
--> $DIR/issue-72442.rs:12:36
33
|
44
LL | let mut f = File::open(path.to_str())?;
5-
| ^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
5+
| ---------- ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: required by a bound in `File::open`
810
--> $SRC_DIR/std/src/fs.rs:LL:COL

src/test/ui/async-await/pin-needed-to-poll-2.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0277]: `PhantomPinned` cannot be unpinned
2-
--> $DIR/pin-needed-to-poll-2.rs:43:9
2+
--> $DIR/pin-needed-to-poll-2.rs:43:18
33
|
44
LL | Pin::new(&mut self.sleep).poll(cx)
5-
| ^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
5+
| -------- ^^^^^^^^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= note: consider using `Box::pin`
810
note: required because it appears within the type `Sleep`

src/test/ui/box/into-boxed-slice-fail.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2-
--> $DIR/into-boxed-slice-fail.rs:7:13
2+
--> $DIR/into-boxed-slice-fail.rs:7:35
33
|
44
LL | let _ = Box::into_boxed_slice(boxed_slice);
5-
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
5+
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `[u8]`
810
note: required by a bound in `Box::<T, A>::into_boxed_slice`
@@ -21,10 +23,12 @@ LL | let _ = Box::into_boxed_slice(boxed_slice);
2123
= note: slice and array elements must have `Sized` type
2224

2325
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
24-
--> $DIR/into-boxed-slice-fail.rs:11:13
26+
--> $DIR/into-boxed-slice-fail.rs:11:35
2527
|
2628
LL | let _ = Box::into_boxed_slice(boxed_trait);
27-
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
29+
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
30+
| |
31+
| required by a bound introduced by this call
2832
|
2933
= help: the trait `Sized` is not implemented for `dyn Debug`
3034
note: required by a bound in `Box::<T, A>::into_boxed_slice`

src/test/ui/chalkify/bugs/async.stderr

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0277]: the trait bound `[static generator@$DIR/async.rs:7:29: 9:2]: Gener
22
--> $DIR/async.rs:7:29
33
|
44
LL | async fn foo(x: u32) -> u32 {
5-
| _____________________________^
5+
| _____________________________-
66
LL | | x
77
LL | | }
8-
| |_^ the trait `Generator<ResumeTy>` is not implemented for `[static generator@$DIR/async.rs:7:29: 9:2]`
8+
| | ^
9+
| | |
10+
| |_the trait `Generator<ResumeTy>` is not implemented for `[static generator@$DIR/async.rs:7:29: 9:2]`
11+
| required by a bound introduced by this call
912
|
1013
note: required by a bound in `std::future::from_generator`
1114
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
@@ -20,7 +23,9 @@ LL | async fn foo(x: u32) -> u32 {
2023
| _____________________________^
2124
LL | | x
2225
LL | | }
23-
| |_^
26+
| | ^ required by a bound introduced by this call
27+
| |_|
28+
|
2429
|
2530
note: required by a bound in `std::future::from_generator`
2631
--> $SRC_DIR/core/src/future/mod.rs:LL:COL

src/test/ui/dst/dst-rvalue.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0277]: the size for values of type `str` cannot be known at compilation time
2-
--> $DIR/dst-rvalue.rs:4:24
2+
--> $DIR/dst-rvalue.rs:4:33
33
|
44
LL | let _x: Box<str> = Box::new(*"hello world");
5-
| ^^^^^^^^ doesn't have a size known at compile-time
5+
| -------- ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `str`
810
note: required by a bound in `Box::<T>::new`
@@ -12,10 +14,12 @@ LL | impl<T> Box<T> {
1214
| ^ required by this bound in `Box::<T>::new`
1315

1416
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
15-
--> $DIR/dst-rvalue.rs:8:28
17+
--> $DIR/dst-rvalue.rs:8:37
1618
|
1719
LL | let _x: Box<[isize]> = Box::new(*array);
18-
| ^^^^^^^^ doesn't have a size known at compile-time
20+
| -------- ^^^^^^ doesn't have a size known at compile-time
21+
| |
22+
| required by a bound introduced by this call
1923
|
2024
= help: the trait `Sized` is not implemented for `[isize]`
2125
note: required by a bound in `Box::<T>::new`

src/test/ui/inference/issue-86162-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0283]: type annotations needed
44
LL | Foo::bar(gen()); //<- Do not suggest `Foo::bar::<impl Clone>()`!
55
| -------- ^^^ cannot infer type of the type parameter `T` declared on the function `gen`
66
| |
7-
| type must be known at this point
7+
| required by a bound introduced by this call
88
|
99
= note: cannot satisfy `_: Clone`
1010
note: required by a bound in `Foo::bar`

src/test/ui/issues/issue-17651.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
2-
--> $DIR/issue-17651.rs:5:9
2+
--> $DIR/issue-17651.rs:5:18
33
|
44
LL | (|| Box::new(*(&[0][..])))();
5-
| ^^^^^^^^ doesn't have a size known at compile-time
5+
| -------- ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `[{integer}]`
810
note: required by a bound in `Box::<T>::new`

src/test/ui/proc-macro/signature.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | / pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
55
LL | |
66
LL | | loop {}
77
LL | | }
8-
| |_^ call the function in a closure: `|| unsafe { /* code */ }`
8+
| | ^
9+
| | |
10+
| |_call the function in a closure: `|| unsafe { /* code */ }`
11+
| required by a bound introduced by this call
912
|
1013
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
1114
= note: unsafe function cannot be called generically without an unsafe block

src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
2020
| ++++++++++++
2121

2222
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
23-
--> $DIR/trait-where-clause.rs:15:5
23+
--> $DIR/trait-where-clause.rs:15:12
2424
|
2525
LL | T::c::<T>();
26-
| ^^^^^^^^^ the trait `~const Bar` is not implemented for `T`
26+
| ^ the trait `~const Bar` is not implemented for `T`
2727
|
2828
note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
29-
--> $DIR/trait-where-clause.rs:15:5
29+
--> $DIR/trait-where-clause.rs:15:12
3030
|
3131
LL | T::c::<T>();
32-
| ^^^^^^^^^
32+
| ^
3333
note: required by a bound in `Foo::c`
3434
--> $DIR/trait-where-clause.rs:8:13
3535
|
@@ -57,10 +57,10 @@ LL | fn test3<T: Foo + Bar>() {
5757
| +++++
5858

5959
error[E0277]: the trait bound `T: Bar` is not satisfied
60-
--> $DIR/trait-where-clause.rs:29:5
60+
--> $DIR/trait-where-clause.rs:29:12
6161
|
6262
LL | T::c::<T>();
63-
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
63+
| ^ the trait `Bar` is not implemented for `T`
6464
|
6565
note: required by a bound in `Foo::c`
6666
--> $DIR/trait-where-clause.rs:8:13

0 commit comments

Comments
 (0)