Skip to content

Commit bab18a5

Browse files
committed
Auto merge of rust-lang#134492 - jhpratt:rollup-elpdwd9, r=jhpratt
Rollup of 8 pull requests Successful merges: - rust-lang#132056 (Stabilize `#[diagnostic::do_not_recommend]`) - rust-lang#133643 (-Znext-solver: modify candidate preference rules) - rust-lang#134388 (Update books) - rust-lang#134418 (Advent of `tests/ui` (misc cleanups and improvements) [3/N]) - rust-lang#134473 (chore: fix some typos) - rust-lang#134481 (Point at lint name instead of whole attr for gated lints) - rust-lang#134484 (Add nnethercote to the `triagebot.toml` vacation list.) - rust-lang#134490 (Fix typo in ptr/mod.rs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 023521e + 80cf85d commit bab18a5

File tree

101 files changed

+724
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+724
-399
lines changed

compiler/rustc_codegen_cranelift/src/compiler_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::c_int;
33
#[cfg(feature = "jit")]
44
use std::ffi::c_void;
55

6-
// FIXME replace with core::ffi::c_size_t once stablized
6+
// FIXME replace with core::ffi::c_size_t once stabilized
77
#[allow(non_camel_case_types)]
88
#[cfg(feature = "jit")]
99
type size_t = usize;

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
6666
sym::log2f64 => "log2",
6767
sym::fmaf32 => "fmaf",
6868
sym::fmaf64 => "fma",
69-
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
69+
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7070
sym::fmuladdf32 => "fmaf", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f32
7171
sym::fmuladdf64 => "fma", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f64
7272
sym::fabsf32 => "fabsf",

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,7 @@ impl HumanEmitter {
25232523
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
25242524
}
25252525
[] => {
2526-
// FIXME: needed? Doesn't get excercised in any test.
2526+
// FIXME: needed? Doesn't get exercised in any test.
25272527
self.draw_col_separator_no_space(buffer, *row_num, max_line_num_len + 1);
25282528
}
25292529
_ => {

compiler/rustc_errors/src/markdown/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn parse_with_end_pat<'a>(
346346
None
347347
}
348348

349-
/// Resturn `(match, residual)` to end of line. The EOL is returned with the
349+
/// Return `(match, residual)` to end of line. The EOL is returned with the
350350
/// residual.
351351
fn parse_to_newline(buf: &[u8]) -> (&[u8], &[u8]) {
352352
buf.iter().position(|ch| *ch == b'\n').map_or((buf, &[]), |pos| buf.split_at(pos))

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ declare_features! (
178178
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
179179
/// Allows using the `#[diagnostic]` attribute tool namespace
180180
(accepted, diagnostic_namespace, "1.78.0", Some(111996)),
181+
/// Controls errors in trait implementations.
182+
(accepted, do_not_recommend, "CURRENT_RUSTC_VERSION", Some(51992)),
181183
/// Allows `#[doc(alias = "...")]`.
182184
(accepted, doc_alias, "1.48.0", Some(50146)),
183185
/// Allows `..` in tuple (struct) patterns.

compiler/rustc_feature/src/builtin_attrs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,9 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
11871187
map
11881188
});
11891189

1190-
pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
1190+
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
11911191
match sym {
1192-
sym::on_unimplemented => true,
1193-
sym::do_not_recommend => features.do_not_recommend(),
1192+
sym::on_unimplemented | sym::do_not_recommend => true,
11941193
_ => false,
11951194
}
11961195
}

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ declare_features! (
462462
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
463463
/// Allows deref patterns.
464464
(incomplete, deref_patterns, "1.79.0", Some(87121)),
465-
/// Controls errors in trait implementations.
466-
(unstable, do_not_recommend, "1.67.0", Some(51992)),
467465
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
468466
(unstable, doc_auto_cfg, "1.58.0", Some(43781)),
469467
/// Allows `#[doc(cfg(...))]`.

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
914914

915915
let src = LintLevelSource::Node { name, span: sp, reason };
916916
for &id in ids {
917-
if self.check_gated_lint(id, attr.span(), false) {
917+
if self.check_gated_lint(id, sp, false) {
918918
self.insert_spec(id, (level, src));
919919
}
920920
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ pub struct ParamEnv<'tcx> {
971971
}
972972

973973
impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
974-
fn caller_bounds(self) -> impl IntoIterator<Item = ty::Clause<'tcx>> {
974+
fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
975975
self.caller_bounds()
976976
}
977977
}

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+95-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::cmp::Ordering;
33
use rustc_type_ir::data_structures::HashMap;
44
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
55
use rustc_type_ir::inherent::*;
6+
use rustc_type_ir::solve::{Goal, QueryInput};
67
use rustc_type_ir::visit::TypeVisitableExt;
78
use rustc_type_ir::{
89
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, InferCtxtLike,
@@ -17,8 +18,11 @@ use crate::delegate::SolverDelegate;
1718
/// while canonicalizing the response happens in the context of the
1819
/// query.
1920
#[derive(Debug, Clone, Copy)]
20-
pub enum CanonicalizeMode {
21-
Input,
21+
enum CanonicalizeMode {
22+
/// When canonicalizing the `param_env`, we keep `'static` as merging
23+
/// trait candidates relies on it when deciding whether a where-bound
24+
/// is trivial.
25+
Input { keep_static: bool },
2226
/// FIXME: We currently return region constraints referring to
2327
/// placeholders and inference variables from a binder instantiated
2428
/// inside of the query.
@@ -59,15 +63,15 @@ pub struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner> {
5963
}
6064

6165
impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
62-
pub fn canonicalize<T: TypeFoldable<I>>(
66+
pub fn canonicalize_response<T: TypeFoldable<I>>(
6367
delegate: &'a D,
64-
canonicalize_mode: CanonicalizeMode,
68+
max_input_universe: ty::UniverseIndex,
6569
variables: &'a mut Vec<I::GenericArg>,
6670
value: T,
6771
) -> ty::Canonical<I, T> {
6872
let mut canonicalizer = Canonicalizer {
6973
delegate,
70-
canonicalize_mode,
74+
canonicalize_mode: CanonicalizeMode::Response { max_input_universe },
7175

7276
variables,
7377
variable_lookup_table: Default::default(),
@@ -80,9 +84,67 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
8084
let value = value.fold_with(&mut canonicalizer);
8185
assert!(!value.has_infer(), "unexpected infer in {value:?}");
8286
assert!(!value.has_placeholders(), "unexpected placeholders in {value:?}");
83-
8487
let (max_universe, variables) = canonicalizer.finalize();
88+
Canonical { max_universe, variables, value }
89+
}
90+
91+
/// When canonicalizing query inputs, we keep `'static` in the `param_env`
92+
/// but erase it everywhere else. We generally don't want to depend on region
93+
/// identity, so while it should not matter whether `'static` is kept in the
94+
/// value or opaque type storage as well, this prevents us from accidentally
95+
/// relying on it in the future.
96+
///
97+
/// We want to keep the option of canonicalizing `'static` to an existential
98+
/// variable in the future by changing the way we detect global where-bounds.
99+
pub fn canonicalize_input<P: TypeFoldable<I>>(
100+
delegate: &'a D,
101+
variables: &'a mut Vec<I::GenericArg>,
102+
input: QueryInput<I, P>,
103+
) -> ty::Canonical<I, QueryInput<I, P>> {
104+
// First canonicalize the `param_env` while keeping `'static`
105+
let mut env_canonicalizer = Canonicalizer {
106+
delegate,
107+
canonicalize_mode: CanonicalizeMode::Input { keep_static: true },
108+
109+
variables,
110+
variable_lookup_table: Default::default(),
111+
primitive_var_infos: Vec::new(),
112+
binder_index: ty::INNERMOST,
113+
114+
cache: Default::default(),
115+
};
116+
let param_env = input.goal.param_env.fold_with(&mut env_canonicalizer);
117+
debug_assert_eq!(env_canonicalizer.binder_index, ty::INNERMOST);
118+
// Then canonicalize the rest of the input without keeping `'static`
119+
// while *mostly* reusing the canonicalizer from above.
120+
let mut rest_canonicalizer = Canonicalizer {
121+
delegate,
122+
canonicalize_mode: CanonicalizeMode::Input { keep_static: false },
123+
124+
variables: env_canonicalizer.variables,
125+
// We're able to reuse the `variable_lookup_table` as whether or not
126+
// it already contains an entry for `'static` does not matter.
127+
variable_lookup_table: env_canonicalizer.variable_lookup_table,
128+
primitive_var_infos: env_canonicalizer.primitive_var_infos,
129+
binder_index: ty::INNERMOST,
85130

131+
// We do not reuse the cache as it may contain entries whose canonicalized
132+
// value contains `'static`. While we could alternatively handle this by
133+
// checking for `'static` when using cached entries, this does not
134+
// feel worth the effort. I do not expect that a `ParamEnv` will ever
135+
// contain large enough types for caching to be necessary.
136+
cache: Default::default(),
137+
};
138+
139+
let predicate = input.goal.predicate.fold_with(&mut rest_canonicalizer);
140+
let goal = Goal { param_env, predicate };
141+
let predefined_opaques_in_body =
142+
input.predefined_opaques_in_body.fold_with(&mut rest_canonicalizer);
143+
let value = QueryInput { goal, predefined_opaques_in_body };
144+
145+
assert!(!value.has_infer(), "unexpected infer in {value:?}");
146+
assert!(!value.has_placeholders(), "unexpected placeholders in {value:?}");
147+
let (max_universe, variables) = rest_canonicalizer.finalize();
86148
Canonical { max_universe, variables, value }
87149
}
88150

@@ -126,7 +188,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
126188
// all information which should not matter for the solver.
127189
//
128190
// For this we compress universes as much as possible.
129-
CanonicalizeMode::Input => {}
191+
CanonicalizeMode::Input { .. } => {}
130192
// When canonicalizing a response we map a universes already entered
131193
// by the caller to the root universe and only return useful universe
132194
// information for placeholders and inference variables created inside
@@ -290,17 +352,15 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
290352
}
291353
},
292354
ty::Placeholder(placeholder) => match self.canonicalize_mode {
293-
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(PlaceholderLike::new(
294-
placeholder.universe(),
295-
self.variables.len().into(),
296-
)),
355+
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
356+
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
357+
),
297358
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
298359
},
299360
ty::Param(_) => match self.canonicalize_mode {
300-
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(PlaceholderLike::new(
301-
ty::UniverseIndex::ROOT,
302-
self.variables.len().into(),
303-
)),
361+
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
362+
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
363+
),
304364
CanonicalizeMode::Response { .. } => panic!("param ty in response: {t:?}"),
305365
},
306366
ty::Bool
@@ -357,29 +417,38 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
357417
let kind = match r.kind() {
358418
ty::ReBound(..) => return r,
359419

360-
// We may encounter `ReStatic` in item signatures or the hidden type
361-
// of an opaque. `ReErased` should only be encountered in the hidden
420+
// We don't canonicalize `ReStatic` in the `param_env` as we use it
421+
// when checking whether a `ParamEnv` candidate is global.
422+
ty::ReStatic => match self.canonicalize_mode {
423+
CanonicalizeMode::Input { keep_static: false } => {
424+
CanonicalVarKind::Region(ty::UniverseIndex::ROOT)
425+
}
426+
CanonicalizeMode::Input { keep_static: true }
427+
| CanonicalizeMode::Response { .. } => return r,
428+
},
429+
430+
// `ReErased` should only be encountered in the hidden
362431
// type of an opaque for regions that are ignored for the purposes of
363432
// captures.
364433
//
365434
// FIXME: We should investigate the perf implications of not uniquifying
366435
// `ReErased`. We may be able to short-circuit registering region
367436
// obligations if we encounter a `ReErased` on one side, for example.
368-
ty::ReStatic | ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
369-
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
437+
ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
438+
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
370439
CanonicalizeMode::Response { .. } => return r,
371440
},
372441

373442
ty::ReEarlyParam(_) | ty::ReLateParam(_) => match self.canonicalize_mode {
374-
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
443+
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
375444
CanonicalizeMode::Response { .. } => {
376445
panic!("unexpected region in response: {r:?}")
377446
}
378447
},
379448

380449
ty::RePlaceholder(placeholder) => match self.canonicalize_mode {
381450
// We canonicalize placeholder regions as existentials in query inputs.
382-
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
451+
CanonicalizeMode::Input { .. } => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
383452
CanonicalizeMode::Response { max_input_universe } => {
384453
// If we have a placeholder region inside of a query, it must be from
385454
// a new universe.
@@ -397,7 +466,9 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
397466
"region vid should have been resolved fully before canonicalization"
398467
);
399468
match self.canonicalize_mode {
400-
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
469+
CanonicalizeMode::Input { keep_static: _ } => {
470+
CanonicalVarKind::Region(ty::UniverseIndex::ROOT)
471+
}
401472
CanonicalizeMode::Response { .. } => {
402473
CanonicalVarKind::Region(self.delegate.universe_of_lt(vid).unwrap())
403474
}
@@ -434,15 +505,15 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
434505
ty::InferConst::Fresh(_) => todo!(),
435506
},
436507
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
437-
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
508+
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
438509
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
439510
),
440511
CanonicalizeMode::Response { .. } => {
441512
CanonicalVarKind::PlaceholderConst(placeholder)
442513
}
443514
},
444515
ty::ConstKind::Param(_) => match self.canonicalize_mode {
445-
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
516+
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
446517
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
447518
),
448519
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),

0 commit comments

Comments
 (0)