Skip to content

Commit 33b74e0

Browse files
authored
Upgrade toolchain to nightly-2024-12-18 (#3794)
Relevant upstream PR: rust-lang/rust#131808. This required replacing `rustc_ast::Attribute` with the new `rustc_hir::Attribute`. Resolves #3788 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent f212ce5 commit 33b74e0

File tree

5 files changed

+26
-46
lines changed

5 files changed

+26
-46
lines changed

kani-compiler/src/codegen_cprover_gotoc/codegen/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::codegen_cprover_gotoc::GotocCtx;
77
use cbmc::goto_program::Location;
88
use lazy_static::lazy_static;
9-
use rustc_ast::Attribute;
9+
use rustc_hir::Attribute;
1010
use rustc_smir::rustc_internal;
1111
use rustc_span::Span;
1212
use stable_mir::ty::Span as SpanStable;

kani-compiler/src/kani_middle/attributes.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ use std::collections::{BTreeMap, HashSet};
66

77
use kani_metadata::{CbmcSolver, HarnessAttributes, HarnessKind, Stub};
88
use quote::ToTokens;
9-
use rustc_ast::{
10-
AttrArgs, AttrArgsEq, AttrKind, Attribute, ExprKind, LitKind, MetaItem, MetaItemKind, attr,
11-
};
9+
use rustc_ast::{LitKind, MetaItem, MetaItemKind, attr};
1210
use rustc_errors::ErrorGuaranteed;
13-
use rustc_hir::{def::DefKind, def_id::DefId};
11+
use rustc_hir::{AttrArgs, AttrKind, Attribute, def::DefKind, def_id::DefId};
1412
use rustc_middle::ty::{Instance, TyCtxt, TyKind};
1513
use rustc_session::Session;
1614
use rustc_smir::rustc_internal;
@@ -673,31 +671,12 @@ fn expect_key_string_value(
673671
attr: &Attribute,
674672
) -> Result<rustc_span::Symbol, ErrorGuaranteed> {
675673
let span = attr.span;
676-
let AttrArgs::Eq { eq_span: _, value } = &attr.get_normal_item().args else {
674+
let AttrArgs::Eq { expr, .. } = &attr.get_normal_item().args else {
677675
return Err(sess
678676
.dcx()
679677
.span_err(span, "Expected attribute of the form #[attr = \"value\"]"));
680678
};
681-
let maybe_str = match value {
682-
AttrArgsEq::Ast(expr) => {
683-
if let ExprKind::Lit(tok) = expr.kind {
684-
match LitKind::from_token_lit(tok) {
685-
Ok(l) => l.str(),
686-
Err(err) => {
687-
return Err(sess.dcx().span_err(
688-
span,
689-
format!("Invalid string literal on right hand side of `=` {err:?}"),
690-
));
691-
}
692-
}
693-
} else {
694-
return Err(sess
695-
.dcx()
696-
.span_err(span, "Expected literal string as right hand side of `=`"));
697-
}
698-
}
699-
AttrArgsEq::Hir(lit) => lit.kind.str(),
700-
};
679+
let maybe_str = expr.kind.str();
701680
if let Some(str) = maybe_str {
702681
Ok(str)
703682
} else {
@@ -841,7 +820,7 @@ fn parse_stubs(tcx: TyCtxt, harness: DefId, attributes: &[&Attribute]) -> Vec<St
841820
attributes
842821
.iter()
843822
.filter_map(|attr| {
844-
let paths = parse_paths(attr).unwrap_or_else(|_| {
823+
let paths = parse_paths(tcx, attr).unwrap_or_else(|_| {
845824
tcx.dcx().span_err(
846825
attr.span,
847826
format!(
@@ -952,8 +931,8 @@ fn parse_integer(attr: &Attribute) -> Option<u128> {
952931
/// Extracts a vector with the path arguments of an attribute.
953932
///
954933
/// Emits an error if it couldn't convert any of the arguments and return an empty vector.
955-
fn parse_paths(attr: &Attribute) -> Result<Vec<TypePath>, syn::Error> {
956-
let syn_attr = syn_attr(attr);
934+
fn parse_paths(tcx: TyCtxt, attr: &Attribute) -> Result<Vec<TypePath>, syn::Error> {
935+
let syn_attr = syn_attr(tcx, attr);
957936
let parser = Punctuated::<TypePath, syn::Token![,]>::parse_terminated;
958937
let paths = syn_attr.parse_args_with(parser)?;
959938
Ok(paths.into_iter().collect())
@@ -990,11 +969,11 @@ fn parse_str_value(attr: &Attribute) -> Option<String> {
990969
fn attr_kind(tcx: TyCtxt, attr: &Attribute) -> Option<KaniAttributeKind> {
991970
match &attr.kind {
992971
AttrKind::Normal(normal) => {
993-
let segments = &normal.item.path.segments;
994-
if (!segments.is_empty()) && segments[0].ident.as_str() == "kanitool" {
972+
let segments = &normal.path.segments;
973+
if (!segments.is_empty()) && segments[0].as_str() == "kanitool" {
995974
let ident_str = segments[1..]
996975
.iter()
997-
.map(|segment| segment.ident.as_str())
976+
.map(|segment| segment.as_str())
998977
.intersperse("::")
999978
.collect::<String>();
1000979
KaniAttributeKind::try_from(ident_str.as_str())
@@ -1014,8 +993,8 @@ fn attr_kind(tcx: TyCtxt, attr: &Attribute) -> Option<KaniAttributeKind> {
1014993
/// Parse an attribute using `syn`.
1015994
///
1016995
/// This provides a user-friendly interface to manipulate than the internal compiler AST.
1017-
fn syn_attr(attr: &Attribute) -> syn::Attribute {
1018-
let attr_str = rustc_ast_pretty::pprust::attribute_to_string(attr);
996+
fn syn_attr(tcx: TyCtxt, attr: &Attribute) -> syn::Attribute {
997+
let attr_str = rustc_hir_pretty::attribute_to_string(&tcx, attr);
1019998
let parser = syn::Attribute::parse_outer;
1020999
parser.parse_str(&attr_str).unwrap().pop().unwrap()
10211000
}

kani-compiler/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern crate rustc_data_structures;
2525
extern crate rustc_driver;
2626
extern crate rustc_errors;
2727
extern crate rustc_hir;
28+
extern crate rustc_hir_pretty;
2829
extern crate rustc_index;
2930
extern crate rustc_interface;
3031
extern crate rustc_metadata;

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
[toolchain]
5-
channel = "nightly-2024-12-15"
5+
channel = "nightly-2024-12-18"
66
components = ["llvm-tools", "rustc-dev", "rust-src", "rustfmt"]

tests/expected/uninit/delayed-ub/expected

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
delayed_ub_trigger_copy.assertion.1\
1+
delayed_ub_trigger_copy.assertion.\
22
- Status: FAILURE\
33
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"\
44

5-
delayed_ub_slices.assertion.4\
5+
delayed_ub_slices.assertion.\
66
- Status: FAILURE\
77
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `[u128; 4]`"
88

9-
delayed_ub_structs.assertion.2\
9+
delayed_ub_structs.assertion.\
1010
- Status: FAILURE\
1111
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `U`"
1212

13-
delayed_ub_double_copy.assertion.1\
13+
delayed_ub_double_copy.assertion.\
1414
- Status: FAILURE\
1515
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"\
1616

17-
delayed_ub_copy.assertion.1\
17+
delayed_ub_copy.assertion.\
1818
- Status: FAILURE\
1919
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
2020

21-
delayed_ub_closure_capture_laundered.assertion.2\
21+
delayed_ub_closure_capture_laundered.assertion.\
2222
- Status: FAILURE\
2323
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
2424

25-
delayed_ub_closure_laundered.assertion.2\
25+
delayed_ub_closure_laundered.assertion.\
2626
- Status: FAILURE\
2727
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
2828

29-
delayed_ub_laundered.assertion.2\
29+
delayed_ub_laundered.assertion.\
3030
- Status: FAILURE\
3131
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
3232

33-
delayed_ub_static.assertion.4\
33+
delayed_ub_static.assertion.\
3434
- Status: FAILURE\
3535
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
3636

37-
delayed_ub_transmute.assertion.2\
37+
delayed_ub_transmute.assertion.\
3838
- Status: FAILURE\
3939
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
4040

41-
delayed_ub.assertion.2\
41+
delayed_ub.assertion.\
4242
- Status: FAILURE\
4343
- Description: "Undefined Behavior: Reading from an uninitialized pointer of type `u128`"
4444

0 commit comments

Comments
 (0)