Skip to content

Commit 59d92bd

Browse files
committed
Auto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #86983 (Add or improve natvis definitions for common standard library types) - #87069 (ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow) - #87138 (Correct invariant documentation for `steps_between`) - #87145 (Make --cap-lints and related options leave crate hash alone) - #87161 (RFC2229: Use the correct place type) - #87162 (Fix type decl layout "overflow") - #87167 (Fix sidebar display on small devices) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a6470c7 + b19f37c commit 59d92bd

File tree

30 files changed

+836
-120
lines changed

30 files changed

+836
-120
lines changed

Diff for: compiler/rustc_interface/src/tests.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ fn test_lints_tracking_hash_different_values() {
236236
(String::from("d"), Level::Deny),
237237
];
238238

239-
assert_different_hash(&v1, &v2);
240-
assert_different_hash(&v1, &v3);
241-
assert_different_hash(&v2, &v3);
239+
assert_non_crate_hash_different(&v1, &v2);
240+
assert_non_crate_hash_different(&v1, &v3);
241+
assert_non_crate_hash_different(&v2, &v3);
242242
}
243243

244244
#[test]
@@ -261,7 +261,21 @@ fn test_lints_tracking_hash_different_construction_order() {
261261
];
262262

263263
// The hash should be order-dependent
264-
assert_different_hash(&v1, &v2);
264+
assert_non_crate_hash_different(&v1, &v2);
265+
}
266+
267+
#[test]
268+
fn test_lint_cap_hash_different() {
269+
let mut v1 = Options::default();
270+
let mut v2 = Options::default();
271+
let v3 = Options::default();
272+
273+
v1.lint_cap = Some(Level::Forbid);
274+
v2.lint_cap = Some(Level::Allow);
275+
276+
assert_non_crate_hash_different(&v1, &v2);
277+
assert_non_crate_hash_different(&v1, &v3);
278+
assert_non_crate_hash_different(&v2, &v3);
265279
}
266280

267281
#[test]

Diff for: compiler/rustc_session/src/options.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ top_level_options!(
133133
/// can influence whether overflow checks are done or not.
134134
debug_assertions: bool [TRACKED],
135135
debuginfo: DebugInfo [TRACKED],
136-
lint_opts: Vec<(String, lint::Level)> [TRACKED],
137-
lint_cap: Option<lint::Level> [TRACKED],
138-
force_warns: Vec<String> [TRACKED],
136+
lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
137+
lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
138+
force_warns: Vec<String> [TRACKED_NO_CRATE_HASH],
139139
describe_lints: bool [UNTRACKED],
140140
output_types: OutputTypes [TRACKED],
141141
search_paths: Vec<SearchPath> [UNTRACKED],

Diff for: compiler/rustc_typeck/src/check/upvar.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -1528,20 +1528,11 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
15281528
&mut self,
15291529
place_with_id: &PlaceWithHirId<'tcx>,
15301530
diag_expr_id: hir::HirId,
1531-
mode: euv::ConsumeMode,
15321531
) {
15331532
debug!(
1534-
"adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})",
1535-
place_with_id, diag_expr_id, mode
1533+
"adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?})",
1534+
place_with_id, diag_expr_id
15361535
);
1537-
1538-
// Copy type being used as ByValue are equivalent to ImmBorrow and don't require any
1539-
// escalation.
1540-
match mode {
1541-
euv::ConsumeMode::Copy => return,
1542-
euv::ConsumeMode::Move => {}
1543-
};
1544-
15451536
let tcx = self.fcx.tcx;
15461537
let upvar_id = if let PlaceBase::Upvar(upvar_id) = place_with_id.place.base {
15471538
upvar_id
@@ -1716,22 +1707,14 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
17161707
}
17171708
}
17181709

1719-
fn consume(
1720-
&mut self,
1721-
place_with_id: &PlaceWithHirId<'tcx>,
1722-
diag_expr_id: hir::HirId,
1723-
mode: euv::ConsumeMode,
1724-
) {
1725-
debug!(
1726-
"consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})",
1727-
place_with_id, diag_expr_id, mode
1728-
);
1710+
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
1711+
debug!("consume(place_with_id={:?}, diag_expr_id={:?})", place_with_id, diag_expr_id);
17291712

17301713
if !self.capture_information.contains_key(&place_with_id.place) {
17311714
self.init_capture_info_for_place(&place_with_id, diag_expr_id);
17321715
}
17331716

1734-
self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id, mode);
1717+
self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id);
17351718
}
17361719

17371720
fn borrow(

Diff for: compiler/rustc_typeck/src/expr_use_visitor.rs

+40-22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//! normal visitor, which just walks the entire body in one shot, the
33
//! `ExprUseVisitor` determines how expressions are being used.
44
5-
pub use self::ConsumeMode::*;
6-
75
// Export these here so that Clippy can use them.
86
pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection};
97

@@ -28,19 +26,20 @@ use crate::mem_categorization as mc;
2826
/// This trait defines the callbacks you can expect to receive when
2927
/// employing the ExprUseVisitor.
3028
pub trait Delegate<'tcx> {
31-
// The value found at `place` is either copied or moved, depending
29+
// The value found at `place` is moved, depending
3230
// on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`.
3331
//
32+
// Use of a `Copy` type in a ByValue context is considered a use
33+
// by `ImmBorrow` and `borrow` is called instead. This is because
34+
// a shared borrow is the "minimum access" that would be needed
35+
// to perform a copy.
36+
//
37+
//
3438
// The parameter `diag_expr_id` indicates the HIR id that ought to be used for
3539
// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
3640
// id will be the id of the expression `expr` but the place itself will have
3741
// the id of the binding in the pattern `pat`.
38-
fn consume(
39-
&mut self,
40-
place_with_id: &PlaceWithHirId<'tcx>,
41-
diag_expr_id: hir::HirId,
42-
mode: ConsumeMode,
43-
);
42+
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId);
4443

4544
// The value found at `place` is being borrowed with kind `bk`.
4645
// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
@@ -60,7 +59,7 @@ pub trait Delegate<'tcx> {
6059
}
6160

6261
#[derive(Copy, Clone, PartialEq, Debug)]
63-
pub enum ConsumeMode {
62+
enum ConsumeMode {
6463
Copy, // reference to x where x has a type that copies
6564
Move, // reference to x where x has a type that moves
6665
}
@@ -141,10 +140,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
141140
}
142141

143142
fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
144-
debug!("delegate_consume(place_with_id={:?})", place_with_id);
145-
146-
let mode = copy_or_move(&self.mc, place_with_id);
147-
self.delegate.consume(place_with_id, diag_expr_id, mode);
143+
delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id)
148144
}
149145

150146
fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) {
@@ -256,12 +252,16 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
256252
| PatKind::Path(..)
257253
| PatKind::Struct(..)
258254
| PatKind::Tuple(..) => {
259-
// If the PatKind is a TupleStruct, Struct or Tuple then we want to check
255+
// If the PatKind is a TupleStruct, Path, Struct or Tuple then we want to check
260256
// whether the Variant is a MultiVariant or a SingleVariant. We only want
261257
// to borrow discr if it is a MultiVariant.
262258
// If it is a SingleVariant and creates a binding we will handle that when
263259
// this callback gets called again.
264-
if let ty::Adt(def, _) = place.place.base_ty.kind() {
260+
261+
// Get the type of the Place after all projections have been applied
262+
let place_ty = place.place.ty();
263+
264+
if let ty::Adt(def, _) = place_ty.kind() {
265265
if def.variants.len() > 1 {
266266
needs_to_be_read = true;
267267
}
@@ -653,9 +653,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
653653
delegate.borrow(place, discr_place.hir_id, bk);
654654
}
655655
ty::BindByValue(..) => {
656-
let mode = copy_or_move(mc, &place);
657656
debug!("walk_pat binding consuming pat");
658-
delegate.consume(place, discr_place.hir_id, mode);
657+
delegate_consume(mc, *delegate, place, discr_place.hir_id);
659658
}
660659
}
661660
}
@@ -773,8 +772,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
773772

774773
match capture_info.capture_kind {
775774
ty::UpvarCapture::ByValue(_) => {
776-
let mode = copy_or_move(&self.mc, &place_with_id);
777-
self.delegate.consume(&place_with_id, place_with_id.hir_id, mode);
775+
self.delegate_consume(&place_with_id, place_with_id.hir_id);
778776
}
779777
ty::UpvarCapture::ByRef(upvar_borrow) => {
780778
self.delegate.borrow(
@@ -798,8 +796,28 @@ fn copy_or_move<'a, 'tcx>(
798796
place_with_id.place.ty(),
799797
mc.tcx().hir().span(place_with_id.hir_id),
800798
) {
801-
Move
799+
ConsumeMode::Move
802800
} else {
803-
Copy
801+
ConsumeMode::Copy
802+
}
803+
}
804+
805+
// - If a place is used in a `ByValue` context then move it if it's not a `Copy` type.
806+
// - If the place that is a `Copy` type consider it a `ImmBorrow`.
807+
fn delegate_consume<'a, 'tcx>(
808+
mc: &mc::MemCategorizationContext<'a, 'tcx>,
809+
delegate: &mut (dyn Delegate<'tcx> + 'a),
810+
place_with_id: &PlaceWithHirId<'tcx>,
811+
diag_expr_id: hir::HirId,
812+
) {
813+
debug!("delegate_consume(place_with_id={:?})", place_with_id);
814+
815+
let mode = copy_or_move(&mc, place_with_id);
816+
817+
match mode {
818+
ConsumeMode::Move => delegate.consume(place_with_id, diag_expr_id),
819+
ConsumeMode::Copy => {
820+
delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
821+
}
804822
}
805823
}

Diff for: library/core/src/iter/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub trait Step: Clone + PartialOrd + Sized {
3030
/// For any `a`, `b`, and `n`:
3131
///
3232
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::forward_checked(&a, n) == Some(b)`
33-
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::backward_checked(&a, n) == Some(a)`
33+
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::backward_checked(&b, n) == Some(a)`
3434
/// * `steps_between(&a, &b) == Some(n)` only if `a <= b`
3535
/// * Corollary: `steps_between(&a, &b) == Some(0)` if and only if `a == b`
3636
/// * Note that `a <= b` does _not_ imply `steps_between(&a, &b) != None`;

Diff for: src/etc/natvis/intrinsic.natvis

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
33
<Type Name="str">
4-
<DisplayString>{data_ptr,[length]s8}</DisplayString>
5-
<StringView>data_ptr,[length]s8</StringView>
4+
<DisplayString>{(char*)data_ptr,[length]s8}</DisplayString>
5+
<StringView>(char*)data_ptr,[length]s8</StringView>
66
<Expand>
77
<Item Name="[len]" ExcludeView="simple">length</Item>
88
<Synthetic Name="[chars]">

Diff for: src/etc/natvis/liballoc.natvis

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<Item Name="[len]" ExcludeView="simple">vec.len</Item>
4949
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
5050
<Synthetic Name="[chars]">
51+
<DisplayString>{(char*)vec.buf.ptr.pointer,[vec.len]s8}</DisplayString>
5152
<Expand>
5253
<ArrayItems>
5354
<Size>vec.len</Size>
@@ -57,22 +58,38 @@
5758
</Synthetic>
5859
</Expand>
5960
</Type>
61+
6062
<Type Name="alloc::rc::Rc&lt;*&gt;">
6163
<DisplayString>{ptr.pointer->value}</DisplayString>
6264
<Expand>
6365
<ExpandedItem>ptr.pointer->value</ExpandedItem>
66+
<Item Name="[Reference count]">ptr.pointer->strong</Item>
67+
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
6468
</Expand>
6569
</Type>
70+
<Type Name="alloc::rc::Weak&lt;*&gt;">
71+
<DisplayString>{ptr.pointer->value}</DisplayString>
72+
<Expand>
73+
<ExpandedItem>ptr.pointer->value</ExpandedItem>
74+
<Item Name="[Reference count]">ptr.pointer->strong</Item>
75+
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
76+
</Expand>
77+
</Type>
78+
6679
<Type Name="alloc::sync::Arc&lt;*&gt;">
6780
<DisplayString>{ptr.pointer->data}</DisplayString>
6881
<Expand>
6982
<ExpandedItem>ptr.pointer->data</ExpandedItem>
83+
<Item Name="[Reference count]">ptr.pointer->strong</Item>
84+
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
7085
</Expand>
7186
</Type>
7287
<Type Name="alloc::sync::Weak&lt;*&gt;">
7388
<DisplayString>{ptr.pointer->data}</DisplayString>
7489
<Expand>
7590
<ExpandedItem>ptr.pointer->data</ExpandedItem>
91+
<Item Name="[Reference count]">ptr.pointer->strong</Item>
92+
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
7693
</Expand>
7794
</Type>
7895
<Type Name="alloc::borrow::Cow&lt;*&gt;">

0 commit comments

Comments
 (0)