Skip to content

Commit 547598b

Browse files
committed
Auto merge of #3191 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 535db18 + feb3782 commit 547598b

File tree

58 files changed

+2679
-2608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2679
-2608
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,24 @@ rustc_index::newtype_index! {
121121
/// `BorrowIndex`, and maps each such index to a `BorrowData`
122122
/// describing the borrow. These indexes are used for representing the
123123
/// borrows in compact bitvectors.
124-
pub struct Borrows<'a, 'tcx> {
124+
pub struct Borrows<'mir, 'tcx> {
125125
tcx: TyCtxt<'tcx>,
126-
body: &'a Body<'tcx>,
126+
body: &'mir Body<'tcx>,
127127

128-
borrow_set: &'a BorrowSet<'tcx>,
128+
borrow_set: &'mir BorrowSet<'tcx>,
129129
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
130130
}
131131

132-
struct OutOfScopePrecomputer<'a, 'tcx> {
132+
struct OutOfScopePrecomputer<'mir, 'tcx> {
133133
visited: BitSet<mir::BasicBlock>,
134134
visit_stack: Vec<mir::BasicBlock>,
135-
body: &'a Body<'tcx>,
136-
regioncx: &'a RegionInferenceContext<'tcx>,
135+
body: &'mir Body<'tcx>,
136+
regioncx: &'mir RegionInferenceContext<'tcx>,
137137
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
138138
}
139139

140-
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
141-
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
140+
impl<'mir, 'tcx> OutOfScopePrecomputer<'mir, 'tcx> {
141+
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
142142
OutOfScopePrecomputer {
143143
visited: BitSet::new_empty(body.basic_blocks.len()),
144144
visit_stack: vec![],
@@ -241,17 +241,17 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
241241
prec.borrows_out_of_scope_at_location
242242
}
243243

244-
struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
244+
struct PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
245245
visited: BitSet<mir::BasicBlock>,
246246
visit_stack: Vec<mir::BasicBlock>,
247-
body: &'a Body<'tcx>,
248-
regioncx: &'a RegionInferenceContext<'tcx>,
247+
body: &'mir Body<'tcx>,
248+
regioncx: &'mir RegionInferenceContext<'tcx>,
249249

250250
loans_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
251251
}
252252

253-
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
254-
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
253+
impl<'mir, 'tcx> PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
254+
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
255255
Self {
256256
visited: BitSet::new_empty(body.basic_blocks.len()),
257257
visit_stack: vec![],
@@ -404,12 +404,12 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
404404
}
405405
}
406406

407-
impl<'a, 'tcx> Borrows<'a, 'tcx> {
407+
impl<'mir, 'tcx> Borrows<'mir, 'tcx> {
408408
pub fn new(
409409
tcx: TyCtxt<'tcx>,
410-
body: &'a Body<'tcx>,
411-
regioncx: &'a RegionInferenceContext<'tcx>,
412-
borrow_set: &'a BorrowSet<'tcx>,
410+
body: &'mir Body<'tcx>,
411+
regioncx: &'mir RegionInferenceContext<'tcx>,
412+
borrow_set: &'mir BorrowSet<'tcx>,
413413
) -> Self {
414414
let mut borrows_out_of_scope_at_location =
415415
calculate_borrows_out_of_scope_at_location(body, regioncx, borrow_set);

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn do_mir_borrowck<'tcx>(
288288
.into_engine(tcx, body)
289289
.pass_name("borrowck")
290290
.iterate_to_fixpoint();
291-
let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe)
291+
let flow_ever_inits = EverInitializedPlaces::new(body, &mdpe)
292292
.into_engine(tcx, body)
293293
.pass_name("borrowck")
294294
.iterate_to_fixpoint();

compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
args.push(codegen_backend_arg);
2828
}
2929
if !passed_args.iter().any(|arg| {
30-
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
30+
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
3131
}) {
3232
args.push(OsString::from("--sysroot"));
3333
args.push(OsString::from(sysroot.to_str().unwrap()));

compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
args.push(codegen_backend_arg);
2828
}
2929
if !passed_args.iter().any(|arg| {
30-
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
30+
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
3131
}) {
3232
args.push(OsString::from("--sysroot"));
3333
args.push(OsString::from(sysroot.to_str().unwrap()));

compiler/rustc_expand/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub(crate) fn matches_codepattern(a: &str, b: &str) -> bool {
135135

136136
/// Advances the given peekable `Iterator` until it reaches a non-whitespace character.
137137
fn scan_for_non_ws_or_end<I: Iterator<Item = char>>(iter: &mut Peekable<I>) {
138-
while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) {
138+
while iter.peek().copied().is_some_and(rustc_lexer::is_whitespace) {
139139
iter.next();
140140
}
141141
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1674,10 +1674,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16741674
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
16751675

16761676
// Check that the self types can be related.
1677-
// FIXME(inherent_associated_types): Should we use `eq` here? Method probing uses
1678-
// `sup` for this situtation, too. What for? To constrain inference variables?
1679-
if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err()
1680-
{
1677+
if ocx.eq(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() {
16811678
return false;
16821679
}
16831680

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22932293
let clone_trait =
22942294
self.tcx.require_lang_item(LangItem::Clone, Some(segment.ident.span));
22952295
if args.is_empty()
2296-
&& self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
2297-
|did| {
2296+
&& self
2297+
.typeck_results
2298+
.borrow()
2299+
.type_dependent_def_id(expr.hir_id)
2300+
.is_some_and(|did| {
22982301
let ai = self.tcx.associated_item(did);
22992302
ai.trait_container(self.tcx) == Some(clone_trait)
2300-
},
2301-
) == Some(true)
2303+
})
23022304
&& segment.ident.name == sym::clone
23032305
{
23042306
// If this expression had a clone call when suggesting borrowing

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
161161
&& self
162162
.tcx()
163163
.opt_associated_item(scope_def_id.to_def_id())
164-
.map(|i| i.fn_has_self_parameter)
165-
== Some(true)
164+
.is_some_and(|i| i.fn_has_self_parameter)
166165
}
167166
}

compiler/rustc_infer/src/infer/resolve.rs

+82
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,85 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
260260
}
261261
}
262262
}
263+
264+
///////////////////////////////////////////////////////////////////////////
265+
// EAGER RESOLUTION
266+
267+
/// Resolves ty, region, and const vars to their inferred values or their root vars.
268+
pub struct EagerResolver<'a, 'tcx> {
269+
infcx: &'a InferCtxt<'tcx>,
270+
}
271+
272+
impl<'a, 'tcx> EagerResolver<'a, 'tcx> {
273+
pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
274+
EagerResolver { infcx }
275+
}
276+
}
277+
278+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerResolver<'_, 'tcx> {
279+
fn interner(&self) -> TyCtxt<'tcx> {
280+
self.infcx.tcx
281+
}
282+
283+
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
284+
match *t.kind() {
285+
ty::Infer(ty::TyVar(vid)) => match self.infcx.probe_ty_var(vid) {
286+
Ok(t) => t.fold_with(self),
287+
Err(_) => Ty::new_var(self.infcx.tcx, self.infcx.root_var(vid)),
288+
},
289+
ty::Infer(ty::IntVar(vid)) => self.infcx.opportunistic_resolve_int_var(vid),
290+
ty::Infer(ty::FloatVar(vid)) => self.infcx.opportunistic_resolve_float_var(vid),
291+
_ => {
292+
if t.has_infer() {
293+
t.super_fold_with(self)
294+
} else {
295+
t
296+
}
297+
}
298+
}
299+
}
300+
301+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
302+
match *r {
303+
ty::ReVar(vid) => self
304+
.infcx
305+
.inner
306+
.borrow_mut()
307+
.unwrap_region_constraints()
308+
.opportunistic_resolve_var(self.infcx.tcx, vid),
309+
_ => r,
310+
}
311+
}
312+
313+
fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
314+
match c.kind() {
315+
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
316+
// FIXME: we need to fold the ty too, I think.
317+
match self.infcx.probe_const_var(vid) {
318+
Ok(c) => c.fold_with(self),
319+
Err(_) => {
320+
ty::Const::new_var(self.infcx.tcx, self.infcx.root_const_var(vid), c.ty())
321+
}
322+
}
323+
}
324+
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
325+
debug_assert_eq!(c.ty(), self.infcx.tcx.types.bool);
326+
match self.infcx.probe_effect_var(vid) {
327+
Some(c) => c.as_const(self.infcx.tcx),
328+
None => ty::Const::new_infer(
329+
self.infcx.tcx,
330+
ty::InferConst::EffectVar(self.infcx.root_effect_var(vid)),
331+
self.infcx.tcx.types.bool,
332+
),
333+
}
334+
}
335+
_ => {
336+
if c.has_infer() {
337+
c.super_fold_with(self)
338+
} else {
339+
c
340+
}
341+
}
342+
}
343+
}
344+
}

compiler/rustc_lint/src/non_fmt_panic.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,13 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
154154

155155
let infcx = cx.tcx.infer_ctxt().build();
156156
let suggest_display = is_str
157-
|| cx
158-
.tcx
159-
.get_diagnostic_item(sym::Display)
160-
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
161-
== Some(true);
157+
|| cx.tcx.get_diagnostic_item(sym::Display).is_some_and(|t| {
158+
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
159+
});
162160
let suggest_debug = !suggest_display
163-
&& cx
164-
.tcx
165-
.get_diagnostic_item(sym::Debug)
166-
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
167-
== Some(true);
161+
&& cx.tcx.get_diagnostic_item(sym::Debug).is_some_and(|t| {
162+
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
163+
});
168164

169165
let suggest_panic_any = !is_str && panic == sym::std_panic_macro;
170166

compiler/rustc_middle/src/ty/print/pretty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::ty::{
88
};
99
use crate::ty::{GenericArg, GenericArgKind};
1010
use rustc_apfloat::ieee::{Double, Single};
11+
use rustc_apfloat::Float;
1112
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1213
use rustc_data_structures::sso::SsoHashSet;
1314
use rustc_hir as hir;
@@ -1477,10 +1478,12 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
14771478
ty::Bool if int == ScalarInt::TRUE => p!("true"),
14781479
// Float
14791480
ty::Float(ty::FloatTy::F32) => {
1480-
p!(write("{}f32", Single::try_from(int).unwrap()))
1481+
let val = Single::try_from(int).unwrap();
1482+
p!(write("{}{}f32", val, if val.is_finite() { "" } else { "_" }))
14811483
}
14821484
ty::Float(ty::FloatTy::F64) => {
1483-
p!(write("{}f64", Double::try_from(int).unwrap()))
1485+
let val = Double::try_from(int).unwrap();
1486+
p!(write("{}{}f64", val, if val.is_finite() { "" } else { "_" }))
14841487
}
14851488
// Int
14861489
ty::Uint(_) | ty::Int(_) => {

0 commit comments

Comments
 (0)