Skip to content

Commit 1406186

Browse files
committed
Auto merge of rust-lang#70994 - Centril:rollup-lftv0a3, r=Centril
Rollup of 9 pull requests Successful merges: - rust-lang#69745 (Use `PredicateObligation`s instead of `Predicate`s) - rust-lang#70938 (Add ThreadSanitizer test case) - rust-lang#70973 (Use forward traversal for unconditional recursion lint) - rust-lang#70978 (compiletest: let config flags overwrite -A unused) - rust-lang#70979 (Follow up on BTreeMap comments) - rust-lang#70981 (Rearrange BTreeMap::into_iter to match range_mut.) - rust-lang#70985 (Clean up E0512 explanation) - rust-lang#70988 (Setup the `@rustbot prioritize` command) - rust-lang#70991 (fix rustc-dev-guide's url in src/librustc_codegen_ssa) Failed merges: r? @ghost
2 parents 9682f0e + 178aa6a commit 1406186

File tree

217 files changed

+754
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+754
-565
lines changed

src/liballoc/collections/btree/map.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1544,19 +1544,19 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
15441544
type IntoIter = IntoIter<K, V>;
15451545

15461546
fn into_iter(self) -> IntoIter<K, V> {
1547-
let me = ManuallyDrop::new(self);
1548-
if me.root.is_none() {
1549-
return IntoIter { front: None, back: None, length: 0 };
1550-
}
1551-
1552-
let root1 = unsafe { unwrap_unchecked(ptr::read(&me.root)).into_ref() };
1553-
let root2 = unsafe { unwrap_unchecked(ptr::read(&me.root)).into_ref() };
1554-
let len = me.length;
1555-
1556-
IntoIter {
1557-
front: Some(root1.first_leaf_edge()),
1558-
back: Some(root2.last_leaf_edge()),
1559-
length: len,
1547+
let mut me = ManuallyDrop::new(self);
1548+
if let Some(root) = me.root.as_mut() {
1549+
let root1 = unsafe { ptr::read(root).into_ref() };
1550+
let root2 = unsafe { ptr::read(root).into_ref() };
1551+
let len = me.length;
1552+
1553+
IntoIter {
1554+
front: Some(root1.first_leaf_edge()),
1555+
back: Some(root2.last_leaf_edge()),
1556+
length: len,
1557+
}
1558+
} else {
1559+
IntoIter { front: None, back: None, length: 0 }
15601560
}
15611561
}
15621562
}
@@ -2771,8 +2771,6 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27712771
pos.next_unchecked();
27722772
}
27732773
}
2774-
2775-
// This internal node might be underfull, but only if it's the root.
27762774
break;
27772775
}
27782776
}

src/liballoc/collections/btree/node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<K, V> Root<K, V> {
161161
NodeRef {
162162
height: self.height,
163163
node: self.node.as_ptr(),
164-
root: self as *const _ as *mut _,
164+
root: ptr::null(),
165165
_marker: PhantomData,
166166
}
167167
}
@@ -179,7 +179,7 @@ impl<K, V> Root<K, V> {
179179
NodeRef {
180180
height: self.height,
181181
node: self.node.as_ptr(),
182-
root: ptr::null_mut(), // FIXME: Is there anything better to do here?
182+
root: ptr::null(),
183183
_marker: PhantomData,
184184
}
185185
}

src/librustc_codegen_ssa/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Please read the rustc-dev-guide chapter on [Backend Agnostic Codegen][bac].
22

3-
[bac]: https://rustc-dev-guide.rust-lang.org/codegen/backend-agnostic.html
3+
[bac]: https://rustc-dev-guide.rust-lang.org/backend/backend-agnostic.html

src/librustc_data_structures/graph/iterate/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ where
209209
// schedule its successors for examination.
210210
self.stack.push(Event { node, becomes: Settled });
211211
for succ in self.graph.successors(node) {
212-
self.stack.push(Event { node: succ, becomes: Visited });
212+
if !visitor.ignore_edge(node, succ) {
213+
self.stack.push(Event { node: succ, becomes: Visited });
214+
}
213215
}
214216
}
215217
}
@@ -255,16 +257,21 @@ where
255257
/// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
256258
fn node_examined(
257259
&mut self,
258-
_target: G::Node,
260+
_node: G::Node,
259261
_prior_status: Option<NodeStatus>,
260262
) -> ControlFlow<Self::BreakVal> {
261263
ControlFlow::Continue
262264
}
263265

264266
/// Called after all nodes reachable from this one have been examined.
265-
fn node_settled(&mut self, _target: G::Node) -> ControlFlow<Self::BreakVal> {
267+
fn node_settled(&mut self, _node: G::Node) -> ControlFlow<Self::BreakVal> {
266268
ControlFlow::Continue
267269
}
270+
271+
/// Behave as if no edges exist from `source` to `target`.
272+
fn ignore_edge(&mut self, _source: G::Node, _target: G::Node) -> bool {
273+
false
274+
}
268275
}
269276

270277
/// This `TriColorVisitor` looks for back edges in a graph, which indicate that a cycle exists.

src/librustc_error_codes/error_codes/E0512.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Transmute with two differently sized types was attempted. Erroneous code
2-
example:
1+
Transmute with two differently sized types was attempted.
2+
3+
Erroneous code example:
34

45
```compile_fail,E0512
56
fn takes_u8(_: u8) {}

src/librustc_infer/infer/outlives/verify.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
296296
let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs);
297297
self.collect_outlives_from_predicate_list(
298298
move |ty| ty == identity_proj,
299-
traits::elaborate_predicates(tcx, trait_predicates),
299+
traits::elaborate_predicates(tcx, trait_predicates)
300+
.into_iter()
301+
.map(|o| o.predicate)
302+
.collect::<Vec<_>>(),
300303
)
301304
.map(|b| b.1)
302305
}

src/librustc_infer/traits/util.rs

+48-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use smallvec::smallvec;
22

3+
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
34
use rustc_data_structures::fx::FxHashSet;
45
use rustc_middle::ty::outlives::Component;
56
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, TyCtxt, WithConstness};
7+
use rustc_span::Span;
68

79
pub fn anonymize_predicate<'tcx>(
810
tcx: TyCtxt<'tcx>,
@@ -87,7 +89,7 @@ impl<T: AsRef<ty::Predicate<'tcx>>> Extend<T> for PredicateSet<'tcx> {
8789
/// holds as well. Similarly, if we have `trait Foo: 'static`, and we know that
8890
/// `T: Foo`, then we know that `T: 'static`.
8991
pub struct Elaborator<'tcx> {
90-
stack: Vec<ty::Predicate<'tcx>>,
92+
stack: Vec<PredicateObligation<'tcx>>,
9193
visited: PredicateSet<'tcx>,
9294
}
9395

@@ -112,35 +114,60 @@ pub fn elaborate_predicates<'tcx>(
112114
) -> Elaborator<'tcx> {
113115
let mut visited = PredicateSet::new(tcx);
114116
predicates.retain(|pred| visited.insert(pred));
115-
Elaborator { stack: predicates, visited }
117+
let obligations: Vec<_> =
118+
predicates.into_iter().map(|predicate| predicate_obligation(predicate, None)).collect();
119+
elaborate_obligations(tcx, obligations)
120+
}
121+
122+
pub fn elaborate_obligations<'tcx>(
123+
tcx: TyCtxt<'tcx>,
124+
mut obligations: Vec<PredicateObligation<'tcx>>,
125+
) -> Elaborator<'tcx> {
126+
let mut visited = PredicateSet::new(tcx);
127+
obligations.retain(|obligation| visited.insert(&obligation.predicate));
128+
Elaborator { stack: obligations, visited }
129+
}
130+
131+
fn predicate_obligation<'tcx>(
132+
predicate: ty::Predicate<'tcx>,
133+
span: Option<Span>,
134+
) -> PredicateObligation<'tcx> {
135+
let mut cause = ObligationCause::dummy();
136+
if let Some(span) = span {
137+
cause.span = span;
138+
}
139+
Obligation { cause, param_env: ty::ParamEnv::empty(), recursion_depth: 0, predicate }
116140
}
117141

118142
impl Elaborator<'tcx> {
119143
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
120144
FilterToTraits::new(self)
121145
}
122146

123-
fn elaborate(&mut self, predicate: &ty::Predicate<'tcx>) {
147+
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
124148
let tcx = self.visited.tcx;
125-
match *predicate {
149+
match obligation.predicate {
126150
ty::Predicate::Trait(ref data, _) => {
127151
// Get predicates declared on the trait.
128152
let predicates = tcx.super_predicates_of(data.def_id());
129153

130-
let predicates = predicates
131-
.predicates
132-
.iter()
133-
.map(|(pred, _)| pred.subst_supertrait(tcx, &data.to_poly_trait_ref()));
134-
debug!("super_predicates: data={:?} predicates={:?}", data, predicates.clone());
154+
let obligations = predicates.predicates.iter().map(|(pred, span)| {
155+
predicate_obligation(
156+
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
157+
Some(*span),
158+
)
159+
});
160+
debug!("super_predicates: data={:?} predicates={:?}", data, &obligations);
135161

136162
// Only keep those bounds that we haven't already seen.
137163
// This is necessary to prevent infinite recursion in some
138164
// cases. One common case is when people define
139165
// `trait Sized: Sized { }` rather than `trait Sized { }`.
140166
let visited = &mut self.visited;
141-
let predicates = predicates.filter(|pred| visited.insert(pred));
167+
let obligations =
168+
obligations.filter(|obligation| visited.insert(&obligation.predicate));
142169

143-
self.stack.extend(predicates);
170+
self.stack.extend(obligations);
144171
}
145172
ty::Predicate::WellFormed(..) => {
146173
// Currently, we do not elaborate WF predicates,
@@ -221,25 +248,26 @@ impl Elaborator<'tcx> {
221248
None
222249
}
223250
})
224-
.filter(|p| visited.insert(p)),
251+
.filter(|p| visited.insert(p))
252+
.map(|p| predicate_obligation(p, None)),
225253
);
226254
}
227255
}
228256
}
229257
}
230258

231259
impl Iterator for Elaborator<'tcx> {
232-
type Item = ty::Predicate<'tcx>;
260+
type Item = PredicateObligation<'tcx>;
233261

234262
fn size_hint(&self) -> (usize, Option<usize>) {
235263
(self.stack.len(), None)
236264
}
237265

238-
fn next(&mut self) -> Option<ty::Predicate<'tcx>> {
266+
fn next(&mut self) -> Option<Self::Item> {
239267
// Extract next item from top-most stack frame, if any.
240-
if let Some(pred) = self.stack.pop() {
241-
self.elaborate(&pred);
242-
Some(pred)
268+
if let Some(obligation) = self.stack.pop() {
269+
self.elaborate(&obligation);
270+
Some(obligation)
243271
} else {
244272
None
245273
}
@@ -282,12 +310,12 @@ impl<I> FilterToTraits<I> {
282310
}
283311
}
284312

285-
impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
313+
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
286314
type Item = ty::PolyTraitRef<'tcx>;
287315

288316
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
289-
while let Some(pred) = self.base_iterator.next() {
290-
if let ty::Predicate::Trait(data, _) = pred {
317+
while let Some(obligation) = self.base_iterator.next() {
318+
if let ty::Predicate::Trait(data, _) = obligation.predicate {
291319
return Some(data.to_poly_trait_ref());
292320
}
293321
}

src/librustc_mir/transform/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
126126
.collect();
127127
if !traits::normalize_and_test_predicates(
128128
tcx,
129-
traits::elaborate_predicates(tcx, predicates).collect(),
129+
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
130130
) {
131131
trace!("ConstProp skipped for {:?}: found unsatisfiable predicates", source.def_id());
132132
return;

src/librustc_mir_build/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> {
178178
build::construct_const(cx, body_id, return_ty, return_ty_span)
179179
};
180180

181+
lints::check(tcx, &body, def_id);
182+
181183
let mut body = BodyAndCache::new(body);
182184
body.ensure_predecessors();
183185

184-
lints::check(tcx, &body.unwrap_read_only(), def_id);
185-
186186
// The borrow checker will replace all the regions here with its own
187187
// inference variables. There's no point having non-erased regions here.
188188
// The exception is `body.user_type_annotations`, which is used unmodified

0 commit comments

Comments
 (0)