Skip to content

Commit 7979016

Browse files
committed
Auto merge of #65632 - JohnTitor:rollup-adb16gb, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #65460 (Clean up `contains()` `insert()` chains on HashSet) - #65463 (Avoid unnecessary arena allocations in `expand_pattern()`.) - #65579 (Changed `resolve_type_vars_with_obligations` to also resolve const inference variables) - #65605 (Remove unreachable unit tuple compare binop codegen) - #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

+3-3
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

+1-2
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

+3
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

+1-3
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

+1-8
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

+1-3
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

+1-3
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

+2-2
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

+4-2
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

+2-4
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

src/librustc_mir/lints.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ fn check_fn_for_unconditional_recursion(
7272
let caller_substs = &InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count];
7373

7474
while let Some(bb) = reachable_without_self_call_queue.pop() {
75-
if visited.contains(bb) {
75+
if !visited.insert(bb) {
7676
//already done
7777
continue;
7878
}
7979

80-
visited.insert(bb);
81-
8280
let block = &basic_blocks[bb];
8381

8482
if let Some(ref terminator) = block.terminator {

src/librustc_resolve/resolve_imports.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
673673
self.throw_unresolved_import_error(errors, None);
674674
errors = vec![];
675675
}
676-
if !seen_spans.contains(&err.span) {
676+
if seen_spans.insert(err.span) {
677677
let path = import_path_to_string(
678678
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
679679
&import.subclass,
680680
err.span,
681681
);
682-
seen_spans.insert(err.span);
683682
errors.push((path, err));
684683
prev_root_id = import.root_id;
685684
}

src/librustc_typeck/check/coercion.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
811811
target: Ty<'tcx>,
812812
allow_two_phase: AllowTwoPhase,
813813
) -> RelateResult<'tcx, Ty<'tcx>> {
814-
let source = self.resolve_type_vars_with_obligations(expr_ty);
814+
let source = self.resolve_vars_with_obligations(expr_ty);
815815
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
816816

817817
let cause = self.cause(expr.span, ObligationCauseCode::ExprAssignable);
@@ -829,7 +829,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
829829

830830
/// Same as `try_coerce()`, but without side-effects.
831831
pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool {
832-
let source = self.resolve_type_vars_with_obligations(expr_ty);
832+
let source = self.resolve_vars_with_obligations(expr_ty);
833833
debug!("coercion::can({:?} -> {:?})", source, target);
834834

835835
let cause = self.cause(syntax_pos::DUMMY_SP, ObligationCauseCode::ExprAssignable);
@@ -853,8 +853,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
853853
-> RelateResult<'tcx, Ty<'tcx>>
854854
where E: AsCoercionSite
855855
{
856-
let prev_ty = self.resolve_type_vars_with_obligations(prev_ty);
857-
let new_ty = self.resolve_type_vars_with_obligations(new_ty);
856+
let prev_ty = self.resolve_vars_with_obligations(prev_ty);
857+
let new_ty = self.resolve_vars_with_obligations(new_ty);
858858
debug!("coercion::try_find_coercion_lub({:?}, {:?})", prev_ty, new_ty);
859859

860860
// Special-case that coercion alone cannot handle:
@@ -1333,7 +1333,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13331333
err.span_label(return_sp, "expected because this return type...");
13341334
err.span_label( *sp, format!(
13351335
"...is found to be `{}` here",
1336-
fcx.resolve_type_vars_with_obligations(expected),
1336+
fcx.resolve_vars_with_obligations(expected),
13371337
));
13381338
}
13391339
err

src/librustc_typeck/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
108108
expected: Ty<'tcx>,
109109
allow_two_phase: AllowTwoPhase)
110110
-> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
111-
let expected = self.resolve_type_vars_with_obligations(expected);
111+
let expected = self.resolve_vars_with_obligations(expected);
112112

113113
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase) {
114114
Ok(ty) => return (ty, None),
@@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117

118118
let expr = expr.peel_drop_temps();
119119
let cause = self.misc(expr.span);
120-
let expr_ty = self.resolve_type_vars_with_obligations(checked_ty);
120+
let expr_ty = self.resolve_vars_with_obligations(checked_ty);
121121
let mut err = self.report_mismatched_types(&cause, expected, expr_ty, e);
122122

123123
if self.is_assign_to_bool(expr, expected) {

src/librustc_typeck/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10101010
expr: &'tcx hir::Expr,
10111011
) -> Ty<'tcx> {
10121012
let flds = expected.only_has_type(self).and_then(|ty| {
1013-
let ty = self.resolve_type_vars_with_obligations(ty);
1013+
let ty = self.resolve_vars_with_obligations(ty);
10141014
match ty.kind {
10151015
ty::Tuple(ref flds) => Some(&flds[..]),
10161016
_ => None

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
919919
// This occurs for UFCS desugaring of `T::method`, where there is no
920920
// receiver expression for the method call, and thus no autoderef.
921921
if let SelfSource::QPath(_) = source {
922-
return is_local(self.resolve_type_vars_with_obligations(rcvr_ty));
922+
return is_local(self.resolve_vars_with_obligations(rcvr_ty));
923923
}
924924

925925
self.autoderef(span, rcvr_ty).any(|(ty, _)| is_local(ty))

src/librustc_typeck/check/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -2440,23 +2440,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24402440
self.cause(span, ObligationCauseCode::MiscObligation)
24412441
}
24422442

2443-
/// Resolves type variables in `ty` if possible. Unlike the infcx
2443+
/// Resolves type and const variables in `ty` if possible. Unlike the infcx
24442444
/// version (resolve_vars_if_possible), this version will
24452445
/// also select obligations if it seems useful, in an effort
24462446
/// to get more type information.
2447-
fn resolve_type_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
2448-
debug!("resolve_type_vars_with_obligations(ty={:?})", ty);
2447+
fn resolve_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
2448+
debug!("resolve_vars_with_obligations(ty={:?})", ty);
24492449

24502450
// No Infer()? Nothing needs doing.
2451-
if !ty.has_infer_types() {
2452-
debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
2451+
if !ty.has_infer_types() && !ty.has_infer_consts() {
2452+
debug!("resolve_vars_with_obligations: ty={:?}", ty);
24532453
return ty;
24542454
}
24552455

24562456
// If `ty` is a type variable, see whether we already know what it is.
24572457
ty = self.resolve_vars_if_possible(&ty);
2458-
if !ty.has_infer_types() {
2459-
debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
2458+
if !ty.has_infer_types() && !ty.has_infer_consts() {
2459+
debug!("resolve_vars_with_obligations: ty={:?}", ty);
24602460
return ty;
24612461
}
24622462

@@ -2467,7 +2467,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24672467
self.select_obligations_where_possible(false, |_| {});
24682468
ty = self.resolve_vars_if_possible(&ty);
24692469

2470-
debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
2470+
debug!("resolve_vars_with_obligations: ty={:?}", ty);
24712471
ty
24722472
}
24732473

@@ -3668,7 +3668,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36683668
formal_ret: Ty<'tcx>,
36693669
formal_args: &[Ty<'tcx>])
36703670
-> Vec<Ty<'tcx>> {
3671-
let formal_ret = self.resolve_type_vars_with_obligations(formal_ret);
3671+
let formal_ret = self.resolve_vars_with_obligations(formal_ret);
36723672
let ret_ty = match expected_ret.only_has_type(self) {
36733673
Some(ret) => ret,
36743674
None => return Vec::new()
@@ -4517,7 +4517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
45174517
err.span_suggestion(
45184518
span,
45194519
"try adding a return type",
4520-
format!("-> {} ", self.resolve_type_vars_with_obligations(found)),
4520+
format!("-> {} ", self.resolve_vars_with_obligations(found)),
45214521
Applicability::MachineApplicable);
45224522
true
45234523
}
@@ -4993,7 +4993,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49934993
// If no resolution is possible, then an error is reported.
49944994
// Numeric inference variables may be left unresolved.
49954995
pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
4996-
let ty = self.resolve_type_vars_with_obligations(ty);
4996+
let ty = self.resolve_vars_with_obligations(ty);
49974997
if !ty.is_ty_var() {
49984998
ty
49994999
} else {

src/librustc_typeck/check/op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
179179
self.check_expr_with_needs(lhs_expr, Needs::MutPlace)
180180
}
181181
};
182-
let lhs_ty = self.resolve_type_vars_with_obligations(lhs_ty);
182+
let lhs_ty = self.resolve_vars_with_obligations(lhs_ty);
183183

184184
// N.B., as we have not yet type-checked the RHS, we don't have the
185185
// type at hand. Make a variable to represent it. The whole reason
@@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
196196

197197
// see `NB` above
198198
let rhs_ty = self.check_expr_coercable_to_type(rhs_expr, rhs_ty_var);
199-
let rhs_ty = self.resolve_type_vars_with_obligations(rhs_ty);
199+
let rhs_ty = self.resolve_vars_with_obligations(rhs_ty);
200200

201201
let return_ty = match result {
202202
Ok(method) => {

src/librustc_typeck/check/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
251251
expected: Ty<'tcx>,
252252
mut def_bm: BindingMode,
253253
) -> (Ty<'tcx>, BindingMode) {
254-
let mut expected = self.resolve_type_vars_with_obligations(&expected);
254+
let mut expected = self.resolve_vars_with_obligations(&expected);
255255

256256
// Peel off as many `&` or `&mut` from the scrutinee type as possible. For example,
257257
// for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches

src/libsyntax/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct Globals {
6767
impl Globals {
6868
fn new(edition: Edition) -> Globals {
6969
Globals {
70-
// We have no idea how many attributes their will be, so just
70+
// We have no idea how many attributes there will be, so just
7171
// initiate the vectors with 0 bits. We'll grow them as necessary.
7272
used_attrs: Lock::new(GrowableBitSet::new_empty()),
7373
known_attrs: Lock::new(GrowableBitSet::new_empty()),

0 commit comments

Comments
 (0)