Skip to content
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

Rollup of 12 pull requests #126016

Merged
merged 41 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a5a60d7
Add `size_of`, `size_of_val`, `align_of`, and `align_of_val` to the p…
joshtriplett Mar 28, 2024
b4834a1
rewrite resolve-rename in rmake
Oneirical May 28, 2024
d553d5b
rewrite incr-prev-body-beyond-eof in rmake
Oneirical May 28, 2024
8530285
rustc_span: Inline some hot functions
petrochenkov Jun 2, 2024
07dc3eb
Allow static mut definitions with #[linkage]
bjorn3 Jun 3, 2024
8f08625
Remove a bunch of redundant args from report_method_error
compiler-errors Jun 3, 2024
e9957b9
Stop passing empty args to check_expr_path
compiler-errors Jun 3, 2024
8f677e8
bootstrap: implement new feature `bootstrap-self-test`
onur-ozkan May 19, 2024
2bad3d1
Make deleting on LinkedList aware of the allocator
xTachyon Jun 4, 2024
59e2074
rewrite suspicious-library in rmake
Oneirical May 28, 2024
5d26f58
Closures are recursively reachable
tmiasko Jun 4, 2024
ac96fa4
Use inline const instead of unsafe to construct arrays in `MaybeUnini…
kpreid May 13, 2024
ec8fa17
Use inline const instead of unsafe to implement `MaybeUninit::uninit_…
kpreid May 13, 2024
2a21937
Add a co-maintainer for the two ARMv4T targets
Lokathor Jun 4, 2024
e1ae0fa
`UNICODE_ARRAY` and `ASCII_ARRAY` fixes.
nnethercote May 29, 2024
d1215da
Don't use the word "parse" for lexing operations.
nnethercote May 30, 2024
f657624
Inline and remove `error_malformed_cfg_attr_missing`.
nnethercote May 31, 2024
769ca3f
Rename `maybe_file_to_stream` as `maybe_source_file_to_stream`.
nnethercote May 31, 2024
3c321b9
Remove `stream_to_parser`.
nnethercote May 31, 2024
af13b48
Improve `panictry_buffer!`.
nnethercote May 31, 2024
29e6e28
Remove low-value comments.
nnethercote May 31, 2024
191b76e
Rename `maybe_source_file_to_parser` as `maybe_new_parser_from_source…
nnethercote May 31, 2024
8964106
Use `source_str_to_stream` in a test file.
nnethercote May 31, 2024
25972ae
Inline and remove `parse_crate{,_attrs}_from_{file,source_str}`.
nnethercote May 31, 2024
ab192a0
Reorder `source_str_to_stream` arguments.
nnethercote May 31, 2024
264dbe4
Inline and remove `source_file_to_stream`.
nnethercote May 31, 2024
b903733
Make top-level `rustc_parse` functions fallible.
nnethercote May 31, 2024
2d4e7df
rustfmt: Remove an unnecessary `catch_unwind` use.
nnethercote Jun 3, 2024
dd6bca5
Add another test for hidden types capturing lifetimes that outlive bu…
compiler-errors Jun 5, 2024
9ccc7b7
Rollup merge of #123168 - joshtriplett:size-of-prelude, r=Amanieu
workingjubilee Jun 5, 2024
0f86182
Rollup merge of #125273 - onur-ozkan:bootstrap-self-test, r=albertlar…
workingjubilee Jun 5, 2024
0f2b34a
Rollup merge of #125683 - Oneirical:patience-testing-test, r=jieyouxu
workingjubilee Jun 5, 2024
05b4674
Rollup merge of #125815 - nnethercote:rustc_parse-top-level-cleanups,…
workingjubilee Jun 5, 2024
0096138
Rollup merge of #125903 - petrochenkov:upctxt3, r=nnethercote
workingjubilee Jun 5, 2024
78d9a7e
Rollup merge of #125906 - compiler-errors:simplify-method-error-args,…
workingjubilee Jun 5, 2024
2b89c1b
Rollup merge of #125920 - bjorn3:allow_static_mut_linkage_def, r=Urgau
workingjubilee Jun 5, 2024
448159c
Rollup merge of #125982 - xTachyon:fix-linked-list, r=jhpratt
workingjubilee Jun 5, 2024
6b6b698
Rollup merge of #125995 - kpreid:const-uninit-stable, r=Nilstrieb
workingjubilee Jun 5, 2024
eb2819e
Rollup merge of #125996 - tmiasko:closure-recursively-reachable, r=ol…
workingjubilee Jun 5, 2024
669935e
Rollup merge of #126003 - Lokathor:new-co-maintainer, r=compiler-errors
workingjubilee Jun 5, 2024
f12fe3a
Rollup merge of #126004 - compiler-errors:captures-soundness-test, r=…
workingjubilee Jun 5, 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
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl CfgEval<'_, '_> {
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
// to the captured `AttrTokenStream` (specifically, we capture
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
let mut parser = rustc_parse::stream_to_parser(&self.cfg.sess.psess, orig_tokens, None);
let mut parser = Parser::new(&self.cfg.sess.psess, orig_tokens, None);
parser.capture_cfg = true;
match parse_annotatable_with(&mut parser) {
Ok(a) => annotatable = a,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_builtin_macros/src/cmdline_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use crate::errors;
use rustc_ast::attr::mk_attr;
use rustc_ast::token;
use rustc_ast::{self as ast, AttrItem, AttrStyle};
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_session::parse::ParseSess;
use rustc_span::FileName;

pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
for raw_attr in attrs {
let mut parser = rustc_parse::new_parser_from_source_str(
let mut parser = unwrap_or_emit_fatal(new_parser_from_source_str(
psess,
FileName::cli_crate_attr_source_code(raw_attr),
raw_attr.clone(),
);
));

let start_span = parser.token.span;
let AttrItem { path, args, tokens: _ } = match parser.parse_attr_item(false) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_expand::base::{
};
use rustc_expand::module::DirOwnership;
use rustc_lint_defs::BuiltinLintDiag;
use rustc_parse::new_parser_from_file;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -126,7 +126,7 @@ pub(crate) fn expand_include<'cx>(
return ExpandResult::Ready(DummyResult::any(sp, guar));
}
};
let p = new_parser_from_file(cx.psess(), &file, Some(sp));
let p = unwrap_or_emit_fatal(new_parser_from_file(cx.psess(), &file, Some(sp)));

// If in the included file we have e.g., `mod bar;`,
// then the path of `bar.rs` should be relative to the directory of `file`.
Expand Down
25 changes: 13 additions & 12 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,22 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
let linkage = Some(linkage_by_name(tcx, did, val.as_str()));
if tcx.is_foreign_item(did) {
codegen_fn_attrs.import_linkage = linkage;

if tcx.is_mutable_static(did.into()) {
let mut diag = tcx.dcx().struct_span_err(
attr.span,
"extern mutable statics are not allowed with `#[linkage]`",
);
diag.note(
"marking the extern static mutable would allow changing which symbol \
the static references rather than make the target of the symbol \
mutable",
);
diag.emit();
}
} 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
10 changes: 6 additions & 4 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use rustc_interface::{interface, Queries};
use rustc_lint::unerased_lint_store;
use rustc_metadata::creader::MetadataLoader;
use rustc_metadata::locator;
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
use rustc_session::getopts::{self, Matches};
Expand Down Expand Up @@ -1264,12 +1265,13 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
}

fn parse_crate_attrs<'a>(sess: &'a Session) -> PResult<'a, ast::AttrVec> {
match &sess.io.input {
Input::File(ifile) => rustc_parse::parse_crate_attrs_from_file(ifile, &sess.psess),
let mut parser = unwrap_or_emit_fatal(match &sess.io.input {
Input::File(file) => new_parser_from_file(&sess.psess, file, None),
Input::Str { name, input } => {
rustc_parse::parse_crate_attrs_from_source_str(name.clone(), input.clone(), &sess.psess)
new_parser_from_source_str(&sess.psess, name.clone(), input.clone())
}
}
});
parser.parse_inner_attributes()
}

/// Runs a closure and catches unwinds triggered by fatal errors.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
use rustc_feature::Features;
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
use rustc_parse::{parser, MACRO_ARGUMENTS};
use rustc_parse::{parser::Parser, MACRO_ARGUMENTS};
use rustc_session::config::CollapseMacroDebuginfo;
use rustc_session::{parse::ParseSess, Limit, Session};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
Expand Down Expand Up @@ -1149,8 +1149,8 @@ impl<'a> ExtCtxt<'a> {
pub fn monotonic_expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
expand::MacroExpander::new(self, true)
}
pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
rustc_parse::stream_to_parser(&self.sess.psess, stream, MACRO_ARGUMENTS)
pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a> {
Parser::new(&self.sess.psess, stream, MACRO_ARGUMENTS)
}
pub fn source_map(&self) -> &'a SourceMap {
self.sess.psess.source_map()
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::errors::{
use rustc_ast::ptr::P;
use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans};
use rustc_errors::{Diag, ErrorGuaranteed};
use rustc_parse::new_parser_from_file;
use rustc_parse::validate_attr;
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
use rustc_session::parse::ParseSess;
use rustc_session::Session;
use rustc_span::symbol::{sym, Ident};
Expand Down Expand Up @@ -66,7 +66,8 @@ pub(crate) fn parse_external_mod(
}

// Actually parse the external file as a module.
let mut parser = new_parser_from_file(&sess.psess, &mp.file_path, Some(span));
let mut parser =
unwrap_or_emit_fatal(new_parser_from_file(&sess.psess, &mp.file_path, Some(span)));
let (inner_attrs, items, inner_span) =
parser.parse_mod(&token::Eof).map_err(|err| ModError::ParserError(err))?;
attrs.extend(inner_attrs);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::tokenstream::TokenStream;
use rustc_errors::ErrorGuaranteed;
use rustc_parse::parser::ForceCollect;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_session::config::ProcMacroExecutionStrategy;
use rustc_span::profiling::SpannedEventArgRecorder;
use rustc_span::Span;
Expand Down Expand Up @@ -154,8 +154,7 @@ impl MultiItemModifier for DeriveProcMacro {
};

let error_count_before = ecx.dcx().err_count();
let mut parser =
rustc_parse::stream_to_parser(&ecx.sess.psess, stream, Some("proc-macro derive"));
let mut parser = Parser::new(&ecx.sess.psess, stream, Some("proc-macro derive"));
let mut items = vec![];

loop {
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
use rustc_parse::lexer::nfc_normalize;
use rustc_parse::parse_stream_from_source_str;
use rustc_parse::parser::Parser;
use rustc_parse::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
use rustc_session::parse::ParseSess;
use rustc_span::def_id::CrateNum;
use rustc_span::symbol::{self, sym, Symbol};
Expand Down Expand Up @@ -466,7 +467,8 @@ impl server::FreeFunctions for Rustc<'_, '_> {

fn literal_from_str(&mut self, s: &str) -> Result<Literal<Self::Span, Self::Symbol>, ()> {
let name = FileName::proc_macro_source_code(s);
let mut parser = rustc_parse::new_parser_from_source_str(self.psess(), name, s.to_owned());
let mut parser =
unwrap_or_emit_fatal(new_parser_from_source_str(self.psess(), name, s.to_owned()));

let first_span = parser.token.span.data();
let minus_present = parser.eat(&token::BinOp(token::Minus));
Expand Down Expand Up @@ -538,12 +540,12 @@ impl server::TokenStream for Rustc<'_, '_> {
}

fn from_str(&mut self, src: &str) -> Self::TokenStream {
parse_stream_from_source_str(
unwrap_or_emit_fatal(source_str_to_stream(
self.psess(),
FileName::proc_macro_source_code(src),
src.to_string(),
self.psess(),
Some(self.call_site),
)
))
}

fn to_string(&mut self, stream: &Self::TokenStream) -> String {
Expand All @@ -553,11 +555,7 @@ impl server::TokenStream for Rustc<'_, '_> {
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
// Parse the expression from our tokenstream.
let expr: PResult<'_, _> = try {
let mut p = rustc_parse::stream_to_parser(
self.psess(),
stream.clone(),
Some("proc_macro expand expr"),
);
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
let expr = p.parse_expr()?;
if p.token != token::Eof {
p.unexpected()?;
Expand Down
39 changes: 18 additions & 21 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::errors::{
YieldExprOutsideOfCoroutine,
};
use crate::fatally_break_rust;
use crate::method::SelfSource;
use crate::type_error_struct;
use crate::CoroutineTypes;
use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectation};
Expand Down Expand Up @@ -223,7 +222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = ensure_sufficient_stack(|| match &expr.kind {
hir::ExprKind::Path(
qpath @ (hir::QPath::Resolved(..) | hir::QPath::TypeRelative(..)),
) => self.check_expr_path(qpath, expr, args, call),
) => self.check_expr_path(qpath, expr, Some(args), call),
_ => self.check_expr_kind(expr, expected),
});
let ty = self.resolve_vars_if_possible(ty);
Expand Down Expand Up @@ -290,7 +289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ExprKind::Path(QPath::LangItem(lang_item, _)) => {
self.check_lang_item_path(lang_item, expr)
}
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, &[], None),
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, None, None),
ExprKind::InlineAsm(asm) => {
// We defer some asm checks as we may not have resolved the input and output types yet (they may still be infer vars).
self.deferred_asm_checks.borrow_mut().push((asm, expr.hir_id));
Expand Down Expand Up @@ -502,12 +501,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
qpath: &'tcx hir::QPath<'tcx>,
expr: &'tcx hir::Expr<'tcx>,
args: &'tcx [hir::Expr<'tcx>],
args: Option<&'tcx [hir::Expr<'tcx>]>,
call: Option<&'tcx hir::Expr<'tcx>>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let (res, opt_ty, segs) =
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span, Some(args));
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span);
let ty = match res {
Res::Err => {
self.suggest_assoc_method_call(segs);
Expand Down Expand Up @@ -564,7 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We just want to check sizedness, so instead of introducing
// placeholder lifetimes with probing, we just replace higher lifetimes
// with fresh vars.
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
let span = args.and_then(|args| args.get(i)).map_or(expr.span, |arg| arg.span);
let input = self.instantiate_binder_with_fresh_vars(
span,
infer::BoundRegionConversionTime::FnCall,
Expand Down Expand Up @@ -1331,9 +1330,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let rcvr_t = self.check_expr(rcvr);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
let span = segment.ident.span;

let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) {
let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
{
Ok(method) => {
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
// trigger this codepath causing `structurally_resolve_type` to emit an error.
Expand All @@ -1342,18 +1341,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
Err(error) => {
if segment.ident.name != kw::Empty {
if let Some(err) = self.report_method_error(
span,
Some(rcvr),
rcvr_t,
segment.ident,
expr.hir_id,
SelfSource::MethodCall(rcvr),
error,
Some(args),
expected,
false,
) {
if let Some(err) =
self.report_method_error(expr.hir_id, rcvr_t, error, expected, false)
{
err.emit();
}
}
Expand All @@ -1362,7 +1352,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// Call the generic checker.
self.check_method_argument_types(span, expr, method, args, DontTupleArguments, expected)
self.check_method_argument_types(
segment.ident.span,
expr,
method,
args,
DontTupleArguments,
expected,
)
}

fn check_expr_cast(
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::callee::{self, DeferredCallResolution};
use crate::errors::{self, CtorIsPrivate};
use crate::method::{self, MethodCallee, SelfSource};
use crate::method::{self, MethodCallee};
use crate::rvalue_scopes;
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -735,7 +735,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath: &'tcx QPath<'tcx>,
hir_id: HirId,
span: Span,
args: Option<&'tcx [hir::Expr<'tcx>]>,
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
debug!(
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
Expand Down Expand Up @@ -828,14 +827,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if item_name.name != kw::Empty {
if let Some(e) = self.report_method_error(
span,
None,
ty.normalized,
item_name,
hir_id,
SelfSource::QPath(qself),
ty.normalized,
error,
args,
Expectation::NoExpectation,
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
) {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod prelude_edition_lints;
pub mod probe;
mod suggest;

pub use self::suggest::SelfSource;
pub use self::MethodError::*;

use crate::FnCtxt;
Expand Down
Loading
Loading