Skip to content

Commit 3b6b1ab

Browse files
authored
Rollup merge of rust-lang#89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts Fixes rust-lang#78132 Fixes rust-lang#78174 Fixes rust-lang#81857 Fixes rust-lang#89964 Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure. Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts. The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure. With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME. Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck). cc `````@spastorino````` `````@lcnr````` r? `````@nikomatsakis````` `````@rustbot````` label A-inference F-inline_const T-compiler
2 parents 36d5475 + 0cb9ac2 commit 3b6b1ab

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clippy_lints/src/matches.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,10 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
10651065
PatKind::Path(path) => {
10661066
#[allow(clippy::match_same_arms)]
10671067
let id = match cx.qpath_res(path, pat.hir_id) {
1068-
Res::Def(DefKind::Const | DefKind::ConstParam | DefKind::AnonConst, _) => return,
1068+
Res::Def(
1069+
DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
1070+
_,
1071+
) => return,
10691072
Res::Def(_, id) => id,
10701073
_ => return,
10711074
};

0 commit comments

Comments
 (0)