Skip to content

Commit

Permalink
Auto merge of rust-lang#46073 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

- Successful merges: rust-lang#45767, rust-lang#46044, rust-lang#46066, rust-lang#46071
- Failed merges:
  • Loading branch information
bors committed Nov 18, 2017
2 parents 130eaae + 5f1c37a commit 18250b0
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 107 deletions.
14 changes: 8 additions & 6 deletions src/doc/rustdoc/src/documentation-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ function! Forcing you to write `main` for every example, no matter how small,
adds friction. So `rustdoc` processes your examples slightly before
running them. Here's the full algorithm rustdoc uses to preprocess examples:

1. Any leading `#![foo]` attributes are left intact as crate attributes.
2. Some common `allow` attributes are inserted, including
1. Some common `allow` attributes are inserted, including
`unused_variables`, `unused_assignments`, `unused_mut`,
`unused_attributes`, and `dead_code`. Small examples often trigger
these lints.
3. If the example does not contain `extern crate`, then `extern crate
2. Any attributes specified with `#![doc(test(attr(...)))]` are added.
3. Any leading `#![foo]` attributes are left intact as crate attributes.
4. If the example does not contain `extern crate`, and
`#![doc(test(no_crate_inject))]` was not specified, then `extern crate
<mycrate>;` is inserted (note the lack of `#[macro_use]`).
4. Finally, if the example does not contain `fn main`, the remainder of the
5. Finally, if the example does not contain `fn main`, the remainder of the
text is wrapped in `fn main() { your_code }`.

For more about that caveat in rule 3, see "Documeting Macros" below.
For more about that caveat in rule 4, see "Documeting Macros" below.

## Hiding portions of the example

Expand Down Expand Up @@ -261,4 +263,4 @@ are added.
The `no_run` attribute will compile your code, but not run it. This is
important for examples such as "Here's how to retrieve a web page,"
which you would want to ensure compiles, but might be run in a test
environment that has no network access.
environment that has no network access.
20 changes: 20 additions & 0 deletions src/doc/rustdoc/src/the-doc-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ to it in the docs. But if you include this:

it will not.

### `test(no_crate_inject)`

By default, `rustdoc` will automatically add a line with `extern crate my_crate;` into each doctest.
But if you include this:

```rust,ignore
#![doc(test(no_crate_inject))]
```

it will not.

### `test(attr(...))`

This form of the `doc` attribute allows you to add arbitrary attributes to all your doctests. For
example, if you want your doctests to fail if they produce any warnings, you could add this:

```rust,ignore
#![doc(test(attr(deny(warnings))))]
```

## At the item level

These forms of the `#[doc]` attribute are used on individual items, to control how
Expand Down
2 changes: 1 addition & 1 deletion src/etc/indenter
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ while True:
if more_re.match(line):
indent += 1

print "%03d %s%s" % (indent, " " * indent, line.strip())
print("%03d %s%s" % (indent, " " * indent, line.strip()))

if less_re.match(line):
indent -= 1
4 changes: 2 additions & 2 deletions src/etc/sugarise-doc-comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def block_trim(s):
lns = lns[:-1]

# remove leading horizontal whitespace
n = sys.maxint
n = sys.maxsize
for ln in lns:
if ln.strip():
n = min(n, len(re.search('^\s*', ln).group()))
if n != sys.maxint:
if n != sys.maxsize:
lns = [ln[n:] for ln in lns]

# strip trailing whitespace
Expand Down
6 changes: 5 additions & 1 deletion src/etc/test-float-parse/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@
from subprocess import Popen, check_call, PIPE
from glob import glob
import multiprocessing
import Queue
import threading
import ctypes
import binascii

try: # Python 3
import queue as Queue
except ImportError: # Python 2
import Queue

NUM_WORKERS = 2
UPDATE_EVERY_N = 50000
INF = namedtuple('INF', '')()
Expand Down
14 changes: 5 additions & 9 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ pub struct Mir<'tcx> {
/// in scope, but a separate set of locals.
pub promoted: IndexVec<Promoted, Mir<'tcx>>,

/// Return type of the function.
pub return_ty: Ty<'tcx>,

/// Yield type of the function, if it is a generator.
pub yield_ty: Option<Ty<'tcx>>,

Expand Down Expand Up @@ -135,7 +132,6 @@ impl<'tcx> Mir<'tcx> {
visibility_scope_info: ClearOnDecode<IndexVec<VisibilityScope,
VisibilityScopeInfo>>,
promoted: IndexVec<Promoted, Mir<'tcx>>,
return_ty: Ty<'tcx>,
yield_ty: Option<Ty<'tcx>>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
arg_count: usize,
Expand All @@ -145,14 +141,12 @@ impl<'tcx> Mir<'tcx> {
// We need `arg_count` locals, and one for the return pointer
assert!(local_decls.len() >= arg_count + 1,
"expected at least {} locals, got {}", arg_count + 1, local_decls.len());
assert_eq!(local_decls[RETURN_POINTER].ty, return_ty);

Mir {
basic_blocks,
visibility_scopes,
visibility_scope_info,
promoted,
return_ty,
yield_ty,
generator_drop: None,
generator_layout: None,
Expand Down Expand Up @@ -273,6 +267,11 @@ impl<'tcx> Mir<'tcx> {
&block.terminator().source_info
}
}

/// Return the return type, it always return first element from `local_decls` array
pub fn return_ty(&self) -> Ty<'tcx> {
self.local_decls[RETURN_POINTER].ty
}
}

#[derive(Clone, Debug)]
Expand All @@ -299,7 +298,6 @@ impl_stable_hash_for!(struct Mir<'tcx> {
visibility_scopes,
visibility_scope_info,
promoted,
return_ty,
yield_ty,
generator_drop,
generator_layout,
Expand Down Expand Up @@ -1744,7 +1742,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
visibility_scopes: self.visibility_scopes.clone(),
visibility_scope_info: self.visibility_scope_info.clone(),
promoted: self.promoted.fold_with(folder),
return_ty: self.return_ty.fold_with(folder),
yield_ty: self.yield_ty.fold_with(folder),
generator_drop: self.generator_drop.fold_with(folder),
generator_layout: self.generator_layout.fold_with(folder),
Expand All @@ -1763,7 +1760,6 @@ impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> {
self.generator_layout.visit_with(visitor) ||
self.yield_ty.visit_with(visitor) ||
self.promoted.visit_with(visitor) ||
self.return_ty.visit_with(visitor) ||
self.local_decls.visit_with(visitor)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ macro_rules! make_mir_visitor {
self.visit_visibility_scope_data(scope);
}

self.visit_ty(&$($mutability)* mir.return_ty, TyContext::ReturnTy(SourceInfo {
self.visit_ty(&$($mutability)* mir.return_ty(), TyContext::ReturnTy(SourceInfo {
span: mir.span,
scope: ARGUMENT_VISIBILITY_SCOPE,
}));
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_mir/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
}).collect()
});

let mut mir = builder.finish(upvar_decls, return_ty, yield_ty);
let mut mir = builder.finish(upvar_decls, yield_ty);
mir.spread_arg = spread_arg;
mir
}
Expand All @@ -469,7 +469,7 @@ fn construct_const<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
// Constants can't `return` so a return block should not be created.
assert_eq!(builder.cached_return_block, None);

builder.finish(vec![], ty, None)
builder.finish(vec![], None)
}

fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
Expand All @@ -481,7 +481,7 @@ fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty);
let source_info = builder.source_info(span);
builder.cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
builder.finish(vec![], ty, None)
builder.finish(vec![], None)
}

impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
Expand Down Expand Up @@ -524,7 +524,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

fn finish(self,
upvar_decls: Vec<UpvarDecl>,
return_ty: Ty<'tcx>,
yield_ty: Option<Ty<'tcx>>)
-> Mir<'tcx> {
for (index, block) in self.cfg.basic_blocks.iter().enumerate() {
Expand All @@ -537,7 +536,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
self.visibility_scopes,
ClearOnDecode::Set(self.visibility_scope_info),
IndexVec::new(),
return_ty,
yield_ty,
self.local_decls,
self.arg_count,
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls_for_sig(&sig, span),
sig.inputs().len(),
Expand Down Expand Up @@ -345,7 +344,6 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
),
ClearOnDecode::Clear,
IndexVec::new(),
self.sig.output(),
None,
self.local_decls,
self.sig.inputs().len(),
Expand Down Expand Up @@ -808,7 +806,6 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls,
sig.inputs().len(),
Expand Down Expand Up @@ -881,7 +878,6 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
),
ClearOnDecode::Clear,
IndexVec::new(),
sig.output(),
None,
local_decls,
sig.inputs().len(),
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ fn create_generator_drop_shim<'a, 'tcx>(
}

// Replace the return variable
mir.return_ty = tcx.mk_nil();
mir.local_decls[RETURN_POINTER] = LocalDecl {
mutability: Mutability::Mut,
ty: tcx.mk_nil(),
Expand Down Expand Up @@ -777,7 +776,7 @@ impl MirPass for StateTransform {
let state_did = tcx.lang_items().gen_state().unwrap();
let state_adt_ref = tcx.adt_def(state_did);
let state_substs = tcx.mk_substs([Kind::from(yield_ty),
Kind::from(mir.return_ty)].iter());
Kind::from(mir.return_ty())].iter());
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);

// We rename RETURN_POINTER which has type mir.return_ty to new_ret_local
Expand Down Expand Up @@ -808,7 +807,6 @@ impl MirPass for StateTransform {
transform.visit_mir(mir);

// Update our MIR struct to reflect the changed we've made
mir.return_ty = ret_ty;
mir.yield_ty = None;
mir.arg_count = 1;
mir.spread_arg = None;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
let span = self.promoted.span;
let new_operand = Operand::Constant(box Constant {
span,
ty: self.promoted.return_ty,
ty: self.promoted.return_ty(),
literal: Literal::Promoted {
index: Promoted::new(self.source.promoted.len())
}
Expand Down Expand Up @@ -385,7 +385,6 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
mir.visibility_scopes.clone(),
mir.visibility_scope_info.clone(),
IndexVec::new(),
ty,
None,
initial_locals,
0,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
// conservative type qualification instead.
if self.qualif.intersects(Qualif::CONST_ERROR) {
self.qualif = Qualif::empty();
let return_ty = mir.return_ty;
let return_ty = mir.return_ty();
self.add_type(return_ty);
}

Expand Down Expand Up @@ -938,7 +938,7 @@ fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// performing the steal.
let mir = &tcx.mir_const(def_id).borrow();

if mir.return_ty.references_error() {
if mir.return_ty().references_error() {
tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors");
return (Qualif::NOT_CONST.bits(), Rc::new(IdxSetBuf::new_empty(0)));
}
Expand All @@ -956,7 +956,7 @@ impl MirPass for QualifyAndPromoteConstants {
src: MirSource,
mir: &mut Mir<'tcx>) {
// There's not really any point in promoting errorful MIR.
if mir.return_ty.references_error() {
if mir.return_ty().references_error() {
tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: Mir had errors");
return;
}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ impl MirPass for QualifyAndPromoteConstants {
return;
}
}
let ty = mir.return_ty;
let ty = mir.return_ty();
tcx.infer_ctxt().enter(|infcx| {
let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
let cause = traits::ObligationCause::new(mir.span, id, traits::SharedStatic);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}

fn visit_mir(&mut self, mir: &Mir<'tcx>) {
self.sanitize_type(&"return type", mir.return_ty);
self.sanitize_type(&"return type", mir.return_ty());
for local_decl in &mir.local_decls {
self.sanitize_type(local_decl, local_decl.ty);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
write!(w, "{:?}: {}", Lvalue::Local(arg), escape(&mir.local_decls[arg].ty))?;
}

write!(w, ") -&gt; {}", escape(mir.return_ty))?;
write!(w, ") -&gt; {}", escape(mir.return_ty()))?;
write!(w, r#"<br align="left"/>"#)?;

for local in mir.vars_and_temps_iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
write!(w, "{:?}: {}", Lvalue::Local(arg), mir.local_decls[arg].ty)?;
}

write!(w, ") -> {}", mir.return_ty)
write!(w, ") -> {}", mir.return_ty())
}
(hir::BodyOwnerKind::Const, _) |
(hir::BodyOwnerKind::Static(_), _) |
(_, Some(_)) => {
assert_eq!(mir.arg_count, 0);
write!(w, ": {} =", mir.return_ty)
write!(w, ": {} =", mir.return_ty())
}
}
}
Expand Down
Loading

0 comments on commit 18250b0

Please sign in to comment.