Auto merge of #24524 - Manishearth:rollup, r=Manishearth
This commit is contained in:
commit
3b2530c748
@ -89,7 +89,7 @@ we hadn’t changed the source file, and so it just ran the binary. If we had
|
||||
made a modification, we would have seen it do both:
|
||||
|
||||
```bash
|
||||
$ cargo build
|
||||
$ cargo run
|
||||
Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world)
|
||||
Running `target/debug/hello_world`
|
||||
Hello, world!
|
||||
|
@ -1,13 +1,18 @@
|
||||
% Vectors
|
||||
|
||||
A *vector* is a dynamic or "growable" array, implemented as the standard
|
||||
library type [`Vec<T>`](../std/vec/) (Where `<T>` is a [Generic](./generics.md) statement). Vectors always allocate their data on the heap. Vectors are to slices
|
||||
what `String` is to `&str`. You can create them with the `vec!` macro:
|
||||
library type [`Vec<T>`](../std/vec/) (Where `<T>` is a [Generic](./generics.md)
|
||||
statement). Vectors always allocate their data on the heap. Vectors are to
|
||||
[slices][slices] what [`String`][string] is to `&str`. You can
|
||||
create them with the `vec!` macro:
|
||||
|
||||
```{rust}
|
||||
let v = vec![1, 2, 3]; // v: Vec<i32>
|
||||
```
|
||||
|
||||
[slices]: primitive-types.html#slices
|
||||
[string]: strings.html
|
||||
|
||||
(Notice that unlike the `println!` macro we've used in the past, we use square
|
||||
brackets `[]` with `vec!`. Rust allows you to use either in either situation,
|
||||
this is just convention.)
|
||||
|
@ -969,7 +969,7 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for RangeFull {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt("..", fmt)
|
||||
write!(fmt, "..")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,6 +606,8 @@ fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
|
||||
"Force overflow checks on or off"),
|
||||
force_dropflag_checks: Option<bool> = (None, parse_opt_bool,
|
||||
"Force drop flag checks on or off"),
|
||||
trace_macros: bool = (false, parse_bool,
|
||||
"For every macro invocation, print its name and arguments"),
|
||||
}
|
||||
|
||||
pub fn default_lib_output() -> CrateType {
|
||||
@ -667,7 +669,7 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
sp.handler().fatal(&format!("Error loading target specification: {}", e));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
||||
|
@ -483,6 +483,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||
crate_name: crate_name.to_string(),
|
||||
features: Some(&features),
|
||||
recursion_limit: sess.recursion_limit.get(),
|
||||
trace_mac: sess.opts.debugging_opts.trace_macros,
|
||||
};
|
||||
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
|
||||
cfg,
|
||||
|
@ -1178,7 +1178,6 @@ fn item<F>(&mut self, item: clean::Item, mut f: F) -> io::Result<()> where
|
||||
{
|
||||
fn render(w: File, cx: &Context, it: &clean::Item,
|
||||
pushname: bool) -> io::Result<()> {
|
||||
info!("Rendering an item to {}", w.path().unwrap().display());
|
||||
// A little unfortunate that this is done like this, but it sure
|
||||
// does make formatting *a lot* nicer.
|
||||
CURRENT_LOCATION_KEY.with(|slot| {
|
||||
|
@ -32,7 +32,6 @@
|
||||
#![feature(test)]
|
||||
#![feature(unicode)]
|
||||
#![feature(str_words)]
|
||||
#![feature(file_path)]
|
||||
#![feature(path_ext)]
|
||||
#![feature(path_relative_from)]
|
||||
#![feature(slice_patterns)]
|
||||
|
@ -51,7 +51,6 @@
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct File {
|
||||
inner: fs_imp::File,
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Metadata information about a file.
|
||||
@ -193,12 +192,12 @@ pub fn create<P: AsRef<Path>>(path: P) -> io::Result<File> {
|
||||
OpenOptions::new().write(true).create(true).truncate(true).open(path)
|
||||
}
|
||||
|
||||
/// Returns the original path that was used to open this file.
|
||||
/// Returns `None`.
|
||||
#[unstable(feature = "file_path",
|
||||
reason = "this abstraction is imposed by this library instead \
|
||||
of the underlying OS and may be removed")]
|
||||
reason = "this abstraction was imposed by this library and was removed")]
|
||||
#[deprecated(since = "1.0.0", reason = "abstraction was removed")]
|
||||
pub fn path(&self) -> Option<&Path> {
|
||||
self.path.as_ref().map(|p| &**p)
|
||||
None
|
||||
}
|
||||
|
||||
/// Attempts to sync all OS-internal metadata to disk.
|
||||
@ -302,7 +301,7 @@ fn as_inner(&self) -> &fs_imp::File { &self.inner }
|
||||
}
|
||||
impl FromInner<fs_imp::File> for File {
|
||||
fn from_inner(f: fs_imp::File) -> File {
|
||||
File { inner: f, path: None }
|
||||
File { inner: f }
|
||||
}
|
||||
}
|
||||
|
||||
@ -470,7 +469,7 @@ pub fn create(&mut self, create: bool) -> &mut OpenOptions {
|
||||
pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> {
|
||||
let path = path.as_ref();
|
||||
let inner = try!(fs_imp::File::open(path, &self.0));
|
||||
Ok(File { path: Some(path.to_path_buf()), inner: inner })
|
||||
Ok(File { inner: inner })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,17 +13,14 @@
|
||||
pub use self::ColorConfig::*;
|
||||
use self::Destination::*;
|
||||
|
||||
use codemap::{COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
|
||||
use codemap;
|
||||
use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
|
||||
use diagnostics;
|
||||
|
||||
use std::cell::{RefCell, Cell};
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::{cmp, error, fmt};
|
||||
use std::io::prelude::*;
|
||||
use std::io;
|
||||
use term::WriterWrapper;
|
||||
use term;
|
||||
use term::{self, WriterWrapper};
|
||||
use libc;
|
||||
|
||||
/// maximum number of lines we will print for each error; arbitrary.
|
||||
@ -83,15 +80,39 @@ fn custom_emit(&mut self, cm: &codemap::CodeMap,
|
||||
/// Used as a return value to signify a fatal error occurred. (It is also
|
||||
/// used as the argument to panic at the moment, but that will eventually
|
||||
/// not be true.)
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[must_use]
|
||||
pub struct FatalError;
|
||||
|
||||
impl fmt::Display for FatalError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "parser fatal error")
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for FatalError {
|
||||
fn description(&self) -> &str {
|
||||
"The parser has encountered a fatal error"
|
||||
}
|
||||
}
|
||||
|
||||
/// Signifies that the compiler died with an explicit call to `.bug`
|
||||
/// or `.span_bug` rather than a failed assertion, etc.
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct ExplicitBug;
|
||||
|
||||
impl fmt::Display for ExplicitBug {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "parser internal bug")
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for ExplicitBug {
|
||||
fn description(&self) -> &str {
|
||||
"The parser has encountered an internal bug"
|
||||
}
|
||||
}
|
||||
|
||||
/// A span-handler is like a handler but also
|
||||
/// accepts span information for source-location
|
||||
/// reporting.
|
||||
|
@ -554,7 +554,6 @@ pub struct ExtCtxt<'a> {
|
||||
pub use_std: bool,
|
||||
|
||||
pub mod_path: Vec<ast::Ident> ,
|
||||
pub trace_mac: bool,
|
||||
pub exported_macros: Vec<ast::MacroDef>,
|
||||
|
||||
pub syntax_env: SyntaxEnv,
|
||||
@ -572,7 +571,6 @@ pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig,
|
||||
mod_path: Vec::new(),
|
||||
ecfg: ecfg,
|
||||
use_std: true,
|
||||
trace_mac: false,
|
||||
exported_macros: Vec::new(),
|
||||
syntax_env: env,
|
||||
recursion_count: 0,
|
||||
@ -732,10 +730,10 @@ pub fn bug(&self, msg: &str) -> ! {
|
||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
pub fn trace_macros(&self) -> bool {
|
||||
self.trace_mac
|
||||
self.ecfg.trace_mac
|
||||
}
|
||||
pub fn set_trace_macros(&mut self, x: bool) {
|
||||
self.trace_mac = x
|
||||
self.ecfg.trace_mac = x
|
||||
}
|
||||
pub fn ident_of(&self, st: &str) -> ast::Ident {
|
||||
str_to_ident(st)
|
||||
|
@ -1406,6 +1406,7 @@ pub struct ExpansionConfig<'feat> {
|
||||
pub crate_name: String,
|
||||
pub features: Option<&'feat Features>,
|
||||
pub recursion_limit: usize,
|
||||
pub trace_mac: bool,
|
||||
}
|
||||
|
||||
macro_rules! feature_tests {
|
||||
@ -1427,6 +1428,7 @@ pub fn default(crate_name: String) -> ExpansionConfig<'static> {
|
||||
crate_name: crate_name,
|
||||
features: None,
|
||||
recursion_limit: 64,
|
||||
trace_mac: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
9
src/test/run-make/trace-macros-flag/Makefile
Normal file
9
src/test/run-make/trace-macros-flag/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# This test verifies that "-Z trace-macros" works as it should. The traditional
|
||||
# "hello world" program provides a small example of this as not only println! is
|
||||
# listed, but also print! (since println! expands to this)
|
||||
|
||||
-include ../tools.mk
|
||||
|
||||
all:
|
||||
$(RUSTC) -Z trace-macros hello.rs > $(TMPDIR)/hello.out
|
||||
diff -u $(TMPDIR)/hello.out hello.trace
|
13
src/test/run-make/trace-macros-flag/hello.rs
Normal file
13
src/test/run-make/trace-macros-flag/hello.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
fn main() {
|
||||
println!("Hello, World!");
|
||||
}
|
2
src/test/run-make/trace-macros-flag/hello.trace
Normal file
2
src/test/run-make/trace-macros-flag/hello.trace
Normal file
@ -0,0 +1,2 @@
|
||||
println! { "Hello, World!" }
|
||||
print! { concat ! ( "Hello, World!" , "\n" ) }
|
Loading…
Reference in New Issue
Block a user