Skip to content

Commit 93ef0cd

Browse files
committed
Auto merge of #99098 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backport rollup * Return a FxIndexSet in is_late_bound query. #98959 * rustdoc: filter '_ lifetimes from ty::PolyTraitRef #98727 * don't succeed evaluate_obligation query if new opaque types were registered #98614 * Update llvm-project #98567 There's a few more as-yet-unapproved/unmerged PRs that'll land later, but creating a partial rollup for now so that we can include at least some PRs in the first crater run. r? `@Mark-Simulacrum`
2 parents 94811fd + b5c6911 commit 93ef0cd

File tree

29 files changed

+163
-192
lines changed

29 files changed

+163
-192
lines changed

compiler/rustc_infer/src/infer/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
891891
.region_constraints_added_in_snapshot(&snapshot.undo_snapshot)
892892
}
893893

894+
pub fn opaque_types_added_in_snapshot(&self, snapshot: &CombinedSnapshot<'a, 'tcx>) -> bool {
895+
self.inner.borrow().undo_log.opaque_types_in_snapshot(&snapshot.undo_snapshot)
896+
}
897+
894898
pub fn add_given(&self, sub: ty::Region<'tcx>, sup: ty::RegionVid) {
895899
self.inner.borrow_mut().unwrap_region_constraints().add_given(sub, sup);
896900
}

compiler/rustc_infer/src/infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
103103
}
104104
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
105105
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
106-
ty::Opaque(def_id, substs) => {
106+
ty::Opaque(def_id, substs) if def_id.is_local() => {
107107
let origin = if self.defining_use_anchor.is_some() {
108108
// Check that this is `impl Trait` type is
109109
// declared by `parent_def_id` -- i.e., one whose

compiler/rustc_infer/src/infer/undo_log.rs

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl<'tcx> InferCtxtUndoLogs<'tcx> {
185185
})
186186
}
187187

188+
pub(crate) fn opaque_types_in_snapshot(&self, s: &Snapshot<'tcx>) -> bool {
189+
self.logs[s.undo_len..].iter().any(|log| matches!(log, UndoLog::OpaqueTypes(..)))
190+
}
191+
188192
pub(crate) fn region_constraints(
189193
&self,
190194
) -> impl Iterator<Item = &'_ region_constraints::UndoLog<'tcx>> + Clone {

compiler/rustc_infer/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
203203
Some(&ProjectionCacheEntry::NormalizedTy { ref ty, complete: _ }) => {
204204
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
205205
let mut ty = ty.clone();
206-
if result == EvaluationResult::EvaluatedToOk {
206+
if result.must_apply_considering_regions() {
207207
ty.obligations = vec![];
208208
}
209209
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty, complete: Some(result) });

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ macro_rules! arena_types {
9696
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
9797
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
9898
[decode] used_trait_imports: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
99+
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::def_id::LocalDefId>,
99100
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
100101

101102
[] dep_kind: rustc_middle::dep_graph::DepKindStruct,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ rustc_queries! {
15721572
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
15731573
desc { "looking up a named region" }
15741574
}
1575-
query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxHashSet<LocalDefId>> {
1575+
query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
15761576
desc { "testing if a region is late bound" }
15771577
}
15781578
/// For a given item (like a struct), gets the default lifetimes to be used

compiler/rustc_middle/src/traits/select.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ pub enum EvaluationResult {
176176
EvaluatedToOk,
177177
/// Evaluation successful, but there were unevaluated region obligations.
178178
EvaluatedToOkModuloRegions,
179+
/// Evaluation successful, but need to rerun because opaque types got
180+
/// hidden types assigned without it being known whether the opaque types
181+
/// are within their defining scope
182+
EvaluatedToOkModuloOpaqueTypes,
179183
/// Evaluation is known to be ambiguous -- it *might* hold for some
180184
/// assignment of inference variables, but it might not.
181185
///
@@ -252,9 +256,11 @@ impl EvaluationResult {
252256

253257
pub fn may_apply(self) -> bool {
254258
match self {
255-
EvaluatedToOk | EvaluatedToOkModuloRegions | EvaluatedToAmbig | EvaluatedToUnknown => {
256-
true
257-
}
259+
EvaluatedToOkModuloOpaqueTypes
260+
| EvaluatedToOk
261+
| EvaluatedToOkModuloRegions
262+
| EvaluatedToAmbig
263+
| EvaluatedToUnknown => true,
258264

259265
EvaluatedToErr | EvaluatedToRecur => false,
260266
}
@@ -264,7 +270,11 @@ impl EvaluationResult {
264270
match self {
265271
EvaluatedToUnknown | EvaluatedToRecur => true,
266272

267-
EvaluatedToOk | EvaluatedToOkModuloRegions | EvaluatedToAmbig | EvaluatedToErr => false,
273+
EvaluatedToOkModuloOpaqueTypes
274+
| EvaluatedToOk
275+
| EvaluatedToOkModuloRegions
276+
| EvaluatedToAmbig
277+
| EvaluatedToErr => false,
268278
}
269279
}
270280
}

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
11051105
Lift
11061106
)]
11071107
pub struct OpaqueTypeKey<'tcx> {
1108+
// FIXME(oli-obk): make this a LocalDefId
11081109
pub def_id: DefId,
11091110
pub substs: SubstsRef<'tcx>,
11101111
}

compiler/rustc_resolve/src/late/lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2539,12 +2539,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25392539
/// "Constrained" basically means that it appears in any type but
25402540
/// not amongst the inputs to a projection. In other words, `<&'a
25412541
/// T as Trait<''b>>::Foo` does not constrain `'a` or `'b`.
2542-
fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxHashSet<LocalDefId>> {
2542+
fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<LocalDefId>> {
25432543
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
25442544
let decl = tcx.hir().fn_decl_by_hir_id(hir_id)?;
25452545
let generics = tcx.hir().get_generics(def_id)?;
25462546

2547-
let mut late_bound = FxHashSet::default();
2547+
let mut late_bound = FxIndexSet::default();
25482548

25492549
let mut constrained_by_input = ConstrainedCollector::default();
25502550
for arg_ty in decl.inputs {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
777777
Ok(
778778
EvaluationResult::EvaluatedToOk
779779
| EvaluationResult::EvaluatedToOkModuloRegions
780+
| EvaluationResult::EvaluatedToOkModuloOpaqueTypes
780781
| EvaluationResult::EvaluatedToAmbig,
781782
) => {}
782783
_ => return false,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
394394
Err(_) => return Ok(EvaluatedToErr),
395395
}
396396

397+
if self.infcx.opaque_types_added_in_snapshot(snapshot) {
398+
return Ok(result.max(EvaluatedToOkModuloOpaqueTypes));
399+
}
400+
397401
match self.infcx.region_constraints_added_in_snapshot(snapshot) {
398402
None => Ok(result),
399403
Some(_) => Ok(result.max(EvaluatedToOkModuloRegions)),

compiler/rustc_type_ir/src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,6 @@ bitflags! {
203203
| TypeFlags::HAS_CT_INFER.bits
204204
| TypeFlags::HAS_TY_PLACEHOLDER.bits
205205
| TypeFlags::HAS_CT_PLACEHOLDER.bits
206-
// The `evaluate_obligation` query does not return further
207-
// obligations. If it evaluates an obligation with an opaque
208-
// type, that opaque type may get compared to another type,
209-
// constraining it. We would lose this information.
210-
// FIXME: differentiate between crate-local opaque types
211-
// and opaque types from other crates, as only opaque types
212-
// from the local crate can possibly be a local name
213-
| TypeFlags::HAS_TY_OPAQUE.bits
214206
// We consider 'freshened' types and constants
215207
// to depend on a particular fn.
216208
// The freshening process throws away information,

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
167167
.collect_referenced_late_bound_regions(&poly_trait_ref)
168168
.into_iter()
169169
.filter_map(|br| match br {
170-
ty::BrNamed(_, name) => Some(GenericParamDef {
170+
ty::BrNamed(_, name) if name != kw::UnderscoreLifetime => Some(GenericParamDef {
171171
name,
172172
kind: GenericParamDefKind::Lifetime { outlives: vec![] },
173173
}),
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// revisions: rpass1 rpass2
2+
// edition:2021
3+
4+
// See https://github.com/rust-lang/rust/issues/98890
5+
6+
#![allow(unused)]
7+
8+
struct Foo;
9+
10+
impl Foo {
11+
async fn f(&self, _: &&()) -> &() {
12+
&()
13+
}
14+
}
15+
16+
#[cfg(rpass2)]
17+
enum Bar {}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// When reexporting this function, make sure the anonymous lifetimes are not rendered.
2+
///
3+
/// https://github.com/rust-lang/rust/issues/98697
4+
pub fn repro<F>()
5+
where
6+
F: Fn(&str),
7+
{
8+
unimplemented!()
9+
}

src/test/rustdoc/issue-98697.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-build:issue-98697-reexport-with-anonymous-lifetime.rs
2+
// ignore-cross-compile
3+
4+
// When reexporting a function with a HRTB with anonymous lifetimes,
5+
// make sure the anonymous lifetimes are not rendered.
6+
//
7+
// https://github.com/rust-lang/rust/issues/98697
8+
9+
extern crate issue_98697_reexport_with_anonymous_lifetime;
10+
11+
// @has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'fn repro<F>() where F: Fn(&str)'
12+
// @!has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'for<'
13+
pub use issue_98697_reexport_with_anonymous_lifetime::repro;

src/test/ui/impl-trait/auto-trait-leak.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111
// return type, which can't depend on the obligation.
1212
fn cycle1() -> impl Clone {
1313
//~^ ERROR cycle detected
14-
//~| ERROR cycle detected
1514
send(cycle2().clone());
1615

1716
Rc::new(Cell::new(5))

src/test/ui/impl-trait/auto-trait-leak.stderr

+15-97
Original file line numberDiff line numberDiff line change
@@ -30,129 +30,47 @@ note: ...which requires building MIR for `cycle1`...
3030
LL | fn cycle1() -> impl Clone {
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3232
note: ...which requires type-checking `cycle1`...
33-
--> $DIR/auto-trait-leak.rs:12:1
34-
|
35-
LL | fn cycle1() -> impl Clone {
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
37-
note: ...which requires computing type of `cycle2::{opaque#0}`...
38-
--> $DIR/auto-trait-leak.rs:20:16
39-
|
40-
LL | fn cycle2() -> impl Clone {
41-
| ^^^^^^^^^^
42-
note: ...which requires borrow-checking `cycle2`...
43-
--> $DIR/auto-trait-leak.rs:20:1
44-
|
45-
LL | fn cycle2() -> impl Clone {
46-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
47-
note: ...which requires processing `cycle2`...
48-
--> $DIR/auto-trait-leak.rs:20:1
49-
|
50-
LL | fn cycle2() -> impl Clone {
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
52-
note: ...which requires processing MIR for `cycle2`...
53-
--> $DIR/auto-trait-leak.rs:20:1
54-
|
55-
LL | fn cycle2() -> impl Clone {
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
57-
note: ...which requires unsafety-checking `cycle2`...
58-
--> $DIR/auto-trait-leak.rs:20:1
59-
|
60-
LL | fn cycle2() -> impl Clone {
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
62-
note: ...which requires building MIR for `cycle2`...
63-
--> $DIR/auto-trait-leak.rs:20:1
64-
|
65-
LL | fn cycle2() -> impl Clone {
66-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
67-
note: ...which requires type-checking `cycle2`...
68-
--> $DIR/auto-trait-leak.rs:20:1
69-
|
70-
LL | fn cycle2() -> impl Clone {
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
72-
= note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle
73-
note: cycle used when checking item types in top-level module
74-
--> $DIR/auto-trait-leak.rs:1:1
75-
|
76-
LL | / use std::cell::Cell;
77-
LL | | use std::rc::Rc;
78-
LL | |
79-
LL | | fn send<T: Send>(_: T) {}
80-
... |
81-
LL | | Rc::new(String::from("foo"))
82-
LL | | }
83-
| |_^
84-
85-
error[E0391]: cycle detected when computing type of `cycle1::{opaque#0}`
86-
--> $DIR/auto-trait-leak.rs:12:16
33+
--> $DIR/auto-trait-leak.rs:14:5
8734
|
88-
LL | fn cycle1() -> impl Clone {
89-
| ^^^^^^^^^^
90-
|
91-
note: ...which requires borrow-checking `cycle1`...
92-
--> $DIR/auto-trait-leak.rs:12:1
93-
|
94-
LL | fn cycle1() -> impl Clone {
95-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
96-
note: ...which requires processing `cycle1`...
97-
--> $DIR/auto-trait-leak.rs:12:1
98-
|
99-
LL | fn cycle1() -> impl Clone {
100-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
101-
note: ...which requires processing MIR for `cycle1`...
102-
--> $DIR/auto-trait-leak.rs:12:1
103-
|
104-
LL | fn cycle1() -> impl Clone {
105-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
106-
note: ...which requires unsafety-checking `cycle1`...
107-
--> $DIR/auto-trait-leak.rs:12:1
108-
|
109-
LL | fn cycle1() -> impl Clone {
110-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
111-
note: ...which requires building MIR for `cycle1`...
112-
--> $DIR/auto-trait-leak.rs:12:1
113-
|
114-
LL | fn cycle1() -> impl Clone {
115-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
116-
note: ...which requires type-checking `cycle1`...
117-
--> $DIR/auto-trait-leak.rs:12:1
118-
|
119-
LL | fn cycle1() -> impl Clone {
120-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
35+
LL | send(cycle2().clone());
36+
| ^^^^
37+
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
12138
note: ...which requires computing type of `cycle2::{opaque#0}`...
122-
--> $DIR/auto-trait-leak.rs:20:16
39+
--> $DIR/auto-trait-leak.rs:19:16
12340
|
12441
LL | fn cycle2() -> impl Clone {
12542
| ^^^^^^^^^^
12643
note: ...which requires borrow-checking `cycle2`...
127-
--> $DIR/auto-trait-leak.rs:20:1
44+
--> $DIR/auto-trait-leak.rs:19:1
12845
|
12946
LL | fn cycle2() -> impl Clone {
13047
| ^^^^^^^^^^^^^^^^^^^^^^^^^
13148
note: ...which requires processing `cycle2`...
132-
--> $DIR/auto-trait-leak.rs:20:1
49+
--> $DIR/auto-trait-leak.rs:19:1
13350
|
13451
LL | fn cycle2() -> impl Clone {
13552
| ^^^^^^^^^^^^^^^^^^^^^^^^^
13653
note: ...which requires processing MIR for `cycle2`...
137-
--> $DIR/auto-trait-leak.rs:20:1
54+
--> $DIR/auto-trait-leak.rs:19:1
13855
|
13956
LL | fn cycle2() -> impl Clone {
14057
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14158
note: ...which requires unsafety-checking `cycle2`...
142-
--> $DIR/auto-trait-leak.rs:20:1
59+
--> $DIR/auto-trait-leak.rs:19:1
14360
|
14461
LL | fn cycle2() -> impl Clone {
14562
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14663
note: ...which requires building MIR for `cycle2`...
147-
--> $DIR/auto-trait-leak.rs:20:1
64+
--> $DIR/auto-trait-leak.rs:19:1
14865
|
14966
LL | fn cycle2() -> impl Clone {
15067
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15168
note: ...which requires type-checking `cycle2`...
152-
--> $DIR/auto-trait-leak.rs:20:1
69+
--> $DIR/auto-trait-leak.rs:20:5
15370
|
154-
LL | fn cycle2() -> impl Clone {
155-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
71+
LL | send(cycle1().clone());
72+
| ^^^^
73+
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
15674
= note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle
15775
note: cycle used when checking item types in top-level module
15876
--> $DIR/auto-trait-leak.rs:1:1
@@ -166,6 +84,6 @@ LL | | Rc::new(String::from("foo"))
16684
LL | | }
16785
| |_^
16886

169-
error: aborting due to 2 previous errors
87+
error: aborting due to previous error
17088

17189
For more information about this error, try `rustc --explain E0391`.

src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
mod m {
77
type Foo = impl std::fmt::Debug;
88
//~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391]
9-
//~| ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391]
109

1110
pub fn foo() -> Foo {
1211
22_u32

0 commit comments

Comments
 (0)