Skip to content

Commit b7bb8a5

Browse files
committedJan 11, 2023
Do not filter substs in remap_generic_params_to_declaration_params.
The relevant filtering should have been performed by borrowck.
1 parent b22c152 commit b7bb8a5

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
@@ -250,7 +250,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
250250
}
251251

252252
let definition_ty = instantiated_ty
253-
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false, origin)
253+
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false)
254254
.ty;
255255

256256
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;
@@ -1316,7 +1315,6 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
13161315
tcx: TyCtxt<'tcx>,
13171316
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
13181317
ignore_errors: bool,
1319-
origin: OpaqueTyOrigin,
13201318
) -> Self {
13211319
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
13221320

@@ -1332,30 +1330,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
13321330
// This zip may have several times the same lifetime in `substs` paired with a different
13331331
// lifetime from `id_substs`. Simply `collect`ing the iterator is the correct behaviour:
13341332
// it will pick the last one, which is the one we introduced in the impl-trait desugaring.
1335-
let map = substs.iter().zip(id_substs);
1336-
1337-
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> = match origin {
1338-
// HACK: The HIR lowering for async fn does not generate
1339-
// any `+ Captures<'x>` bounds for the `impl Future<...>`, so all async fns with lifetimes
1340-
// would now fail to compile. We should probably just make hir lowering fill this in properly.
1341-
OpaqueTyOrigin::AsyncFn(_) => map.collect(),
1342-
OpaqueTyOrigin::FnReturn(_) | OpaqueTyOrigin::TyAlias => {
1343-
// Opaque types may only use regions that are bound. So for
1344-
// ```rust
1345-
// type Foo<'a, 'b, 'c> = impl Trait<'a> + 'b;
1346-
// ```
1347-
// we may not use `'c` in the hidden type.
1348-
let variances = tcx.variances_of(def_id);
1349-
debug!(?variances);
1350-
1351-
map.filter(|(_, v)| {
1352-
let ty::GenericArgKind::Lifetime(lt) = v.unpack() else { return true };
1353-
let ty::ReEarlyBound(ebr) = lt.kind() else { bug!() };
1354-
variances[ebr.index as usize] == ty::Variance::Invariant
1355-
})
1356-
.collect()
1357-
}
1358-
};
1333+
let map = substs.iter().zip(id_substs).collect();
13591334
debug!("map = {:#?}", map);
13601335

13611336
// 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.