Skip to content

Commit 12b71ed

Browse files
committed
Auto merge of rust-lang#94385 - matthiaskrgr:rollup-4pwegqk, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#93603 (Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`) - rust-lang#93870 (Fix switch on discriminant detection in a presence of coverage counters) - rust-lang#94355 (Add one more case to avoid ICE) - rust-lang#94363 (Remove needless borrows from core::fmt) - rust-lang#94377 (`check_used` should only look at actual `used` attributes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d973b35 + 04f7780 commit 12b71ed

File tree

11 files changed

+109
-25
lines changed

11 files changed

+109
-25
lines changed

compiler/rustc_borrowck/src/nll.rs

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
188188
move_data,
189189
elements,
190190
upvars,
191+
use_polonius,
191192
);
192193

193194
if let Some(all_facts) = &mut all_facts {

compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub(super) fn generate<'mir, 'tcx>(
3737
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
3838
move_data: &MoveData<'tcx>,
3939
location_table: &LocationTable,
40+
use_polonius: bool,
4041
) {
4142
debug!("liveness::generate");
4243

@@ -46,7 +47,7 @@ pub(super) fn generate<'mir, 'tcx>(
4647
&typeck.borrowck_context.constraints.outlives_constraints,
4748
);
4849
let live_locals = compute_live_locals(typeck.tcx(), &free_regions, &body);
49-
let facts_enabled = AllFacts::enabled(typeck.tcx());
50+
let facts_enabled = use_polonius || AllFacts::enabled(typeck.tcx());
5051

5152
let polonius_drop_used = if facts_enabled {
5253
let mut drop_used = Vec::new();

compiler/rustc_borrowck/src/type_check/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
136136
move_data: &MoveData<'tcx>,
137137
elements: &Rc<RegionValueElements>,
138138
upvars: &[Upvar<'tcx>],
139+
use_polonius: bool,
139140
) -> MirTypeckResults<'tcx> {
140141
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
141142
let mut universe_causes = FxHashMap::default();
@@ -187,7 +188,15 @@ pub(crate) fn type_check<'mir, 'tcx>(
187188
&mut borrowck_context,
188189
|mut cx| {
189190
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
190-
liveness::generate(&mut cx, body, elements, flow_inits, move_data, location_table);
191+
liveness::generate(
192+
&mut cx,
193+
body,
194+
elements,
195+
flow_inits,
196+
move_data,
197+
location_table,
198+
use_polonius,
199+
);
191200

192201
translate_outlives_facts(&mut cx);
193202
let opaque_type_values = mem::take(&mut infcx.inner.borrow_mut().opaque_types);

compiler/rustc_mir_dataflow/src/impls/mod.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -706,24 +706,27 @@ fn switch_on_enum_discriminant<'mir, 'tcx>(
706706
block: &'mir mir::BasicBlockData<'tcx>,
707707
switch_on: mir::Place<'tcx>,
708708
) -> Option<(mir::Place<'tcx>, &'tcx ty::AdtDef)> {
709-
match block.statements.last().map(|stmt| &stmt.kind) {
710-
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))))
711-
if *lhs == switch_on =>
712-
{
713-
match &discriminated.ty(body, tcx).ty.kind() {
714-
ty::Adt(def, _) => Some((*discriminated, def)),
715-
716-
// `Rvalue::Discriminant` is also used to get the active yield point for a
717-
// generator, but we do not need edge-specific effects in that case. This may
718-
// change in the future.
719-
ty::Generator(..) => None,
720-
721-
t => bug!("`discriminant` called on unexpected type {:?}", t),
709+
for statement in block.statements.iter().rev() {
710+
match &statement.kind {
711+
mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated)))
712+
if *lhs == switch_on =>
713+
{
714+
match &discriminated.ty(body, tcx).ty.kind() {
715+
ty::Adt(def, _) => return Some((*discriminated, def)),
716+
717+
// `Rvalue::Discriminant` is also used to get the active yield point for a
718+
// generator, but we do not need edge-specific effects in that case. This may
719+
// change in the future.
720+
ty::Generator(..) => return None,
721+
722+
t => bug!("`discriminant` called on unexpected type {:?}", t),
723+
}
722724
}
725+
mir::StatementKind::Coverage(_) => continue,
726+
_ => return None,
723727
}
724-
725-
_ => None,
726728
}
729+
None
727730
}
728731

729732
struct OnMutBorrow<F>(F);

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,8 @@ impl CheckAttrVisitor<'_> {
17401740
fn check_used(&self, attrs: &[Attribute], target: Target) {
17411741
let mut used_linker_span = None;
17421742
let mut used_compiler_span = None;
1743-
for attr in attrs {
1744-
if attr.has_name(sym::used) && target != Target::Static {
1743+
for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) {
1744+
if target != Target::Static {
17451745
self.tcx
17461746
.sess
17471747
.span_err(attr.span, "attribute must be applied to a `static` variable");

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+9
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
313313
) => {
314314
// A reborrow has no effect before a dereference.
315315
}
316+
// Catch cases which have Deref(None)
317+
// having them slip to bug! causes ICE
318+
// see #94291 for more info
319+
(&[Adjustment { kind: Adjust::Deref(None), .. }], _) => {
320+
self.tcx.sess.delay_span_bug(
321+
DUMMY_SP,
322+
&format!("Can't compose Deref(None) expressions"),
323+
)
324+
}
316325
// FIXME: currently we never try to compose autoderefs
317326
// and ReifyFnPointer/UnsafeFnPointer, but we could.
318327
_ => bug!(

library/core/src/fmt/builders.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
138138
}
139139
let mut slot = None;
140140
let mut state = Default::default();
141-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
141+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);
142142
writer.write_str(name)?;
143143
writer.write_str(": ")?;
144144
value.fmt(&mut writer)?;
@@ -189,7 +189,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
189189
if self.is_pretty() {
190190
let mut slot = None;
191191
let mut state = Default::default();
192-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
192+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);
193193
writer.write_str("..\n")?;
194194
self.fmt.write_str("}")
195195
} else {
@@ -323,7 +323,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
323323
}
324324
let mut slot = None;
325325
let mut state = Default::default();
326-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
326+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);
327327
value.fmt(&mut writer)?;
328328
writer.write_str(",\n")
329329
} else {
@@ -394,7 +394,7 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
394394
}
395395
let mut slot = None;
396396
let mut state = Default::default();
397-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
397+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);
398398
entry.fmt(&mut writer)?;
399399
writer.write_str(",\n")
400400
} else {
@@ -789,7 +789,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
789789
}
790790
let mut slot = None;
791791
self.state = Default::default();
792-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut self.state);
792+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut self.state);
793793
key.fmt(&mut writer)?;
794794
writer.write_str(": ")?;
795795
} else {
@@ -845,7 +845,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
845845

846846
if self.is_pretty() {
847847
let mut slot = None;
848-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut self.state);
848+
let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut self.state);
849849
value.fmt(&mut writer)?;
850850
writer.write_str(",\n")?;
851851
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
#![feature(used_with_arg)]
4+
5+
#[used(linker)]
6+
#[no_mangle] // accidentally detected as `used(compiler)`
7+
pub static GLOB: usize = 0;
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Checks that code coverage doesn't interfere with const_precise_live_drops.
2+
// Regression test for issue #93848.
3+
//
4+
// check-pass
5+
// compile-flags: --crate-type=lib -Cinstrument-coverage -Zno-profiler-runtime
6+
7+
#![feature(const_precise_live_drops)]
8+
9+
#[inline]
10+
pub const fn transpose<T, E>(this: Option<Result<T, E>>) -> Result<Option<T>, E> {
11+
match this {
12+
Some(Ok(x)) => Ok(Some(x)),
13+
Some(Err(e)) => Err(e),
14+
None => Ok(None),
15+
}
16+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::collections::VecDeque;
2+
3+
pub struct BuildPlanBuilder {
4+
acc: VecDeque<(String, String)>,
5+
current_provides: String,
6+
current_requires: String,
7+
}
8+
9+
impl BuildPlanBuilder {
10+
pub fn or(&mut self) -> &mut Self {
11+
self.acc.push_back(self.current_provides, self.current_requires);
12+
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
13+
self
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
2+
--> $DIR/wrong_argument_ice.rs:11:18
3+
|
4+
LL | self.acc.push_back(self.current_provides, self.current_requires);
5+
| ^^^^^^^^^ --------------------- --------------------- supplied 2 arguments
6+
|
7+
note: associated function defined here
8+
--> $SRC_DIR/alloc/src/collections/vec_deque/mod.rs:LL:COL
9+
|
10+
LL | pub fn push_back(&mut self, value: T) {
11+
| ^^^^^^^^^
12+
help: use parentheses to construct a tuple
13+
|
14+
LL | self.acc.push_back((self.current_provides, self.current_requires));
15+
| + +
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)