Skip to content

Commit d616dba

Browse files
committed
---
yaml --- r: 190253 b: refs/heads/tmp c: edbc0e5 h: refs/heads/master i: 190251: ede9cf3 v: v3
1 parent 3c1d930 commit d616dba

File tree

9 files changed

+129
-145
lines changed

9 files changed

+129
-145
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 30e1f9a1c2bf7134135800bc9afd082773defadc
37+
refs/heads/tmp: edbc0e509f016426f6366fba0d0001bc828bd450
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3939
refs/tags/homu-tmp: d3c49d2140fc65e8bb7d7cf25bfe74dda6ce5ecf

branches/tmp/src/librustc/middle/check_match.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ fn is_useful(cx: &MatchCheckCtxt,
646646
if rows[0].len() == 0 {
647647
return NotUseful;
648648
}
649+
assert!(rows.iter().all(|r| r.len() == v.len()));
649650
let real_pat = match rows.iter().find(|r| (*r)[0].id != DUMMY_NODE_ID) {
650651
Some(r) => raw_pat(r[0]),
651652
None if v.len() == 0 => return NotUseful,
@@ -654,7 +655,12 @@ fn is_useful(cx: &MatchCheckCtxt,
654655
let left_ty = if real_pat.id == DUMMY_NODE_ID {
655656
ty::mk_nil(cx.tcx)
656657
} else {
657-
ty::pat_ty(cx.tcx, &*real_pat)
658+
let left_ty = ty::pat_ty(cx.tcx, &*real_pat);
659+
660+
match real_pat.node {
661+
ast::PatIdent(ast::BindByRef(..), _, _) => ty::deref(left_ty, false).unwrap().ty,
662+
_ => left_ty,
663+
}
658664
};
659665

660666
let max_slice_length = rows.iter().filter_map(|row| match row[0].node {

branches/tmp/src/librustc/middle/dead.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
4747
struct_has_extern_repr: bool,
4848
ignore_non_const_paths: bool,
4949
inherited_pub_visibility: bool,
50+
ignore_variant_stack: Vec<ast::NodeId>,
5051
}
5152

5253
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
@@ -59,6 +60,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
5960
struct_has_extern_repr: false,
6061
ignore_non_const_paths: false,
6162
inherited_pub_visibility: false,
63+
ignore_variant_stack: vec![],
6264
}
6365
}
6466

@@ -79,7 +81,9 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7981
def::DefPrimTy(_) => (),
8082
def::DefVariant(enum_id, variant_id, _) => {
8183
self.check_def_id(enum_id);
82-
self.check_def_id(variant_id);
84+
if !self.ignore_variant_stack.contains(&variant_id.node) {
85+
self.check_def_id(variant_id);
86+
}
8387
}
8488
_ => {
8589
self.check_def_id(def.def_id());
@@ -278,6 +282,23 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
278282
visit::walk_expr(self, expr);
279283
}
280284

285+
fn visit_arm(&mut self, arm: &ast::Arm) {
286+
if arm.pats.len() == 1 {
287+
let pat = &*arm.pats[0];
288+
let variants = pat_util::necessary_variants(&self.tcx.def_map, pat);
289+
290+
// Inside the body, ignore constructions of variants
291+
// necessary for the pattern to match. Those construction sites
292+
// can't be reached unless the variant is constructed elsewhere.
293+
let len = self.ignore_variant_stack.len();
294+
self.ignore_variant_stack.push_all(&*variants);
295+
visit::walk_arm(self, arm);
296+
self.ignore_variant_stack.truncate(len);
297+
} else {
298+
visit::walk_arm(self, arm);
299+
}
300+
}
301+
281302
fn visit_pat(&mut self, pat: &ast::Pat) {
282303
let def_map = &self.tcx.def_map;
283304
match pat.node {
@@ -397,6 +418,11 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
397418
worklist.push(*id);
398419
}
399420
for id in reachable_symbols {
421+
// Reachable variants can be dead, because we warn about
422+
// variants never constructed, not variants never used.
423+
if let Some(ast_map::NodeVariant(..)) = tcx.map.find(*id) {
424+
continue;
425+
}
400426
worklist.push(*id);
401427
}
402428

branches/tmp/src/librustc/middle/pat_util.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,27 @@ pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path {
155155
span: DUMMY_SP,
156156
})
157157
}
158+
159+
/// Return variants that are necessary to exist for the pattern to match.
160+
pub fn necessary_variants(dm: &DefMap, pat: &ast::Pat) -> Vec<ast::NodeId> {
161+
let mut variants = vec![];
162+
walk_pat(pat, |p| {
163+
match p.node {
164+
ast::PatEnum(_, _) |
165+
ast::PatIdent(_, _, None) |
166+
ast::PatStruct(..) => {
167+
match dm.borrow().get(&p.id) {
168+
Some(&PathResolution {base_def: DefVariant(_, id, _), ..}) => {
169+
variants.push(id.node);
170+
}
171+
_ => ()
172+
}
173+
}
174+
_ => ()
175+
}
176+
true
177+
});
178+
variants.sort();
179+
variants.dedup();
180+
variants
181+
}

branches/tmp/src/librustdoc/html/render.rs

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
//! both occur before the crate is rendered.
3535
pub use self::ExternalLocation::*;
3636

37-
use std::ascii::OwnedAsciiExt;
3837
use std::cell::RefCell;
3938
use std::cmp::Ordering;
4039
use std::collections::{HashMap, HashSet};
@@ -240,51 +239,6 @@ struct IndexItem {
240239
path: String,
241240
desc: String,
242241
parent: Option<ast::DefId>,
243-
search_type: Option<IndexItemFunctionType>,
244-
}
245-
246-
/// A type used for the search index.
247-
struct Type {
248-
name: Option<String>,
249-
}
250-
251-
impl fmt::Display for Type {
252-
/// Formats type as {name: $name}.
253-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
254-
// Wrapping struct fmt should never call us when self.name is None,
255-
// but just to be safe we write `null` in that case.
256-
match self.name {
257-
Some(ref n) => write!(f, "{{\"name\":\"{}\"}}", n),
258-
None => write!(f, "null")
259-
}
260-
}
261-
}
262-
263-
/// Full type of functions/methods in the search index.
264-
struct IndexItemFunctionType {
265-
inputs: Vec<Type>,
266-
output: Option<Type>
267-
}
268-
269-
impl fmt::Display for IndexItemFunctionType {
270-
/// Formats a full fn type as a JSON {inputs: [Type], outputs: Type/null}.
271-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
272-
// If we couldn't figure out a type, just write `null`.
273-
if self.inputs.iter().any(|ref i| i.name.is_none()) ||
274-
(self.output.is_some() && self.output.as_ref().unwrap().name.is_none()) {
275-
return write!(f, "null")
276-
}
277-
278-
let inputs: Vec<String> = self.inputs.iter().map(|ref t| format!("{}", t)).collect();
279-
try!(write!(f, "{{\"inputs\":[{}],\"output\":", inputs.connect(",")));
280-
281-
match self.output {
282-
Some(ref t) => try!(write!(f, "{}", t)),
283-
None => try!(write!(f, "null"))
284-
};
285-
286-
Ok(try!(write!(f, "}}")))
287-
}
288242
}
289243

290244
// TLS keys used to carry information around during rendering.
@@ -455,7 +409,6 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> {
455409
path: fqp[..fqp.len() - 1].connect("::"),
456410
desc: shorter(item.doc_value()).to_string(),
457411
parent: Some(did),
458-
search_type: None,
459412
});
460413
},
461414
None => {}
@@ -505,11 +458,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::Result<String> {
505458
let pathid = *nodeid_to_pathid.get(&nodeid).unwrap();
506459
try!(write!(&mut w, ",{}", pathid));
507460
}
508-
None => try!(write!(&mut w, ",null"))
509-
}
510-
match item.search_type {
511-
Some(ref t) => try!(write!(&mut w, ",{}", t)),
512-
None => try!(write!(&mut w, ",null"))
461+
None => {}
513462
}
514463
try!(write!(&mut w, "]"));
515464
}
@@ -923,21 +872,12 @@ impl DocFolder for Cache {
923872

924873
match parent {
925874
(parent, Some(path)) if is_method || (!self.privmod && !hidden_field) => {
926-
// Needed to determine `self` type.
927-
let parent_basename = self.parent_stack.first().and_then(|parent| {
928-
match self.paths.get(parent) {
929-
Some(&(ref fqp, _)) => Some(fqp[fqp.len() - 1].clone()),
930-
_ => None
931-
}
932-
});
933-
934875
self.search_index.push(IndexItem {
935876
ty: shortty(&item),
936877
name: s.to_string(),
937878
path: path.connect("::").to_string(),
938879
desc: shorter(item.doc_value()).to_string(),
939880
parent: parent,
940-
search_type: get_index_search_type(&item, parent_basename),
941881
});
942882
}
943883
(Some(parent), None) if is_method || (!self.privmod && !hidden_field)=> {
@@ -2367,52 +2307,6 @@ fn make_item_keywords(it: &clean::Item) -> String {
23672307
format!("{}, {}", get_basic_keywords(), it.name.as_ref().unwrap())
23682308
}
23692309

2370-
fn get_index_search_type(item: &clean::Item,
2371-
parent: Option<String>) -> Option<IndexItemFunctionType> {
2372-
let decl = match item.inner {
2373-
clean::FunctionItem(ref f) => &f.decl,
2374-
clean::MethodItem(ref m) => &m.decl,
2375-
clean::TyMethodItem(ref m) => &m.decl,
2376-
_ => return None
2377-
};
2378-
2379-
let mut inputs = Vec::new();
2380-
2381-
// Consider `self` an argument as well.
2382-
if let Some(name) = parent {
2383-
inputs.push(Type { name: Some(name.into_ascii_lowercase()) });
2384-
}
2385-
2386-
inputs.extend(&mut decl.inputs.values.iter().map(|arg| {
2387-
get_index_type(&arg.type_)
2388-
}));
2389-
2390-
let output = match decl.output {
2391-
clean::FunctionRetTy::Return(ref return_type) => Some(get_index_type(return_type)),
2392-
_ => None
2393-
};
2394-
2395-
Some(IndexItemFunctionType { inputs: inputs, output: output })
2396-
}
2397-
2398-
fn get_index_type(clean_type: &clean::Type) -> Type {
2399-
Type { name: get_index_type_name(clean_type).map(|s| s.into_ascii_lowercase()) }
2400-
}
2401-
2402-
fn get_index_type_name(clean_type: &clean::Type) -> Option<String> {
2403-
match *clean_type {
2404-
clean::ResolvedPath { ref path, .. } => {
2405-
let segments = &path.segments;
2406-
Some(segments[segments.len() - 1].name.clone())
2407-
},
2408-
clean::Generic(ref s) => Some(s.clone()),
2409-
clean::Primitive(ref p) => Some(format!("{:?}", p)),
2410-
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_),
2411-
// FIXME: add all from clean::Type.
2412-
_ => None
2413-
}
2414-
}
2415-
24162310
pub fn cache() -> Arc<Cache> {
24172311
CACHE_KEY.with(|c| c.borrow().clone())
24182312
}

branches/tmp/src/librustdoc/html/static/main.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -209,33 +209,6 @@
209209
break;
210210
}
211211
}
212-
// searching by type
213-
} else if (val.search("->") > -1) {
214-
var trimmer = function (s) { return s.trim(); };
215-
var parts = val.split("->").map(trimmer);
216-
var input = parts[0];
217-
// sort inputs so that order does not matter
218-
var inputs = input.split(",").map(trimmer).sort();
219-
var output = parts[1];
220-
221-
for (var i = 0; i < nSearchWords; ++i) {
222-
var type = searchIndex[i].type;
223-
if (!type) {
224-
continue;
225-
}
226-
227-
// sort index inputs so that order does not matter
228-
var typeInputs = type.inputs.map(function (input) {
229-
return input.name;
230-
}).sort();
231-
232-
// allow searching for void (no output) functions as well
233-
var typeOutput = type.output ? type.output.name : "";
234-
if (inputs.toString() === typeInputs.toString() &&
235-
output == typeOutput) {
236-
results.push({id: i, index: -1, dontValidate: true});
237-
}
238-
}
239212
} else {
240213
// gather matching search results up to a certain maximum
241214
val = val.replace(/\_/g, "");
@@ -356,11 +329,6 @@
356329
path = result.item.path.toLowerCase(),
357330
parent = result.item.parent;
358331

359-
// this validation does not make sense when searching by types
360-
if (result.dontValidate) {
361-
continue;
362-
}
363-
364332
var valid = validateResult(name, path, split, parent);
365333
if (!valid) {
366334
result.id = -1;
@@ -605,8 +573,7 @@
605573
// (String) name,
606574
// (String) full path or empty string for previous path,
607575
// (String) description,
608-
// (Number | null) the parent path index to `paths`]
609-
// (Object | null) the type of the function (if any)
576+
// (optional Number) the parent path index to `paths`]
610577
var items = rawSearchIndex[crate].items;
611578
// an array of [(Number) item type,
612579
// (String) name]
@@ -631,7 +598,7 @@
631598
var rawRow = items[i];
632599
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
633600
path: rawRow[2] || lastPath, desc: rawRow[3],
634-
parent: paths[rawRow[4]], type: rawRow[5]};
601+
parent: paths[rawRow[4]]};
635602
searchIndex.push(row);
636603
if (typeof row.name === "string") {
637604
var word = row.name.toLowerCase();

branches/tmp/src/libtest/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl fmt::Display for TestName {
123123
#[derive(Clone, Copy)]
124124
enum NamePadding {
125125
PadNone,
126+
#[allow(dead_code)]
126127
PadOnLeft,
127128
PadOnRight,
128129
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2015 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+
#![deny(dead_code)]
12+
13+
#[derive(Copy)]
14+
enum Enum {
15+
Variant1, //~ ERROR: variant is never used
16+
Variant2,
17+
Variant3,
18+
}
19+
20+
fn copy(e: Enum) -> Enum {
21+
use Enum::*;
22+
match e {
23+
Variant1 => Variant1,
24+
Variant2 => Variant2,
25+
Variant3 => Variant3,
26+
}
27+
}
28+
29+
fn max(e: Enum) -> Enum {
30+
use Enum::*;
31+
match e {
32+
Variant1 => Variant3,
33+
Variant2 => Variant3,
34+
Variant3 => Variant3,
35+
}
36+
}
37+
38+
fn main() {
39+
let e = Enum::Variant2;
40+
copy(e);
41+
max(e);
42+
}

0 commit comments

Comments
 (0)