Skip to content

Commit 8f66faf

Browse files
committed
Auto merge of #42391 - photoszzt:master, r=Manishearth
Better suggestion for unknown method r? @Manishearth fixes #42386
2 parents 6684d17 + f113f54 commit 8f66faf

10 files changed

+30
-16
lines changed

src/librustc_typeck/check/method/suggest.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
176176
if mode == Mode::MethodCall {
177177
"method"
178178
} else {
179-
"associated item"
179+
match item_name.as_str().chars().next() {
180+
Some(name) => {
181+
if name.is_lowercase() {
182+
"function or associated item"
183+
} else {
184+
"associated item"
185+
}
186+
},
187+
None => {
188+
""
189+
},
190+
}
180191
},
181192
item_name,
182193
self.ty_to_string(actual))

src/test/compile-fail/bogus-tag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
let red: color = color::rgb(255, 0, 0);
1616
match red {
1717
color::rgb(r, g, b) => { println!("rgb"); }
18-
color::hsl(h, s, l) => { println!("hsl"); } //~ ERROR no associated
18+
color::hsl(h, s, l) => { println!("hsl"); } //~ ERROR no function
1919
}
2020
}

src/test/compile-fail/issue-28344.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use std::ops::BitXor;
1313
fn main() {
1414
let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
1515
//~^ ERROR must be specified
16-
//~| no associated item named
16+
//~| no function or associated item named
1717

1818
let g = BitXor::bitor;
1919
//~^ ERROR must be specified
20-
//~| no associated item named
21-
}
20+
//~| no function or associated item named
21+
}

src/test/compile-fail/issue-30123.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ use issue_30123_aux::*;
1515

1616
fn main() {
1717
let ug = Graph::<i32, i32>::new_undirected();
18-
//~^ ERROR no associated item named `new_undirected` found for type
18+
//~^ ERROR no function or associated item named `new_undirected` found for type
1919
}

src/test/compile-fail/issue-39559.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Dim for Dim3 {
2222

2323
pub struct Vector<T, D: Dim> {
2424
entries: [T; D::dim()]
25-
//~^ ERROR no associated item named `dim` found for type `D` in the current scope
25+
//~^ ERROR no function or associated item named `dim` found for type `D` in the current scope
2626
}
2727

2828
fn main() {}

src/test/compile-fail/issue-3973.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ impl ToString_ for Point {
3030

3131
fn main() {
3232
let p = Point::new(0.0, 0.0);
33-
//~^ ERROR no associated item named `new` found for type `Point` in the current scope
33+
//~^ ERROR no function or associated item named `new` found for type `Point`
3434
println!("{}", p.to_string());
3535
}

src/test/compile-fail/issue-7950.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
struct Foo;
1414

1515
fn main() {
16-
Foo::bar(); //~ ERROR no associated item named `bar` found for type `Foo` in the current scope
16+
Foo::bar();
17+
//~^ ERROR no function or associated item named `bar` found for type `Foo`
1718
}

src/test/compile-fail/lexical-scopes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod Foo {
1717
pub fn f() {}
1818
}
1919
fn g<Foo>() {
20-
Foo::f(); //~ ERROR no associated item named `f`
20+
Foo::f(); //~ ERROR no function or associated item named `f`
2121
}
2222

2323
fn main() {}

src/test/compile-fail/trait-item-privacy.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ fn check_method() {
8686

8787
// Methods, UFCS
8888
// a, b, c are resolved as trait items, their traits need to be in scope
89-
S::a(&S); //~ ERROR no associated item named `a` found for type `S` in the current scope
90-
S::b(&S); //~ ERROR no associated item named `b` found for type `S` in the current scope
89+
S::a(&S);
90+
//~^ ERROR no function or associated item named `a` found for type `S`
91+
S::b(&S);
92+
//~^ ERROR no function or associated item named `b` found for type `S`
9193
S::c(&S); // OK
9294
// a, b, c are resolved as inherent items, their traits don't need to be in scope
9395
C::a(&S); //~ ERROR method `a` is private

src/test/compile-fail/unspecified-self-in-trait-ref.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ pub trait Bar<X=usize, A=Self> {
1818

1919
fn main() {
2020
let a = Foo::lol();
21-
//~^ ERROR no associated item named
21+
//~^ ERROR no function or associated item named
2222
let b = Foo::<_>::lol();
23-
//~^ ERROR no associated item named
23+
//~^ ERROR no function or associated item named
2424
let c = Bar::lol();
25-
//~^ ERROR no associated item named
25+
//~^ ERROR no function or associated item named
2626
let d = Bar::<usize, _>::lol();
27-
//~^ ERROR no associated item named
27+
//~^ ERROR no function or associated item named
2828
let e = Bar::<usize>::lol();
2929
//~^ ERROR must be explicitly specified
3030
}

0 commit comments

Comments
 (0)