Skip to content

Commit db8aca4

Browse files
committed
Auto merge of #126016 - workingjubilee:rollup-nh6ehbz, r=workingjubilee
Rollup of 12 pull requests Successful merges: - #123168 (Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude) - #125273 (bootstrap: implement new feature `bootstrap-self-test`) - #125683 (Rewrite `suspicious-library`, `resolve-rename` and `incr-prev-body-beyond-eof` `run-make` tests in `rmake.rs` format) - #125815 (`rustc_parse` top-level cleanups) - #125903 (rustc_span: Inline some hot functions) - #125906 (Remove a bunch of redundant args from `report_method_error`) - #125920 (Allow static mut definitions with #[linkage]) - #125982 (Make deleting on LinkedList aware of the allocator) - #125995 (Use inline const blocks to create arrays of `MaybeUninit`.) - #125996 (Closures are recursively reachable) - #126003 (Add a co-maintainer for the two ARMv4T targets) - #126004 (Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5ee2dfd + f12fe3a commit db8aca4

File tree

79 files changed

+557
-453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+557
-453
lines changed

compiler/rustc_builtin_macros/src/cfg_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl CfgEval<'_, '_> {
196196
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
197197
// to the captured `AttrTokenStream` (specifically, we capture
198198
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
199-
let mut parser = rustc_parse::stream_to_parser(&self.cfg.sess.psess, orig_tokens, None);
199+
let mut parser = Parser::new(&self.cfg.sess.psess, orig_tokens, None);
200200
parser.capture_cfg = true;
201201
match parse_annotatable_with(&mut parser) {
202202
Ok(a) => annotatable = a,

compiler/rustc_builtin_macros/src/cmdline_attrs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ use crate::errors;
44
use rustc_ast::attr::mk_attr;
55
use rustc_ast::token;
66
use rustc_ast::{self as ast, AttrItem, AttrStyle};
7+
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
78
use rustc_session::parse::ParseSess;
89
use rustc_span::FileName;
910

1011
pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
1112
for raw_attr in attrs {
12-
let mut parser = rustc_parse::new_parser_from_source_str(
13+
let mut parser = unwrap_or_emit_fatal(new_parser_from_source_str(
1314
psess,
1415
FileName::cli_crate_attr_source_code(raw_attr),
1516
raw_attr.clone(),
16-
);
17+
));
1718

1819
let start_span = parser.token.span;
1920
let AttrItem { path, args, tokens: _ } = match parser.parse_attr_item(false) {

compiler/rustc_builtin_macros/src/source_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_expand::base::{
1212
};
1313
use rustc_expand::module::DirOwnership;
1414
use rustc_lint_defs::BuiltinLintDiag;
15-
use rustc_parse::new_parser_from_file;
1615
use rustc_parse::parser::{ForceCollect, Parser};
16+
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
1717
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
1818
use rustc_span::source_map::SourceMap;
1919
use rustc_span::symbol::Symbol;
@@ -126,7 +126,7 @@ pub(crate) fn expand_include<'cx>(
126126
return ExpandResult::Ready(DummyResult::any(sp, guar));
127127
}
128128
};
129-
let p = new_parser_from_file(cx.psess(), &file, Some(sp));
129+
let p = unwrap_or_emit_fatal(new_parser_from_file(cx.psess(), &file, Some(sp)));
130130

131131
// If in the included file we have e.g., `mod bar;`,
132132
// then the path of `bar.rs` should be relative to the directory of `file`.

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,22 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
324324
let linkage = Some(linkage_by_name(tcx, did, val.as_str()));
325325
if tcx.is_foreign_item(did) {
326326
codegen_fn_attrs.import_linkage = linkage;
327+
328+
if tcx.is_mutable_static(did.into()) {
329+
let mut diag = tcx.dcx().struct_span_err(
330+
attr.span,
331+
"extern mutable statics are not allowed with `#[linkage]`",
332+
);
333+
diag.note(
334+
"marking the extern static mutable would allow changing which symbol \
335+
the static references rather than make the target of the symbol \
336+
mutable",
337+
);
338+
diag.emit();
339+
}
327340
} else {
328341
codegen_fn_attrs.linkage = linkage;
329342
}
330-
if tcx.is_mutable_static(did.into()) {
331-
let mut diag = tcx.dcx().struct_span_err(
332-
attr.span,
333-
"mutable statics are not allowed with `#[linkage]`",
334-
);
335-
diag.note(
336-
"making the static mutable would allow changing which symbol the \
337-
static references rather than make the target of the symbol \
338-
mutable",
339-
);
340-
diag.emit();
341-
}
342343
}
343344
}
344345
sym::link_section => {

compiler/rustc_driver_impl/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use rustc_interface::{interface, Queries};
3232
use rustc_lint::unerased_lint_store;
3333
use rustc_metadata::creader::MetadataLoader;
3434
use rustc_metadata::locator;
35+
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
3536
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
3637
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
3738
use rustc_session::getopts::{self, Matches};
@@ -1264,12 +1265,13 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12641265
}
12651266

12661267
fn parse_crate_attrs<'a>(sess: &'a Session) -> PResult<'a, ast::AttrVec> {
1267-
match &sess.io.input {
1268-
Input::File(ifile) => rustc_parse::parse_crate_attrs_from_file(ifile, &sess.psess),
1268+
let mut parser = unwrap_or_emit_fatal(match &sess.io.input {
1269+
Input::File(file) => new_parser_from_file(&sess.psess, file, None),
12691270
Input::Str { name, input } => {
1270-
rustc_parse::parse_crate_attrs_from_source_str(name.clone(), input.clone(), &sess.psess)
1271+
new_parser_from_source_str(&sess.psess, name.clone(), input.clone())
12711272
}
1272-
}
1273+
});
1274+
parser.parse_inner_attributes()
12731275
}
12741276

12751277
/// Runs a closure and catches unwinds triggered by fatal errors.

compiler/rustc_expand/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::sync::{self, Lrc};
1515
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
1616
use rustc_feature::Features;
1717
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
18-
use rustc_parse::{parser, MACRO_ARGUMENTS};
18+
use rustc_parse::{parser::Parser, MACRO_ARGUMENTS};
1919
use rustc_session::config::CollapseMacroDebuginfo;
2020
use rustc_session::{parse::ParseSess, Limit, Session};
2121
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
@@ -1149,8 +1149,8 @@ impl<'a> ExtCtxt<'a> {
11491149
pub fn monotonic_expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
11501150
expand::MacroExpander::new(self, true)
11511151
}
1152-
pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
1153-
rustc_parse::stream_to_parser(&self.sess.psess, stream, MACRO_ARGUMENTS)
1152+
pub fn new_parser_from_tts(&self, stream: TokenStream) -> Parser<'a> {
1153+
Parser::new(&self.sess.psess, stream, MACRO_ARGUMENTS)
11541154
}
11551155
pub fn source_map(&self) -> &'a SourceMap {
11561156
self.sess.psess.source_map()

compiler/rustc_expand/src/module.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::errors::{
55
use rustc_ast::ptr::P;
66
use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans};
77
use rustc_errors::{Diag, ErrorGuaranteed};
8-
use rustc_parse::new_parser_from_file;
98
use rustc_parse::validate_attr;
9+
use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
1010
use rustc_session::parse::ParseSess;
1111
use rustc_session::Session;
1212
use rustc_span::symbol::{sym, Ident};
@@ -66,7 +66,8 @@ pub(crate) fn parse_external_mod(
6666
}
6767

6868
// Actually parse the external file as a module.
69-
let mut parser = new_parser_from_file(&sess.psess, &mp.file_path, Some(span));
69+
let mut parser =
70+
unwrap_or_emit_fatal(new_parser_from_file(&sess.psess, &mp.file_path, Some(span)));
7071
let (inner_attrs, items, inner_span) =
7172
parser.parse_mod(&token::Eof).map_err(|err| ModError::ParserError(err))?;
7273
attrs.extend(inner_attrs);

compiler/rustc_expand/src/proc_macro.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast as ast;
66
use rustc_ast::ptr::P;
77
use rustc_ast::tokenstream::TokenStream;
88
use rustc_errors::ErrorGuaranteed;
9-
use rustc_parse::parser::ForceCollect;
9+
use rustc_parse::parser::{ForceCollect, Parser};
1010
use rustc_session::config::ProcMacroExecutionStrategy;
1111
use rustc_span::profiling::SpannedEventArgRecorder;
1212
use rustc_span::Span;
@@ -154,8 +154,7 @@ impl MultiItemModifier for DeriveProcMacro {
154154
};
155155

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

161160
loop {

compiler/rustc_expand/src/proc_macro_server.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use rustc_data_structures::fx::FxHashMap;
1313
use rustc_data_structures::sync::Lrc;
1414
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
1515
use rustc_parse::lexer::nfc_normalize;
16-
use rustc_parse::parse_stream_from_source_str;
16+
use rustc_parse::parser::Parser;
17+
use rustc_parse::{new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
1718
use rustc_session::parse::ParseSess;
1819
use rustc_span::def_id::CrateNum;
1920
use rustc_span::symbol::{self, sym, Symbol};
@@ -466,7 +467,8 @@ impl server::FreeFunctions for Rustc<'_, '_> {
466467

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

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

540542
fn from_str(&mut self, src: &str) -> Self::TokenStream {
541-
parse_stream_from_source_str(
543+
unwrap_or_emit_fatal(source_str_to_stream(
544+
self.psess(),
542545
FileName::proc_macro_source_code(src),
543546
src.to_string(),
544-
self.psess(),
545547
Some(self.call_site),
546-
)
548+
))
547549
}
548550

549551
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
@@ -553,11 +555,7 @@ impl server::TokenStream for Rustc<'_, '_> {
553555
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
554556
// Parse the expression from our tokenstream.
555557
let expr: PResult<'_, _> = try {
556-
let mut p = rustc_parse::stream_to_parser(
557-
self.psess(),
558-
stream.clone(),
559-
Some("proc_macro expand expr"),
560-
);
558+
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
561559
let expr = p.parse_expr()?;
562560
if p.token != token::Eof {
563561
p.unexpected()?;

compiler/rustc_hir_typeck/src/expr.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::errors::{
1313
YieldExprOutsideOfCoroutine,
1414
};
1515
use crate::fatally_break_rust;
16-
use crate::method::SelfSource;
1716
use crate::type_error_struct;
1817
use crate::CoroutineTypes;
1918
use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectation};
@@ -223,7 +222,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
223222
let ty = ensure_sufficient_stack(|| match &expr.kind {
224223
hir::ExprKind::Path(
225224
qpath @ (hir::QPath::Resolved(..) | hir::QPath::TypeRelative(..)),
226-
) => self.check_expr_path(qpath, expr, args, call),
225+
) => self.check_expr_path(qpath, expr, Some(args), call),
227226
_ => self.check_expr_kind(expr, expected),
228227
});
229228
let ty = self.resolve_vars_if_possible(ty);
@@ -290,7 +289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
290289
ExprKind::Path(QPath::LangItem(lang_item, _)) => {
291290
self.check_lang_item_path(lang_item, expr)
292291
}
293-
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, &[], None),
292+
ExprKind::Path(ref qpath) => self.check_expr_path(qpath, expr, None, None),
294293
ExprKind::InlineAsm(asm) => {
295294
// We defer some asm checks as we may not have resolved the input and output types yet (they may still be infer vars).
296295
self.deferred_asm_checks.borrow_mut().push((asm, expr.hir_id));
@@ -502,12 +501,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
502501
&self,
503502
qpath: &'tcx hir::QPath<'tcx>,
504503
expr: &'tcx hir::Expr<'tcx>,
505-
args: &'tcx [hir::Expr<'tcx>],
504+
args: Option<&'tcx [hir::Expr<'tcx>]>,
506505
call: Option<&'tcx hir::Expr<'tcx>>,
507506
) -> Ty<'tcx> {
508507
let tcx = self.tcx;
509508
let (res, opt_ty, segs) =
510-
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span, Some(args));
509+
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span);
511510
let ty = match res {
512511
Res::Err => {
513512
self.suggest_assoc_method_call(segs);
@@ -564,7 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
564563
// We just want to check sizedness, so instead of introducing
565564
// placeholder lifetimes with probing, we just replace higher lifetimes
566565
// with fresh vars.
567-
let span = args.get(i).map(|a| a.span).unwrap_or(expr.span);
566+
let span = args.and_then(|args| args.get(i)).map_or(expr.span, |arg| arg.span);
568567
let input = self.instantiate_binder_with_fresh_vars(
569568
span,
570569
infer::BoundRegionConversionTime::FnCall,
@@ -1331,9 +1330,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13311330
let rcvr_t = self.check_expr(rcvr);
13321331
// no need to check for bot/err -- callee does that
13331332
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
1334-
let span = segment.ident.span;
13351333

1336-
let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) {
1334+
let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
1335+
{
13371336
Ok(method) => {
13381337
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
13391338
// trigger this codepath causing `structurally_resolve_type` to emit an error.
@@ -1342,18 +1341,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13421341
}
13431342
Err(error) => {
13441343
if segment.ident.name != kw::Empty {
1345-
if let Some(err) = self.report_method_error(
1346-
span,
1347-
Some(rcvr),
1348-
rcvr_t,
1349-
segment.ident,
1350-
expr.hir_id,
1351-
SelfSource::MethodCall(rcvr),
1352-
error,
1353-
Some(args),
1354-
expected,
1355-
false,
1356-
) {
1344+
if let Some(err) =
1345+
self.report_method_error(expr.hir_id, rcvr_t, error, expected, false)
1346+
{
13571347
err.emit();
13581348
}
13591349
}
@@ -1362,7 +1352,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13621352
};
13631353

13641354
// Call the generic checker.
1365-
self.check_method_argument_types(span, expr, method, args, DontTupleArguments, expected)
1355+
self.check_method_argument_types(
1356+
segment.ident.span,
1357+
expr,
1358+
method,
1359+
args,
1360+
DontTupleArguments,
1361+
expected,
1362+
)
13661363
}
13671364

13681365
fn check_expr_cast(

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::callee::{self, DeferredCallResolution};
22
use crate::errors::{self, CtorIsPrivate};
3-
use crate::method::{self, MethodCallee, SelfSource};
3+
use crate::method::{self, MethodCallee};
44
use crate::rvalue_scopes;
55
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
66
use rustc_data_structures::fx::FxHashSet;
@@ -735,7 +735,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
735735
qpath: &'tcx QPath<'tcx>,
736736
hir_id: HirId,
737737
span: Span,
738-
args: Option<&'tcx [hir::Expr<'tcx>]>,
739738
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
740739
debug!(
741740
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
@@ -828,14 +827,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
828827

829828
if item_name.name != kw::Empty {
830829
if let Some(e) = self.report_method_error(
831-
span,
832-
None,
833-
ty.normalized,
834-
item_name,
835830
hir_id,
836-
SelfSource::QPath(qself),
831+
ty.normalized,
837832
error,
838-
args,
839833
Expectation::NoExpectation,
840834
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
841835
) {

compiler/rustc_hir_typeck/src/method/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod prelude_edition_lints;
77
pub mod probe;
88
mod suggest;
99

10-
pub use self::suggest::SelfSource;
1110
pub use self::MethodError::*;
1211

1312
use crate::FnCtxt;

0 commit comments

Comments
 (0)