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 7 pull requests #127580

Merged
merged 18 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d3f1618
fix python bootstrap tests requiring a downloaded stage0
pietroalbini Jun 14, 2024
fcb6ff5
fix rust bootstrap tests requiring a downloaded stage0
pietroalbini Jun 14, 2024
198c809
set the correct executable for initial_{rustc,cargo}
pietroalbini Jul 8, 2024
b4b2643
set the correct rustc and cargo even for tests invoking parse_inner
pietroalbini Jul 8, 2024
af3aa36
do not run test where it cannot run
tshepang Jul 9, 2024
7c88bda
E0191 suggestion correction, inserts turbofish without dyn (#91997)
Borgerr Jul 9, 2024
9cd1d25
use utils::helpers::exe
pietroalbini Jul 10, 2024
c8e4447
Temporarily remove me from review rotation.
m-ou-se Jul 10, 2024
f77394f
instantiate higher ranked goals in candidate selection
lcnr Jul 10, 2024
e7bd16e
Fix local download of Docker caches
Kobzol Jul 10, 2024
e00fd78
simplify and future-proof `needs_normalization`
lcnr Jul 10, 2024
d17e0cf
Rollup merge of #126476 - ferrocene:pa-bootstrap-test-local-rustc, r=…
matthiaskrgr Jul 10, 2024
a7fe30d
Rollup merge of #127094 - Borgerr:E0191-suggestion-correction, r=fmease
matthiaskrgr Jul 10, 2024
aae262c
Rollup merge of #127554 - ferrocene:tshepang-add-missing-attribute, r…
matthiaskrgr Jul 10, 2024
bbb0f66
Rollup merge of #127564 - m-ou-se:review-rotation, r=joboet
matthiaskrgr Jul 10, 2024
7faef5d
Rollup merge of #127568 - lcnr:undo-leakcheck, r=oli-obk
matthiaskrgr Jul 10, 2024
3163919
Rollup merge of #127569 - Kobzol:ci-fix-docker-local-rebuild, r=nikic
matthiaskrgr Jul 10, 2024
22df186
Rollup merge of #127570 - lcnr:normalize-cool, r=compiler-errors
matthiaskrgr Jul 10, 2024
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
14 changes: 13 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use rustc_errors::MultiSpan;
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, Node};
use rustc_middle::bug;
use rustc_middle::query::Key;
use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};
Expand Down Expand Up @@ -740,7 +740,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if object_safety_violations {
return;
}

// related to issue #91997, turbofishes added only when in an expr or pat
let mut in_expr_or_pat = false;
if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) {
let grandparent = tcx.parent_hir_node(tcx.parent_hir_id(bound.trait_ref.hir_ref_id));
in_expr_or_pat = match grandparent {
Node::Expr(_) | Node::Pat(_) => true,
_ => false,
};
match bound.trait_ref.path.segments {
// FIXME: `trait_ref.path.span` can point to a full path with multiple
// segments, even though `trait_ref.path.segments` is of length `1`. Work
Expand Down Expand Up @@ -896,6 +904,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
// suggestion.
format!("{}, {}>", &snippet[..snippet.len() - 1], types.join(", "))
} else if in_expr_or_pat {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator::<Item = Type>`.
format!("{}::<{}>", snippet, types.join(", "))
} else {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator<Item = Type>`.
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,13 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
value: &T,
reveal: Reveal,
) -> bool {
// This mirrors `ty::TypeFlags::HAS_ALIASES` except that we take `Reveal` into account.

let mut flags = ty::TypeFlags::HAS_TY_PROJECTION
| ty::TypeFlags::HAS_TY_WEAK
| ty::TypeFlags::HAS_TY_INHERENT
| ty::TypeFlags::HAS_CT_PROJECTION;
let mut flags = ty::TypeFlags::HAS_ALIAS;

// Opaques are treated as rigid with `Reveal::UserFacing`,
// so we can ignore those.
match reveal {
Reveal::UserFacing => {}
Reveal::All => flags |= ty::TypeFlags::HAS_TY_OPAQUE,
Reveal::UserFacing => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE),
Reveal::All => {}
}

value.has_type_flags(flags)
Expand Down
66 changes: 12 additions & 54 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ mod _match;
mod candidate_assembly;
mod confirmation;

/// Whether to consider the binder of higher ranked goals for the `leak_check` when
/// evaluating higher-ranked goals. See #119820 for more info.
///
/// While this is a bit hacky, it is necessary to match the behavior of the new solver:
/// We eagerly instantiate binders in the new solver, outside of candidate selection, so
/// the leak check inside of candidates does not consider any bound vars from the higher
/// ranked goal. However, we do exit the binder once we're completely finished with a goal,
/// so the leak-check can be used in evaluate by causing nested higher-ranked goals to fail.
#[derive(Debug, Copy, Clone)]
enum LeakCheckHigherRankedGoal {
No,
Yes,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum IntercrateAmbiguityCause<'tcx> {
DownstreamCrate { trait_ref: ty::TraitRef<'tcx>, self_ty: Option<Ty<'tcx>> },
Expand Down Expand Up @@ -402,10 +388,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut no_candidates_apply = true;

for c in candidate_set.vec.iter() {
if self
.evaluate_candidate(stack, c, LeakCheckHigherRankedGoal::No)?
.may_apply()
{
if self.evaluate_candidate(stack, c)?.may_apply() {
no_candidates_apply = false;
break;
}
Expand Down Expand Up @@ -476,7 +459,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// is needed for specialization. Propagate overflow if it occurs.
let mut candidates = candidates
.into_iter()
.map(|c| match self.evaluate_candidate(stack, &c, LeakCheckHigherRankedGoal::No) {
.map(|c| match self.evaluate_candidate(stack, &c) {
Ok(eval) if eval.may_apply() => {
Ok(Some(EvaluatedCandidate { candidate: c, evaluation: eval }))
}
Expand Down Expand Up @@ -566,7 +549,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &PredicateObligation<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
debug_assert!(!self.infcx.next_trait_solver());
self.evaluation_probe(|this, _outer_universe| {
self.evaluation_probe(|this| {
let goal =
this.infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
let mut result = this.evaluate_predicate_recursively(
Expand All @@ -589,11 +572,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// `op`, but this can be overwritten if necessary.
fn evaluation_probe(
&mut self,
op: impl FnOnce(&mut Self, &mut ty::UniverseIndex) -> Result<EvaluationResult, OverflowError>,
op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
) -> Result<EvaluationResult, OverflowError> {
self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
let mut outer_universe = self.infcx.universe();
let result = op(self, &mut outer_universe)?;
let outer_universe = self.infcx.universe();
let result = op(self)?;

match self.infcx.leak_check(outer_universe, Some(snapshot)) {
Ok(()) => {}
Expand Down Expand Up @@ -1254,7 +1237,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

match self.candidate_from_obligation(stack) {
Ok(Some(c)) => self.evaluate_candidate(stack, &c, LeakCheckHigherRankedGoal::Yes),
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
Ok(None) => Ok(EvaluatedToAmbig),
Err(Overflow(OverflowError::Canonical)) => Err(OverflowError::Canonical),
Err(..) => Ok(EvaluatedToErr),
Expand All @@ -1279,10 +1262,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// Further evaluates `candidate` to decide whether all type parameters match and whether nested
/// obligations are met. Returns whether `candidate` remains viable after this further
/// scrutiny.
///
/// Depending on the value of [LeakCheckHigherRankedGoal], we may ignore the binder of the goal
/// when eagerly detecting higher ranked region errors via the `leak_check`. See that enum for
/// more info.
#[instrument(
level = "debug",
skip(self, stack),
Expand All @@ -1293,25 +1272,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
stack: &TraitObligationStack<'o, 'tcx>,
candidate: &SelectionCandidate<'tcx>,
leak_check_higher_ranked_goal: LeakCheckHigherRankedGoal,
) -> Result<EvaluationResult, OverflowError> {
let mut result = self.evaluation_probe(|this, outer_universe| {
// We eagerly instantiate higher ranked goals to prevent universe errors
// from impacting candidate selection. This matches the behavior of the new
// solver. This slightly weakens type inference.
//
// In case there are no unresolved type or const variables this
// should still not be necessary to select a unique impl as any overlap
// relying on a universe error from higher ranked goals should have resulted
// in an overlap error in coherence.
let p = self.infcx.enter_forall_and_leak_universe(stack.obligation.predicate);
let obligation = stack.obligation.with(this.tcx(), ty::Binder::dummy(p));
match leak_check_higher_ranked_goal {
LeakCheckHigherRankedGoal::No => *outer_universe = self.infcx.universe(),
LeakCheckHigherRankedGoal::Yes => {}
}

match this.confirm_candidate(&obligation, candidate.clone()) {
let mut result = self.evaluation_probe(|this| {
match this.confirm_candidate(stack.obligation, candidate.clone()) {
Ok(selection) => {
debug!(?selection);
this.evaluate_predicates_recursively(
Expand Down Expand Up @@ -1731,19 +1694,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
})
.map_err(|_| ())
}

fn where_clause_may_apply<'o>(
&mut self,
stack: &TraitObligationStack<'o, 'tcx>,
where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
self.evaluation_probe(|this, outer_universe| {
// Eagerly instantiate higher ranked goals.
//
// See the comment in `evaluate_candidate` to see why.
let p = self.infcx.enter_forall_and_leak_universe(stack.obligation.predicate);
let obligation = stack.obligation.with(this.tcx(), ty::Binder::dummy(p));
*outer_universe = self.infcx.universe();
match this.match_where_clause_trait_ref(&obligation, where_clause_trait_ref) {
self.evaluation_probe(|this| {
match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
Ok(obligations) => this.evaluate_predicates_recursively(stack.list(), obligations),
Err(()) => Ok(EvaluatedToErr),
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_type_ir/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bitflags::bitflags! {
/// Does this have `ConstKind::Param`?
const HAS_CT_PARAM = 1 << 2;

const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits()
const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits()
| TypeFlags::HAS_RE_PARAM.bits()
| TypeFlags::HAS_CT_PARAM.bits();

Expand All @@ -27,7 +27,7 @@ bitflags::bitflags! {

/// Does this have inference variables? Used to determine whether
/// inference is required.
const HAS_INFER = TypeFlags::HAS_TY_INFER.bits()
const HAS_INFER = TypeFlags::HAS_TY_INFER.bits()
| TypeFlags::HAS_RE_INFER.bits()
| TypeFlags::HAS_CT_INFER.bits();

Expand All @@ -39,7 +39,7 @@ bitflags::bitflags! {
const HAS_CT_PLACEHOLDER = 1 << 8;

/// Does this have placeholders?
const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits()
const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits()
| TypeFlags::HAS_RE_PLACEHOLDER.bits()
| TypeFlags::HAS_CT_PLACEHOLDER.bits();

Expand Down Expand Up @@ -81,7 +81,7 @@ bitflags::bitflags! {
/// Does this have `Alias` or `ConstKind::Unevaluated`?
///
/// Rephrased, could this term be normalized further?
const HAS_ALIASES = TypeFlags::HAS_TY_PROJECTION.bits()
const HAS_ALIAS = TypeFlags::HAS_TY_PROJECTION.bits()
| TypeFlags::HAS_TY_WEAK.bits()
| TypeFlags::HAS_TY_OPAQUE.bits()
| TypeFlags::HAS_TY_INHERENT.bits()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> {
}

fn has_aliases(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_ALIASES)
self.has_type_flags(TypeFlags::HAS_ALIAS)
}

fn has_inherent_projections(&self) -> bool {
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/slice/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fn panic_safe() {

#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_sort() {
let mut rng = test_rng();

Expand Down
19 changes: 19 additions & 0 deletions src/bootstrap/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ def build_args(self, configure_args=None, args=None, env=None):
if env is None:
env = {}

# This test ends up invoking build_bootstrap_cmd, which searches for
# the Cargo binary and errors out if it cannot be found. This is not a
# problem in most cases, but there is a scenario where it would cause
# the test to fail.
#
# When a custom local Cargo is configured in config.toml (with the
# build.cargo setting), no Cargo is downloaded to any location known by
# bootstrap, and bootstrap relies on that setting to find it.
#
# In this test though we are not using the config.toml of the caller:
# we are generating a blank one instead. If we don't set build.cargo in
# it, the test will have no way to find Cargo, failing the test.
cargo_bin = os.environ.get("BOOTSTRAP_TEST_CARGO_BIN")
if cargo_bin is not None:
configure_args += ["--set", "build.cargo=" + cargo_bin]
rustc_bin = os.environ.get("BOOTSTRAP_TEST_RUSTC_BIN")
if rustc_bin is not None:
configure_args += ["--set", "build.rustc=" + rustc_bin]

env = env.copy()
env["PATH"] = os.environ["PATH"]

Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2979,6 +2979,8 @@ impl Step for Bootstrap {
.args(["-m", "unittest", "bootstrap_test.py"])
.env("BUILD_DIR", &builder.out)
.env("BUILD_PLATFORM", builder.build.build.triple)
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
.current_dir(builder.src.join("src/bootstrap/"));
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
// Use `python -m unittest` manually if you want to pass arguments.
Expand Down
25 changes: 23 additions & 2 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,17 @@ impl Config {
TomlConfig::default()
};

if cfg!(test) {
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
// same ones used to call the tests (if custom ones are not defined in the toml). If we
// don't do that, bootstrap will use its own detection logic to find a suitable rustc
// and Cargo, which doesn't work when the caller is specìfying a custom local rustc or
// Cargo in their config.toml.
let build = toml.build.get_or_insert_with(Default::default);
build.rustc = build.rustc.take().or(std::env::var_os("RUSTC").map(|p| p.into()));
build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
}

if let Some(include) = &toml.profile {
// Allows creating alias for profile names, allowing
// profiles to be renamed while maintaining back compatibility
Expand Down Expand Up @@ -1448,7 +1459,12 @@ impl Config {
rustc
} else {
config.download_beta_toolchain();
config.out.join(config.build.triple).join("stage0/bin/rustc")
config
.out
.join(config.build.triple)
.join("stage0")
.join("bin")
.join(exe("rustc", config.build))
};

config.initial_cargo = if let Some(cargo) = cargo {
Expand All @@ -1458,7 +1474,12 @@ impl Config {
cargo
} else {
config.download_beta_toolchain();
config.out.join(config.build.triple).join("stage0/bin/cargo")
config
.out
.join(config.build.triple)
.join("stage0")
.join("bin")
.join(exe("cargo", config.build))
};

// NOTE: it's important this comes *after* we set `initial_rustc` just above.
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
docker --version

REGISTRY=ghcr.io
REGISTRY_USERNAME=${GITHUB_REPOSITORY_OWNER}
REGISTRY_USERNAME=${GITHUB_REPOSITORY_OWNER:-rust-lang-ci}
# Tag used to push the final Docker image, so that it can be pulled by e.g. rustup
IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci:${cksum}
# Tag used to cache the Docker build
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/errors/dynless-turbofish-e0191-issue-91997.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait MyIterator : Iterator {}

fn main() {
let _ = MyIterator::next;
}
//~^^ ERROR the value of the associated type `Item` in `Iterator` must be specified [E0191]
//~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
23 changes: 23 additions & 0 deletions tests/ui/errors/dynless-turbofish-e0191-issue-91997.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/dynless-turbofish-e0191-issue-91997.rs:4:13
|
LL | let _ = MyIterator::next;
| ^^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
|
LL | let _ = <dyn MyIterator>::next;
| ++++ +

error[E0191]: the value of the associated type `Item` in `Iterator` must be specified
--> $DIR/dynless-turbofish-e0191-issue-91997.rs:4:13
|
LL | let _ = MyIterator::next;
| ^^^^^^^^^^ help: specify the associated type: `MyIterator::<Item = Type>`

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0191`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0277]: the trait bound `for<'a> &'a &T: Trait` is not satisfied
--> $DIR/candidate-from-env-universe-err-1.rs:27:16
|
LL | hr_bound::<&T>();
| ^^ the trait `for<'a> Trait` is not implemented for `&'a &T`
|
note: required by a bound in `hr_bound`
--> $DIR/candidate-from-env-universe-err-1.rs:14:20
|
LL | fn hr_bound<T>()
| -------- required by a bound in this function
LL | where
LL | for<'a> &'a T: Trait,
| ^^^^^ required by this bound in `hr_bound`
help: consider removing the leading `&`-reference
|
LL - hr_bound::<&T>();
LL + hr_bound::<T>();
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading
Loading