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 6 pull requests #87164

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
03f2cf2
Make `--force-warns` a normal lint level option
inquisitivecrystal Jul 8, 2021
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
eb3a527
Address review comments
inquisitivecrystal Jul 9, 2021
dbdce6e
Add tests for command line lint control
inquisitivecrystal Jul 9, 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
6e357bc
Fix tests for i686
wesleywiser Jul 14, 2021
4b10218
Remove refs from pat slices
camsteffen 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
d49f977
Layout error instead of an ICE for packed and aligned types
tmiasko Mar 20, 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
5287058
Rollup merge of #83319 - tmiasko:packed-aligned, r=jackh726
GuillaumeGomez Jul 15, 2021
2886cc8
Rollup merge of #86970 - inquisitivecrystal:force-warn, r=davidtwco
GuillaumeGomez Jul 15, 2021
be2eeb1
Rollup merge of #86983 - wesleywiser:natvis_std_types, r=michaelwoeri…
GuillaumeGomez Jul 15, 2021
5dd7ca3
Rollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis
GuillaumeGomez Jul 15, 2021
afbb612
Rollup merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
GuillaumeGomez Jul 15, 2021
86101d8
Rollup merge of #87162 - GuillaumeGomez:type-decl-overflow, r=notriddle
GuillaumeGomez Jul 15, 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
19 changes: 14 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
eq_sign_span: Span,
assignments: &mut Vec<hir::Stmt<'hir>>,
) -> &'hir hir::Pat<'hir> {
self.arena.alloc(self.destructure_assign_mut(lhs, eq_sign_span, assignments))
}

fn destructure_assign_mut(
&mut self,
lhs: &Expr,
eq_sign_span: Span,
assignments: &mut Vec<hir::Stmt<'hir>>,
) -> hir::Pat<'hir> {
match &lhs.kind {
// Underscore pattern.
ExprKind::Underscore => {
Expand All @@ -1080,7 +1089,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (before, after) = pats.split_at(i);
hir::PatKind::Slice(
before,
Some(self.pat_without_dbm(span, hir::PatKind::Wild)),
Some(self.arena.alloc(self.pat_without_dbm(span, hir::PatKind::Wild))),
after,
)
} else {
Expand Down Expand Up @@ -1165,14 +1174,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
let tuple_pat = hir::PatKind::Tuple(&[], Some(0));
return self.pat_without_dbm(lhs.span, tuple_pat);
} else {
return self.destructure_assign(e, eq_sign_span, assignments);
return self.destructure_assign_mut(e, eq_sign_span, assignments);
}
}
_ => {}
}
// Treat all other cases as normal lvalue.
let ident = Ident::new(sym::lhs, lhs.span);
let (pat, binding) = self.pat_ident(lhs.span, ident);
let (pat, binding) = self.pat_ident_mut(lhs.span, ident);
let ident = self.expr_ident(lhs.span, ident, binding);
let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span);
let expr = self.expr(lhs.span, assign, ThinVec::new());
Expand All @@ -1191,7 +1200,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ctx: &str,
eq_sign_span: Span,
assignments: &mut Vec<hir::Stmt<'hir>>,
) -> (&'hir [&'hir hir::Pat<'hir>], Option<(usize, Span)>) {
) -> (&'hir [hir::Pat<'hir>], Option<(usize, Span)>) {
let mut rest = None;
let elements =
self.arena.alloc_from_iter(elements.iter().enumerate().filter_map(|(i, e)| {
Expand All @@ -1204,7 +1213,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
None
} else {
Some(self.destructure_assign(e, eq_sign_span, assignments))
Some(self.destructure_assign_mut(e, eq_sign_span, assignments))
}
}));
(elements, rest)
Expand Down
27 changes: 18 additions & 9 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2577,21 +2577,35 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
}

fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) {
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::Unannotated)
}

fn pat_ident_binding_mode(
&mut self,
span: Span,
ident: Ident,
bm: hir::BindingAnnotation,
) -> (&'hir hir::Pat<'hir>, hir::HirId) {
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
(self.arena.alloc(pat), hir_id)
}

fn pat_ident_binding_mode_mut(
&mut self,
span: Span,
ident: Ident,
bm: hir::BindingAnnotation,
) -> (hir::Pat<'hir>, hir::HirId) {
let hir_id = self.next_id();

(
self.arena.alloc(hir::Pat {
hir::Pat {
hir_id,
kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
span,
default_binding_modes: true,
}),
},
hir_id,
)
}
Expand All @@ -2609,13 +2623,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
})
}

fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
self.arena.alloc(hir::Pat {
hir_id: self.next_id(),
kind,
span,
default_binding_modes: false,
})
fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
hir::Pat { hir_id: self.next_id(), kind, span, default_binding_modes: false }
}

fn ty_path(
Expand Down
28 changes: 16 additions & 12 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use rustc_span::symbol::Ident;
use rustc_span::{source_map::Spanned, Span};

impl<'a, 'hir> LoweringContext<'a, 'hir> {
crate fn lower_pat(&mut self, mut pattern: &Pat) -> &'hir hir::Pat<'hir> {
crate fn lower_pat(&mut self, pattern: &Pat) -> &'hir hir::Pat<'hir> {
self.arena.alloc(self.lower_pat_mut(pattern))
}

crate fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
ensure_sufficient_stack(|| {
// loop here to avoid recursion
let node = loop {
Expand All @@ -34,7 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
PatKind::Or(ref pats) => {
break hir::PatKind::Or(
self.arena.alloc_from_iter(pats.iter().map(|x| self.lower_pat(x))),
self.arena.alloc_from_iter(pats.iter().map(|x| self.lower_pat_mut(x))),
);
}
PatKind::Path(ref qself, ref path) => {
Expand Down Expand Up @@ -101,7 +105,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
pats: &[P<Pat>],
ctx: &str,
) -> (&'hir [&'hir hir::Pat<'hir>], Option<usize>) {
) -> (&'hir [hir::Pat<'hir>], Option<usize>) {
let mut elems = Vec::with_capacity(pats.len());
let mut rest = None;

Expand Down Expand Up @@ -140,7 +144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

// It was not a sub-tuple pattern so lower it normally.
elems.push(self.lower_pat(pat));
elems.push(self.lower_pat_mut(pat));
}

for (_, pat) in iter {
Expand All @@ -149,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// ...but there was one again, so error.
self.ban_extra_rest_pat(pat.span, rest.unwrap().1, ctx);
} else {
elems.push(self.lower_pat(pat));
elems.push(self.lower_pat_mut(pat));
}
}

Expand Down Expand Up @@ -189,11 +193,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Record, lower it to `$binding_mode $ident @ _`, and stop here.
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
prev_rest_span = Some(sub.span);
slice = Some(lower_rest_sub(self, pat, bm, ident, sub));
slice = Some(self.arena.alloc(lower_rest_sub(self, pat, bm, ident, sub)));
break;
}
// It was not a subslice pattern so lower it normally.
_ => before.push(self.lower_pat(pat)),
_ => before.push(self.lower_pat_mut(pat)),
}
}

Expand All @@ -214,7 +218,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.ban_extra_rest_pat(rest_span, prev_rest_span.unwrap(), "slice");
} else {
// Lower the pattern normally.
after.push(self.lower_pat(pat));
after.push(self.lower_pat_mut(pat));
}
}

Expand Down Expand Up @@ -268,17 +272,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> &'hir hir::Pat<'hir> {
self.pat_with_node_id_of(p, hir::PatKind::Wild)
self.arena.alloc(self.pat_with_node_id_of(p, hir::PatKind::Wild))
}

/// Construct a `Pat` with the `HirId` of `p.id` lowered.
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
self.arena.alloc(hir::Pat {
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
hir::Pat {
hir_id: self.lower_node_id(p.id),
kind,
span: p.span,
default_binding_modes: true,
})
}
}

/// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern.
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,13 @@ impl<'hir> Pat<'hir> {
}

use PatKind::*;
match &self.kind {
match self.kind {
Wild | Lit(_) | Range(..) | Binding(.., None) | Path(_) => true,
Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_short_(it),
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
Slice(before, slice, after) => {
before.iter().chain(slice.iter()).chain(after.iter()).all(|p| p.walk_short_(it))
before.iter().chain(slice).chain(after.iter()).all(|p| p.walk_short_(it))
}
}
}
Expand All @@ -836,13 +836,13 @@ impl<'hir> Pat<'hir> {
}

use PatKind::*;
match &self.kind {
match self.kind {
Wild | Lit(_) | Range(..) | Binding(.., None) | Path(_) => {}
Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_(it),
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
Slice(before, slice, after) => {
before.iter().chain(slice.iter()).chain(after.iter()).for_each(|p| p.walk_(it))
before.iter().chain(slice).chain(after.iter()).for_each(|p| p.walk_(it))
}
}
}
Expand Down Expand Up @@ -940,19 +940,19 @@ pub enum PatKind<'hir> {
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()`
TupleStruct(QPath<'hir>, &'hir [&'hir Pat<'hir>], Option<usize>),
TupleStruct(QPath<'hir>, &'hir [Pat<'hir>], Option<usize>),

/// An or-pattern `A | B | C`.
/// Invariant: `pats.len() >= 2`.
Or(&'hir [&'hir Pat<'hir>]),
Or(&'hir [Pat<'hir>]),

/// A path pattern for an unit struct/variant or a (maybe-associated) constant.
Path(QPath<'hir>),

/// A tuple pattern (e.g., `(a, b)`).
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()`
Tuple(&'hir [&'hir Pat<'hir>], Option<usize>),
Tuple(&'hir [Pat<'hir>], Option<usize>),

/// A `box` pattern.
Box(&'hir Pat<'hir>),
Expand All @@ -975,7 +975,7 @@ pub enum PatKind<'hir> {
/// ```
/// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)])
/// ```
Slice(&'hir [&'hir Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [&'hir Pat<'hir>]),
Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]),
}

#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
Expand Down
24 changes: 5 additions & 19 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use rustc_span::symbol::{sym, Symbol};
use rustc_span::{source_map::MultiSpan, Span, DUMMY_SP};
use tracing::debug;

use std::cmp;

fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
let store = unerased_lint_store(tcx);
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
Expand Down Expand Up @@ -91,36 +89,24 @@ impl<'s> LintLevelsBuilder<'s> {
for &(ref lint_name, level) in &sess.opts.lint_opts {
store.check_lint_name_cmdline(sess, &lint_name, level, self.crate_attrs);
let orig_level = level;

// If the cap is less than this specified level, e.g., if we've got
// `--cap-lints allow` but we've also got `-D foo` then we ignore
// this specification as the lint cap will set it to allow anyway.
let level = cmp::min(level, self.sets.lint_cap);

let lint_flag_val = Symbol::intern(lint_name);

let ids = match store.find_lints(&lint_name) {
Ok(ids) => ids,
Err(_) => continue, // errors handled in check_lint_name_cmdline above
};
for id in ids {
// ForceWarn and Forbid cannot be overriden
if let Some((Level::ForceWarn | Level::Forbid, _)) = specs.get(&id) {
continue;
}

self.check_gated_lint(id, DUMMY_SP);
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
specs.insert(id, (level, src));
}
}

for lint_name in &sess.opts.force_warns {
store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn, self.crate_attrs);
let lints = store
.find_lints(lint_name)
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
for id in lints {
let src = LintLevelSource::CommandLine(Symbol::intern(lint_name), Level::ForceWarn);
specs.insert(id, (Level::ForceWarn, src));
}
}

self.cur = self.sets.list.push(LintSet { specs, parent: COMMAND_LINE });
}

Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let dl = self.data_layout();
let pack = repr.pack;
if pack.is_some() && repr.align.is_some() {
bug!("struct cannot be packed and aligned");
self.tcx.sess.delay_span_bug(DUMMY_SP, "struct cannot be packed and aligned");
return Err(LayoutError::Unknown(ty));
}

let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
Expand Down Expand Up @@ -808,7 +809,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

if def.is_union() {
if def.repr.pack.is_some() && def.repr.align.is_some() {
bug!("union cannot be packed and aligned");
self.tcx.sess.delay_span_bug(
tcx.def_span(def.did),
"union cannot be packed and aligned",
);
return Err(LayoutError::Unknown(ty));
}

let mut align =
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {

fn lower_tuple_subpats(
&mut self,
pats: &'tcx [&'tcx hir::Pat<'tcx>],
pats: &'tcx [hir::Pat<'tcx>],
expected_len: usize,
gap_pos: Option<usize>,
) -> Vec<FieldPat<'tcx>> {
Expand All @@ -338,7 +338,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
.collect()
}

fn lower_patterns(&mut self, pats: &'tcx [&'tcx hir::Pat<'tcx>]) -> Vec<Pat<'tcx>> {
fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Vec<Pat<'tcx>> {
pats.iter().map(|p| self.lower_pattern(p)).collect()
}

Expand All @@ -350,9 +350,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
&mut self,
span: Span,
ty: Ty<'tcx>,
prefix: &'tcx [&'tcx hir::Pat<'tcx>],
prefix: &'tcx [hir::Pat<'tcx>],
slice: &'tcx Option<&'tcx hir::Pat<'tcx>>,
suffix: &'tcx [&'tcx hir::Pat<'tcx>],
suffix: &'tcx [hir::Pat<'tcx>],
) -> PatKind<'tcx> {
let prefix = self.lower_patterns(prefix);
let slice = self.lower_opt_pattern(slice);
Expand Down
Loading