Skip to content

Commit 3de9780

Browse files
committed
Auto merge of rust-lang#132420 - matthiaskrgr:rollup-w1vqgx9, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#131168 (Fix `target_os` for `mipsel-sony-psx`) - rust-lang#132209 (Fix validation when lowering `?` trait bounds) - rust-lang#132357 (Improve missing_abi lint) - rust-lang#132385 (compiler: Move `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi`) - rust-lang#132417 (macOS: Document the difference between Clang's `-darwin` and `-macosx` targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a0d98ff + f7c3fa2 commit 3de9780

Some content is hidden

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

46 files changed

+196
-107
lines changed

Cargo.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -3204,9 +3204,11 @@ dependencies = [
32043204
"rand",
32053205
"rand_xoshiro",
32063206
"rustc_data_structures",
3207+
"rustc_feature",
32073208
"rustc_index",
32083209
"rustc_macros",
32093210
"rustc_serialize",
3211+
"rustc_span",
32103212
"tracing",
32113213
]
32123214

@@ -3749,11 +3751,11 @@ dependencies = [
37493751
name = "rustc_hir_pretty"
37503752
version = "0.0.0"
37513753
dependencies = [
3754+
"rustc_abi",
37523755
"rustc_ast",
37533756
"rustc_ast_pretty",
37543757
"rustc_hir",
37553758
"rustc_span",
3756-
"rustc_target",
37573759
]
37583760

37593761
[[package]]
@@ -3938,14 +3940,14 @@ dependencies = [
39383940
name = "rustc_lint_defs"
39393941
version = "0.0.0"
39403942
dependencies = [
3943+
"rustc_abi",
39413944
"rustc_ast",
39423945
"rustc_data_structures",
39433946
"rustc_error_messages",
39443947
"rustc_hir",
39453948
"rustc_macros",
39463949
"rustc_serialize",
39473950
"rustc_span",
3948-
"rustc_target",
39493951
"serde",
39503952
]
39513953

@@ -4054,6 +4056,7 @@ version = "0.0.0"
40544056
dependencies = [
40554057
"either",
40564058
"itertools",
4059+
"rustc_abi",
40574060
"rustc_apfloat",
40584061
"rustc_arena",
40594062
"rustc_ast",
@@ -4069,7 +4072,6 @@ dependencies = [
40694072
"rustc_pattern_analysis",
40704073
"rustc_session",
40714074
"rustc_span",
4072-
"rustc_target",
40734075
"rustc_trait_selection",
40744076
"tracing",
40754077
]

compiler/rustc_abi/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ bitflags = "2.4.1"
99
rand = { version = "0.8.4", default-features = false, optional = true }
1010
rand_xoshiro = { version = "0.6.0", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
12+
rustc_feature = { path = "../rustc_feature", optional = true }
1213
rustc_index = { path = "../rustc_index", default-features = false }
1314
rustc_macros = { path = "../rustc_macros", optional = true }
1415
rustc_serialize = { path = "../rustc_serialize", optional = true }
16+
rustc_span = { path = "../rustc_span", optional = true }
1517
tracing = "0.1"
1618
# tidy-alphabetical-end
1719

@@ -22,8 +24,10 @@ default = ["nightly", "randomize"]
2224
# without depending on rustc_data_structures, rustc_macros and rustc_serialize
2325
nightly = [
2426
"dep:rustc_data_structures",
27+
"dep:rustc_feature",
2528
"dep:rustc_macros",
2629
"dep:rustc_serialize",
30+
"dep:rustc_span",
2731
"rustc_index/nightly",
2832
]
2933
randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]

compiler/rustc_target/src/spec/abi/mod.rs compiler/rustc_abi/src/extern_abi/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use rustc_span::{Span, Symbol};
77
#[cfg(test)]
88
mod tests;
99

10+
use ExternAbi as Abi;
11+
1012
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
1113
#[derive(HashStable_Generic, Encodable, Decodable)]
12-
pub enum Abi {
14+
pub enum ExternAbi {
1315
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
1416
// hashing tests. These are used in many places, so giving them stable values reduces test
1517
// churn. The specific values are meaningless.

compiler/rustc_abi/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![cfg_attr(feature = "nightly", allow(internal_features))]
33
#![cfg_attr(feature = "nightly", doc(rust_logo))]
4+
#![cfg_attr(feature = "nightly", feature(assert_matches))]
45
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
56
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
67
#![cfg_attr(feature = "nightly", feature(step_trait))]
@@ -28,8 +29,15 @@ mod layout;
2829
#[cfg(test)]
2930
mod tests;
3031

32+
#[cfg(feature = "nightly")]
33+
mod extern_abi;
34+
3135
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
3236
#[cfg(feature = "nightly")]
37+
pub use extern_abi::{
38+
AbiDisabled, AbiUnsupported, ExternAbi, all_names, enabled_names, is_enabled, is_stable, lookup,
39+
};
40+
#[cfg(feature = "nightly")]
3341
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
3442
pub use layout::{LayoutCalculator, LayoutCalculatorError};
3543

compiler/rustc_ast/src/ast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,8 @@ pub struct ModSpans {
28102810
/// E.g., `extern { .. }` or `extern "C" { .. }`.
28112811
#[derive(Clone, Encodable, Decodable, Debug)]
28122812
pub struct ForeignMod {
2813+
/// Span of the `extern` keyword.
2814+
pub extern_span: Span,
28132815
/// `unsafe` keyword accepted syntactically for macro DSLs, but not
28142816
/// semantically by Rust.
28152817
pub safety: Safety,

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
525525
}
526526

527527
fn walk_foreign_mod<T: MutVisitor>(vis: &mut T, foreign_mod: &mut ForeignMod) {
528-
let ForeignMod { safety, abi: _, items } = foreign_mod;
528+
let ForeignMod { extern_span: _, safety, abi: _, items } = foreign_mod;
529529
visit_safety(vis, safety);
530530
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
531531
}

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl WalkItemKind for ItemKind {
366366
}
367367
ModKind::Unloaded => {}
368368
},
369-
ItemKind::ForeignMod(ForeignMod { safety: _, abi: _, items }) => {
369+
ItemKind::ForeignMod(ForeignMod { extern_span: _, safety: _, abi: _, items }) => {
370370
walk_list!(visitor, visit_foreign_item, items);
371371
}
372372
ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),

compiler/rustc_ast_passes/src/ast_validation.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,8 @@ impl<'a> AstValidator<'a> {
677677
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
678678
self.dcx().emit_err(errors::PatternFnPointer { span });
679679
});
680-
if let Extern::Implicit(_) = bfty.ext {
681-
let sig_span = self.sess.source_map().next_point(ty.span.shrink_to_lo());
682-
self.maybe_lint_missing_abi(sig_span, ty.id);
680+
if let Extern::Implicit(extern_span) = bfty.ext {
681+
self.maybe_lint_missing_abi(extern_span, ty.id);
683682
}
684683
}
685684
TyKind::TraitObject(bounds, ..) => {
@@ -953,7 +952,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
953952
walk_list!(self, visit_attribute, &item.attrs);
954953
return; // Avoid visiting again.
955954
}
956-
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => {
955+
ItemKind::ForeignMod(ForeignMod { extern_span, abi, safety, .. }) => {
957956
self.with_in_extern_mod(*safety, |this| {
958957
let old_item = mem::replace(&mut this.extern_mod, Some(item.span));
959958
this.visibility_not_permitted(
@@ -977,7 +976,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
977976
}
978977

979978
if abi.is_none() {
980-
this.maybe_lint_missing_abi(item.span, item.id);
979+
this.maybe_lint_missing_abi(*extern_span, item.id);
981980
}
982981
visit::walk_item(this, item);
983982
this.extern_mod = old_item;
@@ -1350,13 +1349,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13501349
if let FnKind::Fn(
13511350
_,
13521351
_,
1353-
FnSig { span: sig_span, header: FnHeader { ext: Extern::Implicit(_), .. }, .. },
1352+
FnSig { header: FnHeader { ext: Extern::Implicit(extern_span), .. }, .. },
13541353
_,
13551354
_,
13561355
_,
13571356
) = fk
13581357
{
1359-
self.maybe_lint_missing_abi(*sig_span, id);
1358+
self.maybe_lint_missing_abi(*extern_span, id);
13601359
}
13611360

13621361
// Functions without bodies cannot have patterns.

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

-6
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
168168
match hir_bound {
169169
hir::GenericBound::Trait(poly_trait_ref) => {
170170
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
171-
let polarity = match polarity {
172-
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
173-
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,
174-
rustc_ast::BoundPolarity::Maybe(_) => continue,
175-
};
176-
177171
let _ = self.lower_poly_trait_ref(
178172
&poly_trait_ref.trait_ref,
179173
poly_trait_ref.span,

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
5151
&trait_bound.trait_ref,
5252
trait_bound.span,
5353
hir::BoundConstness::Never,
54-
ty::PredicatePolarity::Positive,
54+
hir::BoundPolarity::Positive,
5555
dummy_self,
5656
&mut bounds,
5757
PredicateFilter::SelfOnly,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+34-13
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
668668
trait_ref: &hir::TraitRef<'tcx>,
669669
span: Span,
670670
constness: hir::BoundConstness,
671-
polarity: ty::PredicatePolarity,
671+
polarity: hir::BoundPolarity,
672672
self_ty: Ty<'tcx>,
673673
bounds: &mut Bounds<'tcx>,
674674
predicate_filter: PredicateFilter,
@@ -690,15 +690,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
690690
Some(self_ty),
691691
);
692692

693-
if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
694-
&& !self.tcx().is_const_trait(trait_def_id)
695-
{
696-
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
697-
span,
698-
modifier: constness.as_str(),
699-
});
700-
}
701-
702693
let tcx = self.tcx();
703694
let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
704695
debug!(?bound_vars);
@@ -708,6 +699,36 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
708699
bound_vars,
709700
);
710701

702+
let polarity = match polarity {
703+
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
704+
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,
705+
rustc_ast::BoundPolarity::Maybe(_) => {
706+
// Validate associated type at least. We may want to reject these
707+
// outright in the future...
708+
for constraint in trait_segment.args().constraints {
709+
let _ = self.lower_assoc_item_constraint(
710+
trait_ref.hir_ref_id,
711+
poly_trait_ref,
712+
constraint,
713+
&mut Default::default(),
714+
&mut Default::default(),
715+
constraint.span,
716+
predicate_filter,
717+
);
718+
}
719+
return arg_count;
720+
}
721+
};
722+
723+
if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
724+
&& !self.tcx().is_const_trait(trait_def_id)
725+
{
726+
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
727+
span,
728+
modifier: constness.as_str(),
729+
});
730+
}
731+
711732
match predicate_filter {
712733
PredicateFilter::All
713734
| PredicateFilter::SelfOnly
@@ -763,11 +784,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
763784
// since we should have emitted an error for them earlier, and they
764785
// would not be well-formed!
765786
if polarity != ty::PredicatePolarity::Positive {
766-
assert!(
767-
self.dcx().has_errors().is_some(),
787+
self.dcx().span_delayed_bug(
788+
constraint.span,
768789
"negative trait bounds should not have assoc item constraints",
769790
);
770-
continue;
791+
break;
771792
}
772793

773794
// Specify type to assert that error was already reported in `Err` case.

compiler/rustc_hir_pretty/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1011
rustc_hir = { path = "../rustc_hir" }
1112
rustc_span = { path = "../rustc_span" }
12-
rustc_target = { path = "../rustc_target" }
1313
# tidy-alphabetical-end

compiler/rustc_hir_pretty/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use std::cell::Cell;
1010
use std::vec;
1111

12+
use rustc_abi::ExternAbi;
1213
use rustc_ast::util::parser::{self, AssocOp, Fixity};
1314
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
1415
use rustc_ast_pretty::pp::{self, Breaks};
@@ -20,7 +21,6 @@ use rustc_hir::{
2021
use rustc_span::FileName;
2122
use rustc_span::source_map::SourceMap;
2223
use rustc_span::symbol::{Ident, Symbol, kw};
23-
use rustc_target::spec::abi::Abi;
2424
use {rustc_ast as ast, rustc_hir as hir};
2525

2626
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String {
@@ -2240,7 +2240,7 @@ impl<'a> State<'a> {
22402240

22412241
fn print_ty_fn(
22422242
&mut self,
2243-
abi: Abi,
2243+
abi: ExternAbi,
22442244
safety: hir::Safety,
22452245
decl: &hir::FnDecl<'_>,
22462246
name: Option<Symbol>,
@@ -2276,7 +2276,7 @@ impl<'a> State<'a> {
22762276

22772277
self.print_safety(header.safety);
22782278

2279-
if header.abi != Abi::Rust {
2279+
if header.abi != ExternAbi::Rust {
22802280
self.word_nbsp("extern");
22812281
self.word_nbsp(header.abi.to_string());
22822282
}

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edi
268268
269269
lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
270270
.label = ABI should be specified here
271-
.help = the default ABI is {$default_abi}
271+
.suggestion = explicitly specify the {$default_abi} ABI
272272
273273
lint_for_loops_over_fallibles =
274274
for loop over {$article} `{$ref_prefix}{$ty}`. This is more readably written as an `if let` statement

compiler/rustc_lint/src/lints.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2738,11 +2738,9 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
27382738

27392739
#[derive(LintDiagnostic)]
27402740
#[diag(lint_extern_without_abi)]
2741-
#[help]
27422741
pub(crate) struct MissingAbi {
2743-
#[label]
2742+
#[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")]
27442743
pub span: Span,
2745-
27462744
pub default_abi: &'static str,
27472745
}
27482746

compiler/rustc_lint_defs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_data_structures = { path = "../rustc_data_structures" }
1011
rustc_error_messages = { path = "../rustc_error_messages" }
1112
rustc_hir = { path = "../rustc_hir" }
1213
rustc_macros = { path = "../rustc_macros" }
1314
rustc_serialize = { path = "../rustc_serialize" }
1415
rustc_span = { path = "../rustc_span" }
15-
rustc_target = { path = "../rustc_target" }
1616
serde = { version = "1.0.125", features = ["derive"] }
1717
# tidy-alphabetical-end

compiler/rustc_lint_defs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![warn(unreachable_pub)]
33
// tidy-alphabetical-end
44

5+
use rustc_abi::ExternAbi;
56
use rustc_ast::node_id::NodeId;
67
use rustc_ast::{AttrId, Attribute};
78
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -15,7 +16,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1516
pub use rustc_span::edition::Edition;
1617
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
1718
use rustc_span::{Span, Symbol, sym};
18-
use rustc_target::spec::abi::Abi;
1919
use serde::{Deserialize, Serialize};
2020

2121
pub use self::Level::*;
@@ -602,7 +602,7 @@ pub enum BuiltinLintDiag {
602602
path: String,
603603
since_kind: DeprecatedSinceKind,
604604
},
605-
MissingAbi(Span, Abi),
605+
MissingAbi(Span, ExternAbi),
606606
UnusedDocComment(Span),
607607
UnusedBuiltinAttribute {
608608
attr_name: Symbol,

0 commit comments

Comments
 (0)