Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eed5259

Browse files
Rollup merge of #146046 - chenyukang:yukang-fix-method-exists-for-ret-ty-error, r=estebank
Suggest method name with maybe ty mismatch Fixes #146008 I think it's ok to suggest method name even when the return ty mismatch, since we only reporting in `Applicability::MaybeIncorrect`, user may add `()` and continue to fix following errors. r? ```@estebank```
2 parents 142ad69 + 263766b commit eed5259

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

‎compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117
Err(Ambiguity(..)) => true,
118118
Err(PrivateMatch(..)) => false,
119119
Err(IllegalSizedBound { .. }) => true,
120-
Err(BadReturnType) => false,
120+
Err(BadReturnType) => true,
121121
Err(ErrorReported(_)) => false,
122122
}
123123
}

‎tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0599]: no method named `test` found for opaque type `impl Future<Output =
33
|
44
LL | let x: u32 = foo().test();
55
| ^^^^ method not found in `impl Future<Output = A>`
6+
|
7+
help: consider `await`ing on the `Future` and calling the method on its `Output`
8+
|
9+
LL | let x: u32 = foo().await.test();
10+
| ++++++
611

712
error: aborting due to 1 previous error
813

‎tests/ui/privacy/private-field-ty-err.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0616]: field `len` of struct `Foo` is private
33
|
44
LL | if x.len {
55
| ^^^ private field
6+
|
7+
help: a method `len` also exists, call it with parentheses
8+
|
9+
LL | if x.len() {
10+
| ++
611

712
error: aborting due to 1 previous error
813

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct LlamaModel;
2+
3+
impl LlamaModel {
4+
fn chat_template(&self) -> Result<&str, ()> {
5+
todo!()
6+
}
7+
}
8+
9+
fn template_from_str(_x: &str) {}
10+
11+
fn main() {
12+
let model = LlamaModel;
13+
template_from_str(&model.chat_template); //~ ERROR attempted to take value of method `chat_template` on type `LlamaModel`
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0615]: attempted to take value of method `chat_template` on type `LlamaModel`
2+
--> $DIR/suggest-method-name-with-maybe-ty-mismatch-146008.rs:13:30
3+
|
4+
LL | template_from_str(&model.chat_template);
5+
| ^^^^^^^^^^^^^ method, not a field
6+
|
7+
help: use parentheses to call the method
8+
|
9+
LL | template_from_str(&model.chat_template());
10+
| ++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0615`.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /