Skip to content

Commit 473f916

Browse files
committed
Auto merge of rust-lang#111153 - Dylan-DPC:rollup-0pq0hh3, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#107978 (Correctly convert an NT path to a Win32 path in `read_link`) - rust-lang#110436 (Support loading version information from xz tarballs) - rust-lang#110791 (Implement negative bounds for internal testing purposes) - rust-lang#110874 (Adjust obligation cause code for `find_and_report_unsatisfied_index_impl`) - rust-lang#110908 (resolve: One more attempt to simplify `module_children`) - rust-lang#110943 (interpret: fail more gracefully on uninit unsized locals) - rust-lang#111062 (Don't bail out early when checking invalid `repr` attr) - rust-lang#111069 (remove pointless `FIXME` in `bootstrap::download`) - rust-lang#111086 (Remove `MemEncoder`) - rust-lang#111097 (Avoid ICEing miri on layout query cycles) - rust-lang#111112 (Add some triagebot notifications for nnethercote.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9b99ff7 + b5bbe68 commit 473f916

File tree

91 files changed

+846
-579
lines changed

Some content is hidden

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

91 files changed

+846
-579
lines changed

Cargo.lock

+6-4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ dependencies = [
297297
"sha2",
298298
"tar",
299299
"toml",
300+
"xz2",
300301
]
301302

302303
[[package]]
@@ -2060,9 +2061,9 @@ dependencies = [
20602061

20612062
[[package]]
20622063
name = "lzma-sys"
2063-
version = "0.1.16"
2064+
version = "0.1.20"
20642065
source = "registry+https://github.com/rust-lang/crates.io-index"
2065-
checksum = "f24f76ec44a8ac23a31915d6e326bca17ce88da03096f1ff194925dc714dac99"
2066+
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
20662067
dependencies = [
20672068
"cc",
20682069
"libc",
@@ -4059,6 +4060,7 @@ dependencies = [
40594060
"indexmap",
40604061
"rustc_macros",
40614062
"smallvec",
4063+
"tempfile",
40624064
"thin-vec",
40634065
]
40644066

@@ -5658,9 +5660,9 @@ dependencies = [
56585660

56595661
[[package]]
56605662
name = "xz2"
5661-
version = "0.1.6"
5663+
version = "0.1.7"
56625664
source = "registry+https://github.com/rust-lang/crates.io-index"
5663-
checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
5665+
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
56645666
dependencies = [
56655667
"lzma-sys",
56665668
]

compiler/rustc_ast/src/ast.rs

+18
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,20 @@ pub enum TraitBoundModifier {
287287
/// No modifiers
288288
None,
289289

290+
/// `!Trait`
291+
Negative,
292+
290293
/// `?Trait`
291294
Maybe,
292295

293296
/// `~const Trait`
294297
MaybeConst,
295298

299+
/// `~const !Trait`
300+
//
301+
// This parses but will be rejected during AST validation.
302+
MaybeConstNegative,
303+
296304
/// `~const ?Trait`
297305
//
298306
// This parses but will be rejected during AST validation.
@@ -2446,6 +2454,16 @@ impl fmt::Debug for ImplPolarity {
24462454
}
24472455
}
24482456

2457+
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
2458+
pub enum BoundPolarity {
2459+
/// `Type: Trait`
2460+
Positive,
2461+
/// `Type: !Trait`
2462+
Negative(Span),
2463+
/// `Type: ?Trait`
2464+
Maybe(Span),
2465+
}
2466+
24492467
#[derive(Clone, Encodable, Decodable, Debug)]
24502468
pub enum FnRetTy {
24512469
/// Returns type is not specified.

compiler/rustc_ast_lowering/src/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1368,13 +1368,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13681368
this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
13691369
GenericBound::Trait(
13701370
ty,
1371-
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
1371+
TraitBoundModifier::None
1372+
| TraitBoundModifier::MaybeConst
1373+
| TraitBoundModifier::Negative,
13721374
) => Some(this.lower_poly_trait_ref(ty, itctx)),
13731375
// `~const ?Bound` will cause an error during AST validation
13741376
// anyways, so treat it like `?Bound` as compilation proceeds.
13751377
GenericBound::Trait(
13761378
_,
1377-
TraitBoundModifier::Maybe | TraitBoundModifier::MaybeConstMaybe,
1379+
TraitBoundModifier::Maybe
1380+
| TraitBoundModifier::MaybeConstMaybe
1381+
| TraitBoundModifier::MaybeConstNegative,
13781382
) => None,
13791383
GenericBound::Outlives(lifetime) => {
13801384
if lifetime_bound.is_none() {
@@ -2421,11 +2425,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24212425
TraitBoundModifier::None => hir::TraitBoundModifier::None,
24222426
TraitBoundModifier::MaybeConst => hir::TraitBoundModifier::MaybeConst,
24232427

2428+
TraitBoundModifier::Negative => {
2429+
if self.tcx.features().negative_bounds {
2430+
hir::TraitBoundModifier::Negative
2431+
} else {
2432+
hir::TraitBoundModifier::None
2433+
}
2434+
}
2435+
24242436
// `MaybeConstMaybe` will cause an error during AST validation, but we need to pick a
24252437
// placeholder for compilation to proceed.
24262438
TraitBoundModifier::MaybeConstMaybe | TraitBoundModifier::Maybe => {
24272439
hir::TraitBoundModifier::Maybe
24282440
}
2441+
TraitBoundModifier::MaybeConstNegative => hir::TraitBoundModifier::MaybeConst,
24292442
}
24302443
}
24312444

compiler/rustc_ast_passes/messages.ftl

+7-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
206206
.closure = closures cannot have `~const` trait bounds
207207
.function = this function is not `const`, so it cannot have `~const` trait bounds
208208
209-
ast_passes_optional_const_exclusive = `~const` and `?` are mutually exclusive
209+
ast_passes_optional_const_exclusive = `~const` and `{$modifier}` are mutually exclusive
210210
211211
ast_passes_const_and_async = functions cannot be both `const` and `async`
212212
.const = `const` because of this
@@ -235,3 +235,9 @@ ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using t
235235
.help = remove one of these features
236236
237237
ast_passes_show_span = {$msg}
238+
239+
ast_passes_negative_bound_not_supported =
240+
negative bounds are not supported
241+
242+
ast_passes_constraint_on_negative_bound =
243+
associated type constraints not allowed on negative bounds

compiler/rustc_ast_passes/src/ast_validation.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1168,12 +1168,27 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11681168
});
11691169
}
11701170
(_, TraitBoundModifier::MaybeConstMaybe) => {
1171-
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span()});
1171+
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "?" });
1172+
}
1173+
(_, TraitBoundModifier::MaybeConstNegative) => {
1174+
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "!" });
11721175
}
11731176
_ => {}
11741177
}
11751178
}
11761179

1180+
// Negative trait bounds are not allowed to have associated constraints
1181+
if let GenericBound::Trait(trait_ref, TraitBoundModifier::Negative) = bound
1182+
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
1183+
&& let Some(ast::GenericArgs::AngleBracketed(args)) = segment.args.as_deref()
1184+
{
1185+
for arg in &args.args {
1186+
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
1187+
self.err_handler().emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
1188+
}
1189+
}
1190+
}
1191+
11771192
visit::walk_param_bound(self, bound)
11781193
}
11791194

compiler/rustc_ast_passes/src/errors.rs

+15
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ pub enum TildeConstReason {
567567
pub struct OptionalConstExclusive {
568568
#[primary_span]
569569
pub span: Span,
570+
pub modifier: &'static str,
570571
}
571572

572573
#[derive(Diagnostic)]
@@ -693,3 +694,17 @@ pub struct ShowSpan {
693694
pub span: Span,
694695
pub msg: &'static str,
695696
}
697+
698+
#[derive(Diagnostic)]
699+
#[diag(ast_passes_negative_bound_not_supported)]
700+
pub struct NegativeBoundUnsupported {
701+
#[primary_span]
702+
pub span: Span,
703+
}
704+
705+
#[derive(Diagnostic)]
706+
#[diag(ast_passes_constraint_on_negative_bound)]
707+
pub struct ConstraintOnNegativeBound {
708+
#[primary_span]
709+
pub span: Span,
710+
}

compiler/rustc_ast_passes/src/feature_gate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
603603
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
604604
gate_all!(const_closures, "const closures are experimental");
605605

606+
if !visitor.features.negative_bounds {
607+
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
608+
sess.emit_err(errors::NegativeBoundUnsupported { span });
609+
}
610+
}
611+
606612
// All uses of `gate_all!` below this point were added in #65742,
607613
// and subsequently disabled (with the non-early gating readded).
608614
// We emit an early future-incompatible warning for these.

compiler/rustc_ast_pretty/src/pprust/state.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1570,12 +1570,19 @@ impl<'a> State<'a> {
15701570
GenericBound::Trait(tref, modifier) => {
15711571
match modifier {
15721572
TraitBoundModifier::None => {}
1573+
TraitBoundModifier::Negative => {
1574+
self.word("!");
1575+
}
15731576
TraitBoundModifier::Maybe => {
15741577
self.word("?");
15751578
}
15761579
TraitBoundModifier::MaybeConst => {
15771580
self.word_space("~const");
15781581
}
1582+
TraitBoundModifier::MaybeConstNegative => {
1583+
self.word_space("~const");
1584+
self.word("!");
1585+
}
15791586
TraitBoundModifier::MaybeConstMaybe => {
15801587
self.word_space("~const");
15811588
self.word("?");

compiler/rustc_codegen_ssa/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ use rustc_middle::dep_graph::WorkProduct;
3131
use rustc_middle::middle::dependency_format::Dependencies;
3232
use rustc_middle::middle::exported_symbols::SymbolExportKind;
3333
use rustc_middle::ty::query::{ExternProviders, Providers};
34-
use rustc_serialize::opaque::{MemDecoder, MemEncoder};
34+
use rustc_serialize::opaque::{FileEncoder, MemDecoder};
3535
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3636
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
3737
use rustc_session::cstore::{self, CrateSource};
3838
use rustc_session::utils::NativeLibKind;
3939
use rustc_span::symbol::Symbol;
4040
use rustc_span::DebuggerVisualizerFile;
4141
use std::collections::BTreeSet;
42+
use std::io;
4243
use std::path::{Path, PathBuf};
4344

4445
pub mod back;
@@ -215,8 +216,11 @@ const RLINK_MAGIC: &[u8] = b"rustlink";
215216
const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");
216217

217218
impl CodegenResults {
218-
pub fn serialize_rlink(codegen_results: &CodegenResults) -> Vec<u8> {
219-
let mut encoder = MemEncoder::new();
219+
pub fn serialize_rlink(
220+
rlink_file: &Path,
221+
codegen_results: &CodegenResults,
222+
) -> Result<usize, io::Error> {
223+
let mut encoder = FileEncoder::new(rlink_file)?;
220224
encoder.emit_raw_bytes(RLINK_MAGIC);
221225
// `emit_raw_bytes` is used to make sure that the version representation does not depend on
222226
// Encoder's inner representation of `u32`.

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn valtree_into_mplace<'tcx>(
337337

338338
match ty.kind() {
339339
ty::FnDef(_, _) => {
340-
ecx.write_immediate(Immediate::Uninit, &place.into()).unwrap();
340+
// Zero-sized type, nothing to do.
341341
}
342342
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
343343
let scalar_int = valtree.unwrap_leaf();

compiler/rustc_const_eval/src/interpret/operand.rs

+6
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
245245
impl<'tcx, Prov: Provenance> OpTy<'tcx, Prov> {
246246
pub fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
247247
if self.layout.is_unsized() {
248+
if matches!(self.op, Operand::Immediate(Immediate::Uninit)) {
249+
// Uninit unsized places shouldn't occur. In the interpreter we have them
250+
// temporarily for unsized arguments before their value is put in; in ConstProp they
251+
// remain uninit and this code can actually be reached.
252+
throw_inval!(UninitUnsizedLocal);
253+
}
248254
// There are no unsized immediates.
249255
self.assert_mem_place().len(cx)
250256
} else {

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ declare_features! (
164164
(active, link_cfg, "1.14.0", None, None),
165165
/// Allows the `multiple_supertrait_upcastable` lint.
166166
(active, multiple_supertrait_upcastable, "1.69.0", None, None),
167+
/// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!
168+
(incomplete, negative_bounds, "CURRENT_RUSTC_VERSION", None, None),
167169
/// Allows using `#[omit_gdb_pretty_printer_section]`.
168170
(active, omit_gdb_pretty_printer_section, "1.5.0", None, None),
169171
/// Allows using `#[prelude_import]` on glob `use` items.

compiler/rustc_hir/src/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ pub enum GenericArgsParentheses {
435435
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
436436
pub enum TraitBoundModifier {
437437
None,
438+
Negative,
438439
Maybe,
439440
MaybeConst,
440441
}

0 commit comments

Comments
 (0)