Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3bfa31

Browse files
committedMay 30, 2016
Auto merge of #33965 - Manishearth:rollup, r=Manishearth
Rollup of 5 pull requests - Successful merges: #33867, #33926, #33942, #33958, #33964 - Failed merges:
2 parents 5da602b + 26c2098 commit f3bfa31

File tree

13 files changed

+196
-165
lines changed

13 files changed

+196
-165
lines changed
 

‎src/etc/htmldocck.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
from htmlentitydefs import entitydefs
118118
entitydefs['larrb'] = u'\u21e4'
119119
entitydefs['rarrb'] = u'\u21e5'
120+
entitydefs['nbsp'] = ' '
120121

121122
# "void elements" (no closing tag) from the HTML Standard section 12.1.2
122123
VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',

‎src/librustc_driver/driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use syntax_ext;
6363

6464
#[derive(Clone)]
6565
pub struct Resolutions {
66-
pub def_map: RefCell<DefMap>,
66+
pub def_map: DefMap,
6767
pub freevars: FreevarMap,
6868
pub trait_map: TraitMap,
6969
pub maybe_unused_trait_imports: NodeSet,
@@ -818,7 +818,7 @@ pub fn lower_and_resolve<'a>(sess: &Session,
818818
name: &id,
819819
glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None },
820820
}, Resolutions {
821-
def_map: RefCell::new(resolver.def_map),
821+
def_map: resolver.def_map,
822822
freevars: resolver.freevars,
823823
trait_map: resolver.trait_map,
824824
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
@@ -866,7 +866,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
866866
"lifetime resolution",
867867
|| middle::resolve_lifetime::krate(sess,
868868
&hir_map,
869-
&resolutions.def_map.borrow()))?;
869+
&resolutions.def_map))?;
870870

871871
time(time_passes,
872872
"looking for entry point",
@@ -886,14 +886,14 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
886886

887887
time(time_passes,
888888
"static item recursion checking",
889-
|| static_recursion::check_crate(sess, &resolutions.def_map.borrow(), &hir_map))?;
889+
|| static_recursion::check_crate(sess, &resolutions.def_map, &hir_map))?;
890890

891891
let index = stability::Index::new(&hir_map);
892892

893893
let trait_map = resolutions.trait_map;
894894
TyCtxt::create_and_enter(sess,
895895
arenas,
896-
resolutions.def_map,
896+
RefCell::new(resolutions.def_map),
897897
named_region_map,
898898
hir_map,
899899
resolutions.freevars,

‎src/librustc_driver/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_metadata::cstore::CStore;
2929
use rustc_metadata::creader::read_local_crates;
3030
use rustc::hir::map as hir_map;
3131
use rustc::session::{self, config};
32+
use std::cell::RefCell;
3233
use std::rc::Rc;
3334
use syntax::ast;
3435
use syntax::abi::Abi;
@@ -134,12 +135,12 @@ fn test_env<F>(source_string: &str,
134135

135136
// run just enough stuff to build a tcx:
136137
let lang_items = lang_items::collect_language_items(&sess, &ast_map);
137-
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &resolutions.def_map.borrow());
138+
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &resolutions.def_map);
138139
let region_map = region::resolve_crate(&sess, &ast_map);
139140
let index = stability::Index::new(&ast_map);
140141
TyCtxt::create_and_enter(&sess,
141142
&arenas,
142-
resolutions.def_map,
143+
RefCell::new(resolutions.def_map),
143144
named_region_map.unwrap(),
144145
ast_map,
145146
resolutions.freevars,

‎src/librustc_llvm/archive_ro.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use std::path::Path;
1818
use std::slice;
1919
use std::str;
2020

21-
pub struct ArchiveRO { ptr: ArchiveRef }
21+
pub struct ArchiveRO {
22+
ptr: ArchiveRef,
23+
}
2224

2325
pub struct Iter<'a> {
2426
archive: &'a ArchiveRO,
@@ -61,11 +63,16 @@ impl ArchiveRO {
6163
}
6264
}
6365

64-
pub fn raw(&self) -> ArchiveRef { self.ptr }
66+
pub fn raw(&self) -> ArchiveRef {
67+
self.ptr
68+
}
6569

6670
pub fn iter(&self) -> Iter {
6771
unsafe {
68-
Iter { ptr: ::LLVMRustArchiveIteratorNew(self.ptr), archive: self }
72+
Iter {
73+
ptr: ::LLVMRustArchiveIteratorNew(self.ptr),
74+
archive: self,
75+
}
6976
}
7077
}
7178
}
@@ -86,7 +93,10 @@ impl<'a> Iterator for Iter<'a> {
8693
if ptr.is_null() {
8794
::last_error().map(Err)
8895
} else {
89-
Some(Ok(Child { ptr: ptr, _data: marker::PhantomData }))
96+
Some(Ok(Child {
97+
ptr: ptr,
98+
_data: marker::PhantomData,
99+
}))
90100
}
91101
}
92102
}
@@ -107,8 +117,7 @@ impl<'a> Child<'a> {
107117
if name_ptr.is_null() {
108118
None
109119
} else {
110-
let name = slice::from_raw_parts(name_ptr as *const u8,
111-
name_len as usize);
120+
let name = slice::from_raw_parts(name_ptr as *const u8, name_len as usize);
112121
str::from_utf8(name).ok().map(|s| s.trim())
113122
}
114123
}
@@ -125,11 +134,15 @@ impl<'a> Child<'a> {
125134
}
126135
}
127136

128-
pub fn raw(&self) -> ::ArchiveChildRef { self.ptr }
137+
pub fn raw(&self) -> ::ArchiveChildRef {
138+
self.ptr
139+
}
129140
}
130141

131142
impl<'a> Drop for Child<'a> {
132143
fn drop(&mut self) {
133-
unsafe { ::LLVMRustArchiveChildFree(self.ptr); }
144+
unsafe {
145+
::LLVMRustArchiveChildFree(self.ptr);
146+
}
134147
}
135148
}

‎src/librustc_llvm/build.rs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,25 @@ fn main() {
2121
println!("cargo:rustc-cfg=cargobuild");
2222

2323
let target = env::var("TARGET").unwrap();
24-
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from)
25-
.unwrap_or_else(|| {
26-
match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
27-
Some(dir) => {
28-
let to_test = dir.parent().unwrap().parent().unwrap()
29-
.join(&target).join("llvm/bin/llvm-config");
30-
if Command::new(&to_test).output().is_ok() {
31-
return to_test
32-
}
33-
}
34-
None => {}
35-
}
36-
PathBuf::from("llvm-config")
37-
});
24+
let llvm_config = env::var_os("LLVM_CONFIG")
25+
.map(PathBuf::from)
26+
.unwrap_or_else(|| {
27+
match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
28+
Some(dir) => {
29+
let to_test = dir.parent()
30+
.unwrap()
31+
.parent()
32+
.unwrap()
33+
.join(&target)
34+
.join("llvm/bin/llvm-config");
35+
if Command::new(&to_test).output().is_ok() {
36+
return to_test;
37+
}
38+
}
39+
None => {}
40+
}
41+
PathBuf::from("llvm-config")
42+
});
3843

3944
println!("cargo:rerun-if-changed={}", llvm_config.display());
4045

@@ -63,20 +68,22 @@ fn main() {
6368
let host = env::var("HOST").unwrap();
6469
let is_crossed = target != host;
6570

66-
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc",
67-
"pnacl"];
71+
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc", "pnacl"];
6872

6973
// FIXME: surely we don't need all these components, right? Stuff like mcjit
7074
// or interpreter the compiler itself never uses.
71-
let required_components = &["ipo", "bitreader", "bitwriter", "linker",
72-
"asmparser", "mcjit", "interpreter",
75+
let required_components = &["ipo",
76+
"bitreader",
77+
"bitwriter",
78+
"linker",
79+
"asmparser",
80+
"mcjit",
81+
"interpreter",
7382
"instrumentation"];
7483

7584
let components = output(Command::new(&llvm_config).arg("--components"));
7685
let mut components = components.split_whitespace().collect::<Vec<_>>();
77-
components.retain(|c| {
78-
optional_components.contains(c) || required_components.contains(c)
79-
});
86+
components.retain(|c| optional_components.contains(c) || required_components.contains(c));
8087

8188
for component in required_components {
8289
if !components.contains(component) {
@@ -96,7 +103,7 @@ fn main() {
96103
for flag in cxxflags.split_whitespace() {
97104
// Ignore flags like `-m64` when we're doing a cross build
98105
if is_crossed && flag.starts_with("-m") {
99-
continue
106+
continue;
100107
}
101108
cfg.flag(flag);
102109
}
@@ -131,7 +138,7 @@ fn main() {
131138
} else if lib.starts_with("-") {
132139
&lib[1..]
133140
} else {
134-
continue
141+
continue;
135142
};
136143

137144
// Don't need or want this library, but LLVM's CMake build system
@@ -140,10 +147,14 @@ fn main() {
140147
// library and it otherwise may just pull in extra dependencies on
141148
// libedit which we don't want
142149
if name == "LLVMLineEditor" {
143-
continue
150+
continue;
144151
}
145152

146-
let kind = if name.starts_with("LLVM") {"static"} else {"dylib"};
153+
let kind = if name.starts_with("LLVM") {
154+
"static"
155+
} else {
156+
"dylib"
157+
};
147158
println!("cargo:rustc-link-lib={}={}", kind, name);
148159
}
149160

‎src/librustc_llvm/diagnostic.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use self::Diagnostic::*;
1616
use libc::{c_char, c_uint};
1717
use std::ptr;
1818

19-
use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef};
19+
use {DebugLocRef, DiagnosticInfoRef, TwineRef, ValueRef};
2020

2121
#[derive(Copy, Clone)]
2222
pub enum OptimizationDiagnosticKind {
@@ -46,8 +46,9 @@ pub struct OptimizationDiagnostic {
4646
}
4747

4848
impl OptimizationDiagnostic {
49-
unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef)
50-
-> OptimizationDiagnostic {
49+
unsafe fn unpack(kind: OptimizationDiagnosticKind,
50+
di: DiagnosticInfoRef)
51+
-> OptimizationDiagnostic {
5152

5253
let mut opt = OptimizationDiagnostic {
5354
kind: kind,
@@ -58,10 +59,10 @@ impl OptimizationDiagnostic {
5859
};
5960

6061
super::LLVMUnpackOptimizationDiagnostic(di,
61-
&mut opt.pass_name,
62-
&mut opt.function,
63-
&mut opt.debug_loc,
64-
&mut opt.message);
62+
&mut opt.pass_name,
63+
&mut opt.function,
64+
&mut opt.debug_loc,
65+
&mut opt.message);
6566

6667
opt
6768
}
@@ -75,8 +76,7 @@ pub struct InlineAsmDiagnostic {
7576
}
7677

7778
impl InlineAsmDiagnostic {
78-
unsafe fn unpack(di: DiagnosticInfoRef)
79-
-> InlineAsmDiagnostic {
79+
unsafe fn unpack(di: DiagnosticInfoRef) -> InlineAsmDiagnostic {
8080

8181
let mut opt = InlineAsmDiagnostic {
8282
cookie: 0,
@@ -85,9 +85,9 @@ impl InlineAsmDiagnostic {
8585
};
8686

8787
super::LLVMUnpackInlineAsmDiagnostic(di,
88-
&mut opt.cookie,
89-
&mut opt.message,
90-
&mut opt.instruction);
88+
&mut opt.cookie,
89+
&mut opt.message,
90+
&mut opt.instruction);
9191

9292
opt
9393
}
@@ -106,22 +106,25 @@ impl Diagnostic {
106106
let kind = super::LLVMGetDiagInfoKind(di);
107107

108108
match kind {
109-
super::DK_InlineAsm
110-
=> InlineAsm(InlineAsmDiagnostic::unpack(di)),
109+
super::DK_InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)),
111110

112-
super::DK_OptimizationRemark
113-
=> Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di)),
111+
super::DK_OptimizationRemark => {
112+
Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di))
113+
}
114114

115-
super::DK_OptimizationRemarkMissed
116-
=> Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di)),
115+
super::DK_OptimizationRemarkMissed => {
116+
Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di))
117+
}
117118

118-
super::DK_OptimizationRemarkAnalysis
119-
=> Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di)),
119+
super::DK_OptimizationRemarkAnalysis => {
120+
Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di))
121+
}
120122

121-
super::DK_OptimizationFailure
122-
=> Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)),
123+
super::DK_OptimizationFailure => {
124+
Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di))
125+
}
123126

124-
_ => UnknownDiagnostic(di)
127+
_ => UnknownDiagnostic(di),
125128
}
126129
}
127130
}

‎src/librustdoc/html/format.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,27 @@ impl fmt::Display for clean::Generics {
111111

112112
for (i, life) in self.lifetimes.iter().enumerate() {
113113
if i > 0 {
114-
f.write_str(", ")?;
114+
f.write_str(",&nbsp;")?;
115115
}
116116
write!(f, "{}", *life)?;
117117
}
118118

119119
if !self.type_params.is_empty() {
120120
if !self.lifetimes.is_empty() {
121-
f.write_str(", ")?;
121+
f.write_str(",&nbsp;")?;
122122
}
123123
for (i, tp) in self.type_params.iter().enumerate() {
124124
if i > 0 {
125-
f.write_str(", ")?
125+
f.write_str(",&nbsp;")?
126126
}
127127
f.write_str(&tp.name)?;
128128

129129
if !tp.bounds.is_empty() {
130-
write!(f, ": {}", TyParamBounds(&tp.bounds))?;
130+
write!(f, ":&nbsp;{}", TyParamBounds(&tp.bounds))?;
131131
}
132132

133133
match tp.default {
134-
Some(ref ty) => { write!(f, " = {}", ty)?; },
134+
Some(ref ty) => { write!(f, "&nbsp;=&nbsp;{}", ty)?; },
135135
None => {}
136136
};
137137
}
@@ -229,21 +229,21 @@ impl fmt::Display for clean::PathParameters {
229229
let mut comma = false;
230230
for lifetime in lifetimes {
231231
if comma {
232-
f.write_str(", ")?;
232+
f.write_str(",&nbsp;")?;
233233
}
234234
comma = true;
235235
write!(f, "{}", *lifetime)?;
236236
}
237237
for ty in types {
238238
if comma {
239-
f.write_str(", ")?;
239+
f.write_str(",&nbsp;")?;
240240
}
241241
comma = true;
242242
write!(f, "{}", *ty)?;
243243
}
244244
for binding in bindings {
245245
if comma {
246-
f.write_str(", ")?;
246+
f.write_str(",&nbsp;")?;
247247
}
248248
comma = true;
249249
write!(f, "{}", *binding)?;

‎src/librustdoc/html/render.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,26 +2243,24 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22432243
write!(w, "</pre>")?;
22442244

22452245
document(w, cx, it)?;
2246-
let mut fields = s.fields.iter().filter(|f| {
2246+
let mut fields = s.fields.iter().filter_map(|f| {
22472247
match f.inner {
2248-
clean::StructFieldItem(..) => true,
2249-
_ => false,
2248+
clean::StructFieldItem(ref ty) => Some((f, ty)),
2249+
_ => None,
22502250
}
22512251
}).peekable();
22522252
if let doctree::Plain = s.struct_type {
22532253
if fields.peek().is_some() {
2254-
write!(w, "<h2 class='fields'>Fields</h2>\n<table>")?;
2255-
for field in fields {
2256-
write!(w, "<tr class='stab {stab}'>
2257-
<td id='{shortty}.{name}'>\
2258-
<code>{name}</code></td><td>",
2254+
write!(w, "<h2 class='fields'>Fields</h2>")?;
2255+
for (field, ty) in fields {
2256+
write!(w, "<span id='{shortty}.{name}'><code>{name}: {ty}</code></span>
2257+
<span class='stab {stab}'></span>",
22592258
shortty = ItemType::StructField,
22602259
stab = field.stability_class(),
2261-
name = field.name.as_ref().unwrap())?;
2260+
name = field.name.as_ref().unwrap(),
2261+
ty = ty)?;
22622262
document(w, cx, field)?;
2263-
write!(w, "</td></tr>")?;
22642263
}
2265-
write!(w, "</table>")?;
22662264
}
22672265
}
22682266
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)
@@ -2292,7 +2290,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22922290
write!(w, "{}(", name)?;
22932291
for (i, ty) in tys.iter().enumerate() {
22942292
if i > 0 {
2295-
write!(w, ", ")?
2293+
write!(w, ",&nbsp;")?
22962294
}
22972295
write!(w, "{}", *ty)?;
22982296
}
@@ -2324,40 +2322,47 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23242322

23252323
document(w, cx, it)?;
23262324
if !e.variants.is_empty() {
2327-
write!(w, "<h2 class='variants'>Variants</h2>\n<table class='variants_table'>")?;
2325+
write!(w, "<h2 class='variants'>Variants</h2>\n")?;
23282326
for variant in &e.variants {
2329-
write!(w, "<tr><td id='{shortty}.{name}'><code>{name}</code></td><td>",
2327+
write!(w, "<span id='{shortty}.{name}' class='variant'><code>{name}",
23302328
shortty = ItemType::Variant,
23312329
name = variant.name.as_ref().unwrap())?;
2330+
if let clean::VariantItem(ref var) = variant.inner {
2331+
if let clean::TupleVariant(ref tys) = var.kind {
2332+
write!(w, "(")?;
2333+
for (i, ty) in tys.iter().enumerate() {
2334+
if i > 0 {
2335+
write!(w, ",&nbsp;")?;
2336+
}
2337+
write!(w, "{}", *ty)?;
2338+
}
2339+
write!(w, ")")?;
2340+
}
2341+
}
2342+
write!(w, "</code></span>")?;
23322343
document(w, cx, variant)?;
23332344

23342345
use clean::{Variant, StructVariant};
23352346
if let clean::VariantItem( Variant { kind: StructVariant(ref s) } ) = variant.inner {
2336-
let fields = s.fields.iter().filter(|f| {
2337-
match f.inner {
2338-
clean::StructFieldItem(..) => true,
2339-
_ => false,
2340-
}
2341-
});
23422347
write!(w, "<h3 class='fields'>Fields</h3>\n
23432348
<table>")?;
2344-
for field in fields {
2345-
write!(w, "<tr><td \
2346-
id='{shortty}.{v}.field.{f}'>\
2347-
<code>{f}</code></td><td>",
2348-
shortty = ItemType::Variant,
2349-
v = variant.name.as_ref().unwrap(),
2350-
f = field.name.as_ref().unwrap())?;
2351-
document(w, cx, field)?;
2352-
write!(w, "</td></tr>")?;
2349+
for field in &s.fields {
2350+
use clean::StructFieldItem;
2351+
if let StructFieldItem(ref ty) = field.inner {
2352+
write!(w, "<tr><td \
2353+
id='variant.{v}.field.{f}'>\
2354+
<code>{f}:&nbsp;{t}</code></td><td>",
2355+
v = variant.name.as_ref().unwrap(),
2356+
f = field.name.as_ref().unwrap(),
2357+
t = *ty)?;
2358+
document(w, cx, field)?;
2359+
write!(w, "</td></tr>")?;
2360+
}
23532361
}
23542362
write!(w, "</table>")?;
23552363
}
2356-
write!(w, "</td><td>")?;
23572364
render_stability_since(w, variant, it)?;
2358-
write!(w, "</td></tr>")?;
23592365
}
2360-
write!(w, "</table>")?;
23612366
}
23622367
render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?;
23632368
Ok(())

‎src/librustdoc/html/static/rustdoc.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ nav.sub {
265265
.docblock h2 { font-size: 1.15em; }
266266
.docblock h3, .docblock h4, .docblock h5 { font-size: 1em; }
267267

268+
.docblock {
269+
margin-left: 24px;
270+
}
271+
268272
.content .out-of-band {
269273
font-size: 23px;
270274
margin: 0px;
@@ -640,6 +644,21 @@ span.since {
640644
margin-right: 5px;
641645
}
642646

647+
.enum > .toggle-wrapper > .collapse-toggle, .struct > .toggle-wrapper > .collapse-toggle {
648+
left: 0;
649+
margin-top: 5px;
650+
}
651+
652+
.enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock {
653+
margin-left: 30px;
654+
margin-bottom: 20px;
655+
margin-top: 5px;
656+
}
657+
658+
.enum > .collapsed, .struct > .collapsed {
659+
margin-bottom: 25px;
660+
}
661+
643662
:target > code {
644663
background: #FDFFD3;
645664
}

‎src/libstd/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,10 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
13381338
///
13391339
/// // one possible implementation of walking a directory only visiting files
13401340
/// fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
1341-
/// if try!(fs::metadata(dir)).is_dir() {
1341+
/// if dir.is_dir() {
13421342
/// for entry in try!(fs::read_dir(dir)) {
13431343
/// let entry = try!(entry);
1344-
/// if try!(fs::metadata(entry.path())).is_dir() {
1344+
/// if try!(entry.file_type()).is_dir() {
13451345
/// try!(visit_dirs(&entry.path(), cb));
13461346
/// } else {
13471347
/// cb(&entry);

‎src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ use syntax::codemap::{self, respan, DUMMY_SP};
201201
use syntax::codemap::Span;
202202
use syntax::errors::Handler;
203203
use syntax::util::move_map::MoveMap;
204-
use syntax::parse::token::{intern, keywords, InternedString};
204+
use syntax::parse::token::{keywords, InternedString};
205205
use syntax::ptr::P;
206206

207207
use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
@@ -1420,31 +1420,13 @@ impl<'a> MethodDef<'a> {
14201420

14211421
// general helper methods.
14221422
impl<'a> TraitDef<'a> {
1423-
fn set_expn_info(&self,
1424-
cx: &mut ExtCtxt,
1425-
mut to_set: Span) -> Span {
1426-
let trait_name = match self.path.path.last() {
1427-
None => cx.span_bug(self.span, "trait with empty path in generic `derive`"),
1428-
Some(name) => *name
1429-
};
1430-
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
1431-
call_site: to_set,
1432-
callee: codemap::NameAndSpan {
1433-
format: codemap::MacroAttribute(intern(&format!("derive({})", trait_name))),
1434-
span: Some(self.span),
1435-
allow_internal_unstable: false,
1436-
}
1437-
});
1438-
to_set
1439-
}
1440-
14411423
fn summarise_struct(&self,
14421424
cx: &mut ExtCtxt,
14431425
struct_def: &VariantData) -> StaticFields {
14441426
let mut named_idents = Vec::new();
14451427
let mut just_spans = Vec::new();
14461428
for field in struct_def.fields(){
1447-
let sp = self.set_expn_info(cx, field.span);
1429+
let sp = Span { expn_id: self.span.expn_id, ..field.span };
14481430
match field.ident {
14491431
Some(ident) => named_idents.push((ident, sp)),
14501432
_ => just_spans.push(sp),
@@ -1486,7 +1468,7 @@ impl<'a> TraitDef<'a> {
14861468
let mut paths = Vec::new();
14871469
let mut ident_exprs = Vec::new();
14881470
for (i, struct_field) in struct_def.fields().iter().enumerate() {
1489-
let sp = self.set_expn_info(cx, struct_field.span);
1471+
let sp = Span { expn_id: self.span.expn_id, ..struct_field.span };
14901472
let ident = cx.ident_of(&format!("{}_{}", prefix, i));
14911473
paths.push(codemap::Spanned{span: sp, node: ident});
14921474
let val = cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident)));

‎src/libsyntax_ext/deriving/mod.rs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use syntax::ext::base::{ExtCtxt, SyntaxEnv, Annotatable};
1616
use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier};
1717
use syntax::ext::build::AstBuilder;
1818
use syntax::feature_gate;
19-
use syntax::codemap::Span;
19+
use syntax::codemap::{self, Span};
2020
use syntax::parse::token::{intern, intern_and_get_ident};
2121
use syntax::ptr::P;
2222

@@ -94,37 +94,7 @@ fn expand_derive(cx: &mut ExtCtxt,
9494
}
9595

9696
let mut found_partial_eq = false;
97-
let mut found_eq = false;
98-
99-
// This span is **very** sensitive and crucial to
100-
// getting the stability behavior we want. What we are
101-
// doing is marking the generated `#[derive_*]` with the
102-
// span of the `#[deriving(...)]` attribute (the
103-
// entire attribute, not just the `PartialEq` or `Eq`
104-
// part), but with the current backtrace. The current
105-
// backtrace will contain a topmost entry that IS this
106-
// `#[deriving(...)]` attribute and with the
107-
// "allow-unstable" flag set to true.
108-
//
109-
// Note that we do NOT use the span of the `Eq`
110-
// text itself. You might think this is
111-
// equivalent, because the `Eq` appears within the
112-
// `#[deriving(Eq)]` attribute, and hence we would
113-
// inherit the "allows unstable" from the
114-
// backtrace. But in fact this is not always the
115-
// case. The actual source text that led to
116-
// deriving can be `#[$attr]`, for example, where
117-
// `$attr == deriving(Eq)`. In that case, the
118-
// "#[derive_*]" would be considered to
119-
// originate not from the deriving call but from
120-
// text outside the deriving call, and hence would
121-
// be forbidden from using unstable
122-
// content.
123-
//
124-
// See tests src/run-pass/rfc1445 for
125-
// examples. --nmatsakis
126-
let span = Span { expn_id: cx.backtrace(), .. span };
127-
assert!(cx.parse_sess.codemap().span_allows_unstable(span));
97+
let mut eq_span = None;
12898

12999
for titem in traits.iter().rev() {
130100
let tname = match titem.node {
@@ -144,8 +114,19 @@ fn expand_derive(cx: &mut ExtCtxt,
144114
continue;
145115
}
146116

117+
let span = Span {
118+
expn_id: cx.codemap().record_expansion(codemap::ExpnInfo {
119+
call_site: titem.span,
120+
callee: codemap::NameAndSpan {
121+
format: codemap::MacroAttribute(intern(&format!("derive({})", tname))),
122+
span: Some(titem.span),
123+
allow_internal_unstable: true,
124+
},
125+
}), ..titem.span
126+
};
127+
147128
if &tname[..] == "Eq" {
148-
found_eq = true;
129+
eq_span = Some(span);
149130
} else if &tname[..] == "PartialEq" {
150131
found_partial_eq = true;
151132
}
@@ -157,12 +138,13 @@ fn expand_derive(cx: &mut ExtCtxt,
157138

158139
// RFC #1445. `#[derive(PartialEq, Eq)]` adds a (trusted)
159140
// `#[structural_match]` attribute.
160-
if found_partial_eq && found_eq {
161-
debug!("inserting structural_match with span {:?}", span);
162-
let structural_match = intern_and_get_ident("structural_match");
163-
item.attrs.push(cx.attribute(span,
164-
cx.meta_word(span,
165-
structural_match)));
141+
if let Some(eq_span) = eq_span {
142+
if found_partial_eq {
143+
let structural_match = intern_and_get_ident("structural_match");
144+
item.attrs.push(cx.attribute(eq_span,
145+
cx.meta_word(eq_span,
146+
structural_match)));
147+
}
166148
}
167149

168150
item

‎src/test/compile-fail/issue-33571.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[derive(Clone,
12+
Sync, //~ ERROR this unsafe trait should be implemented explicitly
13+
Copy)]
14+
enum Foo {}

0 commit comments

Comments
 (0)
Please sign in to comment.