Auto merge of #119606 - nnethercote:consuming-emit, r=oli-obk
Consuming `emit` This PR makes `DiagnosticBuilder::emit` consuming, i.e. take `self` instead of `&mut self`. This is good because it doesn't make sense to emit a diagnostic twice. This requires some changes to `DiagnosticBuilder` method changing -- every existing non-consuming chaining method gets a new consuming partner with a `_mv` suffix -- but permits a host of beneficial follow-up changes: more concise code through more chaining, removal of redundant diagnostic construction API methods, and removal of machinery to track the possibility of a diagnostic being emitted multiple times. r? `@compiler-errors`
This commit is contained in:
commit
ca663b06c5
112 changed files with 952 additions and 1275 deletions
|
|
@ -3001,7 +3001,7 @@ fn clean_use_statement_inner<'tcx>(
|
|||
E0780,
|
||||
"anonymous imports cannot be inlined"
|
||||
)
|
||||
.span_label(import.span, "anonymous import")
|
||||
.span_label_mv(import.span, "anonymous import")
|
||||
.emit();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -577,13 +577,13 @@ impl Options {
|
|||
{
|
||||
if !theme_file.is_file() {
|
||||
dcx.struct_err(format!("invalid argument: \"{theme_s}\""))
|
||||
.help("arguments to --theme must be files")
|
||||
.help_mv("arguments to --theme must be files")
|
||||
.emit();
|
||||
return Err(1);
|
||||
}
|
||||
if theme_file.extension() != Some(OsStr::new("css")) {
|
||||
dcx.struct_err(format!("invalid argument: \"{theme_s}\""))
|
||||
.help("arguments to --theme must have a .css extension")
|
||||
.help_mv("arguments to --theme must have a .css extension")
|
||||
.emit();
|
||||
return Err(1);
|
||||
}
|
||||
|
|
@ -595,8 +595,8 @@ impl Options {
|
|||
dcx.struct_warn(format!(
|
||||
"theme file \"{theme_s}\" is missing CSS rules from the default theme",
|
||||
))
|
||||
.warn("the theme may appear incorrect when loaded")
|
||||
.help(format!(
|
||||
.warn_mv("the theme may appear incorrect when loaded")
|
||||
.help_mv(format!(
|
||||
"to see what rules are missing, call `rustdoc --check-theme \"{theme_s}\"`",
|
||||
))
|
||||
.emit();
|
||||
|
|
@ -809,7 +809,7 @@ fn check_deprecated_options(matches: &getopts::Matches, dcx: &rustc_errors::Diag
|
|||
for &flag in deprecated_flags.iter() {
|
||||
if matches.opt_present(flag) {
|
||||
dcx.struct_warn(format!("the `{flag}` flag is deprecated"))
|
||||
.note(
|
||||
.note_mv(
|
||||
"see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
||||
for more information",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -495,16 +495,16 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> {
|
|||
.intersperse("::")
|
||||
.collect::<String>()
|
||||
);
|
||||
let mut err = rustc_errors::struct_span_err!(
|
||||
rustc_errors::struct_span_err!(
|
||||
self.tcx.dcx(),
|
||||
path.span,
|
||||
E0433,
|
||||
"failed to resolve: {label}",
|
||||
);
|
||||
err.span_label(path.span, label);
|
||||
err.note("this error was originally ignored because you are running `rustdoc`");
|
||||
err.note("try running again with `rustc` or `cargo check` and you may get a more detailed error");
|
||||
err.emit();
|
||||
)
|
||||
.span_label_mv(path.span, label)
|
||||
.note_mv("this error was originally ignored because you are running `rustdoc`")
|
||||
.note_mv("try running again with `rustc` or `cargo check` and you may get a more detailed error")
|
||||
.emit();
|
||||
}
|
||||
// We could have an outer resolution that succeeded,
|
||||
// but with generic parameters that failed.
|
||||
|
|
|
|||
|
|
@ -1228,7 +1228,7 @@ impl LinkCollector<'_, '_> {
|
|||
span,
|
||||
"linking to associated items of raw pointers is experimental",
|
||||
)
|
||||
.note("rustdoc does not allow disambiguating between `*const` and `*mut`, and pointers are unstable until it does")
|
||||
.note_mv("rustdoc does not allow disambiguating between `*const` and `*mut`, and pointers are unstable until it does")
|
||||
.emit();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ impl Msrv {
|
|||
if let Some(duplicate) = msrv_attrs.last() {
|
||||
sess.dcx()
|
||||
.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
|
||||
.span_note(msrv_attr.span, "first definition found here")
|
||||
.span_note_mv(msrv_attr.span, "first definition found here")
|
||||
.emit();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ pub fn get_unique_attr<'a>(
|
|||
if let Some(duplicate) = unique_attr {
|
||||
sess.dcx()
|
||||
.struct_span_err(attr.span, format!("`{name}` is defined multiple times"))
|
||||
.span_note(duplicate.span, "first definition found here")
|
||||
.span_note_mv(duplicate.span, "first definition found here")
|
||||
.emit();
|
||||
} else {
|
||||
unique_attr = Some(attr);
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ impl<'a> Parser<'a> {
|
|||
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
|
||||
match parser.parse_mod(&TokenKind::Eof) {
|
||||
Ok((a, i, spans)) => Some((a, i, spans.inner_span)),
|
||||
Err(mut e) => {
|
||||
Err(e) => {
|
||||
e.emit();
|
||||
if sess.can_reset_errors() {
|
||||
sess.reset_errors();
|
||||
|
|
@ -165,7 +165,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
match catch_unwind(move || parser.parse_crate_mod()) {
|
||||
Ok(Ok(k)) => Ok(k),
|
||||
Ok(Err(mut db)) => {
|
||||
Ok(Err(db)) => {
|
||||
db.emit();
|
||||
Err(ParserError::ParseError)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue