Skip to content

Commit

Permalink
Auto merge of rust-lang#125611 - GuillaumeGomez:rollup-dfavpgg, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#124870 (Update Result docs to the new guarantees)
 - rust-lang#125148 (codegen: tweak/extend shift comments)
 - rust-lang#125522 (Add "better" edition handling on lint-docs tool)
 - 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#125597 (Uplift `EarlyBinder` into `rustc_type_ir`)
 - rust-lang#125607 (Migrate `run-make/compile-stdin` to `rmake.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 27, 2024
2 parents a59072e + 7083131 commit f6e4703
Show file tree
Hide file tree
Showing 57 changed files with 885 additions and 762 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4686,6 +4686,7 @@ dependencies = [
"rustc_span",
"rustc_type_ir_macros",
"smallvec",
"tracing",
]

[[package]]
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}
}

/// Returns `rhs` sufficiently masked, truncated, and/or extended so that
/// it can be used to shift `lhs`.
/// Returns `rhs` sufficiently masked, truncated, and/or extended so that it can be used to shift
/// `lhs`: it has the same size as `lhs`, and the value, when interpreted unsigned (no matter its
/// type), will not exceed the size of `lhs`.
///
/// Shifts in MIR are all allowed to have mismatched LHS & RHS types.
/// Shifts in MIR are all allowed to have mismatched LHS & RHS types, and signed RHS.
/// The shift methods in `BuilderMethods`, however, are fully homogeneous
/// (both parameters and the return type are all the same type).
/// (both parameters and the return type are all the same size) and assume an unsigned RHS.
///
/// If `is_unchecked` is false, this masks the RHS to ensure it stays in-bounds,
/// as the `BuilderMethods` shifts are UB for out-of-bounds shift amounts.
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_ssa/src/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ pub trait BuilderMethods<'a, 'tcx>:
fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
fn frem_algebraic(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
/// Generate a left-shift. Both operands must have the same size. The right operand must be
/// interpreted as unsigned and can be assumed to be less than the size of the left operand.
fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
/// Generate a logical right-shift. Both operands must have the same size. The right operand
/// must be interpreted as unsigned and can be assumed to be less than the size of the left
/// operand.
fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
/// Generate an arithmetic right-shift. Both operands must have the same size. The right operand
/// must be interpreted as unsigned and can be assumed to be less than the size of the left
/// operand.
fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m_def_id: LocalDefId,
) -> Result<&'tcx DefIdMap<ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed> {
) -> Result<&'tcx DefIdMap<ty::EarlyBinder<'tcx, Ty<'tcx>>>, ErrorGuaranteed> {
let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap();
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
let impl_trait_ref =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
}

#[instrument(level = "debug", skip(tcx))]
fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>> {
fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFnSig<'_>> {
use rustc_hir::Node::*;
use rustc_hir::*;

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ fn opaque_type_bounds<'tcx>(
pub(super) fn explicit_item_bounds(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> {
) -> ty::EarlyBinder<'_, &'_ [(ty::Clause<'_>, Span)]> {
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::All)
}

pub(super) fn explicit_item_super_predicates(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> {
) -> ty::EarlyBinder<'_, &'_ [(ty::Clause<'_>, Span)]> {
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::SelfOnly)
}

pub(super) fn explicit_item_bounds_with_filter(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
filter: PredicateFilter,
) -> ty::EarlyBinder<&'_ [(ty::Clause<'_>, Span)]> {
) -> ty::EarlyBinder<'_, &'_ [(ty::Clause<'_>, Span)]> {
match tcx.opt_rpitit_info(def_id.to_def_id()) {
// RPITIT's bounds are the same as opaque type bounds, but with
// a projection self type.
Expand Down Expand Up @@ -166,7 +166,7 @@ pub(super) fn explicit_item_bounds_with_filter(
ty::EarlyBinder::bind(bounds)
}

pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::Clauses<'_>> {
pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
tcx.explicit_item_bounds(def_id).map_bound(|bounds| {
tcx.mk_clauses_from_iter(util::elaborate(tcx, bounds.iter().map(|&(bound, _span)| bound)))
})
Expand All @@ -175,7 +175,7 @@ pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty:
pub(super) fn item_super_predicates(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> ty::EarlyBinder<ty::Clauses<'_>> {
) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
tcx.explicit_item_super_predicates(def_id).map_bound(|bounds| {
tcx.mk_clauses_from_iter(
util::elaborate(tcx, bounds.iter().map(|&(bound, _span)| bound)).filter_only_self(),
Expand All @@ -186,7 +186,7 @@ pub(super) fn item_super_predicates(
pub(super) fn item_non_self_assumptions(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> ty::EarlyBinder<ty::Clauses<'_>> {
) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect();
let own_bounds: FxIndexSet<_> =
tcx.item_super_predicates(def_id).skip_binder().iter().collect();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn get_path_containing_arg_in_pat<'hir>(
arg_path
}

pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty<'_>> {
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, Ty<'_>> {
use rustc_hir::*;
use rustc_middle::ty::Ty;

Expand Down Expand Up @@ -512,7 +512,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
pub(super) fn type_of_opaque(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> Result<ty::EarlyBinder<Ty<'_>>, CyclePlaceholder> {
) -> Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
if let Some(def_id) = def_id.as_local() {
use rustc_hir::*;

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/outlives/explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::utils::*;

#[derive(Debug)]
pub struct ExplicitPredicatesMap<'tcx> {
map: FxIndexMap<DefId, ty::EarlyBinder<RequiredPredicates<'tcx>>>,
map: FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>>>,
}

impl<'tcx> ExplicitPredicatesMap<'tcx> {
Expand All @@ -18,7 +18,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
&mut self,
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> &ty::EarlyBinder<RequiredPredicates<'tcx>> {
) -> &ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>> {
self.map.entry(def_id).or_insert_with(|| {
let predicates = if def_id.is_local() {
tcx.explicit_predicates_of(def_id)
Expand Down
Loading

0 comments on commit f6e4703

Please sign in to comment.