Skip to content

Commit

Permalink
Auto merge of rust-lang#125588 - workingjubilee:rollup-yr47gxo, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 10 pull requests

Successful merges:

 - rust-lang#125046 (Only allow immutable statics with #[linkage])
 - rust-lang#125466 (Don't continue probing for method if in suggestion and autoderef hits ambiguity)
 - rust-lang#125469 (Don't skip out of inner const when looking for body for suggestion)
 - rust-lang#125530 (cleanup dependence of `ExtCtxt` in transcribe when macro expansion)
 - rust-lang#125535 (clean-up: remove deprecated field `dist.missing-tools`)
 - rust-lang#125539 (crashes: increment the number of tracked ones)
 - rust-lang#125544 (Also mention my-self for other check-cfg docs changes)
 - rust-lang#125559 (Simplify the `unchecked_sh[lr]` ub-checks a bit)
 - rust-lang#125566 (Notify T-rustdoc for beta-accepted and stable-accepted too)
 - rust-lang#125582 (Avoid a `FieldIdx::from_usize` in InstSimplify)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 26, 2024
2 parents bdbbb6c + b2d7f77 commit a62ffec
Show file tree
Hide file tree
Showing 37 changed files with 348 additions and 67 deletions.
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} else {
codegen_fn_attrs.linkage = linkage;
}
if tcx.is_mutable_static(did.into()) {
let mut diag = tcx.dcx().struct_span_err(
attr.span,
"mutable statics are not allowed with `#[linkage]`",
);
diag.note(
"making the static mutable would allow changing which symbol the \
static references rather than make the target of the symbol \
mutable",
);
diag.emit();
}
}
}
sym::link_section => {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ fn expand_macro<'cx>(
let arm_span = rhses[i].span();

// rhs has holes ( `$id` and `$(...)` that need filled)
let tts = match transcribe(cx, &named_matches, rhs, rhs_span, transparency) {
let id = cx.current_expansion.id;
let tts = match transcribe(psess, &named_matches, rhs, rhs_span, transparency, id) {
Ok(tts) => tts,
Err(err) => {
let guar = err.emit();
Expand Down
60 changes: 29 additions & 31 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::base::ExtCtxt;
use crate::errors::{
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
NoSyntaxVarsExprRepeat, VarStillRepeating,
Expand All @@ -9,12 +8,13 @@ use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{pluralize, Diag, PResult};
use rustc_errors::{pluralize, Diag, DiagCtxt, PResult};
use rustc_parse::parser::ParseNtResult;
use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
use rustc_span::{with_metavar_spans, Span, SyntaxContext};

use rustc_session::parse::ParseSess;
use smallvec::{smallvec, SmallVec};
use std::mem;

Expand Down Expand Up @@ -99,11 +99,12 @@ impl<'a> Iterator for Frame<'a> {
///
/// Along the way, we do some additional error checking.
pub(super) fn transcribe<'a>(
cx: &ExtCtxt<'a>,
psess: &'a ParseSess,
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
src: &mbe::Delimited,
src_span: DelimSpan,
transparency: Transparency,
expand_id: LocalExpnId,
) -> PResult<'a, TokenStream> {
// Nothing for us to transcribe...
if src.tts.is_empty() {
Expand Down Expand Up @@ -137,8 +138,9 @@ pub(super) fn transcribe<'a>(
// again, and we are done transcribing.
let mut result: Vec<TokenTree> = Vec::new();
let mut result_stack = Vec::new();
let mut marker = Marker(cx.current_expansion.id, transparency, Default::default());
let mut marker = Marker(expand_id, transparency, Default::default());

let dcx = &psess.dcx;
loop {
// Look at the last frame on the stack.
// If it still has a TokenTree we have not looked at yet, use that tree.
Expand Down Expand Up @@ -201,19 +203,17 @@ pub(super) fn transcribe<'a>(
seq @ mbe::TokenTree::Sequence(_, seq_rep) => {
match lockstep_iter_size(seq, interp, &repeats) {
LockstepIterSize::Unconstrained => {
return Err(cx
.dcx()
.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
return Err(dcx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
}

LockstepIterSize::Contradiction(msg) => {
// FIXME: this really ought to be caught at macro definition time... It
// happens when two meta-variables are used in the same repetition in a
// sequence, but they come from different sequence matchers and repeat
// different amounts.
return Err(cx
.dcx()
.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
return Err(
dcx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg })
);
}

LockstepIterSize::Constraint(len, _) => {
Expand All @@ -227,9 +227,7 @@ pub(super) fn transcribe<'a>(
// FIXME: this really ought to be caught at macro definition
// time... It happens when the Kleene operator in the matcher and
// the body for the same meta-variable do not match.
return Err(cx
.dcx()
.create_err(MustRepeatOnce { span: sp.entire() }));
return Err(dcx.create_err(MustRepeatOnce { span: sp.entire() }));
}
} else {
// 0 is the initial counter (we have done 0 repetitions so far). `len`
Expand Down Expand Up @@ -274,7 +272,7 @@ pub(super) fn transcribe<'a>(
MatchedSingle(ParseNtResult::Tt(tt)) => {
// `tt`s are emitted into the output stream directly as "raw tokens",
// without wrapping them into groups.
maybe_use_metavar_location(cx, &stack, sp, tt, &mut marker)
maybe_use_metavar_location(psess, &stack, sp, tt, &mut marker)
}
MatchedSingle(ParseNtResult::Ident(ident, is_raw)) => {
marker.visit_span(&mut sp);
Expand All @@ -295,7 +293,7 @@ pub(super) fn transcribe<'a>(
}
MatchedSeq(..) => {
// We were unable to descend far enough. This is an error.
return Err(cx.dcx().create_err(VarStillRepeating { span: sp, ident }));
return Err(dcx.create_err(VarStillRepeating { span: sp, ident }));
}
};
result.push(tt)
Expand All @@ -314,7 +312,7 @@ pub(super) fn transcribe<'a>(

// Replace meta-variable expressions with the result of their expansion.
mbe::TokenTree::MetaVarExpr(sp, expr) => {
transcribe_metavar_expr(cx, expr, interp, &mut marker, &repeats, &mut result, sp)?;
transcribe_metavar_expr(dcx, expr, interp, &mut marker, &repeats, &mut result, sp)?;
}

// If we are entering a new delimiter, we push its contents to the `stack` to be
Expand Down Expand Up @@ -374,7 +372,7 @@ pub(super) fn transcribe<'a>(
/// combine with each other and not with tokens outside of the sequence.
/// - The metavariable span comes from a different crate, then we prefer the more local span.
fn maybe_use_metavar_location(
cx: &ExtCtxt<'_>,
psess: &ParseSess,
stack: &[Frame<'_>],
mut metavar_span: Span,
orig_tt: &TokenTree,
Expand Down Expand Up @@ -412,7 +410,7 @@ fn maybe_use_metavar_location(
&& insert(mspans, dspan.entire(), metavar_span)
}),
};
if no_collision || cx.source_map().is_imported(metavar_span) {
if no_collision || psess.source_map().is_imported(metavar_span) {
return orig_tt.clone();
}

Expand Down Expand Up @@ -573,7 +571,7 @@ fn lockstep_iter_size(
/// * `[ $( ${count(foo, 1)} ),* ]` will return an error because `${count(foo, 1)}` is
/// declared inside a single repetition and the index `1` implies two nested repetitions.
fn count_repetitions<'a>(
cx: &ExtCtxt<'a>,
dcx: &'a DiagCtxt,
depth_user: usize,
mut matched: &NamedMatch,
repeats: &[(usize, usize)],
Expand Down Expand Up @@ -610,7 +608,7 @@ fn count_repetitions<'a>(
.and_then(|el| el.checked_sub(repeats.len()))
.unwrap_or_default();
if depth_user > depth_max {
return Err(out_of_bounds_err(cx, depth_max + 1, sp.entire(), "count"));
return Err(out_of_bounds_err(dcx, depth_max + 1, sp.entire(), "count"));
}

// `repeats` records all of the nested levels at which we are currently
Expand All @@ -626,15 +624,15 @@ fn count_repetitions<'a>(
}

if let MatchedSingle(_) = matched {
return Err(cx.dcx().create_err(CountRepetitionMisplaced { span: sp.entire() }));
return Err(dcx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
}

count(depth_user, depth_max, matched)
}

/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]
fn matched_from_ident<'ctx, 'interp, 'rslt>(
cx: &ExtCtxt<'ctx>,
dcx: &'ctx DiagCtxt,
ident: Ident,
interp: &'interp FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
) -> PResult<'ctx, &'rslt NamedMatch>
Expand All @@ -643,12 +641,12 @@ where
{
let span = ident.span;
let key = MacroRulesNormalizedIdent::new(ident);
interp.get(&key).ok_or_else(|| cx.dcx().create_err(MetaVarExprUnrecognizedVar { span, key }))
interp.get(&key).ok_or_else(|| dcx.create_err(MetaVarExprUnrecognizedVar { span, key }))
}

/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
/// example, index(999999) in an repetition of only three elements.
fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) -> Diag<'a> {
fn out_of_bounds_err<'a>(dcx: &'a DiagCtxt, max: usize, span: Span, ty: &str) -> Diag<'a> {
let msg = if max == 0 {
format!(
"meta-variable expression `{ty}` with depth parameter \
Expand All @@ -660,11 +658,11 @@ fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) ->
must be less than {max}"
)
};
cx.dcx().struct_span_err(span, msg)
dcx.struct_span_err(span, msg)
}

fn transcribe_metavar_expr<'a>(
cx: &ExtCtxt<'a>,
dcx: &'a DiagCtxt,
expr: &MetaVarExpr,
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
marker: &mut Marker,
Expand All @@ -679,8 +677,8 @@ fn transcribe_metavar_expr<'a>(
};
match *expr {
MetaVarExpr::Count(original_ident, depth) => {
let matched = matched_from_ident(cx, original_ident, interp)?;
let count = count_repetitions(cx, depth, matched, repeats, sp)?;
let matched = matched_from_ident(dcx, original_ident, interp)?;
let count = count_repetitions(dcx, depth, matched, repeats, sp)?;
let tt = TokenTree::token_alone(
TokenKind::lit(token::Integer, sym::integer(count), None),
visited_span(),
Expand All @@ -689,7 +687,7 @@ fn transcribe_metavar_expr<'a>(
}
MetaVarExpr::Ignore(original_ident) => {
// Used to ensure that `original_ident` is present in the LHS
let _ = matched_from_ident(cx, original_ident, interp)?;
let _ = matched_from_ident(dcx, original_ident, interp)?;
}
MetaVarExpr::Index(depth) => match repeats.iter().nth_back(depth) {
Some((index, _)) => {
Expand All @@ -698,7 +696,7 @@ fn transcribe_metavar_expr<'a>(
visited_span(),
));
}
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "index")),
None => return Err(out_of_bounds_err(dcx, repeats.len(), sp.entire(), "index")),
},
MetaVarExpr::Len(depth) => match repeats.iter().nth_back(depth) {
Some((_, length)) => {
Expand All @@ -707,7 +705,7 @@ fn transcribe_metavar_expr<'a>(
visited_span(),
));
}
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "len")),
None => return Err(out_of_bounds_err(dcx, repeats.len(), sp.entire(), "len")),
},
}
Ok(())
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,11 +1871,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// If this is due to a block, then maybe we forgot a `return`/`break`.
if due_to_block
&& let Some(expr) = expression
&& let Some((parent_fn_decl, parent_id)) = fcx
.tcx
.hir()
.parent_iter(block_or_return_id)
.find_map(|(_, node)| Some((node.fn_decl()?, node.associated_body()?.0)))
&& let Some(parent_fn_decl) =
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
{
fcx.suggest_missing_break_or_return_expr(
&mut err,
Expand All @@ -1884,7 +1881,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected,
found,
block_or_return_id,
parent_id,
fcx.body_id,
);
}

Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ambiguous.
if let Some(bad_ty) = &steps.opt_bad_ty {
if is_suggestion.0 {
// Ambiguity was encountered during a suggestion. Just keep going.
debug!("ProbeContext: encountered ambiguity in suggestion");
// Ambiguity was encountered during a suggestion. There's really
// not much use in suggesting methods in this case.
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: Vec::new(),
unsatisfied_predicates: Vec::new(),
out_of_scope_traits: Vec::new(),
similar_candidate: None,
mode,
}));
} else if bad_ty.reached_raw_pointer
&& !self.tcx.features().arbitrary_self_types
&& !self.tcx.sess.at_least_rust_2018()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
_ => return,
};
if let Some(variant_target_idx) = variant_target {
for (field_index, operand) in operands.iter().enumerate() {
for (field_index, operand) in operands.iter_enumerated() {
if let Some(field) = self.map().apply(
variant_target_idx,
TrackElem::Field(FieldIdx::from_usize(field_index)),
TrackElem::Field(field_index),
) {
self.assign_operand(state, field, operand);
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt};
use rustc_span::sym;
use rustc_span::symbol::Symbol;
use rustc_target::abi::FieldIdx;
use rustc_target::spec::abi::Abi;

pub struct InstSimplify;
Expand Down Expand Up @@ -217,11 +216,11 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
&& let Some(place) = operand.place()
{
let variant = adt_def.non_enum_variant();
for (i, field) in variant.fields.iter().enumerate() {
for (i, field) in variant.fields.iter_enumerated() {
let field_ty = field.ty(self.tcx, args);
if field_ty == *cast_ty {
let place = place.project_deeper(
&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)],
&[ProjectionElem::Field(i, *cast_ty)],
self.tcx,
);
let operand = if operand.is_move() {
Expand Down
3 changes: 0 additions & 3 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,6 @@
# on linux
#src-tarball = true

# Whether to allow failures when building tools
#missing-tools = false

# List of compression formats to use when generating dist tarballs. The list of
# formats is provided to rust-installer, which must support all of them.
#
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,7 @@ macro_rules! int_impl {
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down Expand Up @@ -1381,8 +1380,7 @@ macro_rules! int_impl {
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,8 +1369,7 @@ macro_rules! uint_impl {
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down Expand Up @@ -1468,8 +1467,7 @@ macro_rules! uint_impl {
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down
Loading

0 comments on commit a62ffec

Please sign in to comment.