Skip to content

Commit 6b00227

Browse files
authored
Rollup merge of #91888 - BoxyUwU:generic_arg_infer_aaaa, r=lcnr
Handle unordered const/ty generics for object lifetime defaults *feel like I should have a PR description but cant think of what to put here* r? ```@lcnr```
2 parents e6c495d + 0a0f014 commit 6b00227

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
5252
use rustc_hir::def_id::{DefId, DefPathHash, LocalDefId, CRATE_DEF_ID};
5353
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
5454
use rustc_hir::intravisit;
55-
use rustc_hir::{ConstArg, GenericArg, InferKind, ParamName};
55+
use rustc_hir::{ConstArg, GenericArg, ParamName};
5656
use rustc_index::vec::{Idx, IndexVec};
5757
use rustc_query_system::ich::StableHashingContext;
5858
use rustc_session::lint::builtin::BARE_TRAIT_OBJECTS;
@@ -1113,7 +1113,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11131113
return GenericArg::Infer(hir::InferArg {
11141114
hir_id: self.lower_node_id(ty.id),
11151115
span: self.lower_span(ty.span),
1116-
kind: InferKind::Type,
11171116
});
11181117
}
11191118
// We parse const arguments as path types as we cannot distinguish them during

Diff for: compiler/rustc_hir/src/hir.rs

-14
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,9 @@ pub struct ConstArg {
255255
pub span: Span,
256256
}
257257

258-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
259-
pub enum InferKind {
260-
Const,
261-
Type,
262-
}
263-
264-
impl InferKind {
265-
#[inline]
266-
pub fn is_type(self) -> bool {
267-
matches!(self, InferKind::Type)
268-
}
269-
}
270-
271258
#[derive(Encodable, Debug, HashStable_Generic)]
272259
pub struct InferArg {
273260
pub hir_id: HirId,
274-
pub kind: InferKind,
275261
pub span: Span,
276262
}
277263

Diff for: compiler/rustc_resolve/src/late/lifetimes.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2541,8 +2541,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25412541
GenericParamDefKind::Type { object_lifetime_default, .. } => {
25422542
Some(object_lifetime_default)
25432543
}
2544-
GenericParamDefKind::Lifetime
2545-
| GenericParamDefKind::Const { .. } => None,
2544+
GenericParamDefKind::Const { .. } => Some(Set1::Empty),
2545+
GenericParamDefKind::Lifetime => None,
25462546
})
25472547
.collect()
25482548
})
@@ -2569,12 +2569,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25692569
}
25702570
GenericArg::Const(ct) => {
25712571
self.visit_anon_const(&ct.value);
2572+
i += 1;
25722573
}
25732574
GenericArg::Infer(inf) => {
25742575
self.visit_id(inf.hir_id);
2575-
if inf.kind.is_type() {
2576-
i += 1;
2577-
}
2576+
i += 1;
25782577
}
25792578
}
25802579
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub struct Foo<'a, const N: usize, T: 'a + ?Sized>(pub &'a T, [(); N]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// aux-build:trait_object_lt_defaults_lib.rs
2+
// run-pass
3+
#![allow(dead_code)]
4+
extern crate trait_object_lt_defaults_lib;
5+
6+
// Tests that `A<'a, 3, dyn Test>` is short for `A<'a, 3, dyn Test + 'a>`
7+
// and `Foo<'a, 3, dyn Test>` is short for `Foo<'a, 3, dyn Test + 'a>`
8+
// Test is in `const-generics/defaults` because it relies on param ordering
9+
10+
trait Test {}
11+
12+
struct A<'a, const N: usize, T: ?Sized + 'a>(&'a T, [(); N]);
13+
fn blah<'a>(mut a: A<'a, 3, dyn Test>, arg: &'a (dyn Test + 'a)) {
14+
a.0 = arg;
15+
}
16+
17+
fn other_blah<'a>(
18+
mut a: trait_object_lt_defaults_lib::Foo<'a, 3, dyn Test>,
19+
arg: &'a (dyn Test + 'a),
20+
) {
21+
a.0 = arg;
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)