Skip to content

Commit

Permalink
remove messages.ftl from parser
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 14, 2023
1 parent 4286151 commit bf3b14d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 920 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_mir_dataflow::DEFAULT_LOCALE_RESOURCE,
rustc_mir_transform::DEFAULT_LOCALE_RESOURCE,
rustc_monomorphize::DEFAULT_LOCALE_RESOURCE,
rustc_parse::DEFAULT_LOCALE_RESOURCE,
rustc_passes::DEFAULT_LOCALE_RESOURCE,
rustc_privacy::DEFAULT_LOCALE_RESOURCE,
rustc_query_system::DEFAULT_LOCALE_RESOURCE,
Expand Down
868 changes: 0 additions & 868 deletions compiler/rustc_parse/messages.ftl

This file was deleted.

38 changes: 16 additions & 22 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
use rustc_span::symbol::Ident;
use rustc_span::{Span, Symbol};

use crate::fluent_generated as fluent;
use crate::parser::{ForbiddenLetReason, TokenDescription};

#[derive(Diagnostic)]
Expand Down Expand Up @@ -1206,16 +1205,18 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {

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

Some(TokenDescription::DocComment) => {
fluent::parse_expected_identifier_found_doc_comment_str
"expected identifier, found doc comment `{$token}`"
}
None => fluent::parse_expected_identifier_found_str,

None => "expected identifier, found `{$token}`",
});
diag.set_span(self.span);
diag.set_arg("token", self.token);
Expand Down Expand Up @@ -1262,28 +1263,21 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
let token_descr = TokenDescription::from_token(&self.token);

let mut diag = handler.struct_diagnostic(match token_descr {
Some(TokenDescription::ReservedIdentifier) => DiagnosticMessage::Str(Cow::from(
"expected `;`, found reserved identifier `{$token}`",
)),
Some(TokenDescription::Keyword) => {
DiagnosticMessage::Str(Cow::from("expected `;`, found keyword `{$token}`"))
Some(TokenDescription::ReservedIdentifier) => {
"expected `;`, found reserved identifier `{$token}`"
}
Some(TokenDescription::Keyword) => "expected `;`, found keyword `{$token}`",
Some(TokenDescription::ReservedKeyword) => {
DiagnosticMessage::Str(Cow::from("expected `;`, found reserved keyword `{$token}`"))
}
Some(TokenDescription::DocComment) => {
DiagnosticMessage::Str(Cow::from("expected `;`, found doc comment `{$token}`"))
"expected `;`, found reserved keyword `{$token}`"
}
None => DiagnosticMessage::Str(Cow::from("expected `;`, found `{$token}`")),
Some(TokenDescription::DocComment) => "expected `;`, found doc comment `{$token}`",
None => "expected `;`, found `{$token}`",
});
diag.set_span(self.span);
diag.set_arg("token", self.token);

if let Some(unexpected_token_label) = self.unexpected_token_label {
diag.span_label(
unexpected_token_label,
DiagnosticMessage::Str(Cow::from("unexpected token")),
);
diag.span_label(unexpected_token_label, "unexpected token");
}

self.sugg.add_to_diagnostic(&mut diag);
Expand Down Expand Up @@ -1652,15 +1646,15 @@ impl AddToDiagnostic for FnTraitMissingParen {
rustc_errors::SubdiagnosticMessage,
) -> rustc_errors::SubdiagnosticMessage,
{
diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren);
diag.span_label(self.span, "`Fn` bounds require arguments in parentheses");
let applicability = if self.machine_applicable {
Applicability::MachineApplicable
} else {
Applicability::MaybeIncorrect
};
diag.span_suggestion_short(
self.span.shrink_to_hi(),
crate::fluent_generated::parse_add_paren,
"try adding parentheses",
"()",
applicability,
);
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ use rustc_ast::{AttrItem, Attribute, MetaItem};
use rustc_ast_pretty::pprust;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Diagnostic, FatalError, Level, PResult};
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_fluent_macro::fluent_messages;
use rustc_session::parse::ParseSess;
use rustc_span::{FileName, SourceFile, Span};

use std::path::Path;

pub const MACRO_ARGUMENTS: Option<&str> = Some("macro arguments");
Expand All @@ -37,8 +34,6 @@ pub mod validate_attr;

mod errors;

fluent_messages! { "../messages.ftl" }

// A bunch of utility functions of the form `parse_<thing>_from_<source>`
// where <thing> includes crate, expr, item, stmt, tts, and one that
// uses a HOF to parse anything, and <source> includes file and
Expand Down
39 changes: 20 additions & 19 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::errors::{InvalidMetaItem, SuffixedLiteralInAttribute};
use crate::fluent_generated as fluent;

use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle};
use crate::errors::{InvalidMetaItem, SuffixedLiteralInAttribute};
use rustc_ast as ast;
use rustc_ast::attr;
use rustc_ast::token::{self, Delimiter, Nonterminal};
Expand Down Expand Up @@ -58,9 +56,10 @@ impl<'a> Parser<'a> {
let span = self.token.span;
let mut err = self.sess.span_diagnostic.struct_span_err_with_code(
span,
fluent::parse_inner_doc_comment_not_permitted,
"expected outer doc comment",
error_code!(E0753),
);
err.set_arg("item_type", "doc comment");
if let Some(replacement_span) = self.annotate_following_item_if_applicable(
&mut err,
span,
Expand All @@ -69,10 +68,10 @@ impl<'a> Parser<'a> {
token::CommentKind::Block => OuterAttributeType::DocBlockComment,
},
) {
err.note(fluent::parse_note);
err.note("inner doc comments like this (starting with `//!` or `/*!`) can only appear before items");
err.span_suggestion_verbose(
replacement_span,
fluent::parse_suggestion,
"you might have meant to write a regular comment",
"",
rustc_errors::Applicability::MachineApplicable,
);
Expand Down Expand Up @@ -176,10 +175,10 @@ impl<'a> Parser<'a> {
Ok(Some(item)) => {
// FIXME(#100717)
err.set_arg("item", item.kind.descr());
err.span_label(item.span, fluent::parse_label_does_not_annotate_this);
err.span_label(item.span, "the inner {$item_type} doesn't annotate this {$item}");
err.span_suggestion_verbose(
replacement_span,
fluent::parse_sugg_change_inner_to_outer,
"to annotate the {$item}, change the {$item_type} from inner to outer style",
match attr_type {
OuterAttributeType::Attribute => "",
OuterAttributeType::DocBlockComment => "*",
Expand All @@ -203,27 +202,29 @@ impl<'a> Parser<'a> {
Some(InnerAttrForbiddenReason::AfterOuterDocComment { prev_doc_comment_span }) => {
let mut diag = self.struct_span_err(
attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
"an inner attribute is not permitted following an outer doc comment",
);
diag.span_label(attr_sp, fluent::parse_label_attr)
.span_label(prev_doc_comment_span, fluent::parse_label_prev_doc_comment);
diag.span_label(attr_sp, "not permitted following an outer doc comment")
.span_label(prev_doc_comment_span, "previous doc comment");
diag
}
Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => {
let mut diag = self.struct_span_err(
attr_sp,
fluent::parse_inner_attr_not_permitted_after_outer_attr,
"an inner attribute is not permitted following an outer attribute",
);
diag.span_label(attr_sp, fluent::parse_label_attr)
.span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr);
diag.span_label(attr_sp, "not permitted following an outer attribute")
.span_label(prev_outer_attr_sp, "previous outer attribute");
diag
}
Some(InnerAttrForbiddenReason::InCodeBlock) | None => {
self.struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted)
}
Some(InnerAttrForbiddenReason::InCodeBlock) | None => self.struct_span_err(
attr_sp,
"an inner attribute is not permitted in this context",
),
};

diag.note(fluent::parse_inner_attr_explanation);
diag.set_arg("item_type", "attribute");
diag.note("inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files");
if self
.annotate_following_item_if_applicable(
&mut diag,
Expand All @@ -232,7 +233,7 @@ impl<'a> Parser<'a> {
)
.is_some()
{
diag.note(fluent::parse_outer_attr_explanation);
diag.note("outer attributes, like `#[test]`, annotate the item following them");
};
diag.emit();
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::errors::{
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
};

use crate::fluent_generated as fluent;
use crate::parser;
use rustc_ast as ast;
use rustc_ast::ptr::P;
Expand Down Expand Up @@ -1102,7 +1101,7 @@ impl<'a> Parser<'a> {
if self.eat(&token::Gt) {
e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
fluent::parse_sugg_turbofish_syntax,
"use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments",
"::",
Applicability::MaybeIncorrect,
)
Expand Down Expand Up @@ -2743,7 +2742,7 @@ impl<'a> Parser<'a> {
let mut err = self.struct_span_err(comma_span, "unexpected `,` in pattern");
if let Ok(seq_snippet) = self.span_to_snippet(seq_span) {
if is_mac_invoc {
err.note(fluent::parse_macro_expands_to_match_arm);
err.note("macros cannot expand to match arms");
} else {
err.multipart_suggestion(
format!(
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -1464,7 +1463,7 @@ impl<'a> Parser<'a> {

if this.token == token::Not {
if let Err(mut err) = this.unexpected::<()>() {
err.note(fluent::parse_macro_expands_to_enum_variant).emit();
err.note("macros cannot expand to enum variants").emit();
}

this.bump();
Expand Down

0 comments on commit bf3b14d

Please sign in to comment.