Skip to content

Commit

Permalink
Auto merge of rust-lang#121636 - matthiaskrgr:rollup-1tt2o5n, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#121389 (llvm-wrapper: fix few warnings)
 - rust-lang#121493 (By changing some attributes to only_local, reducing encoding attributes in the crate metadate.)
 - rust-lang#121615 (Move `emit_stashed_diagnostic` call in rustfmt.)
 - rust-lang#121617 (Actually use the right closure kind when checking async Fn goals)
 - rust-lang#121628 (Do not const prop unions)
 - rust-lang#121629 (fix some references to no-longer-existing ReprOptions.layout_seed)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 26, 2024
2 parents b79db43 + 81eddb3 commit 829308e
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 68 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/layout.rs
Expand Up @@ -958,7 +958,7 @@ fn univariant<
#[cfg(feature = "randomize")]
{
use rand::{seq::SliceRandom, SeedableRng};
// `ReprOptions.layout_seed` is a deterministic seed we can use to randomize field
// `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
// ordering.
let mut rng =
rand_xoshiro::Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/lib.rs
Expand Up @@ -41,7 +41,7 @@ bitflags! {
// Internal only for now. If true, don't reorder fields.
const IS_LINEAR = 1 << 3;
// If true, the type's layout can be randomized using
// the seed stored in `ReprOptions.layout_seed`
// the seed stored in `ReprOptions.field_shuffle_seed`
const RANDOMIZE_LAYOUT = 1 << 4;
// Any of these flags being set prevent field reordering optimisation.
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Expand Up @@ -36,7 +36,7 @@ use rustc_span::InnerSpan;
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};

use crate::llvm::diagnostic::OptimizationDiagnosticKind;
use libc::{c_char, c_int, c_uint, c_void, size_t};
use libc::{c_char, c_int, c_void, size_t};
use std::ffi::CString;
use std::fs;
use std::io::{self, Write};
Expand Down Expand Up @@ -406,7 +406,7 @@ fn report_inline_asm(
cgcx: &CodegenContext<LlvmCodegenBackend>,
msg: String,
level: llvm::DiagnosticLevel,
mut cookie: c_uint,
mut cookie: u64,
source: Option<(String, Vec<InnerSpan>)>,
) {
// In LTO build we may get srcloc values from other crates which are invalid
Expand All @@ -420,7 +420,7 @@ fn report_inline_asm(
llvm::DiagnosticLevel::Warning => Level::Warning,
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
};
cgcx.diag_emitter.inline_asm_error(cookie as u32, msg, level, source);
cgcx.diag_emitter.inline_asm_error(cookie.try_into().unwrap(), msg, level, source);
}

unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs
Expand Up @@ -123,7 +123,7 @@ impl SrcMgrDiagnostic {
#[derive(Clone)]
pub struct InlineAsmDiagnostic {
pub level: super::DiagnosticLevel,
pub cookie: c_uint,
pub cookie: u64,
pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>,
}
Expand All @@ -149,7 +149,7 @@ impl InlineAsmDiagnostic {
let smdiag = SrcMgrDiagnostic::unpack(super::LLVMRustGetSMDiagnostic(di, &mut cookie));
InlineAsmDiagnostic {
level: smdiag.level,
cookie,
cookie: cookie.into(),
message: smdiag.message,
source: smdiag.source,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Expand Up @@ -2256,7 +2256,7 @@ extern "C" {
pub fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
DI: &'a DiagnosticInfo,
level_out: &mut DiagnosticLevel,
cookie_out: &mut c_uint,
cookie_out: &mut u64,
message_out: &mut Option<&'a Twine>,
);

Expand Down
62 changes: 44 additions & 18 deletions compiler/rustc_feature/src/builtin_attrs.rs
Expand Up @@ -277,25 +277,35 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk),

// Testing:
ungated!(ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing),
ungated!(
ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
@only_local: true,
),
ungated!(
should_panic, Normal,
template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing,
@only_local: true,
),
// FIXME(Centril): This can be used on stable but shouldn't.
ungated!(reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing),
ungated!(
reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing,
@only_local: true,
),

// Macros:
ungated!(automatically_derived, Normal, template!(Word), WarnFollowing),
ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly),
ungated!(macro_escape, Normal, template!(Word), WarnFollowing), // Deprecated synonym for `macro_use`.
ungated!(
macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly,
@only_local: true,
),
ungated!(macro_escape, Normal, template!(Word), WarnFollowing, @only_local: true), // Deprecated synonym for `macro_use`.
ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros"), WarnFollowing),
ungated!(proc_macro, Normal, template!(Word), ErrorFollowing),
ungated!(proc_macro, Normal, template!(Word), ErrorFollowing, @only_local: true),
ungated!(
proc_macro_derive, Normal,
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
proc_macro_derive, Normal, template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"),
ErrorFollowing, @only_local: true,
),
ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing),
ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing, @only_local: true),

// Lints:
ungated!(
Expand All @@ -308,7 +318,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
gated!(
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
lint_reasons, experimental!(expect)
@only_local: true, lint_reasons, experimental!(expect)
),
ungated!(
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
Expand All @@ -334,32 +344,48 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

// Crate properties:
ungated!(crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing),
ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk),
ungated!(
crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing,
@only_local: true,
),
ungated!(
crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk,
@only_local: true,
),
// crate_id is deprecated
ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing),
ungated!(
crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing,
@only_local: true,
),

// ABI, linking, symbols, and FFI
ungated!(
link, Normal,
template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#),
DuplicatesOk,
@only_local: true,
),
ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
ungated!(no_link, Normal, template!(Word), WarnFollowing),
ungated!(no_link, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, @only_local: true),
ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, @only_local: true),
ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, @only_local: true),
ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),

// Limits:
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
ungated!(
recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing,
@only_local: true
),
ungated!(
type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing,
@only_local: true
),
gated!(
move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
large_assignments, experimental!(move_size_limit)
@only_local: true, large_assignments, experimental!(move_size_limit)
),

// Entry point:
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp
Expand Up @@ -67,7 +67,7 @@ typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;

extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOr =
MemoryBuffer::getFile(Path, -1, false);
MemoryBuffer::getFile(Path, /*IsText*/false, /*RequiresNullTerminator=*/false);
if (!BufOr) {
LLVMRustSetLastError(BufOr.getError().message().c_str());
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Expand Up @@ -1262,7 +1262,7 @@ enum class LLVMRustDiagnosticLevel {
extern "C" void
LLVMRustUnpackInlineAsmDiagnostic(LLVMDiagnosticInfoRef DI,
LLVMRustDiagnosticLevel *LevelOut,
unsigned *CookieOut,
uint64_t *CookieOut,
LLVMTwineRef *MessageOut) {
// Undefined to call this not on an inline assembly diagnostic!
llvm::DiagnosticInfoInlineAsm *IA =
Expand Down
40 changes: 26 additions & 14 deletions compiler/rustc_mir_transform/src/known_panics_lint.rs
Expand Up @@ -585,20 +585,32 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
val.into()
}

Aggregate(ref kind, ref fields) => Value::Aggregate {
fields: fields
.iter()
.map(|field| self.eval_operand(field).map_or(Value::Uninit, Value::Immediate))
.collect(),
variant: match **kind {
AggregateKind::Adt(_, variant, _, _, _) => variant,
AggregateKind::Array(_)
| AggregateKind::Tuple
| AggregateKind::Closure(_, _)
| AggregateKind::Coroutine(_, _)
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::new(0),
},
},
Aggregate(ref kind, ref fields) => {
// Do not const pop union fields as they can be
// made to produce values that don't match their
// underlying layout's type (see ICE #121534).
// If the last element of the `Adt` tuple
// is `Some` it indicates the ADT is a union
if let AggregateKind::Adt(_, _, _, _, Some(_)) = **kind {
return None;
};
Value::Aggregate {
fields: fields
.iter()
.map(|field| {
self.eval_operand(field).map_or(Value::Uninit, Value::Immediate)
})
.collect(),
variant: match **kind {
AggregateKind::Adt(_, variant, _, _, _) => variant,
AggregateKind::Array(_)
| AggregateKind::Tuple
| AggregateKind::Closure(_, _)
| AggregateKind::Coroutine(_, _)
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::new(0),
},
}
}

Repeat(ref op, n) => {
trace!(?op, ?n);
Expand Down
Expand Up @@ -934,7 +934,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
}
ty::Closure(_, args) => {
let sig = args.as_closure().sig();
let args = args.as_closure();
let sig = args.sig();
let trait_ref = sig.map_bound(|sig| {
ty::TraitRef::new(
self.tcx(),
Expand All @@ -950,7 +951,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::TraitRef::new(tcx, future_trait_def_id, [sig.output()])
}),
));
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
(trait_ref, args.kind_ty())
}
_ => bug!("expected callable type for AsyncFn candidate"),
};
Expand Down
22 changes: 16 additions & 6 deletions src/tools/rustfmt/src/formatting.rs
Expand Up @@ -109,19 +109,29 @@ fn format_project<T: FormatHandler>(
let main_file = input.file_name();
let input_is_stdin = main_file == FileName::Stdin;

let parse_session = ParseSess::new(config)?;
let mut parse_session = ParseSess::new(config)?;
if config.skip_children() && parse_session.ignore_file(&main_file) {
return Ok(FormatReport::new());
}

// Parse the crate.
let mut report = FormatReport::new();
let directory_ownership = input.to_directory_ownership();
let krate = match Parser::parse_crate(input, &parse_session) {
Ok(krate) => krate,
// Surface parse error via Session (errors are merged there from report)
Err(e) => {
let forbid_verbose = input_is_stdin || e != ParserError::ParsePanicError;

// rustfmt doesn't use `run_compiler` like other tools, so it must emit any
// stashed diagnostics itself, otherwise the `DiagCtxt` will assert when
// dropped. The final result here combines the parsing result and the
// `emit_stashed_diagnostics` result.
let parse_res = Parser::parse_crate(input, &parse_session);
let stashed_res = parse_session.emit_stashed_diagnostics();
let krate = match (parse_res, stashed_res) {
(Ok(krate), None) => krate,
(parse_res, _) => {
// Surface parse error via Session (errors are merged there from report).
let forbid_verbose = match parse_res {
Err(e) if e != ParserError::ParsePanicError => true,
_ => input_is_stdin,
};
should_emit_verbose(forbid_verbose, config, || {
eprintln!("The Rust parser panicked");
});
Expand Down
16 changes: 4 additions & 12 deletions src/tools/rustfmt/src/parse/parser.rs
Expand Up @@ -162,22 +162,14 @@ impl<'a> Parser<'a> {

fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
let mut parser = AssertUnwindSafe(&mut self.parser);

// rustfmt doesn't use `run_compiler` like other tools, so it must emit
// any stashed diagnostics itself, otherwise the `DiagCtxt` will assert
// when dropped. The final result here combines the parsing result and
// the `emit_stashed_diagnostics` result.
let parse_res = catch_unwind(move || parser.parse_crate_mod());
let stashed_res = self.parser.dcx().emit_stashed_diagnostics();
let err = Err(ParserError::ParsePanicError);
match (parse_res, stashed_res) {
(Ok(Ok(k)), None) => Ok(k),
(Ok(Ok(_)), Some(_guar)) => err,
(Ok(Err(db)), _) => {
match catch_unwind(move || parser.parse_crate_mod()) {
Ok(Ok(k)) => Ok(k),
Ok(Err(db)) => {
db.emit();
err
}
(Err(_), _) => err,
Err(_) => err,
}
}
}
6 changes: 5 additions & 1 deletion src/tools/rustfmt/src/parse/session.rs
Expand Up @@ -6,7 +6,7 @@ use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter};
use rustc_errors::translation::Translate;
use rustc_errors::{
ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, Level as DiagnosticLevel,
ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Level as DiagnosticLevel,
};
use rustc_session::parse::ParseSess as RawParseSess;
use rustc_span::{
Expand Down Expand Up @@ -230,6 +230,10 @@ impl ParseSess {
self.ignore_path_set.as_ref().is_match(path)
}

pub(crate) fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
self.parse_sess.dcx.emit_stashed_diagnostics()
}

pub(crate) fn set_silent_emitter(&mut self) {
self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter());
}
Expand Down
7 changes: 7 additions & 0 deletions src/tools/rustfmt/src/test/parser.rs
Expand Up @@ -62,3 +62,10 @@ fn crate_parsing_stashed_diag() {
let filename = "tests/parser/stashed-diag.rs";
assert_parser_error(filename);
}

#[test]
fn crate_parsing_stashed_diag2() {
// See also https://github.com/rust-lang/rust/issues/121517
let filename = "tests/parser/stashed-diag2.rs";
assert_parser_error(filename);
}
3 changes: 3 additions & 0 deletions src/tools/rustfmt/tests/parser/stashed-diag2.rs
@@ -0,0 +1,3 @@
trait Trait<'1> { s> {}

fn main() {}
8 changes: 6 additions & 2 deletions tests/ui/async-await/async-closures/wrong-fn-kind.rs
@@ -1,7 +1,5 @@
//@ edition:2021

// FIXME(async_closures): This needs a better error message!

#![feature(async_closure)]

fn main() {
Expand All @@ -12,4 +10,10 @@ fn main() {
//~^ ERROR expected a closure that implements the `async Fn` trait, but this closure only implements `async FnMut`
x += 1;
});

let x = String::new();
needs_async_fn(move || async move {
//~^ ERROR expected a closure that implements the `async Fn` trait, but this closure only implements `async FnOnce`
println!("{x}");
});
}

0 comments on commit 829308e

Please sign in to comment.