Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Try error messages #43984

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use self::Destination::*;

use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan, CharPos, CompilerDesugaringKind};

use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper};
use RenderSpan::*;
Expand Down Expand Up @@ -724,7 +724,9 @@ impl EmitterWriter {

// First, find all the spans in <*macros> and point instead at their use site
for sp in span.primary_spans() {
if *sp == DUMMY_SP {
if *sp == DUMMY_SP ||
sp.is_compiler_desugaring(CompilerDesugaringKind::QuestionMark)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool =)

{
continue;
}
let call_sp = cm.call_span_if_macro(*sp);
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/suggestions/try-operator-on-main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
| ---------------------------
| |
| the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
| in this macro invocation
|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::from_error`
Expand Down
10 changes: 2 additions & 8 deletions src/test/ui/suggestions/try-unimplemented.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0277]: the trait bound `u32: std::ops::Try` is not satisfied
--> $DIR/try-unimplemented.rs:17:5
|
17 | 3u32?
| -----
| |
| `?` cannot be applied to a value of type `u32`
| in this macro invocation
| ^^^^^ `?` cannot be applied to a value of type `u32`
|
= help: the trait `std::ops::Try` is not implemented for `u32`
= note: required by `std::ops::Try::into_result`
Expand All @@ -14,10 +11,7 @@ error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
--> $DIR/try-unimplemented.rs:21:5
|
21 | Ok(3u32)?;
| ---------
| |
| cannot use the `?` operator in a function that returns `()`
| in this macro invocation
| ^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this...aspirational?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e., I don't see code that would emit this "cannot use" error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intended to test Return type does not implement Try. Looking at try-operator-on-main, it has a pretty similiar error message, so maybe it was decided to use that error message instead.

|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::from_error`
Expand Down