Skip to content

Rollup of 5 pull requests #63715

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

Merged
merged 15 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
/// // a, b, and foo are all Arcs that point to the same memory location
/// ```
///
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly
/// the meaning of the code. In the example above, this syntax makes it easier to see that
/// this code is creating a new reference rather than copying the whole content of foo.
///
/// ## `Deref` behavior
///
/// `Arc<T>` automatically dereferences to `T` (via the [`Deref`][deref] trait),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
LifetimeName::Static |
LifetimeName::Error |
LifetimeName::Implicit |
LifetimeName::ImplicitObjectLifetimeDefault |
LifetimeName::Underscore => {}
}
}
Expand Down
86 changes: 71 additions & 15 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use syntax::symbol::{kw, sym, Symbol};
use syntax::tokenstream::{TokenStream, TokenTree};
use syntax::parse::token::{self, Token};
use syntax::visit::{self, Visitor};
use syntax_pos::{DUMMY_SP, Span};
use syntax_pos::Span;

const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;

Expand Down Expand Up @@ -322,7 +322,7 @@ enum ParenthesizedGenericArgs {
/// `resolve_lifetime` module. Often we "fallthrough" to that code by generating
/// an "elided" or "underscore" lifetime name. In the future, we probably want to move
/// everything into HIR lowering.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
enum AnonymousLifetimeMode {
/// For **Modern** cases, create a new anonymous region parameter
/// and reference that.
Expand Down Expand Up @@ -715,10 +715,16 @@ impl<'a> LoweringContext<'a> {
anonymous_lifetime_mode: AnonymousLifetimeMode,
op: impl FnOnce(&mut Self) -> R,
) -> R {
debug!(
"with_anonymous_lifetime_mode(anonymous_lifetime_mode={:?})",
anonymous_lifetime_mode,
);
let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode;
self.anonymous_lifetime_mode = anonymous_lifetime_mode;
let result = op(self);
self.anonymous_lifetime_mode = old_anonymous_lifetime_mode;
debug!("with_anonymous_lifetime_mode: restoring anonymous_lifetime_mode={:?}",
old_anonymous_lifetime_mode);
result
}

Expand Down Expand Up @@ -1033,13 +1039,14 @@ impl<'a> LoweringContext<'a> {
/// ```
///
/// returns a `hir::TypeBinding` representing `Item`.
fn lower_assoc_ty_constraint(&mut self,
c: &AssocTyConstraint,
itctx: ImplTraitContext<'_>)
-> hir::TypeBinding {
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", c, itctx);
fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocTyConstraint,
itctx: ImplTraitContext<'_>,
) -> hir::TypeBinding {
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);

let kind = match c.kind {
let kind = match constraint.kind {
AssocTyConstraintKind::Equality { ref ty } => hir::TypeBindingKind::Equality {
ty: self.lower_ty(ty, itctx)
},
Expand Down Expand Up @@ -1094,15 +1101,15 @@ impl<'a> LoweringContext<'a> {
impl_trait_node_id,
DefPathData::ImplTrait,
ExpnId::root(),
DUMMY_SP
constraint.span,
);

self.with_dyn_type_scope(false, |this| {
let ty = this.lower_ty(
&Ty {
id: this.sess.next_node_id(),
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
span: DUMMY_SP,
span: constraint.span,
},
itctx,
);
Expand All @@ -1124,10 +1131,10 @@ impl<'a> LoweringContext<'a> {
};

hir::TypeBinding {
hir_id: self.lower_node_id(c.id),
ident: c.ident,
hir_id: self.lower_node_id(constraint.id),
ident: constraint.ident,
kind,
span: c.span,
span: constraint.span,
}
}

Expand Down Expand Up @@ -1355,6 +1362,13 @@ impl<'a> LoweringContext<'a> {
opaque_ty_node_id: NodeId,
lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds,
) -> hir::TyKind {
debug!(
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
fn_def_id,
opaque_ty_node_id,
span,
);

// Make sure we know that some funky desugaring has been going on here.
// This is a first: there is code in other places like for loop
// desugaring that explicitly states that we don't want to track that.
Expand Down Expand Up @@ -1382,6 +1396,14 @@ impl<'a> LoweringContext<'a> {
&hir_bounds,
);

debug!(
"lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,
);

debug!(
"lower_opaque_impl_trait: lifetime_defs={:#?}", lifetime_defs,
);

self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics {
Expand All @@ -1397,7 +1419,7 @@ impl<'a> LoweringContext<'a> {
origin: hir::OpaqueTyOrigin::FnReturn,
};

trace!("exist ty from impl trait def-index: {:#?}", opaque_ty_def_index);
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_index);
let opaque_ty_id = lctx.generate_opaque_type(
opaque_ty_node_id,
opaque_ty_item,
Expand Down Expand Up @@ -1445,6 +1467,13 @@ impl<'a> LoweringContext<'a> {
parent_index: DefIndex,
bounds: &hir::GenericBounds,
) -> (HirVec<hir::GenericArg>, HirVec<hir::GenericParam>) {
debug!(
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
parent_index={:?}, \
bounds={:#?})",
opaque_ty_id, parent_index, bounds,
);

// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
// appear in the bounds, excluding lifetimes that are created within the bounds.
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
Expand Down Expand Up @@ -1532,6 +1561,11 @@ impl<'a> LoweringContext<'a> {
}
}
hir::LifetimeName::Param(_) => lifetime.name,

// Refers to some other lifetime that is "in
// scope" within the type.
hir::LifetimeName::ImplicitObjectLifetimeDefault => return,

hir::LifetimeName::Error | hir::LifetimeName::Static => return,
};

Expand Down Expand Up @@ -2182,6 +2216,14 @@ impl<'a> LoweringContext<'a> {
fn_def_id: DefId,
opaque_ty_node_id: NodeId,
) -> hir::FunctionRetTy {
debug!(
"lower_async_fn_ret_ty(\
output={:?}, \
fn_def_id={:?}, \
opaque_ty_node_id={:?})",
output, fn_def_id, opaque_ty_node_id,
);

let span = output.span();

let opaque_ty_span = self.mark_span_with_reason(
Expand Down Expand Up @@ -2264,6 +2306,8 @@ impl<'a> LoweringContext<'a> {
),
);

debug!("lower_async_fn_ret_ty: future_bound={:#?}", future_bound);

// Calculate all the lifetimes that should be captured
// by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band.
Expand Down Expand Up @@ -2512,6 +2556,12 @@ impl<'a> LoweringContext<'a> {
hir::LifetimeName::Implicit
| hir::LifetimeName::Underscore
| hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()),
hir::LifetimeName::ImplicitObjectLifetimeDefault => {
span_bug!(
param.ident.span,
"object-lifetime-default should not occur here",
);
}
hir::LifetimeName::Error => ParamName::Error,
};

Expand Down Expand Up @@ -3255,7 +3305,13 @@ impl<'a> LoweringContext<'a> {
AnonymousLifetimeMode::PassThrough => {}
}

self.new_implicit_lifetime(span)
let r = hir::Lifetime {
hir_id: self.next_id(),
span,
name: hir::LifetimeName::ImplicitObjectLifetimeDefault,
};
debug!("elided_dyn_bound: r={:?}", r);
r
}

fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
Expand Down
21 changes: 19 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ pub enum LifetimeName {
/// User wrote nothing (e.g., the lifetime in `&u32`).
Implicit,

/// Implicit lifetime in a context like `dyn Foo`. This is
/// distinguished from implicit lifetimes elsewhere because the
/// lifetime that they default to must appear elsewhere within the
/// enclosing type. This means that, in an `impl Trait` context, we
/// don't have to create a parameter for them. That is, `impl
/// Trait<Item = &u32>` expands to an opaque type like `type
/// Foo<'a> = impl Trait<Item = &'a u32>`, but `impl Trait<item =
/// dyn Bar>` expands to `type Foo = impl Trait<Item = dyn Bar +
/// 'static>`. The latter uses `ImplicitObjectLifetimeDefault` so
/// that surrounding code knows not to create a lifetime
/// parameter.
ImplicitObjectLifetimeDefault,

/// Indicates an error during lowering (usually `'_` in wrong place)
/// that was already reported.
Error,
Expand All @@ -235,7 +248,9 @@ pub enum LifetimeName {
impl LifetimeName {
pub fn ident(&self) -> Ident {
match *self {
LifetimeName::Implicit | LifetimeName::Error => Ident::invalid(),
LifetimeName::ImplicitObjectLifetimeDefault
| LifetimeName::Implicit
| LifetimeName::Error => Ident::invalid(),
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
LifetimeName::Param(param_name) => param_name.ident(),
Expand All @@ -244,7 +259,9 @@ impl LifetimeName {

pub fn is_elided(&self) -> bool {
match self {
LifetimeName::Implicit | LifetimeName::Underscore => true,
LifetimeName::ImplicitObjectLifetimeDefault
| LifetimeName::Implicit
| LifetimeName::Underscore => true,

// It might seem surprising that `Fresh(_)` counts as
// *not* elided -- but this is because, as far as the code
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
debug!(
"instantiate_opaque_types(value={:?}, parent_def_id={:?}, body_id={:?}, \
param_env={:?})",
value, parent_def_id, body_id, param_env,
param_env={:?}, value_span={:?})",
value, parent_def_id, body_id, param_env, value_span,
);
let mut instantiator = Instantiator {
infcx: self,
Expand Down Expand Up @@ -1108,9 +1108,11 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// Use the same type variable if the exact same opaque type appears more
// than once in the return type (e.g., if it's passed to a type alias).
if let Some(opaque_defn) = self.opaque_types.get(&def_id) {
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
return opaque_defn.concrete_ty;
}
let span = tcx.def_span(def_id);
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
let ty_var = infcx
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });

Expand Down
Loading