Skip to content

Commit 0aeaa5e

Browse files
committed
Auto merge of rust-lang#134305 - matthiaskrgr:rollup-bja3lsz, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#133221 (Add external macros specific diagnostics for check-cfg) - rust-lang#133386 (Update linux_musl base to dynamically link the crt by default) - rust-lang#134191 (Make some types and methods related to Polonius + Miri public) - rust-lang#134227 (Update wasi-sdk used to build WASI targets) - rust-lang#134279 ((Re-)return adjustment target if adjust kind is never-to-any) - rust-lang#134295 (Encode coroutine-closures in SMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 85641f7 + b0597b4 commit 0aeaa5e

File tree

55 files changed

+592
-72
lines changed

Some content is hidden

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

55 files changed

+592
-72
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ pub struct BorrowSet<'tcx> {
3434
pub(crate) locals_state_at_exit: LocalsStateAtExit,
3535
}
3636

37+
// These methods are public to support borrowck consumers.
38+
impl<'tcx> BorrowSet<'tcx> {
39+
pub fn location_map(&self) -> &FxIndexMap<Location, BorrowData<'tcx>> {
40+
&self.location_map
41+
}
42+
43+
pub fn activation_map(&self) -> &FxIndexMap<Location, Vec<BorrowIndex>> {
44+
&self.activation_map
45+
}
46+
47+
pub fn local_map(&self) -> &FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>> {
48+
&self.local_map
49+
}
50+
51+
pub fn locals_state_at_exit(&self) -> &LocalsStateAtExit {
52+
&self.locals_state_at_exit
53+
}
54+
}
55+
3756
impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
3857
type Output = BorrowData<'tcx>;
3958

@@ -45,7 +64,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
4564
/// Location where a two-phase borrow is activated, if a borrow
4665
/// is in fact a two-phase borrow.
4766
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
48-
pub(crate) enum TwoPhaseActivation {
67+
pub enum TwoPhaseActivation {
4968
NotTwoPhase,
5069
NotActivated,
5170
ActivatedAt(Location),
@@ -68,6 +87,33 @@ pub struct BorrowData<'tcx> {
6887
pub(crate) assigned_place: mir::Place<'tcx>,
6988
}
7089

90+
// These methods are public to support borrowck consumers.
91+
impl<'tcx> BorrowData<'tcx> {
92+
pub fn reserve_location(&self) -> Location {
93+
self.reserve_location
94+
}
95+
96+
pub fn activation_location(&self) -> TwoPhaseActivation {
97+
self.activation_location
98+
}
99+
100+
pub fn kind(&self) -> mir::BorrowKind {
101+
self.kind
102+
}
103+
104+
pub fn region(&self) -> RegionVid {
105+
self.region
106+
}
107+
108+
pub fn borrowed_place(&self) -> mir::Place<'tcx> {
109+
self.borrowed_place
110+
}
111+
112+
pub fn assigned_place(&self) -> mir::Place<'tcx> {
113+
self.assigned_place
114+
}
115+
}
116+
71117
impl<'tcx> fmt::Display for BorrowData<'tcx> {
72118
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
73119
let kind = match self.kind {
@@ -120,7 +166,7 @@ impl LocalsStateAtExit {
120166
}
121167

122168
impl<'tcx> BorrowSet<'tcx> {
123-
pub(crate) fn build(
169+
pub fn build(
124170
tcx: TyCtxt<'tcx>,
125171
body: &Body<'tcx>,
126172
locals_are_invalidated_at_exit: bool,

compiler/rustc_borrowck/src/consumers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use rustc_index::{IndexSlice, IndexVec};
55
use rustc_middle::mir::{Body, Promoted};
66
use rustc_middle::ty::TyCtxt;
77

8+
pub use super::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
89
pub use super::constraints::OutlivesConstraint;
910
pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_at_location};
10-
pub use super::facts::{AllFacts as PoloniusInput, RustcFacts};
11+
pub use super::facts::{AllFacts as PoloniusInput, PoloniusRegionVid, RustcFacts};
1112
pub use super::location::{LocationTable, RichLocation};
1213
pub use super::nll::PoloniusOutput;
1314
pub use super::place_ext::PlaceExt;
1415
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
1516
pub use super::region_infer::RegionInferenceContext;
16-
use crate::borrow_set::BorrowSet;
1717

1818
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
1919
///

compiler/rustc_const_eval/src/interpret/machine.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,14 @@ pub trait Machine<'tcx>: Sized {
540540
interp_ok(ReturnAction::Normal)
541541
}
542542

543-
/// Called immediately after an "immediate" local variable is read
543+
/// Called immediately after an "immediate" local variable is read in a given frame
544544
/// (i.e., this is called for reads that do not end up accessing addressable memory).
545545
#[inline(always)]
546-
fn after_local_read(_ecx: &InterpCx<'tcx, Self>, _local: mir::Local) -> InterpResult<'tcx> {
546+
fn after_local_read(
547+
_ecx: &InterpCx<'tcx, Self>,
548+
_frame: &Frame<'tcx, Self::Provenance, Self::FrameExtra>,
549+
_local: mir::Local,
550+
) -> InterpResult<'tcx> {
547551
interp_ok(())
548552
}
549553

compiler/rustc_const_eval/src/interpret/operand.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::{bug, mir, span_bug, ty};
1515
use tracing::trace;
1616

1717
use super::{
18-
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, OffsetMode,
19-
PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub, from_known_layout,
20-
interp_ok, mir_assign_valid_types, throw_ub,
18+
CtfeProvenance, Frame, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta,
19+
OffsetMode, PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub,
20+
from_known_layout, interp_ok, mir_assign_valid_types, throw_ub,
2121
};
2222

2323
/// An `Immediate` represents a single immediate self-contained Rust value.
@@ -708,23 +708,32 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
708708
interp_ok(str)
709709
}
710710

711-
/// Read from a local of the current frame.
711+
/// Read from a local of the current frame. Convenience method for [`InterpCx::local_at_frame_to_op`].
712+
pub fn local_to_op(
713+
&self,
714+
local: mir::Local,
715+
layout: Option<TyAndLayout<'tcx>>,
716+
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
717+
self.local_at_frame_to_op(self.frame(), local, layout)
718+
}
719+
720+
/// Read from a local of a given frame.
712721
/// Will not access memory, instead an indirect `Operand` is returned.
713722
///
714-
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
715-
/// OpTy from a local.
716-
pub fn local_to_op(
723+
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
724+
/// to get an OpTy from a local.
725+
pub fn local_at_frame_to_op(
717726
&self,
727+
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
718728
local: mir::Local,
719729
layout: Option<TyAndLayout<'tcx>>,
720730
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
721-
let frame = self.frame();
722731
let layout = self.layout_of_local(frame, local, layout)?;
723732
let op = *frame.locals[local].access()?;
724733
if matches!(op, Operand::Immediate(_)) {
725734
assert!(!layout.is_unsized());
726735
}
727-
M::after_local_read(self, local)?;
736+
M::after_local_read(self, frame, local)?;
728737
interp_ok(OpTy { op, layout })
729738
}
730739

compiler/rustc_const_eval/src/interpret/stack.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
584584
interp_ok(())
585585
}
586586

587+
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
588+
/// to analyze all the locals in a stack frame.
587589
#[inline(always)]
588-
pub(super) fn layout_of_local(
590+
pub fn layout_of_local(
589591
&self,
590592
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
591593
local: mir::Local,

compiler/rustc_hir_typeck/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
if self.try_structurally_resolve_type(expr.span, ty).is_never()
7373
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
7474
{
75-
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
75+
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
7676
let reported = self.dcx().span_delayed_bug(
7777
expr.span,
7878
"expression with never type wound up being adjusted",
7979
);
80-
return Ty::new_error(self.tcx(), reported);
80+
81+
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
82+
target.to_owned()
83+
} else {
84+
Ty::new_error(self.tcx(), reported)
85+
};
8186
}
8287

8388
let adj_ty = self.next_ty_var(expr.span);

compiler/rustc_lint/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,14 @@ lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_printl
806806
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
807807
lint_unexpected_cfg_add_cargo_toml_lint_cfg = or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:{$cargo_toml_lint_cfg}
808808
lint_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
809+
lint_unexpected_cfg_cargo_update = the {$macro_kind} `{$macro_name}` may come from an old version of it's defining crate, try updating your dependencies with `cargo update`
810+
809811
lint_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
810812
lint_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
811813
lint_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
812814
815+
lint_unexpected_cfg_from_external_macro_origin = using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate
816+
lint_unexpected_cfg_from_external_macro_refer = try refering to `{$macro_name}` crate for guidance on how handle this unexpected cfg
813817
lint_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
814818
lint_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
815819
[0] {""}

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

+58-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use rustc_hir::def_id::LOCAL_CRATE;
12
use rustc_middle::bug;
23
use rustc_session::Session;
34
use rustc_session::config::ExpectedValues;
45
use rustc_span::edit_distance::find_best_match_for_name;
56
use rustc_span::symbol::Ident;
6-
use rustc_span::{Span, Symbol, sym};
7+
use rustc_span::{ExpnKind, Span, Symbol, sym};
78

89
use crate::lints;
910

@@ -60,6 +61,35 @@ fn cargo_help_sub(
6061
}
6162
}
6263

64+
fn rustc_macro_help(span: Span) -> Option<lints::UnexpectedCfgRustcMacroHelp> {
65+
let oexpn = span.ctxt().outer_expn_data();
66+
if let Some(def_id) = oexpn.macro_def_id
67+
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
68+
&& def_id.krate != LOCAL_CRATE
69+
{
70+
Some(lints::UnexpectedCfgRustcMacroHelp { macro_kind: macro_kind.descr(), macro_name })
71+
} else {
72+
None
73+
}
74+
}
75+
76+
fn cargo_macro_help(span: Span) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
77+
let oexpn = span.ctxt().outer_expn_data();
78+
if let Some(def_id) = oexpn.macro_def_id
79+
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
80+
&& def_id.krate != LOCAL_CRATE
81+
{
82+
Some(lints::UnexpectedCfgCargoMacroHelp {
83+
macro_kind: macro_kind.descr(),
84+
macro_name,
85+
// FIXME: Get access to a `TyCtxt` from an `EarlyContext`
86+
// crate_name: cx.tcx.crate_name(def_id.krate),
87+
})
88+
} else {
89+
None
90+
}
91+
}
92+
6393
pub(super) fn unexpected_cfg_name(
6494
sess: &Session,
6595
(name, name_span): (Symbol, Span),
@@ -85,6 +115,7 @@ pub(super) fn unexpected_cfg_name(
85115
};
86116

87117
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
118+
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span);
88119
let mut is_feature_cfg = name == sym::feature;
89120

90121
let code_sugg = if is_feature_cfg && is_from_cargo {
@@ -185,12 +216,21 @@ pub(super) fn unexpected_cfg_name(
185216
};
186217

187218
let invocation_help = if is_from_cargo {
188-
let sub = if !is_feature_cfg { Some(cargo_help_sub(sess, &inst)) } else { None };
189-
lints::unexpected_cfg_name::InvocationHelp::Cargo { sub }
219+
let help = if !is_feature_cfg && !is_from_external_macro {
220+
Some(cargo_help_sub(sess, &inst))
221+
} else {
222+
None
223+
};
224+
lints::unexpected_cfg_name::InvocationHelp::Cargo {
225+
help,
226+
macro_help: cargo_macro_help(name_span),
227+
}
190228
} else {
191-
lints::unexpected_cfg_name::InvocationHelp::Rustc(lints::UnexpectedCfgRustcHelp::new(
192-
&inst(EscapeQuotes::No),
193-
))
229+
let help = lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No));
230+
lints::unexpected_cfg_name::InvocationHelp::Rustc {
231+
help,
232+
macro_help: rustc_macro_help(name_span),
233+
}
194234
};
195235

196236
lints::UnexpectedCfgName { code_sugg, invocation_help, name }
@@ -216,7 +256,9 @@ pub(super) fn unexpected_cfg_value(
216256
.copied()
217257
.flatten()
218258
.collect();
259+
219260
let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
261+
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span);
220262

221263
// Show the full list if all possible values for a given name, but don't do it
222264
// for names as the possibilities could be very long
@@ -284,25 +326,31 @@ pub(super) fn unexpected_cfg_value(
284326
};
285327

286328
let invocation_help = if is_from_cargo {
287-
let help = if name == sym::feature {
329+
let help = if name == sym::feature && !is_from_external_macro {
288330
if let Some((value, _value_span)) = value {
289331
Some(lints::unexpected_cfg_value::CargoHelp::AddFeature { value })
290332
} else {
291333
Some(lints::unexpected_cfg_value::CargoHelp::DefineFeatures)
292334
}
293-
} else if can_suggest_adding_value {
335+
} else if can_suggest_adding_value && !is_from_external_macro {
294336
Some(lints::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst)))
295337
} else {
296338
None
297339
};
298-
lints::unexpected_cfg_value::InvocationHelp::Cargo(help)
340+
lints::unexpected_cfg_value::InvocationHelp::Cargo {
341+
help,
342+
macro_help: cargo_macro_help(name_span),
343+
}
299344
} else {
300345
let help = if can_suggest_adding_value {
301346
Some(lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No)))
302347
} else {
303348
None
304349
};
305-
lints::unexpected_cfg_value::InvocationHelp::Rustc(help)
350+
lints::unexpected_cfg_value::InvocationHelp::Rustc {
351+
help,
352+
macro_help: rustc_macro_help(name_span),
353+
}
306354
};
307355

308356
lints::UnexpectedCfgValue {

0 commit comments

Comments
 (0)