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
This commit is contained in:
parent
43c5fef47d
commit
24117f3c58
3 changed files with 57 additions and 12 deletions
46
src/test/rustdoc/issue-33302.rs
Normal file
46
src/test/rustdoc/issue-33302.rs
Normal file
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue