Skip to content

Rollup of 6 pull requests #134305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
44c166e
Add Cargo revision and values to the check-cfg macro test
Urgau Nov 19, 2024
0ab3ae8
Disable most Cargo check-cfg help in external macros
Urgau Nov 19, 2024
e2fbeec
Add external macro specific diagnostic to check-cfg
Urgau Nov 19, 2024
9c37c14
Update linux_musl base to dynamically link the crt by default
wesleywiser Nov 23, 2024
3f3ee2d
Add test for musl dynamically linking
wesleywiser Dec 11, 2024
eb10db0
Make some types and methods related to Polonius + Miri public.
willcrichton Dec 12, 2024
6b93fac
Update wasi-sdk used to build WASI targets
alexcrichton Dec 12, 2024
4d5d470
Make BorrowSet/BorrowData fields accessible via public getters
willcrichton Dec 12, 2024
91e74ed
Encode coroutine-closures in SMIR
compiler-errors Dec 14, 2024
0b0744a
Add a regression test for #134162
jieyouxu Dec 13, 2024
d15315c
Return adjustment target if adjust kind is never-to-any
jieyouxu Dec 13, 2024
f96fdab
Rollup merge of #133221 - Urgau:check-cfg-macro-diag, r=jieyouxu
matthiaskrgr Dec 14, 2024
1c24da6
Rollup merge of #133386 - wesleywiser:update_musl_base_crt_default, r…
matthiaskrgr Dec 14, 2024
fffdb1b
Rollup merge of #134191 - willcrichton:dev, r=RalfJung,lqd
matthiaskrgr Dec 14, 2024
352e323
Rollup merge of #134227 - alexcrichton:update-wasi-sdk, r=lqd
matthiaskrgr Dec 14, 2024
752f79a
Rollup merge of #134279 - jieyouxu:return-adjustment-target, r=compil…
matthiaskrgr Dec 14, 2024
b0597b4
Rollup merge of #134295 - compiler-errors:smir-async-closure, r=oli-obk
matthiaskrgr Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions compiler/rustc_borrowck/src/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ pub struct BorrowSet<'tcx> {
pub(crate) locals_state_at_exit: LocalsStateAtExit,
}

// These methods are public to support borrowck consumers.
impl<'tcx> BorrowSet<'tcx> {
pub fn location_map(&self) -> &FxIndexMap<Location, BorrowData<'tcx>> {
&self.location_map
}

pub fn activation_map(&self) -> &FxIndexMap<Location, Vec<BorrowIndex>> {
&self.activation_map
}

pub fn local_map(&self) -> &FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>> {
&self.local_map
}

pub fn locals_state_at_exit(&self) -> &LocalsStateAtExit {
&self.locals_state_at_exit
}
}

impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
type Output = BorrowData<'tcx>;

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

// These methods are public to support borrowck consumers.
impl<'tcx> BorrowData<'tcx> {
pub fn reserve_location(&self) -> Location {
self.reserve_location
}

pub fn activation_location(&self) -> TwoPhaseActivation {
self.activation_location
}

pub fn kind(&self) -> mir::BorrowKind {
self.kind
}

pub fn region(&self) -> RegionVid {
self.region
}

pub fn borrowed_place(&self) -> mir::Place<'tcx> {
self.borrowed_place
}

pub fn assigned_place(&self) -> mir::Place<'tcx> {
self.assigned_place
}
}

impl<'tcx> fmt::Display for BorrowData<'tcx> {
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
let kind = match self.kind {
Expand Down Expand Up @@ -120,7 +166,7 @@ impl LocalsStateAtExit {
}

impl<'tcx> BorrowSet<'tcx> {
pub(crate) fn build(
pub fn build(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
locals_are_invalidated_at_exit: bool,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/consumers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::{Body, Promoted};
use rustc_middle::ty::TyCtxt;

pub use super::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
pub use super::constraints::OutlivesConstraint;
pub use super::dataflow::{BorrowIndex, Borrows, calculate_borrows_out_of_scope_at_location};
pub use super::facts::{AllFacts as PoloniusInput, RustcFacts};
pub use super::facts::{AllFacts as PoloniusInput, PoloniusRegionVid, RustcFacts};
pub use super::location::{LocationTable, RichLocation};
pub use super::nll::PoloniusOutput;
pub use super::place_ext::PlaceExt;
pub use super::places_conflict::{PlaceConflictBias, places_conflict};
pub use super::region_infer::RegionInferenceContext;
use crate::borrow_set::BorrowSet;

/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
///
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,14 @@ pub trait Machine<'tcx>: Sized {
interp_ok(ReturnAction::Normal)
}

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

Expand Down
27 changes: 18 additions & 9 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use rustc_middle::{bug, mir, span_bug, ty};
use tracing::trace;

use super::{
CtfeProvenance, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta, OffsetMode,
PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub, from_known_layout,
interp_ok, mir_assign_valid_types, throw_ub,
CtfeProvenance, Frame, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, MemPlaceMeta,
OffsetMode, PlaceTy, Pointer, Projectable, Provenance, Scalar, alloc_range, err_ub,
from_known_layout, interp_ok, mir_assign_valid_types, throw_ub,
};

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

/// Read from a local of the current frame.
/// Read from a local of the current frame. Convenience method for [`InterpCx::local_at_frame_to_op`].
pub fn local_to_op(
&self,
local: mir::Local,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
self.local_at_frame_to_op(self.frame(), local, layout)
}

/// Read from a local of a given frame.
/// Will not access memory, instead an indirect `Operand` is returned.
///
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
/// OpTy from a local.
pub fn local_to_op(
/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
/// to get an OpTy from a local.
pub fn local_at_frame_to_op(
&self,
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
local: mir::Local,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
let frame = self.frame();
let layout = self.layout_of_local(frame, local, layout)?;
let op = *frame.locals[local].access()?;
if matches!(op, Operand::Immediate(_)) {
assert!(!layout.is_unsized());
}
M::after_local_read(self, local)?;
M::after_local_read(self, frame, local)?;
interp_ok(OpTy { op, layout })
}

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_const_eval/src/interpret/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
interp_ok(())
}

/// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
/// to analyze all the locals in a stack frame.
#[inline(always)]
pub(super) fn layout_of_local(
pub fn layout_of_local(
&self,
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
local: mir::Local,
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.try_structurally_resolve_type(expr.span, ty).is_never()
&& self.expr_guaranteed_to_constitute_read_for_never(expr)
{
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
let reported = self.dcx().span_delayed_bug(
expr.span,
"expression with never type wound up being adjusted",
);
return Ty::new_error(self.tcx(), reported);

return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
target.to_owned()
} else {
Ty::new_error(self.tcx(), reported)
};
}

let adj_ty = self.next_ty_var(expr.span);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,14 @@ lint_unexpected_cfg_add_build_rs_println = or consider adding `{$build_rs_printl
lint_unexpected_cfg_add_cargo_feature = consider using a Cargo feature instead
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}
lint_unexpected_cfg_add_cmdline_arg = to expect this configuration use `{$cmdline_arg}`
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`

lint_unexpected_cfg_define_features = consider defining some features in `Cargo.toml`
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
lint_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration

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
lint_unexpected_cfg_from_external_macro_refer = try refering to `{$macro_name}` crate for guidance on how handle this unexpected cfg
lint_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
lint_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
[0] {""}
Expand Down
68 changes: 58 additions & 10 deletions compiler/rustc_lint/src/context/diagnostics/check_cfg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::bug;
use rustc_session::Session;
use rustc_session::config::ExpectedValues;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::Ident;
use rustc_span::{Span, Symbol, sym};
use rustc_span::{ExpnKind, Span, Symbol, sym};

use crate::lints;

Expand Down Expand Up @@ -60,6 +61,35 @@ fn cargo_help_sub(
}
}

fn rustc_macro_help(span: Span) -> Option<lints::UnexpectedCfgRustcMacroHelp> {
let oexpn = span.ctxt().outer_expn_data();
if let Some(def_id) = oexpn.macro_def_id
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
&& def_id.krate != LOCAL_CRATE
{
Some(lints::UnexpectedCfgRustcMacroHelp { macro_kind: macro_kind.descr(), macro_name })
} else {
None
}
}

fn cargo_macro_help(span: Span) -> Option<lints::UnexpectedCfgCargoMacroHelp> {
let oexpn = span.ctxt().outer_expn_data();
if let Some(def_id) = oexpn.macro_def_id
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
&& def_id.krate != LOCAL_CRATE
{
Some(lints::UnexpectedCfgCargoMacroHelp {
macro_kind: macro_kind.descr(),
macro_name,
// FIXME: Get access to a `TyCtxt` from an `EarlyContext`
// crate_name: cx.tcx.crate_name(def_id.krate),
})
} else {
None
}
}

pub(super) fn unexpected_cfg_name(
sess: &Session,
(name, name_span): (Symbol, Span),
Expand All @@ -85,6 +115,7 @@ pub(super) fn unexpected_cfg_name(
};

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

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

let invocation_help = if is_from_cargo {
let sub = if !is_feature_cfg { Some(cargo_help_sub(sess, &inst)) } else { None };
lints::unexpected_cfg_name::InvocationHelp::Cargo { sub }
let help = if !is_feature_cfg && !is_from_external_macro {
Some(cargo_help_sub(sess, &inst))
} else {
None
};
lints::unexpected_cfg_name::InvocationHelp::Cargo {
help,
macro_help: cargo_macro_help(name_span),
}
} else {
lints::unexpected_cfg_name::InvocationHelp::Rustc(lints::UnexpectedCfgRustcHelp::new(
&inst(EscapeQuotes::No),
))
let help = lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No));
lints::unexpected_cfg_name::InvocationHelp::Rustc {
help,
macro_help: rustc_macro_help(name_span),
}
};

lints::UnexpectedCfgName { code_sugg, invocation_help, name }
Expand All @@ -216,7 +256,9 @@ pub(super) fn unexpected_cfg_value(
.copied()
.flatten()
.collect();

let is_from_cargo = rustc_session::utils::was_invoked_from_cargo();
let is_from_external_macro = rustc_middle::lint::in_external_macro(sess, name_span);

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

let invocation_help = if is_from_cargo {
let help = if name == sym::feature {
let help = if name == sym::feature && !is_from_external_macro {
if let Some((value, _value_span)) = value {
Some(lints::unexpected_cfg_value::CargoHelp::AddFeature { value })
} else {
Some(lints::unexpected_cfg_value::CargoHelp::DefineFeatures)
}
} else if can_suggest_adding_value {
} else if can_suggest_adding_value && !is_from_external_macro {
Some(lints::unexpected_cfg_value::CargoHelp::Other(cargo_help_sub(sess, &inst)))
} else {
None
};
lints::unexpected_cfg_value::InvocationHelp::Cargo(help)
lints::unexpected_cfg_value::InvocationHelp::Cargo {
help,
macro_help: cargo_macro_help(name_span),
}
} else {
let help = if can_suggest_adding_value {
Some(lints::UnexpectedCfgRustcHelp::new(&inst(EscapeQuotes::No)))
} else {
None
};
lints::unexpected_cfg_value::InvocationHelp::Rustc(help)
lints::unexpected_cfg_value::InvocationHelp::Rustc {
help,
macro_help: rustc_macro_help(name_span),
}
};

lints::UnexpectedCfgValue {
Expand Down
Loading
Loading