Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #100120

Merged
merged 19 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
58f107a
Use TraitEngine in more places that don't specifically need Fulfillme…
compiler-errors Jul 26, 2022
254b89d
Recover from c++ style `enum struct`
obeis Jul 26, 2022
0ad06f1
Add ui test for #99625
obeis Jul 26, 2022
e98b0e8
Prevent ICE for doc_alias on match arm, statement, expression
hdelc Jul 30, 2022
f74d06c
NLL: relate closure to parent fn
aliemjay Jul 3, 2022
28f24eb
fix rustdoc regression
aliemjay Jul 3, 2022
6b37a79
Refactor `Display` impl for `Target` to `Target::name` method
hdelc Aug 2, 2022
c643007
Add exhaustive location checking for `doc_alias` attribute
hdelc Aug 2, 2022
1e8abe7
Make `Target::name` method pass by copy
hdelc Aug 2, 2022
16a3601
Delay a bug when failed to normalize trait ref during specialization
compiler-errors Jul 27, 2022
2be0094
Add items to `DocAliasBadLocation` check error match arm
hdelc Aug 3, 2022
78adc01
cosmetic changes
aliemjay Aug 3, 2022
78bbe57
Add support for link-flavor rust-lld for iOS, tvOS and watchOS
marysaka Jul 1, 2022
7b0360e
Rollup merge of #98771 - Thog:rust-lld-apple-target, r=petrochenkov
matthiaskrgr Aug 3, 2022
88e9417
Rollup merge of #98835 - aliemjay:relate_closure_substs, r=nikomatsakis
matthiaskrgr Aug 3, 2022
0de7f75
Rollup merge of #99746 - compiler-errors:more-trait-engine, r=jackh726
matthiaskrgr Aug 3, 2022
9c18fdc
Rollup merge of #99786 - obeis:issue-99625, r=compiler-errors
matthiaskrgr Aug 3, 2022
02fcec2
Rollup merge of #99795 - compiler-errors:delay-specialization-normali…
matthiaskrgr Aug 3, 2022
f8e6617
Rollup merge of #100029 - hdelc:master, r=cjgillot
matthiaskrgr Aug 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,34 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}

// Now equate closure substs to regions inherited from `typeck_root_def_id`. Fixes #98589.
let typeck_root_def_id = tcx.typeck_root_def_id(self.body.source.def_id());
let typeck_root_substs = ty::InternalSubsts::identity_for_item(tcx, typeck_root_def_id);

let parent_substs = match tcx.def_kind(def_id) {
DefKind::Closure => substs.as_closure().parent_substs(),
DefKind::Generator => substs.as_generator().parent_substs(),
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
other => bug!("unexpected item {:?}", other),
};
let parent_substs = tcx.mk_substs(parent_substs.iter());

assert_eq!(typeck_root_substs.len(), parent_substs.len());
if let Err(_) = self.eq_substs(
typeck_root_substs,
parent_substs,
location.to_locations(),
ConstraintCategory::BoringNoLocation,
) {
span_mirbug!(
self,
def_id,
"could not relate closure to parent {:?} != {:?}",
typeck_root_substs,
parent_substs
);
}

tcx.predicates_of(def_id).instantiate(tcx, substs)
}

Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.relate(a, b)?;
Ok(())
}

/// Add sufficient constraints to ensure `a == b`. See also [Self::relate_types].
pub(super) fn eq_substs(
&mut self,
a: ty::SubstsRef<'tcx>,
b: ty::SubstsRef<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
) -> Fallible<()> {
TypeRelating::new(
self.infcx,
NllTypeRelatingDelegate::new(self, locations, category, UniverseInfo::other()),
ty::Variance::Invariant,
)
.relate(a, b)?;
Ok(())
}
}

struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2675,7 +2675,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
let llvm_target = &sess.target.llvm_target;
if sess.target.vendor != "apple"
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos")
|| flavor != LinkerFlavor::Gcc
|| (flavor != LinkerFlavor::Gcc && flavor != LinkerFlavor::Lld(LldFlavor::Ld64))
{
return;
}
Expand Down Expand Up @@ -2706,13 +2706,16 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
return;
}
};
if llvm_target.contains("macabi") {
cmd.args(&["-target", llvm_target])
} else {
let arch_name = llvm_target.split('-').next().expect("LLVM target must have a hyphen");
cmd.args(&["-arch", arch_name])

match flavor {
LinkerFlavor::Gcc => {
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
}
LinkerFlavor::Lld(LldFlavor::Ld64) => {
cmd.args(&["-syslibroot", &sdk_root]);
}
_ => unreachable!(),
}
cmd.args(&["-isysroot", &sdk_root, "-Wl,-syslibroot", &sdk_root]);
}

fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
use rustc_span::DUMMY_SP;
use rustc_trait_selection::traits::{
self, FulfillmentContext, ImplSource, Obligation, ObligationCause, SelectionContext,
self, ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngineExt,
};

use super::ConstCx;
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Qualif for NeedsNonConstDrop {

// If we successfully found one, then select all of the predicates
// implied by our const drop impl.
let mut fcx = FulfillmentContext::new();
let mut fcx = <dyn TraitEngine<'tcx>>::new(cx.tcx);
for nested in impl_src.nested_obligations() {
fcx.register_predicate_obligation(&infcx, nested);
}
Expand Down
90 changes: 45 additions & 45 deletions compiler/rustc_hir/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,51 +60,7 @@ pub enum Target {

impl Display for Target {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match *self {
Target::ExternCrate => "extern crate",
Target::Use => "use",
Target::Static => "static item",
Target::Const => "constant item",
Target::Fn => "function",
Target::Closure => "closure",
Target::Mod => "module",
Target::ForeignMod => "foreign module",
Target::GlobalAsm => "global asm",
Target::TyAlias => "type alias",
Target::OpaqueTy => "opaque type",
Target::Enum => "enum",
Target::Variant => "enum variant",
Target::Struct => "struct",
Target::Field => "struct field",
Target::Union => "union",
Target::Trait => "trait",
Target::TraitAlias => "trait alias",
Target::Impl => "item",
Target::Expression => "expression",
Target::Statement => "statement",
Target::Arm => "match arm",
Target::AssocConst => "associated const",
Target::Method(kind) => match kind {
MethodKind::Inherent => "inherent method",
MethodKind::Trait { body: false } => "required trait method",
MethodKind::Trait { body: true } => "provided trait method",
},
Target::AssocTy => "associated type",
Target::ForeignFn => "foreign function",
Target::ForeignStatic => "foreign static item",
Target::ForeignTy => "foreign type",
Target::GenericParam(kind) => match kind {
GenericParamKind::Type => "type parameter",
GenericParamKind::Lifetime => "lifetime parameter",
GenericParamKind::Const => "const parameter",
},
Target::MacroDef => "macro def",
Target::Param => "function param",
}
)
write!(f, "{}", Self::name(*self))
}
}

Expand Down Expand Up @@ -185,4 +141,48 @@ impl Target {
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
}
}

pub fn name(self) -> &'static str {
match self {
Target::ExternCrate => "extern crate",
Target::Use => "use",
Target::Static => "static item",
Target::Const => "constant item",
Target::Fn => "function",
Target::Closure => "closure",
Target::Mod => "module",
Target::ForeignMod => "foreign module",
Target::GlobalAsm => "global asm",
Target::TyAlias => "type alias",
Target::OpaqueTy => "opaque type",
Target::Enum => "enum",
Target::Variant => "enum variant",
Target::Struct => "struct",
Target::Field => "struct field",
Target::Union => "union",
Target::Trait => "trait",
Target::TraitAlias => "trait alias",
Target::Impl => "implementation block",
Target::Expression => "expression",
Target::Statement => "statement",
Target::Arm => "match arm",
Target::AssocConst => "associated const",
Target::Method(kind) => match kind {
MethodKind::Inherent => "inherent method",
MethodKind::Trait { body: false } => "required trait method",
MethodKind::Trait { body: true } => "provided trait method",
},
Target::AssocTy => "associated type",
Target::ForeignFn => "foreign function",
Target::ForeignStatic => "foreign static item",
Target::ForeignTy => "foreign type",
Target::GenericParam(kind) => match kind {
GenericParamKind::Type => "type parameter",
GenericParamKind::Lifetime => "lifetime parameter",
GenericParamKind::Const => "const parameter",
},
Target::MacroDef => "macro def",
Target::Param => "function param",
}
}
}
19 changes: 19 additions & 0 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,25 @@ impl<'a> Parser<'a> {

/// Parses an enum declaration.
fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
if self.token.is_keyword(kw::Struct) {
let mut err = self.struct_span_err(
self.prev_token.span.to(self.token.span),
"`enum` and `struct` are mutually exclusive",
);
err.span_suggestion(
self.prev_token.span.to(self.token.span),
"replace `enum struct` with",
"enum",
Applicability::MachineApplicable,
);
if self.look_ahead(1, |t| t.is_ident()) {
self.bump();
err.emit();
} else {
return Err(err);
}
}

let id = self.parse_ident()?;
let mut generics = self.parse_generics()?;
generics.where_clause = self.parse_where_clause()?;
Expand Down
31 changes: 28 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,6 @@ impl CheckAttrVisitor<'_> {

let span = meta.span();
if let Some(location) = match target {
Target::Impl => Some("implementation block"),
Target::ForeignMod => Some("extern block"),
Target::AssocTy => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
Expand All @@ -619,7 +617,34 @@ impl CheckAttrVisitor<'_> {
}
// we check the validity of params elsewhere
Target::Param => return false,
_ => None,
Target::Expression
| Target::Statement
| Target::Arm
| Target::ForeignMod
| Target::Closure
| Target::Impl => Some(target.name()),
Target::ExternCrate
| Target::Use
| Target::Static
| Target::Const
| Target::Fn
| Target::Mod
| Target::GlobalAsm
| Target::TyAlias
| Target::OpaqueTy
| Target::Enum
| Target::Variant
| Target::Struct
| Target::Field
| Target::Union
| Target::Trait
| Target::TraitAlias
| Target::Method(..)
| Target::ForeignFn
| Target::ForeignStatic
| Target::ForeignTy
| Target::GenericParam(..)
| Target::MacroDef => None,
} {
tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location });
return false;
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{FramePointer, Target, TargetOptions};
use crate::spec::{FramePointer, LinkerFlavor, Target, TargetOptions};

pub fn target() -> Target {
let llvm_target = "arm64-apple-ios14.0-macabi";

let mut base = opts("ios", Arch::Arm64_macabi);
base.add_pre_link_args(LinkerFlavor::Gcc, &["-target", llvm_target]);

Target {
llvm_target: "arm64-apple-ios14.0-macabi".into(),
llvm_target: llvm_target.into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
Expand All @@ -21,7 +26,7 @@ pub fn target() -> Target {
-disable-llvm-passes\0\
-Os\0"
.into(),
..opts("ios", Arch::Arm64_macabi)
..base
},
}
}
19 changes: 19 additions & 0 deletions compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,34 @@ pub fn ios_llvm_target(arch: &str) -> String {
format!("{}-apple-ios{}.{}.0", arch, major, minor)
}

pub fn ios_lld_platform_version() -> String {
let (major, minor) = ios_deployment_target();
format!("{}.{}", major, minor)
}

pub fn ios_sim_llvm_target(arch: &str) -> String {
let (major, minor) = ios_deployment_target();
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
}

fn tvos_deployment_target() -> (u32, u32) {
deployment_target("TVOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
}

pub fn tvos_lld_platform_version() -> String {
let (major, minor) = tvos_deployment_target();
format!("{}.{}", major, minor)
}

fn watchos_deployment_target() -> (u32, u32) {
deployment_target("WATCHOS_DEPLOYMENT_TARGET").unwrap_or((5, 0))
}

pub fn watchos_lld_platform_version() -> String {
let (major, minor) = watchos_deployment_target();
format!("{}.{}", major, minor)
}

pub fn watchos_sim_llvm_target(arch: &str) -> String {
let (major, minor) = watchos_deployment_target();
format!("{}-apple-watchos{}.{}.0-simulator", arch, major, minor)
Expand Down
Loading