esac
putvar CFG_LLDB_PYTHON
+# Do some sanity checks if running on buildbot
+# (these env vars are set by rust-buildbot)
+if [ -n "$RUST_DIST_SERVER" -a -n "$ALLOW_NONZERO_RLIMIT_CORE" ]; then
+ # Frequently the llvm submodule directory is broken by the build
+ # being killed
+ llvm_lock="${CFG_SRC_DIR}/.git/modules/src/llvm/index.lock"
+ if [ -e "$llvm_lock" ]; then
+ step_msg "removing $llvm_lock"
+ rm -f "$llvm_lock"
+ fi
+fi
+
step_msg "looking for target specific programs"
probe CFG_ADB adb
--- /dev/null
+# rustbuild-only target
```
The `--incremental` flag will store incremental compilation artifacts
-in `build/stage0-incremental`. Note that we only use incremental
+in `build/<host>/stage0-incremental`. Note that we only use incremental
compilation for the stage0 -> stage1 compilation -- this is because
the stage1 compiler is changing, and we don't try to cache and reuse
incremental artifacts across different versions of the compiler. For
```
The `no_run` attribute will compile your code, but not run it. This is
-important for examples such as "Here's how to start up a network service,"
-which you would want to make sure compile, but might run in an infinite loop!
+important for examples such as "Here's how to retrieve a web page,"
+which you would want to ensure compiles, but might be run in a test
+environment that has no network access.
### Documenting modules
# Testing and concurrency
-One thing that is important to note when writing tests is that they may be run
-concurrently using threads. For this reason you should take care that your tests
-are written in such a way as to not depend on each-other, or on any shared
-state. "Shared state" can also include the environment, such as the current
-working directory, or environment variables.
+It is important to note that tests are run concurrently using threads. For this
+reason, care should be taken to ensure your tests do not depend on each-other,
+or on any shared state. "Shared state" can also include the environment, such
+as the current working directory, or environment variables.
If this is an issue it is possible to control this concurrency, either by
setting the environment variable `RUST_TEST_THREADS`, or by passing the argument
// targets, which means we have to build the alloc_jemalloc crate
// for targets like emscripten, even if we don't use it.
if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") ||
- target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") {
+ target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") ||
+ target.contains("redox") {
println!("cargo:rustc-cfg=dummy_jemalloc");
return;
}
issue = "27783")]
#![feature(allocator)]
#![feature(staged_api)]
-#![cfg_attr(unix, feature(libc))]
+#![cfg_attr(any(unix, target_os = "redox"), feature(libc))]
// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
imp::usable_size(size, align)
}
-#[cfg(unix)]
+#[cfg(any(unix, target_os = "redox"))]
mod imp {
extern crate libc;
}
}
- #[cfg(target_os = "android")]
+ #[cfg(any(target_os = "android", target_os = "redox"))]
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
// On android we currently target API level 9 which unfortunately
// doesn't have the `posix_memalign` API used below. Instead we use
libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8
}
- #[cfg(not(target_os = "android"))]
+ #[cfg(not(any(target_os = "android", target_os = "redox")))]
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
let mut out = ptr::null_mut();
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
//! A doubly-linked list with owned nodes.
//!
-//! The `LinkedList` allows pushing and popping elements at either end and is thus
-//! efficiently usable as a double-ended queue.
+//! The `LinkedList` allows pushing and popping elements at either end
+//! in constant time.
+//!
+//! Almost always it is better to use `Vec` or [`VecDeque`] instead of
+//! [`LinkedList`]. In general, array-based containers are faster,
+//! more memory efficient and make better use of CPU cache.
+//!
+//! [`LinkedList`]: ../linked_list/struct.LinkedList.html
+//! [`VecDeque`]: ../vec_deque/struct.VecDeque.html
#![stable(feature = "rust1", since = "1.0.0")]
use super::SpecExtend;
-/// A doubly-linked list.
+/// A doubly-linked list with owned nodes.
+///
+/// The `LinkedList` allows pushing and popping elements at either end
+/// in constant time.
+///
+/// Almost always it is better to use `Vec` or `VecDeque` instead of
+/// `LinkedList`. In general, array-based containers are faster,
+/// more memory efficient and make better use of CPU cache.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LinkedList<T> {
head: Option<Shared<Node<T>>>,
"atomic_thread_fence.c"]);
}
- if !target.contains("windows") {
+ if !target.contains("redox") && !target.contains("windows") {
sources.extend(&["emutls.c"]);
}
-Subproject commit 0ac39c5ccf6a04395b7c40dd62321cb91f63f160
+Subproject commit e49e9bb7c3d9c7f2fd893f0ee0db81617b8db21f
}
pub trait Resolver {
- // Resolve a global hir path generated by the lowerer when expanding `for`, `if let`, etc.
+ // Resolve a hir path generated by the lowerer when expanding `for`, `if let`, etc.
fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool);
// Obtain the resolution for a node id
let proj_start = p.segments.len() - resolution.depth;
let path = P(hir::Path {
- global: p.global,
def: resolution.base_def,
segments: p.segments[..proj_start].iter().enumerate().map(|(i, segment)| {
let param_mode = match (qself_position, param_mode) {
id: NodeId,
p: &Path,
name: Option<Name>,
- param_mode: ParamMode)
+ param_mode: ParamMode,
+ defaults_to_global: bool)
-> hir::Path {
+ let mut segments = p.segments.iter();
+ if defaults_to_global && p.is_global() {
+ segments.next();
+ }
+
hir::Path {
- global: p.global,
def: self.expect_full_def(id),
- segments: p.segments.iter().map(|segment| {
+ segments: segments.map(|segment| {
self.lower_path_segment(segment, param_mode)
}).chain(name.map(|name| {
hir::PathSegment {
fn lower_path(&mut self,
id: NodeId,
p: &Path,
- param_mode: ParamMode)
+ param_mode: ParamMode,
+ defaults_to_global: bool)
-> hir::Path {
- self.lower_path_extra(id, p, None, param_mode)
+ self.lower_path_extra(id, p, None, param_mode, defaults_to_global)
}
fn lower_path_segment(&mut self,
// Check if the where clause type is a plain type parameter.
match bound_pred.bounded_ty.node {
TyKind::Path(None, ref path)
- if !path.global && path.segments.len() == 1 &&
- bound_pred.bound_lifetimes.is_empty() => {
+ if path.segments.len() == 1 &&
+ bound_pred.bound_lifetimes.is_empty() => {
if let Some(Def::TyParam(def_id)) =
self.resolver.get_resolution(bound_pred.bounded_ty.id)
.map(|d| d.base_def) {
span}) => {
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
id: id,
- path: self.lower_path(id, path, ParamMode::Explicit),
+ path: self.lower_path(id, path, ParamMode::Explicit, false),
ty: self.lower_ty(ty),
span: span,
})
fn lower_trait_ref(&mut self, p: &TraitRef) -> hir::TraitRef {
hir::TraitRef {
- path: self.lower_path(p.ref_id, &p.path, ParamMode::Explicit),
+ path: self.lower_path(p.ref_id, &p.path, ParamMode::Explicit, false),
ref_id: p.ref_id,
}
}
};
let mut path = self.lower_path_extra(import.id, path, suffix,
- ParamMode::Explicit);
+ ParamMode::Explicit, true);
path.span = span;
self.items.insert(import.id, hir::Item {
id: import.id,
path
}
};
- let path = P(self.lower_path(id, path, ParamMode::Explicit));
+ let path = P(self.lower_path(id, path, ParamMode::Explicit, true));
let kind = match view_path.node {
ViewPathSimple(ident, _) => {
*name = ident.name;
Some(def) => {
hir::PatKind::Path(hir::QPath::Resolved(None, P(hir::Path {
span: pth1.span,
- global: false,
def: def,
segments: hir_vec![
hir::PathSegment::from_name(pth1.node.name)
Visibility::Crate(_) => hir::Visibility::Crate,
Visibility::Restricted { ref path, id } => {
hir::Visibility::Restricted {
- path: P(self.lower_path(id, path, ParamMode::Explicit)),
+ path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
id: id
}
}
let expr_path = hir::ExprPath(hir::QPath::Resolved(None, P(hir::Path {
span: span,
- global: false,
def: def,
segments: hir_vec![hir::PathSegment::from_name(id)],
})));
/// `fld.cx.use_std`, and `::core::b::c::d` otherwise.
/// The path is also resolved according to `is_value`.
fn std_path(&mut self, span: Span, components: &[&str], is_value: bool) -> hir::Path {
- let idents = self.crate_root.iter().chain(components);
-
- let segments: Vec<_> = idents.map(|name| {
- hir::PathSegment::from_name(Symbol::intern(name))
- }).collect();
-
let mut path = hir::Path {
span: span,
- global: true,
def: Def::Err,
- segments: segments.into(),
+ segments: iter::once(keywords::CrateRoot.name()).chain({
+ self.crate_root.into_iter().chain(components.iter().cloned()).map(Symbol::intern)
+ }).map(hir::PathSegment::from_name).collect(),
};
self.resolver.resolve_hir_path(&mut path, is_value);
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Path {
pub span: Span,
- /// A `::foo` path, is relative to the crate root rather than current
- /// module (like paths in an import).
- pub global: bool,
/// The definition that the path resolved to.
pub def: Def,
/// The segments in the path: the things separated by `::`.
pub segments: HirVec<PathSegment>,
}
+impl Path {
+ pub fn is_global(&self) -> bool {
+ !self.segments.is_empty() && self.segments[0].name == keywords::CrateRoot.name()
+ }
+}
+
impl fmt::Debug for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "path({})", print::path_to_string(self))
-> io::Result<()> {
self.maybe_print_comment(path.span.lo)?;
- let mut first = !path.global;
- for segment in &path.segments {
- if first {
- first = false
- } else {
+ for (i, segment) in path.segments.iter().enumerate() {
+ if i > 0 {
word(&mut self.s, "::")?
}
-
- self.print_name(segment.name)?;
-
- self.print_path_parameters(&segment.parameters, colons_before_params)?;
+ if segment.name != keywords::CrateRoot.name() && segment.name != "$crate" {
+ self.print_name(segment.name)?;
+ self.print_path_parameters(&segment.parameters, colons_before_params)?;
+ }
}
Ok(())
space(&mut self.s)?;
self.word_space("as")?;
- let mut first = !path.global;
- for segment in &path.segments[..path.segments.len() - 1] {
- if first {
- first = false
- } else {
+ for (i, segment) in path.segments[..path.segments.len() - 1].iter().enumerate() {
+ if i > 0 {
word(&mut self.s, "::")?
}
- self.print_name(segment.name)?;
- self.print_path_parameters(&segment.parameters, colons_before_params)?;
+ if segment.name != keywords::CrateRoot.name() && segment.name != "$crate" {
+ self.print_name(segment.name)?;
+ self.print_path_parameters(&segment.parameters, colons_before_params)?;
+ }
}
word(&mut self.s, ">")?;
new_segs.push(new_seg);
hir::Path {
span: path.span,
- global: path.global,
def: path.def,
segments: new_segs.into()
}
let vendor = &sess.target.target.target_vendor;
let max_atomic_width = sess.target.target.max_atomic_width();
- let fam = if let Some(ref fam) = sess.target.target.options.target_family {
- Symbol::intern(fam)
- } else if sess.target.target.options.is_like_windows {
- Symbol::intern("windows")
- } else {
- Symbol::intern("unix")
- };
-
let mut ret = HashSet::new();
// Target bindings.
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
- ret.insert((Symbol::intern("target_family"), Some(fam)));
+ if let Some(ref fam) = sess.target.target.options.target_family {
+ ret.insert((Symbol::intern("target_family"), Some(Symbol::intern(fam))));
+ if fam == "windows" || fam == "unix" {
+ ret.insert((Symbol::intern(fam), None));
+ }
+ }
ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch))));
ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end))));
ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz))));
ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env))));
ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor))));
- if fam == "windows" || fam == "unix" {
- ret.insert((fam, None));
- }
if sess.target.target.options.has_elf_tls {
ret.insert((Symbol::intern("target_thread_local"), None));
}
});
}
+ // Disable field reordering until we can decide what to do.
+ // The odd pattern here avoids a warning about the value never being read.
+ if can_optimize { can_optimize = false }
+
let (optimize, sort_ascending) = match kind {
StructKind::AlwaysSizedUnivariant => (can_optimize, false),
StructKind::MaybeUnsizedUnivariant => (can_optimize, false),
function_sections: false,
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
is_like_osx: true,
has_rpath: true,
dll_prefix: "lib".to_string(),
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
position_independent_executables: true,
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
pre_link_args: vec![
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
pre_link_args: vec![
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
pre_link_args: vec![
dynamic_linking: true,
executables: true,
has_rpath: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
.. Default::default()
}
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
pre_link_args: vec![
mod windows_msvc_base;
mod thumb_base;
mod fuchsia_base;
+mod redox_base;
pub type TargetResult = Result<Target, String>;
("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia),
("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia),
+ ("x86_64-unknown-redox", x86_64_unknown_redox),
+
("i386-apple-ios", i386_apple_ios),
("x86_64-apple-ios", x86_64_apple_ios),
("aarch64-apple-ios", aarch64_apple_ios),
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
pre_link_args: vec![
TargetOptions {
dynamic_linking: true,
executables: true,
+ target_family: Some("unix".to_string()),
linker_is_gnu: true,
has_rpath: true,
is_like_openbsd: true,
--- /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.
+
+use PanicStrategy;
+use target::TargetOptions;
+use std::default::Default;
+
+pub fn opts() -> TargetOptions {
+ TargetOptions {
+ pre_link_args: vec![
+ // We want to be able to strip as much executable code as possible
+ // from the linker command line, and this flag indicates to the
+ // linker that it can avoid linking in dynamic libraries that don't
+ // actually satisfy any symbols up to that point (as with many other
+ // resolutions the linker does). This option only applies to all
+ // following libraries so we're sure to pass it as one of the first
+ // arguments.
+ "-Wl,--as-needed".to_string(),
+
+ // Always enable NX protection when it is available
+ "-Wl,-z,noexecstack".to_string(),
+
+ // Static link
+ "-static".to_string()
+ ],
+ late_link_args: vec![
+ "-lc".to_string(),
+ "-lm".to_string()
+ ],
+ executables: true,
+ relocation_model: "static".to_string(),
+ disable_redzone: true,
+ eliminate_frame_pointer: false,
+ target_family: None,
+ linker_is_gnu: true,
+ no_default_libraries: true,
+ lib_allocation_crate: "alloc_system".to_string(),
+ exe_allocation_crate: "alloc_system".to_string(),
+ has_elf_tls: true,
+ panic_strategy: PanicStrategy::Abort,
+ .. Default::default()
+ }
+}
dynamic_linking: true,
executables: true,
has_rpath: true,
+ target_family: Some("unix".to_string()),
is_like_solaris: true,
exe_allocation_crate: super::maybe_jemalloc(),
staticlib_prefix: "".to_string(),
staticlib_suffix: ".lib".to_string(),
no_default_libraries: true,
+ target_family: Some("windows".to_string()),
is_like_windows: true,
allows_weak_linkage: false,
pre_link_args: vec![
exe_suffix: ".exe".to_string(),
staticlib_prefix: "".to_string(),
staticlib_suffix: ".lib".to_string(),
+ target_family: Some("windows".to_string()),
is_like_windows: true,
is_like_msvc: true,
pre_link_args: vec![
--- /dev/null
+// 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 <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.
+
+use target::{Target, TargetResult};
+
+pub fn target() -> TargetResult {
+ let mut base = super::redox_base::opts();
+ base.cpu = "x86-64".to_string();
+ base.max_atomic_width = Some(64);
+ base.pre_link_args.push("-m64".to_string());
+
+ Ok(Target {
+ llvm_target: "x86_64-unknown-redox".to_string(),
+ target_endian: "little".to_string(),
+ target_pointer_width: "64".to_string(),
+ data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
+ arch: "x86_64".to_string(),
+ target_os: "redox".to_string(),
+ target_env: "".to_string(),
+ target_vendor: "unknown".to_string(),
+ options: base,
+ })
+}
let v = ctor.variant_for_adt(adt);
let qpath = hir::QPath::Resolved(None, P(hir::Path {
span: DUMMY_SP,
- global: false,
def: Def::Err,
segments: vec![hir::PathSegment::from_name(v.name)].into(),
}));
}
});
+ let whitelisted_legacy_custom_derives = registry.take_whitelisted_custom_derives();
let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
llvm_passes, attributes, mir_passes, .. } = registry;
let resolver_arenas = Resolver::arenas();
let mut resolver =
Resolver::new(sess, &krate, make_glob_map, &mut crate_loader, &resolver_arenas);
+ resolver.whitelisted_legacy_custom_derives = whitelisted_legacy_custom_derives;
syntax_ext::register_builtins(&mut resolver, syntax_exts, sess.features.borrow().quote);
krate = time(time_passes, "expansion", || {
SawStructField,
SawVariant,
SawQPath,
- SawPath(bool),
SawPathSegment,
SawPathParameters,
SawBlock,
fn visit_path(&mut self, path: &'tcx Path, _: ast::NodeId) {
debug!("visit_path: st={:?}", self.st);
- SawPath(path.global).hash(self.st);
hash_span!(self, path.span);
visit::walk_path(self, path)
}
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
// Lint for constants that look like binding identifiers (#7526)
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.node {
- if !path.global && path.segments.len() == 1 && path.segments[0].parameters.is_empty() {
+ if path.segments.len() == 1 && path.segments[0].parameters.is_empty() {
if let Def::Const(..) = path.def {
NonUpperCaseGlobals::check_upper_case(cx,
"constant in pattern",
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
unsafe {
- assert!(index < LLVMCountParams(llfn));
+ assert!(index < LLVMCountParams(llfn),
+ "out of bounds argument access: {} out of {} arguments", index, LLVMCountParams(llfn));
LLVMGetParam(llfn, index)
}
}
}
fn visit_path(&mut self, path: &'a Path, id: NodeId) {
- if path.global && path.segments.len() > 0 {
- let ident = path.segments[0].identifier;
+ if path.segments.len() >= 2 && path.is_global() {
+ let ident = path.segments[1].identifier;
if token::Ident(ident).is_path_segment_keyword() {
self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
id,
#[doc(hidden)]
pub attributes: Vec<(String, AttributeType)>,
+
+ whitelisted_custom_derives: Vec<ast::Name>,
}
impl<'a> Registry<'a> {
llvm_passes: vec![],
attributes: vec![],
mir_passes: Vec::new(),
+ whitelisted_custom_derives: Vec::new(),
}
}
}));
}
+ /// This can be used in place of `register_syntax_extension` to register legacy custom derives
+ /// (i.e. attribute syntax extensions whose name begins with `derive_`). Legacy custom
+ /// derives defined by this function do not trigger deprecation warnings when used.
+ #[unstable(feature = "rustc_private", issue = "27812")]
+ #[rustc_deprecated(since = "1.15.0", reason = "replaced by macros 1.1 (RFC 1861)")]
+ pub fn register_custom_derive(&mut self, name: ast::Name, extension: SyntaxExtension) {
+ assert!(name.as_str().starts_with("derive_"));
+ self.whitelisted_custom_derives.push(name);
+ self.register_syntax_extension(name, extension);
+ }
+
+ pub fn take_whitelisted_custom_derives(&mut self) -> Vec<ast::Name> {
+ ::std::mem::replace(&mut self.whitelisted_custom_derives, Vec::new())
+ }
+
/// Register a macro of the usual kind.
///
/// This is a convenience wrapper for `register_syntax_extension`.
use syntax::ext::expand::mark_tts;
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
+use syntax::parse::token;
use syntax::symbol::keywords;
use syntax::visit::{self, Visitor};
// Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST;
// for simple paths we have to munge the path a little.
- let module_path: Vec<_> = match view_path.node {
+ let mut module_path: Vec<_> = match view_path.node {
ViewPathSimple(_, ref full_path) => {
full_path.segments
.split_last()
}
};
+ // This can be removed once warning cycle #36888 is complete.
+ if module_path.len() >= 2 && module_path[0].name == keywords::CrateRoot.name() &&
+ token::Ident(module_path[1]).is_path_segment_keyword() {
+ module_path.remove(0);
+ }
+
// Build up the import directives.
let is_prelude = attr::contains_name(&item.attrs, "prelude_import");
let rename = node.rename.unwrap_or(node.name);
(module_path.clone(), node.name, rename)
} else {
- let ident = match module_path.last() {
- Some(&ident) => ident,
- None => {
- resolve_error(
- self,
- source_item.span,
- ResolutionError::
- SelfImportOnlyInImportListWithNonEmptyPrefix
- );
- continue;
- }
- };
+ let ident = *module_path.last().unwrap();
+ if ident.name == keywords::CrateRoot.name() {
+ resolve_error(
+ self,
+ source_item.span,
+ ResolutionError::
+ SelfImportOnlyInImportListWithNonEmptyPrefix
+ );
+ continue;
+ }
let module_path = module_path.split_last().unwrap().1;
let rename = node.rename.unwrap_or(ident);
(module_path.to_vec(), ident, rename)
fn visit_poly_trait_ref(&mut self,
tref: &'tcx ast::PolyTraitRef,
m: &'tcx ast::TraitBoundModifier) {
- let ast::Path { ref segments, span, global } = tref.trait_ref.path;
+ let ast::Path { ref segments, span } = tref.trait_ref.path;
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
- let def = self.resolve_trait_reference(&path, global, None, span);
+ let def = self.resolve_trait_reference(&path, None, span);
self.record_def(tref.trait_ref.ref_id, def);
visit::walk_poly_trait_ref(self, tref, m);
}
}
}
-#[derive(Copy, Clone, PartialEq)]
-enum PathScope {
- Global,
- Lexical,
- Import,
-}
-
#[derive(Clone)]
enum PathResult<'a> {
Module(Module<'a>),
resolutions: RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>,
legacy_macro_resolutions: RefCell<Vec<(Mark, Ident, Span)>>,
- macro_resolutions: RefCell<Vec<(Box<[Ident]>, PathScope, Span)>>,
+ macro_resolutions: RefCell<Vec<(Box<[Ident]>, Span)>>,
// Macro invocations that can expand into items in this module.
unresolved_invocations: RefCell<FxHashSet<Mark>>,
lexical_macro_resolutions: Vec<(Name, &'a Cell<LegacyScope<'a>>)>,
macro_map: FxHashMap<DefId, Rc<SyntaxExtension>>,
macro_exports: Vec<Export>,
+ pub whitelisted_legacy_custom_derives: Vec<Name>,
// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
impl<'a> hir::lowering::Resolver for Resolver<'a> {
fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool) {
let namespace = if is_value { ValueNS } else { TypeNS };
- let hir::Path { ref segments, span, global, ref mut def } = *path;
+ let hir::Path { ref segments, span, ref mut def } = *path;
let path: Vec<_> = segments.iter().map(|seg| Ident::with_empty_ctxt(seg.name)).collect();
- let scope = if global { PathScope::Global } else { PathScope::Lexical };
- match self.resolve_path(&path, scope, Some(namespace), Some(span)) {
+ match self.resolve_path(&path, Some(namespace), Some(span)) {
PathResult::Module(module) => *def = module.def().unwrap(),
PathResult::NonModule(path_res) if path_res.depth == 0 => *def = path_res.base_def,
- PathResult::NonModule(..) => match self.resolve_path(&path, scope, None, Some(span)) {
+ PathResult::NonModule(..) => match self.resolve_path(&path, None, Some(span)) {
PathResult::Failed(msg, _) => {
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
}
macro_exports: Vec::new(),
invocations: invocations,
name_already_seen: FxHashMap(),
+ whitelisted_legacy_custom_derives: Vec::new(),
}
}
prefix.segments.iter().map(|seg| seg.identifier).collect();
// Resolve prefix of an import with empty braces (issue #28388)
if items.is_empty() && !prefix.segments.is_empty() {
- let (scope, span) = (PathScope::Import, prefix.span);
+ let span = prefix.span;
// FIXME(#38012) This should be a module path, not anything in TypeNS.
- let result =
- self.resolve_path(&path, scope, Some(TypeNS), Some(span));
+ let result = self.resolve_path(&path, Some(TypeNS), Some(span));
let (def, msg) = match result {
PathResult::Module(module) => (module.def().unwrap(), None),
PathResult::NonModule(res) if res.depth == 0 =>
(res.base_def, None),
PathResult::NonModule(_) => {
// Resolve a module path for better errors
- match self.resolve_path(&path, scope, None, Some(span)) {
+ match self.resolve_path(&path, None, Some(span)) {
PathResult::Failed(msg, _) => (Def::Err, Some(msg)),
_ => unreachable!(),
}
fn resolve_trait_reference(&mut self,
path: &[Ident],
- global: bool,
generics: Option<&Generics>,
span: Span)
-> PathResolution {
- let scope = if global { PathScope::Global } else { PathScope::Lexical };
- let def = match self.resolve_path(path, scope, None, Some(span)) {
+ let def = match self.resolve_path(path, None, Some(span)) {
PathResult::Module(module) => Some(module.def().unwrap()),
PathResult::NonModule(..) => return err_path_resolution(),
PathResult::Failed(msg, false) => {
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
return err_path_resolution();
}
- _ => match self.resolve_path(path, scope, Some(TypeNS), None) {
+ _ => match self.resolve_path(path, Some(TypeNS), None) {
PathResult::NonModule(path_resolution) => Some(path_resolution.base_def),
_ => None,
},
let mut new_val = None;
let mut new_id = None;
if let Some(trait_ref) = opt_trait_ref {
- let ast::Path { ref segments, span, global } = trait_ref.path;
+ let ast::Path { ref segments, span } = trait_ref.path;
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
- let path_res = self.resolve_trait_reference(&path, global, generics, span);
+ let path_res = self.resolve_trait_reference(&path, generics, span);
assert!(path_res.depth == 0);
self.record_def(trait_ref.ref_id, path_res);
if path_res.base_def != Def::Err {
path: &Path,
ns: Namespace)
-> Option<PathResolution> {
- let ast::Path { ref segments, global, span } = *path;
+ let ast::Path { ref segments, span } = *path;
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
- let scope = if global { PathScope::Global } else { PathScope::Lexical };
if let Some(qself) = maybe_qself {
if qself.position == 0 {
});
}
// Make sure the trait is valid.
- self.resolve_trait_reference(&path[..qself.position], global, None, span);
+ self.resolve_trait_reference(&path[..qself.position], None, span);
}
- let result = match self.resolve_path(&path, scope, Some(ns), Some(span)) {
+ let result = match self.resolve_path(&path, Some(ns), Some(span)) {
PathResult::NonModule(path_res) => match path_res.base_def {
Def::Trait(..) if maybe_qself.is_some() => return None,
_ => path_res,
// Such behavior is required for backward compatibility.
// The same fallback is used when `a` resolves to nothing.
PathResult::Module(..) | PathResult::Failed(..)
- if scope == PathScope::Lexical && (ns == TypeNS || path.len() > 1) &&
+ if (ns == TypeNS || path.len() > 1) &&
self.primitive_type_table.primitive_types.contains_key(&path[0].name) => {
PathResolution {
base_def: Def::PrimTy(self.primitive_type_table.primitive_types[&path[0].name]),
}
let unqualified_result = {
- match self.resolve_path(&[*path.last().unwrap()], PathScope::Lexical, Some(ns), None) {
+ match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
PathResult::NonModule(path_res) => path_res.base_def,
PathResult::Module(module) => module.def().unwrap(),
_ => return Some(result),
fn resolve_path(&mut self,
path: &[Ident],
- scope: PathScope,
opt_ns: Option<Namespace>, // `None` indicates a module path
record_used: Option<Span>)
-> PathResult<'a> {
- let (mut module, allow_self) = match scope {
- PathScope::Lexical => (None, true),
- PathScope::Import => (Some(self.graph_root), true),
- PathScope::Global => (Some(self.graph_root), false),
- };
- let mut allow_super = allow_self;
+ let mut module = None;
+ let mut allow_super = true;
for (i, &ident) in path.iter().enumerate() {
let is_last = i == path.len() - 1;
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
- if i == 0 && allow_self && ns == TypeNS && ident.name == keywords::SelfValue.name() {
+ if i == 0 && ns == TypeNS && ident.name == keywords::SelfValue.name() {
module = Some(self.module_map[&self.current_module.normal_ancestor_id.unwrap()]);
continue
- } else if i == 0 && allow_self && ns == TypeNS && ident.name == "$crate" {
- module = Some(self.resolve_crate_var(ident.ctxt));
- continue
} else if allow_super && ns == TypeNS && ident.name == keywords::Super.name() {
let current_module = if i == 0 { self.current_module } else { module.unwrap() };
let self_module = self.module_map[¤t_module.normal_ancestor_id.unwrap()];
}
allow_super = false;
+ if i == 0 && ns == TypeNS && ident.name == keywords::CrateRoot.name() {
+ module = Some(self.graph_root);
+ continue
+ } else if i == 0 && ns == TypeNS && ident.name == "$crate" {
+ module = Some(self.resolve_crate_var(ident.ctxt));
+ continue
+ }
+
let binding = if let Some(module) = module {
self.resolve_ident_in_module(module, ident, ns, false, record_used)
} else if opt_ns == Some(MacroNS) {
}
}
- PathResult::Module(module.unwrap())
+ PathResult::Module(module.unwrap_or(self.graph_root))
}
// Resolve a local definition, potentially adjusting for closures.
} else {
// Be helpful if the name refers to a struct
let path_name = path_names_to_string(path, 0);
- let ast::Path { ref segments, global, .. } = *path;
- let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
- let scope = if global { PathScope::Global } else { PathScope::Lexical };
- let type_res = match self.resolve_path(&path, scope, Some(TypeNS), None) {
+ let path: Vec<_> = path.segments.iter().map(|seg| seg.identifier).collect();
+ let type_res = match self.resolve_path(&path, Some(TypeNS), None) {
PathResult::NonModule(type_res) => Some(type_res),
_ => None,
};
} else {
// we display a help message if this is a module
if let PathResult::Module(module) =
- self.resolve_path(&path, scope, None, None) {
+ self.resolve_path(&path, None, None) {
def = module.def().unwrap();
context = UnresolvedNameContext::PathIsMod(parent);
}
segms.push(ident.into());
let path = Path {
span: span,
- global: false,
segments: segms,
};
// the entity is accessible in the following cases:
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
let mut path_resolution = err_path_resolution();
- let vis = match self.resolve_path(&path, PathScope::Import, None, Some(span)) {
+ let vis = match self.resolve_path(&path, None, Some(span)) {
PathResult::Module(module) => {
path_resolution = PathResolution::new(module.def().unwrap());
ty::Visibility::Restricted(module.normal_ancestor_id.unwrap())
}
fn names_to_string(names: &[Ident]) -> String {
- let mut first = true;
let mut result = String::new();
- for ident in names {
- if first {
- first = false
- } else {
- result.push_str("::")
+ for (i, ident) in names.iter().enumerate() {
+ if i > 0 {
+ result.push_str("::");
+ }
+ if ident.name != keywords::CrateRoot.name() {
+ result.push_str(&ident.name.as_str());
}
- result.push_str(&ident.name.as_str());
}
result
}
// except according to those terms.
use {AmbiguityError, Resolver, ResolutionError, resolve_error};
-use {Module, ModuleKind, NameBinding, NameBindingKind, PathScope, PathResult};
+use {Module, ModuleKind, NameBinding, NameBindingKind, PathResult};
use Namespace::{self, MacroNS};
use build_reduced_graph::BuildReducedGraphVisitor;
use resolve_imports::ImportResolver;
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::fold::Folder;
use syntax::ptr::P;
+use syntax::symbol::keywords;
use syntax::util::lev_distance::find_best_match_for_name;
use syntax::visit::Visitor;
use syntax_pos::{Span, DUMMY_SP};
fn fold_path(&mut self, mut path: ast::Path) -> ast::Path {
let ident = path.segments[0].identifier;
if ident.name == "$crate" {
- path.global = true;
+ path.segments[0].identifier.name = keywords::CrateRoot.name();
let module = self.0.resolve_crate_var(ident.ctxt);
- if module.is_local() {
- path.segments.remove(0);
- } else {
- path.segments[0].identifier = match module.kind {
- ModuleKind::Def(_, name) => ast::Ident::with_empty_ctxt(name),
+ if !module.is_local() {
+ path.segments.insert(1, match module.kind {
+ ModuleKind::Def(_, name) => ast::Ident::with_empty_ctxt(name).into(),
_ => unreachable!(),
- };
+ })
}
}
path
EliminateCrateVar(self).fold_item(item).expect_one("")
}
+ fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool {
+ self.whitelisted_legacy_custom_derives.contains(&name)
+ }
+
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
let invocation = self.invocations[&mark];
self.collect_def_ids(invocation, expansion);
fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, force: bool)
-> Result<Rc<SyntaxExtension>, Determinacy> {
- let ast::Path { ref segments, global, span } = *path;
+ let ast::Path { ref segments, span } = *path;
if segments.iter().any(|segment| segment.parameters.is_some()) {
let kind =
if segments.last().unwrap().parameters.is_some() { "macro" } else { "module" };
return Err(Determinacy::Determined);
}
- let path_scope = if global { PathScope::Global } else { PathScope::Lexical };
let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect();
let invocation = self.invocations[&scope];
self.current_module = invocation.module.get();
- if path.len() > 1 || global {
+ if path.len() > 1 {
if !self.use_extern_macros {
let msg = "non-ident macro paths are experimental";
let feature = "use_extern_macros";
return Err(Determinacy::Determined);
}
- let ext = match self.resolve_path(&path, path_scope, Some(MacroNS), None) {
+ let ext = match self.resolve_path(&path, Some(MacroNS), None) {
PathResult::NonModule(path_res) => match path_res.base_def {
Def::Err => Err(Determinacy::Determined),
def @ _ => Ok(self.get_macro(def)),
_ => Err(Determinacy::Determined),
};
self.current_module.macro_resolutions.borrow_mut()
- .push((path.into_boxed_slice(), path_scope, span));
+ .push((path.into_boxed_slice(), span));
return ext;
}
pub fn finalize_current_module_macro_resolutions(&mut self) {
let module = self.current_module;
- for &(ref path, scope, span) in module.macro_resolutions.borrow().iter() {
- match self.resolve_path(path, scope, Some(MacroNS), Some(span)) {
+ for &(ref path, span) in module.macro_resolutions.borrow().iter() {
+ match self.resolve_path(path, Some(MacroNS), Some(span)) {
PathResult::NonModule(_) => {},
PathResult::Failed(msg, _) => {
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
use {AmbiguityError, Module, PerNS};
use Namespace::{self, TypeNS, MacroNS};
-use {NameBinding, NameBindingKind, PathResult, PathScope, PrivacyError};
+use {NameBinding, NameBindingKind, PathResult, PrivacyError};
use Resolver;
use {names_to_string, module_to_string};
use {resolve_error, ResolutionError};
use syntax::ast::{Ident, NodeId};
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
use syntax::ext::hygiene::Mark;
+use syntax::parse::token;
use syntax::symbol::keywords;
use syntax::util::lev_distance::find_best_match_for_name;
use syntax_pos::Span;
// For better failure detection, pretend that the import will not define any names
// while resolving its module path.
directive.vis.set(ty::Visibility::PrivateExternal);
- let result = self.resolve_path(&directive.module_path, PathScope::Import, None, None);
+ let result = self.resolve_path(&directive.module_path, None, None);
directive.vis.set(vis);
match result {
self.current_module = directive.parent;
let ImportDirective { ref module_path, span, .. } = *directive;
- let module_result = self.resolve_path(&module_path, PathScope::Import, None, Some(span));
+ let module_result = self.resolve_path(&module_path, None, Some(span));
let module = match module_result {
PathResult::Module(module) => module,
PathResult::Failed(msg, _) => {
- let mut path = vec![keywords::SelfValue.ident()];
- path.extend(module_path);
- let result = self.resolve_path(&path, PathScope::Import, None, None);
- return if let PathResult::Module(..) = result {
- Some(format!("Did you mean `self::{}`?", &names_to_string(module_path)))
+ let (mut self_path, mut self_result) = (module_path.clone(), None);
+ if !self_path.is_empty() && !token::Ident(self_path[0]).is_path_segment_keyword() {
+ self_path[0].name = keywords::SelfValue.name();
+ self_result = Some(self.resolve_path(&self_path, None, None));
+ }
+ return if let Some(PathResult::Module(..)) = self_result {
+ Some(format!("Did you mean `{}`?", names_to_string(&self_path)))
} else {
Some(msg)
};
}
fn import_path_to_string(names: &[Ident], subclass: &ImportDirectiveSubclass) -> String {
+ let global = !names.is_empty() && names[0].name == keywords::CrateRoot.name();
+ let names = if global { &names[1..] } else { names };
if names.is_empty() {
import_directive_subclass_to_string(subclass)
} else {
pub variants: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
/// Data for extern crates.
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
/// Data about a function call.
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
/// Data for modules.
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
/// Data for a reference to a module.
pub fields: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
#[derive(Debug, RustcEncodable)]
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
#[derive(Debug, RustcEncodable)]
pub items: Vec<NodeId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
#[derive(Debug, RustcEncodable)]
pub scope: NodeId,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
/// Data for a typedef.
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Option<Signature>,
}
/// Data for a reference to a type or trait.
pub type_value: String,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Option<Signature>,
}
#[derive(Debug, RustcEncodable)]
pub scope: NodeId,
pub ref_id: DefId,
}
+
+
+/// Encodes information about the signature of a definition. This should have
+/// enough information to create a nice display about a definition without
+/// access to the source code.
+#[derive(Clone, Debug, RustcEncodable)]
+pub struct Signature {
+ pub span: Span,
+ pub text: String,
+ // These identify the main identifier for the defintion as byte offsets into
+ // `text`. E.g., of `foo` in `pub fn foo(...)`
+ pub ident_start: usize,
+ pub ident_end: usize,
+ pub defs: Vec<SigElement>,
+ pub refs: Vec<SigElement>,
+}
+
+/// An element of a signature. `start` and `end` are byte offsets into the `text`
+/// of the parent `Signature`.
+#[derive(Clone, Debug, RustcEncodable)]
+pub struct SigElement {
+ pub id: DefId,
+ pub start: usize,
+ pub end: usize,
+}
// a str representation of the entire prefix.
fn process_path_prefixes(&self, path: &ast::Path) -> Vec<(Span, String)> {
let spans = self.span.spans_for_path_segments(path);
+ let segments = &path.segments[if path.is_global() { 1 } else { 0 }..];
// Paths to enums seem to not match their spans - the span includes all the
// variants too. But they seem to always be at the end, so I hope we can cope with
// always using the first ones. So, only error out if we don't have enough spans.
// What could go wrong...?
- if spans.len() < path.segments.len() {
+ if spans.len() < segments.len() {
if generated_code(path.span) {
return vec![];
}
error!("Mis-calculated spans for path '{}'. Found {} spans, expected {}. Found spans:",
path_to_string(path),
spans.len(),
- path.segments.len());
+ segments.len());
for s in &spans {
let loc = self.sess.codemap().lookup_char_pos(s.lo);
error!(" '{}' in {}, line {}",
let mut result: Vec<(Span, String)> = vec![];
let mut segs = vec![];
- for (i, (seg, span)) in path.segments.iter().zip(&spans).enumerate() {
+ for (i, (seg, span)) in segments.iter().zip(&spans).enumerate() {
segs.push(seg.clone());
let sub_path = ast::Path {
span: *span, // span for the last segment
- global: path.global,
segments: segs,
};
- let qualname = if i == 0 && path.global {
+ let qualname = if i == 0 && path.is_global() {
format!("::{}", path_to_string(&sub_path))
} else {
path_to_string(&sub_path)
result
}
- // The global arg allows us to override the global-ness of the path (which
- // actually means 'does the path start with `::`', rather than 'is the path
- // semantically global). We use the override for `use` imports (etc.) where
- // the syntax is non-global, but the semantics are global.
- fn write_sub_paths(&mut self, path: &ast::Path, global: bool) {
+ fn write_sub_paths(&mut self, path: &ast::Path) {
let sub_paths = self.process_path_prefixes(path);
- for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() {
- let qualname = if i == 0 && global && !path.global {
- format!("::{}", qualname)
- } else {
- qualname.clone()
- };
+ for (span, qualname) in sub_paths {
self.dumper.mod_ref(ModRefData {
- span: *span,
+ span: span,
qualname: qualname,
scope: self.cur_scope,
ref_id: None
// As write_sub_paths, but does not process the last ident in the path (assuming it
// will be processed elsewhere). See note on write_sub_paths about global.
- fn write_sub_paths_truncated(&mut self, path: &ast::Path, global: bool) {
+ fn write_sub_paths_truncated(&mut self, path: &ast::Path) {
let sub_paths = self.process_path_prefixes(path);
let len = sub_paths.len();
if len <= 1 {
return;
}
- let sub_paths = &sub_paths[..len-1];
- for (i, &(ref span, ref qualname)) in sub_paths.iter().enumerate() {
- let qualname = if i == 0 && global && !path.global {
- format!("::{}", qualname)
- } else {
- qualname.clone()
- };
+ for (span, qualname) in sub_paths.into_iter().take(len - 1) {
self.dumper.mod_ref(ModRefData {
- span: *span,
+ span: span,
qualname: qualname,
scope: self.cur_scope,
ref_id: None
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
+ sig: None,
}.lower(self.tcx));
}
}
parent: trait_id,
visibility: vis,
docs: docs_for_attrs(attrs),
+ sig: method_data.sig,
}.lower(self.tcx));
}
visibility: Visibility::Inherited,
parent: None,
docs: String::new(),
+ sig: None,
}.lower(self.tcx));
}
}
parent: Some(parent_id),
visibility: vis,
docs: docs_for_attrs(attrs),
+ sig: None,
}.lower(self.tcx));
}
fields: fields,
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: self.save_ctxt.sig_base(item),
}.lower(self.tcx));
}
-
- // fields
for field in def.fields() {
self.process_struct_field_def(field, item.id);
self.visit_ty(&field.ty);
qualname.push_str("::");
qualname.push_str(&name);
+ let text = self.span.signature_string_for_span(variant.span);
+ let ident_start = text.find(&name).unwrap();
+ let ident_end = ident_start + name.len();
+ let sig = Signature {
+ span: variant.span,
+ text: text,
+ ident_start: ident_start,
+ ident_end: ident_end,
+ defs: vec![],
+ refs: vec![],
+ };
+
match variant.node.data {
ast::VariantData::Struct(ref fields, _) => {
let sub_span = self.span.span_for_first_ident(variant.span);
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.map)),
docs: docs_for_attrs(&variant.node.attrs),
+ sig: sig,
}.lower(self.tcx));
}
}
scope: enum_data.scope,
parent: Some(make_def_id(item.id, &self.tcx.map)),
docs: docs_for_attrs(&variant.node.attrs),
+ sig: sig,
}.lower(self.tcx));
}
}
items: methods.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: self.save_ctxt.sig_base(item),
}.lower(self.tcx));
}
Def::Union(..) |
Def::Variant(..) |
Def::TyAlias(..) |
- Def::AssociatedTy(..) => self.write_sub_paths_truncated(path, false),
+ Def::AssociatedTy(..) => self.write_sub_paths_truncated(path),
_ => {}
}
}
fields: &'l [ast::Field],
variant: &'l ty::VariantDef,
base: &'l Option<P<ast::Expr>>) {
- self.write_sub_paths_truncated(path, false);
+ self.write_sub_paths_truncated(path);
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
down_cast_data!(struct_lit_data, TypeRefData, ex.span);
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
+ sig: None,
}.lower(self.tcx));
}
}
visibility: From::from(&item.vis),
}.lower(self.tcx));
}
- self.write_sub_paths_truncated(path, true);
+ self.write_sub_paths_truncated(path);
}
ast::ViewPathGlob(ref path) => {
// Make a comma-separated list of names of imported modules.
visibility: From::from(&item.vis),
}.lower(self.tcx));
}
- self.write_sub_paths(path, true);
+ self.write_sub_paths(path);
}
ast::ViewPathList(ref path, ref list) => {
for plid in list {
}
}
- self.write_sub_paths(path, true);
+ self.write_sub_paths(path);
}
}
}
Struct(ref def, ref ty_params) => self.process_struct(item, def, ty_params),
Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
Impl(..,
- ref ty_params,
- ref trait_ref,
- ref typ,
- ref impl_items) => {
+ ref ty_params,
+ ref trait_ref,
+ ref typ,
+ ref impl_items) => {
self.process_impl(item, ty_params, trait_ref, &typ, impl_items)
}
Trait(_, ref generics, ref trait_refs, ref methods) =>
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
+ sig: Some(self.save_ctxt.sig_base(item)),
}.lower(self.tcx));
}
}.lower(self.tcx));
}
- self.write_sub_paths_truncated(path, false);
+ self.write_sub_paths_truncated(path);
visit::walk_path(self, path);
}
parent: None,
visibility: Visibility::Inherited,
docs: String::new(),
+ sig: None,
}.lower(self.tcx));
}
}
use syntax::codemap::CodeMap;
use syntax_pos::Span;
-use data::{self, Visibility};
+use data::{self, Visibility, SigElement};
// FIXME: this should be pub(crate), but the current snapshot doesn't allow it yet
pub trait Lower {
pub variants: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::EnumData {
variants: self.variants.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::FunctionData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::MethodData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::ModData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub fields: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::StructData {
fields: self.fields.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::StructVariantData {
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub items: Vec<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::TraitData {
items: self.items.into_iter().map(|id| make_def_id(id, &tcx.map)).collect(),
visibility: self.visibility,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub scope: DefId,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Signature,
}
impl Lower for data::TupleVariantData {
scope: make_def_id(self.scope, &tcx.map),
parent: self.parent,
docs: self.docs,
+ sig: self.sig.lower(tcx),
}
}
}
pub visibility: Visibility,
pub parent: Option<DefId>,
pub docs: String,
+ pub sig: Option<Signature>,
}
impl Lower for data::TypeDefData {
visibility: self.visibility,
parent: self.parent,
docs: self.docs,
+ sig: self.sig.map(|s| s.lower(tcx)),
}
}
}
pub parent: Option<DefId>,
pub visibility: Visibility,
pub docs: String,
+ pub sig: Option<Signature>,
}
impl Lower for data::VariableData {
parent: self.parent,
visibility: self.visibility,
docs: self.docs,
+ sig: self.sig.map(|s| s.lower(tcx)),
}
}
}
}
}
}
+
+#[derive(Clone, Debug, RustcEncodable)]
+pub struct Signature {
+ pub span: SpanData,
+ pub text: String,
+ // These identify the main identifier for the defintion as byte offsets into
+ // `text`. E.g., of `foo` in `pub fn foo(...)`
+ pub ident_start: usize,
+ pub ident_end: usize,
+ pub defs: Vec<SigElement>,
+ pub refs: Vec<SigElement>,
+}
+
+impl Lower for data::Signature {
+ type Target = Signature;
+
+ fn lower(self, tcx: TyCtxt) -> Signature {
+ Signature {
+ span: SpanData::from_span(self.span, tcx.sess.codemap()),
+ text: self.text,
+ ident_start: self.ident_start,
+ ident_end: self.ident_end,
+ defs: self.defs,
+ refs: self.refs,
+ }
+ }
+}
use rustc_serialize::json::as_json;
use external_data::*;
-use data::{VariableKind, Visibility};
+use data::{VariableKind, Visibility, SigElement};
use dump::Dump;
use super::Format;
children: Vec<Id>,
decl_id: Option<Id>,
docs: String,
+ sig: Option<JsonSignature>,
}
#[derive(Debug, RustcEncodable)]
children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
})
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
})
}
}
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
parent: None,
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
parent: data.parent.map(|id| From::from(id)),
decl_id: data.decl_id.map(|id| From::from(id)),
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
parent: None,
decl_id: None,
docs: data.docs,
+ sig: None,
})
}
}
parent: None,
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}),
_ => None,
}
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
docs: String::new(),
+ sig: data.sig.map(|s| From::from(s)),
}),
_ => None,
}
}
}
+
impl From<VariableData> for Option<Def> {
fn from(data: VariableData) -> Option<Def> {
match data.visibility {
parent: data.parent.map(|id| From::from(id)),
decl_id: None,
docs: data.docs,
+ sig: data.sig.map(|s| From::from(s)),
}),
_ => None,
}
}
}
+
+#[derive(Debug, RustcEncodable)]
+pub struct JsonSignature {
+ span: SpanData,
+ text: String,
+ ident_start: usize,
+ ident_end: usize,
+ defs: Vec<JsonSigElement>,
+ refs: Vec<JsonSigElement>,
+}
+
+impl From<Signature> for JsonSignature {
+ fn from(data: Signature) -> JsonSignature {
+ JsonSignature {
+ span: data.span,
+ text: data.text,
+ ident_start: data.ident_start,
+ ident_end: data.ident_end,
+ defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
+ refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
+ }
+ }
+}
+
+#[derive(Debug, RustcEncodable)]
+pub struct JsonSigElement {
+ id: Id,
+ start: usize,
+ end: usize,
+}
+
+impl From<SigElement> for JsonSigElement {
+ fn from(data: SigElement) -> JsonSigElement {
+ JsonSigElement {
+ id: From::from(data.id),
+ start: data.start,
+ end: data.end,
+ }
+ }
+}
use rustc_serialize::json::as_json;
use external_data::*;
-use data::VariableKind;
+use data::{VariableKind, SigElement};
use dump::Dump;
use super::Format;
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
};
if def.span.file_name != def.value {
// If the module is an out-of-line defintion, then we'll make the
children: Vec<Id>,
decl_id: Option<Id>,
docs: String,
+ sig: Option<JsonSignature>,
}
#[derive(Debug, RustcEncodable)]
children: data.variants.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: data.fields.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: data.items.into_iter().map(|id| From::from(id)).collect(),
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: vec![],
decl_id: data.decl_id.map(|id| From::from(id)),
docs: data.docs,
+ sig: Some(From::from(data.sig)),
}
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: None,
}
}
}
-
impl From<TypeDefData> for Def {
fn from(data: TypeDefData) -> Def {
Def {
children: vec![],
decl_id: None,
docs: String::new(),
+ sig: data.sig.map(|s| From::from(s)),
}
}
}
children: vec![],
decl_id: None,
docs: data.docs,
+ sig: None,
}
}
}
}
}
}
+
+#[derive(Debug, RustcEncodable)]
+pub struct JsonSignature {
+ span: SpanData,
+ text: String,
+ ident_start: usize,
+ ident_end: usize,
+ defs: Vec<JsonSigElement>,
+ refs: Vec<JsonSigElement>,
+}
+
+impl From<Signature> for JsonSignature {
+ fn from(data: Signature) -> JsonSignature {
+ JsonSignature {
+ span: data.span,
+ text: data.text,
+ ident_start: data.ident_start,
+ ident_end: data.ident_end,
+ defs: data.defs.into_iter().map(|s| From::from(s)).collect(),
+ refs: data.refs.into_iter().map(|s| From::from(s)).collect(),
+ }
+ }
+}
+
+#[derive(Debug, RustcEncodable)]
+pub struct JsonSigElement {
+ id: Id,
+ start: usize,
+ end: usize,
+}
+
+impl From<SigElement> for JsonSigElement {
+ fn from(data: SigElement) -> JsonSigElement {
+ JsonSigElement {
+ id: From::from(data.id),
+ start: data.start,
+ end: data.end,
+ }
+ }
+}
visibility: From::from(&item.vis),
parent: None,
docs: docs_for_attrs(&item.attrs),
+ sig: self.sig_base(item),
}))
}
ast::ItemKind::Static(ref typ, mt, ref expr) => {
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: Some(self.sig_base(item)),
}))
}
ast::ItemKind::Const(ref typ, ref expr) => {
type_value: ty_to_string(&typ),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: Some(self.sig_base(item)),
}))
}
ast::ItemKind::Mod(ref m) => {
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Mod);
filter!(self.span_utils, sub_span, item.span, None);
+
Some(Data::ModData(ModData {
id: item.id,
name: item.ident.to_string(),
items: m.items.iter().map(|i| i.id).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: self.sig_base(item),
}))
}
ast::ItemKind::Enum(ref def, _) => {
variants: def.variants.iter().map(|v| v.node.data.id()).collect(),
visibility: From::from(&item.vis),
docs: docs_for_attrs(&item.attrs),
+ sig: self.sig_base(item),
}))
}
ast::ItemKind::Impl(.., ref trait_ref, ref typ, _) => {
}
}
- pub fn get_field_data(&self, field: &ast::StructField,
- scope: NodeId) -> Option<VariableData> {
+ pub fn get_field_data(&self,
+ field: &ast::StructField,
+ scope: NodeId)
+ -> Option<VariableData> {
if let Some(ident) = field.ident {
+ let name = ident.to_string();
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
- let def_id = self.tcx.map.local_def_id(field.id);
- let typ = self.tcx.item_type(def_id).to_string();
let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon);
filter!(self.span_utils, sub_span, field.span, None);
+ let def_id = self.tcx.map.local_def_id(field.id);
+ let typ = self.tcx.item_type(def_id).to_string();
+
+ let span = field.span;
+ let text = self.span_utils.snippet(field.span);
+ let ident_start = text.find(&name).unwrap();
+ let ident_end = ident_start + name.len();
+ let sig = Signature {
+ span: span,
+ text: text,
+ ident_start: ident_start,
+ ident_end: ident_end,
+ defs: vec![],
+ refs: vec![],
+ };
Some(VariableData {
id: field.id,
kind: VariableKind::Field,
- name: ident.to_string(),
+ name: name,
qualname: qualname,
span: sub_span.unwrap(),
scope: scope,
type_value: typ,
visibility: From::from(&field.vis),
docs: docs_for_attrs(&field.attrs),
+ sig: Some(sig),
})
} else {
None
let sub_span = self.span_utils.sub_span_after_keyword(span, keywords::Fn);
filter!(self.span_utils, sub_span, span, None);
+
+ let name = name.to_string();
+ let text = self.span_utils.signature_string_for_span(span);
+ let ident_start = text.find(&name).unwrap();
+ let ident_end = ident_start + name.len();
+ let sig = Signature {
+ span: span,
+ text: text,
+ ident_start: ident_start,
+ ident_end: ident_end,
+ defs: vec![],
+ refs: vec![],
+ };
+
Some(FunctionData {
id: id,
- name: name.to_string(),
+ name: name,
qualname: qualname,
declaration: decl_id,
span: sub_span.unwrap(),
visibility: vis,
parent: parent_scope,
docs: docs,
+ sig: sig,
})
}
}
}
+ fn sig_base(&self, item: &ast::Item) -> Signature {
+ let text = self.span_utils.signature_string_for_span(item.span);
+ let name = item.ident.to_string();
+ let ident_start = text.find(&name).expect("Name not in signature?");
+ let ident_end = ident_start + name.len();
+ Signature {
+ span: mk_sp(item.span.lo, item.span.lo + BytePos(text.len() as u32)),
+ text: text,
+ ident_start: ident_start,
+ ident_end: ident_end,
+ defs: vec![],
+ refs: vec![],
+ }
+ }
+
#[inline]
pub fn enclosing_scope(&self, id: NodeId) -> NodeId {
self.tcx.map.get_enclosing_scope(id).unwrap_or(CRATE_NODE_ID)
use syntax::ast;
use syntax::parse::lexer::{self, Reader, StringReader};
use syntax::parse::token::{self, Token};
+use syntax::parse::parser::Parser;
use syntax::symbol::keywords;
+use syntax::tokenstream::TokenTree;
use syntax_pos::*;
#[derive(Clone)]
lexer::StringReader::new(s.diagnostic(), filemap)
}
+ fn span_to_tts(&self, span: Span) -> Vec<TokenTree> {
+ let srdr = self.retokenise_span(span);
+ let mut p = Parser::new(&self.sess.parse_sess, Box::new(srdr), None, false);
+ p.parse_all_token_trees().expect("Couldn't re-parse span")
+ }
+
// Re-parses a path and returns the span for the last identifier in the path
pub fn span_for_last_ident(&self, span: Span) -> Option<Span> {
let mut result = None;
}
}
+ /// `span` must be the span for an item such as a function or struct. This
+ /// function returns the program text from the start of the span until the
+ /// end of the 'signature' part, that is up to, but not including an opening
+ /// brace or semicolon.
+ pub fn signature_string_for_span(&self, span: Span) -> String {
+ let mut toks = self.span_to_tts(span).into_iter();
+ let mut prev = toks.next().unwrap();
+ let first_span = prev.get_span();
+ let mut angle_count = 0;
+ for tok in toks {
+ if let TokenTree::Token(_, ref tok) = prev {
+ angle_count += match *tok {
+ token::Eof => { break; }
+ token::Lt => 1,
+ token::Gt => -1,
+ token::BinOp(token::Shl) => 2,
+ token::BinOp(token::Shr) => -2,
+ _ => 0,
+ };
+ }
+ if angle_count > 0 {
+ prev = tok;
+ continue;
+ }
+ if let TokenTree::Token(_, token::Semi) = tok {
+ return self.snippet(mk_sp(first_span.lo, prev.get_span().hi));
+ } else if let TokenTree::Delimited(_, ref d) = tok {
+ if d.delim == token::Brace {
+ return self.snippet(mk_sp(first_span.lo, prev.get_span().hi));
+ }
+ }
+ prev = tok;
+ }
+ self.snippet(span)
+ }
+
pub fn sub_span_before_token(&self, span: Span, tok: Token) -> Option<Span> {
let mut toks = self.retokenise_span(span);
let mut prev = toks.real_token();
use common::{
self, CrateContext, FunctionContext, SharedCrateContext
};
+use adt::MaybeSizedValue;
use consts;
use declare;
use value::Value;
// Call the by-ref closure body with `self` in a cleanup scope,
// to drop `self` when the body returns, or in case it unwinds.
- let self_scope = fcx.schedule_drop_mem(llenv, closure_ty);
+ let self_scope = fcx.schedule_drop_mem(MaybeSizedValue::sized(llenv), closure_ty);
let llfn = callee.reify(bcx.ccx);
let llret;
//! corresponds to a normal exit from a block (for example, an expression
//! completing evaluation successfully without panic).
-use llvm::{BasicBlockRef, ValueRef};
+use llvm::BasicBlockRef;
use base;
+use adt::MaybeSizedValue;
use common::{BlockAndBuilder, FunctionContext, Funclet};
use glue;
use type_::Type;
-use value::Value;
use rustc::ty::Ty;
pub struct CleanupScope<'tcx> {
#[derive(Copy, Clone)]
pub struct DropValue<'tcx> {
- val: ValueRef,
+ val: MaybeSizedValue,
ty: Ty<'tcx>,
skip_dtor: bool,
}
impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
/// Schedules a (deep) drop of `val`, which is a pointer to an instance of `ty`
- pub fn schedule_drop_mem(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
+ pub fn schedule_drop_mem(&self, val: MaybeSizedValue, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
let drop = DropValue {
val: val,
skip_dtor: false,
};
- debug!("schedule_drop_mem(val={:?}, ty={:?}) skip_dtor={}", Value(val), ty, drop.skip_dtor);
-
CleanupScope::new(self, drop)
}
/// `ty`. The scheduled code handles extracting the discriminant
/// and dropping the contents associated with that variant
/// *without* executing any associated drop implementation.
- pub fn schedule_drop_adt_contents(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
+ pub fn schedule_drop_adt_contents(&self, val: MaybeSizedValue, ty: Ty<'tcx>)
+ -> CleanupScope<'tcx> {
// `if` below could be "!contents_needs_drop"; skipping drop
// is just an optimization, so sound to be conservative.
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
skip_dtor: true,
};
- debug!("schedule_drop_adt_contents(val={:?}, ty={:?}) skip_dtor={}",
- Value(val), ty, drop.skip_dtor);
-
CleanupScope::new(self, drop)
}
}
use rustc::ty::subst::{Substs};
use rustc::traits;
use rustc::ty::{self, AdtKind, Ty, TypeFoldable};
-use adt;
+use adt::{self, MaybeSizedValue};
use base::*;
use callee::Callee;
use common::*;
}
}
-fn drop_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, v: ValueRef, t: Ty<'tcx>) {
- call_drop_glue(bcx, v, t, false, None)
+fn drop_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, args: MaybeSizedValue, t: Ty<'tcx>) {
+ call_drop_glue(bcx, args, t, false, None)
}
pub fn call_drop_glue<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
- v: ValueRef,
+ mut args: MaybeSizedValue,
t: Ty<'tcx>,
skip_dtor: bool,
funclet: Option<&'a Funclet>,
};
let glue = get_drop_glue_core(ccx, g);
let glue_type = get_drop_glue_type(ccx.shared(), t);
- let ptr = if glue_type != t {
- bcx.pointercast(v, type_of(ccx, glue_type).ptr_to())
- } else {
- v
- };
+ if glue_type != t {
+ args.value = bcx.pointercast(args.value, type_of(ccx, glue_type).ptr_to());
+ }
// No drop-hint ==> call standard drop glue
- bcx.call(glue, &[ptr], funclet.map(|b| b.bundle()));
+ bcx.call(glue, &[args.value, args.meta][..1 + args.has_meta() as usize],
+ funclet.map(|b| b.bundle()));
}
}
let (llfn, _) = ccx.drop_glues().borrow().get(&g).unwrap().clone();
let fcx = FunctionContext::new(ccx, llfn);
- let bcx = fcx.get_entry_block();
+ let mut bcx = fcx.get_entry_block();
ccx.stats().n_glues_created.set(ccx.stats().n_glues_created.get() + 1);
// All glue functions take values passed *by alias*; this is a
// non-null, (and maybe we need to continue doing so), but we now
// must definitely check for special bit-patterns corresponding to
// the special dtor markings.
- let v0 = get_param(llfn, 0);
let t = g.ty();
+ let value = get_param(llfn, 0);
+ let ptr = if ccx.shared().type_is_sized(t) {
+ MaybeSizedValue::sized(value)
+ } else {
+ MaybeSizedValue::unsized_(value, get_param(llfn, 1))
+ };
+
let skip_dtor = match g {
DropGlueKind::Ty(_) => false,
DropGlueKind::TyContents(_) => true
// a safe-guard, assert TyBox not used with TyContents.
assert!(!skip_dtor);
if !bcx.ccx.shared().type_is_sized(content_ty) {
- let llval = get_dataptr(&bcx, v0);
- let llbox = bcx.load(llval);
- drop_ty(&bcx, v0, content_ty);
- // FIXME(#36457) -- we should pass unsized values to drop glue as two arguments
- let info = get_meta(&bcx, v0);
- let info = bcx.load(info);
+ let llbox = bcx.load(get_dataptr(&bcx, ptr.value));
+ let info = bcx.load(get_meta(&bcx, ptr.value));
+ drop_ty(&bcx, MaybeSizedValue::unsized_(llbox, info), content_ty);
let (llsize, llalign) = size_and_align_of_dst(&bcx, content_ty, info);
// `Box<ZeroSizeType>` does not allocate.
next_cx
}
} else {
- let llval = v0;
- let llbox = bcx.load(llval);
- drop_ty(&bcx, llbox, content_ty);
+ let llbox = bcx.load(ptr.value);
+ drop_ty(&bcx, MaybeSizedValue::sized(llbox), content_ty);
trans_exchange_free_ty(&bcx, llbox, content_ty);
bcx
}
// No support in vtable for distinguishing destroying with
// versus without calling Drop::drop. Assert caller is
// okay with always calling the Drop impl, if any.
- // FIXME(#36457) -- we should pass unsized values to drop glue as two arguments
assert!(!skip_dtor);
- let data_ptr = get_dataptr(&bcx, v0);
- let vtable_ptr = bcx.load(get_meta(&bcx, v0));
- let dtor = bcx.load(vtable_ptr);
- bcx.call(dtor, &[bcx.pointercast(bcx.load(data_ptr), Type::i8p(bcx.ccx))], None);
+ let dtor = bcx.load(ptr.meta);
+ bcx.call(dtor, &[ptr.value], None);
bcx
}
ty::TyAdt(def, ..) if def.dtor_kind().is_present() && !skip_dtor => {
- trans_custom_dtor(bcx, t, v0, def.is_union())
+ let shallow_drop = def.is_union();
+ let tcx = bcx.tcx();
+
+ let def = t.ty_adt_def().unwrap();
+
+ // Be sure to put the contents into a scope so we can use an invoke
+ // instruction to call the user destructor but still call the field
+ // destructors if the user destructor panics.
+ //
+ // FIXME (#14875) panic-in-drop semantics might be unsupported; we
+ // might well consider changing below to more direct code.
+ // Issue #23611: schedule cleanup of contents, re-inspecting the
+ // discriminant (if any) in case of variant swap in drop code.
+ let contents_scope = if !shallow_drop {
+ bcx.fcx().schedule_drop_adt_contents(ptr, t)
+ } else {
+ CleanupScope::noop()
+ };
+
+ let trait_ref = ty::Binder(ty::TraitRef {
+ def_id: tcx.lang_items.drop_trait().unwrap(),
+ substs: tcx.mk_substs_trait(t, &[])
+ });
+ let vtbl = match fulfill_obligation(bcx.ccx.shared(), DUMMY_SP, trait_ref) {
+ traits::VtableImpl(data) => data,
+ _ => bug!("dtor for {:?} is not an impl???", t)
+ };
+ let dtor_did = def.destructor().unwrap();
+ let callee = Callee::def(bcx.ccx, dtor_did, vtbl.substs);
+ let fn_ty = callee.direct_fn_type(bcx.ccx, &[]);
+ let llret;
+ let args = &[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize];
+ if let Some(landing_pad) = contents_scope.landing_pad {
+ let normal_bcx = bcx.fcx().build_new_block("normal-return");
+ llret = bcx.invoke(callee.reify(ccx), args, normal_bcx.llbb(), landing_pad, None);
+ bcx = normal_bcx;
+ } else {
+ llret = bcx.call(callee.reify(bcx.ccx), args, None);
+ }
+ fn_ty.apply_attrs_callsite(llret);
+ contents_scope.trans(&bcx);
+ bcx
}
ty::TyAdt(def, ..) if def.is_union() => {
bcx
}
_ => {
if bcx.ccx.shared().type_needs_drop(t) {
- drop_structural_ty(bcx, v0, t)
+ drop_structural_ty(bcx, ptr, t)
} else {
bcx
}
bcx.ret_void();
}
-fn trans_custom_dtor<'a, 'tcx>(mut bcx: BlockAndBuilder<'a, 'tcx>,
- t: Ty<'tcx>,
- v0: ValueRef,
- shallow_drop: bool)
- -> BlockAndBuilder<'a, 'tcx>
-{
- debug!("trans_custom_dtor t: {}", t);
- let tcx = bcx.tcx();
-
- let def = t.ty_adt_def().unwrap();
-
- // Be sure to put the contents into a scope so we can use an invoke
- // instruction to call the user destructor but still call the field
- // destructors if the user destructor panics.
- //
- // FIXME (#14875) panic-in-drop semantics might be unsupported; we
- // might well consider changing below to more direct code.
- // Issue #23611: schedule cleanup of contents, re-inspecting the
- // discriminant (if any) in case of variant swap in drop code.
- let contents_scope = if !shallow_drop {
- bcx.fcx().schedule_drop_adt_contents(v0, t)
- } else {
- CleanupScope::noop()
- };
-
- let (sized_args, unsized_args);
- let args: &[ValueRef] = if bcx.ccx.shared().type_is_sized(t) {
- sized_args = [v0];
- &sized_args
- } else {
- // FIXME(#36457) -- we should pass unsized values to drop glue as two arguments
- unsized_args = [
- bcx.load(get_dataptr(&bcx, v0)),
- bcx.load(get_meta(&bcx, v0))
- ];
- &unsized_args
- };
-
- let trait_ref = ty::Binder(ty::TraitRef {
- def_id: tcx.lang_items.drop_trait().unwrap(),
- substs: tcx.mk_substs_trait(t, &[])
- });
- let vtbl = match fulfill_obligation(bcx.ccx.shared(), DUMMY_SP, trait_ref) {
- traits::VtableImpl(data) => data,
- _ => bug!("dtor for {:?} is not an impl???", t)
- };
- let dtor_did = def.destructor().unwrap();
- let callee = Callee::def(bcx.ccx, dtor_did, vtbl.substs);
- let fn_ty = callee.direct_fn_type(bcx.ccx, &[]);
- let llret;
- if let Some(landing_pad) = contents_scope.landing_pad {
- let normal_bcx = bcx.fcx().build_new_block("normal-return");
- llret = bcx.invoke(callee.reify(bcx.ccx), args, normal_bcx.llbb(), landing_pad, None);
- bcx = normal_bcx;
- } else {
- llret = bcx.call(callee.reify(bcx.ccx), args, None);
- }
- fn_ty.apply_attrs_callsite(llret);
- contents_scope.trans(&bcx);
- bcx
-}
-
pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
t: Ty<'tcx>, info: ValueRef)
-> (ValueRef, ValueRef) {
// Iterates through the elements of a structural type, dropping them.
fn drop_structural_ty<'a, 'tcx>(cx: BlockAndBuilder<'a, 'tcx>,
- av: ValueRef,
+ ptr: MaybeSizedValue,
t: Ty<'tcx>)
-> BlockAndBuilder<'a, 'tcx> {
fn iter_variant<'a, 'tcx>(cx: &BlockAndBuilder<'a, 'tcx>,
for (i, field) in variant.fields.iter().enumerate() {
let arg = monomorphize::field_ty(tcx, substs, field);
let field_ptr = adt::trans_field_ptr(&cx, t, av, Disr::from(variant.disr_val), i);
- drop_ty(&cx, field_ptr, arg);
+ drop_ty(&cx, MaybeSizedValue::sized(field_ptr), arg);
}
}
- let value = if cx.ccx.shared().type_is_sized(t) {
- adt::MaybeSizedValue::sized(av)
- } else {
- // FIXME(#36457) -- we should pass unsized values as two arguments
- let data = cx.load(get_dataptr(&cx, av));
- let info = cx.load(get_meta(&cx, av));
- adt::MaybeSizedValue::unsized_(data, info)
- };
-
let mut cx = cx;
match t.sty {
ty::TyClosure(def_id, substs) => {
for (i, upvar_ty) in substs.upvar_tys(def_id, cx.tcx()).enumerate() {
- let llupvar = adt::trans_field_ptr(&cx, t, value, Disr(0), i);
- drop_ty(&cx, llupvar, upvar_ty);
+ let llupvar = adt::trans_field_ptr(&cx, t, ptr, Disr(0), i);
+ drop_ty(&cx, MaybeSizedValue::sized(llupvar), upvar_ty);
}
}
ty::TyArray(_, n) => {
- let base = get_dataptr(&cx, value.value);
+ let base = get_dataptr(&cx, ptr.value);
let len = C_uint(cx.ccx, n);
let unit_ty = t.sequence_element_type(cx.tcx());
- cx = tvec::slice_for_each(&cx, base, unit_ty, len, |bb, vv| drop_ty(bb, vv, unit_ty));
+ cx = tvec::slice_for_each(&cx, base, unit_ty, len,
+ |bb, vv| drop_ty(bb, MaybeSizedValue::sized(vv), unit_ty));
}
ty::TySlice(_) | ty::TyStr => {
let unit_ty = t.sequence_element_type(cx.tcx());
- cx = tvec::slice_for_each(&cx, value.value, unit_ty, value.meta,
- |bb, vv| drop_ty(bb, vv, unit_ty));
+ cx = tvec::slice_for_each(&cx, ptr.value, unit_ty, ptr.meta,
+ |bb, vv| drop_ty(bb, MaybeSizedValue::sized(vv), unit_ty));
}
ty::TyTuple(ref args) => {
for (i, arg) in args.iter().enumerate() {
- let llfld_a = adt::trans_field_ptr(&cx, t, value, Disr(0), i);
- drop_ty(&cx, llfld_a, *arg);
+ let llfld_a = adt::trans_field_ptr(&cx, t, ptr, Disr(0), i);
+ drop_ty(&cx, MaybeSizedValue::sized(llfld_a), *arg);
}
}
ty::TyAdt(adt, substs) => match adt.adt_kind() {
AdtKind::Struct => {
let VariantInfo { fields, discr } = VariantInfo::from_ty(cx.tcx(), t, None);
for (i, &Field(_, field_ty)) in fields.iter().enumerate() {
- let llfld_a = adt::trans_field_ptr(&cx, t, value, Disr::from(discr), i);
-
- let val = if cx.ccx.shared().type_is_sized(field_ty) {
- llfld_a
+ let llfld_a = adt::trans_field_ptr(&cx, t, ptr, Disr::from(discr), i);
+ let ptr = if cx.ccx.shared().type_is_sized(field_ty) {
+ MaybeSizedValue::sized(llfld_a)
} else {
- // FIXME(#36457) -- we should pass unsized values as two arguments
- let scratch = alloc_ty(&cx, field_ty, "__fat_ptr_iter");
- cx.store(llfld_a, get_dataptr(&cx, scratch));
- cx.store(value.meta, get_meta(&cx, scratch));
- scratch
+ MaybeSizedValue::unsized_(llfld_a, ptr.meta)
};
- drop_ty(&cx, val, field_ty);
+ drop_ty(&cx, ptr, field_ty);
}
}
AdtKind::Union => {
// NB: we must hit the discriminant first so that structural
// comparison know not to proceed when the discriminants differ.
- match adt::trans_switch(&cx, t, av, false) {
+ match adt::trans_switch(&cx, t, ptr.value, false) {
(adt::BranchKind::Single, None) => {
if n_variants != 0 {
assert!(n_variants == 1);
- iter_variant(&cx, t, adt::MaybeSizedValue::sized(av),
- &adt.variants[0], substs);
+ iter_variant(&cx, t, ptr, &adt.variants[0], substs);
}
}
(adt::BranchKind::Switch, Some(lldiscrim_a)) => {
let tcx = cx.tcx();
- drop_ty(&cx, lldiscrim_a, tcx.types.isize);
+ drop_ty(&cx, MaybeSizedValue::sized(lldiscrim_a), tcx.types.isize);
// Create a fall-through basic block for the "else" case of
// the switch instruction we're about to generate. Note that
let variant_cx = cx.fcx().build_new_block(&variant_cx_name);
let case_val = adt::trans_case(&cx, t, Disr::from(variant.disr_val));
variant_cx.add_case(llswitch, case_val, variant_cx.llbb());
- iter_variant(&variant_cx, t, value, variant, substs);
+ iter_variant(&variant_cx, t, ptr, variant, substs);
variant_cx.br(next_cx.llbb());
}
cx = next_cx;
use rustc::ty::{self, layout};
use rustc::mir;
use abi::{Abi, FnType, ArgType};
-use adt;
+use adt::{self, MaybeSizedValue};
use base::{self, Lifetime};
use callee::{Callee, CalleeData, Fn, Intrinsic, NamedTupleConstructor, Virtual};
use common::{self, BlockAndBuilder, Funclet};
use super::operand::OperandRef;
use super::operand::OperandValue::{Pair, Ref, Immediate};
-use std::ptr;
-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
pub fn trans_block(&mut self, bb: mir::BasicBlock,
funclets: &IndexVec<mir::BasicBlock, Option<Funclet>>) {
let lvalue = self.trans_lvalue(&bcx, location);
let drop_fn = glue::get_drop_glue(bcx.ccx, ty);
let drop_ty = glue::get_drop_glue_type(bcx.ccx.shared(), ty);
- let is_sized = bcx.ccx.shared().type_is_sized(ty);
- let llvalue = if is_sized {
- if drop_ty != ty {
+ let ptr = if bcx.ccx.shared().type_is_sized(ty) {
+ let value = if drop_ty != ty {
bcx.pointercast(lvalue.llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to())
} else {
lvalue.llval
- }
+ };
+ MaybeSizedValue::sized(value)
} else {
- // FIXME(#36457) Currently drop glue takes sized
- // values as a `*(data, meta)`, but elsewhere in
- // MIR we pass `(data, meta)` as two separate
- // arguments. It would be better to fix drop glue,
- // but I am shooting for a quick fix to #35546
- // here that can be cleanly backported to beta, so
- // I want to avoid touching all of trans.
- let scratch = base::alloc_ty(&bcx, ty, "drop");
- Lifetime::Start.call(&bcx, scratch);
- bcx.store(lvalue.llval, base::get_dataptr(&bcx, scratch));
- bcx.store(lvalue.llextra, base::get_meta(&bcx, scratch));
- scratch
+ MaybeSizedValue::unsized_(lvalue.llval, lvalue.llextra)
};
+ let args = &[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize];
if let Some(unwind) = unwind {
- bcx.invoke(drop_fn,
- &[llvalue],
- self.blocks[target],
- llblock(self, unwind),
- cleanup_bundle);
+ bcx.invoke(
+ drop_fn,
+ args,
+ self.blocks[target],
+ llblock(self, unwind),
+ cleanup_bundle
+ );
} else {
- bcx.call(drop_fn, &[llvalue], cleanup_bundle);
+ bcx.call(drop_fn, args, cleanup_bundle);
funclet_br(self, bcx, target);
}
}
}
_ => None
};
- let intrinsic = intrinsic.as_ref().map(|s| &s[..]);
+ let mut intrinsic = intrinsic.as_ref().map(|s| &s[..]);
if intrinsic == Some("move_val_init") {
let &(_, target) = destination.as_ref().unwrap();
return;
}
- // FIXME: This should proxy to the drop glue in the future when the ABI matches;
- // most of the below code was copied from the match arm for TerminatorKind::Drop.
- if intrinsic == Some("drop_in_place") {
- let &(_, target) = destination.as_ref().unwrap();
- let ty = if let ty::TyFnDef(_, substs, _) = callee.ty.sty {
- substs.type_at(0)
- } else {
- bug!("Unexpected ty: {}", callee.ty);
- };
-
- // Double check for necessity to drop
- if !bcx.ccx.shared().type_needs_drop(ty) {
- funclet_br(self, bcx, target);
- return;
- }
-
- let ptr = self.trans_operand(&bcx, &args[0]);
- let (llval, llextra) = match ptr.val {
- Immediate(llptr) => (llptr, ptr::null_mut()),
- Pair(llptr, llextra) => (llptr, llextra),
- Ref(_) => bug!("Deref of by-Ref type {:?}", ptr.ty)
- };
-
- let drop_fn = glue::get_drop_glue(bcx.ccx, ty);
- let drop_ty = glue::get_drop_glue_type(bcx.ccx.shared(), ty);
- let is_sized = bcx.ccx.shared().type_is_sized(ty);
- let llvalue = if is_sized {
- if drop_ty != ty {
- bcx.pointercast(llval, type_of::type_of(bcx.ccx, drop_ty).ptr_to())
- } else {
- llval
- }
- } else {
- // FIXME(#36457) Currently drop glue takes sized
- // values as a `*(data, meta)`, but elsewhere in
- // MIR we pass `(data, meta)` as two separate
- // arguments. It would be better to fix drop glue,
- // but I am shooting for a quick fix to #35546
- // here that can be cleanly backported to beta, so
- // I want to avoid touching all of trans.
- let scratch = base::alloc_ty(&bcx, ty, "drop");
- Lifetime::Start.call(&bcx, scratch);
- bcx.store(llval, base::get_dataptr(&bcx, scratch));
- bcx.store(llextra, base::get_meta(&bcx, scratch));
- scratch
- };
- if let Some(unwind) = *cleanup {
- bcx.invoke(drop_fn,
- &[llvalue],
- self.blocks[target],
- llblock(self, unwind),
- cleanup_bundle);
- } else {
- bcx.call(drop_fn, &[llvalue], cleanup_bundle);
- funclet_br(self, bcx, target);
- }
- return;
- }
-
if intrinsic == Some("transmute") {
let &(ref dest, target) = destination.as_ref().unwrap();
self.with_lvalue_ref(&bcx, dest, |this, dest| {
}).collect::<Vec<_>>();
let fn_ty = callee.direct_fn_type(bcx.ccx, &extra_args);
+ if intrinsic == Some("drop_in_place") {
+ let &(_, target) = destination.as_ref().unwrap();
+ let ty = if let ty::TyFnDef(_, substs, _) = callee.ty.sty {
+ substs.type_at(0)
+ } else {
+ bug!("Unexpected ty: {}", callee.ty);
+ };
+
+ // Double check for necessity to drop
+ if !bcx.ccx.shared().type_needs_drop(ty) {
+ funclet_br(self, bcx, target);
+ return;
+ }
+
+ let drop_fn = glue::get_drop_glue(bcx.ccx, ty);
+ let llty = fn_ty.llvm_type(bcx.ccx).ptr_to();
+ callee.data = Fn(bcx.pointercast(drop_fn, llty));
+ intrinsic = None;
+ }
+
// The arguments we'll be passing. Plus one to account for outptr, if used.
let arg_count = fn_ty.args.len() + fn_ty.ret.is_indirect() as usize;
let mut llargs = Vec::with_capacity(arg_count);
assert_eq!(dg.ty(), glue::get_drop_glue_type(ccx.shared(), dg.ty()));
let t = dg.ty();
- let sig = tcx.mk_fn_sig(iter::once(tcx.mk_mut_ptr(tcx.types.i8)), tcx.mk_nil(), false);
+ let sig = tcx.mk_fn_sig(iter::once(tcx.mk_mut_ptr(t)), tcx.mk_nil(), false);
- // Create a FnType for fn(*mut i8) and substitute the real type in
- // later - that prevents FnType from splitting fat pointers up.
- let mut fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
- fn_ty.args[0].original_ty = type_of::type_of(ccx, t).ptr_to();
+ debug!("predefine_drop_glue: sig={}", sig);
+
+ let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
let llfnty = fn_ty.llvm_type(ccx);
assert!(declare::get_defined_value(ccx, symbol_name).is_none());
segments.pop();
let trait_path = hir::Path {
span: p.span,
- global: p.global,
def: Def::Trait(cx.tcx.associated_item(p.def.def_id()).container.id()),
segments: segments.into(),
};
}
let trait_path = hir::Path {
span: self.span,
- global: false,
def: def,
segments: vec![].into(),
};
impl Clean<Path> for hir::Path {
fn clean(&self, cx: &DocContext) -> Path {
Path {
- global: self.global,
+ global: self.is_global(),
def: self.def,
- segments: self.segments.clean(cx),
+ segments: if self.is_global() { &self.segments[1..] } else { &self.segments }.clean(cx),
}
}
}
}
fn qpath_to_string(p: &hir::QPath) -> String {
- let (segments, global) = match *p {
- hir::QPath::Resolved(_, ref path) => {
- (&path.segments, path.global)
- }
- hir::QPath::TypeRelative(_, ref segment) => {
- return segment.name.to_string()
- }
+ let segments = match *p {
+ hir::QPath::Resolved(_, ref path) => &path.segments,
+ hir::QPath::TypeRelative(_, ref segment) => return segment.name.to_string(),
};
let mut s = String::new();
- let mut first = true;
- for i in segments.iter().map(|x| x.name.as_str()) {
- if !first || global {
+ for (i, seg) in segments.iter().enumerate() {
+ if i > 0 {
s.push_str("::");
- } else {
- first = false;
}
- s.push_str(&i);
+ if seg.name != keywords::CrateRoot.name() {
+ s.push_str(&*seg.name.as_str());
+ }
}
s
}
if !f.alternate() {
clause.push_str("</span>");
let plain = format!("{:#}", self);
- if plain.len() > 80 {
+ if plain.len() + pad > 80 {
//break it onto its own line regardless, but make sure method impls and trait
//blocks keep their fixed padding (2 and 9, respectively)
let padding = if pad > 10 {
<title>{title}</title>
+ <link rel="stylesheet" type="text/css" href="{root_path}normalize.css">
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc.css">
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
{css_extension}
ty: item.type_(),
name: item.name.clone().unwrap(),
path: fqp[..fqp.len() - 1].join("::"),
- desc: Escape(&shorter(item.doc_value())).to_string(),
+ desc: plain_summary_line(item.doc_value()),
parent: Some(did),
parent_idx: None,
search_type: get_index_search_type(&item),
}
let crate_doc = krate.module.as_ref().map(|module| {
- Escape(&shorter(module.doc_value())).to_string()
+ plain_summary_line(module.doc_value())
}).unwrap_or(String::new());
let mut crate_data = BTreeMap::new();
ty: item.type_(),
name: s.to_string(),
path: path.join("::").to_string(),
- desc: Escape(&shorter(item.doc_value())).to_string(),
+ desc: plain_summary_line(item.doc_value()),
parent: parent,
parent_idx: None,
search_type: get_index_search_type(&item),
displayPath + '<span class="' + type + '">' +
name + '</span></a></td><td>' +
'<a href="' + href + '">' +
- '<span class="desc">' + item.desc +
+ '<span class="desc">' + escape(item.desc) +
' </span></a></td></tr>';
});
} else {
search();
}
- function plainSummaryLine(markdown) {
- markdown.replace(/\n/g, ' ')
- .replace(/'/g, "\'")
- .replace(/^#+? (.+?)/, "$1")
- .replace(/\[(.*?)\]\(.*?\)/g, "$1")
- .replace(/\[(.*?)\]\[.*?\]/g, "$1");
- }
-
index = buildIndex(rawSearchIndex);
startSearch();
if (crates[i] === window.currentCrate) {
klass += ' current';
}
- if (rawSearchIndex[crates[i]].items[0]) {
- var desc = rawSearchIndex[crates[i]].items[0][3];
- var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
- 'title': plainSummaryLine(desc),
- 'class': klass}).text(crates[i]);
- ul.append($('<li>').append(link));
- }
+ var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
+ 'title': rawSearchIndex[crates[i]].doc,
+ 'class': klass}).text(crates[i]);
+ ul.append($('<li>').append(link));
}
sidebar.append(div);
}
-@import "normalize.css";
-
/**
* Copyright 2013 The Rust Project Developers. See the COPYRIGHT
* file at the top-level directory of this distribution and at
let target = env::var("TARGET").expect("TARGET was not set");
let host = env::var("HOST").expect("HOST was not set");
if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") &&
- !target.contains("emscripten") && !target.contains("fuchsia") {
+ !target.contains("emscripten") && !target.contains("fuchsia") && !target.contains("redox") {
build_libbacktrace(&host, &target);
}
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LineWriter<W: Write> {
inner: BufWriter<W>,
+ need_flush: bool,
}
impl<W: Write> LineWriter<W> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(cap: usize, inner: W) -> LineWriter<W> {
- LineWriter { inner: BufWriter::with_capacity(cap, inner) }
+ LineWriter {
+ inner: BufWriter::with_capacity(cap, inner),
+ need_flush: false,
+ }
}
/// Gets a reference to the underlying writer.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> {
self.inner.into_inner().map_err(|IntoInnerError(buf, e)| {
- IntoInnerError(LineWriter { inner: buf }, e)
+ IntoInnerError(LineWriter {
+ inner: buf,
+ need_flush: false,
+ }, e)
})
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<W: Write> Write for LineWriter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
- match memchr::memrchr(b'\n', buf) {
- Some(i) => {
- let n = self.inner.write(&buf[..i + 1])?;
- if n != i + 1 || self.inner.flush().is_err() {
- // Do not return errors on partial writes.
- return Ok(n);
- }
- self.inner.write(&buf[i + 1..]).map(|i| n + i)
- }
- None => self.inner.write(buf),
+ if self.need_flush {
+ self.flush()?;
+ }
+
+ // Find the last newline character in the buffer provided. If found then
+ // we're going to write all the data up to that point and then flush,
+ // otherewise we just write the whole block to the underlying writer.
+ let i = match memchr::memrchr(b'\n', buf) {
+ Some(i) => i,
+ None => return self.inner.write(buf),
+ };
+
+
+ // Ok, we're going to write a partial amount of the data given first
+ // followed by flushing the newline. After we've successfully written
+ // some data then we *must* report that we wrote that data, so future
+ // errors are ignored. We set our internal `need_flush` flag, though, in
+ // case flushing fails and we need to try it first next time.
+ let n = self.inner.write(&buf[..i + 1])?;
+ self.need_flush = true;
+ if self.flush().is_err() || n != i + 1 {
+ return Ok(n)
+ }
+
+ // At this point we successfully wrote `i + 1` bytes and flushed it out,
+ // meaning that the entire line is now flushed out on the screen. While
+ // we can attempt to finish writing the rest of the data provided.
+ // Remember though that we ignore errors here as we've successfully
+ // written data, so we need to report that.
+ match self.inner.write(&buf[i + 1..]) {
+ Ok(i) => Ok(n + i),
+ Err(_) => Ok(n),
}
}
- fn flush(&mut self) -> io::Result<()> { self.inner.flush() }
+ fn flush(&mut self) -> io::Result<()> {
+ self.inner.flush()?;
+ self.need_flush = false;
+ Ok(())
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
BufWriter::new(io::sink())
});
}
+
+ struct AcceptOneThenFail {
+ written: bool,
+ flushed: bool,
+ }
+
+ impl Write for AcceptOneThenFail {
+ fn write(&mut self, data: &[u8]) -> io::Result<usize> {
+ if !self.written {
+ assert_eq!(data, b"a\nb\n");
+ self.written = true;
+ Ok(data.len())
+ } else {
+ Err(io::Error::new(io::ErrorKind::NotFound, "test"))
+ }
+ }
+
+ fn flush(&mut self) -> io::Result<()> {
+ assert!(self.written);
+ assert!(!self.flushed);
+ self.flushed = true;
+ Err(io::Error::new(io::ErrorKind::Other, "test"))
+ }
+ }
+
+ #[test]
+ fn erroneous_flush_retried() {
+ let a = AcceptOneThenFail {
+ written: false,
+ flushed: false,
+ };
+
+ let mut l = LineWriter::new(a);
+ assert_eq!(l.write(b"a\nb\na").unwrap(), 4);
+ assert!(l.get_ref().written);
+ assert!(l.get_ref().flushed);
+ l.get_mut().flushed = false;
+
+ assert_eq!(l.write(b"a").unwrap_err().kind(), io::ErrorKind::Other)
+ }
}
/// println!("{}", line.unwrap());
/// }
/// ```
+ ///
+ /// # Errors
+ ///
+ /// Each line of the iterator has the same error semantics as [`BufRead::read_line()`].
+ ///
+ /// [`BufRead::read_line()`]: trait.BufRead.html#method.read_line
#[stable(feature = "rust1", since = "1.0.0")]
fn lines(self) -> Lines<Self> where Self: Sized {
Lines { buf: self }
#![stable(feature = "rust1", since = "1.0.0")]
use fs;
+use net;
use sys;
-use sys_common::{AsInner, FromInner, IntoInner};
+use sys_common::{self, AsInner, FromInner, IntoInner};
/// Raw file descriptors.
#[stable(feature = "rust1", since = "1.0.0")]
}
}
-/*
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRawFd for net::TcpStream {
- fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
+ fn as_raw_fd(&self) -> RawFd {
+ self.as_inner().as_inner().fd().raw()
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRawFd for net::TcpListener {
- fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
+ fn as_raw_fd(&self) -> RawFd {
+ self.as_inner().as_inner().fd().raw()
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRawFd for net::UdpSocket {
- fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
+ fn as_raw_fd(&self) -> RawFd {
+ self.as_inner().as_inner().fd().raw()
+ }
}
#[stable(feature = "from_raw_os", since = "1.1.0")]
impl FromRawFd for net::TcpStream {
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
- let socket = sys::net::Socket::from_inner(fd);
- net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
+ let file = sys::fs::File::from_inner(fd);
+ net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(file))
}
}
#[stable(feature = "from_raw_os", since = "1.1.0")]
impl FromRawFd for net::TcpListener {
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
- let socket = sys::net::Socket::from_inner(fd);
- net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
+ let file = sys::fs::File::from_inner(fd);
+ net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(file))
}
}
#[stable(feature = "from_raw_os", since = "1.1.0")]
impl FromRawFd for net::UdpSocket {
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
- let socket = sys::net::Socket::from_inner(fd);
- net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
+ let file = sys::fs::File::from_inner(fd);
+ net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(file))
}
}
#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for net::TcpStream {
fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_socket().into_inner()
+ self.into_inner().into_inner().into_fd().into_raw()
}
}
#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for net::TcpListener {
fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_socket().into_inner()
+ self.into_inner().into_inner().into_fd().into_raw()
}
}
#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawFd for net::UdpSocket {
fn into_raw_fd(self) -> RawFd {
- self.into_inner().into_socket().into_inner()
+ self.into_inner().into_inner().into_fd().into_raw()
}
}
-*/
#![allow(dead_code, missing_docs, bad_style)]
-pub extern crate syscall;
-
use io::{self, ErrorKind};
pub mod args;
+#[cfg(any(not(cargobuild), feature = "backtrace"))]
pub mod backtrace;
pub mod condvar;
pub mod env;
pub mod rwlock;
pub mod stack_overflow;
pub mod stdio;
+pub mod syscall;
pub mod thread;
pub mod thread_local;
pub mod time;
use self::dns::{Dns, DnsQuery};
-pub extern crate libc as netc;
pub use self::tcp::{TcpStream, TcpListener};
pub use self::udp::UdpSocket;
+pub mod netc;
+
mod dns;
mod tcp;
mod udp;
--- /dev/null
+// 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 <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.
+
+pub type in_addr_t = u32;
+pub type in_port_t = u16;
+
+pub type socklen_t = u32;
+pub type sa_family_t = u16;
+
+pub const AF_INET: sa_family_t = 1;
+pub const AF_INET6: sa_family_t = 2;
+
+#[derive(Copy, Clone)]
+#[repr(C)]
+pub struct in_addr {
+ pub s_addr: in_addr_t,
+}
+
+#[derive(Copy, Clone)]
+#[repr(C)]
+pub struct in6_addr {
+ pub s6_addr: [u8; 16],
+ __align: [u32; 0],
+}
+
+#[derive(Copy, Clone)]
+#[repr(C)]
+pub struct sockaddr {
+ pub sa_family: sa_family_t,
+ pub sa_data: [u8; 14],
+}
+
+#[derive(Copy, Clone)]
+#[repr(C)]
+pub struct sockaddr_in {
+ pub sin_family: sa_family_t,
+ pub sin_port: in_port_t,
+ pub sin_addr: in_addr,
+ pub sin_zero: [u8; 8],
+}
+
+#[derive(Copy, Clone)]
+#[repr(C)]
+pub struct sockaddr_in6 {
+ pub sin6_family: sa_family_t,
+ pub sin6_port: in_port_t,
+ pub sin6_flowinfo: u32,
+ pub sin6_addr: in6_addr,
+ pub sin6_scope_id: u32,
+}
use net::{SocketAddr, Shutdown};
use path::Path;
use sys::fs::{File, OpenOptions};
+use sys_common::{AsInner, FromInner, IntoInner};
use time::Duration;
use vec::Vec;
}
}
+impl AsInner<File> for TcpStream {
+ fn as_inner(&self) -> &File { &self.0 }
+}
+
+impl FromInner<File> for TcpStream {
+ fn from_inner(file: File) -> TcpStream {
+ TcpStream(file)
+ }
+}
+
+impl IntoInner<File> for TcpStream {
+ fn into_inner(self) -> File { self.0 }
+}
+
#[derive(Debug)]
pub struct TcpListener(File);
Err(Error::new(ErrorKind::Other, "TcpListener::set_ttl not implemented"))
}
}
+
+impl AsInner<File> for TcpListener {
+ fn as_inner(&self) -> &File { &self.0 }
+}
+
+impl FromInner<File> for TcpListener {
+ fn from_inner(file: File) -> TcpListener {
+ TcpListener(file)
+ }
+}
+
+impl IntoInner<File> for TcpListener {
+ fn into_inner(self) -> File { self.0 }
+}
use net::{SocketAddr, Ipv4Addr, Ipv6Addr};
use path::Path;
use sys::fs::{File, OpenOptions};
+use sys_common::{AsInner, FromInner, IntoInner};
use time::Duration;
use super::{path_to_peer_addr, path_to_local_addr};
Err(Error::new(ErrorKind::Other, "UdpSocket::leave_multicast_v6 not implemented"))
}
}
+
+impl AsInner<File> for UdpSocket {
+ fn as_inner(&self) -> &File { &self.0 }
+}
+
+impl FromInner<File> for UdpSocket {
+ fn from_inner(file: File) -> UdpSocket {
+ UdpSocket(file, UnsafeCell::new(None))
+ }
+}
+
+impl IntoInner<File> for UdpSocket {
+ fn into_inner(self) -> File { self.0 }
+}
// except according to those terms.
use io;
-use libc;
use rand::Rng;
-pub struct OsRng;
+// FIXME: Use rand:
+pub struct OsRng {
+ state: [u64; 2]
+}
impl OsRng {
/// Create a new `OsRng`.
pub fn new() -> io::Result<OsRng> {
- Ok(OsRng)
+ Ok(OsRng {
+ state: [0xBADF00D1, 0xDEADBEEF]
+ })
}
}
self.next_u64() as u32
}
fn next_u64(&mut self) -> u64 {
- unsafe { libc::random() }
+ // Store the first and second part.
+ let mut x = self.state[0];
+ let y = self.state[1];
+
+ // Put the second part into the first slot.
+ self.state[0] = y;
+ // Twist the first slot.
+ x ^= x << 23;
+ // Update the second slot.
+ self.state[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
+
+ // Generate the final integer.
+ self.state[1].wrapping_add(y)
+
}
fn fill_bytes(&mut self, buf: &mut [u8]) {
for chunk in buf.chunks_mut(8) {
--- /dev/null
+// 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 <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.
+
+use super::error::{Error, Result};
+
+pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+// Clobbers all registers - special for clone
+pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b)
+ : "memory", "r0", "r1", "r2", "r3", "r4"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b), "{r1}"(c)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
+ -> Result<usize> {
+ asm!("swi $$0"
+ : "={r0}"(a)
+ : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f)
+ : "memory"
+ : "volatile");
+
+ Error::demux(a)
+}
--- /dev/null
+// 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 <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.
+
+use super::error::{Error, Result};
+
+pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+// Clobbers all registers - special for clone
+pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b)
+ : "memory", "ebx", "ecx", "edx", "esi", "edi"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b), "{ecx}"(c)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
+ -> Result<usize> {
+ asm!("int 0x80"
+ : "={eax}"(a)
+ : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
--- /dev/null
+// 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 <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.
+
+use super::error::{Error, Result};
+
+pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+// Clobbers all registers - special for clone
+pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b)
+ : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8",
+ "r9", "r10", "r11", "r12", "r13", "r14", "r15"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b), "{rcx}"(c)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
+
+pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
+ -> Result<usize> {
+ asm!("int 0x80"
+ : "={rax}"(a)
+ : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f)
+ : "memory"
+ : "intel", "volatile");
+
+ Error::demux(a)
+}
--- /dev/null
+// 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 <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.
+
+use super::arch::*;
+use super::data::{Stat, StatVfs, TimeSpec};
+use super::error::Result;
+use super::number::*;
+
+use core::mem;
+
+/// Set the end of the process's heap
+///
+/// When `addr` is `0`, this function will return the current break.
+///
+/// When `addr` is nonzero, this function will attempt to set the end of the process's
+/// heap to `addr` and return the new program break. The new program break should be
+/// checked by the allocator, it may not be exactly `addr`, as it may be aligned to a page
+/// boundary.
+///
+/// On error, `Err(ENOMEM)` will be returned indicating that no memory is available
+pub unsafe fn brk(addr: usize) -> Result<usize> {
+ syscall1(SYS_BRK, addr)
+}
+
+/// Change the process's working directory
+///
+/// This function will attempt to set the process's working directory to `path`, which can be
+/// either a relative, scheme relative, or absolute path.
+///
+/// On success, `Ok(0)` will be returned. On error, one of the following errors will be returned.
+///
+/// # Errors
+///
+/// * `EACCES` - permission is denied for one of the components of `path`, or `path`
+/// * `EFAULT` - `path` does not point to the process's addressible memory
+/// * `EIO` - an I/O error occured
+/// * `ENOENT` - `path` does not exit
+/// * `ENOTDIR` - `path` is not a directory
+pub fn chdir(path: &str) -> Result<usize> {
+ unsafe { syscall2(SYS_CHDIR, path.as_ptr() as usize, path.len()) }
+}
+
+pub fn chmod(path: &str, mode: usize) -> Result<usize> {
+ unsafe { syscall3(SYS_CHMOD, path.as_ptr() as usize, path.len(), mode) }
+}
+
+/// Produce a fork of the current process, or a new process thread
+pub unsafe fn clone(flags: usize) -> Result<usize> {
+ syscall1_clobber(SYS_CLONE, flags)
+}
+
+/// Close a file
+pub fn close(fd: usize) -> Result<usize> {
+ unsafe { syscall1(SYS_CLOSE, fd) }
+}
+
+/// Get the current system time
+pub fn clock_gettime(clock: usize, tp: &mut TimeSpec) -> Result<usize> {
+ unsafe { syscall2(SYS_CLOCK_GETTIME, clock, tp as *mut TimeSpec as usize) }
+}
+
+/// Copy and transform a file descriptor
+pub fn dup(fd: usize, buf: &[u8]) -> Result<usize> {
+ unsafe { syscall3(SYS_DUP, fd, buf.as_ptr() as usize, buf.len()) }
+}
+
+/// Replace the current process with a new executable
+pub fn execve(path: &str, args: &[[usize; 2]]) -> Result<usize> {
+ unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(),
+ args.as_ptr() as usize, args.len()) }
+}
+
+/// Exit the current process
+pub fn exit(status: usize) -> Result<usize> {
+ unsafe { syscall1(SYS_EXIT, status) }
+}
+
+/// Register a file for event-based I/O
+pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result<usize> {
+ unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) }
+}
+
+/// Register a file for event-based I/O
+pub fn fevent(fd: usize, flags: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_FEVENT, fd, flags) }
+}
+
+/// Map a file into memory
+pub unsafe fn fmap(fd: usize, offset: usize, size: usize) -> Result<usize> {
+ syscall3(SYS_FMAP, fd, offset, size)
+}
+
+/// Unmap a memory-mapped file
+pub unsafe fn funmap(addr: usize) -> Result<usize> {
+ syscall1(SYS_FUNMAP, addr)
+}
+
+/// Retrieve the canonical path of a file
+pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
+ unsafe { syscall3(SYS_FPATH, fd, buf.as_mut_ptr() as usize, buf.len()) }
+}
+
+/// Get metadata about a file
+pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
+ unsafe { syscall3(SYS_FSTAT, fd, stat as *mut Stat as usize, mem::size_of::<Stat>()) }
+}
+
+/// Get metadata about a filesystem
+pub fn fstatvfs(fd: usize, stat: &mut StatVfs) -> Result<usize> {
+ unsafe { syscall3(SYS_FSTATVFS, fd, stat as *mut StatVfs as usize, mem::size_of::<StatVfs>()) }
+}
+
+/// Sync a file descriptor to its underlying medium
+pub fn fsync(fd: usize) -> Result<usize> {
+ unsafe { syscall1(SYS_FSYNC, fd) }
+}
+
+/// Truncate or extend a file to a specified length
+pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_FTRUNCATE, fd, len) }
+}
+
+/// Fast userspace mutex
+pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32)
+ -> Result<usize> {
+ syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize)
+}
+
+/// Get the current working directory
+pub fn getcwd(buf: &mut [u8]) -> Result<usize> {
+ unsafe { syscall2(SYS_GETCWD, buf.as_mut_ptr() as usize, buf.len()) }
+}
+
+/// Get the effective group ID
+pub fn getegid() -> Result<usize> {
+ unsafe { syscall0(SYS_GETEGID) }
+}
+
+/// Get the effective namespace
+pub fn getens() -> Result<usize> {
+ unsafe { syscall0(SYS_GETENS) }
+}
+
+/// Get the effective user ID
+pub fn geteuid() -> Result<usize> {
+ unsafe { syscall0(SYS_GETEUID) }
+}
+
+/// Get the current group ID
+pub fn getgid() -> Result<usize> {
+ unsafe { syscall0(SYS_GETGID) }
+}
+
+/// Get the current namespace
+pub fn getns() -> Result<usize> {
+ unsafe { syscall0(SYS_GETNS) }
+}
+
+/// Get the current process ID
+pub fn getpid() -> Result<usize> {
+ unsafe { syscall0(SYS_GETPID) }
+}
+
+/// Get the current user ID
+pub fn getuid() -> Result<usize> {
+ unsafe { syscall0(SYS_GETUID) }
+}
+
+/// Set the I/O privilege level
+pub unsafe fn iopl(level: usize) -> Result<usize> {
+ syscall1(SYS_IOPL, level)
+}
+
+/// Send a signal `sig` to the process identified by `pid`
+pub fn kill(pid: usize, sig: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_KILL, pid, sig) }
+}
+
+/// Create a link to a file
+pub unsafe fn link(old: *const u8, new: *const u8) -> Result<usize> {
+ syscall2(SYS_LINK, old as usize, new as usize)
+}
+
+/// Seek to `offset` bytes in a file descriptor
+pub fn lseek(fd: usize, offset: isize, whence: usize) -> Result<usize> {
+ unsafe { syscall3(SYS_LSEEK, fd, offset as usize, whence) }
+}
+
+/// Make a new scheme namespace
+pub fn mkns(schemes: &[[usize; 2]]) -> Result<usize> {
+ unsafe { syscall2(SYS_MKNS, schemes.as_ptr() as usize, schemes.len()) }
+}
+
+/// Sleep for the time specified in `req`
+pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
+ unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize,
+ rem as *mut TimeSpec as usize) }
+}
+
+/// Open a file
+pub fn open(path: &str, flags: usize) -> Result<usize> {
+ unsafe { syscall3(SYS_OPEN, path.as_ptr() as usize, path.len(), flags) }
+}
+
+/// Allocate pages, linearly in physical memory
+pub unsafe fn physalloc(size: usize) -> Result<usize> {
+ syscall1(SYS_PHYSALLOC, size)
+}
+
+/// Free physically allocated pages
+pub unsafe fn physfree(physical_address: usize, size: usize) -> Result<usize> {
+ syscall2(SYS_PHYSFREE, physical_address, size)
+}
+
+/// Map physical memory to virtual memory
+pub unsafe fn physmap(physical_address: usize, size: usize, flags: usize) -> Result<usize> {
+ syscall3(SYS_PHYSMAP, physical_address, size, flags)
+}
+
+/// Unmap previously mapped physical memory
+pub unsafe fn physunmap(virtual_address: usize) -> Result<usize> {
+ syscall1(SYS_PHYSUNMAP, virtual_address)
+}
+
+/// Create a pair of file descriptors referencing the read and write ends of a pipe
+pub fn pipe2(fds: &mut [usize; 2], flags: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_PIPE2, fds.as_ptr() as usize, flags) }
+}
+
+/// Read from a file descriptor into a buffer
+pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
+ unsafe { syscall3(SYS_READ, fd, buf.as_mut_ptr() as usize, buf.len()) }
+}
+
+/// Remove a directory
+pub fn rmdir(path: &str) -> Result<usize> {
+ unsafe { syscall2(SYS_RMDIR, path.as_ptr() as usize, path.len()) }
+}
+
+/// Set the current process group IDs
+pub fn setregid(rgid: usize, egid: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_SETREGID, rgid, egid) }
+}
+
+/// Make a new scheme namespace
+pub fn setrens(rns: usize, ens: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_SETRENS, rns, ens) }
+}
+
+/// Set the current process user IDs
+pub fn setreuid(ruid: usize, euid: usize) -> Result<usize> {
+ unsafe { syscall2(SYS_SETREUID, ruid, euid) }
+}
+
+/// Remove a file
+pub fn unlink(path: &str) -> Result<usize> {
+ unsafe { syscall2(SYS_UNLINK, path.as_ptr() as usize, path.len()) }
+}
+
+/// Convert a virtual address to a physical one
+pub unsafe fn virttophys(virtual_address: usize) -> Result<usize> {
+ syscall1(SYS_VIRTTOPHYS, virtual_address)
+}
+
+/// Check if a child process has exited or received a signal
+pub fn waitpid(pid: usize, status: &mut usize, options: usize) -> Result<usize> {
+ unsafe { syscall3(SYS_WAITPID, pid, status as *mut usize as usize, options) }
+}
+
+/// Write a buffer to a file descriptor
+///
+/// The kernel will attempt to write the bytes in `buf` to the file descriptor `fd`, returning
+/// either an `Err`, explained below, or `Ok(count)` where `count` is the number of bytes which
+/// were written.
+///
+/// # Errors
+///
+/// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block
+/// * `EBADF` - the file descriptor is not valid or is not open for writing
+/// * `EFAULT` - `buf` does not point to the process's addressible memory
+/// * `EIO` - an I/O error occured
+/// * `ENOSPC` - the device containing the file descriptor has no room for data
+/// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed
+pub fn write(fd: usize, buf: &[u8]) -> Result<usize> {
+ unsafe { syscall3(SYS_WRITE, fd, buf.as_ptr() as usize, buf.len()) }
+}
+
+/// Yield the process's time slice to the kernel
+///
+/// This function will return Ok(0) on success
+pub fn sched_yield() -> Result<usize> {
+ unsafe { syscall0(SYS_YIELD) }
+}
--- /dev/null
+// 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 <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.
+
+use core::ops::{Deref, DerefMut};
+use core::{mem, slice};
+
+#[derive(Copy, Clone, Debug, Default)]
+#[repr(packed)]
+pub struct Stat {
+ pub st_dev: u64,
+ pub st_ino: u64,
+ pub st_mode: u16,
+ pub st_nlink: u32,
+ pub st_uid: u32,
+ pub st_gid: u32,
+ pub st_size: u64,
+ pub st_blksize: u32,
+ pub st_blocks: u64,
+ pub st_mtime: u64,
+ pub st_mtime_nsec: u32,
+ pub st_atime: u64,
+ pub st_atime_nsec: u32,
+ pub st_ctime: u64,
+ pub st_ctime_nsec: u32,
+}
+
+impl Deref for Stat {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const Stat as *const u8,
+ mem::size_of::<Stat>()) as &[u8]
+ }
+ }
+}
+
+impl DerefMut for Stat {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut Stat as *mut u8,
+ mem::size_of::<Stat>()) as &mut [u8]
+ }
+ }
+}
+
+#[derive(Copy, Clone, Debug, Default)]
+#[repr(packed)]
+pub struct StatVfs {
+ pub f_bsize: u32,
+ pub f_blocks: u64,
+ pub f_bfree: u64,
+ pub f_bavail: u64,
+}
+
+impl Deref for StatVfs {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const StatVfs as *const u8,
+ mem::size_of::<StatVfs>()) as &[u8]
+ }
+ }
+}
+
+impl DerefMut for StatVfs {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8,
+ mem::size_of::<StatVfs>()) as &mut [u8]
+ }
+ }
+}
+
+#[derive(Copy, Clone, Debug, Default)]
+#[repr(packed)]
+pub struct TimeSpec {
+ pub tv_sec: i64,
+ pub tv_nsec: i32,
+}
--- /dev/null
+// 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 <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.
+
+use core::{fmt, result};
+
+#[derive(Eq, PartialEq)]
+pub struct Error {
+ pub errno: i32,
+}
+
+pub type Result<T> = result::Result<T, Error>;
+
+impl Error {
+ pub fn new(errno: i32) -> Error {
+ Error { errno: errno }
+ }
+
+ pub fn mux(result: Result<usize>) -> usize {
+ match result {
+ Ok(value) => value,
+ Err(error) => -error.errno as usize,
+ }
+ }
+
+ pub fn demux(value: usize) -> Result<usize> {
+ let errno = -(value as i32);
+ if errno >= 1 && errno < STR_ERROR.len() as i32 {
+ Err(Error::new(errno))
+ } else {
+ Ok(value)
+ }
+ }
+
+ pub fn text(&self) -> &str {
+ if let Some(description) = STR_ERROR.get(self.errno as usize) {
+ description
+ } else {
+ "Unknown Error"
+ }
+ }
+}
+
+impl fmt::Debug for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
+ f.write_str(self.text())
+ }
+}
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
+ f.write_str(self.text())
+ }
+}
+
+pub const EPERM: i32 = 1; /* Operation not permitted */
+pub const ENOENT: i32 = 2; /* No such file or directory */
+pub const ESRCH: i32 = 3; /* No such process */
+pub const EINTR: i32 = 4; /* Interrupted system call */
+pub const EIO: i32 = 5; /* I/O error */
+pub const ENXIO: i32 = 6; /* No such device or address */
+pub const E2BIG: i32 = 7; /* Argument list too long */
+pub const ENOEXEC: i32 = 8; /* Exec format error */
+pub const EBADF: i32 = 9; /* Bad file number */
+pub const ECHILD: i32 = 10; /* No child processes */
+pub const EAGAIN: i32 = 11; /* Try again */
+pub const ENOMEM: i32 = 12; /* Out of memory */
+pub const EACCES: i32 = 13; /* Permission denied */
+pub const EFAULT: i32 = 14; /* Bad address */
+pub const ENOTBLK: i32 = 15; /* Block device required */
+pub const EBUSY: i32 = 16; /* Device or resource busy */
+pub const EEXIST: i32 = 17; /* File exists */
+pub const EXDEV: i32 = 18; /* Cross-device link */
+pub const ENODEV: i32 = 19; /* No such device */
+pub const ENOTDIR: i32 = 20; /* Not a directory */
+pub const EISDIR: i32 = 21; /* Is a directory */
+pub const EINVAL: i32 = 22; /* Invalid argument */
+pub const ENFILE: i32 = 23; /* File table overflow */
+pub const EMFILE: i32 = 24; /* Too many open files */
+pub const ENOTTY: i32 = 25; /* Not a typewriter */
+pub const ETXTBSY: i32 = 26; /* Text file busy */
+pub const EFBIG: i32 = 27; /* File too large */
+pub const ENOSPC: i32 = 28; /* No space left on device */
+pub const ESPIPE: i32 = 29; /* Illegal seek */
+pub const EROFS: i32 = 30; /* Read-only file system */
+pub const EMLINK: i32 = 31; /* Too many links */
+pub const EPIPE: i32 = 32; /* Broken pipe */
+pub const EDOM: i32 = 33; /* Math argument out of domain of func */
+pub const ERANGE: i32 = 34; /* Math result not representable */
+pub const EDEADLK: i32 = 35; /* Resource deadlock would occur */
+pub const ENAMETOOLONG: i32 = 36; /* File name too long */
+pub const ENOLCK: i32 = 37; /* No record locks available */
+pub const ENOSYS: i32 = 38; /* Function not implemented */
+pub const ENOTEMPTY: i32 = 39; /* Directory not empty */
+pub const ELOOP: i32 = 40; /* Too many symbolic links encountered */
+pub const EWOULDBLOCK: i32 = 41; /* Operation would block */
+pub const ENOMSG: i32 = 42; /* No message of desired type */
+pub const EIDRM: i32 = 43; /* Identifier removed */
+pub const ECHRNG: i32 = 44; /* Channel number out of range */
+pub const EL2NSYNC: i32 = 45; /* Level 2 not synchronized */
+pub const EL3HLT: i32 = 46; /* Level 3 halted */
+pub const EL3RST: i32 = 47; /* Level 3 reset */
+pub const ELNRNG: i32 = 48; /* Link number out of range */
+pub const EUNATCH: i32 = 49; /* Protocol driver not attached */
+pub const ENOCSI: i32 = 50; /* No CSI structure available */
+pub const EL2HLT: i32 = 51; /* Level 2 halted */
+pub const EBADE: i32 = 52; /* Invalid exchange */
+pub const EBADR: i32 = 53; /* Invalid request descriptor */
+pub const EXFULL: i32 = 54; /* Exchange full */
+pub const ENOANO: i32 = 55; /* No anode */
+pub const EBADRQC: i32 = 56; /* Invalid request code */
+pub const EBADSLT: i32 = 57; /* Invalid slot */
+pub const EDEADLOCK: i32 = 58; /* Resource deadlock would occur */
+pub const EBFONT: i32 = 59; /* Bad font file format */
+pub const ENOSTR: i32 = 60; /* Device not a stream */
+pub const ENODATA: i32 = 61; /* No data available */
+pub const ETIME: i32 = 62; /* Timer expired */
+pub const ENOSR: i32 = 63; /* Out of streams resources */
+pub const ENONET: i32 = 64; /* Machine is not on the network */
+pub const ENOPKG: i32 = 65; /* Package not installed */
+pub const EREMOTE: i32 = 66; /* Object is remote */
+pub const ENOLINK: i32 = 67; /* Link has been severed */
+pub const EADV: i32 = 68; /* Advertise error */
+pub const ESRMNT: i32 = 69; /* Srmount error */
+pub const ECOMM: i32 = 70; /* Communication error on send */
+pub const EPROTO: i32 = 71; /* Protocol error */
+pub const EMULTIHOP: i32 = 72; /* Multihop attempted */
+pub const EDOTDOT: i32 = 73; /* RFS specific error */
+pub const EBADMSG: i32 = 74; /* Not a data message */
+pub const EOVERFLOW: i32 = 75; /* Value too large for defined data type */
+pub const ENOTUNIQ: i32 = 76; /* Name not unique on network */
+pub const EBADFD: i32 = 77; /* File descriptor in bad state */
+pub const EREMCHG: i32 = 78; /* Remote address changed */
+pub const ELIBACC: i32 = 79; /* Can not access a needed shared library */
+pub const ELIBBAD: i32 = 80; /* Accessing a corrupted shared library */
+pub const ELIBSCN: i32 = 81; /* .lib section in a.out corrupted */
+pub const ELIBMAX: i32 = 82; /* Attempting to link in too many shared libraries */
+pub const ELIBEXEC: i32 = 83; /* Cannot exec a shared library directly */
+pub const EILSEQ: i32 = 84; /* Illegal byte sequence */
+pub const ERESTART: i32 = 85; /* Interrupted system call should be restarted */
+pub const ESTRPIPE: i32 = 86; /* Streams pipe error */
+pub const EUSERS: i32 = 87; /* Too many users */
+pub const ENOTSOCK: i32 = 88; /* Socket operation on non-socket */
+pub const EDESTADDRREQ: i32 = 89; /* Destination address required */
+pub const EMSGSIZE: i32 = 90; /* Message too long */
+pub const EPROTOTYPE: i32 = 91; /* Protocol wrong type for socket */
+pub const ENOPROTOOPT: i32 = 92; /* Protocol not available */
+pub const EPROTONOSUPPORT: i32 = 93; /* Protocol not supported */
+pub const ESOCKTNOSUPPORT: i32 = 94; /* Socket type not supported */
+pub const EOPNOTSUPP: i32 = 95; /* Operation not supported on transport endpoint */
+pub const EPFNOSUPPORT: i32 = 96; /* Protocol family not supported */
+pub const EAFNOSUPPORT: i32 = 97; /* Address family not supported by protocol */
+pub const EADDRINUSE: i32 = 98; /* Address already in use */
+pub const EADDRNOTAVAIL: i32 = 99; /* Cannot assign requested address */
+pub const ENETDOWN: i32 = 100; /* Network is down */
+pub const ENETUNREACH: i32 = 101; /* Network is unreachable */
+pub const ENETRESET: i32 = 102; /* Network dropped connection because of reset */
+pub const ECONNABORTED: i32 = 103; /* Software caused connection abort */
+pub const ECONNRESET: i32 = 104; /* Connection reset by peer */
+pub const ENOBUFS: i32 = 105; /* No buffer space available */
+pub const EISCONN: i32 = 106; /* Transport endpoint is already connected */
+pub const ENOTCONN: i32 = 107; /* Transport endpoint is not connected */
+pub const ESHUTDOWN: i32 = 108; /* Cannot send after transport endpoint shutdown */
+pub const ETOOMANYREFS: i32 = 109; /* Too many references: cannot splice */
+pub const ETIMEDOUT: i32 = 110; /* Connection timed out */
+pub const ECONNREFUSED: i32 = 111; /* Connection refused */
+pub const EHOSTDOWN: i32 = 112; /* Host is down */
+pub const EHOSTUNREACH: i32 = 113; /* No route to host */
+pub const EALREADY: i32 = 114; /* Operation already in progress */
+pub const EINPROGRESS: i32 = 115; /* Operation now in progress */
+pub const ESTALE: i32 = 116; /* Stale NFS file handle */
+pub const EUCLEAN: i32 = 117; /* Structure needs cleaning */
+pub const ENOTNAM: i32 = 118; /* Not a XENIX named type file */
+pub const ENAVAIL: i32 = 119; /* No XENIX semaphores available */
+pub const EISNAM: i32 = 120; /* Is a named type file */
+pub const EREMOTEIO: i32 = 121; /* Remote I/O error */
+pub const EDQUOT: i32 = 122; /* Quota exceeded */
+pub const ENOMEDIUM: i32 = 123; /* No medium found */
+pub const EMEDIUMTYPE: i32 = 124; /* Wrong medium type */
+pub const ECANCELED: i32 = 125; /* Operation Canceled */
+pub const ENOKEY: i32 = 126; /* Required key not available */
+pub const EKEYEXPIRED: i32 = 127; /* Key has expired */
+pub const EKEYREVOKED: i32 = 128; /* Key has been revoked */
+pub const EKEYREJECTED: i32 = 129; /* Key was rejected by service */
+pub const EOWNERDEAD: i32 = 130; /* Owner died */
+pub const ENOTRECOVERABLE: i32 = 131; /* State not recoverable */
+
+pub static STR_ERROR: [&'static str; 132] = ["Success",
+ "Operation not permitted",
+ "No such file or directory",
+ "No such process",
+ "Interrupted system call",
+ "I/O error",
+ "No such device or address",
+ "Argument list too long",
+ "Exec format error",
+ "Bad file number",
+ "No child processes",
+ "Try again",
+ "Out of memory",
+ "Permission denied",
+ "Bad address",
+ "Block device required",
+ "Device or resource busy",
+ "File exists",
+ "Cross-device link",
+ "No such device",
+ "Not a directory",
+ "Is a directory",
+ "Invalid argument",
+ "File table overflow",
+ "Too many open files",
+ "Not a typewriter",
+ "Text file busy",
+ "File too large",
+ "No space left on device",
+ "Illegal seek",
+ "Read-only file system",
+ "Too many links",
+ "Broken pipe",
+ "Math argument out of domain of func",
+ "Math result not representable",
+ "Resource deadlock would occur",
+ "File name too long",
+ "No record locks available",
+ "Function not implemented",
+ "Directory not empty",
+ "Too many symbolic links encountered",
+ "Operation would block",
+ "No message of desired type",
+ "Identifier removed",
+ "Channel number out of range",
+ "Level 2 not synchronized",
+ "Level 3 halted",
+ "Level 3 reset",
+ "Link number out of range",
+ "Protocol driver not attached",
+ "No CSI structure available",
+ "Level 2 halted",
+ "Invalid exchange",
+ "Invalid request descriptor",
+ "Exchange full",
+ "No anode",
+ "Invalid request code",
+ "Invalid slot",
+ "Resource deadlock would occur",
+ "Bad font file format",
+ "Device not a stream",
+ "No data available",
+ "Timer expired",
+ "Out of streams resources",
+ "Machine is not on the network",
+ "Package not installed",
+ "Object is remote",
+ "Link has been severed",
+ "Advertise error",
+ "Srmount error",
+ "Communication error on send",
+ "Protocol error",
+ "Multihop attempted",
+ "RFS specific error",
+ "Not a data message",
+ "Value too large for defined data type",
+ "Name not unique on network",
+ "File descriptor in bad state",
+ "Remote address changed",
+ "Can not access a needed shared library",
+ "Accessing a corrupted shared library",
+ ".lib section in a.out corrupted",
+ "Attempting to link in too many shared libraries",
+ "Cannot exec a shared library directly",
+ "Illegal byte sequence",
+ "Interrupted system call should be restarted",
+ "Streams pipe error",
+ "Too many users",
+ "Socket operation on non-socket",
+ "Destination address required",
+ "Message too long",
+ "Protocol wrong type for socket",
+ "Protocol not available",
+ "Protocol not supported",
+ "Socket type not supported",
+ "Operation not supported on transport endpoint",
+ "Protocol family not supported",
+ "Address family not supported by protocol",
+ "Address already in use",
+ "Cannot assign requested address",
+ "Network is down",
+ "Network is unreachable",
+ "Network dropped connection because of reset",
+ "Software caused connection abort",
+ "Connection reset by peer",
+ "No buffer space available",
+ "Transport endpoint is already connected",
+ "Transport endpoint is not connected",
+ "Cannot send after transport endpoint shutdown",
+ "Too many references: cannot splice",
+ "Connection timed out",
+ "Connection refused",
+ "Host is down",
+ "No route to host",
+ "Operation already in progress",
+ "Operation now in progress",
+ "Stale NFS file handle",
+ "Structure needs cleaning",
+ "Not a XENIX named type file",
+ "No XENIX semaphores available",
+ "Is a named type file",
+ "Remote I/O error",
+ "Quota exceeded",
+ "No medium found",
+ "Wrong medium type",
+ "Operation Canceled",
+ "Required key not available",
+ "Key has expired",
+ "Key has been revoked",
+ "Key was rejected by service",
+ "Owner died",
+ "State not recoverable"];
--- /dev/null
+// 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 <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.
+
+pub const CLONE_VM: usize = 0x100;
+pub const CLONE_FS: usize = 0x200;
+pub const CLONE_FILES: usize = 0x400;
+pub const CLONE_VFORK: usize = 0x4000;
+
+pub const CLOCK_REALTIME: usize = 1;
+pub const CLOCK_MONOTONIC: usize = 4;
+
+pub const EVENT_NONE: usize = 0;
+pub const EVENT_READ: usize = 1;
+pub const EVENT_WRITE: usize = 2;
+
+pub const F_GETFL: usize = 1;
+pub const F_SETFL: usize = 2;
+
+pub const FUTEX_WAIT: usize = 0;
+pub const FUTEX_WAKE: usize = 1;
+pub const FUTEX_REQUEUE: usize = 2;
+
+pub const MAP_WRITE: usize = 1;
+pub const MAP_WRITE_COMBINE: usize = 2;
+
+pub const MODE_TYPE: u16 = 0xF000;
+pub const MODE_DIR: u16 = 0x4000;
+pub const MODE_FILE: u16 = 0x8000;
+
+pub const MODE_PERM: u16 = 0x0FFF;
+pub const MODE_SETUID: u16 = 0o4000;
+pub const MODE_SETGID: u16 = 0o2000;
+
+pub const O_RDONLY: usize = 0x0001_0000;
+pub const O_WRONLY: usize = 0x0002_0000;
+pub const O_RDWR: usize = 0x0003_0000;
+pub const O_NONBLOCK: usize = 0x0004_0000;
+pub const O_APPEND: usize = 0x0008_0000;
+pub const O_SHLOCK: usize = 0x0010_0000;
+pub const O_EXLOCK: usize = 0x0020_0000;
+pub const O_ASYNC: usize = 0x0040_0000;
+pub const O_FSYNC: usize = 0x0080_0000;
+pub const O_CLOEXEC: usize = 0x0100_0000;
+pub const O_CREAT: usize = 0x0200_0000;
+pub const O_TRUNC: usize = 0x0400_0000;
+pub const O_EXCL: usize = 0x0800_0000;
+pub const O_DIRECTORY: usize = 0x1000_0000;
+pub const O_STAT: usize = 0x2000_0000;
+pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
+
+pub const SEEK_SET: usize = 0;
+pub const SEEK_CUR: usize = 1;
+pub const SEEK_END: usize = 2;
+
+pub const SIGHUP: usize = 1;
+pub const SIGINT: usize = 2;
+pub const SIGQUIT: usize = 3;
+pub const SIGILL: usize = 4;
+pub const SIGTRAP: usize = 5;
+pub const SIGABRT: usize = 6;
+pub const SIGBUS: usize = 7;
+pub const SIGFPE: usize = 8;
+pub const SIGKILL: usize = 9;
+pub const SIGUSR1: usize = 10;
+pub const SIGSEGV: usize = 11;
+pub const SIGUSR2: usize = 12;
+pub const SIGPIPE: usize = 13;
+pub const SIGALRM: usize = 14;
+pub const SIGTERM: usize = 15;
+pub const SIGSTKFLT: usize= 16;
+pub const SIGCHLD: usize = 17;
+pub const SIGCONT: usize = 18;
+pub const SIGSTOP: usize = 19;
+pub const SIGTSTP: usize = 20;
+pub const SIGTTIN: usize = 21;
+pub const SIGTTOU: usize = 22;
+pub const SIGURG: usize = 23;
+pub const SIGXCPU: usize = 24;
+pub const SIGXFSZ: usize = 25;
+pub const SIGVTALRM: usize= 26;
+pub const SIGPROF: usize = 27;
+pub const SIGWINCH: usize = 28;
+pub const SIGIO: usize = 29;
+pub const SIGPWR: usize = 30;
+pub const SIGSYS: usize = 31;
+
+pub const WNOHANG: usize = 1;
--- /dev/null
+// 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 <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.
+
+pub use self::arch::*;
+pub use self::call::*;
+pub use self::data::*;
+pub use self::error::*;
+pub use self::flag::*;
+pub use self::number::*;
+
+#[cfg(target_arch = "arm")]
+#[path="arch/arm.rs"]
+mod arch;
+
+#[cfg(target_arch = "x86")]
+#[path="arch/x86.rs"]
+mod arch;
+
+#[cfg(target_arch = "x86_64")]
+#[path="arch/x86_64.rs"]
+mod arch;
+
+/// Function definitions
+pub mod call;
+
+/// Complex structures that are used for some system calls
+pub mod data;
+
+/// All errors that can be generated by a system call
+pub mod error;
+
+/// Flags used as an argument to many system calls
+pub mod flag;
+
+/// Call numbers used by each system call
+pub mod number;
--- /dev/null
+// 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 <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.
+
+pub const SYS_CLASS: usize = 0xF000_0000;
+pub const SYS_CLASS_PATH: usize=0x1000_0000;
+pub const SYS_CLASS_FILE: usize=0x2000_0000;
+
+pub const SYS_ARG: usize = 0x0F00_0000;
+pub const SYS_ARG_SLICE: usize =0x0100_0000;
+pub const SYS_ARG_MSLICE: usize=0x0200_0000;
+pub const SYS_ARG_PATH: usize = 0x0300_0000;
+
+pub const SYS_RET: usize = 0x00F0_0000;
+pub const SYS_RET_FILE: usize = 0x0010_0000;
+
+pub const SYS_LINK: usize = SYS_CLASS_PATH | SYS_ARG_PATH | 9;
+pub const SYS_OPEN: usize = SYS_CLASS_PATH | SYS_RET_FILE | 5;
+pub const SYS_CHMOD: usize = SYS_CLASS_PATH | 15;
+pub const SYS_RMDIR: usize = SYS_CLASS_PATH | 84;
+pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10;
+
+pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6;
+pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41;
+pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3;
+pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4;
+pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19;
+pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55;
+pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
+pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90;
+pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91;
+pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928;
+pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28;
+pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100;
+pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118;
+pub const SYS_FTRUNCATE: usize =SYS_CLASS_FILE | 93;
+
+pub const SYS_BRK: usize = 45;
+pub const SYS_CHDIR: usize = 12;
+pub const SYS_CLOCK_GETTIME: usize = 265;
+pub const SYS_CLONE: usize = 120;
+pub const SYS_EXECVE: usize = 11;
+pub const SYS_EXIT: usize = 1;
+pub const SYS_FUTEX: usize = 240;
+pub const SYS_GETCWD: usize = 183;
+pub const SYS_GETEGID: usize = 202;
+pub const SYS_GETENS: usize = 951;
+pub const SYS_GETEUID: usize = 201;
+pub const SYS_GETGID: usize = 200;
+pub const SYS_GETNS: usize = 950;
+pub const SYS_GETPID: usize = 20;
+pub const SYS_GETUID: usize = 199;
+pub const SYS_IOPL: usize = 110;
+pub const SYS_KILL: usize = 37;
+pub const SYS_MKNS: usize = 984;
+pub const SYS_NANOSLEEP: usize =162;
+pub const SYS_PHYSALLOC: usize =945;
+pub const SYS_PHYSFREE: usize = 946;
+pub const SYS_PHYSMAP: usize = 947;
+pub const SYS_PHYSUNMAP: usize =948;
+pub const SYS_VIRTTOPHYS: usize=949;
+pub const SYS_PIPE2: usize = 331;
+pub const SYS_SETREGID: usize = 204;
+pub const SYS_SETRENS: usize = 952;
+pub const SYS_SETREUID: usize = 203;
+pub const SYS_WAITPID: usize = 7;
+pub const SYS_YIELD: usize = 158;
pub type mx_status_t = i32;
pub type mx_size_t = usize;
-pub type mx_ssize_t = isize;
pub const MX_HANDLE_INVALID: mx_handle_t = 0;
// Free functions
////////////////////////////////////////////////////////////////////////////////
-/// Spawns a new thread, returning a `JoinHandle` for it.
+/// Spawns a new thread, returning a [`JoinHandle`] for it.
///
/// The join handle will implicitly *detach* the child thread upon being
/// dropped. In this case, the child thread may outlive the parent (unless
/// the parent thread is the main thread; the whole process is terminated when
-/// the main thread finishes.) Additionally, the join handle provides a `join`
+/// the main thread finishes). Additionally, the join handle provides a [`join`]
/// method that can be used to join the child thread. If the child thread
-/// panics, `join` will return an `Err` containing the argument given to
-/// `panic`.
+/// panics, [`join`] will return an [`Err`] containing the argument given to
+/// [`panic`].
///
/// # Panics
///
-/// Panics if the OS fails to create a thread; use `Builder::spawn`
+/// Panics if the OS fails to create a thread; use [`Builder::spawn`]
/// to recover from such errors.
+///
+/// [`JoinHandle`]: ../../std/thread/struct.JoinHandle.html
+/// [`join`]: ../../std/thread/struct.JoinHandle.html#method.join
+/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
+/// [`panic!`]: ../../std/macro.panic.html
+/// [`Builder::spawn`]: ../../std/thread/struct.Builder.html#method.spawn
+///
+/// # Examples
+///
+/// ```
+/// use std::thread;
+///
+/// let handler = thread::spawn(|| {
+/// // thread code
+/// });
+///
+/// handler.join().unwrap();
+/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
/// Gets a handle to the thread that invokes it.
///
-/// #Examples
+/// # Examples
///
/// Getting a handle to the current thread with `thread::current()`:
///
}
/// Cooperatively gives up a timeslice to the OS scheduler.
+///
+/// # Examples
+///
+/// ```
+/// use std::thread;
+///
+/// thread::yield_now();
+/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn yield_now() {
imp::Thread::yield_now()
///
/// # Examples
///
-/// ```rust,should_panic
+/// ```should_panic
/// use std::thread;
///
/// struct SomeStruct;
/// specifics or platform-dependent functionality. Note that on unix platforms
/// this function will not return early due to a signal being received or a
/// spurious wakeup.
+///
+/// # Examples
+///
+/// ```no_run
+/// use std::thread;
+///
+/// // Let's sleep for 2 seconds:
+/// thread::sleep_ms(2000);
+/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::thread::sleep`")]
pub fn sleep_ms(ms: u32) {
///
/// # Examples
///
-/// ```rust,no_run
+/// ```no_run
/// use std::{thread, time};
///
/// let ten_millis = time::Duration::from_millis(10);
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Path {
pub span: Span,
- /// A `::foo` path, is relative to the crate root rather than current
- /// module (like paths in an import).
- pub global: bool,
/// The segments in the path: the things separated by `::`.
+ /// Global paths begin with `keywords::CrateRoot`.
pub segments: Vec<PathSegment>,
}
pub fn from_ident(s: Span, identifier: Ident) -> Path {
Path {
span: s,
- global: false,
segments: vec![identifier.into()],
}
}
+
+ pub fn default_to_global(mut self) -> Path {
+ let name = self.segments[0].identifier.name;
+ if !self.is_global() && name != "$crate" &&
+ name != keywords::SelfValue.name() && name != keywords::Super.name() {
+ self.segments.insert(0, PathSegment::crate_root());
+ }
+ self
+ }
+
+ pub fn is_global(&self) -> bool {
+ !self.segments.is_empty() && self.segments[0].identifier.name == keywords::CrateRoot.name()
+ }
}
/// A segment of a path: an identifier, an optional lifetime, and a set of types.
}
}
+impl PathSegment {
+ pub fn crate_root() -> Self {
+ PathSegment {
+ identifier: keywords::CrateRoot.ident(),
+ parameters: None,
+ }
+ }
+}
+
/// Parameters of a path segment.
///
/// E.g. `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`
fn next_node_id(&mut self) -> ast::NodeId;
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item>;
+ fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool;
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion);
fn add_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>);
fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }
fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item> { item }
+ fn is_whitelisted_legacy_custom_derive(&self, _name: Name) -> bool { false }
fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {}
fn add_ext(&mut self, _ident: ast::Ident, _ext: Rc<SyntaxExtension>) {}
bindings: Vec<ast::TypeBinding> )
-> ast::Path {
let last_identifier = idents.pop().unwrap();
- let mut segments: Vec<ast::PathSegment> = idents.into_iter().map(Into::into).collect();
+ let mut segments: Vec<ast::PathSegment> = Vec::new();
+ if global {
+ segments.push(ast::PathSegment::crate_root());
+ }
+
+ segments.extend(idents.into_iter().map(Into::into));
let parameters = if lifetimes.is_empty() && types.is_empty() && bindings.is_empty() {
None
} else {
segments.push(ast::PathSegment { identifier: last_identifier, parameters: parameters });
ast::Path {
span: sp,
- global: global,
segments: segments,
}
}
pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion {
fn mac_placeholder() -> ast::Mac {
dummy_spanned(ast::Mac_ {
- path: ast::Path { span: DUMMY_SP, global: false, segments: Vec::new() },
+ path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
tts: Vec::new(),
})
}
i
}
-pub fn noop_fold_path<T: Folder>(Path {global, segments, span}: Path, fld: &mut T) -> Path {
+pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) -> Path {
Path {
- global: global,
segments: segments.move_map(|PathSegment {identifier, parameters}| PathSegment {
identifier: fld.fold_ident(identifier),
parameters: parameters.map(|ps| ps.map(|ps| fld.fold_path_parameters(ps))),
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Path(None, ast::Path {
span: sp(0, 1),
- global: false,
segments: vec![Ident::from_str("a").into()],
}),
span: sp(0, 1),
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Path(None, ast::Path {
span: sp(0, 6),
- global: true,
- segments: vec![Ident::from_str("a").into(), Ident::from_str("b").into()],
+ segments: vec![ast::PathSegment::crate_root(),
+ Ident::from_str("a").into(),
+ Ident::from_str("b").into()]
}),
span: sp(0, 6),
attrs: ThinVec::new(),
id: ast::DUMMY_NODE_ID,
node:ast::ExprKind::Path(None, ast::Path{
span: sp(7, 8),
- global: false,
segments: vec![Ident::from_str("d").into()],
}),
span:sp(7,8),
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Path(None, ast::Path {
span:sp(0,1),
- global:false,
segments: vec![Ident::from_str("b").into()],
}),
span: sp(0,1),
ty: P(ast::Ty{id: ast::DUMMY_NODE_ID,
node: ast::TyKind::Path(None, ast::Path{
span:sp(10,13),
- global:false,
segments: vec![Ident::from_str("i32").into()],
}),
span:sp(10,13)
node: ast::ExprKind::Path(None,
ast::Path{
span:sp(17,18),
- global:false,
segments: vec![Ident::from_str("b").into()],
}),
span: sp(17,18),
} else {
ast::Path {
span: span,
- global: false,
segments: vec![]
}
};
// Parse any number of segments and bound sets. A segment is an
// identifier followed by an optional lifetime and a set of types.
// A bound set is a set of type parameter bounds.
- let segments = match mode {
+ let mut segments = match mode {
PathStyle::Type => {
self.parse_path_segments_without_colons()?
}
}
};
+ if is_global {
+ segments.insert(0, ast::PathSegment::crate_root());
+ }
+
// Assemble the span.
let span = mk_sp(lo, self.prev_span.hi);
// Assemble the result.
Ok(ast::Path {
span: span,
- global: is_global,
segments: segments,
})
}
return Ok(where_clause);
}
+ // This is a temporary hack.
+ //
+ // We are considering adding generics to the `where` keyword as an alternative higher-rank
+ // parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
+ // change, for now we refuse to parse `where < (ident | lifetime) (> | , | :)`.
+ if token::Lt == self.token {
+ let ident_or_lifetime = self.look_ahead(1, |t| t.is_ident() || t.is_lifetime());
+ if ident_or_lifetime {
+ let gt_comma_or_colon = self.look_ahead(2, |t| {
+ *t == token::Gt || *t == token::Comma || *t == token::Colon
+ });
+ if gt_comma_or_colon {
+ self.span_err(self.span, "syntax `where<T>` is reserved for future use");
+ }
+ }
+ }
+
let mut parsed_something = false;
loop {
let lo = self.span.lo;
} else if self.eat_keyword(keywords::Crate) {
pub_crate(self)
} else {
- let path = self.parse_path(PathStyle::Mod)?;
+ let path = self.parse_path(PathStyle::Mod)?.default_to_global();
self.expect(&token::CloseDelim(token::Paren))?;
Ok(Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID })
}
if self.check(&token::OpenDelim(token::Brace)) || self.check(&token::BinOp(token::Star)) ||
self.is_import_coupler() {
// `{foo, bar}`, `::{foo, bar}`, `*`, or `::*`.
+ self.eat(&token::ModSep);
let prefix = ast::Path {
- global: self.eat(&token::ModSep),
- segments: Vec::new(),
+ segments: vec![ast::PathSegment::crate_root()],
span: mk_sp(lo, self.span.hi),
};
let view_path_kind = if self.eat(&token::BinOp(token::Star)) {
};
Ok(P(spanned(lo, self.span.hi, view_path_kind)))
} else {
- let prefix = self.parse_path(PathStyle::Mod)?;
+ let prefix = self.parse_path(PathStyle::Mod)?.default_to_global();
if self.is_import_coupler() {
// `foo::bar::{a, b}` or `foo::bar::*`
self.bump();
}
pub fn path_to_string(p: &ast::Path) -> String {
- to_string(|s| s.print_path(p, false, 0))
+ to_string(|s| s.print_path(p, false, 0, false))
}
pub fn ident_to_string(id: ast::Ident) -> String {
match *vis {
ast::Visibility::Public => format!("pub {}", s),
ast::Visibility::Crate(_) => format!("pub(crate) {}", s),
- ast::Visibility::Restricted { ref path, .. } => format!("pub({}) {}", path, s),
+ ast::Visibility::Restricted { ref path, .. } =>
+ format!("pub({}) {}", to_string(|s| s.print_path(path, false, 0, true)), s),
ast::Visibility::Inherited => s.to_string()
}
}
&generics));
}
ast::TyKind::Path(None, ref path) => {
- try!(self.print_path(path, false, 0));
+ try!(self.print_path(path, false, 0, false));
}
ast::TyKind::Path(Some(ref qself), ref path) => {
try!(self.print_qpath(path, qself, false))
}
ast::ItemKind::Mac(codemap::Spanned { ref node, .. }) => {
try!(self.print_visibility(&item.vis));
- try!(self.print_path(&node.path, false, 0));
+ try!(self.print_path(&node.path, false, 0, false));
try!(word(&mut self.s, "! "));
try!(self.print_ident(item.ident));
try!(self.cbox(INDENT_UNIT));
}
fn print_trait_ref(&mut self, t: &ast::TraitRef) -> io::Result<()> {
- self.print_path(&t.path, false, 0)
+ self.print_path(&t.path, false, 0, false)
}
fn print_formal_lifetime_list(&mut self, lifetimes: &[ast::LifetimeDef]) -> io::Result<()> {
match *vis {
ast::Visibility::Public => self.word_nbsp("pub"),
ast::Visibility::Crate(_) => self.word_nbsp("pub(crate)"),
- ast::Visibility::Restricted { ref path, .. } =>
- self.word_nbsp(&format!("pub({})", path)),
+ ast::Visibility::Restricted { ref path, .. } => {
+ let path = to_string(|s| s.print_path(path, false, 0, true));
+ self.word_nbsp(&format!("pub({})", path))
+ }
ast::Visibility::Inherited => Ok(())
}
}
}
ast::TraitItemKind::Macro(codemap::Spanned { ref node, .. }) => {
// code copied from ItemKind::Mac:
- self.print_path(&node.path, false, 0)?;
+ self.print_path(&node.path, false, 0, false)?;
word(&mut self.s, "! ")?;
self.cbox(INDENT_UNIT)?;
self.popen()?;
}
ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => {
// code copied from ItemKind::Mac:
- try!(self.print_path(&node.path, false, 0));
+ try!(self.print_path(&node.path, false, 0, false));
try!(word(&mut self.s, "! "));
try!(self.cbox(INDENT_UNIT));
try!(self.popen());
pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken)
-> io::Result<()> {
- try!(self.print_path(&m.node.path, false, 0));
+ try!(self.print_path(&m.node.path, false, 0, false));
try!(word(&mut self.s, "!"));
match delim {
token::Paren => try!(self.popen()),
fields: &[ast::Field],
wth: &Option<P<ast::Expr>>,
attrs: &[Attribute]) -> io::Result<()> {
- try!(self.print_path(path, true, 0));
+ try!(self.print_path(path, true, 0, false));
try!(word(&mut self.s, "{"));
try!(self.print_inner_attributes_inline(attrs));
try!(self.commasep_cmnt(
}
}
ast::ExprKind::Path(None, ref path) => {
- try!(self.print_path(path, true, 0))
+ try!(self.print_path(path, true, 0, false))
}
ast::ExprKind::Path(Some(ref qself), ref path) => {
try!(self.print_qpath(path, qself, true))
fn print_path(&mut self,
path: &ast::Path,
colons_before_params: bool,
- depth: usize)
+ depth: usize,
+ defaults_to_global: bool)
-> io::Result<()>
{
try!(self.maybe_print_comment(path.span.lo));
- let mut first = !path.global;
- for segment in &path.segments[..path.segments.len()-depth] {
- if first {
- first = false
- } else {
+ let mut segments = path.segments[..path.segments.len()-depth].iter();
+ if defaults_to_global && path.is_global() {
+ segments.next();
+ }
+ for (i, segment) in segments.enumerate() {
+ if i > 0 {
try!(word(&mut self.s, "::"))
}
-
- try!(self.print_ident(segment.identifier));
-
- if let Some(ref parameters) = segment.parameters {
- try!(self.print_path_parameters(parameters, colons_before_params))
+ if segment.identifier.name != keywords::CrateRoot.name() &&
+ segment.identifier.name != "$crate" {
+ try!(self.print_ident(segment.identifier));
+ if let Some(ref parameters) = segment.parameters {
+ try!(self.print_path_parameters(parameters, colons_before_params));
+ }
}
}
try!(space(&mut self.s));
try!(self.word_space("as"));
let depth = path.segments.len() - qself.position;
- try!(self.print_path(&path, false, depth));
+ try!(self.print_path(&path, false, depth, false));
}
try!(word(&mut self.s, ">"));
try!(word(&mut self.s, "::"));
}
}
PatKind::TupleStruct(ref path, ref elts, ddpos) => {
- try!(self.print_path(path, true, 0));
+ try!(self.print_path(path, true, 0, false));
try!(self.popen());
if let Some(ddpos) = ddpos {
try!(self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(&p)));
try!(self.pclose());
}
PatKind::Path(None, ref path) => {
- try!(self.print_path(path, true, 0));
+ try!(self.print_path(path, true, 0, false));
}
PatKind::Path(Some(ref qself), ref path) => {
try!(self.print_qpath(path, qself, false));
}
PatKind::Struct(ref path, ref fields, etc) => {
- try!(self.print_path(path, true, 0));
+ try!(self.print_path(path, true, 0, false));
try!(self.nbsp());
try!(self.word_space("{"));
try!(self.commasep_cmnt(
try!(self.print_lifetime_bounds(lifetime, bounds));
}
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
- try!(self.print_path(path, false, 0));
+ try!(self.print_path(path, false, 0, false));
try!(space(&mut self.s));
try!(self.word_space("="));
try!(self.print_type(&ty));
pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> io::Result<()> {
match vp.node {
ast::ViewPathSimple(ident, ref path) => {
- try!(self.print_path(path, false, 0));
+ try!(self.print_path(path, false, 0, true));
if path.segments.last().unwrap().identifier.name !=
ident.name {
}
ast::ViewPathGlob(ref path) => {
- try!(self.print_path(path, false, 0));
+ try!(self.print_path(path, false, 0, true));
word(&mut self.s, "::*")
}
if path.segments.is_empty() {
try!(word(&mut self.s, "{"));
} else {
- try!(self.print_path(path, false, 0));
+ try!(self.print_path(path, false, 0, true));
try!(word(&mut self.s, "::{"));
}
try!(self.commasep(Inconsistent, &idents[..], |s, w| {
}],
vis: ast::Visibility::Inherited,
node: ast::ItemKind::Use(P(codemap::dummy_spanned(ast::ViewPathGlob(ast::Path {
- global: false,
- segments: vec![name, "prelude", "v1"].into_iter().map(|name| {
+ segments: ["{{root}}", name, "prelude", "v1"].into_iter().map(|name| {
ast::Ident::from_str(name).into()
}).collect(),
span: span,
(53, Default, "default")
(54, StaticLifetime, "'static")
(55, Union, "union")
+
+ // A virtual keyword that resolves to the crate root when used in a lexical scope.
+ (56, CrateRoot, "{{root}}")
}
// If an interner exists in TLS, return it. Otherwise, prepare a fresh one.
fn path_node(ids: Vec<Ident>) -> ast::Path {
ast::Path {
span: DUMMY_SP,
- global: false,
segments: ids.into_iter().map(Into::into).collect(),
}
}
fn path(&self) -> ast::Path {
ast::Path {
span: self.span,
- global: false,
segments: vec![self.ident.into()],
}
}
impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> {
fn visit_ty(&mut self, ty: &'a ast::Ty) {
- match ty.node {
- ast::TyKind::Path(_, ref path) if !path.global => {
- if let Some(segment) = path.segments.first() {
- if self.ty_param_names.contains(&segment.identifier.name) {
- self.types.push(P(ty.clone()));
- }
+ if let ast::TyKind::Path(_, ref path) = ty.node {
+ if let Some(segment) = path.segments.first() {
+ if self.ty_param_names.contains(&segment.identifier.name) {
+ self.types.push(P(ty.clone()));
}
}
- _ => {}
}
visit::walk_ty(self, ty)
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CUSTOM_DERIVE);
} else {
- cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
let name = Symbol::intern(&format!("derive_{}", tname));
+ if !cx.resolver.is_whitelisted_legacy_custom_derive(name) {
+ cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
+ }
let mitem = cx.meta_word(titem.span, name);
new_attributes.push(cx.attribute(mitem.span, mitem));
}
}
}
+#[cfg(target_os = "redox")]
+fn stdout_isatty() -> bool {
+ // FIXME: Implement isatty on Redox
+ false
+}
#[cfg(unix)]
fn stdout_isatty() -> bool {
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
}
}
+ #[cfg(target_os = "redox")]
+ fn num_cpus() -> usize {
+ // FIXME: Implement num_cpus on Redox
+ 1
+ }
+
#[cfg(any(target_os = "linux",
target_os = "macos",
target_os = "ios",
// Make sure primitive type fallback doesn't work with global paths
let _: ::u8;
- //~^ ERROR type name `u8` is undefined or not in scope
+ //~^ ERROR type name `::u8` is undefined or not in scope
}
pub fn method_selfness(&self) { }
}
-// Change Method Selfmutness -----------------------------------------------------------
+// Change Method Selfmutness ---------------------------------------------------
#[cfg(cfail1)]
impl Foo {
pub fn method_selfmutness(&self) { }
pub fn method_selfmutness(&mut self) { }
}
+
+
+// Add Method To Impl ----------------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_method_to_impl1(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_dirty(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_dirty(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_clean(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_clean(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_method_to_impl1(&self) { }
+
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_method_to_impl2(&self) { }
+}
+
+
+
+// Add Method Parameter --------------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_method_parameter(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_method_parameter(&self, _: i32) { }
+}
+
+
+
+// Change Method Parameter Name ------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn change_method_parameter_name(&self, a: i64) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn change_method_parameter_name(&self, b: i64) { }
+}
+
+
+
+// Change Method Return Type ---------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn change_method_return_type(&self) -> u16 { 0 }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn change_method_return_type(&self) -> u8 { 0 }
+}
+
+
+
+// Make Method #[inline] -------------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn make_method_inline(&self) -> u8 { 0 }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ #[inline]
+ pub fn make_method_inline(&self) -> u8 { 0 }
+}
+
+
+
+// Change order of parameters -------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn change_method_parameter_order(&self, a: i64, b: i64) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn change_method_parameter_order(&self, b: i64, a: i64) { }
+}
+
+
+
+// Make method unsafe ----------------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn make_method_unsafe(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub unsafe fn make_method_unsafe(&self) { }
+}
+
+
+
+// Make method extern ----------------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn make_method_extern(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub extern fn make_method_extern(&self) { }
+}
+
+
+
+// Change method calling convention --------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub extern "C" fn change_method_calling_convention(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub extern "system" fn change_method_calling_convention(&self) { }
+}
+
+
+
+// Add Lifetime Parameter to Method --------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_lifetime_parameter_to_method(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_lifetime_parameter_to_method<'a>(&self) { }
+}
+
+
+
+// Add Type Parameter To Method ------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_type_parameter_to_method(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_type_parameter_to_method<T>(&self) { }
+}
+
+
+
+// Add Lifetime Bound to Lifetime Parameter of Method --------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b>(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { }
+}
+
+
+
+// Add Lifetime Bound to Type Parameter of Method ------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_lifetime_bound_to_type_param_of_method<'a, T>(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { }
+}
+
+
+
+// Add Trait Bound to Type Parameter of Method ------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_trait_bound_to_type_param_of_method<T>(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_trait_bound_to_type_param_of_method<T: Clone>(&self) { }
+}
+
+
+
+// Add #[no_mangle] to Method --------------------------------------------------
+#[cfg(cfail1)]
+impl Foo {
+ pub fn add_no_mangle_to_method(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_clean(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_clean(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Foo {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ #[no_mangle]
+ pub fn add_no_mangle_to_method(&self) { }
+}
+
+
+
+struct Bar<T>(T);
+
+// Add Type Parameter To Impl --------------------------------------------------
+#[cfg(cfail1)]
+impl Bar<u32> {
+ pub fn add_type_parameter_to_impl(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_dirty(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_dirty(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl<T> Bar<T> {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_type_parameter_to_impl(&self) { }
+}
+
+
+
+// Change Self Type of Impl ----------------------------------------------------
+#[cfg(cfail1)]
+impl Bar<u32> {
+ pub fn change_impl_self_type(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_dirty(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_dirty(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl Bar<u64> {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn change_impl_self_type(&self) { }
+}
+
+
+
+// Add Lifetime Bound to Impl --------------------------------------------------
+#[cfg(cfail1)]
+impl<T> Bar<T> {
+ pub fn add_lifetime_bound_to_impl_parameter(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_dirty(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_dirty(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl<T: 'static> Bar<T> {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_lifetime_bound_to_impl_parameter(&self) { }
+}
+
+
+
+// Add Trait Bound to Impl Parameter -------------------------------------------
+#[cfg(cfail1)]
+impl<T> Bar<T> {
+ pub fn add_trait_bound_to_impl_parameter(&self) { }
+}
+
+#[cfg(not(cfail1))]
+#[rustc_dirty(label="Hir", cfg="cfail2")]
+#[rustc_clean(label="Hir", cfg="cfail3")]
+#[rustc_metadata_dirty(cfg="cfail2")]
+#[rustc_metadata_clean(cfg="cfail3")]
+impl<T: Clone> Bar<T> {
+ #[rustc_dirty(label="Hir", cfg="cfail2")]
+ #[rustc_clean(label="Hir", cfg="cfail3")]
+ #[rustc_metadata_dirty(cfg="cfail2")]
+ #[rustc_metadata_clean(cfg="cfail3")]
+ pub fn add_trait_bound_to_impl_parameter(&self) { }
+}
--- /dev/null
+// 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 <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.
+
+// compile-flags: -Z parse-only
+
+fn foo<T>() where <T>::Item: ToString, T: Iterator { }
+ //~^ syntax `where<T>` is reserved for future use
+
+fn main() {}
- (($crate::fmt::format as
+ ((::fmt::format as
fn(std::fmt::Arguments<'_>) -> std::string::String {std::fmt::format})(((<::std::fmt::Arguments>::new_v1
as
fn(&[&str], &[std::fmt::ArgumentV1<'_>]) -> std::fmt::Arguments<'_> {std::fmt::Arguments<'_>::new_v1})(({
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
- reg.register_syntax_extension(
+ reg.register_custom_derive(
Symbol::intern("derive_TotalSum"),
MultiDecorator(box expand));
}
a([u16; 0], u8), b
}
-// Test struct field reordering to make sure it actually reorders.
-struct WillOptimize1(u8, u16, u8);
-struct WillOptimize2 { a: u8, b: u16, c: u8}
-
pub fn main() {
assert_eq!(size_of::<u8>(), 1 as usize);
assert_eq!(size_of::<u32>(), 4 as usize);
assert_eq!(size_of::<e1>(), 8 as usize);
assert_eq!(size_of::<e2>(), 8 as usize);
assert_eq!(size_of::<e3>(), 4 as usize);
-
- assert_eq!(size_of::<WillOptimize1>(), 4);
- assert_eq!(size_of::<WillOptimize2>(), 4);
}
--- /dev/null
+// 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 <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.
+
+#![crate_name = "foo"]
+
+// @has 'search-index.js' 'Foo short link.'
+// @!has - 'www.example.com'
+// @!has - 'More Foo.'
+
+/// Foo short [link](https://www.example.com/).
+///
+/// More Foo.
+pub struct Foo;
-print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
-print-type-size field `.nested`: 8 bytes
-print-type-size field `.post`: 2 bytes
+print-type-size type: `IndirectNonZero<u32>`: 20 bytes, alignment: 4 bytes
print-type-size field `.pre`: 1 bytes
-print-type-size end padding: 1 bytes
-print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
-print-type-size variant `Some`: 12 bytes
-print-type-size field `.0`: 12 bytes
-print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
-print-type-size variant `Record`: 7 bytes
-print-type-size field `.val`: 4 bytes
-print-type-size field `.post`: 2 bytes
-print-type-size field `.pre`: 1 bytes
-print-type-size end padding: 1 bytes
-print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
-print-type-size field `.val`: 4 bytes
+print-type-size padding: 3 bytes
+print-type-size field `.nested`: 12 bytes, alignment: 4 bytes
print-type-size field `.post`: 2 bytes
+print-type-size end padding: 2 bytes
+print-type-size type: `MyOption<IndirectNonZero<u32>>`: 20 bytes, alignment: 4 bytes
+print-type-size variant `Some`: 20 bytes
+print-type-size field `.0`: 20 bytes
+print-type-size type: `EmbeddedDiscr`: 12 bytes, alignment: 4 bytes
+print-type-size variant `Record`: 10 bytes
+print-type-size field `.pre`: 1 bytes
+print-type-size padding: 3 bytes
+print-type-size field `.val`: 4 bytes, alignment: 4 bytes
+print-type-size field `.post`: 2 bytes
+print-type-size end padding: 2 bytes
+print-type-size type: `NestedNonZero<u32>`: 12 bytes, alignment: 4 bytes
print-type-size field `.pre`: 1 bytes
-print-type-size end padding: 1 bytes
+print-type-size padding: 3 bytes
+print-type-size field `.val`: 4 bytes, alignment: 4 bytes
+print-type-size field `.post`: 2 bytes
+print-type-size end padding: 2 bytes
print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
-print-type-size type: `Padded`: 12 bytes, alignment: 4 bytes
-print-type-size field `.g`: 4 bytes
-print-type-size field `.h`: 2 bytes
+print-type-size type: `Padded`: 16 bytes, alignment: 4 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
+print-type-size padding: 2 bytes
+print-type-size field `.g`: 4 bytes, alignment: 4 bytes
print-type-size field `.c`: 1 bytes
+print-type-size padding: 1 bytes
+print-type-size field `.h`: 2 bytes, alignment: 2 bytes
print-type-size field `.d`: 1 bytes
-print-type-size end padding: 2 bytes
+print-type-size end padding: 3 bytes
print-type-size type: `Packed`: 10 bytes, alignment: 1 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
print-type-size type: `E1`: 12 bytes, alignment: 4 bytes
-print-type-size discriminant: 1 bytes
-print-type-size variant `A`: 7 bytes
+print-type-size discriminant: 4 bytes
+print-type-size variant `A`: 5 bytes
+print-type-size field `.0`: 4 bytes
print-type-size field `.1`: 1 bytes
-print-type-size padding: 2 bytes
-print-type-size field `.0`: 4 bytes, alignment: 4 bytes
-print-type-size variant `B`: 11 bytes
-print-type-size padding: 3 bytes
-print-type-size field `.0`: 8 bytes, alignment: 4 bytes
+print-type-size variant `B`: 8 bytes
+print-type-size field `.0`: 8 bytes
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `A`: 7 bytes
print-type-size padding: 3 bytes
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
-print-type-size field `.g`: 4 bytes
print-type-size field `.a`: 1 bytes
print-type-size field `.b`: 1 bytes
-print-type-size end padding: 2 bytes
+print-type-size padding: 2 bytes
+print-type-size field `.g`: 4 bytes, alignment: 4 bytes