about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-08 10:24:46 +0000
committerbors <bors@rust-lang.org>2022-03-08 10:24:46 +0000
commitb97dc20784698730bd7bc1a20eabdcd32066d174 (patch)
tree411126fa7c5a4a0cd31761dcfadbfefa6fc6174a /compiler/rustc_errors/src
parentd2710dbb305a4447b889f11918bc5df96084357c (diff)
parentb879216f079eb5a9f47fab8d59b567859b51fd2c (diff)
downloadrust-b97dc20784698730bd7bc1a20eabdcd32066d174.tar.gz
rust-b97dc20784698730bd7bc1a20eabdcd32066d174.zip
Auto merge of #94734 - matthiaskrgr:rollup-28shqhy, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #91993 (Tweak output for non-exhaustive `match` expression)
 - #92385 (Add Result::{ok, err, and, or, unwrap_or} as const)
 - #94559 (Remove argument from closure in thread::Scope::spawn.)
 - #94580 (Emit `unused_attributes` if a level attr only has a reason)
 - #94586 (Generalize `get_nullable_type` to allow types where null is all-ones.)
 - #94708 (diagnostics: only talk about `Cargo.toml` if running under Cargo)
 - #94712 (promot debug_assert to assert)
 - #94726 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs13
-rw-r--r--compiler/rustc_errors/src/diagnostic_builder.rs1
2 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index a59d91ea789..39ebd57b4b2 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -7,6 +7,7 @@ use crate::SuggestionStyle;
 use crate::ToolMetadata;
 use rustc_lint_defs::Applicability;
 use rustc_serialize::json::Json;
+use rustc_span::edition::LATEST_STABLE_EDITION;
 use rustc_span::{MultiSpan, Span, DUMMY_SP};
 use std::fmt;
 use std::hash::{Hash, Hasher};
@@ -342,6 +343,18 @@ impl Diagnostic {
         self
     }
 
+    /// Help the user upgrade to the latest edition.
+    /// This is factored out to make sure it does the right thing with `Cargo.toml`.
+    pub fn help_use_latest_edition(&mut self) -> &mut Self {
+        if std::env::var_os("CARGO").is_some() {
+            self.help(&format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION));
+        } else {
+            self.help(&format!("pass `--edition {}` to `rustc`", LATEST_STABLE_EDITION));
+        }
+        self.note("for more on editions, read https://doc.rust-lang.org/edition-guide");
+        self
+    }
+
     /// Disallow attaching suggestions this diagnostic.
     /// Any suggestions attached e.g. with the `span_suggestion_*` methods
     /// (before and after the call to `disable_suggestions`) will be ignored.
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs
index 5dc71f16200..98b8b2a569e 100644
--- a/compiler/rustc_errors/src/diagnostic_builder.rs
+++ b/compiler/rustc_errors/src/diagnostic_builder.rs
@@ -409,6 +409,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
         sp: impl Into<MultiSpan>,
         msg: &str,
     ) -> &mut Self);
+    forward!(pub fn help_use_latest_edition(&mut self,) -> &mut Self);
     forward!(pub fn set_is_lint(&mut self,) -> &mut Self);
 
     forward!(pub fn disable_suggestions(&mut self,) -> &mut Self);