Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b25a2bb

Browse files
committedDec 28, 2023
fix conflicts in diagnostics
1 parent a173063 commit b25a2bb

File tree

6 files changed

+60
-66
lines changed

6 files changed

+60
-66
lines changed
 

‎compiler/rustc_errors/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use diagnostic_impls::{
4040
};
4141
pub use emitter::ColorConfig;
4242
pub use rustc_error_messages::{
43-
fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle,
43+
fallback_fluent_bundle, fluent_bundle, fluent_raw, DelayDm, DiagnosticMessage, FluentBundle,
4444
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
4545
};
4646
pub use rustc_lint_defs::{pluralize, Applicability};
@@ -60,11 +60,6 @@ use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
6060
use rustc_data_structures::sync::{Lock, Lrc};
6161
use rustc_data_structures::AtomicRef;
6262
use rustc_lint_defs::LintExpectationId;
63-
pub use rustc_error_messages::{
64-
fallback_fluent_bundle, fluent_bundle, fluent_raw, DelayDm, DiagnosticMessage, FluentBundle,
65-
LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage,
66-
};
67-
pub use rustc_lint_defs::{pluralize, Applicability};
6863
use rustc_span::source_map::SourceMap;
6964
use rustc_span::{Loc, Span, DUMMY_SP};
7065
use std::backtrace::{Backtrace, BacktraceStatus};

‎compiler/rustc_macros/src/diagnostics/diagnostic.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ impl<'a> DiagnosticDerive<'a> {
6060
}
6161
(None, Some(raw_label)) => {
6262
quote! {
63-
let mut #diag = #handler.struct_diagnostic(DiagnosticMessage::FluentRaw(#raw_label.into()));
63+
let mut diag = rustc_errors::DiagnosticBuilder::new(
64+
dcx,
65+
level,
66+
DiagnosticMessage::FluentRaw(#raw_label.into())
67+
);
6468
}
6569
}
6670
(Some(_slug), Some(_raw_label)) => {
@@ -78,20 +82,10 @@ impl<'a> DiagnosticDerive<'a> {
7882
}
7983
});
8084

81-
<<<<<<< HEAD
8285
// A lifetime of `'a` causes conflicts, but `_sess` is fine.
8386
let mut imp = structure.gen_impl(quote! {
8487
gen impl<'_sess, G>
8588
rustc_errors::IntoDiagnostic<'_sess, G>
86-
=======
87-
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else {
88-
unreachable!();
89-
};
90-
91-
let mut imp = structure.gen_impl(quote! {
92-
gen impl<'__diagnostic_handler_sess, G>
93-
rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
94-
>>>>>>> bd3289ea826 (more cleanup on diags)
9589
for @Self
9690
where G: rustc_errors::EmissionGuarantee
9791
{

‎compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl DiagnosticDeriveVariantBuilder {
223223
if ident.to_string() == "code" {
224224
self.attrs.insert("code".to_string(), value.clone());
225225
tokens.extend(quote! {
226-
#diag.code(rustc_errors::DiagnosticId::Error(#lit.to_string()));
226+
diag.code(rustc_errors::DiagnosticId::Error(#lit.to_string()));
227227
});
228228
} else if keys.contains(&ident.to_string().as_str()) {
229229
self.attrs.insert(ident.to_string(), value.clone());
@@ -270,7 +270,7 @@ impl DiagnosticDeriveVariantBuilder {
270270
self.code.set_once((), path.span().unwrap());
271271
let code = nested.parse::<syn::LitStr>()?;
272272
tokens.extend(quote! {
273-
#diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
273+
diag.code(rustc_errors::DiagnosticId::Error(#code.to_string()));
274274
});
275275
} else {
276276
keys.iter().find(|key| path.is_ident(key)).map_or_else(
@@ -528,22 +528,22 @@ impl DiagnosticDeriveVariantBuilder {
528528
let fn_name = format_ident!("span_{}", kind);
529529
if let Some(raw_label) = raw_label {
530530
return quote! {
531-
#diag.#fn_name(
531+
diag.#fn_name(
532532
#field_binding,
533533
DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label))
534534
);
535535
};
536536
}
537537
if let Some(raw_label) = self.get_attr(kind.to_string().as_str()) {
538538
quote! {
539-
#diag.#fn_name(
539+
diag.#fn_name(
540540
#field_binding,
541541
DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label))
542542
);
543543
}
544544
} else {
545545
quote! {
546-
#diag.#fn_name(
546+
diag.#fn_name(
547547
#field_binding,
548548
crate::fluent_generated::#fluent_attr_identifier
549549
);
@@ -559,19 +559,18 @@ impl DiagnosticDeriveVariantBuilder {
559559
fluent_attr_identifier: Path,
560560
raw_label: Option<String>,
561561
) -> TokenStream {
562-
let diag = &self.parent.diag;
563562
if let Some(raw_label) = raw_label {
564563
return quote! {
565-
#diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
564+
diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
566565
};
567566
}
568567
if let Some(raw_label) = self.get_attr(kind.to_string().as_str()) {
569568
quote! {
570-
#diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
569+
diag.#kind(DiagnosticMessage::FluentRaw(std::borrow::Cow::Borrowed(#raw_label)));
571570
}
572571
} else {
573572
quote! {
574-
#diag.#kind(crate::fluent_generated::#fluent_attr_identifier);
573+
diag.#kind(crate::fluent_generated::#fluent_attr_identifier);
575574
}
576575
}
577576
}

‎compiler/rustc_parse/src/errors.rs

+44-37
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use crate::parser::{ForbiddenLetReason, TokenDescription};
55
use rustc_ast::token::Token;
66
use rustc_ast::{Path, Visibility};
77
use rustc_errors::{
8-
AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, IntoDiagnostic, Level,
9-
SubdiagnosticMessage, DiagnosticMessage, fluent_raw
8+
fluent_raw, AddToDiagnostic, Applicability, DiagCtxt, DiagnosticBuilder, DiagnosticMessage,
9+
IntoDiagnostic, Level, SubdiagnosticMessage,
1010
};
11-
use rustc_errors::{AddToDiagnostic, Applicability, ErrorGuaranteed, IntoDiagnostic};
1211
use rustc_macros::{Diagnostic, Subdiagnostic};
1312
use rustc_session::errors::ExprParenthesesNeeded;
1413
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
@@ -1243,25 +1242,29 @@ impl<'a> IntoDiagnostic<'a> for ExpectedIdentifier {
12431242
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a> {
12441243
let token_descr = TokenDescription::from_token(&self.token);
12451244

1246-
let mut diag = handler.struct_diagnostic(match token_descr {
1247-
Some(TokenDescription::ReservedIdentifier) => {
1248-
fluent_raw!("expected identifier, found reserved identifier `{$token}`")
1249-
}
1250-
Some(TokenDescription::Keyword) => {
1251-
fluent_raw!("expected identifier, found keyword `{$token}`")
1252-
}
1253-
1254-
Some(TokenDescription::ReservedKeyword) => {
1255-
fluent_raw!("expected identifier, found reserved keyword `{$token}`")
1256-
}
1257-
1258-
Some(TokenDescription::DocComment) => {
1259-
fluent_raw!("expected identifier, found doc comment `{$token}`")
1260-
}
1261-
None => {
1262-
fluent_raw!("expected identifier, found `{$token}`")
1263-
}
1264-
});
1245+
let mut diag = DiagnosticBuilder::new(
1246+
dcx,
1247+
level,
1248+
match token_descr {
1249+
Some(TokenDescription::ReservedIdentifier) => {
1250+
fluent_raw!("expected identifier, found reserved identifier `{$token}`")
1251+
}
1252+
Some(TokenDescription::Keyword) => {
1253+
fluent_raw!("expected identifier, found keyword `{$token}`")
1254+
}
1255+
1256+
Some(TokenDescription::ReservedKeyword) => {
1257+
fluent_raw!("expected identifier, found reserved keyword `{$token}`")
1258+
}
1259+
1260+
Some(TokenDescription::DocComment) => {
1261+
fluent_raw!("expected identifier, found doc comment `{$token}`")
1262+
}
1263+
None => {
1264+
fluent_raw!("expected identifier, found `{$token}`")
1265+
}
1266+
},
1267+
);
12651268
diag.set_span(self.span);
12661269
diag.set_arg("token", self.token);
12671270

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

1306-
let mut diag = handler.struct_diagnostic(match token_descr {
1307-
Some(TokenDescription::ReservedIdentifier) => {
1308-
fluent_raw!("expected `;`, found reserved identifier `{$token}`")
1309-
}
1310-
Some(TokenDescription::Keyword) => {
1311-
fluent_raw!("expected `;`, found keyword `{$token}`")
1312-
}
1313-
Some(TokenDescription::ReservedKeyword) => {
1314-
fluent_raw!("expected `;`, found reserved keyword `{$token}`")
1315-
}
1316-
Some(TokenDescription::DocComment) => {
1317-
fluent_raw!("expected `;`, found doc comment `{$token}`")
1318-
}
1319-
None => fluent_raw!("expected `;`, found `{$token}`"),
1320-
});
1309+
let mut diag = DiagnosticBuilder::new(
1310+
dcx,
1311+
level,
1312+
match token_descr {
1313+
Some(TokenDescription::ReservedIdentifier) => {
1314+
fluent_raw!("expected `;`, found reserved identifier `{$token}`")
1315+
}
1316+
Some(TokenDescription::Keyword) => {
1317+
fluent_raw!("expected `;`, found keyword `{$token}`")
1318+
}
1319+
Some(TokenDescription::ReservedKeyword) => {
1320+
fluent_raw!("expected `;`, found reserved keyword `{$token}`")
1321+
}
1322+
Some(TokenDescription::DocComment) => {
1323+
fluent_raw!("expected `;`, found doc comment `{$token}`")
1324+
}
1325+
None => fluent_raw!("expected `;`, found `{$token}`"),
1326+
},
1327+
);
13211328
diag.set_span(self.span);
13221329
diag.set_arg("token", self.token);
13231330

‎compiler/rustc_parse/src/parser/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::attr;
55
use rustc_ast::token::{self, Delimiter, Nonterminal};
66
use rustc_errors::fluent_raw;
77
use rustc_errors::DiagnosticMessage;
8-
use rustc_errors::{error_code, Diagnostic, IntoDiagnostic, PResult};
8+
use rustc_errors::{error_code, Diagnostic, PResult};
99
use rustc_span::{sym, BytePos, Span};
1010
use std::borrow::Cow;
1111
use std::convert::TryInto;
@@ -225,7 +225,7 @@ impl<'a> Parser<'a> {
225225
.span_label(prev_outer_attr_sp, "previous outer attribute");
226226
diag
227227
}
228-
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.struct_span_err(
228+
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.dcx().struct_span_err(
229229
attr_sp,
230230
"an inner attribute is not permitted in this context",
231231
),

‎compiler/rustc_parse/src/parser/item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
22
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
33
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
44
use crate::errors::{self, MacroExpandsToAdtField};
5-
use crate::fluent_generated as fluent;
65
use ast::StaticItem;
76
use rustc_ast::ast::*;
87
use rustc_ast::ptr::P;

0 commit comments

Comments
 (0)
Please sign in to comment.