Skip to content

Commit

Permalink
fix conflicts in diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Dec 28, 2023
1 parent a173063 commit b25a2bb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 66 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use diagnostic_impls::{
};
pub use emitter::ColorConfig;
pub use rustc_error_messages::{
fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle,
fallback_fluent_bundle, fluent_bundle, fluent_raw, DelayDm, DiagnosticMessage, FluentBundle,
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
};
pub use rustc_lint_defs::{pluralize, Applicability};
Expand All @@ -60,11 +60,6 @@ use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_data_structures::AtomicRef;
use rustc_lint_defs::LintExpectationId;
pub use rustc_error_messages::{
fallback_fluent_bundle, fluent_bundle, fluent_raw, DelayDm, DiagnosticMessage, FluentBundle,
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
};
pub use rustc_lint_defs::{pluralize, Applicability};
use rustc_span::source_map::SourceMap;
use rustc_span::{Loc, Span, DUMMY_SP};
use std::backtrace::{Backtrace, BacktraceStatus};
Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_macros/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ impl<'a> DiagnosticDerive<'a> {
}
(None, Some(raw_label)) => {
quote! {
let mut #diag = #handler.struct_diagnostic(DiagnosticMessage::FluentRaw(#raw_label.into()));
let mut diag = rustc_errors::DiagnosticBuilder::new(
dcx,
level,
DiagnosticMessage::FluentRaw(#raw_label.into())
);
}
}
(Some(_slug), Some(_raw_label)) => {
Expand All @@ -78,20 +82,10 @@ impl<'a> DiagnosticDerive<'a> {
}
});

<<<<<<< HEAD
// A lifetime of `'a` causes conflicts, but `_sess` is fine.
let mut imp = structure.gen_impl(quote! {
gen impl<'_sess, G>
rustc_errors::IntoDiagnostic<'_sess, G>
=======
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else {
unreachable!();
};

let mut imp = structure.gen_impl(quote! {
gen impl<'__diagnostic_handler_sess, G>
rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
>>>>>>> bd3289ea826 (more cleanup on diags)
for @Self
where G: rustc_errors::EmissionGuarantee
{
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl DiagnosticDeriveVariantBuilder {
if ident.to_string() == "code" {
self.attrs.insert("code".to_string(), value.clone());
tokens.extend(quote! {
#diag.code(rustc_errors::DiagnosticId::Error(#lit.to_string()));
diag.code(rustc_errors::DiagnosticId::Error(#lit.to_string()));
});
} else if keys.contains(&ident.to_string().as_str()) {
self.attrs.insert(ident.to_string(), value.clone());
Expand Down Expand Up @@ -270,7 +270,7 @@ impl DiagnosticDeriveVariantBuilder {
self.code.set_once((), path.span().unwrap());
let code = nested.parse::<syn::LitStr>()?;
tokens.extend(quote! {
#diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
});
} else {
keys.iter().find(|key| path.is_ident(key)).map_or_else(
Expand Down Expand Up @@ -528,22 +528,22 @@ impl DiagnosticDeriveVariantBuilder {
let fn_name = format_ident!("span_{}", kind);
if let Some(raw_label) = raw_label {
return quote! {
#diag.#fn_name(
diag.#fn_name(
#field_binding,
DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label))
);
};
}
if let Some(raw_label) = self.get_attr(kind.to_string().as_str()) {
quote! {
#diag.#fn_name(
diag.#fn_name(
#field_binding,
DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label))
);
}
} else {
quote! {
#diag.#fn_name(
diag.#fn_name(
#field_binding,
crate::fluent_generated::#fluent_attr_identifier
);
Expand All @@ -559,19 +559,18 @@ impl DiagnosticDeriveVariantBuilder {
fluent_attr_identifier: Path,
raw_label: Option<String>,
) -> TokenStream {
let diag = &self.parent.diag;
if let Some(raw_label) = raw_label {
return quote! {
#diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
};
}
if let Some(raw_label) = self.get_attr(kind.to_string().as_str()) {
quote! {
#diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
}
} else {
quote! {
#diag.#kind(crate::fluent_generated::#fluent_attr_identifier);
diag.#kind(crate::fluent_generated::#fluent_attr_identifier);
}
}
}
Expand Down
81 changes: 44 additions & 37 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use crate::parser::{ForbiddenLetReason, TokenDescription};
use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility};
use rustc_errors::{
AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, IntoDiagnostic, Level,
SubdiagnosticMessage, DiagnosticMessage, fluent_raw
fluent_raw, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, DiagnosticMessage,
IntoDiagnostic, Level, SubdiagnosticMessage,
};
use rustc_errors::{AddToDiagnostic, Applicability, ErrorGuaranteed, IntoDiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
Expand Down Expand Up @@ -1243,25 +1242,29 @@ impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
let token_descr = TokenDescription::from_token(&self.token);

let mut diag = handler.struct_diagnostic(match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent_raw!("expected identifier, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
fluent_raw!("expected identifier, found keyword `{$token}`")
}

Some(TokenDescription::ReservedKeyword) => {
fluent_raw!("expected identifier, found reserved keyword `{$token}`")
}

Some(TokenDescription::DocComment) => {
fluent_raw!("expected identifier, found doc comment `{$token}`")
}
None => {
fluent_raw!("expected identifier, found `{$token}`")
}
});
let mut diag = DiagnosticBuilder::new(
dcx,
level,
match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent_raw!("expected identifier, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
fluent_raw!("expected identifier, found keyword `{$token}`")
}

Some(TokenDescription::ReservedKeyword) => {
fluent_raw!("expected identifier, found reserved keyword `{$token}`")
}

Some(TokenDescription::DocComment) => {
fluent_raw!("expected identifier, found doc comment `{$token}`")
}
None => {
fluent_raw!("expected identifier, found `{$token}`")
}
},
);
diag.set_span(self.span);
diag.set_arg("token", self.token);

Expand Down Expand Up @@ -1303,21 +1306,25 @@ impl<'a> IntoDiagnostic<'a> for ExpectedSemi {
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
let token_descr = TokenDescription::from_token(&self.token);

let mut diag = handler.struct_diagnostic(match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent_raw!("expected `;`, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
fluent_raw!("expected `;`, found keyword `{$token}`")
}
Some(TokenDescription::ReservedKeyword) => {
fluent_raw!("expected `;`, found reserved keyword `{$token}`")
}
Some(TokenDescription::DocComment) => {
fluent_raw!("expected `;`, found doc comment `{$token}`")
}
None => fluent_raw!("expected `;`, found `{$token}`"),
});
let mut diag = DiagnosticBuilder::new(
dcx,
level,
match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent_raw!("expected `;`, found reserved identifier `{$token}`")
}
Some(TokenDescription::Keyword) => {
fluent_raw!("expected `;`, found keyword `{$token}`")
}
Some(TokenDescription::ReservedKeyword) => {
fluent_raw!("expected `;`, found reserved keyword `{$token}`")
}
Some(TokenDescription::DocComment) => {
fluent_raw!("expected `;`, found doc comment `{$token}`")
}
None => fluent_raw!("expected `;`, found `{$token}`"),
},
);
diag.set_span(self.span);
diag.set_arg("token", self.token);

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_ast::attr;
use rustc_ast::token::{self, Delimiter, Nonterminal};
use rustc_errors::fluent_raw;
use rustc_errors::DiagnosticMessage;
use rustc_errors::{error_code, Diagnostic, IntoDiagnostic, PResult};
use rustc_errors::{error_code, Diagnostic, PResult};
use rustc_span::{sym, BytePos, Span};
use std::borrow::Cow;
use std::convert::TryInto;
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'a> Parser<'a> {
.span_label(prev_outer_attr_sp, "previous outer attribute");
diag
}
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.struct_span_err(
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.dcx().struct_span_err(
attr_sp,
"an inner attribute is not permitted in this context",
),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
use crate::errors::{self, MacroExpandsToAdtField};
use crate::fluent_generated as fluent;
use ast::StaticItem;
use rustc_ast::ast::*;
use rustc_ast::ptr::P;
Expand Down

0 comments on commit b25a2bb

Please sign in to comment.