Skip to content

Commit f4754ed

Browse files
committed
Auto merge of rust-lang#2986 - rust-lang:rustup-2023-07-18, r=RalfJung
Automatic sync from rustc
2 parents bbabfdc + 7bee1c8 commit f4754ed

File tree

983 files changed

+23907
-14197
lines changed

Some content is hidden

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

983 files changed

+23907
-14197
lines changed

Cargo.lock

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,25 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
513513

514514
[[package]]
515515
name = "clippy"
516-
version = "0.1.72"
516+
version = "0.1.73"
517517
dependencies = [
518518
"clippy_lints",
519+
"clippy_utils",
520+
"derive-new",
519521
"filetime",
522+
"futures",
523+
"if_chain",
520524
"itertools",
525+
"parking_lot 0.12.1",
526+
"quote",
521527
"regex",
522528
"rustc_tools_util",
529+
"serde",
530+
"syn 2.0.8",
523531
"tempfile",
524532
"termize",
525533
"tester",
534+
"tokio",
526535
"toml 0.7.5",
527536
"ui_test",
528537
"walkdir",
@@ -543,7 +552,7 @@ dependencies = [
543552

544553
[[package]]
545554
name = "clippy_lints"
546-
version = "0.1.72"
555+
version = "0.1.73"
547556
dependencies = [
548557
"arrayvec",
549558
"cargo_metadata",
@@ -566,27 +575,9 @@ dependencies = [
566575
"url",
567576
]
568577

569-
[[package]]
570-
name = "clippy_test_deps"
571-
version = "0.1.0"
572-
dependencies = [
573-
"clippy_lints",
574-
"clippy_utils",
575-
"derive-new",
576-
"futures",
577-
"if_chain",
578-
"itertools",
579-
"parking_lot 0.12.1",
580-
"quote",
581-
"regex",
582-
"serde",
583-
"syn 2.0.8",
584-
"tokio",
585-
]
586-
587578
[[package]]
588579
name = "clippy_utils"
589-
version = "0.1.72"
580+
version = "0.1.73"
590581
dependencies = [
591582
"arrayvec",
592583
"if_chain",
@@ -847,7 +838,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
847838

848839
[[package]]
849840
name = "declare_clippy_lint"
850-
version = "0.1.72"
841+
version = "0.1.73"
851842
dependencies = [
852843
"itertools",
853844
"quote",
@@ -3665,6 +3656,7 @@ name = "rustc_hir_typeck"
36653656
version = "0.1.0"
36663657
dependencies = [
36673658
"rustc_ast",
3659+
"rustc_attr",
36683660
"rustc_data_structures",
36693661
"rustc_errors",
36703662
"rustc_fluent_macro",

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ members = [
99
"src/tools/cargotest",
1010
"src/tools/clippy",
1111
"src/tools/clippy/clippy_dev",
12-
"src/tools/clippy/clippy_test_deps",
1312
"src/tools/compiletest",
1413
"src/tools/error_index_generator",
1514
"src/tools/linkchecker",

compiler/rustc_attr/src/builtin.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,3 +1217,20 @@ pub fn parse_alignment(node: &ast::LitKind) -> Result<u32, &'static str> {
12171217
Err("not an unsuffixed integer")
12181218
}
12191219
}
1220+
1221+
/// Read the content of a `rustc_confusables` attribute, and return the list of candidate names.
1222+
pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
1223+
let meta = attr.meta()?;
1224+
let MetaItem { kind: MetaItemKind::List(ref metas), .. } = meta else { return None };
1225+
1226+
let mut candidates = Vec::new();
1227+
1228+
for meta in metas {
1229+
let NestedMetaItem::Lit(meta_lit) = meta else {
1230+
return None;
1231+
};
1232+
candidates.push(meta_lit.symbol);
1233+
}
1234+
1235+
return Some(candidates);
1236+
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,20 +1134,30 @@ impl<'a> MethodDef<'a> {
11341134
trait_: &TraitDef<'b>,
11351135
enum_def: &'b EnumDef,
11361136
type_ident: Ident,
1137-
selflike_args: ThinVec<P<Expr>>,
1137+
mut selflike_args: ThinVec<P<Expr>>,
11381138
nonselflike_args: &[P<Expr>],
11391139
) -> BlockOrExpr {
1140+
assert!(
1141+
!selflike_args.is_empty(),
1142+
"static methods must use `expand_static_enum_method_body`",
1143+
);
1144+
11401145
let span = trait_.span;
11411146
let variants = &enum_def.variants;
11421147

11431148
// Traits that unify fieldless variants always use the tag(s).
11441149
let unify_fieldless_variants =
11451150
self.fieldless_variants_strategy == FieldlessVariantsStrategy::Unify;
11461151

1147-
// There is no sensible code to be generated for *any* deriving on a
1148-
// zero-variant enum. So we just generate a failing expression.
1152+
// For zero-variant enum, this function body is unreachable. Generate
1153+
// `match *self {}`. This produces machine code identical to `unsafe {
1154+
// core::intrinsics::unreachable() }` while being safe and stable.
11491155
if variants.is_empty() {
1150-
return BlockOrExpr(ThinVec::new(), Some(deriving::call_unreachable(cx, span)));
1156+
selflike_args.truncate(1);
1157+
let match_arg = cx.expr_deref(span, selflike_args.pop().unwrap());
1158+
let match_arms = ThinVec::new();
1159+
let expr = cx.expr_match(span, match_arg, match_arms);
1160+
return BlockOrExpr(ThinVec::new(), Some(expr));
11511161
}
11521162

11531163
let prefixes = iter::once("__self".to_string())

compiler/rustc_builtin_macros/src/standard_library_imports.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,29 @@ pub fn inject(
4444

4545
// .rev() to preserve ordering above in combination with insert(0, ...)
4646
for &name in names.iter().rev() {
47-
let ident = if edition >= Edition2018 {
48-
Ident::new(name, span)
47+
let ident_span = if edition >= Edition2018 { span } else { call_site };
48+
let item = if name == sym::compiler_builtins {
49+
// compiler_builtins is a private implementation detail. We only
50+
// need to insert it into the crate graph for linking and should not
51+
// expose any of its public API.
52+
//
53+
// FIXME(#113634) We should inject this during post-processing like
54+
// we do for the panic runtime, profiler runtime, etc.
55+
cx.item(
56+
span,
57+
Ident::new(kw::Underscore, ident_span),
58+
thin_vec![],
59+
ast::ItemKind::ExternCrate(Some(name)),
60+
)
4961
} else {
50-
Ident::new(name, call_site)
51-
};
52-
krate.items.insert(
53-
0,
5462
cx.item(
5563
span,
56-
ident,
64+
Ident::new(name, ident_span),
5765
thin_vec![cx.attr_word(sym::macro_use, span)],
5866
ast::ItemKind::ExternCrate(None),
59-
),
60-
);
67+
)
68+
};
69+
krate.items.insert(0, item);
6170
}
6271

6372
// The crates have been injected, the assumption is that the first one is

compiler/rustc_codegen_cranelift/src/driver/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! [`codegen_static`]: crate::constant::codegen_static
66
77
use rustc_data_structures::profiling::SelfProfilerRef;
8-
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
8+
use rustc_middle::mir::mono::{MonoItem, MonoItemData};
99

1010
use crate::prelude::*;
1111

@@ -16,11 +16,11 @@ pub(crate) mod jit;
1616
fn predefine_mono_items<'tcx>(
1717
tcx: TyCtxt<'tcx>,
1818
module: &mut dyn Module,
19-
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
19+
mono_items: &[(MonoItem<'tcx>, MonoItemData)],
2020
) {
2121
tcx.prof.generic_activity("predefine functions").run(|| {
2222
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
23-
for &(mono_item, (linkage, visibility)) in mono_items {
23+
for &(mono_item, data) in mono_items {
2424
match mono_item {
2525
MonoItem::Fn(instance) => {
2626
let name = tcx.symbol_name(instance).name;
@@ -29,8 +29,8 @@ fn predefine_mono_items<'tcx>(
2929
get_function_sig(tcx, module.target_config().default_call_conv, instance);
3030
let linkage = crate::linkage::get_clif_linkage(
3131
mono_item,
32-
linkage,
33-
visibility,
32+
data.linkage,
33+
data.visibility,
3434
is_compiler_builtins,
3535
);
3636
module.declare_function(name, linkage, &sig).unwrap();

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, supports_128bit_i
159159
let cx = CodegenCx::new(&context, cgu, tcx, supports_128bit_integers);
160160

161161
let mono_items = cgu.items_in_deterministic_order(tcx);
162-
for &(mono_item, (linkage, visibility)) in &mono_items {
163-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, linkage, visibility);
162+
for &(mono_item, data) in &mono_items {
163+
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
164164
}
165165

166166
// ... and now that we have everything pre-defined, fill out those definitions.

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
8686
{
8787
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
8888
let mono_items = cx.codegen_unit.items_in_deterministic_order(cx.tcx);
89-
for &(mono_item, (linkage, visibility)) in &mono_items {
90-
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, linkage, visibility);
89+
for &(mono_item, data) in &mono_items {
90+
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
9191
}
9292

9393
// ... and now that we have everything pre-defined, fill out those definitions.

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,11 @@ fn print_native_static_libs(
13921392
let mut lib_args: Vec<_> = all_native_libs
13931393
.iter()
13941394
.filter(|l| relevant_lib(sess, l))
1395+
// Deduplication of successive repeated libraries, see rust-lang/rust#113209
1396+
//
1397+
// note: we don't use PartialEq/Eq because NativeLib transitively depends on local
1398+
// elements like spans, which we don't care about and would make the deduplication impossible
1399+
.dedup_by(|l1, l2| l1.name == l2.name && l1.kind == l2.kind && l1.verbatim == l2.verbatim)
13951400
.filter_map(|lib| {
13961401
let name = lib.name;
13971402
match lib.kind {

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ fn exported_symbols_provider_local(
328328

329329
let (_, cgus) = tcx.collect_and_partition_mono_items(());
330330

331-
for (mono_item, &(linkage, visibility)) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
332-
if linkage != Linkage::External {
331+
for (mono_item, data) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
332+
if data.linkage != Linkage::External {
333333
// We can only re-use things with external linkage, otherwise
334334
// we'll get a linker error
335335
continue;
336336
}
337337

338-
if need_visibility && visibility == Visibility::Hidden {
338+
if need_visibility && data.visibility == Visibility::Hidden {
339339
// If we potentially share things from Rust dylibs, they must
340340
// not be hidden
341341
continue;

compiler/rustc_const_eval/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ const_eval_unallowed_mutable_refs_raw =
399399
const_eval_unallowed_op_in_const_context =
400400
{$msg}
401401
402+
const_eval_unavailable_target_features_for_fn =
403+
calling a function that requires unavailable target features: {$unavailable_feats}
404+
402405
const_eval_undefined_behavior =
403406
it is undefined behavior to use this value
404407

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
503503
}
504504
}
505505

506+
// Check that all target features required by the callee (i.e., from
507+
// the attribute `#[target_feature(enable = ...)]`) are enabled at
508+
// compile time.
509+
self.check_fn_target_features(instance)?;
510+
506511
if !callee_fn_abi.can_unwind {
507512
// The callee cannot unwind, so force the `Unreachable` unwind handling.
508513
unwind = mir::UnwindAction::Unreachable;
@@ -786,6 +791,31 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
786791
}
787792
}
788793

794+
fn check_fn_target_features(&self, instance: ty::Instance<'tcx>) -> InterpResult<'tcx, ()> {
795+
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
796+
if attrs
797+
.target_features
798+
.iter()
799+
.any(|feature| !self.tcx.sess.target_features.contains(feature))
800+
{
801+
throw_ub_custom!(
802+
fluent::const_eval_unavailable_target_features_for_fn,
803+
unavailable_feats = attrs
804+
.target_features
805+
.iter()
806+
.filter(|&feature| !self.tcx.sess.target_features.contains(feature))
807+
.fold(String::new(), |mut s, feature| {
808+
if !s.is_empty() {
809+
s.push_str(", ");
810+
}
811+
s.push_str(feature.as_str());
812+
s
813+
}),
814+
);
815+
}
816+
Ok(())
817+
}
818+
789819
fn drop_in_place(
790820
&mut self,
791821
place: &PlaceTy<'tcx, M::Provenance>,

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
625625
ErrorFollowing,
626626
INTERNAL_UNSTABLE
627627
),
628+
rustc_attr!(
629+
rustc_confusables, Normal,
630+
template!(List: r#""name1", "name2", ..."#),
631+
ErrorFollowing,
632+
INTERNAL_UNSTABLE,
633+
),
628634
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
629635
rustc_attr!(
630636
rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_attr as attr;
88
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, DefKind, Res};
11-
use rustc_hir::def_id::{DefId, LocalDefId};
11+
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
1212
use rustc_hir::intravisit::Visitor;
1313
use rustc_hir::{ItemKind, Node, PathSegment};
1414
use rustc_infer::infer::opaque_types::ConstrainOpaqueTypeRegionVisitor;
@@ -1378,6 +1378,9 @@ pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
13781378
for id in module.items() {
13791379
check_item_type(tcx, id);
13801380
}
1381+
if module_def_id == CRATE_DEF_ID {
1382+
super::entry::check_for_entry_fn(tcx);
1383+
}
13811384
}
13821385

13831386
fn async_opaque_type_cycle_error(tcx: TyCtxt<'_>, span: Span) -> ErrorGuaranteed {

0 commit comments

Comments
 (0)