Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert \r\n -> \n in include_str! macro #63681

wants to merge 1 commit into from
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -978,7 +978,9 @@ pub(crate) mod builtin {
/// modules are found)
/// This macro will yield an expression of type `&'static str` which is the
/// contents of the file.
/// contents of the file. The string is normalized:
/// * Byte Order Mark (BOM), if any, is removed,
/// * DOS line endings (`\r\n`) are converted to `\n`.
/// # Examples
@@ -112,16 +112,12 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::To
None => return DummyResult::any(sp)
let file = cx.resolve_path(file, sp);
match cx.source_map().load_binary_file(&file) {
Ok(bytes) => match std::str::from_utf8(&bytes) {
Ok(src) => {
let interned_src = Symbol::intern(&src);
base::MacEager::expr(cx.expr_str(sp, interned_src))
Err(_) => {
cx.span_err(sp, &format!("{} wasn't a utf-8 file", file.display()));
match cx.source_map().load_file(&file) {
Ok(source_file) => {
let src = source_file.src.as_ref()
.expect("freshly loaded file should have a source");
let interned_src = Symbol::intern(src.as_str());
base::MacEager::expr(cx.expr_str(sp, interned_src))
Err(e) => {
cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e));
@@ -7,6 +7,6 @@ fn main() {
"\u{FEFF}This file starts with BOM.\r\nLines are separated by \\r\\n.\r\n",
"This file starts with BOM.\nLines are separated by \\r\\n.\n",

This comment has been minimized.

Copy link

lzutao Aug 18, 2019


"Lines are separated by \\n."

This comment has been minimized.

Copy link

matklad Aug 18, 2019

Author Member

Nope, it should be \\r\\n, escaped \r is not changed in any way.

@@ -36,6 +36,7 @@ literal";
assert_eq!(s, "byte string\nliteral".as_bytes());

// validate that our source file has CRLF endings
let source = include_str!("");
let source = include_bytes!("");
let source = std::str::from_utf8(&source[..]).unwrap();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.