Skip to content

Commit a8faccf

Browse files
authored
Merge branch 'rust-lang:master' into master
2 parents 81a9332 + db8aca4 commit a8faccf

File tree

369 files changed

+3430
-3258
lines changed

Some content is hidden

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

369 files changed

+3430
-3258
lines changed

compiler/rustc_borrowck/src/nll.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
125125
placeholder_indices,
126126
placeholder_index_to_region: _,
127127
liveness_constraints,
128-
outlives_constraints,
129-
member_constraints,
128+
mut outlives_constraints,
129+
mut member_constraints,
130130
universe_causes,
131131
type_tests,
132132
} = constraints;
@@ -144,6 +144,16 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
144144
&universal_region_relations,
145145
);
146146

147+
if let Some(guar) = universal_regions.tainted_by_errors() {
148+
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
149+
// outlives bounds that we may end up checking.
150+
outlives_constraints = Default::default();
151+
member_constraints = Default::default();
152+
153+
// Also taint the entire scope.
154+
infcx.set_tainted_by_errors(guar);
155+
}
156+
147157
let mut regioncx = RegionInferenceContext::new(
148158
infcx,
149159
var_origins,

compiler/rustc_borrowck/src/universal_regions.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, T
2929
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
3030
use rustc_middle::{bug, span_bug};
3131
use rustc_span::symbol::{kw, sym};
32-
use rustc_span::Symbol;
32+
use rustc_span::{ErrorGuaranteed, Symbol};
33+
use std::cell::Cell;
3334
use std::iter;
3435

3536
use crate::renumber::RegionCtxt;
@@ -186,6 +187,10 @@ struct UniversalRegionIndices<'tcx> {
186187

187188
/// The vid assigned to `'static`. Used only for diagnostics.
188189
pub fr_static: RegionVid,
190+
191+
/// Whether we've encountered an error region. If we have, cancel all
192+
/// outlives errors, as they are likely bogus.
193+
pub tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
189194
}
190195

191196
#[derive(Debug, PartialEq)]
@@ -408,6 +413,10 @@ impl<'tcx> UniversalRegions<'tcx> {
408413
}
409414
}
410415
}
416+
417+
pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
418+
self.indices.tainted_by_errors.get()
419+
}
411420
}
412421

413422
struct UniversalRegionsBuilder<'cx, 'tcx> {
@@ -663,7 +672,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
663672
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
664673
let arg_mapping = iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
665674

666-
UniversalRegionIndices { indices: global_mapping.chain(arg_mapping).collect(), fr_static }
675+
UniversalRegionIndices {
676+
indices: global_mapping.chain(arg_mapping).collect(),
677+
fr_static,
678+
tainted_by_errors: Cell::new(None),
679+
}
667680
}
668681

669682
fn compute_inputs_and_output(
@@ -868,7 +881,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
868881
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
869882
if let ty::ReVar(..) = *r {
870883
r.as_var()
871-
} else if r.is_error() {
884+
} else if let ty::ReError(guar) = *r {
885+
self.tainted_by_errors.set(Some(guar));
872886
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
873887
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
874888
// errors are being emitted and 2) it leaves the happy path unaffected.

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_cranelift/src/driver/aot.rs

+23
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,29 @@ fn produce_final_output_artifacts(
288288
}
289289
}
290290

291+
if sess.opts.json_artifact_notifications {
292+
if codegen_results.modules.len() == 1 {
293+
codegen_results.modules[0].for_each_output(|_path, ty| {
294+
if sess.opts.output_types.contains_key(&ty) {
295+
let descr = ty.shorthand();
296+
// for single cgu file is renamed to drop cgu specific suffix
297+
// so we regenerate it the same way
298+
let path = crate_output.path(ty);
299+
sess.dcx().emit_artifact_notification(path.as_path(), descr);
300+
}
301+
});
302+
} else {
303+
for module in &codegen_results.modules {
304+
module.for_each_output(|path, ty| {
305+
if sess.opts.output_types.contains_key(&ty) {
306+
let descr = ty.shorthand();
307+
sess.dcx().emit_artifact_notification(&path, descr);
308+
}
309+
});
310+
}
311+
}
312+
}
313+
291314
// We leave the following files around by default:
292315
// - #crate#.o
293316
// - #crate#.crate.metadata.o

compiler/rustc_codegen_ssa/src/back/write.rs

+23
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,29 @@ fn produce_final_output_artifacts(
717717
}
718718
}
719719

720+
if sess.opts.json_artifact_notifications {
721+
if compiled_modules.modules.len() == 1 {
722+
compiled_modules.modules[0].for_each_output(|_path, ty| {
723+
if sess.opts.output_types.contains_key(&ty) {
724+
let descr = ty.shorthand();
725+
// for single cgu file is renamed to drop cgu specific suffix
726+
// so we regenerate it the same way
727+
let path = crate_output.path(ty);
728+
sess.dcx().emit_artifact_notification(path.as_path(), descr);
729+
}
730+
});
731+
} else {
732+
for module in &compiled_modules.modules {
733+
module.for_each_output(|path, ty| {
734+
if sess.opts.output_types.contains_key(&ty) {
735+
let descr = ty.shorthand();
736+
sess.dcx().emit_artifact_notification(&path, descr);
737+
}
738+
});
739+
}
740+
}
741+
}
742+
720743
// We leave the following files around by default:
721744
// - #crate#.o
722745
// - #crate#.crate.metadata.o

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_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn push_debuginfo_type_name<'tcx>(
263263
let ExistentialProjection { def_id: item_def_id, term, .. } =
264264
tcx.instantiate_bound_regions_with_erased(bound);
265265
// FIXME(associated_const_equality): allow for consts here
266-
(item_def_id, term.ty().unwrap())
266+
(item_def_id, term.expect_type())
267267
})
268268
.collect();
269269

compiler/rustc_codegen_ssa/src/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ pub struct CompiledModule {
106106
pub llvm_ir: Option<PathBuf>, // --emit=llvm-ir, llvm-bc is in bytecode
107107
}
108108

109+
impl CompiledModule {
110+
/// Call `emit` function with every artifact type currently compiled
111+
pub fn for_each_output(&self, mut emit: impl FnMut(&Path, OutputType)) {
112+
if let Some(path) = self.object.as_deref() {
113+
emit(path, OutputType::Object);
114+
}
115+
if let Some(path) = self.bytecode.as_deref() {
116+
emit(path, OutputType::Bitcode);
117+
}
118+
if let Some(path) = self.llvm_ir.as_deref() {
119+
emit(path, OutputType::LlvmAssembly);
120+
}
121+
if let Some(path) = self.assembly.as_deref() {
122+
emit(path, OutputType::Assembly);
123+
}
124+
}
125+
}
126+
109127
pub struct CachedModuleCodegen {
110128
pub name: String,
111129
pub source: WorkProduct,

compiler/rustc_driver_impl/src/lib.rs

+17-11
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};
@@ -814,13 +815,17 @@ fn print_crate_info(
814815
match expected_values {
815816
ExpectedValues::Any => check_cfgs.push(format!("{name}=any()")),
816817
ExpectedValues::Some(values) => {
817-
check_cfgs.extend(values.iter().map(|value| {
818-
if let Some(value) = value {
819-
format!("{name}=\"{value}\"")
820-
} else {
821-
name.to_string()
822-
}
823-
}))
818+
if !values.is_empty() {
819+
check_cfgs.extend(values.iter().map(|value| {
820+
if let Some(value) = value {
821+
format!("{name}=\"{value}\"")
822+
} else {
823+
name.to_string()
824+
}
825+
}))
826+
} else {
827+
check_cfgs.push(format!("{name}="))
828+
}
824829
}
825830
}
826831
}
@@ -1260,12 +1265,13 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12601265
}
12611266

12621267
fn parse_crate_attrs<'a>(sess: &'a Session) -> PResult<'a, ast::AttrVec> {
1263-
match &sess.io.input {
1264-
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),
12651270
Input::Str { name, input } => {
1266-
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())
12671272
}
1268-
}
1273+
});
1274+
parser.parse_inner_attributes()
12691275
}
12701276

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

compiler/rustc_driver_impl/src/pretty.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use rustc_ast as ast;
44
use rustc_ast_pretty::pprust as pprust_ast;
55
use rustc_errors::FatalError;
6-
use rustc_hir as hir;
76
use rustc_hir_pretty as pprust_hir;
87
use rustc_middle::bug;
98
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
@@ -70,11 +69,7 @@ struct HirIdentifiedAnn<'tcx> {
7069

7170
impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
7271
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
73-
pprust_hir::PpAnn::nested(
74-
&(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>),
75-
state,
76-
nested,
77-
)
72+
self.tcx.nested(state, nested)
7873
}
7974

8075
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
@@ -152,8 +147,7 @@ impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
152147
if let pprust_hir::Nested::Body(id) = nested {
153148
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
154149
}
155-
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
156-
pprust_hir::PpAnn::nested(pp_ann, state, nested);
150+
self.tcx.nested(state, nested);
157151
self.maybe_typeck_results.set(old_maybe_typeck_results);
158152
}
159153

compiler/rustc_expand/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ expand_not_a_meta_item =
124124
expand_only_one_word =
125125
must only be one word
126126
127+
expand_proc_macro_back_compat = using an old version of `{$crate_name}`
128+
.note = older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
129+
127130
expand_proc_macro_derive_panicked =
128131
proc-macro derive panicked
129132
.help = message: {$message}

0 commit comments

Comments
 (0)