Skip to content

Commit

Permalink
Auto merge of #92062 - matthiaskrgr:rollup-en3p4sb, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #91439 (Mark defaulted `PartialEq`/`PartialOrd` methods as const)
 - #91516 (Improve suggestion to change struct field to &mut)
 - #91896 (Remove `in_band_lifetimes` for `rustc_passes`)
 - #91909 (:arrow_up: rust-analyzer)
 - #91922 (Remove `in_band_lifetimes` from `rustc_mir_dataflow`)
 - #92025 (Revert "socket ancillary data implementation for dragonflybsd.")
 - #92030 (Update stdlib to the 2021 edition)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 18, 2021
2 parents 208ced6 + efbefb6 commit d3f3004
Show file tree
Hide file tree
Showing 41 changed files with 208 additions and 239 deletions.
39 changes: 12 additions & 27 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} => {
err.span_label(span, format!("cannot {ACT}", ACT = act));

if let Some((span, message)) = annotate_struct_field(
if let Some(span) = get_mut_span_in_struct_field(
self.infcx.tcx,
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty,
field,
) {
err.span_suggestion(
err.span_suggestion_verbose(
span,
"consider changing this to be mutable",
message,
" mut ".into(),
Applicability::MaybeIncorrect,
);
}
Expand Down Expand Up @@ -1059,18 +1059,18 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
ty.is_closure() || ty.is_generator()
}

/// Adds a suggestion to a struct definition given a field access to a local.
/// This function expects the local to be a reference to a struct in order to produce a suggestion.
/// Given a field that needs to be mutable, returns a span where the " mut " could go.
/// This function expects the local to be a reference to a struct in order to produce a span.
///
/// ```text
/// LL | s: &'a String
/// | ---------- use `&'a mut String` here to make mutable
/// LL | s: &'a String
/// | ^^^ returns a span taking up the space here
/// ```
fn annotate_struct_field<'tcx>(
fn get_mut_span_in_struct_field<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
field: &mir::Field,
) -> Option<(Span, String)> {
) -> Option<Span> {
// Expect our local to be a reference to a struct of some kind.
if let ty::Ref(_, ty, _) = ty.kind() {
if let ty::Adt(def, _) = ty.kind() {
Expand All @@ -1081,25 +1081,10 @@ fn annotate_struct_field<'tcx>(
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.
if let hir::Node::Field(field) = node {
if let hir::TyKind::Rptr(
lifetime,
hir::MutTy { mutbl: hir::Mutability::Not, ref ty },
) = field.ty.kind
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
field.ty.kind
{
// Get the snippets in two parts - the named lifetime (if there is one) and
// type being referenced, that way we can reconstruct the snippet without loss
// of detail.
let type_snippet = tcx.sess.source_map().span_to_snippet(ty.span).ok()?;
let lifetime_snippet = if !lifetime.is_elided() {
format!("{} ", tcx.sess.source_map().span_to_snippet(lifetime.span).ok()?)
} else {
String::new()
};

return Some((
field.ty.span,
format!("&{}mut {}", lifetime_snippet, &*type_snippet,),
));
return Some(lifetime.span.between(ty.span));
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_mir_dataflow/src/framework/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait Direction {
/// Applies all effects between the given `EffectIndex`s.
///
/// `effects.start()` must precede or equal `effects.end()` in this direction.
fn apply_effects_in_range<A>(
fn apply_effects_in_range<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
Expand All @@ -27,23 +27,23 @@ pub trait Direction {
) where
A: Analysis<'tcx>;

fn apply_effects_in_block<A>(
fn apply_effects_in_block<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
block_data: &mir::BasicBlockData<'tcx>,
) where
A: Analysis<'tcx>;

fn gen_kill_effects_in_block<A>(
fn gen_kill_effects_in_block<'tcx, A>(
analysis: &A,
trans: &mut GenKillSet<A::Idx>,
block: BasicBlock,
block_data: &mir::BasicBlockData<'tcx>,
) where
A: GenKillAnalysis<'tcx>;

fn visit_results_in_block<F, R>(
fn visit_results_in_block<'mir, 'tcx, F, R>(
state: &mut F,
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
Expand All @@ -52,7 +52,7 @@ pub trait Direction {
) where
R: ResultsVisitable<'tcx, FlowState = F>;

fn join_state_into_successors_of<A>(
fn join_state_into_successors_of<'tcx, A>(
analysis: &A,
tcx: TyCtxt<'tcx>,
body: &mir::Body<'tcx>,
Expand All @@ -72,7 +72,7 @@ impl Direction for Backward {
false
}

fn apply_effects_in_block<A>(
fn apply_effects_in_block<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
Expand All @@ -92,7 +92,7 @@ impl Direction for Backward {
}
}

fn gen_kill_effects_in_block<A>(
fn gen_kill_effects_in_block<'tcx, A>(
analysis: &A,
trans: &mut GenKillSet<A::Idx>,
block: BasicBlock,
Expand All @@ -112,7 +112,7 @@ impl Direction for Backward {
}
}

fn apply_effects_in_range<A>(
fn apply_effects_in_range<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
Expand Down Expand Up @@ -189,7 +189,7 @@ impl Direction for Backward {
analysis.apply_statement_effect(state, statement, location);
}

fn visit_results_in_block<F, R>(
fn visit_results_in_block<'mir, 'tcx, F, R>(
state: &mut F,
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Direction for Backward {
vis.visit_block_start(state, block_data, block);
}

fn join_state_into_successors_of<A>(
fn join_state_into_successors_of<'tcx, A>(
analysis: &A,
_tcx: TyCtxt<'tcx>,
body: &mir::Body<'tcx>,
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Direction for Forward {
true
}

fn apply_effects_in_block<A>(
fn apply_effects_in_block<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
Expand All @@ -314,7 +314,7 @@ impl Direction for Forward {
analysis.apply_terminator_effect(state, terminator, location);
}

fn gen_kill_effects_in_block<A>(
fn gen_kill_effects_in_block<'tcx, A>(
analysis: &A,
trans: &mut GenKillSet<A::Idx>,
block: BasicBlock,
Expand All @@ -334,7 +334,7 @@ impl Direction for Forward {
analysis.terminator_effect(trans, terminator, location);
}

fn apply_effects_in_range<A>(
fn apply_effects_in_range<'tcx, A>(
analysis: &A,
state: &mut A::Domain,
block: BasicBlock,
Expand Down Expand Up @@ -407,7 +407,7 @@ impl Direction for Forward {
}
}

fn visit_results_in_block<F, R>(
fn visit_results_in_block<'mir, 'tcx, F, R>(
state: &mut F,
block: BasicBlock,
block_data: &'mir mir::BasicBlockData<'tcx>,
Expand Down Expand Up @@ -438,7 +438,7 @@ impl Direction for Forward {
vis.visit_block_end(state, block_data, block);
}

fn join_state_into_successors_of<A>(
fn join_state_into_successors_of<'tcx, A>(
analysis: &A,
_tcx: TyCtxt<'tcx>,
_body: &mir::Body<'tcx>,
Expand Down Expand Up @@ -591,7 +591,7 @@ where
//
// FIXME: Figure out how to express this using `Option::clone_from`, or maybe lift it into the
// standard library?
fn opt_clone_from_or_clone<T: Clone>(opt: &'a mut Option<T>, val: &T) -> &'a mut T {
fn opt_clone_from_or_clone<'a, T: Clone>(opt: &'a mut Option<T>, val: &T) -> &'a mut T {
if opt.is_some() {
let ret = opt.as_mut().unwrap();
ret.clone_from(val);
Expand Down
21 changes: 12 additions & 9 deletions compiler/rustc_mir_dataflow/src/framework/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ where
pub(super) entry_sets: IndexVec<BasicBlock, A::Domain>,
}

impl<A> Results<'tcx, A>
impl<'tcx, A> Results<'tcx, A>
where
A: Analysis<'tcx>,
{
/// Creates a `ResultsCursor` that can inspect these `Results`.
pub fn into_results_cursor(self, body: &'mir mir::Body<'tcx>) -> ResultsCursor<'mir, 'tcx, A> {
pub fn into_results_cursor<'mir>(
self,
body: &'mir mir::Body<'tcx>,
) -> ResultsCursor<'mir, 'tcx, A> {
ResultsCursor::new(body, self)
}

Expand All @@ -45,7 +48,7 @@ where
&self.entry_sets[block]
}

pub fn visit_with(
pub fn visit_with<'mir>(
&self,
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
Expand All @@ -54,7 +57,7 @@ where
visit_results(body, blocks, self, vis)
}

pub fn visit_reachable_with(
pub fn visit_reachable_with<'mir>(
&self,
body: &'mir mir::Body<'tcx>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, FlowState = A::Domain>,
Expand Down Expand Up @@ -85,7 +88,7 @@ where
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
}

impl<A, D, T> Engine<'a, 'tcx, A>
impl<'a, 'tcx, A, D, T> Engine<'a, 'tcx, A>
where
A: GenKillAnalysis<'tcx, Idx = T, Domain = D>,
D: Clone + JoinSemiLattice + GenKill<T> + BorrowMut<BitSet<T>>,
Expand Down Expand Up @@ -119,7 +122,7 @@ where
}
}

impl<A, D> Engine<'a, 'tcx, A>
impl<'a, 'tcx, A, D> Engine<'a, 'tcx, A>
where
A: Analysis<'tcx, Domain = D>,
D: Clone + JoinSemiLattice,
Expand Down Expand Up @@ -257,7 +260,7 @@ where

/// Writes a DOT file containing the results of a dataflow analysis if the user requested it via
/// `rustc_mir` attributes.
fn write_graphviz_results<A>(
fn write_graphviz_results<'tcx, A>(
tcx: TyCtxt<'tcx>,
body: &mir::Body<'tcx>,
results: &Results<'tcx, A>,
Expand Down Expand Up @@ -330,7 +333,7 @@ struct RustcMirAttrs {
}

impl RustcMirAttrs {
fn parse(tcx: TyCtxt<'tcx>, def_id: DefId) -> Result<Self, ()> {
fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Result<Self, ()> {
let attrs = tcx.get_attrs(def_id);

let mut result = Ok(());
Expand Down Expand Up @@ -373,7 +376,7 @@ impl RustcMirAttrs {

fn set_field<T>(
field: &mut Option<T>,
tcx: TyCtxt<'tcx>,
tcx: TyCtxt<'_>,
attr: &ast::NestedMetaItem,
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
) -> Result<(), ()> {
Expand Down
Loading

0 comments on commit d3f3004

Please sign in to comment.