Skip to content

Commit b6716a1

Browse files
committed
Auto merge of #64695 - Centril:rollup-t1xnl2c, r=Centril
Rollup of 7 pull requests Successful merges: - #64294 (Fix `Stdio::piped` example code and lint) - #64670 (Cleanup syntax::ext::build) - #64674 (Propagate `types.err` in locals further to avoid spurious knock-down errors) - #64676 (Parse assoc type bounds in generic params and provide custom diagnostic) - #64677 (remove outdated comment) - #64679 (Infer consts more consistently) - #64688 (Clarify the "since" tidy check) Failed merges: r? @ghost
2 parents c0b7e71 + 55df97c commit b6716a1

File tree

24 files changed

+186
-466
lines changed

24 files changed

+186
-466
lines changed

src/librustc/infer/combine.rs

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use super::sub::Sub;
3030
use super::type_variable::TypeVariableValue;
3131
use super::unify_key::{ConstVarValue, ConstVariableValue};
3232
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
33+
use super::unify_key::replace_if_possible;
3334

3435
use crate::hir::def_id::DefId;
3536
use crate::mir::interpret::ConstValue;
@@ -127,6 +128,12 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
127128
where
128129
R: TypeRelation<'tcx>,
129130
{
131+
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
132+
if a == b { return Ok(a); }
133+
134+
let a = replace_if_possible(self.const_unification_table.borrow_mut(), a);
135+
let b = replace_if_possible(self.const_unification_table.borrow_mut(), b);
136+
130137
let a_is_expected = relation.a_is_expected();
131138

132139
match (a.val, b.val) {

src/librustc/infer/equate.rs

+3-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use super::combine::{CombineFields, RelationDir, const_unification_error};
1+
use super::combine::{CombineFields, RelationDir};
22
use super::Subtype;
33

44
use crate::hir::def_id::DefId;
55

6-
use crate::ty::{self, Ty, TyCtxt, InferConst};
6+
use crate::ty::{self, Ty, TyCtxt};
77
use crate::ty::TyVar;
88
use crate::ty::subst::SubstsRef;
99
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
10-
use crate::mir::interpret::ConstValue;
11-
use crate::infer::unify_key::replace_if_possible;
1210

1311
/// Ensures `a` is made equal to `b`. Returns `a` on success.
1412
pub struct Equate<'combine, 'infcx, 'tcx> {
@@ -108,39 +106,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
108106
a: &'tcx ty::Const<'tcx>,
109107
b: &'tcx ty::Const<'tcx>,
110108
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
111-
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
112-
if a == b { return Ok(a); }
113-
114-
let infcx = self.fields.infcx;
115-
let a = replace_if_possible(infcx.const_unification_table.borrow_mut(), a);
116-
let b = replace_if_possible(infcx.const_unification_table.borrow_mut(), b);
117-
let a_is_expected = self.a_is_expected();
118-
119-
match (a.val, b.val) {
120-
(ConstValue::Infer(InferConst::Var(a_vid)),
121-
ConstValue::Infer(InferConst::Var(b_vid))) => {
122-
infcx.const_unification_table
123-
.borrow_mut()
124-
.unify_var_var(a_vid, b_vid)
125-
.map_err(|e| const_unification_error(a_is_expected, e))?;
126-
return Ok(a);
127-
}
128-
129-
(ConstValue::Infer(InferConst::Var(a_id)), _) => {
130-
self.fields.infcx.unify_const_variable(a_is_expected, a_id, b)?;
131-
return Ok(a);
132-
}
133-
134-
(_, ConstValue::Infer(InferConst::Var(b_id))) => {
135-
self.fields.infcx.unify_const_variable(!a_is_expected, b_id, a)?;
136-
return Ok(a);
137-
}
138-
139-
_ => {}
140-
}
141-
142-
self.fields.infcx.super_combine_consts(self, a, b)?;
143-
Ok(a)
109+
self.fields.infcx.super_combine_consts(self, a, b)
144110
}
145111

146112
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)

src/librustc/infer/glb.rs

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
6666
a: &'tcx ty::Const<'tcx>,
6767
b: &'tcx ty::Const<'tcx>,
6868
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
69-
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
70-
if a == b {
71-
return Ok(a);
72-
}
73-
7469
self.fields.infcx.super_combine_consts(self, a, b)
7570
}
7671

src/librustc/infer/lub.rs

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ impl TypeRelation<'tcx> for Lub<'combine, 'infcx, 'tcx> {
6666
a: &'tcx ty::Const<'tcx>,
6767
b: &'tcx ty::Const<'tcx>,
6868
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
69-
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
70-
if a == b {
71-
return Ok(a);
72-
}
73-
7469
self.fields.infcx.super_combine_consts(self, a, b)
7570
}
7671

src/librustc/infer/sub.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use super::SubregionOrigin;
2-
use super::combine::{CombineFields, RelationDir, const_unification_error};
2+
use super::combine::{CombineFields, RelationDir};
33

44
use crate::traits::Obligation;
5-
use crate::ty::{self, Ty, TyCtxt, InferConst};
5+
use crate::ty::{self, Ty, TyCtxt};
66
use crate::ty::TyVar;
77
use crate::ty::fold::TypeFoldable;
88
use crate::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
9-
use crate::infer::unify_key::replace_if_possible;
10-
use crate::mir::interpret::ConstValue;
119
use std::mem;
1210

1311
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
@@ -142,41 +140,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
142140
a: &'tcx ty::Const<'tcx>,
143141
b: &'tcx ty::Const<'tcx>,
144142
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
145-
debug!("{}.consts({:?}, {:?})", self.tag(), a, b);
146-
if a == b { return Ok(a); }
147-
148-
let infcx = self.fields.infcx;
149-
let a = replace_if_possible(infcx.const_unification_table.borrow_mut(), a);
150-
let b = replace_if_possible(infcx.const_unification_table.borrow_mut(), b);
151-
152-
// Consts can only be equal or unequal to each other: there's no subtyping
153-
// relation, so we're just going to perform equating here instead.
154-
let a_is_expected = self.a_is_expected();
155-
match (a.val, b.val) {
156-
(ConstValue::Infer(InferConst::Var(a_vid)),
157-
ConstValue::Infer(InferConst::Var(b_vid))) => {
158-
infcx.const_unification_table
159-
.borrow_mut()
160-
.unify_var_var(a_vid, b_vid)
161-
.map_err(|e| const_unification_error(a_is_expected, e))?;
162-
return Ok(a);
163-
}
164-
165-
(ConstValue::Infer(InferConst::Var(a_id)), _) => {
166-
self.fields.infcx.unify_const_variable(a_is_expected, a_id, b)?;
167-
return Ok(a);
168-
}
169-
170-
(_, ConstValue::Infer(InferConst::Var(b_id))) => {
171-
self.fields.infcx.unify_const_variable(!a_is_expected, b_id, a)?;
172-
return Ok(a);
173-
}
174-
175-
_ => {}
176-
}
177-
178-
self.fields.infcx.super_combine_consts(self, a, b)?;
179-
Ok(a)
143+
self.fields.infcx.super_combine_consts(self, a, b)
180144
}
181145

182146
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)

src/librustc_mir/borrow_check/flows.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::rc::Rc;
2323

2424
crate type PoloniusOutput = Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>;
2525

26-
// (forced to be `pub` due to its use as an associated type below.)
2726
crate struct Flows<'b, 'tcx> {
2827
borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>,
2928
pub uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,

src/librustc_typeck/check/coercion.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
163163

164164
// Just ignore error types.
165165
if a.references_error() || b.references_error() {
166-
return success(vec![], b, vec![]);
166+
return success(vec![], self.fcx.tcx.types.err, vec![]);
167167
}
168168

169169
if a.is_never() {
@@ -821,7 +821,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
821821

822822
let (adjustments, _) = self.register_infer_ok_obligations(ok);
823823
self.apply_adjustments(expr, adjustments);
824-
Ok(target)
824+
Ok(if expr_ty.references_error() {
825+
self.tcx.types.err
826+
} else {
827+
target
828+
})
825829
}
826830

827831
/// Same as `try_coerce()`, but without side-effects.

src/librustc_typeck/check/mod.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ use self::method::{MethodCallee, SelfSource};
153153
use self::TupleArgumentsFlag::*;
154154

155155
/// The type of a local binding, including the revealed type for anon types.
156-
#[derive(Copy, Clone)]
156+
#[derive(Copy, Clone, Debug)]
157157
pub struct LocalTy<'tcx> {
158158
decl_ty: Ty<'tcx>,
159159
revealed_ty: Ty<'tcx>
@@ -3822,15 +3822,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38223822

38233823
if let Some(ref init) = local.init {
38243824
let init_ty = self.check_decl_initializer(local, &init);
3825-
if init_ty.references_error() {
3826-
self.write_ty(local.hir_id, init_ty);
3827-
}
3825+
self.overwrite_local_ty_if_err(local, t, init_ty);
38283826
}
38293827

38303828
self.check_pat_top(&local.pat, t, None);
38313829
let pat_ty = self.node_ty(local.pat.hir_id);
3832-
if pat_ty.references_error() {
3833-
self.write_ty(local.hir_id, pat_ty);
3830+
self.overwrite_local_ty_if_err(local, t, pat_ty);
3831+
}
3832+
3833+
fn overwrite_local_ty_if_err(&self, local: &'tcx hir::Local, decl_ty: Ty<'tcx>, ty: Ty<'tcx>) {
3834+
if ty.references_error() {
3835+
// Override the types everywhere with `types.err` to avoid knock down errors.
3836+
self.write_ty(local.hir_id, ty);
3837+
self.write_ty(local.pat.hir_id, ty);
3838+
let local_ty = LocalTy {
3839+
decl_ty,
3840+
revealed_ty: ty,
3841+
};
3842+
self.locals.borrow_mut().insert(local.hir_id, local_ty);
3843+
self.locals.borrow_mut().insert(local.pat.hir_id, local_ty);
38343844
}
38353845
}
38363846

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ impl Stdio {
940940
/// }
941941
///
942942
/// let output = child.wait_with_output().expect("Failed to read stdout");
943-
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n");
943+
/// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH");
944944
/// ```
945945
#[stable(feature = "process", since = "1.0.0")]
946946
pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) }

0 commit comments

Comments
 (0)