Skip to content

Commit

Permalink
Report all lints, even if other errors already occurred.
Browse files Browse the repository at this point in the history
This reduces surprises of the "I fixed all the errors, now I'm getting new ones"-kind
  • Loading branch information
oli-obk committed May 11, 2023
1 parent 4d941cd commit f77c183
Show file tree
Hide file tree
Showing 91 changed files with 1,122 additions and 375 deletions.
9 changes: 0 additions & 9 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {

sess.time("layout_testing", || layout_test::test_layout(tcx));

// Avoid overwhelming user with errors if borrow checking failed.
// I'm not sure how helpful this is, to be honest, but it avoids a
// lot of annoying errors in the ui tests (basically,
// lint warnings and so on -- kindck used to do this abort, but
// kindck is gone now). -nmatsakis
if let Some(reported) = sess.has_errors() {
return Err(reported);
}

sess.time("misc_checking_3", || {
parallel!(
{
Expand Down
37 changes: 24 additions & 13 deletions tests/ui/borrowck/borrowck-access-permissions.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,59 @@
static static_x : i32 = 1;
static mut static_x_mut : i32 = 1;
static STATIC_X: i32 = 1;
static mut STATIC_X_MUT: i32 = 1;

fn main() {
let x = 1;
let mut x_mut = 1;

{ // borrow of local
{
// borrow of local
let _y1 = &mut x; //~ ERROR [E0596]
let _y2 = &mut x_mut; // No error
}

{ // borrow of static
let _y1 = &mut static_x; //~ ERROR [E0596]
unsafe { let _y2 = &mut static_x_mut; } // No error
{
// borrow of static
let _y1 = &mut STATIC_X; //~ ERROR [E0596]
unsafe {
let _y2 = &mut STATIC_X_MUT;
} // No error
}

{ // borrow of deref to box
{
// borrow of deref to box
let box_x = Box::new(1);
let mut box_x_mut = Box::new(1);

let _y1 = &mut *box_x; //~ ERROR [E0596]
let _y2 = &mut *box_x_mut; // No error
}

{ // borrow of deref to reference
{
// borrow of deref to reference
let ref_x = &x;
let ref_x_mut = &mut x_mut;

let _y1 = &mut *ref_x; //~ ERROR [E0596]
let _y2 = &mut *ref_x_mut; // No error
}

{ // borrow of deref to pointer
let ptr_x : *const _ = &x;
let ptr_mut_x : *mut _ = &mut x_mut;
{
// borrow of deref to pointer
let ptr_x: *const _ = &x;
let ptr_mut_x: *mut _ = &mut x_mut;

unsafe {
let _y1 = &mut *ptr_x; //~ ERROR [E0596]
let _y2 = &mut *ptr_mut_x; // No error
}
}

{ // borrowing mutably through an immutable reference
struct Foo<'a> { f: &'a mut i32, g: &'a i32 };
{
// borrowing mutably through an immutable reference
struct Foo<'a> {
f: &'a mut i32,
g: &'a i32,
};
let mut foo = Foo { f: &mut x_mut, g: &x };
let foo_ref = &foo;
let _y = &mut *foo_ref.f; //~ ERROR [E0596]
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/borrowck/borrowck-access-permissions.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:9:19
--> $DIR/borrowck-access-permissions.rs:10:19
|
LL | let _y1 = &mut x;
| ^^^^^^ cannot borrow as mutable
Expand All @@ -9,14 +9,14 @@ help: consider changing this to be mutable
LL | let mut x = 1;
| +++

error[E0596]: cannot borrow immutable static item `static_x` as mutable
--> $DIR/borrowck-access-permissions.rs:14:19
error[E0596]: cannot borrow immutable static item `STATIC_X` as mutable
--> $DIR/borrowck-access-permissions.rs:16:19
|
LL | let _y1 = &mut static_x;
LL | let _y1 = &mut STATIC_X;
| ^^^^^^^^^^^^^ cannot borrow as mutable

error[E0596]: cannot borrow `*box_x` as mutable, as `box_x` is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:22:19
--> $DIR/borrowck-access-permissions.rs:27:19
|
LL | let _y1 = &mut *box_x;
| ^^^^^^^^^^^ cannot borrow as mutable
Expand All @@ -27,7 +27,7 @@ LL | let mut box_x = Box::new(1);
| +++

error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:30:19
--> $DIR/borrowck-access-permissions.rs:36:19
|
LL | let _y1 = &mut *ref_x;
| ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
Expand All @@ -38,18 +38,18 @@ LL | let ref_x = &mut x;
| +++

error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrowck-access-permissions.rs:39:23
--> $DIR/borrowck-access-permissions.rs:46:23
|
LL | let _y1 = &mut *ptr_x;
| ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
|
help: consider changing this to be a mutable pointer
|
LL | let ptr_x : *const _ = &mut x;
| +++
LL | let ptr_x: *const _ = &mut x;
| +++

error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:48:18
--> $DIR/borrowck-access-permissions.rs:59:18
|
LL | let _y = &mut *foo_ref.f;
| ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/borrowck-assign-to-constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
static foo: isize = 5;
static FOO: isize = 5;

fn main() {
// assigning to various global constants
foo = 6; //~ ERROR cannot assign to immutable static item `foo`
FOO = 6; //~ ERROR cannot assign to immutable static item `FOO`
}
4 changes: 2 additions & 2 deletions tests/ui/borrowck/borrowck-assign-to-constants.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0594]: cannot assign to immutable static item `foo`
error[E0594]: cannot assign to immutable static item `FOO`
--> $DIR/borrowck-assign-to-constants.rs:5:5
|
LL | foo = 6;
LL | FOO = 6;
| ^^^^^^^ cannot assign

error: aborting due to previous error
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/issue-64453.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
struct Project;
struct Value;

static settings_dir: String = format!("");
static SETTINGS_DIR: String = format!("");
//~^ ERROR cannot call non-const fn
//~| ERROR is not yet stable as a const

Expand All @@ -11,7 +11,7 @@ fn from_string(_: String) -> Value {
fn set_editor(_: Value) {}

fn main() {
let settings_data = from_string(settings_dir);
let settings_data = from_string(SETTINGS_DIR);
//~^ ERROR cannot move out of static item
let args: i32 = 0;

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/borrowck/issue-64453.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: `Arguments::<'a>::new_const` is not yet stable as a const fn
--> $DIR/issue-64453.rs:4:31
|
LL | static settings_dir: String = format!("");
LL | static SETTINGS_DIR: String = format!("");
| ^^^^^^^^^^^
|
= help: add `#![feature(const_fmt_arguments_new)]` to the crate attributes to enable
Expand All @@ -10,18 +10,18 @@ LL | static settings_dir: String = format!("");
error[E0015]: cannot call non-const fn `format` in statics
--> $DIR/issue-64453.rs:4:31
|
LL | static settings_dir: String = format!("");
LL | static SETTINGS_DIR: String = format!("");
| ^^^^^^^^^^^
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0507]: cannot move out of static item `settings_dir`
error[E0507]: cannot move out of static item `SETTINGS_DIR`
--> $DIR/issue-64453.rs:14:37
|
LL | let settings_data = from_string(settings_dir);
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
LL | let settings_data = from_string(SETTINGS_DIR);
| ^^^^^^^^^^^^ move occurs because `SETTINGS_DIR` has type `String`, which does not implement the `Copy` trait

error: aborting due to 3 previous errors

Expand Down
24 changes: 14 additions & 10 deletions tests/ui/cleanup-rvalue-scopes-cf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use std::ops::Drop;

static mut FLAGS: u64 = 0;

struct StackBox<T> { f: T }
struct AddFlags { bits: u64 }
struct StackBox<T> {
f: T,
}
struct AddFlags {
bits: u64,
}

fn AddFlags(bits: u64) -> AddFlags {
fn add_flags(bits: u64) -> AddFlags {
AddFlags { bits: bits }
}

Expand All @@ -23,13 +27,13 @@ impl AddFlags {
}

pub fn main() {
let x1 = arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
let x2 = AddFlags(1).get(); //~ ERROR temporary value dropped while borrowed
let x3 = &*arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
let ref x4 = *arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
let &ref x5 = arg(&AddFlags(1)); //~ ERROR temporary value dropped while borrowed
let x6 = AddFlags(1).get(); //~ ERROR temporary value dropped while borrowed
let StackBox { f: x7 } = StackBox { f: AddFlags(1).get() };
let x1 = arg(&add_flags(1)); //~ ERROR temporary value dropped while borrowed
let x2 = add_flags(1).get(); //~ ERROR temporary value dropped while borrowed
let x3 = &*arg(&add_flags(1)); //~ ERROR temporary value dropped while borrowed
let ref x4 = *arg(&add_flags(1)); //~ ERROR temporary value dropped while borrowed
let &ref x5 = arg(&add_flags(1)); //~ ERROR temporary value dropped while borrowed
let x6 = add_flags(1).get(); //~ ERROR temporary value dropped while borrowed
let StackBox { f: x7 } = StackBox { f: add_flags(1).get() };
//~^ ERROR temporary value dropped while borrowed
(x1, x2, x3, x4, x5, x6, x7);
}
56 changes: 28 additions & 28 deletions tests/ui/cleanup-rvalue-scopes-cf.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:26:19
--> $DIR/cleanup-rvalue-scopes-cf.rs:30:19
|
LL | let x1 = arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let x1 = arg(&add_flags(1));
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -11,15 +11,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let x1 = arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:27:14
--> $DIR/cleanup-rvalue-scopes-cf.rs:31:14
|
LL | let x2 = AddFlags(1).get();
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let x2 = add_flags(1).get();
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -28,15 +28,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let x2 = binding.get();
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:28:21
--> $DIR/cleanup-rvalue-scopes-cf.rs:32:21
|
LL | let x3 = &*arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let x3 = &*arg(&add_flags(1));
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -45,15 +45,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let x3 = &*arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:29:24
--> $DIR/cleanup-rvalue-scopes-cf.rs:33:24
|
LL | let ref x4 = *arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let ref x4 = *arg(&add_flags(1));
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -62,15 +62,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let ref x4 = *arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:30:24
--> $DIR/cleanup-rvalue-scopes-cf.rs:34:24
|
LL | let &ref x5 = arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let &ref x5 = arg(&add_flags(1));
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -79,15 +79,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let &ref x5 = arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:31:14
--> $DIR/cleanup-rvalue-scopes-cf.rs:35:14
|
LL | let x6 = AddFlags(1).get();
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let x6 = add_flags(1).get();
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -96,15 +96,15 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let x6 = binding.get();
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:32:44
--> $DIR/cleanup-rvalue-scopes-cf.rs:36:44
|
LL | let StackBox { f: x7 } = StackBox { f: AddFlags(1).get() };
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
LL | let StackBox { f: x7 } = StackBox { f: add_flags(1).get() };
| ^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
LL |
Expand All @@ -113,7 +113,7 @@ LL | (x1, x2, x3, x4, x5, x6, x7);
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let binding = AddFlags(1);
LL ~ let binding = add_flags(1);
LL ~ let StackBox { f: x7 } = StackBox { f: binding.get() };
|

Expand Down
Loading

0 comments on commit f77c183

Please sign in to comment.