Skip to content

Commit 40e88bc

Browse files
committed
Auto merge of #146628 - Zalathar:rollup-ecm8zaj, r=Zalathar
Rollup of 3 pull requests Successful merges: - #145181 (remove FIXME block from `has_significant_drop`, it never encounters inference variables) - #146259 (Suggest removing Box::new instead of unboxing it) - #146588 (tests/run-make: Update list of statically linked musl targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents eec6bd9 + be1ac56 commit 40e88bc

File tree

7 files changed

+69
-20
lines changed

7 files changed

+69
-20
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,6 +3021,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30213021
)
30223022
{
30233023
let deref_kind = if checked_ty.is_box() {
3024+
// detect Box::new(..)
3025+
if let ExprKind::Call(box_new, [_]) = expr.kind
3026+
&& let ExprKind::Path(qpath) = &box_new.kind
3027+
&& let Res::Def(DefKind::AssocFn, fn_id) =
3028+
self.typeck_results.borrow().qpath_res(qpath, box_new.hir_id)
3029+
&& let Some(impl_id) = self.tcx.inherent_impl_of_assoc(fn_id)
3030+
&& self.tcx.type_of(impl_id).skip_binder().is_box()
3031+
&& self.tcx.item_name(fn_id) == sym::new
3032+
{
3033+
let l_paren = self.tcx.sess.source_map().next_point(box_new.span);
3034+
let r_paren = self.tcx.sess.source_map().end_point(expr.span);
3035+
return Some((
3036+
vec![
3037+
(box_new.span.to(l_paren), String::new()),
3038+
(r_paren, String::new()),
3039+
],
3040+
"consider removing the Box".to_string(),
3041+
Applicability::MachineApplicable,
3042+
false,
3043+
false,
3044+
));
3045+
}
30243046
"unboxing the value"
30253047
} else if checked_ty.is_ref() {
30263048
"dereferencing the borrow"

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ impl<'tcx> Ty<'tcx> {
13591359
/// 2229 drop reorder migration analysis.
13601360
#[inline]
13611361
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool {
1362+
assert!(!self.has_non_region_infer());
13621363
// Avoid querying in simple cases.
13631364
match needs_drop_components(tcx, self) {
13641365
Err(AlwaysRequiresDrop) => true,
@@ -1371,14 +1372,6 @@ impl<'tcx> Ty<'tcx> {
13711372
_ => self,
13721373
};
13731374

1374-
// FIXME(#86868): We should be canonicalizing, or else moving this to a method of inference
1375-
// context, or *something* like that, but for now just avoid passing inference
1376-
// variables to queries that can't cope with them. Instead, conservatively
1377-
// return "true" (may change drop order).
1378-
if query_ty.has_infer() {
1379-
return true;
1380-
}
1381-
13821375
// This doesn't depend on regions, so try to minimize distinct
13831376
// query keys used.
13841377
let erased = tcx.normalize_erasing_regions(typing_env, query_ty);

tests/run-make/musl-default-linking/rmake.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use run_make_support::{rustc, serde_json};
44
// Per https://github.com/rust-lang/compiler-team/issues/422,
55
// we should be trying to move these targets to dynamically link
66
// musl libc by default.
7-
//@ needs-llvm-components: aarch64 arm mips powerpc riscv systemz x86
7+
//@ needs-llvm-components: aarch64 arm mips powerpc x86
88
static LEGACY_STATIC_LINKING_TARGETS: &[&'static str] = &[
99
"aarch64-unknown-linux-musl",
1010
"arm-unknown-linux-musleabi",
@@ -14,16 +14,8 @@ static LEGACY_STATIC_LINKING_TARGETS: &[&'static str] = &[
1414
"armv7-unknown-linux-musleabihf",
1515
"i586-unknown-linux-musl",
1616
"i686-unknown-linux-musl",
17-
"mips64-unknown-linux-musl",
18-
"mips64-unknown-linux-muslabi64",
1917
"mips64el-unknown-linux-muslabi64",
20-
"powerpc-unknown-linux-musl",
21-
"powerpc-unknown-linux-muslspe",
22-
"powerpc64-unknown-linux-musl",
2318
"powerpc64le-unknown-linux-musl",
24-
"riscv32gc-unknown-linux-musl",
25-
"s390x-unknown-linux-musl",
26-
"thumbv7neon-unknown-linux-musleabihf",
2719
"x86_64-unknown-linux-musl",
2820
];
2921

tests/ui/coercion/coerce-block-tail.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ LL | let _: &i32 = & { Box::new(1i32) };
66
|
77
= note: expected type `i32`
88
found struct `Box<i32>`
9-
help: consider unboxing the value
9+
help: consider removing the Box
10+
|
11+
LL - let _: &i32 = & { Box::new(1i32) };
12+
LL + let _: &i32 = & { 1i32 };
1013
|
11-
LL | let _: &i32 = & { *Box::new(1i32) };
12-
| +
1314

1415
error: aborting due to 1 previous error
1516

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let _: String = Box::new(String::new());
3+
//~^ ERROR mismatched types
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/coerce-box-new-to-unboxed.rs:2:21
3+
|
4+
LL | let _: String = Box::new(String::new());
5+
| ------ ^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Box<String>`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected struct `String`
10+
found struct `Box<String>`
11+
help: consider removing the Box
12+
|
13+
LL - let _: String = Box::new(String::new());
14+
LL + let _: String = String::new();
15+
|
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-pass
2+
// Inference, canonicalization, and significant drops should work nicely together.
3+
// Related issue: #86868
4+
5+
#[clippy::has_significant_drop]
6+
struct DropGuy {}
7+
8+
fn creator() -> DropGuy {
9+
DropGuy {}
10+
}
11+
12+
fn dropper() {
13+
let _ = creator();
14+
}
15+
16+
fn main() {
17+
dropper();
18+
}

0 commit comments

Comments
 (0)