use std::from_str::FromStr;
use getopts::{optopt, optflag, reqopt};
use common::Config;
-use common::{Pretty, DebugInfoGdb, Codegen};
+use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
use util::logv;
use regex::Regex;
optflag("h", "help", "show this message"));
assert!(!args.is_empty());
- let argv0 = (*args.get(0)).clone();
+ let argv0 = args[0].clone();
let args_ = args.tail();
- if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
+ if args[1].as_slice() == "-h" || args[1].as_slice() == "--help" {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
println!("");
}
let filter = if !matches.free.is_empty() {
- let s = matches.free.get(0).as_slice();
+ let s = matches.free[0].as_slice();
match regex::Regex::new(s) {
Ok(re) => Some(re),
Err(e) => {
os::setenv("RUST_TEST_TASKS","1");
}
+ match config.mode {
+ DebugInfoLldb => {
+ // Some older versions of LLDB seem to have problems with multiple
+ // instances running in parallel, so only run one test task at a
+ // time.
+ os::setenv("RUST_TEST_TASKS", "1");
+ }
+ _ => { /* proceed */ }
+ }
+
let opts = test_opts(config);
let tests = make_tests(config);
// sadly osx needs some file descriptor limits raised for running tests in
let proc_res = print_source(config,
props,
testfile,
- (*srcs.get(round)).to_string(),
+ srcs[round].to_string(),
"normal");
if !proc_res.status.success() {
let s = File::open(&filepath).read_to_end().unwrap();
String::from_utf8(s).unwrap()
}
- None => { (*srcs.get(srcs.len() - 2u)).clone() }
+ None => { srcs[srcs.len() - 2u].clone() }
};
- let mut actual = (*srcs.get(srcs.len() - 1u)).clone();
+ let mut actual = srcs[srcs.len() - 1u].clone();
if props.pp_exact.is_some() {
// Now we have to care about line endings
if props.no_pretty_expanded { return }
// additionally, run `--pretty expanded` and try to build it.
- let proc_res = print_source(config, props, testfile, (*srcs.get(round)).clone(), "expanded");
+ let proc_res = print_source(config, props, testfile, srcs[round].clone(), "expanded");
if !proc_res.status.success() {
fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
}
// We don't want to hang when calling `quit` while the process is still running
let mut script_str = String::from_str("settings set auto-confirm true\n");
+ // Make LLDB emit its version, so we have it documented in the test output
+ script_str.push_str("version\n");
+
+ // Switch LLDB into "Rust mode"
+ script_str.push_str("command script import ./src/etc/lldb_rust_formatters.py\n");
+ script_str.push_str("type summary add --no-value ");
+ script_str.push_str("--python-function lldb_rust_formatters.print_val ");
+ script_str.push_str("-x \".*\" --category Rust\n");
+ script_str.push_str("type category enable Rust\n");
+
// Set breakpoints on every line that contains the string "#break"
for line in breakpoint_lines.iter() {
script_str.push_str(format!("breakpoint set --line {}\n",
let mut rest = line.trim();
let mut first = true;
let mut failed = false;
- for frag in check_fragments.get(i).iter() {
+ for frag in check_fragments[i].iter() {
let found = if first {
if rest.starts_with(frag.as_slice()) {
Some(0)
}
let mut next_err_idx = 0u;
- let mut next_err_pat = props.error_patterns.get(next_err_idx);
+ let mut next_err_pat = &props.error_patterns[next_err_idx];
let mut done = false;
let output_to_check = if props.check_stdout {
format!("{}{}", proc_res.stdout, proc_res.stderr)
};
for line in output_to_check.as_slice().lines() {
if line.contains(next_err_pat.as_slice()) {
- debug!("found error pattern {}", *next_err_pat);
+ debug!("found error pattern {}", next_err_pat);
next_err_idx += 1u;
if next_err_idx == props.error_patterns.len() {
debug!("found all error patterns");
done = true;
break;
}
- next_err_pat = props.error_patterns.get(next_err_idx);
+ next_err_pat = &props.error_patterns[next_err_idx];
}
}
if done { return; }
for line in proc_res.stderr.as_slice().lines() {
let mut was_expected = false;
for (i, ee) in expected_errors.iter().enumerate() {
- if !*found_flags.get(i) {
+ if !found_flags[i] {
debug!("prefix={} ee.kind={} ee.msg={} line={}",
- prefixes.get(i).as_slice(),
+ prefixes[i].as_slice(),
ee.kind,
ee.msg,
line);
- if prefix_matches(line, prefixes.get(i).as_slice()) &&
+ if prefix_matches(line, prefixes[i].as_slice()) &&
line.contains(ee.kind.as_slice()) &&
line.contains(ee.msg.as_slice()) {
*found_flags.get_mut(i) = true;
for (i, &flag) in found_flags.iter().enumerate() {
if !flag {
- let ee = expected_errors.get(i);
+ let ee = &expected_errors[i];
fatal_proc_rec(format!("expected {} on line {} not found: {}",
ee.kind, ee.line, ee.msg).as_slice(),
proc_res);
its functionality. Eventually, we'll add more. Since we started off by using
Cargo, it'll be easy to add later.
-Let's convert Hello World to Cargo. The first thing we need to do to begin using Cargo
-is to install Cargo. To do this, we need to build it from source. There are no binaries
-yet.
-
-First, let's go back to our projects directory. We don't want Cargo to
-live in our project!
-
-```{bash}
-$ cd ..
-```
-
-Next, we need these commands:
-
-```{bash}
-$ git clone --recursive https://github.com/rust-lang/cargo
-$ cd cargo
-$ make
-$ make install # may need sudo or admin permissions
-```
-
-The `--recursive` downloads Cargo's own dependencies. You can't use Cargo to
-fetch dependencies until you have Cargo installed! Also, you will need to have
-`git` installed. Much of the Rust world assumes `git` usage, so it's a good
-thing to have around. Please check out [the git
-documentation](http://git-scm.com/book/en/Getting-Started-Installing-Git) for
-more on installing `git`.
-
-We hope to give Cargo a binary installer, similar to Rust's own, so that
-this will not be necessary in the future.
-
-Let's see if that worked. Try this:
-
-```{bash}
-$ cargo
-Commands:
- build # compile the current project
-
-Options (for all commands):
-
--v, [--verbose]
--h, [--help]
-```
-
-If you see this output when you run `cargo`, congrats! Cargo is working. If
-not, please [open an issue](https://github.com/rust-lang/cargo/issues/new) or
-drop by the Rust IRC, and we can help you out.
-
-Let's move back into our `hello_world` directory now:
-
-```{bash}
-$ cd .. # move back up into projects
-$ cd hello_world # move into hello_world
-```
+Let's convert Hello World to Cargo. The first thing we need to do to begin
+using Cargo is to install Cargo. Luckily for us, the script we ran to install
+Rust includes Cargo by default. If you installed Rust some other way, you may
+want to [check the Cargo
+README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies)
+for specific instructions about installing it.
To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
configuration file, and put our source file in the right place. Let's
spawn(proc() {
let numbers = rx.recv();
- println!("{}", *numbers.get(0));
+ println!("{}", numbers[0]);
})
}
```
spawn(proc() {
let numbers = rx.recv();
- println!("{}", numbers.get(0));
+ println!("{}", numbers[0]);
});
// Try to print a number from the original task
- println!("{}", *numbers.get(0));
+ println!("{}", numbers[0]);
}
```
```text
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
-concurrency.rs:12 println!("{}", numbers.get(0));
+concurrency.rs:12 println!("{}", numbers[0]);
^~~~~~~
```
spawn(proc() {
let numbers = rx.recv();
- println!("{:d}", *numbers.get(num as uint));
+ println!("{:d}", numbers[num as uint]);
})
}
}
spawn(proc() {
let numbers = rx.recv();
- println!("{:d}", *numbers.get(num as uint));
+ println!("{:d}", (*numbers)[num as uint]);
})
}
}
// See: https://github.com/rust-lang/rust/issues/6515
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
- println!("{}", *numbers.get(num as uint));
+ println!("{}", (*numbers)[num as uint]);
// When `numbers` goes out of scope the lock is dropped
})
fn print_all<T: Printable + Clone>(printable_things: Vec<T>) {
let mut i = 0;
while i < printable_things.len() {
- let copy_of_thing = printable_things.get(i).clone();
+ let copy_of_thing = printable_things[i].clone();
copy_of_thing.print();
i += 1;
}
import re
import atexit
-# Terminate the debugger
-atexit.register(lambda: lldb.SBDebugger.Terminate())
-
# Set this to True for additional output
DEBUG_OUTPUT = False
--- /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.
+
+import lldb
+
+def print_val(val, internal_dict):
+ '''Prints the given value with Rust syntax'''
+ type_class = val.GetType().GetTypeClass()
+
+ if type_class == lldb.eTypeClassStruct:
+ return print_struct_val(val, internal_dict)
+
+ if type_class == lldb.eTypeClassUnion:
+ return print_enum_val(val, internal_dict)
+
+ if type_class == lldb.eTypeClassPointer:
+ return print_pointer_val(val, internal_dict)
+
+ if type_class == lldb.eTypeClassArray:
+ return print_fixed_size_vec_val(val, internal_dict)
+
+ return val.GetValue()
+
+
+#=--------------------------------------------------------------------------------------------------
+# Type-Specialized Printing Functions
+#=--------------------------------------------------------------------------------------------------
+
+def print_struct_val(val, internal_dict):
+ '''Prints a struct, tuple, or tuple struct value with Rust syntax'''
+ assert val.GetType().GetTypeClass() == lldb.eTypeClassStruct
+
+ if is_vec_slice(val):
+ return print_vec_slice_val(val, internal_dict)
+ else:
+ return print_struct_val_starting_from(0, val, internal_dict)
+
+def print_vec_slice_val(val, internal_dict):
+ output = "&["
+
+ length = val.GetChildAtIndex(1).GetValueAsUnsigned()
+
+ data_ptr_val = val.GetChildAtIndex(0)
+ data_ptr_type = data_ptr_val.GetType()
+ assert data_ptr_type.IsPointerType()
+
+ element_type = data_ptr_type.GetPointeeType()
+ element_type_size = element_type.GetByteSize()
+
+ start_address = data_ptr_val.GetValueAsUnsigned()
+
+ for i in range(length):
+ address = start_address + i * element_type_size
+ element_val = val.CreateValueFromAddress( val.GetName() + ("[%s]" % i), address, element_type )
+ output += print_val(element_val, internal_dict)
+
+ if i != length - 1:
+ output += ", "
+
+ output += "]"
+ return output
+
+def print_struct_val_starting_from(field_start_index, val, internal_dict):
+ '''
+ Prints a struct, tuple, or tuple struct value with Rust syntax.
+ Ignores any fields before field_start_index.
+ '''
+ assert val.GetType().GetTypeClass() == lldb.eTypeClassStruct
+
+ t = val.GetType()
+ has_field_names = type_has_field_names(t)
+ type_name = extract_type_name(t.GetName())
+ output = ""
+
+ if not type_name.startswith("("):
+ # this is a tuple, so don't print the type name
+ output += type_name
+
+ if has_field_names:
+ output += " { \n"
+ else:
+ output += "("
+
+ num_children = val.num_children
+
+ for child_index in range(field_start_index, num_children):
+ if has_field_names:
+ field_name = t.GetFieldAtIndex(child_index).GetName()
+ output += field_name + ": "
+
+ field_val = val.GetChildAtIndex(child_index)
+ output += print_val(field_val, internal_dict)
+
+ if child_index != num_children - 1:
+ output += ", "
+
+ if has_field_names:
+ output += "\n"
+
+ if has_field_names:
+ output += "}"
+ else:
+ output += ")"
+
+ return output
+
+
+def print_enum_val(val, internal_dict):
+ '''Prints an enum value with Rust syntax'''
+
+ assert val.GetType().GetTypeClass() == lldb.eTypeClassUnion
+
+ if val.num_children == 1:
+ first_variant_name = val.GetChildAtIndex(0).GetName()
+ if first_variant_name and first_variant_name.startswith("RUST$ENCODED$ENUM$"):
+ # Try to extract the
+
+ last_separator_index = first_variant_name.rfind("$")
+ if last_separator_index == -1:
+ return "<invalid enum encoding: %s>" % first_variant_name
+
+ second_last_separator_index = first_variant_name.rfind("$", 0, last_separator_index)
+ if second_last_separator_index == -1:
+ return "<invalid enum encoding: %s>" % first_variant_name
+
+ try:
+ disr_field_index = first_variant_name[second_last_separator_index + 1 :
+ last_separator_index]
+ disr_field_index = int(disr_field_index)
+ except:
+ return "<invalid enum encoding: %s>" % first_variant_name
+
+ disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
+
+ if disr_val == 0:
+ null_variant_name = first_variant_name[last_separator_index + 1:]
+ return null_variant_name
+ else:
+ return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
+ else:
+ return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
+
+ # extract the discriminator value by
+ disr_val = val.GetChildAtIndex(0).GetChildAtIndex(0)
+ disr_type = disr_val.GetType()
+
+ if disr_type.GetTypeClass() != lldb.eTypeClassEnumeration:
+ return "<Invalid enum value encountered: Discriminator is not an enum>"
+
+ variant_index = disr_val.GetValueAsUnsigned()
+ return print_struct_val_starting_from(1, val.GetChildAtIndex(variant_index), internal_dict)
+
+
+def print_pointer_val(val, internal_dict):
+ '''Prints a pointer value with Rust syntax'''
+ assert val.GetType().IsPointerType()
+ sigil = "&"
+ type_name = extract_type_name(val.GetType().GetName())
+ if type_name and type_name[0:1] in ["&", "~", "*"]:
+ sigil = type_name[0:1]
+
+ return sigil + hex(val.GetValueAsUnsigned()) #print_val(val.Dereference(), internal_dict)
+
+
+def print_fixed_size_vec_val(val, internal_dict):
+ assert val.GetType().GetTypeClass() == lldb.eTypeClassArray
+
+ output = "["
+
+ for i in range(val.num_children):
+ output += print_val(val.GetChildAtIndex(i), internal_dict)
+ if i != val.num_children - 1:
+ output += ", "
+
+ output += "]"
+ return output
+
+
+#=--------------------------------------------------------------------------------------------------
+# Helper Functions
+#=--------------------------------------------------------------------------------------------------
+
+unqualified_type_markers = frozenset(["(", "[", "&", "*"])
+
+def extract_type_name(qualified_type_name):
+ '''Extracts the type name from a fully qualified path'''
+ if qualified_type_name[0] in unqualified_type_markers:
+ return qualified_type_name
+
+ end_of_search = qualified_type_name.find("<")
+ if end_of_search < 0:
+ end_of_search = len(qualified_type_name)
+
+ index = qualified_type_name.rfind("::", 0, end_of_search)
+ if index < 0:
+ return qualified_type_name
+ else:
+ return qualified_type_name[index + 2:]
+
+
+def type_has_field_names(ty):
+ '''Returns true of this is a type with field names (struct, struct-like enum variant)'''
+ # This may also be an enum variant where the first field doesn't have a name but the rest has
+ if ty.GetNumberOfFields() > 1:
+ return ty.GetFieldAtIndex(1).GetName() != None
+ else:
+ return ty.GetFieldAtIndex(0).GetName() != None
+
+
+def is_vec_slice(val):
+ ty = val.GetType()
+ if ty.GetTypeClass() != lldb.eTypeClassStruct:
+ return False
+
+ if ty.GetNumberOfFields() != 2:
+ return False
+
+ if ty.GetFieldAtIndex(0).GetName() != "data_ptr":
+ return False
+
+ if ty.GetFieldAtIndex(1).GetName() != "length":
+ return False
+
+ type_name = extract_type_name(ty.GetName()).replace("&'static", "&").replace(" ", "")
+ return type_name.startswith("&[") and type_name.endswith("]")
*rust.txt* Filetype plugin for Rust
==============================================================================
-CONTENTS *rust*
+CONTENTS *rust* *ft-rust*
1. Introduction |rust-intro|
2. Settings |rust-settings|
let g:rust_conceal_pub = 1
<
+ *g:rust_fold*
+g:rust_fold~
+ Set this option to turn on |folding|: >
+ let g:rust_fold = 1
+<
+ Value Effect ~
+ 0 No folding
+ 1 Braced blocks are folded. All folds are open by
+ default.
+ 2 Braced blocks are folded. 'foldlevel' is left at the
+ global value (all folds are closed by default).
+
*g:rust_bang_comment_leader*
g:rust_bang_comment_leader~
Set this option to 1 to preserve the leader on multi-line doc comments
" Description: Vim syntax file for Rust
" Maintainer: Chris Morgan <me@chrismorgan.info>
" Maintainer: Kevin Ballard <kevin@sb.org>
-" Last Change: May 27, 2014
+" Last Change: Jul 07, 2014
if exists("b:did_ftplugin")
finish
" otherwise it's better than nothing.
setlocal smartindent nocindent
-setlocal tabstop=4 shiftwidth=4 expandtab
+setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
+
+setlocal textwidth=99
" This includeexpr isn't perfect, but it's a good start
setlocal includeexpr=substitute(v:fname,'::','/','g')
" Cleanup {{{1
let b:undo_ftplugin = "
- \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
+ \ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
+ \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
\|if exists('b:rust_original_delimitMate_excluded_regions')
\|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
\|unlet b:rust_original_delimitMate_excluded_regions
" Maintainer: Patrick Walton <pcwalton@mozilla.com>
" Maintainer: Ben Blum <bblum@cs.cmu.edu>
" Maintainer: Chris Morgan <me@chrismorgan.info>
-" Last Change: 2014 Feb 27
+" Last Change: July 06, 2014
if version < 600
syntax clear
finish
endif
+" Fold settings {{{1
+
+if has("folding") && exists('g:rust_fold') && g:rust_fold != 0
+ setlocal foldmethod=syntax
+ if g:rust_fold == 2
+ setlocal foldlevel<
+ else
+ setlocal foldlevel=99
+ endif
+endif
+
" Syntax definitions {{{1
" Basic keywords {{{2
syn keyword rustConditional match if else
" Trivial folding rules to begin with.
" TODO: use the AST to make really good folding
syn region rustFoldBraces start="{" end="}" transparent fold
-" If you wish to enable this, setlocal foldmethod=syntax
-" It's not enabled by default as it would drive some people mad.
" Default highlighting {{{1
hi def link rustDecNumber rustNumber
//! An ordered map and set implemented as self-balancing binary search
//! trees. The only requirement for the types is that the key implements
//! `Ord`.
+//!
+//! ## Example
+//!
+//! ```{rust}
+//! use std::collections::TreeSet;
+//!
+//! let mut tree_set = TreeSet::new();
+//!
+//! tree_set.insert(2i);
+//! tree_set.insert(1i);
+//! tree_set.insert(3i);
+//!
+//! for i in tree_set.iter() {
+//! println!("{}", i) // prints 1, then 2, then 3
+//! }
+//! ```
use core::prelude::*;
/// A implementation of the `Set` trait on top of the `TreeMap` container. The
/// only requirement is that the type of the elements contained ascribes to the
/// `Ord` trait.
+///
+/// ## Example
+///
+/// ```{rust}
+/// use std::collections::TreeSet;
+///
+/// let mut tree_set = TreeSet::new();
+///
+/// tree_set.insert(2i);
+/// tree_set.insert(1i);
+/// tree_set.insert(3i);
+///
+/// for i in tree_set.iter() {
+/// println!("{}", i) // prints 1, then 2, then 3
+/// }
+/// ```
#[deriving(Clone)]
pub struct TreeSet<T> {
map: TreeMap<T, ()>
/// vec.push(2i);
///
/// assert_eq!(vec.len(), 2);
-/// assert_eq!(vec.get(0), &1);
+/// assert_eq!(vec[0], 1);
///
/// assert_eq!(vec.pop(), Some(2));
/// assert_eq!(vec.len(), 1);
}
}
+impl<T> Index<uint,T> for Vec<T> {
+ #[inline]
+ fn index<'a>(&'a self, index: &uint) -> &'a T {
+ self.get(*index)
+ }
+}
+
+// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
+/*impl<T> IndexMut<uint,T> for Vec<T> {
+ #[inline]
+ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
+ self.get_mut(*index)
+ }
+}*/
+
impl<T> FromIterator<T> for Vec<T> {
#[inline]
fn from_iter<I:Iterator<T>>(mut iterator: I) -> Vec<T> {
/// # Example
///
/// ```rust
+ /// #![allow(deprecated)]
+ ///
/// let vec = vec!(1i, 2, 3);
/// assert!(vec.get(1) == &2);
/// ```
+ #[deprecated="prefer using indexing, e.g., vec[0]"]
#[inline]
pub fn get<'a>(&'a self, index: uint) -> &'a T {
&self.as_slice()[index]
v.truncate(0);
}
+ #[test]
+ fn test_index() {
+ let vec = vec!(1i, 2, 3);
+ assert!(vec[1] == 2);
+ }
+
+ #[test]
+ #[should_fail]
+ fn test_index_out_of_bounds() {
+ let vec = vec!(1i, 2, 3);
+ let _ = vec[3];
+ }
+
#[bench]
fn bench_new(b: &mut Bencher) {
b.iter(|| {
_offset: uint,
inner: *const TyDesc)
-> bool {
- match *self.var_stk.get(self.var_stk.len() - 1) {
+ match self.var_stk[self.var_stk.len() - 1] {
Matched => {
if i != 0 {
try!(self, self.writer.write(", ".as_bytes()));
_disr_val: Disr,
n_fields: uint,
_name: &str) -> bool {
- match *self.var_stk.get(self.var_stk.len() - 1) {
+ match self.var_stk[self.var_stk.len() - 1] {
Matched => {
if n_fields > 0 {
try!(self, self.writer.write([')' as u8]));
//! fn main() {
//! let args: Vec<String> = os::args();
//!
-//! let program = args.get(0).clone();
+//! let program = args[0].clone();
//!
//! let opts = [
//! optopt("o", "", "set output file name", "NAME"),
//! }
//! let output = matches.opt_str("o");
//! let input = if !matches.free.is_empty() {
-//! (*matches.free.get(0)).clone()
+//! matches.free[0].clone()
//! } else {
//! print_usage(program.as_slice(), opts);
//! return;
impl Matches {
fn opt_vals(&self, nm: &str) -> Vec<Optval> {
match find_opt(self.opts.as_slice(), Name::from_str(nm)) {
- Some(id) => (*self.vals.get(id)).clone(),
+ Some(id) => self.vals[id].clone(),
None => fail!("No option '{}' defined", nm)
}
}
if vals.is_empty() {
None
} else {
- Some((*vals.get(0)).clone())
+ Some(vals[0].clone())
}
}
for nm in names.iter() {
match find_opt(self.opts.as_slice(),
Name::from_str(nm.as_slice())) {
- Some(id) if !self.vals.get(id).is_empty() => return true,
+ Some(id) if !self.vals[id].is_empty() => return true,
_ => (),
};
}
if vals.is_empty() {
return None::<String>;
}
- match vals.get(0) {
- &Val(ref s) => Some((*s).clone()),
+ match vals[0] {
+ Val(ref s) => Some((*s).clone()),
_ => None
}
}
if vals.is_empty() {
return None;
}
- match vals.get(0) {
- &Val(ref s) => Some((*s).clone()),
+ match vals[0] {
+ Val(ref s) => Some((*s).clone()),
_ => Some(def.to_string())
}
}
names = vec!(Long(tail.to_string()));
} else {
names =
- vec!(Long((*tail_eq.get(0)).to_string()));
- i_arg = Some((*tail_eq.get(1)).to_string());
+ vec!(Long(tail_eq[0].to_string()));
+ i_arg = Some(tail_eq[1].to_string());
}
} else {
let mut j = 1;
None => {
let arg_follows =
last_valid_opt_id.is_some() &&
- match opts.get(last_valid_opt_id.unwrap())
+ match opts[last_valid_opt_id.unwrap()]
.hasarg {
Yes | Maybe => true,
Some(id) => id,
None => return Err(UnrecognizedOption(nm.to_string()))
};
- match opts.get(optid).hasarg {
+ match opts[optid].hasarg {
No => {
if !i_arg.is_none() {
return Err(UnexpectedArgument(nm.to_string()));
}
i = 0u;
while i < n_opts {
- let n = vals.get(i).len();
- let occ = opts.get(i).occur;
+ let n = vals[i].len();
+ let occ = opts[i].occur;
if occ == Req {
if n == 0 {
- return Err(OptionMissing(opts.get(i).name.to_string()));
+ return Err(OptionMissing(opts[i].name.to_string()));
}
}
if occ != Multi {
if n > 1 {
- return Err(OptionDuplicated(opts.get(i).name.to_string()));
+ return Err(OptionDuplicated(opts[i].name.to_string()));
}
}
i += 1;
if self.require_dir && !path.is_dir() { continue; }
return Some(path);
}
- let ref pattern = *self.dir_patterns.get(idx);
+ let ref pattern = self.dir_patterns[idx];
if pattern.matches_with(match path.filename_str() {
// this ugly match needs to go here to avoid a borrowck error
let mut i = 0;
while i < chars.len() {
- match *chars.get(i) {
+ match chars[i] {
'?' => {
tokens.push(AnyChar);
i += 1;
}
'*' => {
// *, **, ***, ****, ... are all equivalent
- while i < chars.len() && *chars.get(i) == '*' {
+ while i < chars.len() && chars[i] == '*' {
i += 1;
}
tokens.push(AnySequence);
}
'[' => {
- if i <= chars.len() - 4 && *chars.get(i + 1) == '!' {
+ if i <= chars.len() - 4 && chars[i + 1] == '!' {
match chars.slice_from(i + 3).position_elem(&']') {
None => (),
Some(j) => {
}
}
}
- else if i <= chars.len() - 3 && *chars.get(i + 1) != '!' {
+ else if i <= chars.len() - 3 && chars[i + 1] != '!' {
match chars.slice_from(i + 2).position_elem(&']') {
None => (),
Some(j) => {
// the current and parent directory respectively requires that
// the pattern has a leading dot, even if the `MatchOptions` field
// `require_literal_leading_dot` is not set.
- if pattern.tokens.len() > 0 && pattern.tokens.get(0) == &Char('.') {
+ if pattern.tokens.len() > 0 && pattern.tokens[0] == Char('.') {
for &special in [".", ".."].iter() {
if pattern.matches_with(special, options) {
add(todo, path.join(special));
dot::Id::new(format!("N{}", n))
}
fn node_label<'a>(&'a self, n: &Nd) -> dot::LabelText<'a> {
- dot::LabelStr(str::Slice(self.nodes.get(*n).as_slice()))
+ dot::LabelStr(str::Slice(self.nodes[*n].as_slice()))
}
fn edge_label<'a>(&'a self, _: &Ed) -> dot::LabelText<'a> {
dot::LabelStr(str::Slice("⊆"))
}
fn node_label<'a>(&'a self, n: &Nd<'a>) -> dot::LabelText<'a> {
let &(i, _) = n;
- dot::LabelStr(str::Slice(self.nodes.get(i).as_slice()))
+ dot::LabelStr(str::Slice(self.nodes[i].as_slice()))
}
fn edge_label<'a>(&'a self, _: &Ed<'a>) -> dot::LabelText<'a> {
dot::LabelStr(str::Slice("⊆"))
}
fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> {
self.edges.iter()
- .map(|&(i,j)|((i, self.nodes.get(i).as_slice()),
- (j, self.nodes.get(j).as_slice())))
+ .map(|&(i,j)|((i, self.nodes[i].as_slice()),
+ (j, self.nodes[j].as_slice())))
.collect()
}
fn source(&self, e: &Ed<'a>) -> Nd<'a> { let &(s,_) = e; s }
// left paren, let's grab the old flags and see if we
// need a capture.
let (cap, cap_name, oldflags) = {
- let paren = self.stack.get(altfrom-1);
+ let paren = &self.stack[altfrom-1];
(paren.capture(), paren.capture_name(), paren.flags())
};
try!(self.alternate(altfrom));
Some(i) => i,
None => return None,
};
- if *self.chars.get(closer-1) != ':' {
+ if self.chars[closer-1] != ':' {
return None
}
if closer - self.chari <= 3 {
max = Some(min);
} else {
let pieces: Vec<&str> = inner.as_slice().splitn(',', 1).collect();
- let (smin, smax) = (*pieces.get(0), *pieces.get(1));
+ let (smin, smax) = (pieces[0], pieces[1]);
if smin.len() == 0 {
return self.err("Max repetitions cannot be specified \
without min repetitions.")
if self.chari + offset >= self.chars.len() {
return None
}
- Some(*self.chars.get(self.chari + offset))
+ Some(self.chars[self.chari + offset])
}
fn peek_is(&self, offset: uint, is: char) -> bool {
}
fn cur(&self) -> char {
- *self.chars.get(self.chari)
+ self.chars[self.chari]
}
fn slice(&self, start: uint, end: uint) -> String {
pub fn find(&self, text: &str) -> Option<(uint, uint)> {
let caps = exec(self, Location, text);
if has_match(&caps) {
- Some((caps.get(0).unwrap(), caps.get(1).unwrap()))
+ Some((caps[0].unwrap(), caps[1].unwrap()))
} else {
None
}
/// original string matched.
pub fn pos(&self, i: uint) -> Option<(uint, uint)> {
let (s, e) = (i * 2, i * 2 + 1);
- if e >= self.locs.len() || self.locs.get(s).is_none() {
+ if e >= self.locs.len() || self.locs[s].is_none() {
// VM guarantees that each pair of locations are both Some or None.
return None
}
- Some((self.locs.get(s).unwrap(), self.locs.get(e).unwrap()))
+ Some((self.locs[s].unwrap(), self.locs[e].unwrap()))
}
/// Returns the matched string for the capture group `i`.
if !has_match(&caps) {
return None
} else {
- (caps.get(0).unwrap(), caps.get(1).unwrap())
+ (caps[0].unwrap(), caps[1].unwrap())
};
// Don't accept empty matches immediately following a match.
if !has_match(&caps) {
return None
} else {
- (caps.get(0).unwrap(), caps.get(1).unwrap())
+ (caps[0].unwrap(), caps[1].unwrap())
};
// Don't accept empty matches immediately following a match.
#[inline]
fn has_match(caps: &CaptureLocs) -> bool {
- caps.len() >= 2 && caps.get(0).is_some() && caps.get(1).is_some()
+ caps.len() >= 2 && caps[0].is_some() && caps[1].is_some()
}
// Make sure multi-line mode isn't enabled for it, otherwise we can't
// drop the initial .*?
let prefix_anchor =
- match *self.prog.insts.get(1) {
+ match self.prog.insts[1] {
EmptyBegin(flags) if flags & FLAG_MULTI == 0 => true,
_ => false,
};
fn step(&self, groups: &mut [Option<uint>], nlist: &mut Threads,
caps: &mut [Option<uint>], pc: uint)
-> StepState {
- match *self.prog.insts.get(pc) {
+ match self.prog.insts[pc] {
Match => {
match self.which {
Exists => {
//
// We make a minor optimization by indicating that the state is "empty"
// so that its capture groups are not filled in.
- match *self.prog.insts.get(pc) {
+ match self.prog.insts[pc] {
EmptyBegin(flags) => {
let multi = flags & FLAG_MULTI > 0;
nlist.add(pc, groups, true);
#[inline]
fn contains(&self, pc: uint) -> bool {
- let s = *self.sparse.get(pc);
- s < self.size && self.queue.get(s).pc == pc
+ let s = self.sparse[pc];
+ s < self.size && self.queue[s].pc == pc
}
#[inline]
#[inline]
fn pc(&self, i: uint) -> uint {
- self.queue.get(i).pc
+ self.queue[i].pc
}
#[inline]
}
};
+ let code_model = match sess.opts.cg.code_model.as_slice() {
+ "default" => llvm::CodeModelDefault,
+ "small" => llvm::CodeModelSmall,
+ "kernel" => llvm::CodeModelKernel,
+ "medium" => llvm::CodeModelMedium,
+ "large" => llvm::CodeModelLarge,
+ _ => {
+ sess.err(format!("{} is not a valid code model",
+ sess.opts
+ .cg
+ .code_model).as_slice());
+ sess.abort_if_errors();
+ return;
+ }
+ };
+
let tm = sess.targ_cfg
.target_strs
.target_triple
target_feature(sess).with_c_str(|features| {
llvm::LLVMRustCreateTargetMachine(
t, cpu, features,
- llvm::CodeModelDefault,
+ code_model,
reloc_model,
opt_level,
true /* EnableSegstk */,
"prefer dynamic linking to static linking"),
no_integrated_as: bool = (false, parse_bool,
"use an external assembler rather than LLVM's integrated one"),
+ no_redzone: bool = (false, parse_bool,
+ "disable the use of the redzone"),
relocation_model: String = ("pic".to_string(), parse_string,
"choose the relocation model to use (llc -relocation-model for details)"),
+ code_model: String = ("default".to_string(), parse_string,
+ "choose the code model to use (llc -code-model for details)"),
metadata: Vec<String> = (Vec::new(), parse_list,
"metadata to mangle symbol names with"),
extra_filename: String = ("".to_string(), parse_string,
pub fn get_method_name_and_explicit_self(cstore: &cstore::CStore,
def: ast::DefId)
- -> (ast::Ident, ast::ExplicitSelf_)
+ -> (ast::Ident,
+ ty::ExplicitSelfCategory)
{
let cdata = cstore.get_crate_data(def.krate);
decoder::get_method_name_and_explicit_self(cstore.intr.clone(), &*cdata, def.node)
}).collect()
}
-fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
+fn get_explicit_self(item: ebml::Doc) -> ty::ExplicitSelfCategory {
fn get_mutability(ch: u8) -> ast::Mutability {
match ch as char {
'i' => ast::MutImmutable,
let explicit_self_kind = string.as_bytes()[0];
match explicit_self_kind as char {
- 's' => ast::SelfStatic,
- 'v' => ast::SelfValue(special_idents::self_),
- '~' => ast::SelfUniq(special_idents::self_),
+ 's' => ty::StaticExplicitSelfCategory,
+ 'v' => ty::ByValueExplicitSelfCategory,
+ '~' => ty::ByBoxExplicitSelfCategory,
// FIXME(#4846) expl. region
- '&' => ast::SelfRegion(None, get_mutability(string.as_bytes()[1]),
- special_idents::self_),
+ '&' => {
+ ty::ByReferenceExplicitSelfCategory(
+ ty::ReEmpty,
+ get_mutability(string.as_bytes()[1]))
+ }
_ => fail!("unknown self type code: `{}`", explicit_self_kind as char)
}
}
methods
}
-pub fn get_method_name_and_explicit_self(
- intr: Rc<IdentInterner>,
- cdata: Cmd,
- id: ast::NodeId) -> (ast::Ident, ast::ExplicitSelf_)
-{
+pub fn get_method_name_and_explicit_self(intr: Rc<IdentInterner>,
+ cdata: Cmd,
+ id: ast::NodeId)
+ -> (ast::Ident,
+ ty::ExplicitSelfCategory) {
let method_doc = lookup_item(id, cdata.data());
let name = item_name(&*intr, method_doc);
let explicit_self = get_explicit_self(method_doc);
use syntax::ast_map;
use syntax::ast_util::*;
use syntax::ast_util;
+use syntax::ast_util::PostExpansionMethod;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::diagnostic::SpanHandler;
for base_impl_did in implementations.borrow().iter() {
for &method_did in impl_methods.get(base_impl_did).iter() {
let m = ty::method(ecx.tcx, method_did);
- if m.explicit_self == ast::SelfStatic {
+ if m.explicit_self == ty::StaticExplicitSelfCategory {
encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident);
}
}
match ecx.tcx.trait_methods_cache.borrow().find(&exp.def_id) {
Some(methods) => {
for m in methods.iter() {
- if m.explicit_self == ast::SelfStatic {
+ if m.explicit_self == ty::StaticExplicitSelfCategory {
encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident);
}
}
ebml_w.end_tag();
}
-fn encode_explicit_self(ebml_w: &mut Encoder, explicit_self: ast::ExplicitSelf_) {
+fn encode_explicit_self(ebml_w: &mut Encoder,
+ explicit_self: &ty::ExplicitSelfCategory) {
ebml_w.start_tag(tag_item_trait_method_explicit_self);
// Encode the base self type.
- match explicit_self {
- SelfStatic => { ebml_w.writer.write(&[ 's' as u8 ]); }
- SelfValue(_) => { ebml_w.writer.write(&[ 'v' as u8 ]); }
- SelfUniq(_) => { ebml_w.writer.write(&[ '~' as u8 ]); }
- SelfRegion(_, m, _) => {
+ match *explicit_self {
+ ty::StaticExplicitSelfCategory => {
+ ebml_w.writer.write(&[ 's' as u8 ]);
+ }
+ ty::ByValueExplicitSelfCategory => {
+ ebml_w.writer.write(&[ 'v' as u8 ]);
+ }
+ ty::ByBoxExplicitSelfCategory => {
+ ebml_w.writer.write(&[ '~' as u8 ]);
+ }
+ ty::ByReferenceExplicitSelfCategory(_, m) => {
// FIXME(#4846) encode custom lifetime
ebml_w.writer.write(&['&' as u8]);
encode_mutability(ebml_w, m);
tag_item_method_tps);
encode_method_fty(ecx, ebml_w, &method_ty.fty);
encode_visibility(ebml_w, method_ty.vis);
- encode_explicit_self(ebml_w, method_ty.explicit_self);
+ encode_explicit_self(ebml_w, &method_ty.explicit_self);
let fn_style = method_ty.fty.fn_style;
match method_ty.explicit_self {
- ast::SelfStatic => {
+ ty::StaticExplicitSelfCategory => {
encode_family(ebml_w, fn_style_static_method_family(fn_style));
}
_ => encode_family(ebml_w, style_fn_family(fn_style))
} else {
encode_symbol(ecx, ebml_w, m.def_id.node);
}
- encode_method_argument_names(ebml_w, method_fn_decl(&*ast_method));
+ encode_method_argument_names(ebml_w, &*ast_method.pe_fn_decl());
}
ebml_w.end_tag();
encode_path(ebml_w, path.clone().chain(Some(elem).move_iter()));
match method_ty.explicit_self {
- SelfStatic => {
+ ty::StaticExplicitSelfCategory => {
encode_family(ebml_w,
fn_style_static_method_family(
method_ty.fty.fn_style));
encode_attributes(ebml_w, m.attrs.as_slice());
// If this is a static method, we've already encoded
// this.
- if method_ty.explicit_self != SelfStatic {
+ if method_ty.explicit_self != ty::StaticExplicitSelfCategory {
// FIXME: I feel like there is something funny going on.
let pty = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
encode_method_sort(ebml_w, 'p');
encode_inlined_item(ecx, ebml_w,
IIMethodRef(def_id, true, &*m));
- encode_method_argument_names(ebml_w, method_fn_decl(m));
+ encode_method_argument_names(ebml_w, m.pe_fn_decl());
}
}
use util::ppaux::ty_to_string;
use syntax::{ast, ast_map, ast_util, codemap, fold};
+use syntax::ast_util::PostExpansionMethod;
use syntax::codemap::Span;
use syntax::fold::Folder;
use syntax::parse::token;
let ident = match ii {
ast::IIItem(i) => i.ident,
ast::IIForeign(i) => i.ident,
- ast::IIMethod(_, _, m) => ast_util::method_ident(&*m),
+ ast::IIMethod(_, _, m) => m.pe_ident(),
};
debug!("Fn named: {}", token::get_ident(ident));
debug!("< Decoded inlined fn: {}::{}",
mc::cat_static_item |
mc::cat_copied_upvar(..) |
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
- mc::cat_deref(_, _, mc::BorrowedPtr(..)) => {
+ mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
+ mc::cat_deref(_, _, mc::Implicit(..)) => {
assert_eq!(cmt.mutbl, mc::McDeclared);
return;
}
cmt: &mc::cmt) -> Option<mc::cmt> {
match cmt.cat {
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
+ mc::cat_deref(_, _, mc::Implicit(..)) |
mc::cat_deref(_, _, mc::GcPtr) |
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
mc::cat_upvar(..) | mc::cat_static_item |
mc::cat_arg(..) | // L-Local
mc::cat_upvar(..) |
mc::cat_deref(_, _, mc::BorrowedPtr(..)) | // L-Deref-Borrowed
+ mc::cat_deref(_, _, mc::Implicit(..)) |
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
self.check_scope(self.scope(cmt))
}
mc::cat_deref(_, _, mc::UnsafePtr(..)) => {
ty::ReStatic
}
- mc::cat_deref(_, _, mc::BorrowedPtr(_, r)) => {
+ mc::cat_deref(_, _, mc::BorrowedPtr(_, r)) |
+ mc::cat_deref(_, _, mc::Implicit(_, r)) => {
r
}
mc::cat_downcast(ref cmt) |
fn report_cannot_move_out_of(bccx: &BorrowckCtxt, move_from: mc::cmt) {
match move_from.cat {
mc::cat_deref(_, _, mc::BorrowedPtr(..)) |
+ mc::cat_deref(_, _, mc::Implicit(..)) |
mc::cat_deref(_, _, mc::GcPtr) |
mc::cat_deref(_, _, mc::UnsafePtr(..)) |
mc::cat_upvar(..) | mc::cat_static_item |
}
mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::ImmBorrow, lt)) |
- mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::UniqueImmBorrow, lt)) => {
+ mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::UniqueImmBorrow, lt)) |
+ mc::cat_deref(cmt_base, _, mc::Implicit(ty::ImmBorrow, lt)) |
+ mc::cat_deref(cmt_base, _, mc::Implicit(ty::UniqueImmBorrow, lt)) => {
// R-Deref-Imm-Borrowed
if !self.bccx.is_subregion_of(self.loan_region, lt) {
self.bccx.report(
Safe
}
- mc::cat_deref(cmt_base, _, pk @ mc::BorrowedPtr(ty::MutBorrow, lt)) => {
+ mc::cat_deref(cmt_base, _, pk @ mc::BorrowedPtr(ty::MutBorrow, lt)) |
+ mc::cat_deref(cmt_base, _, pk @ mc::Implicit(ty::MutBorrow, lt)) => {
// R-Deref-Mut-Borrowed
if !self.bccx.is_subregion_of(self.loan_region, lt) {
self.bccx.report(
use std::collections::HashSet;
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util;
-use syntax::ast_util::{local_def, is_local};
+use syntax::ast_util::{local_def, is_local, PostExpansionMethod};
use syntax::attr::AttrMetaMethods;
use syntax::attr;
use syntax::codemap;
visit::walk_trait_method(self, &*trait_method, ctxt);
}
ast_map::NodeMethod(method) => {
- visit::walk_block(self, ast_util::method_body(&*method), ctxt);
+ visit::walk_block(self, method.pe_body(), ctxt);
}
ast_map::NodeForeignItem(foreign_item) => {
visit::walk_foreign_item(self, &*foreign_item, ctxt);
// Overwrite so that we don't warn the trait method itself.
fn visit_trait_method(&mut self, trait_method: &ast::TraitMethod, _: ()) {
match *trait_method {
- ast::Provided(ref method) => visit::walk_block(self,
- ast_util::method_body(&**method), ()),
+ ast::Provided(ref method) => visit::walk_block(self, method.pe_body(), ()),
ast::Required(_) => ()
}
}
use std::gc::Gc;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Def {
DefFn(ast::DefId, ast::FnStyle),
DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */),
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum MethodProvenance {
FromTrait(ast::DefId),
FromImpl(ast::DefId),
use util::ppaux;
use syntax::ast;
-use syntax::ast_util;
+use syntax::ast_util::PostExpansionMethod;
use syntax::codemap::Span;
use syntax::visit;
use syntax::visit::Visitor;
visit::FkItemFn(_, _, fn_style, _) =>
(true, fn_style == ast::UnsafeFn),
visit::FkMethod(_, _, method) =>
- (true, ast_util::method_fn_style(method) == ast::UnsafeFn),
+ (true, method.pe_fn_style() == ast::UnsafeFn),
_ => (false, false),
};
span: Span,
struct_did: DefId) {
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
- if !struct_tpt.generics.has_type_params(subst::TypeSpace) {
+ if !struct_tpt.generics.has_type_params(subst::TypeSpace)
+ && !struct_tpt.generics.has_region_params(subst::TypeSpace) {
let struct_ty = ty::mk_struct(cx.tcx, struct_did,
subst::Substs::empty());
if !ty::type_is_sendable(cx.tcx, struct_ty) {
// If this trait has builtin-kind supertraits, meet them.
let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id);
- debug!("checking impl with self type {:?}", ty::get(self_ty).sty);
+ debug!("checking impl with self type {}", ty::get(self_ty).sty);
check_builtin_bounds(cx, self_ty, trait_def.bounds, |missing| {
cx.tcx.sess.span_err(self_type.span,
format!("the type `{}', which does not fulfill `{}`, cannot implement this \
OwnedPtr,
GcPtr,
BorrowedPtr(ty::BorrowKind, ty::Region),
- UnsafePtr(ast::Mutability),
+ Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr.
+ UnsafePtr(ast::Mutability)
}
// We use the term "interior" to mean "something reachable from the
OwnedPtr => {
base_mutbl.inherit()
}
- BorrowedPtr(borrow_kind, _) => {
+ BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
MutabilityCategory::from_borrow_kind(borrow_kind)
}
GcPtr => {
-> McResult<cmt> {
let mut cmt = if_ok!(self.cat_expr_unadjusted(expr));
for deref in range(1u, autoderefs + 1) {
- cmt = self.cat_deref(expr, cmt, deref);
+ cmt = self.cat_deref(expr, cmt, deref, false);
}
return Ok(cmt);
}
match expr.node {
ast::ExprUnary(ast::UnDeref, ref e_base) => {
let base_cmt = if_ok!(self.cat_expr(&**e_base));
- Ok(self.cat_deref(expr, base_cmt, 0))
+ Ok(self.cat_deref(expr, base_cmt, 0, false))
}
ast::ExprField(ref base, f_name, _) => {
}
ast::ExprIndex(ref base, _) => {
- let base_cmt = if_ok!(self.cat_expr(&**base));
- Ok(self.cat_index(expr, base_cmt, 0))
+ let method_call = typeck::MethodCall::expr(expr.id());
+ match self.typer.node_method_ty(method_call) {
+ Some(method_ty) => {
+ // If this is an index implemented by a method call, then it will
+ // include an implicit deref of the result.
+ let ret_ty = ty::ty_fn_ret(method_ty);
+ Ok(self.cat_deref(expr,
+ self.cat_rvalue_node(expr.id(),
+ expr.span(),
+ ret_ty), 1, true))
+ }
+ None => {
+ let base_cmt = if_ok!(self.cat_expr(&**base));
+ Ok(self.cat_index(expr, base_cmt, 0))
+ }
+ }
}
ast::ExprPath(_) => {
}
pub fn cat_deref_obj<N:ast_node>(&self, node: &N, base_cmt: cmt) -> cmt {
- self.cat_deref_common(node, base_cmt, 0, ty::mk_nil())
+ self.cat_deref_common(node, base_cmt, 0, ty::mk_nil(), false)
}
fn cat_deref<N:ast_node>(&self,
node: &N,
base_cmt: cmt,
- deref_cnt: uint)
+ deref_cnt: uint,
+ implicit: bool)
-> cmt {
let adjustment = match self.typer.adjustments().borrow().find(&node.id()) {
Some(&ty::AutoObject(..)) => typeck::AutoObject,
None => base_cmt
};
match ty::deref(base_cmt.ty, true) {
- Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty),
+ Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty, implicit),
None => {
self.tcx().sess.span_bug(
node.span(),
node: &N,
base_cmt: cmt,
deref_cnt: uint,
- deref_ty: ty::t)
+ deref_ty: ty::t,
+ implicit: bool)
-> cmt {
let (m, cat) = match deref_kind(self.tcx(), base_cmt.ty) {
deref_ptr(ptr) => {
+ let ptr = if implicit {
+ match ptr {
+ BorrowedPtr(bk, r) => Implicit(bk, r),
+ _ => self.tcx().sess.span_bug(node.span(),
+ "Implicit deref of non-borrowed pointer")
+ }
+ } else {
+ ptr
+ };
// for unique ptrs, we inherit mutability from the
// owning reference.
(MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
ast::PatBox(ref subpat) | ast::PatRegion(ref subpat) => {
// @p1, ~p1
- let subcmt = self.cat_deref(pat, cmt, 0);
+ let subcmt = self.cat_deref(pat, cmt, 0, false);
if_ok!(self.cat_pattern(subcmt, &**subpat, op));
}
}
_ => {
match pk {
+ Implicit(..) => {
+ "dereference (dereference is implicit, due to indexing)".to_string()
+ }
OwnedPtr | GcPtr => format!("dereference of `{}`", ptr_sigil(pk)),
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
}
cat_deref(_, _, UnsafePtr(..)) |
cat_deref(_, _, GcPtr(..)) |
cat_deref(_, _, BorrowedPtr(..)) |
+ cat_deref(_, _, Implicit(..)) |
cat_upvar(..) => {
Rc::new((*self).clone())
}
match self.cat {
cat_deref(ref b, _, BorrowedPtr(ty::MutBorrow, _)) |
+ cat_deref(ref b, _, Implicit(ty::MutBorrow, _)) |
cat_deref(ref b, _, BorrowedPtr(ty::UniqueImmBorrow, _)) |
+ cat_deref(ref b, _, Implicit(ty::UniqueImmBorrow, _)) |
cat_downcast(ref b) |
cat_deref(ref b, _, OwnedPtr) |
cat_interior(ref b, _) |
Some(AliasableManaged)
}
- cat_deref(_, _, BorrowedPtr(ty::ImmBorrow, _)) => {
+ cat_deref(_, _, BorrowedPtr(ty::ImmBorrow, _)) |
+ cat_deref(_, _, Implicit(ty::ImmBorrow, _)) => {
Some(AliasableBorrowed)
}
}
match ptr {
OwnedPtr => "Box",
GcPtr => "Gc",
- BorrowedPtr(ty::ImmBorrow, _) => "&",
- BorrowedPtr(ty::MutBorrow, _) => "&mut",
- BorrowedPtr(ty::UniqueImmBorrow, _) => "&unique",
+ BorrowedPtr(ty::ImmBorrow, _) |
+ Implicit(ty::ImmBorrow, _) => "&",
+ BorrowedPtr(ty::MutBorrow, _) |
+ Implicit(ty::MutBorrow, _) => "&mut",
+ BorrowedPtr(ty::UniqueImmBorrow, _) |
+ Implicit(ty::UniqueImmBorrow, _) => "&unique",
UnsafePtr(_) => "*"
}
}
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util;
-use syntax::ast_util::{is_local, local_def};
+use syntax::ast_util::{is_local, local_def, PostExpansionMethod};
use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token;
if public_ty || public_trait {
for method in methods.iter() {
- let meth_public = match ast_util::method_explicit_self(&**method).node {
+ let meth_public = match method.pe_explicit_self().node {
ast::SelfStatic => public_ty,
_ => true,
- } && ast_util::method_vis(&**method) == ast::Public;
+ } && method.pe_vis() == ast::Public;
if meth_public || tr.is_some() {
self.exported_items.insert(method.id);
}
let imp = self.tcx.map.get_parent_did(closest_private_id);
match ty::impl_trait_ref(self.tcx, imp) {
Some(..) => return Allowable,
- _ if ast_util::method_vis(&**m) == ast::Public => return Allowable,
- _ => ast_util::method_vis(&**m)
+ _ if m.pe_vis() == ast::Public => return Allowable,
+ _ => m.pe_vis()
}
}
Some(ast_map::NodeTraitMethod(_)) => {
"visibility qualifiers have no effect on trait \
impls");
for m in methods.iter() {
- check_inherited(m.span, ast_util::method_vis(&**m), "");
+ check_inherited(m.span, m.pe_vis(), "");
}
}
for m in methods.iter() {
match *m {
ast::Provided(ref m) => {
- check_inherited(m.span, ast_util::method_vis(&**m),
+ check_inherited(m.span, m.pe_vis(),
"unnecessary visibility");
}
ast::Required(ref m) => {
match item.node {
ast::ItemImpl(_, _, _, ref methods) => {
for m in methods.iter() {
- check_inherited(tcx, m.span, ast_util::method_vis(&**m));
+ check_inherited(tcx, m.span, m.pe_vis());
}
}
ast::ItemForeignMod(ref fm) => {
match *m {
ast::Required(..) => {}
ast::Provided(ref m) => check_inherited(tcx, m.span,
- ast_util::method_vis(&**m)),
+ m.pe_vis()),
}
}
}
// methods will be visible as `Public::foo`.
let mut found_pub_static = false;
for method in methods.iter() {
- if ast_util::method_explicit_self(&**method).node == ast::SelfStatic &&
+ if method.pe_explicit_self().node == ast::SelfStatic &&
self.exported_items.contains(&method.id) {
found_pub_static = true;
visit::walk_method_helper(self, &**method, ());
use syntax::abi;
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util::is_local;
+use syntax::ast_util::{is_local, PostExpansionMethod};
use syntax::ast_util;
use syntax::attr::{InlineAlways, InlineHint, InlineNever, InlineNone};
use syntax::attr;
fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method,
impl_src: ast::DefId) -> bool {
if attributes_specify_inlining(method.attrs.as_slice()) ||
- generics_require_inlining(ast_util::method_generics(&*method)) {
+ generics_require_inlining(method.pe_generics()) {
return true
}
if is_local(impl_src) {
}
}
Some(ast_map::NodeMethod(method)) => {
- if generics_require_inlining(ast_util::method_generics(&*method)) ||
+ if generics_require_inlining(method.pe_generics()) ||
attributes_specify_inlining(method.attrs.as_slice()) {
true
} else {
// Keep going, nothing to get exported
}
ast::Provided(ref method) => {
- visit::walk_block(self, ast_util::method_body(&**method), ())
+ visit::walk_block(self, method.pe_body(), ())
}
}
}
ast_map::NodeMethod(method) => {
let did = self.tcx.map.get_parent_did(search_item);
if method_might_be_inlined(self.tcx, &*method, did) {
- visit::walk_block(self, ast_util::method_body(&*method), ())
+ visit::walk_block(self, method.pe_body(), ())
}
}
// Nothing to recurse on for these
self.sub_free_region(sub_fr, super_fr)
}
+ (ty::ReEarlyBound(param_id_a, param_space_a, index_a, _),
+ ty::ReEarlyBound(param_id_b, param_space_b, index_b, _)) => {
+ // This case is used only to make sure that explicitly-
+ // specified `Self` types match the real self type in
+ // implementations.
+ param_id_a == param_id_b &&
+ param_space_a == param_space_b &&
+ index_a == index_b
+ }
+
_ => {
false
}
#![allow(non_camel_case_types)]
use driver::session::Session;
+use lint;
use metadata::csearch;
use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
use middle::def::*;
use middle::lang_items::LanguageItems;
use middle::pat_util::pat_bindings;
use middle::subst::{ParamSpace, FnSpace, TypeSpace};
-use lint;
+use middle::ty::{ExplicitSelfCategory, StaticExplicitSelfCategory};
use util::nodemap::{NodeMap, DefIdSet, FnvHashMap};
use syntax::ast::*;
use syntax::ast;
-use syntax::ast_util;
-use syntax::ast_util::{local_def};
+use syntax::ast_util::{local_def, PostExpansionMethod};
use syntax::ast_util::{walk_pat, trait_method_to_ty_method};
use syntax::ext::mtwt;
use syntax::parse::token::special_names;
PrefixFound(Rc<Module>, uint)
}
+#[deriving(Clone, Eq, PartialEq)]
+enum MethodIsStaticFlag {
+ MethodIsNotStatic,
+ MethodIsStatic,
+}
+
+impl MethodIsStaticFlag {
+ fn from_explicit_self_category(explicit_self_category:
+ ExplicitSelfCategory)
+ -> MethodIsStaticFlag {
+ if explicit_self_category == StaticExplicitSelfCategory {
+ MethodIsStatic
+ } else {
+ MethodIsNotStatic
+ }
+ }
+}
+
#[deriving(PartialEq)]
enum NameSearchType {
/// We're doing a name search in order to resolve a `use` directive.
graph_root: NameBindings,
- method_map: RefCell<FnvHashMap<(Name, DefId), ast::ExplicitSelf_>>,
+ method_map: RefCell<FnvHashMap<(Name, DefId), MethodIsStaticFlag>>,
+
structs: FnvHashMap<DefId, Vec<Name>>,
// The number of imports that are currently unresolved.
// For each method...
for method in methods.iter() {
// Add the method to the module.
- let ident = ast_util::method_ident(&**method);
+ let ident = method.pe_ident();
let method_name_bindings =
self.add_child(ident,
new_parent.clone(),
ForbidDuplicateValues,
method.span);
- let def = match ast_util::method_explicit_self(&**method).node {
+ let def = match method.pe_explicit_self().node {
SelfStatic => {
// Static methods become
// `def_static_method`s.
DefStaticMethod(local_def(method.id),
FromImpl(local_def(
item.id)),
- ast_util::method_fn_style(&**method))
+ method.pe_fn_style())
}
_ => {
// Non-static methods become
}
};
- let is_public = ast_util::method_vis(&**method) == ast::Public;
+ let is_public = method.pe_vis() == ast::Public;
method_name_bindings.define_value(def,
method.span,
is_public);
let ident = ty_m.ident;
// Add it as a name in the trait module.
- let def = match ty_m.explicit_self.node {
+ let (def, static_flag) = match ty_m.explicit_self.node {
SelfStatic => {
// Static methods become `def_static_method`s.
- DefStaticMethod(local_def(ty_m.id),
+ (DefStaticMethod(local_def(ty_m.id),
FromTrait(local_def(item.id)),
- ty_m.fn_style)
+ ty_m.fn_style),
+ MethodIsStatic)
}
_ => {
// Non-static methods become `def_method`s.
- DefMethod(local_def(ty_m.id),
- Some(local_def(item.id)))
+ (DefMethod(local_def(ty_m.id),
+ Some(local_def(item.id))),
+ MethodIsNotStatic)
}
};
ty_m.span);
method_name_bindings.define_value(def, ty_m.span, true);
- self.method_map.borrow_mut().insert((ident.name, def_id),
- ty_m.explicit_self.node);
+ self.method_map
+ .borrow_mut()
+ .insert((ident.name, def_id), static_flag);
}
name_bindings.define_type(DefTrait(def_id), sp, is_public);
trait method '{}'",
token::get_ident(method_name));
- self.method_map.borrow_mut().insert((method_name.name, def_id), explicit_self);
+ self.method_map
+ .borrow_mut()
+ .insert((method_name.name, def_id),
+ MethodIsStaticFlag::from_explicit_self_category(
+ explicit_self));
if is_exported {
self.external_exports.insert(method_def_id);
this.resolve_type(&*argument.ty);
}
+ match ty_m.explicit_self.node {
+ SelfExplicit(ref typ, _) => {
+ this.resolve_type(*typ)
+ }
+ _ => {}
+ }
+
this.resolve_type(&*ty_m.decl.output);
});
}
fn resolve_method(&mut self,
rib_kind: RibKind,
method: &Method) {
- let method_generics = ast_util::method_generics(method);
+ let method_generics = method.pe_generics();
let type_parameters = HasTypeParameters(method_generics,
FnSpace,
method.id,
rib_kind);
- self.resolve_function(rib_kind, Some(ast_util::method_fn_decl(method)),
+ match method.pe_explicit_self().node {
+ SelfExplicit(ref typ, _) => self.resolve_type(*typ),
+ _ => {}
+ }
+
+ self.resolve_function(rib_kind,
+ Some(method.pe_fn_decl()),
type_parameters,
- ast_util::method_body(method));
+ method.pe_body());
}
fn with_current_self_type<T>(&mut self, self_type: &Ty, f: |&mut Resolver| -> T) -> T {
fn check_trait_method(&self, method: &Method) {
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
for &(did, ref trait_ref) in self.current_trait_ref.iter() {
- let method_name = ast_util::method_ident(method).name;
+ let method_name = method.pe_ident().name;
if self.method_map.borrow().find(&(method_name, did)).is_none() {
let path_str = self.path_idents_to_string(&trait_ref.path);
match containing_module.def_id.get() {
Some(def_id) => {
match self.method_map.borrow().find(&(ident.name, def_id)) {
- Some(x) if *x == SelfStatic => (),
+ Some(&MethodIsStatic) => (),
None => (),
_ => {
debug!("containing module was a trait or impl \
let path_str = self.path_idents_to_string(&trait_ref.path);
match method_map.find(&(name, did)) {
- Some(&SelfStatic) => return StaticTraitMethod(path_str),
+ Some(&MethodIsStatic) => return StaticTraitMethod(path_str),
Some(_) => return TraitMethod,
None => {}
}
use syntax::ast;
use syntax::ast_util;
+use syntax::ast_util::PostExpansionMethod;
use syntax::ast::{NodeId,DefId};
use syntax::ast_map::NodeItem;
use syntax::attr;
},
};
- qualname.push_str(get_ident(ast_util::method_ident(&*method)).get());
+ qualname.push_str(get_ident(method.pe_ident()).get());
let qualname = qualname.as_slice();
// record the decl for this def (if it has one)
decl_id,
scope_id);
- let m_decl = ast_util::method_fn_decl(&*method);
- self.process_formals(&m_decl.inputs, qualname, e);
+ self.process_formals(&method.pe_fn_decl().inputs, qualname, e);
// walk arg and return types
- for arg in m_decl.inputs.iter() {
+ for arg in method.pe_fn_decl().inputs.iter() {
self.visit_ty(&*arg.ty, e);
}
- self.visit_ty(m_decl.output, e);
+ self.visit_ty(method.pe_fn_decl().output, e);
// walk the fn body
- self.visit_block(ast_util::method_body(&*method), DxrVisitorEnv::new_nested(method.id));
+ self.visit_block(method.pe_body(), DxrVisitorEnv::new_nested(method.id));
- self.process_generic_params(ast_util::method_generics(&*method),
+ self.process_generic_params(method.pe_generics(),
method.span,
qualname,
method.id,
use middle::ty_fold::{TypeFoldable, TypeFolder};
use util::ppaux::Repr;
+use std::fmt;
use std::mem;
use std::raw;
use std::slice::{Items, MutItems};
* space* (which indices where the parameter is defined; see
* `ParamSpace`).
*/
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct Substs {
pub types: VecPerParamSpace<ty::t>,
pub regions: RegionSubsts,
* Represents the values to use when substituting lifetime parameters.
* If the value is `ErasedRegions`, then this subst is occurring during
* trans, and all region parameters will be replaced with `ty::ReStatic`. */
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub enum RegionSubsts {
ErasedRegions,
NonerasedRegions(VecPerParamSpace<ty::Region>)
content: Vec<T>,
}
+impl<T:fmt::Show> fmt::Show for VecPerParamSpace<T> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ try!(write!(fmt, "VecPerParamSpace {{"));
+ for space in ParamSpace::all().iter() {
+ try!(write!(fmt, "{}: {}, ", *space, self.get_slice(*space)));
+ }
+ try!(write!(fmt, "}}"));
+ Ok(())
+ }
+}
+
impl<T:Clone> VecPerParamSpace<T> {
pub fn push_all(&mut self, space: ParamSpace, values: &[T]) {
// FIXME (#15435): slow; O(n^2); could enhance vec to make it O(n).
// the specialized routine
// `middle::typeck::check::regionmanip::replace_late_regions_in_fn_sig()`.
match r {
- ty::ReEarlyBound(_, space, i, _) => {
+ ty::ReEarlyBound(_, space, i, region_name) => {
match self.substs.regions {
ErasedRegions => ty::ReStatic,
- NonerasedRegions(ref regions) => *regions.get(space, i),
+ NonerasedRegions(ref regions) =>
+ match regions.opt_get(space, i) {
+ Some(t) => *t,
+ None => {
+ let span = self.span.unwrap_or(DUMMY_SP);
+ self.tcx().sess.span_bug(
+ span,
+ format!("Type parameter out of range \
+ when substituting in region {} (root type={})",
+ region_name.as_str(),
+ self.root_ty.repr(self.tcx())).as_slice());
+ }
+ }
}
}
_ => r
_ => {}
}
+ if ccx.tcx.sess.opts.cg.no_redzone {
+ unsafe {
+ llvm::LLVMAddFunctionAttribute(llfn,
+ llvm::FunctionIndex as c_uint,
+ llvm::NoRedZoneAttribute as uint64_t)
+ }
+ }
+
llvm::SetFunctionCallConv(llfn, cc);
// Function addresses in Rust are never significant, allowing functions to be merged.
llvm::SetUnnamedAddr(llfn, true);
use syntax::util::interner::Interner;
use syntax::codemap::{Span, Pos};
use syntax::{abi, ast, codemap, ast_util, ast_map};
+use syntax::ast_util::PostExpansionMethod;
use syntax::owned_slice::OwnedSlice;
use syntax::parse::token;
use syntax::parse::token::special_idents;
}
}
ast_map::NodeMethod(ref method) => {
- (ast_util::method_ident(&**method),
- ast_util::method_fn_decl(&**method),
- ast_util::method_generics(&**method),
- ast_util::method_body(&**method),
+ (method.pe_ident(),
+ method.pe_fn_decl(),
+ method.pe_generics(),
+ method.pe_body(),
method.span,
true)
}
ast_map::NodeTraitMethod(ref trait_method) => {
match **trait_method {
ast::Provided(ref method) => {
- (ast_util::method_ident(&**method),
- ast_util::method_fn_decl(&**method),
- ast_util::method_generics(&**method),
- ast_util::method_body(&**method),
+ (method.pe_ident(),
+ method.pe_fn_decl(),
+ method.pe_generics(),
+ method.pe_body(),
method.span,
true)
}
use middle::ty;
use syntax::ast;
-use syntax::ast_util::local_def;
+use syntax::ast_util::{local_def, PostExpansionMethod};
use syntax::ast_util;
pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
let impl_tpt = ty::lookup_item_type(ccx.tcx(), impl_did);
let unparameterized =
impl_tpt.generics.types.is_empty() &&
- ast_util::method_generics(&*mth).ty_params.is_empty();
+ mth.pe_generics().ty_params.is_empty();
if unparameterized {
let llfn = get_item_val(ccx, mth.id);
- trans_fn(ccx, ast_util::method_fn_decl(&*mth),
- ast_util::method_body(&*mth), llfn,
+ trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), llfn,
¶m_substs::empty(), mth.id, []);
}
local_def(mth.id)
use std::gc::Gc;
use syntax::abi::Rust;
use syntax::parse::token;
-use syntax::{ast, ast_map, visit, ast_util};
+use syntax::{ast, ast_map, visit};
+use syntax::ast_util::PostExpansionMethod;
/**
The main "translation" pass for methods. Generates code
return;
}
for method in methods.iter() {
- if ast_util::method_generics(&**method).ty_params.len() == 0u {
+ if method.pe_generics().ty_params.len() == 0u {
let llfn = get_item_val(ccx, method.id);
- trans_fn(ccx, ast_util::method_fn_decl(&**method),
- ast_util::method_body(&**method),
+ trans_fn(ccx, method.pe_fn_decl(), method.pe_body(),
llfn, ¶m_substs::empty(), method.id, []);
} else {
let mut v = TransItemVisitor{ ccx: ccx };
ast_map::NodeTraitMethod(method) => {
let ident = match *method {
ast::Required(ref m) => m.ident,
- ast::Provided(ref m) => ast_util::method_ident(&**m)
+ ast::Provided(ref m) => m.pe_ident()
};
ident.name
}
ExprId(0),
substs.clone(),
vtables.clone());
- match m.explicit_self {
- ast::SelfValue(_) => {
- fn_ref = trans_unboxing_shim(bcx,
- fn_ref,
- &*m,
- m_id,
- substs.clone());
- },
- _ => {}
+ if m.explicit_self == ty::ByValueExplicitSelfCategory {
+ fn_ref = trans_unboxing_shim(bcx,
+ fn_ref,
+ &*m,
+ m_id,
+ substs.clone());
}
fn_ref
}
use syntax::abi;
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util;
-use syntax::ast_util::local_def;
+use syntax::ast_util::{local_def, PostExpansionMethod};
use std::hash::{sip, Hash};
pub fn monomorphic_fn(ccx: &CrateContext,
ast_map::NodeMethod(mth) => {
let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
- trans_fn(ccx, ast_util::method_fn_decl(&*mth),
- ast_util::method_body(&*mth), d, &psubsts, mth.id, []);
+ trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, []);
d
}
ast_map::NodeTraitMethod(method) => {
ast::Provided(mth) => {
let d = mk_lldecl();
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
- trans_fn(ccx, ast_util::method_fn_decl(&*mth),
- ast_util::method_body(&*mth), d, &psubsts, mth.id, []);
+ trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d,
+ &psubsts, mth.id, []);
d
}
_ => {
pub ident: ast::Ident,
pub generics: ty::Generics,
pub fty: BareFnTy,
- pub explicit_self: ast::ExplicitSelf_,
+ pub explicit_self: ExplicitSelfCategory,
pub vis: ast::Visibility,
pub def_id: ast::DefId,
pub container: MethodContainer,
pub fn new(ident: ast::Ident,
generics: ty::Generics,
fty: BareFnTy,
- explicit_self: ast::ExplicitSelf_,
+ explicit_self: ExplicitSelfCategory,
vis: ast::Visibility,
def_id: ast::DefId,
container: MethodContainer,
}
}
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct mt {
pub ty: t,
pub mutbl: ast::Mutability,
RegionTraitStore(Region, ast::Mutability),
}
-#[deriving(Clone)]
+#[deriving(Clone, Show)]
pub struct field_ty {
pub name: Name,
pub id: DefId,
/// (inferred) variance.
pub item_variance_map: RefCell<DefIdMap<Rc<ItemVariances>>>,
+ /// True if the variance has been computed yet; false otherwise.
+ pub variance_computed: Cell<bool>,
+
/// A mapping from the def ID of an enum or struct type to the def ID
/// of the method that implements its destructor. If the type is not
/// present in this map, it does not have a destructor. This map is
pub type t_box = &'static t_box_;
+#[deriving(Show)]
pub struct t_box_ {
pub sty: sty,
pub id: uint,
}
pub fn type_id(t: t) -> uint { get(t).id }
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct BareFnTy {
pub fn_style: ast::FnStyle,
pub abi: abi::Abi,
pub sig: FnSig,
}
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ClosureTy {
pub fn_style: ast::FnStyle,
pub onceness: ast::Onceness,
pub variadic: bool
}
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ParamTy {
pub space: subst::ParamSpace,
pub idx: uint,
// NB: If you change this, you'll probably want to change the corresponding
// AST structure in libsyntax/ast.rs as well.
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub enum sty {
ty_nil,
ty_bot,
// on non-useful type error messages)
}
-#[deriving(Clone, PartialEq, Eq, Hash)]
+#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct TyTrait {
pub def_id: DefId,
pub substs: Substs,
pub bounds: BuiltinBounds
}
-#[deriving(PartialEq, Eq, Hash)]
+#[deriving(PartialEq, Eq, Hash, Show)]
pub struct TraitRef {
pub def_id: DefId,
pub substs: Substs,
terr_variadic_mismatch(expected_found<bool>)
}
-#[deriving(PartialEq, Eq, Hash)]
+#[deriving(PartialEq, Eq, Hash, Show)]
pub struct ParamBounds {
pub builtin_bounds: BuiltinBounds,
pub trait_bounds: Vec<Rc<TraitRef>>
}
}
-#[deriving(Clone)]
+#[deriving(Clone, Show)]
pub struct TypeParameterDef {
pub ident: ast::Ident,
pub def_id: ast::DefId,
pub default: Option<ty::t>
}
-#[deriving(Encodable, Decodable, Clone)]
+#[deriving(Encodable, Decodable, Clone, Show)]
pub struct RegionParameterDef {
pub name: ast::Name,
pub def_id: ast::DefId,
/// Information about the type/lifetime parameters associated with an
/// item or method. Analogous to ast::Generics.
-#[deriving(Clone)]
+#[deriving(Clone, Show)]
pub struct Generics {
pub types: VecPerParamSpace<TypeParameterDef>,
pub regions: VecPerParamSpace<RegionParameterDef>,
pub fn has_type_params(&self, space: subst::ParamSpace) -> bool {
!self.types.is_empty_in(space)
}
+
+ pub fn has_region_params(&self, space: subst::ParamSpace) -> bool {
+ !self.regions.is_empty_in(space)
+ }
}
/// When type checking, we use the `ParameterEnvironment` to track
/// - `generics`: the set of type parameters and their bounds
/// - `ty`: the base types, which may reference the parameters defined
/// in `generics`
-#[deriving(Clone)]
+#[deriving(Clone, Show)]
pub struct Polytype {
pub generics: Generics,
pub ty: t
ctxt {
named_region_map: named_region_map,
item_variance_map: RefCell::new(DefIdMap::new()),
+ variance_computed: Cell::new(false),
interner: RefCell::new(FnvHashMap::new()),
next_id: Cell::new(primitives::LAST_PRIMITIVE_ID),
sess: s,
self.upvar_borrow_map.borrow().get_copy(&upvar_id)
}
}
+
+/// The category of explicit self.
+#[deriving(Clone, Eq, PartialEq)]
+pub enum ExplicitSelfCategory {
+ StaticExplicitSelfCategory,
+ ByValueExplicitSelfCategory,
+ ByReferenceExplicitSelfCategory(Region, ast::Mutability),
+ ByBoxExplicitSelfCategory,
+}
+
use middle::const_eval;
use middle::def;
use middle::lang_items::FnMutTraitLangItem;
-use rl = middle::resolve_lifetime;
use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
use middle::ty;
-use middle::typeck::TypeAndSubsts;
-use middle::typeck::lookup_def_tcx;
+use middle::ty_fold::TypeFolder;
use middle::typeck::rscope::RegionScope;
-use middle::typeck::rscope;
+use middle::typeck::{TypeAndSubsts, infer, lookup_def_tcx, rscope};
+use middle::typeck;
+use rl = middle::resolve_lifetime;
use util::ppaux::Repr;
use std::rc::Rc;
}
};
- debug!("opt_ast_region_to_region(opt_lifetime={:?}) yields {}",
+ debug!("opt_ast_region_to_region(opt_lifetime={}) yields {}",
opt_lifetime.as_ref().map(|e| lifetime_to_string(e)),
r.repr(this.tcx()));
}
}
+#[deriving(Show)]
enum PointerTy {
Box,
RPtr(ty::Region),
constr: |ty::t| -> ty::t)
-> ty::t {
let tcx = this.tcx();
- debug!("mk_pointer(ptr_ty={:?})", ptr_ty);
+ debug!("mk_pointer(ptr_ty={})", ptr_ty);
match a_seq_ty.ty.node {
ast::TyVec(ref ty) => {
}
}
-struct SelfInfo {
+struct SelfInfo<'a> {
untransformed_self_ty: ty::t,
- explicit_self: ast::ExplicitSelf
+ explicit_self: ast::ExplicitSelf,
}
pub fn ty_of_method<AC:AstConv>(
- this: &AC,
- id: ast::NodeId,
- fn_style: ast::FnStyle,
- untransformed_self_ty: ty::t,
- explicit_self: ast::ExplicitSelf,
- decl: &ast::FnDecl)
- -> ty::BareFnTy
-{
- ty_of_method_or_bare_fn(this, id, fn_style, abi::Rust, Some(SelfInfo {
+ this: &AC,
+ id: ast::NodeId,
+ fn_style: ast::FnStyle,
+ untransformed_self_ty: ty::t,
+ explicit_self: ast::ExplicitSelf,
+ decl: &ast::FnDecl)
+ -> (ty::BareFnTy, ty::ExplicitSelfCategory) {
+ let self_info = Some(SelfInfo {
untransformed_self_ty: untransformed_self_ty,
- explicit_self: explicit_self
- }), decl)
+ explicit_self: explicit_self,
+ });
+ let (bare_fn_ty, optional_explicit_self_category) =
+ ty_of_method_or_bare_fn(this,
+ id,
+ fn_style,
+ abi::Rust,
+ self_info,
+ decl);
+ (bare_fn_ty, optional_explicit_self_category.unwrap())
}
pub fn ty_of_bare_fn<AC:AstConv>(this: &AC, id: ast::NodeId,
fn_style: ast::FnStyle, abi: abi::Abi,
decl: &ast::FnDecl) -> ty::BareFnTy {
- ty_of_method_or_bare_fn(this, id, fn_style, abi, None, decl)
+ let (bare_fn_ty, _) =
+ ty_of_method_or_bare_fn(this, id, fn_style, abi, None, decl);
+ bare_fn_ty
}
-fn ty_of_method_or_bare_fn<AC:AstConv>(this: &AC, id: ast::NodeId,
- fn_style: ast::FnStyle, abi: abi::Abi,
- opt_self_info: Option<SelfInfo>,
- decl: &ast::FnDecl) -> ty::BareFnTy {
+fn ty_of_method_or_bare_fn<AC:AstConv>(
+ this: &AC,
+ id: ast::NodeId,
+ fn_style: ast::FnStyle,
+ abi: abi::Abi,
+ opt_self_info: Option<SelfInfo>,
+ decl: &ast::FnDecl)
+ -> (ty::BareFnTy,
+ Option<ty::ExplicitSelfCategory>) {
debug!("ty_of_method_or_bare_fn");
// new region names that appear inside of the fn decl are bound to
// that function type
let rb = rscope::BindingRscope::new(id);
+ let mut explicit_self_category_result = None;
let self_ty = opt_self_info.and_then(|self_info| {
- match self_info.explicit_self.node {
- ast::SelfStatic => None,
- ast::SelfValue(_) => {
+ // Figure out and record the explicit self category.
+ let explicit_self_category =
+ determine_explicit_self_category(this, &rb, &self_info);
+ explicit_self_category_result = Some(explicit_self_category);
+ match explicit_self_category {
+ ty::StaticExplicitSelfCategory => None,
+ ty::ByValueExplicitSelfCategory => {
Some(self_info.untransformed_self_ty)
}
- ast::SelfRegion(ref lifetime, mutability, _) => {
- let region =
- opt_ast_region_to_region(this, &rb,
- self_info.explicit_self.span,
- lifetime);
+ ty::ByReferenceExplicitSelfCategory(region, mutability) => {
Some(ty::mk_rptr(this.tcx(), region,
ty::mt {ty: self_info.untransformed_self_ty,
mutbl: mutability}))
}
- ast::SelfUniq(_) => {
+ ty::ByBoxExplicitSelfCategory => {
Some(ty::mk_uniq(this.tcx(), self_info.untransformed_self_ty))
}
}
_ => ast_ty_to_ty(this, &rb, &*decl.output)
};
- return ty::BareFnTy {
+ (ty::BareFnTy {
fn_style: fn_style,
abi: abi,
sig: ty::FnSig {
output: output_ty,
variadic: decl.variadic
}
- };
+ }, explicit_self_category_result)
+}
+
+fn determine_explicit_self_category<AC:AstConv,
+ RS:RegionScope>(
+ this: &AC,
+ rscope: &RS,
+ self_info: &SelfInfo)
+ -> ty::ExplicitSelfCategory {
+ match self_info.explicit_self.node {
+ ast::SelfStatic => ty::StaticExplicitSelfCategory,
+ ast::SelfValue(_) => ty::ByValueExplicitSelfCategory,
+ ast::SelfRegion(ref lifetime, mutability, _) => {
+ let region =
+ opt_ast_region_to_region(this,
+ rscope,
+ self_info.explicit_self.span,
+ lifetime);
+ ty::ByReferenceExplicitSelfCategory(region, mutability)
+ }
+ ast::SelfUniq(_) => ty::ByBoxExplicitSelfCategory,
+ ast::SelfExplicit(ast_type, _) => {
+ let explicit_type = ast_ty_to_ty(this, rscope, ast_type);
+
+ {
+ let inference_context = infer::new_infer_ctxt(this.tcx());
+ let expected_self = self_info.untransformed_self_ty;
+ let actual_self = explicit_type;
+ let result = infer::mk_eqty(
+ &inference_context,
+ false,
+ infer::Misc(self_info.explicit_self.span),
+ expected_self,
+ actual_self);
+ match result {
+ Ok(_) => {
+ inference_context.resolve_regions_and_report_errors();
+ return ty::ByValueExplicitSelfCategory
+ }
+ Err(_) => {}
+ }
+ }
+
+ match ty::get(explicit_type).sty {
+ ty::ty_rptr(region, tm) => {
+ typeck::require_same_types(
+ this.tcx(),
+ None,
+ false,
+ self_info.explicit_self.span,
+ self_info.untransformed_self_ty,
+ tm.ty,
+ || "not a valid type for `self`".to_owned());
+ return ty::ByReferenceExplicitSelfCategory(region,
+ tm.mutbl)
+ }
+ ty::ty_uniq(typ) => {
+ typeck::require_same_types(
+ this.tcx(),
+ None,
+ false,
+ self_info.explicit_self.span,
+ self_info.untransformed_self_ty,
+ typ,
+ || "not a valid type for `self`".to_owned());
+ return ty::ByBoxExplicitSelfCategory
+ }
+ _ => {
+ this.tcx()
+ .sess
+ .span_err(self_info.explicit_self.span,
+ "not a valid type for `self`");
+ return ty::ByValueExplicitSelfCategory
+ }
+ }
+ }
+ }
}
pub fn ty_of_closure<AC:AstConv>(
(&None, ty::UniqTraitStore) => ty::empty_builtin_bounds(),
}
}
+
ty::ty_struct(cid, ref substs) => {
// Verify that the pattern named the right structure.
let item_did = tcx.def_map.borrow().get(&pat.id).def_id();
- let struct_did =
- ty::ty_to_def_id(
- ty::lookup_item_type(tcx, item_did).ty).unwrap();
- if struct_did != cid {
- span_err!(tcx.sess, pat.span, E0032,
- "`{}` does not name the structure `{}`",
- pprust::path_to_string(path),
- fcx.infcx().ty_to_string(expected));
+ match ty::ty_to_def_id(ty::lookup_item_type(tcx, item_did).ty) {
+ Some(struct_did) if struct_did != cid => {
+ span_err!(tcx.sess, path.span, E0032,
+ "`{}` does not name the structure `{}`",
+ pprust::path_to_string(path),
+ fcx.infcx().ty_to_string(expected));
+ },
+ Some(_) => {},
+ None => {
+ tcx.sess.span_bug(
+ path.span,
+ format!("This shouldn't happen: failed to lookup structure. \
+ item_did = {}", item_did).as_slice())
+ },
}
check_struct_pat(pcx, pat.id, pat.span, expected, path,
use std::collections::HashSet;
use std::rc::Rc;
-use syntax::ast::{DefId, SelfValue, SelfRegion};
-use syntax::ast::{SelfUniq, SelfStatic};
-use syntax::ast::{MutMutable, MutImmutable};
+use syntax::ast::{DefId, MutImmutable, MutMutable};
use syntax::ast;
use syntax::codemap::Span;
use syntax::parse::token;
obj_substs.types.pop(subst::SelfSpace).unwrap();
match method_ty.explicit_self {
- ast::SelfStatic => {
+ StaticExplicitSelfCategory => {
tcx.sess.span_bug(span, "static method for object type receiver");
}
- ast::SelfValue(_) => {
+ ByValueExplicitSelfCategory => {
let tr = ty::mk_trait(tcx, trait_def_id, obj_substs,
ty::empty_builtin_bounds());
ty::mk_uniq(tcx, tr)
}
- ast::SelfRegion(..) | ast::SelfUniq(..) => {
+ ByReferenceExplicitSelfCategory(..) | ByBoxExplicitSelfCategory => {
let transformed_self_ty = *method_ty.fty.sig.inputs.get(0);
match ty::get(transformed_self_ty).sty {
ty::ty_rptr(r, mt) => { // must be SelfRegion
let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id);
match trait_methods.iter().position(|m| {
- m.explicit_self != ast::SelfStatic &&
+ m.explicit_self != ty::StaticExplicitSelfCategory &&
m.ident.name == self.m_name }) {
Some(pos) => {
let method = trait_methods.get(pos).clone();
if self.report_statics == ReportStaticMethods {
// lookup should only be called with ReportStaticMethods if a regular lookup failed
- assert!(relevant_candidates.iter().all(|c| c.method_ty.explicit_self == SelfStatic));
+ assert!(relevant_candidates.iter()
+ .all(|c| {
+ c.method_ty.explicit_self == ty::StaticExplicitSelfCategory
+ }));
self.tcx().sess.fileline_note(self.span,
"found defined static methods, maybe a `self` is missing?");
self.enforce_drop_trait_limitations(candidate);
// static methods should never have gotten this far:
- assert!(candidate.method_ty.explicit_self != SelfStatic);
+ assert!(candidate.method_ty.explicit_self !=
+ ty::StaticExplicitSelfCategory);
// Determine the values for the generic parameters of the method.
// If they were not explicitly supplied, just construct fresh
}
match candidate.method_ty.explicit_self {
- ast::SelfStatic => { // reason (a) above
- span_err!(self.tcx().sess, self.span, E0037,
- "cannot call a method without a receiver through an object");
+ ty::StaticExplicitSelfCategory => { // reason (a) above
+ self.tcx().sess.span_err(
+ self.span,
+ "cannot call a method without a receiver \
+ through an object");
}
- ast::SelfValue(_) | ast::SelfRegion(..) | ast::SelfUniq(_) => {}
+ ty::ByValueExplicitSelfCategory |
+ ty::ByReferenceExplicitSelfCategory(..) |
+ ty::ByBoxExplicitSelfCategory => {}
}
// reason (a) above
self.ty_to_string(rcvr_ty), candidate.repr(self.tcx()));
return match candidate.method_ty.explicit_self {
- SelfStatic => {
+ StaticExplicitSelfCategory => {
debug!("(is relevant?) explicit self is static");
self.report_statics == ReportStaticMethods
}
- SelfValue(_) => {
+ ByValueExplicitSelfCategory => {
debug!("(is relevant?) explicit self is by-value");
match ty::get(rcvr_ty).sty {
ty::ty_uniq(typ) => {
}
}
- SelfRegion(_, m, _) => {
+ ByReferenceExplicitSelfCategory(_, m) => {
debug!("(is relevant?) explicit self is a region");
match ty::get(rcvr_ty).sty {
ty::ty_rptr(_, mt) => {
}
}
- SelfUniq(_) => {
+ ByBoxExplicitSelfCategory => {
debug!("(is relevant?) explicit self is a unique pointer");
match ty::get(rcvr_ty).sty {
ty::ty_uniq(typ) => {
}
}
}
+
+
+
use syntax::ast::{Provided, Required};
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util::local_def;
+use syntax::ast_util::{local_def, PostExpansionMethod};
use syntax::ast_util;
use syntax::attr;
use syntax::codemap::Span;
let method_def_id = local_def(method.id);
let method_ty = ty::method(ccx.tcx, method_def_id);
let method_generics = &method_ty.generics;
- let m_body = ast_util::method_body(&*method);
let param_env = ty::construct_parameter_environment(ccx.tcx,
method_generics,
- m_body.id);
+ method.pe_body().id);
let fty = ty::node_id_to_type(ccx.tcx, method.id);
- check_bare_fn(ccx, ast_util::method_fn_decl(&*method),
- m_body, method.id, fty, param_env);
+ check_bare_fn(ccx, method.pe_fn_decl(), method.pe_body(), method.id, fty, param_env);
}
fn check_impl_methods_against_trait(ccx: &CrateCtxt,
compare_impl_method(ccx.tcx,
&*impl_method_ty,
impl_method.span,
- ast_util::method_body(&**impl_method).id,
+ impl_method.pe_body().id,
&**trait_method_ty,
&impl_trait_ref.substs);
}
for trait_method in trait_methods.iter() {
let is_implemented =
impl_methods.iter().any(
- |m| ast_util::method_ident(&**m).name == trait_method.ident.name);
+ |m| m.pe_ident().name == trait_method.ident.name);
let is_provided =
provided_methods.iter().any(
|m| m.ident.name == trait_method.ident.name);
// inscrutable, particularly for cases where one method has no
// self.
match (&trait_m.explicit_self, &impl_m.explicit_self) {
- (&ast::SelfStatic, &ast::SelfStatic) => {}
- (&ast::SelfStatic, _) => {
- span_err!(tcx.sess, impl_m_span, E0047,
- "method `{}` has a `{}` declaration in the impl, but not in the trait",
- token::get_ident(trait_m.ident),
- pprust::explicit_self_to_string(impl_m.explicit_self));
+ (&ty::StaticExplicitSelfCategory,
+ &ty::StaticExplicitSelfCategory) => {}
+ (&ty::StaticExplicitSelfCategory, _) => {
+ tcx.sess.span_err(
+ impl_m_span,
+ format!("method `{}` has a `{}` declaration in the impl, \
+ but not in the trait",
+ token::get_ident(trait_m.ident),
+ ppaux::explicit_self_category_to_str(
+ &impl_m.explicit_self)).as_slice());
return;
}
- (_, &ast::SelfStatic) => {
- span_err!(tcx.sess, impl_m_span, E0048,
- "method `{}` has a `{}` declaration in the trait, but not in the impl",
- token::get_ident(trait_m.ident),
- pprust::explicit_self_to_string(trait_m.explicit_self));
+ (_, &ty::StaticExplicitSelfCategory) => {
+ tcx.sess.span_err(
+ impl_m_span,
+ format!("method `{}` has a `{}` declaration in the trait, \
+ but not in the impl",
+ token::get_ident(trait_m.ident),
+ ppaux::explicit_self_category_to_str(
+ &trait_m.explicit_self)).as_slice());
return;
}
_ => {
});
}
}
+
kind.repr(rcx.tcx()),
cmt_borrowed.repr(rcx.tcx()));
match cmt_borrowed.cat.clone() {
- mc::cat_deref(base, _, mc::BorrowedPtr(_, r_borrowed)) => {
+ mc::cat_deref(base, _, mc::BorrowedPtr(_, r_borrowed)) |
+ mc::cat_deref(base, _, mc::Implicit(_, r_borrowed)) => {
// References to an upvar `x` are translated to
// `*x`, since that is what happens in the
// underlying machine. We detect such references
continue;
}
- mc::cat_deref(base, _, mc::BorrowedPtr(..)) => {
+ mc::cat_deref(base, _, mc::BorrowedPtr(..)) |
+ mc::cat_deref(base, _, mc::Implicit(..)) => {
match base.cat {
mc::cat_upvar(ref upvar_id, _) => {
// if this is an implicit deref of an
continue;
}
- mc::cat_deref(base, _, mc::BorrowedPtr(..)) => {
+ mc::cat_deref(base, _, mc::BorrowedPtr(..)) |
+ mc::cat_deref(base, _, mc::Implicit(..)) => {
match base.cat {
mc::cat_upvar(ref upvar_id, _) => {
// if this is an implicit deref of an
use middle::ty::{ImplContainer, MethodContainer, TraitContainer};
use middle::ty::{Polytype};
use middle::ty;
+use middle::ty_fold::TypeFolder;
use middle::typeck::astconv::{AstConv, ty_of_arg};
use middle::typeck::astconv::{ast_ty_to_ty};
use middle::typeck::astconv;
+use middle::typeck::infer;
use middle::typeck::rscope::*;
use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
+use middle::typeck;
use util::ppaux;
use util::ppaux::Repr;
use syntax::ast::{TraitTyParamBound, UnboxedFnTyParamBound};
use syntax::ast;
use syntax::ast_map;
-use syntax::ast_util;
-use syntax::ast_util::{local_def, method_ident, split_trait_methods};
+use syntax::ast_util::{local_def, split_trait_methods, PostExpansionMethod};
use syntax::codemap::Span;
use syntax::codemap;
use syntax::owned_slice::OwnedSlice;
&ast::Provided(ref m) => {
ty_method_of_trait_method(
ccx, trait_id, &trait_def.generics,
- &m.id, &ast_util::method_ident(&**m),
- ast_util::method_explicit_self(&**m),
- ast_util::method_generics(&**m),
- &ast_util::method_fn_style(&**m),
- ast_util::method_fn_decl(&**m))
+ &m.id, &m.pe_ident(), m.pe_explicit_self(),
+ m.pe_generics(), &m.pe_fn_style(), m.pe_fn_decl())
}
});
- if ty_method.explicit_self == ast::SelfStatic {
+ if ty_method.explicit_self ==
+ ty::StaticExplicitSelfCategory {
make_static_method_ty(ccx, &*ty_method);
}
m_fn_style: &ast::FnStyle,
m_decl: &ast::FnDecl) -> ty::Method
{
- let trait_self_ty = ty::mk_self_type(this.tcx, local_def(trait_id));
- let fty = astconv::ty_of_method(this, *m_id, *m_fn_style, trait_self_ty,
- *m_explicit_self, m_decl);
- let ty_generics =
- ty_generics_for_fn_or_method(this,
- m_generics,
- (*trait_generics).clone());
+ let trait_self_ty = ty::mk_param(this.tcx,
+ subst::SelfSpace,
+ 0,
+ local_def(trait_id));
+ let ty_generics = ty_generics_for_fn_or_method(
+ this,
+ m_generics,
+ (*trait_generics).clone());
+ let (fty, explicit_self_category) =
+ astconv::ty_of_method(this,
+ *m_id,
+ *m_fn_style,
+ trait_self_ty,
+ *m_explicit_self,
+ m_decl);
ty::Method::new(
*m_ident,
ty_generics,
fty,
- m_explicit_self.node,
+ explicit_self_category,
// assume public, because this is only invoked on trait methods
ast::Public,
local_def(*m_id),
let tcx = ccx.tcx;
let mut seen_methods = HashSet::new();
for m in ms.iter() {
- if !seen_methods.insert(ast_util::method_ident(&**m).repr(tcx)) {
+ if !seen_methods.insert(m.pe_ident().repr(ccx.tcx)) {
tcx.sess.span_err(m.span, "duplicate method in trait impl");
}
rcvr_visibility));
let fty = ty::mk_bare_fn(tcx, mty.fty.clone());
debug!("method {} (id {}) has type {}",
- method_ident(&**m).repr(tcx),
+ m.pe_ident().repr(ccx.tcx),
m.id,
- fty.repr(tcx));
+ fty.repr(ccx.tcx));
tcx.tcache.borrow_mut().insert(
local_def(m.id),
Polytype {
rcvr_visibility: ast::Visibility)
-> ty::Method
{
- let fty = astconv::ty_of_method(ccx, m.id, ast_util::method_fn_style(&*m),
- untransformed_rcvr_ty,
- *ast_util::method_explicit_self(&*m),
- ast_util::method_fn_decl(&*m));
+ let (fty, explicit_self_category) =
+ astconv::ty_of_method(ccx,
+ m.id,
+ m.pe_fn_style(),
+ untransformed_rcvr_ty,
+ *m.pe_explicit_self(),
+ m.pe_fn_decl());
// if the method specifies a visibility, use that, otherwise
// inherit the visibility from the impl (so `foo` in `pub impl
// { fn foo(); }` is public, but private in `priv impl { fn
// foo(); }`).
- let method_vis = ast_util::method_vis(&*m).inherit_from(rcvr_visibility);
+ let method_vis = m.pe_vis().inherit_from(rcvr_visibility);
let m_ty_generics =
- ty_generics_for_fn_or_method(ccx, ast_util::method_generics(&*m),
+ ty_generics_for_fn_or_method(ccx, m.pe_generics(),
(*rcvr_ty_generics).clone());
- ty::Method::new(ast_util::method_ident(&*m),
+ ty::Method::new(m.pe_ident(),
m_ty_generics,
fty,
- ast_util::method_explicit_self(&*m).node,
+ explicit_self_category,
method_vis,
local_def(m.id),
container,
it.vis
};
+ for method in ms.iter() {
+ check_method_self_type(ccx,
+ &BindingRscope::new(method.id),
+ selfty,
+ method.pe_explicit_self())
+ }
+
convert_methods(ccx,
ImplContainer(local_def(it.id)),
ms.as_slice(),
ast::ItemTrait(_, _, _, ref trait_methods) => {
let trait_def = trait_def_of_item(ccx, it);
+ for trait_method in trait_methods.iter() {
+ let self_type = ty::mk_param(ccx.tcx,
+ subst::SelfSpace,
+ 0,
+ local_def(it.id));
+ match *trait_method {
+ ast::Required(ref type_method) => {
+ let rscope = BindingRscope::new(type_method.id);
+ check_method_self_type(ccx,
+ &rscope,
+ self_type,
+ &type_method.explicit_self)
+ }
+ ast::Provided(ref method) => {
+ check_method_self_type(ccx,
+ &BindingRscope::new(method.id),
+ self_type,
+ method.pe_explicit_self())
+ }
+ }
+ }
+
// Run convert_methods on the provided methods.
let (_, provided_methods) =
split_trait_methods(trait_methods.as_slice());
let mut result = base_generics;
for (i, l) in lifetimes.iter().enumerate() {
- result.regions.push(space,
- ty::RegionParameterDef { name: l.name,
- space: space,
- index: i,
- def_id: local_def(l.id) });
+ let def = ty::RegionParameterDef { name: l.name,
+ space: space,
+ index: i,
+ def_id: local_def(l.id) };
+ debug!("ty_generics: def for region param: {}", def);
+ result.regions.push(space, def);
}
for (i, param) in types.iter().enumerate() {
let def = get_or_create_type_parameter_def(ccx, space, param, i);
- debug!("def for param: {}", def.repr(ccx.tcx));
+ debug!("ty_generics: def for type param: {}", def.repr(ccx.tcx));
result.types.push(space, def);
}
subst::Substs::new(types, regions)
}
+
+/// Verifies that the explicit self type of a method matches the impl or
+/// trait.
+fn check_method_self_type<RS:RegionScope>(
+ crate_context: &CrateCtxt,
+ rs: &RS,
+ required_type: ty::t,
+ explicit_self: &ast::ExplicitSelf) {
+ match explicit_self.node {
+ ast::SelfExplicit(ref ast_type, _) => {
+ let typ = crate_context.to_ty(rs, *ast_type);
+ let base_type = match ty::get(typ).sty {
+ ty::ty_rptr(_, tm) => tm.ty,
+ ty::ty_uniq(typ) => typ,
+ _ => typ,
+ };
+ let infcx = infer::new_infer_ctxt(crate_context.tcx);
+ drop(typeck::require_same_types(crate_context.tcx,
+ Some(&infcx),
+ false,
+ explicit_self.span,
+ base_type,
+ required_type,
+ || {
+ format!("mismatched self type: expected `{}`",
+ ppaux::ty_to_string(crate_context.tcx, required_type))
+ }));
+ infcx.resolve_regions_and_report_errors();
+ }
+ _ => {}
+ }
+}
+
b_subst: &subst::Substs)
-> cres<subst::Substs>
{
- let variances = ty::item_variances(self.infcx().tcx, item_def_id);
+ let variances = if self.infcx().tcx.variance_computed.get() {
+ Some(ty::item_variances(self.infcx().tcx, item_def_id))
+ } else {
+ None
+ };
let mut substs = subst::Substs::empty();
for &space in subst::ParamSpace::all().iter() {
let a_regions = a_subst.regions().get_slice(space);
let b_regions = b_subst.regions().get_slice(space);
- let r_variances = variances.regions.get_slice(space);
+
+ let mut invariance = Vec::new();
+ let r_variances = match variances {
+ Some(ref variances) => variances.regions.get_slice(space),
+ None => {
+ for _ in a_regions.iter() {
+ invariance.push(ty::Invariant);
+ }
+ invariance.as_slice()
+ }
+ };
+
let regions = if_ok!(relate_region_params(self,
item_def_id,
r_variances,
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util;
-use syntax::ast_util::name_to_dummy_lifetime;
+use syntax::ast_util::{name_to_dummy_lifetime, PostExpansionMethod};
use syntax::owned_slice::OwnedSlice;
use syntax::codemap;
use syntax::parse::token;
}
}
ast_map::NodeMethod(ref m) => {
- Some((ast_util::method_fn_decl(&**m),
- ast_util::method_generics(&**m),
- ast_util::method_fn_style(&**m),
- ast_util::method_ident(&**m),
- Some(ast_util::method_explicit_self(&**m).node), m.span))
+ Some((m.pe_fn_decl(), m.pe_generics(), m.pe_fn_style(),
+ m.pe_ident(), Some(m.pe_explicit_self().node), m.span))
},
_ => None
},
_ => None
},
ast_map::NodeMethod(m) => {
- taken.push_all(ast_util::method_generics(&*m).lifetimes.as_slice());
+ taken.push_all(m.pe_generics().lifetimes.as_slice());
Some(m.id)
},
_ => None
use middle::ty;
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
-use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound,
- ReLateBound};
-use middle::ty::{ReScope, ReVar, ReSkolemized, BrFresh};
+use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound};
+use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
use middle::typeck::infer::cres;
use middle::typeck::infer::{RegionVariableOrigin, SubregionOrigin, TypeTrace};
use middle::typeck::infer;
use middle::graph;
use middle::graph::{Direction, NodeIndex};
use util::common::indenter;
-use util::ppaux::{Repr};
+use util::ppaux::Repr;
use std::cell::{Cell, RefCell};
use std::uint;
if self.in_snapshot() {
self.undo_log.borrow_mut().push(AddVar(vid));
}
- debug!("created new region variable {:?} with origin {:?}",
+ debug!("created new region variable {} with origin {}",
vid, origin.repr(self.tcx));
return vid;
}
origin.repr(self.tcx));
match (sub, sup) {
+ (ReEarlyBound(..), ReEarlyBound(..)) => {
+ // This case is used only to make sure that explicitly-specified
+ // `Self` types match the real self type in implementations.
+ self.add_constraint(ConstrainRegSubReg(sub, sup), origin);
+ }
(ReEarlyBound(..), _) |
(ReLateBound(..), _) |
(_, ReEarlyBound(..)) |
let terms_cx = determine_parameters_to_be_inferred(tcx, &mut arena, krate);
let constraints_cx = add_constraints_from_crate(terms_cx, krate);
solve_constraints(constraints_cx);
+ tcx.variance_computed.set(true);
}
/**************************************************************************
use middle::subst::{VecPerParamSpace,Subst};
use middle::ty::{ReSkolemized, ReVar};
use middle::ty::{BoundRegion, BrAnon, BrNamed};
-use middle::ty::{BrFresh, ctxt};
+use middle::ty::{ReEarlyBound, BrFresh, ctxt};
use middle::ty::{mt, t, ParamTy};
use middle::ty::{ReFree, ReScope, ReInfer, ReStatic, Region, ReEmpty};
use middle::ty::{ty_bool, ty_char, ty_bot, ty_box, ty_struct, ty_enum};
ReEmpty => { ("the empty lifetime".to_string(), None) }
+ ReEarlyBound(_, _, _, name) => {
+ (format!("{}", token::get_name(name)), None)
+ }
+
// I believe these cases should not occur (except when debugging,
// perhaps)
- ty::ReInfer(_) | ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
+ ty::ReInfer(_) | ty::ReLateBound(..) => {
(format!("lifetime {:?}", region), None)
}
};
}
}
+pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
+ -> &'static str {
+ match *category {
+ ty::StaticExplicitSelfCategory => "static",
+ ty::ByValueExplicitSelfCategory => "self",
+ ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
+ "&mut self"
+ }
+ ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
+ ty::ByBoxExplicitSelfCategory => "Box<self>",
+ }
+}
+
pub fn parameterized(cx: &ctxt,
base: &str,
substs: &subst::Substs,
}
}
}
+
+impl Repr for ty::ExplicitSelfCategory {
+ fn repr(&self, _: &ctxt) -> String {
+ explicit_self_category_to_str(self).to_string()
+ }
+}
+
use syntax;
use syntax::ast;
use syntax::ast_util;
+use syntax::ast_util::PostExpansionMethod;
use syntax::attr;
use syntax::attr::{AttributeMethods, AttrMetaMethods};
use syntax::codemap::Pos;
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub enum Attribute {
Word(String),
List(String, Vec<Attribute> ),
fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct TyParam {
pub name: String,
pub did: ast::DefId,
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub enum TyParamBound {
RegionBound,
TraitBound(Type)
}
// maybe use a Generic enum and use ~[Generic]?
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct Generics {
pub lifetimes: Vec<Lifetime>,
pub type_params: Vec<TyParam>,
impl Clean<Item> for ast::Method {
fn clean(&self) -> Item {
- let fn_decl = ast_util::method_fn_decl(self);
- let inputs = match ast_util::method_explicit_self(self).node {
- ast::SelfStatic => fn_decl.inputs.as_slice(),
- _ => fn_decl.inputs.slice_from(1)
+ let all_inputs = &self.pe_fn_decl().inputs;
+ let inputs = match self.pe_explicit_self().node {
+ ast::SelfStatic => all_inputs.as_slice(),
+ _ => all_inputs.slice_from(1)
};
let decl = FnDecl {
inputs: Arguments {
values: inputs.iter().map(|x| x.clean()).collect(),
},
- output: (fn_decl.output.clean()),
- cf: fn_decl.cf.clean(),
+ output: (self.pe_fn_decl().output.clean()),
+ cf: self.pe_fn_decl().cf.clean(),
attrs: Vec::new()
};
Item {
- name: Some(ast_util::method_ident(self).clean()),
+ name: Some(self.pe_ident().clean()),
attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(),
def_id: ast_util::local_def(self.id),
- visibility: ast_util::method_vis(self).clean(),
+ visibility: self.pe_vis().clean(),
stability: get_stability(ast_util::local_def(self.id)),
inner: MethodItem(Method {
- generics: ast_util::method_generics(self).clean(),
- self_: ast_util::method_explicit_self(self).node.clean(),
- fn_style: ast_util::method_fn_style(self).clone(),
+ generics: self.pe_generics().clean(),
+ self_: self.pe_explicit_self().node.clean(),
+ fn_style: self.pe_fn_style().clone(),
decl: decl,
}),
}
SelfValue,
SelfBorrowed(Option<Lifetime>, Mutability),
SelfOwned,
+ SelfExplicit(Type),
}
impl Clean<SelfTy> for ast::ExplicitSelf_ {
ast::SelfStatic => SelfStatic,
ast::SelfValue(_) => SelfValue,
ast::SelfUniq(_) => SelfOwned,
- ast::SelfRegion(lt, mt, _) => SelfBorrowed(lt.clean(), mt.clean()),
+ ast::SelfRegion(lt, mt, _) => {
+ SelfBorrowed(lt.clean(), mt.clean())
+ }
+ ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean()),
}
}
}
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct ClosureDecl {
pub lifetimes: Vec<Lifetime>,
pub decl: FnDecl,
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct FnDecl {
pub inputs: Arguments,
pub output: Type,
pub attrs: Vec<Attribute>,
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct Arguments {
pub values: Vec<Argument>,
}
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct Argument {
pub type_: Type,
pub name: String,
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub enum RetStyle {
NoReturn,
Return
fn clean(&self) -> Item {
let cx = get_cx();
let (self_, sig) = match self.explicit_self {
- ast::SelfStatic => (ast::SelfStatic.clean(), self.fty.sig.clone()),
+ ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(), self.fty.sig.clone()),
s => {
let sig = ty::FnSig {
inputs: Vec::from_slice(self.fty.sig.inputs.slice_from(1)),
..self.fty.sig.clone()
};
let s = match s {
- ast::SelfRegion(..) => {
- match ty::get(*self.fty.sig.inputs.get(0)).sty {
+ ty::ByReferenceExplicitSelfCategory(..) => {
+ match ty::get(self.fty.sig.inputs[0]).sty {
ty::ty_rptr(r, mt) => {
SelfBorrowed(r.clean(), mt.mutbl.clean())
}
- _ => s.clean(),
+ _ => {
+ // FIXME(pcwalton): This is wrong.
+ SelfStatic
+ }
}
}
- s => s.clean(),
+ _ => {
+ // FIXME(pcwalton): This is wrong.
+ SelfStatic
+ }
};
(s, sig)
}
/// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
/// type out of the AST/ty::ctxt given one of these, if more information is needed. Most importantly
/// it does not preserve mutability or boxes.
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub enum Type {
/// structs/enums/traits (anything that'd be an ast::TyPath)
ResolvedPath {
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct Path {
pub global: bool,
pub segments: Vec<PathSegment>,
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct PathSegment {
pub name: String,
pub lifetimes: Vec<Lifetime>,
}
}
-#[deriving(Clone, Encodable, Decodable)]
+#[deriving(Clone, Encodable, Decodable, PartialEq)]
pub struct BareFunctionDecl {
pub fn_style: ast::FnStyle,
pub generics: Generics,
let loc = current_location_key.get().unwrap();
let cache = cache_key.get().unwrap();
let abs_root = root(&**cache, loc.as_slice());
- let rel_root = match path.segments.get(0).name.as_slice() {
+ let rel_root = match path.segments[0].name.as_slice() {
"self" => Some("./".to_string()),
_ => None,
};
args.push_str(format!("&{}self",
MutableSpace(mtbl)).as_slice());
}
+ clean::SelfExplicit(ref typ) => {
+ args.push_str(format!("self: {}", *typ).as_slice());
+ }
}
for (i, input) in d.inputs.values.iter().enumerate() {
if i > 0 || args.len() > 0 { args.push_str(", "); }
}
mydst.push(format!("{}.{}.js",
remote_item_type.to_static_str(),
- *remote_path.get(remote_path.len() - 1)));
+ remote_path[remote_path.len() - 1]));
let all_implementors = try!(collect(&mydst, krate.name.as_slice(),
"implementors"));
println!("only one input file may be specified");
return 1;
}
- let input = matches.free.get(0).as_slice();
+ let input = matches.free[0].as_slice();
let libs = matches.opt_strs("L").iter().map(|s| Path::new(s.as_slice())).collect();
"invalid markdown file: expecting initial line with `% ...TITLE...`");
return 5;
}
- let title = metadata.get(0).as_slice();
+ let title = metadata[0].as_slice();
reset_headers();
});
if lines.len() >= 1 {
- let mut unindented = vec![ lines.get(0).trim().to_string() ];
+ let mut unindented = vec![ lines[0].trim().to_string() ];
unindented.push_all(lines.tail().iter().map(|&line| {
if line.is_whitespace() {
line.to_string()
## Using Autoserialization
-Create a struct called TestStruct1 and serialize and deserialize it to and from JSON
-using the serialization API, using the derived serialization code.
+Create a struct called `TestStruct` and serialize and deserialize it to and from JSON using the
+serialization API, using the derived serialization code.
```rust
extern crate serialize;
use serialize::json;
-#[deriving(Decodable, Encodable)] //generate Decodable, Encodable impl.
-pub struct TestStruct1 {
+// Automatically generate `Decodable` and `Encodable` trait implementations
+#[deriving(Decodable, Encodable)]
+pub struct TestStruct {
data_int: u8,
data_str: String,
data_vector: Vec<u8>,
}
fn main() {
- let object = TestStruct1
- {data_int: 1, data_str:"toto".to_string(), data_vector:vec![2,3,4,5]};
+ let object = TestStruct {
+ data_int: 1,
+ data_str: "toto".to_string(),
+ data_vector: vec![2,3,4,5],
+ };
// Serialize using `json::encode`
let encoded = json::encode(&object);
// Deserialize using `json::decode`
- let decoded: TestStruct1 = json::decode(encoded.as_slice()).unwrap();
+ let decoded: TestStruct = json::decode(encoded.as_slice()).unwrap();
}
```
-## Using `ToJson`
+## Using the `ToJson` trait
+
+The examples above use the `ToJson` trait to generate the JSON string, which required
+for custom mappings.
+
+### Simple example of `ToJson` usage
+
+```rust
+extern crate serialize;
+use serialize::json::ToJson;
+use serialize::json;
+
+// A custom data structure
+struct ComplexNum {
+ a: f64,
+ b: f64,
+}
+
+// JSON value representation
+impl ToJson for ComplexNum {
+ fn to_json(&self) -> json::Json {
+ json::String(format!("{}+{}i", self.a, self.b))
+ }
+}
-This example uses the `ToJson` trait to generate the JSON string.
+// Only generate `Encodable` trait implementation
+#[deriving(Encodable)]
+pub struct ComplexNumRecord {
+ uid: u8,
+ dsc: String,
+ val: json::Json,
+}
+
+fn main() {
+ let num = ComplexNum { a: 0.0001, b: 12.539 };
+ let data: String = json::encode(&ComplexNumRecord{
+ uid: 1,
+ dsc: "test".to_string(),
+ val: num.to_json(),
+ });
+ println!("data: {}", data);
+ // data: {"uid":1,"dsc":"test","val":"0.0001+12.539j"};
+}
+```
+
+### Verbose example of `ToJson` usage
```rust
+extern crate serialize;
use std::collections::TreeMap;
use serialize::json::ToJson;
use serialize::json;
+// Only generate `Decodable` trait implementation
#[deriving(Decodable)]
-pub struct TestStruct1 {
+pub struct TestStruct {
data_int: u8,
data_str: String,
data_vector: Vec<u8>,
}
-impl ToJson for TestStruct1 {
- fn to_json( &self ) -> json::Json {
+// Specify encoding method manually
+impl ToJson for TestStruct {
+ fn to_json(&self) -> json::Json {
let mut d = TreeMap::new();
+ // All standard types implement `to_json()`, so use it
d.insert("data_int".to_string(), self.data_int.to_json());
d.insert("data_str".to_string(), self.data_str.to_json());
d.insert("data_vector".to_string(), self.data_vector.to_json());
fn main() {
// Serialize using `ToJson`
- let test2 = TestStruct1 {data_int: 1, data_str:"toto".to_string(), data_vector:vec![2,3,4,5]};
- let tjson: json::Json = test2.to_json();
- let json_str: String = tjson.to_string();
+ let input_data = TestStruct {
+ data_int: 1,
+ data_str: "toto".to_string(),
+ data_vector: vec![2,3,4,5],
+ };
+ let json_obj: json::Json = input_data.to_json();
+ let json_str: String = json_obj.to_string();
// Deserialize like before
- let decoded: TestStruct1 = json::decode(json_str.as_slice()).unwrap();
+ let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap();
}
```
/// lower indices are at the bottom of the stack while higher indices are
/// at the top.
pub fn get<'l>(&'l self, idx: uint) -> StackElement<'l> {
- match *self.stack.get(idx) {
+ match self.stack[idx] {
InternalIndex(i) => { Index(i) }
InternalKey(start, size) => {
Key(str::from_utf8(
/// An implementation of a hash set using the underlying representation of a
/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
/// requires that the elements implement the `Eq` and `Hash` traits.
+///
+/// # Example
+///
+/// ```rust
+/// use std::collections::HashSet;
+///
+/// // Type inference lets us omit an explicit type signature (which
+/// // would be `HashSet<&str>` in this example).
+/// let mut books = HashSet::new();
+///
+/// // Add some books.
+/// books.insert("A Dance With Dragons");
+/// books.insert("To Kill a Mockingbird");
+/// books.insert("The Odyssey");
+/// books.insert("The Great Gatsby");
+///
+/// // Check for a specific one.
+/// if !books.contains(&("The Winds of Winter")) {
+/// println!("We have {} books, but The Winds of Winter ain't one.",
+/// books.len());
+/// }
+///
+/// // Remove a book.
+/// books.remove(&"The Odyssey");
+///
+/// // Iterate over everything.
+/// for book in books.iter() {
+/// println!("{}", *book);
+/// }
+/// ```
#[deriving(Clone)]
pub struct HashSet<T, H = RandomSipHasher> {
map: HashMap<T, (), H>
impl<T: Hash + Eq> HashSet<T, RandomSipHasher> {
/// Create an empty HashSet
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let mut set: HashSet<int> = HashSet::new();
+ /// ```
#[inline]
pub fn new() -> HashSet<T, RandomSipHasher> {
HashSet::with_capacity(INITIAL_CAPACITY)
/// Create an empty HashSet with space for at least `n` elements in
/// the hash table.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let mut set: HashSet<int> = HashSet::with_capacity(10);
+ /// ```
#[inline]
pub fn with_capacity(capacity: uint) -> HashSet<T, RandomSipHasher> {
HashSet { map: HashMap::with_capacity(capacity) }
}
/// Reserve space for at least `n` elements in the hash table.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let mut set: HashSet<int> = HashSet::new();
+ /// set.reserve(10);
+ /// ```
pub fn reserve(&mut self, n: uint) {
self.map.reserve(n)
}
/// An iterator visiting all elements in arbitrary order.
/// Iterator element type is &'a T.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let mut set = HashSet::new();
+ /// set.insert("a");
+ /// set.insert("b");
+ ///
+ /// // Will print in an arbitrary order.
+ /// for x in set.iter() {
+ /// println!("{}", x);
+ /// }
+ /// ```
pub fn iter<'a>(&'a self) -> SetItems<'a, T> {
self.map.keys()
}
/// Creates a consuming iterator, that is, one that moves each value out
/// of the set in arbitrary order. The set cannot be used after calling
/// this.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let mut set = HashSet::new();
+ /// set.insert("a".to_string());
+ /// set.insert("b".to_string());
+ ///
+ /// // Not possible to collect to a Vec<String> with a regular `.iter()`.
+ /// let v: Vec<String> = set.move_iter().collect();
+ ///
+ /// // Will print in an arbitrary order.
+ /// for x in v.iter() {
+ /// println!("{}", x);
+ /// }
+ /// ```
pub fn move_iter(self) -> SetMoveItems<T> {
self.map.move_iter().map(|(k, _)| k)
}
- /// Visit the values representing the difference
+ /// Visit the values representing the difference.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
+ /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
+ ///
+ /// // Can be seen as `a - b`.
+ /// for x in a.difference(&b) {
+ /// println!("{}", x); // Print 1
+ /// }
+ ///
+ /// let diff: HashSet<int> = a.difference(&b).map(|&x| x).collect();
+ /// assert_eq!(diff, [1i].iter().map(|&x| x).collect());
+ ///
+ /// // Note that difference is not symmetric,
+ /// // and `b - a` means something else:
+ /// let diff: HashSet<int> = b.difference(&a).map(|&x| x).collect();
+ /// assert_eq!(diff, [4i].iter().map(|&x| x).collect());
+ /// ```
pub fn difference<'a>(&'a self, other: &'a HashSet<T, H>) -> SetAlgebraItems<'a, T, H> {
Repeat::new(other).zip(self.iter())
.filter_map(|(other, elt)| {
})
}
- /// Visit the values representing the symmetric difference
+ /// Visit the values representing the symmetric difference.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
+ /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
+ ///
+ /// // Print 1, 4 in arbitrary order.
+ /// for x in a.symmetric_difference(&b) {
+ /// println!("{}", x);
+ /// }
+ ///
+ /// let diff1: HashSet<int> = a.symmetric_difference(&b).map(|&x| x).collect();
+ /// let diff2: HashSet<int> = b.symmetric_difference(&a).map(|&x| x).collect();
+ ///
+ /// assert_eq!(diff1, diff2);
+ /// assert_eq!(diff1, [1i, 4].iter().map(|&x| x).collect());
+ /// ```
pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, H>)
-> Chain<SetAlgebraItems<'a, T, H>, SetAlgebraItems<'a, T, H>> {
self.difference(other).chain(other.difference(self))
}
- /// Visit the values representing the intersection
+ /// Visit the values representing the intersection.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
+ /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
+ ///
+ /// // Print 2, 3 in arbitrary order.
+ /// for x in a.intersection(&b) {
+ /// println!("{}", x);
+ /// }
+ ///
+ /// let diff: HashSet<int> = a.intersection(&b).map(|&x| x).collect();
+ /// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect());
+ /// ```
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, H>)
-> SetAlgebraItems<'a, T, H> {
Repeat::new(other).zip(self.iter())
})
}
- /// Visit the values representing the union
+ /// Visit the values representing the union.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use std::collections::HashSet;
+ /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
+ /// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
+ ///
+ /// // Print 1, 2, 3, 4 in arbitrary order.
+ /// for x in a.union(&b) {
+ /// println!("{}", x);
+ /// }
+ ///
+ /// let diff: HashSet<int> = a.union(&b).map(|&x| x).collect();
+ /// assert_eq!(diff, [1i, 2, 3, 4].iter().map(|&x| x).collect());
+ /// ```
pub fn union<'a>(&'a self, other: &'a HashSet<T, H>)
-> Chain<SetItems<'a, T>, SetAlgebraItems<'a, T, H>> {
self.iter().chain(other.difference(self))
let mask = self.mask;
let mut pos = self.enqueue_pos.load(Relaxed);
loop {
- let node = self.buffer.get(pos & mask);
+ let node = &self.buffer[pos & mask];
let seq = unsafe { (*node.get()).sequence.load(Acquire) };
let diff: int = seq as int - pos as int;
let mask = self.mask;
let mut pos = self.dequeue_pos.load(Relaxed);
loop {
- let node = self.buffer.get(pos & mask);
+ let node = &self.buffer[pos & mask];
let seq = unsafe { (*node.get()).sequence.load(Acquire) };
let diff: int = seq as int - (pos + 1) as int;
if diff == 0 {
}
// Create waiter nobe, and enqueue ourself to
// be woken up by a signaller.
- wait_end = Some(state.blocked.get(condvar_id).wait_end());
+ wait_end = Some(state.blocked[condvar_id].wait_end());
} else {
out_of_bounds = Some(state.blocked.len());
}
let mut result = false;
self.sem.with(|state| {
if condvar_id < state.blocked.len() {
- result = state.blocked.get(condvar_id).signal();
+ result = state.blocked[condvar_id].signal();
} else {
out_of_bounds = Some(state.blocked.len());
}
/// Function name (not all functions have names)
pub type FnIdent = Option<Ident>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Lifetime {
pub id: NodeId,
pub span: Span,
/// A "Path" is essentially Rust's notion of a name; for instance:
/// std::cmp::PartialEq . It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Path {
pub span: Span,
/// A `::foo` path, is relative to the crate root rather than current
/// A segment of a path: an identifier, an optional lifetime, and a set of
/// types.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct PathSegment {
/// The identifier portion of this path segment.
pub identifier: Ident,
/// typeck::collect::compute_bounds matches these against
/// the "special" built-in traits (see middle::lang_items) and
/// detects Copy, Send and Share.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum TyParamBound {
TraitTyParamBound(TraitRef),
StaticRegionTyParamBound,
OtherRegionTyParamBound(Span) // FIXME -- just here until work for #5723 lands
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct TyParam {
pub ident: Ident,
pub id: NodeId,
/// Represents lifetimes and type parameters attached to a declaration
/// of a function, enum, trait, etc.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Generics {
pub lifetimes: Vec<Lifetime>,
pub ty_params: OwnedSlice<TyParam>,
/// used to drive conditional compilation
pub type CrateConfig = Vec<Gc<MetaItem>> ;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Crate {
pub module: Mod,
pub attrs: Vec<Attribute>,
pub type MetaItem = Spanned<MetaItem_>;
-#[deriving(Clone, Encodable, Decodable, Eq, Hash)]
+#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)]
pub enum MetaItem_ {
MetaWord(InternedString),
MetaList(InternedString, Vec<Gc<MetaItem>>),
}
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Block {
pub view_items: Vec<ViewItem>,
pub stmts: Vec<Gc<Stmt>>,
pub span: Span,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Pat {
pub id: NodeId,
pub node: Pat_,
pub span: Span,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct FieldPat {
pub ident: Ident,
pub pat: Gc<Pat>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum BindingMode {
BindByRef(Mutability),
BindByValue(Mutability),
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Pat_ {
PatWild,
PatWildMulti,
MutImmutable,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum ExprVstore {
/// ~[1, 2, 3, 4]
ExprVstoreUniq,
ExprVstoreMutSlice,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum BinOp {
BiAdd,
BiSub,
BiGt,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum UnOp {
UnBox,
UnUniq,
pub type Stmt = Spanned<Stmt_>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Stmt_ {
/// Could be an item or a local (let) binding:
StmtDecl(Gc<Decl>, NodeId),
/// Where a local declaration came from: either a true `let ... =
/// ...;`, or one desugared from the pattern of a for loop.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum LocalSource {
LocalLet,
LocalFor,
// FIXME (pending discussion of #1697, #2178...): local should really be
// a refinement on pat.
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Local {
pub ty: P<Ty>,
pub pat: Gc<Pat>,
pub type Decl = Spanned<Decl_>;
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Decl_ {
/// A local (let) binding:
DeclLocal(Gc<Local>),
}
/// represents one arm of a 'match'
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Arm {
pub attrs: Vec<Attribute>,
pub pats: Vec<Gc<Pat>>,
pub body: Gc<Expr>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Field {
pub ident: SpannedIdent,
pub expr: Gc<Expr>,
pub type SpannedIdent = Spanned<Ident>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum BlockCheckMode {
DefaultBlock,
UnsafeBlock(UnsafeSource),
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum UnsafeSource {
CompilerGenerated,
UserProvided,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Expr {
pub id: NodeId,
pub node: Expr_,
pub span: Span,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Expr_ {
ExprVstore(Gc<Expr>, ExprVstore),
/// First expr is the place; second expr is the value.
/// makes any real sense. You could write them elsewhere but nothing
/// else knows what to do with them, so you'll probably get a syntax
/// error.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
#[doc="For macro invocations; parsing is delegated to the macro"]
pub enum TokenTree {
/// A single token
// macro system. Congratulations.
pub type Matcher = Spanned<Matcher_>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Matcher_ {
/// Match one token
MatchTok(::parse::token::Token),
/// is being invoked, and the vector of token-trees contains the source
/// of the macro invocation.
/// There's only one flavor, now, so this could presumably be simplified.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Mac_ {
// NB: the additional ident for a macro_rules-style macro is actually
// stored in the enclosing item. Oog.
// NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct MutTy {
pub ty: P<Ty>,
pub mutbl: Mutability,
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct TypeField {
pub ident: Ident,
pub mt: MutTy,
/// Represents a required method in a trait declaration,
/// one without a default implementation
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct TypeMethod {
pub ident: Ident,
pub attrs: Vec<Attribute>,
/// a default implementation A trait method is either required (meaning it
/// doesn't have an implementation, just a signature) or provided (meaning it
/// has a default implementation).
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum TraitMethod {
Required(TypeMethod),
Provided(Gc<Method>),
}
// NB PartialEq method appears below.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Ty {
pub id: NodeId,
pub node: Ty_,
}
/// Not represented directly in the AST, referred to by name through a ty_path.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum PrimTy {
TyInt(IntTy),
TyUint(UintTy),
}
/// Represents the type of a closure
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ClosureTy {
pub lifetimes: Vec<Lifetime>,
pub fn_style: FnStyle,
pub bounds: Option<OwnedSlice<TyParamBound>>,
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct BareFnTy {
pub fn_style: FnStyle,
pub abi: Abi,
pub decl: P<FnDecl>
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct UnboxedFnTy {
pub decl: P<FnDecl>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Ty_ {
TyNil,
TyBot, /* bottom type */
TyInfer,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum AsmDialect {
AsmAtt,
AsmIntel
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct InlineAsm {
pub asm: InternedString,
pub asm_str_style: StrStyle,
}
/// represents an argument in a function header
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Arg {
pub ty: P<Ty>,
pub pat: Gc<Pat>,
}
/// represents the header (not the body) of a function declaration
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct FnDecl {
pub inputs: Vec<Arg>,
pub output: P<Ty>,
}
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum RetStyle {
/// Functions with return type ! that always
/// raise an error or exit (i.e. never return to the caller)
}
/// Represents the kind of 'self' associated with a method
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum ExplicitSelf_ {
/// No self
SelfStatic,
- /// `self
+ /// `self`
SelfValue(Ident),
/// `&'lt self`, `&'lt mut self`
SelfRegion(Option<Lifetime>, Mutability, Ident),
/// `~self`
- SelfUniq(Ident)
+ SelfUniq(Ident),
+ /// `self: TYPE`
+ SelfExplicit(P<Ty>, Ident),
}
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Method {
pub attrs: Vec<Attribute>,
pub id: NodeId,
pub node: Method_
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Method_ {
/// Represents a method declaration
MethDecl(Ident, Generics, ExplicitSelf, FnStyle, P<FnDecl>, P<Block>, Visibility),
MethMac(Mac),
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Mod {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
pub items: Vec<Gc<Item>>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ForeignMod {
pub abi: Abi,
pub view_items: Vec<ViewItem>,
pub items: Vec<Gc<ForeignItem>>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct VariantArg {
pub ty: P<Ty>,
pub id: NodeId,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum VariantKind {
TupleVariantKind(Vec<VariantArg>),
StructVariantKind(Gc<StructDef>),
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct EnumDef {
pub variants: Vec<P<Variant>>,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Variant_ {
pub name: Ident,
pub attrs: Vec<Attribute>,
pub type Variant = Spanned<Variant_>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct PathListIdent_ {
pub name: Ident,
pub id: NodeId,
pub type ViewPath = Spanned<ViewPath_>;
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum ViewPath_ {
/// `quux = foo::bar::baz`
ViewPathList(Path, Vec<PathListIdent> , NodeId)
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ViewItem {
pub node: ViewItem_,
pub attrs: Vec<Attribute>,
pub span: Span,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum ViewItem_ {
/// Ident: name used to refer to this crate in the code
/// optional (InternedString,StrStyle): if present, this is a location
/// Distinguishes between Attributes that decorate items and Attributes that
/// are contained as statements within items. These two cases need to be
/// distinguished for pretty-printing.
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum AttrStyle {
AttrOuter,
AttrInner,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct AttrId(pub uint);
/// Doc-comments are promoted to attributes that have is_sugared_doc = true
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Attribute_ {
pub id: AttrId,
pub style: AttrStyle,
/// that the ref_id is for. The impl_id maps to the "self type" of this impl.
/// If this impl is an ItemImpl, the impl_id is redundant (it could be the
/// same as the impl's node id).
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct TraitRef {
pub path: Path,
pub ref_id: NodeId,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Visibility {
Public,
Inherited,
}
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct StructField_ {
pub kind: StructFieldKind,
pub id: NodeId,
pub type StructField = Spanned<StructField_>;
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum StructFieldKind {
NamedField(Ident, Visibility),
/// Element of a tuple-like struct
}
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct StructDef {
/// Fields, not including ctor
pub fields: Vec<StructField>,
FIXME (#3300): Should allow items to be anonymous. Right now
we just use dummy names for anon items.
*/
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct Item {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub span: Span,
}
-#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Item_ {
ItemStatic(P<Ty>, Mutability, Gc<Expr>),
ItemFn(P<FnDecl>, FnStyle, Abi, Generics, P<Block>),
ItemMac(Mac),
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub struct ForeignItem {
pub ident: Ident,
pub attrs: Vec<Attribute>,
pub vis: Visibility,
}
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum ForeignItem_ {
ForeignItemFn(P<FnDecl>, Generics),
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
/// The data we save and restore about an inlined item or method. This is not
/// part of the AST that we parse from a file, but it becomes part of the tree
/// that we trans.
-#[deriving(PartialEq, Eq, Encodable, Decodable, Hash)]
+#[deriving(PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum InlinedItem {
IIItem(Gc<Item>),
IIMethod(DefId /* impl id */, bool /* is provided */, Gc<Method>),
use ast;
use ast_map::{Node};
use ast_map;
-use ast_util;
+use ast_util::PostExpansionMethod;
use codemap::Span;
use visit;
pub fn body<'a>(&'a self) -> P<Block> {
self.handle(|i: ItemFnParts| i.body,
- |m: &'a ast::Method| ast_util::method_body(m),
+ |m: &'a ast::Method| m.pe_body(),
|c: ClosureParts| c.body)
}
pub fn decl<'a>(&'a self) -> P<FnDecl> {
self.handle(|i: ItemFnParts| i.decl,
- |m: &'a ast::Method| ast_util::method_fn_decl(m),
+ |m: &'a ast::Method| m.pe_fn_decl(),
|c: ClosureParts| c.decl)
}
visit::FkFnBlock
};
let method = |m: &'a ast::Method| {
- visit::FkMethod(ast_util::method_ident(m), ast_util::method_generics(m), m)
+ visit::FkMethod(m.pe_ident(), m.pe_generics(), m)
};
self.handle(item, method, closure)
}
inline == InlineNever || inline == InlineNone
}
-
/// Macro invocations are guaranteed not to occur after expansion is complete.
-/// extracting fields of a method requires a dynamic check to make sure that it's
-/// not a macro invocation, though this check is guaranteed to succeed, assuming
+/// Extracting fields of a method requires a dynamic check to make sure that it's
+/// not a macro invocation. This check is guaranteed to succeed, assuming
/// that the invocations are indeed gone.
-macro_rules! method_field_extractor {
- ($fn_name:ident, $field_ty:ty, $field_pat:pat, $result:ident) => {
- /// Returns the ident of a Method. To be used after expansion is complete
- pub fn $fn_name<'a>(method: &'a ast::Method) -> $field_ty {
- match method.node {
+pub trait PostExpansionMethod {
+ fn pe_ident(&self) -> ast::Ident;
+ fn pe_generics<'a>(&'a self) -> &'a ast::Generics;
+ fn pe_explicit_self<'a>(&'a self) -> &'a ast::ExplicitSelf;
+ fn pe_fn_style(&self) -> ast::FnStyle;
+ fn pe_fn_decl(&self) -> P<ast::FnDecl>;
+ fn pe_body(&self) -> P<ast::Block>;
+ fn pe_vis(&self) -> ast::Visibility;
+}
+
+
+/// can't use the standard cfg(stage0) tricks here, because the error occurs in
+/// parsing, before cfg gets a chance to save the day. (yes, interleaved parsing
+/// / expansion / configuring would solve this problem...)
+
+// NOTE: remove after next snapshot
+/// to be more specific: after a snapshot, swap out the "PRE" stuff, and
+// swap in the "POST" stuff.
+
+/// PRE
+macro_rules! mf_method_body{
+ ($slf:ident, $field_pat:pat, $result:ident) => {
+ match $slf.node {
+ $field_pat => $result,
+ MethMac(_) => {
+ fail!("expected an AST without macro invocations");
+ }
+ }
+ }
+}
+
+/// POST
+/*
+#[cfg(not(stage0))]
+macro_rules! mf_method{
+ ($meth_name:ident, $field_ty:ty, $field_pat:pat, $result:ident) => {
+ fn $meth_name<'a>(&'a self) -> $field_ty {
+ match self.node {
$field_pat => $result,
MethMac(_) => {
fail!("expected an AST without macro invocations");
}
}
}
+}*/
+
+
+// PRE
+impl PostExpansionMethod for Method {
+ fn pe_ident(&self) -> ast::Ident {
+ mf_method_body!(self,MethDecl(ident,_,_,_,_,_,_),ident)
+ }
+ fn pe_generics<'a>(&'a self) -> &'a ast::Generics {
+ mf_method_body!(self,MethDecl(_,ref generics,_,_,_,_,_),generics)
+ }
+ fn pe_explicit_self<'a>(&'a self) -> &'a ast::ExplicitSelf {
+ mf_method_body!(self,MethDecl(_,_,ref explicit_self,_,_,_,_),explicit_self)
+ }
+ fn pe_fn_style(&self) -> ast::FnStyle{
+ mf_method_body!(self,MethDecl(_,_,_,fn_style,_,_,_),fn_style)
+ }
+ fn pe_fn_decl(&self) -> P<ast::FnDecl> {
+ mf_method_body!(self,MethDecl(_,_,_,_,decl,_,_),decl)
+ }
+ fn pe_body(&self) -> P<ast::Block> {
+ mf_method_body!(self,MethDecl(_,_,_,_,_,body,_),body)
+ }
+ fn pe_vis(&self) -> ast::Visibility {
+ mf_method_body!(self,MethDecl(_,_,_,_,_,_,vis),vis)
+ }
}
-// Note: this is unhygienic in the lifetime 'a. In order to fix this, we'd have to
-// add :lifetime as a macro argument type, so that the 'a could be supplied by the macro
-// invocation.
-pub method_field_extractor!(method_ident,ast::Ident,MethDecl(ident,_,_,_,_,_,_),ident)
-pub method_field_extractor!(method_generics,&'a ast::Generics,
- MethDecl(_,ref generics,_,_,_,_,_),generics)
-pub method_field_extractor!(method_explicit_self,&'a ast::ExplicitSelf,
- MethDecl(_,_,ref explicit_self,_,_,_,_),explicit_self)
-pub method_field_extractor!(method_fn_style,ast::FnStyle,MethDecl(_,_,_,fn_style,_,_,_),fn_style)
-pub method_field_extractor!(method_fn_decl,P<ast::FnDecl>,MethDecl(_,_,_,_,decl,_,_),decl)
-pub method_field_extractor!(method_body,P<ast::Block>,MethDecl(_,_,_,_,_,body,_),body)
-pub method_field_extractor!(method_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,vis),vis)
+// POST
+/*
+#[cfg(not(stage0))]
+impl PostExpansionMethod for Method {
+ mf_method!(pe_ident,ast::Ident,MethDecl(ident,_,_,_,_,_,_),ident)
+ mf_method!(pe_generics,&'a ast::Generics,
+ MethDecl(_,ref generics,_,_,_,_,_),generics)
+ mf_method!(pe_explicit_self,&'a ast::ExplicitSelf,
+ MethDecl(_,_,ref explicit_self,_,_,_,_),explicit_self)
+ mf_method!(pe_fn_style,ast::FnStyle,MethDecl(_,_,_,fn_style,_,_,_),fn_style)
+ mf_method!(pe_fn_decl,P<ast::FnDecl>,MethDecl(_,_,_,_,decl,_,_),decl)
+ mf_method!(pe_body,P<ast::Block>,MethDecl(_,_,_,_,_,body,_),body)
+ mf_method!(pe_vis,ast::Visibility,MethDecl(_,_,_,_,_,_,vis),vis)
+}
+*/
#[cfg(test)]
mod test {
.iter().map(ident_to_segment).collect::<Vec<PathSegment>>().as_slice()));
}
}
-
/// The types of pointers
pub enum PtrTy<'a> {
- /// ~
- Send,
/// &'lifetime mut
Borrowed(Option<&'a str>, ast::Mutability),
}
Ptr(ref ty, ref ptr) => {
let raw_ty = ty.to_ty(cx, span, self_ty, self_generics);
match *ptr {
- Send => {
- cx.ty_uniq(span, raw_ty)
- }
Borrowed(ref lt, mutbl) => {
let lt = mk_lifetime(cx, span, lt);
cx.ty_rptr(span, raw_ty, lt, mutbl)
let self_ty = respan(
span,
match *ptr {
- Send => ast::SelfUniq(special_idents::self_),
Borrowed(ref lt, mutbl) => {
let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name));
ast::SelfRegion(lt, mutbl, special_idents::self_)
SelfRegion(ref lifetime, m, id) => {
SelfRegion(fold_opt_lifetime(lifetime, self), m, id)
}
+ SelfExplicit(ref typ, id) => SelfExplicit(self.fold_ty(*typ), id),
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::fmt;
use std::default::Default;
use std::hash;
use std::{mem, raw, ptr, slice};
len: uint,
}
+impl<T:fmt::Show> fmt::Show for OwnedSlice<T> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ try!("OwnedSlice {{".fmt(fmt));
+ for i in self.iter() {
+ try!(i.fmt(fmt));
+ }
+ try!("}}".fmt(fmt));
+ Ok(())
+ }
+}
+
#[unsafe_destructor]
impl<T> Drop for OwnedSlice<T> {
fn drop(&mut self) {
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
use ast::{StructVariantKind, BiSub};
use ast::StrStyle;
-use ast::{SelfRegion, SelfStatic, SelfUniq, SelfValue};
+use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfUniq, SelfValue};
use ast::{TokenTree, TraitMethod, TraitRef, TTDelim, TTSeq, TTTok};
use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox};
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
}
}
token::IDENT(..) if self.is_self_ident() => {
- SelfValue(self.expect_self_ident())
+ let self_ident = self.expect_self_ident();
+
+ // Determine whether this is the fully explicit form, `self:
+ // TYPE`.
+ if self.eat(&token::COLON) {
+ SelfExplicit(self.parse_ty(false), self_ident)
+ } else {
+ SelfValue(self_ident)
+ }
}
token::BINOP(token::STAR) => {
// Possibly "*self" or "*mut self" -- not supported. Try to avoid
self.bump();
let _mutability = if Parser::token_is_mutability(&self.token) {
self.parse_mutability()
- } else { MutImmutable };
+ } else {
+ MutImmutable
+ };
if self.is_self_ident() {
let span = self.span;
self.span_err(span, "cannot pass self by unsafe pointer");
_ if Parser::token_is_mutability(&self.token) &&
self.look_ahead(1, |t| token::is_keyword(keywords::Self, t)) => {
mutbl_self = self.parse_mutability();
- SelfValue(self.expect_self_ident())
+ let self_ident = self.expect_self_ident();
+
+ // Determine whether this is the fully explicit form, `self:
+ // TYPE`.
+ if self.eat(&token::COLON) {
+ SelfExplicit(self.parse_ty(false), self_ident)
+ } else {
+ SelfValue(self_ident)
+ }
}
_ if Parser::token_is_mutability(&self.token) &&
self.look_ahead(1, |t| *t == token::TILDE) &&
}
SelfValue(id) => parse_remaining_arguments!(id),
SelfRegion(_,_,id) => parse_remaining_arguments!(id),
- SelfUniq(id) => parse_remaining_arguments!(id)
-
+ SelfUniq(id) => parse_remaining_arguments!(id),
+ SelfExplicit(_,id) => parse_remaining_arguments!(id),
};
try!(self.print_mutability(m));
try!(word(&mut self.s, "self"));
}
+ ast::SelfExplicit(ref typ, _) => {
+ try!(word(&mut self.s, "self"));
+ try!(self.word_space(":"));
+ try!(self.print_type(*typ));
+ }
}
return Ok(true);
}
SelfRegion(ref lifetime, _, _) => {
visitor.visit_opt_lifetime_ref(explicit_self.span, lifetime, env)
}
+ SelfExplicit(ref typ, _) => visitor.visit_ty(*typ, env.clone()),
}
}
assert!(!s.is_empty(), "string conversion produced empty result");
match op {
FormatDigit => {
- if flags.space && !(*s.get(0) == '-' as u8 ||
- *s.get(0) == '+' as u8) {
+ if flags.space && !(s[0] == '-' as u8 ||
+ s[0] == '+' as u8) {
s.unshift(' ' as u8);
}
}
FormatOctal => {
- if flags.alternate && *s.get(0) != '0' as u8 {
+ if flags.alternate && s[0] != '0' as u8 {
s.unshift('0' as u8);
}
}
if matches.opt_present("h") { usage(args[0].as_slice()); return None; }
let filter = if matches.free.len() > 0 {
- let s = matches.free.get(0).as_slice();
+ let s = matches.free[0].as_slice();
match Regex::new(s) {
Ok(re) => Some(re),
Err(e) => return Some(Err(format!("could not parse /{}/: {}", s, e)))
// This inner loop applies `hi`/`lo` summation to each
// partial so that the list of partial sums remains exact.
for i in range(0, partials.len()) {
- let mut y = *partials.get(i);
+ let mut y = partials[i];
if num::abs(x) < num::abs(y) {
mem::swap(&mut x, &mut y);
}
match group_lens.len() {
// Single group, no hyphens
1 => {
- if *group_lens.get(0) != 32 {
- return Err(ErrorInvalidLength(*group_lens.get(0)));
+ if group_lens[0] != 32 {
+ return Err(ErrorInvalidLength(group_lens[0]));
}
},
// Five groups, hyphens in between each
// ignore-stage1
// ignore-tidy-linelength
// ignore-android
+// ignore-cross-compile gives a different error message
#![feature(phase)]
#[phase(plugin)] extern crate rlib_crate_test;
--- /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.
+
+struct MyVec<T> {
+ data: Vec<T>,
+}
+
+impl<T> Index<uint, T> for MyVec<T> {
+ fn index<'a>(&'a self, &i: &uint) -> &'a T {
+ self.data.get(i)
+ }
+}
+
+fn main() {
+ let v = MyVec { data: vec!(box 1i, box 2, box 3) };
+ let good = &v[0]; // Shouldn't fail here
+ let bad = v[0];
+ //~^ ERROR cannot move out of dereference (dereference is implicit, due to indexing)
+}
x: 1,
};
s[2] = 20;
- //~^ ERROR cannot assign to immutable indexed content
+ //~^ ERROR cannot assign to immutable dereference (dereference is implicit, due to indexing)
}
--- /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.
+
+struct Foo<'a,'b> {
+ x: &'a int,
+ y: &'b int,
+}
+
+impl<'a,'b> Foo<'a,'b> {
+ // The number of errors is related to the way invariance works.
+ fn bar(self: Foo<'b,'a>) {}
+ //~^ ERROR mismatched types: expected `Foo<'a,'b>` but found `Foo<'b,'a>`
+ //~^^ ERROR mismatched types: expected `Foo<'a,'b>` but found `Foo<'b,'a>`
+ //~^^^ ERROR mismatched types: expected `Foo<'b,'a>` but found `Foo<'a,'b>`
+ //~^^^^ ERROR mismatched types: expected `Foo<'b,'a>` but found `Foo<'a,'b>`
+}
+
+fn main() {}
+
// error-pattern: type `&Foo` does not implement any method in scope named `foo`
trait Foo {
- fn foo(~self);
+ fn foo(self: Box<Self>);
}
impl Foo for int {
- fn foo(~self) { }
+ fn foo(self: Box<int>) { }
}
fn main() {
struct Foo;
impl Foo {
fn foo(mut self) {} //~ ERROR: variable does not need to be mutable
- fn bar(mut ~self) {} //~ ERROR: variable does not need to be mutable
+ fn bar(mut self: Box<Foo>) {} //~ ERROR: variable does not need to be mutable
}
fn main() {}
fn borrowed(&self);
fn borrowed_mut(&mut self);
- fn owned(~self);
+ fn owned(self: Box<Self>);
}
fn borrowed_receiver(x: &Foo) {
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <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 std::owned::Box;
+
+struct Foo {
+ f: int,
+}
+
+impl Foo {
+ fn foo(self: int, x: int) -> int { //~ ERROR mismatched self type
+//~^ ERROR not a valid type for `self`
+ self.f + x
+ }
+}
+
+struct Bar<T> {
+ f: T,
+}
+
+impl<T> Bar<T> {
+ fn foo(self: Bar<int>, x: int) -> int { //~ ERROR mismatched self type
+//~^ ERROR not a valid type for `self`
+ x
+ }
+ fn bar(self: &Bar<uint>, x: int) -> int { //~ ERROR mismatched self type
+//~^ ERROR not a valid type for `self`
+ x
+ }
+}
+
+fn main() {
+ let foo = box Foo {
+ f: 1,
+ };
+ println!("{}", foo.foo(2));
+ let bar = box Bar {
+ f: 1,
+ };
+ println!("{} {}", bar.foo(2), bar.bar(2));
+}
+
--- /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.
+
+
+
+// Regression test for issue #15557
+
+#![allow(dead_code)]
+struct AReg1<'a>(&'a u32);
+
+impl<'a> Drop for AReg1<'a> {
+//~^ ERROR: cannot implement a destructor on a structure with type parameters
+ fn drop(&mut self) {}
+}
+
+fn main() {}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print f64
// gdb-check:$14 = 3.5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+// lldb-command:print b
+// lldb-check:[...]$0 = false
+// lldb-command:print i
+// lldb-check:[...]$1 = -1
+
+// NOTE: LLDB does not support 32bit chars
+// d ebugger:print (uint)(c)
+// c heck:$3 = 97
+
+// lldb-command:print i8
+// lldb-check:[...]$2 = 'D'
+// lldb-command:print i16
+// lldb-check:[...]$3 = -16
+// lldb-command:print i32
+// lldb-check:[...]$4 = -32
+// lldb-command:print i64
+// lldb-check:[...]$5 = -64
+// lldb-command:print u
+// lldb-check:[...]$6 = 1
+// lldb-command:print u8
+// lldb-check:[...]$7 = 'd'
+// lldb-command:print u16
+// lldb-check:[...]$8 = 16
+// lldb-command:print u32
+// lldb-check:[...]$9 = 32
+// lldb-command:print u64
+// lldb-check:[...]$10 = 64
+// lldb-command:print f32
+// lldb-check:[...]$11 = 2.5
+// lldb-command:print f64
+// lldb-check:[...]$12 = 3.5
+
#![allow(unused_variable)]
fn main() {
let u64: u64 = 64;
let f32: f32 = 2.5;
let f64: f64 = 3.5;
- _zzz();
+ _zzz(); // #break
}
fn _zzz() {()}
// its numerical value.
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *f64_ref
// gdb-check:$14 = 3.5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+// lldb-command:print *bool_ref
+// lldb-check:[...]$0 = true
+
+// lldb-command:print *int_ref
+// lldb-check:[...]$1 = -1
+
+// NOTE: lldb doesn't support 32bit chars at the moment
+// d ebugger:print *char_ref
+// c heck:[...]$x = 97
+
+// lldb-command:print *i8_ref
+// lldb-check:[...]$2 = 'D'
+
+// lldb-command:print *i16_ref
+// lldb-check:[...]$3 = -16
+
+// lldb-command:print *i32_ref
+// lldb-check:[...]$4 = -32
+
+// lldb-command:print *i64_ref
+// lldb-check:[...]$5 = -64
+
+// lldb-command:print *uint_ref
+// lldb-check:[...]$6 = 1
+
+// lldb-command:print *u8_ref
+// lldb-check:[...]$7 = 'd'
+
+// lldb-command:print *u16_ref
+// lldb-check:[...]$8 = 16
+
+// lldb-command:print *u32_ref
+// lldb-check:[...]$9 = 32
+
+// lldb-command:print *u64_ref
+// lldb-check:[...]$10 = 64
+
+// lldb-command:print *f32_ref
+// lldb-check:[...]$11 = 2.5
+
+// lldb-command:print *f64_ref
+// lldb-check:[...]$12 = 3.5
+
#![allow(unused_variable)]
fn main() {
let f64_val: f64 = 3.5;
let f64_ref: &f64 = &f64_val;
- zzz();
+
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *the_c_ref
// gdb-check:$3 = TheC
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *the_a_ref
+// lldb-check:[...]$0 = TheA
+
+// lldb-command:print *the_b_ref
+// lldb-check:[...]$1 = TheB
+
+// lldb-command:print *the_c_ref
+// lldb-check:[...]$2 = TheC
+
#![allow(unused_variable)]
enum ABC { TheA, TheB, TheC }
let the_c = TheC;
let the_c_ref: &ABC = &the_c;
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *univariant_ref
// gdb-check:$3 = {{4820353753753434}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *the_a_ref
+// lldb-check:[...]$0 = TheA { x: 0, y: 8970181431921507452 }
+// lldb-command:print *the_b_ref
+// lldb-check:[...]$1 = TheB(0, 286331153, 286331153)
+// lldb-command:print *univariant_ref
+// lldb-check:[...]$2 = TheOnlyCase(4820353753753434)
+
#![allow(unused_variable)]
#![feature(struct_variant)]
let univariant = TheOnlyCase(4820353753753434);
let univariant_ref: &Univariant = &univariant;
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// its numerical value.
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *f64_ref
// gdb-check:$14 = 3.5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:type format add -f decimal char
+// lldb-command:type format add -f decimal 'unsigned char'
+// lldb-command:run
+
+// lldb-command:print *bool_ref
+// lldb-check:[...]$0 = true
+
+// lldb-command:print *int_ref
+// lldb-check:[...]$1 = -1
+
+// LLDB can't handle 32bit chars yet
+// d ebugger:print *char_ref
+// c heck:[...]$x = 97
+
+// lldb-command:print *i8_ref
+// lldb-check:[...]$2 = 68
+
+// lldb-command:print *i16_ref
+// lldb-check:[...]$3 = -16
+
+// lldb-command:print *i32_ref
+// lldb-check:[...]$4 = -32
+
+// lldb-command:print *i64_ref
+// lldb-check:[...]$5 = -64
+
+// lldb-command:print *uint_ref
+// lldb-check:[...]$6 = 1
+
+// lldb-command:print *u8_ref
+// lldb-check:[...]$7 = 100
+
+// lldb-command:print *u16_ref
+// lldb-check:[...]$8 = 16
+
+// lldb-command:print *u32_ref
+// lldb-check:[...]$9 = 32
+
+// lldb-command:print *u64_ref
+// lldb-check:[...]$10 = 64
+
+// lldb-command:print *f32_ref
+// lldb-check:[...]$11 = 2.5
+
+// lldb-command:print *f64_ref
+// lldb-check:[...]$12 = 3.5
+
#![allow(unused_variable)]
use std::gc::{Gc, GC};
let f64_box: Gc<f64> = box(GC) 3.5;
let f64_ref: &f64 = f64_box;
- zzz();
+
+ zzz(); // #break
}
fn zzz() {()}
// except according to those terms.
// ignore-android: FIXME(#10381)
-
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *unique_val_interior_ref_2
// gdb-check:$10 = 26.5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *stack_val_ref
+// lldb-check:[...]$0 = SomeStruct { x: 10, y: 23.5 }
+
+// lldb-command:print *stack_val_interior_ref_1
+// lldb-check:[...]$1 = 10
+
+// lldb-command:print *stack_val_interior_ref_2
+// lldb-check:[...]$2 = 23.5
+
+// lldb-command:print *ref_to_unnamed
+// lldb-check:[...]$3 = SomeStruct { x: 11, y: 24.5 }
+
+// lldb-command:print *managed_val_ref
+// lldb-check:[...]$4 = SomeStruct { x: 12, y: 25.5 }
+
+// lldb-command:print *managed_val_interior_ref_1
+// lldb-check:[...]$5 = 12
+
+// lldb-command:print *managed_val_interior_ref_2
+// lldb-check:[...]$6 = 25.5
+
+// lldb-command:print *unique_val_ref
+// lldb-check:[...]$7 = SomeStruct { x: 13, y: 26.5 }
+
+// lldb-command:print *unique_val_interior_ref_1
+// lldb-check:[...]$8 = 13
+
+// lldb-command:print *unique_val_interior_ref_2
+// lldb-check:[...]$9 = 26.5
+
#![feature(managed_boxes)]
#![allow(unused_variable)]
let unique_val_interior_ref_1: &int = &unique_val.x;
let unique_val_interior_ref_2: &f64 = &unique_val.y;
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
#![feature(managed_boxes)]
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *unique_val_ref
// gdb-check:$4 = {-17, -22}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *stack_val_ref
+// lldb-check:[...]$0 = (-14, -19)
+
+// lldb-command:print *ref_to_unnamed
+// lldb-check:[...]$1 = (-15, -20)
+
+// lldb-command:print *managed_val_ref
+// lldb-check:[...]$2 = (-16, -21)
+
+// lldb-command:print *unique_val_ref
+// lldb-check:[...]$3 = (-17, -22)
+
+
#![allow(unused_variable)]
use std::gc::{Gc, GC};
let unique_val: Box<(i16, f32)> = box() (-17, -22f32);
let unique_val_ref: &(i16, f32) = unique_val;
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// its numerical value.
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *f64_ref
// gdb-check:$14 = 3.5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:type format add -f decimal char
+// lldb-command:type format add -f decimal 'unsigned char'
+// lldb-command:run
+
+// lldb-command:print *bool_ref
+// lldb-check:[...]$0 = true
+
+// lldb-command:print *int_ref
+// lldb-check:[...]$1 = -1
+
+// d ebugger:print *char_ref
+// c heck:[...]$3 = 97
+
+// lldb-command:print *i8_ref
+// lldb-check:[...]$2 = 68
+
+// lldb-command:print *i16_ref
+// lldb-check:[...]$3 = -16
+
+// lldb-command:print *i32_ref
+// lldb-check:[...]$4 = -32
+
+// lldb-command:print *i64_ref
+// lldb-check:[...]$5 = -64
+
+// lldb-command:print *uint_ref
+// lldb-check:[...]$6 = 1
+
+// lldb-command:print *u8_ref
+// lldb-check:[...]$7 = 100
+
+// lldb-command:print *u16_ref
+// lldb-check:[...]$8 = 16
+
+// lldb-command:print *u32_ref
+// lldb-check:[...]$9 = 32
+
+// lldb-command:print *u64_ref
+// lldb-check:[...]$10 = 64
+
+// lldb-command:print *f32_ref
+// lldb-check:[...]$11 = 2.5
+
+// lldb-command:print *f64_ref
+// lldb-check:[...]$12 = 3.5
+
#![allow(unused_variable)]
let f64_box: Box<f64> = box 3.5;
let f64_ref: &f64 = f64_box;
- zzz();
+
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print d->val
// gdb-check:$4 = false
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+// lldb-command:print *a
+// lldb-check:[...]$0 = 1
+// lldb-command:print *b
+// lldb-check:[...]$1 = (2, 3.5)
+// lldb-command:print c->val
+// lldb-check:[...]$2 = 4
+// lldb-command:print d->val
+// lldb-check:[...]$3 = false
+
#![feature(managed_boxes)]
#![allow(unused_variable)]
let b = box() (2i, 3.5f64);
let c = box(GC) 4i;
let d = box(GC) false;
- _zzz();
+
+ zzz(); // #break
}
-fn _zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print managed_dtor->val
// gdb-check:$4 = {x = 33, y = 333, z = 3333, w = 33333}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *unique
+// lldb-check:[...]$0 = StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 }
+
+// lldb-command:print managed->val
+// lldb-check:[...]$1 = StructWithSomePadding { x: 88, y: 888, z: 8888, w: 88888 }
+
+// lldb-command:print *unique_dtor
+// lldb-check:[...]$2 = StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 }
+
+// lldb-command:print managed_dtor->val
+// lldb-check:[...]$3 = StructWithDestructor { x: 33, y: 333, z: 3333, w: 33333 }
+
#![feature(managed_boxes)]
#![allow(unused_variable)]
let unique_dtor = box StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 };
let managed_dtor = box(GC) StructWithDestructor { x: 33, y: 333, z: 3333, w: 33333 };
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$7 = {{Case1, x = 0, y = 8970181431921507452}, {Case1, 0, 2088533116, 2088533116}}
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print s
+// lldb-check:[...]$0 = Struct { a: 1, b: 2.5 }
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = Struct { a: 3, b: 4.5 }
+// lldb-command:print y
+// lldb-check:[...]$2 = 5
+// lldb-command:print z
+// lldb-check:[...]$3 = 6.5
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$4 = (7, 8, 9.5, 10.5)
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$5 = Newtype(11.5, 12.5, 13, 14)
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$6 = Case1 { x: 0, y: 8970181431921507452 }
+// lldb-command:continue
+
#![feature(struct_variant)]
#[deriving(Clone)]
}
fn fun(s: Struct) {
- zzz();
+ zzz(); // #break
}
fn fun_fun(StructStruct { a: x, b: Struct { a: y, b: z } }: StructStruct) {
- zzz();
+ zzz(); // #break
}
fn tup(a: (int, uint, f64, f64)) {
- zzz();
+ zzz(); // #break
}
struct Newtype(f64, f64, int, uint);
fn new_type(a: Newtype) {
- zzz();
+ zzz(); // #break
}
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
}
fn by_val_enum(x: Enum) {
- zzz();
+ zzz(); // #break
}
fn main() {
by_val_enum(Case1 { x: 0, y: 8970181431921507452 });
}
-fn zzz() {()}
+fn zzz() { () }
#![feature(managed_boxes)]
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$4 = 8888
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print self
+// lldb-check:[...]$0 = 1111
+// lldb-command:continue
+
+// lldb-command:print self
+// lldb-check:[...]$1 = Struct { x: 2222, y: 3333 }
+// lldb-command:continue
+
+// lldb-command:print self
+// lldb-check:[...]$2 = (4444.5, 5555, 6666, 7777.5)
+// lldb-command:continue
+
+// lldb-command:print self->val
+// lldb-check:[...]$3 = 8888
+// lldb-command:continue
+
use std::gc::{Gc, GC};
trait Trait {
impl Trait for int {
fn method(self) -> int {
- zzz();
+ zzz(); // #break
self
}
}
impl Trait for Struct {
fn method(self) -> Struct {
- zzz();
+ zzz(); // #break
self
}
}
impl Trait for (f64, int, int, f64) {
fn method(self) -> (f64, int, int, f64) {
- zzz();
+ zzz(); // #break
self
}
}
impl Trait for Gc<int> {
fn method(self) -> Gc<int> {
- zzz();
+ zzz(); // #break
self
}
}
let _ = (box(GC) 8888).method();
}
-fn zzz() {()}
+fn zzz() { () }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-tidy-linelength
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print struct_with_drop
// gdb-check:$7 = {{a = OneHundred, b = Vienna}, 9}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print tuple_interior_padding
+// lldb-check:[...]$0 = (0, OneHundred)
+
+// lldb-command:print tuple_padding_at_end
+// lldb-check:[...]$1 = ((1, OneThousand), 2)
+// lldb-command:print tuple_different_enums
+// lldb-check:[...]$2 = (OneThousand, MountainView, OneMillion, Vienna)
+
+// lldb-command:print padded_struct
+// lldb-check:[...]$3 = PaddedStruct { a: 3, b: OneMillion, c: 4, d: Toronto, e: 5 }
+
+// lldb-command:print packed_struct
+// lldb-check:[...]$4 = PackedStruct { a: 6, b: OneHundred, c: 7, d: Vienna, e: 8 }
+
+// lldb-command:print non_padded_struct
+// lldb-check:[...]$5 = NonPaddedStruct { a: OneMillion, b: MountainView, c: OneThousand, d: Toronto }
+
+// lldb-command:print struct_with_drop
+// lldb-check:[...]$6 = (StructWithDrop { a: OneHundred, b: Vienna }, 9)
+
#![allow(unused_variable)]
enum AnEnum {
let struct_with_drop = (StructWithDrop { a: OneHundred, b: Vienna }, 9_i64);
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:print 'c-style-enum::SINGLE_VARIANT'
// gdb-command:print 'c-style-enum::MANUAL_THREE'
// gdb-check:$18 = OneMillion
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print auto_one
+// lldb-check:[...]$0 = One
+
+// lldb-command:print auto_two
+// lldb-check:[...]$1 = Two
+
+// lldb-command:print auto_three
+// lldb-check:[...]$2 = Three
+
+// lldb-command:print manual_one_hundred
+// lldb-check:[...]$3 = OneHundred
+
+// lldb-command:print manual_one_thousand
+// lldb-check:[...]$4 = OneThousand
+
+// lldb-command:print manual_one_million
+// lldb-check:[...]$5 = OneMillion
+
+// lldb-command:print single_variant
+// lldb-check:[...]$6 = TheOnlyVariant
+
#![allow(unused_variable)]
#![allow(dead_code)]
MANUAL_THREE = OneMillion;
};
- zzz();
+ zzz(); // #break
let a = SINGLE_VARIANT;
let a = unsafe { AUTO_ONE };
let a = unsafe { MANUAL_ONE };
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$4 = 110
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = 0.5
+// lldb-command:print y
+// lldb-check:[...]$1 = 10
+// lldb-command:continue
+
+// lldb-command:print *x
+// lldb-check:[...]$2 = 29
+// lldb-command:print *y
+// lldb-check:[...]$3 = 110
+// lldb-command:continue
+
fn some_generic_fun<T1, T2>(a: T1, b: T2) -> (T2, T1) {
let closure = |x, y| {
- zzz();
+ zzz(); // #break
(y, x)
};
some_generic_fun(&29i, box 110i);
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$49 = 62
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+// lldb-command:run
+
+// lldb-command:print a
+// lldb-check:[...]$0 = 1
+// lldb-command:print b
+// lldb-check:[...]$1 = false
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$2 = 2
+// lldb-command:print b
+// lldb-check:[...]$3 = 3
+// lldb-command:print c
+// lldb-check:[...]$4 = 4
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$5 = 5
+// lldb-command:print b
+// lldb-check:[...]$6 = (6, 7)
+// lldb-command:continue
+
+// lldb-command:print h
+// lldb-check:[...]$7 = 8
+// lldb-command:print i
+// lldb-check:[...]$8 = Struct { a: 9, b: 10 }
+// lldb-command:print j
+// lldb-check:[...]$9 = 11
+// lldb-command:continue
+
+// lldb-command:print k
+// lldb-check:[...]$10 = 12
+// lldb-command:print l
+// lldb-check:[...]$11 = 13
+// lldb-command:continue
+
+// lldb-command:print m
+// lldb-check:[...]$12 = 14
+// lldb-command:print n
+// lldb-check:[...]$13 = 16
+// lldb-command:continue
+
+// lldb-command:print o
+// lldb-check:[...]$14 = 18
+// lldb-command:continue
+
+// lldb-command:print p
+// lldb-check:[...]$15 = 19
+// lldb-command:print q
+// lldb-check:[...]$16 = 20
+// lldb-command:print r
+// lldb-check:[...]$17 = Struct { a: 21, b: 22 }
+// lldb-command:continue
+
+// lldb-command:print s
+// lldb-check:[...]$18 = 24
+// lldb-command:print t
+// lldb-check:[...]$19 = 23
+// lldb-command:continue
+
+// lldb-command:print u
+// lldb-check:[...]$20 = 25
+// lldb-command:print v
+// lldb-check:[...]$21 = 26
+// lldb-command:print w
+// lldb-check:[...]$22 = 27
+// lldb-command:print x
+// lldb-check:[...]$23 = 28
+// lldb-command:print y
+// lldb-check:[...]$24 = 29
+// lldb-command:print z
+// lldb-check:[...]$25 = 30
+// lldb-command:print ae
+// lldb-check:[...]$26 = 31
+// lldb-command:print oe
+// lldb-check:[...]$27 = 32
+// lldb-command:print ue
+// lldb-check:[...]$28 = 33
+// lldb-command:continue
+
+// lldb-command:print aa
+// lldb-check:[...]$29 = (34, 35)
+// lldb-command:continue
+
+// lldb-command:print bb
+// lldb-check:[...]$30 = (36, 37)
+// lldb-command:continue
+
+// lldb-command:print cc
+// lldb-check:[...]$31 = 38
+// lldb-command:continue
+
+// lldb-command:print dd
+// lldb-check:[...]$32 = (40, 41, 42)
+// lldb-command:continue
+
+// lldb-command:print *ee
+// lldb-check:[...]$33 = (43, 44, 45)
+// lldb-command:continue
+
+// lldb-command:print *ff
+// lldb-check:[...]$34 = 46
+// lldb-command:print gg
+// lldb-check:[...]$35 = (47, 48)
+// lldb-command:continue
+
+// lldb-command:print *hh
+// lldb-check:[...]$36 = 50
+// lldb-command:continue
+
+// lldb-command:print ii
+// lldb-check:[...]$37 = 51
+// lldb-command:continue
+
+// lldb-command:print *jj
+// lldb-check:[...]$38 = 52
+// lldb-command:continue
+
+// lldb-command:print kk
+// lldb-check:[...]$39 = 53
+// lldb-command:print ll
+// lldb-check:[...]$40 = 54
+// lldb-command:continue
+
+// lldb-command:print mm
+// lldb-check:[...]$41 = 55
+// lldb-command:print *nn
+// lldb-check:[...]$42 = 56
+// lldb-command:continue
+
+// lldb-command:print oo
+// lldb-check:[...]$43 = 57
+// lldb-command:print pp
+// lldb-check:[...]$44 = 58
+// lldb-command:print qq
+// lldb-check:[...]$45 = 59
+// lldb-command:continue
+
+// lldb-command:print rr
+// lldb-check:[...]$46 = 60
+// lldb-command:print ss
+// lldb-check:[...]$47 = 61
+// lldb-command:print tt
+// lldb-check:[...]$48 = 62
+// lldb-command:continue
+
#![allow(unused_variable)]
fn simple_tuple((a, b): (int, bool)) {
- zzz();
+ zzz(); // #break
}
fn nested_tuple((a, (b, c)): (int, (u16, u16))) {
- zzz();
+ zzz(); // #break
}
fn destructure_only_first_level((a, b): (int, (u32, u32))) {
- zzz();
+ zzz(); // #break
}
fn struct_as_tuple_element((h, i, j): (i16, Struct, i16)) {
- zzz();
+ zzz(); // #break
}
fn struct_pattern(Struct { a: k, b: l }: Struct) {
- zzz();
+ zzz(); // #break
}
fn ignored_tuple_element((m, _, n): (int, u16, i32)) {
- zzz();
+ zzz(); // #break
}
fn ignored_struct_field(Struct { b: o, .. }: Struct) {
- zzz();
+ zzz(); // #break
}
fn one_struct_destructured_one_not((Struct { a: p, b: q }, r): (Struct, Struct)) {
- zzz();
+ zzz(); // #break
}
fn different_order_of_struct_fields(Struct { b: s, a: t }: Struct ) {
- zzz();
+ zzz(); // #break
}
fn complex_nesting(((u, v ), ((w, (x, Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue ):
((i16, i32), ((i64, (i32, Struct, )), Struct ), u16))
{
- zzz();
+ zzz(); // #break
}
fn managed_box(&aa: &(int, int)) {
- zzz();
+ zzz(); // #break
}
fn borrowed_pointer(&bb: &(int, int)) {
- zzz();
+ zzz(); // #break
}
fn contained_borrowed_pointer((&cc, _): (&int, int)) {
- zzz();
+ zzz(); // #break
}
fn unique_pointer(box dd: Box<(int, int, int)>) {
- zzz();
+ zzz(); // #break
}
fn ref_binding(ref ee: (int, int, int)) {
- zzz();
+ zzz(); // #break
}
fn ref_binding_in_tuple((ref ff, gg): (int, (int, int))) {
- zzz();
+ zzz(); // #break
}
fn ref_binding_in_struct(Struct { b: ref hh, .. }: Struct) {
- zzz();
+ zzz(); // #break
}
fn univariant_enum(Unit(ii): Univariant) {
- zzz();
+ zzz(); // #break
}
fn univariant_enum_with_ref_binding(Unit(ref jj): Univariant) {
- zzz();
+ zzz(); // #break
}
fn tuple_struct(TupleStruct(kk, ll): TupleStruct) {
- zzz();
+ zzz(); // #break
}
fn tuple_struct_with_ref_binding(TupleStruct(mm, ref nn): TupleStruct) {
- zzz();
+ zzz(); // #break
}
fn multiple_arguments((oo, pp): (int, int), qq : int) {
- zzz();
+ zzz(); // #break
}
fn main() {
multiple_arguments((57, 58), 59);
fn nested_function(rr: int, (ss, tt): (int, int)) {
- zzz();
+ zzz(); // #break
}
nested_function(60, (61, 62));
}
-
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *nn
// gdb-check:$43 = 56
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print a
+// lldb-check:[...]$0 = 1
+// lldb-command:print b
+// lldb-check:[...]$1 = false
+
+// lldb-command:print c
+// lldb-check:[...]$2 = 2
+// lldb-command:print d
+// lldb-check:[...]$3 = 3
+// lldb-command:print e
+// lldb-check:[...]$4 = 4
+
+// lldb-command:print f
+// lldb-check:[...]$5 = 5
+// lldb-command:print g
+// lldb-check:[...]$6 = (6, 7)
+
+// lldb-command:print h
+// lldb-check:[...]$7 = 8
+// lldb-command:print i
+// lldb-check:[...]$8 = Struct { a: 9, b: 10 }
+// lldb-command:print j
+// lldb-check:[...]$9 = 11
+
+// lldb-command:print k
+// lldb-check:[...]$10 = 12
+// lldb-command:print l
+// lldb-check:[...]$11 = 13
+
+// lldb-command:print m
+// lldb-check:[...]$12 = 14
+// lldb-command:print n
+// lldb-check:[...]$13 = 16
+
+// lldb-command:print o
+// lldb-check:[...]$14 = 18
+
+// lldb-command:print p
+// lldb-check:[...]$15 = 19
+// lldb-command:print q
+// lldb-check:[...]$16 = 20
+// lldb-command:print r
+// lldb-check:[...]$17 = Struct { a: 21, b: 22 }
+
+// lldb-command:print s
+// lldb-check:[...]$18 = 24
+// lldb-command:print t
+// lldb-check:[...]$19 = 23
+
+// lldb-command:print u
+// lldb-check:[...]$20 = 25
+// lldb-command:print v
+// lldb-check:[...]$21 = 26
+// lldb-command:print w
+// lldb-check:[...]$22 = 27
+// lldb-command:print x
+// lldb-check:[...]$23 = 28
+// lldb-command:print y
+// lldb-check:[...]$24 = 29
+// lldb-command:print z
+// lldb-check:[...]$25 = 30
+// lldb-command:print ae
+// lldb-check:[...]$26 = 31
+// lldb-command:print oe
+// lldb-check:[...]$27 = 32
+// lldb-command:print ue
+// lldb-check:[...]$28 = 33
+
+// lldb-command:print aa
+// lldb-check:[...]$29 = (34, 35)
+
+// lldb-command:print bb
+// lldb-check:[...]$30 = (36, 37)
+
+// lldb-command:print cc
+// lldb-check:[...]$31 = 38
+
+// lldb-command:print dd
+// lldb-check:[...]$32 = (40, 41, 42)
+
+// lldb-command:print *ee
+// lldb-check:[...]$33 = (43, 44, 45)
+
+// lldb-command:print *ff
+// lldb-check:[...]$34 = 46
+
+// lldb-command:print gg
+// lldb-check:[...]$35 = (47, 48)
+
+// lldb-command:print *hh
+// lldb-check:[...]$36 = 50
+
+// lldb-command:print ii
+// lldb-check:[...]$37 = 51
+
+// lldb-command:print *jj
+// lldb-check:[...]$38 = 52
+
+// lldb-command:print kk
+// lldb-check:[...]$39 = 53
+
+// lldb-command:print ll
+// lldb-check:[...]$40 = 54
+
+// lldb-command:print mm
+// lldb-check:[...]$41 = 55
+
+// lldb-command:print *nn
+// lldb-check:[...]$42 = 56
+
+
#![allow(unused_variable)]
struct Struct {
// tuple struct with ref binding
let &TupleStruct(mm, ref nn) = &TupleStruct(55.0, 56);
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print struct_padded_at_end
// gdb-check:$5 = {x = {22, 23}, y = {24, 25}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print no_padding1
+// lldb-check:[...]$0 = NoPadding1 { x: [0, 1, 2], y: -3, z: [4.5, 5.5] }
+// lldb-command:print no_padding2
+// lldb-check:[...]$1 = NoPadding2 { x: [6, 7, 8], y: [[9, 10], [11, 12]] }
+
+// lldb-command:print struct_internal_padding
+// lldb-check:[...]$2 = StructInternalPadding { x: [13, 14], y: [15, 16] }
+
+// lldb-command:print single_vec
+// lldb-check:[...]$3 = SingleVec { x: [17, 18, 19, 20, 21] }
+
+// lldb-command:print struct_padded_at_end
+// lldb-check:[...]$4 = StructPaddedAtEnd { x: [22, 23], y: [24, 25] }
+
#![allow(unused_variable)]
struct NoPadding1 {
y: [24, 25]
};
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// compile-flags:-g
// gdb-command:set print pretty off
-// gdb-command:break function-arg-initialization.rs:139
-// gdb-command:break function-arg-initialization.rs:154
-// gdb-command:break function-arg-initialization.rs:158
-// gdb-command:break function-arg-initialization.rs:162
-// gdb-command:break function-arg-initialization.rs:166
-// gdb-command:break function-arg-initialization.rs:170
-// gdb-command:break function-arg-initialization.rs:174
-// gdb-command:break function-arg-initialization.rs:178
-// gdb-command:break function-arg-initialization.rs:182
-// gdb-command:break function-arg-initialization.rs:190
-// gdb-command:break function-arg-initialization.rs:197
-
+// gdb-command:break function-arg-initialization.rs:243
+// gdb-command:break function-arg-initialization.rs:258
+// gdb-command:break function-arg-initialization.rs:262
+// gdb-command:break function-arg-initialization.rs:266
+// gdb-command:break function-arg-initialization.rs:270
+// gdb-command:break function-arg-initialization.rs:274
+// gdb-command:break function-arg-initialization.rs:278
+// gdb-command:break function-arg-initialization.rs:282
+// gdb-command:break function-arg-initialization.rs:286
+// gdb-command:break function-arg-initialization.rs:294
+// gdb-command:break function-arg-initialization.rs:301
+
+// === GDB TESTS ===================================================================================
// gdb-command:run
// gdb-check:$32 = 45
// gdb-command:continue
-#![allow(unused_variable)]
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$0 = 1
+// lldb-command:print b
+// lldb-check:[...]$1 = true
+// lldb-command:print c
+// lldb-check:[...]$2 = 2.5
+// lldb-command:continue
+
+// NON IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 }
+// lldb-command:print b
+// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 }
+// lldb-command:continue
+
+// BINDING
+// lldb-command:print a
+// lldb-check:[...]$5 = 19
+// lldb-command:print b
+// lldb-check:[...]$6 = 20
+// lldb-command:print c
+// lldb-check:[...]$7 = 21.5
+// lldb-command:continue
+
+// ASSIGNMENT
+// lldb-command:print a
+// lldb-check:[...]$8 = 22
+// lldb-command:print b
+// lldb-check:[...]$9 = 23
+// lldb-command:print c
+// lldb-check:[...]$10 = 24.5
+// lldb-command:continue
+
+// FUNCTION CALL
+// lldb-command:print x
+// lldb-check:[...]$11 = 25
+// lldb-command:print y
+// lldb-check:[...]$12 = 26
+// lldb-command:print z
+// lldb-check:[...]$13 = 27.5
+// lldb-command:continue
+
+// EXPR
+// lldb-command:print x
+// lldb-check:[...]$14 = 28
+// lldb-command:print y
+// lldb-check:[...]$15 = 29
+// lldb-command:print z
+// lldb-check:[...]$16 = 30.5
+// lldb-command:continue
+
+// RETURN EXPR
+// lldb-command:print x
+// lldb-check:[...]$17 = 31
+// lldb-command:print y
+// lldb-check:[...]$18 = 32
+// lldb-command:print z
+// lldb-check:[...]$19 = 33.5
+// lldb-command:continue
+
+// ARITHMETIC EXPR
+// lldb-command:print x
+// lldb-check:[...]$20 = 34
+// lldb-command:print y
+// lldb-check:[...]$21 = 35
+// lldb-command:print z
+// lldb-check:[...]$22 = 36.5
+// lldb-command:continue
+
+// IF EXPR
+// lldb-command:print x
+// lldb-check:[...]$23 = 37
+// lldb-command:print y
+// lldb-check:[...]$24 = 38
+// lldb-command:print z
+// lldb-check:[...]$25 = 39.5
+// lldb-command:continue
+
+// WHILE EXPR
+// lldb-command:print x
+// lldb-check:[...]$26 = 40
+// lldb-command:print y
+// lldb-check:[...]$27 = 41
+// lldb-command:print z
+// lldb-check:[...]$28 = 42
+// lldb-command:continue
+
+// LOOP EXPR
+// lldb-command:print x
+// lldb-check:[...]$29 = 43
+// lldb-command:print y
+// lldb-check:[...]$30 = 44
+// lldb-command:print z
+// lldb-check:[...]$31 = 45
+// lldb-command:continue
+
+
+
+#![allow(unused_variable)]
fn immediate_args(a: int, b: bool, c: f64) {
- ()
+ () // #break
}
struct BigStruct {
}
fn non_immediate_args(a: BigStruct, b: BigStruct) {
- ()
+ () // #break
}
fn binding(a: i64, b: u64, c: f64) {
- let x = 0i;
+ let x = 0i; // #break
}
fn assignment(mut a: u64, b: u64, c: f64) {
- a = b;
+ a = b; // #break
}
fn function_call(x: u64, y: u64, z: f64) {
- std::io::stdio::print("Hi!")
+ std::io::stdio::print("Hi!") // #break
}
fn identifier(x: u64, y: u64, z: f64) -> u64 {
- x
+ x // #break
}
fn return_expr(x: u64, y: u64, z: f64) -> u64 {
- return x;
+ return x; // #break
}
fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 {
- x + y
+ x + y // #break
}
fn if_expr(x: u64, y: u64, z: f64) -> u64 {
- if x + y < 1000 {
+ if x + y < 1000 { // #break
x
} else {
y
}
fn while_expr(mut x: u64, y: u64, z: u64) -> u64 {
- while x + y < 1000 {
+ while x + y > 1000 { // #break
x += z
}
return x;
}
fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 {
- loop {
+ loop { // #break
x += z;
if x + y > 1000 {
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print b
// gdb-check:$4 = 3000
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = 111102
+// lldb-command:print y
+// lldb-check:[...]$1 = true
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$2 = 2000
+// lldb-command:print b
+// lldb-check:[...]$3 = 3000
+// lldb-command:continue
+
fn main() {
fun(111102, true);
nested(2000, 3000);
fn nested(a: i32, b: i64) -> (i32, i64) {
- zzz();
+ zzz(); // #break
(a, b)
}
}
fn fun(x: int, y: bool) -> (int, bool) {
- zzz();
+ zzz(); // #break
(x, y)
}
-fn zzz() {()}
+fn zzz() { () }
// beginning of a function. Functions with the #[no_split_stack] attribute have the same prologue as
// regular C functions compiled with GCC or Clang and therefore are better handled by GDB. As a
// consequence, and as opposed to regular Rust functions, we can set the breakpoints via the
-// function name (and don't have to fall back on using line numbers).
+// function name (and don't have to fall back on using line numbers). For LLDB this shouldn't make
+// a difference because it can handle both cases.
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak immediate_args
// gdb-command:rbreak binding
// gdb-check:$32 = 45
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:breakpoint set --name immediate_args
+// lldb-command:breakpoint set --name non_immediate_args
+// lldb-command:breakpoint set --name binding
+// lldb-command:breakpoint set --name assignment
+// lldb-command:breakpoint set --name function_call
+// lldb-command:breakpoint set --name identifier
+// lldb-command:breakpoint set --name return_expr
+// lldb-command:breakpoint set --name arithmetic_expr
+// lldb-command:breakpoint set --name if_expr
+// lldb-command:breakpoint set --name while_expr
+// lldb-command:breakpoint set --name loop_expr
+// lldb-command:run
+
+// IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$0 = 1
+// lldb-command:print b
+// lldb-check:[...]$1 = true
+// lldb-command:print c
+// lldb-check:[...]$2 = 2.5
+// lldb-command:continue
+
+// NON IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 }
+// lldb-command:print b
+// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 }
+// lldb-command:continue
+
+// BINDING
+// lldb-command:print a
+// lldb-check:[...]$5 = 19
+// lldb-command:print b
+// lldb-check:[...]$6 = 20
+// lldb-command:print c
+// lldb-check:[...]$7 = 21.5
+// lldb-command:continue
+
+// ASSIGNMENT
+// lldb-command:print a
+// lldb-check:[...]$8 = 22
+// lldb-command:print b
+// lldb-check:[...]$9 = 23
+// lldb-command:print c
+// lldb-check:[...]$10 = 24.5
+// lldb-command:continue
+
+// FUNCTION CALL
+// lldb-command:print x
+// lldb-check:[...]$11 = 25
+// lldb-command:print y
+// lldb-check:[...]$12 = 26
+// lldb-command:print z
+// lldb-check:[...]$13 = 27.5
+// lldb-command:continue
+
+// EXPR
+// lldb-command:print x
+// lldb-check:[...]$14 = 28
+// lldb-command:print y
+// lldb-check:[...]$15 = 29
+// lldb-command:print z
+// lldb-check:[...]$16 = 30.5
+// lldb-command:continue
+
+// RETURN EXPR
+// lldb-command:print x
+// lldb-check:[...]$17 = 31
+// lldb-command:print y
+// lldb-check:[...]$18 = 32
+// lldb-command:print z
+// lldb-check:[...]$19 = 33.5
+// lldb-command:continue
+
+// ARITHMETIC EXPR
+// lldb-command:print x
+// lldb-check:[...]$20 = 34
+// lldb-command:print y
+// lldb-check:[...]$21 = 35
+// lldb-command:print z
+// lldb-check:[...]$22 = 36.5
+// lldb-command:continue
+
+// IF EXPR
+// lldb-command:print x
+// lldb-check:[...]$23 = 37
+// lldb-command:print y
+// lldb-check:[...]$24 = 38
+// lldb-command:print z
+// lldb-check:[...]$25 = 39.5
+// lldb-command:continue
+
+// WHILE EXPR
+// lldb-command:print x
+// lldb-check:[...]$26 = 40
+// lldb-command:print y
+// lldb-check:[...]$27 = 41
+// lldb-command:print z
+// lldb-check:[...]$28 = 42
+// lldb-command:continue
+
+// LOOP EXPR
+// lldb-command:print x
+// lldb-check:[...]$29 = 43
+// lldb-command:print y
+// lldb-check:[...]$30 = 44
+// lldb-command:print z
+// lldb-check:[...]$31 = 45
+// lldb-command:continue
+
#![allow(unused_variable)]
#[no_split_stack]
--- /dev/null
+// Copyright 2013-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.
+
+// This test case checks if function arguments already have the correct value when breaking at the
+// beginning of a function.
+
+// ignore-gdb
+// compile-flags:-g
+
+// lldb-command:breakpoint set --name immediate_args
+// lldb-command:breakpoint set --name non_immediate_args
+// lldb-command:breakpoint set --name binding
+// lldb-command:breakpoint set --name assignment
+// lldb-command:breakpoint set --name function_call
+// lldb-command:breakpoint set --name identifier
+// lldb-command:breakpoint set --name return_expr
+// lldb-command:breakpoint set --name arithmetic_expr
+// lldb-command:breakpoint set --name if_expr
+// lldb-command:breakpoint set --name while_expr
+// lldb-command:breakpoint set --name loop_expr
+// lldb-command:run
+
+// IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$0 = 1
+// lldb-command:print b
+// lldb-check:[...]$1 = true
+// lldb-command:print c
+// lldb-check:[...]$2 = 2.5
+// lldb-command:continue
+
+// NON IMMEDIATE ARGS
+// lldb-command:print a
+// lldb-check:[...]$3 = BigStruct { a: 3, b: 4, c: 5, d: 6, e: 7, f: 8, g: 9, h: 10 }
+// lldb-command:print b
+// lldb-check:[...]$4 = BigStruct { a: 11, b: 12, c: 13, d: 14, e: 15, f: 16, g: 17, h: 18 }
+// lldb-command:continue
+
+// BINDING
+// lldb-command:print a
+// lldb-check:[...]$5 = 19
+// lldb-command:print b
+// lldb-check:[...]$6 = 20
+// lldb-command:print c
+// lldb-check:[...]$7 = 21.5
+// lldb-command:continue
+
+// ASSIGNMENT
+// lldb-command:print a
+// lldb-check:[...]$8 = 22
+// lldb-command:print b
+// lldb-check:[...]$9 = 23
+// lldb-command:print c
+// lldb-check:[...]$10 = 24.5
+// lldb-command:continue
+
+// FUNCTION CALL
+// lldb-command:print x
+// lldb-check:[...]$11 = 25
+// lldb-command:print y
+// lldb-check:[...]$12 = 26
+// lldb-command:print z
+// lldb-check:[...]$13 = 27.5
+// lldb-command:continue
+
+// EXPR
+// lldb-command:print x
+// lldb-check:[...]$14 = 28
+// lldb-command:print y
+// lldb-check:[...]$15 = 29
+// lldb-command:print z
+// lldb-check:[...]$16 = 30.5
+// lldb-command:continue
+
+// RETURN EXPR
+// lldb-command:print x
+// lldb-check:[...]$17 = 31
+// lldb-command:print y
+// lldb-check:[...]$18 = 32
+// lldb-command:print z
+// lldb-check:[...]$19 = 33.5
+// lldb-command:continue
+
+// ARITHMETIC EXPR
+// lldb-command:print x
+// lldb-check:[...]$20 = 34
+// lldb-command:print y
+// lldb-check:[...]$21 = 35
+// lldb-command:print z
+// lldb-check:[...]$22 = 36.5
+// lldb-command:continue
+
+// IF EXPR
+// lldb-command:print x
+// lldb-check:[...]$23 = 37
+// lldb-command:print y
+// lldb-check:[...]$24 = 38
+// lldb-command:print z
+// lldb-check:[...]$25 = 39.5
+// lldb-command:continue
+
+// WHILE EXPR
+// lldb-command:print x
+// lldb-check:[...]$26 = 40
+// lldb-command:print y
+// lldb-check:[...]$27 = 41
+// lldb-command:print z
+// lldb-check:[...]$28 = 42
+// lldb-command:continue
+
+// LOOP EXPR
+// lldb-command:print x
+// lldb-check:[...]$29 = 43
+// lldb-command:print y
+// lldb-check:[...]$30 = 44
+// lldb-command:print z
+// lldb-check:[...]$31 = 45
+// lldb-command:continue
+
+#![allow(unused_variable)]
+
+fn immediate_args(a: int, b: bool, c: f64) {
+ ()
+}
+
+struct BigStruct {
+ a: u64,
+ b: u64,
+ c: u64,
+ d: u64,
+ e: u64,
+ f: u64,
+ g: u64,
+ h: u64
+}
+
+fn non_immediate_args(a: BigStruct, b: BigStruct) {
+ ()
+}
+
+fn binding(a: i64, b: u64, c: f64) {
+ let x = 0i;
+}
+
+fn assignment(mut a: u64, b: u64, c: f64) {
+ a = b;
+}
+
+fn function_call(x: u64, y: u64, z: f64) {
+ std::io::stdio::print("Hi!")
+}
+
+fn identifier(x: u64, y: u64, z: f64) -> u64 {
+ x
+}
+
+fn return_expr(x: u64, y: u64, z: f64) -> u64 {
+ return x;
+}
+
+fn arithmetic_expr(x: u64, y: u64, z: f64) -> u64 {
+ x + y
+}
+
+fn if_expr(x: u64, y: u64, z: f64) -> u64 {
+ if x + y < 1000 {
+ x
+ } else {
+ y
+ }
+}
+
+fn while_expr(mut x: u64, y: u64, z: u64) -> u64 {
+ while x + y < 1000 {
+ x += z
+ }
+ return x;
+}
+
+fn loop_expr(mut x: u64, y: u64, z: u64) -> u64 {
+ loop {
+ x += z;
+
+ if x + y > 1000 {
+ return x;
+ }
+ }
+}
+
+fn main() {
+ immediate_args(1, true, 2.5);
+
+ non_immediate_args(
+ BigStruct {
+ a: 3,
+ b: 4,
+ c: 5,
+ d: 6,
+ e: 7,
+ f: 8,
+ g: 9,
+ h: 10
+ },
+ BigStruct {
+ a: 11,
+ b: 12,
+ c: 13,
+ d: 14,
+ e: 15,
+ f: 16,
+ g: 17,
+ h: 18
+ }
+ );
+
+ binding(19, 20, 21.5);
+ assignment(22, 23, 24.5);
+ function_call(25, 26, 27.5);
+ identifier(28, 29, 30.5);
+ return_expr(31, 32, 33.5);
+ arithmetic_expr(34, 35, 36.5);
+ if_expr(37, 38, 39.5);
+ while_expr(40, 41, 42);
+ loop_expr(43, 44, 45);
+}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$9 = {{5, {a = 6, b = 7.5}}, {{a = 6, b = 7.5}, 5}}
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *t0
+// lldb-check:[...]$0 = 1
+// lldb-command:print *t1
+// lldb-check:[...]$1 = 2.5
+// lldb-command:print ret
+// lldb-check:[...]$2 = ((1, 2.5), (2.5, 1))
+// lldb-command:continue
+
+// lldb-command:print *t0
+// lldb-check:[...]$3 = 3.5
+// lldb-command:print *t1
+// lldb-check:[...]$4 = 4
+// lldb-command:print ret
+// lldb-check:[...]$5 = ((3.5, 4), (4, 3.5))
+// lldb-command:continue
+
+// lldb-command:print *t0
+// lldb-check:[...]$6 = 5
+// lldb-command:print *t1
+// lldb-check:[...]$7 = Struct { a: 6, b: 7.5 }
+// lldb-command:print ret
+// lldb-check:[...]$8 = ((5, Struct { a: 6, b: 7.5 }), (Struct { a: 6, b: 7.5 }, 5))
+// lldb-command:continue
+
+
#[deriving(Clone)]
struct Struct {
a: int,
fn dup_tup<T0: Clone, T1: Clone>(t0: &T0, t1: &T1) -> ((T0, T1), (T1, T0)) {
let ret = ((t0.clone(), t1.clone()), (t1.clone(), t0.clone()));
- zzz();
+ zzz(); // #break
ret
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$8 = 2.5
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = -1
+// lldb-command:print y
+// lldb-check:[...]$1 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = -1
+// lldb-command:print y
+// lldb-check:[...]$3 = 2.5
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = -2.5
+// lldb-command:print y
+// lldb-check:[...]$5 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$6 = -2.5
+// lldb-command:print y
+// lldb-check:[...]$7 = 2.5
+// lldb-command:continue
+
fn outer<TA: Clone>(a: TA) {
inner(a.clone(), 1i);
inner(a.clone(), 2.5f64);
fn inner<TX, TY>(x: TX, y: TY) {
- zzz();
+ zzz(); // #break
}
}
outer(-2.5f64);
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$1 = {x = {8888, -8888}}
// gdb-command:print arg1
// gdb-check:$2 = -1
-// gdb-command:print/d arg2
-// gdb-check:$3 = -2
+// gdb-command:print arg2
+// gdb-check:$3 = 2
// gdb-command:continue
// STACK BY VAL
// gdb-check:$15 = -10.5
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct<(u32, i32)> { x: (8888, -8888) }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = 2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct<(u32, i32)> { x: (8888, -8888) }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10.5
+// lldb-command:continue
+
+
struct Struct<T> {
x: T
}
impl<T1> Struct<T1> {
fn self_by_ref<T2>(&self, arg1: int, arg2: T2) -> int {
- zzz();
+ zzz(); // #break
arg1
}
fn self_by_val<T2>(self, arg1: int, arg2: T2) -> int {
- zzz();
+ zzz(); // #break
arg1
}
- fn self_owned<T2>(~self, arg1: int, arg2: T2) -> int {
- zzz();
+ fn self_owned<T2>(self: Box<Struct<T1>>, arg1: int, arg2: T2) -> int {
+ zzz(); // #break
arg1
}
}
fn main() {
let stack = Struct { x: (8888_u32, -8888_i32) };
- let _ = stack.self_by_ref(-1, -2_i8);
+ let _ = stack.self_by_ref(-1, 2_u16);
let _ = stack.self_by_val(-3, -4_i16);
let owned = box Struct { x: 1234.5f64 };
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-tidy-linelength
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print float_int_float
// gdb-check:$4 = {key = 6.5, value = {key = 7, value = 8.5}}
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print int_int
+// lldb-check:[...]$0 = AGenericStruct<int, int> { key: 0, value: 1 }
+// lldb-command:print int_float
+// lldb-check:[...]$1 = AGenericStruct<int, f64> { key: 2, value: 3.5 }
+// lldb-command:print float_int
+// lldb-check:[...]$2 = AGenericStruct<f64, int> { key: 4.5, value: 5 }
+
+// lldb-command:print float_int_float
+// lldb-check:[...]$3 = AGenericStruct<f64, generic-struct::AGenericStruct<int, f64>> { key: 6.5, value: AGenericStruct<int, f64> { key: 7, value: 8.5 } }
+
struct AGenericStruct<TKey, TValue> {
key: TKey,
value: TValue
value: AGenericStruct { key: 7i, value: 8.5f64 },
};
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print union on
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$4 = {{-1}}
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print case1
+// lldb-check:[...]$0 = Case1(0, 31868, 31868, 31868, 31868)
+
+// lldb-command:print case2
+// lldb-check:[...]$1 = Case2(0, 286331153, 286331153)
+
+// lldb-command:print case3
+// lldb-check:[...]$2 = Case3(0, 6438275382588823897)
+
+// lldb-command:print univariant
+// lldb-check:[...]$3 = TheOnlyCase(-1)
+
+
// NOTE: This is a copy of the non-generic test case. The `Txx` type parameters have to be
// substituted with something of size `xx` bits and the same alignment as an integer type of the
// same size.
let univariant = TheOnlyCase(-1_i64);
- zzz();
+ zzz(); // #break
}
-fn zzz() {()}
+fn zzz() { () }
// gdb-command:run
// gdb-command:finish
// gdb-command:print string1.length
-// gdb-check:$1 = 49
+// gdb-check:$1 = 48
// gdb-command:print string2.length
// gdb-check:$2 = 49
// gdb-command:print string3.length
-// gdb-check:$3 = 49
+// gdb-check:$3 = 50
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print string1.length
+// lldb-check:[...]$0 = 48
+// lldb-command:print string2.length
+// lldb-check:[...]$1 = 49
+// lldb-command:print string3.length
+// lldb-check:[...]$2 = 50
+
+// lldb-command:continue
+
#![allow(unused_variable)]
// This test case makes sure that debug info does not ICE when include_str is
let string1 = include_str!("text-to-include-1.txt");
let string2 = include_str!("text-to-include-2.txt");
let string3 = include_str!("text-to-include-3.txt");
- zzz();
+
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$7 = 1000000
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// FIRST ITERATION
+// lldb-command:print x
+// lldb-check:[...]$0 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = -1
+// lldb-command:continue
+
+// SECOND ITERATION
+// lldb-command:print x
+// lldb-check:[...]$2 = 2
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = -2
+// lldb-command:continue
+
+// THIRD ITERATION
+// lldb-command:print x
+// lldb-check:[...]$4 = 3
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = -3
+// lldb-command:continue
+
+// AFTER LOOP
+// lldb-command:print x
+// lldb-check:[...]$6 = 1000000
+// lldb-command:continue
+
fn main() {
let range = [1i, 2, 3];
let x = 1000000i; // wan meeeljen doollaars!
for &x in range.iter() {
- zzz();
+ zzz(); // #break
sentinel();
let x = -1i * x;
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$16 = -1
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// BEFORE if
+// lldb-command:print x
+// lldb-check:[...]$0 = 999
+// lldb-command:print y
+// lldb-check:[...]$1 = -1
+// lldb-command:continue
+
+// AT BEGINNING of 'then' block
+// lldb-command:print x
+// lldb-check:[...]$2 = 999
+// lldb-command:print y
+// lldb-check:[...]$3 = -1
+// lldb-command:continue
+
+// AFTER 1st redeclaration of 'x'
+// lldb-command:print x
+// lldb-check:[...]$4 = 1001
+// lldb-command:print y
+// lldb-check:[...]$5 = -1
+// lldb-command:continue
+
+// AFTER 2st redeclaration of 'x'
+// lldb-command:print x
+// lldb-check:[...]$6 = 1002
+// lldb-command:print y
+// lldb-check:[...]$7 = 1003
+// lldb-command:continue
+
+// AFTER 1st if expression
+// lldb-command:print x
+// lldb-check:[...]$8 = 999
+// lldb-command:print y
+// lldb-check:[...]$9 = -1
+// lldb-command:continue
+
+// BEGINNING of else branch
+// lldb-command:print x
+// lldb-check:[...]$10 = 999
+// lldb-command:print y
+// lldb-check:[...]$11 = -1
+// lldb-command:continue
+
+// BEGINNING of else branch
+// lldb-command:print x
+// lldb-check:[...]$12 = 1004
+// lldb-command:print y
+// lldb-check:[...]$13 = 1005
+// lldb-command:continue
+
+// BEGINNING of else branch
+// lldb-command:print x
+// lldb-check:[...]$14 = 999
+// lldb-command:print y
+// lldb-check:[...]$15 = -1
+// lldb-command:continue
+
+
fn main() {
let x = 999i;
let y = -1i;
- zzz();
+ zzz(); // #break
sentinel();
if x < 1000 {
- zzz();
+ zzz(); // #break
sentinel();
let x = 1001i;
- zzz();
+ zzz(); // #break
sentinel();
let x = 1002i;
let y = 1003i;
- zzz();
+ zzz(); // #break
sentinel();
} else {
unreachable!();
}
- zzz();
+ zzz(); // #break
sentinel();
if x > 1000 {
unreachable!();
} else {
- zzz();
+ zzz(); // #break
sentinel();
let x = 1004i;
let y = 1005i;
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$18 = 232
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print shadowed
+// lldb-check:[...]$0 = 231
+// lldb-command:print not_shadowed
+// lldb-check:[...]$1 = 232
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$2 = 233
+// lldb-command:print not_shadowed
+// lldb-check:[...]$3 = 232
+// lldb-command:print local_to_arm
+// lldb-check:[...]$4 = 234
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$5 = 236
+// lldb-command:print not_shadowed
+// lldb-check:[...]$6 = 232
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$7 = 237
+// lldb-command:print not_shadowed
+// lldb-check:[...]$8 = 232
+// lldb-command:print local_to_arm
+// lldb-check:[...]$9 = 238
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$10 = 239
+// lldb-command:print not_shadowed
+// lldb-check:[...]$11 = 232
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$12 = 241
+// lldb-command:print not_shadowed
+// lldb-check:[...]$13 = 232
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$14 = 243
+// lldb-command:print *local_to_arm
+// lldb-check:[...]$15 = 244
+// lldb-command:continue
+
+// lldb-command:print shadowed
+// lldb-check:[...]$16 = 231
+// lldb-command:print not_shadowed
+// lldb-check:[...]$17 = 232
+// lldb-command:continue
+
+
struct Struct {
x: int,
y: int
let shadowed = 231i;
let not_shadowed = 232i;
- zzz();
+ zzz(); // #break
sentinel();
match (233i, 234i) {
(shadowed, local_to_arm) => {
- zzz();
+ zzz(); // #break
sentinel();
}
}
// with literal
(235, shadowed) => {
- zzz();
+ zzz(); // #break
sentinel();
}
_ => {}
match (Struct { x: 237, y: 238 }) {
Struct { x: shadowed, y: local_to_arm } => {
- zzz();
+ zzz(); // #break
sentinel();
}
}
// ignored field
Struct { x: shadowed, .. } => {
- zzz();
+ zzz(); // #break
sentinel();
}
}
// with literal
Struct { x: shadowed, y: 242 } => {
- zzz();
+ zzz(); // #break
sentinel();
}
_ => {}
match (243i, 244i) {
(shadowed, ref local_to_arm) => {
- zzz();
+ zzz(); // #break
sentinel();
}
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$6 = false
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 1000
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = 2.5
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = false
+// lldb-command:continue
+
fn main() {
let x = false;
- zzz();
+ zzz(); // #break
sentinel();
let stack_closure: |int| = |x| {
- zzz();
+ zzz(); // #break
sentinel();
let x = 2.5f64;
- zzz();
+ zzz(); // #break
sentinel();
let x = true;
- zzz();
+ zzz(); // #break
sentinel();
};
- zzz();
+ zzz(); // #break
sentinel();
stack_closure(1000);
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$13 = 2
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// FIRST ITERATION
+// lldb-command:print x
+// lldb-check:[...]$0 = 0
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 101
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = 101
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = -987
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = 101
+// lldb-command:continue
+
+
+// SECOND ITERATION
+// lldb-command:print x
+// lldb-check:[...]$6 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$7 = 2
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$8 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$9 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$10 = -987
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$11 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$12 = 2
+// lldb-command:continue
+
fn main() {
let mut x = 0i;
break;
}
- zzz();
+ zzz(); // #break
sentinel();
x += 1;
- zzz();
+ zzz(); // #break
sentinel();
// Shadow x
let x = x + 100;
- zzz();
+ zzz(); // #break
sentinel();
// open scope within loop's top level scope
{
- zzz();
+ zzz(); // #break
sentinel();
let x = -987i;
- zzz();
+ zzz(); // #break
sentinel();
}
// Check that we get the x before the inner scope again
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$6 = false
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 1000
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = 2.5
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = false
+// lldb-command:continue
+
fn main() {
let x = false;
- zzz();
+ zzz(); // #break
sentinel();
let unique_closure: proc(int) = proc(x) {
- zzz();
+ zzz(); // #break
sentinel();
let x = 2.5f64;
- zzz();
+ zzz(); // #break
sentinel();
let x = true;
- zzz();
+ zzz(); // #break
sentinel();
};
- zzz();
+ zzz(); // #break
sentinel();
unique_closure(1000);
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$13 = 2
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// FIRST ITERATION
+// lldb-command:print x
+// lldb-check:[...]$0 = 0
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 101
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = 101
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = -987
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = 101
+// lldb-command:continue
+
+
+// SECOND ITERATION
+// lldb-command:print x
+// lldb-check:[...]$6 = 1
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$7 = 2
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$8 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$9 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$10 = -987
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$11 = 102
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$12 = 2
+// lldb-command:continue
+
+
fn main() {
let mut x = 0i;
while x < 2 {
- zzz();
+ zzz(); // #break
sentinel();
x += 1;
- zzz();
+ zzz(); // #break
sentinel();
// Shadow x
let x = x + 100;
- zzz();
+ zzz(); // #break
sentinel();
// open scope within loop's top level scope
{
- zzz();
+ zzz(); // #break
sentinel();
let x = -987i;
- zzz();
+ zzz(); // #break
sentinel();
}
// Check that we get the x before the inner scope again
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = 400
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print a
+// lldb-check:[...]$0 = 10
+// lldb-command:print b
+// lldb-check:[...]$1 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$2 = 890242
+// lldb-command:print b
+// lldb-check:[...]$3 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$4 = 10
+// lldb-command:print b
+// lldb-check:[...]$5 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$6 = 102
+// lldb-command:print b
+// lldb-check:[...]$7 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$8 = 110
+// lldb-command:print b
+// lldb-check:[...]$9 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$10 = 10
+// lldb-command:print b
+// lldb-check:[...]$11 = 34
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$12 = 10
+// lldb-command:print b
+// lldb-check:[...]$13 = 34
+// lldb-command:print c
+// lldb-check:[...]$14 = 400
+// lldb-command:continue
+
+
#![feature(macro_rules)]
macro_rules! trivial(
macro_rules! new_scope(
() => ({
let a = 890242i;
- zzz();
+ zzz(); // #break
sentinel();
})
)
($e1:expr) => ({
let a = $e1 + 2;
- zzz();
+ zzz(); // #break
sentinel();
let a = $e1 + 10;
- zzz();
+ zzz(); // #break
sentinel();
})
)
let a = trivial!(10i);
let b = no_new_scope!(33i);
- zzz();
+ zzz(); // #break
sentinel();
new_scope!();
- zzz();
+ zzz(); // #break
sentinel();
shadow_within_macro!(100i);
- zzz();
+ zzz(); // #break
sentinel();
let c = dup_expr!(10i * 20);
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$57 = 10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STRUCT EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$0 = -1
+// lldb-command:print ten
+// lldb-check:[...]$1 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$2 = 11
+// lldb-command:print ten
+// lldb-check:[...]$3 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$4 = -1
+// lldb-command:print ten
+// lldb-check:[...]$5 = 10
+// lldb-command:continue
+
+// FUNCTION CALL
+// lldb-command:print val
+// lldb-check:[...]$6 = -1
+// lldb-command:print ten
+// lldb-check:[...]$7 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$8 = 12
+// lldb-command:print ten
+// lldb-check:[...]$9 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$10 = -1
+// lldb-command:print ten
+// lldb-check:[...]$11 = 10
+// lldb-command:continue
+
+// TUPLE EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$12 = -1
+// lldb-command:print ten
+// lldb-check:[...]$13 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$14 = 13
+// lldb-command:print ten
+// lldb-check:[...]$15 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$16 = -1
+// lldb-command:print ten
+// lldb-check:[...]$17 = 10
+// lldb-command:continue
+
+// VEC EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$18 = -1
+// lldb-command:print ten
+// lldb-check:[...]$19 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$20 = 14
+// lldb-command:print ten
+// lldb-check:[...]$21 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$22 = -1
+// lldb-command:print ten
+// lldb-check:[...]$23 = 10
+// lldb-command:continue
+
+// REPEAT VEC EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$24 = -1
+// lldb-command:print ten
+// lldb-check:[...]$25 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$26 = 15
+// lldb-command:print ten
+// lldb-check:[...]$27 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$28 = -1
+// lldb-command:print ten
+// lldb-check:[...]$29 = 10
+// lldb-command:continue
+
+// ASSIGNMENT EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$30 = -1
+// lldb-command:print ten
+// lldb-check:[...]$31 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$32 = 16
+// lldb-command:print ten
+// lldb-check:[...]$33 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$34 = -1
+// lldb-command:print ten
+// lldb-check:[...]$35 = 10
+// lldb-command:continue
+
+
+// ARITHMETIC EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$36 = -1
+// lldb-command:print ten
+// lldb-check:[...]$37 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$38 = 17
+// lldb-command:print ten
+// lldb-check:[...]$39 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$40 = -1
+// lldb-command:print ten
+// lldb-check:[...]$41 = 10
+// lldb-command:continue
+
+// INDEX EXPRESSION
+// lldb-command:print val
+// lldb-check:[...]$42 = -1
+// lldb-command:print ten
+// lldb-check:[...]$43 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$44 = 18
+// lldb-command:print ten
+// lldb-check:[...]$45 = 10
+// lldb-command:continue
+
+// lldb-command:print val
+// lldb-check:[...]$46 = -1
+// lldb-command:print ten
+// lldb-check:[...]$47 = 10
+// lldb-command:continue
+
#![allow(unused_variable)]
#![allow(dead_assignment)]
// surrounded by struct expression
let point = Point {
x: {
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 1;
unsafe {MUT_INT = 1;};
- zzz();
+ zzz(); // #break
sentinel();
val
y: 10
};
- zzz();
+ zzz(); // #break
sentinel();
// surrounded by function call
let _ = a_function({
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 2;
unsafe {MUT_INT = 2;};
- zzz();
+ zzz(); // #break
sentinel();
val
});
- zzz();
+ zzz(); // #break
sentinel();
// surrounded by tup
let _ = ({
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 3;
unsafe {MUT_INT = 3;};
- zzz();
+ zzz(); // #break
sentinel();
val
}, 0i);
- zzz();
+ zzz(); // #break
sentinel();
// surrounded by vec
let _ = [{
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 4;
unsafe {MUT_INT = 4;};
- zzz();
+ zzz(); // #break
sentinel();
val
}, 0, 0];
- zzz();
+ zzz(); // #break
sentinel();
// surrounded by repeat vec
let _ = [{
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 5;
unsafe {MUT_INT = 5;};
- zzz();
+ zzz(); // #break
sentinel();
val
}, ..10];
- zzz();
+ zzz(); // #break
sentinel();
// assignment expression
let mut var = 0;
var = {
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 6;
unsafe {MUT_INT = 6;};
- zzz();
+ zzz(); // #break
sentinel();
val
};
- zzz();
+ zzz(); // #break
sentinel();
// arithmetic expression
var = 10 + -{
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 7;
unsafe {MUT_INT = 7;};
- zzz();
+ zzz(); // #break
sentinel();
val
} * 5;
- zzz();
+ zzz(); // #break
sentinel();
// index expression
let a_vector = [10i, ..20];
let _ = a_vector[{
- zzz();
+ zzz(); // #break
sentinel();
let val = ten + 8;
unsafe {MUT_INT = 8;};
- zzz();
+ zzz(); // #break
sentinel();
val as uint
}];
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
+// ignore-lldb
+
// compile-flags:--debuginfo=1
// Make sure functions have proper names
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print univariant->val
// gdb-check:$3 = {{-9747455}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print the_a->val
+// lldb-check:[...]$0 = TheA { x: 0, y: 8970181431921507452 }
+
+// lldb-command:print the_b->val
+// lldb-check:[...]$1 = TheB(0, 286331153, 286331153)
+
+// lldb-command:print univariant->val
+// lldb-check:[...]$2 = TheOnlyCase(-9747455)
+
#![allow(unused_variable)]
#![feature(struct_variant, managed_boxes)]
let univariant = box(GC) TheOnlyCase(-9747455);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
#![feature(managed_boxes)]
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print unique.ptr[3]->val
// gdb-check:$4 = 13
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print unique.ptr[0]->val
+// lldb-check:[...]$0 = 10
+
+// lldb-command:print unique.ptr[1]->val
+// lldb-check:[...]$1 = 11
+
+// lldb-command:print unique.ptr[2]->val
+// lldb-check:[...]$2 = 12
+
+// lldb-command:print unique.ptr[3]->val
+// lldb-check:[...]$3 = 13
+
+
#![allow(unused_variable)]
use std::gc::{Gc, GC};
let unique: Vec<Gc<i64>> = vec!(box(GC) 10, box(GC) 11, box(GC) 12, box(GC) 13);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
#![feature(managed_boxes)]
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print managed_within_unique->y->val
// gdb-check:$3 = -4
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *ordinary_unique
+// lldb-check:[...]$0 = (-1, -2)
+
+// lldb-command:print managed_within_unique->x
+// lldb-check:[...]$1 = -3
+
+// lldb-command:print managed_within_unique->y->val
+// lldb-check:[...]$2 = -4
+
#![allow(unused_variable)]
use std::gc::{GC, Gc};
let managed_within_unique = box ContainsManaged { x: -3, y: box(GC) -4i };
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Variant2(117901063)
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Variant2(117901063)
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Variant1 { x: 1799, y: 1799 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Variant1 { x: 1799, y: 1799 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Variant1 { x: 1799, y: 1799 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
#![feature(struct_variant)]
enum Enum {
impl Enum {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<Enum>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct<(u32, i32)> { x: (8888, -8888) }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct<(u32, i32)> { x: (8888, -8888) }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct<f64> { x: 1234.5 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
+
struct Struct<T> {
x: T
}
impl<T> Struct<T> {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<Struct<T>>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
struct Struct {
x: int
}
impl Struct {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
self.x + arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
self.x + arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<Struct>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
self.x + arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
struct Struct {
x: int
}
trait Trait {
fn self_by_ref(&self, arg1: int, arg2: int) -> int;
fn self_by_val(self, arg1: int, arg2: int) -> int;
- fn self_owned(~self, arg1: int, arg2: int) -> int;
+ fn self_owned(self: Box<Self>, arg1: int, arg2: int) -> int;
}
impl Trait for Struct {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
self.x + arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
self.x + arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<Struct>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
self.x + arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = TupleStruct(100, -100.5)
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = TupleStruct(100, -100.5)
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = TupleStruct(200, -200.5)
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = TupleStruct(200, -200.5)
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = TupleStruct(200, -200.5)
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
struct TupleStruct(int, f64);
impl TupleStruct {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<TupleStruct>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print abc
// gdb-check:$3 = 30303
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print abc
+// lldb-check:[...]$0 = 10101
+// lldb-command:continue
+
+// lldb-command:print abc
+// lldb-check:[...]$1 = 20202
+// lldb-command:continue
+
+// lldb-command:print abc
+// lldb-check:[...]$2 = 30303
+
#![allow(unused_variable)]
fn function_one() {
let abc = 10101i;
- zzz();
+ zzz(); // #break
}
fn function_two() {
let abc = 20202i;
- zzz();
+ zzz(); // #break
}
fn function_three() {
let abc = 30303i;
- zzz();
+ zzz(); // #break
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print c
// gdb-check:$3 = 30303
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print a
+// lldb-check:[...]$0 = 10101
+// lldb-command:continue
+
+// lldb-command:print b
+// lldb-check:[...]$1 = 20202
+// lldb-command:continue
+
+// lldb-command:print c
+// lldb-check:[...]$2 = 30303
+
#![allow(unused_variable)]
fn function_one() {
let a = 10101i;
- zzz();
+ zzz(); // #break
}
fn function_two() {
let b = 20202i;
- zzz();
+ zzz(); // #break
}
fn function_three() {
let c = 30303i;
- zzz();
+ zzz(); // #break
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$12 = 20
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:print y
+// lldb-check:[...]$1 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 10
+// lldb-command:print y
+// lldb-check:[...]$3 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = 10.5
+// lldb-command:print y
+// lldb-check:[...]$5 = 20
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$6 = true
+// lldb-command:print y
+// lldb-check:[...]$7 = 2220
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$8 = 203203.5
+// lldb-command:print y
+// lldb-check:[...]$9 = 2220
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$10 = 10.5
+// lldb-command:print y
+// lldb-check:[...]$11 = 20
+// lldb-command:continue
+
fn main() {
let x = false;
let y = true;
- zzz();
+ zzz(); // #break
sentinel();
let x = 10i;
- zzz();
+ zzz(); // #break
sentinel();
let x = 10.5f64;
let y = 20i;
- zzz();
+ zzz(); // #break
sentinel();
{
let x = true;
let y = 2220i;
- zzz();
+ zzz(); // #break
sentinel();
let x = 203203.5f64;
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// LLDB can't handle zero-sized values
+// ignore-lldb
+
// ignore-android: FIXME(#10381)
// compile-flags:-g
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print full
// gdb-check:$3 = {RUST$ENCODED$ENUM$1$Empty = {454545, 0x87654321, 9988}}
-// gdb-command:print empty->discr
+// gdb-command:print empty_gdb->discr
// gdb-check:$4 = (int *) 0x0
// gdb-command:print droid
// gdb-check:$5 = {RUST$ENCODED$ENUM$2$Void = {id = 675675, range = 10000001, internals = 0x43218765}}
-// gdb-command:print void_droid->internals
+// gdb-command:print void_droid_gdb->internals
// gdb-check:$6 = (int *) 0x0
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print some
+// lldb-check:[...]$0 = Some(&0x12345678)
+
+// lldb-command:print none
+// lldb-check:[...]$1 = None
+
+// lldb-command:print full
+// lldb-check:[...]$2 = Full(454545, &0x87654321, 9988)
+
+// lldb-command:print empty
+// lldb-check:[...]$3 = Empty
+
+// lldb-command:print droid
+// lldb-check:[...]$4 = Droid { id: 675675, range: 10000001, internals: &0x43218765 }
+
+// lldb-command:print void_droid
+// lldb-check:[...]$5 = Void
+
+
#![feature(struct_variant)]
// If a struct has exactly two variants, one of them is empty, and the other one
let full = Full(454545, unsafe { std::mem::transmute(0x87654321u) }, 9988);
- let int_val = 0i;
- let empty: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) };
+ let empty = Empty;
+ let empty_gdb: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) };
let droid = Droid {
id: 675675,
internals: unsafe { std::mem::transmute(0x43218765u) }
};
- let void_droid: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) };
+ let void_droid = Void;
+ let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) };
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print deeplyNested
// gdb-check:$8 = {a = {a = 1, b = {x = 2, y = 3, z = 4}, c = 5, d = {x = 6, y = 7, z = 8}}, b = {a = 9, b = {x = 10, y = 11, z = 12}, c = {x = 13, y = 14, z = 15}, d = 16}, c = {a = 17, b = {x = 18, y = 19, z = 20}, c = 21, d = {x = 22, y = 23, z = 24}}, d = {a = 25, b = {x = 26, y = 27, z = 28}, c = 29, d = {x = 30, y = 31, z = 32}}, e = {a = 33, b = {x = 34, y = 35, z = 36}, c = {x = 37, y = 38, z = 39}, d = 40}, f = {a = 41, b = {x = 42, y = 43, z = 44}, c = 45, d = {x = 46, y = 47, z = 48}}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print packed
+// lldb-check:[...]$0 = Packed { x: 123, y: 234, z: 345 }
+
+// lldb-command:print packedInPacked
+// lldb-check:[...]$1 = PackedInPacked { a: 1111, b: Packed { x: 2222, y: 3333, z: 4444 }, c: 5555, d: Packed { x: 6666, y: 7777, z: 8888 } }
+
+// lldb-command:print packedInUnpacked
+// lldb-check:[...]$2 = PackedInUnpacked { a: -1111, b: Packed { x: -2222, y: -3333, z: -4444 }, c: -5555, d: Packed { x: -6666, y: -7777, z: -8888 } }
+
+// lldb-command:print unpackedInPacked
+// lldb-check:[...]$3 = UnpackedInPacked { a: 987, b: Unpacked { x: 876, y: 765, z: 654 }, c: Unpacked { x: 543, y: 432, z: 321 }, d: 210 }
+
+// lldb-command:print packedInPackedWithDrop
+// lldb-check:[...]$4 = PackedInPackedWithDrop { a: 11, b: Packed { x: 22, y: 33, z: 44 }, c: 55, d: Packed { x: 66, y: 77, z: 88 } }
+
+// lldb-command:print packedInUnpackedWithDrop
+// lldb-check:[...]$5 = PackedInUnpackedWithDrop { a: -11, b: Packed { x: -22, y: -33, z: -44 }, c: -55, d: Packed { x: -66, y: -77, z: -88 } }
+
+// lldb-command:print unpackedInPackedWithDrop
+// lldb-check:[...]$6 = UnpackedInPackedWithDrop { a: 98, b: Unpacked { x: 87, y: 76, z: 65 }, c: Unpacked { x: 54, y: 43, z: 32 }, d: 21 }
+
+// lldb-command:print deeplyNested
+// lldb-check:[...]$7 = DeeplyNested { a: PackedInPacked { a: 1, b: Packed { x: 2, y: 3, z: 4 }, c: 5, d: Packed { x: 6, y: 7, z: 8 } }, b: UnpackedInPackedWithDrop { a: 9, b: Unpacked { x: 10, y: 11, z: 12 }, c: Unpacked { x: 13, y: 14, z: 15 }, d: 16 }, c: PackedInUnpacked { a: 17, b: Packed { x: 18, y: 19, z: 20 }, c: 21, d: Packed { x: 22, y: 23, z: 24 } }, d: PackedInUnpackedWithDrop { a: 25, b: Packed { x: 26, y: 27, z: 28 }, c: 29, d: Packed { x: 30, y: 31, z: 32 } }, e: UnpackedInPacked { a: 33, b: Unpacked { x: 34, y: 35, z: 36 }, c: Unpacked { x: 37, y: 38, z: 39 }, d: 40 }, f: PackedInPackedWithDrop { a: 41, b: Packed { x: 42, y: 43, z: 44 }, c: 45, d: Packed { x: 46, y: 47, z: 48 } } }
+
+
#![allow(unused_variable)]
#[packed]
}
};
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print sizeof(packedInPacked)
// gdb-check:$6 = 40
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print packed
+// lldb-check:[...]$0 = Packed { x: 123, y: 234, z: 345 }
+
+// lldb-command:print packedInPacked
+// lldb-check:[...]$1 = PackedInPacked { a: 1111, b: Packed { x: 2222, y: 3333, z: 4444 }, c: 5555, d: Packed { x: 6666, y: 7777, z: 8888 } }
+
+// lldb-command:print packedInUnpacked
+// lldb-check:[...]$2 = PackedInUnpacked { a: -1111, b: Packed { x: -2222, y: -3333, z: -4444 }, c: -5555, d: Packed { x: -6666, y: -7777, z: -8888 } }
+
+// lldb-command:print unpackedInPacked
+// lldb-check:[...]$3 = UnpackedInPacked { a: 987, b: Unpacked { x: 876, y: 765, z: 654, w: 543 }, c: Unpacked { x: 432, y: 321, z: 210, w: 109 }, d: -98 }
+
+// lldb-command:print sizeof(packed)
+// lldb-check:[...]$4 = 14
+
+// lldb-command:print sizeof(packedInPacked)
+// lldb-check:[...]$5 = 40
+
#![allow(unused_variable)]
#[packed]
d: -98
};
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
+// ignore-lldb
+
// compile-flags:-g
// gdb-command:run
// ignore-tidy-linelength
// ignore-android: FIXME(#10381)
+// ignore-lldb
#![feature(managed_boxes)]
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$15 = -10
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = -2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct { x: 100 }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct { x: 200 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10
+// lldb-command:continue
+
+
struct Struct {
x: int
}
trait Trait {
fn self_by_ref(&self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
fn self_by_val(self, arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
- fn self_owned(~self, arg1: int, arg2: int) -> int {
- zzz();
+ fn self_owned(self: Box<Self>, arg1: int, arg2: int) -> int {
+ zzz(); // #break
arg1 + arg2
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$1 = {x = 987}
// gdb-command:print arg1
// gdb-check:$2 = -1
-// gdb-command:print/d arg2
-// gdb-check:$3 = -2
+// gdb-command:print arg2
+// gdb-check:$3 = 2
// gdb-command:continue
// STACK BY VAL
// gdb-check:$15 = -10.5
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STACK BY REF
+// lldb-command:print *self
+// lldb-check:[...]$0 = Struct { x: 987 }
+// lldb-command:print arg1
+// lldb-check:[...]$1 = -1
+// lldb-command:print arg2
+// lldb-check:[...]$2 = 2
+// lldb-command:continue
+
+// STACK BY VAL
+// lldb-command:print self
+// lldb-check:[...]$3 = Struct { x: 987 }
+// lldb-command:print arg1
+// lldb-check:[...]$4 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$5 = -4
+// lldb-command:continue
+
+// OWNED BY REF
+// lldb-command:print *self
+// lldb-check:[...]$6 = Struct { x: 879 }
+// lldb-command:print arg1
+// lldb-check:[...]$7 = -5
+// lldb-command:print arg2
+// lldb-check:[...]$8 = -6
+// lldb-command:continue
+
+// OWNED BY VAL
+// lldb-command:print self
+// lldb-check:[...]$9 = Struct { x: 879 }
+// lldb-command:print arg1
+// lldb-check:[...]$10 = -7
+// lldb-command:print arg2
+// lldb-check:[...]$11 = -8
+// lldb-command:continue
+
+// OWNED MOVED
+// lldb-command:print *self
+// lldb-check:[...]$12 = Struct { x: 879 }
+// lldb-command:print arg1
+// lldb-check:[...]$13 = -9
+// lldb-command:print arg2
+// lldb-check:[...]$14 = -10.5
+// lldb-command:continue
+
+
struct Struct {
x: int
}
trait Trait {
fn self_by_ref<T>(&self, arg1: int, arg2: T) -> int {
- zzz();
+ zzz(); // #break
arg1
}
fn self_by_val<T>(self, arg1: int, arg2: T) -> int {
- zzz();
+ zzz(); // #break
arg1
}
- fn self_owned<T>(~self, arg1: int, arg2: T) -> int {
- zzz();
+ fn self_owned<T>(self: Box<Self>, arg1: int, arg2: T) -> int {
+ zzz(); // #break
arg1
}
}
fn main() {
let stack = Struct { x: 987 };
- let _ = stack.self_by_ref(-1, -2_i8);
+ let _ = stack.self_by_ref(-1, 2_u16);
let _ = stack.self_by_val(-3, -4_i16);
let owned = box Struct { x: 879 };
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$6 = 20
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:print y
+// lldb-check:[...]$1 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 10
+// lldb-command:print y
+// lldb-check:[...]$3 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = 10.5
+// lldb-command:print y
+// lldb-check:[...]$5 = 20
+// lldb-command:continue
+
fn a_function(x: bool, y: bool) {
- zzz();
+ zzz(); // #break
sentinel();
let x = 10i;
- zzz();
+ zzz(); // #break
sentinel();
let x = 10.5f64;
let y = 20i;
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$6 = 20
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:print y
+// lldb-check:[...]$1 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 10
+// lldb-command:print y
+// lldb-check:[...]$3 = true
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = 10.5
+// lldb-command:print y
+// lldb-check:[...]$5 = 20
+// lldb-command:continue
+
fn main() {
let x = false;
let y = true;
- zzz();
+ zzz(); // #break
sentinel();
let x = 10i;
- zzz();
+ zzz(); // #break
sentinel();
let x = 10.5f64;
let y = 20i;
- zzz();
+ zzz(); // #break
sentinel();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// Need a fix for LLDB first...
+// ignore-lldb
+
// ignore-android: FIXME(#10381)
// compile-flags:-g
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:continue
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print x
+// lldb-check:[...]$0 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$1 = false
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$2 = 10
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$3 = 10
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$4 = 10.5
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$5 = 10
+// lldb-command:continue
+
+// lldb-command:print x
+// lldb-check:[...]$6 = false
+// lldb-command:continue
+
fn main() {
let x = false;
- zzz();
+ zzz(); // #break
sentinel();
{
- zzz();
+ zzz(); // #break
sentinel();
let x = 10i;
- zzz();
+ zzz(); // #break
sentinel();
{
- zzz();
+ zzz(); // #break
sentinel();
let x = 10.5f64;
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
- zzz();
+ zzz(); // #break
sentinel();
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-check:$19 = {a = 10019, b = -10020, x = -10016, y = -10017.5, z = 10018}
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print no_padding16
+// lldb-check:[...]$0 = NoPadding16 { x: 10000, y: -10001 }
+
+// lldb-command:print no_padding32
+// lldb-check:[...]$1 = NoPadding32 { x: -10002, y: -10003.5, z: 10004 }
+
+// lldb-command:print no_padding64
+// lldb-check:[...]$2 = NoPadding64 { x: -10005.5, y: 10006, z: 10007 }
+
+// lldb-command:print no_padding163264
+// lldb-check:[...]$3 = NoPadding163264 { a: -10008, b: 10009, c: 10010, d: 10011 }
+
+// lldb-command:print internal_padding
+// lldb-check:[...]$4 = InternalPadding { x: 10012, y: -10013 }
+
+// lldb-command:print padding_at_end
+// lldb-check:[...]$5 = PaddingAtEnd { x: -10014, y: 10015 }
+
#![feature(struct_inherit)];
#![allow(unused_variable)];
#![allow(dead_code)];
PADDING_AT_END.y = 28;
}
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:print 'simple-tuple::PADDING_AT_END'
// gdb-check:$21 = {116, 117}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print/d noPadding8
+// lldb-check:[...]$0 = (-100, 100)
+// lldb-command:print noPadding16
+// lldb-check:[...]$1 = (0, 1, 2)
+// lldb-command:print noPadding32
+// lldb-check:[...]$2 = (3, 4.5, 5)
+// lldb-command:print noPadding64
+// lldb-check:[...]$3 = (6, 7.5, 8)
+
+// lldb-command:print internalPadding1
+// lldb-check:[...]$4 = (9, 10)
+// lldb-command:print internalPadding2
+// lldb-check:[...]$5 = (11, 12, 13, 14)
+
+// lldb-command:print paddingAtEnd
+// lldb-check:[...]$6 = (15, 16)
+
#![allow(unused_variable)]
#![allow(dead_code)]
PADDING_AT_END = (116, 117);
}
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$5 = 5
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// STRUCT
+// lldb-command:print arg1
+// lldb-check:[...]$0 = 1
+// lldb-command:print arg2
+// lldb-check:[...]$1 = 2
+// lldb-command:continue
+
+// ENUM
+// lldb-command:print arg1
+// lldb-check:[...]$2 = -3
+// lldb-command:print arg2
+// lldb-check:[...]$3 = 4.5
+// lldb-command:print arg3
+// lldb-check:[...]$4 = 5
+// lldb-command:continue
+
#![feature(struct_variant)]
struct Struct {
impl Struct {
fn static_method(arg1: int, arg2: int) -> int {
- zzz();
+ zzz(); // #break
arg1 + arg2
}
}
impl Enum {
fn static_method(arg1: int, arg2: f64, arg3: uint) -> int {
- zzz();
+ zzz(); // #break
arg1
}
}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print union on
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print univariant
// gdb-check:$3 = {{{x = 123, y = 456, z = 789}}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print case1
+// lldb-check:[...]$0 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 })
+// lldb-command:print case2
+// lldb-check:[...]$1 = Case2(0, 1229782938247303441, 4369)
+
+// lldb-command:print univariant
+// lldb-check:[...]$2 = TheOnlyCase(Struct { x: 123, y: 456, z: 789 })
+
#![allow(unused_variable)]
struct Struct {
let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 });
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+// ignore-tidy-linelength
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print padding_at_end_parent
// gdb-check:$3 = {x = {x = 10, y = 11}, y = {x = 12, y = 13}, z = {x = 14, y = 15}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print three_simple_structs
+// lldb-check:[...]$0 = ThreeSimpleStructs { x: Simple { x: 1 }, y: Simple { x: 2 }, z: Simple { x: 3 } }
+
+// lldb-command:print internal_padding_parent
+// lldb-check:[...]$1 = InternalPaddingParent { x: InternalPadding { x: 4, y: 5 }, y: InternalPadding { x: 6, y: 7 }, z: InternalPadding { x: 8, y: 9 } }
+
+// lldb-command:print padding_at_end_parent
+// lldb-check:[...]$2 = PaddingAtEndParent { x: PaddingAtEnd { x: 10, y: 11 }, y: PaddingAtEnd { x: 12, y: 13 }, z: PaddingAtEnd { x: 14, y: 15 } }
+
+// lldb-command:print mixed
+// lldb-check:[...]$3 = Mixed { x: PaddingAtEnd { x: 16, y: 17 }, y: InternalPadding { x: 18, y: 19 }, z: Simple { x: 20 }, w: 21 }
+
+// lldb-command:print bag
+// lldb-check:[...]$4 = Bag { x: Simple { x: 22 } }
+
+// lldb-command:print bag_in_bag
+// lldb-check:[...]$5 = BagInBag { x: Bag { x: Simple { x: 23 } } }
+
+// lldb-command:print tjo
+// lldb-check:[...]$6 = ThatsJustOverkill { x: BagInBag { x: Bag { x: Simple { x: 24 } } } }
+
+// lldb-command:print tree
+// lldb-check:[...]$7 = Tree { x: Simple { x: 25 }, y: InternalPaddingParent { x: InternalPadding { x: 26, y: 27 }, y: InternalPadding { x: 28, y: 29 }, z: InternalPadding { x: 30, y: 31 } }, z: BagInBag { x: Bag { x: Simple { x: 32 } } } }
+
#![allow(unused_variable)]
struct Simple {
}
};
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print union on
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print univariant
// gdb-check:$4 = {{a = -1}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print case1
+// lldb-check:[...]$0 = Case1 { a: 0, b: 31868, c: 31868, d: 31868, e: 31868 }
+
+// lldb-command:print case2
+// lldb-check:[...]$1 = Case2 { a: 0, b: 286331153, c: 286331153 }
+
+// lldb-command:print case3
+// lldb-check:[...]$2 = Case3 { a: 0, b: 6438275382588823897 }
+
+// lldb-command:print univariant
+// lldb-check:[...]$3 = TheOnlyCase { a: -1 }
+
#![allow(unused_variable)]
#![feature(struct_variant)]
let univariant = TheOnlyCase { a: -1 };
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print nested
// gdb-check:$4 = {a = {a = {x = 7890, y = 9870}}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+// lldb-command:print simple
+// lldb-check:[...]$0 = WithDestructor { x: 10, y: 20 }
+
+// lldb-command:print noDestructor
+// lldb-check:[...]$1 = NoDestructorGuarded { a: NoDestructor { x: 10, y: 20 }, guard: -1 }
+
+// lldb-command:print withDestructor
+// lldb-check:[...]$2 = WithDestructorGuarded { a: WithDestructor { x: 10, y: 20 }, guard: -1 }
+
+// lldb-command:print nested
+// lldb-check:[...]$3 = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } }
+
#![allow(unused_variable)]
struct NoDestructor {
// <-------NestedOuter-------->
let nested = NestedOuter { a: NestedInner { a: WithDestructor { x: 7890, y: 9870 } } };
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
-some text to include in another file as string 1
+some text to include in another file as string 1
\ No newline at end of file
-some text to include in another file as string 2
+some text to include in another file as string 2.
\ No newline at end of file
-some text to include in another file as string 3
+some text to include in another file as string 3..
\ No newline at end of file
// except according to those terms.
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:continue
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print no_padding1
+// lldb-check:[...]$0 = { x = (0, 1) y = 2 z = (3, 4, 5) }
+// lldb-command:print no_padding2
+// lldb-check:[...]$1 = { x = (6, 7) y = { = (8, 9) = 10 } }
+
+// lldb-command:print tuple_internal_padding
+// lldb-check:[...]$2 = { x = (11, 12) y = (13, 14) }
+// lldb-command:print struct_internal_padding
+// lldb-check:[...]$3 = { x = (15, 16) y = (17, 18) }
+// lldb-command:print both_internally_padded
+// lldb-check:[...]$4 = { x = (19, 20, 21) y = (22, 23) }
+
+// lldb-command:print single_tuple
+// lldb-check:[...]$5 = { x = (24, 25, 26) }
+
+// lldb-command:print tuple_padded_at_end
+// lldb-check:[...]$6 = { x = (27, 28) y = (29, 30) }
+// lldb-command:print struct_padded_at_end
+// lldb-check:[...]$7 = { x = (31, 32) y = (33, 34) }
+// lldb-command:print both_padded_at_end
+// lldb-check:[...]$8 = { x = (35, 36, 37) y = (38, 39) }
+
+// lldb-command:print mixed_padding
+// lldb-check:[...]$9 = { x = { = (40, 41, 42) = (43, 44) } y = (45, 46, 47, 48) }
+
struct Struct {
x: int
}
trait Trait {
fn generic_static_default_method<T>(arg1: int, arg2: T) -> int {
- zzz();
+ zzz(); // #break
arg1
}
}
// ignore-android: FIXME(#10381)
+// ignore-lldb
+
// compile-flags:-g
// gdb-command:run
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print padding_at_end2
// gdb-check:$7 = {{21, 22}, 23}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print no_padding1
+// lldb-check:[...]$0 = ((0, 1), 2, 3)
+// lldb-command:print no_padding2
+// lldb-check:[...]$1 = (4, (5, 6), 7)
+// lldb-command:print no_padding3
+// lldb-check:[...]$2 = (8, 9, (10, 11))
+
+// lldb-command:print internal_padding1
+// lldb-check:[...]$3 = (12, (13, 14))
+// lldb-command:print internal_padding2
+// lldb-check:[...]$4 = (15, (16, 17))
+
+// lldb-command:print padding_at_end1
+// lldb-check:[...]$5 = (18, (19, 20))
+// lldb-command:print padding_at_end2
+// lldb-check:[...]$6 = ((21, 22), 23)
+
#![allow(unused_variable)]
fn main() {
let padding_at_end1: (i32, (i32, i16)) = (18, (19, 20));
let padding_at_end2: ((i32, i16), i32) = ((21, 22), 23);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-check:$6 = {-10014, 10015}
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print no_padding16
+// lldb-check:[...]$0 = NoPadding16(10000, -10001)
+
+// lldb-command:print no_padding32
+// lldb-check:[...]$1 = NoPadding32(-10002, -10003.5, 10004)
+
+// lldb-command:print no_padding64
+// lldb-check:[...]$2 = NoPadding64(-10005.5, 10006, 10007)
+
+// lldb-command:print no_padding163264
+// lldb-check:[...]$3 = NoPadding163264(-10008, 10009, 10010, 10011)
+
+// lldb-command:print internal_padding
+// lldb-check:[...]$4 = InternalPadding(10012, -10013)
+
+// lldb-command:print padding_at_end
+// lldb-check:[...]$5 = PaddingAtEnd(-10014, 10015)
+
// This test case mainly makes sure that no field names are generated for tuple structs (as opposed
// to all fields having the name "<unnamed_field>"). Otherwise they are handled the same a normal
// structs.
let internal_padding = InternalPadding(10012, -10013);
let padding_at_end = PaddingAtEnd(-10014, 10015);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print union on
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print univariant
// gdb-check:$4 = {{-1}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print case1
+// lldb-check:[...]$0 = Case1(0, 31868, 31868, 31868, 31868)
+
+// lldb-command:print case2
+// lldb-check:[...]$1 = Case2(0, 286331153, 286331153)
+
+// lldb-command:print case3
+// lldb-check:[...]$2 = Case3(0, 6438275382588823897)
+
+// lldb-command:print univariant
+// lldb-check:[...]$3 = TheOnlyCase(-1)
+
#![allow(unused_variable)]
// The first element is to ensure proper alignment, irrespective of the machines word size. Since
let univariant = TheOnlyCase(-1);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *univariant
// gdb-check:$3 = {{123234}}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print *the_a
+// lldb-check:[...]$0 = TheA { x: 0, y: 8970181431921507452 }
+
+// lldb-command:print *the_b
+// lldb-check:[...]$1 = TheB(0, 286331153, 286331153)
+
+// lldb-command:print *univariant
+// lldb-check:[...]$2 = TheOnlyCase(123234)
+
#![allow(unused_variable)]
#![feature(struct_variant)]
let univariant = box TheOnlyCase(123234);
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-check:$14 = 8
// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print variable
+// lldb-check:[...]$0 = 1
+// lldb-command:print constant
+// lldb-check:[...]$1 = 2
+// lldb-command:print a_struct
+// lldb-check:[...]$2 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *struct_ref
+// lldb-check:[...]$3 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *owned
+// lldb-check:[...]$4 = 6
+// lldb-command:print managed->val
+// lldb-check:[...]$5 = 7
+// lldb-command:print closure_local
+// lldb-check:[...]$6 = 8
+// lldb-command:continue
+
+// lldb-command:print variable
+// lldb-check:[...]$7 = 1
+// lldb-command:print constant
+// lldb-check:[...]$8 = 2
+// lldb-command:print a_struct
+// lldb-check:[...]$9 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *struct_ref
+// lldb-check:[...]$10 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *owned
+// lldb-check:[...]$11 = 6
+// lldb-command:print managed->val
+// lldb-check:[...]$12 = 7
+// lldb-command:print closure_local
+// lldb-check:[...]$13 = 8
+// lldb-command:continue
+
#![feature(managed_boxes)]
#![allow(unused_variable)]
let closure_local = 8;
let nested_closure = || {
- zzz();
+ zzz(); // #break
variable = constant + a_struct.a + struct_ref.a + *owned + *managed + closure_local;
};
- zzz();
+ zzz(); // #break
nested_closure();
};
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print *owned
// gdb-check:$3 = 5
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print constant
+// lldb-check:[...]$0 = 1
+// lldb-command:print a_struct
+// lldb-check:[...]$1 = Struct { a: -2, b: 3.5, c: 4 }
+// lldb-command:print *owned
+// lldb-check:[...]$2 = 5
+
#![allow(unused_variable)]
struct Struct {
let owned = box 5;
let closure: proc() = proc() {
- zzz();
+ zzz(); // #break
do_something(&constant, &a_struct.a, owned);
};
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:finish
// gdb-command:print managed->val
// gdb-check:$6 = 7
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print variable
+// lldb-check:[...]$0 = 1
+// lldb-command:print constant
+// lldb-check:[...]$1 = 2
+// lldb-command:print a_struct
+// lldb-check:[...]$2 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *struct_ref
+// lldb-check:[...]$3 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-command:print *owned
+// lldb-check:[...]$4 = 6
+// lldb-command:print managed->val
+// lldb-check:[...]$5 = 7
+
#![feature(managed_boxes)]
#![allow(unused_variable)]
let managed = box(GC) 7;
let closure = || {
- zzz();
+ zzz(); // #break
variable = constant + a_struct.a + struct_ref.a + *owned + *managed;
};
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print *((int64_t[2]*)('vec-slices::MUT_VECT_SLICE'.data_ptr))
// gdb-check:$15 = {64, 65}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+
+// lldb-command:print empty
+// lldb-check:[...]$0 = &[]
+
+// lldb-command:print singleton
+// lldb-check:[...]$1 = &[1]
+
+// lldb-command:print multiple
+// lldb-check:[...]$2 = &[2, 3, 4, 5]
+
+// lldb-command:print slice_of_slice
+// lldb-check:[...]$3 = &[3, 4]
+
+// lldb-command:print padded_tuple
+// lldb-check:[...]$4 = &[(6, 7), (8, 9)]
+
+// lldb-command:print padded_struct
+// lldb-check:[...]$5 = &[AStruct { x: 10, y: 11, z: 12 }, AStruct { x: 13, y: 14, z: 15 }]
+
#![allow(unused_variable)]
struct AStruct {
MUT_VECT_SLICE = VECT_SLICE;
}
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
// ignore-android: FIXME(#10381)
// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+
// gdb-command:set print pretty off
// gdb-command:rbreak zzz
// gdb-command:run
// gdb-command:print vec::VECT
// gdb-check:$2 = {4, 5, 6}
+
+// === LLDB TESTS ==================================================================================
+
+// lldb-command:run
+// lldb-command:print a
+// lldb-check:[...]$0 = [1, 2, 3]
+
#![allow(unused_variable)]
static mut VECT: [i32, ..3] = [1, 2, 3];
VECT[2] = 6;
}
- zzz();
+ zzz(); // #break
}
fn zzz() {()}
trait double {
- fn double(~self) -> uint;
+ fn double(self: Box<Self>) -> uint;
}
impl double for uint {
- fn double(~self) -> uint { *self * 2u }
+ fn double(self: Box<uint>) -> uint { *self * 2u }
}
pub fn main() {
trait double {
- fn double(~self) -> uint;
+ fn double(self: Box<Self>) -> uint;
}
impl double for Box<uint> {
- fn double(~self) -> uint { **self * 2u }
+ fn double(self: Box<Box<uint>>) -> uint { **self * 2u }
}
pub fn main() {
// except according to those terms.
trait double {
- fn double(~self) -> uint;
+ fn double(self: Box<Self>) -> uint;
}
impl double for uint {
- fn double(~self) -> uint { *self * 2u }
+ fn double(self: Box<uint>) -> uint { *self * 2u }
}
pub fn main() {
// except according to those terms.
trait double {
- fn double(~self) -> uint;
+ fn double(self: Box<Self>) -> uint;
}
impl double for uint {
- fn double(~self) -> uint { *self * 2u }
+ fn double(self: Box<uint>) -> uint { *self * 2u }
}
pub fn main() {
trait Foo {
- fn f(~self);
+ fn f(self: Box<Self>);
}
struct S {
}
impl Foo for S {
- fn f(~self) {
+ fn f(self: Box<S>) {
assert_eq!(self.x, 3);
}
}
}
impl thing {
- pub fn bar(~self) -> int { self.x.a }
+ pub fn bar(self: Box<thing>) -> int { self.x.a }
pub fn quux(&self) -> int { self.x.a }
pub fn baz<'a>(&'a self) -> &'a A { &self.x }
pub fn spam(self) -> int { self.x.a }
trait Foo {
- fn foo(~self) { bar(self as Box<Foo>); }
+ fn foo(self: Box<Self>) { bar(self as Box<Foo>); }
}
fn bar(_b: Box<Foo>) { }
trait FooTrait {
- fn foo(~self) -> uint;
+ fn foo(self: Box<Self>) -> uint;
}
struct BarStruct {
}
impl FooTrait for BarStruct {
- fn foo(~self) -> uint {
+ fn foo(self: Box<BarStruct>) -> uint {
self.x
}
}
self
}
- fn change_again(mut ~self) -> Box<Self> {
+ fn change_again(mut self: Box<Self>) -> Box<Self> {
self.set_to(45);
self
}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <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 std::owned::Box;
+
+struct Foo {
+ f: int,
+}
+
+impl Foo {
+ fn foo(self: Foo, x: int) -> int {
+ self.f + x
+ }
+ fn bar(self: &Foo, x: int) -> int {
+ self.f + x
+ }
+ fn baz(self: Box<Foo>, x: int) -> int {
+ self.f + x
+ }
+}
+
+struct Bar<T> {
+ f: T,
+}
+
+impl<T> Bar<T> {
+ fn foo(self: Bar<T>, x: int) -> int {
+ x
+ }
+ fn bar<'a>(self: &'a Bar<T>, x: int) -> int {
+ x
+ }
+ fn baz(self: Bar<T>, x: int) -> int {
+ x
+ }
+}
+
+fn main() {
+ let foo = box Foo {
+ f: 1,
+ };
+ println!("{} {} {}", foo.foo(2), foo.bar(2), foo.baz(2));
+ let bar = box Bar {
+ f: 1,
+ };
+ println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
+ let bar: Box<Bar<int>> = bar;
+ println!("{} {} {}", bar.foo(2), bar.bar(2), bar.baz(2));
+}
+
}
trait Changer {
- fn change(mut ~self) -> Box<Self>;
+ fn change(mut self: Box<Self>) -> Box<Self>;
}
impl Changer for X {
- fn change(mut ~self) -> Box<X> {
+ fn change(mut self: Box<X>) -> Box<X> {
self.a = 55;
self
}