std::io: expand the oneshot/periodic docs.
Examples!
Fixes #14714.
"libstd/sync/mpmc_bounded_queue.rs", # BSD
"libsync/mpsc_intrusive.rs", # BSD
"test/bench/shootout-meteor.rs", # BSD
+ "test/bench/shootout-regex-dna.rs", # BSD
]
def check_license(name, contents):
use core::prelude::*;
use alloc::owned::Box;
+use core::fmt;
use core::iter;
use core::mem;
use core::ptr;
}
}
+impl<A: fmt::Show> fmt::Show for DList<A> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ try!(write!(f, "["));
+
+ for (i, e) in self.iter().enumerate() {
+ if i != 0 { try!(write!(f, ", ")); }
+ try!(write!(f, "{}", *e));
+ }
+
+ write!(f, "]")
+ }
+}
+
#[cfg(test)]
mod tests {
use std::prelude::*;
}
}
+ #[test]
+ fn test_show() {
+ let list: DList<int> = range(0, 10).collect();
+ assert!(list.to_str().as_slice() == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
+
+ let list: DList<&str> = vec!["just", "one", "test", "more"].iter()
+ .map(|&s| s)
+ .collect();
+ assert!(list.to_str().as_slice() == "[just, one, test, more]");
+ }
+
#[cfg(test)]
fn fuzz_test(sz: int) {
let mut m: DList<int> = DList::new();
use core::prelude::*;
+use core::fmt;
use core::iter::{Enumerate, FilterMap};
use core::mem::replace;
}
}
+impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ try!(write!(f, r"\{"));
+
+ for (i, (k, v)) in self.iter().enumerate() {
+ if i != 0 { try!(write!(f, ", ")); }
+ try!(write!(f, "{}: {}", k, *v));
+ }
+
+ write!(f, r"\}")
+ }
+}
macro_rules! iterator {
(impl $name:ident -> $elem:ty, $getter:ident) => {
assert!(called);
m.insert(2, box 1);
}
+
+ #[test]
+ fn test_show() {
+ let mut map = SmallIntMap::new();
+ let empty = SmallIntMap::<int>::new();
+
+ map.insert(1, 2);
+ map.insert(3, 4);
+
+ let map_str = map.to_str();
+ let map_str = map_str.as_slice();
+ assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
+ assert_eq!(format!("{}", empty), "{}".to_string());
+ }
}
#[cfg(test)]
/// Trait for values that can be compared for equality and inequality.
///
-/// This trait allows partial equality, where types can be unordered instead of
-/// strictly equal or unequal. For example, with the built-in floating-point
-/// types `a == b` and `a != b` will both evaluate to false if either `a` or
-/// `b` is NaN (cf. IEEE 754-2008 section 5.11).
+/// This trait allows for partial equality, for types that do not have an
+/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
+/// so floating point types implement `PartialEq` but not `Eq`.
///
-/// PartialEq only requires the `eq` method to be implemented; `ne` is its negation by
-/// default.
+/// PartialEq only requires the `eq` method to be implemented; `ne` is defined
+/// in terms of it by default. Any manual implementation of `ne` *must* respect
+/// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
+/// only if `a != b`.
///
/// Eventually, this will be implemented by default for types that implement
/// `Eq`.
/// PartialOrd only requires implementation of the `lt` method,
/// with the others generated from default implementations.
///
-/// However it remains possible to implement the others separately,
-/// for compatibility with floating-point NaN semantics
-/// (cf. IEEE 754-2008 section 5.11).
+/// However it remains possible to implement the others separately for types
+/// which do not have a total order. For example, for floating point numbers,
+/// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section
+/// 5.11).
#[lang="ord"]
pub trait PartialOrd: PartialEq {
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.
pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
for attribute in attrs.iter() {
- match attribute.name_str_pair() {
- Some((ref key, ref value)) if key.equiv(&("lang")) => {
- return Some((*value).clone());
+ match attribute.value_str() {
+ Some(ref value) if attribute.check_name("lang") => {
+ return Some(value.clone());
}
- Some(..) | None => {}
+ _ => {}
}
}
TypeOverflow,
UnusedUnsafe,
UnsafeBlock,
- AttributeUsage,
UnusedAttribute,
UnknownFeatures,
UnknownCrateType,
default: Allow
}),
- ("attribute_usage",
- LintSpec {
- lint: AttributeUsage,
- desc: "detects bad use of attributes",
- default: Warn
- }),
-
("unused_attribute",
LintSpec {
lint: UnusedAttribute,
}
}
-static crate_attrs: &'static [&'static str] = &[
- "crate_type", "feature", "no_start", "no_main", "no_std", "crate_id",
- "desc", "comment", "license", "copyright", // not used in rustc now
- "no_builtins",
-];
-
-
-static obsolete_attrs: &'static [(&'static str, &'static str)] = &[
- ("abi", "Use `extern \"abi\" fn` instead"),
- ("auto_encode", "Use `#[deriving(Encodable)]` instead"),
- ("auto_decode", "Use `#[deriving(Decodable)]` instead"),
- ("fast_ffi", "Remove it"),
- ("fixed_stack_segment", "Remove it"),
- ("rust_stack", "Remove it"),
-];
-
-static other_attrs: &'static [&'static str] = &[
- // item-level
- "address_insignificant", // can be crate-level too
- "thread_local", // for statics
- "allow", "deny", "forbid", "warn", // lint options
- "deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
- "cfg", "doc", "export_name", "link_section",
- "no_mangle", "static_assert", "unsafe_no_drop_flag", "packed",
- "simd", "repr", "deriving", "unsafe_destructor", "link", "phase",
- "macro_export", "must_use", "automatically_derived",
-
- //mod-level
- "path", "link_name", "link_args", "macro_escape", "no_implicit_prelude",
-
- // fn-level
- "test", "bench", "should_fail", "ignore", "inline", "lang", "main", "start",
- "no_split_stack", "cold", "macro_registrar", "linkage",
-
- // internal attribute: bypass privacy inside items
- "!resolve_unexported",
-];
-
-fn check_crate_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
-
- for attr in attrs.iter() {
- let name = attr.node.value.name();
- let mut iter = crate_attrs.iter().chain(other_attrs.iter());
- if !iter.any(|other_attr| { name.equiv(other_attr) }) {
- cx.span_lint(AttributeUsage, attr.span, "unknown crate attribute");
- }
- if name.equiv(&("link")) {
- cx.tcx.sess.span_err(attr.span,
- "obsolete crate `link` attribute");
- cx.tcx.sess.note("the link attribute has been superceded by the crate_id \
- attribute, which has the format `#[crate_id = \"name#version\"]`");
- }
- }
-}
-
-fn check_attrs_usage(cx: &Context, attrs: &[ast::Attribute]) {
- // check if element has crate-level, obsolete, or any unknown attributes.
-
- for attr in attrs.iter() {
- let name = attr.node.value.name();
- for crate_attr in crate_attrs.iter() {
- if name.equiv(crate_attr) {
- let msg = match attr.node.style {
- ast::AttrOuter => "crate-level attribute should be an inner attribute: \
- add an exclamation mark: #![foo]",
- ast::AttrInner => "crate-level attribute should be in the root module",
- };
- cx.span_lint(AttributeUsage, attr.span, msg);
- return;
- }
- }
-
- for &(obs_attr, obs_alter) in obsolete_attrs.iter() {
- if name.equiv(&obs_attr) {
- cx.span_lint(AttributeUsage, attr.span,
- format!("obsolete attribute: {:s}",
- obs_alter).as_slice());
- return;
- }
- }
-
- if !other_attrs.iter().any(|other_attr| { name.equiv(other_attr) }) {
- cx.span_lint(AttributeUsage, attr.span, "unknown attribute");
- }
- }
-}
-
-fn check_unused_attribute(cx: &Context, attrs: &[ast::Attribute]) {
+fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
static ATTRIBUTE_WHITELIST: &'static [&'static str] = &'static [
// FIXME: #14408 whitelist docs since rustdoc looks at them
"doc",
"stable",
"unstable",
];
- for attr in attrs.iter() {
- for &name in ATTRIBUTE_WHITELIST.iter() {
- if attr.check_name(name) {
- break;
- }
+
+ static CRATE_ATTRS: &'static [&'static str] = &'static [
+ "crate_type",
+ "feature",
+ "no_start",
+ "no_main",
+ "no_std",
+ "crate_id",
+ "desc",
+ "comment",
+ "license",
+ "copyright",
+ "no_builtins",
+ ];
+
+ for &name in ATTRIBUTE_WHITELIST.iter() {
+ if attr.check_name(name) {
+ break;
}
+ }
- if !attr::is_used(attr) {
- cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
+ if !attr::is_used(attr) {
+ cx.span_lint(UnusedAttribute, attr.span, "unused attribute");
+ if CRATE_ATTRS.contains(&attr.name().get()) {
+ let msg = match attr.node.style {
+ ast::AttrOuter => "crate-level attribute should be an inner \
+ attribute: add an exclamation mark: #![foo]",
+ ast::AttrInner => "crate-level attribute should be in the \
+ root module",
+ };
+ cx.span_lint(UnusedAttribute, attr.span, msg);
}
}
}
check_item_non_uppercase_statics(cx, it);
check_heap_item(cx, it);
check_missing_doc_item(cx, it);
- check_attrs_usage(cx, it.attrs.as_slice());
- check_unused_attribute(cx, it.attrs.as_slice());
check_raw_ptr_deriving(cx, it);
cx.visit_ids(|v| v.visit_item(it, ()));
fn visit_foreign_item(&mut self, it: &ast::ForeignItem, _: ()) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
- check_attrs_usage(cx, it.attrs.as_slice());
visit::walk_foreign_item(cx, it, ());
})
}
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
self.with_lint_attrs(i.attrs.as_slice(), |cx| {
- check_attrs_usage(cx, i.attrs.as_slice());
-
cx.visit_ids(|v| v.visit_view_item(i, ()));
visit::walk_view_item(cx, i, ());
visit::FkMethod(ident, _, m) => {
self.with_lint_attrs(m.attrs.as_slice(), |cx| {
check_missing_doc_method(cx, m);
- check_attrs_usage(cx, m.attrs.as_slice());
match method_context(cx, m) {
PlainImpl => check_snake_case(cx, "method", ident, span),
fn visit_ty_method(&mut self, t: &ast::TypeMethod, _: ()) {
self.with_lint_attrs(t.attrs.as_slice(), |cx| {
check_missing_doc_ty_method(cx, t);
- check_attrs_usage(cx, t.attrs.as_slice());
check_snake_case(cx, "trait method", t.ident, t.span);
visit::walk_ty_method(cx, t, ());
fn visit_struct_field(&mut self, s: &ast::StructField, _: ()) {
self.with_lint_attrs(s.node.attrs.as_slice(), |cx| {
check_missing_doc_struct_field(cx, s);
- check_attrs_usage(cx, s.node.attrs.as_slice());
visit::walk_struct_field(cx, s, ());
})
fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, _: ()) {
self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
check_missing_doc_variant(cx, v);
- check_attrs_usage(cx, v.node.attrs.as_slice());
visit::walk_variant(cx, v, g, ());
})
// FIXME(#10894) should continue recursing
fn visit_ty(&mut self, _t: &ast::Ty, _: ()) {}
+
+ fn visit_attribute(&mut self, attr: &ast::Attribute, _: ()) {
+ check_unused_attribute(self, attr);
+ }
}
impl<'a> IdVisitingOperation for Context<'a> {
visit::walk_crate(v, krate, ());
});
- check_crate_attrs_usage(cx, krate.attrs.as_slice());
// since the root module isn't visited as an item (because it isn't an item), warn for it
// here.
- check_unused_attribute(cx, krate.attrs.as_slice());
check_missing_doc_attrs(cx,
None,
krate.attrs.as_slice(),
{
// no-op
} else if !ty::type_is_numeric(b_ty) && !ty::type_is_char(b_ty) {
- tcx.sess.span_err(pat.span, "non-numeric type used in range");
+ tcx.sess.span_err(pat.span,
+ "only char and numeric types are allowed in range");
} else {
match valid_range_bounds(fcx.ccx, begin, end) {
Some(false) => {
}
}
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
- fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
- None
- }
}
impl<'a> attr::AttrMetaMethods for &'a Attribute {
fn name(&self) -> InternedString { (**self).name() }
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
- fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
- None
- }
}
#[deriving(Clone, Encodable, Decodable)]
a.attr('target', '_blank');
$(this).append(a);
}, function() {
- $(this).find('a').remove();
+ $(this).find('a.test-arrow').remove();
});
}
}());
if lints {
prog.push_str(r"
#![deny(warnings)]
-#![allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)]
+#![allow(unused_variable, dead_assignment, unused_mut, unused_attribute, dead_code)]
");
}
fn value_str(&self) -> Option<InternedString>;
/// Gets a list of inner meta items from a list MetaItem type.
fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]>;
-
- /**
- * If the meta item is a name-value type with a string value then returns
- * a tuple containing the name and string value, otherwise `None`
- */
- fn name_str_pair(&self) -> Option<(InternedString,InternedString)>;
}
impl AttrMetaMethods for Attribute {
fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
self.node.value.meta_item_list()
}
- fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
- self.meta().name_str_pair()
- }
}
impl AttrMetaMethods for MetaItem {
_ => None
}
}
-
- fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
- self.value_str().map(|s| (self.name(), s))
- }
}
// Annoying, but required to get test_cfg to work
fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
(**self).meta_item_list()
}
- fn name_str_pair(&self) -> Option<(InternedString,InternedString)> {
- (**self).name_str_pair()
- }
}
}
}
+ impl ToSource for ast::Arg {
+ fn to_source(&self) -> String {
+ pprust::arg_to_str(self)
+ }
+ }
+
impl<'a> ToSource for &'a str {
fn to_source(&self) -> String {
let lit = dummy_spanned(ast::LitStr(
impl_to_tokens!(Generics)
impl_to_tokens!(@ast::Expr)
impl_to_tokens!(ast::Block)
+ impl_to_tokens!(ast::Arg)
impl_to_tokens_self!(&'a str)
impl_to_tokens!(())
impl_to_tokens!(char)
to_str(|s| s.print_variant(var))
}
+pub fn arg_to_str(arg: &ast::Arg) -> String {
+ to_str(|s| s.print_arg(arg))
+}
+
pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String {
match vis {
ast::Public => format!("pub {}", s).to_string(),
fn visit_path(&mut self, path: &Path, _id: ast::NodeId, e: E) {
walk_path(self, path, e)
}
+ fn visit_attribute(&mut self, _attr: &Attribute, _e: E) {}
}
pub fn walk_inlined_item<E: Clone, V: Visitor<E>>(visitor: &mut V,
pub fn walk_crate<E: Clone, V: Visitor<E>>(visitor: &mut V, krate: &Crate, env: E) {
- visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env)
+ visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID, env.clone());
+ for attr in krate.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) {
pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) {
match vi.node {
ViewItemExternCrate(name, _, _) => {
- visitor.visit_ident(vi.span, name, env)
+ visitor.visit_ident(vi.span, name, env.clone())
}
ViewItemUse(ref vp) => {
match vp.node {
}
}
}
+ for attr in vi.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) {
match item.node {
ItemStatic(typ, _, expr) => {
visitor.visit_ty(typ, env.clone());
- visitor.visit_expr(expr, env);
+ visitor.visit_expr(expr, env.clone());
}
ItemFn(declaration, fn_style, abi, ref generics, body) => {
visitor.visit_fn(&FkItemFn(item.ident, generics, fn_style, abi),
body,
item.span,
item.id,
- env)
+ env.clone())
}
ItemMod(ref module) => {
- visitor.visit_mod(module, item.span, item.id, env)
+ visitor.visit_mod(module, item.span, item.id, env.clone())
}
ItemForeignMod(ref foreign_module) => {
for view_item in foreign_module.view_items.iter() {
}
ItemTy(typ, ref type_parameters) => {
visitor.visit_ty(typ, env.clone());
- visitor.visit_generics(type_parameters, env)
+ visitor.visit_generics(type_parameters, env.clone())
}
ItemEnum(ref enum_definition, ref type_parameters) => {
visitor.visit_generics(type_parameters, env.clone());
- walk_enum_def(visitor, enum_definition, type_parameters, env)
+ walk_enum_def(visitor, enum_definition, type_parameters, env.clone())
}
ItemImpl(ref type_parameters,
ref trait_reference,
item.ident,
generics,
item.id,
- env)
+ env.clone())
}
ItemTrait(ref generics, _, ref trait_paths, ref methods) => {
visitor.visit_generics(generics, env.clone());
visitor.visit_trait_method(method, env.clone())
}
}
- ItemMac(ref macro) => visitor.visit_mac(macro, env),
+ ItemMac(ref macro) => visitor.visit_mac(macro, env.clone()),
+ }
+ for attr in item.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
}
}
}
}
match variant.node.disr_expr {
- Some(expr) => visitor.visit_expr(expr, env),
+ Some(expr) => visitor.visit_expr(expr, env.clone()),
None => ()
}
+ for attr in variant.node.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) {
match foreign_item.node {
ForeignItemFn(function_declaration, ref generics) => {
walk_fn_decl(visitor, function_declaration, env.clone());
- visitor.visit_generics(generics, env)
+ visitor.visit_generics(generics, env.clone())
}
- ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env),
+ ForeignItemStatic(typ, _) => visitor.visit_ty(typ, env.clone()),
+ }
+
+ for attr in foreign_item.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
}
}
method.body,
method.span,
method.id,
- env)
+ env.clone());
+ for attr in method.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn walk_fn<E: Clone, V: Visitor<E>>(visitor: &mut V,
visitor.visit_ty(argument_type.ty, env.clone())
}
visitor.visit_generics(&method_type.generics, env.clone());
- visitor.visit_ty(method_type.decl.output, env);
+ visitor.visit_ty(method_type.decl.output, env.clone());
+ for attr in method_type.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn walk_trait_method<E: Clone, V: Visitor<E>>(visitor: &mut V,
_ => {}
}
- visitor.visit_ty(struct_field.node.ty, env)
+ visitor.visit_ty(struct_field.node.ty, env.clone());
+
+ for attr in struct_field.node.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
pub fn walk_block<E: Clone, V: Visitor<E>>(visitor: &mut V, block: &Block, env: E) {
visitor.visit_pat(*pattern, env.clone())
}
walk_expr_opt(visitor, arm.guard, env.clone());
- visitor.visit_expr(arm.body, env)
+ visitor.visit_expr(arm.body, env.clone());
+ for attr in arm.attrs.iter() {
+ visitor.visit_attribute(attr, env.clone());
+ }
}
-// 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.
+// The Computer Language Benchmarks Game
+// http://benchmarksgame.alioth.debian.org/
//
-// 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.
+// contributed by the Rust Project Developers
+
+// Copyright (c) 2014 The Rust Project Developers
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// - Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// - Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in
+// the documentation and/or other materials provided with the
+// distribution.
+//
+// - Neither the name of "The Computer Language Benchmarks Game" nor
+// the name of "The Computer Language Shootout Benchmarks" nor the
+// names of its contributors may be used to endorse or promote
+// products derived from this software without specific prior
+// written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
// FIXME(#13725) windows needs fixing.
// ignore-win32
struct A { a: int, b: Box<int> }
-fn borrow<T>(_: &T) { }
-
-fn use_after_move() {
+fn deref_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
drop(*x.b); //~ ERROR use of partially moved value: `*x.b`
}
-fn use_after_fu_move() {
+fn deref_after_fu_move() {
let x = A { a: 1, b: box 2 };
let y = A { a: 3, .. x };
drop(*x.b); //~ ERROR use of partially moved value: `*x.b`
fn borrow_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
- borrow(&x.b); //~ ERROR use of moved value: `x.b`
+ let p = &x.b; //~ ERROR use of moved value: `x.b`
+ drop(**p);
}
fn borrow_after_fu_move() {
let x = A { a: 1, b: box 2 };
let _y = A { a: 3, .. x };
- borrow(&x.b); //~ ERROR use of moved value: `x.b`
+ let p = &x.b; //~ ERROR use of moved value: `x.b`
+ drop(**p);
}
fn move_after_borrow() {
let x = A { a: 1, b: box 2 };
- let y = &x.b;
+ let p = &x.b;
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
- borrow(&*y);
+ drop(**p);
}
fn fu_move_after_borrow() {
let x = A { a: 1, b: box 2 };
- let y = &x.b;
- let _z = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
- borrow(&*y);
+ let p = &x.b;
+ let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
+ drop(**p);
}
fn mut_borrow_after_mut_borrow() {
let mut x = A { a: 1, b: box 2 };
- let y = &mut x.a;
- let z = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
- drop(*y);
- drop(*z);
+ let p = &mut x.a;
+ let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
+ drop(*p);
+ drop(*q);
}
fn move_after_move() {
// The following functions aren't yet accepted, but they should be.
-fn use_after_field_assign_after_uninit() {
+fn move_after_borrow_correct() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
+ drop(*p);
+}
+
+fn fu_move_after_borrow_correct() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
+ drop(*p);
+}
+
+fn copy_after_field_assign_after_uninit() {
let mut x: A;
x.a = 1;
drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
fn borrow_after_field_assign_after_uninit() {
let mut x: A;
x.a = 1;
- borrow(&x.a); //~ ERROR use of possibly uninitialized variable: `x.a`
+ let p = &x.a; //~ ERROR use of possibly uninitialized variable: `x.a`
+ drop(*p);
}
fn move_after_field_assign_after_uninit() {
}
fn main() {
- use_after_move();
- use_after_fu_move();
+ deref_after_move();
+ deref_after_fu_move();
borrow_after_move();
borrow_after_fu_move();
fu_move_after_move();
fu_move_after_fu_move();
- use_after_field_assign_after_uninit();
+ move_after_borrow_correct();
+ fu_move_after_borrow_correct();
+
+ copy_after_field_assign_after_uninit();
borrow_after_field_assign_after_uninit();
move_after_field_assign_after_uninit();
}
// When denying at the crate level, be sure to not get random warnings from the
// injected intrinsics by the compiler.
-#![deny(attribute_usage)]
#![deny(unused_attribute)]
mod a {
- #![crate_type = "bin"] //~ ERROR: crate-level attribute
- //~^ ERROR: unused attribute
+ #![crate_type = "bin"] //~ ERROR unused attribute
+ //~^ ERROR should be in the root module
}
-#[crate_type = "bin"] fn main() {} //~ ERROR: crate-level attribute
- //~^ ERROR: unused attribute
+#[crate_type = "bin"] fn main() {} //~ ERROR unused attribute
+ //~^ ERROR should be an inner
// When denying at the crate level, be sure to not get random warnings from the
// injected intrinsics by the compiler.
-#![deny(attribute_usage)]
#![deny(unused_attribute)]
#![allow(dead_code)]
-#[abi="stdcall"] extern {} //~ ERROR: obsolete attribute
- //~^ ERROR: unused attribute
+#[abi="stdcall"] extern {} //~ ERROR unused attribute
-#[fixed_stack_segment] fn f() {} //~ ERROR: obsolete attribute
- //~^ ERROR: unused attribute
+#[fixed_stack_segment] fn f() {} //~ ERROR unused attribute
fn main() {}
// When denying at the crate level, be sure to not get random warnings from the
// injected intrinsics by the compiler.
-#![deny(attribute_usage)]
#![deny(unused_attribute)]
-#![mutable_doc] //~ ERROR: unknown crate attribute
- //~^ ERROR: unused attribute
+#![mutable_doc] //~ ERROR unused attribute
-#[dance] mod a {} //~ ERROR: unknown attribute
- //~^ ERROR: unused attribute
+#[dance] mod a {} //~ ERROR unused attribute
-#[dance] fn main() {} //~ ERROR: unknown attribute
- //~^ ERROR: unused attribute
+#[dance] fn main() {} //~ ERROR unused attribute
// except according to those terms.
//error-pattern: lower range bound
-//error-pattern: non-numeric
+//error-pattern: only char and numeric types
//error-pattern: mismatched types
fn main() {
--- /dev/null
+// 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.
+#![deny(unused_attribute)]
+#![allow(dead_code, unused_imports)]
+
+#![foo] //~ ERROR unused attribute
+
+#[foo] //~ ERROR unused attribute
+extern crate std;
+
+#[foo] //~ ERROR unused attribute
+use std::collections;
+
+#[foo] //~ ERROR unused attribute
+extern "C" {
+ #[foo] //~ ERROR unused attribute
+ fn foo();
+}
+
+#[foo] //~ ERROR unused attribute
+mod foo {
+ #[foo] //~ ERROR unused attribute
+ pub enum Foo {
+ #[foo] //~ ERROR unused attribute
+ Bar,
+ }
+}
+
+#[foo] //~ ERROR unused attribute
+fn bar(f: foo::Foo) {
+ match f {
+ #[foo] //~ ERROR unused attribute
+ foo::Bar => {}
+ }
+}
+
+#[foo] //~ ERROR unused attribute
+struct Foo {
+ #[foo] //~ ERROR unused attribute
+ a: int
+}
+
+#[foo] //~ ERROR unused attribute
+trait Baz {
+ #[foo] //~ ERROR unused attribute
+ fn blah();
+ #[foo] //~ ERROR unused attribute
+ fn blah2() {}
+}
+
+fn main() {}
struct A { a: int, b: Box<int> }
struct B { a: Box<int>, b: Box<int> }
-fn borrow<T>(_: &T) { }
-
-fn move_after_use() {
+fn move_after_copy() {
let x = A { a: 1, b: box 2 };
drop(x.a);
drop(x.b);
}
-fn move_after_fu_use() {
+fn move_after_fu_copy() {
let x = A { a: 1, b: box 2 };
let _y = A { b: box 3, .. x };
drop(x.b);
}
-fn fu_move_after_use() {
+fn fu_move_after_copy() {
let x = A { a: 1, b: box 2 };
drop(x.a);
- let y = A { a: 3, .. x };
- drop(y.b);
+ let _y = A { a: 3, .. x };
}
-fn fu_move_after_fu_use() {
+fn fu_move_after_fu_copy() {
let x = A { a: 1, b: box 2 };
let _y = A { b: box 3, .. x };
- let z = A { a: 4, .. x };
- drop(z.b);
+ let _z = A { a: 4, .. x };
}
-fn use_after_move() {
+fn copy_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
drop(x.a);
}
-fn use_after_fu_move() {
+fn copy_after_fu_move() {
let x = A { a: 1, b: box 2 };
let y = A { a: 3, .. x };
drop(x.a);
- drop(y.b);
}
-fn fu_use_after_move() {
+fn fu_copy_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
let _y = A { b: box 3, .. x };
}
-fn fu_use_after_fu_move() {
+fn fu_copy_after_fu_move() {
let x = A { a: 1, b: box 2 };
- let y = A { a: 3, .. x };
+ let _y = A { a: 3, .. x };
let _z = A { b: box 3, .. x };
- drop(y.b);
}
fn borrow_after_move() {
let x = A { a: 1, b: box 2 };
drop(x.b);
- borrow(&x.a);
+ let p = &x.a;
+ drop(*p);
}
fn borrow_after_fu_move() {
let x = A { a: 1, b: box 2 };
- let y = A { a: 3, .. x };
- borrow(&x.a);
- drop(y.b);
-}
-
-fn move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- borrow(&x.a);
- drop(x.b);
-}
-
-fn fu_move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- borrow(&x.a);
- let y = A { a: 3, .. x };
- drop(y.b);
+ let _y = A { a: 3, .. x };
+ let p = &x.a;
+ drop(*p);
}
fn mut_borrow_after_mut_borrow() {
let mut x = A { a: 1, b: box 2 };
- let y = &mut x.a;
- let z = &mut x.b;
- drop(*y);
- drop(**z);
+ let p = &mut x.a;
+ let q = &mut x.b;
+ drop(*p);
+ drop(**q);
}
fn move_after_move() {
let x = B { a: box 1, b: box 2 };
let y = B { a: box 3, .. x };
drop(x.a);
- drop(y.b);
}
fn fu_move_after_move() {
fn fu_move_after_fu_move() {
let x = B { a: box 1, b: box 2 };
- let y = B { b: box 3, .. x };
- let z = B { a: box 4, .. x };
- drop(y.a);
- drop(z.b);
+ let _y = B { b: box 3, .. x };
+ let _z = B { a: box 4, .. x };
}
-fn use_after_assign_after_move() {
+fn copy_after_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x = A { a: 3, b: box 4 };
drop(*x.b);
}
-fn use_after_field_assign_after_move() {
+fn copy_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ drop(*x.b);
+}
+
+fn copy_after_field_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x.b = box 3;
drop(*x.b);
}
+fn copy_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(*x.b);
+}
+
fn borrow_after_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x = A { a: 3, b: box 4 };
- borrow(&x.b);
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ let p = &x.b;
+ drop(**p);
}
fn borrow_after_field_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
drop(x.b);
x.b = box 3;
- borrow(&x.b);
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ let p = &x.b;
+ drop(**p);
}
fn move_after_assign_after_move() {
let mut x = A { a: 1, b: box 2 };
- let y = x.b;
+ let _y = x.b;
+ x = A { a: 3, b: box 4 };
+ drop(x.b);
+}
+
+fn move_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
x = A { a: 3, b: box 4 };
drop(x.b);
- drop(y);
}
fn move_after_field_assign_after_move() {
drop(x.b);
}
-fn use_after_assign_after_uninit() {
+fn move_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(x.b);
+}
+
+fn copy_after_assign_after_uninit() {
let mut x: A;
x = A { a: 1, b: box 2 };
drop(x.a);
fn borrow_after_assign_after_uninit() {
let mut x: A;
x = A { a: 1, b: box 2 };
- borrow(&x.a);
+ let p = &x.a;
+ drop(*p);
}
fn move_after_assign_after_uninit() {
}
fn main() {
- move_after_use();
- move_after_fu_use();
- fu_move_after_use();
- fu_move_after_fu_use();
- use_after_move();
- use_after_fu_move();
- fu_use_after_move();
- fu_use_after_fu_move();
+ move_after_copy();
+ move_after_fu_copy();
+ fu_move_after_copy();
+ fu_move_after_fu_copy();
+ copy_after_move();
+ copy_after_fu_move();
+ fu_copy_after_move();
+ fu_copy_after_fu_move();
borrow_after_move();
borrow_after_fu_move();
- move_after_borrow();
- fu_move_after_borrow();
mut_borrow_after_mut_borrow();
move_after_move();
fu_move_after_move();
fu_move_after_fu_move();
- use_after_assign_after_move();
- use_after_field_assign_after_move();
+ copy_after_assign_after_move();
+ copy_after_assign_after_fu_move();
+ copy_after_field_assign_after_move();
+ copy_after_field_assign_after_fu_move();
+
borrow_after_assign_after_move();
+ borrow_after_assign_after_fu_move();
borrow_after_field_assign_after_move();
+ borrow_after_field_assign_after_fu_move();
+
move_after_assign_after_move();
+ move_after_assign_after_fu_move();
move_after_field_assign_after_move();
+ move_after_field_assign_after_fu_move();
- use_after_assign_after_uninit();
+ copy_after_assign_after_uninit();
borrow_after_assign_after_uninit();
move_after_assign_after_uninit();
}