Skip to content

Commit 12604fa

Browse files
committed
Skip suggest impl or dyn when poly trait is not a real trait
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent 27b866d commit 12604fa

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
8686
"expected a type, found a trait"
8787
);
8888
if self_ty.span.can_be_used_for_suggestions()
89+
&& poly_trait_ref.trait_ref.trait_def_id().is_some()
8990
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
9091
&& !self.maybe_suggest_dyn_trait(self_ty, sugg, &mut diag)
9192
{

Diff for: tests/ui/traits/object/suggestion-trait-object-issue-139174.stderr

-15
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,18 @@ error[E0782]: expected a type, found a trait
2121
|
2222
LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
2323
| ^^^^^^^^^^
24-
|
25-
help: you can add the `dyn` keyword if you want a trait object
26-
|
27-
LL | fn f<'a>(x: Box<dyn Fn() -> Option<dyn usize + 'a>>) -> usize {
28-
| +++
2924

3025
error[E0782]: expected a type, found a trait
3126
--> $DIR/suggestion-trait-object-issue-139174.rs:9:32
3227
|
3328
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
3429
| ^^^^^^^^^^
35-
|
36-
help: `usize + 'a` is dyn-incompatible, use `impl usize + 'a` to return an opaque type, as long as you return a single underlying type
37-
|
38-
LL | fn create_adder<'a>(x: i32) -> impl usize + 'a {
39-
| ++++
4030

4131
error[E0782]: expected a type, found a trait
4232
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
4333
|
4434
LL | x: usize + 'a,
4535
| ^^^^^^^^^^
46-
|
47-
help: you can add the `dyn` keyword if you want a trait object
48-
|
49-
LL | x: dyn usize + 'a,
50-
| +++
5136

5237
error: aborting due to 6 previous errors
5338

0 commit comments

Comments
 (0)