From 5e22500754913f55d6dcba34707b6a442c05bcc7 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Mon, 13 Dec 2021 21:49:21 -0700 Subject: Remove `in_band_lifetimes` from `rustc_incremental` --- compiler/rustc_incremental/src/assert_dep_graph.rs | 4 ++-- compiler/rustc_incremental/src/assert_module_sources.rs | 2 +- compiler/rustc_incremental/src/lib.rs | 1 - compiler/rustc_incremental/src/persist/dirty_clean.rs | 8 ++++---- 4 files changed, 7 insertions(+), 8 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 7b5b015d5a5..4691cdd64c1 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -103,7 +103,7 @@ struct IfThisChanged<'tcx> { then_this_would_need: Targets, } -impl IfThisChanged<'tcx> { +impl<'tcx> IfThisChanged<'tcx> { fn argument(&self, attr: &ast::Attribute) -> Option { let mut value = None; for list_item in attr.meta_item_list().unwrap_or_default() { @@ -172,7 +172,7 @@ impl IfThisChanged<'tcx> { } } -impl Visitor<'tcx> for IfThisChanged<'tcx> { +impl<'tcx> Visitor<'tcx> for IfThisChanged<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/compiler/rustc_incremental/src/assert_module_sources.rs b/compiler/rustc_incremental/src/assert_module_sources.rs index 2cf8f9b08e1..b5974f8fb76 100644 --- a/compiler/rustc_incremental/src/assert_module_sources.rs +++ b/compiler/rustc_incremental/src/assert_module_sources.rs @@ -56,7 +56,7 @@ struct AssertModuleSource<'tcx> { available_cgus: BTreeSet, } -impl AssertModuleSource<'tcx> { +impl<'tcx> AssertModuleSource<'tcx> { fn check_attr(&self, attr: &ast::Attribute) { let (expected_reuse, comp_kind) = if attr.has_name(sym::rustc_partition_reused) { (CguReuse::PreLto, ComparisonKind::AtLeast) diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index 07e9f8b00ca..df64534ce54 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -2,7 +2,6 @@ #![deny(missing_docs)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(in_band_lifetimes)] #![feature(let_else)] #![feature(nll)] #![recursion_limit = "256"] diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs index b2eaf61b7d1..7ac00b4609a 100644 --- a/compiler/rustc_incremental/src/persist/dirty_clean.rs +++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs @@ -155,7 +155,7 @@ pub struct DirtyCleanVisitor<'tcx> { checked_attrs: FxHashSet, } -impl DirtyCleanVisitor<'tcx> { +impl<'tcx> DirtyCleanVisitor<'tcx> { /// Possibly "deserialize" the attribute into a clean/dirty assertion fn assertion_maybe(&mut self, item_id: LocalDefId, attr: &Attribute) -> Option { if !attr.has_name(sym::rustc_clean) { @@ -352,7 +352,7 @@ impl DirtyCleanVisitor<'tcx> { } } -impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { +impl<'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { self.check_item(item.def_id, item.span); } @@ -415,7 +415,7 @@ pub struct FindAllAttrs<'tcx> { found_attrs: Vec<&'tcx Attribute>, } -impl FindAllAttrs<'tcx> { +impl<'tcx> FindAllAttrs<'tcx> { fn is_active_attr(&mut self, attr: &Attribute) -> bool { if attr.has_name(sym::rustc_clean) && check_config(self.tcx, attr) { return true; @@ -434,7 +434,7 @@ impl FindAllAttrs<'tcx> { } } -impl intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> { +impl<'tcx> intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap { -- cgit 1.4.1-3-g733a5 From 2b46c7c90615b9486841ff8e71c126ce95a3fd8a Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Tue, 14 Dec 2021 12:48:41 -0600 Subject: Added -Z layout_seed for allowing user-defined randomization seeds --- compiler/rustc_middle/src/ty/mod.rs | 9 ++++++++- compiler/rustc_session/src/options.rs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d0d2a46fc4c..529e8478371 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1640,7 +1640,14 @@ impl ReprOptions { // Generate a deterministically-derived seed from the item's path hash // to allow for cross-crate compilation to actually work - let field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash(); + let mut field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash(); + + // If the user defined a custom seed for layout randomization, xor the item's + // path hash with the user defined seed, this will allowing determinism while + // still allowing users to further randomize layout generation for e.g. fuzzing + if let Some(user_seed) = tcx.sess.opts.debugging_opts.layout_seed { + field_shuffle_seed ^= user_seed; + } for attr in tcx.get_attrs(did).iter() { for r in attr::find_repr_attrs(&tcx.sess, attr) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index bd7b1639613..32fabb6be4b 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1321,6 +1321,8 @@ options! { "print some statistics about the query system (default: no)"), randomize_layout: bool = (false, parse_bool, [TRACKED], "randomize the layout of types (default: no)"), + layout_seed: Option = (None, parse_opt_number, [TRACKED], + "seed layout randomization"), relax_elf_relocations: Option = (None, parse_opt_bool, [TRACKED], "whether ELF relocations can be relaxed"), relro_level: Option = (None, parse_relro_level, [TRACKED], -- cgit 1.4.1-3-g733a5 From 2af02abd93db9c41d2ee80e4e7562520ae51f24a Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Tue, 14 Dec 2021 13:40:16 -0600 Subject: Minor cleanup --- compiler/rustc_middle/src/ty/layout.rs | 8 ++++---- compiler/rustc_middle/src/ty/mod.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 02811b2491c..727c0ba63cb 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -347,10 +347,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let mut inverse_memory_index: Vec = (0..fields.len() as u32).collect(); - // `ReprOptions.layout_seed` is a deterministic seed that we can use to - // randomize field ordering with - let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed); - let optimize = !repr.inhibit_struct_field_reordering_opt(); if optimize { let end = @@ -364,6 +360,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // the field ordering to try and catch some code making assumptions about layouts // we don't guarantee if repr.can_randomize_type_layout() { + // `ReprOptions.layout_seed` is a deterministic seed that we can use to + // randomize field ordering with + let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed); + // Shuffle the ordering of the fields optimizing.shuffle(&mut rng); diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 529e8478371..10232dc9cb6 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1608,9 +1608,9 @@ bitflags! { // the seed stored in `ReprOptions.layout_seed` const RANDOMIZE_LAYOUT = 1 << 5; // Any of these flags being set prevent field reordering optimisation. - const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits | - ReprFlags::IS_SIMD.bits | - ReprFlags::IS_LINEAR.bits; + const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits + | ReprFlags::IS_SIMD.bits + | ReprFlags::IS_LINEAR.bits; } } -- cgit 1.4.1-3-g733a5 From 6b7fcf720a714b07ab8dc5d21aac03ade62bbdcc Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 14 Dec 2021 22:44:27 -0700 Subject: fix(rustc_lint): better detect when parens are necessary Fixes #90807 --- compiler/rustc_lint/src/unused.rs | 5 ++++- src/test/ui/lint/unused/issue-90807-unused-paren.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/unused/issue-90807-unused-paren.rs (limited to 'compiler') diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index da1edcf6fe3..23a5407950e 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -476,8 +476,11 @@ trait UnusedDelimLint { lhs_needs_parens || (followed_by_block - && match inner.kind { + && match &inner.kind { ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, + ExprKind::Range(_lhs, Some(rhs), _limits) => { + !classify::expr_requires_semi_to_be_stmt(&rhs) + } _ => parser::contains_exterior_struct_lit(&inner), }) } diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren.rs b/src/test/ui/lint/unused/issue-90807-unused-paren.rs new file mode 100644 index 00000000000..4c0930f967d --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren.rs @@ -0,0 +1,8 @@ +// check-pass +// Make sure unused parens lint doesn't emit a false positive. +// See https://github.com/rust-lang/rust/issues/90807 +#![deny(unused_parens)] + +fn main() { + for _ in (1..{ 2 }) {} +} -- cgit 1.4.1-3-g733a5 From f4a0321c03884d2f7e71e9850c7524cabdb73c7c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 17 Dec 2021 14:12:31 -0700 Subject: fix(rustc_lint): mark the parens around `(1..loop {})` as unused --- compiler/rustc_lint/src/unused.rs | 2 +- .../lint/unused/issue-90807-unused-paren-error.rs | 9 +++++++ .../unused/issue-90807-unused-paren-error.stderr | 31 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/unused/issue-90807-unused-paren-error.rs create mode 100644 src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr (limited to 'compiler') diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 23a5407950e..f0ec930345a 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -479,7 +479,7 @@ trait UnusedDelimLint { && match &inner.kind { ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true, ExprKind::Range(_lhs, Some(rhs), _limits) => { - !classify::expr_requires_semi_to_be_stmt(&rhs) + matches!(rhs.kind, ExprKind::Block(..)) } _ => parser::contains_exterior_struct_lit(&inner), }) diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs b/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs new file mode 100644 index 00000000000..2fca2e26265 --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren-error.rs @@ -0,0 +1,9 @@ +// Make sure unused parens lint emit is emitted for loop and match. +// See https://github.com/rust-lang/rust/issues/90807 +// and https://github.com/rust-lang/rust/pull/91956#discussion_r771647953 +#![deny(unused_parens)] + +fn main() { + for _ in (1..loop { break 2 }) {} //~ERROR + for _ in (1..match () { () => 2 }) {} //~ERROR +} diff --git a/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr b/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr new file mode 100644 index 00000000000..4e158e126ac --- /dev/null +++ b/src/test/ui/lint/unused/issue-90807-unused-paren-error.stderr @@ -0,0 +1,31 @@ +error: unnecessary parentheses around `for` iterator expression + --> $DIR/issue-90807-unused-paren-error.rs:7:14 + | +LL | for _ in (1..loop { break 2 }) {} + | ^ ^ + | +note: the lint level is defined here + --> $DIR/issue-90807-unused-paren-error.rs:4:9 + | +LL | #![deny(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - for _ in (1..loop { break 2 }) {} +LL + for _ in 1..loop { break 2 } {} + | + +error: unnecessary parentheses around `for` iterator expression + --> $DIR/issue-90807-unused-paren-error.rs:8:14 + | +LL | for _ in (1..match () { () => 2 }) {} + | ^ ^ + | +help: remove these parentheses + | +LL - for _ in (1..match () { () => 2 }) {} +LL + for _ in 1..match () { () => 2 } {} + | + +error: aborting due to 2 previous errors + -- cgit 1.4.1-3-g733a5