Skip to content

Commit d3218fa

Browse files
committed
Check the constants’ parameter environment
1 parent 5af829b commit d3218fa

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/librustc_typeck/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,8 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
11511151
sp: Span,
11521152
e: &'tcx hir::Expr,
11531153
id: ast::NodeId) {
1154-
ccx.inherited(None).enter(|inh| {
1154+
let param_env = ParameterEnvironment::for_item(ccx.tcx, id);
1155+
ccx.inherited(Some(param_env)).enter(|inh| {
11551156
let rty = ccx.tcx.node_id_to_type(id);
11561157
let fcx = FnCtxt::new(&inh, ty::FnConverging(rty), e.id);
11571158
let declty = fcx.tcx.lookup_item_type(ccx.tcx.map.local_def_id(id)).ty;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(associated_consts)]
11+
12+
trait Lattice {
13+
const BOTTOM: Self;
14+
}
15+
16+
// FIXME(#33573): this should work without the 'static lifetime bound.
17+
impl<T: 'static> Lattice for Option<T> {
18+
const BOTTOM: Option<T> = None;
19+
}
20+
21+
fn main(){}

0 commit comments

Comments
 (0)