Skip to content

Commit c1b08dd

Browse files
committed
Auto merge of #63715 - Centril:rollup-dga8qtp, r=Centril
Rollup of 5 pull requests Successful merges: - #63252 (Remove recommendation about idiomatic syntax for Arc::clone) - #63376 (use different lifetime name for object-lifetime-default elision) - #63620 (Use constraint span when lowering associated types) - #63699 (Fix suggestion from incorrect `move async` to `async move`.) - #63704 ( Fixed: error: unnecessary trailing semicolon) Failed merges: r? @ghost
2 parents 29a5403 + ac34594 commit c1b08dd

33 files changed

+847
-219
lines changed

src/liballoc/sync.rs

-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
107107
/// // a, b, and foo are all Arcs that point to the same memory location
108108
/// ```
109109
///
110-
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly
111-
/// the meaning of the code. In the example above, this syntax makes it easier to see that
112-
/// this code is creating a new reference rather than copying the whole content of foo.
113-
///
114110
/// ## `Deref` behavior
115111
///
116112
/// `Arc<T>` automatically dereferences to `T` (via the [`Deref`][deref] trait),

src/librustc/hir/intravisit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
433433
LifetimeName::Static |
434434
LifetimeName::Error |
435435
LifetimeName::Implicit |
436+
LifetimeName::ImplicitObjectLifetimeDefault |
436437
LifetimeName::Underscore => {}
437438
}
438439
}

src/librustc/hir/lowering.rs

+71-15
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use syntax::symbol::{kw, sym, Symbol};
7272
use syntax::tokenstream::{TokenStream, TokenTree};
7373
use syntax::parse::token::{self, Token};
7474
use syntax::visit::{self, Visitor};
75-
use syntax_pos::{DUMMY_SP, Span};
75+
use syntax_pos::Span;
7676

7777
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
7878

@@ -322,7 +322,7 @@ enum ParenthesizedGenericArgs {
322322
/// `resolve_lifetime` module. Often we "fallthrough" to that code by generating
323323
/// an "elided" or "underscore" lifetime name. In the future, we probably want to move
324324
/// everything into HIR lowering.
325-
#[derive(Copy, Clone)]
325+
#[derive(Copy, Clone, Debug)]
326326
enum AnonymousLifetimeMode {
327327
/// For **Modern** cases, create a new anonymous region parameter
328328
/// and reference that.
@@ -715,10 +715,16 @@ impl<'a> LoweringContext<'a> {
715715
anonymous_lifetime_mode: AnonymousLifetimeMode,
716716
op: impl FnOnce(&mut Self) -> R,
717717
) -> R {
718+
debug!(
719+
"with_anonymous_lifetime_mode(anonymous_lifetime_mode={:?})",
720+
anonymous_lifetime_mode,
721+
);
718722
let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode;
719723
self.anonymous_lifetime_mode = anonymous_lifetime_mode;
720724
let result = op(self);
721725
self.anonymous_lifetime_mode = old_anonymous_lifetime_mode;
726+
debug!("with_anonymous_lifetime_mode: restoring anonymous_lifetime_mode={:?}",
727+
old_anonymous_lifetime_mode);
722728
result
723729
}
724730

@@ -1033,13 +1039,14 @@ impl<'a> LoweringContext<'a> {
10331039
/// ```
10341040
///
10351041
/// returns a `hir::TypeBinding` representing `Item`.
1036-
fn lower_assoc_ty_constraint(&mut self,
1037-
c: &AssocTyConstraint,
1038-
itctx: ImplTraitContext<'_>)
1039-
-> hir::TypeBinding {
1040-
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", c, itctx);
1042+
fn lower_assoc_ty_constraint(
1043+
&mut self,
1044+
constraint: &AssocTyConstraint,
1045+
itctx: ImplTraitContext<'_>,
1046+
) -> hir::TypeBinding {
1047+
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
10411048

1042-
let kind = match c.kind {
1049+
let kind = match constraint.kind {
10431050
AssocTyConstraintKind::Equality { ref ty } => hir::TypeBindingKind::Equality {
10441051
ty: self.lower_ty(ty, itctx)
10451052
},
@@ -1094,15 +1101,15 @@ impl<'a> LoweringContext<'a> {
10941101
impl_trait_node_id,
10951102
DefPathData::ImplTrait,
10961103
ExpnId::root(),
1097-
DUMMY_SP
1104+
constraint.span,
10981105
);
10991106

11001107
self.with_dyn_type_scope(false, |this| {
11011108
let ty = this.lower_ty(
11021109
&Ty {
11031110
id: this.sess.next_node_id(),
11041111
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1105-
span: DUMMY_SP,
1112+
span: constraint.span,
11061113
},
11071114
itctx,
11081115
);
@@ -1124,10 +1131,10 @@ impl<'a> LoweringContext<'a> {
11241131
};
11251132

11261133
hir::TypeBinding {
1127-
hir_id: self.lower_node_id(c.id),
1128-
ident: c.ident,
1134+
hir_id: self.lower_node_id(constraint.id),
1135+
ident: constraint.ident,
11291136
kind,
1130-
span: c.span,
1137+
span: constraint.span,
11311138
}
11321139
}
11331140

@@ -1355,6 +1362,13 @@ impl<'a> LoweringContext<'a> {
13551362
opaque_ty_node_id: NodeId,
13561363
lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds,
13571364
) -> hir::TyKind {
1365+
debug!(
1366+
"lower_opaque_impl_trait(fn_def_id={:?}, opaque_ty_node_id={:?}, span={:?})",
1367+
fn_def_id,
1368+
opaque_ty_node_id,
1369+
span,
1370+
);
1371+
13581372
// Make sure we know that some funky desugaring has been going on here.
13591373
// This is a first: there is code in other places like for loop
13601374
// desugaring that explicitly states that we don't want to track that.
@@ -1382,6 +1396,14 @@ impl<'a> LoweringContext<'a> {
13821396
&hir_bounds,
13831397
);
13841398

1399+
debug!(
1400+
"lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,
1401+
);
1402+
1403+
debug!(
1404+
"lower_opaque_impl_trait: lifetime_defs={:#?}", lifetime_defs,
1405+
);
1406+
13851407
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
13861408
let opaque_ty_item = hir::OpaqueTy {
13871409
generics: hir::Generics {
@@ -1397,7 +1419,7 @@ impl<'a> LoweringContext<'a> {
13971419
origin: hir::OpaqueTyOrigin::FnReturn,
13981420
};
13991421

1400-
trace!("exist ty from impl trait def-index: {:#?}", opaque_ty_def_index);
1422+
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_index);
14011423
let opaque_ty_id = lctx.generate_opaque_type(
14021424
opaque_ty_node_id,
14031425
opaque_ty_item,
@@ -1445,6 +1467,13 @@ impl<'a> LoweringContext<'a> {
14451467
parent_index: DefIndex,
14461468
bounds: &hir::GenericBounds,
14471469
) -> (HirVec<hir::GenericArg>, HirVec<hir::GenericParam>) {
1470+
debug!(
1471+
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
1472+
parent_index={:?}, \
1473+
bounds={:#?})",
1474+
opaque_ty_id, parent_index, bounds,
1475+
);
1476+
14481477
// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
14491478
// appear in the bounds, excluding lifetimes that are created within the bounds.
14501479
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
@@ -1532,6 +1561,11 @@ impl<'a> LoweringContext<'a> {
15321561
}
15331562
}
15341563
hir::LifetimeName::Param(_) => lifetime.name,
1564+
1565+
// Refers to some other lifetime that is "in
1566+
// scope" within the type.
1567+
hir::LifetimeName::ImplicitObjectLifetimeDefault => return,
1568+
15351569
hir::LifetimeName::Error | hir::LifetimeName::Static => return,
15361570
};
15371571

@@ -2182,6 +2216,14 @@ impl<'a> LoweringContext<'a> {
21822216
fn_def_id: DefId,
21832217
opaque_ty_node_id: NodeId,
21842218
) -> hir::FunctionRetTy {
2219+
debug!(
2220+
"lower_async_fn_ret_ty(\
2221+
output={:?}, \
2222+
fn_def_id={:?}, \
2223+
opaque_ty_node_id={:?})",
2224+
output, fn_def_id, opaque_ty_node_id,
2225+
);
2226+
21852227
let span = output.span();
21862228

21872229
let opaque_ty_span = self.mark_span_with_reason(
@@ -2264,6 +2306,8 @@ impl<'a> LoweringContext<'a> {
22642306
),
22652307
);
22662308

2309+
debug!("lower_async_fn_ret_ty: future_bound={:#?}", future_bound);
2310+
22672311
// Calculate all the lifetimes that should be captured
22682312
// by the opaque type. This should include all in-scope
22692313
// lifetime parameters, including those defined in-band.
@@ -2512,6 +2556,12 @@ impl<'a> LoweringContext<'a> {
25122556
hir::LifetimeName::Implicit
25132557
| hir::LifetimeName::Underscore
25142558
| hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()),
2559+
hir::LifetimeName::ImplicitObjectLifetimeDefault => {
2560+
span_bug!(
2561+
param.ident.span,
2562+
"object-lifetime-default should not occur here",
2563+
);
2564+
}
25152565
hir::LifetimeName::Error => ParamName::Error,
25162566
};
25172567

@@ -3255,7 +3305,13 @@ impl<'a> LoweringContext<'a> {
32553305
AnonymousLifetimeMode::PassThrough => {}
32563306
}
32573307

3258-
self.new_implicit_lifetime(span)
3308+
let r = hir::Lifetime {
3309+
hir_id: self.next_id(),
3310+
span,
3311+
name: hir::LifetimeName::ImplicitObjectLifetimeDefault,
3312+
};
3313+
debug!("elided_dyn_bound: r={:?}", r);
3314+
r
32593315
}
32603316

32613317
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {

src/librustc/hir/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ pub enum LifetimeName {
221221
/// User wrote nothing (e.g., the lifetime in `&u32`).
222222
Implicit,
223223

224+
/// Implicit lifetime in a context like `dyn Foo`. This is
225+
/// distinguished from implicit lifetimes elsewhere because the
226+
/// lifetime that they default to must appear elsewhere within the
227+
/// enclosing type. This means that, in an `impl Trait` context, we
228+
/// don't have to create a parameter for them. That is, `impl
229+
/// Trait<Item = &u32>` expands to an opaque type like `type
230+
/// Foo<'a> = impl Trait<Item = &'a u32>`, but `impl Trait<item =
231+
/// dyn Bar>` expands to `type Foo = impl Trait<Item = dyn Bar +
232+
/// 'static>`. The latter uses `ImplicitObjectLifetimeDefault` so
233+
/// that surrounding code knows not to create a lifetime
234+
/// parameter.
235+
ImplicitObjectLifetimeDefault,
236+
224237
/// Indicates an error during lowering (usually `'_` in wrong place)
225238
/// that was already reported.
226239
Error,
@@ -235,7 +248,9 @@ pub enum LifetimeName {
235248
impl LifetimeName {
236249
pub fn ident(&self) -> Ident {
237250
match *self {
238-
LifetimeName::Implicit | LifetimeName::Error => Ident::invalid(),
251+
LifetimeName::ImplicitObjectLifetimeDefault
252+
| LifetimeName::Implicit
253+
| LifetimeName::Error => Ident::invalid(),
239254
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
240255
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
241256
LifetimeName::Param(param_name) => param_name.ident(),
@@ -244,7 +259,9 @@ impl LifetimeName {
244259

245260
pub fn is_elided(&self) -> bool {
246261
match self {
247-
LifetimeName::Implicit | LifetimeName::Underscore => true,
262+
LifetimeName::ImplicitObjectLifetimeDefault
263+
| LifetimeName::Implicit
264+
| LifetimeName::Underscore => true,
248265

249266
// It might seem surprising that `Fresh(_)` counts as
250267
// *not* elided -- but this is because, as far as the code

src/librustc/infer/opaque_types/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
127127
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
128128
debug!(
129129
"instantiate_opaque_types(value={:?}, parent_def_id={:?}, body_id={:?}, \
130-
param_env={:?})",
131-
value, parent_def_id, body_id, param_env,
130+
param_env={:?}, value_span={:?})",
131+
value, parent_def_id, body_id, param_env, value_span,
132132
);
133133
let mut instantiator = Instantiator {
134134
infcx: self,
@@ -1108,9 +1108,11 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11081108
// Use the same type variable if the exact same opaque type appears more
11091109
// than once in the return type (e.g., if it's passed to a type alias).
11101110
if let Some(opaque_defn) = self.opaque_types.get(&def_id) {
1111+
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
11111112
return opaque_defn.concrete_ty;
11121113
}
11131114
let span = tcx.def_span(def_id);
1115+
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
11141116
let ty_var = infcx
11151117
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
11161118

0 commit comments

Comments
 (0)