Skip to content

Commit caee496

Browse files
committedAug 4, 2022
Auto merge of rust-lang#100120 - matthiaskrgr:rollup-g6ycykq, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#98771 (Add support for link-flavor rust-lld for iOS, tvOS and watchOS) - rust-lang#98835 (relate `closure_substs.parent_substs()` to parent fn in NLL) - rust-lang#99746 (Use `TraitEngine` in more places that don't specifically need `FulfillmentContext::new_in_snapshot`) - rust-lang#99786 (Recover from C++ style `enum struct`) - rust-lang#99795 (Delay a bug when failed to normalize trait ref during specialization) - rust-lang#100029 (Prevent ICE for `doc_alias` on match arm, statement, expression) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1ad5635 + f8e6617 commit caee496

37 files changed

+496
-102
lines changed
 

‎compiler/rustc_borrowck/src/type_check/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,34 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26192619
);
26202620
}
26212621

2622+
// Now equate closure substs to regions inherited from `typeck_root_def_id`. Fixes #98589.
2623+
let typeck_root_def_id = tcx.typeck_root_def_id(self.body.source.def_id());
2624+
let typeck_root_substs = ty::InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
2625+
2626+
let parent_substs = match tcx.def_kind(def_id) {
2627+
DefKind::Closure => substs.as_closure().parent_substs(),
2628+
DefKind::Generator => substs.as_generator().parent_substs(),
2629+
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
2630+
other => bug!("unexpected item {:?}", other),
2631+
};
2632+
let parent_substs = tcx.mk_substs(parent_substs.iter());
2633+
2634+
assert_eq!(typeck_root_substs.len(), parent_substs.len());
2635+
if let Err(_) = self.eq_substs(
2636+
typeck_root_substs,
2637+
parent_substs,
2638+
location.to_locations(),
2639+
ConstraintCategory::BoringNoLocation,
2640+
) {
2641+
span_mirbug!(
2642+
self,
2643+
def_id,
2644+
"could not relate closure to parent {:?} != {:?}",
2645+
typeck_root_substs,
2646+
parent_substs
2647+
);
2648+
}
2649+
26222650
tcx.predicates_of(def_id).instantiate(tcx, substs)
26232651
}
26242652

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3838
.relate(a, b)?;
3939
Ok(())
4040
}
41+
42+
/// Add sufficient constraints to ensure `a == b`. See also [Self::relate_types].
43+
pub(super) fn eq_substs(
44+
&mut self,
45+
a: ty::SubstsRef<'tcx>,
46+
b: ty::SubstsRef<'tcx>,
47+
locations: Locations,
48+
category: ConstraintCategory<'tcx>,
49+
) -> Fallible<()> {
50+
TypeRelating::new(
51+
self.infcx,
52+
NllTypeRelatingDelegate::new(self, locations, category, UniverseInfo::other()),
53+
ty::Variance::Invariant,
54+
)
55+
.relate(a, b)?;
56+
Ok(())
57+
}
4158
}
4259

4360
struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {

‎compiler/rustc_codegen_ssa/src/back/link.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2675,7 +2675,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
26752675
let llvm_target = &sess.target.llvm_target;
26762676
if sess.target.vendor != "apple"
26772677
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos")
2678-
|| flavor != LinkerFlavor::Gcc
2678+
|| (flavor != LinkerFlavor::Gcc && flavor != LinkerFlavor::Lld(LldFlavor::Ld64))
26792679
{
26802680
return;
26812681
}
@@ -2706,13 +2706,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
27062706
return;
27072707
}
27082708
};
2709-
if llvm_target.contains("macabi") {
2710-
cmd.args(&["-target", llvm_target])
2711-
} else {
2712-
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
2713-
cmd.args(&["-arch", arch_name])
2709+
2710+
match flavor {
2711+
LinkerFlavor::Gcc => {
2712+
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
2713+
}
2714+
LinkerFlavor::Lld(LldFlavor::Ld64) => {
2715+
cmd.args(&["-syslibroot", &sdk_root]);
2716+
}
2717+
_ => unreachable!(),
27142718
}
2715-
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
27162719
}
27172720

27182721
fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {

‎compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::*;
1010
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
1111
use rustc_span::DUMMY_SP;
1212
use rustc_trait_selection::traits::{
13-
self, FulfillmentContext, ImplSource, Obligation, ObligationCause, SelectionContext,
13+
self, ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngineExt,
1414
};
1515

1616
use super::ConstCx;
@@ -191,7 +191,7 @@ impl Qualif for NeedsNonConstDrop {
191191

192192
// If we successfully found one, then select all of the predicates
193193
// implied by our const drop impl.
194-
let mut fcx = FulfillmentContext::new();
194+
let mut fcx = <dyn TraitEngine<'tcx>>::new(cx.tcx);
195195
for nested in impl_src.nested_obligations() {
196196
fcx.register_predicate_obligation(&infcx, nested);
197197
}

‎compiler/rustc_hir/src/target.rs

+45-45
Original file line numberDiff line numberDiff line change
@@ -60,51 +60,7 @@ pub enum Target {
6060

6161
impl Display for Target {
6262
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63-
write!(
64-
f,
65-
"{}",
66-
match *self {
67-
Target::ExternCrate => "extern crate",
68-
Target::Use => "use",
69-
Target::Static => "static item",
70-
Target::Const => "constant item",
71-
Target::Fn => "function",
72-
Target::Closure => "closure",
73-
Target::Mod => "module",
74-
Target::ForeignMod => "foreign module",
75-
Target::GlobalAsm => "global asm",
76-
Target::TyAlias => "type alias",
77-
Target::OpaqueTy => "opaque type",
78-
Target::Enum => "enum",
79-
Target::Variant => "enum variant",
80-
Target::Struct => "struct",
81-
Target::Field => "struct field",
82-
Target::Union => "union",
83-
Target::Trait => "trait",
84-
Target::TraitAlias => "trait alias",
85-
Target::Impl => "item",
86-
Target::Expression => "expression",
87-
Target::Statement => "statement",
88-
Target::Arm => "match arm",
89-
Target::AssocConst => "associated const",
90-
Target::Method(kind) => match kind {
91-
MethodKind::Inherent => "inherent method",
92-
MethodKind::Trait { body: false } => "required trait method",
93-
MethodKind::Trait { body: true } => "provided trait method",
94-
},
95-
Target::AssocTy => "associated type",
96-
Target::ForeignFn => "foreign function",
97-
Target::ForeignStatic => "foreign static item",
98-
Target::ForeignTy => "foreign type",
99-
Target::GenericParam(kind) => match kind {
100-
GenericParamKind::Type => "type parameter",
101-
GenericParamKind::Lifetime => "lifetime parameter",
102-
GenericParamKind::Const => "const parameter",
103-
},
104-
Target::MacroDef => "macro def",
105-
Target::Param => "function param",
106-
}
107-
)
63+
write!(f, "{}", Self::name(*self))
10864
}
10965
}
11066

@@ -185,4 +141,48 @@ impl Target {
185141
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
186142
}
187143
}
144+
145+
pub fn name(self) -> &'static str {
146+
match self {
147+
Target::ExternCrate => "extern crate",
148+
Target::Use => "use",
149+
Target::Static => "static item",
150+
Target::Const => "constant item",
151+
Target::Fn => "function",
152+
Target::Closure => "closure",
153+
Target::Mod => "module",
154+
Target::ForeignMod => "foreign module",
155+
Target::GlobalAsm => "global asm",
156+
Target::TyAlias => "type alias",
157+
Target::OpaqueTy => "opaque type",
158+
Target::Enum => "enum",
159+
Target::Variant => "enum variant",
160+
Target::Struct => "struct",
161+
Target::Field => "struct field",
162+
Target::Union => "union",
163+
Target::Trait => "trait",
164+
Target::TraitAlias => "trait alias",
165+
Target::Impl => "implementation block",
166+
Target::Expression => "expression",
167+
Target::Statement => "statement",
168+
Target::Arm => "match arm",
169+
Target::AssocConst => "associated const",
170+
Target::Method(kind) => match kind {
171+
MethodKind::Inherent => "inherent method",
172+
MethodKind::Trait { body: false } => "required trait method",
173+
MethodKind::Trait { body: true } => "provided trait method",
174+
},
175+
Target::AssocTy => "associated type",
176+
Target::ForeignFn => "foreign function",
177+
Target::ForeignStatic => "foreign static item",
178+
Target::ForeignTy => "foreign type",
179+
Target::GenericParam(kind) => match kind {
180+
GenericParamKind::Type => "type parameter",
181+
GenericParamKind::Lifetime => "lifetime parameter",
182+
GenericParamKind::Const => "const parameter",
183+
},
184+
Target::MacroDef => "macro def",
185+
Target::Param => "function param",
186+
}
187+
}
188188
}

‎compiler/rustc_parse/src/parser/item.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,25 @@ impl<'a> Parser<'a> {
12161216

12171217
/// Parses an enum declaration.
12181218
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
1219+
if self.token.is_keyword(kw::Struct) {
1220+
let mut err = self.struct_span_err(
1221+
self.prev_token.span.to(self.token.span),
1222+
"`enum` and `struct` are mutually exclusive",
1223+
);
1224+
err.span_suggestion(
1225+
self.prev_token.span.to(self.token.span),
1226+
"replace `enum struct` with",
1227+
"enum",
1228+
Applicability::MachineApplicable,
1229+
);
1230+
if self.look_ahead(1, |t| t.is_ident()) {
1231+
self.bump();
1232+
err.emit();
1233+
} else {
1234+
return Err(err);
1235+
}
1236+
}
1237+
12191238
let id = self.parse_ident()?;
12201239
let mut generics = self.parse_generics()?;
12211240
generics.where_clause = self.parse_where_clause()?;

‎compiler/rustc_passes/src/check_attr.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,6 @@ impl CheckAttrVisitor<'_> {
596596

597597
let span = meta.span();
598598
if let Some(location) = match target {
599-
Target::Impl => Some("implementation block"),
600-
Target::ForeignMod => Some("extern block"),
601599
Target::AssocTy => {
602600
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
603601
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
@@ -619,7 +617,34 @@ impl CheckAttrVisitor<'_> {
619617
}
620618
// we check the validity of params elsewhere
621619
Target::Param => return false,
622-
_ => None,
620+
Target::Expression
621+
| Target::Statement
622+
| Target::Arm
623+
| Target::ForeignMod
624+
| Target::Closure
625+
| Target::Impl => Some(target.name()),
626+
Target::ExternCrate
627+
| Target::Use
628+
| Target::Static
629+
| Target::Const
630+
| Target::Fn
631+
| Target::Mod
632+
| Target::GlobalAsm
633+
| Target::TyAlias
634+
| Target::OpaqueTy
635+
| Target::Enum
636+
| Target::Variant
637+
| Target::Struct
638+
| Target::Field
639+
| Target::Union
640+
| Target::Trait
641+
| Target::TraitAlias
642+
| Target::Method(..)
643+
| Target::ForeignFn
644+
| Target::ForeignStatic
645+
| Target::ForeignTy
646+
| Target::GenericParam(..)
647+
| Target::MacroDef => None,
623648
} {
624649
tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location });
625650
return false;

‎compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
use super::apple_sdk_base::{opts, Arch};
2-
use crate::spec::{FramePointer, Target, TargetOptions};
2+
use crate::spec::{FramePointer, LinkerFlavor, Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let llvm_target = "arm64-apple-ios14.0-macabi";
6+
7+
let mut base = opts("ios", Arch::Arm64_macabi);
8+
base.add_pre_link_args(LinkerFlavor::Gcc, &["-target", llvm_target]);
9+
510
Target {
6-
llvm_target: "arm64-apple-ios14.0-macabi".into(),
11+
llvm_target: llvm_target.into(),
712
pointer_width: 64,
813
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
914
arch: "aarch64".into(),
@@ -21,7 +26,7 @@ pub fn target() -> Target {
2126
-disable-llvm-passes\0\
2227
-Os\0"
2328
.into(),
24-
..opts("ios", Arch::Arm64_macabi)
29+
..base
2530
},
2631
}
2732
}

‎compiler/rustc_target/src/spec/apple_base.rs

+19
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,34 @@ pub fn ios_llvm_target(arch: &str) -> String {
109109
format!("{}-apple-ios{}.{}.0", arch, major, minor)
110110
}
111111

112+
pub fn ios_lld_platform_version() -> String {
113+
let (major, minor) = ios_deployment_target();
114+
format!("{}.{}", major, minor)
115+
}
116+
112117
pub fn ios_sim_llvm_target(arch: &str) -> String {
113118
let (major, minor) = ios_deployment_target();
114119
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
115120
}
116121

122+
fn tvos_deployment_target() -> (u32, u32) {
123+
deployment_target("TVOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
124+
}
125+
126+
pub fn tvos_lld_platform_version() -> String {
127+
let (major, minor) = tvos_deployment_target();
128+
format!("{}.{}", major, minor)
129+
}
130+
117131
fn watchos_deployment_target() -> (u32, u32) {
118132
deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
119133
}
120134

135+
pub fn watchos_lld_platform_version() -> String {
136+
let (major, minor) = watchos_deployment_target();
137+
format!("{}.{}", major, minor)
138+
}
139+
121140
pub fn watchos_sim_llvm_target(arch: &str) -> String {
122141
let (major, minor) = watchos_deployment_target();
123142
format!("{}-apple-watchos{}.{}.0-simulator", arch, major, minor)

0 commit comments

Comments
 (0)
Please sign in to comment.