about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/errors.rs
diff options
context:
space:
mode:
authorXiretza <xiretza@xiretza.xyz>2022-12-28 23:21:04 +0100
committerXiretza <xiretza@xiretza.xyz>2023-02-01 21:56:28 +0100
commit0d0d36991599d230d4781432391608f9821765fa (patch)
tree9c43880852c0a5bf7654766a9994d83a122d7fb9 /compiler/rustc_parse/src/errors.rs
parenta476683c8478f548adee406e036328412a0f9d19 (diff)
downloadrust-0d0d36991599d230d4781432391608f9821765fa.tar.gz
rust-0d0d36991599d230d4781432391608f9821765fa.zip
Make "use latest edition" subdiagnostic translatable
Diffstat (limited to 'compiler/rustc_parse/src/errors.rs')
-rw-r--r--compiler/rustc_parse/src/errors.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index 5a7e28ce523..145611923ff 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -1,10 +1,9 @@
 use rustc_ast::token::Token;
 use rustc_ast::{Path, Visibility};
-use rustc_errors::{
-    fluent, AddToDiagnostic, Applicability, EmissionGuarantee, HelpUseLatestEdition, IntoDiagnostic,
-};
+use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
 use rustc_macros::{Diagnostic, Subdiagnostic};
 use rustc_session::errors::ExprParenthesesNeeded;
+use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
 use rustc_span::symbol::Ident;
 use rustc_span::{Span, Symbol};
 
@@ -1916,3 +1915,24 @@ pub(crate) struct NegativeBoundsNotSupportedSugg {
     pub num_bounds: usize,
     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 }
+        }
+    }
+}