Skip to content

Commit b85aefb

Browse files
committed
Auto merge of #47495 - nikomatsakis:nll-issue-47153, r=pnkfelix
remove bogus assertion and comments The code (incorrectly) assumed that constants could not have generics in scope, but it's not really a problem if they do. Fixes #47153 r? @pnkfelix
2 parents 15a1e28 + 3b390e5 commit b85aefb

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/librustc_mir/borrow_check/nll/universal_regions.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,9 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
584584

585585
DefiningTy::FnDef(_, substs) => substs,
586586

587-
// When we encounter other sorts of constant
588-
// expressions, such as the `22` in `[foo; 22]`, we can
589-
// get the type `usize` here. For now, just return an
590-
// empty vector of substs in this case, since there are no
591-
// generics in scope in such expressions right now.
587+
// When we encounter a constant body, just return whatever
588+
// substitutions are in scope for that constant.
592589
DefiningTy::Const(_) => {
593-
assert!(identity_substs.is_empty());
594590
identity_substs
595591
}
596592
};
@@ -654,9 +650,8 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
654650
sig.inputs_and_output()
655651
}
656652

657-
// This happens on things like `[foo; 22]`. Hence, no
658-
// inputs, one output, but it seems like we need a more
659-
// general way to handle this category of MIR.
653+
// For a constant body, there are no inputs, and one
654+
// "output" (the type of the constant).
660655
DefiningTy::Const(ty) => ty::Binder::dummy(tcx.mk_type_list(iter::once(ty))),
661656
}
662657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
11+
// Regression test for #47153: constants in a generic context (such as
12+
// a trait) used to ICE.
13+
14+
#![feature(nll)]
15+
#![allow(warnings)]
16+
17+
trait Foo {
18+
const B: bool = true;
19+
}
20+
21+
struct Bar<T> { x: T }
22+
23+
impl<T> Bar<T> {
24+
const B: bool = true;
25+
}
26+
27+
fn main() { }

0 commit comments

Comments
 (0)