Account for relative paths

This commit is contained in:
Michael Goulet 2022-08-16 23:13:23 +00:00
parent c005e760f5
commit d05fea6ac4
18 changed files with 112 additions and 56 deletions

View File

@ -1645,7 +1645,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
})
});
let fallback_param_to_point_at = predicate_substs.types().find_map(|ty| {
ty.walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
@ -1660,8 +1659,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let hir = self.tcx.hir();
match hir.get(hir_id) {
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(hir::QPath::Resolved(_, path)), hir_id, .. }) => {
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(qpath), hir_id, .. }) => {
if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Call(callee, args), hir_id: call_hir_id, .. })
= hir.get(hir.get_parent_node(*hir_id))
&& callee.hir_id == *hir_id
@ -1677,12 +1677,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}
if let Some(param_to_point_at) = param_to_point_at
if let hir::QPath::Resolved(_, path) = qpath
&& let Some(param_to_point_at) = param_to_point_at
&& let Some(segment) = path.segments.last()
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
{
return;
}
if let hir::QPath::TypeRelative(_, segment) = qpath
&& let Some(param_to_point_at) = param_to_point_at
&& self.point_at_generics_if_possible(error, def_id, param_to_point_at, segment)
{
return;
}
}
}
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::MethodCall(segment, args, ..), .. }) => {
@ -1727,6 +1735,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.enumerate()
.filter(|(_, ty)| ty.walk().any(|arg| arg == param_to_point_at))
.collect();
if let [(idx, _)] = args_referencing_param.as_slice()
&& let Some(arg) = args.get(*idx)
{

View File

@ -1,8 +1,10 @@
error[E0277]: the trait bound `Option<&str>: AsRef<Path>` is not satisfied
--> $DIR/issue-72442.rs:12:25
--> $DIR/issue-72442.rs:12:36
|
LL | let mut f = File::open(path.to_str())?;
| ^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
| ---------- ^^^^^^^^^^^^^ the trait `AsRef<Path>` is not implemented for `Option<&str>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `File::open`
--> $SRC_DIR/std/src/fs.rs:LL:COL

View File

@ -1,8 +1,10 @@
error[E0277]: `PhantomPinned` cannot be unpinned
--> $DIR/pin-needed-to-poll-2.rs:43:9
--> $DIR/pin-needed-to-poll-2.rs:43:18
|
LL | Pin::new(&mut self.sleep).poll(cx)
| ^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
| -------- ^^^^^^^^^^^^^^^ within `Sleep`, the trait `Unpin` is not implemented for `PhantomPinned`
| |
| required by a bound introduced by this call
|
= note: consider using `Box::pin`
note: required because it appears within the type `Sleep`

View File

@ -1,8 +1,10 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/into-boxed-slice-fail.rs:7:13
--> $DIR/into-boxed-slice-fail.rs:7:35
|
LL | let _ = Box::into_boxed_slice(boxed_slice);
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[u8]`
note: required by a bound in `Box::<T, A>::into_boxed_slice`
@ -21,10 +23,12 @@ LL | let _ = Box::into_boxed_slice(boxed_slice);
= note: slice and array elements must have `Sized` type
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
--> $DIR/into-boxed-slice-fail.rs:11:13
--> $DIR/into-boxed-slice-fail.rs:11:35
|
LL | let _ = Box::into_boxed_slice(boxed_trait);
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| --------------------- ^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `dyn Debug`
note: required by a bound in `Box::<T, A>::into_boxed_slice`

View File

@ -2,10 +2,13 @@ error[E0277]: the trait bound `[static generator@$DIR/async.rs:7:29: 9:2]: Gener
--> $DIR/async.rs:7:29
|
LL | async fn foo(x: u32) -> u32 {
| _____________________________^
| _____________________________-
LL | | x
LL | | }
| |_^ the trait `Generator<ResumeTy>` is not implemented for `[static generator@$DIR/async.rs:7:29: 9:2]`
| | ^
| | |
| |_the trait `Generator<ResumeTy>` is not implemented for `[static generator@$DIR/async.rs:7:29: 9:2]`
| required by a bound introduced by this call
|
note: required by a bound in `std::future::from_generator`
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
@ -20,7 +23,9 @@ LL | async fn foo(x: u32) -> u32 {
| _____________________________^
LL | | x
LL | | }
| |_^
| | ^ required by a bound introduced by this call
| |_|
|
|
note: required by a bound in `std::future::from_generator`
--> $SRC_DIR/core/src/future/mod.rs:LL:COL

View File

@ -1,8 +1,10 @@
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/dst-rvalue.rs:4:24
--> $DIR/dst-rvalue.rs:4:33
|
LL | let _x: Box<str> = Box::new(*"hello world");
| ^^^^^^^^ doesn't have a size known at compile-time
| -------- ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
note: required by a bound in `Box::<T>::new`
@ -12,10 +14,12 @@ LL | impl<T> Box<T> {
| ^ required by this bound in `Box::<T>::new`
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
--> $DIR/dst-rvalue.rs:8:28
--> $DIR/dst-rvalue.rs:8:37
|
LL | let _x: Box<[isize]> = Box::new(*array);
| ^^^^^^^^ doesn't have a size known at compile-time
| -------- ^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[isize]`
note: required by a bound in `Box::<T>::new`

View File

@ -4,7 +4,7 @@ error[E0283]: type annotations needed
LL | Foo::bar(gen()); //<- Do not suggest `Foo::bar::<impl Clone>()`!
| -------- ^^^ cannot infer type of the type parameter `T` declared on the function `gen`
| |
| type must be known at this point
| required by a bound introduced by this call
|
= note: cannot satisfy `_: Clone`
note: required by a bound in `Foo::bar`

View File

@ -1,8 +1,10 @@
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
--> $DIR/issue-17651.rs:5:9
--> $DIR/issue-17651.rs:5:18
|
LL | (|| Box::new(*(&[0][..])))();
| ^^^^^^^^ doesn't have a size known at compile-time
| -------- ^^^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `[{integer}]`
note: required by a bound in `Box::<T>::new`

View File

@ -5,7 +5,10 @@ LL | / pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
LL | |
LL | | loop {}
LL | | }
| |_^ call the function in a closure: `|| unsafe { /* code */ }`
| | ^
| | |
| |_call the function in a closure: `|| unsafe { /* code */ }`
| required by a bound introduced by this call
|
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
= note: unsafe function cannot be called generically without an unsafe block

View File

@ -20,16 +20,16 @@ LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
| ++++++++++++
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
--> $DIR/trait-where-clause.rs:15:5
--> $DIR/trait-where-clause.rs:15:12
|
LL | T::c::<T>();
| ^^^^^^^^^ the trait `~const Bar` is not implemented for `T`
| ^ the trait `~const Bar` is not implemented for `T`
|
note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
--> $DIR/trait-where-clause.rs:15:5
--> $DIR/trait-where-clause.rs:15:12
|
LL | T::c::<T>();
| ^^^^^^^^^
| ^
note: required by a bound in `Foo::c`
--> $DIR/trait-where-clause.rs:8:13
|
@ -57,10 +57,10 @@ LL | fn test3<T: Foo + Bar>() {
| +++++
error[E0277]: the trait bound `T: Bar` is not satisfied
--> $DIR/trait-where-clause.rs:29:5
--> $DIR/trait-where-clause.rs:29:12
|
LL | T::c::<T>();
| ^^^^^^^^^ the trait `Bar` is not implemented for `T`
| ^ the trait `Bar` is not implemented for `T`
|
note: required by a bound in `Foo::c`
--> $DIR/trait-where-clause.rs:8:13

View File

@ -46,10 +46,12 @@ LL | pub const fn new(pointer: P) -> Pin<P> {
| ^^^
error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
--> $DIR/expected-boxed-future-isnt-pinned.rs:19:5
--> $DIR/expected-boxed-future-isnt-pinned.rs:19:14
|
LL | Pin::new(x)
| ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
| -------- ^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
| |
| required by a bound introduced by this call
|
= note: consider using `Box::pin`
note: required by a bound in `Pin::<P>::new`
@ -59,10 +61,12 @@ LL | impl<P: Deref<Target: Unpin>> Pin<P> {
| ^^^^^ required by this bound in `Pin::<P>::new`
error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
--> $DIR/expected-boxed-future-isnt-pinned.rs:24:5
--> $DIR/expected-boxed-future-isnt-pinned.rs:24:14
|
LL | Pin::new(Box::new(x))
| ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
| -------- ^^^^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
| |
| required by a bound introduced by this call
|
= note: consider using `Box::pin`
note: required by a bound in `Pin::<P>::new`

View File

@ -1,10 +1,11 @@
error[E0277]: the trait bound `Fancy: SomeTrait` is not satisfied
--> $DIR/issue-84973.rs:6:13
--> $DIR/issue-84973.rs:6:24
|
LL | let o = Other::new(f);
| ^^^^^^^^^^ the trait `SomeTrait` is not implemented for `Fancy`
| ---------- ^ expected an implementor of trait `SomeTrait`
| |
| required by a bound introduced by this call
|
= help: the trait `SomeTrait` is implemented for `&'a Fancy`
note: required by a bound in `Other::<'a, G>::new`
--> $DIR/issue-84973.rs:25:8
|
@ -13,6 +14,10 @@ LL | G: SomeTrait,
LL | {
LL | pub fn new(g: G) -> Self {
| --- required by a bound in this
help: consider borrowing here
|
LL | let o = Other::new(&f);
| +
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0277]: the trait bound `&dyn std::io::Write: std::io::Write` is not satisfied
--> $DIR/mut-borrow-needed-by-trait.rs:17:14
--> $DIR/mut-borrow-needed-by-trait.rs:17:29
|
LL | let fp = BufWriter::new(fp);
| ^^^^^^^^^^^^^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
| -------------- ^^ the trait `std::io::Write` is not implemented for `&dyn std::io::Write`
| |
| required by a bound introduced by this call
|
= note: `std::io::Write` is implemented for `&mut dyn std::io::Write`, but not for `&dyn std::io::Write`
note: required by a bound in `BufWriter::<W>::new`

View File

@ -1,19 +1,29 @@
error[E0277]: the trait bound `&T: std::io::Read` is not satisfied
--> $DIR/suggest-change-mut.rs:12:33
--> $DIR/suggest-change-mut.rs:12:48
|
LL | let mut stream_reader = BufReader::new(&stream);
| ^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&T`
| -------------- ^^^^^^^ the trait `std::io::Read` is not implemented for `&T`
| |
| required by a bound introduced by this call
|
= note: `std::io::Read` is implemented for `&mut T`, but not for `&T`
note: required by a bound in `BufReader::<R>::new`
--> $SRC_DIR/std/src/io/buffered/bufreader.rs:LL:COL
|
LL | impl<R: Read> BufReader<R> {
| ^^^^ required by this bound in `BufReader::<R>::new`
help: consider removing the leading `&`-reference
|
LL - let mut stream_reader = BufReader::new(&stream);
LL + let mut stream_reader = BufReader::new(stream);
|
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | fn issue_81421<T: Read + Write>(mut stream: T) where &T: std::io::Read {
| +++++++++++++++++++++++
help: consider changing this borrow's mutability
|
LL | let mut stream_reader = BufReader::new(&mut stream);
| ~~~~
error[E0599]: the method `read_until` exists for struct `BufReader<&T>`, but its trait bounds were not satisfied
--> $DIR/suggest-change-mut.rs:16:23

View File

@ -24,10 +24,12 @@ LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
| ++++++++++++++++
error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
--> $DIR/repeated-supertrait-ambig.rs:34:5
--> $DIR/repeated-supertrait-ambig.rs:34:34
|
LL | <dyn CompareToInts>::same_as(c, 22)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
| ---------------------------- ^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `CompareTo<T>`:
<i64 as CompareTo<i64>>

View File

@ -39,6 +39,17 @@ help: consider specifying the generic argument
LL | opts.get::<Q>(opt.as_ref());
| +++++
error[E0282]: type annotations needed
--> $DIR/issue-77982.rs:13:59
|
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect();
| ^^^^
|
help: try using a fully qualified path to specify the expected types
|
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect();
| +++++++++++++++++++++++ ~
error[E0283]: type annotations needed
--> $DIR/issue-77982.rs:13:59
|
@ -98,6 +109,7 @@ help: consider giving this pattern a type, where the type for type parameter `T`
LL | let _: Box<T> = (&()).bar();
| ++++++++
error: aborting due to 5 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0283`.
Some errors have detailed explanations: E0282, E0283.
For more information about an error, try `rustc --explain E0282`.

View File

@ -13,6 +13,6 @@ impl std::ops::Deref for NoToSocketAddrs {
fn main() {
let _works = TcpListener::bind("some string");
let bad = NoToSocketAddrs("bad".to_owned());
let _errors = TcpListener::bind(&bad);
let _errors = TcpListener::bind(&*bad);
//~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
}

View File

@ -1,21 +1,11 @@
error[E0277]: the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
--> $DIR/issue-39029.rs:16:19
--> $DIR/issue-39029.rs:16:37
|
LL | let _errors = TcpListener::bind(&bad);
| ----------------- ^^^^ the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `ToSocketAddrs`:
&'a [std::net::SocketAddr]
&T
(&str, u16)
(IpAddr, u16)
(Ipv4Addr, u16)
(Ipv6Addr, u16)
(String, u16)
SocketAddrV4
and 4 others
= note: required for `&NoToSocketAddrs` to implement `ToSocketAddrs`
note: required by a bound in `TcpListener::bind`
--> $SRC_DIR/std/src/net/tcp.rs:LL:COL