Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: pnkfelix/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: rustc-contracts-ast
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 13 commits
  • 83 files changed
  • 1 contributor

Commits on Oct 14, 2024

  1. Copy the full SHA
    e8b3a46 View commit details

Commits on Oct 15, 2024

  1. Copy the full SHA
    59642ca View commit details
  2. checkpoint compiler and rustdoc changes that build with some HIR adop…

    …tion of contract form.
    pnkfelix committed Oct 15, 2024
    Copy the full SHA
    93d3633 View commit details

Commits on Oct 16, 2024

  1. Copy the full SHA
    80d2036 View commit details
  2. Copy the full SHA
    91af61c View commit details

Commits on Oct 17, 2024

  1. Copy the full SHA
    3ffe83d View commit details
  2. Match what rustfmt wants.

    pnkfelix committed Oct 17, 2024
    Copy the full SHA
    17d4ea0 View commit details
  3. Copy the full SHA
    d1f03ae View commit details
  4. Copy the full SHA
    1504e07 View commit details

Commits on Oct 22, 2024

  1. Copy the full SHA
    cd74991 View commit details

Commits on Oct 28, 2024

  1. Copy the full SHA
    3007ba7 View commit details

Commits on Oct 29, 2024

  1. attempt to fill in blanks re contract codegen. it still ICEs -- namel…

    …y stealing an already stolen thir_body in visit_inner_body of check_unsafety.rs:205.
    pnkfelix committed Oct 29, 2024
    Copy the full SHA
    44e97b4 View commit details

Commits on Oct 31, 2024

  1. instrument steal code a bit.

    pnkfelix committed Oct 31, 2024
    Copy the full SHA
    59805ae View commit details
Showing with 734 additions and 313 deletions.
  1. +8 −1 compiler/rustc_ast/src/ast.rs
  2. +19 −3 compiler/rustc_ast/src/mut_visit.rs
  3. +58 −12 compiler/rustc_ast/src/visit.rs
  4. +89 −30 compiler/rustc_ast_lowering/src/item.rs
  5. +8 −5 compiler/rustc_ast_lowering/src/lib.rs
  6. +8 −5 compiler/rustc_ast_passes/src/ast_validation.rs
  7. +19 −5 compiler/rustc_ast_pretty/src/pprust/state/item.rs
  8. +38 −23 compiler/rustc_borrowck/src/universal_regions.rs
  9. +3 −1 compiler/rustc_builtin_macros/src/alloc_error_handler.rs
  10. +1 −0 compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
  11. +1 −0 compiler/rustc_builtin_macros/src/global_allocator.rs
  12. +1 −0 compiler/rustc_builtin_macros/src/test_harness.rs
  13. +27 −3 compiler/rustc_data_structures/src/steal.rs
  14. +7 −1 compiler/rustc_hir/src/def.rs
  15. +4 −1 compiler/rustc_hir/src/definitions.rs
  16. +49 −25 compiler/rustc_hir/src/hir.rs
  17. +25 −3 compiler/rustc_hir/src/intravisit.rs
  18. +4 −4 compiler/rustc_hir_analysis/src/check/entry.rs
  19. +1 −1 compiler/rustc_hir_analysis/src/check/intrinsic.rs
  20. +2 −1 compiler/rustc_hir_analysis/src/check/wfcheck.rs
  21. +1 −1 compiler/rustc_hir_analysis/src/collect.rs
  22. +3 −2 compiler/rustc_hir_analysis/src/collect/generics_of.rs
  23. +5 −5 compiler/rustc_hir_analysis/src/collect/predicates_of.rs
  24. +1 −1 compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
  25. +2 −2 compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs
  26. +26 −2 compiler/rustc_hir_pretty/src/lib.rs
  27. +1 −1 compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
  28. +1 −0 compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
  29. +1 −1 compiler/rustc_hir_typeck/src/upvar.rs
  30. +5 −3 compiler/rustc_hir_typeck/src/writeback.rs
  31. +2 −1 compiler/rustc_lint/src/builtin.rs
  32. +1 −1 compiler/rustc_lint/src/early.rs
  33. +22 −11 compiler/rustc_metadata/src/rmeta/encoder.rs
  34. +1 −0 compiler/rustc_metadata/src/rmeta/table.rs
  35. +17 −4 compiler/rustc_middle/src/hir/map/mod.rs
  36. +2 −1 compiler/rustc_middle/src/thir.rs
  37. +42 −35 compiler/rustc_middle/src/ty/context.rs
  38. +31 −1 compiler/rustc_mir_build/src/build/mod.rs
  39. +6 −6 compiler/rustc_mir_build/src/thir/cx/mod.rs
  40. +7 −3 compiler/rustc_mir_build/src/thir/pattern/check_match.rs
  41. +2 −1 compiler/rustc_monomorphize/src/polymorphize.rs
  42. +15 −0 compiler/rustc_parse/src/parser/generics.rs
  43. +7 −5 compiler/rustc_parse/src/parser/item.rs
  44. +1 −1 compiler/rustc_passes/src/check_attr.rs
  45. +1 −1 compiler/rustc_passes/src/naked_functions.rs
  46. +1 −1 compiler/rustc_passes/src/stability.rs
  47. +25 −11 compiler/rustc_privacy/src/lib.rs
  48. +3 −2 compiler/rustc_resolve/src/build_reduced_graph.rs
  49. +4 −1 compiler/rustc_resolve/src/def_collector.rs
  50. +5 −3 compiler/rustc_resolve/src/late.rs
  51. +3 −3 compiler/rustc_resolve/src/late/diagnostics.rs
  52. +4 −3 compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs
  53. +2 −1 compiler/rustc_smir/src/rustc_smir/mod.rs
  54. +3 −0 compiler/rustc_span/src/symbol.rs
  55. +2 −1 compiler/rustc_symbol_mangling/src/v0.rs
  56. +1 −1 compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
  57. +1 −1 compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs
  58. +1 −1 compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
  59. +6 −6 compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
  60. +5 −4 compiler/rustc_ty_utils/src/implied_bounds.rs
  61. +2 −1 compiler/rustc_ty_utils/src/opaque_types.rs
  62. +1 −0 compiler/rustc_ty_utils/src/sig_types.rs
  63. +1 −1 src/librustdoc/clean/mod.rs
  64. +1 −0 src/librustdoc/formats/item_type.rs
  65. +1 −1 src/librustdoc/html/render/span_map.rs
  66. +1 −0 src/librustdoc/passes/collect_intra_doc_links.rs
  67. +1 −1 src/tools/clippy/clippy_lints/src/attrs/utils.rs
  68. +4 −4 src/tools/clippy/clippy_lints/src/doc/mod.rs
  69. +3 −3 src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs
  70. +2 −2 src/tools/clippy/clippy_lints/src/functions/must_use.rs
  71. +3 −3 src/tools/clippy/clippy_lints/src/functions/result.rs
  72. +4 −4 src/tools/clippy/clippy_lints/src/implicit_hasher.rs
  73. +9 −9 src/tools/clippy/clippy_lints/src/lifetimes.rs
  74. +2 −2 src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs
  75. +3 −3 src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
  76. +1 −1 src/tools/clippy/clippy_lints/src/multiple_bound_locations.rs
  77. +1 −1 src/tools/clippy/clippy_lints/src/no_mangle_with_rust_abi.rs
  78. +1 −1 src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
  79. +5 −5 src/tools/clippy/clippy_lints/src/returns.rs
  80. +23 −0 src/tools/clippy/clippy_utils/src/ast_utils.rs
  81. +15 −15 src/tools/clippy/clippy_utils/src/lib.rs
  82. +4 −2 src/tools/rustfmt/src/items.rs
  83. +5 −2 src/tools/rustfmt/src/visitor.rs
9 changes: 8 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
@@ -3246,11 +3246,18 @@ pub struct Impl {
pub items: ThinVec<P<AssocItem>>,
}

#[derive(Clone, Encodable, Decodable, Debug, Default)]
pub struct FnContract {
pub requires: Option<P<Expr>>,
pub ensures: Option<P<Expr>>,
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Fn {
pub defaultness: Defaultness,
pub generics: Generics,
pub sig: FnSig,
pub contract: FnContract,
pub body: Option<P<Block>>,
}

@@ -3548,7 +3555,7 @@ mod size_asserts {
static_assert_size!(Block, 32);
static_assert_size!(Expr, 72);
static_assert_size!(ExprKind, 40);
static_assert_size!(Fn, 160);
static_assert_size!(Fn, 176);
static_assert_size!(ForeignItem, 88);
static_assert_size!(ForeignItemKind, 16);
static_assert_size!(GenericArg, 24);
22 changes: 19 additions & 3 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
@@ -119,6 +119,10 @@ pub trait MutVisitor: Sized {
walk_flat_map_item(self, i)
}

fn visit_contract(&mut self, c: &mut FnContract) {
walk_contract(self, c);
}

fn visit_fn_decl(&mut self, d: &mut P<FnDecl>) {
walk_fn_decl(self, d);
}
@@ -898,6 +902,15 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
}
}

fn walk_contract<T: MutVisitor>(vis: &mut T, contract: &mut FnContract) {
if let Some(pred) = &mut contract.requires {
vis.visit_expr(pred);
}
if let Some(pred) = &mut contract.ensures {
vis.visit_expr(pred);
}
}

fn walk_fn_decl<T: MutVisitor>(vis: &mut T, decl: &mut P<FnDecl>) {
let FnDecl { inputs, output } = decl.deref_mut();
inputs.flat_map_in_place(|param| vis.flat_map_param(param));
@@ -1100,8 +1113,9 @@ impl WalkItemKind for ItemKind {
ItemKind::Const(item) => {
visit_const_item(item, vis);
}
ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
ItemKind::Fn(box Fn { defaultness, generics, sig, contract, body }) => {
visit_defaultness(vis, defaultness);
vis.visit_contract(contract);
vis.visit_fn(FnKind::Fn(sig, generics, body), span, id);
}
ItemKind::Mod(safety, mod_kind) => {
@@ -1206,8 +1220,9 @@ impl WalkItemKind for AssocItemKind {
AssocItemKind::Const(item) => {
visit_const_item(item, visitor);
}
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
AssocItemKind::Fn(box Fn { defaultness, generics, sig, contract, body }) => {
visit_defaultness(visitor, defaultness);
visitor.visit_contract(contract);
visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id);
}
AssocItemKind::Type(box TyAlias {
@@ -1311,8 +1326,9 @@ impl WalkItemKind for ForeignItemKind {
visitor.visit_ty(ty);
visit_opt(expr, |expr| visitor.visit_expr(expr));
}
ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
ForeignItemKind::Fn(box Fn { defaultness, generics, sig, contract, body }) => {
visit_defaultness(visitor, defaultness);
visitor.visit_contract(contract);
visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id);
}
ForeignItemKind::TyAlias(box TyAlias {
70 changes: 58 additions & 12 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@
pub use rustc_ast_ir::visit::VisitorResult;
pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list};
use rustc_span::Span;
use rustc_span::symbol::Ident;
use rustc_span::Span;

use crate::ast::*;
use crate::ptr::P;
@@ -66,7 +66,7 @@ impl BoundKind {
#[derive(Copy, Clone, Debug)]
pub enum FnKind<'a> {
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, &'a FnContract, Option<&'a Block>),

/// E.g., `|x, y| body`.
Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
@@ -75,7 +75,7 @@ pub enum FnKind<'a> {
impl<'a> FnKind<'a> {
pub fn header(&self) -> Option<&'a FnHeader> {
match *self {
FnKind::Fn(_, _, sig, _, _, _) => Some(&sig.header),
FnKind::Fn(_, _, sig, _, _, _, _) => Some(&sig.header),
FnKind::Closure(..) => None,
}
}
@@ -89,7 +89,7 @@ impl<'a> FnKind<'a> {

pub fn decl(&self) -> &'a FnDecl {
match self {
FnKind::Fn(_, _, sig, _, _, _) => &sig.decl,
FnKind::Fn(_, _, sig, _, _, _, _) => &sig.decl,
FnKind::Closure(_, _, decl, _) => decl,
}
}
@@ -188,6 +188,9 @@ pub trait Visitor<'ast>: Sized {
fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) -> Self::Result {
walk_closure_binder(self, b)
}
fn visit_contract(&mut self, c: &'ast FnContract) -> Self::Result {
walk_contract(self, c)
}
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) -> Self::Result {
walk_where_predicate(self, p)
}
@@ -359,8 +362,16 @@ impl WalkItemKind for ItemKind {
try_visit!(visitor.visit_ty(ty));
visit_opt!(visitor, visit_expr, expr);
}
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Free, *ident, sig, vis, generics, body.as_deref());
ItemKind::Fn(box Fn { defaultness: _, generics, sig, contract, body }) => {
let kind = FnKind::Fn(
FnCtxt::Free,
*ident,
sig,
vis,
generics,
&contract,
body.as_deref(),
);
try_visit!(visitor.visit_fn(kind, *span, *id));
}
ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
@@ -695,8 +706,16 @@ impl WalkItemKind for ForeignItemKind {
try_visit!(visitor.visit_ty(ty));
visit_opt!(visitor, visit_expr, expr);
}
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, contract, body }) => {
let kind = FnKind::Fn(
FnCtxt::Foreign,
ident,
sig,
vis,
generics,
contract,
body.as_deref(),
);
try_visit!(visitor.visit_fn(kind, span, id));
}
ForeignItemKind::TyAlias(box TyAlias {
@@ -784,6 +803,17 @@ pub fn walk_closure_binder<'a, V: Visitor<'a>>(
V::Result::output()
}

pub fn walk_contract<'a, V: Visitor<'a>>(visitor: &mut V, c: &'a FnContract) -> V::Result {
let FnContract { requires, ensures } = c;
if let Some(pred) = requires {
visitor.visit_expr(pred);
}
if let Some(pred) = ensures {
visitor.visit_expr(pred);
}
V::Result::output()
}

pub fn walk_where_predicate<'a, V: Visitor<'a>>(
visitor: &mut V,
predicate: &'a WherePredicate,
@@ -829,11 +859,20 @@ pub fn walk_fn_decl<'a, V: Visitor<'a>>(

pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
match kind {
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
FnKind::Fn(
_ctxt,
_ident,
FnSig { header, decl, span: _ },
_vis,
generics,
contract,
body,
) => {
// Identifier and visibility are visited as a part of the item.
try_visit!(visitor.visit_fn_header(header));
try_visit!(visitor.visit_generics(generics));
try_visit!(walk_fn_decl(visitor, decl));
try_visit!(visitor.visit_contract(contract));
visit_opt!(visitor, visit_block, body);
}
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
@@ -859,9 +898,16 @@ impl WalkItemKind for AssocItemKind {
try_visit!(visitor.visit_ty(ty));
visit_opt!(visitor, visit_expr, expr);
}
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind =
FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, contract, body }) => {
let kind = FnKind::Fn(
FnCtxt::Assoc(ctxt),
ident,
sig,
vis,
generics,
contract,
body.as_deref(),
);
try_visit!(visitor.visit_fn(kind, span, id));
}
AssocItemKind::Type(box TyAlias {
Loading