From d5ffd36a6cd6fa03b09a60a3835ce6ca90c310ff Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Wed, 16 Oct 2019 13:46:44 +0900 Subject: [PATCH 1/2] Change HashSet element type to `DefId` --- src/librustc_mir/hair/pattern/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 58d741b9295..72e6970ebba 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -1217,7 +1217,7 @@ struct Search<'tcx> { // tracks ADT's previously encountered during search, so that // we will not recur on them again. - seen: FxHashSet<&'tcx AdtDef>, + seen: FxHashSet, } impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> { @@ -1257,14 +1257,12 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool { return true // Halt visiting! } - if self.seen.contains(adt_def) { + if !self.seen.insert(adt_def.did) { debug!("Search already seen adt_def: {:?}", adt_def); // let caller continue its search return false; } - self.seen.insert(adt_def); - // `#[structural_match]` does not care about the // instantiation of the generics in an ADT (it // instead looks directly at its fields outside From ac2f906a592135953ede70429efadd876e21cd09 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Wed, 16 Oct 2019 13:48:20 +0900 Subject: [PATCH 2/2] Make use of the return value of `HashSet::insert` --- src/librustc/middle/stability.rs | 3 +-- src/librustc_codegen_llvm/debuginfo/metadata.rs | 4 +--- src/librustc_metadata/native_libs.rs | 4 +--- src/librustc_mir/borrow_check/conflict_errors.rs | 4 +--- src/librustc_mir/lints.rs | 4 +--- src/librustc_resolve/resolve_imports.rs | 3 +-- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 302c11f309d..b8d1a549ecd 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -905,11 +905,10 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // Warn if the user has enabled an already-stable lang feature. unnecessary_stable_feature_lint(tcx, span, feature, since); } - if lang_features.contains(&feature) { + if !lang_features.insert(feature) { // Warn if the user enables a lang feature multiple times. duplicate_feature_err(tcx.sess, span, feature); } - lang_features.insert(feature); } let declared_lib_features = &tcx.features().declared_lib_features; diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 438a660b8a8..7bd82ced3c3 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -2069,11 +2069,9 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>, { let mut composite_types_completed = debug_context(cx).composite_types_completed.borrow_mut(); - if composite_types_completed.contains(&composite_type_metadata) { + if !composite_types_completed.insert(&composite_type_metadata) { bug!("debuginfo::set_members_of_composite_type() - \ Already completed forward declaration re-encountered."); - } else { - composite_types_completed.insert(composite_type_metadata); } } diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 9e4c2685f11..a58db6a903b 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -198,12 +198,10 @@ fn process_command_line(&mut self) { self.tcx.sess.err(&format!("renaming of the library `{}` was specified, \ however this crate contains no `#[link(...)]` \ attributes referencing this library.", name)); - } else if renames.contains(name) { + } else if !renames.insert(name) { self.tcx.sess.err(&format!("multiple renamings were \ specified for library `{}` .", name)); - } else { - renames.insert(name); } } } diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index 098258994f4..4c469a82ac3 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -78,7 +78,7 @@ pub(super) fn report_use_of_moved_or_uninitialized( .last() .unwrap(); - if self.uninitialized_error_reported.contains(&root_place) { + if !self.uninitialized_error_reported.insert(root_place) { debug!( "report_use_of_moved_or_uninitialized place: error about {:?} suppressed", root_place @@ -86,8 +86,6 @@ pub(super) fn report_use_of_moved_or_uninitialized( return; } - self.uninitialized_error_reported.insert(root_place); - let item_msg = match self.describe_place_with_options(used_place, IncludingDowncast(true)) { Some(name) => format!("`{}`", name), diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index da3fead1f9d..158b730b9bd 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -72,13 +72,11 @@ fn check_fn_for_unconditional_recursion( let caller_substs = &InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]; while let Some(bb) = reachable_without_self_call_queue.pop() { - if visited.contains(bb) { + if !visited.insert(bb) { //already done continue; } - visited.insert(bb); - let block = &basic_blocks[bb]; if let Some(ref terminator) = block.terminator { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 360343169bc..0a734d881ef 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -670,13 +670,12 @@ pub fn finalize_imports(&mut self) { self.throw_unresolved_import_error(errors, None); errors = vec![]; } - if !seen_spans.contains(&err.span) { + if seen_spans.insert(err.span) { let path = import_path_to_string( &import.module_path.iter().map(|seg| seg.ident).collect::>(), &import.subclass, err.span, ); - seen_spans.insert(err.span); errors.push((path, err)); prev_root_id = import.root_id; }