Skip to content

Commit c990a56

Browse files
committed
fix APITIT being treated as a normal generic parameter in suggestions
1 parent 6ba0ce4 commit c990a56

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ fn missing_items_err(
232232
};
233233

234234
// Obtain the level of indentation ending in `sugg_sp`.
235-
let padding =
236-
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
235+
let padding = tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(String::new);
237236
let (mut missing_trait_item, mut missing_trait_item_none, mut missing_trait_item_label) =
238237
(Vec::new(), Vec::new(), Vec::new());
239238

@@ -356,6 +355,10 @@ fn bounds_from_generic_predicates<'tcx>(
356355
let mut types_str = vec![];
357356
for (ty, bounds) in types {
358357
if let ty::Param(_) = ty.kind() {
358+
let ty_str = ty.to_string();
359+
if ty_str.contains("impl ") {
360+
continue;
361+
}
359362
let mut bounds_str = vec![];
360363
for bound in bounds {
361364
let mut projections_str = vec![];
@@ -376,9 +379,9 @@ fn bounds_from_generic_predicates<'tcx>(
376379
}
377380
}
378381
if bounds_str.is_empty() {
379-
types_str.push(ty.to_string());
382+
types_str.push(ty_str);
380383
} else {
381-
types_str.push(format!("{}: {}", ty, bounds_str.join(" + ")));
384+
types_str.push(format!("{}: {}", ty_str, bounds_str.join(" + ")));
382385
}
383386
} else {
384387
// Avoid suggesting the following:
@@ -475,7 +478,7 @@ fn fn_sig_suggestion<'tcx>(
475478
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
476479

477480
// FIXME: this is not entirely correct, as the lifetimes from borrowed params will
478-
// not be present in the `fn` definition, not will we account for renamed
481+
// not be present in the `fn` definition, nor will we account for renamed
479482
// lifetimes between the `impl` and the `trait`, but this should be good enough to
480483
// fill in a significant portion of the missing code, and other subsequent
481484
// suggestions can help the user fix the code.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ aux-build:dep.rs
2+
3+
extern crate dep;
4+
use dep::*;
5+
6+
struct Local;
7+
impl Trait for Local {}
8+
//~^ ERROR not all trait items implemented
9+
//~| HELP implement the missing item: `fn foo(_: impl Sized) { todo!() }`
10+
//~| HELP implement the missing item: `fn bar<T>(_: impl Sized) { todo!() }`
11+
12+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `foo`, `bar`
2+
--> $DIR/apitit-unimplemented-method.rs:7:1
3+
|
4+
LL | impl Trait for Local {}
5+
| ^^^^^^^^^^^^^^^^^^^^ missing `foo`, `bar` in implementation
6+
|
7+
= help: implement the missing item: `fn foo(_: impl Sized) { todo!() }`
8+
= help: implement the missing item: `fn bar<T>(_: impl Sized) { todo!() }`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0046`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub trait Trait {
2+
fn foo(_: impl Sized);
3+
fn bar<T>(_: impl Sized);
4+
}

0 commit comments

Comments
 (0)