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 11 pull requests #111153

Merged
merged 31 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e40a446
Support loading version information from xz tarballs
Mark-Simulacrum Apr 17, 2023
20742ea
Adjust obligation cause code for find_and_report_unsatisfied_index_impl
compiler-errors Apr 26, 2023
25e9b79
interpret: fail more gracefully on uninit unsized locals
RalfJung Apr 27, 2023
6fcf165
move some const-prop tests to appropriate folder
RalfJung Apr 28, 2023
b4ba2f0
Change rlink serialization from `MemEncoder` to `FileEncoder`.
nnethercote May 1, 2023
0453cda
Don't bail out early when checking invalid `repr` attr
clubby789 May 1, 2023
bc68de9
remove pointless `FIXME` in `bootstrap::download`
onur-ozkan May 1, 2023
8d359e4
Move some `Encodable`/`Decodable` tests.
nnethercote May 2, 2023
ebee3f8
Remove `MemEncoder`.
nnethercote May 1, 2023
ef77dd2
resolve: One more attempt to simplify `module_children`
petrochenkov Apr 27, 2023
7bc6d59
Avoid ICEing miri on layout query cycles
oli-obk May 2, 2023
6af761a
Add some triagebot notifications for nnethercote.
nnethercote May 2, 2023
51b9f78
Amend the triagebot comment for `Cargo.lock` changes.
nnethercote May 2, 2023
6e01e91
Implement negative bounds
compiler-errors Apr 25, 2023
86f50b9
Disallow associated type constraints on negative bounds
compiler-errors Apr 25, 2023
40a63cb
Make tools happy
compiler-errors Apr 25, 2023
03469c3
Make negative trait bounds work with the old trait solver
compiler-errors Apr 25, 2023
6fca051
Rustfmt support for negative bounds, test
compiler-errors Apr 26, 2023
6e37784
Correctly convert an NT path to a Win32 path
ChrisDenton Feb 12, 2023
109a47f
Use `from_wide_to_user_path` in `read_link`
ChrisDenton May 3, 2023
068807a
Rollup merge of #107978 - ChrisDenton:nt-to-win32, r=m-ou-se
Dylan-DPC May 3, 2023
32f3ddb
Rollup merge of #110436 - Mark-Simulacrum:support-xz-version, r=pietr…
Dylan-DPC May 3, 2023
80df4ab
Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obk
Dylan-DPC May 3, 2023
a2e4dab
Rollup merge of #110874 - compiler-errors:index-op-specific, r=oli-obk
Dylan-DPC May 3, 2023
0228994
Rollup merge of #110908 - petrochenkov:notagain4, r=compiler-errors
Dylan-DPC May 3, 2023
8b7080b
Rollup merge of #110943 - RalfJung:interpret-unsized-arg-ice, r=oli-obk
Dylan-DPC May 3, 2023
fce0741
Rollup merge of #111062 - clubby789:invalid-repr-unchecked, r=petroch…
Dylan-DPC May 3, 2023
a47fa34
Rollup merge of #111069 - ozkanonur:remove-pointless-fixme, r=albertl…
Dylan-DPC May 3, 2023
887dffc
Rollup merge of #111086 - nnethercote:rm-MemEncoder, r=cjgillot
Dylan-DPC May 3, 2023
e87fcf9
Rollup merge of #111097 - oli-obk:🚲_layout, r=compiler-errors
Dylan-DPC May 3, 2023
b5bbe68
Rollup merge of #111112 - nnethercote:triagebot, r=compiler-errors
Dylan-DPC May 3, 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
10 changes: 6 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ dependencies = [
"sha2",
"tar",
"toml",
"xz2",
]

[[package]]
Expand Down Expand Up @@ -2060,9 +2061,9 @@ dependencies = [

[[package]]
name = "lzma-sys"
version = "0.1.16"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f24f76ec44a8ac23a31915d6e326bca17ce88da03096f1ff194925dc714dac99"
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
dependencies = [
"cc",
"libc",
Expand Down Expand Up @@ -4059,6 +4060,7 @@ dependencies = [
"indexmap",
"rustc_macros",
"smallvec",
"tempfile",
"thin-vec",
]

Expand Down Expand Up @@ -5658,9 +5660,9 @@ dependencies = [

[[package]]
name = "xz2"
version = "0.1.6"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
dependencies = [
"lzma-sys",
]
Expand Down
18 changes: 18 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,20 @@ pub enum TraitBoundModifier {
/// No modifiers
None,

/// `!Trait`
Negative,

/// `?Trait`
Maybe,

/// `~const Trait`
MaybeConst,

/// `~const !Trait`
//
// This parses but will be rejected during AST validation.
MaybeConstNegative,

/// `~const ?Trait`
//
// This parses but will be rejected during AST validation.
Expand Down Expand Up @@ -2446,6 +2454,16 @@ impl fmt::Debug for ImplPolarity {
}
}

#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
pub enum BoundPolarity {
/// `Type: Trait`
Positive,
/// `Type: !Trait`
Negative(Span),
/// `Type: ?Trait`
Maybe(Span),
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub enum FnRetTy {
/// Returns type is not specified.
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,13 +1368,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
GenericBound::Trait(
ty,
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
TraitBoundModifier::None
| TraitBoundModifier::MaybeConst
| TraitBoundModifier::Negative,
) => Some(this.lower_poly_trait_ref(ty, itctx)),
// `~const ?Bound` will cause an error during AST validation
// anyways, so treat it like `?Bound` as compilation proceeds.
GenericBound::Trait(
_,
TraitBoundModifier::Maybe | TraitBoundModifier::MaybeConstMaybe,
TraitBoundModifier::Maybe
| TraitBoundModifier::MaybeConstMaybe
| TraitBoundModifier::MaybeConstNegative,
) => None,
GenericBound::Outlives(lifetime) => {
if lifetime_bound.is_none() {
Expand Down Expand Up @@ -2421,11 +2425,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
TraitBoundModifier::None => hir::TraitBoundModifier::None,
TraitBoundModifier::MaybeConst => hir::TraitBoundModifier::MaybeConst,

TraitBoundModifier::Negative => {
if self.tcx.features().negative_bounds {
hir::TraitBoundModifier::Negative
} else {
hir::TraitBoundModifier::None
}
}

// `MaybeConstMaybe` will cause an error during AST validation, but we need to pick a
// placeholder for compilation to proceed.
TraitBoundModifier::MaybeConstMaybe | TraitBoundModifier::Maybe => {
hir::TraitBoundModifier::Maybe
}
TraitBoundModifier::MaybeConstNegative => hir::TraitBoundModifier::MaybeConst,
}
}

Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
.closure = closures cannot have `~const` trait bounds
.function = this function is not `const`, so it cannot have `~const` trait bounds

ast_passes_optional_const_exclusive = `~const` and `?` are mutually exclusive
ast_passes_optional_const_exclusive = `~const` and `{$modifier}` are mutually exclusive

ast_passes_const_and_async = functions cannot be both `const` and `async`
.const = `const` because of this
Expand Down Expand Up @@ -235,3 +235,9 @@ ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using t
.help = remove one of these features

ast_passes_show_span = {$msg}

ast_passes_negative_bound_not_supported =
negative bounds are not supported

ast_passes_constraint_on_negative_bound =
associated type constraints not allowed on negative bounds
17 changes: 16 additions & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,27 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
});
}
(_, TraitBoundModifier::MaybeConstMaybe) => {
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span()});
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "?" });
}
(_, TraitBoundModifier::MaybeConstNegative) => {
self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "!" });
}
_ => {}
}
}

// Negative trait bounds are not allowed to have associated constraints
if let GenericBound::Trait(trait_ref, TraitBoundModifier::Negative) = bound
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
&& let Some(ast::GenericArgs::AngleBracketed(args)) = segment.args.as_deref()
{
for arg in &args.args {
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
self.err_handler().emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
}
}
}

visit::walk_param_bound(self, bound)
}

Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ pub enum TildeConstReason {
pub struct OptionalConstExclusive {
#[primary_span]
pub span: Span,
pub modifier: &'static str,
}

#[derive(Diagnostic)]
Expand Down Expand Up @@ -693,3 +694,17 @@ pub struct ShowSpan {
pub span: Span,
pub msg: &'static str,
}

#[derive(Diagnostic)]
#[diag(ast_passes_negative_bound_not_supported)]
pub struct NegativeBoundUnsupported {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_constraint_on_negative_bound)]
pub struct ConstraintOnNegativeBound {
#[primary_span]
pub span: Span,
}
6 changes: 6 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
gate_all!(const_closures, "const closures are experimental");

if !visitor.features.negative_bounds {
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
sess.emit_err(errors::NegativeBoundUnsupported { span });
}
}

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
// We emit an early future-incompatible warning for these.
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,12 +1570,19 @@ impl<'a> State<'a> {
GenericBound::Trait(tref, modifier) => {
match modifier {
TraitBoundModifier::None => {}
TraitBoundModifier::Negative => {
self.word("!");
}
TraitBoundModifier::Maybe => {
self.word("?");
}
TraitBoundModifier::MaybeConst => {
self.word_space("~const");
}
TraitBoundModifier::MaybeConstNegative => {
self.word_space("~const");
self.word("!");
}
TraitBoundModifier::MaybeConstMaybe => {
self.word_space("~const");
self.word("?");
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_serialize::opaque::{MemDecoder, MemEncoder};
use rustc_serialize::opaque::{FileEncoder, MemDecoder};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
use rustc_session::cstore::{self, CrateSource};
use rustc_session::utils::NativeLibKind;
use rustc_span::symbol::Symbol;
use rustc_span::DebuggerVisualizerFile;
use std::collections::BTreeSet;
use std::io;
use std::path::{Path, PathBuf};

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

impl CodegenResults {
pub fn serialize_rlink(codegen_results: &CodegenResults) -> Vec<u8> {
let mut encoder = MemEncoder::new();
pub fn serialize_rlink(
rlink_file: &Path,
codegen_results: &CodegenResults,
) -> Result<usize, io::Error> {
let mut encoder = FileEncoder::new(rlink_file)?;
encoder.emit_raw_bytes(RLINK_MAGIC);
// `emit_raw_bytes` is used to make sure that the version representation does not depend on
// Encoder's inner representation of `u32`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/valtrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn valtree_into_mplace<'tcx>(

match ty.kind() {
ty::FnDef(_, _) => {
ecx.write_immediate(Immediate::Uninit, &place.into()).unwrap();
// Zero-sized type, nothing to do.
}
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
let scalar_int = valtree.unwrap_leaf();
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
impl<'tcx, Prov: Provenance> OpTy<'tcx, Prov> {
pub fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
if self.layout.is_unsized() {
if matches!(self.op, Operand::Immediate(Immediate::Uninit)) {
// Uninit unsized places shouldn't occur. In the interpreter we have them
// temporarily for unsized arguments before their value is put in; in ConstProp they
// remain uninit and this code can actually be reached.
throw_inval!(UninitUnsizedLocal);
}
// There are no unsized immediates.
self.assert_mem_place().len(cx)
} else {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ declare_features! (
(active, link_cfg, "1.14.0", None, None),
/// Allows the `multiple_supertrait_upcastable` lint.
(active, multiple_supertrait_upcastable, "1.69.0", None, None),
/// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!
(incomplete, negative_bounds, "CURRENT_RUSTC_VERSION", None, None),
/// Allows using `#[omit_gdb_pretty_printer_section]`.
(active, omit_gdb_pretty_printer_section, "1.5.0", None, None),
/// Allows using `#[prelude_import]` on glob `use` items.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ pub enum GenericArgsParentheses {
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
pub enum TraitBoundModifier {
None,
Negative,
Maybe,
MaybeConst,
}
Expand Down
Loading