diff options
| author | bors <bors@rust-lang.org> | 2021-06-25 18:16:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-25 18:16:37 +0000 |
| commit | 0d7f236b8a255b7e0afa19223bfe72cbaf9cc2d5 (patch) | |
| tree | 0081c36ba17f9bc754420b0f3d7968eb67447763 /compiler | |
| parent | f726dbe934d7dcf8ac72e5a8863703e64bb049ae (diff) | |
| parent | b238e6fcabf2222156071def30bef6d542448da7 (diff) | |
| download | rust-0d7f236b8a255b7e0afa19223bfe72cbaf9cc2d5.tar.gz rust-0d7f236b8a255b7e0afa19223bfe72cbaf9cc2d5.zip | |
Auto merge of #86627 - JohnTitor:rollup-ey29pc1, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #86330 (Change how edition based future compatibility warnings are handled) - #86513 (Rustdoc: Do not list impl when trait has doc(hidden)) - #86592 (Use `#[non_exhaustive]` where appropriate) - #86608 (chore(rustdoc): remove unused members of RenderType) - #86624 (Update compiler-builtins) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/array_into_iter.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 43 | ||||
| -rw-r--r-- | compiler/rustc_lint_defs/src/lib.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/dynamic_lib.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/lint.rs | 25 |
7 files changed, 67 insertions, 63 deletions
diff --git a/compiler/rustc_lint/src/array_into_iter.rs b/compiler/rustc_lint/src/array_into_iter.rs index 0b5bd39f7f9..14ffbbc35eb 100644 --- a/compiler/rustc_lint/src/array_into_iter.rs +++ b/compiler/rustc_lint/src/array_into_iter.rs @@ -3,7 +3,8 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_middle::ty; use rustc_middle::ty::adjustment::{Adjust, Adjustment}; -use rustc_session::lint::FutureBreakage; +use rustc_session::lint::FutureIncompatibilityReason; +use rustc_span::edition::Edition; use rustc_span::symbol::sym; declare_lint! { @@ -37,10 +38,7 @@ declare_lint! { "detects calling `into_iter` on arrays", @future_incompatible = FutureIncompatibleInfo { reference: "issue #66145 <https://github.com/rust-lang/rust/issues/66145>", - edition: None, - future_breakage: Some(FutureBreakage { - date: None - }) + reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021), }; } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index f6a84966f7a..5479af1dc30 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -47,6 +47,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, Subst}; use rustc_middle::ty::Instance; use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt}; +use rustc_session::lint::FutureIncompatibilityReason; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::source_map::Spanned; @@ -874,7 +875,7 @@ declare_lint! { "detects anonymous parameters", @future_incompatible = FutureIncompatibleInfo { reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } @@ -1663,7 +1664,7 @@ declare_lint! { "`...` range patterns are deprecated", @future_incompatible = FutureIncompatibleInfo { reference: "issue #80165 <https://github.com/rust-lang/rust/issues/80165>", - edition: Some(Edition::Edition2021), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), }; } @@ -1891,7 +1892,7 @@ declare_lint! { "detects edition keywords being used as an identifier", @future_incompatible = FutureIncompatibleInfo { reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index a8df1b0952c..2dc04d57d1e 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -209,8 +209,8 @@ impl LintStore { bug!("duplicate specification of lint {}", lint.name_lower()) } - if let Some(FutureIncompatibleInfo { edition, .. }) = lint.future_incompatible { - if let Some(edition) = edition { + if let Some(FutureIncompatibleInfo { reason, .. }) = lint.future_incompatible { + if let Some(edition) = reason.edition() { self.lint_groups .entry(edition.lint_name()) .or_insert(LintGroup { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index a2f60142ffc..4136398adb5 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -6,7 +6,7 @@ //! compiler code, rather than using their own custom pass. Those //! lints are all available in `rustc_lint::builtin`. -use crate::{declare_lint, declare_lint_pass, FutureBreakage}; +use crate::{declare_lint, declare_lint_pass, FutureBreakage, FutureIncompatibilityReason}; use rustc_span::edition::Edition; declare_lint! { @@ -41,7 +41,6 @@ declare_lint! { "applying forbid to lint-groups", @future_incompatible = FutureIncompatibleInfo { reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>", - edition: None, }; } @@ -77,7 +76,6 @@ declare_lint! { "ill-formed attribute inputs that were previously accepted and used in practice", @future_incompatible = FutureIncompatibleInfo { reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>", - edition: None, }; crate_level_only } @@ -114,7 +112,6 @@ declare_lint! { "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice", @future_incompatible = FutureIncompatibleInfo { reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>", - edition: None, }; } @@ -293,7 +290,6 @@ declare_lint! { "constant evaluation encountered erroneous expression", @future_incompatible = FutureIncompatibleInfo { reference: "issue #71800 <https://github.com/rust-lang/rust/issues/71800>", - edition: None, }; report_in_external_macro } @@ -900,7 +896,6 @@ declare_lint! { "detect private items in public interfaces not caught by the old implementation", @future_incompatible = FutureIncompatibleInfo { reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", - edition: None, }; } @@ -980,7 +975,6 @@ declare_lint! { "detect public re-exports of private extern crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", - edition: None, }; } @@ -1010,7 +1004,6 @@ declare_lint! { "type parameter default erroneously allowed in invalid location", @future_incompatible = FutureIncompatibleInfo { reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>", - edition: None, }; } @@ -1078,7 +1071,6 @@ declare_lint! { "detects unaligned references to fields of packed structs", @future_incompatible = FutureIncompatibleInfo { reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>", - edition: None, }; report_in_external_macro } @@ -1200,7 +1192,6 @@ declare_lint! { "patterns in functions without body were erroneously allowed", @future_incompatible = FutureIncompatibleInfo { reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>", - edition: None, }; } @@ -1244,7 +1235,6 @@ declare_lint! { "detects missing fragment specifiers in unused `macro_rules!` patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>", - edition: None, }; } @@ -1286,7 +1276,6 @@ declare_lint! { "detects generic lifetime arguments in path segments with late bound lifetime parameters", @future_incompatible = FutureIncompatibleInfo { reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>", - edition: None, }; } @@ -1322,7 +1311,6 @@ declare_lint! { "trait-object types were treated as different depending on marker-trait order", @future_incompatible = FutureIncompatibleInfo { reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>", - edition: None, }; } @@ -1362,7 +1350,6 @@ declare_lint! { "distinct impls distinguished only by the leak-check code", @future_incompatible = FutureIncompatibleInfo { reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>", - edition: None, }; } @@ -1554,7 +1541,7 @@ declare_lint! { "raw pointer to an inference variable", @future_incompatible = FutureIncompatibleInfo { reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } @@ -1621,7 +1608,7 @@ declare_lint! { "suggest using `dyn Trait` for trait objects", @future_incompatible = FutureIncompatibleInfo { reference: "issue #80165 <https://github.com/rust-lang/rust/issues/80165>", - edition: Some(Edition::Edition2021), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), }; } @@ -1676,7 +1663,7 @@ declare_lint! { instead of `crate`, `self`, or an extern crate name", @future_incompatible = FutureIncompatibleInfo { reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } @@ -1725,7 +1712,6 @@ declare_lint! { "floating-point literals cannot be used in patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>", - edition: None, }; } @@ -1769,7 +1755,6 @@ declare_lint! { "detects name collision with an existing but unstable method", @future_incompatible = FutureIncompatibleInfo { reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>", - edition: None, // Note: this item represents future incompatibility of all unstable functions in the // standard library, and thus should never be removed or changed to an error. }; @@ -1873,7 +1858,6 @@ declare_lint! { "checks the object safety of where clauses", @future_incompatible = FutureIncompatibleInfo { reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>", - edition: None, }; } @@ -1940,7 +1924,6 @@ declare_lint! { "detects proc macro derives using inaccessible names from parent modules", @future_incompatible = FutureIncompatibleInfo { reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>", - edition: None, }; } @@ -2043,7 +2026,6 @@ declare_lint! { cannot be referred to by absolute paths", @future_incompatible = FutureIncompatibleInfo { reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>", - edition: None, }; crate_level_only } @@ -2134,7 +2116,6 @@ declare_lint! { "constant used in pattern contains value of non-structural-match type in a field or a variant", @future_incompatible = FutureIncompatibleInfo { reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>", - edition: None, }; } @@ -2190,7 +2171,6 @@ declare_lint! { "pointers are not structural-match", @future_incompatible = FutureIncompatibleInfo { reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>", - edition: None, }; } @@ -2229,7 +2209,6 @@ declare_lint! { expression contains values of non-structural-match types", @future_incompatible = FutureIncompatibleInfo { reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>", - edition: None, }; } @@ -2287,7 +2266,6 @@ declare_lint! { "ambiguous associated items", @future_incompatible = FutureIncompatibleInfo { reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>", - edition: None, }; } @@ -2318,7 +2296,6 @@ declare_lint! { "reservation of a two-phased borrow conflicts with other shared borrows", @future_incompatible = FutureIncompatibleInfo { reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>", - edition: None, }; } @@ -2360,7 +2337,6 @@ declare_lint! { "a feature gate that doesn't break dependent crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>", - edition: None, }; } @@ -2589,7 +2565,6 @@ declare_lint! { "a C-like enum implementing Drop is cast", @future_incompatible = FutureIncompatibleInfo { reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>", - edition: None, }; } @@ -2629,7 +2604,6 @@ declare_lint! { "detects a generic constant is used in a type without a emitting a warning", @future_incompatible = FutureIncompatibleInfo { reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>", - edition: None, }; } @@ -2688,7 +2662,6 @@ declare_lint! { "uninhabited static", @future_incompatible = FutureIncompatibleInfo { reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>", - edition: None, }; } @@ -2758,7 +2731,6 @@ declare_lint! { "unsupported naked function definitions", @future_incompatible = FutureIncompatibleInfo { reference: "issue #32408 <https://github.com/rust-lang/rust/issues/32408>", - edition: None, }; } @@ -2831,7 +2803,6 @@ declare_lint! { "trailing semicolon in macro body used as expression", @future_incompatible = FutureIncompatibleInfo { reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>", - edition: None, }; } @@ -3154,7 +3125,6 @@ declare_lint! { "detects invalid `#[doc(...)]` attributes", @future_incompatible = FutureIncompatibleInfo { reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>", - edition: None, }; } @@ -3201,7 +3171,6 @@ declare_lint! { "detects usage of old versions of certain proc-macro crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>", - edition: None, future_breakage: Some(FutureBreakage { date: None }) @@ -3242,7 +3211,7 @@ declare_lint! { "detects usage of old versions of or-patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #84869 <https://github.com/rust-lang/rust/issues/84869>", - edition: Some(Edition::Edition2021), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), }; } @@ -3291,6 +3260,6 @@ declare_lint! { prelude in future editions", @future_incompatible = FutureIncompatibleInfo { reference: "issue #85684 <https://github.com/rust-lang/rust/issues/85684>", - edition: Some(Edition::Edition2021), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), }; } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index f1c4e5fb4a3..b3d98747dcf 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -142,15 +142,39 @@ pub struct Lint { pub struct FutureIncompatibleInfo { /// e.g., a URL for an issue/PR/RFC or error code pub reference: &'static str, - /// If this is an edition fixing lint, the edition in which - /// this lint becomes obsolete - pub edition: Option<Edition>, + /// The reason for the lint used by diagnostics to provide + /// the right help message + pub reason: FutureIncompatibilityReason, /// Information about a future breakage, which will /// be emitted in JSON messages to be displayed by Cargo /// for upstream deps pub future_breakage: Option<FutureBreakage>, } +/// The reason for future incompatibility +#[derive(Copy, Clone, Debug)] +pub enum FutureIncompatibilityReason { + /// This will be an error in a future release + /// for all editions + FutureReleaseError, + /// Previously accepted code that will become an + /// error in the provided edition + EditionError(Edition), + /// Code that changes meaning in some way in + /// the provided edition + EditionSemanticsChange(Edition), +} + +impl FutureIncompatibilityReason { + pub fn edition(self) -> Option<Edition> { + match self { + Self::EditionError(e) => Some(e), + Self::EditionSemanticsChange(e) => Some(e), + _ => None, + } + } +} + #[derive(Copy, Clone, Debug)] pub struct FutureBreakage { pub date: Option<&'static str>, @@ -158,7 +182,11 @@ pub struct FutureBreakage { impl FutureIncompatibleInfo { pub const fn default_fields_for_macro() -> Self { - FutureIncompatibleInfo { reference: "", edition: None, future_breakage: None } + FutureIncompatibleInfo { + reference: "", + reason: FutureIncompatibilityReason::FutureReleaseError, + future_breakage: None, + } } } diff --git a/compiler/rustc_metadata/src/dynamic_lib.rs b/compiler/rustc_metadata/src/dynamic_lib.rs index 1a900ccbf65..e8929cd5c02 100644 --- a/compiler/rustc_metadata/src/dynamic_lib.rs +++ b/compiler/rustc_metadata/src/dynamic_lib.rs @@ -70,13 +70,12 @@ mod dl { use std::sync::{Mutex, MutexGuard}; pub fn lock() -> MutexGuard<'static, Guard> { - static LOCK: SyncLazy<Mutex<Guard>> = SyncLazy::new(|| Mutex::new(Guard { _priv: () })); + static LOCK: SyncLazy<Mutex<Guard>> = SyncLazy::new(|| Mutex::new(Guard)); LOCK.lock().unwrap() } - pub struct Guard { - _priv: (), - } + #[non_exhaustive] + pub struct Guard; impl Guard { pub fn get(&mut self) -> Result<(), String> { diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 4c7ea937ceb..8180d853f60 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -7,7 +7,7 @@ use rustc_errors::{DiagnosticBuilder, DiagnosticId}; use rustc_hir::HirId; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, - Level, Lint, LintId, + FutureIncompatibilityReason, Level, Lint, LintId, }; use rustc_session::{DiagnosticMessageId, Session}; use rustc_span::hygiene::MacroKind; @@ -292,7 +292,7 @@ pub fn struct_lint_level<'s, 'd>( // if this lint occurs in the expansion of a macro from an external crate, // allow individual lints to opt-out from being reported. let not_future_incompatible = - future_incompatible.map(|f| f.edition.is_some()).unwrap_or(true); + future_incompatible.map(|f| f.reason.edition().is_some()).unwrap_or(true); if not_future_incompatible && !lint.report_in_external_macro { err.cancel(); // Don't continue further, since we don't want to have @@ -373,9 +373,6 @@ pub fn struct_lint_level<'s, 'd>( err.code(DiagnosticId::Lint { name, has_future_breakage }); if let Some(future_incompatible) = future_incompatible { - const STANDARD_MESSAGE: &str = "this was previously accepted by the compiler but is being phased out; \ - it will become a hard error"; - let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) { "once this associated item is added to the standard library, the ambiguity may \ cause an error or change in behavior!" @@ -384,10 +381,22 @@ pub fn struct_lint_level<'s, 'd>( "this borrowing pattern was not meant to be accepted, and may become a hard error \ in the future" .to_owned() - } else if let Some(edition) = future_incompatible.edition { - format!("{} in the {} edition!", STANDARD_MESSAGE, edition) + } else if let FutureIncompatibilityReason::EditionError(edition) = + future_incompatible.reason + { + let current_edition = sess.edition(); + format!( + "this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!", + current_edition, edition + ) + } else if let FutureIncompatibilityReason::EditionSemanticsChange(edition) = + future_incompatible.reason + { + format!("this changes meaning in Rust {}", edition) } else { - format!("{} in a future release!", STANDARD_MESSAGE) + "this was previously accepted by the compiler but is being phased out; \ + it will become a hard error in a future release!" + .to_owned() }; let citation = format!("for more information, see {}", future_incompatible.reference); err.warn(&explanation); |
