Skip to content

Commit fc1a03d

Browse files
committed
Auto merge of #45442 - matthewjasper:const-dynamic-capture-error, r=petrochenkov
Cleanly error for non-const variable in associated const Not sure if wrapping the whole `visit::walk_impl_item` call is correct. Closes #44239
2 parents 942f31f + 02635c2 commit fc1a03d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/librustc_resolve/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,9 @@ impl<'a> Resolver<'a> {
20842084
ValueNS,
20852085
impl_item.span,
20862086
|n, s| ResolutionError::ConstNotMemberOfTrait(n, s));
2087-
visit::walk_impl_item(this, impl_item);
2087+
this.with_constant_rib(|this|
2088+
visit::walk_impl_item(this, impl_item)
2089+
);
20882090
}
20892091
ImplItemKind::Method(ref sig, _) => {
20902092
// If this is a trait impl, ensure the method

src/test/compile-fail/issue-44239.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 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+
fn main() {
12+
let n = 0;
13+
14+
struct Foo;
15+
impl Foo {
16+
const N: usize = n;
17+
//~^ ERROR attempt to use a non-constant value
18+
}
19+
}

0 commit comments

Comments
 (0)