Skip to content

Rollup of 5 pull requests #28820

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

Merged
merged 23 commits into from
Oct 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b1149d
use the infcx tables to check if a closure is Copy
Sep 24, 2015
24b5d3a
Improve speed of `fmt::Debug` for `str` and `char`
semmaz Sep 23, 2015
025ca11
Add `fmt::Debug` string escape tests
semmaz Sep 29, 2015
d2d0872
Implement `size_hint` for `EscapeDefault`
semmaz Sep 29, 2015
8c963c0
rustc: Support output filenames for each emit type
alexcrichton Sep 30, 2015
0294098
Implement `size_hint` for `EscapeUnicode`
semmaz Sep 30, 2015
8a4bfbb
Add a test that rustc can compile standard input
wthrowe Oct 2, 2015
98841d4
Fix misnamed variable in rustdoc
nagisa Sep 29, 2015
f38bc2c
Fix librustdoc search events
nagisa Sep 29, 2015
20cccfa
Change tests per RFC 246 (const vs static)
sanxiyn Sep 25, 2015
61f5b2b
Check attribute usage
sanxiyn Sep 25, 2015
1741962
rustc: Emit phony targets for inputs in dep-info
alexcrichton Sep 30, 2015
e650491
Auto merge of #28768 - alexcrichton:dep-info++, r=brson
bors Oct 2, 2015
ef07d7d
Auto merge of #28650 - sanxiyn:attr-usage, r=nrc
bors Oct 2, 2015
eac9d71
reference: fix markdown formatting
matklad Oct 2, 2015
669fc7f
Auto merge of #28626 - arielb1:closure-needs-infer, r=nikomatsakis
bors Oct 2, 2015
bfb2603
Auto merge of #28662 - semmaz:fmt-debug, r=alexcrichton
bors Oct 2, 2015
f528c47
Add in some <hr>s for emphasis
steveklabnik Oct 2, 2015
f368a18
Rollup merge of #28736 - nagisa:rustdocjsfix, r=alexcrichton
steveklabnik Oct 3, 2015
9c5837e
Rollup merge of #28805 - wthrowe:compile-stdin, r=alexcrichton
steveklabnik Oct 3, 2015
c3c5de1
Rollup merge of #28812 - steveklabnik:improve_str_from_utf8_docs, r=b…
steveklabnik Oct 3, 2015
323037d
Rollup merge of #28814 - matklad:fix-md, r=alexcrichton
steveklabnik Oct 3, 2015
92cff9f
Rollup merge of #28819 - steveklabnik:doc_hr, r=brson
steveklabnik Oct 3, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Comma separated list of types of crates for the compiler to emit.
Specify the name of the crate being built.
.TP
\fB\-\-emit\fR [asm|llvm\-bc|llvm\-ir|obj|link|dep\-info]
Configure the output that \fBrustc\fR will produce.
Configure the output that \fBrustc\fR will produce. Each option may also be of
the form KIND=PATH to specify the explicit output location for that particular
emission kind.
.TP
\fB\-\-print\fR [crate\-name|file\-names|sysroot]
Comma separated list of compiler information to print on stdout.
Expand All @@ -66,7 +68,8 @@ Equivalent to \fI\-C\ opt\-level=2\fR.
.TP
\fB\-o\fR \fIFILENAME\fR
Write output to \fIFILENAME\fR.
Ignored if multiple \fI\-\-emit\fR outputs are specified.
Ignored if multiple \fI\-\-emit\fR outputs are specified which don't have an
explicit path otherwise.
.TP
\fB\-\-out\-dir\fR \fIDIR\fR
Write output to compiler\[hy]chosen filename in \fIDIR\fR.
Expand Down
3 changes: 3 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ An identifier is any nonempty Unicode[^non_ascii_idents] string of the following
gated. This is expected to improve soon.

Either

* The first character has property `XID_start`
* The remaining characters have property `XID_continue`

Or

* The first character is `_`
* The identifier is more than one character, `_` alone is not an identifier
* The remaining characters have property `XID_continue`
Expand Down
8 changes: 8 additions & 0 deletions src/doc/trpl/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ println!("{}", x + y);

Here's an explanation, rendered:

-------------------------------------------------------------------------------

First, we set `x` to five:

```rust
Expand All @@ -303,8 +305,12 @@ Finally, we print the sum of `x` and `y`:
println!("{}", x + y);
```

-------------------------------------------------------------------------------

Here's the same explanation, in raw text:

-------------------------------------------------------------------------------

> First, we set `x` to five:
>
> ```text
Expand All @@ -329,6 +335,8 @@ Here's the same explanation, in raw text:
> println!("{}", x + y);
> ```

-------------------------------------------------------------------------------

By repeating all parts of the example, you can ensure that your example still
compiles, while only showing the parts that are relevant to that part of your
explanation.
Expand Down
31 changes: 27 additions & 4 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ impl CharExt for char {
'\t' => EscapeDefaultState::Backslash('t'),
'\r' => EscapeDefaultState::Backslash('r'),
'\n' => EscapeDefaultState::Backslash('n'),
'\\' => EscapeDefaultState::Backslash('\\'),
'\'' => EscapeDefaultState::Backslash('\''),
'"' => EscapeDefaultState::Backslash('"'),
'\\' | '\'' | '"' => EscapeDefaultState::Backslash(self),
'\x20' ... '\x7e' => EscapeDefaultState::Char(self),
_ => EscapeDefaultState::Unicode(self.escape_unicode())
};
Expand Down Expand Up @@ -344,6 +342,22 @@ impl Iterator for EscapeUnicode {
EscapeUnicodeState::Done => None,
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
let mut n = 0;
while (self.c as usize) >> (4 * (n + 1)) != 0 {
n += 1;
}
let n = match self.state {
EscapeUnicodeState::Backslash => n + 5,
EscapeUnicodeState::Type => n + 4,
EscapeUnicodeState::LeftBrace => n + 3,
EscapeUnicodeState::Value(offset) => offset + 2,
EscapeUnicodeState::RightBrace => 1,
EscapeUnicodeState::Done => 0,
};
(n, Some(n))
}
}

/// An iterator over the characters that represent a `char`, escaped
Expand Down Expand Up @@ -377,7 +391,16 @@ impl Iterator for EscapeDefault {
Some(c)
}
EscapeDefaultState::Done => None,
EscapeDefaultState::Unicode(ref mut iter) => iter.next()
EscapeDefaultState::Unicode(ref mut iter) => iter.next(),
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
match self.state {
EscapeDefaultState::Char(_) => (1, Some(1)),
EscapeDefaultState::Backslash(_) => (2, Some(2)),
EscapeDefaultState::Unicode(ref iter) => iter.size_hint(),
EscapeDefaultState::Done => (0, Some(0)),
}
}
}
23 changes: 16 additions & 7 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,11 +1332,21 @@ impl Display for bool {
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for str {
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f, "\""));
for c in self.chars().flat_map(|c| c.escape_default()) {
try!(f.write_char(c))
try!(f.write_char('"'));
let mut from = 0;
for (i, c) in self.char_indices() {
let esc = c.escape_default();
// If char needs escaping, flush backlog so far and write, else skip
if esc.size_hint() != (1, Some(1)) {
try!(f.write_str(&self[from..i]));
for c in esc {
try!(f.write_char(c));
}
from = i + c.len_utf8();
}
}
write!(f, "\"")
try!(f.write_str(&self[from..]));
f.write_char('"')
}
}

Expand All @@ -1350,12 +1360,11 @@ impl Display for str {
#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for char {
fn fmt(&self, f: &mut Formatter) -> Result {
use char::CharExt;
try!(write!(f, "'"));
try!(f.write_char('\''));
for c in self.escape_default() {
try!(f.write_char(c))
}
write!(f, "'")
f.write_char('\'')
}
}

Expand Down
110 changes: 110 additions & 0 deletions src/librustc/front/check_attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2015 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.

use session::Session;

use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::visit;
use syntax::visit::Visitor;

#[derive(Copy, Clone, PartialEq)]
enum Target {
Fn,
Struct,
Enum,
Other,
}

impl Target {
fn from_item(item: &ast::Item) -> Target {
match item.node {
ast::ItemFn(..) => Target::Fn,
ast::ItemStruct(..) => Target::Struct,
ast::ItemEnum(..) => Target::Enum,
_ => Target::Other,
}
}
}

struct CheckAttrVisitor<'a> {
sess: &'a Session,
}

impl<'a> CheckAttrVisitor<'a> {
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
if target != Target::Fn {
self.sess.span_err(
attr.span,
"attribute should be applied to function");
}
}

fn check_repr(&self, attr: &ast::Attribute, target: Target) {
let words = match attr.meta_item_list() {
Some(words) => words,
None => {
return;
}
};
for word in words {
let word: &str = &word.name();
match word {
"C" => {
if target != Target::Struct && target != Target::Enum {
self.sess.span_err(
attr.span,
"attribute should be applied to struct or enum");
}
}
"packed" |
"simd" => {
if target != Target::Struct {
self.sess.span_err(
attr.span,
"attribute should be applied to struct");
}
}
"i8" | "u8" | "i16" | "u16" |
"i32" | "u32" | "i64" | "u64" |
"isize" | "usize" => {
if target != Target::Enum {
self.sess.span_err(
attr.span,
"attribute should be applied to enum");
}
}
_ => (),
}
}
}

fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
let name: &str = &attr.name();
match name {
"inline" => self.check_inline(attr, target),
"repr" => self.check_repr(attr, target),
_ => (),
}
}
}

impl<'a, 'v> Visitor<'v> for CheckAttrVisitor<'a> {
fn visit_item(&mut self, item: &ast::Item) {
let target = Target::from_item(item);
for attr in &item.attrs {
self.check_attribute(attr, target);
}
}
}

pub fn check_crate(sess: &Session, krate: &ast::Crate) {
visit::walk_crate(&mut CheckAttrVisitor { sess: sess }, krate);
}
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub mod back {
}

pub mod front {
pub mod check_attr;
pub mod map;
}

Expand Down
9 changes: 8 additions & 1 deletion src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.resolve_type_vars_or_error(&ty)
}

pub fn tables_are_tcx_tables(&self) -> bool {
let tables: &RefCell<ty::Tables> = &self.tables;
let tcx_tables: &RefCell<ty::Tables> = &self.tcx.tables;
tables as *const _ == tcx_tables as *const _
}

pub fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
let ty = self.resolve_type_vars_if_possible(&ty);
if ty.needs_infer() {
if ty.needs_infer() ||
(ty.has_closure_types() && !self.tables_are_tcx_tables()) {
// this can get called from typeck (by euv), and moves_by_default
// rightly refuses to work with inference variables, but
// moves_by_default has a cache, which we want to use in other
Expand Down
Loading