Skip to content

Commit 7979016

Browse files
committed
Auto merge of rust-lang#65632 - JohnTitor:rollup-adb16gb, r=JohnTitor
Rollup of 5 pull requests Successful merges: - rust-lang#65460 (Clean up `contains()` `insert()` chains on HashSet) - rust-lang#65463 (Avoid unnecessary arena allocations in `expand_pattern()`.) - rust-lang#65579 (Changed `resolve_type_vars_with_obligations` to also resolve const inference variables) - rust-lang#65605 (Remove unreachable unit tuple compare binop codegen) - rust-lang#65626 (trivial typo fix) Failed merges: r? @ghost
2 parents 89e645a + c609a5a commit 7979016

File tree

21 files changed

+53
-67
lines changed

21 files changed

+53
-67
lines changed

src/librustc/infer/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{InferCtxt, FixupError, FixupResult, Span};
22
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
33
use crate::mir::interpret::ConstValue;
4-
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags};
4+
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst};
55
use crate::ty::fold::{TypeFolder, TypeVisitor};
66

77
///////////////////////////////////////////////////////////////////////////
@@ -29,7 +29,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
2929
}
3030

3131
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
32-
if !t.has_infer_types() {
32+
if !t.has_infer_types() && !t.has_infer_consts() {
3333
t // micro-optimize -- if there is nothing in this type that this fold affects...
3434
} else {
3535
let t = self.infcx.shallow_resolve(t);
@@ -38,7 +38,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
3838
}
3939

4040
fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
41-
if !ct.has_type_flags(TypeFlags::HAS_CT_INFER) {
41+
if !ct.has_infer_consts() {
4242
ct // micro-optimize -- if there is nothing in this const that this fold affects...
4343
} else {
4444
let ct = self.infcx.shallow_resolve(ct);

src/librustc/middle/stability.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,10 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
905905
// Warn if the user has enabled an already-stable lang feature.
906906
unnecessary_stable_feature_lint(tcx, span, feature, since);
907907
}
908-
if lang_features.contains(&feature) {
908+
if !lang_features.insert(feature) {
909909
// Warn if the user enables a lang feature multiple times.
910910
duplicate_feature_err(tcx.sess, span, feature);
911911
}
912-
lang_features.insert(feature);
913912
}
914913

915914
let declared_lib_features = &tcx.features().declared_lib_features;

src/librustc/ty/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
8888
fn has_infer_types(&self) -> bool {
8989
self.has_type_flags(TypeFlags::HAS_TY_INFER)
9090
}
91+
fn has_infer_consts(&self) -> bool {
92+
self.has_type_flags(TypeFlags::HAS_CT_INFER)
93+
}
9194
fn has_local_value(&self) -> bool {
9295
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
9396
}

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,11 +2069,9 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
20692069
{
20702070
let mut composite_types_completed =
20712071
debug_context(cx).composite_types_completed.borrow_mut();
2072-
if composite_types_completed.contains(&composite_type_metadata) {
2072+
if !composite_types_completed.insert(&composite_type_metadata) {
20732073
bug!("debuginfo::set_members_of_composite_type() - \
20742074
Already completed forward declaration re-encountered.");
2075-
} else {
2076-
composite_types_completed.insert(composite_type_metadata);
20772075
}
20782076
}
20792077

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
556556
) -> Bx::Value {
557557
let is_float = input_ty.is_floating_point();
558558
let is_signed = input_ty.is_signed();
559-
let is_unit = input_ty.is_unit();
560559
match op {
561560
mir::BinOp::Add => if is_float {
562561
bx.fadd(lhs, rhs)
@@ -594,13 +593,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
594593
mir::BinOp::Shl => common::build_unchecked_lshift(bx, lhs, rhs),
595594
mir::BinOp::Shr => common::build_unchecked_rshift(bx, input_ty, lhs, rhs),
596595
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt |
597-
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_unit {
598-
bx.cx().const_bool(match op {
599-
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt => false,
600-
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => true,
601-
_ => unreachable!()
602-
})
603-
} else if is_float {
596+
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_float {
604597
bx.fcmp(
605598
base::bin_op_to_fcmp_predicate(op.to_hir_binop()),
606599
lhs, rhs

src/librustc_metadata/native_libs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,10 @@ impl Collector<'tcx> {
198198
self.tcx.sess.err(&format!("renaming of the library `{}` was specified, \
199199
however this crate contains no `#[link(...)]` \
200200
attributes referencing this library.", name));
201-
} else if renames.contains(name) {
201+
} else if !renames.insert(name) {
202202
self.tcx.sess.err(&format!("multiple renamings were \
203203
specified for library `{}` .",
204204
name));
205-
} else {
206-
renames.insert(name);
207205
}
208206
}
209207
}

src/librustc_mir/borrow_check/conflict_errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
7878
.last()
7979
.unwrap();
8080

81-
if self.uninitialized_error_reported.contains(&root_place) {
81+
if !self.uninitialized_error_reported.insert(root_place) {
8282
debug!(
8383
"report_use_of_moved_or_uninitialized place: error about {:?} suppressed",
8484
root_place
8585
);
8686
return;
8787
}
8888

89-
self.uninitialized_error_reported.insert(root_place);
90-
9189
let item_msg = match self.describe_place_with_options(used_place,
9290
IncludingDowncast(true)) {
9391
Some(name) => format!("`{}`", name),

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ use std::ops::RangeInclusive;
189189
use std::u128;
190190
use std::convert::TryInto;
191191

192-
pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> &'a Pat<'tcx> {
193-
cx.pattern_arena.alloc(LiteralExpander { tcx: cx.tcx }.fold_pattern(&pat))
192+
pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> Pat<'tcx> {
193+
LiteralExpander { tcx: cx.tcx }.fold_pattern(&pat)
194194
}
195195

196196
struct LiteralExpander<'tcx> {

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
154154
self.tables
155155
);
156156
patcx.include_lint_checks();
157-
let pattern = expand_pattern(cx, patcx.lower_pattern(&pat));
157+
let pattern =
158+
cx.pattern_arena.alloc(expand_pattern(cx, patcx.lower_pattern(&pat))) as &_;
158159
if !patcx.errors.is_empty() {
159160
patcx.report_inlining_errors(pat.span);
160161
have_errors = true;
@@ -253,8 +254,9 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
253254
patcx.include_lint_checks();
254255
let pattern = patcx.lower_pattern(pat);
255256
let pattern_ty = pattern.ty;
257+
let pattern = expand_pattern(cx, pattern);
256258
let pats: Matrix<'_, '_> = vec![smallvec![
257-
expand_pattern(cx, pattern)
259+
&pattern
258260
]].into_iter().collect();
259261

260262
let witnesses = match check_not_useful(cx, pattern_ty, &pats, pat.hir_id) {

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ fn search_for_adt_without_structural_match<'tcx>(tcx: TyCtxt<'tcx>,
12141214

12151215
// tracks ADT's previously encountered during search, so that
12161216
// we will not recur on them again.
1217-
seen: FxHashSet<&'tcx AdtDef>,
1217+
seen: FxHashSet<hir::def_id::DefId>,
12181218
}
12191219

12201220
impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
@@ -1254,14 +1254,12 @@ fn search_for_adt_without_structural_match<'tcx>(tcx: TyCtxt<'tcx>,
12541254
return true // Halt visiting!
12551255
}
12561256

1257-
if self.seen.contains(adt_def) {
1257+
if !self.seen.insert(adt_def.did) {
12581258
debug!("Search already seen adt_def: {:?}", adt_def);
12591259
// let caller continue its search
12601260
return false;
12611261
}
12621262

1263-
self.seen.insert(adt_def);
1264-
12651263
// `#[structural_match]` does not care about the
12661264
// instantiation of the generics in an ADT (it
12671265
// instead looks directly at its fields outside

0 commit comments

Comments
 (0)