Skip to content

Commit 7e11b22

Browse files
committed
auto merge of rust-lang#20117 : lfairy/rust/rename-include-bin, r=alexcrichton
According to [RFC 344][], methods that return `&[u8]` should have names ending in `bytes`. Though `include_bin!` is a macro not a method, it seems reasonable to follow the convention anyway. We keep the old name around for now, but trigger a deprecation warning when it is used. [RFC 344]: https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md [breaking-change]
2 parents 14597f9 + 85c1a4b commit 7e11b22

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ names, and invoked through a consistent syntax: `name!(...)`. Examples include:
640640
* `stringify!` : pretty-print the Rust expression given as an argument
641641
* `include!` : include the Rust expression in the given file
642642
* `include_str!` : include the contents of the given file as a string
643-
* `include_bin!` : include the contents of the given file as a binary blob
643+
* `include_bytes!` : include the contents of the given file as a binary blob
644644
* `error!`, `warn!`, `info!`, `debug!` : provide diagnostic information.
645645

646646
All of the above extensions are expressions with values.

src/librustdoc/html/render.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,26 +491,26 @@ fn write_shared(cx: &Context,
491491
// Add all the static files. These may already exist, but we just
492492
// overwrite them anyway to make sure that they're fresh and up-to-date.
493493
try!(write(cx.dst.join("jquery.js"),
494-
include_bin!("static/jquery-2.1.0.min.js")));
495-
try!(write(cx.dst.join("main.js"), include_bin!("static/main.js")));
496-
try!(write(cx.dst.join("playpen.js"), include_bin!("static/playpen.js")));
497-
try!(write(cx.dst.join("main.css"), include_bin!("static/main.css")));
494+
include_bytes!("static/jquery-2.1.0.min.js")));
495+
try!(write(cx.dst.join("main.js"), include_bytes!("static/main.js")));
496+
try!(write(cx.dst.join("playpen.js"), include_bytes!("static/playpen.js")));
497+
try!(write(cx.dst.join("main.css"), include_bytes!("static/main.css")));
498498
try!(write(cx.dst.join("normalize.css"),
499-
include_bin!("static/normalize.css")));
499+
include_bytes!("static/normalize.css")));
500500
try!(write(cx.dst.join("FiraSans-Regular.woff"),
501-
include_bin!("static/FiraSans-Regular.woff")));
501+
include_bytes!("static/FiraSans-Regular.woff")));
502502
try!(write(cx.dst.join("FiraSans-Medium.woff"),
503-
include_bin!("static/FiraSans-Medium.woff")));
503+
include_bytes!("static/FiraSans-Medium.woff")));
504504
try!(write(cx.dst.join("Heuristica-Italic.woff"),
505-
include_bin!("static/Heuristica-Italic.woff")));
505+
include_bytes!("static/Heuristica-Italic.woff")));
506506
try!(write(cx.dst.join("SourceSerifPro-Regular.woff"),
507-
include_bin!("static/SourceSerifPro-Regular.woff")));
507+
include_bytes!("static/SourceSerifPro-Regular.woff")));
508508
try!(write(cx.dst.join("SourceSerifPro-Bold.woff"),
509-
include_bin!("static/SourceSerifPro-Bold.woff")));
509+
include_bytes!("static/SourceSerifPro-Bold.woff")));
510510
try!(write(cx.dst.join("SourceCodePro-Regular.woff"),
511-
include_bin!("static/SourceCodePro-Regular.woff")));
511+
include_bytes!("static/SourceCodePro-Regular.woff")));
512512
try!(write(cx.dst.join("SourceCodePro-Semibold.woff"),
513-
include_bin!("static/SourceCodePro-Semibold.woff")));
513+
include_bytes!("static/SourceCodePro-Semibold.woff")));
514514

515515
fn collect(path: &Path, krate: &str,
516516
key: &str) -> io::IoResult<Vec<String>> {

src/libstd/macros.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,14 @@ pub mod builtin {
621621
/// # Example
622622
///
623623
/// ```rust,ignore
624-
/// let secret_key = include_bin!("secret-key.bin");
624+
/// let secret_key = include_bytes!("secret-key.bin");
625625
/// ```
626626
#[macro_export]
627-
macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */ }) }
627+
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
628+
629+
/// Deprecated alias for `include_bytes!()`.
630+
#[macro_export]
631+
macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */}) }
628632

629633
/// Expands to a string that represents the current module path.
630634
///

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
442442
syntax_expanders.insert(intern("include_bin"),
443443
builtin_normal_expander(
444444
ext::source_util::expand_include_bin));
445+
syntax_expanders.insert(intern("include_bytes"),
446+
builtin_normal_expander(
447+
ext::source_util::expand_include_bytes));
445448
syntax_expanders.insert(intern("module_path"),
446449
builtin_normal_expander(
447450
ext::source_util::expand_mod));

src/libsyntax/ext/source_util.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
163163

164164
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
165165
-> Box<base::MacResult+'static> {
166-
let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") {
166+
cx.span_warn(sp, "include_bin! is deprecated; use include_bytes! instead");
167+
expand_include_bytes(cx, sp, tts)
168+
}
169+
170+
pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
171+
-> Box<base::MacResult+'static> {
172+
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
167173
Some(f) => f,
168174
None => return DummyResult::expr(sp)
169175
};

src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn main() {
148148
use std::io::{stdio, MemReader, BufferedReader};
149149

150150
let rdr = if os::getenv("RUST_BENCH").is_some() {
151-
let foo = include_bin!("shootout-k-nucleotide.data");
151+
let foo = include_bytes!("shootout-k-nucleotide.data");
152152
box MemReader::new(foo.to_vec()) as Box<Reader>
153153
} else {
154154
box stdio::stdin() as Box<Reader>

src/test/compile-fail/macros-nonfatal-errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ fn main() {
4343

4444
include_str!(invalid); //~ ERROR
4545
include_str!("i'd be quite surprised if a file with this name existed"); //~ ERROR
46-
include_bin!(invalid); //~ ERROR
47-
include_bin!("i'd be quite surprised if a file with this name existed"); //~ ERROR
46+
include_bytes!(invalid); //~ ERROR
47+
include_bytes!("i'd be quite surprised if a file with this name existed"); //~ ERROR
4848

4949
trace_macros!(invalid); //~ ERROR
5050
}

src/test/run-make/symbols-are-reasonable/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub static X: &'static str = "foobarbaz";
12-
pub static Y: &'static [u8] = include_bin!("lib.rs");
12+
pub static Y: &'static [u8] = include_bytes!("lib.rs");
1313

1414
trait Foo {}
1515
impl Foo for uint {}

src/test/run-pass/syntax-extension-source-utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn main() {
3939
.as_slice()
4040
.starts_with("/* this is for "));
4141
assert!(
42-
include_bin!("syntax-extension-source-utils-files/includeme.fragment")
42+
include_bytes!("syntax-extension-source-utils-files/includeme.fragment")
4343
[1] == (42 as u8)); // '*'
4444
// The Windows tests are wrapped in an extra module for some reason
4545
assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2")));

0 commit comments

Comments
 (0)