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

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
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,

compiler/rustc_monomorphize/src/mono_checks/move_check.rs

Lines changed: 25 additions & 8 deletions
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

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

Lines changed: 33 additions & 3 deletions
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
}

library/core/src/cell.rs

Lines changed: 5 additions & 1 deletion
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
///

library/core/src/clone.rs

Lines changed: 1 addition & 1 deletion
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

library/core/src/num/mod.rs

Lines changed: 2 additions & 2 deletions
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
};

library/std/src/sync/poison/mutex.rs

Lines changed: 5 additions & 1 deletion
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();

library/std/src/sync/poison/rwlock.rs

Lines changed: 3 additions & 1 deletion
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
///

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

Lines changed: 1 addition & 1 deletion
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,

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 1 addition & 1 deletion
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 {

0 commit comments

Comments
 (0)