Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #83790

Merged
merged 28 commits into from
Apr 2, 2021
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7c89cc4
Add SharedResource abstraction and use it in write_shared
jyn514 Mar 25, 2021
f77ebd4
Add unstable option to only emit shared/crate-specific files
jyn514 Mar 25, 2021
0dbed61
Rework `std::sys::windows::alloc`
CDirkx Mar 12, 2021
b01bf0e
Apply suggestions from code review
CDirkx Mar 22, 2021
4cce9e3
Cache `GetProcessHeap`
CDirkx Mar 26, 2021
fa89c0f
add testcase for double-drop during Vec in-place collection
the8472 Mar 29, 2021
421f5d2
fix double-drop in in-place collect specialization
the8472 Mar 29, 2021
f2e52ff
2229: Produce a rustfix migration suggestion
arora-aman Mar 29, 2021
8f77356
give full path of constraint in suggest_constraining_type_param
Rustin170506 Mar 30, 2021
e78fac5
Handle the case of partially captured drop type
arora-aman Mar 31, 2021
d4f3f91
Enforce that Toolchain files are static and Crate files are dynamic
jyn514 Mar 31, 2021
1086d9b
Rename CrateSpecific -> InvocationSpecific
jyn514 Mar 31, 2021
413938d
Fix `--external-css` to be invocation-specific and note main.js shoul…
jyn514 Mar 31, 2021
18af989
Update lint message
arora-aman Apr 1, 2021
da86348
Update test cases
arora-aman Apr 1, 2021
a721957
Don't introduce a block if a block exists
arora-aman Apr 2, 2021
1b9620d
Make the diagnostic message more readable
arora-aman Apr 2, 2021
ca14abb
Fix stack overflow detection on FreeBSD 11.1+
asomers Mar 27, 2021
fad5388
Simplify coverage tests
richkadel Apr 1, 2021
c86e098
Introduce `get_process_heap` and fix atomic ordering.
CDirkx Apr 2, 2021
db1d003
Remove `debug_assert`
CDirkx Apr 2, 2021
48ebad5
Rollup merge of #83065 - CDirkx:win-alloc, r=dtolnay
Dylan-DPC Apr 2, 2021
31f5320
Rollup merge of #83478 - jyn514:fine-grained-files, r=Mark-Simulacrum
Dylan-DPC Apr 2, 2021
542f441
Rollup merge of #83629 - the8472:fix-inplace-panic-on-drop, r=m-ou-se
Dylan-DPC Apr 2, 2021
6cb74ad
Rollup merge of #83673 - hi-rustin:rustin-patch-suggestion, r=estebank
Dylan-DPC Apr 2, 2021
7009117
Rollup merge of #83755 - richkadel:cov-test-simplify, r=tmandry
Dylan-DPC Apr 2, 2021
eed73c6
Rollup merge of #83757 - sexxi-goose:migrations_out, r=nikomatsakis
Dylan-DPC Apr 2, 2021
cb7133f
Rollup merge of #83771 - asomers:stack_overflow_freebsd, r=dtolnay
Dylan-DPC Apr 2, 2021
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
Update lint message
  • Loading branch information
arora-aman committed Apr 1, 2021
commit 18af989c063efd759e03d6eebb7b18e2b03349a4
43 changes: 31 additions & 12 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);

if !need_migrations.is_empty() {
let migrations_text = migration_suggestion_for_2229(self.tcx, &need_migrations);
let (migration_string, migrated_variables_concat) =
migration_suggestion_for_2229(self.tcx, &need_migrations);

let local_def_id = closure_def_id.expect_local();
let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id);
Expand All @@ -495,15 +496,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (sugg, app) =
match self.tcx.sess.source_map().span_to_snippet(closure_body_span) {
Ok(s) => (
format!("{{ {} {} }}", migrations_text, s),
format!("{{ {}; {} }}", migration_string, s),
Applicability::MachineApplicable,
),
Err(_) => (migrations_text.clone(), Applicability::HasPlaceholders),
Err(_) => (migration_string.clone(), Applicability::HasPlaceholders),
};

let diagnostic_msg = format!(
"`{}` causes {} to be fully captured",
migration_string, migrated_variables_concat
);

diagnostics_builder.span_suggestion(
closure_body_span,
&format!("You can restore original behavior adding `{}` to the closure/generator", migrations_text),
&diagnostic_msg,
sugg,
app,
);
Expand Down Expand Up @@ -1537,16 +1543,29 @@ fn should_do_migration_analysis(tcx: TyCtxt<'_>, closure_id: hir::HirId) -> bool
!matches!(level, lint::Level::Allow)
}

fn migration_suggestion_for_2229(tcx: TyCtxt<'_>, need_migrations: &Vec<hir::HirId>) -> String {
let need_migrations_strings =
need_migrations.iter().map(|v| format!("&{}", var_name(tcx, *v))).collect::<Vec<_>>();
let migrations_list_concat = need_migrations_strings.join(", ");
/// Return a two string tuple (s1, s2)
/// - s1: Line of code that is needed for the migration: eg: `let _ = (&x, ...)`.
/// - s2: Comma separated names of the variables being migrated.
fn migration_suggestion_for_2229(
tcx: TyCtxt<'_>,
need_migrations: &Vec<hir::HirId>,
) -> (String, String) {
let need_migrations_variables =
need_migrations.iter().map(|v| var_name(tcx, *v)).collect::<Vec<_>>();

let migration_ref_concat =
need_migrations_variables.iter().map(|v| format!("&{}", v)).collect::<Vec<_>>().join(", ");

if 1 == need_migrations.len() {
format!("let _ = {};", migrations_list_concat)
let migration_string = if 1 == need_migrations.len() {
format!("let _ = {}", migration_ref_concat)
} else {
format!("let _ = ({});", migrations_list_concat)
}
format!("let _ = ({})", migration_ref_concat)
};

let migrated_variables_concat =
need_migrations_variables.iter().map(|v| format!("`{}`", v)).collect::<Vec<_>>().join(", ");

(migration_string, migrated_variables_concat)
}

/// Helper function to determine if we need to escalate CaptureKind from
Expand Down