diff --git a/src/doc/book/casting-between-types.md b/src/doc/book/casting-between-types.md index 7056a6c0f1708..a101f397c3793 100644 --- a/src/doc/book/casting-between-types.md +++ b/src/doc/book/casting-between-types.md @@ -135,14 +135,14 @@ cast four bytes into a `u32`: ```rust,ignore let a = [0u8, 0u8, 0u8, 0u8]; -let b = a as u32; // four eights makes 32 +let b = a as u32; // four u8s makes a u32 ``` This errors with: ```text error: non-scalar cast: `[u8; 4]` as `u32` -let b = a as u32; // four eights makes 32 +let b = a as u32; // four u8s makes a u32 ^~~~~~~~ ``` diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index ad90b44750854..a40608b0762d6 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -86,7 +86,7 @@ macro_rules! assert { #[stable(feature = "rust1", since = "1.0.0")] macro_rules! assert_eq { ($left:expr , $right:expr) => ({ - match (&($left), &($right)) { + match (&$left, &$right) { (left_val, right_val) => { if !(*left_val == *right_val) { panic!("assertion failed: `(left == right)` \ diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 52ba8d9a631d8..1bdab88d71da0 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -26,8 +26,9 @@ //! [1]: http://llvm.org/docs/LangRef.html#memory-model-for-concurrent-operations //! //! Atomic variables are safe to share between threads (they implement `Sync`) -//! but they do not themselves provide the mechanism for sharing. The most -//! common way to share an atomic variable is to put it into an `Arc` (an +//! but they do not themselves provide the mechanism for sharing and follow the +//! [threading model](../../../std/thread/index.html#the-threading-model) of rust. +//! The most common way to share an atomic variable is to put it into an `Arc` (an //! atomically-reference-counted shared pointer). //! //! Most atomic types may be stored in static variables, initialized using @@ -48,12 +49,16 @@ //! let spinlock = Arc::new(AtomicUsize::new(1)); //! //! let spinlock_clone = spinlock.clone(); -//! thread::spawn(move|| { +//! let thread = thread::spawn(move|| { //! spinlock_clone.store(0, Ordering::SeqCst); //! }); //! //! // Wait for the other thread to release the lock //! while spinlock.load(Ordering::SeqCst) != 0 {} +//! +//! if let Err(panic) = thread.join() { +//! println!("Thread had an error: {:?}", panic); +//! } //! } //! ``` //! diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index ba655b35eda15..28506fd20fe53 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1286,8 +1286,12 @@ impl<'a> LoweringContext<'a> { maybe_expr.as_ref().map(|x| self.lower_expr(x))) } ExprKind::Paren(ref ex) => { - // merge attributes into the inner expression. return self.lower_expr(ex).map(|mut ex| { + // include parens in span, but only if it is a super-span. + if e.span.contains(ex.span) { + ex.span = e.span; + } + // merge attributes into the inner expression. ex.attrs.update(|attrs| { attrs.prepend(e.attrs.clone()) }); diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 5ebb1ab32b8f8..c1e83588570e7 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -152,7 +152,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, ty::TyEnum(def, _) if def.has_dtor() => { let mut err = struct_span_err!(bccx, move_from.span, E0509, "cannot move out of type `{}`, \ - which defines the `Drop` trait", + which implements the `Drop` trait", b.ty); err.span_label(move_from.span, &format!("cannot move out of here")); err diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index d68998927da9f..992e07fa7449d 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -617,7 +617,13 @@ pub fn coerce_unsized_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, (&ty::TyRawPtr(..), &ty::TyRawPtr(..)) => { let (base, info) = if common::type_is_fat_ptr(bcx.tcx(), src_ty) { // fat-ptr to fat-ptr unsize preserves the vtable - load_fat_ptr(bcx, src, src_ty) + // i.e. &'a fmt::Debug+Send => &'a fmt::Debug + // So we need to pointercast the base to ensure + // the types match up. + let (base, info) = load_fat_ptr(bcx, src, src_ty); + let llcast_ty = type_of::fat_ptr_base_ty(bcx.ccx(), dst_ty); + let base = PointerCast(bcx, base, llcast_ty); + (base, info) } else { let base = load_ty(bcx, src, src_ty); unsize_thin_ptr(bcx, base, src_ty, dst_ty) diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index bcbf3e1fa1836..5945e8813a48d 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -262,14 +262,17 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { assert!(common::type_is_fat_ptr(bcx.tcx(), cast_ty)); match operand.val { - OperandValue::FatPtr(..) => { + OperandValue::FatPtr(lldata, llextra) => { // unsize from a fat pointer - this is a // "trait-object-to-supertrait" coercion, for // example, // &'a fmt::Debug+Send => &'a fmt::Debug, - // and is a no-op at the LLVM level + // So we need to pointercast the base to ensure + // the types match up. self.set_operand_dropped(&bcx, source); - operand.val + let llcast_ty = type_of::fat_ptr_base_ty(bcx.ccx(), cast_ty); + let lldata = bcx.pointercast(lldata, llcast_ty); + OperandValue::FatPtr(lldata, llextra) } OperandValue::Immediate(lldata) => { // "standard" unsize diff --git a/src/librustc_trans/type_of.rs b/src/librustc_trans/type_of.rs index 98ec87ebbcf6f..e5acb9b6699bd 100644 --- a/src/librustc_trans/type_of.rs +++ b/src/librustc_trans/type_of.rs @@ -157,6 +157,17 @@ pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Typ llsizingty } +pub fn fat_ptr_base_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Type { + match ty.sty { + ty::TyBox(t) | + ty::TyRef(_, ty::TypeAndMut { ty: t, .. }) | + ty::TyRawPtr(ty::TypeAndMut { ty: t, .. }) if !type_is_sized(ccx.tcx(), t) => { + in_memory_type_of(ccx, t).ptr_to() + } + _ => bug!("expected fat ptr ty but got {:?}", ty) + } +} + fn unsized_info_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Type { let unsized_part = ccx.tcx().struct_tail(ty); match unsized_part.sty { diff --git a/src/test/compile-fail/E0036.rs b/src/test/compile-fail/E0036.rs new file mode 100644 index 0000000000000..35fd6e8942fe7 --- /dev/null +++ b/src/test/compile-fail/E0036.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Test; + +impl Test { + fn method(&self, v: &[T]) -> usize { + v.len() + } +} + +fn main() { + let x = Test; + let v = &[0]; + x.method::(v); //~ ERROR E0036 +} diff --git a/src/test/compile-fail/E0038.rs b/src/test/compile-fail/E0038.rs new file mode 100644 index 0000000000000..26d2f339763aa --- /dev/null +++ b/src/test/compile-fail/E0038.rs @@ -0,0 +1,20 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Trait { + fn foo(&self) -> Self; +} + +fn call_foo(x: Box) { //~ ERROR E0038 + let y = x.foo(); +} + +fn main() { +} diff --git a/src/test/compile-fail/E0040.rs b/src/test/compile-fail/E0040.rs new file mode 100644 index 0000000000000..f998778a50d66 --- /dev/null +++ b/src/test/compile-fail/E0040.rs @@ -0,0 +1,24 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo { + x: i32, +} + +impl Drop for Foo { + fn drop(&mut self) { + println!("kaboom"); + } +} + +fn main() { + let mut x = Foo { x: -7 }; + x.drop(); //~ ERROR E0040 +} diff --git a/src/test/compile-fail/E0044.rs b/src/test/compile-fail/E0044.rs new file mode 100644 index 0000000000000..48fe230003129 --- /dev/null +++ b/src/test/compile-fail/E0044.rs @@ -0,0 +1,14 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { fn some_func(x: T); } //~ ERROR E0044 + +fn main() { +} diff --git a/src/test/compile-fail/E0045.rs b/src/test/compile-fail/E0045.rs new file mode 100644 index 0000000000000..edec911d3c070 --- /dev/null +++ b/src/test/compile-fail/E0045.rs @@ -0,0 +1,14 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern "rust-call" { fn foo(x: u8, ...); } //~ ERROR E0045 + +fn main() { +} diff --git a/src/test/compile-fail/E0046.rs b/src/test/compile-fail/E0046.rs new file mode 100644 index 0000000000000..63bd0a5ca2858 --- /dev/null +++ b/src/test/compile-fail/E0046.rs @@ -0,0 +1,20 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(); +} + +struct Bar; + +impl Foo for Bar {} //~ ERROR E0046 + +fn main() { +} diff --git a/src/test/compile-fail/E0049.rs b/src/test/compile-fail/E0049.rs new file mode 100644 index 0000000000000..5867e11e9acc6 --- /dev/null +++ b/src/test/compile-fail/E0049.rs @@ -0,0 +1,22 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(x: T) -> Self; +} + +struct Bar; + +impl Foo for Bar { + fn foo(x: bool) -> Self { Bar } //~ ERROR E0049 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0050.rs b/src/test/compile-fail/E0050.rs new file mode 100644 index 0000000000000..2f7dc96361f9c --- /dev/null +++ b/src/test/compile-fail/E0050.rs @@ -0,0 +1,22 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(&self, x: u8) -> bool; +} + +struct Bar; + +impl Foo for Bar { + fn foo(&self) -> bool { true } //~ ERROR E0050 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0053.rs b/src/test/compile-fail/E0053.rs new file mode 100644 index 0000000000000..4effda3c49e8e --- /dev/null +++ b/src/test/compile-fail/E0053.rs @@ -0,0 +1,24 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(x: u16); + fn bar(&self); +} + +struct Bar; + +impl Foo for Bar { + fn foo(x: i16) { } //~ ERROR E0053 + fn bar(&mut self) { } //~ ERROR E0053 +} + +fn main() { +} diff --git a/src/test/compile-fail/E0054.rs b/src/test/compile-fail/E0054.rs new file mode 100644 index 0000000000000..158cd6ff9bbc4 --- /dev/null +++ b/src/test/compile-fail/E0054.rs @@ -0,0 +1,14 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = 5; + let x_is_nonzero = x as bool; //~ ERROR E0054 +} diff --git a/src/test/compile-fail/E0055.rs b/src/test/compile-fail/E0055.rs new file mode 100644 index 0000000000000..cb78f4b3bb597 --- /dev/null +++ b/src/test/compile-fail/E0055.rs @@ -0,0 +1,23 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![recursion_limit="2"] +struct Foo; + +impl Foo { + fn foo(&self) {} +} + +fn main() { + let foo = Foo; + let ref_foo = &&Foo; + ref_foo.foo(); //~ ERROR E0055 + //~^ ERROR E0275 +} diff --git a/src/test/compile-fail/E0057.rs b/src/test/compile-fail/E0057.rs new file mode 100644 index 0000000000000..1fb5498b099c9 --- /dev/null +++ b/src/test/compile-fail/E0057.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let f = |x| x * 3; + let a = f(); //~ ERROR E0057 + let b = f(4); + let c = f(2, 3); //~ ERROR E0057 +} diff --git a/src/test/compile-fail/E0059.rs b/src/test/compile-fail/E0059.rs new file mode 100644 index 0000000000000..4ae9b2f91d25f --- /dev/null +++ b/src/test/compile-fail/E0059.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unboxed_closures)] + +fn foo>(f: F) -> F::Output { f(3) } //~ ERROR E0059 + +fn main() { +} diff --git a/src/test/compile-fail/E0060.rs b/src/test/compile-fail/E0060.rs new file mode 100644 index 0000000000000..b4a2898749792 --- /dev/null +++ b/src/test/compile-fail/E0060.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern "C" { + fn printf(_: *const u8, ...) -> u32; +} + +fn main() { + unsafe { printf(); } //~ ERROR E0060 +} diff --git a/src/test/compile-fail/E0061.rs b/src/test/compile-fail/E0061.rs new file mode 100644 index 0000000000000..4a8eac2a9e226 --- /dev/null +++ b/src/test/compile-fail/E0061.rs @@ -0,0 +1,15 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn f(a: u16, b: &str) {} + +fn main() { + f(0); //~ ERROR E0061 +} diff --git a/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs index 438a548819bc7..5d9c9d0bd4615 100644 --- a/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs +++ b/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs @@ -37,7 +37,7 @@ impl Drop for S { fn move_in_match() { match (S {f: "foo".to_string(), g: "bar".to_string()}) { - S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait + S { //~ ERROR cannot move out of type `S`, which implements the `Drop` trait //~| cannot move out of here f: _s, //~ NOTE to prevent move g: _t //~ NOTE and here diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs index 3d13cbe30c5a2..16302d276cee2 100644 --- a/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-struct-with-dtor.rs @@ -16,17 +16,17 @@ impl Drop for S { fn move_in_match() { match (S {f:"foo".to_string()}) { S {f:_s} => {} - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } } fn move_in_let() { let S {f:_s} = S {f:"foo".to_string()}; - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } fn move_in_fn_arg(S {f:_s}: S) { - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } fn main() {} diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs index 625f71849057b..f5fedb8d487ee 100644 --- a/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-tuple-struct-with-dtor.rs @@ -16,17 +16,17 @@ impl Drop for S { fn move_in_match() { match S("foo".to_string()) { S(_s) => {} - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } } fn move_in_let() { let S(_s) = S("foo".to_string()); - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } fn move_in_fn_arg(S(_s): S) { - //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `S`, which implements the `Drop` trait } fn main() {} diff --git a/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs index bf1497420e2a7..c364788a9cc8d 100644 --- a/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs +++ b/src/test/compile-fail/borrowck/borrowck-struct-update-with-dtor.rs @@ -19,11 +19,13 @@ struct T { a: isize, mv: Box } impl Drop for T { fn drop(&mut self) { } } fn f(s0:S) { - let _s2 = S{a: 2, ..s0}; //~error: cannot move out of type `S`, which defines the `Drop` trait + let _s2 = S{a: 2, ..s0}; + //~^ error: cannot move out of type `S`, which implements the `Drop` trait } fn g(s0:T) { - let _s2 = T{a: 2, ..s0}; //~error: cannot move out of type `T`, which defines the `Drop` trait + let _s2 = T{a: 2, ..s0}; + //~^ error: cannot move out of type `T`, which implements the `Drop` trait } fn main() { } diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs index 5078009d4b222..38049209903d1 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs @@ -23,6 +23,6 @@ fn main() { match x { X { x: y } => println!("contents: {}", y) - //~^ ERROR cannot move out of type `X`, which defines the `Drop` trait + //~^ ERROR cannot move out of type `X`, which implements the `Drop` trait } } diff --git a/src/test/compile-fail/issue-2392.rs b/src/test/compile-fail/issue-2392.rs index 47d50eb9d5379..790b774bd2133 100644 --- a/src/test/compile-fail/issue-2392.rs +++ b/src/test/compile-fail/issue-2392.rs @@ -81,11 +81,11 @@ impl FuncContainerOuter { fn run(&self) { unsafe { (*self.container).f1(1); //~ ERROR no method named `f1` found - //~^ NOTE use `(*self.container.f1)(...)` + //~^ NOTE use `((*self.container).f1)(...)` (*self.container).f2(1); //~ ERROR no method named `f2` found - //~^ NOTE use `(*self.container.f2)(...)` + //~^ NOTE use `((*self.container).f2)(...)` (*self.container).f3(1); //~ ERROR no method named `f3` found - //~^ NOTE use `(*self.container.f3)(...)` + //~^ NOTE use `((*self.container).f3)(...)` } } } diff --git a/src/test/compile-fail/paren-span.rs b/src/test/compile-fail/paren-span.rs new file mode 100644 index 0000000000000..8ed5050f3de3c --- /dev/null +++ b/src/test/compile-fail/paren-span.rs @@ -0,0 +1,31 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Be smart about span of parenthesized expression in macro. + +macro_rules! paren { + ($e:expr) => (($e)) + // ^^^^ do not highlight here +} + +mod m { + pub struct S { + x: i32 + } + pub fn make() -> S { + S { x: 0 } + } +} + +fn main() { + let s = m::make(); + paren!(s.x); //~ ERROR field `x` of struct `m::S` is private + // ^^^ highlight here +} diff --git a/src/test/run-pass/issue-33387.rs b/src/test/run-pass/issue-33387.rs new file mode 100644 index 0000000000000..a4b85bc7a091d --- /dev/null +++ b/src/test/run-pass/issue-33387.rs @@ -0,0 +1,44 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +use std::sync::Arc; + +trait Foo { + fn get(&self) -> [u8; 2]; +} + +impl Foo for [u8; 2] { + fn get(&self) -> [u8; 2] { + *self + } +} + +struct Bar(T); + +#[rustc_mir] +fn unsize_fat_ptr<'a>(x: &'a Bar) -> &'a Bar { + x +} + +#[rustc_mir] +fn unsize_nested_fat_ptr(x: Arc) -> Arc { + x +} + +#[rustc_mir] +fn main() { + let x: Box> = Box::new(Bar([1,2])); + assert_eq!(unsize_fat_ptr(&*x).0.get(), [1, 2]); + + let x: Arc = Arc::new([3, 4]); + assert_eq!(unsize_nested_fat_ptr(x).get(), [3, 4]); +}