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

src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ LL | pub const fn new(pointer: P) -> Pin<P> {
4646
| ^^^
4747

4848
error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
49-
--> $DIR/expected-boxed-future-isnt-pinned.rs:19:5
49+
--> $DIR/expected-boxed-future-isnt-pinned.rs:19:14
5050
|
5151
LL | Pin::new(x)
52-
| ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
52+
| -------- ^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
53+
| |
54+
| required by a bound introduced by this call
5355
|
5456
= note: consider using `Box::pin`
5557
note: required by a bound in `Pin::<P>::new`
@@ -59,10 +61,12 @@ LL | impl<P: Deref<Target: Unpin>> Pin<P> {
5961
| ^^^^^ required by this bound in `Pin::<P>::new`
6062

6163
error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
62-
--> $DIR/expected-boxed-future-isnt-pinned.rs:24:5
64+
--> $DIR/expected-boxed-future-isnt-pinned.rs:24:14
6365
|
6466
LL | Pin::new(Box::new(x))
65-
| ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
67+
| -------- ^^^^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
68+
| |
69+
| required by a bound introduced by this call
6670
|
6771
= note: consider using `Box::pin`
6872
note: required by a bound in `Pin::<P>::new`

src/test/ui/suggestions/issue-84973.stderr

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
error[E0277]: the trait bound `Fancy: SomeTrait` is not satisfied
2-
--> $DIR/issue-84973.rs:6:13
2+
--> $DIR/issue-84973.rs:6:24
33
|
44
LL | let o = Other::new(f);
5-
| ^^^^^^^^^^ the trait `SomeTrait` is not implemented for `Fancy`
5+
| ---------- ^ expected an implementor of trait `SomeTrait`
6+
| |
7+
| required by a bound introduced by this call
68
|
7-
= help: the trait `SomeTrait` is implemented for `&'a Fancy`
89
note: required by a bound in `Other::<'a, G>::new`
910
--> $DIR/issue-84973.rs:25:8
1011
|
@@ -13,6 +14,10 @@ LL | G: SomeTrait,
1314
LL | {
1415
LL | pub fn new(g: G) -> Self {
1516
| --- required by a bound in this
17+
help: consider borrowing here
18+
|
19+
LL | let o = Other::new(&f);
20+
| +
1621

1722
error: aborting due to previous error
1823

src/test/ui/suggestions/mut-borrow-needed-by-trait.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 `&dyn std::io::Write: std::io::Write` is not satisfied
2-
--> $DIR/mut-borrow-needed-by-trait.rs:17:14
2+
--> $DIR/mut-borrow-needed-by-trait.rs:17:29
33
|
44
LL | let fp = BufWriter::new(fp);
5-
| ^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
5+
| -------------- ^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write`
810
note: required by a bound in `BufWriter::<W>::new`

src/test/ui/suggestions/suggest-change-mut.stderr

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
error[E0277]: the trait bound `&T: std::io::Read` is not satisfied
2-
--> $DIR/suggest-change-mut.rs:12:33
2+
--> $DIR/suggest-change-mut.rs:12:48
33
|
44
LL | let mut stream_reader = BufReader::new(&stream);
5-
| ^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&T`
5+
| -------------- ^^^^^^^ the trait `std::io::Read` is not implemented for `&T`
6+
| |
7+
| required by a bound introduced by this call
68
|
7-
= note: `std::io::Read` is implemented for `&mut T`, but not for `&T`
89
note: required by a bound in `BufReader::<R>::new`
910
--> $SRC_DIR/std/src/io/buffered/bufreader.rs:LL:COL
1011
|
1112
LL | impl<R: Read> BufReader<R> {
1213
| ^^^^ required by this bound in `BufReader::<R>::new`
14+
help: consider removing the leading `&`-reference
15+
|
16+
LL - let mut stream_reader = BufReader::new(&stream);
17+
LL + let mut stream_reader = BufReader::new(stream);
18+
|
1319
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
1420
|
1521
LL | fn issue_81421<T: Read + Write>(mut stream: T) where &T: std::io::Read {
1622
| +++++++++++++++++++++++
23+
help: consider changing this borrow's mutability
24+
|
25+
LL | let mut stream_reader = BufReader::new(&mut stream);
26+
| ~~~~
1727

1828
error[E0599]: the method `read_until` exists for struct `BufReader<&T>`, but its trait bounds were not satisfied
1929
--> $DIR/suggest-change-mut.rs:16:23

src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
2424
| ++++++++++++++++
2525

2626
error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
27-
--> $DIR/repeated-supertrait-ambig.rs:34:5
27+
--> $DIR/repeated-supertrait-ambig.rs:34:34
2828
|
2929
LL | <dyn CompareToInts>::same_as(c, 22)
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
30+
| ---------------------------- ^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
31+
| |
32+
| required by a bound introduced by this call
3133
|
3234
= help: the following other types implement trait `CompareTo<T>`:
3335
<i64 as CompareTo<i64>>

src/test/ui/traits/issue-77982.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ help: consider specifying the generic argument
3939
LL | opts.get::<Q>(opt.as_ref());
4040
| +++++
4141

42+
error[E0282]: type annotations needed
43+
--> $DIR/issue-77982.rs:13:59
44+
|
45+
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect();
46+
| ^^^^
47+
|
48+
help: try using a fully qualified path to specify the expected types
49+
|
50+
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect();
51+
| +++++++++++++++++++++++ ~
52+
4253
error[E0283]: type annotations needed
4354
--> $DIR/issue-77982.rs:13:59
4455
|
@@ -98,6 +109,7 @@ help: consider giving this pattern a type, where the type for type parameter `T`
98109
LL | let _: Box<T> = (&()).bar();
99110
| ++++++++
100111

101-
error: aborting due to 5 previous errors
112+
error: aborting due to 6 previous errors
102113

103-
For more information about this error, try `rustc --explain E0283`.
114+
Some errors have detailed explanations: E0282, E0283.
115+
For more information about an error, try `rustc --explain E0282`.

src/test/ui/traits/suggest-deferences/issue-39029.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ impl std::ops::Deref for NoToSocketAddrs {
1313
fn main() {
1414
let _works = TcpListener::bind("some string");
1515
let bad = NoToSocketAddrs("bad".to_owned());
16-
let _errors = TcpListener::bind(&bad);
16+
let _errors = TcpListener::bind(&*bad);
1717
//~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
1818
}

0 commit comments

Comments
 (0)