jiebi/CodeConvo huggingface dataset:
} ast::ExprMatch(ref discr, ref arms) => { <del> // treatment of the discriminant is handled while // walking the arms: self.walk_expr(&**discr); </del> let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr)); <ins> self.borrow_expr(&**discr, ty::ReEmpty, ty::ImmBorrow, MatchDiscriminant); // treatment of the discriminant is handled while walking the arms. </ins> for arm in arms.iter() { self.walk_arm(discr_cmt.clone(), arm); }
<ins> // 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. fn foo(_s: i16) { } fn bar(_s: u32) { } fn main() { foo(1*(1 as int)); //~^ ERROR: mismatched types: expected `i16`, found `int` (expected `i16`, found `int`) bar(1*(1 as uint)); //~^ ERROR: mismatched types: expected `u32`, found `uint` (expected `u32`, found `uint`) } </ins>
<ins> // 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 X(int); enum Enum { Variant1, Variant2 } impl Drop for X { fn drop(&mut self) {} } impl Drop for Enum { fn drop(&mut self) {} } fn main() { let foo = X(1i); drop(foo); match foo { //~ ERROR use of moved value X(1i) => (), _ => unreachable!() } let e = Variant2; drop(e); match e { //~ ERROR use of moved value Variant1 => unreachable!(), Variant2 => () } } </ins>
<del> // 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. fn foo(_s: i16) { } fn bar(_s: u32) { } fn main() { foo(1*(1 as int)); //~^ ERROR: mismatched types: expected `i16`, found `int` (expected `i16`, found `int`) bar(1*(1 as uint)); //~^ ERROR: mismatched types: expected `u32`, found `uint` (expected `u32`, found `uint`) } </del>
{ let parent = self.get_parent(id); let parent = match self.find_entry(id) { <del> Some(EntryForeignItem(..)) | Some(EntryVariant(..)) => { // Anonymous extern items, enum variants and struct ctors // go in the parent scope. </del> <ins> Some(EntryForeignItem(..)) => { // Anonymous extern items go in the parent scope. </ins> self.get_parent(parent) } // But tuple struct ctors don't have names, so use the path of its
prim_ty_to_ty(tcx, base_segments, prim_ty) } _ => { <ins> let node = def.def_id().node; </ins> span_err!(tcx.sess, span, E0248, <del> "found value name used as a type: {:?}", *def); </del> <ins> "found value `{}` used as a type", tcx.map.path_to_string(node)); </ins> return this.tcx().types.err; } }
<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. use foo::MyEnum::Result; use foo::NoResult; // Through a re-export mod foo { pub use self::MyEnum::NoResult; enum MyEnum { Result, NoResult } fn new() -> NoResult<MyEnum, String> { //~^ ERROR: found value `foo::MyEnum::NoResult` used as a type unimplemented!() } } mod bar { use foo::MyEnum::Result; use foo; fn new() -> Result<foo::MyEnum, String> { //~^ ERROR: found value `foo::MyEnum::Result` used as a type unimplemented!() } } fn new() -> Result<foo::MyEnum, String> { //~^ ERROR: found value `foo::MyEnum::Result` used as a type unimplemented!() } fn newer() -> NoResult<foo::MyEnum, String> { //~^ ERROR: found value `foo::MyEnum::NoResult` used as a type unimplemented!() } fn main() { let _ = new(); } </ins>
#[rustc_move_fragments] pub fn test_match_partial(p: Lonely<D, D>) { //~^ ERROR                 parent_of_fragments: `$(local p)` <del> //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)` </del> <ins> //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Zero)` </ins> match p { Zero(..) => {} _ => {}
#[rustc_move_fragments] pub fn test_match_full(p: Lonely<D, D>) { //~^ ERROR                 parent_of_fragments: `$(local p)` <del> //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)` //~| ERROR                  assigned_leaf_path: `($(local p) as One)` //~| ERROR                  assigned_leaf_path: `($(local p) as Two)` </del> <ins> //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Zero)` //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::One)` //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Two)` </ins> match p { Zero(..) => {} One(..) => {}
#[rustc_move_fragments] pub fn test_match_bind_one(p: Lonely<D, D>) { //~^ ERROR                 parent_of_fragments: `$(local p)` <del> //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)` //~| ERROR                 parent_of_fragments: `($(local p) as One)` //~| ERROR                     moved_leaf_path: `($(local p) as One).#0` //~| ERROR                  assigned_leaf_path: `($(local p) as Two)` </del> <ins> //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Zero)` //~| ERROR                 parent_of_fragments: `($(local p) as Lonely::One)` //~| ERROR                     moved_leaf_path: `($(local p) as Lonely::One).#0` //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Two)` </ins> //~| ERROR                  assigned_leaf_path: `$(local data)` match p { Zero(..) => {}
#[rustc_move_fragments] pub fn test_match_bind_many(p: Lonely<D, D>) { //~^ ERROR                 parent_of_fragments: `$(local p)` <del> //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)` //~| ERROR                 parent_of_fragments: `($(local p) as One)` //~| ERROR                     moved_leaf_path: `($(local p) as One).#0` </del> <ins> //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Zero)` //~| ERROR                 parent_of_fragments: `($(local p) as Lonely::One)` //~| ERROR                     moved_leaf_path: `($(local p) as Lonely::One).#0` </ins> //~| ERROR                  assigned_leaf_path: `$(local data)` <del> //~| ERROR                 parent_of_fragments: `($(local p) as Two)` //~| ERROR                     moved_leaf_path: `($(local p) as Two).#0` //~| ERROR                     moved_leaf_path: `($(local p) as Two).#1` </del> <ins> //~| ERROR                 parent_of_fragments: `($(local p) as Lonely::Two)` //~| ERROR                     moved_leaf_path: `($(local p) as Lonely::Two).#0` //~| ERROR                     moved_leaf_path: `($(local p) as Lonely::Two).#1` </ins> //~| ERROR                  assigned_leaf_path: `$(local left)` //~| ERROR                  assigned_leaf_path: `$(local right)` match p {
#[rustc_move_fragments] pub fn test_match_bind_and_underscore(p: Lonely<D, D>) { //~^ ERROR                 parent_of_fragments: `$(local p)` <del> //~| ERROR                  assigned_leaf_path: `($(local p) as Zero)` //~| ERROR                  assigned_leaf_path: `($(local p) as One)` //~| ERROR                 parent_of_fragments: `($(local p) as Two)` //~| ERROR                     moved_leaf_path: `($(local p) as Two).#0` //~| ERROR                    unmoved_fragment: `($(local p) as Two).#1` </del> <ins> //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::Zero)` //~| ERROR                  assigned_leaf_path: `($(local p) as Lonely::One)` //~| ERROR                 parent_of_fragments: `($(local p) as Lonely::Two)` //~| ERROR                     moved_leaf_path: `($(local p) as Lonely::Two).#0` //~| ERROR                    unmoved_fragment: `($(local p) as Lonely::Two).#1` </ins> //~| ERROR                  assigned_leaf_path: `$(local left)` match p {
impl<'a> Writer for &'a mut Writer+'a { #[inline] <del> fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) } </del> <ins> fn write(&mut self, buf: &[u8]) -> IoResult<()> { (**self).write(buf) } </ins> #[inline] <del> fn flush(&mut self) -> IoResult<()> { self.flush() } </del> <ins> fn flush(&mut self) -> IoResult<()> { (**self).flush() } </ins> } /// A `RefWriter` is a struct implementing `Writer` which contains a reference
It generally helps our diagnosis to include your specific OS (for example: Mac OS X 10.8.3, Windows 7, Ubuntu 12.04) and your hardware architecture (for example: i686, x86_64). <del> It's also helpful to copy/paste the output of re-running the erroneous rustc command with the `-v` flag. Finally, if you can run the offending command under gdb, pasting a stack trace can be useful; to do so, you will need to set a breakpoint on `rust_fail`. </del> <ins> It's also helpful to provide the exact version and host by copying the output of re-running the erroneous rustc command with the `--version=verbose` flag, which will produce something like this: ```{ignore} rustc 0.12.0 (ba4081a5a 2014-10-07 13:44:41 -0700) binary: rustc commit-hash: ba4081a5a8573875fed17545846f6f6902c8ba8d commit-date: 2014-10-07 13:44:41 -0700 host: i686-apple-darwin release: 0.12.0 ``` Finally, if you can run the offending command under gdb, pasting a stack trace can be useful; to do so, you will need to set a breakpoint on `rust_fail`. </ins> # I submitted a bug, but nobody has commented on it!
# Some less critical tests that are not prone to breakage. # Not run as part of the normal test suite, but tested by bors on checkin. <del> check-secondary: check-lexer check-pretty </del> <ins> check-secondary: check-build-compiletest check-lexer check-pretty </ins> # check + check-secondary. <del> check-all: check check-secondary </del> <ins> # # Issue #17883: build check-secondary first so hidden dependencies in # e.g. building compiletest are exercised (resolve those by adding # deps to rules that need them; not by putting `check` first here). check-all: check-secondary check </ins> # Pretty-printing tests. check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec <ins> define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE check-stage$(1)-build-compiletest: 	$$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD)) endef $(foreach stage,$(STAGES),  $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage)))) check-build-compiletest:  check-stage1-build-compiletest  check-stage2-build-compiletest </ins> .PHONY: cleantmptestlogs cleantestlibs cleantmptestlogs:
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS) PRETTY_DEPS_pretty-bench = $(BENCH_TESTS) PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS) <ins> # The stage- and host-specific dependencies are for e.g. macro_crate_test which pulls in # external crates. PRETTY_DEPS$(1)_H_$(3)_pretty-rpass = PRETTY_DEPS$(1)_H_$(3)_pretty-rpass-full = $$(HLIB$(1)_H_$(3))/stamp.syntax $$(HLIB$(1)_H_$(3))/stamp.rustc PRETTY_DEPS$(1)_H_$(3)_pretty-rfail = PRETTY_DEPS$(1)_H_$(3)_pretty-bench = PRETTY_DEPS$(1)_H_$(3)_pretty-pretty = </ins> PRETTY_DIRNAME_pretty-rpass = run-pass PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps PRETTY_DIRNAME_pretty-rfail = run-fail
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):  $$(TEST_SREQ$(1)_T_$(2)_H_$(3))  <del> $$(PRETTY_DEPS_$(4)) </del> <ins> $$(PRETTY_DEPS_$(4))  $$(PRETTY_DEPS$(1)_H_$(3)_$(4)) </ins> @$$(call E, run pretty-rpass [$(2)]: $$<) $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3))  $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4))
impl fmt::Show for Duration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { <del> let days = self.num_days(); let secs = self.secs - days * SECS_PER_DAY; </del> <ins> // technically speaking, negative duration is not valid ISO 8601, // but we need to print it anyway. let (abs, sign) = if self.secs < 0 { (-self, "-") } else { (*self, "") }; let days = abs.secs / SECS_PER_DAY; let secs = abs.secs - days * SECS_PER_DAY; </ins> let hasdate = days != 0; <del> let hastime = (secs != 0 || self.nanos != 0) || !hasdate; </del> <ins> let hastime = (secs != 0 || abs.nanos != 0) || !hasdate; try!(write!(f, "{}P", sign)); </ins> <del> try!(write!(f, "P")); </del> if hasdate { <del> // technically speaking the negative part is not the valid ISO 8601, // but we need to print it anyway. </del> try!(write!(f, "{}D", days)); } if hastime { <del> if self.nanos == 0 { </del> <ins> if abs.nanos == 0 { </ins> try!(write!(f, "T{}S", secs)); <del> } else if self.nanos % NANOS_PER_MILLI == 0 { try!(write!(f, "T{}.{:03}S", secs, self.nanos / NANOS_PER_MILLI)); } else if self.nanos % NANOS_PER_MICRO == 0 { try!(write!(f, "T{}.{:06}S", secs, self.nanos / NANOS_PER_MICRO)); </del> <ins> } else if abs.nanos % NANOS_PER_MILLI == 0 { try!(write!(f, "T{}.{:03}S", secs, abs.nanos / NANOS_PER_MILLI)); } else if abs.nanos % NANOS_PER_MICRO == 0 { try!(write!(f, "T{}.{:06}S", secs, abs.nanos / NANOS_PER_MICRO)); </ins> } else { <del> try!(write!(f, "T{}.{:09}S", secs, self.nanos)); </del> <ins> try!(write!(f, "T{}.{:09}S", secs, abs.nanos)); </ins> } } Ok(())
let d: Duration = Zero::zero(); assert_eq!(d.to_string(), "PT0S".to_string()); assert_eq!(Duration::days(42).to_string(), "P42D".to_string()); <del> assert_eq!(Duration::days(-42).to_string(), "P-42D".to_string()); </del> <ins> assert_eq!(Duration::days(-42).to_string(), "-P42D".to_string()); </ins> assert_eq!(Duration::seconds(42).to_string(), "PT42S".to_string()); assert_eq!(Duration::milliseconds(42).to_string(), "PT0.042S".to_string()); assert_eq!(Duration::microseconds(42).to_string(), "PT0.000042S".to_string()); assert_eq!(Duration::nanoseconds(42).to_string(), "PT0.000000042S".to_string()); assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(), "P7DT6.543S".to_string()); <ins> assert_eq!(Duration::seconds(-86401).to_string(), "-P1DT1S".to_string()); assert_eq!(Duration::nanoseconds(-1).to_string(), "-PT0.000000001S".to_string()); </ins> // the format specifier should have no effect on `Duration` assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)),
else: rustc_dlls.append("libgcc_s_seh-1.dll") <del> target_libs = ["crtbegin.o", "crtend.o", "crt2.o", "dllcrt2.o", "libadvapi32.a", "libcrypt32.a", "libgcc.a", "libgcc_eh.a", "libgcc_s.a", "libimagehlp.a", "libiphlpapi.a", "libkernel32.a", "libm.a", "libmingw32.a", "libmingwex.a", "libmsvcrt.a", "libpsapi.a", "libshell32.a", "libstdc++.a", "libuser32.a", "libws2_32.a", "libiconv.a", "libmoldname.a"] </del> <ins> target_libs = [ # MinGW libs "crtbegin.o", "crtend.o", "crt2.o", "dllcrt2.o", "libgcc.a", "libgcc_eh.a", "libgcc_s.a", "libm.a", "libmingw32.a", "libmingwex.a", "libstdc++.a", "libiconv.a", "libmoldname.a", # Windows import libs "libadvapi32.a", "libbcrypt.a", "libcomctl32.a", "libcomdlg32.a", "libcrypt32.a", "libctl3d32.a", "libgdi32.a", "libimagehlp.a", "libiphlpapi.a", "libkernel32.a", "libmsvcrt.a", "libodbc32.a", "libole32.a", "liboleaut32.a", "libopengl32.a", "libpsapi.a", "librpcrt4.a", "libsetupapi.a", "libshell32.a", "libuser32.a", "libuuid.a", "libwinhttp.a", "libwinmm.a", "libwinspool.a", "libws2_32.a", "libwsock32.a", ] </ins> # Find mingw artifacts we want to bundle target_tools = find_files(target_tools, bin_path)
shutil.copy(src, dist_bin_dir) # Copy platform tools to platform-specific bin directory <del> target_bin_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "gcc", "bin") </del> <ins> target_bin_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "bin") </ins> if not os.path.exists(target_bin_dir): os.makedirs(target_bin_dir) for src in target_tools: shutil.copy(src, target_bin_dir) # Copy platform libs to platform-spcific lib directory <del> target_lib_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "gcc", "lib") </del> <ins> target_lib_dir = os.path.join(dist_root, "bin", "rustlib", target_triple, "lib") </ins> if not os.path.exists(target_lib_dir): os.makedirs(target_lib_dir) for src in target_libs:
trans: &CrateTranslation, outputs: &OutputFilenames) { let old_path = os::getenv("PATH").unwrap_or_else(||String::new()); <del> let mut new_path = os::split_paths(old_path.as_slice()); new_path.extend(sess.host_filesearch().get_tools_search_paths().into_iter()); </del> <ins> let mut new_path = sess.host_filesearch().get_tools_search_paths(); new_path.extend(os::split_paths(old_path.as_slice()).into_iter()); </ins> os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap()); time(sess.time_passes(), "linking", (), |_|
p.push(find_libdir(self.sysroot)); p.push(rustlibdir()); p.push(self.triple); <del> let mut p1 = p.clone(); p1.push("bin"); let mut p2 = p.clone(); p2.push("gcc"); p2.push("bin"); vec![p1, p2] </del> <ins> p.push("bin"); vec![p] </ins> } }
<ins> // 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. // error-pattern:stop // #18576 // Make sure that an calling extern function pointer in an unreachable // context doesn't cause an LLVM assertion #[allow(unreachable_code)] fn main() { panic!("stop"); let pointer = other; pointer(); } extern fn other() {} </ins>
use common::{CodegenCx, val_ty}; use declare; use monomorphize::Instance; <ins> use syntax_pos::Span; use syntax_pos::symbol::LocalInternedString; </ins> use type_::Type; use type_of::LayoutLlvmExt; <del> use rustc::ty; </del> <ins> use rustc::ty::{self, Ty}; </ins> use rustc::ty::layout::{Align, LayoutOf}; <del> use rustc::hir::{self, CodegenFnAttrFlags}; </del> <ins> use rustc::hir::{self, CodegenFnAttrs, CodegenFnAttrFlags}; </ins> use std::ffi::{CStr, CString};
let ty = instance.ty(cx.tcx); let sym = cx.tcx.symbol_name(instance).as_str(); <ins> debug!("get_static: sym={} instance={:?}", sym, instance); </ins> let g = if let Some(id) = cx.tcx.hir.as_local_node_id(def_id) { let llty = cx.layout_of(ty).llvm_type(cx);
hir_map::NodeForeignItem(&hir::ForeignItem { ref attrs, span, node: hir::ForeignItemKind::Static(..), .. }) => { <del> let g = if let Some(linkage) = cx.tcx.codegen_fn_attrs(def_id).linkage { // If this is a static with a linkage specified, then we need to handle // it a little specially. The typesystem prevents things like &T and // extern "C" fn() from being non-null, so we can't just declare a // static and call it a day. Some linkages (like weak) will make it such // that the static actually has a null value. let llty2 = match ty.sty { ty::TyRawPtr(ref mt) => cx.layout_of(mt.ty).llvm_type(cx), _ => { cx.sess().span_fatal(span, "must have type `*const T` or `*mut T`"); } }; unsafe { // Declare a symbol `foo` with the desired linkage. let g1 = declare::declare_global(cx, &sym, llty2); llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage)); // Declare an internal global `extern_with_linkage_foo` which // is initialized with the address of `foo`.  If `foo` is // discarded during linking (for example, if `foo` has weak // linkage and there are no definitions), then // `extern_with_linkage_foo` will instead be initialized to // zero. let mut real_name = "_rust_extern_with_linkage_".to_string(); real_name.push_str(&sym); let g2 = declare::define_global(cx, &real_name, llty).unwrap_or_else(||{ cx.sess().span_fatal(span, &format!("symbol `{}` is already defined", &sym)) }); llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage); llvm::LLVMSetInitializer(g2, g1); g2 } } else { // Generate an external declaration. declare::declare_global(cx, &sym, llty) }; (g, attrs) </del> <ins> let fn_attrs = cx.tcx.codegen_fn_attrs(def_id); (check_and_apply_linkage(cx, &fn_attrs, ty, sym, Some(span)), attrs) </ins> } item => bug!("get_static: expected static, found {:?}", item) }; <ins> debug!("get_static: sym={} attrs={:?}", sym, attrs); </ins> for attr in attrs { if attr.check_name("thread_local") { llvm::set_thread_local_mode(g, cx.tls_model);
g } else { // FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow? <del> // FIXME(nagisa): investigate whether it can be changed into define_global let g = declare::declare_global(cx, &sym, cx.layout_of(ty).llvm_type(cx)); </del> <ins> debug!("get_static: sym={} item_attr={:?}", sym, cx.tcx.item_attrs(def_id)); let attrs = cx.tcx.codegen_fn_attrs(def_id); let g = check_and_apply_linkage(cx, &attrs, ty, sym, None); </ins> // Thread-local statics in some other crate need to *always* be linked // against in a thread-local fashion, so we need to be sure to apply the // thread-local attribute locally if it was present remotely. If we // don't do this then linker errors can be generated where the linker // complains that one object files has a thread local version of the // symbol and another one doesn't. <del> for attr in cx.tcx.get_attrs(def_id).iter() { if attr.check_name("thread_local") { llvm::set_thread_local_mode(g, cx.tls_model); } </del> <ins> if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { llvm::set_thread_local_mode(g, cx.tls_model); </ins> } if cx.use_dll_storage_attrs && !cx.tcx.is_foreign_item(def_id) { // This item is external but not foreign, i.e. it originates from an external Rust // crate. Since we don't know whether this crate will be linked dynamically or
g } <ins> fn check_and_apply_linkage<'tcx>( cx: &CodegenCx<'_, 'tcx>, attrs: &CodegenFnAttrs, ty: Ty<'tcx>, sym: LocalInternedString, span: Option<Span> ) -> ValueRef { let llty = cx.layout_of(ty).llvm_type(cx); if let Some(linkage) = attrs.linkage { debug!("get_static: sym={} linkage={:?}", sym, linkage); // If this is a static with a linkage specified, then we need to handle // it a little specially. The typesystem prevents things like &T and // extern "C" fn() from being non-null, so we can't just declare a // static and call it a day. Some linkages (like weak) will make it such // that the static actually has a null value. let llty2 = match ty.sty { ty::TyRawPtr(ref mt) => cx.layout_of(mt.ty).llvm_type(cx), _ => { if span.is_some() { cx.sess().span_fatal(span.unwrap(), "must have type `*const T` or `*mut T`") } else { bug!("must have type `*const T` or `*mut T`") } } }; unsafe { // Declare a symbol `foo` with the desired linkage. let g1 = declare::declare_global(cx, &sym, llty2); llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage)); // Declare an internal global `extern_with_linkage_foo` which // is initialized with the address of `foo`.  If `foo` is // discarded during linking (for example, if `foo` has weak // linkage and there are no definitions), then // `extern_with_linkage_foo` will instead be initialized to // zero. let mut real_name = "_rust_extern_with_linkage_".to_string(); real_name.push_str(&sym); let g2 = declare::define_global(cx, &real_name, llty).unwrap_or_else(||{ if span.is_some() { cx.sess().span_fatal( span.unwrap(), &format!("symbol `{}` is already defined", &sym) ) } else { bug!("symbol `{}` is already defined", &sym) } }); llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage); llvm::LLVMSetInitializer(g2, g1); g2 } } else { // Generate an external declaration. // FIXME(nagisa): investigate whether it can be changed into define_global declare::declare_global(cx, &sym, llty) } } </ins> pub fn codegen_static<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, def_id: DefId,