Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #87182

Merged
merged 30 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07f1e61
Add natvis for NonZero and Wrapping types
wesleywiser Jun 28, 2021
9740dcc
Add natvis for Atomic types
wesleywiser Jun 29, 2021
cad42e0
Add natvis for cell types
wesleywiser Jun 29, 2021
8f1eec3
Fixup natvis for NonNull and Unique types
wesleywiser Jun 29, 2021
f2aba34
Add natvis for Range types
wesleywiser Jun 29, 2021
691ee05
Add natvis for Duration, ManuallyDrop and Pin types
wesleywiser Jun 30, 2021
a6a82c6
Add/improve visualizations for liballoc types
wesleywiser Jun 30, 2021
8500274
Add visualizer for OsString and fixup other string visualizers
wesleywiser Jul 1, 2021
d1852e1
Respond to review feedback
wesleywiser Jul 9, 2021
10b536f
ExprUseVisitor: treat ByValue use of Copy types as ImmBorrow
arora-aman Jul 11, 2021
14fdf8a
Add test for `Unique<T>`, weak ref counts and ref counts for `Weak<T>`
wesleywiser Jul 12, 2021
36f51c9
Add test for copy type in move closure
arora-aman Jul 14, 2021
6c3774e
ExprUseVisitor::Delegate consume only when moving
arora-aman Jul 14, 2021
e753f30
Correct invariant documentation for `steps_between`
dhwthompson Jul 14, 2021
6e357bc
Fix tests for i686
wesleywiser Jul 14, 2021
51142a0
Make --cap-lints and related options leave crate hash alone
jsgf Jul 14, 2021
c4ac836
PR feedback
arora-aman Jul 15, 2021
75291ee
Update compiler/rustc_typeck/src/expr_use_visitor.rs
nikomatsakis Jul 15, 2021
9fe470b
Get the right place type
roxelo Jul 15, 2021
59103d1
Fix layout overflow in type declaration
GuillaumeGomez Jul 15, 2021
25e7403
Add regression test for type declaration layout overflow
GuillaumeGomez Jul 15, 2021
c3c4b9e
Do not hide the sidebar on mobile, move it outside of the viewport in…
GuillaumeGomez Jul 15, 2021
868ffd0
Add test for sidebar display value on mobile
GuillaumeGomez Jul 15, 2021
f4e47ba
Rollup merge of #86983 - wesleywiser:natvis_std_types, r=michaelwoeri…
GuillaumeGomez Jul 16, 2021
c1ffca0
Rollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis
GuillaumeGomez Jul 16, 2021
36de877
Rollup merge of #87138 - dhwthompson:fix-range-invariant, r=JohnTitor
GuillaumeGomez Jul 16, 2021
c1b9bbf
Rollup merge of #87145 - jsgf:fix-lint-opt-hash, r=michaelwoerister
GuillaumeGomez Jul 16, 2021
4143379
Rollup merge of #87161 - sexxi-goose:fix-issue-87097, r=nikomatsakis
GuillaumeGomez Jul 16, 2021
a547abe
Rollup merge of #87162 - GuillaumeGomez:type-decl-overflow, r=notriddle
GuillaumeGomez Jul 16, 2021
b19f37c
Rollup merge of #87167 - GuillaumeGomez:sidebar-display-mobile, r=not…
GuillaumeGomez Jul 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ fn test_lints_tracking_hash_different_values() {
(String::from("d"), Level::Deny),
];

assert_different_hash(&v1, &v2);
assert_different_hash(&v1, &v3);
assert_different_hash(&v2, &v3);
assert_non_crate_hash_different(&v1, &v2);
assert_non_crate_hash_different(&v1, &v3);
assert_non_crate_hash_different(&v2, &v3);
}

#[test]
Expand All @@ -261,7 +261,21 @@ fn test_lints_tracking_hash_different_construction_order() {
];

// The hash should be order-dependent
assert_different_hash(&v1, &v2);
assert_non_crate_hash_different(&v1, &v2);
}

#[test]
fn test_lint_cap_hash_different() {
let mut v1 = Options::default();
let mut v2 = Options::default();
let v3 = Options::default();

v1.lint_cap = Some(Level::Forbid);
v2.lint_cap = Some(Level::Allow);

assert_non_crate_hash_different(&v1, &v2);
assert_non_crate_hash_different(&v1, &v3);
assert_non_crate_hash_different(&v2, &v3);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ top_level_options!(
/// can influence whether overflow checks are done or not.
debug_assertions: bool [TRACKED],
debuginfo: DebugInfo [TRACKED],
lint_opts: Vec<(String, lint::Level)> [TRACKED],
lint_cap: Option<lint::Level> [TRACKED],
force_warns: Vec<String> [TRACKED],
lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
force_warns: Vec<String> [TRACKED_NO_CRATE_HASH],
describe_lints: bool [UNTRACKED],
output_types: OutputTypes [TRACKED],
search_paths: Vec<SearchPath> [UNTRACKED],
Expand Down
27 changes: 5 additions & 22 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1528,20 +1528,11 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
&mut self,
place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId,
mode: euv::ConsumeMode,
) {
debug!(
"adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})",
place_with_id, diag_expr_id, mode
"adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?})",
place_with_id, diag_expr_id
);

// Copy type being used as ByValue are equivalent to ImmBorrow and don't require any
// escalation.
match mode {
euv::ConsumeMode::Copy => return,
euv::ConsumeMode::Move => {}
};

let tcx = self.fcx.tcx;
let upvar_id = if let PlaceBase::Upvar(upvar_id) = place_with_id.place.base {
upvar_id
Expand Down Expand Up @@ -1716,22 +1707,14 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
}
}

fn consume(
&mut self,
place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId,
mode: euv::ConsumeMode,
) {
debug!(
"consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})",
place_with_id, diag_expr_id, mode
);
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
debug!("consume(place_with_id={:?}, diag_expr_id={:?})", place_with_id, diag_expr_id);

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

self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id, mode);
self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id);
}

fn borrow(
Expand Down
62 changes: 40 additions & 22 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! normal visitor, which just walks the entire body in one shot, the
//! `ExprUseVisitor` determines how expressions are being used.

pub use self::ConsumeMode::*;

// Export these here so that Clippy can use them.
pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection};

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

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

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum ConsumeMode {
enum ConsumeMode {
Copy, // reference to x where x has a type that copies
Move, // reference to x where x has a type that moves
}
Expand Down Expand Up @@ -141,10 +140,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
}

fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
debug!("delegate_consume(place_with_id={:?})", place_with_id);

let mode = copy_or_move(&self.mc, place_with_id);
self.delegate.consume(place_with_id, diag_expr_id, mode);
delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id)
}

fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) {
Expand Down Expand Up @@ -256,12 +252,16 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
| PatKind::Path(..)
| PatKind::Struct(..)
| PatKind::Tuple(..) => {
// If the PatKind is a TupleStruct, Struct or Tuple then we want to check
// If the PatKind is a TupleStruct, Path, Struct or Tuple then we want to check
// whether the Variant is a MultiVariant or a SingleVariant. We only want
// to borrow discr if it is a MultiVariant.
// If it is a SingleVariant and creates a binding we will handle that when
// this callback gets called again.
if let ty::Adt(def, _) = place.place.base_ty.kind() {

// Get the type of the Place after all projections have been applied
let place_ty = place.place.ty();

if let ty::Adt(def, _) = place_ty.kind() {
if def.variants.len() > 1 {
needs_to_be_read = true;
}
Expand Down Expand Up @@ -653,9 +653,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
delegate.borrow(place, discr_place.hir_id, bk);
}
ty::BindByValue(..) => {
let mode = copy_or_move(mc, &place);
debug!("walk_pat binding consuming pat");
delegate.consume(place, discr_place.hir_id, mode);
delegate_consume(mc, *delegate, place, discr_place.hir_id);
}
}
}
Expand Down Expand Up @@ -773,8 +772,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {

match capture_info.capture_kind {
ty::UpvarCapture::ByValue(_) => {
let mode = copy_or_move(&self.mc, &place_with_id);
self.delegate.consume(&place_with_id, place_with_id.hir_id, mode);
self.delegate_consume(&place_with_id, place_with_id.hir_id);
}
ty::UpvarCapture::ByRef(upvar_borrow) => {
self.delegate.borrow(
Expand All @@ -798,8 +796,28 @@ fn copy_or_move<'a, 'tcx>(
place_with_id.place.ty(),
mc.tcx().hir().span(place_with_id.hir_id),
) {
Move
ConsumeMode::Move
} else {
Copy
ConsumeMode::Copy
}
}

// - If a place is used in a `ByValue` context then move it if it's not a `Copy` type.
// - If the place that is a `Copy` type consider it a `ImmBorrow`.
fn delegate_consume<'a, 'tcx>(
mc: &mc::MemCategorizationContext<'a, 'tcx>,
delegate: &mut (dyn Delegate<'tcx> + 'a),
place_with_id: &PlaceWithHirId<'tcx>,
diag_expr_id: hir::HirId,
) {
debug!("delegate_consume(place_with_id={:?})", place_with_id);

let mode = copy_or_move(&mc, place_with_id);

match mode {
ConsumeMode::Move => delegate.consume(place_with_id, diag_expr_id),
ConsumeMode::Copy => {
delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
}
}
}
2 changes: 1 addition & 1 deletion library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait Step: Clone + PartialOrd + Sized {
/// For any `a`, `b`, and `n`:
///
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::forward_checked(&a, n) == Some(b)`
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::backward_checked(&a, n) == Some(a)`
/// * `steps_between(&a, &b) == Some(n)` if and only if `Step::backward_checked(&b, n) == Some(a)`
/// * `steps_between(&a, &b) == Some(n)` only if `a <= b`
/// * Corollary: `steps_between(&a, &b) == Some(0)` if and only if `a == b`
/// * Note that `a <= b` does _not_ imply `steps_between(&a, &b) != None`;
Expand Down
4 changes: 2 additions & 2 deletions src/etc/natvis/intrinsic.natvis
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="str">
<DisplayString>{data_ptr,[length]s8}</DisplayString>
<StringView>data_ptr,[length]s8</StringView>
<DisplayString>{(char*)data_ptr,[length]s8}</DisplayString>
<StringView>(char*)data_ptr,[length]s8</StringView>
<Expand>
<Item Name="[len]" ExcludeView="simple">length</Item>
<Synthetic Name="[chars]">
Expand Down
17 changes: 17 additions & 0 deletions src/etc/natvis/liballoc.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Item Name="[len]" ExcludeView="simple">vec.len</Item>
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
<Synthetic Name="[chars]">
<DisplayString>{(char*)vec.buf.ptr.pointer,[vec.len]s8}</DisplayString>
<Expand>
<ArrayItems>
<Size>vec.len</Size>
Expand All @@ -57,22 +58,38 @@
</Synthetic>
</Expand>
</Type>

<Type Name="alloc::rc::Rc&lt;*&gt;">
<DisplayString>{ptr.pointer->value}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->value</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::rc::Weak&lt;*&gt;">
<DisplayString>{ptr.pointer->value}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->value</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>

<Type Name="alloc::sync::Arc&lt;*&gt;">
<DisplayString>{ptr.pointer->data}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->data</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::sync::Weak&lt;*&gt;">
<DisplayString>{ptr.pointer->data}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->data</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::borrow::Cow&lt;*&gt;">
Expand Down
Loading