Skip to content

Commit 9af60a1

Browse files
committed
add text about not being able to change return type
1 parent 28cc822 commit 9af60a1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

text/0000-try-trait.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,15 @@ or perhaps if we want to be more strictly correct:
291291
292292
We could also go further and analyze the type to which `?` is applied
293293
and figure out the set of legal return types for the function to
294-
have. So if the code is invoking `foo.write()?` (i.e., applying `?` to an
295-
`io::Result`), then we could offer a suggestion like "consider changing
296-
the return type to `Result<(), io::Error>`" or perhaps just "consider
297-
changing the return type to a `Result"`.
294+
have. So if the code is invoking `foo.write()?` (i.e., applying `?` to
295+
an `io::Result`), then we could offer a suggestion like "consider
296+
changing the return type to `Result<(), io::Error>`" or perhaps just
297+
"consider changing the return type to a `Result"`. Note however that
298+
if `?` is used within an impl of a trait method, or within `main()`,
299+
or in some other context where the user is not free to change the type
300+
signature, then we should make this suggestion. In the case of an impl
301+
of a trait defined in the current crate, we could consider suggesting
302+
that the user change the definition of the trait.
298303

299304
On an implementation note, it would probably be helpful for improving
300305
the error message if `?` were not desugared when lowering from AST to

0 commit comments

Comments
 (0)