Skip to content

Commit 30b21b7

Browse files
committed
add test
1 parent 0b095a6 commit 30b21b7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
99
use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_session::lint;
1111
use rustc_span::symbol::{kw, Symbol};
12-
use rustc_span::Span;
12+
use rustc_span::{sym, Span};
1313

1414
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
1515
use rustc_hir::*;
@@ -295,7 +295,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
295295
})
296296
}
297297
GenericParamKind::Const { default, .. } => {
298-
if !matches!(allow_defaults, Defaults::Allowed) && default.is_some() {
298+
// `rustc_host` effect params are allowed to have defaults.
299+
if !matches!(allow_defaults, Defaults::Allowed)
300+
&& default.is_some()
301+
&& !tcx.has_attr(param.def_id, sym::rustc_host)
302+
{
299303
tcx.sess.span_err(
300304
param.span,
301305
"defaults for const parameters are only allowed in \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// check-pass
2+
3+
// gate-test-effects
4+
// ^ effects doesn't have a gate so we will trick tidy into thinking this is a gate test
5+
6+
#![feature(const_trait_impl, effects, rustc_attrs)]
7+
8+
// ensure we are passing in the correct host effect in always const contexts.
9+
10+
pub const fn hmm</* T, */ #[rustc_host] const host: bool = true>() -> usize {
11+
if host {
12+
1
13+
} else {
14+
0
15+
}
16+
}
17+
18+
const _: () = {
19+
let x = hmm();
20+
assert!(0 == x);
21+
};
22+
23+
/* FIXME(effects)
24+
pub const fn uwu(x: [u8; hmm::<()>()]) {
25+
let [] = x;
26+
}
27+
*/
28+
29+
fn main() {}

0 commit comments

Comments
 (0)