Skip to content

Commit b55e07e

Browse files
committed
correct E0619 span re method call receivers whose type must be known
Previously, when the type of a method receiver could not be determined, the error message would, potentially confusingly, highlight the span of the entire method call. Resolves #36598, resolves #42234.
1 parent 6c04c41 commit b55e07e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
29252925
let rcvr = &args[0];
29262926
let rcvr_t = self.check_expr_with_needs(&rcvr, needs);
29272927
// no need to check for bot/err -- callee does that
2928-
let rcvr_t = self.structurally_resolved_type(expr.span, rcvr_t);
2928+
let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t);
29292929

29302930
let method = match self.lookup_method(rcvr_t,
29312931
segment,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// When the type of a method call's receiver is unknown, the span should point
12+
// to the receiver (and not the entire call, as was previously the case before
13+
// the fix of which this tests).
14+
15+
fn shines_a_beacon_through_the_darkness() {
16+
let x: Option<_> = None;
17+
x.unwrap().method_that_could_exist_on_some_type();
18+
//~^ ERROR 17:5: 17:15: the type of this value must be known in this context
19+
}
20+
21+
fn courier_to_des_moines_and_points_west(data: &[u32]) -> String {
22+
data.iter() //~ ERROR 22:5: 23:20: the type of this value must be known in this context
23+
.sum::<_>()
24+
.to_string()
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0619]: the type of this value must be known in this context
2+
--> $DIR/issue-42234-unknown-receiver-type.rs:17:5
3+
|
4+
17 | x.unwrap().method_that_could_exist_on_some_type();
5+
| ^^^^^^^^^^
6+
7+
error[E0619]: the type of this value must be known in this context
8+
--> $DIR/issue-42234-unknown-receiver-type.rs:22:5
9+
|
10+
22 | / data.iter() //~ ERROR 22:5: 23:20: the type of this value must be known in this context
11+
23 | | .sum::<_>()
12+
| |___________________^
13+
14+
error: aborting due to 2 previous errors
15+

0 commit comments

Comments
 (0)