Skip to content
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

Rollup of 8 pull requests #38106

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dac987e
add regression test for #36168
nikomatsakis Nov 21, 2016
1a91fc6
Add missing examples for Ipv6Addr
GuillaumeGomez Nov 18, 2016
a5049f7
Add ::1 example in IPv6 to IPv4 conversion
GuillaumeGomez Nov 22, 2016
ebcc6d2
Add part of missing UdpSocket's urls and examples
GuillaumeGomez Nov 26, 2016
0bcb05c
Finishing d2f8fb0a0a9dd from @jseyfried
dns2utf8 Nov 27, 2016
2dc3fdf
Resolve visibility issues
dns2utf8 Nov 27, 2016
28b64dc
Use keywords::Invalid
dns2utf8 Nov 27, 2016
72fbf9f
fixup test cases
nikomatsakis Nov 28, 2016
ffcdc19
bootstrap/README: fix small typo
cardoe Nov 29, 2016
336e5dd
Add missing examples for IpAddr enum
GuillaumeGomez Nov 29, 2016
d21861d
Refactor one_bound_for_assoc_type to take an Iterator instead of Vec.
Mark-Simulacrum Nov 27, 2016
8e6ae19
Add cloned example for Option
GuillaumeGomez Nov 30, 2016
8de607c
Rollup merge of #37859 - GuillaumeGomez:net_examples, r=nagisa
dns2utf8 Dec 1, 2016
9709dba
Rollup merge of #37919 - nikomatsakis:incremental-36168, r=mw
dns2utf8 Dec 1, 2016
031a485
Rollup merge of #38020 - GuillaumeGomez:udp-socket-doc, r=frewsxcv
dns2utf8 Dec 1, 2016
fede13b
Rollup merge of #38028 - Mark-Simulacrum:polish, r=nikomatsakis
dns2utf8 Dec 1, 2016
b7ae05e
Rollup merge of #38029 - dns2utf8:fix_verify.rs, r=petrochenkov
dns2utf8 Dec 1, 2016
e9fa764
Rollup merge of #38073 - cardoe:fix-typo, r=frewsxcv
dns2utf8 Dec 1, 2016
464faa1
Rollup merge of #38077 - GuillaumeGomez:ipaddr_doc, r=frewsxcv
dns2utf8 Dec 1, 2016
0c28d5d
Rollup merge of #38090 - GuillaumeGomez:option_doc, r=frewsxcv
dns2utf8 Dec 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The script accepts commands, flags, and filters to determine what to do:
# build the whole compiler
./x.py build

# build the stage1 compier
# build the stage1 compiler
./x.py build --stage 1

# build stage0 libstd
Expand Down
36 changes: 19 additions & 17 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ use std::fs::File;
use std::io::{BufRead, Read};
use std::path::Path;

use syntax::parse;
use syntax::parse::lexer;
use rustc::dep_graph::DepGraph;
use rustc::session::{self, config};
use rustc::middle::cstore::DummyCrateStore;

use std::rc::Rc;
use syntax::ast;
use syntax::ast::Name;
use syntax::codemap;
use syntax::parse::token::{self, BinOpToken, DelimToken, Lit, Token};
use syntax::parse::lexer::TokenAndSpan;
use syntax_pos::Pos;

use syntax::symbol::{Symbol, keywords};

fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
fn id() -> token::Token {
Token::Ident(ast::Ident::with_empty_ctxt(Name(0)))
Token::Ident(ast::Ident::with_empty_ctxt(keywords::Invalid.name()))
}

let mut res = HashMap::new();
Expand All @@ -65,7 +65,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"SHL" => Token::BinOp(BinOpToken::Shl),
"LBRACE" => Token::OpenDelim(DelimToken::Brace),
"RARROW" => Token::RArrow,
"LIT_STR" => Token::Literal(Lit::Str_(Name(0)), None),
"LIT_STR" => Token::Literal(Lit::Str_(keywords::Invalid.name()), None),
"DOTDOT" => Token::DotDot,
"MOD_SEP" => Token::ModSep,
"DOTDOTDOT" => Token::DotDotDot,
Expand All @@ -75,21 +75,22 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"ANDAND" => Token::AndAnd,
"AT" => Token::At,
"LBRACKET" => Token::OpenDelim(DelimToken::Bracket),
"LIT_STR_RAW" => Token::Literal(Lit::StrRaw(Name(0), 0), None),
"LIT_STR_RAW" => Token::Literal(Lit::StrRaw(keywords::Invalid.name(), 0), None),
"RPAREN" => Token::CloseDelim(DelimToken::Paren),
"SLASH" => Token::BinOp(BinOpToken::Slash),
"COMMA" => Token::Comma,
"LIFETIME" => Token::Lifetime(ast::Ident::with_empty_ctxt(Name(0))),
"LIFETIME" => Token::Lifetime(
ast::Ident::with_empty_ctxt(keywords::Invalid.name())),
"CARET" => Token::BinOp(BinOpToken::Caret),
"TILDE" => Token::Tilde,
"IDENT" => id(),
"PLUS" => Token::BinOp(BinOpToken::Plus),
"LIT_CHAR" => Token::Literal(Lit::Char(Name(0)), None),
"LIT_BYTE" => Token::Literal(Lit::Byte(Name(0)), None),
"LIT_CHAR" => Token::Literal(Lit::Char(keywords::Invalid.name()), None),
"LIT_BYTE" => Token::Literal(Lit::Byte(keywords::Invalid.name()), None),
"EQ" => Token::Eq,
"RBRACKET" => Token::CloseDelim(DelimToken::Bracket),
"COMMENT" => Token::Comment,
"DOC_COMMENT" => Token::DocComment(Name(0)),
"DOC_COMMENT" => Token::DocComment(keywords::Invalid.name()),
"DOT" => Token::Dot,
"EQEQ" => Token::EqEq,
"NE" => Token::Ne,
Expand All @@ -99,9 +100,9 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"BINOP" => Token::BinOp(BinOpToken::Plus),
"POUND" => Token::Pound,
"OROR" => Token::OrOr,
"LIT_INTEGER" => Token::Literal(Lit::Integer(Name(0)), None),
"LIT_INTEGER" => Token::Literal(Lit::Integer(keywords::Invalid.name()), None),
"BINOPEQ" => Token::BinOpEq(BinOpToken::Plus),
"LIT_FLOAT" => Token::Literal(Lit::Float(Name(0)), None),
"LIT_FLOAT" => Token::Literal(Lit::Float(keywords::Invalid.name()), None),
"WHITESPACE" => Token::Whitespace,
"UNDERSCORE" => Token::Underscore,
"MINUS" => Token::BinOp(BinOpToken::Minus),
Expand All @@ -111,10 +112,11 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"OR" => Token::BinOp(BinOpToken::Or),
"GT" => Token::Gt,
"LE" => Token::Le,
"LIT_BINARY" => Token::Literal(Lit::ByteStr(Name(0)), None),
"LIT_BINARY_RAW" => Token::Literal(Lit::ByteStrRaw(Name(0), 0), None),
"LIT_BINARY" => Token::Literal(Lit::ByteStr(keywords::Invalid.name()), None),
"LIT_BINARY_RAW" => Token::Literal(
Lit::ByteStrRaw(keywords::Invalid.name(), 0), None),
"QUESTION" => Token::Question,
"SHEBANG" => Token::Shebang(Name(0)),
"SHEBANG" => Token::Shebang(keywords::Invalid.name()),
_ => continue,
};

Expand Down Expand Up @@ -158,7 +160,7 @@ fn fix(mut lit: &str) -> ast::Name {
let leading_hashes = count(lit);

// +1/-1 to adjust for single quotes
parse::token::intern(&lit[leading_hashes + 1..lit.len() - leading_hashes - 1])
Symbol::intern(&lit[leading_hashes + 1..lit.len() - leading_hashes - 1])
}

/// Assuming a char/byte literal, strip the 'b' prefix and the single quotes.
Expand All @@ -168,7 +170,7 @@ fn fixchar(mut lit: &str) -> ast::Name {
lit = &lit[1..];
}

parse::token::intern(&lit[1..lit.len() - 1])
Symbol::intern(&lit[1..lit.len() - 1])
}

fn count(lit: &str) -> usize {
Expand Down Expand Up @@ -196,7 +198,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
let not_found = format!("didn't find token {:?} in the map", toknum);
let proto_tok = tokens.get(toknum).expect(&not_found[..]);

let nm = parse::token::intern(content);
let nm = Symbol::intern(content);

debug!("What we got: content (`{}`), proto: {:?}", content, proto_tok);

Expand Down
10 changes: 10 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ impl<T> Option<T> {
impl<'a, T: Clone> Option<&'a T> {
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
/// option.
///
/// # Examples
///
/// ```
/// let x = 12;
/// let opt_x = Some(&x);
/// assert_eq!(opt_x, Some(&12));
/// let cloned = opt_x.cloned();
/// assert_eq!(cloned, Some(12));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.clone())
Expand Down
66 changes: 33 additions & 33 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// those that do.
self.ensure_super_predicates(binding.span, trait_ref.def_id())?;

let candidates: Vec<ty::PolyTraitRef> =
let candidates =
traits::supertraits(tcx, trait_ref.clone())
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), binding.item_name))
.collect();
.filter(|r| self.trait_defines_associated_type_named(r.def_id(), binding.item_name));

let candidate = self.one_bound_for_assoc_type(candidates,
&trait_ref.to_string(),
Expand Down Expand Up @@ -1191,10 +1190,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {

// Check that there is exactly one way to find an associated type with the
// correct name.
let suitable_bounds: Vec<_> =
let suitable_bounds =
traits::transitive_bounds(tcx, &bounds)
.filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name))
.collect();
.filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name));

self.one_bound_for_assoc_type(suitable_bounds,
&ty_param_name.as_str(),
Expand All @@ -1205,54 +1203,57 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {

// Checks that bounds contains exactly one element and reports appropriate
// errors otherwise.
fn one_bound_for_assoc_type(&self,
bounds: Vec<ty::PolyTraitRef<'tcx>>,
fn one_bound_for_assoc_type<I>(&self,
mut bounds: I,
ty_param_name: &str,
assoc_name: &str,
span: Span)
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
where I: Iterator<Item=ty::PolyTraitRef<'tcx>>
{
if bounds.is_empty() {
struct_span_err!(self.tcx().sess, span, E0220,
"associated type `{}` not found for `{}`",
assoc_name,
ty_param_name)
.span_label(span, &format!("associated type `{}` not found", assoc_name))
.emit();
return Err(ErrorReported);
}

if bounds.len() > 1 {
let spans = bounds.iter().map(|b| {
self.tcx().associated_items(b.def_id()).find(|item| {
item.kind == ty::AssociatedKind::Type && item.name == assoc_name
})
.and_then(|item| self.tcx().map.span_if_local(item.def_id))
});
let bound = match bounds.next() {
Some(bound) => bound,
None => {
struct_span_err!(self.tcx().sess, span, E0220,
"associated type `{}` not found for `{}`",
assoc_name,
ty_param_name)
.span_label(span, &format!("associated type `{}` not found", assoc_name))
.emit();
return Err(ErrorReported);
}
};

if let Some(bound2) = bounds.next() {
let bounds = iter::once(bound).chain(iter::once(bound2)).chain(bounds);
let mut err = struct_span_err!(
self.tcx().sess, span, E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name);
err.span_label(span, &format!("ambiguous associated type `{}`", assoc_name));

for span_and_bound in spans.zip(&bounds) {
if let Some(span) = span_and_bound.0 {
for bound in bounds {
let bound_span = self.tcx().associated_items(bound.def_id()).find(|item| {
item.kind == ty::AssociatedKind::Type && item.name == assoc_name
})
.and_then(|item| self.tcx().map.span_if_local(item.def_id));

if let Some(span) = bound_span {
err.span_label(span, &format!("ambiguous `{}` from `{}`",
assoc_name,
span_and_bound.1));
bound));
} else {
span_note!(&mut err, span,
"associated type `{}` could derive from `{}`",
ty_param_name,
span_and_bound.1);
bound);
}
}
err.emit();
}

Ok(bounds[0].clone())
return Ok(bound);
}

// Create a type from a path to an associated type.
Expand Down Expand Up @@ -1293,11 +1294,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
return (tcx.types.err, Def::Err);
}

let candidates: Vec<ty::PolyTraitRef> =
let candidates =
traits::supertraits(tcx, ty::Binder(trait_ref))
.filter(|r| self.trait_defines_associated_type_named(r.def_id(),
assoc_name))
.collect();
assoc_name));

match self.one_bound_for_assoc_type(candidates,
"Self",
Expand Down
Loading