Skip to content

Commit a319331

Browse files
committed
Don't require has_self when adding constness
This can help with typeck and fixes ui tests.
1 parent d4551d2 commit a319331

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

compiler/rustc_typeck/src/astconv/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
390390
}
391391
}
392392
}
393-
if !has_constness && has_self && let Some(constness) = constness {
393+
if !has_constness && let Some(constness) = constness {
394394
if let ty::ConstnessArg::Const = constness {
395395
substs.push(constness.into());
396396
}

compiler/rustc_typeck/src/check/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub(super) fn check_fn<'a, 'tcx>(
8484
can_be_generator: Option<hir::Movability>,
8585
return_type_pre_known: bool,
8686
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
87+
debug!(?body.value.hir_id);
8788
// Create the function context. This is either derived from scratch or,
8889
// in the case of closures, based on the outer context.
8990
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
845845
expect_args
846846
}
847847

848+
#[tracing::instrument(level = "debug", skip(self))]
848849
pub(in super::super) fn resolve_lang_item_path(
849850
&self,
850851
lang_item: hir::LangItem,

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
147147
return_type_pre_known: true,
148148
return_type_has_opaque: false,
149149
constness: {
150-
if body_id.is_owner() {
151-
let did = body_id.expect_owner();
152-
if inh.tcx.is_const_fn_raw(did.to_def_id()) || inh.tcx.is_const_default_method(did.to_def_id()) || inh.tcx.def_kind(did.to_def_id()) == hir::def::DefKind::Const {
150+
fn get_constness(tcx: TyCtxt<'_>, did: DefId) -> ty::ConstnessArg {
151+
if tcx.is_const_fn_raw(did) || tcx.is_const_default_method(did) || tcx.def_kind(did) == hir::def::DefKind::Const {
152+
trace!("const");
153153
ty::ConstnessArg::Const
154154
} else {
155+
trace!("not const");
156+
ty::ConstnessArg::Not
157+
}
158+
}
159+
if body_id.is_owner() {
160+
let did = body_id.expect_owner();
161+
get_constness(inh.tcx, did.to_def_id())
162+
} else if let Some(hir::Node::Expr(hir::Expr { kind, .. })) = inh.tcx.hir().find(body_id) {
163+
if let hir::ExprKind::Closure { .. } = kind {
155164
ty::ConstnessArg::Not
165+
} else {
166+
get_constness(inh.tcx, body_id.owner.to_def_id())
156167
}
157168
} else {
158-
// TODO: check correctness
159169
ty::ConstnessArg::Not
160170
}
161171
},

0 commit comments

Comments
 (0)