From 8f7c2d518d1892c98d2ef57992a65669834f24e2 Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Sat, 17 Jan 2015 17:00:32 +0100 Subject: Replace `be` with `become` As per rust-lang/rfcs#601, replace `be` with `become` as reserved keyword for tail call optimization. --- src/test/compile-fail/reserved-be.rs | 14 -------------- src/test/compile-fail/reserved-become.rs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 src/test/compile-fail/reserved-be.rs create mode 100644 src/test/compile-fail/reserved-become.rs (limited to 'src/test') diff --git a/src/test/compile-fail/reserved-be.rs b/src/test/compile-fail/reserved-be.rs deleted file mode 100644 index 386d53cc16e..00000000000 --- a/src/test/compile-fail/reserved-be.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2012 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 be = 0; - //~^ ERROR `be` is a reserved keyword -} diff --git a/src/test/compile-fail/reserved-become.rs b/src/test/compile-fail/reserved-become.rs new file mode 100644 index 00000000000..82e9ebc10d1 --- /dev/null +++ b/src/test/compile-fail/reserved-become.rs @@ -0,0 +1,14 @@ +// Copyright 2012-2015 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 become = 0; + //~^ ERROR `become` is a reserved keyword +} -- cgit 1.4.1-3-g733a5 From 4ef7551ccacd4d2042493f2ed905813b297634d0 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Sun, 18 Jan 2015 19:43:35 +0900 Subject: Fix type inference related to upvars in closures --- src/librustc/middle/traits/select.rs | 8 ++++++++ src/test/run-pass/unboxed-closures-infer-upvar.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/test/run-pass/unboxed-closures-infer-upvar.rs (limited to 'src/test') diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index b8af91add9e..2fe07df1709 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1587,6 +1587,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return Ok(ParameterBuiltin); } + // Upvars are always local variables or references to + // local variables, and local variables cannot be + // unsized, so the closure struct as a whole must be + // Sized. + if bound == ty::BoundSized { + return Ok(If(Vec::new())); + } + match self.closure_typer.closure_upvars(def_id, substs) { Some(upvars) => { Ok(If(upvars.iter().map(|c| c.ty).collect())) diff --git a/src/test/run-pass/unboxed-closures-infer-upvar.rs b/src/test/run-pass/unboxed-closures-infer-upvar.rs new file mode 100644 index 00000000000..087ef5dcf05 --- /dev/null +++ b/src/test/run-pass/unboxed-closures-infer-upvar.rs @@ -0,0 +1,22 @@ +// Copyright 2015 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. + +// Test that the type variable in the type(`Vec<_>`) of a closed over +// variable does not interfere with type inference. + +fn f(mut f: F) { + f(); +} + +fn main() { + let mut v: Vec<_> = vec![]; + f(|| v.push(0)); + assert_eq!(v, vec![0]); +} -- cgit 1.4.1-3-g733a5 From 61b4823b77ffaf39e0825314d749eac3a115764d Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 8 Feb 2015 10:51:46 +0200 Subject: Add a test for mainless emit targets --- src/test/run-make/empty-file/Makefile | 5 +++++ src/test/run-make/empty-file/empty.rs | 0 2 files changed, 5 insertions(+) create mode 100644 src/test/run-make/empty-file/Makefile create mode 100644 src/test/run-make/empty-file/empty.rs (limited to 'src/test') diff --git a/src/test/run-make/empty-file/Makefile b/src/test/run-make/empty-file/Makefile new file mode 100644 index 00000000000..f55a2cc3bb1 --- /dev/null +++ b/src/test/run-make/empty-file/Makefile @@ -0,0 +1,5 @@ +-include ../tools.mk + +all: + $(RUSTC) --emit=asm,llvm-bc,llvm-ir,obj,dep-info empty.rs + $(RUSTC) --emit=link --crate-type=rlib,dylib,staticlib empty.rs diff --git a/src/test/run-make/empty-file/empty.rs b/src/test/run-make/empty-file/empty.rs new file mode 100644 index 00000000000..e69de29bb2d -- cgit 1.4.1-3-g733a5 From 8fb426469a4f7b08a240172c8f4295e868c65db8 Mon Sep 17 00:00:00 2001 From: Sébastien Marie Date: Sun, 8 Feb 2015 09:36:08 +0100 Subject: adapt run-make test suite for openbsd - c-link-to-rust-staticlib: use EXTRACFLAGS defined by tools.mk for choose the good libraries to link to. - no-stack-check: disabled for openbsd (no segmented stacks here) - symbols-are-reasonable: use portable grep pattern - target-specs: use POSIX form for options when invoking grep - use-extern-for-plugins: disable as OpenBSD only support x86_64 for now --- src/test/run-make/c-link-to-rust-staticlib/Makefile | 4 +--- src/test/run-make/no-stack-check/Makefile | 5 +++++ src/test/run-make/symbols-are-reasonable/Makefile | 6 +++--- src/test/run-make/target-specs/Makefile | 4 ++-- src/test/run-make/use-extern-for-plugins/Makefile | 5 +++++ 5 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/test') diff --git a/src/test/run-make/c-link-to-rust-staticlib/Makefile b/src/test/run-make/c-link-to-rust-staticlib/Makefile index 8a6d6e4dd6d..477b85f362a 100644 --- a/src/test/run-make/c-link-to-rust-staticlib/Makefile +++ b/src/test/run-make/c-link-to-rust-staticlib/Makefile @@ -1,9 +1,7 @@ -include ../tools.mk ifndef IS_WINDOWS -ifneq ($(shell uname),Darwin) - EXTRAFLAGS := -lm -lrt -ldl -lpthread -endif +EXTRAFLAGS := $(EXTRACFLAGS) endif # FIXME: ignore freebsd diff --git a/src/test/run-make/no-stack-check/Makefile b/src/test/run-make/no-stack-check/Makefile index 561056d719e..5fce35e2beb 100644 --- a/src/test/run-make/no-stack-check/Makefile +++ b/src/test/run-make/no-stack-check/Makefile @@ -1,6 +1,7 @@ -include ../tools.mk ifndef IS_WINDOWS +ifneq ($(UNAME),OpenBSD) all: $(RUSTC) -O --emit asm attr.rs ! grep -q morestack $(TMPDIR)/attr.s @@ -9,6 +10,10 @@ all: $(RUSTC) -O --emit asm -C no-stack-check flag.rs ! grep -q morestack $(TMPDIR)/flag.s else +# On OpenBSD, morestack isn't used as the segmented stacks are disabled +all: +endif +else # On Windows we use __chkstk and it only appears in functions with large allocations, # so this test wouldn't be reliable. all: diff --git a/src/test/run-make/symbols-are-reasonable/Makefile b/src/test/run-make/symbols-are-reasonable/Makefile index 42a72f7ca39..89f610dee17 100644 --- a/src/test/run-make/symbols-are-reasonable/Makefile +++ b/src/test/run-make/symbols-are-reasonable/Makefile @@ -10,6 +10,6 @@ OUT=$(TMPDIR)/lib.s all: $(RUSTC) lib.rs --emit=asm --crate-type=staticlib # just check for symbol declarations with the names we're expecting. - grep 'str[0-9]\+:' $(OUT) - grep 'binary[0-9]\+:' $(OUT) - grep 'vtable[0-9]\+' $(OUT) + grep 'str[0-9][0-9]*:' $(OUT) + grep 'binary[0-9][0-9]*:' $(OUT) + grep 'vtable[0-9][0-9]*' $(OUT) diff --git a/src/test/run-make/target-specs/Makefile b/src/test/run-make/target-specs/Makefile index a352bc3a8cc..db2b253a6f1 100644 --- a/src/test/run-make/target-specs/Makefile +++ b/src/test/run-make/target-specs/Makefile @@ -1,11 +1,11 @@ -include ../tools.mk all: $(RUSTC) foo.rs --target=my-awesome-platform.json --crate-type=lib --emit=asm - grep --quiet --invert-match morestack < $(TMPDIR)/foo.s + grep -q -v morestack < $(TMPDIR)/foo.s $(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep --quiet "Error loading target specification" $(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target' RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm # The built-in target *should* override the one we have here, and thus we # should have morestack - grep --quiet morestack < $(TMPDIR)/foo.s + grep -q morestack < $(TMPDIR)/foo.s diff --git a/src/test/run-make/use-extern-for-plugins/Makefile b/src/test/run-make/use-extern-for-plugins/Makefile index 84032b45159..bdce7b7810a 100644 --- a/src/test/run-make/use-extern-for-plugins/Makefile +++ b/src/test/run-make/use-extern-for-plugins/Makefile @@ -1,5 +1,6 @@ -include ../tools.mk +ifneq ($(UNAME),OpenBSD) HOST := $(shell $(RUSTC) -vV | grep 'host:' | sed 's/host: //') ifeq ($(findstring i686,$(HOST)),i686) TARGET := $(subst i686,x86_64,$(HOST)) @@ -11,3 +12,7 @@ all: $(RUSTC) foo.rs -C extra-filename=-host $(RUSTC) bar.rs -C extra-filename=-targ --target $(TARGET) $(RUSTC) baz.rs --extern a=$(TMPDIR)/liba-targ.rlib --target $(TARGET) +else +# OpenBSD support only x86_64 architecture for now +all: +endif -- cgit 1.4.1-3-g733a5 From a6e8496601767e59acce010531f8e4dfb40c7c0a Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 9 Feb 2015 19:30:22 +0200 Subject: Deduplicate --crate-type arguments Crate types from multiple sources appear to be deduplicated properly, but not deduplicated if they come from the command line arguments. At worst, this used to cause compiler failures when `--crate-type=lib,rlib` (the same as `--crate-type=rlib,rlib`, at least at the time of this commit) is provided and generate the output multiple times otherwise. --- src/librustc/session/config.rs | 4 +++- src/test/run-make/duplicate-output-flavors/Makefile | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index efd2392e453..6d09b8b09e7 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1061,7 +1061,9 @@ pub fn parse_crate_types_from_list(list_list: Vec) -> Result Date: Mon, 9 Feb 2015 09:29:21 -0800 Subject: Process cfg_attr right before stripping cfg Fixes #22070. Fixes #19372. --- src/libsyntax/config.rs | 49 ++++++++++++++++++++++++++++++- src/libsyntax/ext/base.rs | 2 -- src/libsyntax/ext/cfg_attr.rs | 34 --------------------- src/libsyntax/lib.rs | 1 - src/test/compile-fail/cfg-attr-cfg-2.rs | 18 ++++++++++++ src/test/compile-fail/cfg-attr-crate-2.rs | 17 +++++++++++ src/test/run-pass/cfg-attr-cfg.rs | 15 ++++++++++ src/test/run-pass/cfg-attr-crate.rs | 15 ++++++++++ 8 files changed, 113 insertions(+), 38 deletions(-) delete mode 100644 src/libsyntax/ext/cfg_attr.rs create mode 100644 src/test/compile-fail/cfg-attr-cfg-2.rs create mode 100644 src/test/compile-fail/cfg-attr-crate-2.rs create mode 100644 src/test/run-pass/cfg-attr-cfg.rs create mode 100644 src/test/run-pass/cfg-attr-crate.rs (limited to 'src/test') diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index eb845e463a0..7ca0591be50 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -12,7 +12,7 @@ use attr::AttrMetaMethods; use diagnostic::SpanHandler; use fold::Folder; use {ast, fold, attr}; -use codemap::Spanned; +use codemap::{Spanned, respan}; use ptr::P; use util::small_vector::SmallVector; @@ -26,6 +26,7 @@ struct Context where F: FnMut(&[ast::Attribute]) -> bool { // Support conditional compilation by transforming the AST, stripping out // any items that do not belong in the current configuration pub fn strip_unconfigured_items(diagnostic: &SpanHandler, krate: ast::Crate) -> ast::Crate { + let krate = process_cfg_attr(diagnostic, krate); let config = krate.config.clone(); strip_items(krate, |attrs| in_cfg(diagnostic, &config, attrs)) } @@ -281,3 +282,49 @@ fn in_cfg(diagnostic: &SpanHandler, cfg: &[P], attrs: &[ast::Attr attr::cfg_matches(diagnostic, cfg, &*mis[0]) }) } + +struct CfgAttrFolder<'a> { + diag: &'a SpanHandler, + config: ast::CrateConfig, +} + +// Process `#[cfg_attr]`. +fn process_cfg_attr(diagnostic: &SpanHandler, krate: ast::Crate) -> ast::Crate { + let mut fld = CfgAttrFolder { + diag: diagnostic, + config: krate.config.clone(), + }; + fld.fold_crate(krate) +} + +impl<'a> fold::Folder for CfgAttrFolder<'a> { + fn fold_attribute(&mut self, attr: ast::Attribute) -> Option { + if !attr.check_name("cfg_attr") { + return fold::noop_fold_attribute(attr, self); + } + + let (cfg, mi) = match attr.meta_item_list() { + Some([ref cfg, ref mi]) => (cfg, mi), + _ => { + self.diag.span_err(attr.span, "expected `#[cfg_attr(, )]`"); + return None; + } + }; + + if attr::cfg_matches(self.diag, &self.config[], &cfg) { + Some(respan(mi.span, ast::Attribute_ { + id: attr::mk_attr_id(), + style: attr.node.style, + value: mi.clone(), + is_sugared_doc: false, + })) + } else { + None + } + } + + // Need the ability to run pre-expansion. + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) + } +} diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 778b2cabea6..64ae6162ef4 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -528,8 +528,6 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv { syntax_expanders.insert(intern("cfg"), builtin_normal_expander( ext::cfg::expand_cfg)); - syntax_expanders.insert(intern("cfg_attr"), - Modifier(box ext::cfg_attr::expand)); syntax_expanders.insert(intern("trace_macros"), builtin_normal_expander( ext::trace_macros::expand_trace_macros)); diff --git a/src/libsyntax/ext/cfg_attr.rs b/src/libsyntax/ext/cfg_attr.rs deleted file mode 100644 index 72eaa3e47be..00000000000 --- a/src/libsyntax/ext/cfg_attr.rs +++ /dev/null @@ -1,34 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use ast; -use attr; -use codemap::Span; -use ext::base::ExtCtxt; -use ext::build::AstBuilder; -use ptr::P; - -pub fn expand(cx: &mut ExtCtxt, sp: Span, mi: &ast::MetaItem, it: P) -> P { - let (cfg, attr) = match mi.node { - ast::MetaList(_, ref mis) if mis.len() == 2 => (&mis[0], &mis[1]), - _ => { - cx.span_err(sp, "expected `#[cfg_attr(, )]`"); - return it; - } - }; - - let mut out = (*it).clone(); - if attr::cfg_matches(&cx.parse_sess.span_diagnostic, &cx.cfg, &**cfg) { - out.attrs.push(cx.attribute(attr.span, attr.clone())); - } - - P(out) -} - diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 08e795ef80d..41850ada3e6 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -96,7 +96,6 @@ pub mod ext { pub mod base; pub mod build; pub mod cfg; - pub mod cfg_attr; pub mod concat; pub mod concat_idents; pub mod deriving; diff --git a/src/test/compile-fail/cfg-attr-cfg-2.rs b/src/test/compile-fail/cfg-attr-cfg-2.rs new file mode 100644 index 00000000000..b71a3be5dce --- /dev/null +++ b/src/test/compile-fail/cfg-attr-cfg-2.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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. +// +// error-pattern: main function not found +// compile-flags: --cfg foo + +// main is conditionally compiled, but the conditional compilation +// is conditional too! + +#[cfg_attr(foo, cfg(bar))] +fn main() { } diff --git a/src/test/compile-fail/cfg-attr-crate-2.rs b/src/test/compile-fail/cfg-attr-crate-2.rs new file mode 100644 index 00000000000..4867dd8d0b4 --- /dev/null +++ b/src/test/compile-fail/cfg-attr-crate-2.rs @@ -0,0 +1,17 @@ +// Copyright 2015 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. +// +// compile-flags: --cfg broken + +// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044 + +#![cfg_attr(broken, no_std)] //~ ERROR no_std is experimental + +fn main() { } diff --git a/src/test/run-pass/cfg-attr-cfg.rs b/src/test/run-pass/cfg-attr-cfg.rs new file mode 100644 index 00000000000..09ab7019486 --- /dev/null +++ b/src/test/run-pass/cfg-attr-cfg.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +// main is conditionally compiled, but the conditional compilation +// is conditional too! + +#[cfg_attr(foo, cfg(bar))] +fn main() { } diff --git a/src/test/run-pass/cfg-attr-crate.rs b/src/test/run-pass/cfg-attr-crate.rs new file mode 100644 index 00000000000..e6bd8afad28 --- /dev/null +++ b/src/test/run-pass/cfg-attr-crate.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044 + +#![cfg_attr(not_used, no_std)] + +fn main() { } -- cgit 1.4.1-3-g733a5 From a1b3189f4864f1ada755e9ebc2e0ce1ac5bf2e06 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 6 Feb 2015 18:05:32 +0100 Subject: add test illustrating the feature. (with multiple impls to further exercise correct trait-matching.) --- .../run-pass/infer-container-across-object-cast.rs | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/run-pass/infer-container-across-object-cast.rs (limited to 'src/test') diff --git a/src/test/run-pass/infer-container-across-object-cast.rs b/src/test/run-pass/infer-container-across-object-cast.rs new file mode 100644 index 00000000000..979e76b1ff9 --- /dev/null +++ b/src/test/run-pass/infer-container-across-object-cast.rs @@ -0,0 +1,59 @@ +// Copyright 2015 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. + +// Given ` as Box`, we should be able to infer that a +// `Box<_>` is the expected type. + +trait Foo { fn foo(&self) -> u32; } +impl Foo for u32 { fn foo(&self) -> u32 { *self } } + +// (another impl to ensure trait-matching cannot just choose from a singleton set) +impl Foo for () { fn foo(&self) -> u32 { -176 } } + +trait Boxed { fn make() -> Self; } +impl Boxed for Box { fn make() -> Self { Box::new(7) } } + +// (another impl to ensure trait-matching cannot just choose from a singleton set) +impl Boxed for () { fn make() -> Self { () } } + +fn boxed_foo() { + let b7 = Boxed::make() as Box; + assert_eq!(b7.foo(), 7); +} + +trait Refed<'a,T> { fn make(&'a T) -> Self; } +impl<'a> Refed<'a, u32> for &'a u32 { fn make(x: &'a u32) -> Self { x } } + +// (another impl to ensure trait-matching cannot just choose from a singleton set) +impl<'a,'b> Refed<'a, ()> for &'b () { fn make(_: &'a ()) -> Self { static U: () = (); &U } } + +fn refed_foo() { + let a = 8; + let b7 = Refed::make(&a) as &Foo; + assert_eq!(b7.foo(), 8); +} + +fn check_subtyping_works() { + fn inner<'short, 'long:'short>(_s: &'short u32, + l: &'long u32) -> &'short (Foo+'short) { + Refed::make(l) as &Foo + } + + let a = 9; + let b = 10; + let r = inner(&b, &a); + assert_eq!(r.foo(), 9); +} + +pub fn main() { + boxed_foo(); + refed_foo(); + check_subtyping_works(); +} -- cgit 1.4.1-3-g733a5 From 3513c97302b72b6dd51136ce1e259ca0e67458f3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 10 Feb 2015 15:01:31 +0100 Subject: Add error message (i.e. do not ICE) when moving out of unsafe pointers. Fix #20801. --- .../borrowck/gather_loans/move_error.rs | 1 + src/test/compile-fail/issue-20801.rs | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/test/compile-fail/issue-20801.rs (limited to 'src/test') diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index b00973c82bd..10ffb89e728 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -118,6 +118,7 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, match move_from.cat { mc::cat_deref(_, _, mc::BorrowedPtr(..)) | mc::cat_deref(_, _, mc::Implicit(..)) | + mc::cat_deref(_, _, mc::UnsafePtr(..)) | mc::cat_static_item => { bccx.span_err(move_from.span, &format!("cannot move out of {}", diff --git a/src/test/compile-fail/issue-20801.rs b/src/test/compile-fail/issue-20801.rs new file mode 100644 index 00000000000..a2565e88467 --- /dev/null +++ b/src/test/compile-fail/issue-20801.rs @@ -0,0 +1,47 @@ +// Copyright 2015 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. + +// We used to ICE when moving out of a `*mut T` or `*const T`. + +struct T(u8); + +static mut GLOBAL_MUT_T: T = T(0); + +static GLOBAL_T: T = T(0); + +fn imm_ref() -> &'static T { + unsafe { &GLOBAL_T } +} + +fn mut_ref() -> &'static mut T { + unsafe { &mut GLOBAL_MUT_T } +} + +fn mut_ptr() -> *mut T { + unsafe { 0u8 as *mut T } +} + +fn const_ptr() -> *const T { + unsafe { 0u8 as *const T } +} + +pub fn main() { + let a = unsafe { *mut_ref() }; + //~^ ERROR cannot move out of dereference of borrowed content + + let b = unsafe { *imm_ref() }; + //~^ ERROR cannot move out of dereference of borrowed content + + let c = unsafe { *mut_ptr() }; + //~^ ERROR cannot move out of dereference of unsafe pointer + + let d = unsafe { *const_ptr() }; + //~^ ERROR cannot move out of dereference of unsafe pointer +} -- cgit 1.4.1-3-g733a5 From 0b1d5f01828fdb21e31071d149618d2e983342c5 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 26 Jan 2015 14:27:22 +0100 Subject: Make FRU respect privacy of all struct fields, mentioned or unmentioned. This is RFC 736. Fix #21407. --- src/librustc_privacy/lib.rs | 29 +++++++-------- .../functional-struct-update-respects-privacy.rs | 42 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/test/compile-fail/functional-struct-update-respects-privacy.rs (limited to 'src/test') diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index aa9b6c479bb..4afe8fe7878 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -390,8 +390,8 @@ enum PrivacyResult { enum FieldName { UnnamedField(uint), // index - // FIXME #6993: change type (and name) from Ident to Name - NamedField(ast::Ident), + // (Name, not Ident, because struct fields are not macro-hygienic) + NamedField(ast::Name), } impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { @@ -665,9 +665,9 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { name: FieldName) { let fields = ty::lookup_struct_fields(self.tcx, id); let field = match name { - NamedField(ident) => { - debug!("privacy - check named field {} in struct {:?}", ident.name, id); - fields.iter().find(|f| f.name == ident.name).unwrap() + NamedField(f_name) => { + debug!("privacy - check named field {} in struct {:?}", f_name, id); + fields.iter().find(|f| f.name == f_name).unwrap() } UnnamedField(idx) => &fields[idx] }; @@ -686,7 +686,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { }; let msg = match name { NamedField(name) => format!("field `{}` of {} is private", - token::get_ident(name), struct_desc), + token::get_name(name), struct_desc), UnnamedField(idx) => format!("field #{} of {} is private", idx + 1, struct_desc), }; @@ -873,7 +873,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { match expr.node { ast::ExprField(ref base, ident) => { if let ty::ty_struct(id, _) = ty::expr_ty_adjusted(self.tcx, &**base).sty { - self.check_field(expr.span, id, NamedField(ident.node)); + self.check_field(expr.span, id, NamedField(ident.node.name)); } } ast::ExprTupField(ref base, idx) => { @@ -897,10 +897,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } ast::ExprStruct(_, ref fields, _) => { match ty::expr_ty(self.tcx, expr).sty { - ty::ty_struct(id, _) => { - for field in &(*fields) { - self.check_field(expr.span, id, - NamedField(field.ident.node)); + ty::ty_struct(ctor_id, _) => { + let all_fields = ty::lookup_struct_fields(self.tcx, ctor_id); + for field in all_fields { + self.check_field(expr.span, ctor_id, + NamedField(field.name)); } } ty::ty_enum(_, _) => { @@ -908,7 +909,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { def::DefVariant(_, variant_id, _) => { for field in fields { self.check_field(expr.span, variant_id, - NamedField(field.ident.node)); + NamedField(field.ident.node.name)); } } _ => self.tcx.sess.span_bug(expr.span, @@ -973,7 +974,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { ty::ty_struct(id, _) => { for field in fields { self.check_field(pattern.span, id, - NamedField(field.node.ident)); + NamedField(field.node.ident.name)); } } ty::ty_enum(_, _) => { @@ -981,7 +982,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { Some(&def::DefVariant(_, variant_id, _)) => { for field in fields { self.check_field(pattern.span, variant_id, - NamedField(field.node.ident)); + NamedField(field.node.ident.name)); } } _ => self.tcx.sess.span_bug(pattern.span, diff --git a/src/test/compile-fail/functional-struct-update-respects-privacy.rs b/src/test/compile-fail/functional-struct-update-respects-privacy.rs new file mode 100644 index 00000000000..c1619a38a29 --- /dev/null +++ b/src/test/compile-fail/functional-struct-update-respects-privacy.rs @@ -0,0 +1,42 @@ +// Copyright 2015 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. + +// RFC 736 (and Issue 21407): functional struct update should respect privacy. + +// The `foo` module attempts to maintains an invariant that each `S` +// has a unique `u64` id. +use self::foo::S; +mod foo { + use std::cell::{UnsafeCell}; + + static mut count : UnsafeCell = UnsafeCell { value: 1 }; + + pub struct S { pub a: u8, pub b: String, secret_uid: u64 } + + pub fn make_secrets(a: u8, b: String) -> S { + let val = unsafe { let p = count.get(); let val = *p; *p = val + 1; val }; + println!("creating {}, uid {}", b, val); + S { a: a, b: b, secret_uid: val } + } + + impl Drop for S { + fn drop(&mut self) { + println!("dropping {}, uid {}", self.b, self.secret_uid); + } + } +} + +fn main() { + let s_1 = foo::make_secrets(3, format!("ess one")); + let s_2 = foo::S { b: format!("ess two"), ..s_1 }; // FRU ... + + println!("main forged an S named: {}", s_2.b); + // at end of scope, ... both s_1 *and* s_2 get dropped. Boom! +} -- cgit 1.4.1-3-g733a5 From ad3be9f23f9389c71f7f712ae5195d4190becf05 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 9 Feb 2015 23:42:31 -0500 Subject: parse cfgspecs passed to rustdoc fixes #22131 --- src/librustdoc/test.rs | 10 ++-------- src/test/run-make/issue-22131/Makefile | 6 ++++++ src/test/run-make/issue-22131/foo.rs | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/test/run-make/issue-22131/Makefile create mode 100644 src/test/run-make/issue-22131/foo.rs (limited to 'src/test') diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e43c3a6da3a..09df9fc8cbb 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -24,11 +24,8 @@ use rustc::session::{self, config}; use rustc::session::config::get_unstable_features_setting; use rustc::session::search_paths::{SearchPaths, PathKind}; use rustc_driver::{driver, Compilation}; -use syntax::ast; -use syntax::codemap::{CodeMap, dummy_spanned}; +use syntax::codemap::CodeMap; use syntax::diagnostic; -use syntax::parse::token; -use syntax::ptr::P; use core; use clean; @@ -67,10 +64,7 @@ pub fn run(input: &str, span_diagnostic_handler); let mut cfg = config::build_configuration(&sess); - cfg.extend(cfgs.into_iter().map(|cfg_| { - let cfg_ = token::intern_and_get_ident(&cfg_); - P(dummy_spanned(ast::MetaWord(cfg_))) - })); + cfg.extend(config::parse_cfgspecs(cfgs).into_iter()); let krate = driver::phase_1_parse_input(&sess, cfg, &input); let krate = driver::phase_2_configure_and_expand(&sess, krate, "rustdoc-test", None) diff --git a/src/test/run-make/issue-22131/Makefile b/src/test/run-make/issue-22131/Makefile new file mode 100644 index 00000000000..46d89f0e2a6 --- /dev/null +++ b/src/test/run-make/issue-22131/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: foo.rs + $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs + $(RUSTDOC) --test --cfg 'feature="bar"' -L $(TMPDIR) foo.rs |\ + grep --quiet 'test foo_0 ... ok' diff --git a/src/test/run-make/issue-22131/foo.rs b/src/test/run-make/issue-22131/foo.rs new file mode 100644 index 00000000000..0b1f1291df0 --- /dev/null +++ b/src/test/run-make/issue-22131/foo.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name="foo"] + +/// ```rust +/// assert_eq!(foo::foo(), 1); +/// ``` +#[cfg(feature = "bar")] +pub fn foo() -> i32 { 1 } -- cgit 1.4.1-3-g733a5 From 3f5af9f34d282cde910c0a1dc6b9c595227701c3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 10 Feb 2015 17:32:39 +0100 Subject: add `//~ ERROR` line to test for privacy respecting FRU (RFC 736). --- src/test/compile-fail/functional-struct-update-respects-privacy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/compile-fail/functional-struct-update-respects-privacy.rs b/src/test/compile-fail/functional-struct-update-respects-privacy.rs index c1619a38a29..51e23a689a1 100644 --- a/src/test/compile-fail/functional-struct-update-respects-privacy.rs +++ b/src/test/compile-fail/functional-struct-update-respects-privacy.rs @@ -36,7 +36,7 @@ mod foo { fn main() { let s_1 = foo::make_secrets(3, format!("ess one")); let s_2 = foo::S { b: format!("ess two"), ..s_1 }; // FRU ... - + //~^ ERROR field `secret_uid` of struct `foo::S` is private println!("main forged an S named: {}", s_2.b); // at end of scope, ... both s_1 *and* s_2 get dropped. Boom! } -- cgit 1.4.1-3-g733a5 From 3e10785e21b731d536cf9ad9b911e8261862bde7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 10 Feb 2015 11:05:20 -0800 Subject: Test fixes and rebase conflicts --- src/compiletest/compiletest.rs | 1 - src/libgetopts/lib.rs | 1 - src/liblibc/lib.rs | 2 +- src/libterm/lib.rs | 1 - src/test/compile-fail/issue-17551.rs | 4 ++-- src/test/compile-fail/issue-17999.rs | 1 - src/test/compile-fail/issue-20801.rs | 4 ++-- src/test/compile-fail/issue-2150.rs | 1 - src/test/compile-fail/liveness-unused.rs | 1 - src/test/run-make/issue-22131/Makefile | 5 +++-- 10 files changed, 8 insertions(+), 13 deletions(-) (limited to 'src/test') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index e6d2a691cf5..3c92fa02f20 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -12,7 +12,6 @@ #![feature(box_syntax)] #![feature(collections)] -#![feature(core)] #![feature(int_uint)] #![feature(io)] #![feature(os)] diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 72832cb9466..a3cae259fd3 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -90,7 +90,6 @@ #![deny(missing_docs)] #![feature(collections)] -#![feature(core)] #![feature(int_uint)] #![feature(slicing_syntax)] #![feature(staged_api)] diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index d95d0863ca8..94e4012c5ee 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -1930,7 +1930,7 @@ pub mod types { pub iSecurityScheme: c_int, pub dwMessageSize: DWORD, pub dwProviderReserved: DWORD, - pub szProtocol: [u8; WSAPROTOCOL_LEN as usize + 1], + pub szProtocol: [u8; WSAPROTOCOL_LEN as usize + 1us], } pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 219c9baf4c8..084152f107c 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -52,7 +52,6 @@ #![feature(box_syntax)] #![feature(collections)] -#![feature(core)] #![feature(int_uint)] #![feature(io)] #![feature(path)] diff --git a/src/test/compile-fail/issue-17551.rs b/src/test/compile-fail/issue-17551.rs index b19a7703b85..e037ba92b4a 100644 --- a/src/test/compile-fail/issue-17551.rs +++ b/src/test/compile-fail/issue-17551.rs @@ -13,6 +13,6 @@ struct B; fn main() { - let foo = B; - let closure = || foo; //~ ERROR unable to infer enough type information + let foo = B; //~ ERROR: unable to infer enough type information + let closure = || foo; } diff --git a/src/test/compile-fail/issue-17999.rs b/src/test/compile-fail/issue-17999.rs index f4c0a9c38c3..88945f80eae 100644 --- a/src/test/compile-fail/issue-17999.rs +++ b/src/test/compile-fail/issue-17999.rs @@ -9,7 +9,6 @@ // except according to those terms. #![deny(unused_variables)] -#![feature(core)] fn main() { for _ in 1..101 { diff --git a/src/test/compile-fail/issue-20801.rs b/src/test/compile-fail/issue-20801.rs index a2565e88467..929c8ec0fd6 100644 --- a/src/test/compile-fail/issue-20801.rs +++ b/src/test/compile-fail/issue-20801.rs @@ -34,10 +34,10 @@ fn const_ptr() -> *const T { pub fn main() { let a = unsafe { *mut_ref() }; - //~^ ERROR cannot move out of dereference of borrowed content + //~^ ERROR cannot move out of borrowed content let b = unsafe { *imm_ref() }; - //~^ ERROR cannot move out of dereference of borrowed content + //~^ ERROR cannot move out of borrowed content let c = unsafe { *mut_ptr() }; //~^ ERROR cannot move out of dereference of unsafe pointer diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index a2711d532d2..79df16c8979 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -11,7 +11,6 @@ #![deny(unreachable_code)] #![allow(unused_variables)] #![allow(dead_code)] -#![feature(core)] fn fail_len(v: Vec ) -> usize { let mut i = 3; diff --git a/src/test/compile-fail/liveness-unused.rs b/src/test/compile-fail/liveness-unused.rs index d4238120d06..ac4b8a5f309 100644 --- a/src/test/compile-fail/liveness-unused.rs +++ b/src/test/compile-fail/liveness-unused.rs @@ -11,7 +11,6 @@ #![deny(unused_variables)] #![deny(unused_assignments)] #![allow(dead_code, non_camel_case_types)] -#![feature(core)] fn f1(x: isize) { //~^ ERROR unused variable: `x` diff --git a/src/test/run-make/issue-22131/Makefile b/src/test/run-make/issue-22131/Makefile index 46d89f0e2a6..0f927320c4e 100644 --- a/src/test/run-make/issue-22131/Makefile +++ b/src/test/run-make/issue-22131/Makefile @@ -2,5 +2,6 @@ all: foo.rs $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs - $(RUSTDOC) --test --cfg 'feature="bar"' -L $(TMPDIR) foo.rs |\ - grep --quiet 'test foo_0 ... ok' + $(HOST_RPATH_ENV) $(RUSTDOC) --test --cfg 'feature="bar"' \ + -L $(TMPDIR) foo.rs |\ + grep --quiet 'test foo_0 ... ok' -- cgit 1.4.1-3-g733a5