mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 05:27:36 +00:00
![]() Remove invalid suggestion involving `Fn` trait bound This pull request closes #85735. The actual issue is a duplicate of #21974, but #85735 contains a further problem, which is an invalid suggestion if `Fn`/`FnMut`/`FnOnce` trait bounds are involved: The suggestion code checks whether the trait bound ends with `>` to determine whether it has any generic arguments, but the `Fn*` traits have a special syntax for generic arguments that doesn't involve angle brackets. The example given in #85735: ```rust trait Foo {} impl<'a, 'b, T> Foo for T where T: FnMut(&'a ()), T: FnMut(&'b ()), { } ``` currently produces: ``` error[E0283]: type annotations needed --> src/lib.rs:4:8 | 4 | T: FnMut(&'a ()), | ^^^^^^^^^^^^^ cannot infer type for type parameter `T` | = note: cannot satisfy `T: FnMut<(&'a (),)>` help: consider specifying the type arguments in the function call | 4 | T: FnMut(&'a ())::<Self, Args>, | ^^^^^^^^^^^^^^ error: aborting due to previous error ``` which is incorrect, because there is no function call, and applying the suggestion would lead to a parse error. With my changes, I get: ``` error[E0283]: type annotations needed --> test.rs:4:8 | 4 | T: FnMut(&'a ()), | ^^^^^^^^^^^^^ cannot infer type for type parameter `T` | ::: [...]/library/core/src/ops/function.rs:147:1 | 147 | pub trait FnMut<Args>: FnOnce<Args> { | ----------------------------------- required by this bound in `FnMut` | = note: cannot satisfy `T: FnMut<(&'a (),)>` error: aborting due to previous error ``` i.e. I have added a check to prevent the invalid suggestion from being issued for `Fn*` bounds, while the underlying issue #21974 remains for now. |
||
---|---|---|
.. | ||
rustc | ||
rustc_apfloat | ||
rustc_arena | ||
rustc_ast | ||
rustc_ast_lowering | ||
rustc_ast_passes | ||
rustc_ast_pretty | ||
rustc_attr | ||
rustc_builtin_macros | ||
rustc_codegen_cranelift | ||
rustc_codegen_llvm | ||
rustc_codegen_ssa | ||
rustc_data_structures | ||
rustc_driver | ||
rustc_error_codes | ||
rustc_errors | ||
rustc_expand | ||
rustc_feature | ||
rustc_fs_util | ||
rustc_graphviz | ||
rustc_hir | ||
rustc_hir_pretty | ||
rustc_incremental | ||
rustc_index | ||
rustc_infer | ||
rustc_interface | ||
rustc_lexer | ||
rustc_lint | ||
rustc_lint_defs | ||
rustc_llvm | ||
rustc_macros | ||
rustc_metadata | ||
rustc_middle | ||
rustc_mir | ||
rustc_mir_build | ||
rustc_parse | ||
rustc_parse_format | ||
rustc_passes | ||
rustc_plugin_impl | ||
rustc_privacy | ||
rustc_query_impl | ||
rustc_query_system | ||
rustc_resolve | ||
rustc_save_analysis | ||
rustc_serialize | ||
rustc_session | ||
rustc_span | ||
rustc_symbol_mangling | ||
rustc_target | ||
rustc_trait_selection | ||
rustc_traits | ||
rustc_ty_utils | ||
rustc_type_ir | ||
rustc_typeck |