Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::def::DefKind;
use rustc_hir::{self as hir, ExprKind, HirId, Node};
use rustc_hir_analysis::autoderef::{self, Autoderef};
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
Expand Down Expand Up @@ -486,13 +485,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.resolve_vars_if_possible(ty.value);
let guar = match *ty.kind() {
ty::Infer(ty::TyVar(_)) => {
// We want to get the variable name that the method
// is being called on. If it is a method call.
let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
(
Mode::MethodCall,
Node::Expr(hir::Expr {
kind: ExprKind::MethodCall(_, recv, ..),
..
}),
) => recv.span,
_ => span,
};

let raw_ptr_call = bad_ty.reached_raw_pointer
&& !self.tcx.features().arbitrary_self_types();
// FIXME: Ideally we'd use the span of the self-expr here,
// not of the method path.

let mut err = self.err_ctxt().emit_inference_failure_err(
self.body_id,
span,
err_span,
ty.into(),
TypeAnnotationNeeded::E0282,
!raw_ptr_call,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let var_fn = Value::wrap();
| ^^^^^^
...
LL | let _ = var_fn.clone();
| ----- type must be known at this point
| ------ type must be known at this point
|
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | needs_foo(|x| {
| ^
...
LL | x.to_string();
| --------- type must be known at this point
| - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| -------- type must be known at this point
| ---- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| -------- type must be known at this point
| ---- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| -------- type must be known at this point
| ---- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| -------- type must be known at this point
| ---- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/incompat-call-after-qualified-path-0.rs:21:6
|
LL | f(|a, b| a.cmp(b));
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/incompat-call-after-qualified-path-1.rs:25:6
|
LL | f(|a, b| a.cmp(b));
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-20261.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0282]: type annotations needed
--> $DIR/issue-20261.rs:4:11
--> $DIR/issue-20261.rs:4:9
|
LL | i.clone();
| ^^^^^ cannot infer type
| ^ cannot infer type

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-2151.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed
LL | let x = panic!();
| ^
LL | x.clone();
| ----- type must be known at this point
| - type must be known at this point
|
help: consider giving `x` an explicit type
|
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/lazy-type-alias-impl-trait/branches3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:9:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -13,7 +13,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:18:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -24,7 +24,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:26:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -35,7 +35,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:33:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
18 changes: 8 additions & 10 deletions tests/ui/methods/call_method_unknown_pointee.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
error[E0282]: type annotations needed
--> $DIR/call_method_unknown_pointee.rs:10:41
--> $DIR/call_method_unknown_pointee.rs:10:23
|
LL | let _a: i32 = (ptr as *const _).read();
| ^^^^
| |
| cannot infer type
| cannot call a method on a raw pointer with an unknown pointee type
| ^^^^^^^^^^^^^^^^^ ---- cannot call a method on a raw pointer with an unknown pointee type
| |
| cannot infer type

error[E0282]: type annotations needed for `*const _`
--> $DIR/call_method_unknown_pointee.rs:12:13
Expand All @@ -22,13 +21,12 @@ LL | let b: *const _ = ptr as *const _;
| ++++++++++

error[E0282]: type annotations needed
--> $DIR/call_method_unknown_pointee.rs:21:39
--> $DIR/call_method_unknown_pointee.rs:21:23
|
LL | let _a: i32 = (ptr as *mut _).read();
| ^^^^
| |
| cannot infer type
| cannot call a method on a raw pointer with an unknown pointee type
| ^^^^^^^^^^^^^^^ ---- cannot call a method on a raw pointer with an unknown pointee type
| |
| cannot infer type

error[E0282]: type annotations needed for `*mut _`
--> $DIR/call_method_unknown_pointee.rs:23:13
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/methods/call_method_unknown_referent.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0282]: type annotations needed
--> $DIR/call_method_unknown_referent.rs:20:31
--> $DIR/call_method_unknown_referent.rs:20:19
|
LL | let _a: i32 = (ptr as &_).read();
| ^^^^ cannot infer type
| ^^^^^^^^^^^ cannot infer type

error[E0282]: type annotations needed
--> $DIR/call_method_unknown_referent.rs:26:37
--> $DIR/call_method_unknown_referent.rs:26:14
|
LL | let _b = (rc as std::rc::Rc<_>).read();
| ^^^^ cannot infer type
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

error[E0599]: no method named `read` found for struct `SmartPtr<T>` in the current scope
--> $DIR/call_method_unknown_referent.rs:46:35
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/quote/not-repeatable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ note: the traits `Iterator` and `ToTokens` must be implemented
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

error[E0282]: type annotations needed
--> $DIR/not-repeatable.rs:11:13
--> $DIR/not-repeatable.rs:11:25
|
LL | let _ = quote! { $($ip)* };
| ^^^^^^^^^^^^^^^^^^ cannot infer type
| ^^ cannot infer type

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let x = [Foo(PhantomData); 2];
| ^
LL |
LL | extract(x).max(2);
| --- type must be known at this point
| ---------- type must be known at this point
|
help: consider giving `x` an explicit type, where the placeholders `_` are specified
|
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/span/issue-42234-unknown-receiver-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed
LL | let x: Option<_> = None;
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
LL | x.unwrap().method_that_could_exist_on_some_type();
| ------------------------------------ type must be known at this point
| ---------- type must be known at this point
|
help: consider specifying the generic argument
|
Expand All @@ -16,8 +16,6 @@ error[E0282]: type annotations needed
|
LL | .sum::<_>()
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
LL | .to_string()
| --------- type must be known at this point
|

error: aborting due to 2 previous errors
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/type-alias-impl-trait/closures_in_branches.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/closures_in_branches.rs:8:10
|
LL | |x| x.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -13,7 +13,7 @@ error[E0282]: type annotations needed
--> $DIR/closures_in_branches.rs:22:10
|
LL | |x| x.len()
| ^ --- type must be known at this point
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/type-inference/regression-issue-81317.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let iv = S ^ index.into();
| ^^
LL |
LL | &iv.to_bytes_be();
| ----------- type must be known at this point
| -- type must be known at this point
|
help: consider giving `iv` an explicit type
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/typeck/issue-13853.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ LL | for node in graph.iter() {
| ^^^^ method not found in `&G`

error[E0282]: type annotations needed
--> $DIR/issue-13853.rs:28:14
--> $DIR/issue-13853.rs:28:9
|
LL | node.zomg();
| ^^^^ cannot infer type
| ^^^^ cannot infer type

error[E0308]: mismatched types
--> $DIR/issue-13853.rs:37:13
Expand Down
Loading