Skip to content

Commit

Permalink
Auto merge of #124945 - matthiaskrgr:rollup-r6395sn, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #124915 (`rustc_target` cleanups)
 - #124927 (opt-dist: use xz2 instead of xz crate)
 - #124936 (analyse visitor: build proof tree in probe)
 - #124943 (always use `GenericArgsRef`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 9, 2024
2 parents 8f9080d + 2f7df58 commit a44a2b8
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 77 deletions.
11 changes: 1 addition & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ dependencies = [
"tabled",
"tar",
"tempfile",
"xz",
"xz2",
"zip",
]

Expand Down Expand Up @@ -6586,15 +6586,6 @@ dependencies = [
"rustix",
]

[[package]]
name = "xz"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c887690ff2a2e233e8e49633461521f98ec57fbff9d59a884c9a4f04ec1da34"
dependencies = [
"xz2",
]

[[package]]
name = "xz2"
version = "0.1.7"
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
trait_def_id: DefId,
self_ty: Ty<'tcx>,
opt_input_types: Option<&[Ty<'tcx>]>,
) -> (traits::PredicateObligation<'tcx>, &'tcx ty::List<ty::GenericArg<'tcx>>) {
) -> (traits::PredicateObligation<'tcx>, ty::GenericArgsRef<'tcx>) {
// Construct a trait-reference `self_ty : Trait<input_tys>`
let args = GenericArgs::for_item(self.tcx, trait_def_id, |param, _| {
match param.kind {
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
m_name: Ident,
trait_def_id: DefId,
obligation: traits::PredicateObligation<'tcx>,
args: &'tcx ty::List<ty::GenericArg<'tcx>>,
args: ty::GenericArgsRef<'tcx>,
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
debug!(?obligation);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
unmentioned_fields: &mut Vec<(&'tcx ty::FieldDef, Ident)>,
pat: &'tcx Pat<'tcx>,
variant: &ty::VariantDef,
args: &'tcx ty::List<ty::GenericArg<'tcx>>,
args: ty::GenericArgsRef<'tcx>,
) -> Diag<'tcx> {
let tcx = self.tcx;
let (field_names, t, plural) = if let [field] = inexistent_fields {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use hir::{Expr, Pat};
use rustc_hir as hir;
use rustc_infer::{infer::TyCtxtInferExt, traits::ObligationCause};
use rustc_middle::ty::{self, List};
use rustc_middle::ty;
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::{sym, Span};
use rustc_trait_selection::traits::ObligationCtxt;
Expand Down Expand Up @@ -123,7 +123,7 @@ fn extract_iterator_next_call<'tcx>(
fn suggest_question_mark<'tcx>(
cx: &LateContext<'tcx>,
adt: ty::AdtDef<'tcx>,
args: &List<ty::GenericArg<'tcx>>,
args: ty::GenericArgsRef<'tcx>,
span: Span,
) -> bool {
let Some(body_id) = cx.enclosing_body else { return false };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn mk_args_from_iter<I, T>(self, iter: I) -> T::Output
where
I: Iterator<Item = T>,
T: CollectAndApply<GenericArg<'tcx>, &'tcx List<GenericArg<'tcx>>>,
T: CollectAndApply<GenericArg<'tcx>, ty::GenericArgsRef<'tcx>>,
{
T::collect_and_apply(iter, |xs| self.mk_args(xs))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
fn pretty_print_opaque_impl_type(
&mut self,
def_id: DefId,
args: &'tcx ty::List<ty::GenericArg<'tcx>>,
args: ty::GenericArgsRef<'tcx>,
) -> Result<(), PrintError> {
let tcx = self.tcx();

Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_target/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
//! more 'stuff' here in the future. It does not have a dependency on
//! LLVM.

// tidy-alphabetical-start
#![allow(internal_features)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(min_exhaustive_patterns)]
#![feature(rustdoc_internals)]
#![feature(assert_matches)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(min_exhaustive_patterns)]
#![feature(rustc_attrs)]
#![feature(step_trait)]
#![allow(internal_features)]
#![feature(rustdoc_internals)]
// tidy-alphabetical-end

use std::path::{Path, PathBuf};

Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,19 +603,6 @@ impl LinkSelfContainedDefault {
self == LinkSelfContainedDefault::False
}

/// Returns whether the target spec explicitly requests self-contained linking, i.e. not via
/// inference.
pub fn is_linker_enabled(self) -> bool {
match self {
LinkSelfContainedDefault::True => true,
LinkSelfContainedDefault::False => false,
LinkSelfContainedDefault::WithComponents(c) => {
c.contains(LinkSelfContainedComponents::LINKER)
}
_ => false,
}
}

/// Returns the key to use when serializing the setting to json:
/// - individual components in a `link-self-contained` object value
/// - the other variants as a backwards-compatible `crt-objects-fallback` string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ pub(in crate::solve) fn make_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>
/// This currently assumes that unifying the var values trivially succeeds.
/// Adding any inference constraints which weren't present when originally
/// computing the canonical query can result in bugs.
#[instrument(level = "debug", skip(infcx, span, param_env))]
pub(in crate::solve) fn instantiate_canonical_state<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
infcx: &InferCtxt<'tcx>,
span: Span,
Expand Down
44 changes: 33 additions & 11 deletions compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
/// inference constraints, and optionally the args of an impl if this candidate
/// came from a `CandidateSource::Impl`. This function modifies the state of the
/// `infcx`.
#[instrument(
level = "debug",
skip_all,
fields(goal = ?self.goal.goal, nested_goals = ?self.nested_goals)
)]
pub fn instantiate_nested_goals_and_opt_impl_args(
&self,
span: Span,
Expand Down Expand Up @@ -213,10 +218,23 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
};
let goal =
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });
let proof_tree = EvalCtxt::enter_root(infcx, GenerateProofTree::Yes, |ecx| {
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
})
.1;
// We have to use a `probe` here as evaluating a `NormalizesTo` can constrain the
// expected term. This means that candidates which only fail due to nested goals
// and which normalize to a different term then the final result could ICE: when
// building their proof tree, the expected term was unconstrained, but when
// instantiating the candidate it is already constrained to the result of another
// candidate.
let proof_tree = infcx
.probe(|_| {
EvalCtxt::enter_root(infcx, GenerateProofTree::Yes, |ecx| {
ecx.evaluate_goal_raw(
GoalEvaluationKind::Root,
GoalSource::Misc,
goal,
)
})
})
.1;
InspectGoal::new(
infcx,
self.goal.depth + 1,
Expand All @@ -225,13 +243,17 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
source,
)
}
_ => InspectGoal::new(
infcx,
self.goal.depth + 1,
infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1.unwrap(),
None,
source,
),
_ => {
// We're using a probe here as evaluating a goal could constrain
// inference variables by choosing one candidate. If we then recurse
// into another candidate who ends up with different inference
// constraints, we get an ICE if we already applied the constraints
// from the chosen candidate.
let proof_tree = infcx
.probe(|_| infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1)
.unwrap();
InspectGoal::new(infcx, self.goal.depth + 1, proof_tree, None, source)
}
})
.collect();

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_infer::infer::canonical::Canonical;
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
use rustc_infer::traits::query::NoSolution;
use rustc_infer::{infer::outlives::env::OutlivesEnvironment, traits::FulfillmentError};
use rustc_middle::ty::{self, AdtDef, GenericArg, List, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::DUMMY_SP;

use super::outlives_bounds::InferCtxtExt;
Expand Down Expand Up @@ -129,7 +129,7 @@ pub fn all_fields_implement_trait<'tcx>(
param_env: ty::ParamEnv<'tcx>,
self_type: Ty<'tcx>,
adt: AdtDef<'tcx>,
args: &'tcx List<GenericArg<'tcx>>,
args: ty::GenericArgsRef<'tcx>,
parent_cause: ObligationCause<'tcx>,
lang_item: LangItem,
) -> Result<(), Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
use rustc_hir::{HirId, Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, FieldDef, GenericArg, List};
use rustc_middle::ty::{self, FieldDef};
use rustc_session::declare_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -85,7 +85,7 @@ fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'t
}
}

fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: &'tcx List<GenericArg<'tcx>>) -> bool {
fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsRef<'tcx>) -> bool {
let ty = field.ty(cx.tcx, args);
if let Ok(layout) = cx.layout_of(ty) {
layout.is_zst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::{Rvalue, StatementKind};
use rustc_middle::ty::{
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, List, ParamTy, ProjectionPredicate, Ty,
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, ParamTy, ProjectionPredicate, Ty,
};
use rustc_session::impl_lint_pass;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -161,7 +161,7 @@ fn needless_borrow_count<'tcx>(
cx: &LateContext<'tcx>,
possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
fn_id: DefId,
callee_args: &'tcx List<GenericArg<'tcx>>,
callee_args: ty::GenericArgsRef<'tcx>,
arg_index: usize,
param_ty: ParamTy,
mut expr: &Expr<'tcx>,
Expand Down
8 changes: 6 additions & 2 deletions src/tools/clippy/clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::traits::EvaluationResult;
use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{
self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
GenericParamDefKind, IntTy, List, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt,
GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr,
};
use rustc_span::symbol::Ident;
Expand Down Expand Up @@ -961,7 +961,11 @@ pub struct AdtVariantInfo {

impl AdtVariantInfo {
/// Returns ADT variants ordered by size
pub fn new<'tcx>(cx: &LateContext<'tcx>, adt: AdtDef<'tcx>, subst: &'tcx List<GenericArg<'tcx>>) -> Vec<Self> {
pub fn new<'tcx>(
cx: &LateContext<'tcx>,
adt: AdtDef<'tcx>,
subst: GenericArgsRef<'tcx>
) -> Vec<Self> {
let mut variants_size = adt
.variants()
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/tools/opt-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ camino = "1"
reqwest = { version = "0.11", features = ["blocking"] }
zip = { version = "0.6", default-features = false, features = ["deflate"] }
tar = "0.4"
xz = "0.1"
xz = { version = "0.1", package = "xz2" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
glob = "0.3"
Expand Down
14 changes: 0 additions & 14 deletions tests/crashes/124702.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//@ compile-flags: -Znext-solver=coherence
//@ check-pass

// A regression test for #124791. Computing ambiguity causes
// for the overlap of the `ToString` impls caused an ICE.
#![crate_type = "lib"]
#![feature(min_specialization)]
trait Display {}

trait ToOwned {
type Owned;
}

impl<T> ToOwned for T {
type Owned = T;
}

struct Cow<B: ?Sized>(B);

impl<B: ?Sized> Display for Cow<B>
where
B: ToOwned,
B::Owned: Display,
{
}

impl Display for () {}

trait ToString {
fn to_string();
}

impl<T: Display + ?Sized> ToString for T {
default fn to_string() {}
}

impl ToString for Cow<str> {
fn to_string() {}
}

impl ToOwned for str {
type Owned = ();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ compile-flags: -Znext-solver=coherence

// A regression test for #124791. Computing ambiguity causes
// for the overlap of the `ToString` impls caused an ICE.
#![crate_type = "lib"]
trait ToOwned {
type Owned;
}
impl<T> ToOwned for T {
type Owned = u8;
}
impl ToOwned for str {
type Owned = i8;
}

trait Overlap {}
impl<T: ToOwned<Owned = i8> + ?Sized> Overlap for T {}
impl Overlap for str {}
//~^ ERROR conflicting implementations of trait `Overlap`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0119]: conflicting implementations of trait `Overlap` for type `str`
--> $DIR/ambiguity-causes-canonical-state-ice-2.rs:18:1
|
LL | impl<T: ToOwned<Owned = i8> + ?Sized> Overlap for T {}
| --------------------------------------------------- first implementation here
LL | impl Overlap for str {}
| ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `str`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
// entering the cycle from `A` fails, but would work if we were to use the cache
// result of `B<X>`.
impls_trait::<A<X>, _, _, _>();
//~^ ERROR the trait bound `A<X>: Trait<i32, u8, u8>` is not satisfied
//~^ ERROR the trait bound `A<X>: Trait<_, _, _>` is not satisfied
}

fn main() {
Expand Down
Loading

0 comments on commit a44a2b8

Please sign in to comment.