Skip to content

Commit 97e3b30

Browse files
committed
Auto merge of rust-lang#89791 - matthiaskrgr:rollup-1lhxh5b, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#89471 (Use Ancestory to check default fn in const impl instead of comparing idents) - rust-lang#89643 (Fix inherent impl overlap check.) - rust-lang#89651 (Add `Poll::ready` and revert stabilization of `task::ready!`) - rust-lang#89675 (Re-use TypeChecker instead of passing around some of its fields ) - rust-lang#89710 (Add long explanation for error E0482) - rust-lang#89756 (Greatly reduce amount of debuginfo compiled for bootstrap itself) - rust-lang#89760 (Remove hack ignoring unused attributes for stage 0 std) - rust-lang#89772 (Fix function-names test for GDB 10.1) - rust-lang#89785 (Fix ICE when compiling nightly std/rustc on beta compiler) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7cc8c44 + f94a325 commit 97e3b30

File tree

22 files changed

+385
-183
lines changed

22 files changed

+385
-183
lines changed

Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ gimli.debug = 0
8989
miniz_oxide.debug = 0
9090
object.debug = 0
9191

92+
# The only package that ever uses debug builds is bootstrap.
93+
# We care a lot about bootstrap's compile times, so don't include debug info for
94+
# dependencies, only bootstrap itself.
95+
[profile.dev]
96+
debug = 0
97+
[profile.dev.package]
98+
# Only use debuginfo=1 to further reduce compile times.
99+
bootstrap.debug = 1
100+
92101
# We want the RLS to use the version of Cargo that we've got vendored in this
93102
# repository to ensure that the same exact version of Cargo is used by both the
94103
# RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository

RELEASES.md

-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Stabilised APIs
6464
- [`VecDeque::shrink_to`]
6565
- [`HashMap::shrink_to`]
6666
- [`HashSet::shrink_to`]
67-
- [`task::ready!`]
6867

6968
These APIs are now usable in const contexts:
7069

@@ -128,7 +127,6 @@ and related tools.
128127
[`VecDeque::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.shrink_to
129128
[`HashMap::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.shrink_to
130129
[`HashSet::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_set/struct.HashSet.html#method.shrink_to
131-
[`task::ready!`]: https://doc.rust-lang.org/stable/std/task/macro.ready.html
132130
[`std::mem::transmute`]: https://doc.rust-lang.org/stable/std/mem/fn.transmute.html
133131
[`slice::first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first
134132
[`slice::split_first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first

compiler/rustc_borrowck/src/type_check/mod.rs

-22
Original file line numberDiff line numberDiff line change
@@ -1153,28 +1153,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11531153
.convert_all(data);
11541154
}
11551155

1156-
/// Convenient wrapper around `relate_tys::relate_types` -- see
1157-
/// that fn for docs.
1158-
fn relate_types(
1159-
&mut self,
1160-
a: Ty<'tcx>,
1161-
v: ty::Variance,
1162-
b: Ty<'tcx>,
1163-
locations: Locations,
1164-
category: ConstraintCategory,
1165-
) -> Fallible<()> {
1166-
relate_tys::relate_types(
1167-
self.infcx,
1168-
self.param_env,
1169-
a,
1170-
v,
1171-
b,
1172-
locations,
1173-
category,
1174-
self.borrowck_context,
1175-
)
1176-
}
1177-
11781156
/// Try to relate `sub <: sup`
11791157
fn sub_types(
11801158
&mut self,

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+53-59
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,44 @@
11
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
2-
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
2+
use rustc_infer::infer::NllRegionVariableOrigin;
33
use rustc_middle::mir::ConstraintCategory;
44
use rustc_middle::ty::relate::TypeRelation;
55
use rustc_middle::ty::{self, Const, Ty};
66
use rustc_trait_selection::traits::query::Fallible;
77

88
use crate::constraints::OutlivesConstraint;
99
use crate::diagnostics::UniverseInfo;
10-
use crate::type_check::{BorrowCheckContext, Locations};
11-
12-
/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
13-
///
14-
/// - "Covariant" `a <: b`
15-
/// - "Invariant" `a == b`
16-
/// - "Contravariant" `a :> b`
17-
///
18-
/// N.B., the type `a` is permitted to have unresolved inference
19-
/// variables, but not the type `b`.
20-
#[instrument(skip(infcx, param_env, borrowck_context), level = "debug")]
21-
pub(super) fn relate_types<'tcx>(
22-
infcx: &InferCtxt<'_, 'tcx>,
23-
param_env: ty::ParamEnv<'tcx>,
24-
a: Ty<'tcx>,
25-
v: ty::Variance,
26-
b: Ty<'tcx>,
27-
locations: Locations,
28-
category: ConstraintCategory,
29-
borrowck_context: &mut BorrowCheckContext<'_, 'tcx>,
30-
) -> Fallible<()> {
31-
TypeRelating::new(
32-
infcx,
33-
NllTypeRelatingDelegate::new(
34-
infcx,
35-
borrowck_context,
36-
param_env,
37-
locations,
38-
category,
39-
UniverseInfo::relate(a, b),
40-
),
41-
v,
42-
)
43-
.relate(a, b)?;
44-
Ok(())
10+
use crate::type_check::{Locations, TypeChecker};
11+
12+
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13+
/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
14+
///
15+
/// - "Covariant" `a <: b`
16+
/// - "Invariant" `a == b`
17+
/// - "Contravariant" `a :> b`
18+
///
19+
/// N.B., the type `a` is permitted to have unresolved inference
20+
/// variables, but not the type `b`.
21+
#[instrument(skip(self), level = "debug")]
22+
pub(super) fn relate_types(
23+
&mut self,
24+
a: Ty<'tcx>,
25+
v: ty::Variance,
26+
b: Ty<'tcx>,
27+
locations: Locations,
28+
category: ConstraintCategory,
29+
) -> Fallible<()> {
30+
TypeRelating::new(
31+
self.infcx,
32+
NllTypeRelatingDelegate::new(self, locations, category, UniverseInfo::relate(a, b)),
33+
v,
34+
)
35+
.relate(a, b)?;
36+
Ok(())
37+
}
4538
}
4639

4740
struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
48-
infcx: &'me InferCtxt<'me, 'tcx>,
49-
borrowck_context: &'me mut BorrowCheckContext<'bccx, 'tcx>,
50-
51-
param_env: ty::ParamEnv<'tcx>,
41+
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
5242

5343
/// Where (and why) is this relation taking place?
5444
locations: Locations,
@@ -63,25 +53,24 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
6353

6454
impl NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
6555
fn new(
66-
infcx: &'me InferCtxt<'me, 'tcx>,
67-
borrowck_context: &'me mut BorrowCheckContext<'bccx, 'tcx>,
68-
param_env: ty::ParamEnv<'tcx>,
56+
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
6957
locations: Locations,
7058
category: ConstraintCategory,
7159
universe_info: UniverseInfo<'tcx>,
7260
) -> Self {
73-
Self { infcx, borrowck_context, param_env, locations, category, universe_info }
61+
Self { type_checker, locations, category, universe_info }
7462
}
7563
}
7664

7765
impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
7866
fn param_env(&self) -> ty::ParamEnv<'tcx> {
79-
self.param_env
67+
self.type_checker.param_env
8068
}
8169

8270
fn create_next_universe(&mut self) -> ty::UniverseIndex {
83-
let universe = self.infcx.create_next_universe();
84-
self.borrowck_context
71+
let universe = self.type_checker.infcx.create_next_universe();
72+
self.type_checker
73+
.borrowck_context
8574
.constraints
8675
.universe_causes
8776
.insert(universe, self.universe_info.clone());
@@ -90,15 +79,18 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
9079

9180
fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> {
9281
let origin = NllRegionVariableOrigin::Existential { from_forall };
93-
self.infcx.next_nll_region_var(origin)
82+
self.type_checker.infcx.next_nll_region_var(origin)
9483
}
9584

9685
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
97-
self.borrowck_context.constraints.placeholder_region(self.infcx, placeholder)
86+
self.type_checker
87+
.borrowck_context
88+
.constraints
89+
.placeholder_region(self.type_checker.infcx, placeholder)
9890
}
9991

10092
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
101-
self.infcx.next_nll_region_var_in_universe(
93+
self.type_checker.infcx.next_nll_region_var_in_universe(
10294
NllRegionVariableOrigin::Existential { from_forall: false },
10395
universe,
10496
)
@@ -110,15 +102,17 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
110102
sub: ty::Region<'tcx>,
111103
info: ty::VarianceDiagInfo<'tcx>,
112104
) {
113-
let sub = self.borrowck_context.universal_regions.to_region_vid(sub);
114-
let sup = self.borrowck_context.universal_regions.to_region_vid(sup);
115-
self.borrowck_context.constraints.outlives_constraints.push(OutlivesConstraint {
116-
sup,
117-
sub,
118-
locations: self.locations,
119-
category: self.category,
120-
variance_info: info,
121-
});
105+
let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub);
106+
let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup);
107+
self.type_checker.borrowck_context.constraints.outlives_constraints.push(
108+
OutlivesConstraint {
109+
sup,
110+
sub,
111+
locations: self.locations,
112+
category: self.category,
113+
variance_info: info,
114+
},
115+
);
122116
}
123117

124118
// We don't have to worry about the equality of consts during borrow checking

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ E0468: include_str!("./error_codes/E0468.md"),
242242
E0469: include_str!("./error_codes/E0469.md"),
243243
E0477: include_str!("./error_codes/E0477.md"),
244244
E0478: include_str!("./error_codes/E0478.md"),
245+
E0482: include_str!("./error_codes/E0482.md"),
245246
E0491: include_str!("./error_codes/E0491.md"),
246247
E0492: include_str!("./error_codes/E0492.md"),
247248
E0493: include_str!("./error_codes/E0493.md"),
@@ -599,7 +600,6 @@ E0785: include_str!("./error_codes/E0785.md"),
599600
// E0479, // the type `..` (provided as the value of a type parameter) is...
600601
// E0480, // lifetime of method receiver does not outlive the method call
601602
// E0481, // lifetime of function argument does not outlive the function call
602-
E0482, // lifetime of return value does not outlive the function call
603603
// E0483, // lifetime of operand does not outlive the operation
604604
// E0484, // reference is not valid at the time of borrow
605605
// E0485, // automatically reference is not valid at the time of borrow
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
A lifetime of a returned value does not outlive the function call.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0482
6+
fn prefix<'a>(
7+
words: impl Iterator<Item = &'a str>
8+
) -> impl Iterator<Item = String> { // error!
9+
words.map(|v| format!("foo-{}", v))
10+
}
11+
```
12+
13+
To fix this error, make the lifetime of the returned value explicit:
14+
15+
```
16+
fn prefix<'a>(
17+
words: impl Iterator<Item = &'a str> + 'a
18+
) -> impl Iterator<Item = String> + 'a { // ok!
19+
words.map(|v| format!("foo-{}", v))
20+
}
21+
```
22+
23+
The [`impl Trait`] feature in this example uses an implicit `'static` lifetime
24+
restriction in the returned type. However the type implementing the `Iterator`
25+
passed to the function lives just as long as `'a`, which is not long enough.
26+
27+
The solution involves adding lifetime bound to both function argument and
28+
the return value to make sure that the values inside the iterator
29+
are not dropped when the function goes out of the scope.
30+
31+
An alternative solution would be to guarantee that the `Item` references
32+
in the iterator are alive for the whole lifetime of the program.
33+
34+
```
35+
fn prefix(
36+
words: impl Iterator<Item = &'static str>
37+
) -> impl Iterator<Item = String> { // ok!
38+
words.map(|v| format!("foo-{}", v))
39+
}
40+
```
41+
42+
A similar lifetime problem might arise when returning closures:
43+
44+
```compile_fail,E0482
45+
fn foo(
46+
x: &mut Vec<i32>
47+
) -> impl FnMut(&mut Vec<i32>) -> &[i32] { // error!
48+
|y| {
49+
y.append(x);
50+
y
51+
}
52+
}
53+
```
54+
55+
Analogically, a solution here is to use explicit return lifetime
56+
and move the ownership of the variable to the closure.
57+
58+
```
59+
fn foo<'a>(
60+
x: &'a mut Vec<i32>
61+
) -> impl FnMut(&mut Vec<i32>) -> &[i32] + 'a { // ok!
62+
move |y| {
63+
y.append(x);
64+
y
65+
}
66+
}
67+
```
68+
69+
To better understand the lifetime treatment in the [`impl Trait`],
70+
please see the [RFC 1951].
71+
72+
[`impl Trait`]: https://doc.rust-lang.org/reference/types/impl-trait.html
73+
[RFC 1951]: https://rust-lang.github.io/rfcs/1951-expand-impl-trait.html

compiler/rustc_index/src/vec.rs

+6
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,12 @@ impl<I: Idx, T> IndexVec<I, Option<T>> {
738738
self.ensure_contains_elem(index, || None);
739739
self[index].get_or_insert_with(value)
740740
}
741+
742+
#[inline]
743+
pub fn remove(&mut self, index: I) -> Option<T> {
744+
self.ensure_contains_elem(index, || None);
745+
self[index].take()
746+
}
741747
}
742748

743749
impl<I: Idx, T: Clone> IndexVec<I, T> {

0 commit comments

Comments
 (0)