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
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2975,6 +2975,7 @@ impl<'a, 'b, 'tcx> ArgsCtxt<'a, 'b, 'tcx> {
IsSuggestion(true),
callee_ty.peel_refs(),
self.call_ctxt.callee_expr.unwrap().hir_id,
None,
TraitsInScope,
|mut ctxt| ctxt.probe_for_similar_candidate(),
)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty,
expr.hir_id,
ProbeScope::TraitsInScope,
Some(expr.span),
)
{
(pick.item, segment)
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty,
call_expr_id,
ProbeScope::TraitsInScope,
None,
) {
Ok(pick) => {
pick.maybe_emit_unstable_name_collision_hint(
Expand Down Expand Up @@ -188,7 +189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ProbeScope::TraitsInScope
};

let pick = self.lookup_probe(segment.ident, self_ty, call_expr, scope)?;
let pick = self.lookup_probe(segment.ident, self_ty, call_expr, self_expr, scope)?;

self.lint_edition_dependent_dot_call(
self_ty, segment, span, call_expr, self_expr, &pick, args,
Expand All @@ -215,6 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
segment.ident,
trait_type,
call_expr,
self_expr,
ProbeScope::TraitsInScope,
) {
Ok(ref new_pick) if pick.differs_from(new_pick) => {
Expand Down Expand Up @@ -283,6 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method_name: Ident,
self_ty: Ty<'tcx>,
call_expr: &hir::Expr<'_>,
self_expr: &hir::Expr<'_>,
scope: ProbeScope,
) -> probe::PickResult<'tcx> {
let pick = self.probe_for_name(
Expand All @@ -293,7 +296,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty,
call_expr.hir_id,
scope,
Some(self_expr.span),
)?;

pick.maybe_emit_unstable_name_collision_hint(self.tcx, method_name.span, call_expr.hir_id);
Ok(pick)
}
Expand All @@ -314,6 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty,
call_expr.hir_id,
scope,
None,
)?;
Ok(pick)
}
Expand Down Expand Up @@ -533,6 +539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty,
expr_id,
ProbeScope::TraitsInScope,
Some(self_ty_span),
);
let pick = match (pick, struct_variant) {
// Fall back to a resolution that will produce an error later.
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
IsSuggestion(true),
self_ty,
scope_expr_id,
None,
ProbeScope::AllTraits,
|probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
)
Expand All @@ -311,6 +312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
IsSuggestion(true),
self_ty,
scope_expr_id,
None,
ProbeScope::AllTraits,
|probe_cx| probe_cx.pick(),
)
Expand All @@ -330,6 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty: Ty<'tcx>,
scope_expr_id: HirId,
scope: ProbeScope,
self_expr_span: Option<Span>,
) -> PickResult<'tcx> {
self.probe_op(
item_name.span,
Expand All @@ -339,6 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_suggestion,
self_ty,
scope_expr_id,
self_expr_span,
scope,
|probe_cx| probe_cx.pick(),
)
Expand All @@ -363,6 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_suggestion,
self_ty,
scope_expr_id,
None,
scope,
|probe_cx| {
Ok(probe_cx
Expand All @@ -383,6 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>,
scope_expr_id: HirId,
self_expr: Option<Span>,
scope: ProbeScope,
op: OP,
) -> Result<R, MethodError<'tcx>>
Expand Down Expand Up @@ -488,11 +494,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Infer(ty::TyVar(_)) => {
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,
self_expr.unwrap_or(span),
ty.into(),
TypeAnnotationNeeded::E0282,
!raw_ptr_call,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rcvr_ty,
expr_id,
ProbeScope::TraitsInScope,
None,
)
.is_ok()
})
Expand Down Expand Up @@ -3176,6 +3177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
deref_ty,
ty.hir_id,
ProbeScope::TraitsInScope,
None,
) {
if deref_ty.is_suggestable(self.tcx, true)
// If this method receives `&self`, then the provided
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the changes in tests code are pretty good, I'm not sure whether there is some other way to get the self expr's span, so many fn signature need to change for the new extra parameter.

|
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
Loading
Loading