mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Make "use latest edition" subdiagnostic translatable
This commit is contained in:
parent
a476683c84
commit
0d0d369915
@ -57,3 +57,7 @@ hir_typeck_lang_start_incorrect_param = parameter {$param_num} of the `start` la
|
|||||||
|
|
||||||
hir_typeck_lang_start_incorrect_ret_ty = the return type of the `start` lang item is incorrect
|
hir_typeck_lang_start_incorrect_ret_ty = the return type of the `start` lang item is incorrect
|
||||||
.suggestion = change the type from `{$found_ty}` to `{$expected_ty}`
|
.suggestion = change the type from `{$found_ty}` to `{$expected_ty}`
|
||||||
|
|
||||||
|
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
|
||||||
|
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
|
||||||
|
hir_typeck_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
|
||||||
|
@ -574,3 +574,7 @@ parse_negative_bounds_not_supported = negative bounds are not supported
|
|||||||
[one] remove the bound
|
[one] remove the bound
|
||||||
*[other] remove the bounds
|
*[other] remove the bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
|
||||||
|
parse_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`
|
||||||
|
parse_note_edition_guide = for more on editions, read https://doc.rust-lang.org/edition-guide
|
||||||
|
@ -7,7 +7,6 @@ use rustc_data_structures::fx::FxHashMap;
|
|||||||
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
|
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
|
||||||
use rustc_error_messages::FluentValue;
|
use rustc_error_messages::FluentValue;
|
||||||
use rustc_lint_defs::{Applicability, LintExpectationId};
|
use rustc_lint_defs::{Applicability, LintExpectationId};
|
||||||
use rustc_span::edition::LATEST_STABLE_EDITION;
|
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -1071,39 +1070,3 @@ impl PartialEq for Diagnostic {
|
|||||||
self.keys() == other.keys()
|
self.keys() == other.keys()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum HelpUseLatestEdition {
|
|
||||||
Cargo,
|
|
||||||
Standalone,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HelpUseLatestEdition {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
if std::env::var_os("CARGO").is_some() { Self::Cargo } else { Self::Standalone }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AddToDiagnostic for HelpUseLatestEdition {
|
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, f: F)
|
|
||||||
where
|
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
||||||
{
|
|
||||||
let msg = f(
|
|
||||||
diag,
|
|
||||||
match self {
|
|
||||||
Self::Cargo => {
|
|
||||||
format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION)
|
|
||||||
}
|
|
||||||
Self::Standalone => {
|
|
||||||
format!("pass `--edition {}` to `rustc`", LATEST_STABLE_EDITION)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
diag.help(msg);
|
|
||||||
|
|
||||||
let msg =
|
|
||||||
f(diag, "for more on editions, read https://doc.rust-lang.org/edition-guide".into());
|
|
||||||
diag.note(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -378,7 +378,7 @@ pub struct DelayedBugPanic;
|
|||||||
|
|
||||||
pub use diagnostic::{
|
pub use diagnostic::{
|
||||||
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
||||||
DiagnosticStyledString, HelpUseLatestEdition, IntoDiagnosticArg, SubDiagnostic,
|
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
||||||
};
|
};
|
||||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
|
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
|
||||||
pub use diagnostic_impls::{DiagnosticArgFromDisplay, DiagnosticSymbolList};
|
pub use diagnostic_impls::{DiagnosticArgFromDisplay, DiagnosticSymbolList};
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
use rustc_errors::{AddToDiagnostic, Applicability, Diagnostic, MultiSpan, SubdiagnosticMessage};
|
use rustc_errors::{AddToDiagnostic, Applicability, Diagnostic, MultiSpan, SubdiagnosticMessage};
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_span::{symbol::Ident, Span};
|
use rustc_span::{
|
||||||
|
edition::{Edition, LATEST_STABLE_EDITION},
|
||||||
|
symbol::Ident,
|
||||||
|
Span,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_typeck_field_multiply_specified_in_initializer, code = "E0062")]
|
#[diag(hir_typeck_field_multiply_specified_in_initializer, code = "E0062")]
|
||||||
@ -205,3 +209,24 @@ pub struct LangStartIncorrectRetTy<'tcx> {
|
|||||||
pub expected_ty: Ty<'tcx>,
|
pub expected_ty: Ty<'tcx>,
|
||||||
pub found_ty: Ty<'tcx>,
|
pub found_ty: Ty<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub enum HelpUseLatestEdition {
|
||||||
|
#[help(hir_typeck_help_set_edition_cargo)]
|
||||||
|
#[note(hir_typeck_note_edition_guide)]
|
||||||
|
Cargo { edition: Edition },
|
||||||
|
#[help(hir_typeck_help_set_edition_standalone)]
|
||||||
|
#[note(hir_typeck_note_edition_guide)]
|
||||||
|
Standalone { edition: Edition },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HelpUseLatestEdition {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let edition = LATEST_STABLE_EDITION;
|
||||||
|
if std::env::var_os("CARGO").is_some() {
|
||||||
|
Self::Cargo { edition }
|
||||||
|
} else {
|
||||||
|
Self::Standalone { edition }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ use crate::coercion::DynamicCoerceMany;
|
|||||||
use crate::errors::TypeMismatchFruTypo;
|
use crate::errors::TypeMismatchFruTypo;
|
||||||
use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive};
|
use crate::errors::{AddressOfTemporaryTaken, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive};
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct,
|
FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition,
|
||||||
YieldExprOutsideOfGenerator,
|
YieldExprOutsideOfGenerator,
|
||||||
};
|
};
|
||||||
use crate::fatally_break_rust;
|
use crate::fatally_break_rust;
|
||||||
@ -24,7 +24,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
pluralize, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
|
pluralize, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
|
||||||
DiagnosticId, ErrorGuaranteed, HelpUseLatestEdition, StashKey,
|
DiagnosticId, ErrorGuaranteed, StashKey,
|
||||||
};
|
};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use rustc_ast::token::Token;
|
use rustc_ast::token::Token;
|
||||||
use rustc_ast::{Path, Visibility};
|
use rustc_ast::{Path, Visibility};
|
||||||
use rustc_errors::{
|
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
|
||||||
fluent, AddToDiagnostic, Applicability, EmissionGuarantee, HelpUseLatestEdition, IntoDiagnostic,
|
|
||||||
};
|
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_session::errors::ExprParenthesesNeeded;
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
|
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
@ -1916,3 +1915,24 @@ pub(crate) struct NegativeBoundsNotSupportedSugg {
|
|||||||
pub num_bounds: usize,
|
pub num_bounds: usize,
|
||||||
pub fixed: String,
|
pub fixed: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub enum HelpUseLatestEdition {
|
||||||
|
#[help(parse_help_set_edition_cargo)]
|
||||||
|
#[note(parse_note_edition_guide)]
|
||||||
|
Cargo { edition: Edition },
|
||||||
|
#[help(parse_help_set_edition_standalone)]
|
||||||
|
#[note(parse_note_edition_guide)]
|
||||||
|
Standalone { edition: Edition },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HelpUseLatestEdition {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let edition = LATEST_STABLE_EDITION;
|
||||||
|
if std::env::var_os("CARGO").is_some() {
|
||||||
|
Self::Cargo { edition }
|
||||||
|
} else {
|
||||||
|
Self::Standalone { edition }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,15 +11,16 @@ use crate::errors::{
|
|||||||
ComparisonInterpretedAsGeneric, ComparisonOrShiftInterpretedAsGenericSugg,
|
ComparisonInterpretedAsGeneric, ComparisonOrShiftInterpretedAsGenericSugg,
|
||||||
DoCatchSyntaxRemoved, DotDotDot, EqFieldInit, ExpectedElseBlock, ExpectedEqForLetExpr,
|
DoCatchSyntaxRemoved, DotDotDot, EqFieldInit, ExpectedElseBlock, ExpectedEqForLetExpr,
|
||||||
ExpectedExpressionFoundLet, FieldExpressionWithGeneric, FloatLiteralRequiresIntegerPart,
|
ExpectedExpressionFoundLet, FieldExpressionWithGeneric, FloatLiteralRequiresIntegerPart,
|
||||||
FoundExprWouldBeStmt, IfExpressionLetSomeSub, IfExpressionMissingCondition,
|
FoundExprWouldBeStmt, HelpUseLatestEdition, IfExpressionLetSomeSub,
|
||||||
IfExpressionMissingThenBlock, IfExpressionMissingThenBlockSub, InvalidBlockMacroSegment,
|
IfExpressionMissingCondition, IfExpressionMissingThenBlock, IfExpressionMissingThenBlockSub,
|
||||||
InvalidComparisonOperator, InvalidComparisonOperatorSub, InvalidInterpolatedExpression,
|
InvalidBlockMacroSegment, InvalidComparisonOperator, InvalidComparisonOperatorSub,
|
||||||
InvalidLiteralSuffixOnTupleIndex, InvalidLogicalOperator, InvalidLogicalOperatorSub,
|
InvalidInterpolatedExpression, InvalidLiteralSuffixOnTupleIndex, InvalidLogicalOperator,
|
||||||
LabeledLoopInBreak, LeadingPlusNotSupported, LeftArrowOperator, LifetimeInBorrowExpression,
|
InvalidLogicalOperatorSub, LabeledLoopInBreak, LeadingPlusNotSupported, LeftArrowOperator,
|
||||||
MacroInvocationWithQualifiedPath, MalformedLoopLabel, MatchArmBodyWithoutBraces,
|
LifetimeInBorrowExpression, MacroInvocationWithQualifiedPath, MalformedLoopLabel,
|
||||||
MatchArmBodyWithoutBracesSugg, MissingCommaAfterMatchArm, MissingDotDot, MissingInInForLoop,
|
MatchArmBodyWithoutBraces, MatchArmBodyWithoutBracesSugg, MissingCommaAfterMatchArm,
|
||||||
MissingInInForLoopSub, MissingSemicolonBeforeArray, NoFieldsForFnCall, NotAsNegationOperator,
|
MissingDotDot, MissingInInForLoop, MissingInInForLoopSub, MissingSemicolonBeforeArray,
|
||||||
NotAsNegationOperatorSub, OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields,
|
NoFieldsForFnCall, NotAsNegationOperator, NotAsNegationOperatorSub,
|
||||||
|
OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields,
|
||||||
RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere,
|
RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere,
|
||||||
StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedIfWithIf,
|
StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedIfWithIf,
|
||||||
UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
|
UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses,
|
||||||
@ -39,8 +40,8 @@ use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, R
|
|||||||
use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind};
|
use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
|
AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
|
||||||
HelpUseLatestEdition, IntoDiagnostic, PResult, StashKey,
|
PResult, StashKey,
|
||||||
};
|
};
|
||||||
use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded};
|
use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded};
|
||||||
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
|
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
|
||||||
|
@ -3,7 +3,7 @@ use crate::errors::{
|
|||||||
BoundsNotAllowedOnTraitAliases, ConstGlobalCannotBeMutable, ConstLetMutuallyExclusive,
|
BoundsNotAllowedOnTraitAliases, ConstGlobalCannotBeMutable, ConstLetMutuallyExclusive,
|
||||||
DefaultNotFollowedByItem, DocCommentDoesNotDocumentAnything, EnumStructMutuallyExclusive,
|
DefaultNotFollowedByItem, DocCommentDoesNotDocumentAnything, EnumStructMutuallyExclusive,
|
||||||
ExpectedTraitInTraitImplFoundType, ExternCrateNameWithDashes, ExternCrateNameWithDashesSugg,
|
ExpectedTraitInTraitImplFoundType, ExternCrateNameWithDashes, ExternCrateNameWithDashesSugg,
|
||||||
ExternItemCannotBeConst, MissingConstType, MissingForInTraitImpl,
|
ExternItemCannotBeConst, HelpUseLatestEdition, MissingConstType, MissingForInTraitImpl,
|
||||||
MissingKeywordForItemDefinition, MissingTraitInTraitImpl, SelfArgumentPointer,
|
MissingKeywordForItemDefinition, MissingTraitInTraitImpl, SelfArgumentPointer,
|
||||||
TraitAliasCannotBeAuto, TraitAliasCannotBeUnsafe, UnexpectedTokenAfterStructName,
|
TraitAliasCannotBeAuto, TraitAliasCannotBeUnsafe, UnexpectedTokenAfterStructName,
|
||||||
UseEmptyBlockNotSemi, VisibilityNotFollowedByItem,
|
UseEmptyBlockNotSemi, VisibilityNotFollowedByItem,
|
||||||
@ -26,8 +26,8 @@ use rustc_ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, Visibility
|
|||||||
use rustc_ast::{MacCall, MacDelimiter};
|
use rustc_ast::{MacCall, MacDelimiter};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, HelpUseLatestEdition,
|
struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult,
|
||||||
IntoDiagnostic, PResult, StashKey,
|
StashKey,
|
||||||
};
|
};
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::lev_distance::lev_distance;
|
use rustc_span::lev_distance::lev_distance;
|
||||||
|
Loading…
Reference in New Issue
Block a user