-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #33371 - birkenfeld:issue-33302, r=cmr
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
- Loading branch information
Showing
3 changed files
with
57 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |