Auto merge of #37514 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #36849, #37059, #37296, #37316, #37484, #37485, #37495 - Failed merges:
This commit is contained in:
commit
3fba503bf5
@ -510,12 +510,11 @@ fn factory() -> Box<Fn(i32) -> i32> {
|
||||
|
||||
Box::new(|x| x + num)
|
||||
}
|
||||
# fn main() {
|
||||
|
||||
let f = factory();
|
||||
|
||||
let answer = f(1);
|
||||
assert_eq!(6, answer);
|
||||
# }
|
||||
```
|
||||
|
||||
There’s just one last problem:
|
||||
@ -540,12 +539,11 @@ fn factory() -> Box<Fn(i32) -> i32> {
|
||||
|
||||
Box::new(move |x| x + num)
|
||||
}
|
||||
fn main() {
|
||||
|
||||
let f = factory();
|
||||
|
||||
let answer = f(1);
|
||||
assert_eq!(6, answer);
|
||||
}
|
||||
```
|
||||
|
||||
By making the inner closure a `move Fn`, we create a new stack frame for our
|
||||
|
@ -362,7 +362,6 @@ numbers. A bare number like above is actually shorthand for `^0.3.0`,
|
||||
meaning "anything compatible with 0.3.0".
|
||||
If we wanted to use only `0.3.0` exactly, we could say `rand="=0.3.0"`
|
||||
(note the two equal signs).
|
||||
And if we wanted to use the latest version we could use `rand="*"`.
|
||||
We could also use a range of versions.
|
||||
[Cargo’s documentation][cargodoc] contains more details.
|
||||
|
||||
|
@ -24,9 +24,11 @@ Cargo will automatically generate a simple test when you make a new project.
|
||||
Here's the contents of `src/lib.rs`:
|
||||
|
||||
```rust
|
||||
# fn main() {}
|
||||
#[test]
|
||||
fn it_works() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -36,11 +38,11 @@ currently has no body. That's good enough to pass! We can run the tests with
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test it_works ... ok
|
||||
test tests::it_works ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
@ -56,7 +58,7 @@ for the test we wrote, and another for documentation tests. We'll talk about
|
||||
those later. For now, see this line:
|
||||
|
||||
```text
|
||||
test it_works ... ok
|
||||
test tests::it_works ... ok
|
||||
```
|
||||
|
||||
Note the `it_works`. This comes from the name of our function:
|
||||
@ -89,31 +91,30 @@ run our tests again:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test it_works ... FAILED
|
||||
test tests::it_works ... FAILED
|
||||
|
||||
failures:
|
||||
|
||||
---- it_works stdout ----
|
||||
thread 'it_works' panicked at 'assertion failed: false', /home/steve/tmp/adder/src/lib.rs:3
|
||||
|
||||
---- test::it_works stdout ----
|
||||
thread 'tests::it_works' panicked at 'assertion failed: false', src/lib.rs:5
|
||||
|
||||
|
||||
failures:
|
||||
it_works
|
||||
tests::it_works
|
||||
|
||||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
|
||||
|
||||
thread 'main' panicked at 'Some tests failed', /home/steve/src/rust/src/libtest/lib.rs:247
|
||||
error: test failed
|
||||
```
|
||||
|
||||
Rust indicates that our test failed:
|
||||
|
||||
```text
|
||||
test it_works ... FAILED
|
||||
test tests::it_works ... FAILED
|
||||
```
|
||||
|
||||
And that's reflected in the summary line:
|
||||
@ -159,11 +160,11 @@ This test will now succeed if we `panic!` and fail if we complete. Let's try it:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test it_works ... ok
|
||||
test tests::it_works ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
@ -191,11 +192,11 @@ passes:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test it_works ... ok
|
||||
test tests::it_works ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
@ -262,8 +263,8 @@ not:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 2 tests
|
||||
test expensive_test ... ignored
|
||||
@ -282,7 +283,7 @@ The expensive tests can be run explicitly using `cargo test -- --ignored`:
|
||||
|
||||
```bash
|
||||
$ cargo test -- --ignored
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test expensive_test ... ok
|
||||
@ -302,8 +303,11 @@ which is why the command is `cargo test -- --ignored`.
|
||||
# The `tests` module
|
||||
|
||||
There is one way in which our existing example is not idiomatic: it's
|
||||
missing the `tests` module. The idiomatic way of writing our example
|
||||
looks like this:
|
||||
missing the `tests` module. You might have noticed this test module was
|
||||
present in the code that was initially generated with `cargo new` but
|
||||
was missing from our last example. Let's explain what this does.
|
||||
|
||||
The idiomatic way of writing our example looks like this:
|
||||
|
||||
```rust,ignore
|
||||
# fn main() {}
|
||||
@ -356,8 +360,8 @@ Note the different `use` line. Now we run our tests:
|
||||
```bash
|
||||
$ cargo test
|
||||
Updating registry `https://github.com/rust-lang/crates.io-index`
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test tests::it_works ... ok
|
||||
@ -404,15 +408,15 @@ Let's run them:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/you/projects/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0 (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test tests::it_works ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
Running target/lib-c18e7d3494509e74
|
||||
Running target/debug/integration_test-68064b69521c828a
|
||||
|
||||
running 1 test
|
||||
test it_works ... ok
|
||||
@ -490,15 +494,15 @@ Let's run the tests again:
|
||||
|
||||
```bash
|
||||
$ cargo test
|
||||
Compiling adder v0.0.1 (file:///home/steve/tmp/adder)
|
||||
Running target/adder-91b3e234d4ed382a
|
||||
Compiling adder v0.1.0. (file:///home/you/projects/adder)
|
||||
Running target/debug/deps/adder-91b3e234d4ed382a
|
||||
|
||||
running 1 test
|
||||
test tests::it_works ... ok
|
||||
|
||||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
||||
|
||||
Running target/lib-c18e7d3494509e74
|
||||
Running target/debug/integration_test-68064b69521c828a
|
||||
|
||||
running 1 test
|
||||
test it_works ... ok
|
||||
|
@ -145,7 +145,7 @@ pub trait AsMut<T: ?Sized> {
|
||||
///
|
||||
/// # Generic Impls
|
||||
///
|
||||
/// - `[From<T>][From] for U` implies `Into<U> for T`
|
||||
/// - [`From<T>`][From]` for U` implies `Into<U> for T`
|
||||
/// - [`into()`] is reflexive, which means that `Into<T> for T` is implemented
|
||||
///
|
||||
/// [`TryInto`]: trait.TryInto.html
|
||||
@ -178,14 +178,14 @@ pub trait Into<T>: Sized {
|
||||
/// ```
|
||||
/// # Generic impls
|
||||
///
|
||||
/// - `From<T> for U` implies `[Into<U>] for T`
|
||||
/// - `From<T> for U` implies [`Into<U>`]` for T`
|
||||
/// - [`from()`] is reflexive, which means that `From<T> for T` is implemented
|
||||
///
|
||||
/// [`TryFrom`]: trait.TryFrom.html
|
||||
/// [`Option<T>`]: ../../std/option/enum.Option.html
|
||||
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
|
||||
/// [`String`]: ../../std/string/struct.String.html
|
||||
/// [Into<U>]: trait.Into.html
|
||||
/// [`Into<U>`]: trait.Into.html
|
||||
/// [`from()`]: trait.From.html#tymethod.from
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait From<T>: Sized {
|
||||
|
@ -42,12 +42,13 @@ macro_rules! panic {
|
||||
/// Unsafe code relies on `assert!` to enforce run-time invariants that, if
|
||||
/// violated could lead to unsafety.
|
||||
///
|
||||
/// Other use-cases of `assert!` include
|
||||
/// [testing](https://doc.rust-lang.org/book/testing.html) and enforcing
|
||||
/// run-time invariants in safe code (whose violation cannot result in unsafety).
|
||||
/// Other use-cases of `assert!` include [testing] and enforcing run-time
|
||||
/// invariants in safe code (whose violation cannot result in unsafety).
|
||||
///
|
||||
/// This macro has a second version, where a custom panic message can be provided.
|
||||
///
|
||||
/// [testing]: ../book/testing.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
|
@ -241,8 +241,8 @@ pub trait Unsize<T: ?Sized> {
|
||||
/// compile-time error. Specifically, with structs you'll get [E0204] and with enums you'll get
|
||||
/// [E0205].
|
||||
///
|
||||
/// [E0204]: https://doc.rust-lang.org/error-index.html#E0204
|
||||
/// [E0205]: https://doc.rust-lang.org/error-index.html#E0205
|
||||
/// [E0204]: ../../error-index.html#E0204
|
||||
/// [E0205]: ../../error-index.html#E0205
|
||||
///
|
||||
/// ## When *should* my type be `Copy`?
|
||||
///
|
||||
|
@ -182,11 +182,11 @@ pub trait Drop {
|
||||
/// After this function is over, the memory of `self` will be deallocated.
|
||||
///
|
||||
/// This function cannot be called explicitly. This is compiler error
|
||||
/// [0040]. However, the [`std::mem::drop`] function in the prelude can be
|
||||
/// [E0040]. However, the [`std::mem::drop`] function in the prelude can be
|
||||
/// used to call the argument's `Drop` implementation.
|
||||
///
|
||||
/// [0040]: https://doc.rust-lang.org/error-index.html#E0040
|
||||
/// [`std::mem::drop`]: https://doc.rust-lang.org/std/mem/fn.drop.html
|
||||
/// [E0040]: ../../error-index.html#E0040
|
||||
/// [`std::mem::drop`]: ../../std/mem/fn.drop.html
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -132,7 +132,7 @@ impl Utf8Error {
|
||||
/// verified.
|
||||
///
|
||||
/// It is the maximum index such that `from_utf8(input[..index])`
|
||||
/// would return `Some(_)`.
|
||||
/// would return `Ok(_)`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -199,9 +199,6 @@ pub enum TypeOrigin {
|
||||
// Computing common supertype of an if expression with no else counter-part
|
||||
IfExpressionWithNoElse(Span),
|
||||
|
||||
// Computing common supertype in a range expression
|
||||
RangeExpression(Span),
|
||||
|
||||
// `where a == b`
|
||||
EquatePredicate(Span),
|
||||
|
||||
@ -231,7 +228,6 @@ impl TypeOrigin {
|
||||
},
|
||||
&TypeOrigin::IfExpression(_) => "if and else have incompatible types",
|
||||
&TypeOrigin::IfExpressionWithNoElse(_) => "if may be missing an else clause",
|
||||
&TypeOrigin::RangeExpression(_) => "start and end of range have incompatible types",
|
||||
&TypeOrigin::EquatePredicate(_) => "equality predicate not satisfied",
|
||||
&TypeOrigin::MainFunctionType(_) => "main function has wrong type",
|
||||
&TypeOrigin::StartFunctionType(_) => "start function has wrong type",
|
||||
@ -251,7 +247,6 @@ impl TypeOrigin {
|
||||
&TypeOrigin::MatchExpressionArm(..) => "match arms have compatible types",
|
||||
&TypeOrigin::IfExpression(_) => "if and else have compatible types",
|
||||
&TypeOrigin::IfExpressionWithNoElse(_) => "if missing an else returns ()",
|
||||
&TypeOrigin::RangeExpression(_) => "start and end of range have compatible types",
|
||||
&TypeOrigin::EquatePredicate(_) => "equality where clause is satisfied",
|
||||
&TypeOrigin::MainFunctionType(_) => "`main` function has the correct type",
|
||||
&TypeOrigin::StartFunctionType(_) => "`start` function has the correct type",
|
||||
@ -1755,7 +1750,6 @@ impl TypeOrigin {
|
||||
TypeOrigin::MatchExpressionArm(match_span, ..) => match_span,
|
||||
TypeOrigin::IfExpression(span) => span,
|
||||
TypeOrigin::IfExpressionWithNoElse(span) => span,
|
||||
TypeOrigin::RangeExpression(span) => span,
|
||||
TypeOrigin::EquatePredicate(span) => span,
|
||||
TypeOrigin::MainFunctionType(span) => span,
|
||||
TypeOrigin::StartFunctionType(span) => span,
|
||||
|
@ -101,8 +101,8 @@ impl PpMode {
|
||||
|
||||
pub fn needs_analysis(&self) -> bool {
|
||||
match *self {
|
||||
PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
|
||||
_ => false,
|
||||
PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,14 +233,11 @@ impl PpSourceMode {
|
||||
arenas,
|
||||
id,
|
||||
|tcx, _, _, _| {
|
||||
let annotation = TypedAnnotation {
|
||||
tcx: tcx,
|
||||
};
|
||||
let annotation = TypedAnnotation { tcx: tcx };
|
||||
let _ignore = tcx.dep_graph.in_ignore();
|
||||
f(&annotation,
|
||||
payload,
|
||||
ast_map.forest.krate())
|
||||
}), sess)
|
||||
f(&annotation, payload, ast_map.forest.krate())
|
||||
}),
|
||||
sess)
|
||||
}
|
||||
_ => panic!("Should use call_with_pp_support"),
|
||||
}
|
||||
@ -281,9 +278,11 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn {
|
||||
/// Computes an user-readable representation of a path, if possible.
|
||||
fn node_path(&self, id: ast::NodeId) -> Option<String> {
|
||||
self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| {
|
||||
path.data.into_iter().map(|elem| {
|
||||
elem.data.to_string()
|
||||
}).collect::<Vec<_>>().join("::")
|
||||
path.data
|
||||
.into_iter()
|
||||
.map(|elem| elem.data.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("::")
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -352,7 +351,8 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> {
|
||||
}
|
||||
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
|
||||
match node {
|
||||
pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()),
|
||||
pprust::NodeIdent(_) |
|
||||
pprust::NodeName(_) => Ok(()),
|
||||
|
||||
pprust::NodeItem(item) => {
|
||||
pp::space(&mut s.s)?;
|
||||
@ -617,15 +617,14 @@ impl ReplaceBodyWithLoop {
|
||||
impl fold::Folder for ReplaceBodyWithLoop {
|
||||
fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
|
||||
match i {
|
||||
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
|
||||
ast::ItemKind::Static(..) |
|
||||
ast::ItemKind::Const(..) => {
|
||||
self.within_static_or_const = true;
|
||||
let ret = fold::noop_fold_item_kind(i, self);
|
||||
self.within_static_or_const = false;
|
||||
return ret;
|
||||
}
|
||||
_ => {
|
||||
fold::noop_fold_item_kind(i, self)
|
||||
}
|
||||
_ => fold::noop_fold_item_kind(i, self),
|
||||
}
|
||||
}
|
||||
|
||||
@ -656,11 +655,15 @@ impl fold::Folder for ReplaceBodyWithLoop {
|
||||
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
|
||||
fn expr_to_block(rules: ast::BlockCheckMode, e: Option<P<ast::Expr>>) -> P<ast::Block> {
|
||||
P(ast::Block {
|
||||
stmts: e.map(|e| ast::Stmt {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: e.span,
|
||||
node: ast::StmtKind::Expr(e),
|
||||
}).into_iter().collect(),
|
||||
stmts: e.map(|e| {
|
||||
ast::Stmt {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: e.span,
|
||||
node: ast::StmtKind::Expr(e),
|
||||
}
|
||||
})
|
||||
.into_iter()
|
||||
.collect(),
|
||||
rules: rules,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: syntax_pos::DUMMY_SP,
|
||||
@ -721,9 +724,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
|
||||
}
|
||||
blocks::FnLikeCode(fn_like) => {
|
||||
let (bccx, analysis_data) =
|
||||
borrowck::build_borrowck_dataflow_data_for_fn(tcx,
|
||||
fn_like.to_fn_parts(),
|
||||
&cfg);
|
||||
borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_like.to_fn_parts(), &cfg);
|
||||
|
||||
let lcfg = borrowck_dot::DataflowLabeller {
|
||||
inner: lcfg,
|
||||
@ -756,13 +757,13 @@ pub fn fold_crate(krate: ast::Crate, ppm: PpMode) -> ast::Crate {
|
||||
fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, String) {
|
||||
let src_name = driver::source_name(input);
|
||||
let src = sess.codemap()
|
||||
.get_filemap(&src_name)
|
||||
.unwrap()
|
||||
.src
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
.get_filemap(&src_name)
|
||||
.unwrap()
|
||||
.src
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
(src, src_name)
|
||||
}
|
||||
|
||||
@ -795,17 +796,18 @@ pub fn print_after_parsing(sess: &Session,
|
||||
// Silently ignores an identified node.
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support(sess, None, box out, |annotation, out| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
false)
|
||||
}).unwrap()
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
false)
|
||||
})
|
||||
.unwrap()
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
@ -828,8 +830,15 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
|
||||
if ppm.needs_analysis() {
|
||||
print_with_analysis(sess, ast_map, analysis, resolutions,
|
||||
crate_name, arenas, ppm, opt_uii, ofile);
|
||||
print_with_analysis(sess,
|
||||
ast_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
crate_name,
|
||||
arenas,
|
||||
ppm,
|
||||
opt_uii,
|
||||
ofile);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -839,82 +848,82 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
let mut out = Vec::new();
|
||||
|
||||
match (ppm, opt_uii) {
|
||||
(PpmSource(s), _) => {
|
||||
// Silently ignores an identified node.
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
true)
|
||||
})
|
||||
}
|
||||
(PpmSource(s), _) => {
|
||||
// Silently ignores an identified node.
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support(sess, Some(ast_map), box out, |annotation, out| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
true)
|
||||
})
|
||||
}
|
||||
|
||||
(PpmHir(s), None) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
ast_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
crate_name,
|
||||
box out,
|
||||
|annotation, out, krate| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust_hir::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
true)
|
||||
})
|
||||
}
|
||||
(PpmHir(s), None) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
ast_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
crate_name,
|
||||
box out,
|
||||
|annotation, out, krate| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
pprust_hir::print_crate(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
krate,
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
true)
|
||||
})
|
||||
}
|
||||
|
||||
(PpmHir(s), Some(uii)) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
ast_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
crate_name,
|
||||
(out,uii),
|
||||
|annotation, (out,uii), _| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
|
||||
let mut pp_state =
|
||||
pprust_hir::State::new_from_input(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
box out,
|
||||
annotation.pp_ann(),
|
||||
true,
|
||||
Some(ast_map.krate()));
|
||||
for node_id in uii.all_matching_node_ids(ast_map) {
|
||||
let node = ast_map.get(node_id);
|
||||
pp_state.print_node(&node)?;
|
||||
pp::space(&mut pp_state.s)?;
|
||||
let path = annotation.node_path(node_id)
|
||||
.expect("--unpretty missing node paths");
|
||||
pp_state.synth_comment(path)?;
|
||||
pp::hardbreak(&mut pp_state.s)?;
|
||||
}
|
||||
pp::eof(&mut pp_state.s)
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}.unwrap();
|
||||
(PpmHir(s), Some(uii)) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
ast_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
arenas,
|
||||
crate_name,
|
||||
(out, uii),
|
||||
|annotation, (out, uii), _| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
|
||||
let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(),
|
||||
sess.diagnostic(),
|
||||
src_name.to_string(),
|
||||
&mut rdr,
|
||||
box out,
|
||||
annotation.pp_ann(),
|
||||
true,
|
||||
Some(ast_map.krate()));
|
||||
for node_id in uii.all_matching_node_ids(ast_map) {
|
||||
let node = ast_map.get(node_id);
|
||||
pp_state.print_node(&node)?;
|
||||
pp::space(&mut pp_state.s)?;
|
||||
let path = annotation.node_path(node_id)
|
||||
.expect("--unpretty missing node paths");
|
||||
pp_state.synth_comment(path)?;
|
||||
pp::hardbreak(&mut pp_state.s)?;
|
||||
}
|
||||
pp::eof(&mut pp_state.s)
|
||||
})
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
write_output(out, ofile);
|
||||
}
|
||||
@ -955,27 +964,28 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
let def_id = tcx.map.local_def_id(nodeid);
|
||||
match ppm {
|
||||
PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mut out),
|
||||
PpmMirCFG => {
|
||||
write_mir_graphviz(tcx, iter::once(def_id), &mut out)
|
||||
}
|
||||
PpmMirCFG => write_mir_graphviz(tcx, iter::once(def_id), &mut out),
|
||||
_ => unreachable!(),
|
||||
}?;
|
||||
} else {
|
||||
match ppm {
|
||||
PpmMir => write_mir_pretty(tcx,
|
||||
tcx.mir_map.borrow().keys().into_iter(),
|
||||
&mut out),
|
||||
PpmMirCFG => write_mir_graphviz(tcx,
|
||||
tcx.mir_map.borrow().keys().into_iter(),
|
||||
&mut out),
|
||||
PpmMir => {
|
||||
write_mir_pretty(tcx, tcx.mir_map.borrow().keys().into_iter(), &mut out)
|
||||
}
|
||||
PpmMirCFG => {
|
||||
write_mir_graphviz(tcx,
|
||||
tcx.mir_map.borrow().keys().into_iter(),
|
||||
&mut out)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
PpmFlowGraph(mode) => {
|
||||
let nodeid = nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or \
|
||||
unique path suffix (b::c::d)");
|
||||
let nodeid =
|
||||
nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
|
||||
suffix (b::c::d)");
|
||||
let node = tcx.map.find(nodeid).unwrap_or_else(|| {
|
||||
tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
|
||||
});
|
||||
@ -990,8 +1000,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
print_flowgraph(variants, tcx, code, mode, out)
|
||||
}
|
||||
None => {
|
||||
let message = format!("--pretty=flowgraph needs block, fn, or method; got \
|
||||
{:?}",
|
||||
let message = format!("--pretty=flowgraph needs block, fn, or method; \
|
||||
got {:?}",
|
||||
node);
|
||||
|
||||
// Point to what was found, if there's an accessible span.
|
||||
@ -1004,7 +1014,9 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}), sess).unwrap();
|
||||
}),
|
||||
sess)
|
||||
.unwrap();
|
||||
|
||||
write_output(out, ofile);
|
||||
}
|
||||
|
@ -20,26 +20,11 @@ use libc::c_char;
|
||||
// detection code will walk past the end of the feature array,
|
||||
// leading to crashes.
|
||||
|
||||
const ARM_WHITELIST: &'static [&'static str] = &[
|
||||
"neon\0",
|
||||
"vfp2\0",
|
||||
"vfp3\0",
|
||||
"vfp4\0",
|
||||
];
|
||||
const ARM_WHITELIST: &'static [&'static str] = &["neon\0", "vfp2\0", "vfp3\0", "vfp4\0"];
|
||||
|
||||
const X86_WHITELIST: &'static [&'static str] = &[
|
||||
"avx\0",
|
||||
"avx2\0",
|
||||
"bmi\0",
|
||||
"bmi2\0",
|
||||
"sse\0",
|
||||
"sse2\0",
|
||||
"sse3\0",
|
||||
"sse4.1\0",
|
||||
"sse4.2\0",
|
||||
"ssse3\0",
|
||||
"tbm\0",
|
||||
];
|
||||
const X86_WHITELIST: &'static [&'static str] = &["avx\0", "avx2\0", "bmi\0", "bmi2\0", "sse\0",
|
||||
"sse2\0", "sse3\0", "sse4.1\0", "sse4.2\0",
|
||||
"ssse3\0", "tbm\0"];
|
||||
|
||||
/// Add `target_feature = "..."` cfgs for a variety of platform
|
||||
/// specific features (SSE, NEON etc.).
|
||||
@ -59,7 +44,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
|
||||
for feat in whitelist {
|
||||
assert_eq!(feat.chars().last(), Some('\0'));
|
||||
if unsafe { LLVMRustHasFeature(target_machine, feat.as_ptr() as *const c_char) } {
|
||||
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len()-1])))
|
||||
cfg.push(attr::mk_name_value_item_str(tf.clone(), intern(&feat[..feat.len() - 1])))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ use syntax_pos::DUMMY_SP;
|
||||
|
||||
use rustc::hir;
|
||||
|
||||
struct Env<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||
struct Env<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
||||
infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
|
||||
@ -86,8 +86,7 @@ impl Emitter for ExpectErrorEmitter {
|
||||
|
||||
fn errors(msgs: &[&str]) -> (Box<Emitter + Send>, usize) {
|
||||
let v = msgs.iter().map(|m| m.to_string()).collect();
|
||||
(box ExpectErrorEmitter { messages: v } as Box<Emitter + Send>,
|
||||
msgs.len())
|
||||
(box ExpectErrorEmitter { messages: v } as Box<Emitter + Send>, msgs.len())
|
||||
}
|
||||
|
||||
fn test_env<F>(source_string: &str,
|
||||
@ -103,8 +102,12 @@ fn test_env<F>(source_string: &str,
|
||||
let dep_graph = DepGraph::new(false);
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
let cstore = Rc::new(CStore::new(&dep_graph));
|
||||
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler,
|
||||
Rc::new(CodeMap::new()), cstore.clone());
|
||||
let sess = session::build_session_(options,
|
||||
&dep_graph,
|
||||
None,
|
||||
diagnostic_handler,
|
||||
Rc::new(CodeMap::new()),
|
||||
cstore.clone());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let input = config::Input::Str {
|
||||
name: driver::anon_src(),
|
||||
@ -112,9 +115,15 @@ fn test_env<F>(source_string: &str,
|
||||
};
|
||||
let krate = driver::phase_1_parse_input(&sess, &input).unwrap();
|
||||
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
|
||||
driver::phase_2_configure_and_expand(
|
||||
&sess, &cstore, krate, None, "test", None, MakeGlobMap::No, |_| Ok(()),
|
||||
).expect("phase 2 aborted")
|
||||
driver::phase_2_configure_and_expand(&sess,
|
||||
&cstore,
|
||||
krate,
|
||||
None,
|
||||
"test",
|
||||
None,
|
||||
MakeGlobMap::No,
|
||||
|_| Ok(()))
|
||||
.expect("phase 2 aborted")
|
||||
};
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
|
||||
@ -167,14 +176,22 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
|
||||
let node = ast::NodeId::from_u32;
|
||||
let dscope = self.infcx
|
||||
.tcx
|
||||
.region_maps
|
||||
.intern_code_extent(CodeExtentData::DestructionScope(node(1)),
|
||||
region::ROOT_CODE_EXTENT);
|
||||
.tcx
|
||||
.region_maps
|
||||
.intern_code_extent(CodeExtentData::DestructionScope(node(1)),
|
||||
region::ROOT_CODE_EXTENT);
|
||||
self.create_region_hierarchy(&RH {
|
||||
id: node(1),
|
||||
sub: &[RH { id: node(10), sub: &[] }, RH { id: node(11), sub: &[] }],
|
||||
}, dscope);
|
||||
id: node(1),
|
||||
sub: &[RH {
|
||||
id: node(10),
|
||||
sub: &[],
|
||||
},
|
||||
RH {
|
||||
id: node(11),
|
||||
sub: &[],
|
||||
}],
|
||||
},
|
||||
dscope);
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // this seems like it could be useful, even if we don't use it now
|
||||
@ -213,22 +230,16 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
hir::ItemStatic(..) |
|
||||
hir::ItemFn(..) |
|
||||
hir::ItemForeignMod(..) |
|
||||
hir::ItemTy(..) => {
|
||||
None
|
||||
}
|
||||
hir::ItemTy(..) => None,
|
||||
|
||||
hir::ItemEnum(..) |
|
||||
hir::ItemStruct(..) |
|
||||
hir::ItemUnion(..) |
|
||||
hir::ItemTrait(..) |
|
||||
hir::ItemImpl(..) |
|
||||
hir::ItemDefaultImpl(..) => {
|
||||
None
|
||||
}
|
||||
hir::ItemDefaultImpl(..) => None,
|
||||
|
||||
hir::ItemMod(ref m) => {
|
||||
search_mod(this, m, idx, names)
|
||||
}
|
||||
hir::ItemMod(ref m) => search_mod(this, m, idx, names),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -281,10 +292,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
self.infcx.tcx.mk_param(index, token::intern(&name[..]))
|
||||
}
|
||||
|
||||
pub fn re_early_bound(&self,
|
||||
index: u32,
|
||||
name: &'static str)
|
||||
-> &'tcx ty::Region {
|
||||
pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region {
|
||||
let name = token::intern(name);
|
||||
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
index: index,
|
||||
@ -292,7 +300,9 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn re_late_bound_with_debruijn(&self, id: u32, debruijn: ty::DebruijnIndex)
|
||||
pub fn re_late_bound_with_debruijn(&self,
|
||||
id: u32,
|
||||
debruijn: ty::DebruijnIndex)
|
||||
-> &'tcx ty::Region {
|
||||
self.infcx.tcx.mk_region(ty::ReLateBound(debruijn, ty::BrAnon(id)))
|
||||
}
|
||||
@ -394,9 +404,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
|
||||
self.assert_eq(t, t_lub);
|
||||
}
|
||||
Err(ref e) => {
|
||||
panic!("unexpected error in LUB: {}", e)
|
||||
}
|
||||
Err(ref e) => panic!("unexpected error in LUB: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,9 +412,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
|
||||
pub fn check_glb(&self, t1: Ty<'tcx>, t2: Ty<'tcx>, t_glb: Ty<'tcx>) {
|
||||
debug!("check_glb(t1={}, t2={}, t_glb={})", t1, t2, t_glb);
|
||||
match self.glb(t1, t2) {
|
||||
Err(e) => {
|
||||
panic!("unexpected error computing LUB: {:?}", e)
|
||||
}
|
||||
Err(e) => panic!("unexpected error computing LUB: {:?}", e),
|
||||
Ok(InferOk { obligations, value: t }) => {
|
||||
// FIXME(#32730) once obligations are being propagated, assert the right thing.
|
||||
assert!(obligations.is_empty());
|
||||
|
@ -69,7 +69,9 @@ pub trait Error: Debug + Display {
|
||||
/// It should not contain newlines or sentence-ending punctuation,
|
||||
/// to facilitate embedding in larger user-facing strings.
|
||||
/// For showing formatted error messages with more information see
|
||||
/// [Display](https://doc.rust-lang.org/std/fmt/trait.Display.html).
|
||||
/// [`Display`].
|
||||
///
|
||||
/// [`Display`]: ../fmt/trait.Display.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -23,7 +23,7 @@ use io::{self, SeekFrom, Error, ErrorKind};
|
||||
///
|
||||
/// The standard library implements some I/O traits on various types which
|
||||
/// are commonly used as a buffer, like `Cursor<`[`Vec`]`<u8>>` and
|
||||
/// `Cursor<`[`&[u8]`]`>`.
|
||||
/// `Cursor<`[`&[u8]`][bytes]`>`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -35,7 +35,7 @@ use io::{self, SeekFrom, Error, ErrorKind};
|
||||
/// [`Read`]: ../../std/io/trait.Read.html
|
||||
/// [`Write`]: ../../std/io/trait.Write.html
|
||||
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
||||
/// [`&[u8]`]: ../../std/primitive.slice.html
|
||||
/// [bytes]: ../../std/primitive.slice.html
|
||||
/// [`File`]: ../fs/struct.File.html
|
||||
///
|
||||
/// ```no_run
|
||||
|
@ -914,6 +914,7 @@ impl<'a> cmp::Ord for Components<'a> {
|
||||
/// [`Path`]: struct.Path.html
|
||||
/// [`push`]: struct.PathBuf.html#method.push
|
||||
/// [`set_extension`]: struct.PathBuf.html#method.set_extension
|
||||
/// [`Deref`]: ../ops/trait.Deref.html
|
||||
///
|
||||
/// More details about the overall approach can be found in
|
||||
/// the module documentation.
|
||||
|
Loading…
x
Reference in New Issue
Block a user