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 10 pull requests #109438

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9261fd0
Nested impl traits trigger opaque_hidden_inferred_bound too much
compiler-errors Feb 27, 2023
d7049ca
add the --json flag to compiletest
pietroalbini Mar 1, 2023
d2f3806
render compiletest output with render_tests
pietroalbini Mar 2, 2023
f96774b
add support for terse output
pietroalbini Mar 2, 2023
f816d3a
add a splash of color
pietroalbini Mar 2, 2023
9388c8e
record tests in build metrics
pietroalbini Mar 2, 2023
b14b355
add support for benchmarks
pietroalbini Mar 2, 2023
50b3583
switch all tests to use render_tests
pietroalbini Mar 2, 2023
ad9a444
avoid overlapping stderr
pietroalbini Mar 2, 2023
f23e205
do not use render_tests for clippy
pietroalbini Mar 2, 2023
9a1ff1b
handle non-json output in stdout
pietroalbini Mar 3, 2023
4958272
change approach to prevent interleaving compiletest message
pietroalbini Mar 3, 2023
3248ab7
fix name of the field containing the ignore reason
pietroalbini Mar 6, 2023
c015d0d
switch to termcolor
pietroalbini Mar 7, 2023
f7a9702
rustdoc: Cleanup parent module tracking for doc links
petrochenkov Mar 18, 2023
ae47810
rustdoc: Factor out some doc link resolution code into a separate fun…
petrochenkov Mar 19, 2023
69a82f7
add myself to mailmap
aDotInTheVoid Mar 19, 2023
9f80c75
Walk un-shifted nested `impl Trait` in trait when setting up default …
compiler-errors Mar 16, 2023
239ec6c
drive-by: Fix a comment in TyCtxt::fold_regions and remove an unused …
compiler-errors Mar 17, 2023
5b4fa5b
fix typo
lcnr Mar 20, 2023
8e4e55e
Support aggregate expressions
cbeuw Mar 20, 2023
e24f5ac
Fix off-by-one in mir syntax doc
cbeuw Mar 20, 2023
f404f33
Use builtin_index instead of match
cbeuw Mar 20, 2023
e4a4064
adapt tests/codegen/vec-shrink-panik for LLVM 17
krasimirgg Mar 20, 2023
5058cc8
not *all* retags might be explicit in Runtime MIR
RalfJung Mar 20, 2023
93eeb12
Refactor `handle_missing_lit`.
nnethercote Feb 1, 2023
3ecc354
Rollup merge of #108541 - compiler-errors:lol-nested-rpits, r=oli-obk
Noratrieb Mar 21, 2023
d3749f0
Rollup merge of #108659 - ferrocene:pa-test-metrics, r=Mark-Simulacrum
Noratrieb Mar 21, 2023
38e6c35
Rollup merge of #109240 - compiler-errors:dont-binder-twice, r=oli-obk
Noratrieb Mar 21, 2023
3d6676a
Rollup merge of #109312 - petrochenkov:docice5, r=GuillaumeGomez
Noratrieb Mar 21, 2023
17c9f27
Rollup merge of #109385 - lcnr:typo, r=Dylan-DPC
Noratrieb Mar 21, 2023
bb98a8e
Rollup merge of #109386 - aDotInTheVoid:mailmap, r=WaffleLapkin
Noratrieb Mar 21, 2023
a352a17
Rollup merge of #109390 - cbeuw:aggregate-lit, r=oli-obk
Noratrieb Mar 21, 2023
aa8d357
Rollup merge of #109394 - krasimirgg:llvm-17-vec-panic, r=nikic
Noratrieb Mar 21, 2023
27a9dcf
Rollup merge of #109408 - RalfJung:retags, r=compiler-errors
Noratrieb Mar 21, 2023
b567a1c
Rollup merge of #109415 - nnethercote:refactor-handle_missing_lit, r=…
Noratrieb Mar 21, 2023
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
3 changes: 2 additions & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Alexander Ronald Altman <alexanderaltman@me.com>
Alexandre Martin <martin.alex32@hotmail.fr>
Alexis Beingessner <a.beingessner@gmail.com>
Alfie John <alfie@alfie.wtf> Alfie John <alfiej@fastmail.fm>
Alona Enraght-Moony <code@alona.page> <nixon.emoony@gmail.com>
Alona Enraght-Moony <code@alona.page> <nixon@caminus.local>
Amos Onn <amosonn@gmail.com>
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
Anatoly Ikorsky <aikorsky@gmail.com>
Expand Down Expand Up @@ -415,7 +417,6 @@ Nicolas Abram <abramlujan@gmail.com>
Nicole Mazzuca <npmazzuca@gmail.com>
Nif Ward <nif.ward@gmail.com>
Nika Layzell <nika@thelayzells.com> <michael@thelayzells.com>
Nixon Enraght-Moony <nixon.emoony@gmail.com>
NODA Kai <nodakai@gmail.com>
oliver <16816606+o752d@users.noreply.github.com>
Oliver Middleton <olliemail27@gmail.com> <ollie27@users.noreply.github.com>
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
found: Option<ty::OpaqueHiddenType<'tcx>>,

/// In the presence of dead code, typeck may figure out a hidden type
/// while borrowck will now. We collect these cases here and check at
/// while borrowck will not. We collect these cases here and check at
/// the end that we actually found a type that matches (modulo regions).
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
}
Expand Down
23 changes: 19 additions & 4 deletions compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_hir as hir;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable,
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, DefIdTree, Ty, TypeFoldable,
};
use rustc_span::Span;
use rustc_trait_selection::traits;
Expand All @@ -27,6 +27,8 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(type_alias_impl_trait)]
///
/// trait Duh {}
///
/// impl Duh for i32 {}
Expand All @@ -41,7 +43,9 @@ declare_lint! {
/// type Assoc = F;
/// }
///
/// fn test() -> impl Trait<Assoc = impl Sized> {
/// type Tait = impl Sized;
///
/// fn test() -> impl Trait<Assoc = Tait> {
/// 42
/// }
/// ```
Expand All @@ -54,7 +58,7 @@ declare_lint! {
///
/// Although the hidden type, `i32` does satisfy this bound, we do not
/// consider the return type to be well-formed with this lint. It can be
/// fixed by changing `impl Sized` into `impl Sized + Send`.
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Send`.
pub OPAQUE_HIDDEN_INFERRED_BOUND,
Warn,
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"
Expand All @@ -64,7 +68,7 @@ declare_lint_pass!(OpaqueHiddenInferredBound => [OPAQUE_HIDDEN_INFERRED_BOUND]);

impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let hir::ItemKind::OpaqueTy(_) = &item.kind else { return; };
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else { return; };
let def_id = item.owner_id.def_id.to_def_id();
let infcx = &cx.tcx.infer_ctxt().build();
// For every projection predicate in the opaque type's explicit bounds,
Expand All @@ -81,6 +85,17 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// have opaques in them anyways.
let Some(proj_term) = proj.term.ty() else { continue };

// HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"...
if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind()
&& cx.tcx.parent(opaque_ty.def_id) == def_id
&& matches!(
opaque.origin,
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_)
)
{
continue;
}

let proj_ty =
cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs);
// For every instance of the projection type in the bounds,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ pub enum MirPhase {
/// MIR, this is UB.
/// - Retags: If `-Zmir-emit-retag` is enabled, analysis MIR has "implicit" retags in the same way
/// that Rust itself has them. Where exactly these are is generally subject to change, and so we
/// don't document this here. Runtime MIR has all retags explicit.
/// don't document this here. Runtime MIR has most retags explicit (though implicit retags
/// can still occur at `Rvalue::{Ref,AddrOf}`).
/// - Generator bodies: In analysis MIR, locals may actually be behind a pointer that user code has
/// access to. This occurs in generator bodies. Such locals do not behave like other locals,
/// because they eg may be aliased in surprising ways. Runtime MIR has no such special locals -
Expand Down Expand Up @@ -1165,7 +1166,7 @@ pub enum AggregateKind<'tcx> {
Tuple,

/// The second field is the variant index. It's equal to 0 for struct
/// and union expressions. The fourth field is
/// and union expressions. The last field is the
/// active field number and is present only for union expressions
/// -- e.g., for a union expression `SomeUnion { c: .. }`, the
/// active field index would identity the field `c`
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ where
// Region folder

impl<'tcx> TyCtxt<'tcx> {
/// Folds the escaping and free regions in `value` using `f`, and
/// sets `skipped_regions` to true if any late-bound region was found
/// and skipped.
/// Folds the escaping and free regions in `value` using `f`.
pub fn fold_regions<T>(
self,
value: T,
Expand All @@ -64,17 +62,6 @@ impl<'tcx> TyCtxt<'tcx> {
{
value.fold_with(&mut RegionFolder::new(self, &mut f))
}

pub fn super_fold_regions<T>(
self,
value: T,
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
) -> T
where
T: TypeSuperFoldable<TyCtxt<'tcx>>,
{
value.super_fold_with(&mut RegionFolder::new(self, &mut f))
}
}

/// Folds over the substructure of a type, visiting its component
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_mir_build/src/build/custom/parse/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
let cast_kind = mir_cast_kind(source_ty, expr.ty);
Ok(Rvalue::Cast(cast_kind, source, expr.ty))
},
ExprKind::Tuple { fields } => Ok(
Rvalue::Aggregate(
Box::new(AggregateKind::Tuple),
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
)
),
ExprKind::Array { fields } => {
let elem_ty = expr.ty.builtin_index().expect("ty must be an array");
Ok(Rvalue::Aggregate(
Box::new(AggregateKind::Array(elem_ty)),
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
))
},
ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => {
let is_union = adt_def.is_union();
let active_field_index = is_union.then(|| fields[0].name.index());

Ok(Rvalue::Aggregate(
Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)),
fields.iter().map(|f| self.parse_operand(f.expr)).collect::<Result<_, _>>()?
))
},
_ => self.parse_operand(expr_id).map(Rvalue::Use),
)
}
Expand Down
22 changes: 8 additions & 14 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,20 +1843,14 @@ impl<'a> Parser<'a> {
&mut self,
mk_lit_char: impl FnOnce(Symbol, Span) -> L,
) -> PResult<'a, L> {
if let token::Interpolated(inner) = &self.token.kind {
let expr = match inner.as_ref() {
token::NtExpr(expr) => Some(expr),
token::NtLiteral(expr) => Some(expr),
_ => None,
};
if let Some(expr) = expr {
if matches!(expr.kind, ExprKind::Err) {
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
.into_diagnostic(&self.sess.span_diagnostic);
err.downgrade_to_delayed_bug();
return Err(err);
}
}
if let token::Interpolated(nt) = &self.token.kind
&& let token::NtExpr(e) | token::NtLiteral(e) = &**nt
&& matches!(e.kind, ExprKind::Err)
{
let mut err = errors::InvalidInterpolatedExpression { span: self.token.span }
.into_diagnostic(&self.sess.span_diagnostic);
err.downgrade_to_delayed_bug();
return Err(err);
}
let token = self.token.clone();
let err = |self_: &Self| {
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ pub enum DocFragmentKind {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct DocFragment {
pub span: Span,
/// The module this doc-comment came from.
///
/// This allows distinguishing between the original documentation and a pub re-export.
/// If it is `None`, the item was not re-exported.
pub parent_module: Option<DefId>,
/// The item this doc-comment came from.
/// Used to determine the scope in which doc links in this fragment are resolved.
/// Typically filled for reexport docs when they are merged into the docs of the
/// original reexported item.
/// If the id is not filled, which happens for the original reexported item, then
/// it has to be taken from somewhere else during doc link resolution.
pub item_id: Option<DefId>,
pub doc: Symbol,
pub kind: DocFragmentKind,
pub indent: usize,
Expand Down Expand Up @@ -186,15 +188,15 @@ pub fn attrs_to_doc_fragments<'a>(
) -> (Vec<DocFragment>, ast::AttrVec) {
let mut doc_fragments = Vec::new();
let mut other_attrs = ast::AttrVec::new();
for (attr, parent_module) in attrs {
for (attr, item_id) in attrs {
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
let doc = beautify_doc_string(doc_str, comment_kind);
let kind = if attr.is_doc_comment() {
DocFragmentKind::SugaredDoc
} else {
DocFragmentKind::RawDoc
};
let fragment = DocFragment { span: attr.span, doc, kind, parent_module, indent: 0 };
let fragment = DocFragment { span: attr.span, doc, kind, item_id, indent: 0 };
doc_fragments.push(fragment);
} else if !doc_only {
other_attrs.push(attr.clone());
Expand All @@ -216,7 +218,7 @@ pub fn prepare_to_doc_link_resolution(
) -> FxHashMap<Option<DefId>, String> {
let mut res = FxHashMap::default();
for fragment in doc_fragments {
let out_str = res.entry(fragment.parent_module).or_default();
let out_str = res.entry(fragment.item_id).or_default();
add_doc_fragment(out_str, fragment);
}
res
Expand Down
42 changes: 26 additions & 16 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use rustc_middle::ty::{
TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::{DefId, CRATE_DEF_ID};
use rustc_span::{
def_id::{DefId, CRATE_DEF_ID},
DUMMY_SP,
};
use rustc_trait_selection::traits;

fn sized_constraint_for_ty<'tcx>(
Expand Down Expand Up @@ -275,16 +278,22 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
}

fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
if let ty::Alias(ty::Projection, alias_ty) = *ty.kind()
&& self.tcx.is_impl_trait_in_trait(alias_ty.def_id)
&& self.tcx.impl_trait_in_trait_parent_fn(alias_ty.def_id) == self.fn_def_id
&& self.seen.insert(alias_ty.def_id)
if let ty::Alias(ty::Projection, unshifted_alias_ty) = *ty.kind()
&& self.tcx.is_impl_trait_in_trait(unshifted_alias_ty.def_id)
&& self.tcx.impl_trait_in_trait_parent_fn(unshifted_alias_ty.def_id) == self.fn_def_id
&& self.seen.insert(unshifted_alias_ty.def_id)
{
// We have entered some binders as we've walked into the
// bounds of the RPITIT. Shift these binders back out when
// constructing the top-level projection predicate.
let alias_ty = self.tcx.fold_regions(alias_ty, |re, _| {
let shifted_alias_ty = self.tcx.fold_regions(unshifted_alias_ty, |re, depth| {
if let ty::ReLateBound(index, bv) = re.kind() {
if depth != ty::INNERMOST {
return self.tcx.mk_re_error_with_message(
DUMMY_SP,
"we shouldn't walk non-predicate binders with `impl Trait`...",
);
}
self.tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv)
} else {
re
Expand All @@ -295,26 +304,27 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
// the `type_of` of the trait's associated item. If we're using the old lowering
// strategy, then just reinterpret the associated type like an opaque :^)
let default_ty = if self.tcx.lower_impl_trait_in_trait_to_assoc_ty() {
self
.tcx
.type_of(alias_ty.def_id)
.subst(self.tcx, alias_ty.substs)
self.tcx.type_of(shifted_alias_ty.def_id).subst(self.tcx, shifted_alias_ty.substs)
} else {
self.tcx.mk_alias(ty::Opaque, alias_ty)
self.tcx.mk_alias(ty::Opaque, shifted_alias_ty)
};

self.predicates.push(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
projection_ty: alias_ty,
term: default_ty.into(),
},
ty::ProjectionPredicate { projection_ty: shifted_alias_ty, term: default_ty.into() },
self.bound_vars,
)
.to_predicate(self.tcx),
);

for bound in self.tcx.item_bounds(alias_ty.def_id).subst_iter(self.tcx, alias_ty.substs)
// We walk the *un-shifted* alias ty, because we're tracking the de bruijn
// binder depth, and if we were to walk `shifted_alias_ty` instead, we'd
// have to reset `self.depth` back to `ty::INNERMOST` or something. It's
// easier to just do this.
for bound in self
.tcx
.item_bounds(unshifted_alias_ty.def_id)
.subst_iter(self.tcx, unshifted_alias_ty.substs)
{
bound.visit_with(self);
}
Expand Down
22 changes: 22 additions & 0 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ dependencies = [
"memchr",
]

[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]

[[package]]
name = "autocfg"
version = "1.1.0"
Expand All @@ -36,6 +47,7 @@ dependencies = [
name = "bootstrap"
version = "0.0.0"
dependencies = [
"atty",
"build_helper",
"cc",
"cmake",
Expand All @@ -55,6 +67,7 @@ dependencies = [
"sha2",
"sysinfo",
"tar",
"termcolor",
"toml",
"walkdir",
"windows",
Expand Down Expand Up @@ -636,6 +649,15 @@ dependencies = [
"xattr",
]

[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]

[[package]]
name = "thread_local"
version = "1.1.4"
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ path = "bin/sccache-plus-cl.rs"
test = false

[dependencies]
atty = "0.2.14"
build_helper = { path = "../tools/build_helper" }
cmake = "0.1.38"
filetime = "0.2"
Expand All @@ -45,6 +46,7 @@ serde_derive = "1.0.137"
serde_json = "1.0.2"
sha2 = "0.10"
tar = "0.4"
termcolor = "1.2.0"
toml = "0.5"
ignore = "0.4.10"
opener = "0.5"
Expand Down
Loading