Skip to content

tutorial: remove duplicate link references. #7845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
12 changes: 1 addition & 11 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ supported build environments that are most likely to work.
> know.

[bug-3319]: https://github.com/mozilla/rust/issues/3319
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust

To build from source you will also need the following prerequisite
packages:
Expand Down Expand Up @@ -118,7 +118,6 @@ API-documentation tool; `rustpkg`, the Rust package manager;
`rusti`, the Rust REPL; and `rust`, a tool which acts both as a unified
interface for them, and for a few common command line scenarios.

[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
[tarball]: http://static.rust-lang.org/dist/rust-0.7.tar.gz
[win-exe]: http://static.rust-lang.org/dist/rust-0.7-install.exe

Expand Down Expand Up @@ -410,8 +409,6 @@ println(fmt!("what is this thing: %?", mystery_object));

You can define your own syntax extensions with the macro system. For details, see the [macro tutorial][macros].

[macros]: tutorial-macros.html

# Control structures

## Conditionals
Expand Down Expand Up @@ -1512,8 +1509,6 @@ closures, but they also own them: that is, no other code can access
them. Owned closures are used in concurrent code, particularly
for spawning [tasks][tasks].

[tasks]: tutorial-tasks.html

## Closure compatibility

Rust closures have a convenient subtyping property: you can pass any kind of
Expand Down Expand Up @@ -2534,9 +2529,4 @@ There is further documentation on the [wiki].
[ffi]: tutorial-ffi.html

[wiki]: https://github.com/mozilla/rust/wiki/Docs
[unit testing]: https://github.com/mozilla/rust/wiki/Doc-unit-testing
[rustdoc]: https://github.com/mozilla/rust/wiki/Doc-using-rustdoc
[cargo]: https://github.com/mozilla/rust/wiki/Doc-using-cargo-to-manage-packages
[attributes]: https://github.com/mozilla/rust/wiki/Doc-attributes

[pound-rust]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust
4 changes: 2 additions & 2 deletions src/libextra/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ impl<V> SmallIntMap<V> {
/// Visit all key-value pairs in reverse order
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
for uint::range_rev(self.v.len(), 0) |i| {
match self.v[i - 1] {
Some(ref elt) => if !it(i - 1, elt) { return false; },
match self.v[i] {
Some(ref elt) => if !it(i, elt) { return false; },
None => ()
}
}
Expand Down
58 changes: 53 additions & 5 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,58 @@ pub fn classify(e: &expr,
pub fn lookup_const(tcx: ty::ctxt, e: &expr) -> Option<@expr> {
match tcx.def_map.find(&e.id) {
Some(&ast::def_static(def_id, false)) => lookup_const_by_id(tcx, def_id),
Some(&ast::def_variant(enum_def, variant_def)) => lookup_variant_by_id(tcx,
enum_def,
variant_def),
_ => None
}
}

pub fn lookup_variant_by_id(tcx: ty::ctxt,
enum_def: ast::def_id,
variant_def: ast::def_id)
-> Option<@expr> {
fn variant_expr(variants: &[ast::variant], id: ast::node_id) -> Option<@expr> {
for variants.iter().advance |variant| {
if variant.node.id == id {
return variant.node.disr_expr;
}
}
None
}

if ast_util::is_local(enum_def) {
match tcx.items.find(&enum_def.node) {
None => None,
Some(&ast_map::node_item(it, _)) => match it.node {
item_enum(ast::enum_def { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node)
}
_ => None
},
Some(_) => None
}
} else {
let maps = astencode::Maps {
root_map: @mut HashMap::new(),
method_map: @mut HashMap::new(),
vtable_map: @mut HashMap::new(),
write_guard_map: @mut HashSet::new(),
capture_map: @mut HashMap::new()
};
match csearch::maybe_get_item_ast(tcx, enum_def,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
csearch::found(ast::ii_item(item)) => match item.node {
item_enum(ast::enum_def { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node)
}
_ => None
},
_ => None
}
}
}

pub fn lookup_const_by_id(tcx: ty::ctxt,
def_id: ast::def_id)
-> Option<@expr> {
Expand Down Expand Up @@ -237,13 +285,13 @@ pub enum const_val {
}

pub fn eval_const_expr(tcx: middle::ty::ctxt, e: &expr) -> const_val {
match eval_const_expr_partial(tcx, e) {
match eval_const_expr_partial(&tcx, e) {
Ok(r) => r,
Err(s) => tcx.sess.span_fatal(e.span, s)
}
}

pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &expr)
-> Result<const_val, ~str> {
use middle::ty;
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
Expand Down Expand Up @@ -360,7 +408,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
}
}
expr_cast(base, _) => {
let ety = ty::expr_ty(tcx, e);
let ety = tcx.expr_ty(e);
let base = eval_const_expr_partial(tcx, base);
match /*bad*/copy base {
Err(_) => base,
Expand Down Expand Up @@ -390,8 +438,8 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
}
}
expr_path(_) => {
match lookup_const(tcx, e) {
Some(actual_e) => eval_const_expr_partial(tcx, actual_e),
match lookup_const(tcx.ty_ctxt(), e) {
Some(actual_e) => eval_const_expr_partial(&tcx.ty_ctxt(), actual_e),
None => Err(~"Non-constant path in constant expr")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
"explicit copy requires a copyable argument");
}
expr_repeat(element, count_expr, _) => {
let count = ty::eval_repeat_count(cx.tcx, count_expr);
let count = ty::eval_repeat_count(&cx.tcx, count_expr);
if count > 1 {
let element_ty = ty::expr_ty(cx.tcx, element);
check_copy(cx, element_ty, element.span,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub fn write_content(bcx: block,
return expr::trans_into(bcx, element, Ignore);
}
SaveIn(lldest) => {
let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
let count = ty::eval_repeat_count(&bcx.tcx(), count_expr);
if count == 0 {
return bcx;
}
Expand Down Expand Up @@ -509,7 +509,7 @@ pub fn elements_required(bcx: block, content_expr: &ast::expr) -> uint {
},
ast::expr_vec(ref es, _) => es.len(),
ast::expr_repeat(_, count_expr, _) => {
ty::eval_repeat_count(bcx.tcx(), count_expr)
ty::eval_repeat_count(&bcx.tcx(), count_expr)
}
_ => bcx.tcx().sess.span_bug(content_expr.span,
"Unexpected evec content")
Expand Down
47 changes: 31 additions & 16 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4230,42 +4230,57 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
return t_norm;
}

pub trait ExprTyProvider {
pub fn expr_ty(&self, ex: &ast::expr) -> t;
pub fn ty_ctxt(&self) -> ctxt;
}

impl ExprTyProvider for ctxt {
pub fn expr_ty(&self, ex: &ast::expr) -> t {
expr_ty(*self, ex)
}

pub fn ty_ctxt(&self) -> ctxt {
*self
}
}

// Returns the repeat count for a repeating vector expression.
pub fn eval_repeat_count(tcx: ctxt, count_expr: &ast::expr) -> uint {
pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::expr) -> uint {
match const_eval::eval_const_expr_partial(tcx, count_expr) {
Ok(ref const_val) => match *const_val {
const_eval::const_int(count) => if count < 0 {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found negative integer");
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found negative integer");
return 0;
} else {
return count as uint
},
const_eval::const_uint(count) => return count as uint,
const_eval::const_float(count) => {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found float");
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found float");
return count as uint;
}
const_eval::const_str(_) => {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found string");
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found string");
return 0;
}
const_eval::const_bool(_) => {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found boolean");
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found boolean");
return 0;
}
},
Err(*) => {
tcx.sess.span_err(count_expr.span,
"expected constant integer for repeat count \
but found variable");
tcx.ty_ctxt().sess.span_err(count_expr.span,
"expected constant integer for repeat count \
but found variable");
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Copy + 'static>(
}
}
ast::ty_fixed_length_vec(ref a_mt, e) => {
match const_eval::eval_const_expr_partial(tcx, e) {
match const_eval::eval_const_expr_partial(&tcx, e) {
Ok(ref r) => {
match *r {
const_eval::const_int(i) =>
Expand Down
20 changes: 15 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use middle::pat_util;
use middle::lint::unreachable_code;
use middle::ty::{FnSig, VariantInfo_};
use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty};
use middle::ty::{substs, param_ty};
use middle::ty::{substs, param_ty, ExprTyProvider};
use middle::ty;
use middle::typeck::astconv::AstConv;
use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
Expand Down Expand Up @@ -290,6 +290,16 @@ pub fn blank_fn_ctxt(ccx: @mut CrateCtxt,
}
}

impl ExprTyProvider for FnCtxt {
pub fn expr_ty(&self, ex: &ast::expr) -> ty::t {
self.expr_ty(ex)
}

pub fn ty_ctxt(&self) -> ty::ctxt {
self.ccx.tcx
}
}

pub fn check_item_types(ccx: @mut CrateCtxt, crate: &ast::crate) {
let visit = visit::mk_simple_visitor(@visit::SimpleVisitor {
visit_item: |a| check_item(ccx, a),
Expand Down Expand Up @@ -797,7 +807,7 @@ impl FnCtxt {
pat.repr(self.tcx())
}

pub fn expr_ty(&self, ex: @ast::expr) -> ty::t {
pub fn expr_ty(&self, ex: &ast::expr) -> ty::t {
match self.inh.node_types.find(&ex.id) {
Some(&t) => t,
None => {
Expand Down Expand Up @@ -2250,8 +2260,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
}
}
ast::expr_repeat(element, count_expr, mutbl) => {
let _ = ty::eval_repeat_count(tcx, count_expr);
check_expr_with_hint(fcx, count_expr, ty::mk_uint());
let _ = ty::eval_repeat_count(fcx, count_expr);
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
let mutability = match vst {
ast::expr_vstore_mut_box | ast::expr_vstore_mut_slice => {
Expand Down Expand Up @@ -2730,8 +2740,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fcx.write_ty(id, typ);
}
ast::expr_repeat(element, count_expr, mutbl) => {
let count = ty::eval_repeat_count(tcx, count_expr);
check_expr_with_hint(fcx, count_expr, ty::mk_uint());
let count = ty::eval_repeat_count(fcx, count_expr);
let t: ty::t = fcx.infcx().next_ty_var();
check_expr_has_type(fcx, element, t);
let element_ty = fcx.expr_ty(element);
Expand Down Expand Up @@ -3126,7 +3136,7 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
// that the expression is in an form that eval_const_expr can
// handle, so we may still get an internal compiler error

match const_eval::eval_const_expr_partial(ccx.tcx, e) {
match const_eval::eval_const_expr_partial(&ccx.tcx, e) {
Ok(const_eval::const_int(val)) => {
*disr_val = val as int;
}
Expand Down
Loading