Skip to content

Commit 6d46b1e

Browse files
committedJan 18, 2023
Auto merge of #106503 - cjgillot:remap-nofilter, r=oli-obk
Do not filter substs in `remap_generic_params_to_declaration_params`. The relevant filtering should have been performed by borrowck. Fixes #105826 r? types
2 parents 1f72129 + b7bb8a5 commit 6d46b1e

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed
 

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
252252
}
253253

254254
let definition_ty = instantiated_ty
255-
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false, origin)
255+
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false)
256256
.ty;
257257

258258
if !check_opaque_type_parameter_valid(

‎compiler/rustc_hir_typeck/src/writeback.rs

-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
564564
opaque_type_key,
565565
self.fcx.infcx.tcx,
566566
true,
567-
decl.origin,
568567
);
569568

570569
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);

‎compiler/rustc_middle/src/ty/mod.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use crate::ty::util::Discr;
2828
pub use adt::*;
2929
pub use assoc::*;
3030
pub use generics::*;
31-
use hir::OpaqueTyOrigin;
3231
use rustc_ast as ast;
3332
use rustc_ast::node_id::NodeMap;
3433
use rustc_attr as attr;
@@ -1345,7 +1344,6 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
13451344
tcx: TyCtxt<'tcx>,
13461345
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
13471346
ignore_errors: bool,
1348-
origin: OpaqueTyOrigin,
13491347
) -> Self {
13501348
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
13511349

@@ -1361,30 +1359,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
13611359
// This zip may have several times the same lifetime in `substs` paired with a different
13621360
// lifetime from `id_substs`. Simply `collect`ing the iterator is the correct behaviour:
13631361
// it will pick the last one, which is the one we introduced in the impl-trait desugaring.
1364-
let map = substs.iter().zip(id_substs);
1365-
1366-
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> = match origin {
1367-
// HACK: The HIR lowering for async fn does not generate
1368-
// any `+ Captures<'x>` bounds for the `impl Future<...>`, so all async fns with lifetimes
1369-
// would now fail to compile. We should probably just make hir lowering fill this in properly.
1370-
OpaqueTyOrigin::AsyncFn(_) => map.collect(),
1371-
OpaqueTyOrigin::FnReturn(_) | OpaqueTyOrigin::TyAlias => {
1372-
// Opaque types may only use regions that are bound. So for
1373-
// ```rust
1374-
// type Foo<'a, 'b, 'c> = impl Trait<'a> + 'b;
1375-
// ```
1376-
// we may not use `'c` in the hidden type.
1377-
let variances = tcx.variances_of(def_id);
1378-
debug!(?variances);
1379-
1380-
map.filter(|(_, v)| {
1381-
let ty::GenericArgKind::Lifetime(lt) = v.unpack() else { return true };
1382-
let ty::ReEarlyBound(ebr) = lt.kind() else { bug!() };
1383-
variances[ebr.index as usize] == ty::Variance::Invariant
1384-
})
1385-
.collect()
1386-
}
1387-
};
1362+
let map = substs.iter().zip(id_substs).collect();
13881363
debug!("map = {:#?}", map);
13891364

13901365
// Convert the type from the function into a type valid outside
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// check-pass
2+
3+
use std::io::Write;
4+
5+
struct A(Vec<u8>);
6+
7+
struct B<'a> {
8+
one: &'a mut A,
9+
two: &'a mut Vec<u8>,
10+
three: Vec<u8>,
11+
}
12+
13+
impl<'a> B<'a> {
14+
fn one(&mut self) -> &mut impl Write {
15+
&mut self.one.0
16+
}
17+
fn two(&mut self) -> &mut impl Write {
18+
&mut *self.two
19+
}
20+
fn three(&mut self) -> &mut impl Write {
21+
&mut self.three
22+
}
23+
}
24+
25+
struct C<'a>(B<'a>);
26+
27+
impl<'a> C<'a> {
28+
fn one(&mut self) -> &mut impl Write {
29+
self.0.one()
30+
}
31+
fn two(&mut self) -> &mut impl Write {
32+
self.0.two()
33+
}
34+
fn three(&mut self) -> &mut impl Write {
35+
self.0.three()
36+
}
37+
}
38+
39+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.