From 53e04742543c7034e1da912cc55cfa2a177b8c8b Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 17 May 2019 23:01:53 +0100 Subject: [PATCH 01/31] Add better tests for hidden lifetimes in impl trait --- src/test/ui/impl-trait/hidden-lifetimes.rs | 63 +++++++++++++++++++ .../ui/impl-trait/hidden-lifetimes.stderr | 27 ++++++++ src/test/ui/impl-trait/multiple-lifetimes.rs | 12 ++++ 3 files changed, 102 insertions(+) create mode 100644 src/test/ui/impl-trait/hidden-lifetimes.rs create mode 100644 src/test/ui/impl-trait/hidden-lifetimes.stderr create mode 100644 src/test/ui/impl-trait/multiple-lifetimes.rs diff --git a/src/test/ui/impl-trait/hidden-lifetimes.rs b/src/test/ui/impl-trait/hidden-lifetimes.rs new file mode 100644 index 0000000000000..2ee004a37a6fc --- /dev/null +++ b/src/test/ui/impl-trait/hidden-lifetimes.rs @@ -0,0 +1,63 @@ +// Test to show what happens if we were not careful and allowed invariant +// lifetimes to escape though an impl trait. +// +// Specifically we swap a long lived and short lived reference, giving us a +// dangling pointer. + +use std::cell::RefCell; +use std::rc::Rc; + +trait Swap: Sized { + fn swap(self, other: Self); +} + +impl Swap for &mut T { + fn swap(self, other: Self) { + std::mem::swap(self, other); + } +} + +impl Swap for Rc> { + fn swap(self, other: Self) { + >::swap(&self, &other); + } +} + +// Here we are hiding `'b` making the caller believe that `&'a mut &'s T` and +// `&'a mut &'l T` are the same type. +fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { + //~^ ERROR hidden type + x +} + +fn dangle_ref() -> &'static [i32; 3] { + let mut res = &[4, 5, 6]; + let x = [1, 2, 3]; + hide_ref(&mut res).swap(hide_ref(&mut &x)); + res +} + +// Here we are hiding `'b` making the caller believe that `Rc>` +// and `Rc>` are the same type. +// +// This is different to the previous example because the concrete return type +// only has a single lifetime. +fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { + //~^ ERROR hidden type + x +} + +fn dangle_rc_refcell() -> &'static [i32; 3] { + let long = Rc::new(RefCell::new(&[4, 5, 6])); + let x = [1, 2, 3]; + let short = Rc::new(RefCell::new(&x)); + hide_rc_refcell(long.clone()).swap(hide_rc_refcell(short)); + let res: &'static [i32; 3] = *long.borrow(); + res +} + +fn main() { + // both will print nonsense values. + println!("{:?}", dangle_ref()); + println!("{:?}", dangle_rc_refcell()) +} diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr new file mode 100644 index 0000000000000..650161753d1e5 --- /dev/null +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -0,0 +1,27 @@ +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/hidden-lifetimes.rs:28:54 + | +LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { + | ^^^^^^^^^^^^^^ + | +note: hidden type `&'a mut &'b T` captures the lifetime 'b as defined on the function body at 28:17 + --> $DIR/hidden-lifetimes.rs:28:17 + | +LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { + | ^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/hidden-lifetimes.rs:45:70 + | +LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { + | ^^^^^^^^^^^^^^ + | +note: hidden type `std::rc::Rc>` captures the lifetime 'b as defined on the function body at 45:24 + --> $DIR/hidden-lifetimes.rs:45:24 + | +LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { + | ^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes.rs b/src/test/ui/impl-trait/multiple-lifetimes.rs new file mode 100644 index 0000000000000..8346542135bec --- /dev/null +++ b/src/test/ui/impl-trait/multiple-lifetimes.rs @@ -0,0 +1,12 @@ +// Test that multiple liftimes are allowed in impl trait types. +// compile-pass + +trait X<'x>: Sized {} + +impl X<'_> for U {} + +fn multiple_lifeteimes<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl X<'b> + 'a { + x +} + +fn main() {} From fb52aeafc97f4927e7dcc178a81bc005c3dc0015 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 22 May 2019 01:09:58 +0300 Subject: [PATCH 02/31] tests: Centralize proc macros commonly used for testing --- src/test/ui/custom-derive/auxiliary/plugin.rs | 28 ----- src/test/ui/custom-derive/derive-in-mod.rs | 13 --- .../helper-attr-blocked-by-import-ambig.rs | 12 -- ...helper-attr-blocked-by-import-ambig.stderr | 21 ---- .../helper-attr-blocked-by-import.rs | 28 ----- src/test/ui/custom-derive/issue-36935.rs | 12 -- src/test/ui/custom-derive/issue-36935.stderr | 10 -- .../proc-macro/attribute-order-restricted.rs | 10 +- .../attribute-order-restricted.stderr | 4 +- .../ui/proc-macro/attribute-with-error.rs | 17 ++- .../ui/proc-macro/attribute-with-error.stderr | 8 +- .../proc-macro/auxiliary/attr_proc_macro.rs | 13 --- .../auxiliary/attribute-with-error.rs | 13 --- .../proc-macro/auxiliary/bang_proc_macro.rs | 13 --- .../ui/proc-macro/auxiliary/derive-a-b.rs | 17 --- src/test/ui/proc-macro/auxiliary/derive-a.rs | 13 --- .../auxiliary/derive-helper-shadowed-2.rs | 2 +- .../auxiliary/derive-helper-shadowed.rs | 12 -- .../auxiliary/derive-helper-shadowing.rs | 17 --- .../ui/proc-macro/auxiliary/derive-panic.rs | 13 --- .../auxiliary/dollar-crate-external.rs | 6 +- .../ui/proc-macro/auxiliary/dollar-crate.rs | 35 ------ .../ui/proc-macro/auxiliary/issue-41211.rs | 12 -- .../ui/proc-macro/auxiliary/issue-53481.rs | 13 --- .../ui/proc-macro/auxiliary/macro-brackets.rs | 12 -- .../proc-macro/auxiliary/nested-item-spans.rs | 13 --- .../proc-macro/auxiliary/proc-macro-gates.rs | 18 --- .../proc-macro/auxiliary/span-preservation.rs | 13 --- .../ui/proc-macro/auxiliary/test-macros.rs | 104 ++++++++++++++++-- .../ui/proc-macro/derive-helper-shadowed.rs | 12 +- .../ui/proc-macro/derive-helper-shadowing.rs | 20 ++-- .../proc-macro/derive-helper-shadowing.stderr | 34 +++--- src/test/ui/proc-macro/derive-in-mod.rs | 13 +++ src/test/ui/proc-macro/derive-still-gated.rs | 8 +- .../ui/proc-macro/derive-still-gated.stderr | 8 +- .../ui/proc-macro/dollar-crate-issue-57089.rs | 9 +- .../dollar-crate-issue-57089.stdout | 9 +- src/test/ui/proc-macro/dollar-crate.rs | 13 +-- src/test/ui/proc-macro/dollar-crate.stderr | 4 +- src/test/ui/proc-macro/dollar-crate.stdout | 28 +++-- .../helper-attr-blocked-by-import-ambig.rs | 11 ++ ...helper-attr-blocked-by-import-ambig.stderr | 21 ++++ .../helper-attr-blocked-by-import.rs | 28 +++++ src/test/ui/proc-macro/import.rs | 11 +- src/test/ui/proc-macro/import.stderr | 8 +- src/test/ui/proc-macro/issue-36935.rs | 12 ++ src/test/ui/proc-macro/issue-36935.stderr | 10 ++ src/test/ui/proc-macro/issue-37788.rs | 4 +- src/test/ui/proc-macro/issue-41211.rs | 10 +- src/test/ui/proc-macro/issue-41211.stderr | 10 +- src/test/ui/proc-macro/issue-53481.rs | 14 +-- src/test/ui/proc-macro/load-panic.rs | 7 +- src/test/ui/proc-macro/load-panic.stderr | 8 +- src/test/ui/proc-macro/macro-brackets.rs | 8 +- src/test/ui/proc-macro/macro-use-attr.rs | 7 +- src/test/ui/proc-macro/macro-use-bang.rs | 6 +- src/test/ui/proc-macro/macros-in-extern.rs | 9 +- .../ui/proc-macro/macros-in-extern.stderr | 18 +-- src/test/ui/proc-macro/nested-item-spans.rs | 11 +- .../ui/proc-macro/nested-item-spans.stderr | 4 +- src/test/ui/proc-macro/no-macro-use-attr.rs | 4 +- .../ui/proc-macro/no-macro-use-attr.stderr | 4 +- src/test/ui/proc-macro/proc-macro-gates.rs | 43 ++++---- .../ui/proc-macro/proc-macro-gates.stderr | 98 ++++++++--------- src/test/ui/proc-macro/proc-macro-gates2.rs | 11 +- .../ui/proc-macro/proc-macro-gates2.stderr | 16 +-- src/test/ui/proc-macro/resolve-error.rs | 10 +- src/test/ui/proc-macro/resolve-error.stderr | 16 +-- src/test/ui/proc-macro/shadow.rs | 6 +- src/test/ui/proc-macro/shadow.stderr | 12 +- src/test/ui/proc-macro/span-preservation.rs | 17 ++- .../ui/proc-macro/span-preservation.stderr | 10 +- 72 files changed, 475 insertions(+), 649 deletions(-) delete mode 100644 src/test/ui/custom-derive/auxiliary/plugin.rs delete mode 100644 src/test/ui/custom-derive/derive-in-mod.rs delete mode 100644 src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.rs delete mode 100644 src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.stderr delete mode 100644 src/test/ui/custom-derive/helper-attr-blocked-by-import.rs delete mode 100644 src/test/ui/custom-derive/issue-36935.rs delete mode 100644 src/test/ui/custom-derive/issue-36935.stderr delete mode 100644 src/test/ui/proc-macro/auxiliary/attr_proc_macro.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/attribute-with-error.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/bang_proc_macro.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/derive-a-b.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/derive-a.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/derive-helper-shadowed.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/derive-panic.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/dollar-crate.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/issue-41211.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/issue-53481.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/macro-brackets.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/nested-item-spans.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/proc-macro-gates.rs delete mode 100644 src/test/ui/proc-macro/auxiliary/span-preservation.rs create mode 100644 src/test/ui/proc-macro/derive-in-mod.rs create mode 100644 src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.rs create mode 100644 src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr create mode 100644 src/test/ui/proc-macro/helper-attr-blocked-by-import.rs create mode 100644 src/test/ui/proc-macro/issue-36935.rs create mode 100644 src/test/ui/proc-macro/issue-36935.stderr diff --git a/src/test/ui/custom-derive/auxiliary/plugin.rs b/src/test/ui/custom-derive/auxiliary/plugin.rs deleted file mode 100644 index 5e500de607c1a..0000000000000 --- a/src/test/ui/custom-derive/auxiliary/plugin.rs +++ /dev/null @@ -1,28 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_derive(Foo)] -pub fn derive_foo(input: TokenStream) -> TokenStream { - input -} - -#[proc_macro_derive(Bar)] -pub fn derive_bar(input: TokenStream) -> TokenStream { - panic!("lolnope"); -} - -#[proc_macro_derive(WithHelper, attributes(helper))] -pub fn with_helper(input: TokenStream) -> TokenStream { - TokenStream::new() -} - -#[proc_macro_attribute] -pub fn helper(_: TokenStream, input: TokenStream) -> TokenStream { - input -} diff --git a/src/test/ui/custom-derive/derive-in-mod.rs b/src/test/ui/custom-derive/derive-in-mod.rs deleted file mode 100644 index 8478ff1a6ae6c..0000000000000 --- a/src/test/ui/custom-derive/derive-in-mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -// compile-pass -// aux-build:plugin.rs - -extern crate plugin; - -mod inner { - use plugin::WithHelper; - - #[derive(WithHelper)] - struct S; -} - -fn main() {} diff --git a/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.rs b/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.rs deleted file mode 100644 index ba072ba3568b7..0000000000000 --- a/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.rs +++ /dev/null @@ -1,12 +0,0 @@ -// aux-build:plugin.rs - -#[macro_use(WithHelper)] -extern crate plugin; - -use plugin::helper; - -#[derive(WithHelper)] -#[helper] //~ ERROR `helper` is ambiguous -struct S; - -fn main() {} diff --git a/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.stderr b/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.stderr deleted file mode 100644 index e83c291c9bfe4..0000000000000 --- a/src/test/ui/custom-derive/helper-attr-blocked-by-import-ambig.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0659]: `helper` is ambiguous (derive helper attribute vs any other name) - --> $DIR/helper-attr-blocked-by-import-ambig.rs:9:3 - | -LL | #[helper] - | ^^^^^^ ambiguous name - | -note: `helper` could refer to the derive helper attribute defined here - --> $DIR/helper-attr-blocked-by-import-ambig.rs:8:10 - | -LL | #[derive(WithHelper)] - | ^^^^^^^^^^ -note: `helper` could also refer to the attribute macro imported here - --> $DIR/helper-attr-blocked-by-import-ambig.rs:6:5 - | -LL | use plugin::helper; - | ^^^^^^^^^^^^^^ - = help: use `crate::helper` to refer to this attribute macro unambiguously - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0659`. diff --git a/src/test/ui/custom-derive/helper-attr-blocked-by-import.rs b/src/test/ui/custom-derive/helper-attr-blocked-by-import.rs deleted file mode 100644 index abbf014f55337..0000000000000 --- a/src/test/ui/custom-derive/helper-attr-blocked-by-import.rs +++ /dev/null @@ -1,28 +0,0 @@ -// compile-pass -// aux-build:plugin.rs - -#[macro_use(WithHelper)] -extern crate plugin; - -use self::one::*; -use self::two::*; - -mod helper {} - -mod one { - use helper; - - #[derive(WithHelper)] - #[helper] - struct One; -} - -mod two { - use helper; - - #[derive(WithHelper)] - #[helper] - struct Two; -} - -fn main() {} diff --git a/src/test/ui/custom-derive/issue-36935.rs b/src/test/ui/custom-derive/issue-36935.rs deleted file mode 100644 index 7a5d19f771f3c..0000000000000 --- a/src/test/ui/custom-derive/issue-36935.rs +++ /dev/null @@ -1,12 +0,0 @@ -// aux-build:plugin.rs - - -#[macro_use] extern crate plugin; - -#[derive(Foo, Bar)] //~ ERROR proc-macro derive panicked -struct Baz { - a: i32, - b: i32, -} - -fn main() {} diff --git a/src/test/ui/custom-derive/issue-36935.stderr b/src/test/ui/custom-derive/issue-36935.stderr deleted file mode 100644 index 2875bc5fce99b..0000000000000 --- a/src/test/ui/custom-derive/issue-36935.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: proc-macro derive panicked - --> $DIR/issue-36935.rs:6:15 - | -LL | #[derive(Foo, Bar)] - | ^^^ - | - = help: message: lolnope - -error: aborting due to previous error - diff --git a/src/test/ui/proc-macro/attribute-order-restricted.rs b/src/test/ui/proc-macro/attribute-order-restricted.rs index 7b1eecd155865..a3d4d23450ca6 100644 --- a/src/test/ui/proc-macro/attribute-order-restricted.rs +++ b/src/test/ui/proc-macro/attribute-order-restricted.rs @@ -1,14 +1,14 @@ -// aux-build:attr_proc_macro.rs +// aux-build:test-macros.rs -extern crate attr_proc_macro; -use attr_proc_macro::*; +#[macro_use] +extern crate test_macros; -#[attr_proc_macro] // OK +#[identity_attr] // OK #[derive(Clone)] struct Before; #[derive(Clone)] -#[attr_proc_macro] //~ ERROR macro attributes must be placed before `#[derive]` +#[identity_attr] //~ ERROR macro attributes must be placed before `#[derive]` struct After; fn main() {} diff --git a/src/test/ui/proc-macro/attribute-order-restricted.stderr b/src/test/ui/proc-macro/attribute-order-restricted.stderr index 39db45cf569a7..9ca8a443e40fb 100644 --- a/src/test/ui/proc-macro/attribute-order-restricted.stderr +++ b/src/test/ui/proc-macro/attribute-order-restricted.stderr @@ -1,8 +1,8 @@ error: macro attributes must be placed before `#[derive]` --> $DIR/attribute-order-restricted.rs:11:1 | -LL | #[attr_proc_macro] - | ^^^^^^^^^^^^^^^^^^ +LL | #[identity_attr] + | ^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/proc-macro/attribute-with-error.rs b/src/test/ui/proc-macro/attribute-with-error.rs index 2cced40830a74..aaa6c07dddbbd 100644 --- a/src/test/ui/proc-macro/attribute-with-error.rs +++ b/src/test/ui/proc-macro/attribute-with-error.rs @@ -1,12 +1,11 @@ -// aux-build:attribute-with-error.rs +// aux-build:test-macros.rs #![feature(custom_inner_attributes)] -extern crate attribute_with_error; +#[macro_use] +extern crate test_macros; -use attribute_with_error::foo; - -#[foo] +#[recollect_attr] fn test1() { let a: i32 = "foo"; //~^ ERROR: mismatched types @@ -15,13 +14,13 @@ fn test1() { } fn test2() { - #![foo] + #![recollect_attr] // FIXME: should have a type error here and assert it works but it doesn't } trait A { - // FIXME: should have a #[foo] attribute here and assert that it works + // FIXME: should have a #[recollect_attr] attribute here and assert that it works fn foo(&self) { let a: i32 = "foo"; //~^ ERROR: mismatched types @@ -31,13 +30,13 @@ trait A { struct B; impl A for B { - #[foo] + #[recollect_attr] fn foo(&self) { let a: i32 = "foo"; //~^ ERROR: mismatched types } } -#[foo] +#[recollect_attr] fn main() { } diff --git a/src/test/ui/proc-macro/attribute-with-error.stderr b/src/test/ui/proc-macro/attribute-with-error.stderr index c5970ab6baaf8..937d47ff08979 100644 --- a/src/test/ui/proc-macro/attribute-with-error.stderr +++ b/src/test/ui/proc-macro/attribute-with-error.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/attribute-with-error.rs:11:18 + --> $DIR/attribute-with-error.rs:10:18 | LL | let a: i32 = "foo"; | ^^^^^ expected i32, found reference @@ -8,7 +8,7 @@ LL | let a: i32 = "foo"; found type `&'static str` error[E0308]: mismatched types - --> $DIR/attribute-with-error.rs:13:18 + --> $DIR/attribute-with-error.rs:12:18 | LL | let b: i32 = "f'oo"; | ^^^^^^ expected i32, found reference @@ -17,7 +17,7 @@ LL | let b: i32 = "f'oo"; found type `&'static str` error[E0308]: mismatched types - --> $DIR/attribute-with-error.rs:26:22 + --> $DIR/attribute-with-error.rs:25:22 | LL | let a: i32 = "foo"; | ^^^^^ expected i32, found reference @@ -26,7 +26,7 @@ LL | let a: i32 = "foo"; found type `&'static str` error[E0308]: mismatched types - --> $DIR/attribute-with-error.rs:36:22 + --> $DIR/attribute-with-error.rs:35:22 | LL | let a: i32 = "foo"; | ^^^^^ expected i32, found reference diff --git a/src/test/ui/proc-macro/auxiliary/attr_proc_macro.rs b/src/test/ui/proc-macro/auxiliary/attr_proc_macro.rs deleted file mode 100644 index b1f54be6bac4b..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/attr_proc_macro.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_attribute] -pub fn attr_proc_macro(_: TokenStream, input: TokenStream) -> TokenStream { - input -} diff --git a/src/test/ui/proc-macro/auxiliary/attribute-with-error.rs b/src/test/ui/proc-macro/auxiliary/attribute-with-error.rs deleted file mode 100644 index c073be0031019..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/attribute-with-error.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_attribute] -pub fn foo(_attr: TokenStream, input: TokenStream) -> TokenStream { - input.into_iter().collect() -} diff --git a/src/test/ui/proc-macro/auxiliary/bang_proc_macro.rs b/src/test/ui/proc-macro/auxiliary/bang_proc_macro.rs deleted file mode 100644 index 16f3b7640290d..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/bang_proc_macro.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro] -pub fn bang_proc_macro(input: TokenStream) -> TokenStream { - input -} diff --git a/src/test/ui/proc-macro/auxiliary/derive-a-b.rs b/src/test/ui/proc-macro/auxiliary/derive-a-b.rs deleted file mode 100644 index 64d4e0f7b7ae5..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/derive-a-b.rs +++ /dev/null @@ -1,17 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::TokenStream; - -#[proc_macro_derive(A)] -pub fn derive_a(_: TokenStream) -> TokenStream { - "".parse().unwrap() -} - -#[proc_macro_derive(B)] -pub fn derive_b(_: TokenStream) -> TokenStream { - "".parse().unwrap() -} diff --git a/src/test/ui/proc-macro/auxiliary/derive-a.rs b/src/test/ui/proc-macro/auxiliary/derive-a.rs deleted file mode 100644 index c9d94aba9f756..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/derive-a.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_derive(A)] -pub fn derive_a(input: TokenStream) -> TokenStream { - "".parse().unwrap() -} diff --git a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed-2.rs b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed-2.rs index 9912a89dafb3f..ab532da299224 100644 --- a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed-2.rs +++ b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed-2.rs @@ -1,2 +1,2 @@ #[macro_export] -macro_rules! my_attr { () => () } +macro_rules! empty_helper { () => () } diff --git a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed.rs b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed.rs deleted file mode 100644 index 5b5243dd60ee3..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowed.rs +++ /dev/null @@ -1,12 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::*; - -#[proc_macro_derive(MyTrait, attributes(my_attr))] -pub fn foo(_: TokenStream) -> TokenStream { - TokenStream::new() -} diff --git a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs deleted file mode 100644 index 6e0bdcba9c50f..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs +++ /dev/null @@ -1,17 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::*; - -#[proc_macro_attribute] -pub fn my_attr(_: TokenStream, input: TokenStream) -> TokenStream { - input -} - -#[proc_macro_derive(MyTrait, attributes(my_attr))] -pub fn derive(input: TokenStream) -> TokenStream { - TokenStream::new() -} diff --git a/src/test/ui/proc-macro/auxiliary/derive-panic.rs b/src/test/ui/proc-macro/auxiliary/derive-panic.rs deleted file mode 100644 index e2afa7affa302..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/derive-panic.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_derive(A)] -pub fn derive_a(_input: TokenStream) -> TokenStream { - panic!("nope!"); -} diff --git a/src/test/ui/proc-macro/auxiliary/dollar-crate-external.rs b/src/test/ui/proc-macro/auxiliary/dollar-crate-external.rs index 8f15a2b975bf3..d5d393b5a6457 100644 --- a/src/test/ui/proc-macro/auxiliary/dollar-crate-external.rs +++ b/src/test/ui/proc-macro/auxiliary/dollar-crate-external.rs @@ -3,14 +3,14 @@ pub type S = u8; #[macro_export] macro_rules! external { () => { - dollar_crate::m! { + print_bang! { struct M($crate::S); } - #[dollar_crate::a] + #[print_attr] struct A($crate::S); - #[derive(dollar_crate::d)] + #[derive(Print)] struct D($crate::S); }; } diff --git a/src/test/ui/proc-macro/auxiliary/dollar-crate.rs b/src/test/ui/proc-macro/auxiliary/dollar-crate.rs deleted file mode 100644 index c5347d2e81a6b..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/dollar-crate.rs +++ /dev/null @@ -1,35 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::TokenStream; - -#[proc_macro] -pub fn m_empty(input: TokenStream) -> TokenStream { - println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input); - println!("PROC MACRO INPUT: {:#?}", input); - TokenStream::new() -} - -#[proc_macro] -pub fn m(input: TokenStream) -> TokenStream { - println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input); - println!("PROC MACRO INPUT: {:#?}", input); - input.into_iter().collect() -} - -#[proc_macro_attribute] -pub fn a(_args: TokenStream, input: TokenStream) -> TokenStream { - println!("ATTRIBUTE INPUT (PRETTY-PRINTED): {}", input); - println!("ATTRIBUTE INPUT: {:#?}", input); - input.into_iter().collect() -} - -#[proc_macro_derive(d)] -pub fn d(input: TokenStream) -> TokenStream { - println!("DERIVE INPUT (PRETTY-PRINTED): {}", input); - println!("DERIVE INPUT: {:#?}", input); - input.into_iter().collect() -} diff --git a/src/test/ui/proc-macro/auxiliary/issue-41211.rs b/src/test/ui/proc-macro/auxiliary/issue-41211.rs deleted file mode 100644 index db946e7f331ca..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/issue-41211.rs +++ /dev/null @@ -1,12 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::TokenStream; - -#[proc_macro_attribute] -pub fn emit_unchanged(_args: TokenStream, input: TokenStream) -> TokenStream { - input -} diff --git a/src/test/ui/proc-macro/auxiliary/issue-53481.rs b/src/test/ui/proc-macro/auxiliary/issue-53481.rs deleted file mode 100644 index d9f290dec7ef9..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/issue-53481.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::*; - -#[proc_macro_derive(MyTrait, attributes(my_attr))] -pub fn foo(_: TokenStream) -> TokenStream { - TokenStream::new() -} diff --git a/src/test/ui/proc-macro/auxiliary/macro-brackets.rs b/src/test/ui/proc-macro/auxiliary/macro-brackets.rs deleted file mode 100644 index f2c62ab1b5ef0..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/macro-brackets.rs +++ /dev/null @@ -1,12 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; -use proc_macro::*; - -#[proc_macro_attribute] -pub fn doit(_: TokenStream, input: TokenStream) -> TokenStream { - input.into_iter().collect() -} diff --git a/src/test/ui/proc-macro/auxiliary/nested-item-spans.rs b/src/test/ui/proc-macro/auxiliary/nested-item-spans.rs deleted file mode 100644 index 8f720b4574dde..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/nested-item-spans.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::*; - -#[proc_macro_attribute] -pub fn foo(_: TokenStream, item: TokenStream) -> TokenStream { - item.into_iter().collect() -} diff --git a/src/test/ui/proc-macro/auxiliary/proc-macro-gates.rs b/src/test/ui/proc-macro/auxiliary/proc-macro-gates.rs deleted file mode 100644 index c7c7167eca0d5..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/proc-macro-gates.rs +++ /dev/null @@ -1,18 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::*; - -#[proc_macro] -pub fn m(a: TokenStream) -> TokenStream { - a -} - -#[proc_macro_attribute] -pub fn a(_a: TokenStream, b: TokenStream) -> TokenStream { - b -} diff --git a/src/test/ui/proc-macro/auxiliary/span-preservation.rs b/src/test/ui/proc-macro/auxiliary/span-preservation.rs deleted file mode 100644 index 33c7968104b72..0000000000000 --- a/src/test/ui/proc-macro/auxiliary/span-preservation.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host -// no-prefer-dynamic - -#![crate_type = "proc-macro"] - -extern crate proc_macro; - -use proc_macro::TokenStream; - -#[proc_macro_attribute] -pub fn foo(_: TokenStream, input: TokenStream) -> TokenStream { - input.into_iter().collect() -} diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs index 15fe3804f9b4f..27efa44f98032 100644 --- a/src/test/ui/proc-macro/auxiliary/test-macros.rs +++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs @@ -1,26 +1,112 @@ // force-host // no-prefer-dynamic +// Proc macros commonly used by tests. +// `panic`/`print` -> `panic_bang`/`print_bang` to avoid conflicts with standard macros. + #![crate_type = "proc-macro"] extern crate proc_macro; - use proc_macro::TokenStream; +// Macro that return empty token stream. + +#[proc_macro] +pub fn empty(_: TokenStream) -> TokenStream { + TokenStream::new() +} + #[proc_macro_attribute] -pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream { - assert!(_attr.to_string().is_empty()); - input +pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream { + TokenStream::new() +} + +#[proc_macro_derive(Empty, attributes(empty_helper))] +pub fn empty_derive(_: TokenStream) -> TokenStream { + TokenStream::new() +} + +// Macro that panics. + +#[proc_macro] +pub fn panic_bang(_: TokenStream) -> TokenStream { + panic!("panic-bang"); } #[proc_macro_attribute] -pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream { - assert!(_attr.to_string().is_empty()); - assert!(!_input.to_string().is_empty()); - "".parse().unwrap() +pub fn panic_attr(_: TokenStream, _: TokenStream) -> TokenStream { + panic!("panic-attr"); +} + +#[proc_macro_derive(Panic, attributes(panic_helper))] +pub fn panic_derive(_: TokenStream) -> TokenStream { + panic!("panic-derive"); } +// Macros that return the input stream. + #[proc_macro] -pub fn emit_input(input: TokenStream) -> TokenStream { +pub fn identity(input: TokenStream) -> TokenStream { input } + +#[proc_macro_attribute] +pub fn identity_attr(_: TokenStream, input: TokenStream) -> TokenStream { + input +} + +#[proc_macro_derive(Identity, attributes(identity_helper))] +pub fn identity_derive(input: TokenStream) -> TokenStream { + input +} + +// Macros that iterate and re-collect the input stream. + +#[proc_macro] +pub fn recollect(input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +#[proc_macro_attribute] +pub fn recollect_attr(_: TokenStream, input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +#[proc_macro_derive(Recollect, attributes(recollect_helper))] +pub fn recollect_derive(input: TokenStream) -> TokenStream { + input.into_iter().collect() +} + +// Macros that print their input in the original and re-collected forms (if they differ). + +fn print_helper(input: TokenStream, kind: &str) -> TokenStream { + let input_display = format!("{}", input); + let input_debug = format!("{:#?}", input); + let recollected = input.into_iter().collect(); + let recollected_display = format!("{}", recollected); + let recollected_debug = format!("{:#?}", recollected); + println!("PRINT-{} INPUT (DISPLAY): {}", kind, input_display); + if recollected_display != input_display { + println!("PRINT-{} RE-COLLECTED (DISPLAY): {}", kind, recollected_display); + } + println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); + if recollected_debug != input_debug { + println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + } + recollected +} + +#[proc_macro] +pub fn print_bang(input: TokenStream) -> TokenStream { + print_helper(input, "BANG") +} + +#[proc_macro_attribute] +pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { + print_helper(input, "ATTR") +} + +#[proc_macro_derive(Print, attributes(print_helper))] +pub fn print_derive(input: TokenStream) -> TokenStream { + print_helper(input, "DERIVE") +} diff --git a/src/test/ui/proc-macro/derive-helper-shadowed.rs b/src/test/ui/proc-macro/derive-helper-shadowed.rs index 792b54b3b945a..0388e647b58aa 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowed.rs +++ b/src/test/ui/proc-macro/derive-helper-shadowed.rs @@ -1,16 +1,16 @@ // compile-pass -// aux-build:derive-helper-shadowed.rs +// aux-build:test-macros.rs // aux-build:derive-helper-shadowed-2.rs #[macro_use] -extern crate derive_helper_shadowed; -#[macro_use(my_attr)] +extern crate test_macros; +#[macro_use(empty_helper)] extern crate derive_helper_shadowed_2; -macro_rules! my_attr { () => () } +macro_rules! empty_helper { () => () } -#[derive(MyTrait)] -#[my_attr] // OK +#[derive(Empty)] +#[empty_helper] // OK struct S; fn main() {} diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.rs b/src/test/ui/proc-macro/derive-helper-shadowing.rs index f6fe9f9fd8b30..cdc0d6da94695 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowing.rs +++ b/src/test/ui/proc-macro/derive-helper-shadowing.rs @@ -1,23 +1,25 @@ -// aux-build:derive-helper-shadowing.rs +// aux-build:test-macros.rs -extern crate derive_helper_shadowing; -use derive_helper_shadowing::*; +#[macro_use] +extern crate test_macros; -#[my_attr] //~ ERROR `my_attr` is ambiguous -#[derive(MyTrait)] +use test_macros::empty_attr as empty_helper; + +#[empty_helper] //~ ERROR `empty_helper` is ambiguous +#[derive(Empty)] struct S { // FIXME No ambiguity, attributes in non-macro positions are not resolved properly - #[my_attr] + #[empty_helper] field: [u8; { // FIXME No ambiguity, derive helpers are not put into scope for non-attributes - use my_attr; + use empty_helper; // FIXME No ambiguity, derive helpers are not put into scope for inner items - #[my_attr] + #[empty_helper] struct U; mod inner { - #[my_attr] //~ ERROR attribute `my_attr` is currently unknown + #[empty_helper] //~ ERROR attribute `empty_helper` is currently unknown struct V; } diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.stderr b/src/test/ui/proc-macro/derive-helper-shadowing.stderr index fb86cabf939c4..ed6d30516562d 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowing.stderr +++ b/src/test/ui/proc-macro/derive-helper-shadowing.stderr @@ -1,29 +1,29 @@ -error[E0658]: The attribute `my_attr` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/derive-helper-shadowing.rs:20:15 +error[E0658]: The attribute `empty_helper` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/derive-helper-shadowing.rs:22:15 | -LL | #[my_attr] - | ^^^^^^^ +LL | #[empty_helper] + | ^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable -error[E0659]: `my_attr` is ambiguous (derive helper attribute vs any other name) - --> $DIR/derive-helper-shadowing.rs:6:3 +error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name) + --> $DIR/derive-helper-shadowing.rs:8:3 | -LL | #[my_attr] - | ^^^^^^^ ambiguous name +LL | #[empty_helper] + | ^^^^^^^^^^^^ ambiguous name | -note: `my_attr` could refer to the derive helper attribute defined here - --> $DIR/derive-helper-shadowing.rs:7:10 +note: `empty_helper` could refer to the derive helper attribute defined here + --> $DIR/derive-helper-shadowing.rs:9:10 | -LL | #[derive(MyTrait)] - | ^^^^^^^ -note: `my_attr` could also refer to the attribute macro imported here - --> $DIR/derive-helper-shadowing.rs:4:5 +LL | #[derive(Empty)] + | ^^^^^ +note: `empty_helper` could also refer to the attribute macro imported here + --> $DIR/derive-helper-shadowing.rs:6:5 | -LL | use derive_helper_shadowing::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: use `crate::my_attr` to refer to this attribute macro unambiguously +LL | use test_macros::empty_attr as empty_helper; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: use `crate::empty_helper` to refer to this attribute macro unambiguously error: aborting due to 2 previous errors diff --git a/src/test/ui/proc-macro/derive-in-mod.rs b/src/test/ui/proc-macro/derive-in-mod.rs new file mode 100644 index 0000000000000..e6b91324f95d0 --- /dev/null +++ b/src/test/ui/proc-macro/derive-in-mod.rs @@ -0,0 +1,13 @@ +// compile-pass +// aux-build:test-macros.rs + +extern crate test_macros; + +mod inner { + use test_macros::Empty; + + #[derive(Empty)] + struct S; +} + +fn main() {} diff --git a/src/test/ui/proc-macro/derive-still-gated.rs b/src/test/ui/proc-macro/derive-still-gated.rs index 526eff39891ae..d895d26f26763 100644 --- a/src/test/ui/proc-macro/derive-still-gated.rs +++ b/src/test/ui/proc-macro/derive-still-gated.rs @@ -1,11 +1,9 @@ -// aux-build:derive-a.rs - -#![allow(warnings)] +// aux-build:test-macros.rs #[macro_use] -extern crate derive_a; +extern crate test_macros; -#[derive_A] //~ ERROR attribute `derive_A` is currently unknown +#[derive_Empty] //~ ERROR attribute `derive_Empty` is currently unknown struct A; fn main() {} diff --git a/src/test/ui/proc-macro/derive-still-gated.stderr b/src/test/ui/proc-macro/derive-still-gated.stderr index d235343ff1618..f299b5abdbc6b 100644 --- a/src/test/ui/proc-macro/derive-still-gated.stderr +++ b/src/test/ui/proc-macro/derive-still-gated.stderr @@ -1,8 +1,8 @@ -error[E0658]: The attribute `derive_A` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/derive-still-gated.rs:8:3 +error[E0658]: The attribute `derive_Empty` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/derive-still-gated.rs:6:3 | -LL | #[derive_A] - | ^^^^^^^^ help: a built-in attribute with a similar name exists: `derive` +LL | #[derive_Empty] + | ^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.rs b/src/test/ui/proc-macro/dollar-crate-issue-57089.rs index 2d54c07ff9530..2615db3e119f1 100644 --- a/src/test/ui/proc-macro/dollar-crate-issue-57089.rs +++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.rs @@ -1,22 +1,23 @@ // compile-pass // edition:2018 -// aux-build:dollar-crate.rs +// aux-build:test-macros.rs // Anonymize unstable non-dummy spans while still showing dummy spans `0..0`. // normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)" // normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)" -extern crate dollar_crate; +#[macro_use] +extern crate test_macros; type S = u8; macro_rules! m { () => { - dollar_crate::m_empty! { + print_bang! { struct M($crate::S); } - #[dollar_crate::a] + #[print_attr] struct A($crate::S); }; } diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout index 618380d7f0bee..0611fcb13f267 100644 --- a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout +++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout @@ -1,5 +1,5 @@ -PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ; -PROC MACRO INPUT: TokenStream [ +PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ; +PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #2 bytes(LO..HI), @@ -38,8 +38,9 @@ PROC MACRO INPUT: TokenStream [ span: #2 bytes(LO..HI), }, ] -ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(crate::S); -ATTRIBUTE INPUT: TokenStream [ +PRINT-ATTR INPUT (DISPLAY): struct A(crate::S); +PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #2 bytes(LO..HI), diff --git a/src/test/ui/proc-macro/dollar-crate.rs b/src/test/ui/proc-macro/dollar-crate.rs index 1460e9a3b2d55..aadd87ffaf203 100644 --- a/src/test/ui/proc-macro/dollar-crate.rs +++ b/src/test/ui/proc-macro/dollar-crate.rs @@ -1,29 +1,28 @@ // edition:2018 -// aux-build:dollar-crate.rs +// aux-build:test-macros.rs // aux-build:dollar-crate-external.rs // Anonymize unstable non-dummy spans while still showing dummy spans `0..0`. // normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)" // normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)" -extern crate dollar_crate; +#[macro_use] +extern crate test_macros; extern crate dollar_crate_external; type S = u8; mod local { - use crate::dollar_crate; - macro_rules! local { () => { - dollar_crate::m! { + print_bang! { struct M($crate::S); } - #[dollar_crate::a] + #[print_attr] struct A($crate::S); - #[derive(dollar_crate::d)] + #[derive(Print)] struct D($crate::S); //~ ERROR the name `D` is defined multiple times }; } diff --git a/src/test/ui/proc-macro/dollar-crate.stderr b/src/test/ui/proc-macro/dollar-crate.stderr index d1b836e7f6f28..5d78a8e198729 100644 --- a/src/test/ui/proc-macro/dollar-crate.stderr +++ b/src/test/ui/proc-macro/dollar-crate.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:27:13 + --> $DIR/dollar-crate.rs:26:13 | LL | struct D($crate::S); | ^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | local!(); = note: `D` must be defined only once in the type namespace of this module error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:37:5 + --> $DIR/dollar-crate.rs:36:5 | LL | dollar_crate_external::external!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/proc-macro/dollar-crate.stdout b/src/test/ui/proc-macro/dollar-crate.stdout index 454da53943054..3c88ee99842a2 100644 --- a/src/test/ui/proc-macro/dollar-crate.stdout +++ b/src/test/ui/proc-macro/dollar-crate.stdout @@ -1,5 +1,5 @@ -PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ; -PROC MACRO INPUT: TokenStream [ +PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ; +PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #2 bytes(LO..HI), @@ -38,8 +38,9 @@ PROC MACRO INPUT: TokenStream [ span: #2 bytes(LO..HI), }, ] -ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(crate::S); -ATTRIBUTE INPUT: TokenStream [ +PRINT-ATTR INPUT (DISPLAY): struct A(crate::S); +PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #2 bytes(LO..HI), @@ -78,8 +79,9 @@ ATTRIBUTE INPUT: TokenStream [ span: #2 bytes(LO..HI), }, ] -DERIVE INPUT (PRETTY-PRINTED): struct D(crate::S); -DERIVE INPUT: TokenStream [ +PRINT-DERIVE INPUT (DISPLAY): struct D(crate::S); +PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ( $crate :: S ) ; +PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #2 bytes(LO..HI), @@ -118,8 +120,8 @@ DERIVE INPUT: TokenStream [ span: #2 bytes(LO..HI), }, ] -PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ; -PROC MACRO INPUT: TokenStream [ +PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ; +PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #10 bytes(LO..HI), @@ -158,8 +160,9 @@ PROC MACRO INPUT: TokenStream [ span: #10 bytes(LO..HI), }, ] -ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(::dollar_crate_external::S); -ATTRIBUTE INPUT: TokenStream [ +PRINT-ATTR INPUT (DISPLAY): struct A(::dollar_crate_external::S); +PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #10 bytes(LO..HI), @@ -198,8 +201,9 @@ ATTRIBUTE INPUT: TokenStream [ span: #10 bytes(LO..HI), }, ] -DERIVE INPUT (PRETTY-PRINTED): struct D(::dollar_crate_external::S); -DERIVE INPUT: TokenStream [ +PRINT-DERIVE INPUT (DISPLAY): struct D(::dollar_crate_external::S); +PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ( $crate :: S ) ; +PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "struct", span: #10 bytes(LO..HI), diff --git a/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.rs b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.rs new file mode 100644 index 0000000000000..3a1c56efce8c2 --- /dev/null +++ b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.rs @@ -0,0 +1,11 @@ +// aux-build:test-macros.rs + +#[macro_use(Empty)] +extern crate test_macros; +use test_macros::empty_attr as empty_helper; + +#[derive(Empty)] +#[empty_helper] //~ ERROR `empty_helper` is ambiguous +struct S; + +fn main() {} diff --git a/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr new file mode 100644 index 0000000000000..012fb105b128d --- /dev/null +++ b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr @@ -0,0 +1,21 @@ +error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name) + --> $DIR/helper-attr-blocked-by-import-ambig.rs:8:3 + | +LL | #[empty_helper] + | ^^^^^^^^^^^^ ambiguous name + | +note: `empty_helper` could refer to the derive helper attribute defined here + --> $DIR/helper-attr-blocked-by-import-ambig.rs:7:10 + | +LL | #[derive(Empty)] + | ^^^^^ +note: `empty_helper` could also refer to the attribute macro imported here + --> $DIR/helper-attr-blocked-by-import-ambig.rs:5:5 + | +LL | use test_macros::empty_attr as empty_helper; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: use `crate::empty_helper` to refer to this attribute macro unambiguously + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0659`. diff --git a/src/test/ui/proc-macro/helper-attr-blocked-by-import.rs b/src/test/ui/proc-macro/helper-attr-blocked-by-import.rs new file mode 100644 index 0000000000000..6d3e5ec198d85 --- /dev/null +++ b/src/test/ui/proc-macro/helper-attr-blocked-by-import.rs @@ -0,0 +1,28 @@ +// compile-pass +// aux-build:test-macros.rs + +#[macro_use(Empty)] +extern crate test_macros; + +use self::one::*; +use self::two::*; + +mod empty_helper {} + +mod one { + use empty_helper; + + #[derive(Empty)] + #[empty_helper] + struct One; +} + +mod two { + use empty_helper; + + #[derive(Empty)] + #[empty_helper] + struct Two; +} + +fn main() {} diff --git a/src/test/ui/proc-macro/import.rs b/src/test/ui/proc-macro/import.rs index 8fbccdf1aed14..d1b1ff350695f 100644 --- a/src/test/ui/proc-macro/import.rs +++ b/src/test/ui/proc-macro/import.rs @@ -1,11 +1,8 @@ -// aux-build:derive-a.rs +// aux-build:test-macros.rs -#![allow(warnings)] +extern crate test_macros; -#[macro_use] -extern crate derive_a; - -use derive_a::derive_a; -//~^ ERROR: unresolved import `derive_a::derive_a` +use test_macros::empty_derive; +//~^ ERROR: unresolved import `test_macros::empty_derive` fn main() {} diff --git a/src/test/ui/proc-macro/import.stderr b/src/test/ui/proc-macro/import.stderr index 813a8ac260460..aae621193ab9f 100644 --- a/src/test/ui/proc-macro/import.stderr +++ b/src/test/ui/proc-macro/import.stderr @@ -1,8 +1,8 @@ -error[E0432]: unresolved import `derive_a::derive_a` - --> $DIR/import.rs:8:5 +error[E0432]: unresolved import `test_macros::empty_derive` + --> $DIR/import.rs:5:5 | -LL | use derive_a::derive_a; - | ^^^^^^^^^^^^^^^^^^ no `derive_a` in the root +LL | use test_macros::empty_derive; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ no `empty_derive` in the root error: aborting due to previous error diff --git a/src/test/ui/proc-macro/issue-36935.rs b/src/test/ui/proc-macro/issue-36935.rs new file mode 100644 index 0000000000000..f809592d5f449 --- /dev/null +++ b/src/test/ui/proc-macro/issue-36935.rs @@ -0,0 +1,12 @@ +// aux-build:test-macros.rs + +#[macro_use] +extern crate test_macros; + +#[derive(Identity, Panic)] //~ ERROR proc-macro derive panicked +struct Baz { + a: i32, + b: i32, +} + +fn main() {} diff --git a/src/test/ui/proc-macro/issue-36935.stderr b/src/test/ui/proc-macro/issue-36935.stderr new file mode 100644 index 0000000000000..da4366eb668d6 --- /dev/null +++ b/src/test/ui/proc-macro/issue-36935.stderr @@ -0,0 +1,10 @@ +error: proc-macro derive panicked + --> $DIR/issue-36935.rs:6:20 + | +LL | #[derive(Identity, Panic)] + | ^^^^^ + | + = help: message: panic-derive + +error: aborting due to previous error + diff --git a/src/test/ui/proc-macro/issue-37788.rs b/src/test/ui/proc-macro/issue-37788.rs index 75fcd24d85f6f..73b1f0d58c837 100644 --- a/src/test/ui/proc-macro/issue-37788.rs +++ b/src/test/ui/proc-macro/issue-37788.rs @@ -1,7 +1,7 @@ -// aux-build:derive-a-b.rs +// aux-build:test-macros.rs #[macro_use] -extern crate derive_a_b; +extern crate test_macros; fn main() { // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE. diff --git a/src/test/ui/proc-macro/issue-41211.rs b/src/test/ui/proc-macro/issue-41211.rs index 0b082f4818f1b..ee9246e1c9b5c 100644 --- a/src/test/ui/proc-macro/issue-41211.rs +++ b/src/test/ui/proc-macro/issue-41211.rs @@ -1,14 +1,14 @@ -// aux-build:issue-41211.rs +// aux-build:test-macros.rs // FIXME: https://github.com/rust-lang/rust/issues/41430 // This is a temporary regression test for the ICE reported in #41211 #![feature(custom_inner_attributes)] -#![emit_unchanged] -//~^ ERROR attribute `emit_unchanged` is currently unknown to the compiler +#![identity_attr] +//~^ ERROR attribute `identity_attr` is currently unknown to the compiler //~| ERROR inconsistent resolution for a macro: first custom attribute, then attribute macro -extern crate issue_41211; -use issue_41211::emit_unchanged; +extern crate test_macros; +use test_macros::identity_attr; fn main() {} diff --git a/src/test/ui/proc-macro/issue-41211.stderr b/src/test/ui/proc-macro/issue-41211.stderr index dfb2f6f63d847..1de6b293ecfb8 100644 --- a/src/test/ui/proc-macro/issue-41211.stderr +++ b/src/test/ui/proc-macro/issue-41211.stderr @@ -1,8 +1,8 @@ -error[E0658]: The attribute `emit_unchanged` is currently unknown to the compiler and may have meaning added to it in the future +error[E0658]: The attribute `identity_attr` is currently unknown to the compiler and may have meaning added to it in the future --> $DIR/issue-41211.rs:8:4 | -LL | #![emit_unchanged] - | ^^^^^^^^^^^^^^ +LL | #![identity_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable @@ -10,8 +10,8 @@ LL | #![emit_unchanged] error: inconsistent resolution for a macro: first custom attribute, then attribute macro --> $DIR/issue-41211.rs:8:4 | -LL | #![emit_unchanged] - | ^^^^^^^^^^^^^^ +LL | #![identity_attr] + | ^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/proc-macro/issue-53481.rs b/src/test/ui/proc-macro/issue-53481.rs index 479fd1db630a3..2fbde5fedb95b 100644 --- a/src/test/ui/proc-macro/issue-53481.rs +++ b/src/test/ui/proc-macro/issue-53481.rs @@ -1,21 +1,21 @@ // compile-pass -// aux-build:issue-53481.rs +// aux-build:test-macros.rs #[macro_use] -extern crate issue_53481; +extern crate test_macros; mod m1 { - use m2::MyTrait; + use m2::Empty; - #[derive(MyTrait)] + #[derive(Empty)] struct A {} } mod m2 { - pub type MyTrait = u8; + pub type Empty = u8; - #[derive(MyTrait)] - #[my_attr] + #[derive(Empty)] + #[empty_helper] struct B {} } diff --git a/src/test/ui/proc-macro/load-panic.rs b/src/test/ui/proc-macro/load-panic.rs index fa279c559fbf1..2e9a311d882bd 100644 --- a/src/test/ui/proc-macro/load-panic.rs +++ b/src/test/ui/proc-macro/load-panic.rs @@ -1,10 +1,9 @@ -// aux-build:derive-panic.rs -// compile-flags:--error-format human +// aux-build:test-macros.rs #[macro_use] -extern crate derive_panic; +extern crate test_macros; -#[derive(A)] +#[derive(Panic)] //~^ ERROR: proc-macro derive panicked struct Foo; diff --git a/src/test/ui/proc-macro/load-panic.stderr b/src/test/ui/proc-macro/load-panic.stderr index b448c804bff59..40cc4ee0e3d37 100644 --- a/src/test/ui/proc-macro/load-panic.stderr +++ b/src/test/ui/proc-macro/load-panic.stderr @@ -1,10 +1,10 @@ error: proc-macro derive panicked - --> $DIR/load-panic.rs:7:10 + --> $DIR/load-panic.rs:6:10 | -LL | #[derive(A)] - | ^ +LL | #[derive(Panic)] + | ^^^^^ | - = help: message: nope! + = help: message: panic-derive error: aborting due to previous error diff --git a/src/test/ui/proc-macro/macro-brackets.rs b/src/test/ui/proc-macro/macro-brackets.rs index c46abf03654ce..aa0046f458229 100644 --- a/src/test/ui/proc-macro/macro-brackets.rs +++ b/src/test/ui/proc-macro/macro-brackets.rs @@ -1,13 +1,13 @@ -// aux-build:macro-brackets.rs +// aux-build:test-macros.rs -extern crate macro_brackets as bar; -use bar::doit; +#[macro_use] +extern crate test_macros; macro_rules! id { ($($t:tt)*) => ($($t)*) } -#[doit] +#[identity_attr] id![static X: u32 = 'a';]; //~ ERROR: mismatched types diff --git a/src/test/ui/proc-macro/macro-use-attr.rs b/src/test/ui/proc-macro/macro-use-attr.rs index 13db0725a388b..d1b1430fb5d03 100644 --- a/src/test/ui/proc-macro/macro-use-attr.rs +++ b/src/test/ui/proc-macro/macro-use-attr.rs @@ -1,9 +1,10 @@ // compile-pass -// aux-build:attr_proc_macro.rs +// aux-build:test-macros.rs -#[macro_use] extern crate attr_proc_macro; +#[macro_use] +extern crate test_macros; -#[attr_proc_macro] +#[identity_attr] struct Foo; fn main() { diff --git a/src/test/ui/proc-macro/macro-use-bang.rs b/src/test/ui/proc-macro/macro-use-bang.rs index 4bf3bcd6f3aae..d39c42267fb96 100644 --- a/src/test/ui/proc-macro/macro-use-bang.rs +++ b/src/test/ui/proc-macro/macro-use-bang.rs @@ -1,11 +1,11 @@ // compile-pass -// aux-build:bang_proc_macro.rs +// aux-build:test-macros.rs #![feature(proc_macro_hygiene)] #[macro_use] -extern crate bang_proc_macro; +extern crate test_macros; fn main() { - bang_proc_macro!(println!("Hello, world!")); + identity!(println!("Hello, world!")); } diff --git a/src/test/ui/proc-macro/macros-in-extern.rs b/src/test/ui/proc-macro/macros-in-extern.rs index 5c5603b6c06b0..0477b5c48ecc9 100644 --- a/src/test/ui/proc-macro/macros-in-extern.rs +++ b/src/test/ui/proc-macro/macros-in-extern.rs @@ -1,10 +1,9 @@ // aux-build:test-macros.rs // ignore-wasm32 +#[macro_use] extern crate test_macros; -use test_macros::{nop_attr, no_output, emit_input}; - fn main() { assert_eq!(unsafe { rust_get_test_int() }, 0isize); assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF); @@ -12,14 +11,14 @@ fn main() { #[link(name = "rust_test_helpers", kind = "static")] extern { - #[no_output] + #[empty_attr] //~^ ERROR macro invocations in `extern {}` blocks are experimental fn some_definitely_unknown_symbol_which_should_be_removed(); - #[nop_attr] + #[identity_attr] //~^ ERROR macro invocations in `extern {}` blocks are experimental fn rust_get_test_int() -> isize; - emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); + identity!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); //~^ ERROR macro invocations in `extern {}` blocks are experimental } diff --git a/src/test/ui/proc-macro/macros-in-extern.stderr b/src/test/ui/proc-macro/macros-in-extern.stderr index 61571650f2f04..592c91553aa8c 100644 --- a/src/test/ui/proc-macro/macros-in-extern.stderr +++ b/src/test/ui/proc-macro/macros-in-extern.stderr @@ -1,26 +1,26 @@ error[E0658]: macro invocations in `extern {}` blocks are experimental - --> $DIR/macros-in-extern.rs:15:5 + --> $DIR/macros-in-extern.rs:14:5 | -LL | #[no_output] - | ^^^^^^^^^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/49476 = help: add #![feature(macros_in_extern)] to the crate attributes to enable error[E0658]: macro invocations in `extern {}` blocks are experimental - --> $DIR/macros-in-extern.rs:19:5 + --> $DIR/macros-in-extern.rs:18:5 | -LL | #[nop_attr] - | ^^^^^^^^^^^ +LL | #[identity_attr] + | ^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/49476 = help: add #![feature(macros_in_extern)] to the crate attributes to enable error[E0658]: macro invocations in `extern {}` blocks are experimental - --> $DIR/macros-in-extern.rs:23:5 + --> $DIR/macros-in-extern.rs:22:5 | -LL | emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | identity!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/49476 = help: add #![feature(macros_in_extern)] to the crate attributes to enable diff --git a/src/test/ui/proc-macro/nested-item-spans.rs b/src/test/ui/proc-macro/nested-item-spans.rs index e365b74b3be8f..63da170d0bbb2 100644 --- a/src/test/ui/proc-macro/nested-item-spans.rs +++ b/src/test/ui/proc-macro/nested-item-spans.rs @@ -1,10 +1,9 @@ -// aux-build:nested-item-spans.rs +// aux-build:test-macros.rs -extern crate nested_item_spans; +#[macro_use] +extern crate test_macros; -use nested_item_spans::foo; - -#[foo] +#[recollect_attr] fn another() { fn bar() { let x: u32 = "x"; //~ ERROR: mismatched types @@ -14,7 +13,7 @@ fn another() { } fn main() { - #[foo] + #[recollect_attr] fn bar() { let x: u32 = "x"; //~ ERROR: mismatched types } diff --git a/src/test/ui/proc-macro/nested-item-spans.stderr b/src/test/ui/proc-macro/nested-item-spans.stderr index 011a91d446295..bef80311f38e5 100644 --- a/src/test/ui/proc-macro/nested-item-spans.stderr +++ b/src/test/ui/proc-macro/nested-item-spans.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/nested-item-spans.rs:10:22 + --> $DIR/nested-item-spans.rs:9:22 | LL | let x: u32 = "x"; | ^^^ expected u32, found reference @@ -8,7 +8,7 @@ LL | let x: u32 = "x"; found type `&'static str` error[E0308]: mismatched types - --> $DIR/nested-item-spans.rs:19:22 + --> $DIR/nested-item-spans.rs:18:22 | LL | let x: u32 = "x"; | ^^^ expected u32, found reference diff --git a/src/test/ui/proc-macro/no-macro-use-attr.rs b/src/test/ui/proc-macro/no-macro-use-attr.rs index 62a501ded1006..15ab431fe754a 100644 --- a/src/test/ui/proc-macro/no-macro-use-attr.rs +++ b/src/test/ui/proc-macro/no-macro-use-attr.rs @@ -1,9 +1,9 @@ -// aux-build:derive-a.rs +// aux-build:test-macros.rs #![feature(rustc_attrs)] #![warn(unused_extern_crates)] -extern crate derive_a; +extern crate test_macros; //~^ WARN unused extern crate #[rustc_error] diff --git a/src/test/ui/proc-macro/no-macro-use-attr.stderr b/src/test/ui/proc-macro/no-macro-use-attr.stderr index 4b2fce7f6e4ca..87487bcc7d662 100644 --- a/src/test/ui/proc-macro/no-macro-use-attr.stderr +++ b/src/test/ui/proc-macro/no-macro-use-attr.stderr @@ -1,8 +1,8 @@ warning: unused extern crate --> $DIR/no-macro-use-attr.rs:6:1 | -LL | extern crate derive_a; - | ^^^^^^^^^^^^^^^^^^^^^^ help: remove it +LL | extern crate test_macros; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here --> $DIR/no-macro-use-attr.rs:4:9 diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs index af6bfa08aaa94..678dc83b753b5 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.rs +++ b/src/test/ui/proc-macro/proc-macro-gates.rs @@ -1,61 +1,62 @@ -// aux-build:proc-macro-gates.rs +// aux-build:test-macros.rs // gate-test-proc_macro_hygiene #![feature(stmt_expr_attributes)] -extern crate proc_macro_gates as foo; - -use foo::*; +#[macro_use] +extern crate test_macros; fn _test_inner() { - #![a] //~ ERROR: non-builtin inner attributes are unstable + #![empty_attr] //~ ERROR: non-builtin inner attributes are unstable } -#[a] //~ ERROR: custom attributes cannot be applied to modules +#[empty_attr] //~ ERROR: custom attributes cannot be applied to modules mod _test2 {} mod _test2_inner { - #![a] //~ ERROR: custom attributes cannot be applied to modules + #![empty_attr] //~ ERROR: custom attributes cannot be applied to modules //~| ERROR: non-builtin inner attributes are unstable } -#[a = "y"] //~ ERROR: must only be followed by a delimiter token +#[empty_attr = "y"] //~ ERROR: must only be followed by a delimiter token fn _test3() {} fn attrs() { // Statement, item - #[a] // OK + #[empty_attr] // OK struct S; // Statement, macro - #[a] //~ ERROR: custom attributes cannot be applied to statements + #[empty_attr] //~ ERROR: custom attributes cannot be applied to statements println!(); // Statement, semi - #[a] //~ ERROR: custom attributes cannot be applied to statements + #[empty_attr] //~ ERROR: custom attributes cannot be applied to statements S; // Statement, local - #[a] //~ ERROR: custom attributes cannot be applied to statements + #[empty_attr] //~ ERROR: custom attributes cannot be applied to statements let _x = 2; // Expr - let _x = #[a] 2; //~ ERROR: custom attributes cannot be applied to expressions + let _x = #[identity_attr] 2; //~ ERROR: custom attributes cannot be applied to expressions // Opt expr - let _x = [#[a] 2]; //~ ERROR: custom attributes cannot be applied to expressions + let _x = [#[identity_attr] 2]; //~ ERROR: custom attributes cannot be applied to expressions // Expr macro - let _x = #[a] println!(); //~ ERROR: custom attributes cannot be applied to expressions + let _x = #[identity_attr] println!(); + //~^ ERROR: custom attributes cannot be applied to expressions } fn main() { - let _x: m!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types - if let m!(Some(_x)) = Some(3) {} //~ ERROR: procedural macros cannot be expanded to patterns + let _x: identity!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types + if let identity!(Some(_x)) = Some(3) {} + //~^ ERROR: procedural macros cannot be expanded to patterns - m!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements - m!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements + empty!(struct S;); //~ ERROR: procedural macros cannot be expanded to statements + empty!(let _x = 3;); //~ ERROR: procedural macros cannot be expanded to statements - let _x = m!(3); //~ ERROR: procedural macros cannot be expanded to expressions - let _x = [m!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions + let _x = identity!(3); //~ ERROR: procedural macros cannot be expanded to expressions + let _x = [empty!(3)]; //~ ERROR: procedural macros cannot be expanded to expressions } diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr index 1bb864b52ea7d..f53ad222a0368 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates.stderr @@ -1,95 +1,95 @@ error[E0658]: non-builtin inner attributes are unstable - --> $DIR/proc-macro-gates.rs:11:5 + --> $DIR/proc-macro-gates.rs:10:5 | -LL | #![a] - | ^^^^^ +LL | #![empty_attr] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54726 = help: add #![feature(custom_inner_attributes)] to the crate attributes to enable error[E0658]: non-builtin inner attributes are unstable - --> $DIR/proc-macro-gates.rs:18:5 + --> $DIR/proc-macro-gates.rs:17:5 | -LL | #![a] - | ^^^^^ +LL | #![empty_attr] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54726 = help: add #![feature(custom_inner_attributes)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to modules - --> $DIR/proc-macro-gates.rs:14:1 + --> $DIR/proc-macro-gates.rs:13:1 | -LL | #[a] - | ^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to modules - --> $DIR/proc-macro-gates.rs:18:5 + --> $DIR/proc-macro-gates.rs:17:5 | -LL | #![a] - | ^^^^^ +LL | #![empty_attr] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error: custom attribute invocations must be of the form #[foo] or #[foo(..)], the macro name must only be followed by a delimiter token - --> $DIR/proc-macro-gates.rs:22:1 + --> $DIR/proc-macro-gates.rs:21:1 | -LL | #[a = "y"] - | ^^^^^^^^^^ +LL | #[empty_attr = "y"] + | ^^^^^^^^^^^^^^^^^^^ error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:31:5 + --> $DIR/proc-macro-gates.rs:30:5 | -LL | #[a] - | ^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:35:5 + --> $DIR/proc-macro-gates.rs:34:5 | -LL | #[a] - | ^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:39:5 + --> $DIR/proc-macro-gates.rs:38:5 | -LL | #[a] - | ^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:43:14 + --> $DIR/proc-macro-gates.rs:42:14 | -LL | let _x = #[a] 2; - | ^^^^ +LL | let _x = #[identity_attr] 2; + | ^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:46:15 + --> $DIR/proc-macro-gates.rs:45:15 | -LL | let _x = [#[a] 2]; - | ^^^^ +LL | let _x = [#[identity_attr] 2]; + | ^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:49:14 + --> $DIR/proc-macro-gates.rs:48:14 | -LL | let _x = #[a] println!(); - | ^^^^ +LL | let _x = #[identity_attr] println!(); + | ^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable @@ -97,8 +97,8 @@ LL | let _x = #[a] println!(); error[E0658]: procedural macros cannot be expanded to types --> $DIR/proc-macro-gates.rs:53:13 | -LL | let _x: m!(u32) = 3; - | ^^^^^^^ +LL | let _x: identity!(u32) = 3; + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable @@ -106,44 +106,44 @@ LL | let _x: m!(u32) = 3; error[E0658]: procedural macros cannot be expanded to patterns --> $DIR/proc-macro-gates.rs:54:12 | -LL | if let m!(Some(_x)) = Some(3) {} - | ^^^^^^^^^^^^ +LL | if let identity!(Some(_x)) = Some(3) {} + | ^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to statements - --> $DIR/proc-macro-gates.rs:56:5 + --> $DIR/proc-macro-gates.rs:57:5 | -LL | m!(struct S;); - | ^^^^^^^^^^^^^^ +LL | empty!(struct S;); + | ^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to statements - --> $DIR/proc-macro-gates.rs:57:5 + --> $DIR/proc-macro-gates.rs:58:5 | -LL | m!(let _x = 3;); - | ^^^^^^^^^^^^^^^^ +LL | empty!(let _x = 3;); + | ^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to expressions - --> $DIR/proc-macro-gates.rs:59:14 + --> $DIR/proc-macro-gates.rs:60:14 | -LL | let _x = m!(3); - | ^^^^^ +LL | let _x = identity!(3); + | ^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to expressions - --> $DIR/proc-macro-gates.rs:60:15 + --> $DIR/proc-macro-gates.rs:61:15 | -LL | let _x = [m!(3)]; - | ^^^^^ +LL | let _x = [empty!(3)]; + | ^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add #![feature(proc_macro_hygiene)] to the crate attributes to enable diff --git a/src/test/ui/proc-macro/proc-macro-gates2.rs b/src/test/ui/proc-macro/proc-macro-gates2.rs index 46b543a397cc7..35d7fc8042a3d 100644 --- a/src/test/ui/proc-macro/proc-macro-gates2.rs +++ b/src/test/ui/proc-macro/proc-macro-gates2.rs @@ -1,21 +1,20 @@ -// aux-build:proc-macro-gates.rs +// aux-build:test-macros.rs #![feature(stmt_expr_attributes)] -extern crate proc_macro_gates as foo; - -use foo::*; +#[macro_use] +extern crate test_macros; // NB. these errors aren't the best errors right now, but they're definitely // intended to be errors. Somehow using a custom attribute in these positions // should either require a feature gate or not be allowed on stable. -fn _test6<#[a] T>() {} +fn _test6<#[empty_attr] T>() {} //~^ ERROR: unknown to the compiler fn _test7() { match 1 { - #[a] //~ ERROR: unknown to the compiler + #[empty_attr] //~ ERROR: unknown to the compiler 0 => {} _ => {} } diff --git a/src/test/ui/proc-macro/proc-macro-gates2.stderr b/src/test/ui/proc-macro/proc-macro-gates2.stderr index 0e8236f460f8c..8eeca99ab3984 100644 --- a/src/test/ui/proc-macro/proc-macro-gates2.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates2.stderr @@ -1,17 +1,17 @@ -error[E0658]: The attribute `a` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/proc-macro-gates2.rs:13:11 +error[E0658]: The attribute `empty_attr` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/proc-macro-gates2.rs:12:11 | -LL | fn _test6<#[a] T>() {} - | ^^^^ +LL | fn _test6<#[empty_attr] T>() {} + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable -error[E0658]: The attribute `a` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/proc-macro-gates2.rs:18:9 +error[E0658]: The attribute `empty_attr` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/proc-macro-gates2.rs:17:9 | -LL | #[a] - | ^^^^ +LL | #[empty_attr] + | ^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable diff --git a/src/test/ui/proc-macro/resolve-error.rs b/src/test/ui/proc-macro/resolve-error.rs index bb242f302496e..82607136f0b6f 100644 --- a/src/test/ui/proc-macro/resolve-error.rs +++ b/src/test/ui/proc-macro/resolve-error.rs @@ -1,7 +1,6 @@ // aux-build:derive-foo.rs // aux-build:derive-clona.rs -// aux-build:attr_proc_macro.rs -// aux-build:bang_proc_macro.rs +// aux-build:test-macros.rs #![feature(custom_attribute)] @@ -9,11 +8,10 @@ extern crate derive_foo; #[macro_use] extern crate derive_clona; -extern crate attr_proc_macro; -extern crate bang_proc_macro; +extern crate test_macros; -use attr_proc_macro::attr_proc_macro; -use bang_proc_macro::bang_proc_macro; +use test_macros::empty as bang_proc_macro; +use test_macros::empty_attr as attr_proc_macro; macro_rules! FooWithLongNam { () => {} diff --git a/src/test/ui/proc-macro/resolve-error.stderr b/src/test/ui/proc-macro/resolve-error.stderr index cf7de578c7d42..705ef6006a049 100644 --- a/src/test/ui/proc-macro/resolve-error.stderr +++ b/src/test/ui/proc-macro/resolve-error.stderr @@ -1,47 +1,47 @@ error: cannot find derive macro `FooWithLongNan` in this scope - --> $DIR/resolve-error.rs:26:10 + --> $DIR/resolve-error.rs:24:10 | LL | #[derive(FooWithLongNan)] | ^^^^^^^^^^^^^^ help: try: `FooWithLongName` error: cannot find derive macro `Dlone` in this scope - --> $DIR/resolve-error.rs:36:10 + --> $DIR/resolve-error.rs:34:10 | LL | #[derive(Dlone)] | ^^^^^ help: try: `Clone` error: cannot find derive macro `Dlona` in this scope - --> $DIR/resolve-error.rs:40:10 + --> $DIR/resolve-error.rs:38:10 | LL | #[derive(Dlona)] | ^^^^^ help: try: `Clona` error: cannot find derive macro `attr_proc_macra` in this scope - --> $DIR/resolve-error.rs:44:10 + --> $DIR/resolve-error.rs:42:10 | LL | #[derive(attr_proc_macra)] | ^^^^^^^^^^^^^^^ error: cannot find macro `FooWithLongNama!` in this scope - --> $DIR/resolve-error.rs:49:5 + --> $DIR/resolve-error.rs:47:5 | LL | FooWithLongNama!(); | ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam` error: cannot find macro `attr_proc_macra!` in this scope - --> $DIR/resolve-error.rs:52:5 + --> $DIR/resolve-error.rs:50:5 | LL | attr_proc_macra!(); | ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac` error: cannot find macro `Dlona!` in this scope - --> $DIR/resolve-error.rs:55:5 + --> $DIR/resolve-error.rs:53:5 | LL | Dlona!(); | ^^^^^ error: cannot find macro `bang_proc_macrp!` in this scope - --> $DIR/resolve-error.rs:58:5 + --> $DIR/resolve-error.rs:56:5 | LL | bang_proc_macrp!(); | ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro` diff --git a/src/test/ui/proc-macro/shadow.rs b/src/test/ui/proc-macro/shadow.rs index 9c49bae28a3bc..61959594c7981 100644 --- a/src/test/ui/proc-macro/shadow.rs +++ b/src/test/ui/proc-macro/shadow.rs @@ -1,8 +1,8 @@ -// aux-build:derive-a.rs +// aux-build:test-macros.rs #[macro_use] -extern crate derive_a; +extern crate test_macros; #[macro_use] -extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times +extern crate test_macros; //~ ERROR the name `test_macros` is defined multiple times fn main() {} diff --git a/src/test/ui/proc-macro/shadow.stderr b/src/test/ui/proc-macro/shadow.stderr index 08057e163496d..e7d95cc835811 100644 --- a/src/test/ui/proc-macro/shadow.stderr +++ b/src/test/ui/proc-macro/shadow.stderr @@ -1,13 +1,13 @@ -error[E0259]: the name `derive_a` is defined multiple times +error[E0259]: the name `test_macros` is defined multiple times --> $DIR/shadow.rs:6:1 | -LL | extern crate derive_a; - | ---------------------- previous import of the extern crate `derive_a` here +LL | extern crate test_macros; + | ------------------------- previous import of the extern crate `test_macros` here LL | #[macro_use] -LL | extern crate derive_a; - | ^^^^^^^^^^^^^^^^^^^^^^ `derive_a` reimported here +LL | extern crate test_macros; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `test_macros` reimported here | - = note: `derive_a` must be defined only once in the type namespace of this module + = note: `test_macros` must be defined only once in the type namespace of this module error: aborting due to previous error diff --git a/src/test/ui/proc-macro/span-preservation.rs b/src/test/ui/proc-macro/span-preservation.rs index 64f675ecc1c4d..0a82d28e9e544 100644 --- a/src/test/ui/proc-macro/span-preservation.rs +++ b/src/test/ui/proc-macro/span-preservation.rs @@ -1,19 +1,18 @@ //~ ERROR mismatched types -// aux-build:span-preservation.rs +// aux-build:test-macros.rs // For each of these, we should get the appropriate type mismatch error message, // and the function should be echoed. -extern crate span_preservation as foo; +#[macro_use] +extern crate test_macros; -use foo::foo; - -#[foo] +#[recollect_attr] fn a() { let x: usize = "hello";;;;; //~ ERROR mismatched types } -#[foo] +#[recollect_attr] fn b(x: Option) -> usize { match x { Some(x) => { return x }, //~ ERROR mismatched types @@ -21,7 +20,7 @@ fn b(x: Option) -> usize { } } -#[foo] +#[recollect_attr] fn c() { struct Foo { a: usize @@ -39,12 +38,12 @@ fn c() { // FIXME: This doesn't work at the moment. See the one below. The pretty-printer // injects a "C" between `extern` and `fn` which causes a "probably_eq" // `TokenStream` mismatch. The lack of `"C"` should be preserved in the AST. -#[foo] +#[recollect_attr] extern fn bar() { 0 } -#[foo] +#[recollect_attr] extern "C" fn baz() { 0 //~ ERROR mismatched types } diff --git a/src/test/ui/proc-macro/span-preservation.stderr b/src/test/ui/proc-macro/span-preservation.stderr index 1cc7706ce3a4c..cf03deee7e445 100644 --- a/src/test/ui/proc-macro/span-preservation.stderr +++ b/src/test/ui/proc-macro/span-preservation.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types found type `{integer}` error[E0308]: mismatched types - --> $DIR/span-preservation.rs:13:20 + --> $DIR/span-preservation.rs:12:20 | LL | let x: usize = "hello";;;;; | ^^^^^^^ expected usize, found reference @@ -13,7 +13,7 @@ LL | let x: usize = "hello";;;;; found type `&'static str` error[E0308]: mismatched types - --> $DIR/span-preservation.rs:19:29 + --> $DIR/span-preservation.rs:18:29 | LL | fn b(x: Option) -> usize { | ----- expected `usize` because of return type @@ -22,13 +22,13 @@ LL | Some(x) => { return x }, | ^ expected usize, found isize error[E0308]: mismatched types - --> $DIR/span-preservation.rs:35:22 + --> $DIR/span-preservation.rs:34:22 | LL | let x = Foo { a: 10isize }; | ^^^^^^^ expected usize, found isize error[E0560]: struct `c::Foo` has no field named `b` - --> $DIR/span-preservation.rs:36:26 + --> $DIR/span-preservation.rs:35:26 | LL | let y = Foo { a: 10, b: 10isize }; | ^ `c::Foo` does not have this field @@ -36,7 +36,7 @@ LL | let y = Foo { a: 10, b: 10isize }; = note: available fields are: `a` error[E0308]: mismatched types - --> $DIR/span-preservation.rs:49:5 + --> $DIR/span-preservation.rs:48:5 | LL | extern "C" fn baz() { | - possibly return type missing here? From f27ec0f05f2f90ca0291c24a58022b789792c8bf Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Sat, 25 May 2019 15:02:35 -0500 Subject: [PATCH 03/31] Add test that impl Seek for BufReader correctly invalidates buffer between seeks --- src/libstd/io/buffered.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index e309f81192cf3..3bdb1e34a8b73 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1162,6 +1162,40 @@ mod tests { assert_eq!(reader.get_ref().pos, expected); } + fn test_buffered_reader_seek_underflow_discard_buffer_between_seeks() { + // gimmick reader that returns Err after first seek + struct ErrAfterFirstSeekReader { + first_seek: bool, + } + impl Read for ErrAfterFirstSeekReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + for x in &mut *buf { + *x = 0; + } + Ok(buf.len()) + } + } + impl Seek for ErrAfterFirstSeekReader { + fn seek(&mut self, _: SeekFrom) -> io::Result { + if self.first_seek { + self.first_seek = false; + Ok(0) + } else { + Err(io::Error::new(io::ErrorKind::Other, "oh no!")) + } + } + } + + let mut reader = BufReader::with_capacity(5, ErrAfterFirstSeekReader { first_seek: true }); + assert_eq!(reader.fill_buf().ok(), Some(&[0, 0, 0, 0, 0][..])); + + // The following seek will require two underlying seeks. The first will + // succeed but the second will fail. This should still invalidate the + // buffer. + assert!(reader.seek(SeekFrom::Current(i64::min_value())).is_err()); + assert_eq!(reader.buffer().len(), 0); + } + #[test] fn test_buffered_writer() { let inner = Vec::new(); From b1ae49cae078d472d9ac55168d7bf5e07ff15a40 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Sat, 25 May 2019 16:37:38 -0500 Subject: [PATCH 04/31] Annotate test with #[test] --- src/libstd/io/buffered.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 3bdb1e34a8b73..d0e56acc8fb27 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1162,6 +1162,7 @@ mod tests { assert_eq!(reader.get_ref().pos, expected); } + #[test] fn test_buffered_reader_seek_underflow_discard_buffer_between_seeks() { // gimmick reader that returns Err after first seek struct ErrAfterFirstSeekReader { From 04e45c877fc43a6b1624adfddeed5700becfa543 Mon Sep 17 00:00:00 2001 From: oberien Date: Sun, 26 May 2019 02:55:21 +0200 Subject: [PATCH 05/31] Print file mode of PermissionExt in octal in Examples --- src/libstd/sys/redox/ext/fs.rs | 2 +- src/libstd/sys/unix/ext/fs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/redox/ext/fs.rs b/src/libstd/sys/redox/ext/fs.rs index 53b9dd68f734f..4ddc1f09a319b 100644 --- a/src/libstd/sys/redox/ext/fs.rs +++ b/src/libstd/sys/redox/ext/fs.rs @@ -27,7 +27,7 @@ pub trait PermissionsExt { /// let metadata = f.metadata()?; /// let permissions = metadata.permissions(); /// - /// println!("permissions: {}", permissions.mode()); + /// println!("permissions: {:o}", permissions.mode()); /// Ok(()) /// } /// ``` diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index d9baac993c42c..c033c60cbe9e1 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -238,7 +238,7 @@ pub trait PermissionsExt { /// let metadata = f.metadata()?; /// let permissions = metadata.permissions(); /// - /// println!("permissions: {}", permissions.mode()); + /// println!("permissions: {:o}", permissions.mode()); /// Ok(()) } /// ``` #[stable(feature = "fs_ext", since = "1.1.0")] From 7bba62c309a807f886ea17ed0907b3d914d96207 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 28 May 2019 06:40:16 -0400 Subject: [PATCH 06/31] Fixing mailmap for Carol --- .mailmap | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.mailmap b/.mailmap index 2d5759b539e5d..cde116c6f8033 100644 --- a/.mailmap +++ b/.mailmap @@ -46,8 +46,9 @@ Brian Anderson Brian Dawn Brian Leibig Brian Leibig Carl-Anton Ingmarsson +Carol (Nichols || Goulding) <193874+carols10cents@users.noreply.github.com> +Carol (Nichols || Goulding) Carol (Nichols || Goulding) -Carol (Nichols || Goulding) Carol Nichols Carol Willing Chris C Cerami Chris C Cerami Chris Pressey From 2a6490c7ff65b6bc67ddd9d3b2805529e36ac85d Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 28 May 2019 06:40:41 -0400 Subject: [PATCH 07/31] Adding mailmap for myself --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index cde116c6f8033..6e54a71d10f68 100644 --- a/.mailmap +++ b/.mailmap @@ -131,6 +131,8 @@ Jonathan Turner Jorge Aparicio Joseph Martin João Oliveira joaoxsouls +Joseph T. Lyons +Joseph T. Lyons Junyoung Cho Jyun-Yan You Kang Seonghoon From b0c3385a6348d8ed3ed71d95b643c9ec041cc5e3 Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Tue, 28 May 2019 06:42:47 -0400 Subject: [PATCH 08/31] Alphabetized lines with Atom's Sort Lines package https://github.com/atom/sort-lines --- .mailmap | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.mailmap b/.mailmap index 6e54a71d10f68..679aa55d31458 100644 --- a/.mailmap +++ b/.mailmap @@ -5,8 +5,8 @@ # email addresses. # -Aaron Todd Aaron Power Erin Power +Aaron Todd Abhishek Chanda Abhishek Chanda Adolfo Ochagavía Adrien Tétar @@ -29,8 +29,8 @@ Ariel Ben-Yehuda Ariel Ben-Yehuda Ariel Ben-Yehuda arielb1 Austin Seipp Aydin Kim aydin.kim -Bastian Kauschke Barosl Lee Barosl LEE +Bastian Kauschke Ben Alpert Ben Sago Ben S Ben Sago Ben S @@ -54,15 +54,15 @@ Chris C Cerami Chris C Cerami Chris Thorn Chris Thorn Chris Vittal Christopher Vittal -Christian Poveda Christian Poveda +Christian Poveda Clark Gaebel Clinton Ryan Corey Richardson Elaine "See More" Nemo Cyryl PÅ‚otnicki Damien Schoof -Daniel Ramos Daniel J Rollins +Daniel Ramos David Klein David Manescu David Ross @@ -71,9 +71,9 @@ Diggory Hardy Diggory Hardy Dylan Braithwaite Dzmitry Malyshau E. Dunham edunham +Eduard-Mihai Burtescu Eduardo Bautista <=> Eduardo Bautista -Eduard-Mihai Burtescu Elliott Slaughter Elly Fong-Jones Eric Holk @@ -81,8 +81,8 @@ Eric Holk Eric Holmes Eric Reed Erick Tryzelaar -Esteban Küber Esteban Küber +Esteban Küber Esteban Küber Evgeny Sologubov Falco Hirschenberger @@ -103,9 +103,9 @@ Herman J. Radtke III Herman J. Radtke III Ivan Ivaschenko J. J. Weber +Jakub Adam Wieczorek Jakub Adam Wieczorek Jakub Adam Wieczorek -Jakub Adam Wieczorek James Deng James Miller James Perry @@ -120,6 +120,7 @@ Jethro Beekman Jihyun Yu Jihyun Yu jihyun Jihyun Yu Jihyun Yu +João Oliveira joaoxsouls Johann Hofmann Johann John Clements John Hodge John Hodge @@ -130,7 +131,6 @@ Jonathan S Jonathan S Jonathan Turner Jorge Aparicio Joseph Martin -João Oliveira joaoxsouls Joseph T. Lyons Joseph T. Lyons Junyoung Cho @@ -148,8 +148,6 @@ Lindsey Kuper Luke Metz Luqman Aden Luqman Aden -NAKASHIMA, Makoto -NAKASHIMA, Makoto Marcell Pardavi Margaret Meyerhofer Mark Rousskov @@ -170,12 +168,14 @@ Michael Woerister Mickaël Raybaud-Roig m-r-r Ms2ger Mukilan Thiagarajan +NAKASHIMA, Makoto +NAKASHIMA, Makoto Nathan West Nathan Wilson Nathaniel Herman Nathaniel Herman Neil Pankey -Nicole Mazzuca Nick Platt +Nicole Mazzuca Nif Ward Oliver Schneider oli-obk Oliver Schneider Oliver 'ker' Schneider @@ -233,8 +233,8 @@ Tim JIANG Tim Joseph Dumol Torsten Weber Ty Overby -Ulrik Sverdrup bluss Ulrik Sverdrup bluss +Ulrik Sverdrup bluss Ulrik Sverdrup Ulrik Sverdrup Vadim Petrochenkov Vadim Petrochenkov petrochenkov From ce7689293b84a0309488b4a5d832ed2fa0d8bf0f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 May 2019 18:04:37 +0200 Subject: [PATCH 09/31] mention that MaybeUninit is a bit like Option --- src/libcore/mem.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index ce4aee7ebc54f..058c01cdf1007 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -966,6 +966,9 @@ impl DerefMut for ManuallyDrop { /// /// The compiler then knows to not make any incorrect assumptions or optimizations on this code. /// +/// You can think of `MaybeUninit` and being a bit like `Option` but without +/// any of the run-time tracking and without any of the safety checks. +/// /// ## out-pointers /// /// You can use `MaybeUninit` to implement "out-pointers": instead of returning data From 2bf80cf6ca3a9cb516216592e66b589e96839868 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 May 2019 18:20:24 +0200 Subject: [PATCH 10/31] Update src/libcore/mem.rs Co-Authored-By: Mazdak Farrokhzad --- src/libcore/mem.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 058c01cdf1007..40f4354213b40 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -966,7 +966,7 @@ impl DerefMut for ManuallyDrop { /// /// The compiler then knows to not make any incorrect assumptions or optimizations on this code. /// -/// You can think of `MaybeUninit` and being a bit like `Option` but without +/// You can think of `MaybeUninit` as being a bit like `Option` but without /// any of the run-time tracking and without any of the safety checks. /// /// ## out-pointers From 6e5e0daff2aee5ec5832ed22499417ffdf4b3827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claude-Alban=20RAN=C3=89LY-VERG=C3=89-D=C3=89PR=C3=89?= Date: Fri, 17 May 2019 23:55:04 +0200 Subject: [PATCH 11/31] Changes the type `mir::Mir` into `mir::Body` The commit should have changed comments as well. At the time of writting, it passes the tidy and check tool. Revisions asked by eddyb : - Renamed of all the occurences of {visit/super}_mir - Renamed test structures `CachedMir` to `Cached` Fixing the missing import on `AggregateKind` --- src/librustc/mir/cache.rs | 6 +-- src/librustc/mir/mod.rs | 42 +++++++++--------- src/librustc/mir/traversal.rs | 18 ++++---- src/librustc/mir/visit.rs | 10 ++--- src/librustc/query/mod.rs | 12 ++--- src/librustc/ty/context.rs | 10 ++--- src/librustc/ty/mod.rs | 4 +- src/librustc/ty/steal.rs | 2 +- .../debuginfo/create_scope_map.rs | 6 +-- src/librustc_codegen_llvm/debuginfo/mod.rs | 4 +- src/librustc_codegen_ssa/mir/analyze.rs | 8 ++-- src/librustc_codegen_ssa/mir/mod.rs | 8 ++-- src/librustc_codegen_ssa/traits/debuginfo.rs | 4 +- src/librustc_metadata/decoder.rs | 4 +- src/librustc_metadata/encoder.rs | 2 +- src/librustc_metadata/schema.rs | 2 +- src/librustc_mir/borrow_check/borrow_set.rs | 10 ++--- src/librustc_mir/borrow_check/location.rs | 4 +- src/librustc_mir/borrow_check/mod.rs | 14 +++--- .../borrow_check/mutability_errors.rs | 4 +- .../borrow_check/nll/constraint_generation.rs | 4 +- .../nll/explain_borrow/find_use.rs | 8 ++-- .../borrow_check/nll/explain_borrow/mod.rs | 4 +- .../borrow_check/nll/invalidation.rs | 8 ++-- src/librustc_mir/borrow_check/nll/mod.rs | 10 ++--- .../nll/region_infer/error_reporting/mod.rs | 18 ++++---- .../error_reporting/region_name.rs | 14 +++--- .../region_infer/error_reporting/var_name.rs | 6 +-- .../borrow_check/nll/region_infer/mod.rs | 28 ++++++------ .../borrow_check/nll/region_infer/values.rs | 6 +-- src/librustc_mir/borrow_check/nll/renumber.rs | 12 ++--- .../nll/type_check/input_output.rs | 2 +- .../nll/type_check/liveness/local_use_map.rs | 6 +-- .../nll/type_check/liveness/mod.rs | 6 +-- .../nll/type_check/liveness/trace.rs | 6 +-- .../borrow_check/nll/type_check/mod.rs | 44 +++++++++---------- src/librustc_mir/borrow_check/path_utils.rs | 4 +- src/librustc_mir/borrow_check/place_ext.rs | 6 +-- .../borrow_check/places_conflict.rs | 10 ++--- src/librustc_mir/borrow_check/prefixes.rs | 4 +- src/librustc_mir/borrow_check/used_muts.rs | 2 +- src/librustc_mir/build/mod.rs | 22 +++++----- src/librustc_mir/const_eval.rs | 6 +-- .../dataflow/drop_flag_effects.rs | 20 ++++----- src/librustc_mir/dataflow/graphviz.rs | 14 +++--- .../dataflow/impls/borrowed_locals.rs | 6 +-- src/librustc_mir/dataflow/impls/borrows.rs | 8 ++-- src/librustc_mir/dataflow/impls/mod.rs | 18 ++++---- .../dataflow/impls/storage_liveness.rs | 6 +-- src/librustc_mir/dataflow/mod.rs | 14 +++--- .../dataflow/move_paths/builder.rs | 6 +-- src/librustc_mir/dataflow/move_paths/mod.rs | 6 +-- src/librustc_mir/interpret/eval_context.rs | 8 ++-- src/librustc_mir/interpret/machine.rs | 2 +- src/librustc_mir/lints.rs | 6 +-- src/librustc_mir/monomorphize/collector.rs | 4 +- src/librustc_mir/shim.rs | 24 +++++----- src/librustc_mir/transform/add_call_guards.rs | 4 +- .../transform/add_moves_for_packed_drops.rs | 8 ++-- src/librustc_mir/transform/add_retag.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 6 +-- .../transform/cleanup_post_borrowck.rs | 6 +-- src/librustc_mir/transform/const_prop.rs | 16 +++---- src/librustc_mir/transform/copy_prop.rs | 10 ++--- src/librustc_mir/transform/deaggregator.rs | 2 +- src/librustc_mir/transform/dump_mir.rs | 6 +-- src/librustc_mir/transform/elaborate_drops.rs | 10 ++--- src/librustc_mir/transform/erase_regions.rs | 4 +- src/librustc_mir/transform/generator.rs | 44 +++++++++---------- src/librustc_mir/transform/inline.rs | 18 ++++---- src/librustc_mir/transform/instcombine.rs | 13 +++--- src/librustc_mir/transform/lower_128bit.rs | 4 +- src/librustc_mir/transform/mod.rs | 16 +++---- src/librustc_mir/transform/no_landing_pads.rs | 6 +-- src/librustc_mir/transform/promote_consts.rs | 14 +++--- src/librustc_mir/transform/qualify_consts.rs | 6 +-- .../transform/qualify_min_const_fn.rs | 13 +++--- .../transform/remove_noop_landing_pads.rs | 8 ++-- src/librustc_mir/transform/rustc_peek.rs | 8 ++-- src/librustc_mir/transform/simplify.rs | 14 +++--- .../transform/simplify_branches.rs | 2 +- .../transform/uniform_array_move_out.rs | 12 ++--- src/librustc_mir/util/collect_writes.rs | 6 +-- src/librustc_mir/util/def_use.rs | 14 +++--- src/librustc_mir/util/elaborate_drops.rs | 2 +- src/librustc_mir/util/graphviz.rs | 10 ++--- src/librustc_mir/util/liveness.rs | 8 ++-- src/librustc_mir/util/patch.rs | 8 ++-- src/librustc_mir/util/pretty.rs | 16 +++---- .../regions/regions-lub-ref-ref-rc.rs | 8 ++-- 90 files changed, 441 insertions(+), 435 deletions(-) diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs index 1cc927b1f720f..007013f8f8287 100644 --- a/src/librustc/mir/cache.rs +++ b/src/librustc/mir/cache.rs @@ -3,7 +3,7 @@ use rustc_data_structures::sync::{RwLock, MappedReadGuard, ReadGuard}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; use crate::ich::StableHashingContext; -use crate::mir::{Mir, BasicBlock}; +use crate::mir::{Body, BasicBlock}; use crate::rustc_serialize as serialize; @@ -47,7 +47,7 @@ impl Cache { pub fn predecessors( &self, - mir: &Mir<'_> + mir: &Body<'_> ) -> MappedReadGuard<'_, IndexVec>> { if self.predecessors.borrow().is_none() { *self.predecessors.borrow_mut() = Some(calculate_predecessors(mir)); @@ -57,7 +57,7 @@ impl Cache { } } -fn calculate_predecessors(mir: &Mir<'_>) -> IndexVec> { +fn calculate_predecessors(mir: &Body<'_>) -> IndexVec> { let mut result = IndexVec::from_elem(vec![], mir.basic_blocks()); for (bb, data) in mir.basic_blocks().iter_enumerated() { if let Some(ref term) = data.terminator { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 84aff8101a09d..d2cfcdcf158ea 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -60,7 +60,7 @@ impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { } } -impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> { +impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> { fn local_decls(&self) -> &LocalDecls<'tcx> { &self.local_decls } @@ -86,7 +86,7 @@ impl MirPhase { /// Lowered representation of a single function. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Mir<'tcx> { +pub struct Body<'tcx> { /// List of basic blocks. References to basic block use a newtyped index type `BasicBlock` /// that indexes into this vector. basic_blocks: IndexVec>, @@ -107,15 +107,15 @@ pub struct Mir<'tcx> { pub source_scope_local_data: ClearCrossCrate>, /// Rvalues promoted from this function, such as borrows of constants. - /// Each of them is the Mir of a constant with the fn's type parameters + /// Each of them is the Body of a constant with the fn's type parameters /// in scope, but a separate set of locals. - pub promoted: IndexVec>, + pub promoted: IndexVec>, /// Yields type of the function, if it is a generator. pub yield_ty: Option>, /// Generator drop glue - pub generator_drop: Option>>, + pub generator_drop: Option>>, /// The layout of a generator. Produced by the state transformation. pub generator_layout: Option>, @@ -167,12 +167,12 @@ pub struct Mir<'tcx> { cache: cache::Cache, } -impl<'tcx> Mir<'tcx> { +impl<'tcx> Body<'tcx> { pub fn new( basic_blocks: IndexVec>, source_scopes: IndexVec, source_scope_local_data: ClearCrossCrate>, - promoted: IndexVec>, + promoted: IndexVec>, yield_ty: Option>, local_decls: LocalDecls<'tcx>, user_type_annotations: CanonicalUserTypeAnnotations<'tcx>, @@ -189,7 +189,7 @@ impl<'tcx> Mir<'tcx> { local_decls.len() ); - Mir { + Body { phase: MirPhase::Build, basic_blocks, source_scopes, @@ -423,7 +423,7 @@ pub enum Safety { ExplicitUnsafe(hir::HirId), } -impl_stable_hash_for!(struct Mir<'tcx> { +impl_stable_hash_for!(struct Body<'tcx> { phase, basic_blocks, source_scopes, @@ -442,7 +442,7 @@ impl_stable_hash_for!(struct Mir<'tcx> { cache }); -impl<'tcx> Index for Mir<'tcx> { +impl<'tcx> Index for Body<'tcx> { type Output = BasicBlockData<'tcx>; #[inline] @@ -451,7 +451,7 @@ impl<'tcx> Index for Mir<'tcx> { } } -impl<'tcx> IndexMut for Mir<'tcx> { +impl<'tcx> IndexMut for Body<'tcx> { #[inline] fn index_mut(&mut self, index: BasicBlock) -> &mut BasicBlockData<'tcx> { &mut self.basic_blocks_mut()[index] @@ -599,7 +599,7 @@ newtype_index! { } } -/// Classifies locals into categories. See `Mir::local_kind`. +/// Classifies locals into categories. See `Body::local_kind`. #[derive(PartialEq, Eq, Debug, HashStable)] pub enum LocalKind { /// User-declared variable binding @@ -2831,23 +2831,23 @@ impl<'tcx> Display for Constant<'tcx> { } } -impl<'tcx> graph::DirectedGraph for Mir<'tcx> { +impl<'tcx> graph::DirectedGraph for Body<'tcx> { type Node = BasicBlock; } -impl<'tcx> graph::WithNumNodes for Mir<'tcx> { +impl<'tcx> graph::WithNumNodes for Body<'tcx> { fn num_nodes(&self) -> usize { self.basic_blocks.len() } } -impl<'tcx> graph::WithStartNode for Mir<'tcx> { +impl<'tcx> graph::WithStartNode for Body<'tcx> { fn start_node(&self) -> Self::Node { START_BLOCK } } -impl<'tcx> graph::WithPredecessors for Mir<'tcx> { +impl<'tcx> graph::WithPredecessors for Body<'tcx> { fn predecessors<'graph>( &'graph self, node: Self::Node, @@ -2856,7 +2856,7 @@ impl<'tcx> graph::WithPredecessors for Mir<'tcx> { } } -impl<'tcx> graph::WithSuccessors for Mir<'tcx> { +impl<'tcx> graph::WithSuccessors for Body<'tcx> { fn successors<'graph>( &'graph self, node: Self::Node, @@ -2865,12 +2865,12 @@ impl<'tcx> graph::WithSuccessors for Mir<'tcx> { } } -impl<'a, 'b> graph::GraphPredecessors<'b> for Mir<'a> { +impl<'a, 'b> graph::GraphPredecessors<'b> for Body<'a> { type Item = BasicBlock; type Iter = IntoIter; } -impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> { +impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> { type Item = BasicBlock; type Iter = iter::Cloned>; } @@ -2909,7 +2909,7 @@ impl Location { } /// Returns `true` if `other` is earlier in the control flow graph than `self`. - pub fn is_predecessor_of<'tcx>(&self, other: Location, mir: &Mir<'tcx>) -> bool { + pub fn is_predecessor_of<'tcx>(&self, other: Location, mir: &Body<'tcx>) -> bool { // If we are in the same block as the other location and are an earlier statement // then we are a predecessor of `other`. if self.block == other.block && self.statement_index < other.statement_index { @@ -3162,7 +3162,7 @@ CloneTypeFoldableAndLiftImpls! { } BraceStructTypeFoldableImpl! { - impl<'tcx> TypeFoldable<'tcx> for Mir<'tcx> { + impl<'tcx> TypeFoldable<'tcx> for Body<'tcx> { phase, basic_blocks, source_scopes, diff --git a/src/librustc/mir/traversal.rs b/src/librustc/mir/traversal.rs index f8398c27cc2da..75d995d801d78 100644 --- a/src/librustc/mir/traversal.rs +++ b/src/librustc/mir/traversal.rs @@ -21,14 +21,14 @@ use super::*; /// A preorder traversal of this graph is either `A B D C` or `A C D B` #[derive(Clone)] pub struct Preorder<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, visited: BitSet, worklist: Vec, root_is_start_block: bool, } impl<'a, 'tcx> Preorder<'a, 'tcx> { - pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> { + pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Preorder<'a, 'tcx> { let worklist = vec![root]; Preorder { @@ -40,7 +40,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> { } } -pub fn preorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Preorder<'a, 'tcx> { +pub fn preorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Preorder<'a, 'tcx> { Preorder::new(mir, START_BLOCK) } @@ -99,14 +99,14 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> { /// /// A Postorder traversal of this graph is `D B C A` or `D C B A` pub struct Postorder<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, visited: BitSet, visit_stack: Vec<(BasicBlock, Successors<'a>)>, root_is_start_block: bool, } impl<'a, 'tcx> Postorder<'a, 'tcx> { - pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> { + pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> { let mut po = Postorder { mir, visited: BitSet::new_empty(mir.basic_blocks().len()), @@ -194,7 +194,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> { } } -pub fn postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> Postorder<'a, 'tcx> { +pub fn postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> Postorder<'a, 'tcx> { Postorder::new(mir, START_BLOCK) } @@ -252,13 +252,13 @@ impl<'a, 'tcx> Iterator for Postorder<'a, 'tcx> { /// to re-use the traversal #[derive(Clone)] pub struct ReversePostorder<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, blocks: Vec, idx: usize } impl<'a, 'tcx> ReversePostorder<'a, 'tcx> { - pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> { + pub fn new(mir: &'a Body<'tcx>, root: BasicBlock) -> ReversePostorder<'a, 'tcx> { let blocks : Vec<_> = Postorder::new(mir, root).map(|(bb, _)| bb).collect(); let len = blocks.len(); @@ -276,7 +276,7 @@ impl<'a, 'tcx> ReversePostorder<'a, 'tcx> { } -pub fn reverse_postorder<'a, 'tcx>(mir: &'a Mir<'tcx>) -> ReversePostorder<'a, 'tcx> { +pub fn reverse_postorder<'a, 'tcx>(mir: &'a Body<'tcx>) -> ReversePostorder<'a, 'tcx> { ReversePostorder::new(mir, START_BLOCK) } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 64ffd80e21ec0..01c815fba9f3c 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -71,8 +71,8 @@ macro_rules! make_mir_visitor { // Override these, and call `self.super_xxx` to revert back to the // default behavior. - fn visit_mir(&mut self, mir: & $($mutability)? Mir<'tcx>) { - self.super_mir(mir); + fn visit_body(&mut self, mir: & $($mutability)? Body<'tcx>) { + self.super_body(mir); } fn visit_basic_block_data(&mut self, @@ -251,8 +251,8 @@ macro_rules! make_mir_visitor { // The `super_xxx` methods comprise the default behavior and are // not meant to be overridden. - fn super_mir(&mut self, - mir: & $($mutability)? Mir<'tcx>) { + fn super_body(&mut self, + mir: & $($mutability)? Body<'tcx>) { if let Some(yield_ty) = &$($mutability)? mir.yield_ty { self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo { span: mir.span, @@ -825,7 +825,7 @@ macro_rules! make_mir_visitor { // Convenience methods - fn visit_location(&mut self, mir: & $($mutability)? Mir<'tcx>, location: Location) { + fn visit_location(&mut self, mir: & $($mutability)? Body<'tcx>, location: Location) { let basic_block = & $($mutability)? mir[location.block]; if basic_block.statements.len() == location.statement_index { if let Some(ref $($mutability)? terminator) = basic_block.terminator { diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index ed363800d79de..39d91d66a438f 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -97,26 +97,26 @@ rustc_queries! { /// Fetch the MIR for a given `DefId` right after it's built - this includes /// unreachable code. - query mir_built(_: DefId) -> &'tcx Steal> {} + query mir_built(_: DefId) -> &'tcx Steal> {} /// Fetch the MIR for a given `DefId` up till the point where it is /// ready for const evaluation. /// /// See the README for the `mir` module for details. - query mir_const(_: DefId) -> &'tcx Steal> { + query mir_const(_: DefId) -> &'tcx Steal> { no_hash } - query mir_validated(_: DefId) -> &'tcx Steal> { + query mir_validated(_: DefId) -> &'tcx Steal> { no_hash } /// MIR after our optimization passes have run. This is MIR that is ready /// for codegen. This is also the only query that can fetch non-local MIR, at present. - query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> { + query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> { cache { key.is_local() } load_cached(tcx, id) { - let mir: Option> = tcx.queries.on_disk_cache + let mir: Option> = tcx.queries.on_disk_cache .try_load_query_result(tcx, id); mir.map(|x| tcx.alloc_mir(x)) } @@ -456,7 +456,7 @@ rustc_queries! { /// in the case of closures, this will be redirected to the enclosing function. query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {} - query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx> { + query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> { no_force desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index a56fe7d7003a1..7041789931854 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -23,7 +23,7 @@ use crate::middle::cstore::EncodedMetadata; use crate::middle::lang_items; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; -use crate::mir::{self, Mir, interpret, ProjectionKind}; +use crate::mir::{self, Body, interpret, ProjectionKind}; use crate::mir::interpret::{ConstValue, Allocation, Scalar}; use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst}; use crate::ty::ReprOptions; @@ -103,8 +103,8 @@ pub struct GlobalArenas<'tcx> { generics: TypedArena, trait_def: TypedArena, adt_def: TypedArena, - steal_mir: TypedArena>>, - mir: TypedArena>, + steal_mir: TypedArena>>, + mir: TypedArena>, tables: TypedArena>, /// miri allocations const_allocs: TypedArena, @@ -1154,11 +1154,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.global_arenas.generics.alloc(generics) } - pub fn alloc_steal_mir(self, mir: Mir<'gcx>) -> &'gcx Steal> { + pub fn alloc_steal_mir(self, mir: Body<'gcx>) -> &'gcx Steal> { self.global_arenas.steal_mir.alloc(Steal::new(mir)) } - pub fn alloc_mir(self, mir: Mir<'gcx>) -> &'gcx Mir<'gcx> { + pub fn alloc_mir(self, mir: Body<'gcx>) -> &'gcx Body<'gcx> { self.global_arenas.mir.alloc(mir) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index f1d1abfa0fb4b..fa993325e2712 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -19,7 +19,7 @@ use crate::ich::StableHashingContext; use crate::infer::canonical::Canonical; use crate::middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; -use crate::mir::Mir; +use crate::mir::Body; use crate::mir::interpret::{GlobalId, ErrorHandled}; use crate::mir::GeneratorLayout; use crate::session::CrateDisambiguator; @@ -3002,7 +3002,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair. pub fn instance_mir(self, instance: ty::InstanceDef<'gcx>) - -> &'gcx Mir<'gcx> + -> &'gcx Body<'gcx> { match instance { ty::InstanceDef::Item(did) => { diff --git a/src/librustc/ty/steal.rs b/src/librustc/ty/steal.rs index a8f9301ba51c9..a5a0b198734c1 100644 --- a/src/librustc/ty/steal.rs +++ b/src/librustc/ty/steal.rs @@ -9,7 +9,7 @@ use rustc_data_structures::sync::{RwLock, ReadGuard, MappedReadGuard}; /// queries are these pure functions that produce an immutable value /// (since if you did the query twice, you could observe the /// mutations). So instead we have the query produce a `&'tcx -/// Steal>` (to be very specific). Now we can read from this +/// Steal>` (to be very specific). Now we can read from this /// as much as we want (using `borrow()`), but you can also /// `steal()`. Once you steal, any further attempt to read will panic. /// Therefore, we know that -- assuming no ICE -- nobody is observing diff --git a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs index c8ddf733ecf1f..8b3ed5b0c623a 100644 --- a/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs +++ b/src/librustc_codegen_llvm/debuginfo/create_scope_map.rs @@ -5,7 +5,7 @@ use super::utils::{DIB, span_start}; use crate::llvm; use crate::llvm::debuginfo::{DIScope, DISubprogram}; use crate::common::CodegenCx; -use rustc::mir::{Mir, SourceScope}; +use rustc::mir::{Body, SourceScope}; use libc::c_uint; @@ -20,7 +20,7 @@ use syntax_pos::BytePos; /// If debuginfo is disabled, the returned vector is empty. pub fn create_mir_scopes( cx: &CodegenCx<'ll, '_>, - mir: &Mir<'_>, + mir: &Body<'_>, debug_context: &FunctionDebugContext<&'ll DISubprogram>, ) -> IndexVec> { let null_scope = MirDebugScope { @@ -55,7 +55,7 @@ pub fn create_mir_scopes( } fn make_mir_scope(cx: &CodegenCx<'ll, '_>, - mir: &Mir<'_>, + mir: &Body<'_>, has_variables: &BitSet, debug_context: &FunctionDebugContextData<&'ll DISubprogram>, scope: SourceScope, diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 527290392fff4..6fa594d445300 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -239,7 +239,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { instance: Instance<'tcx>, sig: ty::FnSig<'tcx>, llfn: &'ll Value, - mir: &mir::Mir<'_>, + mir: &mir::Body<'_>, ) -> FunctionDebugContext<&'ll DISubprogram> { if self.sess().opts.debuginfo == DebugInfo::None { return FunctionDebugContext::DebugInfoDisabled; @@ -523,7 +523,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn create_mir_scopes( &self, - mir: &mir::Mir<'_>, + mir: &mir::Body<'_>, debug_context: &mut FunctionDebugContext<&'ll DISubprogram>, ) -> IndexVec> { create_scope_map::create_mir_scopes(self, mir, debug_context) diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 06d7b6c78f14b..bb6a13ed15a52 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -18,7 +18,7 @@ pub fn non_ssa_locals<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( let mir = fx.mir; let mut analyzer = LocalAnalyzer::new(fx); - analyzer.visit_mir(mir); + analyzer.visit_body(mir); for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() { let ty = fx.monomorphize(&ty); @@ -272,9 +272,9 @@ impl CleanupKind { } } -pub fn cleanup_kinds<'a, 'tcx>(mir: &mir::Mir<'tcx>) -> IndexVec { +pub fn cleanup_kinds<'a, 'tcx>(mir: &mir::Body<'tcx>) -> IndexVec { fn discover_masters<'tcx>(result: &mut IndexVec, - mir: &mir::Mir<'tcx>) { + mir: &mir::Body<'tcx>) { for (bb, data) in mir.basic_blocks().iter_enumerated() { match data.terminator().kind { TerminatorKind::Goto { .. } | @@ -304,7 +304,7 @@ pub fn cleanup_kinds<'a, 'tcx>(mir: &mir::Mir<'tcx>) -> IndexVec(result: &mut IndexVec, - mir: &mir::Mir<'tcx>) { + mir: &mir::Body<'tcx>) { let mut funclet_succs = IndexVec::from_elem(None, mir.basic_blocks()); let mut set_successor = |funclet: mir::BasicBlock, succ| { diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index fed12c9a29fd2..4a43201dedf37 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -1,6 +1,6 @@ use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts}; use rustc::ty::layout::{TyLayout, HasTyCtxt, FnTypeExt}; -use rustc::mir::{self, Mir}; +use rustc::mir::{self, Body}; use rustc::session::config::DebugInfo; use rustc_mir::monomorphize::Instance; use rustc_target::abi::call::{FnType, PassMode, IgnoreMode}; @@ -27,7 +27,7 @@ use self::operand::{OperandRef, OperandValue}; pub struct FunctionCx<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { instance: Instance<'tcx>, - mir: &'a mir::Mir<'tcx>, + mir: &'a mir::Body<'tcx>, debug_context: FunctionDebugContext, @@ -196,7 +196,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> { pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, llfn: Bx::Value, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, instance: Instance<'tcx>, sig: ty::FnSig<'tcx>, ) { @@ -360,7 +360,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } fn create_funclets<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, bx: &mut Bx, cleanup_kinds: &IndexVec, block_bxs: &IndexVec) diff --git a/src/librustc_codegen_ssa/traits/debuginfo.rs b/src/librustc_codegen_ssa/traits/debuginfo.rs index aadffc5932ba8..37b7a15e2ba5e 100644 --- a/src/librustc_codegen_ssa/traits/debuginfo.rs +++ b/src/librustc_codegen_ssa/traits/debuginfo.rs @@ -22,12 +22,12 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes { instance: Instance<'tcx>, sig: ty::FnSig<'tcx>, llfn: Self::Value, - mir: &mir::Mir<'_>, + mir: &mir::Body<'_>, ) -> FunctionDebugContext; fn create_mir_scopes( &self, - mir: &mir::Mir<'_>, + mir: &mir::Body<'_>, debug_context: &mut FunctionDebugContext, ) -> IndexVec>; fn extend_scope_to_file( diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index a484928ce6c36..10ff606b013a7 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -18,7 +18,7 @@ use rustc::mir::interpret::AllocDecodingSession; use rustc::session::Session; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::codec::TyDecoder; -use rustc::mir::Mir; +use rustc::mir::Body; use rustc::util::captures::Captures; use std::io; @@ -887,7 +887,7 @@ impl<'a, 'tcx> CrateMetadata { pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefIndex) - -> Option> { + -> Option> { match self.is_proc_macro(id) { true => None, false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))), diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 5d080de2645e3..588682a2420a9 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1026,7 +1026,7 @@ impl EncodeContext<'_, 'tcx> { self.lazy_seq(param_names.iter().map(|ident| ident.name)) } - fn encode_optimized_mir(&mut self, def_id: DefId) -> Option>> { + fn encode_optimized_mir(&mut self, def_id: DefId) -> Option>> { debug!("EntryBuilder::encode_mir({:?})", def_id); if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) { let mir = self.tcx.optimized_mir(def_id); diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index b9e5bdef27ab4..2c3291a41d32b 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -222,7 +222,7 @@ pub struct Entry<'tcx> { pub predicates: Option>>, pub predicates_defined_on: Option>>, - pub mir: Option>>, + pub mir: Option>>, } #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 5ced497baa1fd..d9d6fe0affb32 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -5,7 +5,7 @@ use crate::dataflow::indexes::BorrowIndex; use crate::dataflow::move_paths::MoveData; use rustc::mir::traversal; use rustc::mir::visit::{PlaceContext, Visitor, NonUseContext, MutatingUseContext}; -use rustc::mir::{self, Location, Mir, Local}; +use rustc::mir::{self, Location, Body, Local}; use rustc::ty::{RegionVid, TyCtxt}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_data_structures::indexed_vec::IndexVec; @@ -90,7 +90,7 @@ crate enum LocalsStateAtExit { impl LocalsStateAtExit { fn build( locals_are_invalidated_at_exit: bool, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx> ) -> Self { struct HasStorageDead(BitSet); @@ -107,7 +107,7 @@ impl LocalsStateAtExit { LocalsStateAtExit::AllAreInvalidated } else { let mut has_storage_dead = HasStorageDead(BitSet::new_empty(mir.local_decls.len())); - has_storage_dead.visit_mir(mir); + has_storage_dead.visit_body(mir); let mut has_storage_dead_or_moved = has_storage_dead.0; for move_out in &move_data.moves { if let Some(index) = move_data.base_local(move_out.path) { @@ -123,7 +123,7 @@ impl LocalsStateAtExit { impl<'tcx> BorrowSet<'tcx> { pub fn build( tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, locals_are_invalidated_at_exit: bool, move_data: &MoveData<'tcx> ) -> Self { @@ -163,7 +163,7 @@ impl<'tcx> BorrowSet<'tcx> { struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, idx_vec: IndexVec>, location_map: FxHashMap, activation_map: FxHashMap>, diff --git a/src/librustc_mir/borrow_check/location.rs b/src/librustc_mir/borrow_check/location.rs index 20a477576c95c..feade0d2a4aee 100644 --- a/src/librustc_mir/borrow_check/location.rs +++ b/src/librustc_mir/borrow_check/location.rs @@ -1,4 +1,4 @@ -use rustc::mir::{BasicBlock, Location, Mir}; +use rustc::mir::{BasicBlock, Location, Body}; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; /// Maps between a MIR Location, which identifies a particular @@ -30,7 +30,7 @@ crate enum RichLocation { } impl LocationTable { - crate fn new(mir: &Mir<'_>) -> Self { + crate fn new(mir: &Body<'_>) -> Self { let mut num_points = 0; let statements_before_block = mir.basic_blocks() .iter() diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 437f95e332a3d..82be2405701d5 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -10,7 +10,9 @@ use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT}; use rustc::middle::borrowck::SignalledError; use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; use rustc::mir::{ - ClearCrossCrate, Local, Location, Mir, Mutability, Operand, Place, PlaceBase, Static, StaticKind + ClearCrossCrate, Local, Location, Body, Mutability, Operand, Place, PlaceBase, Static, + + StaticKind }; use rustc::mir::{Field, Projection, ProjectionElem, Rvalue, Statement, StatementKind}; use rustc::mir::{Terminator, TerminatorKind}; @@ -118,7 +120,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC } let opt_closure_req = tcx.infer_ctxt().enter(|infcx| { - let input_mir: &Mir<'_> = &input_mir.borrow(); + let input_mir: &Body<'_> = &input_mir.borrow(); do_mir_borrowck(&infcx, input_mir, def_id) }); debug!("mir_borrowck done"); @@ -128,7 +130,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC fn do_mir_borrowck<'a, 'gcx, 'tcx>( infcx: &InferCtxt<'a, 'gcx, 'tcx>, - input_mir: &Mir<'gcx>, + input_mir: &Body<'gcx>, def_id: DefId, ) -> BorrowCheckResult<'gcx> { debug!("do_mir_borrowck(def_id = {:?})", def_id); @@ -175,7 +177,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( // requires first making our own copy of the MIR. This copy will // be modified (in place) to contain non-lexical lifetimes. It // will have a lifetime tied to the inference context. - let mut mir: Mir<'tcx> = input_mir.clone(); + let mut mir: Body<'tcx> = input_mir.clone(); let free_regions = nll::replace_regions_in_mir(infcx, def_id, param_env, &mut mir); let mir = &mir; // no further changes let location_table = &LocationTable::new(mir); @@ -451,7 +453,7 @@ fn downgrade_if_error(diag: &mut Diagnostic) { pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> { infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>, - mir: &'cx Mir<'tcx>, + mir: &'cx Body<'tcx>, mir_def_id: DefId, move_data: &'cx MoveData<'tcx>, @@ -537,7 +539,7 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> { impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'gcx, 'tcx> { type FlowState = Flows<'cx, 'gcx, 'tcx>; - fn mir(&self) -> &'cx Mir<'tcx> { + fn mir(&self) -> &'cx Body<'tcx> { self.mir } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 16fbc8d6bb299..a292115707d8e 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -1,6 +1,6 @@ use rustc::hir; use rustc::hir::Node; -use rustc::mir::{self, BindingForm, Constant, ClearCrossCrate, Local, Location, Mir}; +use rustc::mir::{self, BindingForm, Constant, ClearCrossCrate, Local, Location, Body}; use rustc::mir::{ Mutability, Operand, Place, PlaceBase, Projection, ProjectionElem, Static, StaticKind, }; @@ -562,7 +562,7 @@ fn suggest_ampmut_self<'cx, 'gcx, 'tcx>( // by trying (3.), then (2.) and finally falling back on (1.). fn suggest_ampmut<'cx, 'gcx, 'tcx>( tcx: TyCtxt<'cx, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, local: Local, local_decl: &mir::LocalDecl<'tcx>, opt_ty_info: Option, diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index b0e395cbbdfb5..b485f37b78c2d 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -6,7 +6,7 @@ use crate::borrow_check::nll::region_infer::values::LivenessValues; use rustc::infer::InferCtxt; use rustc::mir::visit::TyContext; use rustc::mir::visit::Visitor; -use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, PlaceBase, Rvalue}; +use rustc::mir::{BasicBlock, BasicBlockData, Location, Body, Place, PlaceBase, Rvalue}; use rustc::mir::{SourceInfo, Statement, Terminator}; use rustc::mir::UserTypeProjection; use rustc::ty::fold::TypeFoldable; @@ -18,7 +18,7 @@ pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>( liveness_constraints: &mut LivenessValues, all_facts: &mut Option, location_table: &LocationTable, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, borrow_set: &BorrowSet<'tcx>, ) { let mut cg = ConstraintGeneration { diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs index 9a2090d05084d..3921246b06d38 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs @@ -5,12 +5,12 @@ use crate::borrow_check::nll::region_infer::{Cause, RegionInferenceContext}; use crate::borrow_check::nll::ToRegionVid; use crate::util::liveness::{self, DefUse}; use rustc::mir::visit::{MirVisitable, PlaceContext, Visitor}; -use rustc::mir::{Local, Location, Mir}; +use rustc::mir::{Local, Location, Body}; use rustc::ty::{RegionVid, TyCtxt}; use rustc_data_structures::fx::FxHashSet; crate fn find<'tcx>( - mir: &Mir<'tcx>, + mir: &Body<'tcx>, regioncx: &Rc>, tcx: TyCtxt<'_, '_, 'tcx>, region_vid: RegionVid, @@ -28,7 +28,7 @@ crate fn find<'tcx>( } struct UseFinder<'cx, 'gcx: 'tcx, 'tcx: 'cx> { - mir: &'cx Mir<'tcx>, + mir: &'cx Body<'tcx>, regioncx: &'cx Rc>, tcx: TyCtxt<'cx, 'gcx, 'tcx>, region_vid: RegionVid, @@ -100,7 +100,7 @@ impl<'cx, 'gcx, 'tcx> UseFinder<'cx, 'gcx, 'tcx> { } struct DefUseVisitor<'cx, 'gcx: 'tcx, 'tcx: 'cx> { - mir: &'cx Mir<'tcx>, + mir: &'cx Body<'tcx>, tcx: TyCtxt<'cx, 'gcx, 'tcx>, region_vid: RegionVid, def_use_result: Option, diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 6bca470bf3e5f..60c46b36f5f06 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -6,7 +6,7 @@ use crate::borrow_check::nll::region_infer::{Cause, RegionName}; use crate::borrow_check::nll::ConstraintDescription; use crate::borrow_check::{MirBorrowckCtxt, WriteKind}; use rustc::mir::{ - CastKind, ConstraintCategory, FakeReadCause, Local, Location, Mir, Operand, Place, PlaceBase, + CastKind, ConstraintCategory, FakeReadCause, Local, Location, Body, Operand, Place, PlaceBase, Projection, ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, }; use rustc::ty::{self, TyCtxt}; @@ -54,7 +54,7 @@ impl BorrowExplanation { pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'cx, 'gcx, 'tcx>( &self, tcx: TyCtxt<'cx, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, err: &mut DiagnosticBuilder<'_>, borrow_desc: &str, borrow_span: Option, diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index e3ab48ccff15b..017f4d48c1200 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -11,7 +11,7 @@ use crate::borrow_check::path_utils::*; use crate::dataflow::indexes::BorrowIndex; use rustc::ty::TyCtxt; use rustc::mir::visit::Visitor; -use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue}; +use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::TerminatorKind; use rustc::mir::{Operand, BorrowKind}; @@ -21,7 +21,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>( tcx: TyCtxt<'cx, 'gcx, 'tcx>, all_facts: &mut Option, location_table: &LocationTable, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, borrow_set: &BorrowSet<'tcx>, ) { if all_facts.is_none() { @@ -39,7 +39,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>( mir, dominators, }; - ig.visit_mir(mir); + ig.visit_body(mir); } } @@ -47,7 +47,7 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> { tcx: TyCtxt<'cx, 'gcx, 'tcx>, all_facts: &'cx mut AllFacts, location_table: &'cx LocationTable, - mir: &'cx Mir<'tcx>, + mir: &'cx Body<'tcx>, dominators: Dominators, borrow_set: &'cx BorrowSet<'tcx>, } diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index fa490c108c896..0fb1705c8c294 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -11,7 +11,7 @@ use crate::transform::MirSource; use crate::borrow_check::Upvar; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; -use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Mir}; +use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Body}; use rustc::ty::{self, RegionKind, RegionVid}; use rustc_errors::Diagnostic; use std::fmt::Debug; @@ -50,7 +50,7 @@ pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'gcx, 'tcx>( infcx: &InferCtxt<'cx, 'gcx, 'tcx>, def_id: DefId, param_env: ty::ParamEnv<'tcx>, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, ) -> UniversalRegions<'tcx> { debug!("replace_regions_in_mir(def_id={:?})", def_id); @@ -73,7 +73,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( infcx: &InferCtxt<'cx, 'gcx, 'tcx>, def_id: DefId, universal_regions: UniversalRegions<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], location_table: &LocationTable, param_env: ty::ParamEnv<'gcx>, @@ -213,7 +213,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( fn dump_mir_results<'a, 'gcx, 'tcx>( infcx: &InferCtxt<'a, 'gcx, 'tcx>, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, regioncx: &RegionInferenceContext<'_>, closure_region_requirements: &Option>, ) { @@ -273,7 +273,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( fn dump_annotation<'a, 'gcx, 'tcx>( infcx: &InferCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, regioncx: &RegionInferenceContext<'tcx>, closure_region_requirements: &Option>, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 18ca105070e8f..db43ea0558cc7 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -9,7 +9,7 @@ use rustc::hir::def_id::DefId; use rustc::infer::error_reporting::nice_region_error::NiceRegionError; use rustc::infer::InferCtxt; use rustc::infer::NLLRegionVariableOrigin; -use rustc::mir::{ConstraintCategory, Location, Mir}; +use rustc::mir::{ConstraintCategory, Location, Body}; use rustc::ty::{self, RegionVid}; use rustc_data_structures::indexed_vec::IndexVec; use rustc_errors::{Diagnostic, DiagnosticBuilder}; @@ -62,7 +62,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// path to blame. fn best_blame_constraint( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, from_region: RegionVid, target_test: impl Fn(RegionVid) -> bool, ) -> (ConstraintCategory, bool, Span) { @@ -237,7 +237,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`. pub(super) fn report_error( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], infcx: &InferCtxt<'_, '_, 'tcx>, mir_def_id: DefId, @@ -357,7 +357,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// ``` fn report_fnmut_error( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], infcx: &InferCtxt<'_, '_, 'tcx>, mir_def_id: DefId, @@ -422,7 +422,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// ``` fn report_escaping_data_error( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], infcx: &InferCtxt<'_, '_, 'tcx>, mir_def_id: DefId, @@ -514,7 +514,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// ``` fn report_general_error( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], infcx: &InferCtxt<'_, '_, 'tcx>, mir_def_id: DefId, @@ -667,7 +667,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { crate fn free_region_constraint_info( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, infcx: &InferCtxt<'_, '_, 'tcx>, @@ -724,7 +724,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Finds a good span to blame for the fact that `fr1` outlives `fr2`. crate fn find_outlives_blame_span( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, fr1: RegionVid, fr2: RegionVid, ) -> (ConstraintCategory, Span) { @@ -735,7 +735,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn retrieve_closure_constraint_info( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, constraint: &OutlivesConstraint, ) -> (ConstraintCategory, bool, Span) { let loc = match constraint.locations { diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index f3cfc1a59a981..25415039fc80a 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -7,7 +7,7 @@ use rustc::hir; use rustc::hir::def::{Res, DefKind}; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; -use rustc::mir::Mir; +use rustc::mir::Body; use rustc::ty::subst::{SubstsRef, UnpackedKind}; use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt}; use rustc::ty::print::RegionHighlightMode; @@ -152,7 +152,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { crate fn give_region_a_name( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, fr: RegionVid, @@ -332,7 +332,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_anonymous_region_appears_in_arguments( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, fr: RegionVid, counter: &mut usize, @@ -360,7 +360,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_we_can_match_hir_ty_from_argument( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, needle_fr: RegionVid, argument_ty: Ty<'tcx>, @@ -406,7 +406,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_we_cannot_match_hir_ty( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, needle_fr: RegionVid, argument_ty: Ty<'tcx>, counter: &mut usize, @@ -676,7 +676,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_anonymous_region_appears_in_output( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, fr: RegionVid, counter: &mut usize, @@ -736,7 +736,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_anonymous_region_appears_in_yield_ty( &self, infcx: &InferCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, fr: RegionVid, counter: &mut usize, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index d8f34233839b9..c02a492c34100 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -1,7 +1,7 @@ use crate::borrow_check::nll::region_infer::RegionInferenceContext; use crate::borrow_check::nll::ToRegionVid; use crate::borrow_check::Upvar; -use rustc::mir::{Local, Mir}; +use rustc::mir::{Local, Body}; use rustc::ty::{RegionVid, TyCtxt}; use rustc_data_structures::indexed_vec::Idx; use syntax::source_map::Span; @@ -11,7 +11,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { crate fn get_var_name_and_span_for_region( &self, tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], fr: RegionVid, ) -> Option<(Option, Span)> { @@ -120,7 +120,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// declared. crate fn get_argument_name_and_span_for_region( &self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, argument_index: usize, ) -> (Option, Span) { let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs(); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 9dd18ab76a5f2..4a00571feb110 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -13,7 +13,7 @@ use rustc::infer::region_constraints::{GenericKind, VarInfos, VerifyBound}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin}; use rustc::mir::{ ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, - ConstraintCategory, Local, Location, Mir, + ConstraintCategory, Local, Location, Body, }; use rustc::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::{self, ErrorReported}; @@ -185,7 +185,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { universal_regions: Rc>, placeholder_indices: Rc, universal_region_relations: Rc>, - _mir: &Mir<'tcx>, + _mir: &Body<'tcx>, outlives_constraints: ConstraintSet, closure_bounds_mapping: FxHashMap< Location, @@ -400,7 +400,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { pub(super) fn solve<'gcx>( &mut self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, errors_buffer: &mut Vec, @@ -416,7 +416,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn solve_inner<'gcx>( &mut self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, errors_buffer: &mut Vec, @@ -468,7 +468,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// for each region variable until all the constraints are /// satisfied. Note that some values may grow **too** large to be /// feasible, but we check this later. - fn propagate_constraints(&mut self, _mir: &Mir<'tcx>) { + fn propagate_constraints(&mut self, _mir: &Body<'tcx>) { debug!("propagate_constraints()"); debug!("propagate_constraints: constraints={:#?}", { @@ -581,7 +581,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn check_type_tests<'gcx>( &self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, mut propagated_outlives_requirements: Option<&mut Vec>>, errors_buffer: &mut Vec, @@ -725,7 +725,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn try_promote_type_test<'gcx>( &self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, type_test: &TypeTest<'tcx>, propagated_outlives_requirements: &mut Vec>, ) -> bool { @@ -944,7 +944,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn eval_verify_bound( &self, tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, generic_ty: Ty<'tcx>, lower_bound: RegionVid, verify_bound: &VerifyBound<'tcx>, @@ -977,7 +977,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn eval_if_eq( &self, tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, generic_ty: Ty<'tcx>, lower_bound: RegionVid, test_ty: Ty<'tcx>, @@ -1037,7 +1037,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Evaluate whether `sup_region: sub_region @ point`. fn eval_outlives( &self, - _mir: &Mir<'tcx>, + _mir: &Body<'tcx>, sup_region: RegionVid, sub_region: RegionVid, ) -> bool { @@ -1105,7 +1105,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn check_universal_regions<'gcx>( &self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, mut propagated_outlives_requirements: Option<&mut Vec>>, @@ -1150,7 +1150,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn check_universal_region<'gcx>( &self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, longer_fr: RegionVid, @@ -1216,7 +1216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { longer_fr: RegionVid, shorter_fr: RegionVid, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, upvars: &[Upvar], mir_def_id: DefId, propagated_outlives_requirements: &mut Option<&mut Vec>>, @@ -1282,7 +1282,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn check_bound_universal_region<'gcx>( &self, infcx: &InferCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, _mir_def_id: DefId, longer_fr: RegionVid, placeholder: ty::PlaceholderRegion, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/values.rs b/src/librustc_mir/borrow_check/nll/region_infer/values.rs index 2101447965a15..8822d7bb37393 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/values.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/values.rs @@ -1,4 +1,4 @@ -use rustc::mir::{BasicBlock, Location, Mir}; +use rustc::mir::{BasicBlock, Location, Body}; use rustc::ty::{self, RegionVid}; use rustc_data_structures::bit_set::{HybridBitSet, SparseBitMatrix}; use rustc_data_structures::fx::FxHashMap; @@ -20,7 +20,7 @@ crate struct RegionValueElements { } impl RegionValueElements { - crate fn new(mir: &Mir<'_>) -> Self { + crate fn new(mir: &Body<'_>) -> Self { let mut num_points = 0; let statements_before_block: IndexVec = mir.basic_blocks() .iter() @@ -92,7 +92,7 @@ impl RegionValueElements { /// Pushes all predecessors of `index` onto `stack`. crate fn push_predecessors( &self, - mir: &Mir<'_>, + mir: &Body<'_>, index: PointIndex, stack: &mut Vec, ) { diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index 58e567c39a9bb..a3b142c2ffcc3 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,17 +1,17 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable}; -use rustc::mir::{Location, Mir}; +use rustc::mir::{Location, Body}; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; /// Replaces all free regions appearing in the MIR with fresh /// inference variables, returning the number of variables created. -pub fn renumber_mir<'tcx>(infcx: &InferCtxt<'_, '_, 'tcx>, mir: &mut Mir<'tcx>) { +pub fn renumber_mir<'tcx>(infcx: &InferCtxt<'_, '_, 'tcx>, mir: &mut Body<'tcx>) { debug!("renumber_mir()"); debug!("renumber_mir: mir.arg_count={:?}", mir.arg_count); let mut visitor = NLLVisitor { infcx }; - visitor.visit_mir(mir); + visitor.visit_body(mir); } /// Replaces all regions appearing in `value` with fresh inference @@ -47,12 +47,12 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> { } impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> { - fn visit_mir(&mut self, mir: &mut Mir<'tcx>) { + fn visit_body(&mut self, mir: &mut Body<'tcx>) { for promoted in mir.promoted.iter_mut() { - self.visit_mir(promoted); + self.visit_body(promoted); } - self.super_mir(mir); + self.super_body(mir); } fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) { diff --git a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs index 50828c294fa1b..120088e1784d4 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs @@ -20,7 +20,7 @@ use super::{Locations, TypeChecker}; impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { pub(super) fn equate_inputs_and_outputs( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, universal_regions: &UniversalRegions<'tcx>, normalized_inputs_and_output: &[Ty<'tcx>], ) { diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs index 6ba41806a313f..e1a7b9babd48a 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs @@ -1,7 +1,7 @@ use crate::borrow_check::nll::region_infer::values::{PointIndex, RegionValueElements}; use crate::util::liveness::{categorize, DefUse}; use rustc::mir::visit::{PlaceContext, Visitor}; -use rustc::mir::{Local, Location, Mir}; +use rustc::mir::{Local, Location, Body}; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_data_structures::vec_linked_list as vll; @@ -60,7 +60,7 @@ impl LocalUseMap { crate fn build( live_locals: &Vec, elements: &RegionValueElements, - mir: &Mir<'_>, + mir: &Body<'_>, ) -> Self { let nones = IndexVec::from_elem_n(None, mir.local_decls.len()); let mut local_use_map = LocalUseMap { @@ -81,7 +81,7 @@ impl LocalUseMap { elements, locals_with_use_data, } - .visit_mir(mir); + .visit_body(mir); local_use_map } diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs index 58a164b38f911..3cefab36e2351 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/mod.rs @@ -7,7 +7,7 @@ use crate::borrow_check::nll::ToRegionVid; use crate::dataflow::move_paths::MoveData; use crate::dataflow::FlowAtLocation; use crate::dataflow::MaybeInitializedPlaces; -use rustc::mir::{Local, Mir}; +use rustc::mir::{Local, Body}; use rustc::ty::{RegionVid, TyCtxt}; use rustc_data_structures::fx::FxHashSet; use std::rc::Rc; @@ -27,7 +27,7 @@ mod trace; /// performed before pub(super) fn generate<'gcx, 'tcx>( typeck: &mut TypeChecker<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, elements: &Rc, flow_inits: &mut FlowAtLocation<'tcx, MaybeInitializedPlaces<'_, 'gcx, 'tcx>>, move_data: &MoveData<'tcx>, @@ -77,7 +77,7 @@ pub(super) fn generate<'gcx, 'tcx>( fn compute_live_locals( tcx: TyCtxt<'_, '_, 'tcx>, free_regions: &FxHashSet, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ) -> Vec { let live_locals: Vec = mir .local_decls diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs index 87e9a704fac1e..345780c4760eb 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs @@ -7,7 +7,7 @@ use crate::dataflow::indexes::MovePathIndex; use crate::dataflow::move_paths::MoveData; use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces}; use rustc::infer::canonical::QueryRegionConstraint; -use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Mir}; +use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Body}; use rustc::traits::query::dropck_outlives::DropckOutlivesResult; use rustc::traits::query::type_op::outlives::DropckOutlives; use rustc::traits::query::type_op::TypeOp; @@ -32,7 +32,7 @@ use std::rc::Rc; /// this respects `#[may_dangle]` annotations). pub(super) fn trace( typeck: &mut TypeChecker<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, elements: &Rc, flow_inits: &mut FlowAtLocation<'tcx, MaybeInitializedPlaces<'_, 'gcx, 'tcx>>, move_data: &MoveData<'tcx>, @@ -72,7 +72,7 @@ where elements: &'me RegionValueElements, /// MIR we are analyzing. - mir: &'me Mir<'tcx>, + mir: &'me Body<'tcx>, /// Mapping to/from the various indices used for initialization tracking. move_data: &'me MoveData<'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index de8e75ca277ee..84799eb97ed8a 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -112,7 +112,7 @@ mod relate_tys; pub(crate) fn type_check<'gcx, 'tcx>( infcx: &InferCtxt<'_, 'gcx, 'tcx>, param_env: ty::ParamEnv<'gcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mir_def_id: DefId, universal_regions: &Rc>, location_table: &LocationTable, @@ -179,7 +179,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>( infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, mir_def_id: DefId, param_env: ty::ParamEnv<'gcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, region_bound_pairs: &'a RegionBoundPairs<'tcx>, implicit_region_bound: ty::Region<'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, @@ -198,7 +198,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, R>( ); let errors_reported = { let mut verifier = TypeVerifier::new(&mut checker, mir); - verifier.visit_mir(mir); + verifier.visit_body(mir); verifier.errors_reported }; @@ -253,7 +253,7 @@ enum FieldAccessError { /// is a problem. struct TypeVerifier<'a, 'b: 'a, 'gcx: 'tcx, 'tcx: 'b> { cx: &'a mut TypeChecker<'b, 'gcx, 'tcx>, - mir: &'b Mir<'tcx>, + mir: &'b Body<'tcx>, last_span: Span, mir_def_id: DefId, errors_reported: bool, @@ -368,7 +368,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { } } - fn visit_mir(&mut self, mir: &Mir<'tcx>) { + fn visit_body(&mut self, mir: &Body<'tcx>) { self.sanitize_type(&"return type", mir.return_ty()); for local_decl in &mir.local_decls { self.sanitize_type(local_decl, local_decl.ty); @@ -376,12 +376,12 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { if self.errors_reported { return; } - self.super_mir(mir); + self.super_body(mir); } } impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { - fn new(cx: &'a mut TypeChecker<'b, 'gcx, 'tcx>, mir: &'b Mir<'tcx>) -> Self { + fn new(cx: &'a mut TypeChecker<'b, 'gcx, 'tcx>, mir: &'b Body<'tcx>) -> Self { TypeVerifier { mir, mir_def_id: cx.mir_def_id, @@ -538,7 +538,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { }) } - fn sanitize_promoted(&mut self, promoted_mir: &'b Mir<'tcx>, location: Location) { + fn sanitize_promoted(&mut self, promoted_mir: &'b Body<'tcx>, location: Location) { // Determine the constraints from the promoted MIR by running the type // checker on the promoted MIR, then transfer the constraints back to // the main MIR, changing the locations to the provided location. @@ -562,7 +562,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { &mut closure_bounds ); - self.visit_mir(promoted_mir); + self.visit_body(promoted_mir); if !self.errors_reported { // if verifier failed, don't do further checks to avoid ICEs @@ -969,7 +969,7 @@ impl Locations { } /// Gets a span representing the location. - pub fn span(&self, mir: &Mir<'_>) -> Span { + pub fn span(&self, mir: &Body<'_>) -> Span { match self { Locations::All(span) => *span, Locations::Single(l) => mir.source_info(*l).span, @@ -980,7 +980,7 @@ impl Locations { impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn new( infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mir_def_id: DefId, param_env: ty::ParamEnv<'gcx>, region_bound_pairs: &'a RegionBoundPairs<'tcx>, @@ -1317,7 +1317,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { self.infcx.tcx } - fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Location) { + fn check_stmt(&mut self, mir: &Body<'tcx>, stmt: &Statement<'tcx>, location: Location) { debug!("check_stmt: {:?}", stmt); let tcx = self.tcx(); match stmt.kind { @@ -1456,7 +1456,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn check_terminator( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, term: &Terminator<'tcx>, term_location: Location, ) { @@ -1618,7 +1618,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn check_call_dest( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, term: &Terminator<'tcx>, sig: &ty::FnSig<'tcx>, destination: &Option<(Place<'tcx>, BasicBlock)>, @@ -1687,7 +1687,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn check_call_inputs( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, term: &Terminator<'tcx>, sig: &ty::FnSig<'tcx>, args: &[Operand<'tcx>], @@ -1728,7 +1728,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } - fn check_iscleanup(&mut self, mir: &Mir<'tcx>, block_data: &BasicBlockData<'tcx>) { + fn check_iscleanup(&mut self, mir: &Body<'tcx>, block_data: &BasicBlockData<'tcx>) { let is_cleanup = block_data.is_cleanup; self.last_span = block_data.terminator().source_info.span; match block_data.terminator().kind { @@ -1820,7 +1820,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn assert_iscleanup( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ctxt: &dyn fmt::Debug, bb: BasicBlock, iscleanuppad: bool, @@ -1836,7 +1836,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } - fn check_local(&mut self, mir: &Mir<'tcx>, local: Local, local_decl: &LocalDecl<'tcx>) { + fn check_local(&mut self, mir: &Body<'tcx>, local: Local, local_decl: &LocalDecl<'tcx>) { match mir.local_kind(local) { LocalKind::ReturnPointer | LocalKind::Arg => { // return values of normal functions are required to be @@ -1938,7 +1938,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } - fn check_rvalue(&mut self, mir: &Mir<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { + fn check_rvalue(&mut self, mir: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { let tcx = self.tcx(); match rvalue { @@ -2274,7 +2274,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { fn check_aggregate_rvalue( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, rvalue: &Rvalue<'tcx>, aggregate_kind: &AggregateKind<'tcx>, operands: &[Operand<'tcx>], @@ -2332,7 +2332,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { /// - `borrowed_place`: the place `P` being borrowed fn add_reborrow_constraint( &mut self, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, location: Location, borrow_region: ty::Region<'tcx>, borrowed_place: &Place<'tcx>, @@ -2621,7 +2621,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { }) } - fn typeck_mir(&mut self, mir: &Mir<'tcx>) { + fn typeck_mir(&mut self, mir: &Body<'tcx>) { self.last_span = mir.span; debug!("run_on_mir: {:?}", mir.span); diff --git a/src/librustc_mir/borrow_check/path_utils.rs b/src/librustc_mir/borrow_check/path_utils.rs index caef8d8bc5a92..557d235c23f05 100644 --- a/src/librustc_mir/borrow_check/path_utils.rs +++ b/src/librustc_mir/borrow_check/path_utils.rs @@ -2,7 +2,7 @@ use crate::borrow_check::borrow_set::{BorrowSet, BorrowData, TwoPhaseActivation} use crate::borrow_check::places_conflict; use crate::borrow_check::AccessDepth; use crate::dataflow::indexes::BorrowIndex; -use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase}; +use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase}; use rustc::mir::{ProjectionElem, BorrowKind}; use rustc::ty::TyCtxt; use rustc_data_structures::graph::dominators::Dominators; @@ -25,7 +25,7 @@ pub(super) enum Control { pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> ( s: &mut S, tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, _location: Location, access_place: (AccessDepth, &Place<'tcx>), borrow_set: &BorrowSet<'tcx>, diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs index 9ad0e936e1b2d..9306e88e9ae9c 100644 --- a/src/librustc_mir/borrow_check/place_ext.rs +++ b/src/librustc_mir/borrow_check/place_ext.rs @@ -1,6 +1,6 @@ use rustc::hir; use rustc::mir::ProjectionElem; -use rustc::mir::{Mir, Place, PlaceBase, Mutability, Static, StaticKind}; +use rustc::mir::{Body, Place, PlaceBase, Mutability, Static, StaticKind}; use rustc::ty::{self, TyCtxt}; use crate::borrow_check::borrow_set::LocalsStateAtExit; @@ -13,7 +13,7 @@ crate trait PlaceExt<'tcx> { fn ignore_borrow( &self, tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, locals_state_at_exit: &LocalsStateAtExit, ) -> bool; } @@ -22,7 +22,7 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { fn ignore_borrow( &self, tcx: TyCtxt<'_, '_, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, locals_state_at_exit: &LocalsStateAtExit, ) -> bool { self.iterate(|place_base, place_projection| { diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index c9e8d9894783b..74da3f96653e4 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -3,7 +3,7 @@ use crate::borrow_check::Overlap; use crate::borrow_check::{Deep, Shallow, AccessDepth}; use rustc::hir; use rustc::mir::{ - BorrowKind, Mir, Place, PlaceBase, Projection, ProjectionElem, ProjectionsIter, + BorrowKind, Body, Place, PlaceBase, Projection, ProjectionElem, ProjectionsIter, StaticKind }; use rustc::ty::{self, TyCtxt}; @@ -26,7 +26,7 @@ crate enum PlaceConflictBias { /// dataflow). crate fn places_conflict<'gcx, 'tcx>( tcx: TyCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, borrow_place: &Place<'tcx>, access_place: &Place<'tcx>, bias: PlaceConflictBias, @@ -48,7 +48,7 @@ crate fn places_conflict<'gcx, 'tcx>( /// order to make the conservative choice and preserve soundness. pub(super) fn borrow_conflicts_with_place<'gcx, 'tcx>( tcx: TyCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, borrow_place: &Place<'tcx>, borrow_kind: BorrowKind, access_place: &Place<'tcx>, @@ -85,7 +85,7 @@ pub(super) fn borrow_conflicts_with_place<'gcx, 'tcx>( fn place_components_conflict<'gcx, 'tcx>( tcx: TyCtxt<'_, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, borrow_projections: (&PlaceBase<'tcx>, ProjectionsIter<'_, 'tcx>), borrow_kind: BorrowKind, access_projections: (&PlaceBase<'tcx>, ProjectionsIter<'_, 'tcx>), @@ -367,7 +367,7 @@ fn place_base_conflict<'a, 'gcx: 'tcx, 'tcx>( // between `elem1` and `elem2`. fn place_projection_conflict<'a, 'gcx: 'tcx, 'tcx>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, pi1: &Projection<'tcx>, pi2: &Projection<'tcx>, bias: PlaceConflictBias, diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index 866f1cf994e69..0e1abeba70dff 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -11,7 +11,7 @@ use super::MirBorrowckCtxt; use rustc::hir; use rustc::ty::{self, TyCtxt}; -use rustc::mir::{Mir, Place, PlaceBase, ProjectionElem}; +use rustc::mir::{Body, Place, PlaceBase, ProjectionElem}; pub trait IsPrefixOf<'tcx> { fn is_prefix_of(&self, other: &Place<'tcx>) -> bool; @@ -38,7 +38,7 @@ impl<'tcx> IsPrefixOf<'tcx> for Place<'tcx> { pub(super) struct Prefixes<'cx, 'gcx: 'tcx, 'tcx: 'cx> { - mir: &'cx Mir<'tcx>, + mir: &'cx Body<'tcx>, tcx: TyCtxt<'cx, 'gcx, 'tcx>, kind: PrefixSet, next: Option<&'cx Place<'tcx>>, diff --git a/src/librustc_mir/borrow_check/used_muts.rs b/src/librustc_mir/borrow_check/used_muts.rs index f4866fad9a5fd..abfc2f9466c8e 100644 --- a/src/librustc_mir/borrow_check/used_muts.rs +++ b/src/librustc_mir/borrow_check/used_muts.rs @@ -34,7 +34,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { never_initialized_mut_locals: &mut never_initialized_mut_locals, mbcx: self, }; - visitor.visit_mir(visitor.mbcx.mir); + visitor.visit_body(visitor.mbcx.mir); } // Take the union of the existed `used_mut` set with those variables we've found were diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 55b5d5d1471ac..5d79ef6a4bbc9 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -26,7 +26,7 @@ use syntax_pos::Span; use super::lints; /// Construct the MIR for a given `DefId`. -pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'tcx> { +pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'tcx> { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); // Figure out what primary body this item has. @@ -169,9 +169,9 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t tcx, span: mir.span }; - globalizer.visit_mir(&mut mir); + globalizer.visit_body(&mut mir); let mir = unsafe { - mem::transmute::, Mir<'tcx>>(mir) + mem::transmute::, Body<'tcx>>(mir) }; mir_util::dump_mir(tcx, None, "mir_map", &0, @@ -236,7 +236,7 @@ impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> { fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ctor_id: hir::HirId, v: &'tcx hir::VariantData) - -> Mir<'tcx> + -> Body<'tcx> { let span = tcx.hir().span_by_hir_id(ctor_id); if let hir::VariantData::Tuple(ref fields, ctor_id) = *v { @@ -249,9 +249,9 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx, span: mir.span }; - globalizer.visit_mir(&mut mir); + globalizer.visit_body(&mut mir); let mir = unsafe { - mem::transmute::, Mir<'tcx>>(mir) + mem::transmute::, Body<'tcx>>(mir) }; mir_util::dump_mir(tcx, None, "mir_map", &0, @@ -628,7 +628,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, yield_ty: Option>, return_ty_span: Span, body: &'gcx hir::Body) - -> Mir<'tcx> + -> Body<'tcx> where A: Iterator> { let arguments: Vec<_> = arguments.collect(); @@ -748,7 +748,7 @@ fn construct_const<'a, 'gcx, 'tcx>( body_id: hir::BodyId, const_ty: Ty<'tcx>, const_ty_span: Span, -) -> Mir<'tcx> { +) -> Body<'tcx> { let tcx = hir.tcx(); let owner_id = tcx.hir().body_owner(body_id); let span = tcx.hir().span(owner_id); @@ -787,7 +787,7 @@ fn construct_const<'a, 'gcx, 'tcx>( fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>, body_id: hir::BodyId) - -> Mir<'tcx> { + -> Body<'tcx> { let owner_id = hir.tcx().hir().body_owner(body_id); let span = hir.tcx().hir().span(owner_id); let ty = hir.tcx().types.err; @@ -849,14 +849,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { fn finish(self, yield_ty: Option>) - -> Mir<'tcx> { + -> Body<'tcx> { for (index, block) in self.cfg.basic_blocks.iter().enumerate() { if block.terminator.is_none() { span_bug!(self.fn_span, "no terminator on block {:?}", index); } } - Mir::new( + Body::new( self.cfg.basic_blocks, self.source_scopes, ClearCrossCrate::Set(self.source_scope_local_data), diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index c43bc41ba685e..141f13f460e33 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -55,7 +55,7 @@ pub(crate) fn mk_eval_cx<'a, 'mir, 'tcx>( pub(crate) fn eval_promoted<'a, 'mir, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, cid: GlobalId<'tcx>, - mir: &'mir mir::Mir<'tcx>, + mir: &'mir mir::Body<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> EvalResult<'tcx, MPlaceTy<'tcx>> { let span = tcx.def_span(cid.instance.def_id()); @@ -137,7 +137,7 @@ fn op_to_const<'tcx>( fn eval_body_using_ecx<'mir, 'tcx>( ecx: &mut CompileTimeEvalContext<'_, 'mir, 'tcx>, cid: GlobalId<'tcx>, - mir: &'mir mir::Mir<'tcx>, + mir: &'mir mir::Body<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> EvalResult<'tcx, MPlaceTy<'tcx>> { debug!("eval_body_using_ecx: {:?}, {:?}", cid, param_env); @@ -331,7 +331,7 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx> args: &[OpTy<'tcx>], dest: Option>, ret: Option, - ) -> EvalResult<'tcx, Option<&'mir mir::Mir<'tcx>>> { + ) -> EvalResult<'tcx, Option<&'mir mir::Body<'tcx>>> { debug!("eval_fn_call: {:?}", instance); // Only check non-glue functions if let ty::InstanceDef::Item(def_id) = instance.def { diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index 66ca4b4dc8922..f9d88ab879596 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -1,4 +1,4 @@ -use rustc::mir::{self, Mir, Location}; +use rustc::mir::{self, Body, Location}; use rustc::ty::{self, TyCtxt}; use crate::util::elaborate_drops::DropFlagState; @@ -47,7 +47,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>, // // FIXME: we have to do something for moving slice patterns. fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, place: &mir::Place<'tcx>) -> bool { let ty = place.ty(mir, tcx).ty; match ty.sty { @@ -74,7 +74,7 @@ fn place_contents_drop_state_cannot_differ<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, pub(crate) fn on_lookup_result_bits<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx>, lookup_result: LookupResult, each_child: F) @@ -92,7 +92,7 @@ pub(crate) fn on_lookup_result_bits<'a, 'gcx, 'tcx, F>( pub(crate) fn on_all_children_bits<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, mut each_child: F) @@ -100,7 +100,7 @@ pub(crate) fn on_all_children_bits<'a, 'gcx, 'tcx, F>( { fn is_terminal_path<'a, 'gcx, 'tcx>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx>, path: MovePathIndex) -> bool { @@ -110,7 +110,7 @@ pub(crate) fn on_all_children_bits<'a, 'gcx, 'tcx, F>( fn on_all_children_bits<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, each_child: &mut F) @@ -133,7 +133,7 @@ pub(crate) fn on_all_children_bits<'a, 'gcx, 'tcx, F>( pub(crate) fn on_all_drop_children_bits<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, path: MovePathIndex, mut each_child: F) @@ -156,7 +156,7 @@ pub(crate) fn on_all_drop_children_bits<'a, 'gcx, 'tcx, F>( pub(crate) fn drop_flag_effects_for_function_entry<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, mut callback: F) where F: FnMut(MovePathIndex, DropFlagState) @@ -173,7 +173,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'a, 'gcx, 'tcx, F>( pub(crate) fn drop_flag_effects_for_location<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ctxt: &MoveDataParamEnv<'gcx, 'tcx>, loc: Location, mut callback: F) @@ -205,7 +205,7 @@ pub(crate) fn drop_flag_effects_for_location<'a, 'gcx, 'tcx, F>( pub(crate) fn for_location_inits<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, move_data: &MoveData<'tcx>, loc: Location, mut callback: F) diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs index d68377681f1ca..4965f1a585d48 100644 --- a/src/librustc_mir/dataflow/graphviz.rs +++ b/src/librustc_mir/dataflow/graphviz.rs @@ -1,7 +1,7 @@ //! Hook into libgraphviz for rendering dataflow graphs for MIR. use rustc::hir::def_id::DefId; -use rustc::mir::{BasicBlock, Mir}; +use rustc::mir::{BasicBlock, Body}; use std::fs; use std::io; @@ -17,7 +17,7 @@ use super::DebugFormatted; pub trait MirWithFlowState<'tcx> { type BD: BitDenotation<'tcx>; fn def_id(&self) -> DefId; - fn mir(&self) -> &Mir<'tcx>; + fn mir(&self) -> &Body<'tcx>; fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>; } @@ -26,7 +26,7 @@ impl<'a, 'tcx, BD> MirWithFlowState<'tcx> for DataflowBuilder<'a, 'tcx, BD> { type BD = BD; fn def_id(&self) -> DefId { self.def_id } - fn mir(&self) -> &Mir<'tcx> { self.flow_state.mir() } + fn mir(&self) -> &Body<'tcx> { self.flow_state.mir() } fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { &self.flow_state.flow_state } } @@ -59,7 +59,7 @@ pub type Node = BasicBlock; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct Edge { source: BasicBlock, index: usize } -fn outgoing(mir: &Mir<'_>, bb: BasicBlock) -> Vec { +fn outgoing(mir: &Body<'_>, bb: BasicBlock) -> Vec { (0..mir[bb].terminator().successors().count()) .map(|index| Edge { source: bb, index: index}).collect() } @@ -124,7 +124,7 @@ where MWF: MirWithFlowState<'tcx>, n: &Node, w: &mut W, block: BasicBlock, - mir: &Mir<'_>) -> io::Result<()> { + mir: &Body<'_>) -> io::Result<()> { // Header rows const HDRS: [&str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"]; const HDR_FMT: &str = "bgcolor=\"grey\""; @@ -149,7 +149,7 @@ where MWF: MirWithFlowState<'tcx>, n: &Node, w: &mut W, block: BasicBlock, - mir: &Mir<'_>) + mir: &Body<'_>) -> io::Result<()> { let i = n.index(); @@ -199,7 +199,7 @@ where MWF: MirWithFlowState<'tcx>, n: &Node, w: &mut W, block: BasicBlock, - mir: &Mir<'_>) + mir: &Body<'_>) -> io::Result<()> { let i = n.index(); diff --git a/src/librustc_mir/dataflow/impls/borrowed_locals.rs b/src/librustc_mir/dataflow/impls/borrowed_locals.rs index 65cbc83fbcb84..47af10a1c5023 100644 --- a/src/librustc_mir/dataflow/impls/borrowed_locals.rs +++ b/src/librustc_mir/dataflow/impls/borrowed_locals.rs @@ -12,16 +12,16 @@ use crate::dataflow::BitDenotation; /// immovable generators. #[derive(Copy, Clone)] pub struct HaveBeenBorrowedLocals<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, } impl<'a, 'tcx: 'a> HaveBeenBorrowedLocals<'a, 'tcx> { - pub fn new(mir: &'a Mir<'tcx>) + pub fn new(mir: &'a Body<'tcx>) -> Self { HaveBeenBorrowedLocals { mir } } - pub fn mir(&self) -> &Mir<'tcx> { + pub fn mir(&self) -> &Body<'tcx> { self.mir } } diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 43cb0ed4565fe..99051fb37f148 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -1,7 +1,7 @@ use crate::borrow_check::borrow_set::{BorrowSet, BorrowData}; use crate::borrow_check::place_ext::PlaceExt; -use rustc::mir::{self, Location, Place, PlaceBase, Mir}; +use rustc::mir::{self, Location, Place, PlaceBase, Body}; use rustc::ty::TyCtxt; use rustc::ty::RegionVid; @@ -31,7 +31,7 @@ newtype_index! { /// borrows in compact bitvectors. pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, borrow_set: Rc>, borrows_out_of_scope_at_location: FxHashMap>, @@ -48,7 +48,7 @@ struct StackEntry { } fn precompute_borrows_out_of_scope<'tcx>( - mir: &Mir<'tcx>, + mir: &Body<'tcx>, regioncx: &Rc>, borrows_out_of_scope_at_location: &mut FxHashMap>, borrow_index: BorrowIndex, @@ -136,7 +136,7 @@ fn precompute_borrows_out_of_scope<'tcx>( impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { crate fn new( tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, nonlexical_regioncx: Rc>, borrow_set: &Rc>, ) -> Self { diff --git a/src/librustc_mir/dataflow/impls/mod.rs b/src/librustc_mir/dataflow/impls/mod.rs index 03d55b84f32e2..4f3b180edd111 100644 --- a/src/librustc_mir/dataflow/impls/mod.rs +++ b/src/librustc_mir/dataflow/impls/mod.rs @@ -3,7 +3,7 @@ //! zero-sized structure. use rustc::ty::TyCtxt; -use rustc::mir::{self, Mir, Location}; +use rustc::mir::{self, Body, Location}; use rustc_data_structures::bit_set::{BitSet, BitSetOperator}; use rustc_data_structures::indexed_vec::Idx; @@ -65,13 +65,13 @@ pub(super) mod borrows; /// places that would require a dynamic drop-flag at that statement. pub struct MaybeInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, } impl<'a, 'gcx: 'tcx, 'tcx> MaybeInitializedPlaces<'a, 'gcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) -> Self { @@ -120,13 +120,13 @@ impl<'a, 'gcx, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'gcx, 'tcx /// places that would require a dynamic drop-flag at that statement. pub struct MaybeUninitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, } impl<'a, 'gcx, 'tcx> MaybeUninitializedPlaces<'a, 'gcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) -> Self { @@ -174,13 +174,13 @@ impl<'a, 'gcx, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, 'gcx, 't /// that would require a dynamic drop-flag at that statement. pub struct DefinitelyInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, } impl<'a, 'gcx, 'tcx: 'a> DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) -> Self { @@ -223,13 +223,13 @@ impl<'a, 'gcx, 'tcx: 'a> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, ' /// ``` pub struct EverInitializedPlaces<'a, 'gcx: 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>, } impl<'a, 'gcx: 'tcx, 'tcx: 'a> EverInitializedPlaces<'a, 'gcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'gcx, 'tcx>) -> Self { diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index 3bf11c57379c2..ab79d6cc947e8 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -5,16 +5,16 @@ use crate::dataflow::BitDenotation; #[derive(Copy, Clone)] pub struct MaybeStorageLive<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, } impl<'a, 'tcx: 'a> MaybeStorageLive<'a, 'tcx> { - pub fn new(mir: &'a Mir<'tcx>) + pub fn new(mir: &'a Body<'tcx>) -> Self { MaybeStorageLive { mir } } - pub fn mir(&self) -> &Mir<'tcx> { + pub fn mir(&self) -> &Body<'tcx> { self.mir } } diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index a9d23a0afeabc..26bad0cb04d70 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -7,7 +7,7 @@ use rustc_data_structures::work_queue::WorkQueue; use rustc::hir::def_id::DefId; use rustc::ty::{self, TyCtxt}; -use rustc::mir::{self, Mir, BasicBlock, BasicBlockData, Location, Statement, Terminator}; +use rustc::mir::{self, Body, BasicBlock, BasicBlockData, Location, Statement, Terminator}; use rustc::mir::traversal; use rustc::session::Session; @@ -122,7 +122,7 @@ pub struct MoveDataParamEnv<'gcx, 'tcx> { } pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, def_id: DefId, attributes: &[ast::Attribute], dead_unwinds: &BitSet, @@ -343,13 +343,13 @@ pub(crate) trait DataflowResultsConsumer<'a, 'tcx: 'a> { // Delegated Hooks: Provide access to the MIR and process the flow state. - fn mir(&self) -> &'a Mir<'tcx>; + fn mir(&self) -> &'a Body<'tcx>; } pub fn state_for_location<'tcx, T: BitDenotation<'tcx>>(loc: Location, analysis: &T, result: &DataflowResults<'tcx, T>, - mir: &Mir<'tcx>) + mir: &Body<'tcx>) -> BitSet { let mut on_entry = result.sets().on_entry_set_for(loc.block.index()).to_owned(); let mut kill_set = on_entry.to_hybrid(); @@ -384,7 +384,7 @@ pub struct DataflowAnalysis<'a, 'tcx: 'a, O> where O: BitDenotation<'tcx> { flow_state: DataflowState<'tcx, O>, dead_unwinds: &'a BitSet, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, } impl<'a, 'tcx: 'a, O> DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> @@ -393,7 +393,7 @@ impl<'a, 'tcx: 'a, O> DataflowAnalysis<'a, 'tcx, O> where O: BitDenotation<'tcx> DataflowResults(self.flow_state) } - pub fn mir(&self) -> &'a Mir<'tcx> { self.mir } + pub fn mir(&self) -> &'a Body<'tcx> { self.mir } } pub struct DataflowResults<'tcx, O>(pub(crate) DataflowState<'tcx, O>) where O: BitDenotation<'tcx>; @@ -697,7 +697,7 @@ pub trait BitDenotation<'tcx>: BitSetOperator { impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation<'tcx> { - pub fn new(mir: &'a Mir<'tcx>, + pub fn new(mir: &'a Body<'tcx>, dead_unwinds: &'a BitSet, denotation: D) -> Self where D: InitialFlow { let bits_per_block = denotation.bits_per_block(); diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index ab0a2d87302c8..816a269625399 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -13,14 +13,14 @@ use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind}; use super::IllegalMoveOriginKind::*; struct MoveDataBuilder<'a, 'gcx: 'tcx, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>, data: MoveData<'tcx>, errors: Vec<(Place<'tcx>, MoveError<'tcx>)>, } impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { - fn new(mir: &'a Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self { + fn new(mir: &'a Body<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self { let mut move_paths = IndexVec::new(); let mut path_map = IndexVec::new(); let mut init_path_map = IndexVec::new(); @@ -203,7 +203,7 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { } pub(super) fn gather_moves<'a, 'gcx, 'tcx>( - mir: &Mir<'tcx>, + mir: &Body<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx> ) -> Result, (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>)> { let mut builder = MoveDataBuilder::new(mir, tcx); diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 7aaf44a8a890e..0d20040d0d2d7 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -138,7 +138,7 @@ impl IndexMut for LocationMap { } impl LocationMap where T: Default + Clone { - fn new(mir: &Mir<'_>) -> Self { + fn new(mir: &Body<'_>) -> Self { LocationMap { map: mir.basic_blocks().iter().map(|block| { vec![T::default(); block.statements.len()+1] @@ -205,7 +205,7 @@ impl fmt::Debug for Init { } impl Init { - crate fn span<'gcx>(&self, mir: &Mir<'gcx>) -> Span { + crate fn span<'gcx>(&self, mir: &Body<'gcx>) -> Span { match self.location { InitLocation::Argument(local) => mir.local_decls[local].source_info.span, InitLocation::Statement(location) => mir.source_info(location).span, @@ -306,7 +306,7 @@ impl<'tcx> MoveError<'tcx> { } impl<'a, 'gcx, 'tcx> MoveData<'tcx> { - pub fn gather_moves(mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) + pub fn gather_moves(mir: &Body<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Result, MoveError<'tcx>)>)> { builder::gather_moves(mir, tcx) } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 2f89740876db1..d3cbd2bcc03a5 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -53,7 +53,7 @@ pub struct Frame<'mir, 'tcx: 'mir, Tag=(), Extra=()> { // Function and callsite information //////////////////////////////////////////////////////////////////////////////// /// The MIR for the function called on this frame. - pub mir: &'mir mir::Mir<'tcx>, + pub mir: &'mir mir::Body<'tcx>, /// The def_id and substs of the current function. pub instance: ty::Instance<'tcx>, @@ -244,7 +244,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc } #[inline(always)] - pub(super) fn mir(&self) -> &'mir mir::Mir<'tcx> { + pub(super) fn mir(&self) -> &'mir mir::Body<'tcx> { self.frame().mir } @@ -294,7 +294,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc pub fn load_mir( &self, instance: ty::InstanceDef<'tcx>, - ) -> EvalResult<'tcx, &'tcx mir::Mir<'tcx>> { + ) -> EvalResult<'tcx, &'tcx mir::Body<'tcx>> { // do not continue if typeck errors occurred (can only occur in local crate) let did = instance.def_id(); if did.is_local() @@ -472,7 +472,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc &mut self, instance: ty::Instance<'tcx>, span: source_map::Span, - mir: &'mir mir::Mir<'tcx>, + mir: &'mir mir::Body<'tcx>, return_place: Option>, return_to_block: StackPopCleanup, ) -> EvalResult<'tcx> { diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 288ffbf3cd616..873c2d2ec6088 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -117,7 +117,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized { args: &[OpTy<'tcx, Self::PointerTag>], dest: Option>, ret: Option, - ) -> EvalResult<'tcx, Option<&'mir mir::Mir<'tcx>>>; + ) -> EvalResult<'tcx, Option<&'mir mir::Body<'tcx>>>; /// Directly process an intrinsic without pushing a stack frame. /// If this returns successfully, the engine will take care of jumping to the next block. diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 51ceb2a01c3a4..cbfc899347186 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -3,12 +3,12 @@ use rustc::hir::def_id::DefId; use rustc::hir::intravisit::FnKind; use rustc::hir::map::blocks::FnLikeNode; use rustc::lint::builtin::UNCONDITIONAL_RECURSION; -use rustc::mir::{self, Mir, TerminatorKind}; +use rustc::mir::{self, Body, TerminatorKind}; use rustc::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt}; use rustc::ty::subst::InternalSubsts; pub fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); @@ -19,7 +19,7 @@ pub fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn_kind: FnKind<'_>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, def_id: DefId) { if let FnKind::Closure(_) = fn_kind { // closures can't recur, so they don't matter. diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index b90db7646d492..c1131336f3636 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -517,7 +517,7 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, struct MirNeighborCollector<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &'a mir::Mir<'tcx>, + mir: &'a mir::Body<'tcx>, output: &'a mut Vec>, param_substs: SubstsRef<'tcx>, } @@ -1218,7 +1218,7 @@ fn collect_neighbours<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mir, output, param_substs: instance.substs, - }.visit_mir(&mir); + }.visit_body(&mir); let param_env = ty::ParamEnv::reveal_all(); for i in 0..mir.promoted.len() { use rustc_data_structures::indexed_vec::Idx; diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 12a1659e043c6..087f8779b6916 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -28,7 +28,7 @@ pub fn provide(providers: &mut Providers<'_>) { fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: ty::InstanceDef<'tcx>) - -> &'tcx Mir<'tcx> + -> &'tcx Body<'tcx> { debug!("make_shim({:?})", instance); @@ -169,7 +169,7 @@ fn local_decls_for_sig<'tcx>(sig: &ty::FnSig<'tcx>, span: Span) fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, ty: Option>) - -> Mir<'tcx> + -> Body<'tcx> { debug!("build_drop_shim(def_id={:?}, ty={:?})", def_id, ty); @@ -202,7 +202,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, block(&mut blocks, TerminatorKind::Goto { target: return_block }); block(&mut blocks, TerminatorKind::Return); - let mut mir = Mir::new( + let mut mir = Body::new( blocks, IndexVec::from_elem_n( SourceScopeData { span: span, parent_scope: None }, 1 @@ -256,7 +256,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } pub struct DropShimElaborator<'a, 'tcx: 'a> { - pub mir: &'a Mir<'tcx>, + pub mir: &'a Body<'tcx>, pub patch: MirPatch<'tcx>, pub tcx: TyCtxt<'a, 'tcx, 'tcx>, pub param_env: ty::ParamEnv<'tcx>, @@ -272,7 +272,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { type Path = (); fn patch(&mut self) -> &mut MirPatch<'tcx> { &mut self.patch } - fn mir(&self) -> &'a Mir<'tcx> { self.mir } + fn mir(&self) -> &'a Body<'tcx> { self.mir } fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.tcx } fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env } @@ -309,7 +309,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> { fn build_clone_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - -> Mir<'tcx> + -> Body<'tcx> { debug!("build_clone_shim(def_id={:?})", def_id); @@ -371,8 +371,8 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> { } } - fn into_mir(self) -> Mir<'tcx> { - Mir::new( + fn into_mir(self) -> Body<'tcx> { + Body::new( self.blocks, IndexVec::from_elem_n( SourceScopeData { span: self.span, parent_scope: None }, 1 @@ -696,7 +696,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, rcvr_adjustment: Adjustment, call_kind: CallKind, untuple_args: Option<&[Ty<'tcx>]>) - -> Mir<'tcx> + -> Body<'tcx> { debug!("build_call_shim(def_id={:?}, rcvr_adjustment={:?}, \ call_kind={:?}, untuple_args={:?})", @@ -821,7 +821,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, block(&mut blocks, vec![], TerminatorKind::Resume, true); } - let mut mir = Mir::new( + let mut mir = Body::new( blocks, IndexVec::from_elem_n( SourceScopeData { span: span, parent_scope: None }, 1 @@ -846,7 +846,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, ctor_id: hir::HirId, fields: &[hir::StructField], span: Span) - -> Mir<'tcx> + -> Body<'tcx> { let tcx = infcx.tcx; let gcx = tcx.global_tcx(); @@ -900,7 +900,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>, is_cleanup: false }; - Mir::new( + Body::new( IndexVec::from_elem_n(start_block, 1), IndexVec::from_elem_n( SourceScopeData { span: span, parent_scope: None }, 1 diff --git a/src/librustc_mir/transform/add_call_guards.rs b/src/librustc_mir/transform/add_call_guards.rs index 88042d64e96b7..712e9b1fe2505 100644 --- a/src/librustc_mir/transform/add_call_guards.rs +++ b/src/librustc_mir/transform/add_call_guards.rs @@ -34,13 +34,13 @@ impl MirPass for AddCallGuards { fn run_pass<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { self.add_call_guards(mir); } } impl AddCallGuards { - pub fn add_call_guards(&self, mir: &mut Mir<'_>) { + pub fn add_call_guards(&self, mir: &mut Body<'_>) { let pred_count: IndexVec<_, _> = mir.predecessors().iter().map(|ps| ps.len()).collect(); diff --git a/src/librustc_mir/transform/add_moves_for_packed_drops.rs b/src/librustc_mir/transform/add_moves_for_packed_drops.rs index b6436ec70eef2..f7a4bf759545c 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -43,7 +43,7 @@ impl MirPass for AddMovesForPackedDrops { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) + mir: &mut Body<'tcx>) { debug!("add_moves_for_packed_drops({:?} @ {:?})", src, mir.span); add_moves_for_packed_drops(tcx, mir, src.def_id()); @@ -52,7 +52,7 @@ impl MirPass for AddMovesForPackedDrops { pub fn add_moves_for_packed_drops<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, def_id: DefId) { let patch = add_moves_for_packed_drops_patch(tcx, mir, def_id); @@ -61,7 +61,7 @@ pub fn add_moves_for_packed_drops<'a, 'tcx>( fn add_moves_for_packed_drops_patch<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, def_id: DefId) -> MirPatch<'tcx> { @@ -92,7 +92,7 @@ fn add_moves_for_packed_drops_patch<'a, 'tcx>( fn add_move_for_packed_drop<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, patch: &mut MirPatch<'tcx>, terminator: &Terminator<'tcx>, loc: Location, diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index 32c9953ee9e08..23319f7055183 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -77,7 +77,7 @@ impl MirPass for AddRetag { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) + mir: &mut Body<'tcx>) { if !tcx.sess.opts.debugging_opts.mir_emit_retag { return; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 394d1f06029cb..8ec8a8fa12eec 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -19,7 +19,7 @@ use std::ops::Bound; use crate::util; pub struct UnsafetyChecker<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, const_context: bool, min_const_fn: bool, source_scope_local_data: &'a IndexVec, @@ -36,7 +36,7 @@ impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { fn new( const_context: bool, min_const_fn: bool, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, source_scope_local_data: &'a IndexVec, tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -538,7 +538,7 @@ fn unsafety_check_result<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) let mut checker = UnsafetyChecker::new( const_context, min_const_fn, mir, source_scope_local_data, tcx, param_env); - checker.visit_mir(mir); + checker.visit_body(mir); check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); UnsafetyCheckResult { diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index 64fd0b1365690..63a1b059d9017 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -16,7 +16,7 @@ //! [`FakeRead`]: rustc::mir::StatementKind::FakeRead //! [`Nop`]: rustc::mir::StatementKind::Nop -use rustc::mir::{BorrowKind, Rvalue, Location, Mir}; +use rustc::mir::{BorrowKind, Rvalue, Location, Body}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::visit::MutVisitor; use rustc::ty::TyCtxt; @@ -30,9 +30,9 @@ impl MirPass for CleanupNonCodegenStatements { fn run_pass<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let mut delete = DeleteNonCodegenStatements; - delete.visit_mir(mir); + delete.visit_body(mir); } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 11022be097cfd..9a38b5bd91849 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -3,7 +3,7 @@ use rustc::hir::def::DefKind; use rustc::mir::{ - AggregateKind, Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Local, + AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue, Local, NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind, TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem, SourceScope, SourceScopeLocalData, LocalDecl, Promoted, @@ -33,7 +33,7 @@ impl MirPass for ConstProp { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { // will be evaluated by miri and produce its errors there if source.promoted.is_some() { return; @@ -63,7 +63,7 @@ impl MirPass for ConstProp { // That would require an uniform one-def no-mutation analysis // and RPO (or recursing when needing the value of a local). let mut optimization_finder = ConstPropagator::new(mir, tcx, source); - optimization_finder.visit_mir(mir); + optimization_finder.visit_body(mir); // put back the data we stole from `mir` std::mem::replace( @@ -91,7 +91,7 @@ struct ConstPropagator<'a, 'mir, 'tcx:'a+'mir> { param_env: ParamEnv<'tcx>, source_scope_local_data: ClearCrossCrate>, local_decls: IndexVec>, - promoted: IndexVec>, + promoted: IndexVec>, } impl<'a, 'b, 'tcx> LayoutOf for ConstPropagator<'a, 'b, 'tcx> { @@ -119,7 +119,7 @@ impl<'a, 'b, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'a, 'b, 'tcx> { impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { fn new( - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource<'tcx>, ) -> ConstPropagator<'a, 'mir, 'tcx> { @@ -143,7 +143,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { can_const_prop, places: IndexVec::from_elem(None, &mir.local_decls), source_scope_local_data, - //FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_mir()` needs it + //FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it local_decls: mir.local_decls.clone(), promoted, } @@ -572,7 +572,7 @@ struct CanConstProp { impl CanConstProp { /// returns true if `local` can be propagated - fn check(mir: &Mir<'_>) -> IndexVec { + fn check(mir: &Body<'_>) -> IndexVec { let mut cpv = CanConstProp { can_const_prop: IndexVec::from_elem(true, &mir.local_decls), found_assignment: IndexVec::from_elem(false, &mir.local_decls), @@ -589,7 +589,7 @@ impl CanConstProp { trace!("local {:?} can't be propagated because it's not a temporary", local); } } - cpv.visit_mir(mir); + cpv.visit_body(mir); cpv.can_const_prop } } diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index dfe2e991ba97b..c48d2d295711a 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -20,7 +20,7 @@ //! future. use rustc::mir::{ - Constant, Local, LocalKind, Location, Place, PlaceBase, Mir, Operand, Rvalue, StatementKind + Constant, Local, LocalKind, Location, Place, PlaceBase, Body, Operand, Rvalue, StatementKind }; use rustc::mir::visit::MutVisitor; use rustc::ty::TyCtxt; @@ -33,7 +33,7 @@ impl MirPass for CopyPropagation { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { // We only run when the MIR optimization level is > 1. // This avoids a slow pass, and messing up debug info. if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 { @@ -135,7 +135,7 @@ impl MirPass for CopyPropagation { } fn eliminate_self_assignments( - mir: &mut Mir<'_>, + mir: &mut Body<'_>, def_use_analysis: &DefUseAnalysis, ) -> bool { let mut changed = false; @@ -177,7 +177,7 @@ enum Action<'tcx> { } impl<'tcx> Action<'tcx> { - fn local_copy(mir: &Mir<'tcx>, def_use_analysis: &DefUseAnalysis, src_place: &Place<'tcx>) + fn local_copy(mir: &Body<'tcx>, def_use_analysis: &DefUseAnalysis, src_place: &Place<'tcx>) -> Option> { // The source must be a local. let src_local = if let Place::Base(PlaceBase::Local(local)) = *src_place { @@ -232,7 +232,7 @@ impl<'tcx> Action<'tcx> { } fn perform(self, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, def_use_analysis: &DefUseAnalysis, dest_local: Local, location: Location) diff --git a/src/librustc_mir/transform/deaggregator.rs b/src/librustc_mir/transform/deaggregator.rs index 9215356daa484..7da37f956cedd 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -10,7 +10,7 @@ impl MirPass for Deaggregator { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let (basic_blocks, local_decls) = mir.basic_blocks_and_local_decls_mut(); let local_decls = &*local_decls; for bb in basic_blocks { diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs index 81e48fe2dbe3b..ebb65094a306d 100644 --- a/src/librustc_mir/transform/dump_mir.rs +++ b/src/librustc_mir/transform/dump_mir.rs @@ -5,7 +5,7 @@ use std::fmt; use std::fs::File; use std::io; -use rustc::mir::Mir; +use rustc::mir::Body; use rustc::session::config::{OutputFilenames, OutputType}; use rustc::ty::TyCtxt; use crate::transform::{MirPass, MirSource}; @@ -21,7 +21,7 @@ impl MirPass for Marker { fn run_pass<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _source: MirSource<'tcx>, - _mir: &mut Mir<'tcx>) + _mir: &mut Body<'tcx>) { } } @@ -42,7 +42,7 @@ pub fn on_mir_pass<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pass_num: &dyn fmt::Display, pass_name: &str, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, is_after: bool) { if mir_util::dump_enabled(tcx, pass_name, source) { mir_util::dump_mir(tcx, diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index 6320cb4424814..c833af29c36f0 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -24,7 +24,7 @@ impl MirPass for ElaborateDrops { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) + mir: &mut Body<'tcx>) { debug!("elaborate_drops({:?} @ {:?})", src, mir.span); @@ -79,7 +79,7 @@ impl MirPass for ElaborateDrops { /// that can't drop anything. fn find_dead_unwinds<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, def_id: hir::def_id::DefId, env: &MoveDataParamEnv<'tcx, 'tcx>) -> BitSet @@ -143,7 +143,7 @@ struct InitializationData { impl InitializationData { fn apply_location<'a,'tcx>(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, env: &MoveDataParamEnv<'tcx, 'tcx>, loc: Location) { @@ -186,7 +186,7 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { &mut self.ctxt.patch } - fn mir(&self) -> &'a Mir<'tcx> { + fn mir(&self) -> &'a Body<'tcx> { self.ctxt.mir } @@ -291,7 +291,7 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> { struct ElaborateDropsCtxt<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, env: &'a MoveDataParamEnv<'tcx, 'tcx>, flow_inits: DataflowResults<'tcx, MaybeInitializedPlaces<'a, 'tcx, 'tcx>>, flow_uninits: DataflowResults<'tcx, MaybeUninitializedPlaces<'a, 'tcx, 'tcx>>, diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 7c2ff94b75d86..ffc5bba6d6086 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -53,7 +53,7 @@ impl MirPass for EraseRegions { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { - EraseRegionsVisitor::new(tcx).visit_mir(mir); + mir: &mut Body<'tcx>) { + EraseRegionsVisitor::new(tcx).visit_body(mir); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index ab2f2933a969e..f36ede4e8d9cd 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -210,7 +210,7 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> { } // Create a statement which reads the discriminant into a temporary - fn get_discr(&self, mir: &mut Mir<'tcx>) -> (Statement<'tcx>, Place<'tcx>) { + fn get_discr(&self, mir: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) { let temp_decl = LocalDecl::new_internal(self.tcx.types.isize, mir.span); let local_decls_len = mir.local_decls.push(temp_decl); let temp = Place::Base(PlaceBase::Local(local_decls_len)); @@ -304,7 +304,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> { fn make_generator_state_argument_indirect<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let gen_ty = mir.local_decls.raw[1].ty; let region = ty::ReFree(ty::FreeRegion { @@ -323,12 +323,12 @@ fn make_generator_state_argument_indirect<'a, 'tcx>( mir.local_decls.raw[1].ty = ref_gen_ty; // Add a deref to accesses of the generator state - DerefArgVisitor.visit_mir(mir); + DerefArgVisitor.visit_body(mir); } fn make_generator_state_argument_pinned<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let ref_gen_ty = mir.local_decls.raw[1].ty; let pin_did = tcx.lang_items().pin_type().unwrap(); @@ -340,12 +340,12 @@ fn make_generator_state_argument_pinned<'a, 'tcx>( mir.local_decls.raw[1].ty = pin_ref_gen_ty; // Add the Pin field access to accesses of the generator state - PinArgVisitor { ref_gen_ty }.visit_mir(mir); + PinArgVisitor { ref_gen_ty }.visit_body(mir); } fn replace_result_variable<'tcx>( ret_ty: Ty<'tcx>, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, ) -> Local { let source_info = source_info(mir); let new_ret = LocalDecl { @@ -366,7 +366,7 @@ fn replace_result_variable<'tcx>( RenameLocalVisitor { from: RETURN_PLACE, to: new_ret_local, - }.visit_mir(mir); + }.visit_body(mir); new_ret_local } @@ -387,7 +387,7 @@ impl<'tcx> Visitor<'tcx> for StorageIgnored { fn locals_live_across_suspend_points( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, source: MirSource<'tcx>, movable: bool, ) -> ( @@ -408,7 +408,7 @@ fn locals_live_across_suspend_points( // Find the MIR locals which do not use StorageLive/StorageDead statements. // The storage of these locals are always live. let mut ignored = StorageIgnored(BitSet::new_filled(mir.local_decls.len())); - ignored.visit_mir(mir); + ignored.visit_body(mir); // Calculate the MIR locals which have been previously // borrowed (even if they are still active). @@ -503,7 +503,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, upvars: &Vec>, interior: Ty<'tcx>, movable: bool, - mir: &mut Mir<'tcx>) + mir: &mut Body<'tcx>) -> (FxHashMap, VariantIdx, usize)>, GeneratorLayout<'tcx>, FxHashMap) @@ -576,7 +576,7 @@ fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (remap, layout, storage_liveness) } -fn insert_switch<'a, 'tcx>(mir: &mut Mir<'tcx>, +fn insert_switch<'a, 'tcx>(mir: &mut Body<'tcx>, cases: Vec<(usize, BasicBlock)>, transform: &TransformVisitor<'a, 'tcx>, default: TerminatorKind<'tcx>) { @@ -608,7 +608,7 @@ fn insert_switch<'a, 'tcx>(mir: &mut Mir<'tcx>, fn elaborate_generator_drops<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { use crate::util::elaborate_drops::{elaborate_drop, Unwind}; use crate::util::patch::MirPatch; use crate::shim::DropShimElaborator; @@ -663,8 +663,8 @@ fn create_generator_drop_shim<'a, 'tcx>( def_id: DefId, source: MirSource<'tcx>, gen_ty: Ty<'tcx>, - mir: &Mir<'tcx>, - drop_clean: BasicBlock) -> Mir<'tcx> { + mir: &Body<'tcx>, + drop_clean: BasicBlock) -> Body<'tcx> { let mut mir = mir.clone(); let source_info = source_info(&mir); @@ -734,7 +734,7 @@ fn create_generator_drop_shim<'a, 'tcx>( mir } -fn insert_term_block<'tcx>(mir: &mut Mir<'tcx>, kind: TerminatorKind<'tcx>) -> BasicBlock { +fn insert_term_block<'tcx>(mir: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> BasicBlock { let term_block = BasicBlock::new(mir.basic_blocks().len()); let source_info = source_info(mir); mir.basic_blocks_mut().push(BasicBlockData { @@ -749,7 +749,7 @@ fn insert_term_block<'tcx>(mir: &mut Mir<'tcx>, kind: TerminatorKind<'tcx>) -> B } fn insert_panic_block<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, message: AssertMessage<'tcx>) -> BasicBlock { let assert_block = BasicBlock::new(mir.basic_blocks().len()); let term = TerminatorKind::Assert { @@ -783,7 +783,7 @@ fn create_generator_resume_function<'a, 'tcx>( transform: TransformVisitor<'a, 'tcx>, def_id: DefId, source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { // Poison the generator when it unwinds for block in mir.basic_blocks_mut() { let source_info = block.terminator().source_info; @@ -821,14 +821,14 @@ fn create_generator_resume_function<'a, 'tcx>( dump_mir(tcx, None, "generator_resume", &0, source, mir, |_, _| Ok(()) ); } -fn source_info<'a, 'tcx>(mir: &Mir<'tcx>) -> SourceInfo { +fn source_info<'a, 'tcx>(mir: &Body<'tcx>) -> SourceInfo { SourceInfo { span: mir.span, scope: OUTERMOST_SOURCE_SCOPE, } } -fn insert_clean_drop<'a, 'tcx>(mir: &mut Mir<'tcx>) -> BasicBlock { +fn insert_clean_drop<'a, 'tcx>(mir: &mut Body<'tcx>) -> BasicBlock { let return_block = insert_term_block(mir, TerminatorKind::Return); // Create a block to destroy an unresumed generators. This can only destroy upvars. @@ -851,7 +851,7 @@ fn insert_clean_drop<'a, 'tcx>(mir: &mut Mir<'tcx>) -> BasicBlock { drop_clean } -fn create_cases<'a, 'tcx, F>(mir: &mut Mir<'tcx>, +fn create_cases<'a, 'tcx, F>(mir: &mut Body<'tcx>, transform: &TransformVisitor<'a, 'tcx>, target: F) -> Vec<(usize, BasicBlock)> where F: Fn(&SuspensionPoint) -> Option { @@ -895,7 +895,7 @@ impl MirPass for StateTransform { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let yield_ty = if let Some(yield_ty) = mir.yield_ty { yield_ty } else { @@ -959,7 +959,7 @@ impl MirPass for StateTransform { new_ret_local, discr_ty, }; - transform.visit_mir(mir); + transform.visit_body(mir); // Update our MIR struct to reflect the changed we've made mir.yield_ty = None; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 782af3024ad2c..0fac6868f57d3 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -41,7 +41,7 @@ impl MirPass for Inline { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { Inliner { tcx, source }.run_pass(mir); } @@ -54,7 +54,7 @@ struct Inliner<'a, 'tcx: 'a> { } impl<'a, 'tcx> Inliner<'a, 'tcx> { - fn run_pass(&self, caller_mir: &mut Mir<'tcx>) { + fn run_pass(&self, caller_mir: &mut Body<'tcx>) { // Keep a queue of callsites to try inlining on. We take // advantage of the fact that queries detect cycles here to // allow us to try and fetch the fully optimized MIR of a @@ -171,7 +171,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { fn get_valid_function_call(&self, bb: BasicBlock, bb_data: &BasicBlockData<'tcx>, - caller_mir: &Mir<'tcx>, + caller_mir: &Body<'tcx>, param_env: ParamEnv<'tcx>, ) -> Option> { // Don't inline calls that are in cleanup blocks. @@ -204,7 +204,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { fn consider_optimizing(&self, callsite: CallSite<'tcx>, - callee_mir: &Mir<'tcx>) + callee_mir: &Body<'tcx>) -> bool { debug!("consider_optimizing({:?})", callsite); @@ -216,7 +216,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { fn should_inline(&self, callsite: CallSite<'tcx>, - callee_mir: &Mir<'tcx>) + callee_mir: &Body<'tcx>) -> bool { debug!("should_inline({:?})", callsite); @@ -394,8 +394,8 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { fn inline_call(&self, callsite: CallSite<'tcx>, - caller_mir: &mut Mir<'tcx>, - mut callee_mir: Mir<'tcx>) -> bool { + caller_mir: &mut Body<'tcx>, + mut callee_mir: Body<'tcx>) -> bool { let terminator = caller_mir[callsite.bb].terminator.take().unwrap(); match terminator.kind { // FIXME: Handle inlining of diverging calls @@ -531,7 +531,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { &self, args: Vec>, callsite: &CallSite<'tcx>, - caller_mir: &mut Mir<'tcx>, + caller_mir: &mut Body<'tcx>, ) -> Vec { let tcx = self.tcx; @@ -601,7 +601,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { &self, arg: Operand<'tcx>, callsite: &CallSite<'tcx>, - caller_mir: &mut Mir<'tcx>, + caller_mir: &mut Body<'tcx>, ) -> Local { // FIXME: Analysis of the usage of the arguments to avoid // unnecessary temporaries. diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 8187a81f0edab..1b92b1acac55d 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -1,6 +1,7 @@ //! Performs various peephole optimizations. -use rustc::mir::{Constant, Location, Place, PlaceBase, Mir, Operand, ProjectionElem, Rvalue, Local}; +use rustc::mir::{Constant, Location, Place, PlaceBase, Body, Operand, ProjectionElem, Rvalue, + Local}; use rustc::mir::visit::{MutVisitor, Visitor}; use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; @@ -14,7 +15,7 @@ impl MirPass for InstCombine { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { // We only run when optimizing MIR (at any level). if tcx.sess.opts.debugging_opts.mir_opt_level == 0 { return @@ -25,12 +26,12 @@ impl MirPass for InstCombine { // `Place::ty()`). let optimizations = { let mut optimization_finder = OptimizationFinder::new(mir, tcx); - optimization_finder.visit_mir(mir); + optimization_finder.visit_body(mir); optimization_finder.optimizations }; // Then carry out those optimizations. - MutVisitor::visit_mir(&mut InstCombineVisitor { optimizations }, mir); + MutVisitor::visit_body(&mut InstCombineVisitor { optimizations }, mir); } } @@ -63,13 +64,13 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { /// Finds optimization opportunities on the MIR. struct OptimizationFinder<'b, 'a, 'tcx:'a+'b> { - mir: &'b Mir<'tcx>, + mir: &'b Body<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>, optimizations: OptimizationList<'tcx>, } impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> { - fn new(mir: &'b Mir<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> OptimizationFinder<'b, 'a, 'tcx> { + fn new(mir: &'b Body<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> OptimizationFinder<'b, 'a, 'tcx> { OptimizationFinder { mir, tcx, diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index fd9d6bb5760b1..8c19637a955f1 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -13,7 +13,7 @@ impl MirPass for Lower128Bit { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let debugging_override = tcx.sess.opts.debugging_opts.lower_128bit_ops; let target_default = tcx.sess.host.options.i128_lowering; if !debugging_override.unwrap_or(target_default) { @@ -25,7 +25,7 @@ impl MirPass for Lower128Bit { } impl Lower128Bit { - fn lower_128bit_ops<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Mir<'tcx>) { + fn lower_128bit_ops<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Body<'tcx>) { let mut new_blocks = Vec::new(); let cur_len = mir.basic_blocks().len(); diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index b609164415717..3fd4e6044af74 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -1,6 +1,6 @@ use crate::build; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::mir::{Mir, MirPhase, Promoted}; +use rustc::mir::{Body, MirPhase, Promoted}; use rustc::ty::{TyCtxt, InstanceDef}; use rustc::ty::query::Providers; use rustc::ty::steal::Steal; @@ -95,7 +95,7 @@ fn mir_keys<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, krate: CrateNum) tcx.arena.alloc(set) } -fn mir_built<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { +fn mir_built<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { let mir = build::mir_build(tcx, def_id); tcx.alloc_steal_mir(mir) } @@ -145,19 +145,19 @@ pub trait MirPass { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, source: MirSource<'tcx>, - mir: &mut Mir<'tcx>); + mir: &mut Body<'tcx>); } pub fn run_passes( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &mut Mir<'tcx>, + mir: &mut Body<'tcx>, instance: InstanceDef<'tcx>, mir_phase: MirPhase, passes: &[&dyn MirPass], ) { let phase_index = mir_phase.phase_index(); - let run_passes = |mir: &mut Mir<'tcx>, promoted| { + let run_passes = |mir: &mut Body<'tcx>, promoted| { if mir.phase >= mir_phase { return; } @@ -196,7 +196,7 @@ pub fn run_passes( } } -fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { +fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { // Unsafety check uses the raw mir, so make sure it is run let _ = tcx.unsafety_check_result(def_id); @@ -210,7 +210,7 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea tcx.alloc_steal_mir(mir) } -fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { +fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal> { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(hir_id) { // Ensure that we compute the `mir_const_qualif` for constants at @@ -227,7 +227,7 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx tcx.alloc_steal_mir(mir) } -fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Mir<'tcx> { +fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Body<'tcx> { // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. tcx.ensure().mir_borrowck(def_id); diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index 648f4e65b0d07..719e22ca15023 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -12,14 +12,14 @@ impl MirPass for NoLandingPads { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { no_landing_pads(tcx, mir) } } -pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Mir<'tcx>) { +pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Body<'tcx>) { if tcx.sess.no_landing_pads() { - NoLandingPads.visit_mir(mir); + NoLandingPads.visit_body(mir); } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 0bf96c689176b..24f810cceaf86 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -71,7 +71,7 @@ pub enum Candidate { struct TempCollector<'tcx> { temps: IndexVec, span: Span, - mir: &'tcx Mir<'tcx>, + mir: &'tcx Body<'tcx>, } impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> { @@ -134,7 +134,7 @@ impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> { } } -pub fn collect_temps(mir: &Mir<'_>, +pub fn collect_temps(mir: &Body<'_>, rpo: &mut ReversePostorder<'_, '_>) -> IndexVec { let mut collector = TempCollector { temps: IndexVec::from_elem(TempState::Undefined, &mir.local_decls), @@ -149,8 +149,8 @@ pub fn collect_temps(mir: &Mir<'_>, struct Promoter<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - source: &'a mut Mir<'tcx>, - promoted: Mir<'tcx>, + source: &'a mut Body<'tcx>, + promoted: Body<'tcx>, temps: &'a mut IndexVec, /// If true, all nested temps are also kept in the @@ -369,7 +369,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { } } -pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, +pub fn promote_candidates<'a, 'tcx>(mir: &mut Body<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut temps: IndexVec, candidates: Vec) { @@ -393,13 +393,13 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, } - // Declare return place local so that `Mir::new` doesn't complain. + // Declare return place local so that `Body::new` doesn't complain. let initial_locals = iter::once( LocalDecl::new_return_place(tcx.types.never, mir.span) ).collect(); let promoter = Promoter { - promoted: Mir::new( + promoted: Body::new( IndexVec::new(), // FIXME: maybe try to filter this to avoid blowing up // memory usage? diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index dca2836839373..862c863500c80 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -113,7 +113,7 @@ struct ConstCx<'a, 'tcx> { tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, mode: Mode, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, per_local: PerQualif>, } @@ -619,7 +619,7 @@ impl Deref for Checker<'a, 'tcx> { impl<'a, 'tcx> Checker<'a, 'tcx> { fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, mode: Mode) -> Self { assert!(def_id.is_local()); @@ -1444,7 +1444,7 @@ impl MirPass for QualifyAndPromoteConstants { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { // There's not really any point in promoting errorful MIR. if mir.return_ty().references_error() { tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: Mir had errors"); diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index a1e2d0683d380..4811380e23860 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -11,7 +11,7 @@ type McfResult = Result<(), (Span, Cow<'static, str>)>; pub fn is_min_const_fn( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, ) -> McfResult { let mut current = def_id; loop { @@ -130,7 +130,7 @@ fn check_ty( fn check_rvalue( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, rvalue: &Rvalue<'tcx>, span: Span, ) -> McfResult { @@ -210,7 +210,7 @@ fn check_rvalue( fn check_statement( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, statement: &Statement<'tcx>, ) -> McfResult { let span = statement.source_info.span; @@ -250,7 +250,10 @@ fn check_operand( } } -fn check_place(place: &Place<'tcx>, span: Span) -> McfResult { +fn check_place( + place: &Place<'tcx>, + span: Span, +) -> McfResult { place.iterate(|place_base, place_projection| { for proj in place_projection { match proj.elem { @@ -277,7 +280,7 @@ fn check_place(place: &Place<'tcx>, span: Span) -> McfResult { fn check_terminator( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, terminator: &Terminator<'tcx>, ) -> McfResult { let span = terminator.source_info.span; diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index b7493b25d4650..42818a571151e 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -11,7 +11,7 @@ pub struct RemoveNoopLandingPads; pub fn remove_noop_landing_pads<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &mut Mir<'tcx>) + mir: &mut Body<'tcx>) { if tcx.sess.no_landing_pads() { return @@ -25,7 +25,7 @@ impl MirPass for RemoveNoopLandingPads { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { remove_noop_landing_pads(tcx, mir); } } @@ -34,7 +34,7 @@ impl RemoveNoopLandingPads { fn is_nop_landing_pad( &self, bb: BasicBlock, - mir: &Mir<'_>, + mir: &Body<'_>, nop_landing_pads: &BitSet, ) -> bool { for stmt in &mir[bb].statements { @@ -86,7 +86,7 @@ impl RemoveNoopLandingPads { } } - fn remove_nop_landing_pads(&self, mir: &mut Mir<'_>) { + fn remove_nop_landing_pads(&self, mir: &mut Body<'_>) { // make sure there's a single resume block let resume_block = { let patch = MirPatch::new(mir); diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 7d2dbff996d08..2b3eb9e1edf30 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -5,7 +5,7 @@ use syntax_pos::Span; use rustc::ty::{self, TyCtxt}; use rustc::hir::def_id::DefId; -use rustc::mir::{self, Mir, Location}; +use rustc::mir::{self, Body, Location}; use rustc_data_structures::bit_set::BitSet; use crate::transform::{MirPass, MirSource}; @@ -26,7 +26,7 @@ pub struct SanityCheck; impl MirPass for SanityCheck { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, - src: MirSource<'tcx>, mir: &mut Mir<'tcx>) { + src: MirSource<'tcx>, mir: &mut Body<'tcx>) { let def_id = src.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); @@ -85,7 +85,7 @@ impl MirPass for SanityCheck { /// expression form above, then that emits an error as well, but those /// errors are not intended to be used for unit tests.) pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, def_id: DefId, _attributes: &[ast::Attribute], results: &DataflowResults<'tcx, O>) @@ -102,7 +102,7 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, results: &DataflowResults<'tcx, O>, bb: mir::BasicBlock) where O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx> diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index ee16ec7b41cf5..e7be238e850f2 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -44,7 +44,7 @@ impl SimplifyCfg { } } -pub fn simplify_cfg(mir: &mut Mir<'_>) { +pub fn simplify_cfg(mir: &mut Body<'_>) { CfgSimplifier::new(mir).simplify(); remove_dead_blocks(mir); @@ -60,7 +60,7 @@ impl MirPass for SimplifyCfg { fn run_pass<'a, 'tcx>(&self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, mir); simplify_cfg(mir); } @@ -72,7 +72,7 @@ pub struct CfgSimplifier<'a, 'tcx: 'a> { } impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> { - pub fn new(mir: &'a mut Mir<'tcx>) -> Self { + pub fn new(mir: &'a mut Body<'tcx>) -> Self { let mut pred_count = IndexVec::from_elem(0u32, mir.basic_blocks()); // we can't use mir.predecessors() here because that counts @@ -263,7 +263,7 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> { } } -pub fn remove_dead_blocks(mir: &mut Mir<'_>) { +pub fn remove_dead_blocks(mir: &mut Body<'_>) { let mut seen = BitSet::new_empty(mir.basic_blocks().len()); for (bb, _) in traversal::preorder(mir) { seen.insert(bb.index()); @@ -299,9 +299,9 @@ impl MirPass for SimplifyLocals { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let mut marker = DeclMarker { locals: BitSet::new_empty(mir.local_decls.len()) }; - marker.visit_mir(mir); + marker.visit_body(mir); // Return pointer and arguments are always live marker.locals.insert(RETURN_PLACE); for arg in mir.args_iter() { @@ -317,7 +317,7 @@ impl MirPass for SimplifyLocals { let map = make_local_map(&mut mir.local_decls, marker.locals); // Update references to all vars and tmps now - LocalUpdater { map }.visit_mir(mir); + LocalUpdater { map }.visit_body(mir); mir.local_decls.shrink_to_fit(); } } diff --git a/src/librustc_mir/transform/simplify_branches.rs b/src/librustc_mir/transform/simplify_branches.rs index db73e829c53a7..53949bcfcd707 100644 --- a/src/librustc_mir/transform/simplify_branches.rs +++ b/src/librustc_mir/transform/simplify_branches.rs @@ -22,7 +22,7 @@ impl MirPass for SimplifyBranches { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { for block in mir.basic_blocks_mut() { let terminator = block.terminator_mut(); terminator.kind = match terminator.kind { diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index a2433ab838d07..ee1d2ca2a891c 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -40,18 +40,18 @@ impl MirPass for UniformArrayMoveOut { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let mut patch = MirPatch::new(mir); { let mut visitor = UniformArrayMoveOutVisitor{mir, patch: &mut patch, tcx}; - visitor.visit_mir(mir); + visitor.visit_body(mir); } patch.apply(mir); } } struct UniformArrayMoveOutVisitor<'a, 'tcx: 'a> { - mir: &'a Mir<'tcx>, + mir: &'a Body<'tcx>, patch: &'a mut MirPatch<'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>, } @@ -165,14 +165,14 @@ impl MirPass for RestoreSubsliceArrayMoveOut { fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource<'tcx>, - mir: &mut Mir<'tcx>) { + mir: &mut Body<'tcx>) { let mut patch = MirPatch::new(mir); { let mut visitor = RestoreDataCollector { locals_use: IndexVec::from_elem(LocalUse::new(), &mir.local_decls), candidates: vec![], }; - visitor.visit_mir(mir); + visitor.visit_body(mir); for candidate in &visitor.candidates { let statement = &mir[candidate.block].statements[candidate.statement_index]; @@ -254,7 +254,7 @@ impl RestoreSubsliceArrayMoveOut { } fn try_get_item_source<'a, 'tcx>(local_use: &LocalUse, - mir: &'a Mir<'tcx>) -> Option<(u32, &'a Place<'tcx>)> { + mir: &'a Body<'tcx>) -> Option<(u32, &'a Place<'tcx>)> { if let Some(location) = local_use.first_use { let block = &mir[location.block]; if block.statements.len() > location.statement_index { diff --git a/src/librustc_mir/util/collect_writes.rs b/src/librustc_mir/util/collect_writes.rs index 7bd61c3a59c94..c8804dfbaf261 100644 --- a/src/librustc_mir/util/collect_writes.rs +++ b/src/librustc_mir/util/collect_writes.rs @@ -1,5 +1,5 @@ use rustc::mir::{Local, Location}; -use rustc::mir::Mir; +use rustc::mir::Body; use rustc::mir::visit::PlaceContext; use rustc::mir::visit::Visitor; @@ -9,10 +9,10 @@ crate trait FindAssignments { fn find_assignments(&self, local: Local) -> Vec; } -impl<'tcx> FindAssignments for Mir<'tcx>{ +impl<'tcx> FindAssignments for Body<'tcx>{ fn find_assignments(&self, local: Local) -> Vec{ let mut visitor = FindLocalAssignmentVisitor{ needle: local, locations: vec![]}; - visitor.visit_mir(self); + visitor.visit_body(self); visitor.locations } } diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index 2925005b6674d..ba0190756c542 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -1,6 +1,6 @@ //! Def-use analysis. -use rustc::mir::{Local, Location, Mir}; +use rustc::mir::{Local, Location, Body}; use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor}; use rustc_data_structures::indexed_vec::IndexVec; use std::mem; @@ -21,19 +21,19 @@ pub struct Use { } impl DefUseAnalysis { - pub fn new(mir: &Mir<'_>) -> DefUseAnalysis { + pub fn new(mir: &Body<'_>) -> DefUseAnalysis { DefUseAnalysis { info: IndexVec::from_elem_n(Info::new(), mir.local_decls.len()), } } - pub fn analyze(&mut self, mir: &Mir<'_>) { + pub fn analyze(&mut self, mir: &Body<'_>) { self.clear(); let mut finder = DefUseFinder { info: mem::replace(&mut self.info, IndexVec::new()), }; - finder.visit_mir(mir); + finder.visit_body(mir); self.info = finder.info } @@ -47,7 +47,7 @@ impl DefUseAnalysis { &self.info[local] } - fn mutate_defs_and_uses(&self, local: Local, mir: &mut Mir<'_>, mut callback: F) + fn mutate_defs_and_uses(&self, local: Local, mir: &mut Body<'_>, mut callback: F) where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) { @@ -61,7 +61,7 @@ impl DefUseAnalysis { // FIXME(pcwalton): this should update the def-use chains. pub fn replace_all_defs_and_uses_with(&self, local: Local, - mir: &mut Mir<'_>, + mir: &mut Body<'_>, new_local: Local) { self.mutate_defs_and_uses(local, mir, |local, _, _| *local = new_local) } @@ -123,7 +123,7 @@ struct MutateUseVisitor { } impl MutateUseVisitor { - fn new(query: Local, callback: F, _: &Mir<'_>) + fn new(query: Local, callback: F, _: &Body<'_>) -> MutateUseVisitor where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) { MutateUseVisitor { diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index ac5ebc5e2512a..076ba60c6441c 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -74,7 +74,7 @@ pub trait DropElaborator<'a, 'tcx: 'a> : fmt::Debug { type Path : Copy + fmt::Debug; fn patch(&mut self) -> &mut MirPatch<'tcx>; - fn mir(&self) -> &'a Mir<'tcx>; + fn mir(&self) -> &'a Body<'tcx>; fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>; fn param_env(&self) -> ty::ParamEnv<'tcx>; diff --git a/src/librustc_mir/util/graphviz.rs b/src/librustc_mir/util/graphviz.rs index fc4c6b3fd3f24..20d92da9ba330 100644 --- a/src/librustc_mir/util/graphviz.rs +++ b/src/librustc_mir/util/graphviz.rs @@ -34,7 +34,7 @@ pub fn graphviz_safe_def_name(def_id: DefId) -> String { /// Write a graphviz DOT graph of the MIR. pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>, def_id: DefId, - mir: &Mir<'_>, + mir: &Body<'_>, w: &mut W) -> io::Result<()> where W: Write { @@ -68,7 +68,7 @@ pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>, /// `init` and `fini` are callbacks for emitting additional rows of /// data (using HTML enclosed with `` in the emitted text). pub fn write_node_label(block: BasicBlock, - mir: &Mir<'_>, + mir: &Body<'_>, w: &mut W, num_cols: u32, init: INIT, @@ -110,7 +110,7 @@ pub fn write_node_label(block: BasicBlock, } /// Write a graphviz DOT node for the given basic block. -fn write_node(block: BasicBlock, mir: &Mir<'_>, w: &mut W) -> io::Result<()> { +fn write_node(block: BasicBlock, mir: &Body<'_>, w: &mut W) -> io::Result<()> { // Start a new node with the label to follow, in one of DOT's pseudo-HTML tables. write!(w, r#" {} [shape="none", label=<"#, node(block))?; write_node_label(block, mir, w, 1, |_| Ok(()), |_| Ok(()))?; @@ -119,7 +119,7 @@ fn write_node(block: BasicBlock, mir: &Mir<'_>, w: &mut W) -> io::Resu } /// Write graphviz DOT edges with labels between the given basic block and all of its successors. -fn write_edges(source: BasicBlock, mir: &Mir<'_>, w: &mut W) -> io::Result<()> { +fn write_edges(source: BasicBlock, mir: &Body<'_>, w: &mut W) -> io::Result<()> { let terminator = mir[source].terminator(); let labels = terminator.kind.fmt_successor_labels(); @@ -135,7 +135,7 @@ fn write_edges(source: BasicBlock, mir: &Mir<'_>, w: &mut W) -> io::Re /// all the variables and temporaries. fn write_graph_label<'a, 'gcx, 'tcx, W: Write>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId, - mir: &Mir<'_>, + mir: &Body<'_>, w: &mut W) -> io::Result<()> { write!(w, " label=( - mir: &Mir<'tcx>, + mir: &Body<'tcx>, ) -> LivenessResult { let num_live_vars = mir.local_decls.len(); @@ -258,7 +258,7 @@ pub fn dump_mir<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, pass_name: &str, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, result: &LivenessResult, ) { if !dump_enabled(tcx, pass_name, source) { @@ -276,7 +276,7 @@ fn dump_matched_mir_node<'a, 'tcx>( pass_name: &str, node_path: &str, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, result: &LivenessResult, ) { let mut file_path = PathBuf::new(); @@ -297,7 +297,7 @@ fn dump_matched_mir_node<'a, 'tcx>( pub fn write_mir_fn<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, w: &mut dyn Write, result: &LivenessResult, ) -> io::Result<()> { diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index 366cd71f6d4e9..974dda867bc9d 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -17,7 +17,7 @@ pub struct MirPatch<'tcx> { } impl<'tcx> MirPatch<'tcx> { - pub fn new(mir: &Mir<'tcx>) -> Self { + pub fn new(mir: &Body<'tcx>) -> Self { let mut result = MirPatch { patch_map: IndexVec::from_elem(None, mir.basic_blocks()), new_blocks: vec![], @@ -75,7 +75,7 @@ impl<'tcx> MirPatch<'tcx> { self.patch_map[bb].is_some() } - pub fn terminator_loc(&self, mir: &Mir<'tcx>, bb: BasicBlock) -> Location { + pub fn terminator_loc(&self, mir: &Body<'tcx>, bb: BasicBlock) -> Location { let offset = match bb.index().checked_sub(mir.basic_blocks().len()) { Some(index) => self.new_blocks[index].statements.len(), None => mir[bb].statements.len() @@ -127,7 +127,7 @@ impl<'tcx> MirPatch<'tcx> { self.make_nop.push(loc); } - pub fn apply(self, mir: &mut Mir<'tcx>) { + pub fn apply(self, mir: &mut Body<'tcx>) { debug!("MirPatch: make nops at: {:?}", self.make_nop); for loc in self.make_nop { mir.make_statement_nop(loc); @@ -177,7 +177,7 @@ impl<'tcx> MirPatch<'tcx> { } } - pub fn source_info_for_location(&self, mir: &Mir<'_>, loc: Location) -> SourceInfo { + pub fn source_info_for_location(&self, mir: &Body<'_>, loc: Location) -> SourceInfo { let data = match loc.block.index().checked_sub(mir.basic_blocks().len()) { Some(new) => &self.new_blocks[new], None => &mir[loc.block] diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index cf90f44e6707f..aec8ce7ced6c7 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -68,7 +68,7 @@ pub fn dump_mir<'a, 'gcx, 'tcx, F>( pass_name: &str, disambiguator: &dyn Display, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, extra_data: F, ) where F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>, @@ -124,7 +124,7 @@ fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>( node_path: &str, disambiguator: &dyn Display, source: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, mut extra_data: F, ) where F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>, @@ -282,7 +282,7 @@ pub fn write_mir_pretty<'a, 'gcx, 'tcx>( pub fn write_mir_fn<'a, 'gcx, 'tcx, F>( tcx: TyCtxt<'a, 'gcx, 'tcx>, src: MirSource<'tcx>, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, extra_data: &mut F, w: &mut dyn Write, ) -> io::Result<()> @@ -306,7 +306,7 @@ where pub fn write_basic_block<'cx, 'gcx, 'tcx, F>( tcx: TyCtxt<'cx, 'gcx, 'tcx>, block: BasicBlock, - mir: &Mir<'tcx>, + mir: &Body<'tcx>, extra_data: &mut F, w: &mut dyn Write, ) -> io::Result<()> @@ -464,7 +464,7 @@ fn comment(tcx: TyCtxt<'_, '_, '_>, SourceInfo { span, scope }: SourceInfo) -> S /// Prints local variables in a scope tree. fn write_scope_tree( tcx: TyCtxt<'_, '_, '_>, - mir: &Mir<'_>, + mir: &Body<'_>, scope_tree: &FxHashMap>, w: &mut dyn Write, parent: SourceScope, @@ -541,7 +541,7 @@ fn write_scope_tree( pub fn write_mir_intro<'a, 'gcx, 'tcx>( tcx: TyCtxt<'a, 'gcx, 'tcx>, src: MirSource<'tcx>, - mir: &Mir<'_>, + mir: &Body<'_>, w: &mut dyn Write, ) -> io::Result<()> { write_mir_sig(tcx, src, mir, w)?; @@ -572,7 +572,7 @@ pub fn write_mir_intro<'a, 'gcx, 'tcx>( fn write_mir_sig( tcx: TyCtxt<'_, '_, '_>, src: MirSource<'tcx>, - mir: &Mir<'_>, + mir: &Body<'_>, w: &mut dyn Write, ) -> io::Result<()> { use rustc::hir::def::DefKind; @@ -629,7 +629,7 @@ fn write_mir_sig( Ok(()) } -fn write_user_type_annotations(mir: &Mir<'_>, w: &mut dyn Write) -> io::Result<()> { +fn write_user_type_annotations(mir: &Body<'_>, w: &mut dyn Write) -> io::Result<()> { if !mir.user_type_annotations.is_empty() { writeln!(w, "| User Type Annotations")?; } diff --git a/src/test/run-pass/regions/regions-lub-ref-ref-rc.rs b/src/test/run-pass/regions/regions-lub-ref-ref-rc.rs index cd095f6f3a4a3..96c71b084b13e 100644 --- a/src/test/run-pass/regions/regions-lub-ref-ref-rc.rs +++ b/src/test/run-pass/regions/regions-lub-ref-ref-rc.rs @@ -11,16 +11,16 @@ use std::rc::Rc; #[derive(Clone)] -enum CachedMir<'mir> { +enum Cached<'mir> { Ref(&'mir String), Owned(Rc), } -impl<'mir> CachedMir<'mir> { +impl<'mir> Cached<'mir> { fn get_ref<'a>(&'a self) -> &'a String { match *self { - CachedMir::Ref(r) => r, - CachedMir::Owned(ref rc) => &rc, + Cached::Ref(r) => r, + Cached::Owned(ref rc) => &rc, } } } From 9c34473ecf87a6f541b9f6404b782eaa484033d7 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 25 May 2019 22:29:18 +0100 Subject: [PATCH 12/31] Special-case `.llvm` in mangler to fix segfaults This commit special cases `.llvm` in the mangler to print `.llvm$6d$` instead. This will avoid segfaults when names in a user's Rust code are `llvm`. --- src/librustc_codegen_utils/symbol_names.rs | 3 ++ src/test/ui/issue-53912.rs | 37 +++++++++++++++++++ src/test/ui/symbol-names/issue-60925.rs | 39 +++++++++++++++++++++ src/test/ui/symbol-names/issue-60925.stderr | 8 +++++ 4 files changed, 87 insertions(+) create mode 100644 src/test/ui/issue-53912.rs create mode 100644 src/test/ui/symbol-names/issue-60925.rs create mode 100644 src/test/ui/symbol-names/issue-60925.stderr diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 1a8647ed197b5..5a342114fe834 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -613,6 +613,9 @@ impl fmt::Write for SymbolPrinter<'_, '_> { // for ':' and '-' '-' | ':' => self.path.temp_buf.push('.'), + // Avoid segmentation fault on some platforms, see #60925. + 'm' if self.path.temp_buf.ends_with(".llv") => self.path.temp_buf.push_str("$6d$"), + // These are legal symbols 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => self.path.temp_buf.push(c), diff --git a/src/test/ui/issue-53912.rs b/src/test/ui/issue-53912.rs new file mode 100644 index 0000000000000..d2347c3077cf3 --- /dev/null +++ b/src/test/ui/issue-53912.rs @@ -0,0 +1,37 @@ +// compile-pass + +// This test is the same code as in ui/symbol-names/issue-60925.rs but this checks that the +// reproduction compiles successfully and doesn't segfault, whereas that test just checks that the +// symbol mangling fix produces the correct result. + +fn dummy() {} + +mod llvm { + pub(crate) struct Foo; +} +mod foo { + pub(crate) struct Foo(T); + + impl Foo<::llvm::Foo> { + pub(crate) fn foo() { + for _ in 0..0 { + for _ in &[::dummy()] { + ::dummy(); + ::dummy(); + ::dummy(); + } + } + } + } + + pub(crate) fn foo() { + Foo::foo(); + Foo::foo(); + } +} + +pub fn foo() { + foo::foo(); +} + +fn main() {} diff --git a/src/test/ui/symbol-names/issue-60925.rs b/src/test/ui/symbol-names/issue-60925.rs new file mode 100644 index 0000000000000..e9f763ad7cf67 --- /dev/null +++ b/src/test/ui/symbol-names/issue-60925.rs @@ -0,0 +1,39 @@ +#![feature(rustc_attrs)] + +// This test is the same code as in ui/issue-53912.rs but this test checks that the symbol mangling +// fix produces the correct result, whereas that test just checks that the reproduction compiles +// successfully and doesn't segfault + +fn dummy() {} + +mod llvm { + pub(crate) struct Foo; +} +mod foo { + pub(crate) struct Foo(T); + + impl Foo<::llvm::Foo> { + #[rustc_symbol_name] +//~^ ERROR _ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE + pub(crate) fn foo() { + for _ in 0..0 { + for _ in &[::dummy()] { + ::dummy(); + ::dummy(); + ::dummy(); + } + } + } + } + + pub(crate) fn foo() { + Foo::foo(); + Foo::foo(); + } +} + +pub fn foo() { + foo::foo(); +} + +fn main() {} diff --git a/src/test/ui/symbol-names/issue-60925.stderr b/src/test/ui/symbol-names/issue-60925.stderr new file mode 100644 index 0000000000000..84a18745e2ea7 --- /dev/null +++ b/src/test/ui/symbol-names/issue-60925.stderr @@ -0,0 +1,8 @@ +error: symbol-name(_ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE) + --> $DIR/issue-60925.rs:16:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From 73f7e426be348e9d479c8685843399b9cbbff064 Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 May 2019 18:01:50 +0100 Subject: [PATCH 13/31] Relate identical parameters in array lengths --- src/librustc/ty/relate.rs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 75d227d8067c3..70c47a6ca3426 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -9,7 +9,6 @@ use crate::ty::subst::{Kind, UnpackedKind, SubstsRef}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; use crate::ty::error::{ExpectedFound, TypeError}; use crate::mir::interpret::{GlobalId, ConstValue, Scalar}; -use crate::util::common::ErrorReported; use syntax_pos::DUMMY_SP; use std::rc::Rc; use std::iter; @@ -474,8 +473,9 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => { let t = relation.relate(&a_t, &b_t)?; - let to_u64 = |x: ty::Const<'tcx>| -> Result { - match x.val { + + let to_u64 = |ct: &'tcx ty::Const<'tcx>| -> Option { + match ct.val { // FIXME(const_generics): this doesn't work right now, // because it tries to relate an `Infer` to a `Param`. ConstValue::Unevaluated(def_id, substs) => { @@ -493,26 +493,18 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, instance, promoted: None, }; - if let Some(s) = tcx.const_eval(param_env.and(cid)) - .ok() - .map(|c| c.unwrap_usize(tcx)) { - return Ok(s) - } + return tcx.const_eval(param_env.and(cid)) + .ok() + .map(|c| c.unwrap_usize(tcx)); } } - tcx.sess.delay_span_bug(tcx.def_span(def_id), - "array length could not be evaluated"); - Err(ErrorReported) + None } - _ => x.assert_usize(tcx).ok_or_else(|| { - tcx.sess.delay_span_bug(DUMMY_SP, - "array length could not be evaluated"); - ErrorReported - }) + _ => ct.assert_usize(tcx), } }; - match (to_u64(*sz_a), to_u64(*sz_b)) { - (Ok(sz_a_u64), Ok(sz_b_u64)) => { + match (to_u64(sz_a), to_u64(sz_b)) { + (Some(sz_a_u64), Some(sz_b_u64)) => { if sz_a_u64 == sz_b_u64 { Ok(tcx.mk_ty(ty::Array(t, sz_a))) } else { @@ -520,9 +512,13 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, expected_found(relation, &sz_a_u64, &sz_b_u64))) } } - // We reported an error or will ICE, so we can return Error. - (Err(ErrorReported), _) | (_, Err(ErrorReported)) => { - Ok(tcx.types.err) + _ => { + if let Ok(sz) = relation.relate(&sz_a, &sz_b) { + Ok(tcx.mk_ty(ty::Array(t, sz))) + } else { + tcx.sess.delay_span_bug(DUMMY_SP, "array length could not be evaluated"); + Ok(tcx.types.err) + } } } } From 5a585fe45e93b946013ec2eebb0b2c2ec3bed15a Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 May 2019 18:02:05 +0100 Subject: [PATCH 14/31] Add a test for a function taking a const param array as an argument --- .../fn-taking-const-generic-array.rs | 16 ++++++++++++++++ .../fn-taking-const-generic-array.stderr | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/ui/const-generics/fn-taking-const-generic-array.rs create mode 100644 src/test/ui/const-generics/fn-taking-const-generic-array.stderr diff --git a/src/test/ui/const-generics/fn-taking-const-generic-array.rs b/src/test/ui/const-generics/fn-taking-const-generic-array.rs new file mode 100644 index 0000000000000..d3d17cca4da27 --- /dev/null +++ b/src/test/ui/const-generics/fn-taking-const-generic-array.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +use std::fmt::Display; + +fn print_slice(slice: &[T; N]) { + for x in slice.iter() { + println!("{}", x); + } +} + +fn main() { + print_slice(&[1, 2, 3]); +} diff --git a/src/test/ui/const-generics/fn-taking-const-generic-array.stderr b/src/test/ui/const-generics/fn-taking-const-generic-array.stderr new file mode 100644 index 0000000000000..367041283251f --- /dev/null +++ b/src/test/ui/const-generics/fn-taking-const-generic-array.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/fn-taking-const-generic-array.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + From 4ad5c62550aa402716f9c845e8fdfc1c89e8a4fa Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 May 2019 18:54:14 +0100 Subject: [PATCH 15/31] Resolve consts in OpportunisticTypeResolver --- src/librustc/infer/resolve.rs | 15 ++++++++++++--- src/librustc/traits/codegen/mod.rs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index 079385368f883..e9a4805c439ad 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -1,6 +1,6 @@ use super::{InferCtxt, FixupError, FixupResult, Span, type_variable::TypeVariableOrigin}; use crate::mir::interpret::ConstValue; -use crate::ty::{self, Ty, TyCtxt, TypeFoldable, InferConst}; +use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags}; use crate::ty::fold::{TypeFolder, TypeVisitor}; /////////////////////////////////////////////////////////////////////////// @@ -31,8 +31,17 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'g if !t.has_infer_types() { t // micro-optimize -- if there is nothing in this type that this fold affects... } else { - let t0 = self.infcx.shallow_resolve(t); - t0.super_fold_with(self) + let t = self.infcx.shallow_resolve(t); + t.super_fold_with(self) + } + } + + fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> { + if !ct.has_type_flags(TypeFlags::HAS_CT_INFER) { + ct // micro-optimize -- if there is nothing in this const that this fold affects... + } else { + let ct = self.infcx.shallow_resolve(ct); + ct.super_fold_with(self) } } } diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs index 7e3d6d752ccdc..fa8e87cb859bd 100644 --- a/src/librustc/traits/codegen/mod.rs +++ b/src/librustc/traits/codegen/mod.rs @@ -157,7 +157,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let result = self.tcx.erase_regions(&result); self.tcx.lift_to_global(&result).unwrap_or_else(|| - bug!("Uninferred types/regions in `{:?}`", result) + bug!("Uninferred types/regions/consts in `{:?}`", result) ) } } From 55dcc20f9a605e19d3c34bfc7f84380f079350fb Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 May 2019 18:58:15 +0100 Subject: [PATCH 16/31] Add tests for uninferred consts during codegen --- .../uninferred-consts-during-codegen-1.rs | 18 ++++++++++++++++++ .../uninferred-consts-during-codegen-1.stderr | 6 ++++++ .../uninferred-consts-during-codegen-2.rs | 18 ++++++++++++++++++ .../uninferred-consts-during-codegen-2.stderr | 6 ++++++ 4 files changed, 48 insertions(+) create mode 100644 src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs create mode 100644 src/test/ui/const-generics/uninferred-consts-during-codegen-1.stderr create mode 100644 src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs create mode 100644 src/test/ui/const-generics/uninferred-consts-during-codegen-2.stderr diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs new file mode 100644 index 0000000000000..2e555d11ababc --- /dev/null +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs @@ -0,0 +1,18 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +use std::fmt; + +struct Array([T; N]); + +impl fmt::Debug for Array { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries(self.0.iter()).finish() + } +} + +fn main() { + println!("{:?}", Array([1, 2, 3])); +} diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.stderr b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.stderr new file mode 100644 index 0000000000000..eb2e446396c33 --- /dev/null +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/uninferred-consts-during-codegen-1.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs new file mode 100644 index 0000000000000..7a1a4f49794d9 --- /dev/null +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs @@ -0,0 +1,18 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +use std::fmt; + +struct Array(T); + +impl fmt::Debug for Array<[T; N]> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries((&self.0 as &[T]).iter()).finish() + } +} + +fn main() { + println!("{:?}", Array([1, 2, 3])); +} diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.stderr b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.stderr new file mode 100644 index 0000000000000..eaa20bb789222 --- /dev/null +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/uninferred-consts-during-codegen-2.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + From c94ba6382d274d5b1ce9ef9a8392ec7351a4714b Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 11 May 2019 19:08:26 +0100 Subject: [PATCH 17/31] Rename `OpportunisticTypeResolver` to `OpportunisticVarResolver` --- src/librustc/infer/error_reporting/mod.rs | 6 ++--- .../infer/error_reporting/need_type_info.rs | 6 ++--- .../nice_region_error/placeholder_error.rs | 4 +-- src/librustc/infer/fudge.rs | 2 +- src/librustc/infer/mod.rs | 20 +++++++------- src/librustc/infer/opaque_types/mod.rs | 4 +-- src/librustc/infer/outlives/env.rs | 2 +- src/librustc/infer/outlives/obligations.rs | 4 +-- src/librustc/infer/resolve.rs | 14 +++++----- src/librustc/middle/mem_categorization.rs | 8 +++--- src/librustc/traits/auto_trait.rs | 6 ++--- src/librustc/traits/chalk_fulfill.rs | 2 +- src/librustc/traits/codegen/mod.rs | 2 +- src/librustc/traits/coherence.rs | 4 +-- src/librustc/traits/error_reporting.rs | 26 +++++++++---------- src/librustc/traits/fulfill.rs | 10 +++---- src/librustc/traits/mod.rs | 2 +- src/librustc/traits/project.rs | 6 ++--- src/librustc/traits/query/dropck_outlives.rs | 2 +- src/librustc/traits/query/type_op/custom.rs | 2 +- src/librustc/traits/select.rs | 6 ++--- src/librustc/traits/specialize/mod.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_traits/chalk_context/mod.rs | 2 +- .../chalk_context/program_clauses/mod.rs | 2 +- .../chalk_context/resolvent_ops.rs | 4 +-- .../implied_outlives_bounds.rs | 2 +- .../normalize_erasing_regions.rs | 2 +- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/autoderef.rs | 6 ++--- src/librustc_typeck/check/cast.rs | 4 +-- src/librustc_typeck/check/closure.rs | 4 +-- src/librustc_typeck/check/coercion.rs | 2 +- .../check/generator_interior.rs | 2 +- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 6 ++--- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 26 +++++++++---------- src/librustc_typeck/check/op.rs | 2 +- src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/writeback.rs | 8 +++--- 42 files changed, 111 insertions(+), 113 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8ec9d42ec5f82..f87c6977f33d0 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -652,7 +652,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { for sp in prior_arms { err.span_label(*sp, format!( "this is found to be of type `{}`", - self.resolve_type_vars_if_possible(&last_ty), + self.resolve_vars_if_possible(&last_ty), )); } } else if let Some(sp) = prior_arms.last() { @@ -1278,7 +1278,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { &self, exp_found: &ty::error::ExpectedFound>, ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { - let exp_found = self.resolve_type_vars_if_possible(exp_found); + let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; } @@ -1291,7 +1291,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { &self, exp_found: &ty::error::ExpectedFound, ) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> { - let exp_found = self.resolve_type_vars_if_possible(exp_found); + let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; } diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index ca159872ea7fb..972ffbe1820a5 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -24,7 +24,7 @@ impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> { }); match ty_opt { Some(ty) => { - let ty = self.infcx.resolve_type_vars_if_possible(&ty); + let ty = self.infcx.resolve_vars_if_possible(&ty); ty.walk().any(|inner_ty| { inner_ty == self.target_ty || match (&inner_ty.sty, &self.target_ty.sty) { (&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => { @@ -94,7 +94,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { span: Span, ty: Ty<'tcx> ) -> DiagnosticBuilder<'gcx> { - let ty = self.resolve_type_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(&ty); let name = self.extract_type_name(&ty, None); let mut err_span = span; @@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { span: Span, ty: Ty<'tcx> ) -> DiagnosticBuilder<'gcx> { - let ty = self.resolve_type_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(&ty); let name = self.extract_type_name(&ty, None); let mut err = struct_span_err!(self.tcx.sess, diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 60acbe0afe431..1dd391950254d 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -210,11 +210,11 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { _ => (), } - let expected_trait_ref = self.infcx.resolve_type_vars_if_possible(&ty::TraitRef { + let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { def_id: trait_def_id, substs: expected_substs, }); - let actual_trait_ref = self.infcx.resolve_type_vars_if_possible(&ty::TraitRef { + let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef { def_id: trait_def_id, substs: actual_substs, }); diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index 5f5a2d4a489e3..7461d8bc72860 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -74,7 +74,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let (mut fudger, value) = self.probe(|snapshot| { match f() { Ok(value) => { - let value = self.resolve_type_vars_if_possible(&value); + let value = self.resolve_vars_if_possible(&value); // At this point, `value` could in principle refer // to inference variables that have been created during diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index b5a9184079aa6..a4a7efdbc9e3e 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1174,7 +1174,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// Process the region constraints and report any errors that /// result. After this, no more unification operations should be /// done -- or the compiler will panic -- but it is legal to use - /// `resolve_type_vars_if_possible` as well as `fully_resolve`. + /// `resolve_vars_if_possible` as well as `fully_resolve`. pub fn resolve_regions_and_report_errors( &self, region_context: DefId, @@ -1262,7 +1262,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } pub fn ty_to_string(&self, t: Ty<'tcx>) -> String { - self.resolve_type_vars_if_possible(&t).to_string() + self.resolve_vars_if_possible(&t).to_string() } pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String { @@ -1271,7 +1271,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String { - self.resolve_type_vars_if_possible(t).to_string() + self.resolve_vars_if_possible(t).to_string() } /// If `TyVar(vid)` resolves to a type, return that type. Else, return the @@ -1297,20 +1297,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.type_variables.borrow_mut().root_var(var) } - /// Where possible, replaces type/int/float variables in + /// Where possible, replaces type/const variables in /// `value` with their final value. Note that region variables - /// are unaffected. If a type variable has not been unified, it + /// are unaffected. If a type/const variable has not been unified, it /// is left as is. This is an idempotent operation that does /// not affect inference state in any way and so you can do it /// at will. - pub fn resolve_type_vars_if_possible(&self, value: &T) -> T + pub fn resolve_vars_if_possible(&self, value: &T) -> T where T: TypeFoldable<'tcx>, { if !value.needs_infer() { return value.clone(); // avoid duplicated subst-folding } - let mut r = resolve::OpportunisticTypeResolver::new(self); + let mut r = resolve::OpportunisticVarResolver::new(self); value.fold_with(&mut r) } @@ -1318,7 +1318,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// process of visiting `T`, this will resolve (where possible) /// type variables in `T`, but it never constructs the final, /// resolved type, so it's more efficient than - /// `resolve_type_vars_if_possible()`. + /// `resolve_vars_if_possible()`. pub fn unresolved_type_vars(&self, value: &T) -> Option<(Ty<'tcx>, Option)> where T: TypeFoldable<'tcx>, @@ -1389,7 +1389,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { where M: FnOnce(String) -> DiagnosticBuilder<'tcx>, { - let actual_ty = self.resolve_type_vars_if_possible(&actual_ty); + let actual_ty = self.resolve_vars_if_possible(&actual_ty); debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty); // Don't report an error if actual type is `Error`. @@ -1446,7 +1446,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ty: Ty<'tcx>, span: Span, ) -> bool { - let ty = self.resolve_type_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(&ty); // Even if the type may have no inference variables, during // type-checking closure types are in local tables only. diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 4351f94df2f13..3f114595597f7 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -284,9 +284,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { debug!("constrain_opaque_type: def_id={:?}", def_id); debug!("constrain_opaque_type: opaque_defn={:#?}", opaque_defn); - let tcx = self.tcx; - - let concrete_ty = self.resolve_type_vars_if_possible(&opaque_defn.concrete_ty); + let concrete_ty = self.resolve_vars_if_possible(&opaque_defn.concrete_ty); debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty); diff --git a/src/librustc/infer/outlives/env.rs b/src/librustc/infer/outlives/env.rs index 39aa51a95f793..3e626999200fe 100644 --- a/src/librustc/infer/outlives/env.rs +++ b/src/librustc/infer/outlives/env.rs @@ -168,7 +168,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> { debug!("add_implied_bounds()"); for &ty in fn_sig_tys { - let ty = infcx.resolve_type_vars_if_possible(&ty); + let ty = infcx.resolve_vars_if_possible(&ty); debug!("add_implied_bounds: ty = {}", ty); let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span); self.add_outlives_bounds(Some(infcx), implied_bounds) diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs index ee66032848519..90b3be213854c 100644 --- a/src/librustc/infer/outlives/obligations.rs +++ b/src/librustc/infer/outlives/obligations.rs @@ -177,7 +177,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { sup_type, sub_region, origin ); - let sup_type = self.resolve_type_vars_if_possible(&sup_type); + let sup_type = self.resolve_vars_if_possible(&sup_type); if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) { let outlives = &mut TypeOutlives::new( @@ -215,7 +215,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { implicit_region_bound, param_env, ); - let ty = self.resolve_type_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(&ty); outlives.type_must_outlive(origin, ty, region); } } diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index e9a4805c439ad..98f63c803ca03 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -4,25 +4,25 @@ use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags}; use crate::ty::fold::{TypeFolder, TypeVisitor}; /////////////////////////////////////////////////////////////////////////// -// OPPORTUNISTIC TYPE RESOLVER +// OPPORTUNISTIC KIND RESOLVER -/// The opportunistic type resolver can be used at any time. It simply replaces -/// type variables that have been unified with the things they have +/// The opportunistic kind resolver can be used at any time. It simply replaces +/// type/const variables that have been unified with the things they have /// been unified with (similar to `shallow_resolve`, but deep). This is /// useful for printing messages etc but also required at various /// points for correctness. -pub struct OpportunisticTypeResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { +pub struct OpportunisticVarResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, } -impl<'a, 'gcx, 'tcx> OpportunisticTypeResolver<'a, 'gcx, 'tcx> { +impl<'a, 'gcx, 'tcx> OpportunisticVarResolver<'a, 'gcx, 'tcx> { #[inline] pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self { - OpportunisticTypeResolver { infcx } + OpportunisticVarResolver { infcx } } } -impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'gcx, 'tcx> { +impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticVarResolver<'a, 'gcx, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c6b544469b5fa..8d7c6f18a854f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -458,10 +458,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { .unwrap_or(true) } - fn resolve_type_vars_if_possible(&self, value: &T) -> T + fn resolve_vars_if_possible(&self, value: &T) -> T where T: TypeFoldable<'tcx> { - self.infcx.map(|infcx| infcx.resolve_type_vars_if_possible(value)) + self.infcx.map(|infcx| infcx.resolve_vars_if_possible(value)) .unwrap_or_else(|| value.clone()) } @@ -475,7 +475,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { -> McResult> { match ty { Some(ty) => { - let ty = self.resolve_type_vars_if_possible(&ty); + let ty = self.resolve_vars_if_possible(&ty); if ty.references_error() || ty.is_ty_var() { debug!("resolve_type_vars_or_error: error from {:?}", ty); Err(()) @@ -602,7 +602,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { where F: FnOnce() -> McResult> { debug!("cat_expr_adjusted_with({:?}): {:?}", adjustment, expr); - let target = self.resolve_type_vars_if_possible(&adjustment.target); + let target = self.resolve_vars_if_possible(&adjustment.target); match adjustment.kind { adjustment::Adjust::Deref(overloaded) => { // Equivalent to *expr or something similar. diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 2fa896962daf9..7505b3c1be844 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -307,9 +307,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { continue; } - // Call infcx.resolve_type_vars_if_possible to see if we can + // Call infcx.resolve_vars_if_possible to see if we can // get rid of any inference variables. - let obligation = infcx.resolve_type_vars_if_possible( + let obligation = infcx.resolve_vars_if_possible( &Obligation::new(dummy_cause.clone(), new_env, pred) ); let result = select.select(&obligation); @@ -642,7 +642,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { fresh_preds.insert(self.clean_pred(select.infcx(), predicate)); // Resolve any inference variables that we can, to help selection succeed - predicate = select.infcx().resolve_type_vars_if_possible(&predicate); + predicate = select.infcx().resolve_vars_if_possible(&predicate); // We only add a predicate as a user-displayable bound if // it involves a generic parameter, and doesn't contain diff --git a/src/librustc/traits/chalk_fulfill.rs b/src/librustc/traits/chalk_fulfill.rs index d9eb6d8157dfb..a7b5e6cf41b77 100644 --- a/src/librustc/traits/chalk_fulfill.rs +++ b/src/librustc/traits/chalk_fulfill.rs @@ -33,7 +33,7 @@ fn in_environment( obligation: PredicateObligation<'tcx> ) -> InEnvironment<'tcx, PredicateObligation<'tcx>> { assert!(!infcx.is_in_snapshot()); - let obligation = infcx.resolve_type_vars_if_possible(&obligation); + let obligation = infcx.resolve_vars_if_possible(&obligation); let environment = match obligation.param_env.def_id { Some(def_id) => infcx.tcx.environment(def_id), diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs index fa8e87cb859bd..591557eb2bea5 100644 --- a/src/librustc/traits/codegen/mod.rs +++ b/src/librustc/traits/codegen/mod.rs @@ -153,7 +153,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors); } - let result = self.resolve_type_vars_if_possible(result); + let result = self.resolve_vars_if_possible(result); let result = self.tcx.erase_regions(&result); self.tcx.lift_to_global(&result).unwrap_or_else(|| diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index afbce5a4f0a49..c6521a931bb29 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -155,7 +155,7 @@ fn overlap_within_probe( a_impl_header.predicates .iter() .chain(&b_impl_header.predicates) - .map(|p| infcx.resolve_type_vars_if_possible(p)) + .map(|p| infcx.resolve_vars_if_possible(p)) .map(|p| Obligation { cause: ObligationCause::dummy(), param_env, recursion_depth: 0, @@ -171,7 +171,7 @@ fn overlap_within_probe( return None } - let impl_header = selcx.infcx().resolve_type_vars_if_possible(&a_impl_header); + let impl_header = selcx.infcx().resolve_vars_if_possible(&a_impl_header); let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes(); debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 9019c4a0575d4..5a2bf07b065f8 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -186,7 +186,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { error: &MismatchedProjectionTypes<'tcx>) { let predicate = - self.resolve_type_vars_if_possible(&obligation.predicate); + self.resolve_vars_if_possible(&obligation.predicate); if predicate.references_error() { return @@ -531,7 +531,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { where T: fmt::Display + TypeFoldable<'tcx> { let predicate = - self.resolve_type_vars_if_possible(&obligation.predicate); + self.resolve_vars_if_possible(&obligation.predicate); let mut err = struct_span_err!(self.tcx.sess, obligation.cause.span, E0275, "overflow evaluating the requirement `{}`", predicate); @@ -553,7 +553,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// we do not suggest increasing the overflow limit, which is not /// going to help). pub fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! { - let cycle = self.resolve_type_vars_if_possible(&cycle.to_owned()); + let cycle = self.resolve_vars_if_possible(&cycle.to_owned()); assert!(cycle.len() > 0); debug!("report_overflow_error_cycle: cycle={:?}", cycle); @@ -589,7 +589,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn get_parent_trait_ref(&self, code: &ObligationCauseCode<'tcx>) -> Option { match code { &ObligationCauseCode::BuiltinDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_type_vars_if_possible( + let parent_trait_ref = self.resolve_vars_if_possible( &data.parent_trait_ref); match self.get_parent_trait_ref(&data.parent_code) { Some(t) => Some(t), @@ -625,7 +625,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { match obligation.predicate { ty::Predicate::Trait(ref trait_predicate) => { let trait_predicate = - self.resolve_type_vars_if_possible(trait_predicate); + self.resolve_vars_if_possible(trait_predicate); if self.tcx.sess.has_errors() && trait_predicate.references_error() { return; @@ -749,7 +749,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } ty::Predicate::RegionOutlives(ref predicate) => { - let predicate = self.resolve_type_vars_if_possible(predicate); + let predicate = self.resolve_vars_if_possible(predicate); let err = self.region_outlives_predicate(&obligation.cause, &predicate).err().unwrap(); struct_span_err!( @@ -761,7 +761,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => { let predicate = - self.resolve_type_vars_if_possible(&obligation.predicate); + self.resolve_vars_if_possible(&obligation.predicate); struct_span_err!(self.tcx.sess, span, E0280, "the requirement `{}` is not satisfied", predicate) @@ -852,8 +852,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => { - let found_trait_ref = self.resolve_type_vars_if_possible(&*found_trait_ref); - let expected_trait_ref = self.resolve_type_vars_if_possible(&*expected_trait_ref); + let found_trait_ref = self.resolve_vars_if_possible(&*found_trait_ref); + let expected_trait_ref = self.resolve_vars_if_possible(&*expected_trait_ref); if expected_trait_ref.self_ty().references_error() { return; @@ -1345,7 +1345,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // ambiguous impls. The latter *ought* to be a // coherence violation, so we don't report it here. - let predicate = self.resolve_type_vars_if_possible(&obligation.predicate); + let predicate = self.resolve_vars_if_possible(&obligation.predicate); let span = obligation.cause.span; debug!("maybe_report_ambiguity(predicate={:?}, obligation={:?})", @@ -1617,7 +1617,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { err.note("shared static variables must have a type that implements `Sync`"); } ObligationCauseCode::BuiltinDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); let ty = parent_trait_ref.skip_binder().self_ty(); err.note(&format!("required because it appears within the type `{}`", ty)); obligated_types.push(ty); @@ -1631,7 +1631,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } ObligationCauseCode::ImplDerivedObligation(ref data) => { - let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); err.note( &format!("required because of the requirements on the impl of `{}` for `{}`", parent_trait_ref, @@ -1672,7 +1672,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { obligated_types: &mut Vec<&ty::TyS<'tcx>>, cause_code: &ObligationCauseCode<'tcx>) -> bool { if let ObligationCauseCode::BuiltinDerivedObligation(ref data) = cause_code { - let parent_trait_ref = self.resolve_type_vars_if_possible(&data.parent_trait_ref); + let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); if obligated_types.iter().any(|ot| ot == &parent_trait_ref.skip_binder().self_ty()) { return true; diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 96212d829d448..c7943d16885bd 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -178,7 +178,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> { { // this helps to reduce duplicate errors, as well as making // debug output much nicer to read and so on. - let obligation = infcx.resolve_type_vars_if_possible(&obligation); + let obligation = infcx.resolve_vars_if_possible(&obligation); debug!("register_predicate_obligation(obligation={:?})", obligation); @@ -261,7 +261,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, }) { debug!("process_predicate: pending obligation {:?} still stalled on {:?}", self.selcx.infcx() - .resolve_type_vars_if_possible(&pending_obligation.obligation), + .resolve_vars_if_possible(&pending_obligation.obligation), pending_obligation.stalled_on); return ProcessResult::Unchanged; } @@ -272,7 +272,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, if obligation.predicate.has_infer_types() { obligation.predicate = - self.selcx.infcx().resolve_type_vars_if_possible(&obligation.predicate); + self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate); } debug!("process_obligation: obligation = {:?}", obligation); @@ -318,7 +318,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx, trait_ref_type_vars(self.selcx, data.to_poly_trait_ref()); debug!("process_predicate: pending obligation {:?} now stalled on {:?}", - self.selcx.infcx().resolve_type_vars_if_possible(obligation), + self.selcx.infcx().resolve_vars_if_possible(obligation), pending_obligation.stalled_on); ProcessResult::Unchanged @@ -519,7 +519,7 @@ fn trait_ref_type_vars<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 't { t.skip_binder() // ok b/c this check doesn't care about regions .input_types() - .map(|t| selcx.infcx().resolve_type_vars_if_possible(&t)) + .map(|t| selcx.infcx().resolve_vars_if_possible(&t)) .filter(|t| t.has_infer_types()) .flat_map(|t| t.walk()) .filter(|t| match t.sty { ty::Infer(_) => true, _ => false }) diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 4b555e54f397d..c135b0b759c6f 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -927,7 +927,7 @@ pub fn fully_normalize<'a, 'gcx, 'tcx, T>( debug!("fully_normalize: select_all_or_error start"); fulfill_cx.select_all_or_error(infcx)?; debug!("fully_normalize: select_all_or_error complete"); - let resolved_value = infcx.resolve_type_vars_if_possible(&normalized_value); + let resolved_value = infcx.resolve_vars_if_possible(&normalized_value); debug!("fully_normalize: resolved_value={:?}", resolved_value); Ok(resolved_value) } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 92d5d4f031903..88bb3172c5e79 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -312,7 +312,7 @@ impl<'a, 'b, 'gcx, 'tcx> AssocTypeNormalizer<'a, 'b, 'gcx, 'tcx> { } fn fold>(&mut self, value: &T) -> T { - let value = self.selcx.infcx().resolve_type_vars_if_possible(value); + let value = self.selcx.infcx().resolve_vars_if_possible(value); if !value.has_projections() { value @@ -508,7 +508,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>( { let infcx = selcx.infcx(); - let projection_ty = infcx.resolve_type_vars_if_possible(&projection_ty); + let projection_ty = infcx.resolve_vars_if_possible(&projection_ty); let cache_key = ProjectionCacheKey { ty: projection_ty }; debug!("opt_normalize_projection_type(\ @@ -1614,7 +1614,7 @@ impl<'cx, 'gcx, 'tcx> ProjectionCacheKey<'tcx> { // from a specific call to `opt_normalize_projection_type` - if // there's no precise match, the original cache entry is "stranded" // anyway. - ty: infcx.resolve_type_vars_if_possible(&predicate.projection_ty) + ty: infcx.resolve_vars_if_possible(&predicate.projection_ty) }) } } diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 5800b024ad245..c4aa14d2b7ebc 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -54,7 +54,7 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> { &orig_values, result) { - let ty = self.infcx.resolve_type_vars_if_possible(&ty); + let ty = self.infcx.resolve_vars_if_possible(&ty); let kinds = value.into_kinds_reporting_overflows(tcx, span, ty); return InferOk { value: kinds, diff --git a/src/librustc/traits/query/type_op/custom.rs b/src/librustc/traits/query/type_op/custom.rs index 7e38282cc1adc..5933d2366e81c 100644 --- a/src/librustc/traits/query/type_op/custom.rs +++ b/src/librustc/traits/query/type_op/custom.rs @@ -97,7 +97,7 @@ fn scrape_region_constraints<'gcx, 'tcx, R>( region_obligations .iter() .map(|(_, r_o)| (r_o.sup_type, r_o.sub_region)) - .map(|(ty, r)| (infcx.resolve_type_vars_if_possible(&ty), r)), + .map(|(ty, r)| (infcx.resolve_vars_if_possible(&ty), r)), ®ion_constraint_data, ); diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index ec5e127a5ec4b..ba96233b85328 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1463,7 +1463,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { let obligation = &stack.obligation; let predicate = self.infcx() - .resolve_type_vars_if_possible(&obligation.predicate); + .resolve_vars_if_possible(&obligation.predicate); // OK to skip binder because of the nature of the // trait-ref-is-knowable check, which does not care about @@ -1621,7 +1621,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { cause: obligation.cause.clone(), recursion_depth: obligation.recursion_depth, predicate: self.infcx() - .resolve_type_vars_if_possible(&obligation.predicate), + .resolve_vars_if_possible(&obligation.predicate), }; if obligation.predicate.skip_binder().self_ty().is_ty_var() { @@ -1737,7 +1737,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { snapshot: &CombinedSnapshot<'_, 'tcx>, ) -> bool { let poly_trait_predicate = self.infcx() - .resolve_type_vars_if_possible(&obligation.predicate); + .resolve_vars_if_possible(&obligation.predicate); let (placeholder_trait_predicate, placeholder_map) = self.infcx() .replace_bound_vars_with_placeholders(&poly_trait_predicate); debug!( diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 5da4a1b9c5f36..b5d45d040fb99 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -278,7 +278,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, // Now resolve the *substitution* we built for the target earlier, replacing // the inference variables inside with whatever we got from fulfillment. - Ok(infcx.resolve_type_vars_if_possible(&target_substs)) + Ok(infcx.resolve_vars_if_possible(&target_substs)) } } }) diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index de8e75ca277ee..20b7f7eef0a16 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1263,7 +1263,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { debug!( "eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}", opaque_decl.concrete_ty, - infcx.resolve_type_vars_if_possible(&opaque_decl.concrete_ty), + infcx.resolve_vars_if_possible(&opaque_decl.concrete_ty), opaque_defn_ty ); obligations.add(infcx diff --git a/src/librustc_traits/chalk_context/mod.rs b/src/librustc_traits/chalk_context/mod.rs index 04cd632b29793..96c647ca31e6f 100644 --- a/src/librustc_traits/chalk_context/mod.rs +++ b/src/librustc_traits/chalk_context/mod.rs @@ -411,7 +411,7 @@ impl context::UnificationOps, ChalkArenas<'tcx>> } fn debug_ex_clause(&mut self, value: &'v ChalkExClause<'tcx>) -> Box { - let string = format!("{:?}", self.infcx.resolve_type_vars_if_possible(value)); + let string = format!("{:?}", self.infcx.resolve_vars_if_possible(value)); Box::new(string) } diff --git a/src/librustc_traits/chalk_context/program_clauses/mod.rs b/src/librustc_traits/chalk_context/program_clauses/mod.rs index 7ce450c7039a0..c1f14cd3f8ed5 100644 --- a/src/librustc_traits/chalk_context/program_clauses/mod.rs +++ b/src/librustc_traits/chalk_context/program_clauses/mod.rs @@ -57,7 +57,7 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> { use rustc::traits::WhereClause::*; use rustc::infer::canonical::OriginalQueryValues; - let goal = self.infcx.resolve_type_vars_if_possible(goal); + let goal = self.infcx.resolve_vars_if_possible(goal); debug!("program_clauses(goal = {:?})", goal); diff --git a/src/librustc_traits/chalk_context/resolvent_ops.rs b/src/librustc_traits/chalk_context/resolvent_ops.rs index 9d234e93b837b..f1b8588790b72 100644 --- a/src/librustc_traits/chalk_context/resolvent_ops.rs +++ b/src/librustc_traits/chalk_context/resolvent_ops.rs @@ -111,8 +111,8 @@ impl context::ResolventOps, ChalkArenas<'tcx>> ) -> Fallible> { debug!( "apply_answer_subst(ex_clause = {:?}, selected_goal = {:?})", - self.infcx.resolve_type_vars_if_possible(&ex_clause), - self.infcx.resolve_type_vars_if_possible(selected_goal) + self.infcx.resolve_vars_if_possible(&ex_clause), + self.infcx.resolve_vars_if_possible(selected_goal) ); let (answer_subst, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars( diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index b1688a7fbbb72..73bb3fb5b9a2d 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -121,7 +121,7 @@ fn compute_implied_outlives_bounds<'tcx>( ty::Predicate::TypeOutlives(ref data) => match data.no_bound_vars() { None => vec![], Some(ty::OutlivesPredicate(ty_a, r_b)) => { - let ty_a = infcx.resolve_type_vars_if_possible(&ty_a); + let ty_a = infcx.resolve_vars_if_possible(&ty_a); let mut components = smallvec![]; tcx.push_outlives_components(ty_a, &mut components); implied_bounds_from_components(r_b, components) diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index 412d2ca6dfcff..24fa5e97752a6 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -36,7 +36,7 @@ fn normalize_ty_after_erasing_regions<'tcx>( None, ); - let normalized_value = infcx.resolve_type_vars_if_possible(&normalized_value); + let normalized_value = infcx.resolve_vars_if_possible(&normalized_value); let normalized_value = infcx.tcx.erase_regions(&normalized_value); tcx.lift_to_global(&normalized_value).unwrap() } diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index a74a33b7448e2..5a84e0cb85a6e 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -226,7 +226,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Now that we know the types can be unified we find the unified type and use // it to type the entire expression. - let common_type = self.resolve_type_vars_if_possible(&lhs_ty); + let common_type = self.resolve_vars_if_possible(&lhs_ty); // subtyping doesn't matter here, as the value is some kind of scalar self.demand_eqtype_pat(pat.span, expected, lhs_ty, discrim_span); diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index f863cfe1887db..38c3ee776369a 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { body_id, param_env, steps: vec![], - cur_ty: infcx.resolve_type_vars_if_possible(&base_ty), + cur_ty: infcx.resolve_vars_if_possible(&base_ty), obligations: vec![], at_start: true, include_raw_pointers: false, @@ -152,7 +152,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { ty, normalized_ty, obligations); self.obligations.extend(obligations); - Some(self.infcx.resolve_type_vars_if_possible(&normalized_ty)) + Some(self.infcx.resolve_vars_if_possible(&normalized_ty)) } /// Returns the final type, generating an error if it is an @@ -164,7 +164,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> { /// Returns the final type we ended up with, which may well be an /// inference variable (we will resolve it first, if possible). pub fn maybe_ambiguous_final_ty(&self) -> Ty<'tcx> { - self.infcx.resolve_type_vars_if_possible(&self.cur_ty) + self.infcx.resolve_vars_if_possible(&self.cur_ty) } pub fn step_count(&self) -> usize { diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 4689456d11fe2..f8cad733ca1c8 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -82,7 +82,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { debug!("pointer_kind({:?}, {:?})", t, span); - let t = self.resolve_type_vars_if_possible(&t); + let t = self.resolve_vars_if_possible(&t); if t.references_error() { return Err(ErrorReported); @@ -334,7 +334,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { let tstr = fcx.ty_to_string(self.cast_ty); let mut err = type_error_struct!(fcx.tcx.sess, self.span, self.expr_ty, E0620, "cast to unsized type: `{}` as `{}`", - fcx.resolve_type_vars_if_possible(&self.expr_ty), + fcx.resolve_vars_if_possible(&self.expr_ty), tstr); match self.expr_ty.sty { ty::Ref(_, _, mt) => { diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 3fa192f16f32e..419f61b0ee2c0 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -282,7 +282,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let input_tys = if is_fn { let arg_param_ty = trait_ref.skip_binder().substs.type_at(1); - let arg_param_ty = self.resolve_type_vars_if_possible(&arg_param_ty); + let arg_param_ty = self.resolve_vars_if_possible(&arg_param_ty); debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty); match arg_param_ty.sty { @@ -295,7 +295,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let ret_param_ty = projection.skip_binder().ty; - let ret_param_ty = self.resolve_type_vars_if_possible(&ret_param_ty); + let ret_param_ty = self.resolve_vars_if_possible(&ret_param_ty); debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty); let sig = self.tcx.mk_fn_sig( diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 90b2643d165be..d64be24f7538f 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -575,7 +575,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { // Uncertain or unimplemented. Ok(None) => { if trait_ref.def_id() == unsize_did { - let trait_ref = self.resolve_type_vars_if_possible(&trait_ref); + let trait_ref = self.resolve_vars_if_possible(&trait_ref); let self_ty = trait_ref.skip_binder().self_ty(); let unsize_ty = trait_ref.skip_binder().input_types().nth(1).unwrap(); debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_ref); diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 08809917ba2be..3785c3c8684b4 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -48,7 +48,7 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> { }); if let Some(yield_span) = live_across_yield { - let ty = self.fcx.resolve_type_vars_if_possible(&ty); + let ty = self.fcx.resolve_vars_if_possible(&ty); debug!("type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}", expr, scope, ty, self.expr_count, yield_span); diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index f93d5449e8b78..493486321ac2f 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -511,7 +511,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { let base_ty = self.tables.borrow().expr_adjustments(base_expr).last() .map_or_else(|| self.node_ty(expr.hir_id), |adj| adj.target); - let base_ty = self.resolve_type_vars_if_possible(&base_ty); + let base_ty = self.resolve_vars_if_possible(&base_ty); // Need to deref because overloaded place ops take self by-reference. let base_ty = base_ty.builtin_deref(false) diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 65bc06b65e1fc..213d53cf48254 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -253,7 +253,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { scope: ProbeScope) -> probe::PickResult<'tcx> { let mode = probe::Mode::MethodCall; - let self_ty = self.resolve_type_vars_if_possible(&self_ty); + let self_ty = self.resolve_vars_if_possible(&self_ty); self.probe_for_name(span, mode, method_name, IsSuggestion(false), self_ty, call_expr.hir_id, scope) } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 596ce008099a6..d78e013708277 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1338,7 +1338,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // and point at it rather than reporting the entire // trait-ref? result = ProbeResult::NoMatch; - let trait_ref = self.resolve_type_vars_if_possible(&trait_ref); + let trait_ref = self.resolve_vars_if_possible(&trait_ref); possibly_unsatisfied_predicates.push(trait_ref); } } @@ -1351,7 +1351,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // Evaluate those obligations to see if they might possibly hold. for o in candidate_obligations.into_iter().chain(sub_obligations) { - let o = self.resolve_type_vars_if_possible(&o); + let o = self.resolve_vars_if_possible(&o); if !self.predicate_may_hold(&o) { result = ProbeResult::NoMatch; if let &ty::Predicate::Trait(ref pred) = &o.predicate { @@ -1364,7 +1364,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { if let (Some(return_ty), Some(xform_ret_ty)) = (self.return_type, probe.xform_ret_ty) { - let xform_ret_ty = self.resolve_type_vars_if_possible(&xform_ret_ty); + let xform_ret_ty = self.resolve_vars_if_possible(&xform_ret_ty); debug!("comparing return_ty {:?} with xform ret ty {:?}", return_ty, probe.xform_ret_ty); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index dfe21edee41f3..d2fcb987bc2d8 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }) => { let tcx = self.tcx; - let actual = self.resolve_type_vars_if_possible(&rcvr_ty); + let actual = self.resolve_vars_if_possible(&rcvr_ty); let ty_str = self.ty_to_string(actual); let is_method = mode == Mode::MethodCall; let item_kind = if is_method { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f60ad5547a278..8701d751f2d91 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -330,13 +330,13 @@ impl<'a, 'gcx, 'tcx> Expectation<'tcx> { match self { NoExpectation => NoExpectation, ExpectCastableToType(t) => { - ExpectCastableToType(fcx.resolve_type_vars_if_possible(&t)) + ExpectCastableToType(fcx.resolve_vars_if_possible(&t)) } ExpectHasType(t) => { - ExpectHasType(fcx.resolve_type_vars_if_possible(&t)) + ExpectHasType(fcx.resolve_vars_if_possible(&t)) } ExpectRvalueLikeUnsized(t) => { - ExpectRvalueLikeUnsized(fcx.resolve_type_vars_if_possible(&t)) + ExpectRvalueLikeUnsized(fcx.resolve_vars_if_possible(&t)) } } } @@ -2067,7 +2067,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Resolves type variables in `ty` if possible. Unlike the infcx - /// version (resolve_type_vars_if_possible), this version will + /// version (resolve_vars_if_possible), this version will /// also select obligations if it seems useful, in an effort /// to get more type information. fn resolve_type_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> { @@ -2080,7 +2080,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } // If `ty` is a type variable, see whether we already know what it is. - ty = self.resolve_type_vars_if_possible(&ty); + ty = self.resolve_vars_if_possible(&ty); if !ty.has_infer_types() { debug!("resolve_type_vars_with_obligations: ty={:?}", ty); return ty; @@ -2091,7 +2091,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // indirect dependencies that don't seem worth tracking // precisely. self.select_obligations_where_possible(false); - ty = self.resolve_type_vars_if_possible(&ty); + ty = self.resolve_vars_if_possible(&ty); debug!("resolve_type_vars_with_obligations: ty={:?}", ty); ty @@ -2127,7 +2127,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { #[inline] pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) { debug!("write_ty({:?}, {:?}) in fcx {}", - id, self.resolve_type_vars_if_possible(&ty), self.tag()); + id, self.resolve_vars_if_possible(&ty), self.tag()); self.tables.borrow_mut().node_types_mut().insert(id, ty); if ty.references_error() { @@ -2950,9 +2950,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else { // is the missing argument of type `()`? let sugg_unit = if expected_arg_tys.len() == 1 && supplied_arg_count == 0 { - self.resolve_type_vars_if_possible(&expected_arg_tys[0]).is_unit() + self.resolve_vars_if_possible(&expected_arg_tys[0]).is_unit() } else if fn_inputs.len() == 1 && supplied_arg_count == 0 { - self.resolve_type_vars_if_possible(&fn_inputs[0]).is_unit() + self.resolve_vars_if_possible(&fn_inputs[0]).is_unit() } else { false }; @@ -3063,7 +3063,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } ty::FnDef(..) => { let ptr_ty = self.tcx.mk_fn_ptr(arg_ty.fn_sig(self.tcx)); - let ptr_ty = self.resolve_type_vars_if_possible(&ptr_ty); + let ptr_ty = self.resolve_vars_if_possible(&ptr_ty); variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string()); } _ => {} @@ -3253,7 +3253,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Record all the argument types, with the substitutions // produced from the above subtyping unification. Ok(formal_args.iter().map(|ty| { - self.resolve_type_vars_if_possible(ty) + self.resolve_vars_if_possible(ty) }).collect()) }).unwrap_or_default(); debug!("expected_inputs_for_expected_output(formal={:?} -> {:?}, expected={:?} -> {:?})", @@ -4333,9 +4333,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Find the type of `e`. Supply hints based on the type we are casting to, // if appropriate. let t_cast = self.to_ty_saving_user_provided_ty(t); - let t_cast = self.resolve_type_vars_if_possible(&t_cast); + let t_cast = self.resolve_vars_if_possible(&t_cast); let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast)); - let t_cast = self.resolve_type_vars_if_possible(&t_cast); + let t_cast = self.resolve_vars_if_possible(&t_cast); // Eagerly check for some obvious errors. if t_expr.references_error() || t_cast.references_error() { diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index cd207478f8f6f..0bab63582aaa1 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -618,7 +618,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { method.sig.output() } Err(()) => { - let actual = self.resolve_type_vars_if_possible(&operand_ty); + let actual = self.resolve_vars_if_possible(&operand_ty); if !actual.references_error() { let mut err = struct_span_err!(self.tcx.sess, ex.span, E0600, "cannot apply unary operator `{}` to type `{}`", diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 353b9ac6cc30c..62c9c7c8b1c37 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -270,7 +270,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// of b will be `&.i32` and then `*b` will require that `` be bigger than the let and /// the `*b` expression, so we will effectively resolve `` to be the block B. pub fn resolve_type(&self, unresolved_ty: Ty<'tcx>) -> Ty<'tcx> { - self.resolve_type_vars_if_possible(&unresolved_ty) + self.resolve_vars_if_possible(&unresolved_ty) } /// Try to resolve the type for the given node. diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 13baf667808f8..a856013b719fe 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -138,7 +138,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { hir::ExprKind::Unary(hir::UnNeg, ref inner) | hir::ExprKind::Unary(hir::UnNot, ref inner) => { let inner_ty = self.fcx.node_ty(inner.hir_id); - let inner_ty = self.fcx.resolve_type_vars_if_possible(&inner_ty); + let inner_ty = self.fcx.resolve_vars_if_possible(&inner_ty); if inner_ty.is_scalar() { let mut tables = self.fcx.tables.borrow_mut(); @@ -149,10 +149,10 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { hir::ExprKind::Binary(ref op, ref lhs, ref rhs) | hir::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => { let lhs_ty = self.fcx.node_ty(lhs.hir_id); - let lhs_ty = self.fcx.resolve_type_vars_if_possible(&lhs_ty); + let lhs_ty = self.fcx.resolve_vars_if_possible(&lhs_ty); let rhs_ty = self.fcx.node_ty(rhs.hir_id); - let rhs_ty = self.fcx.resolve_type_vars_if_possible(&rhs_ty); + let rhs_ty = self.fcx.resolve_vars_if_possible(&rhs_ty); if lhs_ty.is_scalar() && rhs_ty.is_scalar() { let mut tables = self.fcx.tables.borrow_mut(); @@ -192,7 +192,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { // All valid indexing looks like this; might encounter non-valid indexes at this point if let ty::Ref(_, base_ty, _) = tables.expr_ty_adjusted(&base).sty { let index_ty = tables.expr_ty_adjusted(&index); - let index_ty = self.fcx.resolve_type_vars_if_possible(&index_ty); + let index_ty = self.fcx.resolve_vars_if_possible(&index_ty); if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize { // Remove the method call record From 908d97d03ce4d20287163d91a71695f03f3a906e Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 12 May 2019 22:28:26 +0100 Subject: [PATCH 18/31] Update test output --- src/test/ui/array-break-length.rs | 2 ++ src/test/ui/array-break-length.stderr | 25 ++++++++++++++++--- .../ui/closures/closure-array-break-length.rs | 2 ++ .../closure-array-break-length.stderr | 25 ++++++++++++++++--- .../ui/type/type-dependent-def-issue-49241.rs | 1 + .../type-dependent-def-issue-49241.stderr | 12 +++++++-- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/test/ui/array-break-length.rs b/src/test/ui/array-break-length.rs index ab15ce6e8d8e0..2696aea5e8993 100644 --- a/src/test/ui/array-break-length.rs +++ b/src/test/ui/array-break-length.rs @@ -1,9 +1,11 @@ fn main() { loop { |_: [_; break]| {} //~ ERROR: `break` outside of loop + //~^ ERROR mismatched types } loop { |_: [_; continue]| {} //~ ERROR: `continue` outside of loop + //~^ ERROR mismatched types } } diff --git a/src/test/ui/array-break-length.stderr b/src/test/ui/array-break-length.stderr index 1cbf77a99f87e..0e0dc8f623e68 100644 --- a/src/test/ui/array-break-length.stderr +++ b/src/test/ui/array-break-length.stderr @@ -5,11 +5,30 @@ LL | |_: [_; break]| {} | ^^^^^ cannot break outside of a loop error[E0268]: `continue` outside of loop - --> $DIR/array-break-length.rs:7:17 + --> $DIR/array-break-length.rs:8:17 | LL | |_: [_; continue]| {} | ^^^^^^^^ cannot break outside of a loop -error: aborting due to 2 previous errors +error[E0308]: mismatched types + --> $DIR/array-break-length.rs:3:9 + | +LL | |_: [_; break]| {} + | ^^^^^^^^^^^^^^^^^^ expected (), found closure + | + = note: expected type `()` + found type `[closure@$DIR/array-break-length.rs:3:9: 3:27]` + +error[E0308]: mismatched types + --> $DIR/array-break-length.rs:8:9 + | +LL | |_: [_; continue]| {} + | ^^^^^^^^^^^^^^^^^^^^^ expected (), found closure + | + = note: expected type `()` + found type `[closure@$DIR/array-break-length.rs:8:9: 8:30]` + +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0268`. +Some errors have detailed explanations: E0268, E0308. +For more information about an error, try `rustc --explain E0268`. diff --git a/src/test/ui/closures/closure-array-break-length.rs b/src/test/ui/closures/closure-array-break-length.rs index ac17bfdc941c8..a7f16d70ba860 100644 --- a/src/test/ui/closures/closure-array-break-length.rs +++ b/src/test/ui/closures/closure-array-break-length.rs @@ -2,6 +2,8 @@ fn main() { |_: [_; continue]| {}; //~ ERROR: `continue` outside of loop while |_: [_; continue]| {} {} //~ ERROR: `continue` outside of loop + //~^ ERROR mismatched types while |_: [_; break]| {} {} //~ ERROR: `break` outside of loop + //~^ ERROR mismatched types } diff --git a/src/test/ui/closures/closure-array-break-length.stderr b/src/test/ui/closures/closure-array-break-length.stderr index 9b78aa16a580f..46fbd3e0fae0b 100644 --- a/src/test/ui/closures/closure-array-break-length.stderr +++ b/src/test/ui/closures/closure-array-break-length.stderr @@ -11,11 +11,30 @@ LL | while |_: [_; continue]| {} {} | ^^^^^^^^ cannot break outside of a loop error[E0268]: `break` outside of loop - --> $DIR/closure-array-break-length.rs:6:19 + --> $DIR/closure-array-break-length.rs:7:19 | LL | while |_: [_; break]| {} {} | ^^^^^ cannot break outside of a loop -error: aborting due to 3 previous errors +error[E0308]: mismatched types + --> $DIR/closure-array-break-length.rs:4:11 + | +LL | while |_: [_; continue]| {} {} + | ^^^^^^^^^^^^^^^^^^^^^ expected bool, found closure + | + = note: expected type `bool` + found type `[closure@$DIR/closure-array-break-length.rs:4:11: 4:32]` + +error[E0308]: mismatched types + --> $DIR/closure-array-break-length.rs:7:11 + | +LL | while |_: [_; break]| {} {} + | ^^^^^^^^^^^^^^^^^^ expected bool, found closure + | + = note: expected type `bool` + found type `[closure@$DIR/closure-array-break-length.rs:7:11: 7:29]` + +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0268`. +Some errors have detailed explanations: E0268, E0308. +For more information about an error, try `rustc --explain E0268`. diff --git a/src/test/ui/type/type-dependent-def-issue-49241.rs b/src/test/ui/type/type-dependent-def-issue-49241.rs index 51bd116fbd61c..5ad50ffcbc389 100644 --- a/src/test/ui/type/type-dependent-def-issue-49241.rs +++ b/src/test/ui/type/type-dependent-def-issue-49241.rs @@ -3,4 +3,5 @@ fn main() { const l: usize = v.count(); //~ ERROR attempt to use a non-constant value in a constant let s: [u32; l] = v.into_iter().collect(); //~^ ERROR evaluation of constant value failed + //~^^ ERROR a collection of type } diff --git a/src/test/ui/type/type-dependent-def-issue-49241.stderr b/src/test/ui/type/type-dependent-def-issue-49241.stderr index 25cae8d9e4954..851004d105897 100644 --- a/src/test/ui/type/type-dependent-def-issue-49241.stderr +++ b/src/test/ui/type/type-dependent-def-issue-49241.stderr @@ -10,7 +10,15 @@ error[E0080]: evaluation of constant value failed LL | let s: [u32; l] = v.into_iter().collect(); | ^ referenced constant has errors -error: aborting due to 2 previous errors +error[E0277]: a collection of type `[u32; _]` cannot be built from an iterator over elements of type `{integer}` + --> $DIR/type-dependent-def-issue-49241.rs:4:37 + | +LL | let s: [u32; l] = v.into_iter().collect(); + | ^^^^^^^ a collection of type `[u32; _]` cannot be built from `std::iter::Iterator` + | + = help: the trait `std::iter::FromIterator<{integer}>` is not implemented for `[u32; _]` + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0080, E0435. +Some errors have detailed explanations: E0080, E0277, E0435. For more information about an error, try `rustc --explain E0080`. From d5c6cb87784ea5c82177beb2662ccdc6c4751388 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 13 May 2019 21:15:08 +0100 Subject: [PATCH 19/31] Eagerly evaluate in `super_relate_consts` --- src/librustc/ty/relate.rs | 93 ++++++++----------- .../ui/consts/const-array-oob-arith.stderr | 4 +- 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 70c47a6ca3426..55525d868e2fa 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -8,8 +8,7 @@ use crate::hir::def_id::DefId; use crate::ty::subst::{Kind, UnpackedKind, SubstsRef}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; use crate::ty::error::{ExpectedFound, TypeError}; -use crate::mir::interpret::{GlobalId, ConstValue, Scalar}; -use syntax_pos::DUMMY_SP; +use crate::mir::interpret::{ConstValue, Scalar, GlobalId}; use std::rc::Rc; use std::iter; use rustc_target::spec::abi; @@ -473,54 +472,8 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => { let t = relation.relate(&a_t, &b_t)?; - - let to_u64 = |ct: &'tcx ty::Const<'tcx>| -> Option { - match ct.val { - // FIXME(const_generics): this doesn't work right now, - // because it tries to relate an `Infer` to a `Param`. - ConstValue::Unevaluated(def_id, substs) => { - // FIXME(eddyb) get the right param_env. - let param_env = ty::ParamEnv::empty(); - if let Some(substs) = tcx.lift_to_global(&substs) { - let instance = ty::Instance::resolve( - tcx.global_tcx(), - param_env, - def_id, - substs, - ); - if let Some(instance) = instance { - let cid = GlobalId { - instance, - promoted: None, - }; - return tcx.const_eval(param_env.and(cid)) - .ok() - .map(|c| c.unwrap_usize(tcx)); - } - } - None - } - _ => ct.assert_usize(tcx), - } - }; - match (to_u64(sz_a), to_u64(sz_b)) { - (Some(sz_a_u64), Some(sz_b_u64)) => { - if sz_a_u64 == sz_b_u64 { - Ok(tcx.mk_ty(ty::Array(t, sz_a))) - } else { - Err(TypeError::FixedArraySize( - expected_found(relation, &sz_a_u64, &sz_b_u64))) - } - } - _ => { - if let Ok(sz) = relation.relate(&sz_a, &sz_b) { - Ok(tcx.mk_ty(ty::Array(t, sz))) - } else { - tcx.sess.delay_span_bug(DUMMY_SP, "array length could not be evaluated"); - Ok(tcx.types.err) - } - } - } + let sz = relation.relate(&sz_a, &sz_b)?; + Ok(tcx.mk_ty(ty::Array(t, sz))) } (&ty::Slice(a_t), &ty::Slice(b_t)) => @@ -594,11 +547,36 @@ where { let tcx = relation.tcx(); + let eagerly_eval = |x: &'tcx ty::Const<'tcx>| { + if let ConstValue::Unevaluated(def_id, substs) = x.val { + // FIXME(eddyb) get the right param_env. + let param_env = ty::ParamEnv::empty(); + if let Some(substs) = tcx.lift_to_global(&substs) { + let instance = ty::Instance::resolve( + tcx.global_tcx(), + param_env, + def_id, + substs, + ); + if let Some(instance) = instance { + let cid = GlobalId { + instance, + promoted: None, + }; + if let Ok(ct) = tcx.const_eval(param_env.and(cid)) { + return ct.val; + } + } + } + } + x.val + }; + // Currently, the values that can be unified are those that // implement both `PartialEq` and `Eq`, corresponding to // `structural_match` types. // FIXME(const_generics): check for `structural_match` synthetic attribute. - match (a.val, b.val) { + match (eagerly_eval(a), eagerly_eval(b)) { (ConstValue::Infer(_), _) | (_, ConstValue::Infer(_)) => { // The caller should handle these cases! bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b) @@ -609,8 +587,13 @@ where (ConstValue::Placeholder(p1), ConstValue::Placeholder(p2)) if p1 == p2 => { Ok(a) } - (ConstValue::Scalar(Scalar::Raw { .. }), _) if a == b => { - Ok(a) + (a_val @ ConstValue::Scalar(Scalar::Raw { .. }), b_val @ _) + if a.ty == b.ty && a_val == b_val => + { + Ok(tcx.mk_const(ty::Const { + val: a_val, + ty: a.ty, + })) } (ConstValue::ByRef(..), _) => { bug!( @@ -631,9 +614,7 @@ where })) } - _ => { - Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))) - } + _ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))), } } diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index 00286b0b0e0f8..29297b24e988f 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:7:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ^^^ expected an array with a fixed size of 2 elements, found one with 1 elements + | ^^^ expected `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 2 }) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 1 }) }` | = note: expected type `[i32; 2]` found type `[i32; 1]` @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:8:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ^^^^^^^ expected an array with a fixed size of 1 elements, found one with 2 elements + | ^^^^^^^ expected `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 1 }) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 2 }) }` | = note: expected type `[i32; 1]` found type `[i32; 2]` From 193b748d5fa1f056263be641e42f2b4b1801387d Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 13 May 2019 21:24:00 +0100 Subject: [PATCH 20/31] Remove FixedArraySize error --- src/librustc/infer/opaque_types/mod.rs | 2 ++ src/librustc/ty/error.rs | 7 ------- src/librustc/ty/structural_impls.rs | 2 -- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 3f114595597f7..220b7b5fa67fe 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -284,6 +284,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { debug!("constrain_opaque_type: def_id={:?}", def_id); debug!("constrain_opaque_type: opaque_defn={:#?}", opaque_defn); + let tcx = self.tcx; + let concrete_ty = self.resolve_vars_if_possible(&opaque_defn.concrete_ty); debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty); diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 4e4024d5bab43..9bf1dbe295887 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -23,7 +23,6 @@ pub enum TypeError<'tcx> { AbiMismatch(ExpectedFound), Mutability, TupleSize(ExpectedFound), - FixedArraySize(ExpectedFound), ArgCount, RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>), @@ -94,12 +93,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.found) } Mutability => write!(f, "types differ in mutability"), - FixedArraySize(values) => { - write!(f, "expected an array with a fixed size of {} elements, \ - found one with {} elements", - values.expected, - values.found) - } TupleSize(values) => { write!(f, "expected a tuple with {} elements, \ found one with {} elements", diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 0daa567052d56..b0062f20e7f6e 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -716,7 +716,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { AbiMismatch(x) => AbiMismatch(x), Mutability => Mutability, TupleSize(x) => TupleSize(x), - FixedArraySize(x) => FixedArraySize(x), ArgCount => ArgCount, RegionsDoesNotOutlive(a, b) => { return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b)) @@ -1295,7 +1294,6 @@ EnumTypeFoldableImpl! { (ty::error::TypeError::AbiMismatch)(x), (ty::error::TypeError::Mutability), (ty::error::TypeError::TupleSize)(x), - (ty::error::TypeError::FixedArraySize)(x), (ty::error::TypeError::ArgCount), (ty::error::TypeError::RegionsDoesNotOutlive)(a, b), (ty::error::TypeError::RegionsInsufficientlyPolymorphic)(a, b), From 57ff5899d22fd0b898784b3b55b1dacad27664c6 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 20 May 2019 23:03:38 +0100 Subject: [PATCH 21/31] Add broken MIR regression tests --- src/test/ui/const-generics/broken-mir-1.rs | 17 +++++++++++++++++ .../ui/const-generics/broken-mir-1.stderr | 6 ++++++ src/test/ui/const-generics/broken-mir-2.rs | 9 +++++++++ .../ui/const-generics/broken-mir-2.stderr | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 src/test/ui/const-generics/broken-mir-1.rs create mode 100644 src/test/ui/const-generics/broken-mir-1.stderr create mode 100644 src/test/ui/const-generics/broken-mir-2.rs create mode 100644 src/test/ui/const-generics/broken-mir-2.stderr diff --git a/src/test/ui/const-generics/broken-mir-1.rs b/src/test/ui/const-generics/broken-mir-1.rs new file mode 100644 index 0000000000000..9a11bd3d0313a --- /dev/null +++ b/src/test/ui/const-generics/broken-mir-1.rs @@ -0,0 +1,17 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +pub trait Foo { + fn foo(&self); +} + + +impl Foo for [T; N] { + fn foo(&self) { + let _ = &self; + } +} + +fn main() {} diff --git a/src/test/ui/const-generics/broken-mir-1.stderr b/src/test/ui/const-generics/broken-mir-1.stderr new file mode 100644 index 0000000000000..55dc7fcb7cc72 --- /dev/null +++ b/src/test/ui/const-generics/broken-mir-1.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/broken-mir-1.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + diff --git a/src/test/ui/const-generics/broken-mir-2.rs b/src/test/ui/const-generics/broken-mir-2.rs new file mode 100644 index 0000000000000..2c93ed0defdfe --- /dev/null +++ b/src/test/ui/const-generics/broken-mir-2.rs @@ -0,0 +1,9 @@ +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +use std::fmt::Debug; + +#[derive(Debug)] +struct S([T; N]); //~ ERROR `[T; N]` doesn't implement `std::fmt::Debug` + +fn main() {} diff --git a/src/test/ui/const-generics/broken-mir-2.stderr b/src/test/ui/const-generics/broken-mir-2.stderr new file mode 100644 index 0000000000000..162153573a115 --- /dev/null +++ b/src/test/ui/const-generics/broken-mir-2.stderr @@ -0,0 +1,19 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/broken-mir-2.rs:1:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + +error[E0277]: `[T; N]` doesn't implement `std::fmt::Debug` + --> $DIR/broken-mir-2.rs:7:36 + | +LL | struct S([T; N]); + | ^^^^^^ `[T; N]` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | + = help: the trait `std::fmt::Debug` is not implemented for `[T; N]` + = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[T; N]` + = note: required for the cast to the object type `dyn std::fmt::Debug` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From cfa1f80cd92c2fb273598adbb77e51ddbd3aef7b Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 21 May 2019 10:14:44 +0100 Subject: [PATCH 22/31] Fix test after rebase --- .../cannot-infer-type-for-const-param.rs | 1 + .../cannot-infer-type-for-const-param.stderr | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs index c3f5e360fe280..26496ec4a90b9 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs @@ -8,4 +8,5 @@ struct Foo(pub [u8; NUM_BYTES]); fn main() { let _ = Foo::<3>([1, 2, 3]); //~ ERROR type annotations needed + //~^ ERROR mismatched types } diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr index a0641bd2fdc96..1b5d9b173de14 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr @@ -10,6 +10,16 @@ error[E0282]: type annotations needed LL | let _ = Foo::<3>([1, 2, 3]); | ^ cannot infer type for `{integer}` -error: aborting due to previous error +error[E0308]: mismatched types + --> $DIR/cannot-infer-type-for-const-param.rs:10:22 + | +LL | let _ = Foo::<3>([1, 2, 3]); + | ^^^^^^^^^ expected `Const { ty: usize, val: Unevaluated(DefId(0:18 ~ cannot_infer_type_for_const_param[317d]::main[0]::{{constant}}[0]), []) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 3 }) }` + | + = note: expected type `[u8; _]` + found type `[u8; 3]` + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0282, E0308. +For more information about an error, try `rustc --explain E0282`. From f865b7dda43cd8e453ec1ce485d9155e5591248f Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 25 May 2019 20:42:14 +0100 Subject: [PATCH 23/31] Update tests after pretty printing --- src/test/ui/const-generics/broken-mir-2.rs | 2 +- src/test/ui/const-generics/broken-mir-2.stderr | 8 ++++---- .../cannot-infer-type-for-const-param.stderr | 2 +- src/test/ui/consts/const-array-oob-arith.stderr | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/ui/const-generics/broken-mir-2.rs b/src/test/ui/const-generics/broken-mir-2.rs index 2c93ed0defdfe..fb9a63ea738fa 100644 --- a/src/test/ui/const-generics/broken-mir-2.rs +++ b/src/test/ui/const-generics/broken-mir-2.rs @@ -4,6 +4,6 @@ use std::fmt::Debug; #[derive(Debug)] -struct S([T; N]); //~ ERROR `[T; N]` doesn't implement `std::fmt::Debug` +struct S([T; N]); //~ ERROR `[T; _]` doesn't implement `std::fmt::Debug` fn main() {} diff --git a/src/test/ui/const-generics/broken-mir-2.stderr b/src/test/ui/const-generics/broken-mir-2.stderr index 162153573a115..fb9b88bde0a25 100644 --- a/src/test/ui/const-generics/broken-mir-2.stderr +++ b/src/test/ui/const-generics/broken-mir-2.stderr @@ -4,14 +4,14 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t LL | #![feature(const_generics)] | ^^^^^^^^^^^^^^ -error[E0277]: `[T; N]` doesn't implement `std::fmt::Debug` +error[E0277]: `[T; _]` doesn't implement `std::fmt::Debug` --> $DIR/broken-mir-2.rs:7:36 | LL | struct S([T; N]); - | ^^^^^^ `[T; N]` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | ^^^^^^ `[T; _]` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | - = help: the trait `std::fmt::Debug` is not implemented for `[T; N]` - = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[T; N]` + = help: the trait `std::fmt::Debug` is not implemented for `[T; _]` + = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[T; _]` = note: required for the cast to the object type `dyn std::fmt::Debug` error: aborting due to previous error diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr index 1b5d9b173de14..094bdbf486ce5 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr @@ -14,7 +14,7 @@ error[E0308]: mismatched types --> $DIR/cannot-infer-type-for-const-param.rs:10:22 | LL | let _ = Foo::<3>([1, 2, 3]); - | ^^^^^^^^^ expected `Const { ty: usize, val: Unevaluated(DefId(0:18 ~ cannot_infer_type_for_const_param[317d]::main[0]::{{constant}}[0]), []) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 3 }) }` + | ^^^^^^^^^ expected `Const { ty: usize, val: Unevaluated(DefId(0:18 ~ cannot_infer_type_for_const_param[317d]::main[0]::{{constant}}[0]), []) }`, found `Const { ty: usize, val: Scalar(0x0000000000000003) }` | = note: expected type `[u8; _]` found type `[u8; 3]` diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index 29297b24e988f..745d59040410b 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:7:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ^^^ expected `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 2 }) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 1 }) }` + | ^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000002) }`, found `Const { ty: usize, val: Scalar(0x0000000000000001) }` | = note: expected type `[i32; 2]` found type `[i32; 1]` @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:8:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ^^^^^^^ expected `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 1 }) }`, found `Const { ty: usize, val: Scalar(Bits { size: 8, bits: 2 }) }` + | ^^^^^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000001) }`, found `Const { ty: usize, val: Scalar(0x0000000000000002) }` | = note: expected type `[i32; 1]` found type `[i32; 2]` From f13317ca2ee16163ee121fbdf28eb2184840b6dd Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 25 May 2019 21:00:29 +0100 Subject: [PATCH 24/31] Use Display rather than Debug printing for const mismatch --- src/librustc/ty/error.rs | 2 +- .../const-generics/cannot-infer-type-for-const-param.stderr | 2 +- src/test/ui/consts/const-array-oob-arith.stderr | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 9bf1dbe295887..0a2a9472eaaf2 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -159,7 +159,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { &format!("trait `{}`", values.found)) } ConstMismatch(ref values) => { - write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found) + write!(f, "expected `{}`, found `{}`", values.expected, values.found) } } } diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr index 094bdbf486ce5..fb151648f2f9b 100644 --- a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr +++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr @@ -14,7 +14,7 @@ error[E0308]: mismatched types --> $DIR/cannot-infer-type-for-const-param.rs:10:22 | LL | let _ = Foo::<3>([1, 2, 3]); - | ^^^^^^^^^ expected `Const { ty: usize, val: Unevaluated(DefId(0:18 ~ cannot_infer_type_for_const_param[317d]::main[0]::{{constant}}[0]), []) }`, found `Const { ty: usize, val: Scalar(0x0000000000000003) }` + | ^^^^^^^^^ expected `3`, found `3usize` | = note: expected type `[u8; _]` found type `[u8; 3]` diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index 745d59040410b..ded8207cdef78 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:7:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000002) }`, found `Const { ty: usize, val: Scalar(0x0000000000000001) }` + | ^^^ expected `2usize`, found `1usize` | = note: expected type `[i32; 2]` found type `[i32; 1]` @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:8:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ^^^^^^^ expected `Const { ty: usize, val: Scalar(0x0000000000000001) }`, found `Const { ty: usize, val: Scalar(0x0000000000000002) }` + | ^^^^^^^ expected `1usize`, found `2usize` | = note: expected type `[i32; 1]` found type `[i32; 2]` From 854995313a029df89381449bb168bf61c88c546c Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 27 May 2019 14:05:29 +0100 Subject: [PATCH 25/31] Reintroduce `TypeError::FixedArraySize` --- src/librustc/ty/error.rs | 7 +++++++ src/librustc/ty/relate.rs | 18 ++++++++++++++++-- src/librustc/ty/structural_impls.rs | 2 ++ .../ui/consts/const-array-oob-arith.stderr | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 0a2a9472eaaf2..3d9e9cd690223 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -23,6 +23,7 @@ pub enum TypeError<'tcx> { AbiMismatch(ExpectedFound), Mutability, TupleSize(ExpectedFound), + FixedArraySize(ExpectedFound), ArgCount, RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>), @@ -99,6 +100,12 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { values.expected, values.found) } + FixedArraySize(values) => { + write!(f, "expected an array with a fixed size of {} elements, \ + found one with {} elements", + values.expected, + values.found) + } ArgCount => { write!(f, "incorrect number of function parameters") } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 55525d868e2fa..5a284e5439629 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -472,8 +472,22 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => { let t = relation.relate(&a_t, &b_t)?; - let sz = relation.relate(&sz_a, &sz_b)?; - Ok(tcx.mk_ty(ty::Array(t, sz))) + match relation.relate(&sz_a, &sz_b) { + Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))), + Err(err) => { + // Check whether the lengths are both `usize`s, + // but differ in value, for better diagnostics. + // FIXME(eddyb) get the right param_env. + match (sz_a.assert_usize(tcx), sz_b.assert_usize(tcx)) { + (Some(sz_a_val), Some(sz_b_val)) => { + Err(TypeError::FixedArraySize( + expected_found(relation, &sz_a_val, &sz_b_val) + )) + } + _ => return Err(err), + } + } + } } (&ty::Slice(a_t), &ty::Slice(b_t)) => diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index b0062f20e7f6e..0daa567052d56 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -716,6 +716,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { AbiMismatch(x) => AbiMismatch(x), Mutability => Mutability, TupleSize(x) => TupleSize(x), + FixedArraySize(x) => FixedArraySize(x), ArgCount => ArgCount, RegionsDoesNotOutlive(a, b) => { return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b)) @@ -1294,6 +1295,7 @@ EnumTypeFoldableImpl! { (ty::error::TypeError::AbiMismatch)(x), (ty::error::TypeError::Mutability), (ty::error::TypeError::TupleSize)(x), + (ty::error::TypeError::FixedArraySize)(x), (ty::error::TypeError::ArgCount), (ty::error::TypeError::RegionsDoesNotOutlive)(a, b), (ty::error::TypeError::RegionsInsufficientlyPolymorphic)(a, b), diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index ded8207cdef78..00286b0b0e0f8 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:7:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ^^^ expected `2usize`, found `1usize` + | ^^^ expected an array with a fixed size of 2 elements, found one with 1 elements | = note: expected type `[i32; 2]` found type `[i32; 1]` @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:8:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ^^^^^^^ expected `1usize`, found `2usize` + | ^^^^^^^ expected an array with a fixed size of 1 elements, found one with 2 elements | = note: expected type `[i32; 1]` found type `[i32; 2]` From 56181cf8abf8ad7f7d36e92ef4d7bf294df23c4c Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 27 May 2019 14:28:20 +0100 Subject: [PATCH 26/31] Correct pluralisation of tuple/array/associated type binding mismatch errors --- src/librustc/ty/error.rs | 25 +++++++++++++------ .../ui/consts/const-array-oob-arith.stderr | 4 +-- src/test/ui/tuple/tuple-arity-mismatch.rs | 2 +- src/test/ui/tuple/tuple-arity-mismatch.stderr | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 3d9e9cd690223..09426fe19e11e 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -80,6 +80,12 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { } }; + macro_rules! pluralise { + ($x:expr) => { + if $x != 1 { "s" } else { "" } + }; + } + match *self { CyclicTy(_) => write!(f, "cyclic type of infinite size"), Mismatch => write!(f, "types differ"), @@ -95,16 +101,20 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { } Mutability => write!(f, "types differ in mutability"), TupleSize(values) => { - write!(f, "expected a tuple with {} elements, \ - found one with {} elements", + write!(f, "expected a tuple with {} element{}, \ + found one with {} element{}", values.expected, - values.found) + pluralise!(values.expected), + values.found, + pluralise!(values.found)) } FixedArraySize(values) => { - write!(f, "expected an array with a fixed size of {} elements, \ - found one with {} elements", + write!(f, "expected an array with a fixed size of {} element{}, \ + found one with {} element{}", values.expected, - values.found) + pluralise!(values.expected), + values.found, + pluralise!(values.found)) } ArgCount => { write!(f, "incorrect number of function parameters") @@ -157,8 +167,9 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { tcx.def_path_str(values.found)) }), ProjectionBoundsLength(ref values) => { - write!(f, "expected {} associated type bindings, found {}", + write!(f, "expected {} associated type binding{}, found {}", values.expected, + pluralise!(values.expected), values.found) }, ExistentialMismatch(ref values) => { diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index 00286b0b0e0f8..77414fc7c928b 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:7:45 | LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; - | ^^^ expected an array with a fixed size of 2 elements, found one with 1 elements + | ^^^ expected an array with a fixed size of 2 elements, found one with 1 element | = note: expected type `[i32; 2]` found type `[i32; 1]` @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/const-array-oob-arith.rs:8:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; - | ^^^^^^^ expected an array with a fixed size of 1 elements, found one with 2 elements + | ^^^^^^^ expected an array with a fixed size of 1 element, found one with 2 elements | = note: expected type `[i32; 1]` found type `[i32; 2]` diff --git a/src/test/ui/tuple/tuple-arity-mismatch.rs b/src/test/ui/tuple/tuple-arity-mismatch.rs index 1c8b881d2469e..4f505c05a6a2c 100644 --- a/src/test/ui/tuple/tuple-arity-mismatch.rs +++ b/src/test/ui/tuple/tuple-arity-mismatch.rs @@ -13,5 +13,5 @@ fn main() { //~^ ERROR mismatched types //~| expected type `(isize, f64)` //~| found type `(isize,)` - //~| expected a tuple with 2 elements, found one with 1 elements + //~| expected a tuple with 2 elements, found one with 1 element } diff --git a/src/test/ui/tuple/tuple-arity-mismatch.stderr b/src/test/ui/tuple/tuple-arity-mismatch.stderr index 650f4c58c776c..6946a60c59af9 100644 --- a/src/test/ui/tuple/tuple-arity-mismatch.stderr +++ b/src/test/ui/tuple/tuple-arity-mismatch.stderr @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/tuple-arity-mismatch.rs:12:20 | LL | let y = first ((1,)); - | ^^^^ expected a tuple with 2 elements, found one with 1 elements + | ^^^^ expected a tuple with 2 elements, found one with 1 element | = note: expected type `(isize, f64)` found type `(isize,)` From b3a13fdd13e11e11410e42a53f48c7d675f9963f Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 27 May 2019 14:30:16 +0100 Subject: [PATCH 27/31] Make sure array length diagnostic doesn't regress --- src/test/ui/consts/const-array-oob-arith.rs | 8 ++++++-- src/test/ui/consts/const-array-oob-arith.stderr | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/const-array-oob-arith.rs b/src/test/ui/consts/const-array-oob-arith.rs index 2f9b30b51d10a..2f5661e32a90e 100644 --- a/src/test/ui/consts/const-array-oob-arith.rs +++ b/src/test/ui/consts/const-array-oob-arith.rs @@ -4,8 +4,12 @@ const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47]; const IDX: usize = 3; const VAL: i32 = ARR[IDX]; const BONG: [i32; (ARR[0] - 41) as usize] = [5]; -const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; //~ ERROR: mismatched types -const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; //~ ERROR: mismatched types +const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; +//~^ ERROR: mismatched types +//~| expected an array with a fixed size of 2 elements, found one with 1 element +const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; +//~^ ERROR: mismatched types +//~| expected an array with a fixed size of 1 element, found one with 2 elements fn main() { let _ = VAL; diff --git a/src/test/ui/consts/const-array-oob-arith.stderr b/src/test/ui/consts/const-array-oob-arith.stderr index 77414fc7c928b..987e7ddf4d91e 100644 --- a/src/test/ui/consts/const-array-oob-arith.stderr +++ b/src/test/ui/consts/const-array-oob-arith.stderr @@ -8,7 +8,7 @@ LL | const BLUB: [i32; (ARR[0] - 40) as usize] = [5]; found type `[i32; 1]` error[E0308]: mismatched types - --> $DIR/const-array-oob-arith.rs:8:44 + --> $DIR/const-array-oob-arith.rs:10:44 | LL | const BOO: [i32; (ARR[0] - 41) as usize] = [5, 99]; | ^^^^^^^ expected an array with a fixed size of 1 element, found one with 2 elements From 294916065a0692aa6b0c2c9e009da887cf897038 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 28 May 2019 20:25:21 +0100 Subject: [PATCH 28/31] Fix nits --- src/librustc/infer/resolve.rs | 4 ++-- src/librustc/ty/relate.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index 98f63c803ca03..95bae8f2bd1af 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -4,9 +4,9 @@ use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags}; use crate::ty::fold::{TypeFolder, TypeVisitor}; /////////////////////////////////////////////////////////////////////////// -// OPPORTUNISTIC KIND RESOLVER +// OPPORTUNISTIC VAR RESOLVER -/// The opportunistic kind resolver can be used at any time. It simply replaces +/// The opportunistic resolver can be used at any time. It simply replaces /// type/const variables that have been unified with the things they have /// been unified with (similar to `shallow_resolve`, but deep). This is /// useful for printing messages etc but also required at various diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 5a284e5439629..0440be13a7271 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -475,9 +475,8 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R, match relation.relate(&sz_a, &sz_b) { Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))), Err(err) => { - // Check whether the lengths are both `usize`s, - // but differ in value, for better diagnostics. - // FIXME(eddyb) get the right param_env. + // Check whether the lengths are both concrete/known values, + // but are unequal, for better diagnostics. match (sz_a.assert_usize(tcx), sz_b.assert_usize(tcx)) { (Some(sz_a_val), Some(sz_b_val)) => { Err(TypeError::FixedArraySize( From 6233d1fee5df70258b02bb549967bc9319014081 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 28 May 2019 21:34:18 +0100 Subject: [PATCH 29/31] Use assert_eq! instead of println! in tests --- .../ui/const-generics/uninferred-consts-during-codegen-1.rs | 2 +- .../ui/const-generics/uninferred-consts-during-codegen-2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs index 2e555d11ababc..1e064fbd97064 100644 --- a/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-1.rs @@ -14,5 +14,5 @@ impl fmt::Debug for Array { } fn main() { - println!("{:?}", Array([1, 2, 3])); + assert_eq!(format!("{:?}", Array([1, 2, 3])), "[1, 2, 3]"); } diff --git a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs index 7a1a4f49794d9..0cf505906f626 100644 --- a/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs +++ b/src/test/ui/const-generics/uninferred-consts-during-codegen-2.rs @@ -14,5 +14,5 @@ impl fmt::Debug for Array<[T; N]> { } fn main() { - println!("{:?}", Array([1, 2, 3])); + assert_eq!(format!("{:?}", Array([1, 2, 3])), "[1, 2, 3]"); } From 3e5beb2c6f168b29f4a86c0d2a3e1c5e717d9389 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 29 May 2019 00:26:56 +0300 Subject: [PATCH 30/31] rustc: rename Mir to mir::Body in comments and to MIR in error strings. --- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc/mir/visit.rs | 2 +- src/librustc/query/mod.rs | 2 +- src/librustc/ty/steal.rs | 6 +++--- src/librustc_mir/build/mod.rs | 4 ++-- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/transform/mod.rs | 4 ++-- src/librustc_mir/transform/promote_consts.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 595ea8bd34687..902dc59e67f09 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -47,7 +47,7 @@ pub struct GlobalId<'tcx> { /// For a promoted global, the `Instance` of the function they belong to. pub instance: ty::Instance<'tcx>, - /// The index for promoted globals within their function's `Mir`. + /// The index for promoted globals within their function's `mir::Body`. pub promoted: Option, } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 01c815fba9f3c..dd33fae0d6197 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -261,7 +261,7 @@ macro_rules! make_mir_visitor { } // for best performance, we want to use an iterator rather - // than a for-loop, to avoid calling Mir::invalidate for + // than a for-loop, to avoid calling `mir::Body::invalidate` for // each basic block. macro_rules! basic_blocks { (mut) => (mir.basic_blocks_mut().iter_enumerated_mut()); diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 39d91d66a438f..81aa8d434d37f 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -88,7 +88,7 @@ rustc_queries! { desc { "getting a list of all mir_keys" } } - /// Maps DefId's that have an associated Mir to the result + /// Maps DefId's that have an associated `mir::Body` to the result /// of the MIR qualify_consts pass. The actual meaning of /// the value isn't known except to the pass itself. query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet) { diff --git a/src/librustc/ty/steal.rs b/src/librustc/ty/steal.rs index a5a0b198734c1..711e59dbcc9d2 100644 --- a/src/librustc/ty/steal.rs +++ b/src/librustc/ty/steal.rs @@ -7,9 +7,9 @@ use rustc_data_structures::sync::{RwLock, ReadGuard, MappedReadGuard}; /// optimization, but that'd be expensive. And yet we don't just want /// to mutate it in place, because that would spoil the idea that /// queries are these pure functions that produce an immutable value -/// (since if you did the query twice, you could observe the -/// mutations). So instead we have the query produce a `&'tcx -/// Steal>` (to be very specific). Now we can read from this +/// (since if you did the query twice, you could observe the mutations). +/// So instead we have the query produce a `&'tcx Steal>` +/// (to be very specific). Now we can read from this /// as much as we want (using `borrow()`), but you can also /// `steal()`. Once you steal, any further attempt to read will panic. /// Therefore, we know that -- assuming no ICE -- nobody is observing diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 5d79ef6a4bbc9..5797f9c347866 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -164,7 +164,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<' build::construct_const(cx, body_id, return_ty, return_ty_span) }; - // Convert the Mir to global types. + // Convert the `mir::Body` to global types. let mut globalizer = GlobalizeMir { tcx, span: mir.span @@ -243,7 +243,7 @@ fn create_constructor_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx.infer_ctxt().enter(|infcx| { let mut mir = shim::build_adt_ctor(&infcx, ctor_id, fields, span); - // Convert the Mir to global types. + // Convert the `mir::Body` to global types. let tcx = infcx.tcx.global_tcx(); let mut globalizer = GlobalizeMir { tcx, diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 9798d7e8a16dd..80f64e85f9cf9 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -44,7 +44,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { /// Whether this constant/function needs overflow checks. check_overflow: bool, - /// See field with the same name on `Mir`. + /// See field with the same name on `mir::Body`. control_flow_destroyed: Vec<(Span, String)>, } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 3fd4e6044af74..22b96a9db4750 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -100,7 +100,7 @@ fn mir_built<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea tcx.alloc_steal_mir(mir) } -/// Where a specific Mir comes from. +/// Where a specific `mir::Body` comes from. #[derive(Debug, Copy, Clone)] pub struct MirSource<'tcx> { pub instance: InstanceDef<'tcx>, @@ -228,7 +228,7 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx } fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Body<'tcx> { - // (Mir-)Borrowck uses `mir_validated`, so we have to force it to + // `mir_borrowck` uses `mir_validated`, so we have to force it to // execute before we can steal. tcx.ensure().mir_borrowck(def_id); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 24f810cceaf86..4b95fbf4b7d2f 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -393,7 +393,7 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Body<'tcx>, } - // Declare return place local so that `Body::new` doesn't complain. + // Declare return place local so that `mir::Body::new` doesn't complain. let initial_locals = iter::once( LocalDecl::new_return_place(tcx.types.never, mir.span) ).collect(); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 862c863500c80..a416792101f73 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1431,7 +1431,7 @@ fn mir_const_qualif<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mir = &tcx.mir_const(def_id).borrow(); if mir.return_ty().references_error() { - tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: Mir had errors"); + tcx.sess.delay_span_bug(mir.span, "mir_const_qualif: MIR had errors"); return (1 << IsNotPromotable::IDX, tcx.arena.alloc(BitSet::new_empty(0))); } @@ -1447,7 +1447,7 @@ impl MirPass for QualifyAndPromoteConstants { mir: &mut Body<'tcx>) { // There's not really any point in promoting errorful MIR. if mir.return_ty().references_error() { - tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: Mir had errors"); + tcx.sess.delay_span_bug(mir.span, "QualifyAndPromoteConstants: MIR had errors"); return; } From 95013e612d3ffaee2b674da4a29308aaa7551726 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 29 May 2019 00:27:42 +0300 Subject: [PATCH 31/31] syntax: bail out of `find_width_of_character_at_span` if the span doesn't start and end in the same file. --- src/libsyntax/source_map.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index 8a210db91858e..e2171a84e2300 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -727,6 +727,11 @@ impl SourceMap { debug!("find_width_of_character_at_span: local_begin=`{:?}`, local_end=`{:?}`", local_begin, local_end); + if local_begin.sf.start_pos != local_end.sf.start_pos { + debug!("find_width_of_character_at_span: begin and end are in different files"); + return 1; + } + let start_index = local_begin.pos.to_usize(); let end_index = local_end.pos.to_usize(); debug!("find_width_of_character_at_span: start_index=`{:?}`, end_index=`{:?}`",