Remove various has_errors or err_count uses#120342
Conversation
All errors are local anyway, so we can track them directly
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs
Outdated
Show resolved
Hide resolved
| let err = sess.dcx().err_count(); | ||
| check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix); | ||
| err == sess.dcx().err_count() | ||
| check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix)?; |
There was a problem hiding this comment.
You can drop the trailing ?; and the Ok(()).
There was a problem hiding this comment.
This function returns Result<()> while the _core function returns an ok value
| valid &= check_lhs_nt_follows(sess, def, &tt); | ||
| // We don't handle errors here, the driver will abort | ||
| // after parsing/expansion. we can report every error in every macro this way. | ||
| valid &= check_lhs_nt_follows(sess, def, &tt).is_ok(); |
There was a problem hiding this comment.
Pre-existing, but updating valid here is pointless when it's immediately followed by return.
There was a problem hiding this comment.
Which means check_lhs_nt_follows doesn't need to return a bool.
It would be good to know how/why the driver will abort after parsing/expansion, bonus points if you understand that and can augment this comment appropriately.
There was a problem hiding this comment.
No, this return is in a closure
| assert!( | ||
| !fn_ctxt.errors_reported_since_creation(), | ||
| "Newly created FnCtxt contained errors" | ||
| ); |
There was a problem hiding this comment.
Do you think this assertion just isn't that important? Likewise with the similar one below?
There was a problem hiding this comment.
Yea, one of them just checked that constructing a FnCtxt doesn't have errors. The other was just unusual to me. One could check the error count manually if such a check was desired. I don't think these checks actually caught anything
| // FIXME: statically guarantee this by tainting after the diagnostic is emitted | ||
| self.set_tainted_by_errors( | ||
| tcx.dcx().span_delayed_bug(span, "`report_selection_error` did not emit an error"), | ||
| ); |
There was a problem hiding this comment.
This was weird, good to see it removed.
| if predicate.references_error() { | ||
| return; | ||
| if let Err(e) = predicate.error_reported() { | ||
| return e; |
There was a problem hiding this comment.
Can you just predicate.error_reported()?;?
There was a problem hiding this comment.
No, we return ErrorGuaranteed, not Result
| if predicate.references_error() { | ||
| return; | ||
| if let Err(e) = predicate.error_reported() { | ||
| return e; |
| return e; | ||
| } | ||
| if let Some(e) = self.dcx().has_errors() { | ||
| return e; |
There was a problem hiding this comment.
This has_errors call is unfortunate, as is the one just below :/
There was a problem hiding this comment.
I wonder if it's really necessary.
There was a problem hiding this comment.
Preexisting. I'm not touching these in this PR
There was a problem hiding this comment.
I will get rid of them in follow ups
| return e; | ||
| } | ||
| if let Some(e) = self.tainted_by_errors() { | ||
| return e; |
There was a problem hiding this comment.
But this one doesn't have the has_errors call, nor does the following one. Interesting.
There was a problem hiding this comment.
I think it was just haphazard bugfixing. We'll be able to fix that with sufficiently smart tainting, I'm certain
| .with_note("this may fail depending on what value the parameter takes") | ||
| .emit(); | ||
| return None; | ||
| return Err(guar); |
There was a problem hiding this comment.
No need for the guar local variable, just return directly.
There was a problem hiding this comment.
But it's such a long method chain...
|
|
||
| fn f() -> impl Foo { | ||
| //~^ ERROR the trait bound `i32: Foo` is not satisfied | ||
| //~| ERROR `report_selection_error` did not emit an error |
There was a problem hiding this comment.
I guess this is an improvement? Yeah, seems so.
| _ => { | ||
| let expr = p.parse_expr()?; | ||
| if !args.named_args().is_empty() { | ||
| ecx.dcx().emit_err(errors::PositionalAfterNamed { |
There was a problem hiding this comment.
This seems unconnected with the second half of this commit. Is it necessary?
Also, if necessary, it seems incomplete, because there are two other emit calls in this function. Seems like they should be converted to return created errors as well?
There was a problem hiding this comment.
The others return. this one doesn't
There was a problem hiding this comment.
I see one err.emit() and two emit_err() calls in parse_args. Prior to this change, none of them returned. After this change, one of them returns an Err without emitting, and the other two are unchanged.
There was a problem hiding this comment.
Oh hmm. Need to rethink this one
There was a problem hiding this comment.
The reason I did this is so that expand_format_args_impl (which is the only parse_args caller), doesn't cause follow-up warnings like
warning: named argument `foo` is not used by name
--> $DIR/format-parse-errors.rs:9:9
|
LL | "s {foo} {} {}",
| -- this formatting argument uses named argument `foo` by position
LL | foo = foo,
| ^^^ this named argument is referred to by position in formatting string
|
= note: `#[warn(named_arguments_used_positionally)]` on by default
help: use the named argument by name to avoid ambiguity
|
LL | "s {foo} {foo} {}",
| +++
which are a bit nonsensical considering we already got a
error: positional arguments cannot follow named arguments
--> $DIR/format-parse-errors.rs:10:9
|
LL | foo = foo,
| --------- named argument
LL | bar,
| ^^^ positional arguments must be before named arguments
and the fact that the diagnostic is likely always wrong. So I opted to just make the entire macro expansion go to a DummyResult::any if there were errors during it. This is already done for other errors, so...
There was a problem hiding this comment.
I'm now not clear if you're intending to do more work here ("need to rethink this one") or if you are waiting for a response from me. Can you clarify?
There was a problem hiding this comment.
There are no changes needed. this early return ensures that the macro expansion is poisoned instead of expanding to nonsense that may cause follow up nonsensical diagnostics.
There was a problem hiding this comment.
Basically I think we should merge it as is, but I can also remove the entire commit and file it as a separate PR if you prefer
There was a problem hiding this comment.
Ok, I'll accept that explanation, thanks.
|
These are nice improvements, and it all LGTM except for the fifth commit with the |
|
r=me if you want to exclude the 5th commit (containing the |
|
@bors r+ |
…llaumeGomez Rollup of 11 pull requests Successful merges: - rust-lang#117906 (Improve display of crate name when hovered) - rust-lang#118533 (Suppress unhelpful diagnostics for unresolved top level attributes) - rust-lang#120293 (Deduplicate more sized errors on call exprs) - rust-lang#120295 (Remove `raw_os_nonzero` feature.) - rust-lang#120310 (adapt test for v0 symbol mangling) - rust-lang#120342 (Remove various `has_errors` or `err_count` uses) - rust-lang#120434 (Revert outdated version of "Add the wasm32-wasi-preview2 target") - rust-lang#120445 (Fix some `Arc` allocator leaks) - rust-lang#120475 (Improve error message when `cargo build` is used to build the compiler) - rust-lang#120476 (Remove some unnecessary check logic for lang items in HIR typeck) - rust-lang#120485 (add missing potential_query_instability for keys and values in hashmap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120342 - oli-obk:track_errors6, r=nnethercote Remove various `has_errors` or `err_count` uses follow up to rust-lang#119895 r? `@nnethercote` since you recently did something similar. There are so many more of these, but I wanted to get a PR out instead of growing the commit list indefinitely. The commits all work on their own and can be reviewed commit by commit.
Remove various `has_errors` or `err_count` uses follow up to rust-lang#119895 r? `@nnethercote` since you recently did something similar. There are so many more of these, but I wanted to get a PR out instead of growing the commit list indefinitely. The commits all work on their own and can be reviewed commit by commit.
follow up to #119895
r? @nnethercote since you recently did something similar.
There are so many more of these, but I wanted to get a PR out instead of growing the commit list indefinitely. The commits all work on their own and can be reviewed commit by commit.