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 7 pull requests #65032

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5cbe6aa
Reword E0392 slightly
estebank Sep 30, 2019
7b480cd
Implement Clone::clone_from for LinkedList
crgl Oct 1, 2019
2537a8a
syntax: improve parameter without type suggestions
davidtwco Oct 1, 2019
fb80e6c
BacktraceStatus: add Eq impl
mathstuf Oct 2, 2019
03455e4
Filter out RLS output directories on tidy runs
spastorino Oct 2, 2019
c845f3d
track the kind of async generator we are creating
nikomatsakis Sep 25, 2019
44e801a
thread down the body so we can check if this is an async fn body
nikomatsakis Sep 25, 2019
c8e5851
improved debug output
nikomatsakis Oct 2, 2019
f7ed53c
extract expected return type from `-> impl Future` obligation
nikomatsakis Oct 2, 2019
094f3a8
WIP tidy hir/lowering/expr.rs
nikomatsakis Oct 2, 2019
81cd596
WIP rebase for `shallow_resolve` call
nikomatsakis Oct 2, 2019
5055d4b
Use zipped iterators in clone_from for LinkedList
crgl Oct 2, 2019
df203a2
Compare primary with value instead of dropping it
AnthonyMikh Oct 2, 2019
dce20bf
WIP fix tests
nikomatsakis Oct 2, 2019
3ae4abb
correct coercion comments
nikomatsakis Oct 2, 2019
a999132
improve comments on `GeneratorKind` and `AsyncGeneratorKind`
nikomatsakis Oct 2, 2019
5d64b3d
document `ret_coercion` and `ret_coercion_span`
nikomatsakis Oct 2, 2019
5fea1d2
document `shallow_resolve`
nikomatsakis Oct 2, 2019
3f277e1
s/`async` fn/`async fn`/
nikomatsakis Oct 2, 2019
a96bce7
avoid using `skip_binder` and instead look for bound vars properly
nikomatsakis Oct 2, 2019
864e6fe
Add test for LinkedList clone_from
crgl Oct 2, 2019
a180294
review comment
estebank Oct 2, 2019
4a49351
add unsize slice-str coercion
nikomatsakis Oct 2, 2019
19c07cc
fix example (le sigh)
nikomatsakis Oct 2, 2019
e948b08
Rollup merge of #64931 - estebank:missing-param-ref, r=matthewjasper,…
Centril Oct 2, 2019
f770830
Rollup merge of #64959 - davidtwco:issue-64252-self-type-help, r=Cent…
Centril Oct 2, 2019
d1edd84
Rollup merge of #64975 - crgl:clone-from-linked-list, r=bluss
Centril Oct 2, 2019
1541091
Rollup merge of #64993 - mathstuf:backtrace-status-eq, r=withoutboats
Centril Oct 2, 2019
f6125f1
Rollup merge of #64998 - spastorino:filter-rls-on-tidy, r=petrochenkov
Centril Oct 2, 2019
bb39529
Rollup merge of #64999 - nikomatsakis:issue-60424-async-return-infere…
Centril Oct 2, 2019
9e9e5b3
Rollup merge of #65010 - AnthonyMikh:fix_65001, r=estebank
Centril Oct 2, 2019
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
13 changes: 13 additions & 0 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,19 @@ impl<T: Clone> Clone for LinkedList<T> {
fn clone(&self) -> Self {
self.iter().cloned().collect()
}

fn clone_from(&mut self, other: &Self) {
let mut iter_other = other.iter();
if self.len() > other.len() {
self.split_off(other.len());
}
for (elem, elem_other) in self.iter_mut().zip(&mut iter_other) {
elem.clone_from(elem_other);
}
if !iter_other.is_empty() {
self.extend(iter_other.cloned());
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
43 changes: 43 additions & 0 deletions src/liballoc/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,49 @@ fn test_append() {
check_links(&n);
}

#[test]
fn test_clone_from() {
// Short cloned from long
{
let v = vec![1, 2, 3, 4, 5];
let u = vec![8, 7, 6, 2, 3, 4, 5];
let mut m = list_from(&v);
let n = list_from(&u);
m.clone_from(&n);
check_links(&m);
assert_eq!(m, n);
for elt in u {
assert_eq!(m.pop_front(), Some(elt))
}
}
// Long cloned from short
{
let v = vec![1, 2, 3, 4, 5];
let u = vec![6, 7, 8];
let mut m = list_from(&v);
let n = list_from(&u);
m.clone_from(&n);
check_links(&m);
assert_eq!(m, n);
for elt in u {
assert_eq!(m.pop_front(), Some(elt))
}
}
// Two equal length lists
{
let v = vec![1, 2, 3, 4, 5];
let u = vec![9, 8, 1, 2, 3];
let mut m = list_from(&v);
let n = list_from(&u);
m.clone_from(&n);
check_links(&m);
assert_eq!(m, n);
for elt in u {
assert_eq!(m.pop_front(), Some(elt))
}
}
}

#[test]
fn test_insert_prev() {
let mut m = list_from(&[0, 2, 4, 6, 8]);
Expand Down
30 changes: 19 additions & 11 deletions src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ impl LoweringContext<'_> {
hir::MatchSource::Normal,
),
ExprKind::Async(capture_clause, closure_node_id, ref block) => {
self.make_async_expr(capture_clause, closure_node_id, None, block.span, |this| {
this.with_new_scopes(|this| this.lower_block_expr(block))
})
self.make_async_expr(
capture_clause,
closure_node_id,
None,
block.span,
hir::AsyncGeneratorKind::Block,
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
)
}
ExprKind::Await(ref expr) => self.lower_expr_await(e.span, expr),
ExprKind::Closure(
Expand Down Expand Up @@ -457,6 +462,7 @@ impl LoweringContext<'_> {
closure_node_id: NodeId,
ret_ty: Option<AstP<Ty>>,
span: Span,
async_gen_kind: hir::AsyncGeneratorKind,
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
) -> hir::ExprKind {
let capture_clause = self.lower_capture_clause(capture_clause);
Expand All @@ -470,7 +476,7 @@ impl LoweringContext<'_> {
};
let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None);
let body_id = self.lower_fn_body(&ast_decl, |this| {
this.generator_kind = Some(hir::GeneratorKind::Async);
this.generator_kind = Some(hir::GeneratorKind::Async(async_gen_kind));
body(this)
});

Expand Down Expand Up @@ -522,7 +528,7 @@ impl LoweringContext<'_> {
/// ```
fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind {
match self.generator_kind {
Some(hir::GeneratorKind::Async) => {},
Some(hir::GeneratorKind::Async(_)) => {},
Some(hir::GeneratorKind::Gen) |
None => {
let mut err = struct_span_err!(
Expand Down Expand Up @@ -727,7 +733,7 @@ impl LoweringContext<'_> {
Movability::Static => hir::GeneratorMovability::Static,
})
},
Some(hir::GeneratorKind::Async) => {
Some(hir::GeneratorKind::Async(_)) => {
bug!("non-`async` closure body turned `async` during lowering");
},
None => {
Expand Down Expand Up @@ -786,10 +792,12 @@ impl LoweringContext<'_> {
None
};
let async_body = this.make_async_expr(
capture_clause, closure_id, async_ret_ty, body.span,
|this| {
this.with_new_scopes(|this| this.lower_expr(body))
}
capture_clause,
closure_id,
async_ret_ty,
body.span,
hir::AsyncGeneratorKind::Closure,
|this| this.with_new_scopes(|this| this.lower_expr(body)),
);
this.expr(fn_decl_span, async_body, ThinVec::new())
});
Expand Down Expand Up @@ -1005,7 +1013,7 @@ impl LoweringContext<'_> {
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind {
match self.generator_kind {
Some(hir::GeneratorKind::Gen) => {},
Some(hir::GeneratorKind::Async) => {
Some(hir::GeneratorKind::Async(_)) => {
span_err!(
self.sess,
span,
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,11 @@ impl LoweringContext<'_> {
}

let async_expr = this.make_async_expr(
CaptureBy::Value, closure_id, None, body.span,
CaptureBy::Value,
closure_id,
None,
body.span,
hir::AsyncGeneratorKind::Fn,
|this| {
// Create a block from the user's function body:
let user_body = this.lower_block_expr(body);
Expand Down
39 changes: 34 additions & 5 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,21 +1362,49 @@ impl Body {
}

/// The type of source expression that caused this generator to be created.
// Not `IsAsync` because we want to eventually add support for `AsyncGen`
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum GeneratorKind {
/// An `async` block or function.
Async,
/// An explicit `async` block or the body of an async function.
Async(AsyncGeneratorKind),

/// A generator literal created via a `yield` inside a closure.
Gen,
}

impl fmt::Display for GeneratorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GeneratorKind::Async(k) => fmt::Display::fmt(k, f),
GeneratorKind::Gen => f.write_str("generator"),
}
}
}

/// In the case of a generator created as part of an async construct,
/// which kind of async construct caused it to be created?
///
/// This helps error messages but is also used to drive coercions in
/// type-checking (see #60424).
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, HashStable,
RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum AsyncGeneratorKind {
/// An explicit `async` block written by the user.
Block,

/// An explicit `async` block written by the user.
Closure,

/// The `async` block generated as the body of an async function.
Fn,
}

impl fmt::Display for AsyncGeneratorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
GeneratorKind::Async => "`async` object",
GeneratorKind::Gen => "generator",
AsyncGeneratorKind::Block => "`async` block",
AsyncGeneratorKind::Closure => "`async` closure body",
AsyncGeneratorKind::Fn => "`async fn` body",
})
}
}
Expand Down Expand Up @@ -1758,6 +1786,7 @@ pub struct Destination {
pub enum GeneratorMovability {
/// May contain self-references, `!Unpin`.
Static,

/// Must not contain self-references, `Unpin`.
Movable,
}
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

/// Resolve any type variables found in `value` -- but only one
/// level. So, if the variable `?X` is bound to some type
/// `Foo<?Y>`, then this would return `Foo<?Y>` (but `?Y` may
/// itself be bound to a type).
///
/// Useful when you only need to inspect the outermost level of
/// the type and don't care about nested types (or perhaps you
/// will be resolving them as well, e.g. in a loop).
pub fn shallow_resolve<T>(&self, value: T) -> T
where
T: TypeFoldable<'tcx>,
Expand Down Expand Up @@ -1567,6 +1575,9 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
ShallowResolver { infcx }
}

/// If `typ` is a type variable of some kind, resolve it one level
/// (but do not resolve types found in the result). If `typ` is
/// not a type variable, just return it unmodified.
pub fn shallow_resolve(&mut self, typ: Ty<'tcx>) -> Ty<'tcx> {
match typ.kind {
ty::Infer(ty::TyVar(v)) => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ impl EmitterWriter {
children.iter()
.map(|sub| self.get_multispan_max_line_num(&sub.span))
.max()
.unwrap_or(primary)
.unwrap_or(0)
.max(primary)
}

/// Adds a left margin to every line but the first, given a padding length and the label being
Expand Down
Loading