jiebi/CodeConvo huggingface dataset:
//! //! where `&.T` and `*T` are references of either mutability, //! and where unsize_kind(`T`) is the kind of the unsize info <del> //! in `T` - a vtable or a length (or `()` if `T: Sized`). </del> <ins> //! in `T` - the vtable for a trait definition (e.g. `fmt::Display` or //! `Iterator`, not `Iterator<Item=u8>`) or a length (or `()` if `T: Sized`). //! //! Note that lengths are not adjusted when casting raw slices - //! `T: *const [u16] as *const [u8]` creates a slice that only includes //! half of the original memory. </ins> //! //! Casting is not transitive, that is, even if `e as U1 as U2` is a valid //! expression, `e as U2` is not necessarily so (in fact it will only be valid if
-> Option<UnsizeKind<'tcx>> { match t.sty { ty::TySlice(_) | ty::TyStr => Some(UnsizeKind::Length), <del> ty::TyTrait(_) => Some(UnsizeKind::Vtable), </del> <ins> ty::TyTrait(ref tty) => Some(UnsizeKind::Vtable(tty.principal_def_id())), </ins> ty::TyStruct(did, substs) => { match ty::struct_fields(fcx.tcx(), did, substs).pop() { None => None,
impl Foo<u32> for u32 { fn foo(&self, _: u32) -> u32 { self+43 } } impl Bar for () {} <del> unsafe fn fool<'a>(t: *const (Foo<u32>+'a)) -> u32 { let bar : *const Bar = t as *const Bar; </del> <ins> unsafe fn round_trip_and_call<'a>(t: *const (Foo<u32>+'a)) -> u32 { </ins> let foo_e : *const Foo<u16> = t as *const _; let r_1 = foo_e as *mut Foo<u32>; <del> (&*r_1).foo(0)*(&*(bar as *const Foo<u32>)).foo(0) </del> <ins> (&*r_1).foo(0) </ins> } #[repr(C)]
fn main() { let x = 4u32; let y : &Foo<u32> = &x; <del> let fl = unsafe { fool(y as *const Foo<u32>) }; assert_eq!(fl, (43+4)*(43+4)); </del> <ins> let fl = unsafe { round_trip_and_call(y as *const Foo<u32>) }; assert_eq!(fl, (43+4)); </ins> let s = FooS([0,1,2]); let u: &FooS<[u32]> = &s;
assert_eq!(u as *const u8, p as *const u8); assert_eq!(u as *const u16, p as *const u16); <del> // ptr-ptr-cast (both vk=Length) </del> <ins> // ptr-ptr-cast (Length vtables) </ins> let mut l : [u8; 2] = [0,1]; let w: *mut [u16; 2] = &mut l as *mut [u8; 2] as *mut _; let w: *mut [u16] = unsafe {&mut *w};
let l_via_str = unsafe{&*(s as *const [u8])}; assert_eq!(&l, l_via_str); <ins> // ptr-ptr-cast (Length vtables, check length is preserved) let l: [[u8; 3]; 2] = [[3, 2, 6], [4, 5, 1]]; let p: *const [[u8; 3]] = &l; let p: &[[u8; 2]] = unsafe {&*(p as *const [[u8; 2]])}; assert_eq!(p, [[3, 2], [6, 4]]); </ins> // enum-cast assert_eq!(Simple::A as u8, 0); assert_eq!(Simple::B as u8, 1);
let impl_m = &cm.mty; <del> if impl_m.fty.meta.purity != trait_m.fty.meta.purity { tcx.sess.span_err( cm.span, fmt!("method `%s`'s purity does  not match the trait method's  purity", tcx.sess.str_of(impl_m.ident))); } // is this check right? </del> <ins> // FIXME(#2687)---this check is too strict.  For example, a trait // method with self type `&self` or `&mut self` should be // implementable by an `&const self` method (the impl assumes less // than the trait provides). </ins> if impl_m.self_ty != trait_m.self_ty { tcx.sess.span_err( cm.span,
debug!("trait_fty (pre-subst): %s", ty_to_str(tcx, trait_fty)); ty::subst(tcx, &substs, trait_fty) }; <del> debug!("trait_fty: %s", ty_to_str(tcx, trait_fty)); require_same_types( tcx, None, false, cm.span, impl_fty, trait_fty, || fmt!("method `%s` has an incompatible type", tcx.sess.str_of(trait_m.ident))); </del> <ins> let infcx = infer::new_infer_ctxt(tcx); match infer::mk_subty(infcx, false, cm.span, impl_fty, trait_fty) { result::Ok(()) => {} result::Err(ref terr) => { tcx.sess.span_err( cm.span, fmt!("method `%s` has an incompatible type: %s", tcx.sess.str_of(trait_m.ident), ty::type_err_to_str(tcx, terr))); ty::note_and_explain_type_err(tcx, terr); } } </ins> return; // Replaces bound references to the self region with `with_r`.
<ins> trait Mumbo { pure fn jumbo(&self, x: @uint) -> uint; fn jambo(&self, x: @const uint) -> uint; fn jbmbo(&self) -> @uint; } impl uint: Mumbo { // Cannot have a larger effect than the trait: fn jumbo(&self, x: @uint) { *self + *x; } //~^ ERROR expected pure fn but found impure fn // Cannot accept a narrower range of parameters: fn jambo(&self, x: @uint) { *self + *x; } //~^ ERROR values differ in mutability // Cannot return a wider range of values: fn jbmbo(&self) -> @const uint { @const 0 } //~^ ERROR values differ in mutability } fn main() {} </ins>
<ins> trait Mumbo { fn jumbo(&self, x: @uint) -> uint; } impl uint: Mumbo { // Note: this method def is ok, it is more accepting and // less effecting than the trait method: pure fn jumbo(&self, x: @const uint) -> uint { *self + *x } } fn main() { let a = 3u; let b = a.jumbo(@mut 6); let x = @a as @Mumbo; let y = x.jumbo(@mut 6); //~ ERROR values differ in mutability let z = x.jumbo(@6); } </ins>
fn bar<'a>(...) ``` <del> This part declares our lifetimes. This says that `bar` has one lifetime, `'a`. If we had two reference parameters, it would look like this: </del> <ins> We previously talked a little about [function syntax][functions], but we didn’t discuss the `<>`s after a function’s name. A function can have ‘generic parameters’ between the `<>`s, of which lifetimes are one kind. We’ll discuss other kinds of generics [later in the book][generics], but for now, let’s just focus on the lifteimes aspect. [functions]: functions.html [generics]: generics.html We use `<>` to declare our lifetimes. This says that `bar` has one lifetime, `'a`. If we had two reference parameters, it would look like this: </ins> ```rust,ignore fn bar<'a, 'b>(...)
let mut sign = None; if !is_positive { sign = Some('-'); width += 1; <del> } else if self.flags & (1 << (FlagV1::SignPlus as u32)) != 0 { </del> <ins> } else if self.sign_plus() { </ins> sign = Some('+'); width += 1; } let mut prefixed = false; <del> if self.flags & (1 << (FlagV1::Alternate as u32)) != 0 { </del> <ins> if self.alternate() { </ins> prefixed = true; width += prefix.char_len(); }
} // The sign and prefix goes before the padding if the fill character // is zero <del> Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 => { </del> <ins> Some(min) if self.sign_aware_zero_pad() => { </ins> self.fill = '0'; try!(write_prefix(self)); self.with_padding(min - width, Alignment::Right, |f| {
let mut formatted = formatted.clone(); let mut align = self.align; let old_fill = self.fill; <del> if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 { </del> <ins> if self.sign_aware_zero_pad() { </ins> // a sign always goes first let sign = unsafe { str::from_utf8_unchecked(formatted.sign) }; try!(self.buf.write_str(sign));
issue = "27726")] pub fn precision(&self) -> Option<usize> { self.precision } <ins> /// Determines if the `+` flag was specified. #[unstable(feature = "fmt_flags", reason = "method was just created", issue = "27726")] pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 } /// Determines if the `-` flag was specified. #[unstable(feature = "fmt_flags", reason = "method was just created", issue = "27726")] pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 } /// Determines if the `#` flag was specified. #[unstable(feature = "fmt_flags", reason = "method was just created", issue = "27726")] pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 } /// Determines if the `0` flag was specified. #[unstable(feature = "fmt_flags", reason = "method was just created", issue = "27726")] pub fn sign_aware_zero_pad(&self) -> bool { self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0 } </ins> /// Creates a `DebugStruct` builder designed to assist with creation of /// `fmt::Debug` implementations for structs. ///
// it denotes whether to prefix with 0x. We use it to work out whether // or not to zero extend, and then unconditionally set it to get the // prefix. <del> if f.flags & 1 << (FlagV1::Alternate as u32) > 0 { </del> <ins> if f.alternate() { </ins> f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); if let None = f.width {
fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool) -> Result where T: flt2dec::DecodableFloat { <del> let force_sign = fmt.flags & (1 << (FlagV1::SignPlus as u32)) != 0; </del> <ins> let force_sign = fmt.sign_plus(); </ins> let sign = match (force_sign, negative_zero) { (false, false) => flt2dec::Sign::Minus, (false, true)  => flt2dec::Sign::MinusRaw,
fn float_to_exponential_common<T>(fmt: &mut Formatter, num: &T, upper: bool) -> Result where T: flt2dec::DecodableFloat { <del> let force_sign = fmt.flags & (1 << (FlagV1::SignPlus as u32)) != 0; </del> <ins> let force_sign = fmt.sign_plus(); </ins> let sign = match force_sign { false => flt2dec::Sign::Minus, true  => flt2dec::Sign::MinusPlus,
} function startSearch() { <ins> $(".search-input").on("keyup",function() { if ($(this).val().length === 0) { window.history.replaceState("", "std - Rust", "?search="); $('#main.content').removeClass('hidden'); $('#search.content').addClass('hidden'); } }); </ins> var keyUpTimeout; $('.do-search').on('click', search); $('.search-input').on('keyup', function() {
pub const tag_impl_coerce_unsized_kind: usize = 0xa5; pub const tag_items_data_item_constness: usize = 0xa6; <ins> pub const tag_rustc_version: usize = 0x10f; pub fn rustc_version() -> String { format!( "rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version") ) } </ins>
return ret; } <ins> fn verify_rustc_version(&self, name: &str, span: Span, metadata: &MetadataBlob) { let crate_rustc_version = decoder::crate_rustc_version(metadata.as_slice()); if crate_rustc_version != Some(rustc_version()) { span_err!(self.sess, span, E0514, "the crate `{}` has been compiled with {}, which is  incompatible with this version of rustc", name, crate_rustc_version .as_ref().map(|s|&**s) .unwrap_or("an old version of rustc") ); self.sess.abort_if_errors(); } } </ins> fn register_crate(&mut self, root: &Option<CratePaths>, ident: &str,
index::Index::from_buf(index.data, index.start, index.end) } <ins> pub fn crate_rustc_version(data: &[u8]) -> Option<String> { let doc = rbml::Doc::new(data); reader::maybe_get_doc(doc, tag_rustc_version).map(|s| s.as_str()) } </ins> #[derive(Debug, PartialEq)] enum Family { ImmStatic,             // c
rbml_w.wr_tagged_str(tag_crate_hash, hash.as_str()); } <ins> fn encode_rustc_version(rbml_w: &mut Encoder) { rbml_w.wr_tagged_str(tag_rustc_version, &rustc_version()); } </ins> fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) { rbml_w.wr_tagged_str(tag_crate_crate_name, crate_name); }
let mut rbml_w = Encoder::new(wr); <ins> encode_rustc_version(&mut rbml_w); </ins> encode_crate_name(&mut rbml_w, &ecx.link_meta.crate_name); encode_crate_triple(&mut rbml_w, &tcx.sess.opts.target_triple); encode_hash(&mut rbml_w, &ecx.link_meta.crate_hash);
// can just use the tcx as the typer. // // FIXME(stage0): the :'t here is probably only important for stage0 <del> pub struct ExprUseVisitor<'d, 't, 'a: 't, 'tcx:'a+'d+'t> { </del> <ins> pub struct ExprUseVisitor<'d, 't, 'a: 't, 'tcx:'a+'d> { </ins> typer: &'t infer::InferCtxt<'a, 'tcx>, mc: mc::MemCategorizationContext<'t, 'a, 'tcx>, delegate: &'d mut Delegate<'tcx>,
impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { pub fn new(delegate: &'d mut Delegate<'tcx>, typer: &'t infer::InferCtxt<'a, 'tcx>) <del> -> ExprUseVisitor<'d,'t,'a,'tcx> </del> <ins> -> ExprUseVisitor<'d,'t,'a,'tcx> where 'tcx:'a </ins> { ExprUseVisitor { typer: typer,
% Closures <del> Rust not only has named functions, but anonymous functions as well. Anonymous functions that have an associated environment are called ‘closures’, because they close over an environment. Rust has a really great implementation of them, as we’ll see. </del> <ins> Sometimes it is useful to wrap up a function and _free variables_ for better clarity and reuse. The free variables that can be used come from the enclosing scope and are ‘closed over’ when used in the function. From this, we get the name ‘closures’ and Rust provides a really great implementation of them, as we’ll see. </ins> # Syntax
assert_eq!(2, plus_one(1)); ``` <del> But we don’t have to. Why is this? Basically, it was chosen for ergonomic reasons. While specifying the full type for named functions is helpful with things like documentation and type inference, the types of closures are rarely documented since they’re anonymous, and they don’t cause the kinds of error-at-a-distance problems that inferring named function types can. </del> <ins> But we don’t have to. Why is this? Basically, it was chosen for ergonomic reasons. While specifying the full type for named functions is helpful with things like documentation and type inference, the full type signatures of closures are rarely documented since they’re anonymous, and they don’t cause the kinds of error-at-a-distance problems that inferring named function types can. </ins> <del> The second is that the syntax is similar, but a bit different. I’ve added spaces here for easier comparison: </del> <ins> The second is that the syntax is similar, but a bit different. I’ve added spaces here for easier comparison: </ins> ```rust fn  plus_one_v1   (x: i32) -> i32 { x + 1 }
it, while a `move` closure is self-contained. This means that you cannot generally return a non-`move` closure from a function, for example. <del> But before we talk about taking and returning closures, we should talk some more about the way that closures are implemented. As a systems language, Rust gives you tons of control over what your code does, and closures are no different. </del> <ins> But before we talk about taking and returning closures, we should talk some more about the way that closures are implemented. As a systems language, Rust gives you tons of control over what your code does, and closures are no different. </ins> # Closure implementation
#   some_closure(1) } ``` <del> Because `Fn` is a trait, we can bound our generic with it. In this case, our closure takes a `i32` as an argument and returns an `i32`, and so the generic bound we use is `Fn(i32) -> i32`. </del> <ins> Because `Fn` is a trait, we can bound our generic with it. In this case, our closure takes a `i32` as an argument and returns an `i32`, and so the generic bound we use is `Fn(i32) -> i32`. </ins> There’s one other key point here: because we’re bounding a generic with a trait, this will get monomorphized, and therefore, we’ll be doing static
The error also points out that the return type is expected to be a reference, but what we are trying to return is not. Further, we cannot directly assign a `'static` lifetime to an object. So we'll take a different approach and return <del> a "trait object" by `Box`ing up the `Fn`. This _almost_ works: </del> <ins> a ‘trait object’ by `Box`ing up the `Fn`. This _almost_ works: </ins> ```rust,ignore fn factory() -> Box<Fn(i32) -> i32> {
#[inline] fn last(self) -> Option<A::Item> { match self.state { <del> ChainState::Both => self.b.last().or(self.a.last()), </del> <ins> ChainState::Both => { // Must exhaust a before b. let a_last = self.a.last(); let b_last = self.b.last(); b_last.or(a_last) }, </ins> ChainState::Front => self.a.last(), ChainState::Back => self.b.last() }
talk about what you do want instead. There are three broad classes of things that are relevant here: iterators, <del> *iterator adapters*, and *consumers*. Here's some definitions: </del> <ins> *iterator adaptors*, and *consumers*. Here's some definitions: </ins> * *iterators* give you a sequence of values. <del> * *iterator adapters* operate on an iterator, producing a new iterator with a </del> <ins> * *iterator adaptors* operate on an iterator, producing a new iterator with a </ins> different output sequence. * *consumers* operate on an iterator, producing some final set of values.
These two basic iterators should serve you well. There are some more advanced iterators, including ones that are infinite. <del> That's enough about iterators. Iterator adapters are the last concept </del> <ins> That's enough about iterators. Iterator adaptors are the last concept </ins> we need to talk about with regards to iterators. Let's get to it! <del> ## Iterator adapters </del> <ins> ## Iterator adaptors </ins> <del> *Iterator adapters* take an iterator and modify it somehow, producing </del> <ins> *Iterator adaptors* take an iterator and modify it somehow, producing </ins> a new iterator. The simplest one is called `map`: ```rust,ignore
This will give you a vector containing `6`, `12`, `18`, `24`, and `30`. <del> This is just a small taste of what iterators, iterator adapters, and consumers </del> <ins> This is just a small taste of what iterators, iterator adaptors, and consumers </ins> can help you with. There are a number of really useful iterators, and you can write your own as well. Iterators provide a safe, efficient way to manipulate all kinds of lists. They're a little unusual at first, but if you play with
<ins> // Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <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 ensures that vec.into_iter does not overconstrain element lifetime. pub fn main() { original_report(); revision_1(); revision_2(); } fn original_report() { drop(vec![&()].into_iter()) } fn revision_1() { // below is what above `vec!` expands into at time of this writing. drop(<[_]>::into_vec(::std::boxed::Box::new([&()])).into_iter()) } fn revision_2() { drop((match (Vec::new(), &()) { (mut v, b) => { v.push(b); v } }).into_iter()) } </ins>
///     use std::io::Cursor; ///     let mut buff = Cursor::new(vec![0; 15]); /// <del> ///     write_ten_bytes(&mut buff).unwrap(); </del> <ins> ///     write_ten_bytes_at_end(&mut buff).unwrap(); </ins> /// ///     assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); /// }
/// character, as `char`s. /// /// All characters are escaped with Rust syntax of the form `u{NNNN}` <del> /// where `NNNN` is the shortest hexadecimal representation of the code /// point. </del> <ins> /// where `NNNN` is the shortest hexadecimal representation. </ins> /// /// # Examples /// <ins> /// Basic usage: /// </ins> /// ``` /// for c in '❤'.escape_unicode() { ///     print!("{}", c);
//! Like many traits, these are often used as bounds for generic functions, to //! support arguments of multiple types. //! <ins> //! - Impl the `As*` traits for reference-to-reference conversions //! - Impl the `Into` trait when you want to consume the value in the conversion //! - The `From` trait is the most flexible, usefull for values _and_ references conversions //! //! As a library writer, you should prefer implementing `From<T>` rather than //! `Into<U>`, as `From` provides greater flexibility and offer the equivalent `Into` //! implementation for free, thanks to a blanket implementation in the standard library. //! //! **Note: these traits must not fail**. If the conversion can fail, you must use a dedicated //! method which return an `Option<T>` or a `Result<T, E>`. //! //! # Generic impl //! //! - `AsRef` and `AsMut` auto-dereference if the inner type is a reference //! - `From<U> for T` implies `Into<T> for U` //! - `From` and `Into` are reflexive, which means that all types can `into()` //!   themselves and `from()` themselves //! </ins> //! See each trait for usage examples. #![stable(feature = "rust1", since = "1.0.0")]
/// let s = "hello".to_string(); /// is_hello(s); /// ``` <ins> /// /// # Generic Impls /// /// - `AsRef` auto-dereference if the inner type is a reference or a mutable /// reference (eg: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`) /// </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRef<T: ?Sized> { /// Performs the conversion.
} /// A cheap, mutable reference-to-mutable reference conversion. <ins> /// /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which /// return an `Option<T>` or a `Result<T, E>`. /// /// # Generic Impls /// /// - `AsMut` auto-dereference if the inner type is a reference or a mutable /// reference (eg: `foo.as_ref()` will work the same if `foo` has type `&mut Foo` or `&&mut Foo`) /// </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait AsMut<T: ?Sized> { /// Performs the conversion.
/// A conversion that consumes `self`, which may or may not be expensive. /// <ins> /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which /// return an `Option<T>` or a `Result<T, E>`. /// /// Library writer should not implement directly this trait, but should prefer the implementation /// of the `From` trait, which offer greater flexibility and provide the equivalent `Into` /// implementation for free, thanks to a blanket implementation in the standard library. /// </ins> /// # Examples /// /// `String` implements `Into<Vec<u8>>`:
/// let s = "hello".to_string(); /// is_hello(s); /// ``` <ins> /// /// # Generic Impls /// /// - `From<T> for U` implies `Into<U> for T` /// - `into()` is reflexive, which means that `Into<T> for T` is implemented /// </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait Into<T>: Sized { /// Performs the conversion.
/// /// assert_eq!(string, other_string); /// ``` <ins> /// # Generic impls /// /// - `From<T> for U` implies `Into<U> for T` /// - `from()` is reflexive, which means that `From<T> for T` is implemented /// </ins> #[stable(feature = "rust1", since = "1.0.0")] pub trait From<T>: Sized { /// Performs the conversion.
} } <ins> pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, did: DefId, ty: Ty<'tcx>) -> ValueRef { if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) { base::get_item_val(ccx, node_id) } else { base::get_extern_const(ccx, did, ty) } } </ins>
use middle::def_id::DefId; use trans::{adt, closure, debuginfo, expr, inline, machine}; use trans::base::{self, push_ctxt}; <ins> use trans::common::{self, type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt}; </ins> use trans::common::{CrateContext, C_integral, C_floating, C_bool, C_str_slice, C_bytes, val_ty}; <del> use trans::common::{type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt}; </del> use trans::common::{C_struct, C_undef, const_to_opt_int, const_to_opt_uint, VariantInfo, C_uint}; use trans::common::{type_is_fat_ptr, Field, C_vector, C_array, C_null, ExprId, MethodCallKey}; use trans::declare;
} let opt_def = cx.tcx().def_map.borrow().get(&cur.id).map(|d| d.full_def()); if let Some(def::DefStatic(def_id, _)) = opt_def { <del> get_static_val(cx, def_id, ety) </del> <ins> common::get_static_val(cx, def_id, ety) </ins> } else { // If this isn't the address of a static, then keep going through // normal constant evaluation.
Ok(g) } } <del> fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, did: DefId, ty: Ty<'tcx>) -> ValueRef { if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) { base::get_item_val(ccx, node_id) } else { base::trans_external_path(ccx, did, ty) } } </del>
DatumBlock::new(bcx, datum.to_expr_datum()) } def::DefStatic(did, _) => { <del> // There are two things that may happen here: //  1) If the static item is defined in this crate, it will be //     translated using `get_item_val`, and we return a pointer to //     the result. //  2) If the static item is defined in another crate then we add //     (or reuse) a declaration of an external global, and return a //     pointer to that. </del> let const_ty = expr_ty(bcx, ref_expr); <del> // For external constants, we don't inline. let val = if let Some(node_id) = bcx.tcx().map.as_local_node_id(did) { // Case 1. // The LLVM global has the type of its initializer, // which may not be equal to the enum's type for // non-C-like enums. let val = base::get_item_val(bcx.ccx(), node_id); let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to(); PointerCast(bcx, val, pty) } else { // Case 2. base::get_extern_const(bcx.ccx(), did, const_ty) }; </del> <ins> let val = get_static_val(bcx.ccx(), did, const_ty); </ins> let lval = Lvalue::new("expr::trans_def"); DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr(lval))) }