Skip to content

Commit b45fabd

Browse files
committed
Inline a function that is only used once
1 parent d35d1ef commit b45fabd

File tree

1 file changed

+39
-53
lines changed

1 file changed

+39
-53
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,47 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8080
}
8181
if self.defining_use_anchor.is_some() {
8282
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
83-
ty::Opaque(def_id, substs) => self.fold_opaque_ty_new(
83+
ty::Opaque(def_id, substs) => Some(self.register_hidden_type(
8484
OpaqueTypeKey { def_id, substs },
8585
cause.clone(),
8686
param_env,
8787
b,
88-
),
88+
// Check that this is `impl Trait` type is
89+
// declared by `parent_def_id` -- i.e., one whose
90+
// value we are inferring. At present, this is
91+
// always true during the first phase of
92+
// type-check, but not always true later on during
93+
// NLL. Once we support named opaque types more fully,
94+
// this same scenario will be able to arise during all phases.
95+
//
96+
// Here is an example using type alias `impl Trait`
97+
// that indicates the distinction we are checking for:
98+
//
99+
// ```rust
100+
// mod a {
101+
// pub type Foo = impl Iterator;
102+
// pub fn make_foo() -> Foo { .. }
103+
// }
104+
//
105+
// mod b {
106+
// fn foo() -> a::Foo { a::make_foo() }
107+
// }
108+
// ```
109+
//
110+
// Here, the return type of `foo` references an
111+
// `Opaque` indeed, but not one whose value is
112+
// presently being inferred. You can get into a
113+
// similar situation with closure return types
114+
// today:
115+
//
116+
// ```rust
117+
// fn foo() -> impl Iterator { .. }
118+
// fn bar() {
119+
// let x = || foo(); // returns the Opaque assoc with `foo`
120+
// }
121+
// ```
122+
self.opaque_type_origin(def_id, cause.span)?,
123+
)),
89124
_ => None,
90125
};
91126
if let Some(res) = process(a, b) {
@@ -479,63 +514,14 @@ impl UseKind {
479514
}
480515

481516
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
482-
fn fold_opaque_ty_new(
517+
#[instrument(skip(self), level = "debug")]
518+
fn register_hidden_type(
483519
&self,
484520
opaque_type_key: OpaqueTypeKey<'tcx>,
485521
cause: ObligationCause<'tcx>,
486522
param_env: ty::ParamEnv<'tcx>,
487523
hidden_ty: Ty<'tcx>,
488-
) -> Option<InferResult<'tcx, ()>> {
489-
// Check that this is `impl Trait` type is
490-
// declared by `parent_def_id` -- i.e., one whose
491-
// value we are inferring. At present, this is
492-
// always true during the first phase of
493-
// type-check, but not always true later on during
494-
// NLL. Once we support named opaque types more fully,
495-
// this same scenario will be able to arise during all phases.
496-
//
497-
// Here is an example using type alias `impl Trait`
498-
// that indicates the distinction we are checking for:
499-
//
500-
// ```rust
501-
// mod a {
502-
// pub type Foo = impl Iterator;
503-
// pub fn make_foo() -> Foo { .. }
504-
// }
505-
//
506-
// mod b {
507-
// fn foo() -> a::Foo { a::make_foo() }
508-
// }
509-
// ```
510-
//
511-
// Here, the return type of `foo` references an
512-
// `Opaque` indeed, but not one whose value is
513-
// presently being inferred. You can get into a
514-
// similar situation with closure return types
515-
// today:
516-
//
517-
// ```rust
518-
// fn foo() -> impl Iterator { .. }
519-
// fn bar() {
520-
// let x = || foo(); // returns the Opaque assoc with `foo`
521-
// }
522-
// ```
523-
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
524-
return Some(self.fold_opaque_ty(cause, param_env, opaque_type_key, origin, hidden_ty));
525-
}
526-
527-
debug!(?opaque_type_key, "encountered opaque outside its definition scope",);
528-
None
529-
}
530-
531-
#[instrument(skip(self), level = "debug")]
532-
fn fold_opaque_ty(
533-
&self,
534-
cause: ObligationCause<'tcx>,
535-
param_env: ty::ParamEnv<'tcx>,
536-
opaque_type_key: OpaqueTypeKey<'tcx>,
537524
origin: hir::OpaqueTyOrigin,
538-
hidden_ty: Ty<'tcx>,
539525
) -> InferResult<'tcx, ()> {
540526
let tcx = self.tcx;
541527
let OpaqueTypeKey { def_id, substs } = opaque_type_key;

0 commit comments

Comments
 (0)