Skip to content

Commit

Permalink
Auto merge of #36049 - jonathandturner:rollup, r=jonathandturner
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

- Successful merges: #35657, #35980, #35985, #35989, #36003, #36044
- Failed merges:
  • Loading branch information
bors committed Aug 27, 2016
2 parents a23064a + d00a89a commit e17d6db
Show file tree
Hide file tree
Showing 39 changed files with 469 additions and 32 deletions.
45 changes: 44 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,50 @@ fn cookie() -> ! { // error: definition of an unknown language item: `cookie`
```
"##,

E0525: r##"
A closure was attempted to get used whereas it doesn't implement the expected
trait.
Erroneous code example:
```compile_fail,E0525
struct X;
fn foo<T>(_: T) {}
fn bar<T: Fn(u32)>(_: T) {}
fn main() {
let x = X;
let closure = |_| foo(x); // error: expected a closure that implements
// the `Fn` trait, but this closure only
// implements `FnOnce`
bar(closure);
}
```
In the example above, `closure` is an `FnOnce` closure whereas the `bar`
function expected an `Fn` closure. In this case, it's simple to fix the issue,
you just have to implement `Copy` and `Clone` traits on `struct X` and it'll
be ok:
```
#[derive(Clone, Copy)] // We implement `Clone` and `Copy` traits.
struct X;
fn foo<T>(_: T) {}
fn bar<T: Fn(u32)>(_: T) {}
fn main() {
let x = X;
let closure = |_| foo(x);
bar(closure); // ok!
}
```
To understand better how closures work in Rust, read:
https://doc.rust-lang.org/book/closures.html
"##,

}


Expand Down Expand Up @@ -1760,5 +1804,4 @@ register_diagnostics! {
E0490, // a value of type `..` is borrowed for too long
E0491, // in type `..`, reference has a longer lifetime than the data it...
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0525 // expected a closure that implements `..` but this closure only implements `..`
}
5 changes: 3 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,12 @@ pub trait LintContext: Sized {
"{}({}) overruled by outer forbid({})",
level.as_str(), lint_name,
lint_name);
diag_builder.span_label(span, &format!("overruled by previous forbid"));
match now_source {
LintSource::Default => &mut diag_builder,
LintSource::Node(forbid_source_span) => {
diag_builder.span_note(forbid_source_span,
"`forbid` lint level set here")
diag_builder.span_label(forbid_source_span,
&format!("`forbid` level set here"))
},
LintSource::CommandLine => {
diag_builder.note("`forbid` lint level was set on command line")
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
return;
}

let mut err = struct_span_err!(
self.tcx.sess, span, E0277,
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
"the trait bound `{}` is not satisfied",
trait_ref.to_predicate());
err.span_label(span, &format!("trait `{}` not satisfied",
trait_ref.to_predicate()));

// Try to report a help message

Expand Down
6 changes: 4 additions & 2 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
err
}
mc::AliasableBorrowed => {
struct_span_err!(
let mut e = struct_span_err!(
self.tcx.sess, span, E0389,
"{} in a `&` reference", prefix)
"{} in a `&` reference", prefix);
e.span_label(span, &"assignment into an immutable reference");
e
}
};

Expand Down
1 change: 0 additions & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ let Wrapping(x) = x;
let y: usize = 1.wrapping_neg();
assert_eq!(x, y);
```
"##
}

Expand Down
33 changes: 26 additions & 7 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,32 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}), ..}) => ty,
_ => expr_ty
}.ty_adt_def().unwrap();
let any_priv = def.struct_variant().fields.iter().any(|f| {
!f.vis.is_accessible_from(self.curitem, &self.tcx.map)
});
if any_priv {
span_err!(self.tcx.sess, expr.span, E0450,
"cannot invoke tuple struct constructor with private \
fields");

let private_indexes : Vec<_> = def.struct_variant().fields.iter().enumerate()
.filter(|&(_,f)| {
!f.vis.is_accessible_from(self.curitem, &self.tcx.map)
}).map(|(n,&_)|n).collect();

if !private_indexes.is_empty() {

let mut error = struct_span_err!(self.tcx.sess, expr.span, E0450,
"cannot invoke tuple struct constructor \
with private fields");
error.span_label(expr.span,
&format!("cannot construct with a private field"));

if let Some(def_id) = self.tcx.map.as_local_node_id(def.did) {
if let Some(hir::map::NodeItem(node)) = self.tcx.map.find(def_id) {
if let hir::Item_::ItemStruct(ref tuple_data, _) = node.node {

for i in private_indexes {
error.span_label(tuple_data.fields()[i].span,
&format!("private field declared here"));
}
}
}
}
error.emit();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_trans/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ extern "platform-intrinsic" {
fn simd_add<T>(a: T, b: T) -> T;
}
unsafe { simd_add(0, 1); }
// error: invalid monomorphization of `simd_add` intrinsic
fn main() {
unsafe { simd_add(0, 1); }
// error: invalid monomorphization of `simd_add` intrinsic
}
```
The generic type has to be a SIMD type. Example:
Expand Down
17 changes: 11 additions & 6 deletions src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ fn equate_intrinsic_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}));
let i_n_tps = i_ty.generics.types.len();
if i_n_tps != n_tps {
struct_span_err!(tcx.sess, it.span, E0094,
"intrinsic has wrong number of type \
parameters: found {}, expected {}",
i_n_tps, n_tps)
.span_label(it.span, &format!("expected {} type parameter", n_tps))
.emit();
let span = match it.node {
hir::ForeignItemFn(_, ref generics) => generics.span().unwrap_or(it.span),
hir::ForeignItemStatic(_, _) => it.span
};

struct_span_err!(tcx.sess, span, E0094,
"intrinsic has wrong number of type \
parameters: found {}, expected {}",
i_n_tps, n_tps)
.span_label(span, &format!("expected {} type parameter", n_tps))
.emit();
} else {
require_same_types(ccx,
TypeOrigin::IntrinsicType(it.span),
Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail-fulldeps/lint-plugin-forbid-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#![plugin(lint_plugin_test)]
#![forbid(test_lint)]
//~^ NOTE lint level defined here
//~| NOTE `forbid` lint level set here
//~| NOTE `forbid` level set here

fn lintme() { } //~ ERROR item is named 'lintme'

#[allow(test_lint)] //~ ERROR allow(test_lint) overruled by outer forbid(test_lint)
#[allow(test_lint)]
//~^ ERROR allow(test_lint) overruled by outer forbid(test_lint)
//~| NOTE overruled by previous forbid
pub fn main() {
lintme();
}
5 changes: 4 additions & 1 deletion src/test/compile-fail/E0277.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ fn some_func<T: Foo>(foo: T) {
}

fn main() {
some_func(5i32); //~ ERROR E0277
some_func(5i32);
//~^ ERROR the trait bound `i32: Foo` is not satisfied
//~| NOTE trait `i32: Foo` not satisfied
//~| NOTE required by `some_func`
}
1 change: 1 addition & 0 deletions src/test/compile-fail/E0389.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ fn main() {
let mut fancy = FancyNum{ num: 5 };
let fancy_ref = &(&mut fancy);
fancy_ref.num = 6; //~ ERROR E0389
//~^ NOTE assignment into an immutable reference
println!("{}", fancy_ref.num);
}
8 changes: 6 additions & 2 deletions src/test/compile-fail/E0450.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
// except according to those terms.

mod Bar {
pub struct Foo(isize);
pub struct Foo( bool, pub i32, f32, bool);
//~^ NOTE private field declared here
//~| NOTE private field declared here
//~| NOTE private field declared here
}

fn main() {
let f = Bar::Foo(0); //~ ERROR E0450
let f = Bar::Foo(false,1,0.1, true); //~ ERROR E0450
//~^ NOTE cannot construct with a private field
}
5 changes: 4 additions & 1 deletion src/test/compile-fail/E0453.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// except according to those terms.

#![forbid(non_snake_case)]
//~^ NOTE `forbid` level set here

#[allow(non_snake_case)] //~ ERROR E0453
#[allow(non_snake_case)]
//~^ ERROR allow(non_snake_case) overruled by outer forbid(non_snake_case)
//~| NOTE overruled by previous forbid
fn main() {
}
18 changes: 18 additions & 0 deletions src/test/compile-fail/E0502.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016 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.

fn bar(x: &mut i32) {}
fn foo(a: &mut i32) {
let ref y = a;
bar(a); //~ ERROR E0502
}

fn main() {
}
15 changes: 15 additions & 0 deletions src/test/compile-fail/E0503.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 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.

fn main() {
let mut value = 3;
let _borrow = &mut value;
let _sum = value + 1; //~ ERROR E0503
}
25 changes: 25 additions & 0 deletions src/test/compile-fail/E0504.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 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.

struct FancyNum {
num: u8,
}

fn main() {
let fancy_num = FancyNum { num: 5 };
let fancy_ref = &fancy_num;

let x = move || {
println!("child function: {}", fancy_num.num); //~ ERROR E0504
};

x();
println!("main function: {}", fancy_ref.num);
}
21 changes: 21 additions & 0 deletions src/test/compile-fail/E0505.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2016 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.

struct Value {}

fn eat(val: Value) {}

fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
eat(x); //~ ERROR E0505
}
}
21 changes: 21 additions & 0 deletions src/test/compile-fail/E0506.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2016 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.

struct FancyNum {
num: u8,
}

fn main() {
let mut fancy_num = FancyNum { num: 5 };
let fancy_ref = &fancy_num;
fancy_num = FancyNum { num: 6 }; //~ ERROR E0506

println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
}
23 changes: 23 additions & 0 deletions src/test/compile-fail/E0507.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2016 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 std::cell::RefCell;

struct TheDarkKnight;

impl TheDarkKnight {
fn nothing_is_true(self) {}
}

fn main() {
let x = RefCell::new(TheDarkKnight);

x.borrow().nothing_is_true(); //~ ERROR E0507
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/E0508.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 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.

struct NonCopy;

fn main() {
let array = [NonCopy; 1];
let _value = array[0]; //~ ERROR E0508
}
Loading

0 comments on commit e17d6db

Please sign in to comment.