From 5ec0a21ebeba234d0fcb3d8b5c4d004eeb954998 Mon Sep 17 00:00:00 2001 From: Ludwig Neste Date: Thu, 7 Dec 2023 17:50:37 +0100 Subject: [PATCH 01/16] Introduce explanation about fields being used in ordering --- library/core/src/cmp.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index fadf2fcc9fce6..efab04bca2382 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -707,7 +707,8 @@ impl Clone for Reverse { /// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering /// based on the top-to-bottom declaration order of the struct's members. /// -/// When `derive`d on enums, variants are ordered by their discriminants. +/// When `derive`d on enums, variants are ordered primarily by their discriminants. +/// Secondarily, they are ordered by their fields. /// By default, the discriminant is smallest for variants at the top, and /// largest for variants at the bottom. Here's an example: /// @@ -960,7 +961,8 @@ pub macro Ord($item:item) { /// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering /// based on the top-to-bottom declaration order of the struct's members. /// -/// When `derive`d on enums, variants are ordered by their discriminants. +/// When `derive`d on enums, variants are primarily ordered by their discriminants. +/// Secondarily, they are ordered by their fields. /// By default, the discriminant is smallest for variants at the top, and /// largest for variants at the bottom. Here's an example: /// From 8b52275ee34c829a29bbb677fffd7da48d242616 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 8 Jan 2024 09:27:52 -0700 Subject: [PATCH 02/16] rustdoc: hide modals when resizing the sidebar Follow-up for https://github.com/rust-lang/rust/pull/119477#discussion_r1439085011 --- src/librustdoc/html/static/js/main.js | 1 + .../sidebar-resize-close-popover.goml | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/rustdoc-gui/sidebar-resize-close-popover.goml diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 88901191cda25..b46701b55ea7a 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1721,6 +1721,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm } currentPointerId = e.pointerId; } + window.hideAllModals(false); e.preventDefault(); window.addEventListener("pointermove", resize, false); window.addEventListener("pointercancel", stopResize, false); diff --git a/tests/rustdoc-gui/sidebar-resize-close-popover.goml b/tests/rustdoc-gui/sidebar-resize-close-popover.goml new file mode 100644 index 0000000000000..2a8fbac855e97 --- /dev/null +++ b/tests/rustdoc-gui/sidebar-resize-close-popover.goml @@ -0,0 +1,20 @@ +// Checks sidebar resizing close the Settings popover +go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" +assert-property: (".sidebar", {"clientWidth": "200"}) +show-text: true +click: "#settings-menu" +wait-for: "#settings" +assert-css: ("#settings", {"display": "block"}) +// normal resizing +drag-and-drop: ((205, 100), (185, 100)) +assert-property: (".sidebar", {"clientWidth": "182"}) +assert-css: ("#settings", {"display": "none"}) + +// Now same thing, but for source code +go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" +click: "#settings-menu" +wait-for: "#settings" +assert-css: ("#settings", {"display": "block"}) +assert-property: (".sidebar", {"clientWidth": "49"}) +drag-and-drop: ((52, 100), (185, 100)) +assert-css: ("#settings", {"display": "none"}) From a04ac4952ce0fd9ac7a61da2eef1e2d8e4f9098d Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:37:51 +0100 Subject: [PATCH 03/16] Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result` --- compiler/rustc_lint/messages.ftl | 3 + compiler/rustc_lint/src/let_underscore.rs | 59 ++++++++++----- compiler/rustc_lint/src/lints.rs | 43 ++++++----- .../clippy/tests/ui/let_underscore_lock.rs | 1 + .../let_underscore/let_underscore_drop.rs | 2 + .../let_underscore/let_underscore_lock.rs | 15 ++++ .../let_underscore/let_underscore_lock.stderr | 73 +++++++++++++++++-- 7 files changed, 154 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index b6fa2f1f22163..7d4afc5bad7fc 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -345,6 +345,9 @@ lint_multiple_supertrait_upcastable = `{$ident}` is object-safe and has multiple lint_node_source = `forbid` level set here .note = {$reason} +lint_non_binding_let_multi_drop_fn = + consider immediately dropping the value using `drop(..)` after the `let` statement + lint_non_binding_let_multi_suggestion = consider immediately dropping the value diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index bdace8e01f6c5..0c9dff2b5d93e 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -5,7 +5,7 @@ use crate::{ use rustc_errors::MultiSpan; use rustc_hir as hir; use rustc_middle::ty; -use rustc_span::Symbol; +use rustc_span::{sym, Symbol}; declare_lint! { /// The `let_underscore_drop` lint checks for statements which don't bind @@ -105,51 +105,70 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { - if !matches!(local.pat.kind, hir::PatKind::Wild) { - return; - } - if matches!(local.source, rustc_hir::LocalSource::AsyncFn) { return; } - if let Some(init) = local.init { - let init_ty = cx.typeck_results().expr_ty(init); + + let mut top_level = true; + + // We recursively walk through all patterns, so that we can catch cases where the lock is nested in a pattern. + // For the basic `let_underscore_drop` lint, we only look at the top level, since there are many legitimate reasons + // to bind a sub-pattern to an `_`, if we're only interested in the rest. + // But with locks, we prefer having the chance of "false positives" over missing cases, since the effects can be + // quite catastrophic. + local.pat.walk_always(|pat| { + let is_top_level = top_level; + top_level = false; + + if !matches!(pat.kind, hir::PatKind::Wild) { + return; + } + + let ty = cx.typeck_results().pat_ty(pat); + // If the type has a trivial Drop implementation, then it doesn't // matter that we drop the value immediately. - if !init_ty.needs_drop(cx.tcx, cx.param_env) { + if !ty.needs_drop(cx.tcx, cx.param_env) { return; } - let is_sync_lock = match init_ty.kind() { + // Lint for patterns like `mutex.lock()`, which returns `Result` as well. + let potential_lock_type = match ty.kind() { + ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => { + args.type_at(0) + } + _ => ty, + }; + let is_sync_lock = match potential_lock_type.kind() { ty::Adt(adt, _) => SYNC_GUARD_SYMBOLS .iter() .any(|guard_symbol| cx.tcx.is_diagnostic_item(*guard_symbol, adt.did())), _ => false, }; + let can_use_init = is_top_level.then_some(local.init).flatten(); + let sub = NonBindingLetSub { - suggestion: local.pat.span, - multi_suggestion_start: local.span.until(init.span), - multi_suggestion_end: init.span.shrink_to_hi(), + suggestion: pat.span, + // We can't suggest `drop()` when we're on the top level. + drop_fn_start_end: can_use_init + .map(|init| (local.span.until(init.span), init.span.shrink_to_hi())), is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)), }; if is_sync_lock { - let mut span = MultiSpan::from_spans(vec![local.pat.span, init.span]); + let mut span = MultiSpan::from_span(pat.span); span.push_span_label( - local.pat.span, + pat.span, "this lock is not assigned to a binding and is immediately dropped".to_string(), ); - span.push_span_label( - init.span, - "this binding will immediately drop the value assigned to it".to_string(), - ); cx.emit_spanned_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub }); - } else { + // Only emit let_underscore_drop for top-level `_` patterns. + } else if can_use_init.is_some() { cx.emit_spanned_lint( LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub }, ); } - } + }); } } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index f370c4392b384..46e75ef975ef7 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -930,8 +930,7 @@ pub enum NonBindingLet { pub struct NonBindingLetSub { pub suggestion: Span, - pub multi_suggestion_start: Span, - pub multi_suggestion_end: Span, + pub drop_fn_start_end: Option<(Span, Span)>, pub is_assign_desugar: bool, } @@ -940,21 +939,31 @@ impl AddToDiagnostic for NonBindingLetSub { where F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage, { - let prefix = if self.is_assign_desugar { "let " } else { "" }; - diag.span_suggestion_verbose( - self.suggestion, - fluent::lint_non_binding_let_suggestion, - format!("{prefix}_unused"), - Applicability::MachineApplicable, - ); - diag.multipart_suggestion( - fluent::lint_non_binding_let_multi_suggestion, - vec![ - (self.multi_suggestion_start, "drop(".to_string()), - (self.multi_suggestion_end, ")".to_string()), - ], - Applicability::MachineApplicable, - ); + let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar; + + if can_suggest_binding { + let prefix = if self.is_assign_desugar { "let " } else { "" }; + diag.span_suggestion_verbose( + self.suggestion, + fluent::lint_non_binding_let_suggestion, + format!("{prefix}_unused"), + Applicability::MachineApplicable, + ); + } else { + diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion); + } + if let Some(drop_fn_start_end) = self.drop_fn_start_end { + diag.multipart_suggestion( + fluent::lint_non_binding_let_multi_suggestion, + vec![ + (drop_fn_start_end.0, "drop(".to_string()), + (drop_fn_start_end.1, ")".to_string()), + ], + Applicability::MachineApplicable, + ); + } else { + diag.help(fluent::lint_non_binding_let_multi_drop_fn); + } } } diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.rs b/src/tools/clippy/tests/ui/let_underscore_lock.rs index ccac73be79e4d..28d8dd498319f 100644 --- a/src/tools/clippy/tests/ui/let_underscore_lock.rs +++ b/src/tools/clippy/tests/ui/let_underscore_lock.rs @@ -26,6 +26,7 @@ fn main() { let _ = p_rw; } +#[allow(let_underscore_lock)] fn uplifted() { // shouldn't lint std locks as they were uplifted as rustc's `let_underscore_lock` diff --git a/tests/ui/lint/let_underscore/let_underscore_drop.rs b/tests/ui/lint/let_underscore/let_underscore_drop.rs index f298871f122d3..a31b18ed59465 100644 --- a/tests/ui/lint/let_underscore/let_underscore_drop.rs +++ b/tests/ui/lint/let_underscore/let_underscore_drop.rs @@ -11,4 +11,6 @@ impl Drop for NontrivialDrop { fn main() { let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop` + + let (_, _) = (NontrivialDrop, NontrivialDrop); // This should be ignored. } diff --git a/tests/ui/lint/let_underscore/let_underscore_lock.rs b/tests/ui/lint/let_underscore/let_underscore_lock.rs index 7423862cdf05d..df7e60e39409d 100644 --- a/tests/ui/lint/let_underscore/let_underscore_lock.rs +++ b/tests/ui/lint/let_underscore/let_underscore_lock.rs @@ -1,7 +1,22 @@ // check-fail use std::sync::{Arc, Mutex}; +struct Struct { + a: T, +} + fn main() { let data = Arc::new(Mutex::new(0)); let _ = data.lock().unwrap(); //~ERROR non-binding let on a synchronization lock + + let _ = data.lock(); //~ERROR non-binding let on a synchronization lock + + let (_, _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock + + let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock + + (_ , _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock + + let _b; + (_b, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock } diff --git a/tests/ui/lint/let_underscore/let_underscore_lock.stderr b/tests/ui/lint/let_underscore/let_underscore_lock.stderr index f88a1df55e066..fb8b9ec220336 100644 --- a/tests/ui/lint/let_underscore/let_underscore_lock.stderr +++ b/tests/ui/lint/let_underscore/let_underscore_lock.stderr @@ -1,10 +1,8 @@ error: non-binding let on a synchronization lock - --> $DIR/let_underscore_lock.rs:6:9 + --> $DIR/let_underscore_lock.rs:10:9 | LL | let _ = data.lock().unwrap(); - | ^ ^^^^^^^^^^^^^^^^^^^^ this binding will immediately drop the value assigned to it - | | - | this lock is not assigned to a binding and is immediately dropped + | ^ this lock is not assigned to a binding and is immediately dropped | = note: `#[deny(let_underscore_lock)]` on by default help: consider binding to an unused variable to avoid immediately dropping the value @@ -16,5 +14,70 @@ help: consider immediately dropping the value LL | drop(data.lock().unwrap()); | ~~~~~ + -error: aborting due to 1 previous error +error: non-binding let on a synchronization lock + --> $DIR/let_underscore_lock.rs:12:9 + | +LL | let _ = data.lock(); + | ^ this lock is not assigned to a binding and is immediately dropped + | +help: consider binding to an unused variable to avoid immediately dropping the value + | +LL | let _unused = data.lock(); + | ~~~~~~~ +help: consider immediately dropping the value + | +LL | drop(data.lock()); + | ~~~~~ + + +error: non-binding let on a synchronization lock + --> $DIR/let_underscore_lock.rs:14:10 + | +LL | let (_, _) = (data.lock(), 1); + | ^ this lock is not assigned to a binding and is immediately dropped + | + = help: consider immediately dropping the value using `drop(..)` after the `let` statement +help: consider binding to an unused variable to avoid immediately dropping the value + | +LL | let (_unused, _) = (data.lock(), 1); + | ~~~~~~~ + +error: non-binding let on a synchronization lock + --> $DIR/let_underscore_lock.rs:16:26 + | +LL | let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() }); + | ^ this lock is not assigned to a binding and is immediately dropped + | + = help: consider immediately dropping the value using `drop(..)` after the `let` statement +help: consider binding to an unused variable to avoid immediately dropping the value + | +LL | let (_a, Struct { a: _unused }) = (0, Struct { a: data.lock() }); + | ~~~~~~~ + +error: non-binding let on a synchronization lock + --> $DIR/let_underscore_lock.rs:18:6 + | +LL | (_ , _) = (data.lock(), 1); + | ^ this lock is not assigned to a binding and is immediately dropped + | +help: consider binding to an unused variable to avoid immediately dropping the value + --> $DIR/let_underscore_lock.rs:18:6 + | +LL | (_ , _) = (data.lock(), 1); + | ^ + = help: consider immediately dropping the value using `drop(..)` after the `let` statement + +error: non-binding let on a synchronization lock + --> $DIR/let_underscore_lock.rs:21:22 + | +LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() }); + | ^ this lock is not assigned to a binding and is immediately dropped + | +help: consider binding to an unused variable to avoid immediately dropping the value + --> $DIR/let_underscore_lock.rs:21:22 + | +LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() }); + | ^ + = help: consider immediately dropping the value using `drop(..)` after the `let` statement + +error: aborting due to 6 previous errors From 724fe8fcfb030372527182ed9c861bc8104e98a4 Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Fri, 19 Jan 2024 15:23:58 -0500 Subject: [PATCH 04/16] Adjust Attributes of Integer Division Methods --- library/core/src/num/int_macros.rs | 9 +++++---- library/core/src/num/uint_macros.rs | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index fd01f1b261012..a0e275412e747 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1913,6 +1913,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] + #[track_caller] pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { if unlikely!(rhs == -1) { (0, self == Self::MIN) @@ -2172,7 +2173,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn div_euclid(self, rhs: Self) -> Self { let q = self / rhs; if self % rhs < 0 { @@ -2211,7 +2212,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn rem_euclid(self, rhs: Self) -> Self { let r = self % rhs; if r < 0 { @@ -2258,7 +2259,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn div_floor(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; @@ -2298,7 +2299,7 @@ macro_rules! int_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn div_ceil(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 11a53aaf122ec..ad084a5c3303b 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1141,6 +1141,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] + #[track_caller] pub const fn saturating_div(self, rhs: Self) -> Self { // on unsigned types, there is no overflow in integer division self.wrapping_div(rhs) @@ -1275,6 +1276,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[track_caller] pub const fn wrapping_div(self, rhs: Self) -> Self { self / rhs } @@ -1304,6 +1306,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[track_caller] pub const fn wrapping_div_euclid(self, rhs: Self) -> Self { self / rhs } @@ -1331,6 +1334,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[track_caller] pub const fn wrapping_rem(self, rhs: Self) -> Self { self % rhs } @@ -1361,6 +1365,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[track_caller] pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self { self % rhs } @@ -1743,6 +1748,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[track_caller] pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) { (self / rhs, false) } @@ -1773,6 +1779,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[track_caller] pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { (self / rhs, false) } @@ -1800,6 +1807,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[track_caller] pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) { (self % rhs, false) } @@ -1830,6 +1838,7 @@ macro_rules! uint_impl { #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] + #[track_caller] pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { (self % rhs, false) } @@ -2065,7 +2074,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn div_euclid(self, rhs: Self) -> Self { self / rhs } @@ -2094,7 +2103,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn rem_euclid(self, rhs: Self) -> Self { self % rhs } @@ -2119,6 +2128,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] + #[track_caller] pub const fn div_floor(self, rhs: Self) -> Self { self / rhs } @@ -2146,7 +2156,7 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] - #[rustc_inherit_overflow_checks] + #[track_caller] pub const fn div_ceil(self, rhs: Self) -> Self { let d = self / rhs; let r = self % rhs; From 6b8eae0d243258f616562395be0b4dd5d5f23acf Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Fri, 19 Jan 2024 15:27:26 -0500 Subject: [PATCH 05/16] Make `saturating_div` Docs Consistent with Others --- library/core/src/num/int_macros.rs | 9 ++++----- library/core/src/num/uint_macros.rs | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index a0e275412e747..4b7daa1aafddf 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1121,6 +1121,10 @@ macro_rules! int_impl { /// Saturating integer division. Computes `self / rhs`, saturating at the /// numeric bounds instead of overflowing. /// + /// # Panics + /// + /// This function will panic if `rhs` is 0. + /// /// # Examples /// /// Basic usage: @@ -1131,11 +1135,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_div(-1), ", stringify!($SelfT), "::MAX);")] /// /// ``` - /// - /// ```should_panic - #[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")] - /// - /// ``` #[stable(feature = "saturating_div", since = "1.58.0")] #[rustc_const_stable(feature = "saturating_div", since = "1.58.0")] #[must_use = "this returns the result of the operation, \ diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ad084a5c3303b..4d9aff8287b05 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1123,6 +1123,10 @@ macro_rules! uint_impl { /// Saturating integer division. Computes `self / rhs`, saturating at the /// numeric bounds instead of overflowing. /// + /// # Panics + /// + /// This function will panic if `rhs` is 0. + /// /// # Examples /// /// Basic usage: @@ -1131,11 +1135,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")] /// /// ``` - /// - /// ```should_panic - #[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")] - /// - /// ``` #[stable(feature = "saturating_div", since = "1.58.0")] #[rustc_const_stable(feature = "saturating_div", since = "1.58.0")] #[must_use = "this returns the result of the operation, \ From 76659ae74324d52627a6911ca27e5ef02f3e79ef Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Fri, 19 Jan 2024 15:33:19 -0500 Subject: [PATCH 06/16] Clarify Panicking Behavior in Integer Division Docs --- library/core/src/num/int_macros.rs | 22 ++++++++-------------- library/core/src/num/uint_macros.rs | 5 ----- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 4b7daa1aafddf..19f3ed68124c4 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2152,7 +2152,8 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the division results in overflow. + /// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is + /// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag. /// /// # Examples /// @@ -2190,7 +2191,8 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is 0 or the division results in overflow. + /// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is + /// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag. /// /// # Examples /// @@ -2233,12 +2235,8 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is zero. - /// - /// ## Overflow behavior - /// - /// On overflow, this function will panic if overflow checks are enabled (default in debug - /// mode) and wrap if overflow checks are disabled (default in release mode). + /// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is + /// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag. /// /// # Examples /// @@ -2273,12 +2271,8 @@ macro_rules! int_impl { /// /// # Panics /// - /// This function will panic if `rhs` is zero. - /// - /// ## Overflow behavior - /// - /// On overflow, this function will panic if overflow checks are enabled (default in debug - /// mode) and wrap if overflow checks are disabled (default in release mode). + /// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is + /// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag. /// /// # Examples /// diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 4d9aff8287b05..9876eaf6f0414 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -2138,11 +2138,6 @@ macro_rules! uint_impl { /// /// This function will panic if `rhs` is zero. /// - /// ## Overflow behavior - /// - /// On overflow, this function will panic if overflow checks are enabled (default in debug - /// mode) and wrap if overflow checks are disabled (default in release mode). - /// /// # Examples /// /// Basic usage: From 1821bfaa095273523bd06a9e72075962e040daad Mon Sep 17 00:00:00 2001 From: HTGAzureX1212 <39023054+HTGAzureX1212@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:39:09 +0800 Subject: [PATCH 07/16] chore: suggest wrapping in an `assert!()` instead This shortens the `#[must_use]` diagnostics displayed, in light of the [review comment](https://github.com/rust-lang/rust/pull/62431/files#r300819839) on when this was originally added. --- library/core/src/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index ce29352ba1952..c94e7d73a2ae6 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -642,7 +642,7 @@ impl Option { /// assert_eq!(x.is_none(), true); /// ``` #[must_use = "if you intended to assert that this doesn't have a value, consider \ - `.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"] + wrapping this in an `assert!()` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")] From ff02662d44b2e7841c9e5476f13dcb8f7509b1f1 Mon Sep 17 00:00:00 2001 From: Noritada Kobayashi Date: Mon, 22 Jan 2024 01:02:20 +0900 Subject: [PATCH 08/16] Correct the anchor of an URL in an error message --- compiler/rustc_codegen_ssa/messages.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 5881c6236ece6..a80f6a1add099 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -325,7 +325,7 @@ codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}` codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target -codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname) +codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib) codegen_ssa_version_script_write_failure = failed to write version script: {$error} From 30b8b44990d2cfb66a723b1d1eefbd9c31da6892 Mon Sep 17 00:00:00 2001 From: Rowan S-L Date: Sun, 21 Jan 2024 12:43:09 -0500 Subject: [PATCH 09/16] use /usr/bin/env bash instead of /bin/bash --- src/tools/rust-installer/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-installer/test.sh b/src/tools/rust-installer/test.sh index 4f69bfc63e973..16b05c66197c8 100755 --- a/src/tools/rust-installer/test.sh +++ b/src/tools/rust-installer/test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e -u From ab6216a1d3eeb1a8cf50406987da925500b16934 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 22 Jan 2024 09:44:15 +1100 Subject: [PATCH 10/16] Adjust whitespace. --- triagebot.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index b684f3ca55c64..201af97708c18 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -735,7 +735,6 @@ style-team = [ "@joshtriplett", "@yaahc", ] - project-const-traits = [ "@compiler-errors", "@fee1-dead", @@ -780,7 +779,7 @@ project-stable-mir = [ "/library/panic_unwind" = ["libs"] "/library/proc_macro" = ["@petrochenkov"] "/library/std" = ["libs"] -"/library/std/src/sys/pal/windows" = ["@ChrisDenton", "@thomcc"] +"/library/std/src/sys/pal/windows" = ["@ChrisDenton", "@thomcc"] "/library/stdarch" = ["libs"] "/library/test" = ["libs"] "/src/bootstrap" = ["bootstrap"] From ae3c00c28ea56d7e7d801ba869ba39ef4b57da57 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 22 Jan 2024 09:51:12 +1100 Subject: [PATCH 11/16] Add a group for `rustc_arena` and put nnethercote in it. --- triagebot.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 201af97708c18..fceb2e322b649 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -702,6 +702,9 @@ lexer = [ "@nnethercote", "@petrochenkov", ] +arena = [ + "@nnethercote", +] mir = [ "@davidtwco", "@oli-obk", @@ -753,6 +756,7 @@ project-stable-mir = [ "/Cargo.lock" = ["@Mark-Simulacrum"] "/Cargo.toml" = ["@Mark-Simulacrum"] "/compiler" = ["compiler"] +"/compiler/rustc_arena" = ["compiler", "arena"] "/compiler/rustc_ast" = ["compiler", "parser"] "/compiler/rustc_ast_lowering" = ["compiler", "ast_lowering"] "/compiler/rustc_hir_analysis" = ["compiler", "types"] From b95ce3056b31ac2d7b9764ad345fe0fb9b00a66b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 22 Jan 2024 09:52:34 +1100 Subject: [PATCH 12/16] Add nnethercote to the full review rotation. --- triagebot.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/triagebot.toml b/triagebot.toml index fceb2e322b649..b324b3f04b737 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -646,6 +646,7 @@ compiler-team = [ compiler-team-contributors = [ "@TaKO8Ki", "@b-naber", + "@nnethercote", ] compiler = [ "compiler-team", From f00c088393a995bfaf174938b7838cc69433e4fe Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 15 Jan 2024 10:35:24 +1100 Subject: [PATCH 13/16] Clarify comments about diagnostic count fields. --- compiler/rustc_errors/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 141547b537dea..17bcc31c0064d 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -421,16 +421,16 @@ pub struct DiagCtxt { struct DiagCtxtInner { flags: DiagCtxtFlags, - /// The number of lint errors that have been emitted. + /// The number of lint errors that have been emitted, including duplicates. lint_err_count: usize, - /// The number of errors that have been emitted, including duplicates. - /// - /// This is not necessarily the count that's reported to the user once - /// compilation ends. + /// The number of non-lint errors that have been emitted, including duplicates. err_count: usize, + + /// The error count shown to the user at the end. deduplicated_err_count: usize, - /// The warning count, used for a recap upon finishing + /// The warning count shown to the user at the end. deduplicated_warn_count: usize, + /// Has this diagnostic context printed any diagnostics? (I.e. has /// `self.emitter.emit_diagnostic()` been called? has_printed: bool, From 807c8687de342bd11a7038df54946f4abcc03d2c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 15 Jan 2024 14:41:12 +1100 Subject: [PATCH 14/16] Count "unused extern" errors as lints rather than normal errors. --- compiler/rustc_errors/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 17bcc31c0064d..e47daf4afa172 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1162,7 +1162,7 @@ impl DiagCtxt { let mut inner = self.inner.borrow_mut(); if loud && lint_level.is_error() { - inner.err_count += 1; + inner.lint_err_count += 1; inner.panic_if_treat_err_as_bug(); } From 1f9fa2305a099cbbf9858e3eb777495a7246e84a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 15 Jan 2024 10:40:54 +1100 Subject: [PATCH 15/16] Tweak error counting. We have several methods indicating the presence of errors, lint errors, and delayed bugs. I find it frustrating that it's very unclear which one you should use in any particular spot. This commit attempts to instill a basic principle of "use the least general one possible", because that reflects reality in practice -- `has_errors` is the least general one and has by far the most uses (esp. via `abort_if_errors`). Specifics: - Add some comments giving some usage guidelines. - Prefer `has_errors` to comparing `err_count` to zero. - Remove `has_errors_or_span_delayed_bugs` because it's a weird one: in the cases where we need to count delayed bugs, we should really be counting lint errors as well. - Rename `is_compilation_going_to_fail` as `has_errors_or_lint_errors_or_span_delayed_bugs`, for consistency with `has_errors` and `has_errors_or_lint_errors`. - Change a few other `has_errors_or_lint_errors` calls to `has_errors`, as per the "least general" principle. This didn't turn out to be as neat as I hoped when I started, but I think it's still an improvement. --- compiler/rustc_builtin_macros/src/format.rs | 2 +- compiler/rustc_errors/src/lib.rs | 26 ++++++++----------- .../rustc_hir_analysis/src/check/wfcheck.rs | 2 +- compiler/rustc_incremental/src/persist/fs.rs | 2 +- .../rustc_incremental/src/persist/save.rs | 6 ++--- .../src/infer/error_reporting/mod.rs | 11 ++++---- compiler/rustc_middle/src/ty/visit.rs | 7 +++-- .../rustc_query_system/src/dep_graph/graph.rs | 2 +- compiler/rustc_session/src/session.rs | 1 + src/librustdoc/core.rs | 1 + src/librustdoc/doctest.rs | 1 + src/librustdoc/lib.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 2 +- src/librustdoc/scrape_examples.rs | 2 +- 14 files changed, 35 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 93381b69fdcc1..eb331ef585301 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -529,7 +529,7 @@ fn make_format_args( // Only check for unused named argument names if there are no other errors to avoid causing // too much noise in output errors, such as when a named argument is entirely unused. - if invalid_refs.is_empty() && ecx.dcx().err_count() == 0 { + if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() { for &(index, span, used_as) in &numeric_refences_to_named_arg { let (position_sp_to_replace, position_sp_for_msg) = match used_as { Placeholder(pspan) => (span, pspan), diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index e47daf4afa172..9d80c45651725 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -927,11 +927,13 @@ impl DiagCtxt { self.struct_bug(msg).emit() } + /// This excludes lint errors and delayed bugs. #[inline] pub fn err_count(&self) -> usize { self.inner.borrow().err_count } + /// This excludes lint errors and delayed bugs. pub fn has_errors(&self) -> Option { self.inner.borrow().has_errors().then(|| { #[allow(deprecated)] @@ -939,30 +941,24 @@ impl DiagCtxt { }) } + /// This excludes delayed bugs. Unless absolutely necessary, prefer + /// `has_errors` to this method. pub fn has_errors_or_lint_errors(&self) -> Option { let inner = self.inner.borrow(); - let has_errors_or_lint_errors = inner.has_errors() || inner.lint_err_count > 0; - has_errors_or_lint_errors.then(|| { + let result = inner.has_errors() || inner.lint_err_count > 0; + result.then(|| { #[allow(deprecated)] ErrorGuaranteed::unchecked_claim_error_was_emitted() }) } - pub fn has_errors_or_span_delayed_bugs(&self) -> Option { + /// Unless absolutely necessary, prefer `has_errors` or + /// `has_errors_or_lint_errors` to this method. + pub fn has_errors_or_lint_errors_or_delayed_bugs(&self) -> Option { let inner = self.inner.borrow(); - let has_errors_or_span_delayed_bugs = - inner.has_errors() || !inner.span_delayed_bugs.is_empty(); - has_errors_or_span_delayed_bugs.then(|| { - #[allow(deprecated)] - ErrorGuaranteed::unchecked_claim_error_was_emitted() - }) - } - - pub fn is_compilation_going_to_fail(&self) -> Option { - let inner = self.inner.borrow(); - let will_fail = + let result = inner.has_errors() || inner.lint_err_count > 0 || !inner.span_delayed_bugs.is_empty(); - will_fail.then(|| { + result.then(|| { #[allow(deprecated)] ErrorGuaranteed::unchecked_claim_error_was_emitted() }) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 3b9837ff7c2bd..70213ee0614f8 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -116,7 +116,7 @@ where let errors = wfcx.select_all_or_error(); if !errors.is_empty() { let err = infcx.err_ctxt().report_fulfillment_errors(errors); - if tcx.dcx().err_count() > 0 { + if tcx.dcx().has_errors().is_some() { return Err(err); } else { // HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index e18b1365d9c02..2578f284dee7a 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -312,7 +312,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option) { let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone(); - if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() { + if sess.dcx().has_errors_or_lint_errors_or_delayed_bugs().is_some() { // If there have been any errors during compilation, we don't want to // publish this session directory. Rather, we'll just delete it. diff --git a/compiler/rustc_incremental/src/persist/save.rs b/compiler/rustc_incremental/src/persist/save.rs index 08b7d08bcc006..ff0c58d09de2d 100644 --- a/compiler/rustc_incremental/src/persist/save.rs +++ b/compiler/rustc_incremental/src/persist/save.rs @@ -31,8 +31,8 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) { if sess.opts.incremental.is_none() { return; } - // This is going to be deleted in finalize_session_directory, so let's not create it - if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() { + // This is going to be deleted in finalize_session_directory, so let's not create it. + if sess.dcx().has_errors_or_lint_errors_or_delayed_bugs().is_some() { return; } @@ -87,7 +87,7 @@ pub fn save_work_product_index( return; } // This is going to be deleted in finalize_session_directory, so let's not create it - if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() { + if sess.dcx().has_errors_or_lint_errors().is_some() { return; } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 875e94fcd9f16..7882e761a0c31 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -117,9 +117,9 @@ fn escape_literal(s: &str) -> String { /// field is only populated during an in-progress typeck. /// Get an instance by calling `InferCtxt::err_ctxt` or `FnCtxt::err_ctxt`. /// -/// You must only create this if you intend to actually emit an error. -/// This provides a lot of utility methods which should not be used -/// during the happy path. +/// You must only create this if you intend to actually emit an error (or +/// perhaps a warning, though preferably not.) It provides a lot of utility +/// methods which should not be used during the happy path. pub struct TypeErrCtxt<'a, 'tcx> { pub infcx: &'a InferCtxt<'tcx>, pub typeck_results: Option>>, @@ -133,9 +133,10 @@ pub struct TypeErrCtxt<'a, 'tcx> { impl Drop for TypeErrCtxt<'_, '_> { fn drop(&mut self) { - if let Some(_) = self.dcx().has_errors_or_span_delayed_bugs() { - // ok, emitted an error. + if self.dcx().has_errors().is_some() { + // Ok, emitted an error. } else { + // Didn't emit an error; maybe it was created but not yet emitted. self.infcx .tcx .sess diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index 1f8978aa8633d..a750a86d25707 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -55,10 +55,13 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable> { } fn error_reported(&self) -> Result<(), ErrorGuaranteed> { if self.references_error() { - if let Some(reported) = ty::tls::with(|tcx| tcx.dcx().is_compilation_going_to_fail()) { + // We must include lint errors and span delayed bugs here. + if let Some(reported) = + ty::tls::with(|tcx| tcx.dcx().has_errors_or_lint_errors_or_delayed_bugs()) + { Err(reported) } else { - bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`"); + bug!("expected some kind of error in `error_reported`"); } } else { Ok(()) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 0f57688063e02..2faa4876798e0 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -818,7 +818,7 @@ impl DepGraphData { None => {} } - if let None = qcx.dep_context().sess().dcx().has_errors_or_span_delayed_bugs() { + if let None = qcx.dep_context().sess().dcx().has_errors_or_lint_errors_or_delayed_bugs() { panic!("try_mark_previous_green() - Forcing the DepNode should have set its color") } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index cba6ce0d235ea..24aa336c68fe9 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -323,6 +323,7 @@ impl Session { } pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> { + // We must include lint errors here. if let Some(reported) = self.dcx().has_errors_or_lint_errors() { let _ = self.dcx().emit_stashed_diagnostics(); Err(reported) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index fa72758c21659..8bb1ed6d476d4 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -449,6 +449,7 @@ pub(crate) fn run_global_ctxt( tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc))); + // We must include lint errors here. if tcx.dcx().has_errors_or_lint_errors().is_some() { rustc_errors::FatalError.raise(); } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 82746a7ab0343..f2e083de0ec74 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -150,6 +150,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { collector }); + // We must include lint errors here. if compiler.sess.dcx().has_errors_or_lint_errors().is_some() { FatalError.raise(); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d962beda4beed..658ed862ae764 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -796,7 +796,7 @@ fn main_args( compiler.enter(|queries| { let mut gcx = abort_on_err(queries.global_ctxt(), sess); - if sess.dcx().has_errors_or_lint_errors().is_some() { + if sess.dcx().has_errors().is_some() { sess.dcx().fatal("Compilation failed, aborting rustdoc"); } diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index fc7ef4bcdfa97..e2a7ef8556ea6 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -22,7 +22,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> let tcx = cx.tcx; // We need to check if there are errors before running this pass because it would crash when // we try to get auto and blanket implementations. - if tcx.dcx().has_errors_or_lint_errors().is_some() { + if tcx.dcx().has_errors().is_some() { return krate; } diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 74bec5a2e11fd..b7d9c16f34837 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -311,7 +311,7 @@ pub(crate) fn run( // The visitor might have found a type error, which we need to // promote to a fatal error - if tcx.dcx().has_errors_or_lint_errors().is_some() { + if tcx.dcx().has_errors().is_some() { return Err(String::from("Compilation failed, aborting rustdoc")); } From 774a47da2803d27b384966b9030d7ddd9a5e37fa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 22 Jan 2024 13:13:20 +1100 Subject: [PATCH 16/16] Link to triagebot.toml documentation. --- triagebot.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index b324b3f04b737..a9ddd1b99c72a 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1,3 +1,6 @@ +# This file's format is documented at +# https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration + [relabel] allow-unauthenticated = [ "A-*",