Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ impl<S: Stage> AttributeParser<S> for ConfusablesParser {
return None;
}

Some(AttributeKind::RustcConfusables {
symbols: self.confusables,
first_span: self.first_span.unwrap(),
})
Some(AttributeKind::RustcConfusables { confusables: self.confusables })
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'tcx> CValue<'tcx> {

/// Create an instance of a ZST
///
/// The is represented by a dangling pointer of suitable alignment.
/// The ZST is represented by a dangling pointer of suitable alignment.
pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
assert!(layout.is_zst());
CValue::by_ref(crate::Pointer::dangling(layout.align.abi), layout)
Expand Down
26 changes: 10 additions & 16 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,10 @@ pub trait GlobDelegationExpander {
fn expand(&self, ecx: &mut ExtCtxt<'_>) -> ExpandResult<Vec<(Ident, Option<Ident>)>, ()>;
}

// Use a macro because forwarding to a simple function has type system issues
macro_rules! make_stmts_default {
($me:expr) => {
$me.make_expr().map(|e| {
smallvec![ast::Stmt {
id: ast::DUMMY_NODE_ID,
span: e.span,
kind: ast::StmtKind::Expr(e),
}]
})
};
fn make_stmts_default(expr: Option<Box<ast::Expr>>) -> Option<SmallVec<[ast::Stmt; 1]>> {
expr.map(|e| {
smallvec![ast::Stmt { id: ast::DUMMY_NODE_ID, span: e.span, kind: ast::StmtKind::Expr(e) }]
})
}

/// The result of a macro expansion. The return values of the various
Expand Down Expand Up @@ -465,7 +458,7 @@ pub trait MacResult {
/// By default this attempts to create an expression statement,
/// returning None if that fails.
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
make_stmts_default!(self)
make_stmts_default(self.make_expr())
}

fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> {
Expand Down Expand Up @@ -571,9 +564,10 @@ impl MacResult for MacEager {
}

fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
match self.stmts.as_ref().map_or(0, |s| s.len()) {
0 => make_stmts_default!(self),
_ => self.stmts,
if self.stmts.as_ref().is_none_or(|s| s.is_empty()) {
make_stmts_default(self.make_expr())
} else {
self.stmts
}
}

Expand Down Expand Up @@ -898,7 +892,7 @@ impl SyntaxExtension {
fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) -> bool {
let flag = sess.opts.cg.collapse_macro_debuginfo;
let attr = if let Some(info) = find_attr!(attrs, CollapseDebugInfo(info) => info) {
info.clone()
*info
} else if find_attr!(attrs, RustcBuiltinMacro { .. }) {
CollapseMacroDebuginfo::Yes
} else {
Expand Down
35 changes: 13 additions & 22 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,24 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -

// If the enabled feature is unstable, record it.
if UNSTABLE_LANG_FEATURES.iter().find(|f| feature_ident.name == f.name).is_some() {
// When the ICE comes from a standard library crate, there's a chance that the person
// hitting the ICE may be using -Zbuild-std or similar with an untested target.
// The bug is probably in the standard library and not the compiler in that case,
// but that doesn't really matter - we want a bug report.
if features.internal(feature_ident.name)
&& !STDLIB_STABLE_CRATES.contains(&crate_name)
{
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
}

features.set_enabled_lang_feature(EnabledLangFeature {
gate_name: feature_ident.name,
attr_sp: feature_ident.span,
stable_since: None,
});
continue;
} else {
// Otherwise, the feature is unknown. Enable it as a lib feature.
// It will be checked later whether the feature really exists.
features.set_enabled_lib_feature(EnabledLibFeature {
gate_name: feature_ident.name,
attr_sp: feature_ident.span,
});
}

// Otherwise, the feature is unknown. Enable it as a lib feature.
// It will be checked later whether the feature really exists.
features.set_enabled_lib_feature(EnabledLibFeature {
gate_name: feature_ident.name,
attr_sp: feature_ident.span,
});

// Similar to above, detect internal lib features to suppress
// the ICE message that asks for a report.
// When the ICE comes from a standard library crate, there's a chance that the person
// hitting the ICE may be using -Zbuild-std or similar with an untested target.
// The bug is probably in the standard library and not the compiler in that case,
// but that doesn't really matter - we want a bug report.
if features.internal(feature_ident.name) && !STDLIB_STABLE_CRATES.contains(&crate_name)
{
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
Expand Down Expand Up @@ -285,7 +276,7 @@ impl<'a> StripUnconfigured<'a> {

let Some((cfg_predicate, expanded_attrs)) = rustc_attr_parsing::parse_cfg_attr(
cfg_attr,
&self.sess,
self.sess,
self.features,
self.lint_node_id,
) else {
Expand Down Expand Up @@ -422,7 +413,7 @@ impl<'a> StripUnconfigured<'a> {
&& !attr.span.allows_unstable(sym::stmt_expr_attributes)
{
let mut err = feature_err(
&self.sess,
self.sess,
sym::stmt_expr_attributes,
attr.span,
msg!("attributes on expressions are experimental"),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
return;
}
feature_err(
&self.cx.sess,
self.cx.sess,
sym::proc_macro_hygiene,
span,
format!("custom attributes cannot be applied to {kind}"),
Expand Down Expand Up @@ -1085,7 +1085,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}

if !self.cx.ecfg.features.proc_macro_hygiene() {
annotatable.visit_with(&mut GateProcMacroInput { sess: &self.cx.sess });
annotatable.visit_with(&mut GateProcMacroInput { sess: self.cx.sess });
}
}

Expand Down Expand Up @@ -1474,15 +1474,15 @@ impl InvocationCollectorNode for Box<ast::Item> {
}
}
let mut idents = Vec::new();
collect_use_tree_leaves(&ut, &mut idents);
collect_use_tree_leaves(ut, &mut idents);
idents
} else {
self.kind.ident().into_iter().collect()
}
}

fn as_target(&self) -> Target {
Target::from_ast_item(&*self)
Target::from_ast_item(self)
}
}

Expand Down
49 changes: 22 additions & 27 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,52 +288,47 @@ pub(super) fn emit_frag_parse_err(
_ => annotate_err_with_kind(&mut e, kind, site_span),
};

let mut bindings_rules = vec![];
for rule in bindings {
let MacroRule::Func { lhs, .. } = rule else { continue };
for param in lhs {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
bindings_rules.push(*bind);
}
}

let mut matched_rule_bindings_rules = vec![];
for param in matched_rule_bindings {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
matched_rule_bindings_rules.push(*bind);
}

let matched_rule_bindings_names: Vec<_> =
matched_rule_bindings_rules.iter().map(|bind| bind.name).collect();
let bindings_name: Vec<_> = bindings_rules.iter().map(|bind| bind.name).collect();
if parser.token.kind == token::Dollar {
parser.bump();
if let token::Ident(name, _) = parser.token.kind {
let mut bindings_names = vec![];
for rule in bindings {
let MacroRule::Func { lhs, .. } = rule else { continue };
for param in lhs {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
bindings_names.push(bind.name);
}
}

let mut matched_rule_bindings_names = vec![];
for param in matched_rule_bindings {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
matched_rule_bindings_names.push(bind.name);
}

if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
&matched_rule_bindings_names[..],
name,
None,
) {
e.span_suggestion_verbose(
parser.token.span,
"there is a macro metavariable with similar name",
format!("{matched_name}"),
"there is a macro metavariable with a similar name",
matched_name,
Applicability::MaybeIncorrect,
);
} else if bindings_name.contains(&name) {
} else if bindings_names.contains(&name) {
e.span_label(
parser.token.span,
format!(
"there is an macro metavariable with this name in another macro matcher"
),
"there is an macro metavariable with this name in another macro matcher",
);
} else if let Some(matched_name) =
rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
rustc_span::edit_distance::find_best_match_for_name(&bindings_names[..], name, None)
{
e.span_suggestion_verbose(
parser.token.span,
"there is a macro metavariable with a similar name in another macro matcher",
format!("{matched_name}"),
matched_name,
Applicability::MaybeIncorrect,
);
} else {
Expand All @@ -343,7 +338,7 @@ pub(super) fn emit_frag_parse_err(
.collect::<Vec<_>>()
.join(", ");

e.span_label(parser.token.span, format!("macro metavariable not found"));
e.span_label(parser.token.span, "macro metavariable not found");
if !matched_rule_bindings_names.is_empty() {
e.note(format!("available metavariable names are: {msg}"));
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
let idx_seq = idx_first - 1;
inner(&seq.tts, locs, next_metavar, seq_depth + 1);

if let Some(separator) = &seq.separator {
locs.push(MatcherLoc::SequenceSep { separator: separator.clone() });
if let Some(separator) = seq.separator {
locs.push(MatcherLoc::SequenceSep { separator });
locs.push(MatcherLoc::SequenceKleeneOpAfterSep { idx_first });
} else {
locs.push(MatcherLoc::SequenceKleeneOpNoSep { op, idx_first });
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn parse_tree<'a>(
// during parsing.
let mut next = outer_iter.next();
let mut iter_storage;
let mut iter: &mut TokenStreamIter<'_> = match next {
let iter: &mut TokenStreamIter<'_> = match next {
Some(tokenstream::TokenTree::Delimited(.., delim, tts)) if delim.skip() => {
iter_storage = tts.iter();
next = iter_storage.next();
Expand Down Expand Up @@ -284,7 +284,7 @@ fn parse_tree<'a>(
let sequence = parse(tts, part, sess, node_id, features, edition);
// Get the Kleene operator and optional separator
let (separator, kleene) =
parse_sep_and_kleene_op(&mut iter, delim_span.entire(), sess);
parse_sep_and_kleene_op(iter, delim_span.entire(), sess);
// Count the number of captured "names" (i.e., named metavars)
let num_captures =
if part.is_pattern() { count_metavar_decls(&sequence) } else { 0 };
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn transcribe_sequence<'tx, 'itp>(
// The first time we encounter the sequence we push it to the stack. It
// then gets reused (see the beginning of the loop) until we are done
// repeating.
tscx.stack.push(Frame::new_sequence(seq_rep, seq.separator.clone(), seq.kleene.op));
tscx.stack.push(Frame::new_sequence(seq_rep, seq.separator, seq.kleene.op));
}
}
}
Expand Down Expand Up @@ -629,7 +629,7 @@ fn metavar_expr_concat<'tx>(
) -> PResult<'tx, TokenTree> {
let dcx = tscx.psess.dcx();
let mut concatenated = String::new();
for element in elements.into_iter() {
for element in elements {
let symbol = match element {
MetaVarExprConcatElem::Ident(elem) => elem.name,
MetaVarExprConcatElem::Literal(elem) => *elem,
Expand Down Expand Up @@ -747,7 +747,7 @@ fn maybe_use_metavar_location(
TokenTree::Token(Token { kind, span }, spacing) => {
let span = metavar_span.with_ctxt(span.ctxt());
with_metavar_spans(|mspans| mspans.insert(span, metavar_span));
TokenTree::Token(Token { kind: kind.clone(), span }, *spacing)
TokenTree::Token(Token { kind: *kind, span }, *spacing)
}
TokenTree::Delimited(dspan, dspacing, delimiter, tts) => {
let open = metavar_span.with_ctxt(dspan.open.ctxt());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(crate) fn parse_external_mod(
Some(span),
));
let (inner_attrs, items, inner_span) =
parser.parse_mod(exp!(Eof)).map_err(|err| ModError::ParserError(err))?;
parser.parse_mod(exp!(Eof)).map_err(ModError::ParserError)?;
attrs.extend(inner_attrs);
(items, inner_span, mp.file_path)
};
Expand Down
Loading
Loading