diff options
| author | Georg Brandl <georg@python.org> | 2016-05-03 13:09:42 +0200 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2016-05-03 13:09:42 +0200 |
| commit | 24117f3c589dca680bdfe7e193e52e210770dc79 (patch) | |
| tree | d2e04a92095b4bc4b87fd9aa45dd03368644ecde /src/test/rustdoc | |
| parent | 43c5fef47dcaebea4c77771cc6f187b2a72b3639 (diff) | |
| download | rust-24117f3c589dca680bdfe7e193e52e210770dc79.tar.gz rust-24117f3c589dca680bdfe7e193e52e210770dc79.zip | |
rustdoc: fix inserting source code spans for constant values
This will go wrong when the constants partially result from macro expansion. Instead, use the expressions and pretty-print them as Rust code. Fixes: #33302
Diffstat (limited to 'src/test/rustdoc')
| -rw-r--r-- | src/test/rustdoc/issue-33302.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/rustdoc/issue-33302.rs b/src/test/rustdoc/issue-33302.rs new file mode 100644 index 00000000000..b9188e8a4e9 --- /dev/null +++ b/src/test/rustdoc/issue-33302.rs @@ -0,0 +1,46 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Ensure constant and array length values are not taken from source +// code, which wreaks havoc with macros. + +#![feature(associated_consts)] + +macro_rules! make { + ($n:expr) => { + pub struct S; + + // @has issue_33302/constant.CST.html \ + // '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4' + pub const CST: i32 = ($n * $n); + // @has issue_33302/static.ST.html \ + // '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4' + pub static ST: i32 = ($n * $n); + + pub trait T<X> { + fn ignore(_: &X) {} + const C: X; + // @has issue_33302/trait.T.html \ + // '//*[@class="rust trait"]' 'const D: i32 = 4 * 4;' + // @has - '//*[@id="associatedconstant.D"]' 'const D: i32 = 4 * 4' + const D: i32 = ($n * $n); + } + + // @has issue_33302/struct.S.html \ + // '//h3[@class="impl"]' 'impl T<[i32; 4 * 4]> for S' + // @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 4 * 4] = [0; 4 * 4]' + // @has - '//*[@id="associatedconstant.D"]' 'const D: i32 = 4 * 4' + impl T<[i32; ($n * $n)]> for S { + const C: [i32; ($n * $n)] = [0; ($n * $n)]; + } + } +} + +make!(4); |
