Skip to content

Commit 5a0d572

Browse files
committed
Auto merge of #154870 - JonathanBrouwer:rollup-OFrhW8F, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #153440 (Various LTO cleanups) - #151899 (Constify fold, reduce and last for iterator) - #154561 (Suggest similar keyword when visibility is not followed by an item) - #154657 (Fix pattern assignment suggestions for uninitialized bindings) - #154717 (Fix ICE in unsafe binder discriminant helpers) - #154722 (fix(lints): Improve `ill_formed_attribute_input` with better help message) - #154777 (`#[cfg]`: suggest alternative `target_` name when the value does not match) - #154849 (Promote `char::is_case_ignorable` from perma-unstable to unstable) - #154850 (ast_validation: scalable vectors okay for rustdoc)
2 parents c2efcc4 + ec78f91 commit 5a0d572

File tree

34 files changed

+626
-231
lines changed

34 files changed

+626
-231
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13791379
this.dcx()
13801380
.emit_err(errors::ScalableVectorNotTupleStruct { span: item.span });
13811381
}
1382-
if !self.sess.target.arch.supports_scalable_vectors() {
1382+
if !self.sess.target.arch.supports_scalable_vectors()
1383+
&& !self.sess.opts.actually_rustdoc
1384+
{
13831385
this.dcx().emit_err(errors::ScalableVectorBadArch { span: attr.span });
13841386
}
13851387
}

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,11 @@ impl DocParser {
665665
let span = cx.attr_span;
666666
cx.emit_lint(
667667
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
668-
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
668+
AttributeLintKind::IllFormedAttributeInput {
669+
suggestions,
670+
docs: None,
671+
help: None,
672+
},
669673
span,
670674
);
671675
}

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
2727
};
2828
Some(str_value)
2929
}
30-
ArgParser::List(_) => {
31-
cx.adcx().warn_ill_formed_attribute_input(ILL_FORMED_ATTRIBUTE_INPUT);
30+
ArgParser::List(list) => {
31+
let help = list.single().and_then(|item| item.meta_item()).and_then(|item| {
32+
item.args().no_args().ok()?;
33+
Some(item.path().to_string())
34+
});
35+
cx.adcx().warn_ill_formed_attribute_input_with_help(
36+
ILL_FORMED_ATTRIBUTE_INPUT,
37+
help,
38+
);
3239
return None;
3340
}
3441
},

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,18 @@ where
830830
}
831831

832832
pub(crate) fn warn_ill_formed_attribute_input(&mut self, lint: &'static Lint) {
833+
self.warn_ill_formed_attribute_input_with_help(lint, None)
834+
}
835+
pub(crate) fn warn_ill_formed_attribute_input_with_help(
836+
&mut self,
837+
lint: &'static Lint,
838+
help: Option<String>,
839+
) {
833840
let suggestions = self.suggestions();
834841
let span = self.attr_span;
835842
self.emit_lint(
836843
lint,
837-
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None },
844+
AttributeLintKind::IllFormedAttributeInput { suggestions, docs: None, help },
838845
span,
839846
);
840847
}

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ fn emit_malformed_attribute(
211211
BuiltinLintDiag::AttributeLint(AttributeLintKind::IllFormedAttributeInput {
212212
suggestions: suggestions.clone(),
213213
docs: template.docs,
214+
help: None,
214215
}),
215216
);
216217
} else {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -914,32 +914,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
914914
if show_assign_sugg {
915915
struct LetVisitor {
916916
decl_span: Span,
917-
sugg_span: Option<Span>,
917+
sugg: Option<(Span, bool)>,
918918
}
919919

920920
impl<'v> Visitor<'v> for LetVisitor {
921921
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
922-
if self.sugg_span.is_some() {
922+
if self.sugg.is_some() {
923923
return;
924924
}
925925

926926
// FIXME: We make sure that this is a normal top-level binding,
927927
// but we could suggest `todo!()` for all uninitialized bindings in the pattern
928928
if let hir::StmtKind::Let(hir::LetStmt { span, ty, init: None, pat, .. }) =
929929
&ex.kind
930-
&& let hir::PatKind::Binding(..) = pat.kind
930+
&& let hir::PatKind::Binding(binding_mode, ..) = pat.kind
931931
&& span.contains(self.decl_span)
932932
{
933-
self.sugg_span = ty.map_or(Some(self.decl_span), |ty| Some(ty.span));
933+
// Insert after the whole binding pattern so suggestions stay valid for
934+
// bindings with `@` subpatterns like `ref mut x @ v`.
935+
let strip_ref = matches!(binding_mode.0, hir::ByRef::Yes(..));
936+
self.sugg =
937+
ty.map_or(Some((pat.span, strip_ref)), |ty| Some((ty.span, strip_ref)));
934938
}
935939
hir::intravisit::walk_stmt(self, ex);
936940
}
937941
}
938942

939-
let mut visitor = LetVisitor { decl_span, sugg_span: None };
943+
let mut visitor = LetVisitor { decl_span, sugg: None };
940944
visitor.visit_body(&body);
941-
if let Some(span) = visitor.sugg_span {
942-
self.suggest_assign_value(&mut err, moved_place, span);
945+
if let Some((span, strip_ref)) = visitor.sugg {
946+
self.suggest_assign_value(&mut err, moved_place, span, strip_ref);
943947
}
944948
}
945949
err
@@ -950,8 +954,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
950954
err: &mut Diag<'_>,
951955
moved_place: PlaceRef<'tcx>,
952956
sugg_span: Span,
957+
strip_ref: bool,
953958
) {
954-
let ty = moved_place.ty(self.body, self.infcx.tcx).ty;
959+
let mut ty = moved_place.ty(self.body, self.infcx.tcx).ty;
960+
if strip_ref && let ty::Ref(_, inner, _) = ty.kind() {
961+
ty = *inner;
962+
}
955963
debug!("ty: {:?}, kind: {:?}", ty, ty.kind());
956964

957965
let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.infcx.param_env, ty)

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use rustc_data_structures::memmap::Mmap;
3131
use rustc_data_structures::profiling::SelfProfilerRef;
3232
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3333
use rustc_log::tracing::info;
34-
use rustc_session::config::Lto;
3534
use tempfile::{TempDir, tempdir};
3635

3736
use crate::back::write::{codegen, save_temp_bitcode};
@@ -45,11 +44,7 @@ struct LtoData {
4544
tmp_path: TempDir,
4645
}
4746

48-
fn prepare_lto(
49-
cgcx: &CodegenContext,
50-
each_linked_rlib_for_lto: &[PathBuf],
51-
dcx: DiagCtxtHandle<'_>,
52-
) -> LtoData {
47+
fn prepare_lto(each_linked_rlib_for_lto: &[PathBuf], dcx: DiagCtxtHandle<'_>) -> LtoData {
5348
let tmp_path = match tempdir() {
5449
Ok(tmp_path) => tmp_path,
5550
Err(error) => {
@@ -64,32 +59,30 @@ fn prepare_lto(
6459
// We save off all the bytecode and GCC module file path for later processing
6560
// with either fat or thin LTO
6661
let mut upstream_modules = Vec::new();
67-
if cgcx.lto != Lto::ThinLocal {
68-
for path in each_linked_rlib_for_lto {
69-
let archive_data = unsafe {
70-
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
71-
};
72-
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
73-
let obj_files = archive
74-
.members()
75-
.filter_map(|child| {
76-
child.ok().and_then(|c| {
77-
std::str::from_utf8(c.name()).ok().map(|name| (name.trim(), c))
78-
})
79-
})
80-
.filter(|&(name, _)| looks_like_rust_object_file(name));
81-
for (name, child) in obj_files {
82-
info!("adding bitcode from {}", name);
83-
let path = tmp_path.path().join(name);
84-
match save_as_file(child.data(&*archive_data).expect("corrupt rlib"), &path) {
85-
Ok(()) => {
86-
let buffer = ModuleBuffer::new(path);
87-
let module = SerializedModule::Local(buffer);
88-
upstream_modules.push((module, CString::new(name).unwrap()));
89-
}
90-
Err(e) => {
91-
dcx.emit_fatal(e);
92-
}
62+
for path in each_linked_rlib_for_lto {
63+
let archive_data = unsafe {
64+
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
65+
};
66+
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
67+
let obj_files = archive
68+
.members()
69+
.filter_map(|child| {
70+
child
71+
.ok()
72+
.and_then(|c| std::str::from_utf8(c.name()).ok().map(|name| (name.trim(), c)))
73+
})
74+
.filter(|&(name, _)| looks_like_rust_object_file(name));
75+
for (name, child) in obj_files {
76+
info!("adding bitcode from {}", name);
77+
let path = tmp_path.path().join(name);
78+
match save_as_file(child.data(&*archive_data).expect("corrupt rlib"), &path) {
79+
Ok(()) => {
80+
let buffer = ModuleBuffer::new(path);
81+
let module = SerializedModule::Local(buffer);
82+
upstream_modules.push((module, CString::new(name).unwrap()));
83+
}
84+
Err(e) => {
85+
dcx.emit_fatal(e);
9386
}
9487
}
9588
}
@@ -115,7 +108,7 @@ pub(crate) fn run_fat(
115108
) -> CompiledModule {
116109
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
117110
let dcx = dcx.handle();
118-
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
111+
let lto_data = prepare_lto(each_linked_rlib_for_lto, dcx);
119112
/*let symbols_below_threshold =
120113
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
121114
fat_lto(

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ use gccjit::{CType, Context, OptimizationLevel};
8181
#[cfg(feature = "master")]
8282
use gccjit::{TargetInfo, Version};
8383
use rustc_ast::expand::allocator::AllocatorMethod;
84-
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule};
84+
use rustc_codegen_ssa::back::lto::ThinModule;
8585
use rustc_codegen_ssa::back::write::{
86-
CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn,
86+
CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn, ThinLtoInput,
8787
};
8888
use rustc_codegen_ssa::base::codegen_crate;
8989
use rustc_codegen_ssa::target_features::cfg_target_feature;
@@ -449,8 +449,7 @@ impl WriteBackendMethods for GccCodegenBackend {
449449
// FIXME(bjorn3): Limit LTO exports to these symbols
450450
_exported_symbols_for_lto: &[String],
451451
_each_linked_rlib_for_lto: &[PathBuf],
452-
_modules: Vec<(String, Self::ModuleBuffer)>,
453-
_cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
452+
_modules: Vec<ThinLtoInput<Self>>,
454453
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>) {
455454
unreachable!()
456455
}

0 commit comments

Comments
 (0)