Skip to content

Commit 51548ce

Browse files
committed
Auto merge of rust-lang#139595 - matthiaskrgr:rollup-kaa8aim, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#138470 (Test interaction between RFC 2229 migration and use closures) - rust-lang#138628 (Add more ergonomic clone tests) - rust-lang#139164 (std: improve documentation for get_mut() methods regarding forgotten guards) - rust-lang#139488 (Add missing regression GUI test) - rust-lang#139489 (compiletest: Add directive `dont-require-annotations`) - rust-lang#139513 (Report higher-ranked trait error when higher-ranked projection goal fails in new solver) - rust-lang#139521 (triagebot: roll compiler reviewers for rustc/unstable book) - rust-lang#139532 (Update `u8`-to-and-from-`i8` suggestions.) - rust-lang#139551 (report call site of inlined scopes for large assignment lints) - rust-lang#139575 (Remove redundant words) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 934880f + 7aab307 commit 51548ce

36 files changed

+493
-86
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ pub struct PointeeInfo {
18291829
pub safe: Option<PointerKind>,
18301830
/// If `safe` is `Some`, then the pointer is either null or dereferenceable for this many bytes.
18311831
/// On a function argument, "dereferenceable" here means "dereferenceable for the entire duration
1832-
/// of this function call", i.e. it is UB for the memory that this pointer points to to be freed
1832+
/// of this function call", i.e. it is UB for the memory that this pointer points to be freed
18331833
/// while this function is still running.
18341834
/// The size can be zero if the pointer is not dereferenceable.
18351835
pub size: Size,

Diff for: compiler/rustc_monomorphize/src/mono_checks/move_check.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
148148
span: Span,
149149
) {
150150
let source_info = self.body.source_info(location);
151-
for reported_span in &self.move_size_spans {
152-
if reported_span.overlaps(span) {
153-
return;
154-
}
155-
}
151+
156152
let lint_root = source_info.scope.lint_root(&self.body.source_scopes);
157153
let Some(lint_root) = lint_root else {
158154
// This happens when the issue is in a function from a foreign crate that
@@ -162,13 +158,34 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
162158
// but correct span? This would make the lint at least accept crate-level lint attributes.
163159
return;
164160
};
161+
162+
// If the source scope is inlined by the MIR inliner, report the lint on the call site.
163+
let reported_span = self
164+
.body
165+
.source_scopes
166+
.get(source_info.scope)
167+
.and_then(|source_scope_data| source_scope_data.inlined)
168+
.map(|(_, call_site)| call_site)
169+
.unwrap_or(span);
170+
171+
for previously_reported_span in &self.move_size_spans {
172+
if previously_reported_span.overlaps(reported_span) {
173+
return;
174+
}
175+
}
176+
165177
self.tcx.emit_node_span_lint(
166178
LARGE_ASSIGNMENTS,
167179
lint_root,
168-
span,
169-
LargeAssignmentsLint { span, size: too_large_size.bytes(), limit: limit as u64 },
180+
reported_span,
181+
LargeAssignmentsLint {
182+
span: reported_span,
183+
size: too_large_size.bytes(),
184+
limit: limit as u64,
185+
},
170186
);
171-
self.move_size_spans.push(span);
187+
188+
self.move_size_spans.push(reported_span);
172189
}
173190
}
174191

Diff for: compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,34 @@ impl<'tcx> BestObligation<'tcx> {
291291
}
292292
}
293293

294+
/// When a higher-ranked projection goal fails, check that the corresponding
295+
/// higher-ranked trait goal holds or not. This is because the process of
296+
/// instantiating and then re-canonicalizing the binder of the projection goal
297+
/// forces us to be unable to see that the leak check failed in the nested
298+
/// `NormalizesTo` goal, so we don't fall back to the rigid projection check
299+
/// that should catch when a projection goal fails due to an unsatisfied trait
300+
/// goal.
301+
fn detect_error_in_higher_ranked_projection(
302+
&mut self,
303+
goal: &inspect::InspectGoal<'_, 'tcx>,
304+
) -> ControlFlow<PredicateObligation<'tcx>> {
305+
let tcx = goal.infcx().tcx;
306+
if let Some(projection_clause) = goal.goal().predicate.as_projection_clause()
307+
&& !projection_clause.bound_vars().is_empty()
308+
{
309+
let pred = projection_clause.map_bound(|proj| proj.projection_term.trait_ref(tcx));
310+
self.with_derived_obligation(self.obligation.with(tcx, pred), |this| {
311+
goal.infcx().visit_proof_tree_at_depth(
312+
goal.goal().with(tcx, pred),
313+
goal.depth() + 1,
314+
this,
315+
)
316+
})
317+
} else {
318+
ControlFlow::Continue(())
319+
}
320+
}
321+
294322
/// It is likely that `NormalizesTo` failed without any applicable candidates
295323
/// because the alias is not well-formed.
296324
///
@@ -374,7 +402,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
374402
source: CandidateSource::Impl(impl_def_id),
375403
result: _,
376404
} = candidate.kind()
377-
&& goal.infcx().tcx.do_not_recommend_impl(impl_def_id)
405+
&& tcx.do_not_recommend_impl(impl_def_id)
378406
{
379407
trace!("#[do_not_recommend] -> exit");
380408
return ControlFlow::Break(self.obligation.clone());
@@ -486,7 +514,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
486514
if let Some(obligation) = goal
487515
.infcx()
488516
.visit_proof_tree_at_depth(
489-
goal.goal().with(goal.infcx().tcx, ty::ClauseKind::WellFormed(lhs.into())),
517+
goal.goal().with(tcx, ty::ClauseKind::WellFormed(lhs.into())),
490518
goal.depth() + 1,
491519
self,
492520
)
@@ -496,7 +524,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
496524
} else if let Some(obligation) = goal
497525
.infcx()
498526
.visit_proof_tree_at_depth(
499-
goal.goal().with(goal.infcx().tcx, ty::ClauseKind::WellFormed(rhs.into())),
527+
goal.goal().with(tcx, ty::ClauseKind::WellFormed(rhs.into())),
500528
goal.depth() + 1,
501529
self,
502530
)
@@ -506,6 +534,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
506534
}
507535
}
508536

537+
self.detect_error_in_higher_ranked_projection(goal)?;
538+
509539
ControlFlow::Break(self.obligation.clone())
510540
}
511541
}

Diff for: library/core/src/cell.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,9 @@ impl<T: ?Sized> RefCell<T> {
11561156
/// Since this method borrows `RefCell` mutably, it is statically guaranteed
11571157
/// that no borrows to the underlying data exist. The dynamic checks inherent
11581158
/// in [`borrow_mut`] and most other methods of `RefCell` are therefore
1159-
/// unnecessary.
1159+
/// unnecessary. Note that this method does not reset the borrowing state if borrows were previously leaked
1160+
/// (e.g., via [`forget()`] on a [`Ref`] or [`RefMut`]). For that purpose,
1161+
/// consider using the unstable [`undo_leak`] method.
11601162
///
11611163
/// This method can only be called if `RefCell` can be mutably borrowed,
11621164
/// which in general is only the case directly after the `RefCell` has
@@ -1167,6 +1169,8 @@ impl<T: ?Sized> RefCell<T> {
11671169
/// Use [`borrow_mut`] to get mutable access to the underlying data then.
11681170
///
11691171
/// [`borrow_mut`]: RefCell::borrow_mut()
1172+
/// [`forget()`]: mem::forget
1173+
/// [`undo_leak`]: RefCell::undo_leak()
11701174
///
11711175
/// # Examples
11721176
///

Diff for: library/core/src/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ pub unsafe trait CloneToUninit {
427427
/// read or dropped, because even if it was previously valid, it may have been partially
428428
/// overwritten.
429429
///
430-
/// The caller may wish to to take care to deallocate the allocation pointed to by `dest`,
430+
/// The caller may wish to take care to deallocate the allocation pointed to by `dest`,
431431
/// if applicable, to avoid a memory leak (but this is not a requirement).
432432
///
433433
/// Implementors should avoid leaking values by, upon unwinding, dropping all component values

Diff for: library/core/src/num/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ macro_rules! i8_xe_bytes_doc {
9999
100100
**Note**: This function is meaningless on `i8`. Byte order does not exist as a
101101
concept for byte-sized integers. This function is only provided in symmetry
102-
with larger integer types. You can cast from and to `u8` using `as i8` and `as
103-
u8`.
102+
with larger integer types. You can cast from and to `u8` using
103+
[`cast_signed`](u8::cast_signed) and [`cast_unsigned`](Self::cast_unsigned).
104104
105105
"
106106
};

Diff for: library/std/src/sync/poison/mutex.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ impl<T: ?Sized> Mutex<T> {
582582
/// Returns a mutable reference to the underlying data.
583583
///
584584
/// Since this call borrows the `Mutex` mutably, no actual locking needs to
585-
/// take place -- the mutable borrow statically guarantees no locks exist.
585+
/// take place -- the mutable borrow statically guarantees no new locks can be acquired
586+
/// while this reference exists. Note that this method does not clear any previous abandoned locks
587+
/// (e.g., via [`forget()`] on a [`MutexGuard`]).
586588
///
587589
/// # Errors
588590
///
@@ -599,6 +601,8 @@ impl<T: ?Sized> Mutex<T> {
599601
/// *mutex.get_mut().unwrap() = 10;
600602
/// assert_eq!(*mutex.lock().unwrap(), 10);
601603
/// ```
604+
///
605+
/// [`forget()`]: mem::forget
602606
#[stable(feature = "mutex_get_mut", since = "1.6.0")]
603607
pub fn get_mut(&mut self) -> LockResult<&mut T> {
604608
let data = self.data.get_mut();

Diff for: library/std/src/sync/poison/rwlock.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ impl<T: ?Sized> RwLock<T> {
608608
/// Returns a mutable reference to the underlying data.
609609
///
610610
/// Since this call borrows the `RwLock` mutably, no actual locking needs to
611-
/// take place -- the mutable borrow statically guarantees no locks exist.
611+
/// take place -- the mutable borrow statically guarantees no new locks can be acquired
612+
/// while this reference exists. Note that this method does not clear any previously abandoned locks
613+
/// (e.g., via [`forget()`] on a [`RwLockReadGuard`] or [`RwLockWriteGuard`]).
612614
///
613615
/// # Errors
614616
///

Diff for: src/doc/rustc-dev-guide/src/solve/opaque-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For opaque types in the defining scope and in the implicit-negative coherence mo
3333
always done in two steps. Outside of the defining scope `normalizes-to` for opaques always
3434
returns `Err(NoSolution)`.
3535

36-
We start by trying to to assign the expected type as a hidden type.
36+
We start by trying to assign the expected type as a hidden type.
3737

3838
In the implicit-negative coherence mode, this currently always results in ambiguity without
3939
interacting with the opaque types storage. We could instead add allow 'defining' all opaque types,

Diff for: src/librustdoc/html/static/css/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
14471447
cursor: pointer;
14481448
}
14491449
.setting-check input {
1450-
flex-shrink: 0,
1450+
flex-shrink: 0;
14511451
}
14521452

14531453
.setting-radio input:checked {

Diff for: src/tools/compiletest/src/directive-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
2222
"dont-check-compiler-stderr",
2323
"dont-check-compiler-stdout",
2424
"dont-check-failure-status",
25+
"dont-require-annotations",
2526
"edition",
2627
"error-pattern",
2728
"exact-llvm-major-version",

Diff for: src/tools/compiletest/src/errors.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::sync::OnceLock;
88
use regex::Regex;
99
use tracing::*;
1010

11-
#[derive(Copy, Clone, Debug, PartialEq)]
11+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
1212
pub enum ErrorKind {
1313
Help,
1414
Error,
@@ -40,6 +40,15 @@ impl ErrorKind {
4040
_ => return None,
4141
})
4242
}
43+
44+
pub fn expect_from_user_str(s: &str) -> ErrorKind {
45+
ErrorKind::from_user_str(s).unwrap_or_else(|| {
46+
panic!(
47+
"unexpected diagnostic kind `{s}`, expected \
48+
`ERROR`, `WARN`, `NOTE`, `HELP` or `SUGGESTION`"
49+
)
50+
})
51+
}
4352
}
4453

4554
impl fmt::Display for ErrorKind {

Diff for: src/tools/compiletest/src/header.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::{HashMap, HashSet};
22
use std::env;
33
use std::fs::File;
44
use std::io::BufReader;
@@ -11,6 +11,7 @@ use tracing::*;
1111

1212
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
14+
use crate::errors::ErrorKind;
1415
use crate::executor::{CollectedTestDesc, ShouldPanic};
1516
use crate::header::auxiliary::{AuxProps, parse_and_update_aux};
1617
use crate::header::needs::CachedNeedsConditions;
@@ -196,6 +197,8 @@ pub struct TestProps {
196197
/// Build and use `minicore` as `core` stub for `no_core` tests in cross-compilation scenarios
197198
/// that don't otherwise want/need `-Z build-std`.
198199
pub add_core_stubs: bool,
200+
/// Whether line annotatins are required for the given error kind.
201+
pub require_annotations: HashMap<ErrorKind, bool>,
199202
}
200203

201204
mod directives {
@@ -212,6 +215,7 @@ mod directives {
212215
pub const CHECK_RUN_RESULTS: &'static str = "check-run-results";
213216
pub const DONT_CHECK_COMPILER_STDOUT: &'static str = "dont-check-compiler-stdout";
214217
pub const DONT_CHECK_COMPILER_STDERR: &'static str = "dont-check-compiler-stderr";
218+
pub const DONT_REQUIRE_ANNOTATIONS: &'static str = "dont-require-annotations";
215219
pub const NO_PREFER_DYNAMIC: &'static str = "no-prefer-dynamic";
216220
pub const PRETTY_MODE: &'static str = "pretty-mode";
217221
pub const PRETTY_COMPARE_ONLY: &'static str = "pretty-compare-only";
@@ -297,6 +301,13 @@ impl TestProps {
297301
no_auto_check_cfg: false,
298302
has_enzyme: false,
299303
add_core_stubs: false,
304+
require_annotations: HashMap::from([
305+
(ErrorKind::Help, true),
306+
(ErrorKind::Note, true),
307+
(ErrorKind::Error, true),
308+
(ErrorKind::Warning, true),
309+
(ErrorKind::Suggestion, false),
310+
]),
300311
}
301312
}
302313

@@ -570,6 +581,13 @@ impl TestProps {
570581
config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
571582

572583
self.update_add_core_stubs(ln, config);
584+
585+
if let Some(err_kind) =
586+
config.parse_name_value_directive(ln, DONT_REQUIRE_ANNOTATIONS)
587+
{
588+
self.require_annotations
589+
.insert(ErrorKind::expect_from_user_str(&err_kind), false);
590+
}
573591
},
574592
);
575593

Diff for: src/tools/compiletest/src/runtest.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,6 @@ impl<'test> TestCx<'test> {
709709
self.testpaths.file.display().to_string()
710710
};
711711

712-
// If the testcase being checked contains at least one expected "help"
713-
// message, then we'll ensure that all "help" messages are expected.
714-
// Otherwise, all "help" messages reported by the compiler will be ignored.
715-
// This logic also applies to "note" messages.
716712
let expect_help = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Help));
717713
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
718714

@@ -800,22 +796,24 @@ impl<'test> TestCx<'test> {
800796
}
801797

802798
/// Returns `true` if we should report an error about `actual_error`,
803-
/// which did not match any of the expected error. We always require
804-
/// errors/warnings to be explicitly listed, but only require
805-
/// helps/notes if there are explicit helps/notes given.
799+
/// which did not match any of the expected error.
806800
fn is_unexpected_compiler_message(
807801
&self,
808802
actual_error: &Error,
809803
expect_help: bool,
810804
expect_note: bool,
811805
) -> bool {
812806
actual_error.require_annotation
813-
&& match actual_error.kind {
814-
Some(ErrorKind::Help) => expect_help,
815-
Some(ErrorKind::Note) => expect_note,
816-
Some(ErrorKind::Error) | Some(ErrorKind::Warning) => true,
817-
Some(ErrorKind::Suggestion) | None => false,
818-
}
807+
&& actual_error.kind.map_or(false, |err_kind| {
808+
// If the test being checked doesn't contain any "help" or "note" annotations, then
809+
// we don't require annotating "help" or "note" (respecively) diagnostics at all.
810+
let default_require_annotations = self.props.require_annotations[&err_kind];
811+
match err_kind {
812+
ErrorKind::Help => expect_help && default_require_annotations,
813+
ErrorKind::Note => expect_note && default_require_annotations,
814+
_ => default_require_annotations,
815+
}
816+
})
819817
}
820818

821819
fn should_emit_metadata(&self, pm: Option<PassMode>) -> Emit {

Diff for: tests/rustdoc-gui/settings.goml

+14
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ compare-elements-position: (".sub form", "#settings", ["x"])
314314
// Check that setting-line has the same margin in this mode as in the popover.
315315
assert-css: (".setting-line", {"margin": |setting_line_margin|})
316316

317+
// We will check that the checkboxes size doesn't change either.
318+
assert-size: (
319+
"#settings label > input[type='checkbox']",
320+
{"width": 19, "height": 19},
321+
ALL,
322+
)
323+
317324
// We now check the display with JS disabled.
318325
assert-false: "noscript section"
319326
javascript: false
@@ -327,3 +334,10 @@ reload:
327334
set-window-size: (300, 1000)
328335
wait-for: "#settings"
329336
assert-css: (".setting-radio", {"cursor": "pointer"})
337+
338+
// We ensure that the checkboxes size didn't change.
339+
assert-size: (
340+
"#settings label > input[type='checkbox']",
341+
{"width": 19, "height": 19},
342+
ALL,
343+
)

0 commit comments

Comments
 (0)