Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
4e7d53d
Search codegen backends based on target libdir instead of sysroot.
o01eg Dec 24, 2018
fcad209
Add closure cannot be moved note.
davidtwco Dec 24, 2018
fff905b
panic when calling MaybeUninhabited::into_inner on uninhabited type
RalfJung Dec 27, 2018
c118b17
use a better way to get at the type parameter
RalfJung Dec 27, 2018
2149d73
Remove unnecessary borrow generation
matthewjasper Dec 1, 2018
49e52e7
Remove unused types from rustc::mir::interpret
matthewjasper Dec 29, 2018
4e77c3a
test: Add test for issues 45510 and 18952.
cjgillot Nov 4, 2018
6de9c13
rustfmt: librust_typeck/check/callee.rs
cjgillot Nov 4, 2018
1827d52
rustc_typeck: Implement resolution advised in issue 45510.
cjgillot Nov 4, 2018
f518cf9
Move tests to ui.
cjgillot Nov 8, 2018
2f42a18
Fix failing diagnostic test.
cjgillot Nov 21, 2018
2530ce9
Add comment.
cjgillot Nov 21, 2018
91c155b
Change return types and check return values in tests.
cjgillot Nov 27, 2018
afb7c06
Remove unused nll debug flags
matthewjasper Dec 30, 2018
3512a72
Implement the re-rebalance coherence rfc
weiznich Nov 20, 2018
b8ee6fa
Add some tests
weiznich Nov 21, 2018
e869e5f
Add some docs about the new feature to the unstable book
weiznich Nov 21, 2018
cae96b1
Fix tidy
weiznich Nov 21, 2018
eee09d5
Update src/doc/unstable-book/src/language-features/re-rebalance-coher…
varkor Nov 22, 2018
6912b2d
Directly check if input_ty is a type parameter and therefore a
weiznich Nov 23, 2018
44089c8
Fix failing compile tests
weiznich Dec 14, 2018
ad7d015
Update some new tests to changed error messages
weiznich Dec 14, 2018
8a5d45d
Unify tests
weiznich Dec 28, 2018
da08a81
Fix typo
weiznich Dec 28, 2018
6caa4ce
Add missing files
weiznich Dec 29, 2018
794b81e
Rename and fix nolink-with-link-args test
Smibu Dec 31, 2018
f4826ab
Fix backtraces on Windows
Zoxc Dec 31, 2018
d2c91a1
Fix broken links to second edition TRPL.
frewsxcv Jan 1, 2019
b903cb9
Move the `Unevaluated` constant arm upwards in the type structure
oli-obk Dec 11, 2018
88df3a2
Mingw is special wrt type sizes
oli-obk Dec 12, 2018
1351328
Simplify and fix some diagnostics around arrays
oli-obk Dec 12, 2018
f36c655
Add `unwrap_usize` to `LazyConst`, too
oli-obk Dec 13, 2018
bb9f717
`const_to_op` is now `lazy_const_to_op`
oli-obk Dec 13, 2018
37a0df3
`<&'tcx ty::Const as Deref>::deref`
oli-obk Dec 13, 2018
17db209
Simplify bit inspection of a constant
oli-obk Dec 13, 2018
d96c4a9
Undo a few - now unnecessary - changes
oli-obk Dec 13, 2018
089c403
Pacify tidy
oli-obk Dec 13, 2018
cb933ef
rebase fallout
oli-obk Dec 15, 2018
3d924a6
Git is drunk
oli-obk Dec 23, 2018
48aa819
what is going on?
oli-obk Dec 27, 2018
e42b21b
Properly lift `Allocations`
oli-obk Dec 28, 2018
72bcf92
Macrofy more `Lift` impls
oli-obk Dec 28, 2018
9654ae9
Remove unused function
oli-obk Dec 28, 2018
03b8928
Check the correct arena
oli-obk Dec 28, 2018
185636e
Update reference of rlibc crate to compiler-builtins crate
king6cong Jan 2, 2019
0fd5003
src/jemalloc is gone, remove its mention from COPYRIGHT
SimonSapin Jan 2, 2019
2a02d6d
Make sure feature gate errors are recoverable (take 2)
petrochenkov Jan 2, 2019
0a6fb84
make `panictry!` private to libsyntax
euclio Dec 4, 2018
0b6d217
Update compiler_builtins 0.1.2 -> 0.1.3
Jan 2, 2019
3852dc8
Add Clippy to config.toml.example
mati865 Jan 2, 2019
ea7fef1
bootstrap: Link LLVM as a dylib with ThinLTO
alexcrichton Dec 18, 2018
a175969
Avoid using open_global_now
alexcrichton Dec 18, 2018
82a1bb3
Remove no longer working test
alexcrichton Dec 19, 2018
fa4f014
Remove now stray comment
alexcrichton Dec 19, 2018
c0662a0
Update the stdsimd submodule
alexcrichton Jan 2, 2019
71fed3a
Don't package up libLLVM.so with libstd
alexcrichton Jan 2, 2019
a944ecf
Fix 'be be' constructs
d-e-s-o Jan 3, 2019
32118a9
More test deduplication
weiznich Jan 3, 2019
677eef5
Rollup merge of #55986 - cjgillot:issue-45510, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
be8a496
Rollup merge of #56145 - weiznich:re_rebalance_coherence, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
fee93ea
Rollup merge of #56723 - oli-obk:lazy_const, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
3baae65
Rollup merge of #56897 - euclio:parse-fatal, r=estebank
Mark-Simulacrum Jan 3, 2019
c90bf0e
Rollup merge of #57099 - davidtwco:issue-57098, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
4473e32
Rollup merge of #57101 - o01eg:fix-57014, r=alexcrichton
Mark-Simulacrum Jan 3, 2019
2701289
Rollup merge of #57145 - RalfJung:panic-if-uninhabited, r=alexcrichton
Mark-Simulacrum Jan 3, 2019
88818d6
Rollup merge of #57219 - matthewjasper:mir-cleanup, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
ac58493
Rollup merge of #57233 - Smibu:rename-and-fix-nolink-test, r=alexcric…
Mark-Simulacrum Jan 3, 2019
400d453
Rollup merge of #57238 - Zoxc:bt-fix, r=alexcrichton
Mark-Simulacrum Jan 3, 2019
028774c
Rollup merge of #57249 - frewsxcv:frewsxcv-second-edition, r=KodrAus
Mark-Simulacrum Jan 3, 2019
e78b596
Rollup merge of #57259 - king6cong:master, r=alexcrichton
Mark-Simulacrum Jan 3, 2019
0496b18
Rollup merge of #57267 - rust-lang:SimonSapin-patch-1, r=varkor
Mark-Simulacrum Jan 3, 2019
f05bd30
Rollup merge of #57272 - petrochenkov:featrecov, r=estebank
Mark-Simulacrum Jan 3, 2019
cf56d3f
Rollup merge of #57273 - alexcrichton:update-stdsimd, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
6e80fb1
Rollup merge of #57275 - jethrogb:jb/update-compiler_builtins, r=alex…
Mark-Simulacrum Jan 3, 2019
e8472e4
Rollup merge of #57278 - mati865:config_clippy, r=alexcrichton
Mark-Simulacrum Jan 3, 2019
5508d36
Rollup merge of #57286 - alexcrichton:less-thin-2-2, r=nikomatsakis
Mark-Simulacrum Jan 3, 2019
6adc37e
Rollup merge of #57295 - d-e-s-o:topic/be-be, r=zackmdavis
Mark-Simulacrum Jan 3, 2019
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
Prev Previous commit
Next Next commit
Add closure cannot be moved note.
This commit extends existing logic for checking whether a closure that
is `FnOnce` and therefore moves variables that it captures from the
environment has already been invoked when being invoked again.

Now, this logic will also check whether the closure is being moved after
previously being moved or invoked and add an appropriate note.
  • Loading branch information
davidtwco committed Dec 26, 2018
commit fcad2094497519989327e372c09f9470bac7f957
82 changes: 43 additions & 39 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Origin::Mir,
);

self.add_closure_invoked_twice_with_moved_variable_suggestion(
self.add_moved_or_invoked_closure_note(
context.loc,
used_place,
&mut err,
Expand Down Expand Up @@ -1331,7 +1331,8 @@ enum StorageDeadOrDrop<'tcx> {

impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {

/// Adds a suggestion when a closure is invoked twice with a moved variable.
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
/// is moved after being invoked.
///
/// ```text
/// note: closure cannot be invoked more than once because it moves the variable `dict` out of
Expand All @@ -1341,30 +1342,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
/// LL | for (key, value) in dict {
/// | ^^^^
/// ```
pub(super) fn add_closure_invoked_twice_with_moved_variable_suggestion(
pub(super) fn add_moved_or_invoked_closure_note(
&self,
location: Location,
place: &Place<'tcx>,
diag: &mut DiagnosticBuilder<'_>,
) {
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
let mut target = place.local();
debug!(
"add_closure_invoked_twice_with_moved_variable_suggestion: location={:?} place={:?} \
target={:?}",
location, place, target,
);
for stmt in &self.mir[location.block].statements[location.statement_index..] {
debug!(
"add_closure_invoked_twice_with_moved_variable_suggestion: stmt={:?} \
target={:?}",
stmt, target,
);
debug!("add_moved_or_invoked_closure_note: stmt={:?} target={:?}", stmt, target);
if let StatementKind::Assign(into, box Rvalue::Use(from)) = &stmt.kind {
debug!(
"add_closure_invoked_twice_with_moved_variable_suggestion: into={:?} \
from={:?}",
into, from,
);
debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from);
match from {
Operand::Copy(ref place) |
Operand::Move(ref place) if target == place.local() =>
Expand All @@ -1374,12 +1363,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}
}


// Check if we are attempting to call a closure after it has been invoked.
let terminator = self.mir[location.block].terminator();
debug!(
"add_closure_invoked_twice_with_moved_variable_suggestion: terminator={:?}",
terminator,
);
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
if let TerminatorKind::Call {
func: Operand::Constant(box Constant {
literal: ty::Const { ty: &ty::TyS { sty: ty::TyKind::FnDef(id, _), .. }, .. },
Expand All @@ -1388,41 +1374,59 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
args,
..
} = &terminator.kind {
debug!("add_closure_invoked_twice_with_moved_variable_suggestion: id={:?}", id);
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
if self.infcx.tcx.parent(id) == self.infcx.tcx.lang_items().fn_once_trait() {
let closure = match args.first() {
Some(Operand::Copy(ref place)) |
Some(Operand::Move(ref place)) if target == place.local() =>
place.local().unwrap(),
_ => return,
};
debug!(
"add_closure_invoked_twice_with_moved_variable_suggestion: closure={:?}",
closure,
);

if let ty::TyKind::Closure(did, _substs) = self.mir.local_decls[closure].ty.sty {
let node_id = match self.infcx.tcx.hir().as_local_node_id(did) {
Some(node_id) => node_id,
_ => return,
};
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
if let ty::TyKind::Closure(did, _) = self.mir.local_decls[closure].ty.sty {
let node_id = self.infcx.tcx.hir().as_local_node_id(did).unwrap();
let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id);

if let Some((
span, name
)) = self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id) {
if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did)
.closure_kind_origins()
.get(hir_id)
{
diag.span_note(
*span,
&format!(
"closure cannot be invoked more than once because it \
moves the variable `{}` out of its environment",
name,
"closure cannot be invoked more than once because it moves the \
variable `{}` out of its environment",
name,
),
);
return;
}
}
}
}

// Check if we are just moving a closure after it has been invoked.
if let Some(target) = target {
if let ty::TyKind::Closure(did, _) = self.mir.local_decls[target].ty.sty {
let node_id = self.infcx.tcx.hir().as_local_node_id(did).unwrap();
let hir_id = self.infcx.tcx.hir().node_to_hir_id(node_id);

if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did)
.closure_kind_origins()
.get(hir_id)
{
diag.span_note(
*span,
&format!(
"closure cannot be moved more than once as it is not `Copy` due to \
moving the variable `{}` out of its environment",
name
),
);
}
}
}
}

/// End-user visible description of `place` if one can be found. If the
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/not-copy-closure.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ LL | let b = hello;
| ----- value moved here
LL | let c = hello; //~ ERROR use of moved value: `hello` [E0382]
| ^^^^^ value used here after move
|
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `a` out of its environment
--> $DIR/not-copy-closure.rs:6:9
|
LL | a += 1;
| ^

error: aborting due to previous error

Expand Down