Skip to content

Commit

Permalink
Latest fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Jan 2, 2021
1 parent df00187 commit d73cf5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
41 changes: 13 additions & 28 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,46 +744,31 @@ pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) ->
let mut curr_string = name;

for (i, proj) in place.projections.iter().enumerate() {
if HirProjectionKind::Deref == proj.kind {
curr_string = format!("*{}", curr_string);
} else {
match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) if def.is_enum() => {
// we might be projecting *to* a variant, or to a field *in* a variant.
match proj.kind {
HirProjectionKind::Field(idx, variant) => {
curr_string = format!(
"{}.{}",
curr_string,
def.variants[variant].fields[idx as usize].ident.name.as_str()
);
}
_ => {
bug!("Could not handle ProjectionKind {:?}", proj.kind)
}
}
}
match proj.kind {
HirProjectionKind::Deref => {
curr_string = format!("*{}", curr_string);
}
HirProjectionKind::Field(idx, variant) => match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) => {
curr_string = format!(
"{}.{}",
curr_string,
def.non_enum_variant().fields[0].ident.name.as_str()
def.variants[variant].fields[idx as usize].ident.name.as_str()
);
}
ty::Tuple(_) => match proj.kind {
HirProjectionKind::Field(idx, _) => {
curr_string = format!("{}.{}", curr_string, idx);
}
_ => {
bug!("Could not handle ProjectionKind {:?}", proj.kind)
}
},
ty::Tuple(_) => {
curr_string = format!("{}.{}", curr_string, idx);
}
_ => {
bug!(
"Field projection applied to a type other than Adt or Tuple: {:?}.",
place.ty_before_projection(i).kind()
)
}
},
_ => {
// FIXME: Handle Index properly
bug!("Unexpected ProjectionKind: {:?}.", proj.kind)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
//~| `#[warn(incomplete_features)]` on by default
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
struct S(String);
struct S(String, String);

fn expect_fn<F: Fn()>(_f: F) {}

fn main() {
let s = S(format!("s"));
let c = || { //~ ERROR expected a closure
let s = s.0;
let s = S(format!("s"), format!("s"));
let c = || { //~ ERROR expected a closure that implements the `Fn`
let s = s.1;
};
expect_fn(c);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ error[E0525]: expected a closure that implements the `Fn` trait, but this closur
|
LL | let c = || {
| ^^ this closure implements `FnOnce`, not `Fn`
LL | let s = s.0;
| --- closure is `FnOnce` because it moves the variable `s.0` out of its environment
LL | let s = s.1;
| --- closure is `FnOnce` because it moves the variable `s.1` out of its environment
LL | };
LL | expect_fn(c);
| --------- the requirement to implement `Fn` derives from here
Expand Down

0 comments on commit d73cf5f

Please sign in to comment.