Skip to content

Commit

Permalink
Address latest comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Dec 30, 2020
1 parent 1cb3878 commit 784681e
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 19 deletions.
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) ->
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
_ => bug!("Capture_information should only contain upvars"),
};
let mut curr_string = format!("{}", name);
let mut curr_string = name;

for (i, proj) in place.projections.iter().enumerate() {
if HirProjectionKind::Deref == proj.kind {
Expand All @@ -751,11 +751,11 @@ pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) ->
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) => {
HirProjectionKind::Field(idx, variant) => {
curr_string = format!(
"{}.{}",
curr_string,
def.variants[variant].fields[0].ident.name.as_str()
def.variants[variant].fields[idx as usize].ident.name.as_str()
);
}
_ => {
Expand All @@ -779,7 +779,10 @@ pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) ->
}
},
_ => {
bug!("Could not handle ty kind {:?}", place.ty_before_projection(i).kind())
bug!(
"Field projection applied to a type other than Adt or Tuple: {:?}.",
place.ty_before_projection(i).kind()
)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let origin = if self.tcx.features().capture_disjoint_fields {
origin
} else {
// FIXME(project-rfc-2229#26): Once rust-lang#80092 is merged, we should restrict the

This comment has been minimized.

Copy link
@arora-aman

arora-aman Dec 30, 2020

Member

you don't need rust-lang here, that's the default. Also it should be rust. rust is the project, rust-lang is the org.

// precision of origin as well. Otherwise, this will cause issues when project-rfc-2229#26
// is fixed as we might see Index projections in the origin, which we can't print because
// we don't store enough information.
(origin.0, Place { projections: vec![], ..origin.1 })
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closure-multi-variant-diagnostics.rs:1:12
--> $DIR/closure-origin-multi-variant-diagnostics.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,15 +8,15 @@ LL | #![feature(capture_disjoint_fields)]
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error[E0382]: use of moved value: `c`
--> $DIR/closure-multi-variant-diagnostics.rs:30:13
--> $DIR/closure-origin-multi-variant-diagnostics.rs:30:13
|
LL | let a = c;
| - value moved here
LL | let b = c;
| ^ value used here after move
|
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment
--> $DIR/closure-multi-variant-diagnostics.rs:20:52
--> $DIR/closure-origin-multi-variant-diagnostics.rs:20:52
|
LL | if let MultiVariant::Point(ref mut x, _) = point {
| ^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn main() {
let mut point = SingleVariant::Point(10, -10);

let c = || {
// FIXME(project-rfc-2229#24): Change this to be a destructure pattern
// once this is fixed, to remove the warning.
if let SingleVariant::Point(ref mut x, _) = point {
//~^ WARNING: irrefutable if-let pattern
*x += 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closure-single-variant-diagnostics.rs:1:12
--> $DIR/closure-origin-single-variant-diagnostics.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![feature(capture_disjoint_fields)]
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

warning: irrefutable if-let pattern
--> $DIR/closure-single-variant-diagnostics.rs:16:9
--> $DIR/closure-origin-single-variant-diagnostics.rs:18:9
|
LL | / if let SingleVariant::Point(ref mut x, _) = point {
LL | |
Expand All @@ -19,15 +19,15 @@ LL | | }
= note: `#[warn(irrefutable_let_patterns)]` on by default

error[E0382]: use of moved value: `c`
--> $DIR/closure-single-variant-diagnostics.rs:23:13
--> $DIR/closure-origin-single-variant-diagnostics.rs:25:13
|
LL | let b = c;
| - value moved here
LL | let a = c;
| ^ value used here after move
|
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `point.0` out of its environment
--> $DIR/closure-single-variant-diagnostics.rs:16:53
--> $DIR/closure-origin-single-variant-diagnostics.rs:18:53
|
LL | if let SingleVariant::Point(ref mut x, _) = point {
| ^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closure-struct-diagnostics.rs:1:12
--> $DIR/closure-origin-struct-diagnostics.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,15 +8,15 @@ LL | #![feature(capture_disjoint_fields)]
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error[E0382]: use of moved value: `hello`
--> $DIR/closure-struct-diagnostics.rs:24:13
--> $DIR/closure-origin-struct-diagnostics.rs:24:13
|
LL | let b = hello;
| ----- value moved here
LL | let c = hello;
| ^^^^^ value used here after move
|
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x.y.a` out of its environment
--> $DIR/closure-struct-diagnostics.rs:20:9
--> $DIR/closure-origin-struct-diagnostics.rs:20:9
|
LL | x.y.a += 1;
| ^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closure-tuple-diagnostics.rs:1:12
--> $DIR/closure-origin-tuple-diagnostics-1.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,15 +8,15 @@ LL | #![feature(capture_disjoint_fields)]
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error[E0382]: use of moved value: `hello`
--> $DIR/closure-tuple-diagnostics.rs:15:13
--> $DIR/closure-origin-tuple-diagnostics-1.rs:15:13
|
LL | let b = hello;
| ----- value moved here
LL | let c = hello;
| ^^^^^ value used here after move
|
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x.0` out of its environment
--> $DIR/closure-tuple-diagnostics.rs:11:9
--> $DIR/closure-origin-tuple-diagnostics-1.rs:11:9
|
LL | x.0 += 1;
| ^^^
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/closure-tuple-diagnostics.rs:1:12
--> $DIR/closure-origin-tuple-diagnostics.rs:1:12
|
LL | #![feature(capture_disjoint_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | #![feature(capture_disjoint_fields)]
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
--> $DIR/closure-tuple-diagnostics.rs:11:13
--> $DIR/closure-origin-tuple-diagnostics.rs:11:13
|
LL | let c = || {
| ^^ this closure implements `FnOnce`, not `Fn`
Expand Down

0 comments on commit 784681e

Please sign in to comment.