Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 366d112

Browse files
committedJan 22, 2024
Auto merge of #120226 - matthiaskrgr:rollup-9xwx0si, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #118714 ( Explanation that fields are being used when deriving `(Partial)Ord` on enums) - #119710 (Improve `let_underscore_lock`) - #119726 (Tweak Library Integer Division Docs) - #119746 (rustdoc: hide modals when resizing the sidebar) - #119986 (Fix error counting) - #120194 (Shorten `#[must_use]` Diagnostic Message for `Option::is_none`) - #120200 (Correct the anchor of an URL in an error message) - #120203 (Replace `#!/bin/bash` with `#!/usr/bin/env bash` in rust-installer tests) - #120212 (Give nnethercote more reviews) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6fff796 + 610f13d commit 366d112

File tree

30 files changed

+267
-124
lines changed

30 files changed

+267
-124
lines changed
 

‎compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn make_format_args(
529529

530530
// Only check for unused named argument names if there are no other errors to avoid causing
531531
// too much noise in output errors, such as when a named argument is entirely unused.
532-
if invalid_refs.is_empty() && ecx.dcx().err_count() == 0 {
532+
if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() {
533533
for &(index, span, used_as) in &numeric_refences_to_named_arg {
534534
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
535535
Placeholder(pspan) => (span, pspan),

‎compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
325325
326326
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target
327327
328-
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)
328+
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)
329329
330330
codegen_ssa_version_script_write_failure = failed to write version script: {$error}
331331

‎compiler/rustc_errors/src/lib.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,16 @@ pub struct DiagCtxt {
421421
struct DiagCtxtInner {
422422
flags: DiagCtxtFlags,
423423

424-
/// The number of lint errors that have been emitted.
424+
/// The number of lint errors that have been emitted, including duplicates.
425425
lint_err_count: usize,
426-
/// The number of errors that have been emitted, including duplicates.
427-
///
428-
/// This is not necessarily the count that's reported to the user once
429-
/// compilation ends.
426+
/// The number of non-lint errors that have been emitted, including duplicates.
430427
err_count: usize,
428+
429+
/// The error count shown to the user at the end.
431430
deduplicated_err_count: usize,
432-
/// The warning count, used for a recap upon finishing
431+
/// The warning count shown to the user at the end.
433432
deduplicated_warn_count: usize,
433+
434434
/// Has this diagnostic context printed any diagnostics? (I.e. has
435435
/// `self.emitter.emit_diagnostic()` been called?
436436
has_printed: bool,
@@ -927,42 +927,38 @@ impl DiagCtxt {
927927
self.struct_bug(msg).emit()
928928
}
929929

930+
/// This excludes lint errors and delayed bugs.
930931
#[inline]
931932
pub fn err_count(&self) -> usize {
932933
self.inner.borrow().err_count
933934
}
934935

936+
/// This excludes lint errors and delayed bugs.
935937
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
936938
self.inner.borrow().has_errors().then(|| {
937939
#[allow(deprecated)]
938940
ErrorGuaranteed::unchecked_claim_error_was_emitted()
939941
})
940942
}
941943

944+
/// This excludes delayed bugs. Unless absolutely necessary, prefer
945+
/// `has_errors` to this method.
942946
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
943947
let inner = self.inner.borrow();
944-
let has_errors_or_lint_errors = inner.has_errors() || inner.lint_err_count > 0;
945-
has_errors_or_lint_errors.then(|| {
946-
#[allow(deprecated)]
947-
ErrorGuaranteed::unchecked_claim_error_was_emitted()
948-
})
949-
}
950-
951-
pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
952-
let inner = self.inner.borrow();
953-
let has_errors_or_span_delayed_bugs =
954-
inner.has_errors() || !inner.span_delayed_bugs.is_empty();
955-
has_errors_or_span_delayed_bugs.then(|| {
948+
let result = inner.has_errors() || inner.lint_err_count > 0;
949+
result.then(|| {
956950
#[allow(deprecated)]
957951
ErrorGuaranteed::unchecked_claim_error_was_emitted()
958952
})
959953
}
960954

961-
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
955+
/// Unless absolutely necessary, prefer `has_errors` or
956+
/// `has_errors_or_lint_errors` to this method.
957+
pub fn has_errors_or_lint_errors_or_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
962958
let inner = self.inner.borrow();
963-
let will_fail =
959+
let result =
964960
inner.has_errors() || inner.lint_err_count > 0 || !inner.span_delayed_bugs.is_empty();
965-
will_fail.then(|| {
961+
result.then(|| {
966962
#[allow(deprecated)]
967963
ErrorGuaranteed::unchecked_claim_error_was_emitted()
968964
})
@@ -1162,7 +1158,7 @@ impl DiagCtxt {
11621158
let mut inner = self.inner.borrow_mut();
11631159

11641160
if loud && lint_level.is_error() {
1165-
inner.err_count += 1;
1161+
inner.lint_err_count += 1;
11661162
inner.panic_if_treat_err_as_bug();
11671163
}
11681164

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
let errors = wfcx.select_all_or_error();
117117
if !errors.is_empty() {
118118
let err = infcx.err_ctxt().report_fulfillment_errors(errors);
119-
if tcx.dcx().err_count() > 0 {
119+
if tcx.dcx().has_errors().is_some() {
120120
return Err(err);
121121
} else {
122122
// HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs

‎compiler/rustc_incremental/src/persist/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
312312

313313
let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
314314

315-
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
315+
if sess.dcx().has_errors_or_lint_errors_or_delayed_bugs().is_some() {
316316
// If there have been any errors during compilation, we don't want to
317317
// publish this session directory. Rather, we'll just delete it.
318318

‎compiler/rustc_incremental/src/persist/save.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
3131
if sess.opts.incremental.is_none() {
3232
return;
3333
}
34-
// This is going to be deleted in finalize_session_directory, so let's not create it
35-
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
34+
// This is going to be deleted in finalize_session_directory, so let's not create it.
35+
if sess.dcx().has_errors_or_lint_errors_or_delayed_bugs().is_some() {
3636
return;
3737
}
3838

@@ -87,7 +87,7 @@ pub fn save_work_product_index(
8787
return;
8888
}
8989
// This is going to be deleted in finalize_session_directory, so let's not create it
90-
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
90+
if sess.dcx().has_errors_or_lint_errors().is_some() {
9191
return;
9292
}
9393

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ fn escape_literal(s: &str) -> String {
117117
/// field is only populated during an in-progress typeck.
118118
/// Get an instance by calling `InferCtxt::err_ctxt` or `FnCtxt::err_ctxt`.
119119
///
120-
/// You must only create this if you intend to actually emit an error.
121-
/// This provides a lot of utility methods which should not be used
122-
/// during the happy path.
120+
/// You must only create this if you intend to actually emit an error (or
121+
/// perhaps a warning, though preferably not.) It provides a lot of utility
122+
/// methods which should not be used during the happy path.
123123
pub struct TypeErrCtxt<'a, 'tcx> {
124124
pub infcx: &'a InferCtxt<'tcx>,
125125
pub typeck_results: Option<std::cell::Ref<'a, ty::TypeckResults<'tcx>>>,
@@ -133,9 +133,10 @@ pub struct TypeErrCtxt<'a, 'tcx> {
133133

134134
impl Drop for TypeErrCtxt<'_, '_> {
135135
fn drop(&mut self) {
136-
if let Some(_) = self.dcx().has_errors_or_span_delayed_bugs() {
137-
// ok, emitted an error.
136+
if self.dcx().has_errors().is_some() {
137+
// Ok, emitted an error.
138138
} else {
139+
// Didn't emit an error; maybe it was created but not yet emitted.
139140
self.infcx
140141
.tcx
141142
.sess

‎compiler/rustc_lint/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ lint_multiple_supertrait_upcastable = `{$ident}` is object-safe and has multiple
345345
lint_node_source = `forbid` level set here
346346
.note = {$reason}
347347
348+
lint_non_binding_let_multi_drop_fn =
349+
consider immediately dropping the value using `drop(..)` after the `let` statement
350+
348351
lint_non_binding_let_multi_suggestion =
349352
consider immediately dropping the value
350353

‎compiler/rustc_lint/src/let_underscore.rs

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
use rustc_errors::MultiSpan;
66
use rustc_hir as hir;
77
use rustc_middle::ty;
8-
use rustc_span::Symbol;
8+
use rustc_span::{sym, Symbol};
99

1010
declare_lint! {
1111
/// The `let_underscore_drop` lint checks for statements which don't bind
@@ -105,51 +105,70 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [
105105

106106
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
107107
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) {
108-
if !matches!(local.pat.kind, hir::PatKind::Wild) {
109-
return;
110-
}
111-
112108
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
113109
return;
114110
}
115-
if let Some(init) = local.init {
116-
let init_ty = cx.typeck_results().expr_ty(init);
111+
112+
let mut top_level = true;
113+
114+
// We recursively walk through all patterns, so that we can catch cases where the lock is nested in a pattern.
115+
// For the basic `let_underscore_drop` lint, we only look at the top level, since there are many legitimate reasons
116+
// to bind a sub-pattern to an `_`, if we're only interested in the rest.
117+
// But with locks, we prefer having the chance of "false positives" over missing cases, since the effects can be
118+
// quite catastrophic.
119+
local.pat.walk_always(|pat| {
120+
let is_top_level = top_level;
121+
top_level = false;
122+
123+
if !matches!(pat.kind, hir::PatKind::Wild) {
124+
return;
125+
}
126+
127+
let ty = cx.typeck_results().pat_ty(pat);
128+
117129
// If the type has a trivial Drop implementation, then it doesn't
118130
// matter that we drop the value immediately.
119-
if !init_ty.needs_drop(cx.tcx, cx.param_env) {
131+
if !ty.needs_drop(cx.tcx, cx.param_env) {
120132
return;
121133
}
122-
let is_sync_lock = match init_ty.kind() {
134+
// Lint for patterns like `mutex.lock()`, which returns `Result<MutexGuard, _>` as well.
135+
let potential_lock_type = match ty.kind() {
136+
ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => {
137+
args.type_at(0)
138+
}
139+
_ => ty,
140+
};
141+
let is_sync_lock = match potential_lock_type.kind() {
123142
ty::Adt(adt, _) => SYNC_GUARD_SYMBOLS
124143
.iter()
125144
.any(|guard_symbol| cx.tcx.is_diagnostic_item(*guard_symbol, adt.did())),
126145
_ => false,
127146
};
128147

148+
let can_use_init = is_top_level.then_some(local.init).flatten();
149+
129150
let sub = NonBindingLetSub {
130-
suggestion: local.pat.span,
131-
multi_suggestion_start: local.span.until(init.span),
132-
multi_suggestion_end: init.span.shrink_to_hi(),
151+
suggestion: pat.span,
152+
// We can't suggest `drop()` when we're on the top level.
153+
drop_fn_start_end: can_use_init
154+
.map(|init| (local.span.until(init.span), init.span.shrink_to_hi())),
133155
is_assign_desugar: matches!(local.source, rustc_hir::LocalSource::AssignDesugar(_)),
134156
};
135157
if is_sync_lock {
136-
let mut span = MultiSpan::from_spans(vec![local.pat.span, init.span]);
158+
let mut span = MultiSpan::from_span(pat.span);
137159
span.push_span_label(
138-
local.pat.span,
160+
pat.span,
139161
"this lock is not assigned to a binding and is immediately dropped".to_string(),
140162
);
141-
span.push_span_label(
142-
init.span,
143-
"this binding will immediately drop the value assigned to it".to_string(),
144-
);
145163
cx.emit_spanned_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock { sub });
146-
} else {
164+
// Only emit let_underscore_drop for top-level `_` patterns.
165+
} else if can_use_init.is_some() {
147166
cx.emit_spanned_lint(
148167
LET_UNDERSCORE_DROP,
149168
local.span,
150169
NonBindingLet::DropType { sub },
151170
);
152171
}
153-
}
172+
});
154173
}
155174
}

‎compiler/rustc_lint/src/lints.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,7 @@ pub enum NonBindingLet {
930930

931931
pub struct NonBindingLetSub {
932932
pub suggestion: Span,
933-
pub multi_suggestion_start: Span,
934-
pub multi_suggestion_end: Span,
933+
pub drop_fn_start_end: Option<(Span, Span)>,
935934
pub is_assign_desugar: bool,
936935
}
937936

@@ -940,21 +939,31 @@ impl AddToDiagnostic for NonBindingLetSub {
940939
where
941940
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
942941
{
943-
let prefix = if self.is_assign_desugar { "let " } else { "" };
944-
diag.span_suggestion_verbose(
945-
self.suggestion,
946-
fluent::lint_non_binding_let_suggestion,
947-
format!("{prefix}_unused"),
948-
Applicability::MachineApplicable,
949-
);
950-
diag.multipart_suggestion(
951-
fluent::lint_non_binding_let_multi_suggestion,
952-
vec![
953-
(self.multi_suggestion_start, "drop(".to_string()),
954-
(self.multi_suggestion_end, ")".to_string()),
955-
],
956-
Applicability::MachineApplicable,
957-
);
942+
let can_suggest_binding = self.drop_fn_start_end.is_some() || !self.is_assign_desugar;
943+
944+
if can_suggest_binding {
945+
let prefix = if self.is_assign_desugar { "let " } else { "" };
946+
diag.span_suggestion_verbose(
947+
self.suggestion,
948+
fluent::lint_non_binding_let_suggestion,
949+
format!("{prefix}_unused"),
950+
Applicability::MachineApplicable,
951+
);
952+
} else {
953+
diag.span_help(self.suggestion, fluent::lint_non_binding_let_suggestion);
954+
}
955+
if let Some(drop_fn_start_end) = self.drop_fn_start_end {
956+
diag.multipart_suggestion(
957+
fluent::lint_non_binding_let_multi_suggestion,
958+
vec![
959+
(drop_fn_start_end.0, "drop(".to_string()),
960+
(drop_fn_start_end.1, ")".to_string()),
961+
],
962+
Applicability::MachineApplicable,
963+
);
964+
} else {
965+
diag.help(fluent::lint_non_binding_let_multi_drop_fn);
966+
}
958967
}
959968
}
960969

‎compiler/rustc_middle/src/ty/visit.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
5555
}
5656
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
5757
if self.references_error() {
58-
if let Some(reported) = ty::tls::with(|tcx| tcx.dcx().is_compilation_going_to_fail()) {
58+
// We must include lint errors and span delayed bugs here.
59+
if let Some(reported) =
60+
ty::tls::with(|tcx| tcx.dcx().has_errors_or_lint_errors_or_delayed_bugs())
61+
{
5962
Err(reported)
6063
} else {
61-
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");
64+
bug!("expected some kind of error in `error_reported`");
6265
}
6366
} else {
6467
Ok(())

‎compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl<D: Deps> DepGraphData<D> {
818818
None => {}
819819
}
820820

821-
if let None = qcx.dep_context().sess().dcx().has_errors_or_span_delayed_bugs() {
821+
if let None = qcx.dep_context().sess().dcx().has_errors_or_lint_errors_or_delayed_bugs() {
822822
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
823823
}
824824

‎compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ impl Session {
323323
}
324324

325325
pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> {
326+
// We must include lint errors here.
326327
if let Some(reported) = self.dcx().has_errors_or_lint_errors() {
327328
let _ = self.dcx().emit_stashed_diagnostics();
328329
Err(reported)

‎library/core/src/cmp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ impl<T: Clone> Clone for Reverse<T> {
710710
/// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering
711711
/// based on the top-to-bottom declaration order of the struct's members.
712712
///
713-
/// When `derive`d on enums, variants are ordered by their discriminants.
713+
/// When `derive`d on enums, variants are ordered primarily by their discriminants.
714+
/// Secondarily, they are ordered by their fields.
714715
/// By default, the discriminant is smallest for variants at the top, and
715716
/// largest for variants at the bottom. Here's an example:
716717
///
@@ -963,7 +964,8 @@ pub macro Ord($item:item) {
963964
/// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering
964965
/// based on the top-to-bottom declaration order of the struct's members.
965966
///
966-
/// When `derive`d on enums, variants are ordered by their discriminants.
967+
/// When `derive`d on enums, variants are primarily ordered by their discriminants.
968+
/// Secondarily, they are ordered by their fields.
967969
/// By default, the discriminant is smallest for variants at the top, and
968970
/// largest for variants at the bottom. Here's an example:
969971
///

‎library/core/src/num/int_macros.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,10 @@ macro_rules! int_impl {
16431643
/// Saturating integer division. Computes `self / rhs`, saturating at the
16441644
/// numeric bounds instead of overflowing.
16451645
///
1646+
/// # Panics
1647+
///
1648+
/// This function will panic if `rhs` is 0.
1649+
///
16461650
/// # Examples
16471651
///
16481652
/// Basic usage:
@@ -1653,11 +1657,6 @@ macro_rules! int_impl {
16531657
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_div(-1), ", stringify!($SelfT), "::MAX);")]
16541658
///
16551659
/// ```
1656-
///
1657-
/// ```should_panic
1658-
#[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")]
1659-
///
1660-
/// ```
16611660
#[stable(feature = "saturating_div", since = "1.58.0")]
16621661
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
16631662
#[must_use = "this returns the result of the operation, \
@@ -2435,6 +2434,7 @@ macro_rules! int_impl {
24352434
#[must_use = "this returns the result of the operation, \
24362435
without modifying the original"]
24372436
#[inline]
2437+
#[track_caller]
24382438
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
24392439
if unlikely!(rhs == -1) {
24402440
(0, self == Self::MIN)
@@ -2674,7 +2674,8 @@ macro_rules! int_impl {
26742674
///
26752675
/// # Panics
26762676
///
2677-
/// This function will panic if `rhs` is 0 or the division results in overflow.
2677+
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2678+
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
26782679
///
26792680
/// # Examples
26802681
///
@@ -2694,7 +2695,7 @@ macro_rules! int_impl {
26942695
#[must_use = "this returns the result of the operation, \
26952696
without modifying the original"]
26962697
#[inline]
2697-
#[rustc_inherit_overflow_checks]
2698+
#[track_caller]
26982699
pub const fn div_euclid(self, rhs: Self) -> Self {
26992700
let q = self / rhs;
27002701
if self % rhs < 0 {
@@ -2712,7 +2713,8 @@ macro_rules! int_impl {
27122713
///
27132714
/// # Panics
27142715
///
2715-
/// This function will panic if `rhs` is 0 or the division results in overflow.
2716+
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2717+
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
27162718
///
27172719
/// # Examples
27182720
///
@@ -2733,7 +2735,7 @@ macro_rules! int_impl {
27332735
#[must_use = "this returns the result of the operation, \
27342736
without modifying the original"]
27352737
#[inline]
2736-
#[rustc_inherit_overflow_checks]
2738+
#[track_caller]
27372739
pub const fn rem_euclid(self, rhs: Self) -> Self {
27382740
let r = self % rhs;
27392741
if r < 0 {
@@ -2755,12 +2757,8 @@ macro_rules! int_impl {
27552757
///
27562758
/// # Panics
27572759
///
2758-
/// This function will panic if `rhs` is zero.
2759-
///
2760-
/// ## Overflow behavior
2761-
///
2762-
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2763-
/// mode) and wrap if overflow checks are disabled (default in release mode).
2760+
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2761+
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
27642762
///
27652763
/// # Examples
27662764
///
@@ -2780,7 +2778,7 @@ macro_rules! int_impl {
27802778
#[must_use = "this returns the result of the operation, \
27812779
without modifying the original"]
27822780
#[inline]
2783-
#[rustc_inherit_overflow_checks]
2781+
#[track_caller]
27842782
pub const fn div_floor(self, rhs: Self) -> Self {
27852783
let d = self / rhs;
27862784
let r = self % rhs;
@@ -2795,12 +2793,8 @@ macro_rules! int_impl {
27952793
///
27962794
/// # Panics
27972795
///
2798-
/// This function will panic if `rhs` is zero.
2799-
///
2800-
/// ## Overflow behavior
2801-
///
2802-
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2803-
/// mode) and wrap if overflow checks are disabled (default in release mode).
2796+
/// This function will panic if `rhs` is 0 or if `self` is -1 and `rhs` is
2797+
/// `Self::MIN`. This behavior is not affected by the `overflow-checks` flag.
28042798
///
28052799
/// # Examples
28062800
///
@@ -2820,7 +2814,7 @@ macro_rules! int_impl {
28202814
#[must_use = "this returns the result of the operation, \
28212815
without modifying the original"]
28222816
#[inline]
2823-
#[rustc_inherit_overflow_checks]
2817+
#[track_caller]
28242818
pub const fn div_ceil(self, rhs: Self) -> Self {
28252819
let d = self / rhs;
28262820
let r = self % rhs;

‎library/core/src/num/uint_macros.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,10 @@ macro_rules! uint_impl {
15311531
/// Saturating integer division. Computes `self / rhs`, saturating at the
15321532
/// numeric bounds instead of overflowing.
15331533
///
1534+
/// # Panics
1535+
///
1536+
/// This function will panic if `rhs` is 0.
1537+
///
15341538
/// # Examples
15351539
///
15361540
/// Basic usage:
@@ -1539,16 +1543,12 @@ macro_rules! uint_impl {
15391543
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")]
15401544
///
15411545
/// ```
1542-
///
1543-
/// ```should_panic
1544-
#[doc = concat!("let _ = 1", stringify!($SelfT), ".saturating_div(0);")]
1545-
///
1546-
/// ```
15471546
#[stable(feature = "saturating_div", since = "1.58.0")]
15481547
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
15491548
#[must_use = "this returns the result of the operation, \
15501549
without modifying the original"]
15511550
#[inline]
1551+
#[track_caller]
15521552
pub const fn saturating_div(self, rhs: Self) -> Self {
15531553
// on unsigned types, there is no overflow in integer division
15541554
self.wrapping_div(rhs)
@@ -1683,6 +1683,7 @@ macro_rules! uint_impl {
16831683
#[must_use = "this returns the result of the operation, \
16841684
without modifying the original"]
16851685
#[inline(always)]
1686+
#[track_caller]
16861687
pub const fn wrapping_div(self, rhs: Self) -> Self {
16871688
self / rhs
16881689
}
@@ -1712,6 +1713,7 @@ macro_rules! uint_impl {
17121713
#[must_use = "this returns the result of the operation, \
17131714
without modifying the original"]
17141715
#[inline(always)]
1716+
#[track_caller]
17151717
pub const fn wrapping_div_euclid(self, rhs: Self) -> Self {
17161718
self / rhs
17171719
}
@@ -1739,6 +1741,7 @@ macro_rules! uint_impl {
17391741
#[must_use = "this returns the result of the operation, \
17401742
without modifying the original"]
17411743
#[inline(always)]
1744+
#[track_caller]
17421745
pub const fn wrapping_rem(self, rhs: Self) -> Self {
17431746
self % rhs
17441747
}
@@ -1769,6 +1772,7 @@ macro_rules! uint_impl {
17691772
#[must_use = "this returns the result of the operation, \
17701773
without modifying the original"]
17711774
#[inline(always)]
1775+
#[track_caller]
17721776
pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self {
17731777
self % rhs
17741778
}
@@ -2151,6 +2155,7 @@ macro_rules! uint_impl {
21512155
#[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")]
21522156
#[must_use = "this returns the result of the operation, \
21532157
without modifying the original"]
2158+
#[track_caller]
21542159
pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
21552160
(self / rhs, false)
21562161
}
@@ -2181,6 +2186,7 @@ macro_rules! uint_impl {
21812186
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
21822187
#[must_use = "this returns the result of the operation, \
21832188
without modifying the original"]
2189+
#[track_caller]
21842190
pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
21852191
(self / rhs, false)
21862192
}
@@ -2208,6 +2214,7 @@ macro_rules! uint_impl {
22082214
#[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")]
22092215
#[must_use = "this returns the result of the operation, \
22102216
without modifying the original"]
2217+
#[track_caller]
22112218
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
22122219
(self % rhs, false)
22132220
}
@@ -2238,6 +2245,7 @@ macro_rules! uint_impl {
22382245
#[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
22392246
#[must_use = "this returns the result of the operation, \
22402247
without modifying the original"]
2248+
#[track_caller]
22412249
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
22422250
(self % rhs, false)
22432251
}
@@ -2473,7 +2481,7 @@ macro_rules! uint_impl {
24732481
#[must_use = "this returns the result of the operation, \
24742482
without modifying the original"]
24752483
#[inline(always)]
2476-
#[rustc_inherit_overflow_checks]
2484+
#[track_caller]
24772485
pub const fn div_euclid(self, rhs: Self) -> Self {
24782486
self / rhs
24792487
}
@@ -2502,7 +2510,7 @@ macro_rules! uint_impl {
25022510
#[must_use = "this returns the result of the operation, \
25032511
without modifying the original"]
25042512
#[inline(always)]
2505-
#[rustc_inherit_overflow_checks]
2513+
#[track_caller]
25062514
pub const fn rem_euclid(self, rhs: Self) -> Self {
25072515
self % rhs
25082516
}
@@ -2527,6 +2535,7 @@ macro_rules! uint_impl {
25272535
#[must_use = "this returns the result of the operation, \
25282536
without modifying the original"]
25292537
#[inline(always)]
2538+
#[track_caller]
25302539
pub const fn div_floor(self, rhs: Self) -> Self {
25312540
self / rhs
25322541
}
@@ -2537,11 +2546,6 @@ macro_rules! uint_impl {
25372546
///
25382547
/// This function will panic if `rhs` is zero.
25392548
///
2540-
/// ## Overflow behavior
2541-
///
2542-
/// On overflow, this function will panic if overflow checks are enabled (default in debug
2543-
/// mode) and wrap if overflow checks are disabled (default in release mode).
2544-
///
25452549
/// # Examples
25462550
///
25472551
/// Basic usage:
@@ -2554,7 +2558,7 @@ macro_rules! uint_impl {
25542558
#[must_use = "this returns the result of the operation, \
25552559
without modifying the original"]
25562560
#[inline]
2557-
#[rustc_inherit_overflow_checks]
2561+
#[track_caller]
25582562
pub const fn div_ceil(self, rhs: Self) -> Self {
25592563
let d = self / rhs;
25602564
let r = self % rhs;

‎library/core/src/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<T> Option<T> {
642642
/// assert_eq!(x.is_none(), true);
643643
/// ```
644644
#[must_use = "if you intended to assert that this doesn't have a value, consider \
645-
`.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"]
645+
wrapping this in an `assert!()` instead"]
646646
#[inline]
647647
#[stable(feature = "rust1", since = "1.0.0")]
648648
#[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")]

‎src/librustdoc/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ pub(crate) fn run_global_ctxt(
449449

450450
tcx.sess.time("check_lint_expectations", || tcx.check_expectations(Some(sym::rustdoc)));
451451

452+
// We must include lint errors here.
452453
if tcx.dcx().has_errors_or_lint_errors().is_some() {
453454
rustc_errors::FatalError.raise();
454455
}

‎src/librustdoc/doctest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
150150

151151
collector
152152
});
153+
// We must include lint errors here.
153154
if compiler.sess.dcx().has_errors_or_lint_errors().is_some() {
154155
FatalError.raise();
155156
}

‎src/librustdoc/html/static/js/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
17211721
}
17221722
currentPointerId = e.pointerId;
17231723
}
1724+
window.hideAllModals(false);
17241725
e.preventDefault();
17251726
window.addEventListener("pointermove", resize, false);
17261727
window.addEventListener("pointercancel", stopResize, false);

‎src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ fn main_args(
796796

797797
compiler.enter(|queries| {
798798
let mut gcx = abort_on_err(queries.global_ctxt(), sess);
799-
if sess.dcx().has_errors_or_lint_errors().is_some() {
799+
if sess.dcx().has_errors().is_some() {
800800
sess.dcx().fatal("Compilation failed, aborting rustdoc");
801801
}
802802

‎src/librustdoc/passes/collect_trait_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
2222
let tcx = cx.tcx;
2323
// We need to check if there are errors before running this pass because it would crash when
2424
// we try to get auto and blanket implementations.
25-
if tcx.dcx().has_errors_or_lint_errors().is_some() {
25+
if tcx.dcx().has_errors().is_some() {
2626
return krate;
2727
}
2828

‎src/librustdoc/scrape_examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub(crate) fn run(
311311

312312
// The visitor might have found a type error, which we need to
313313
// promote to a fatal error
314-
if tcx.dcx().has_errors_or_lint_errors().is_some() {
314+
if tcx.dcx().has_errors().is_some() {
315315
return Err(String::from("Compilation failed, aborting rustdoc"));
316316
}
317317

‎src/tools/clippy/tests/ui/let_underscore_lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn main() {
2626
let _ = p_rw;
2727
}
2828

29+
#[allow(let_underscore_lock)]
2930
fn uplifted() {
3031
// shouldn't lint std locks as they were uplifted as rustc's `let_underscore_lock`
3132

‎src/tools/rust-installer/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e -u
44

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Checks sidebar resizing close the Settings popover
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
3+
assert-property: (".sidebar", {"clientWidth": "200"})
4+
show-text: true
5+
click: "#settings-menu"
6+
wait-for: "#settings"
7+
assert-css: ("#settings", {"display": "block"})
8+
// normal resizing
9+
drag-and-drop: ((205, 100), (185, 100))
10+
assert-property: (".sidebar", {"clientWidth": "182"})
11+
assert-css: ("#settings", {"display": "none"})
12+
13+
// Now same thing, but for source code
14+
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
15+
click: "#settings-menu"
16+
wait-for: "#settings"
17+
assert-css: ("#settings", {"display": "block"})
18+
assert-property: (".sidebar", {"clientWidth": "49"})
19+
drag-and-drop: ((52, 100), (185, 100))
20+
assert-css: ("#settings", {"display": "none"})

‎tests/ui/lint/let_underscore/let_underscore_drop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ impl Drop for NontrivialDrop {
1111

1212
fn main() {
1313
let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
14+
15+
let (_, _) = (NontrivialDrop, NontrivialDrop); // This should be ignored.
1416
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
// check-fail
22
use std::sync::{Arc, Mutex};
33

4+
struct Struct<T> {
5+
a: T,
6+
}
7+
48
fn main() {
59
let data = Arc::new(Mutex::new(0));
610
let _ = data.lock().unwrap(); //~ERROR non-binding let on a synchronization lock
11+
12+
let _ = data.lock(); //~ERROR non-binding let on a synchronization lock
13+
14+
let (_, _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock
15+
16+
let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock
17+
18+
(_ , _) = (data.lock(), 1); //~ERROR non-binding let on a synchronization lock
19+
20+
let _b;
21+
(_b, Struct { a: _ }) = (0, Struct { a: data.lock() }); //~ERROR non-binding let on a synchronization lock
722
}
Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error: non-binding let on a synchronization lock
2-
--> $DIR/let_underscore_lock.rs:6:9
2+
--> $DIR/let_underscore_lock.rs:10:9
33
|
44
LL | let _ = data.lock().unwrap();
5-
| ^ ^^^^^^^^^^^^^^^^^^^^ this binding will immediately drop the value assigned to it
6-
| |
7-
| this lock is not assigned to a binding and is immediately dropped
5+
| ^ this lock is not assigned to a binding and is immediately dropped
86
|
97
= note: `#[deny(let_underscore_lock)]` on by default
108
help: consider binding to an unused variable to avoid immediately dropping the value
@@ -16,5 +14,70 @@ help: consider immediately dropping the value
1614
LL | drop(data.lock().unwrap());
1715
| ~~~~~ +
1816

19-
error: aborting due to 1 previous error
17+
error: non-binding let on a synchronization lock
18+
--> $DIR/let_underscore_lock.rs:12:9
19+
|
20+
LL | let _ = data.lock();
21+
| ^ this lock is not assigned to a binding and is immediately dropped
22+
|
23+
help: consider binding to an unused variable to avoid immediately dropping the value
24+
|
25+
LL | let _unused = data.lock();
26+
| ~~~~~~~
27+
help: consider immediately dropping the value
28+
|
29+
LL | drop(data.lock());
30+
| ~~~~~ +
31+
32+
error: non-binding let on a synchronization lock
33+
--> $DIR/let_underscore_lock.rs:14:10
34+
|
35+
LL | let (_, _) = (data.lock(), 1);
36+
| ^ this lock is not assigned to a binding and is immediately dropped
37+
|
38+
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
39+
help: consider binding to an unused variable to avoid immediately dropping the value
40+
|
41+
LL | let (_unused, _) = (data.lock(), 1);
42+
| ~~~~~~~
43+
44+
error: non-binding let on a synchronization lock
45+
--> $DIR/let_underscore_lock.rs:16:26
46+
|
47+
LL | let (_a, Struct { a: _ }) = (0, Struct { a: data.lock() });
48+
| ^ this lock is not assigned to a binding and is immediately dropped
49+
|
50+
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
51+
help: consider binding to an unused variable to avoid immediately dropping the value
52+
|
53+
LL | let (_a, Struct { a: _unused }) = (0, Struct { a: data.lock() });
54+
| ~~~~~~~
55+
56+
error: non-binding let on a synchronization lock
57+
--> $DIR/let_underscore_lock.rs:18:6
58+
|
59+
LL | (_ , _) = (data.lock(), 1);
60+
| ^ this lock is not assigned to a binding and is immediately dropped
61+
|
62+
help: consider binding to an unused variable to avoid immediately dropping the value
63+
--> $DIR/let_underscore_lock.rs:18:6
64+
|
65+
LL | (_ , _) = (data.lock(), 1);
66+
| ^
67+
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
68+
69+
error: non-binding let on a synchronization lock
70+
--> $DIR/let_underscore_lock.rs:21:22
71+
|
72+
LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() });
73+
| ^ this lock is not assigned to a binding and is immediately dropped
74+
|
75+
help: consider binding to an unused variable to avoid immediately dropping the value
76+
--> $DIR/let_underscore_lock.rs:21:22
77+
|
78+
LL | (_b, Struct { a: _ }) = (0, Struct { a: data.lock() });
79+
| ^
80+
= help: consider immediately dropping the value using `drop(..)` after the `let` statement
81+
82+
error: aborting due to 6 previous errors
2083

‎triagebot.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file's format is documented at
2+
# https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration
3+
14
[relabel]
25
allow-unauthenticated = [
36
"A-*",
@@ -646,6 +649,7 @@ compiler-team = [
646649
compiler-team-contributors = [
647650
"@TaKO8Ki",
648651
"@b-naber",
652+
"@nnethercote",
649653
]
650654
compiler = [
651655
"compiler-team",
@@ -702,6 +706,9 @@ lexer = [
702706
"@nnethercote",
703707
"@petrochenkov",
704708
]
709+
arena = [
710+
"@nnethercote",
711+
]
705712
mir = [
706713
"@davidtwco",
707714
"@oli-obk",
@@ -735,7 +742,6 @@ style-team = [
735742
"@joshtriplett",
736743
"@yaahc",
737744
]
738-
739745
project-const-traits = [
740746
"@compiler-errors",
741747
"@fee1-dead",
@@ -754,6 +760,7 @@ project-stable-mir = [
754760
"/Cargo.lock" = ["@Mark-Simulacrum"]
755761
"/Cargo.toml" = ["@Mark-Simulacrum"]
756762
"/compiler" = ["compiler"]
763+
"/compiler/rustc_arena" = ["compiler", "arena"]
757764
"/compiler/rustc_ast" = ["compiler", "parser"]
758765
"/compiler/rustc_ast_lowering" = ["compiler", "ast_lowering"]
759766
"/compiler/rustc_hir_analysis" = ["compiler", "types"]
@@ -780,7 +787,7 @@ project-stable-mir = [
780787
"/library/panic_unwind" = ["libs"]
781788
"/library/proc_macro" = ["@petrochenkov"]
782789
"/library/std" = ["libs"]
783-
"/library/std/src/sys/pal/windows" = ["@ChrisDenton", "@thomcc"]
790+
"/library/std/src/sys/pal/windows" = ["@ChrisDenton", "@thomcc"]
784791
"/library/stdarch" = ["libs"]
785792
"/library/test" = ["libs"]
786793
"/src/bootstrap" = ["bootstrap"]

0 commit comments

Comments
 (0)
Please sign in to comment.