summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_typeck/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_hir_typeck/src/errors.rs')
-rw-r--r--compiler/rustc_hir_typeck/src/errors.rs47
1 files changed, 35 insertions, 12 deletions
diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs
index 5b4fd5e4a..3eee2278d 100644
--- a/compiler/rustc_hir_typeck/src/errors.rs
+++ b/compiler/rustc_hir_typeck/src/errors.rs
@@ -1,8 +1,13 @@
//! Errors emitted by `rustc_hir_typeck`.
+use crate::fluent_generated as fluent;
use rustc_errors::{AddToDiagnostic, Applicability, Diagnostic, MultiSpan, SubdiagnosticMessage};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
-use rustc_span::{symbol::Ident, Span};
+use rustc_span::{
+ edition::{Edition, LATEST_STABLE_EDITION},
+ symbol::Ident,
+ Span,
+};
#[derive(Diagnostic)]
#[diag(hir_typeck_field_multiply_specified_in_initializer, code = "E0062")]
@@ -10,7 +15,7 @@ pub struct FieldMultiplySpecifiedInInitializer {
#[primary_span]
#[label]
pub span: Span,
- #[label(previous_use_label)]
+ #[label(hir_typeck_previous_use_label)]
pub prev_span: Span,
pub ident: Ident,
}
@@ -20,9 +25,9 @@ pub struct FieldMultiplySpecifiedInInitializer {
pub struct ReturnStmtOutsideOfFnBody {
#[primary_span]
pub span: Span,
- #[label(encl_body_label)]
+ #[label(hir_typeck_encl_body_label)]
pub encl_body_span: Option<Span>,
- #[label(encl_fn_label)]
+ #[label(hir_typeck_encl_fn_label)]
pub encl_fn_span: Option<Span>,
}
@@ -153,20 +158,17 @@ impl AddToDiagnostic for TypeMismatchFruTypo {
// Only explain that `a ..b` is a range if it's split up
if self.expr_span.between(self.fru_span).is_empty() {
- diag.span_note(
- self.expr_span.to(self.fru_span),
- rustc_errors::fluent::hir_typeck_fru_note,
- );
+ diag.span_note(self.expr_span.to(self.fru_span), fluent::hir_typeck_fru_note);
} else {
let mut multispan: MultiSpan = vec![self.expr_span, self.fru_span].into();
- multispan.push_span_label(self.expr_span, rustc_errors::fluent::hir_typeck_fru_expr);
- multispan.push_span_label(self.fru_span, rustc_errors::fluent::hir_typeck_fru_expr2);
- diag.span_note(multispan, rustc_errors::fluent::hir_typeck_fru_note);
+ multispan.push_span_label(self.expr_span, fluent::hir_typeck_fru_expr);
+ multispan.push_span_label(self.fru_span, fluent::hir_typeck_fru_expr2);
+ diag.span_note(multispan, fluent::hir_typeck_fru_note);
}
diag.span_suggestion(
self.expr_span.shrink_to_hi(),
- rustc_errors::fluent::hir_typeck_fru_suggestion,
+ fluent::hir_typeck_fru_suggestion,
", ",
Applicability::MaybeIncorrect,
);
@@ -205,3 +207,24 @@ pub struct LangStartIncorrectRetTy<'tcx> {
pub expected_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 }
+ }
+ }
+}