Skip to content

Commit

Permalink
Rename include_bin! to include_bytes!
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
lambda-fairy committed Dec 23, 2014
1 parent 62fb41c commit 85c1a4b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/doc/reference.md
Expand Up @@ -640,7 +640,7 @@ names, and invoked through a consistent syntax: `name!(...)`. Examples include:
* `stringify!` : pretty-print the Rust expression given as an argument
* `include!` : include the Rust expression in the given file
* `include_str!` : include the contents of the given file as a string
* `include_bin!` : include the contents of the given file as a binary blob
* `include_bytes!` : include the contents of the given file as a binary blob
* `error!`, `warn!`, `info!`, `debug!` : provide diagnostic information.

All of the above extensions are expressions with values.
Expand Down
24 changes: 12 additions & 12 deletions src/librustdoc/html/render.rs
Expand Up @@ -491,26 +491,26 @@ fn write_shared(cx: &Context,
// Add all the static files. These may already exist, but we just
// overwrite them anyway to make sure that they're fresh and up-to-date.
try!(write(cx.dst.join("jquery.js"),
include_bin!("static/jquery-2.1.0.min.js")));
try!(write(cx.dst.join("main.js"), include_bin!("static/main.js")));
try!(write(cx.dst.join("playpen.js"), include_bin!("static/playpen.js")));
try!(write(cx.dst.join("main.css"), include_bin!("static/main.css")));
include_bytes!("static/jquery-2.1.0.min.js")));
try!(write(cx.dst.join("main.js"), include_bytes!("static/main.js")));
try!(write(cx.dst.join("playpen.js"), include_bytes!("static/playpen.js")));
try!(write(cx.dst.join("main.css"), include_bytes!("static/main.css")));
try!(write(cx.dst.join("normalize.css"),
include_bin!("static/normalize.css")));
include_bytes!("static/normalize.css")));
try!(write(cx.dst.join("FiraSans-Regular.woff"),
include_bin!("static/FiraSans-Regular.woff")));
include_bytes!("static/FiraSans-Regular.woff")));
try!(write(cx.dst.join("FiraSans-Medium.woff"),
include_bin!("static/FiraSans-Medium.woff")));
include_bytes!("static/FiraSans-Medium.woff")));
try!(write(cx.dst.join("Heuristica-Italic.woff"),
include_bin!("static/Heuristica-Italic.woff")));
include_bytes!("static/Heuristica-Italic.woff")));
try!(write(cx.dst.join("SourceSerifPro-Regular.woff"),
include_bin!("static/SourceSerifPro-Regular.woff")));
include_bytes!("static/SourceSerifPro-Regular.woff")));
try!(write(cx.dst.join("SourceSerifPro-Bold.woff"),
include_bin!("static/SourceSerifPro-Bold.woff")));
include_bytes!("static/SourceSerifPro-Bold.woff")));
try!(write(cx.dst.join("SourceCodePro-Regular.woff"),
include_bin!("static/SourceCodePro-Regular.woff")));
include_bytes!("static/SourceCodePro-Regular.woff")));
try!(write(cx.dst.join("SourceCodePro-Semibold.woff"),
include_bin!("static/SourceCodePro-Semibold.woff")));
include_bytes!("static/SourceCodePro-Semibold.woff")));

fn collect(path: &Path, krate: &str,
key: &str) -> io::IoResult<Vec<String>> {
Expand Down
8 changes: 6 additions & 2 deletions src/libstd/macros.rs
Expand Up @@ -621,10 +621,14 @@ pub mod builtin {
/// # Example
///
/// ```rust,ignore
/// let secret_key = include_bin!("secret-key.bin");
/// let secret_key = include_bytes!("secret-key.bin");
/// ```
#[macro_export]
macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */ }) }
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }

/// Deprecated alias for `include_bytes!()`.
#[macro_export]
macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */}) }

/// Expands to a string that represents the current module path.
///
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/ext/base.rs
Expand Up @@ -442,6 +442,9 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv {
syntax_expanders.insert(intern("include_bin"),
builtin_normal_expander(
ext::source_util::expand_include_bin));
syntax_expanders.insert(intern("include_bytes"),
builtin_normal_expander(
ext::source_util::expand_include_bytes));
syntax_expanders.insert(intern("module_path"),
builtin_normal_expander(
ext::source_util::expand_mod));
Expand Down
8 changes: 7 additions & 1 deletion src/libsyntax/ext/source_util.rs
Expand Up @@ -163,7 +163,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])

pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") {
cx.span_warn(sp, "include_bin! is deprecated; use include_bytes! instead");
expand_include_bytes(cx, sp, tts)
}

pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
Some(f) => f,
None => return DummyResult::expr(sp)
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-k-nucleotide-pipes.rs
Expand Up @@ -148,7 +148,7 @@ fn main() {
use std::io::{stdio, MemReader, BufferedReader};

let rdr = if os::getenv("RUST_BENCH").is_some() {
let foo = include_bin!("shootout-k-nucleotide.data");
let foo = include_bytes!("shootout-k-nucleotide.data");
box MemReader::new(foo.to_vec()) as Box<Reader>
} else {
box stdio::stdin() as Box<Reader>
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/macros-nonfatal-errors.rs
Expand Up @@ -43,8 +43,8 @@ fn main() {

include_str!(invalid); //~ ERROR
include_str!("i'd be quite surprised if a file with this name existed"); //~ ERROR
include_bin!(invalid); //~ ERROR
include_bin!("i'd be quite surprised if a file with this name existed"); //~ ERROR
include_bytes!(invalid); //~ ERROR
include_bytes!("i'd be quite surprised if a file with this name existed"); //~ ERROR

trace_macros!(invalid); //~ ERROR
}
2 changes: 1 addition & 1 deletion src/test/run-make/symbols-are-reasonable/lib.rs
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

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

trait Foo {}
impl Foo for uint {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/syntax-extension-source-utils.rs
Expand Up @@ -39,7 +39,7 @@ pub fn main() {
.as_slice()
.starts_with("/* this is for "));
assert!(
include_bin!("syntax-extension-source-utils-files/includeme.fragment")
include_bytes!("syntax-extension-source-utils-files/includeme.fragment")
[1] == (42 as u8)); // '*'
// The Windows tests are wrapped in an extra module for some reason
assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2")));
Expand Down

7 comments on commit 85c1a4b

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lfairy/rust/rename-include-bin = 85c1a4b into auto

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "7e11b22713aebd28ceaaa2ecef937c9b9d247c2f"}

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lfairy/rust/rename-include-bin = 85c1a4b merged ok, testing candidate = 7e11b22

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 7e11b22

@bors
Copy link
Contributor

@bors bors commented on 85c1a4b Dec 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 7e11b22

Please sign in to comment.