Skip to content

Commit 4f53b5c

Browse files
committed
Auto merge of #60888 - Manishearth:rollup-oihtoyq, r=Manishearth
Rollup of 5 pull requests Successful merges: - #60207 (Outdent example, preserving nested fence) - #60278 (Document the `html_root_url` doc attribute value.) - #60597 (Do some simple constant propagation in the ConstProp pass) - #60837 (Update release notes for 1.35.0) - #60887 (Update clippy) Failed merges: r? @ghost
2 parents 7d5aa43 + b80a906 commit 4f53b5c

File tree

9 files changed

+312
-21
lines changed

9 files changed

+312
-21
lines changed

RELEASES.md

+99-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,108 @@
1+
Version 1.35.0 (2019-05-23)
2+
==========================
3+
4+
Language
5+
--------
6+
- [`FnOnce`, `FnMut`, and the `Fn` traits are now implemented for `Box<FnOnce>`,
7+
`Box<FnMut>`, and `Box<Fn>` respectively.][59500]
8+
- [You can now coerce closures into unsafe function pointers.][59580] e.g.
9+
```rust
10+
unsafe fn call_unsafe(func: unsafe fn()) {
11+
func()
12+
}
13+
14+
pub fn main() {
15+
unsafe { call_unsafe(|| {}); }
16+
}
17+
```
18+
19+
20+
Compiler
21+
--------
22+
- [Added the `armv6-unknown-freebsd-gnueabihf` and
23+
`armv7-unknown-freebsd-gnueabihf` targets.][58080]
24+
- [Added the `wasm32-unknown-wasi` target.][59464]
25+
26+
27+
Libraries
28+
---------
29+
- [`Thread` will now show its ID in `Debug` output.][59460]
30+
- [`StdinLock`, `StdoutLock`, and `StderrLock` now implement `AsRawFd`.][59512]
31+
- [`alloc::System` now implements `Default`.][59451]
32+
- [Expanded `Debug` output (`{:#?}`) for structs now has a trailing comma on the
33+
last field.][59076]
34+
- [`char::{ToLowercase, ToUppercase}` now
35+
implement `ExactSizeIterator`.][58778]
36+
- [All `NonZero` numeric types now implement `FromStr`.][58717]
37+
- [Removed the `Read` trait bounds
38+
on the `BufReader::{get_ref, get_mut, into_inner}` methods.][58423]
39+
- [You can now call the `dbg!` macro without any parameters to print the file
40+
and line where it is called.][57847]
41+
- [In place ASCII case conversions are now up to 4× faster.][59283]
42+
e.g. `str::make_ascii_lowercase`
43+
- [`hash_map::{OccupiedEntry, VacantEntry}` now implement `Sync`
44+
and `Send`.][58369]
45+
46+
Stabilized APIs
47+
---------------
48+
- [`f32::copysign`]
49+
- [`f64::copysign`]
50+
- [`RefCell::replace_with`]
51+
- [`RefCell::map_split`]
52+
- [`ptr::hash`]
53+
- [`Range::contains`]
54+
- [`RangeFrom::contains`]
55+
- [`RangeTo::contains`]
56+
- [`RangeInclusive::contains`]
57+
- [`RangeToInclusive::contains`]
58+
- [`Option::copied`]
59+
60+
Cargo
61+
-----
62+
- [You can now set `cargo:rustc-cdylib-link-arg` at build time to pass custom
63+
linker arguments when building a `cdylib`.][cargo/6298] Its usage is highly
64+
platform specific.
65+
66+
Misc
67+
----
68+
- [The Rust toolchain is now available natively for musl based distros.][58575]
69+
70+
[59460]: https://github.com/rust-lang/rust/pull/59460/
71+
[59464]: https://github.com/rust-lang/rust/pull/59464/
72+
[59500]: https://github.com/rust-lang/rust/pull/59500/
73+
[59512]: https://github.com/rust-lang/rust/pull/59512/
74+
[59580]: https://github.com/rust-lang/rust/pull/59580/
75+
[59283]: https://github.com/rust-lang/rust/pull/59283/
76+
[59451]: https://github.com/rust-lang/rust/pull/59451/
77+
[59076]: https://github.com/rust-lang/rust/pull/59076/
78+
[58778]: https://github.com/rust-lang/rust/pull/58778/
79+
[58717]: https://github.com/rust-lang/rust/pull/58717/
80+
[58369]: https://github.com/rust-lang/rust/pull/58369/
81+
[58423]: https://github.com/rust-lang/rust/pull/58423/
82+
[58080]: https://github.com/rust-lang/rust/pull/58080/
83+
[57847]: https://github.com/rust-lang/rust/pull/57847/
84+
[58575]: https://github.com/rust-lang/rust/pull/58575
85+
[cargo/6298]: https://github.com/rust-lang/cargo/pull/6298/
86+
[`f32::copysign`]: https://doc.rust-lang.org/stable/std/primitive.f32.html#method.copysign
87+
[`f64::copysign`]: https://doc.rust-lang.org/stable/std/primitive.f64.html#method.copysign
88+
[`RefCell::replace_with`]: https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html#method.replace_with
89+
[`RefCell::map_split`]: https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html#method.map_split
90+
[`ptr::hash`]: https://doc.rust-lang.org/stable/std/ptr/fn.hash.html
91+
[`Range::contains`]: https://doc.rust-lang.org/std/ops/struct.Range.html#method.contains
92+
[`RangeFrom::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeFrom.html#method.contains
93+
[`RangeTo::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeTo.html#method.contains
94+
[`RangeInclusive::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html#method.contains
95+
[`RangeToInclusive::contains`]: https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html#method.contains
96+
[`Option::copied`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.copied
97+
198
Version 1.34.2 (2019-05-14)
299
===========================
3100

4101
* [Destabilize the `Error::type_id` function due to a security
5-
vulnerability][60785]
102+
vulnerability][60785] ([CVE-2019-12083])
6103

7104
[60785]: https://github.com/rust-lang/rust/pull/60785
105+
[CVE-2019-12083]: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-12083
8106

9107
Version 1.34.1 (2019-04-25)
10108
===========================

src/doc/rustdoc/src/the-doc-attribute.md

+15
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ the tracking issue.
9292
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
9393
```
9494

95+
### `html_root_url`
96+
97+
The `#[doc(html_root_url = "…")]` attribute value indicates the URL for
98+
generating links to external crates. When rustdoc needs to generate a link to
99+
an item in an external crate, it will first check if the extern crate has been
100+
documented locally on-disk, and if so link directly to it. Failing that, it
101+
will use the URL given by the `--extern-html-root-url` command-line flag if
102+
available. If that is not available, then it will use the `html_root_url`
103+
value in the extern crate if it is available. If that is not available, then
104+
the extern items will not be linked.
105+
106+
```rust,ignore
107+
#![doc(html_root_url = "https://docs.rs/serde/1.0")]
108+
```
109+
95110
### `html_no_source`
96111

97112
By default, `rustdoc` will include the source code of your program, with links

src/doc/rustdoc/src/what-is-rustdoc.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,21 @@ documentation for them as well!
9898
`rustdoc` can also generate HTML from standalone Markdown files. Let's
9999
give it a try: create a `README.md` file with these contents:
100100

101-
```text
102-
# Docs
101+
````text
102+
# Docs
103103
104-
This is a project to test out `rustdoc`.
104+
This is a project to test out `rustdoc`.
105105
106-
[Here is a link!](https://www.rust-lang.org)
106+
[Here is a link!](https://www.rust-lang.org)
107107
108-
## Subheading
108+
## Subheading
109109
110-
```rust
111-
fn foo() -> i32 {
112-
1 + 1
113-
}
114-
```
110+
```rust
111+
fn foo() -> i32 {
112+
1 + 1
113+
}
115114
```
115+
````
116116

117117
And call `rustdoc` on it:
118118

src/librustc_mir/transform/const_prop.rs

+62-9
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
44
use rustc::hir::def::DefKind;
55
use rustc::mir::{
6-
Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Local,
6+
AggregateKind, Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Local,
77
NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind,
88
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem,
99
SourceScope, SourceScopeLocalData, LocalDecl, Promoted,
1010
};
11-
use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext};
11+
use rustc::mir::visit::{
12+
Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext,
13+
};
1214
use rustc::mir::interpret::{InterpError, Scalar, GlobalId, EvalResult};
1315
use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
14-
use syntax::source_map::DUMMY_SP;
16+
use syntax_pos::{Span, DUMMY_SP};
1517
use rustc::ty::subst::InternalSubsts;
1618
use rustc_data_structures::indexed_vec::IndexVec;
1719
use rustc::ty::layout::{
1820
LayoutOf, TyLayout, LayoutError,
1921
HasTyCtxt, TargetDataLayout, HasDataLayout,
2022
};
2123

22-
use crate::interpret::{InterpretCx, ScalarMaybeUndef, Immediate, OpTy, ImmTy, MemoryKind};
24+
use crate::interpret::{self, InterpretCx, ScalarMaybeUndef, Immediate, OpTy, ImmTy, MemoryKind};
2325
use crate::const_eval::{
2426
CompileTimeInterpreter, error_to_const_error, eval_promoted, mk_eval_cx,
2527
};
@@ -497,6 +499,53 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
497499
},
498500
}
499501
}
502+
503+
fn operand_from_scalar(&self, scalar: Scalar, ty: Ty<'tcx>, span: Span) -> Operand<'tcx> {
504+
Operand::Constant(Box::new(
505+
Constant {
506+
span,
507+
ty,
508+
user_ty: None,
509+
literal: self.tcx.mk_const(ty::Const::from_scalar(
510+
scalar,
511+
ty,
512+
))
513+
}
514+
))
515+
}
516+
517+
fn replace_with_const(&self, rval: &mut Rvalue<'tcx>, value: Const<'tcx>, span: Span) {
518+
self.ecx.validate_operand(
519+
value,
520+
vec![],
521+
None,
522+
true,
523+
).expect("value should already be a valid const");
524+
525+
if let interpret::Operand::Immediate(im) = *value {
526+
match im {
527+
interpret::Immediate::Scalar(ScalarMaybeUndef::Scalar(scalar)) => {
528+
*rval = Rvalue::Use(self.operand_from_scalar(scalar, value.layout.ty, span));
529+
},
530+
Immediate::ScalarPair(
531+
ScalarMaybeUndef::Scalar(one),
532+
ScalarMaybeUndef::Scalar(two)
533+
) => {
534+
let ty = &value.layout.ty.sty;
535+
if let ty::Tuple(substs) = ty {
536+
*rval = Rvalue::Aggregate(
537+
Box::new(AggregateKind::Tuple),
538+
vec![
539+
self.operand_from_scalar(one, substs[0].expect_ty(), span),
540+
self.operand_from_scalar(two, substs[1].expect_ty(), span),
541+
],
542+
);
543+
}
544+
},
545+
_ => { }
546+
}
547+
}
548+
}
500549
}
501550

502551
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -560,10 +609,10 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
560609
}
561610
}
562611

563-
impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
612+
impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
564613
fn visit_constant(
565614
&mut self,
566-
constant: &Constant<'tcx>,
615+
constant: &mut Constant<'tcx>,
567616
location: Location,
568617
) {
569618
trace!("visit_constant: {:?}", constant);
@@ -573,11 +622,11 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
573622

574623
fn visit_statement(
575624
&mut self,
576-
statement: &Statement<'tcx>,
625+
statement: &mut Statement<'tcx>,
577626
location: Location,
578627
) {
579628
trace!("visit_statement: {:?}", statement);
580-
if let StatementKind::Assign(ref place, ref rval) = statement.kind {
629+
if let StatementKind::Assign(ref place, ref mut rval) = statement.kind {
581630
let place_ty: Ty<'tcx> = place
582631
.ty(&self.local_decls, self.tcx)
583632
.ty;
@@ -589,6 +638,10 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
589638
trace!("storing {:?} to {:?}", value, local);
590639
assert!(self.places[local].is_none());
591640
self.places[local] = Some(value);
641+
642+
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
643+
self.replace_with_const(rval, value, statement.source_info.span);
644+
}
592645
}
593646
}
594647
}
@@ -599,7 +652,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
599652

600653
fn visit_terminator(
601654
&mut self,
602-
terminator: &Terminator<'tcx>,
655+
terminator: &mut Terminator<'tcx>,
603656
location: Location,
604657
) {
605658
self.super_terminator(terminator, location);
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
fn main() {
2+
let x: u32 = [0, 1, 2, 3][2];
3+
}
4+
5+
// END RUST SOURCE
6+
// START rustc.main.ConstProp.before.mir
7+
// bb0: {
8+
// ...
9+
// _2 = [const 0u32, const 1u32, const 2u32, const 3u32];
10+
// ...
11+
// _3 = const 2usize;
12+
// _4 = const 4usize;
13+
// _5 = Lt(_3, _4);
14+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
15+
// }
16+
// bb1: {
17+
// _1 = _2[_3];
18+
// ...
19+
// return;
20+
// }
21+
// END rustc.main.ConstProp.before.mir
22+
// START rustc.main.ConstProp.after.mir
23+
// bb0: {
24+
// ...
25+
// _5 = const true;
26+
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
27+
// }
28+
// bb1: {
29+
// _1 = _2[_3];
30+
// ...
31+
// return;
32+
// }
33+
// END rustc.main.ConstProp.after.mir
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags: -C overflow-checks=on
2+
3+
fn main() {
4+
let x: u32 = 1 + 1;
5+
}
6+
7+
// END RUST SOURCE
8+
// START rustc.main.ConstProp.before.mir
9+
// bb0: {
10+
// ...
11+
// _2 = CheckedAdd(const 1u32, const 1u32);
12+
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
13+
// }
14+
// END rustc.main.ConstProp.before.mir
15+
// START rustc.main.ConstProp.after.mir
16+
// bb0: {
17+
// ...
18+
// _2 = (const 2u32, const false);
19+
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
20+
// }
21+
// END rustc.main.ConstProp.after.mir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[inline(never)]
2+
fn read(_: usize) { }
3+
4+
fn main() {
5+
const FOO: &i32 = &1;
6+
let x = FOO as *const i32 as usize;
7+
read(x);
8+
}
9+
10+
// END RUST SOURCE
11+
// START rustc.main.ConstProp.before.mir
12+
// bb0: {
13+
// ...
14+
// _3 = _4;
15+
// _2 = move _3 as *const i32 (Misc);
16+
// ...
17+
// _1 = move _2 as usize (Misc);
18+
// ...
19+
// _6 = _1;
20+
// _5 = const read(move _6) -> bb1;
21+
// }
22+
// END rustc.main.ConstProp.before.mir
23+
// START rustc.main.ConstProp.after.mir
24+
// bb0: {
25+
// ...
26+
// _3 = _4;
27+
// _2 = move _3 as *const i32 (Misc);
28+
// ...
29+
// _1 = move _2 as usize (Misc);
30+
// ...
31+
// _6 = _1;
32+
// _5 = const read(move _6) -> bb1;
33+
// }
34+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)