Skip to content

Commit 9ca8831

Browse files
committed
Auto merge of #40440 - arielb1:rollup, r=arielb1
Rollup of 13 pull requests - Successful merges: #40146, #40299, #40315, #40319, #40344, #40345, #40367, #40372, #40373, #40385, #40400, #40404, #40431 - Failed merges:
2 parents 4b1dfbd + effb66c commit 9ca8831

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+615
-276
lines changed

src/libcore/fmt/mod.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,26 @@ pub trait Debug {
529529
#[stable(feature = "rust1", since = "1.0.0")]
530530
pub trait Display {
531531
/// Formats the value using the given formatter.
532+
///
533+
/// # Examples
534+
///
535+
/// ```
536+
/// use std::fmt;
537+
///
538+
/// struct Position {
539+
/// longitude: f32,
540+
/// latitude: f32,
541+
/// }
542+
///
543+
/// impl fmt::Display for Position {
544+
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545+
/// write!(f, "({}, {})", self.longitude, self.latitude)
546+
/// }
547+
/// }
548+
///
549+
/// assert_eq!("(1.987, 2.983)".to_owned(),
550+
/// format!("{}", Position { longitude: 1.987, latitude: 2.983, }));
551+
/// ```
532552
#[stable(feature = "rust1", since = "1.0.0")]
533553
fn fmt(&self, f: &mut Formatter) -> Result;
534554
}
@@ -930,7 +950,6 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
930950
}
931951

932952
impl<'a> Formatter<'a> {
933-
934953
// First up is the collection of functions used to execute a format string
935954
// at runtime. This consumes all of the compile-time statics generated by
936955
// the format! syntax extension.

src/librustc/infer/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ course, it depends on the program.
152152

153153
The main case which fails today that I would like to support is:
154154

155-
```text
155+
```rust
156156
fn foo<T>(x: T, y: T) { ... }
157157

158158
fn bar() {
@@ -168,6 +168,8 @@ because the type variable `T` is merged with the type variable for
168168
`X`, and thus inherits its UB/LB of `@mut int`. This leaves no
169169
flexibility for `T` to later adjust to accommodate `@int`.
170170

171+
Note: `@` and `@mut` are replaced with `Rc<T>` and `Rc<RefCell<T>>` in current Rust.
172+
171173
### What to do when not all bounds are present
172174

173175
In the prior discussion we assumed that A.ub was not top and B.lb was

src/librustc/infer/region_inference/README.md

+59-49
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,19 @@ every expression, block, and pattern (patterns are considered to
121121
"execute" by testing the value they are applied to and creating any
122122
relevant bindings). So, for example:
123123

124-
fn foo(x: isize, y: isize) { // -+
125-
// +------------+ // |
126-
// | +-----+ // |
127-
// | +-+ +-+ +-+ // |
128-
// | | | | | | | // |
129-
// v v v v v v v // |
130-
let z = x + y; // |
131-
... // |
132-
} // -+
133-
134-
fn bar() { ... }
124+
```rust
125+
fn foo(x: isize, y: isize) { // -+
126+
// +------------+ // |
127+
// | +-----+ // |
128+
// | +-+ +-+ +-+ // |
129+
// | | | | | | | // |
130+
// v v v v v v v // |
131+
let z = x + y; // |
132+
... // |
133+
} // -+
134+
135+
fn bar() { ... }
136+
```
135137

136138
In this example, there is a region for the fn body block as a whole,
137139
and then a subregion for the declaration of the local variable.
@@ -160,28 +162,32 @@ this, we get a lot of spurious errors around nested calls, in
160162
particular when combined with `&mut` functions. For example, a call
161163
like this one
162164

163-
self.foo(self.bar())
165+
```rust
166+
self.foo(self.bar())
167+
```
164168

165169
where both `foo` and `bar` are `&mut self` functions will always yield
166170
an error.
167171

168172
Here is a more involved example (which is safe) so we can see what's
169173
going on:
170174

171-
struct Foo { f: usize, g: usize }
172-
...
173-
fn add(p: &mut usize, v: usize) {
174-
*p += v;
175-
}
176-
...
177-
fn inc(p: &mut usize) -> usize {
178-
*p += 1; *p
179-
}
180-
fn weird() {
181-
let mut x: Box<Foo> = box Foo { ... };
182-
'a: add(&mut (*x).f,
183-
'b: inc(&mut (*x).f)) // (..)
184-
}
175+
```rust
176+
struct Foo { f: usize, g: usize }
177+
// ...
178+
fn add(p: &mut usize, v: usize) {
179+
*p += v;
180+
}
181+
// ...
182+
fn inc(p: &mut usize) -> usize {
183+
*p += 1; *p
184+
}
185+
fn weird() {
186+
let mut x: Box<Foo> = box Foo { /* ... */ };
187+
'a: add(&mut (*x).f,
188+
'b: inc(&mut (*x).f)) // (..)
189+
}
190+
```
185191

186192
The important part is the line marked `(..)` which contains a call to
187193
`add()`. The first argument is a mutable borrow of the field `f`. The
@@ -197,16 +203,18 @@ can see that this error is unnecessary. Let's examine the lifetimes
197203
involved with `'a` in detail. We'll break apart all the steps involved
198204
in a call expression:
199205

200-
'a: {
201-
'a_arg1: let a_temp1: ... = add;
202-
'a_arg2: let a_temp2: &'a mut usize = &'a mut (*x).f;
203-
'a_arg3: let a_temp3: usize = {
204-
let b_temp1: ... = inc;
205-
let b_temp2: &'b = &'b mut (*x).f;
206-
'b_call: b_temp1(b_temp2)
207-
};
208-
'a_call: a_temp1(a_temp2, a_temp3) // (**)
209-
}
206+
```rust
207+
'a: {
208+
'a_arg1: let a_temp1: ... = add;
209+
'a_arg2: let a_temp2: &'a mut usize = &'a mut (*x).f;
210+
'a_arg3: let a_temp3: usize = {
211+
let b_temp1: ... = inc;
212+
let b_temp2: &'b = &'b mut (*x).f;
213+
'b_call: b_temp1(b_temp2)
214+
};
215+
'a_call: a_temp1(a_temp2, a_temp3) // (**)
216+
}
217+
```
210218

211219
Here we see that the lifetime `'a` includes a number of substatements.
212220
In particular, there is this lifetime I've called `'a_call` that
@@ -225,19 +233,21 @@ it will not be *dereferenced* during the evaluation of the second
225233
argument, it can still be *invalidated* by that evaluation. Consider
226234
this similar but unsound example:
227235

228-
struct Foo { f: usize, g: usize }
229-
...
230-
fn add(p: &mut usize, v: usize) {
231-
*p += v;
232-
}
233-
...
234-
fn consume(x: Box<Foo>) -> usize {
235-
x.f + x.g
236-
}
237-
fn weird() {
238-
let mut x: Box<Foo> = box Foo { ... };
239-
'a: add(&mut (*x).f, consume(x)) // (..)
240-
}
236+
```rust
237+
struct Foo { f: usize, g: usize }
238+
// ...
239+
fn add(p: &mut usize, v: usize) {
240+
*p += v;
241+
}
242+
// ...
243+
fn consume(x: Box<Foo>) -> usize {
244+
x.f + x.g
245+
}
246+
fn weird() {
247+
let mut x: Box<Foo> = box Foo { ... };
248+
'a: add(&mut (*x).f, consume(x)) // (..)
249+
}
250+
```
241251

242252
In this case, the second argument to `add` actually consumes `x`, thus
243253
invalidating the first argument.

src/librustc/infer/region_inference/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
9191
};
9292

9393
if output_template.is_empty() {
94-
bug!("empty string provided as RUST_REGION_GRAPH");
94+
panic!("empty string provided as RUST_REGION_GRAPH");
9595
}
9696

9797
if output_template.contains('%') {

src/librustc/lint/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,12 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
806806
self.tables = old_tables;
807807
}
808808

809+
fn visit_body(&mut self, body: &'tcx hir::Body) {
810+
run_lints!(self, check_body, late_passes, body);
811+
hir_visit::walk_body(self, body);
812+
run_lints!(self, check_body_post, late_passes, body);
813+
}
814+
809815
fn visit_item(&mut self, it: &'tcx hir::Item) {
810816
self.with_lint_attrs(&it.attrs, |cx| {
811817
run_lints!(cx, check_item, late_passes, it);

src/librustc/lint/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ pub trait LintPass {
133133
// FIXME: eliminate the duplication with `Visitor`. But this also
134134
// contains a few lint-specific methods with no equivalent in `Visitor`.
135135
pub trait LateLintPass<'a, 'tcx>: LintPass {
136+
fn check_body(&mut self, _: &LateContext, _: &'tcx hir::Body) { }
137+
fn check_body_post(&mut self, _: &LateContext, _: &'tcx hir::Body) { }
136138
fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { }
137139
fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { }
138140
fn check_crate_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { }

src/librustc/traits/error_reporting.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,26 @@ use super::{
2323
ObjectSafetyViolation,
2424
};
2525

26+
use errors::DiagnosticBuilder;
2627
use fmt_macros::{Parser, Piece, Position};
28+
use hir::{intravisit, Local, Pat};
29+
use hir::intravisit::{Visitor, NestedVisitorMap};
30+
use hir::map::NodeExpr;
2731
use hir::def_id::DefId;
2832
use infer::{self, InferCtxt};
2933
use infer::type_variable::TypeVariableOrigin;
3034
use rustc::lint::builtin::EXTRA_REQUIREMENT_IN_IMPL;
35+
use std::fmt;
36+
use syntax::ast;
3137
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
3238
use ty::error::ExpectedFound;
3339
use ty::fast_reject;
3440
use ty::fold::TypeFolder;
3541
use ty::subst::Subst;
3642
use util::nodemap::{FxHashMap, FxHashSet};
3743

38-
use std::fmt;
39-
use syntax::ast;
40-
use hir::{intravisit, Local, Pat};
41-
use hir::intravisit::{Visitor, NestedVisitorMap};
4244
use syntax_pos::{DUMMY_SP, Span};
43-
use errors::DiagnosticBuilder;
45+
4446

4547
#[derive(Debug, PartialEq, Eq, Hash)]
4648
pub struct TraitErrorKey<'tcx> {
@@ -848,15 +850,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
848850

849851
err.span_label(cause.span, &format!("cannot infer type for `{}`", name));
850852

851-
let expr = self.tcx.hir.expect_expr(cause.body_id);
852-
853853
let mut local_visitor = FindLocalByTypeVisitor {
854854
infcx: &self,
855855
target_ty: &ty,
856856
found_pattern: None,
857857
};
858858

859-
local_visitor.visit_expr(expr);
859+
// #40294: cause.body_id can also be a fn declaration.
860+
// Currently, if it's anything other than NodeExpr, we just ignore it
861+
match self.tcx.hir.find(cause.body_id) {
862+
Some(NodeExpr(expr)) => local_visitor.visit_expr(expr),
863+
_ => ()
864+
}
860865

861866
if let Some(pattern) = local_visitor.found_pattern {
862867
let pattern_span = pattern.span;

src/librustc/traits/select.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24612461
let new_trait = tcx.mk_dynamic(
24622462
ty::Binder(tcx.mk_existential_predicates(iter)), r_b);
24632463
let InferOk { obligations, .. } =
2464-
self.infcx.sub_types(false, &obligation.cause, new_trait, target)
2464+
self.infcx.eq_types(false, &obligation.cause, new_trait, target)
24652465
.map_err(|_| Unimplemented)?;
24662466
self.inferred_obligations.extend(obligations);
24672467

@@ -2520,7 +2520,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25202520
// [T; n] -> [T].
25212521
(&ty::TyArray(a, _), &ty::TySlice(b)) => {
25222522
let InferOk { obligations, .. } =
2523-
self.infcx.sub_types(false, &obligation.cause, a, b)
2523+
self.infcx.eq_types(false, &obligation.cause, a, b)
25242524
.map_err(|_| Unimplemented)?;
25252525
self.inferred_obligations.extend(obligations);
25262526
}
@@ -2583,7 +2583,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
25832583
});
25842584
let new_struct = tcx.mk_adt(def, tcx.mk_substs(params));
25852585
let InferOk { obligations, .. } =
2586-
self.infcx.sub_types(false, &obligation.cause, new_struct, target)
2586+
self.infcx.eq_types(false, &obligation.cause, new_struct, target)
25872587
.map_err(|_| Unimplemented)?;
25882588
self.inferred_obligations.extend(obligations);
25892589

src/librustc_driver/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const ARM_WHITELIST: &'static [&'static str] = &["neon\0", "vfp2\0", "vfp3\0", "
2525
const X86_WHITELIST: &'static [&'static str] = &["avx\0", "avx2\0", "bmi\0", "bmi2\0", "sse\0",
2626
"sse2\0", "sse3\0", "sse4.1\0", "sse4.2\0",
2727
"ssse3\0", "tbm\0", "lzcnt\0", "popcnt\0",
28-
"sse4a\0", "rdrnd\0", "rdseed\0"];
28+
"sse4a\0", "rdrnd\0", "rdseed\0", "fma\0"];
2929

3030
/// Add `target_feature = "..."` cfgs for a variety of platform
3131
/// specific features (SSE, NEON etc.).

src/librustc_mir/build/expr/as_temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5555
(https://github.com/rust-lang/rust/issues/39283)");
5656
}
5757

58-
if temp_lifetime.is_some() {
58+
if !expr_ty.is_never() && temp_lifetime.is_some() {
5959
this.cfg.push(block, Statement {
6060
source_info: source_info,
6161
kind: StatementKind::StorageLive(temp.clone())

src/librustc_save_analysis/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
395395
}
396396
}
397397
None => {
398-
span_bug!(span, "Could not find container for method {}", id);
398+
debug!("Could not find container for method {} at {:?}", id, span);
399+
// This is not necessarily a bug, if there was a compilation error, the tables
400+
// we need might not exist.
401+
return None;
399402
}
400403
},
401404
};

src/librustc_trans/mir/analyze.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc::mir::visit::{Visitor, LvalueContext};
1818
use rustc::mir::traversal;
1919
use common;
2020
use super::MirContext;
21-
use super::rvalue;
2221

2322
pub fn lvalue_locals<'a, 'tcx>(mircx: &MirContext<'a, 'tcx>) -> BitVector {
2423
let mir = mircx.mir;
@@ -92,7 +91,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
9291

9392
if let mir::Lvalue::Local(index) = *lvalue {
9493
self.mark_assigned(index);
95-
if !rvalue::rvalue_creates_operand(rvalue) {
94+
if !self.cx.rvalue_creates_operand(rvalue) {
9695
self.mark_as_lvalue(index);
9796
}
9897
} else {

src/librustc_trans/mir/block.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,21 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
833833
self.trans_lvalue(bcx, dest)
834834
};
835835
if fn_ret_ty.is_indirect() {
836-
llargs.push(dest.llval);
837-
ReturnDest::Nothing
836+
match dest.alignment {
837+
Alignment::AbiAligned => {
838+
llargs.push(dest.llval);
839+
ReturnDest::Nothing
840+
},
841+
Alignment::Packed => {
842+
// Currently, MIR code generation does not create calls
843+
// that store directly to fields of packed structs (in
844+
// fact, the calls it creates write only to temps),
845+
//
846+
// If someone changes that, please update this code path
847+
// to create a temporary.
848+
span_bug!(self.mir.span, "can't directly store to unaligned value");
849+
}
850+
}
838851
} else {
839852
ReturnDest::Store(dest.llval)
840853
}

0 commit comments

Comments
 (0)