Skip to content

Commit 4b94758

Browse files
committed
Auto merge of #147640 - matthiaskrgr:rollup-fio3d88, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #144266 (Supress swapping lhs and rhs in equality suggestion in extern macro ) - #147471 (Assert that non-extended temporaries and `super let` bindings have scopes) - #147533 (Renumber return local after state transform) - #147566 (rewrite outlives placeholder constraints to outlives static when handling opaque types) - #147613 (Make logging filters work again by moving EnvFilter into its own layer) - #147615 (reduce calls to attr.span() in old doc attr parsing) - #147636 (miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed1d943 + 8d2b142 commit 4b94758

File tree

252 files changed

+4083
-867
lines changed

Some content is hidden

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

252 files changed

+4083
-867
lines changed

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(crate) fn compute_sccs_applying_placeholder_outlives_constraints<'tcx>(
344344
}
345345
}
346346

347-
fn rewrite_placeholder_outlives<'tcx>(
347+
pub(crate) fn rewrite_placeholder_outlives<'tcx>(
348348
sccs: &Sccs<RegionVid, ConstraintSccIndex>,
349349
annotations: &SccAnnotations<'_, '_, RegionTracker>,
350350
fr_static: RegionVid,

compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(super) fn apply_member_constraints<'tcx>(
3939
debug!(?member_constraints);
4040
for scc_a in rcx.constraint_sccs.all_sccs() {
4141
debug!(?scc_a);
42-
// Start by adding the region values required by outlives constraints. This
42+
// Start by adding the region values required by outlives constraints. This
4343
// matches how we compute the final region values in `fn compute_regions`.
4444
//
4545
// We need to do this here to get a lower bound when applying member constraints.
@@ -64,6 +64,7 @@ fn apply_member_constraint<'tcx>(
6464
// If the member region lives in a higher universe, we currently choose
6565
// the most conservative option by leaving it unchanged.
6666
if !rcx.max_placeholder_universe_reached(member).is_root() {
67+
debug!("member region reached non root universe, bailing");
6768
return;
6869
}
6970

compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ fn collect_defining_uses<'tcx>(
253253
}
254254
} else {
255255
errors.push(DeferredOpaqueTypeError::InvalidOpaqueTypeArgs(err));
256+
debug!(
257+
"collect_defining_uses: InvalidOpaqueTypeArgs for {:?} := {:?}",
258+
non_nll_opaque_type_key, hidden_type
259+
);
256260
}
257261
continue;
258262
}
@@ -276,6 +280,7 @@ fn collect_defining_uses<'tcx>(
276280
defining_uses
277281
}
278282

283+
#[instrument(level = "debug", skip(rcx, hidden_types, defining_uses, errors))]
279284
fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
280285
rcx: &RegionCtxt<'_, 'tcx>,
281286
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
@@ -287,13 +292,15 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
287292
let mut decls_modulo_regions: FxIndexMap<OpaqueTypeKey<'tcx>, (OpaqueTypeKey<'tcx>, Span)> =
288293
FxIndexMap::default();
289294
for &DefiningUse { opaque_type_key, ref arg_regions, hidden_type } in defining_uses {
295+
debug!(?opaque_type_key, ?arg_regions, ?hidden_type);
290296
// After applying member constraints, we now map all regions in the hidden type
291297
// to the `arg_regions` of this defining use. In case a region in the hidden type
292298
// ended up not being equal to any such region, we error.
293299
let hidden_type =
294300
match hidden_type.try_fold_with(&mut ToArgRegionsFolder::new(rcx, arg_regions)) {
295301
Ok(hidden_type) => hidden_type,
296302
Err(r) => {
303+
debug!("UnexpectedHiddenRegion: {:?}", r);
297304
errors.push(DeferredOpaqueTypeError::UnexpectedHiddenRegion {
298305
hidden_type,
299306
opaque_type_key,

compiler/rustc_borrowck/src/region_infer/opaque_types/region_ctxt.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use crate::constraints::ConstraintSccIndex;
1111
use crate::handle_placeholders::{SccAnnotations, region_definitions};
1212
use crate::region_infer::reverse_sccs::ReverseSccGraph;
1313
use crate::region_infer::values::RegionValues;
14-
use crate::region_infer::{ConstraintSccs, RegionDefinition, RegionTracker, Representative};
14+
use crate::region_infer::{
15+
ConstraintSccs, OutlivesConstraintSet, RegionDefinition, RegionTracker, Representative,
16+
};
1517
use crate::type_check::MirTypeckRegionConstraints;
1618
use crate::type_check::free_region_relations::UniversalRegionRelations;
1719
use crate::universal_regions::UniversalRegions;
@@ -39,16 +41,36 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
3941
location_map: Rc<DenseLocationMap>,
4042
constraints: &MirTypeckRegionConstraints<'tcx>,
4143
) -> RegionCtxt<'a, 'tcx> {
44+
let mut outlives_constraints = constraints.outlives_constraints.clone();
4245
let universal_regions = &universal_region_relations.universal_regions;
4346
let (definitions, _has_placeholders) = region_definitions(infcx, universal_regions);
47+
48+
let compute_sccs =
49+
|outlives_constraints: &OutlivesConstraintSet<'tcx>,
50+
annotations: &mut SccAnnotations<'_, 'tcx, RegionTracker>| {
51+
ConstraintSccs::new_with_annotation(
52+
&outlives_constraints
53+
.graph(definitions.len())
54+
.region_graph(outlives_constraints, universal_regions.fr_static),
55+
annotations,
56+
)
57+
};
58+
4459
let mut scc_annotations = SccAnnotations::init(&definitions);
45-
let constraint_sccs = ConstraintSccs::new_with_annotation(
46-
&constraints
47-
.outlives_constraints
48-
.graph(definitions.len())
49-
.region_graph(&constraints.outlives_constraints, universal_regions.fr_static),
50-
&mut scc_annotations,
60+
let mut constraint_sccs = compute_sccs(&outlives_constraints, &mut scc_annotations);
61+
62+
let added_constraints = crate::handle_placeholders::rewrite_placeholder_outlives(
63+
&constraint_sccs,
64+
&scc_annotations,
65+
universal_regions.fr_static,
66+
&mut outlives_constraints,
5167
);
68+
69+
if added_constraints {
70+
scc_annotations = SccAnnotations::init(&definitions);
71+
constraint_sccs = compute_sccs(&outlives_constraints, &mut scc_annotations);
72+
}
73+
5274
let scc_annotations = scc_annotations.scc_to_annotation;
5375

5476
// Unlike the `RegionInferenceContext`, we only care about free regions

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ fn resolve_local<'tcx>(
498498
// Iterate up to the enclosing destruction scope to find the same scope that will also
499499
// be used for the result of the block itself.
500500
if let Some(inner_scope) = visitor.cx.var_parent {
501-
(visitor.cx.var_parent, _) = visitor.scope_tree.default_temporary_scope(inner_scope)
501+
visitor.cx.var_parent =
502+
Some(visitor.scope_tree.default_temporary_scope(inner_scope).0)
502503
}
503504
// Don't lifetime-extend child `super let`s or block tail expressions' temporaries in
504505
// the initializer when this `super let` is not itself extended by a parent `let`
@@ -752,10 +753,10 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
752753
// The body of the every fn is a root scope.
753754
resolve_expr(this, body.value, true);
754755
} else {
755-
// Only functions have an outer terminating (drop) scope, while
756-
// temporaries in constant initializers may be 'static, but only
757-
// according to rvalue lifetime semantics, using the same
758-
// syntactical rules used for let initializers.
756+
// All bodies have an outer temporary drop scope, but temporaries
757+
// and `super let` bindings in constant initializers may be extended
758+
// to have 'static lifetimes, using the same syntactical rules used
759+
// for `let` initializers.
759760
//
760761
// e.g., in `let x = &f();`, the temporary holding the result from
761762
// the `f()` call lives for the entirety of the surrounding block.

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36363636
.must_apply_modulo_regions()
36373637
{
36383638
let sm = self.tcx.sess.source_map();
3639-
if let Ok(rhs_snippet) = sm.span_to_snippet(rhs_expr.span)
3639+
// If the span of rhs_expr or lhs_expr is in an external macro,
3640+
// we just suppress the suggestion. See issue #139050
3641+
if !rhs_expr.span.in_external_macro(sm)
3642+
&& !lhs_expr.span.in_external_macro(sm)
3643+
&& let Ok(rhs_snippet) = sm.span_to_snippet(rhs_expr.span)
36403644
&& let Ok(lhs_snippet) = sm.span_to_snippet(lhs_expr.span)
36413645
{
36423646
err.note(format!("`{rhs_ty}` implements `PartialEq<{lhs_ty}>`"));

compiler/rustc_log/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ use std::io::{self, IsTerminal};
3939

4040
use tracing::dispatcher::SetGlobalDefaultError;
4141
use tracing::{Event, Subscriber};
42+
use tracing_subscriber::Registry;
4243
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
4344
use tracing_subscriber::fmt::FmtContext;
4445
use tracing_subscriber::fmt::format::{self, FormatEvent, FormatFields};
4546
use tracing_subscriber::layer::SubscriberExt;
46-
use tracing_subscriber::{Layer, Registry};
4747

4848
/// The values of all the environment variables that matter for configuring a logger.
4949
/// Errors are explicitly preserved so that we can share error handling.
@@ -152,18 +152,19 @@ where
152152
}
153153
}
154154

155-
let subscriber = build_subscriber().with(layer.with_filter(filter));
155+
let subscriber = build_subscriber();
156+
// NOTE: It is important to make sure that the filter is applied on the last layer
156157
match cfg.backtrace {
157158
Ok(backtrace_target) => {
158159
let fmt_layer = tracing_subscriber::fmt::layer()
159160
.with_writer(io::stderr)
160161
.without_time()
161162
.event_format(BacktraceFormatter { backtrace_target });
162-
let subscriber = subscriber.with(fmt_layer);
163+
let subscriber = subscriber.with(layer).with(fmt_layer).with(filter);
163164
tracing::subscriber::set_global_default(subscriber)?;
164165
}
165166
Err(_) => {
166-
tracing::subscriber::set_global_default(subscriber)?;
167+
tracing::subscriber::set_global_default(subscriber.with(layer).with(filter))?;
167168
}
168169
};
169170

compiler/rustc_middle/src/middle/region.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
1616
use rustc_span::{DUMMY_SP, Span};
1717
use tracing::debug;
1818

19-
use crate::ty::TyCtxt;
19+
use crate::ty::{self, TyCtxt};
2020

2121
/// Represents a statically-describable scope that can be used to
2222
/// bound the lifetime/region for values.
@@ -302,20 +302,20 @@ impl ScopeTree {
302302

303303
/// Returns the scope of non-lifetime-extended temporaries within a given scope, as well as
304304
/// whether we've recorded a potential backwards-incompatible change to lint on.
305-
/// Returns `None` when no enclosing temporary scope is found, such as for static items.
306-
pub fn default_temporary_scope(&self, inner: Scope) -> (Option<Scope>, Option<Scope>) {
305+
/// Panics if no enclosing temporary scope is found.
306+
pub fn default_temporary_scope(&self, inner: Scope) -> (Scope, Option<Scope>) {
307307
let mut id = inner;
308308
let mut backwards_incompatible = None;
309309

310310
while let Some(&p) = self.parent_map.get(&id) {
311311
match p.data {
312312
ScopeData::Destruction => {
313313
debug!("temporary_scope({inner:?}) = {id:?} [enclosing]");
314-
return (Some(id), backwards_incompatible);
314+
return (id, backwards_incompatible);
315315
}
316316
ScopeData::IfThenRescope | ScopeData::MatchGuard => {
317317
debug!("temporary_scope({inner:?}) = {p:?} [enclosing]");
318-
return (Some(p), backwards_incompatible);
318+
return (p, backwards_incompatible);
319319
}
320320
ScopeData::Node
321321
| ScopeData::CallSite
@@ -335,7 +335,6 @@ impl ScopeTree {
335335
}
336336
}
337337

338-
debug!("temporary_scope({inner:?}) = None");
339-
(None, backwards_incompatible)
338+
span_bug!(ty::tls::with(|tcx| inner.span(tcx, self)), "no enclosing temporary scope")
340339
}
341340
}

compiler/rustc_middle/src/ty/rvalue_scopes.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ impl RvalueScopes {
3131
return (s, None);
3232
}
3333

34-
// Otherwise, locate the innermost terminating scope
35-
// if there's one. Static items, for instance, won't
36-
// have an enclosing scope, hence no scope will be
37-
// returned.
38-
region_scope_tree
39-
.default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node })
34+
// Otherwise, locate the innermost terminating scope.
35+
let (scope, backward_incompatible) = region_scope_tree
36+
.default_temporary_scope(Scope { local_id: expr_id, data: ScopeData::Node });
37+
(Some(scope), backward_incompatible)
4038
}
4139

4240
/// Make an association between a sub-expression and an extended lifetime

0 commit comments

Comments
 (0)