diff options
| author | bors <bors@rust-lang.org> | 2018-04-13 01:43:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-04-13 01:43:09 +0000 |
| commit | defcfe7142fca424f7e34aa5c789239e9e9fcfe8 (patch) | |
| tree | 8b6e479ea80191563607ff243cd46699c53ce56e /src/test/compile-fail | |
| parent | c4a03283cd17c86c9bcdc3fdc76d924ab5eaff2a (diff) | |
| parent | fcf48520a0d63828190217ea59849f9098177427 (diff) | |
| download | rust-defcfe7142fca424f7e34aa5c789239e9e9fcfe8.tar.gz rust-defcfe7142fca424f7e34aa5c789239e9e9fcfe8.zip | |
Auto merge of #49718 - petrochenkov:fieldcmp, r=eddyb
Hygiene 2.0: Avoid comparing fields by name
There are two separate commits here (not counting tests):
- The first one unifies named (`obj.name`) and numeric (`obj.0`) field access expressions in AST and HIR. Before field references in these expressions are resolved it doesn't matter whether the field is named or numeric (it's just a symbol) and 99% of code is common. After field references are resolved we work with
them by index for all fields (see the second commit), so it's again not important whether the field was named or numeric (this includes MIR where all fields were already by index).
(This refactoring actually fixed some bugs in HIR-based borrow checker where borrows through names (`S {
0: ref x }`) and indices (`&s.0`) weren't considered overlapping.)
- The second commit removes all by-name field comparison and instead resolves field references to their indices once, and then uses those resolutions. (There are still a few name comparisons in save-analysis, because save-analysis is weird, but they are made correctly hygienic).
Thus we are fixing a bunch of "secondary" field hygiene bugs (in borrow checker, lints).
Fixes https://github.com/rust-lang/rust/issues/46314
Diffstat (limited to 'src/test/compile-fail')
17 files changed, 5 insertions, 447 deletions
diff --git a/src/test/compile-fail/borrowck/borrowck-uninit-field-access.rs b/src/test/compile-fail/borrowck/borrowck-uninit-field-access.rs index a214e3c126e..eec7df84c82 100644 --- a/src/test/compile-fail/borrowck/borrowck-uninit-field-access.rs +++ b/src/test/compile-fail/borrowck/borrowck-uninit-field-access.rs @@ -36,7 +36,7 @@ fn main() { let mut line1 = Line::default(); let _moved = line1.origin; - let _ = line1.origin.x + 1; //[ast]~ ERROR use of collaterally moved value: `line1.origin.x` + let _ = line1.origin.x + 1; //[ast]~ ERROR use of moved value: `line1.origin.x` //[mir]~^ [E0382] let mut line2 = Line::default(); diff --git a/src/test/compile-fail/for-loop-hygiene.rs b/src/test/compile-fail/for-loop-hygiene.rs deleted file mode 100644 index d9386421970..00000000000 --- a/src/test/compile-fail/for-loop-hygiene.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// for-loops are expanded in the front end, and use an `iter` ident in their expansion. Check that -// `iter` is not accessible inside the for loop. - -fn main() { - for _ in 0..10 { - iter.next(); //~ ERROR cannot find value `iter` in this scope - } -} diff --git a/src/test/compile-fail/hygiene/assoc_item_ctxt.rs b/src/test/compile-fail/hygiene/assoc_item_ctxt.rs deleted file mode 100644 index e336b0df13f..00000000000 --- a/src/test/compile-fail/hygiene/assoc_item_ctxt.rs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-pretty pretty-printing is unhygienic - -#![feature(decl_macro)] -#![allow(unused)] - -mod ok { - macro mac_trait_item($method: ident) { - fn $method(); - } - - trait Tr { - mac_trait_item!(method); - } - - macro mac_trait_impl() { - impl Tr for u8 { // OK - fn method() {} // OK - } - } - - mac_trait_impl!(); -} - -mod error { - macro mac_trait_item() { - fn method(); - } - - trait Tr { - mac_trait_item!(); - } - - macro mac_trait_impl() { - impl Tr for u8 { //~ ERROR not all trait items implemented, missing: `method` - fn method() {} //~ ERROR method `method` is not a member of trait `Tr` - } - } - - mac_trait_impl!(); -} - -fn main() {} diff --git a/src/test/compile-fail/hygiene/assoc_ty_bindings.rs b/src/test/compile-fail/hygiene/assoc_ty_bindings.rs deleted file mode 100644 index 46a138749ff..00000000000 --- a/src/test/compile-fail/hygiene/assoc_ty_bindings.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-pretty pretty-printing is unhygienic - -#![feature(decl_macro, associated_type_defaults)] -#![feature(rustc_attrs)] - -trait Base { - type AssocTy; - fn f(); -} -trait Derived: Base { - fn g(); -} - -macro mac() { - type A = Base<AssocTy = u8>; - type B = Derived<AssocTy = u8>; - - impl Base for u8 { - type AssocTy = u8; - fn f() { - let _: Self::AssocTy; - } - } - impl Derived for u8 { - fn g() { - let _: Self::AssocTy; - } - } - - fn h<T: Base, U: Derived>() { - let _: T::AssocTy; - let _: U::AssocTy; - } -} - -mac!(); - -#[rustc_error] -fn main() {} //~ ERROR compilation successful diff --git a/src/test/compile-fail/hygiene/auxiliary/intercrate.rs b/src/test/compile-fail/hygiene/auxiliary/intercrate.rs deleted file mode 100644 index aa67e5c5f4d..00000000000 --- a/src/test/compile-fail/hygiene/auxiliary/intercrate.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -pub mod foo { - pub use self::bar::m; - mod bar { - fn f() -> u32 { 1 } - pub macro m() { - f(); - } - } -} diff --git a/src/test/compile-fail/hygiene/fields.rs b/src/test/compile-fail/hygiene/fields.rs deleted file mode 100644 index 64217770b13..00000000000 --- a/src/test/compile-fail/hygiene/fields.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-pretty pretty-printing is unhygienic - -#![feature(decl_macro)] - -mod foo { - struct S { x: u32 } - struct T(u32); - - pub macro m($S:ident, $x:ident) {{ - struct $S { - $x: u32, - x: i32, - } - - let s = S { x: 0 }; //~ ERROR type `foo::S` is private - let _ = s.x; //~ ERROR type `foo::S` is private - - let t = T(0); //~ ERROR type `foo::T` is private - let _ = t.0; //~ ERROR type `foo::T` is private - - let s = $S { $x: 0, x: 1 }; - assert_eq!((s.$x, s.x), (0, 1)); - s - }} -} - -fn main() { - let s = foo::m!(S, x); - assert_eq!(s.x, 0); -} diff --git a/src/test/compile-fail/hygiene/globs.rs b/src/test/compile-fail/hygiene/globs.rs deleted file mode 100644 index 7ba217061c6..00000000000 --- a/src/test/compile-fail/hygiene/globs.rs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -mod foo { - pub fn f() {} -} - -mod bar { - pub fn g() {} -} - -macro m($($t:tt)*) { - $($t)* - use foo::*; - f(); - g(); //~ ERROR cannot find function `g` in this scope -} - -fn main() { - m! { - use bar::*; - g(); - f(); //~ ERROR cannot find function `f` in this scope - } -} - -n!(f); -macro n($i:ident) { - mod foo { - pub fn $i() -> u32 { 0 } - pub fn f() {} - - mod test { - use super::*; - fn g() { - let _: u32 = $i(); - let _: () = f(); - } - } - - macro n($j:ident) { - mod test { - use super::*; - fn g() { - let _: u32 = $i(); - let _: () = f(); - $j(); - } - } - } - - n!(f); - mod test2 { - super::n! { - f //~ ERROR cannot find function `f` in this scope - } - } - } -} diff --git a/src/test/compile-fail/hygiene/impl_items.rs b/src/test/compile-fail/hygiene/impl_items.rs deleted file mode 100644 index cdba559445d..00000000000 --- a/src/test/compile-fail/hygiene/impl_items.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-pretty pretty-printing is unhygienic - -#![feature(decl_macro)] - -mod foo { - struct S; - impl S { - fn f(&self) {} - } - - pub macro m() { - let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {foo::S::f}` is private - } -} - -struct S; - -macro m($f:ident) { - impl S { - fn f(&self) -> u32 { 0 } - fn $f(&self) -> i32 { 0 } - } - fn f() { - let _: u32 = S.f(); - let _: i32 = S.$f(); - } -} - -m!(f); - -fn main() { - let _: i32 = S.f(); - foo::m!(); -} diff --git a/src/test/compile-fail/hygiene/intercrate.rs b/src/test/compile-fail/hygiene/intercrate.rs deleted file mode 100644 index 50fc985ba34..00000000000 --- a/src/test/compile-fail/hygiene/intercrate.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// ignore-pretty pretty-printing is unhygienic - -// aux-build:intercrate.rs - -// error-pattern:type `fn() -> u32 {intercrate::foo::bar::f}` is private - -#![feature(decl_macro)] - -extern crate intercrate; - -fn main() { - assert_eq!(intercrate::foo::m!(), 1); -} diff --git a/src/test/compile-fail/hygiene/nested_macro_privacy.rs b/src/test/compile-fail/hygiene/nested_macro_privacy.rs deleted file mode 100644 index 6612359649c..00000000000 --- a/src/test/compile-fail/hygiene/nested_macro_privacy.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -macro n($foo:ident, $S:ident, $i:ident, $m:ident) { - mod $foo { - #[derive(Default)] - pub struct $S { $i: u32 } - pub macro $m($e:expr) { $e.$i } - } -} - -n!(foo, S, i, m); - -fn main() { - use foo::{S, m}; - S::default().i; //~ ERROR field `i` of struct `foo::S` is private - m!(S::default()); // ok -} diff --git a/src/test/compile-fail/hygiene/no_implicit_prelude.rs b/src/test/compile-fail/hygiene/no_implicit_prelude.rs deleted file mode 100644 index c90c7b3093c..00000000000 --- a/src/test/compile-fail/hygiene/no_implicit_prelude.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -mod foo { - pub macro m() { Vec::new(); ().clone() } - fn f() { ::bar::m!(); } -} - -#[no_implicit_prelude] -mod bar { - pub macro m() { - Vec::new(); //~ ERROR failed to resolve - ().clone() //~ ERROR no method named `clone` found - } - fn f() { ::foo::m!(); } -} diff --git a/src/test/compile-fail/hygiene/privacy.rs b/src/test/compile-fail/hygiene/privacy.rs deleted file mode 100644 index 987cad187d4..00000000000 --- a/src/test/compile-fail/hygiene/privacy.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -mod foo { - fn f() {} - - pub macro m($e:expr) { - f(); - self::f(); - ::foo::f(); - $e - } -} - -fn main() { - foo::m!( - foo::f() //~ ERROR `f` is private - ); -} diff --git a/src/test/compile-fail/hygiene/trait_items.rs b/src/test/compile-fail/hygiene/trait_items.rs deleted file mode 100644 index 3bd19cbc0ac..00000000000 --- a/src/test/compile-fail/hygiene/trait_items.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(decl_macro)] - -mod foo { - pub trait T { - fn f(&self) {} - } - impl T for () {} -} - -mod bar { - use foo::*; - pub macro m() { ().f() } - fn f() { ::baz::m!(); } -} - -mod baz { - pub macro m() { ().f() } //~ ERROR no method named `f` found for type `()` in the current scope - fn f() { ::bar::m!(); } -} - -fn main() {} diff --git a/src/test/compile-fail/issue-19244-1.rs b/src/test/compile-fail/issue-19244-1.rs index 0fa1a154772..df34aab4b8f 100644 --- a/src/test/compile-fail/issue-19244-1.rs +++ b/src/test/compile-fail/issue-19244-1.rs @@ -12,5 +12,5 @@ const TUP: (usize,) = (42,); fn main() { let a: [isize; TUP.1]; - //~^ ERROR attempted out-of-bounds tuple index + //~^ ERROR no field `1` on type `(usize,)` } diff --git a/src/test/compile-fail/pattern-macro-hygiene.rs b/src/test/compile-fail/pattern-macro-hygiene.rs deleted file mode 100644 index 26d411c9154..00000000000 --- a/src/test/compile-fail/pattern-macro-hygiene.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -macro_rules! foo { () => ( x ) } - -fn main() { - let foo!() = 2; - x + 1; //~ ERROR cannot find value `x` in this scope -} diff --git a/src/test/compile-fail/struct-field-privacy.rs b/src/test/compile-fail/struct-field-privacy.rs index 5b2e04e25a9..f487ef62aa4 100644 --- a/src/test/compile-fail/struct-field-privacy.rs +++ b/src/test/compile-fail/struct-field-privacy.rs @@ -42,7 +42,7 @@ fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B, z: inner::Z) { e.b; //~ ERROR: field `b` of struct `xc::B` is private z.0; - z.1; //~ ERROR: field `1` of tuple-struct `inner::Z` is private + z.1; //~ ERROR: field `1` of struct `inner::Z` is private } fn main() {} diff --git a/src/test/compile-fail/tuple-index-out-of-bounds.rs b/src/test/compile-fail/tuple-index-out-of-bounds.rs index 4597cf3d350..35b843676b4 100644 --- a/src/test/compile-fail/tuple-index-out-of-bounds.rs +++ b/src/test/compile-fail/tuple-index-out-of-bounds.rs @@ -15,10 +15,10 @@ fn main() { origin.0; origin.1; origin.2; - //~^ ERROR attempted out-of-bounds tuple index `2` on type `Point` + //~^ ERROR no field `2` on type `Point` let tuple = (0, 0); tuple.0; tuple.1; tuple.2; - //~^ ERROR attempted out-of-bounds tuple index `2` on type `({integer}, {integer})` + //~^ ERROR no field `2` on type `({integer}, {integer})` } |
