Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0439f4e
Hint that memchr returns an in-bounds index
SomeFlyingThing Jul 23, 2026
c1f36d5
Hint that memrchr returns an in-bounds index
SomeFlyingThing Jul 24, 2026
844c01e
Cover memchr fast path with bounds assertion
SomeFlyingThing Jul 27, 2026
49c1f02
Fix memchr result CI checks
SomeFlyingThing Jul 27, 2026
7696641
Add regression test for fn-ptr coercion normalization ICE
zakrad Jul 27, 2026
4ab575d
Update `browser-ui-test` version to `0.25.0`
GuillaumeGomez Jul 27, 2026
51a9794
Improve consistency of proc macro attribute error messages
nnethercote Jul 28, 2026
c9be59d
Improve consistency of `rustc_abi` attribute error messages
nnethercote Jul 28, 2026
02df958
Improve consistency of `rustc_const_stable` attribute error messages
nnethercote Jul 28, 2026
909079f
Improve consistency of `diagnostic::on_const` attribute error messages
nnethercote Jul 28, 2026
6c97237
Improve consistency of `test`/`bench` attribute error messages
nnethercote Jul 28, 2026
8704b63
Improve consistency of unsafe attribute error messages
nnethercote Jul 28, 2026
8bfa429
Add regression test for generic associated function suggestions
chenyukang Jul 28, 2026
c9dbe2b
Use value syntax for associated function suggestions
chenyukang Jul 28, 2026
1d32220
Add missing `"clipboard-read"` permission
GuillaumeGomez Jul 28, 2026
f31ead3
Rollup merge of #159784 - SomeFlyingThing:agent/hint-memchr-result-bo…
JonathanBrouwer Jul 28, 2026
a703a8f
Rollup merge of #160027 - zakrad:regr-test-132767, r=chenyukang
JonathanBrouwer Jul 28, 2026
574817e
Rollup merge of #160030 - GuillaumeGomez:update-browser-ui-test, r=Gu…
JonathanBrouwer Jul 28, 2026
ed9cb0d
Rollup merge of #160046 - nnethercote:attr-errors-2, r=estebank
JonathanBrouwer Jul 28, 2026
94eceec
Rollup merge of #160056 - chenyukang:yukang-fix-159813-assoc-fn-turbo…
JonathanBrouwer Jul 28, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::attributes::diagnostic::*;
use crate::attributes::prelude::*;
#[derive(Default)]
pub(crate) struct OnConstParser {
span: Option<Span>,
path_span: Option<Span>,
directive: Option<(Span, Directive)>,
}

Expand All @@ -21,8 +21,8 @@ impl AttributeParser for OnConstParser {
return;
}

let span = cx.attr_span;
this.span = Some(span);
let path_span = cx.attr_path.span;
this.path_span = Some(path_span);

let mode = Mode::DiagnosticOnConst;

Expand All @@ -31,7 +31,7 @@ impl AttributeParser for OnConstParser {
let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else {
return;
};
merge_directives(cx, &mut this.directive, (span, directive));
merge_directives(cx, &mut this.directive, (path_span, directive));
},
)];

Expand All @@ -44,8 +44,11 @@ impl AttributeParser for OnConstParser {
]);

fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
if let Some(span) = self.span {
Some(AttributeKind::OnConst { span, directive: self.directive.map(|d| Box::new(d.1)) })
if let Some(path_span) = self.path_span {
Some(AttributeKind::OnConst {
span: path_span,
directive: self.directive.map(|d| Box::new(d.1)),
})
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl AttributeParser for ConstStabilityParser {
{
this.stability = Some((
PartialConstStability { level, feature, promotable: false },
cx.attr_span,
cx.attr_path.span,
));
}
},
Expand All @@ -225,7 +225,7 @@ impl AttributeParser for ConstStabilityParser {
{
this.stability = Some((
PartialConstStability { level, feature, promotable: false },
cx.attr_span,
cx.attr_path.span,
));
}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ pub(crate) enum InvalidOnClause {
pub(crate) struct DupesNotAllowed;

#[derive(Diagnostic)]
#[diag("usage of the unsafe `#[{$attr_path}]` attribute")]
#[diag("usage of the unsafe `{$attr_path}` attribute")]
#[note("{$note}")]
pub(crate) struct UnsafeAttribute {
pub attr_path: AttrPath,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ pub(crate) struct TakesNoArguments<'a> {
}

#[derive(Diagnostic)]
#[diag("the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type")]
#[diag("the `{$path}` attribute is only usable with crates of the `proc-macro` crate type")]
pub(crate) struct AttributeOnlyUsableWithCrateType<'a> {
#[primary_span]
pub span: Span,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
}

if !self.is_proc_macro_crate {
let path = &attr.get_normal_item().path;
self.dcx
.create_err(diagnostics::AttributeOnlyUsableWithCrateType {
span: attr.span,
span: path.span,
path: &pprust::path_to_string(&attr.get_normal_item().path),
})
.emit();
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ pub(crate) fn expand_test(

pub(crate) fn expand_bench(
cx: &mut ExtCtxt<'_>,
attr_sp: Span,
attr_path_sp: Span,
meta_item: &ast::MetaItem,
item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(cx, meta_item, sym::bench);
warn_on_duplicate_attribute(cx, &item, sym::bench);
expand_test_or_bench(cx, attr_sp, item, true)
expand_test_or_bench(cx, attr_path_sp, item, true)
}

pub(crate) fn expand_test_or_bench(
Expand Down Expand Up @@ -413,7 +413,7 @@ pub(crate) fn expand_test_or_bench(
fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Option<&ast::Item>) {
let dcx = cx.dcx();
let name = if is_bench { "bench" } else { "test" };
let msg = format!("the `#[{name}]` attribute may only be used on a free function");
let msg = format!("the `{name}` attribute may only be used on a free function");
let level = match item.map(|i| &i.kind) {
// These were a warning before #92959 and need to continue being that to avoid breaking
// stable user code (#94508).
Expand All @@ -432,7 +432,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Opt
),
);
}
err.span_label(attr_sp, format!("the `#[{name}]` macro causes a function to be run as a test and has no effect on non-functions"));
err.span_label(attr_sp, format!("the `{name}` attribute causes a function to be run as a test and has no effect on non-functions"));

if !is_bench {
err.with_span_suggestion(attr_sp,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ pub enum AttributeKind {

/// Represents `#[diagnostic::on_const]`.
OnConst {
/// The attribute path span.
span: Span,
/// None if the directive was malformed in some way.
directive: Option<Box<Directive>>,
Expand Down Expand Up @@ -1391,7 +1392,8 @@ pub enum AttributeKind {
/// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`.
RustcConstStability {
stability: PartialConstStability,
/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
/// Path span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]`
/// attribute.
span: Span,
},

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3399,7 +3399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
};

let name = self.ty_to_value_string(actual);
let name = self.ty_to_string(actual);
let inner_id = kind.did();
let mutable = if let Some(AutorefOrPtrAdjustment::Autoref { mutbl, .. }) =
pick.autoref_or_ptr_adjustment
Expand Down Expand Up @@ -3868,7 +3868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Print out the type for use in value namespace.
fn ty_to_value_string(&self, ty: Ty<'tcx>) -> String {
match ty.kind() {
ty::Adt(def, args) => self.tcx.def_path_str_with_args(def.did(), args),
ty::Adt(def, args) => self.tcx.value_path_str_with_args(def.did(), args),
_ => self.ty_to_string(ty),
}
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ use rustc_trait_selection::traits::ObligationCtxt;
use crate::diagnostics;

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")]
#[diag(
"the `diagnostic::on_const` attribute can only be applied to non-const trait implementations"
)]
struct DiagnosticOnConstOnlyForNonConstTraitImpls {
#[label("this is a const trait implementation")]
item_span: Span,
Expand Down Expand Up @@ -569,7 +571,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
/// Checks if `#[diagnostic::on_const]` is applied to a on-const trait impl
fn check_diagnostic_on_const(
&self,
attr_span: Span,
attr_path_span: Span,
hir_id: HirId,
target: Target,
item: Option<&'tcx Item<'tcx>>,
Expand Down Expand Up @@ -609,7 +611,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.tcx.emit_node_span_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
attr_path_span,
DiagnosticOnConstOnlyForNonConstTraitImpls { item_span },
);
return;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub(crate) struct AbiNe {

#[derive(Diagnostic)]
#[diag(
"`#[rustc_abi]` can only be applied to function items, type aliases, and associated functions"
"the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions"
)]
pub(crate) struct AbiInvalidAttribute {
#[primary_span]
Expand Down Expand Up @@ -810,13 +810,13 @@ pub(crate) struct MissingConstErr {

#[derive(Diagnostic)]
#[diag(
"attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`"
"the `rustc_const_stable` attribute can only be applied to functions marked with the `stable` attribute"
)]
pub(crate) struct ConstStableNotStable {
#[primary_span]
pub fn_sig_span: Span,
#[label("attribute specified here")]
pub const_span: Span,
pub path_span: Span,
}

#[derive(Diagnostic)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
&& let Some(fn_sig) = fn_sig
&& const_stab.is_const_stable()
&& !stab.is_some_and(|s| s.is_stable())
&& let Some(const_span) = find_attr_span!(RustcConstStability)
&& let Some(path_span) = find_attr_span!(RustcConstStability)
{
self.tcx.dcx().emit_err(diagnostics::ConstStableNotStable {
fn_sig_span: fn_sig.span,
const_span,
path_span,
});
}

Expand Down
20 changes: 16 additions & 4 deletions library/core/src/slice/memchr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const fn contains_zero_byte(x: usize) -> bool {
#[must_use]
pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
// Fast path for small slices.
if text.len() < 2 * USIZE_BYTES {
return memchr_naive(x, text);
let result =
if text.len() < 2 * USIZE_BYTES { memchr_naive(x, text) } else { memchr_aligned(x, text) };
if let Some(index) = result {
// SAFETY: Both implementations only return an index from within `text`.
unsafe { crate::hint::assert_unchecked(index < text.len()) };
}

memchr_aligned(x, text)
result
}

#[inline]
Expand Down Expand Up @@ -107,8 +109,18 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
}

/// Returns the last index matching the byte `x` in `text`.
#[inline]
#[must_use]
pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
let result = memrchr_aligned(x, text);
if let Some(index) = result {
// SAFETY: `memrchr_aligned` only returns the index of a matching byte in `text`.
unsafe { crate::hint::assert_unchecked(index < text.len()) };
}
result
}

fn memrchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
// Scan for a single byte value by reading two `usize` words at a time.
//
// Split `text` in three parts:
Expand Down
11 changes: 11 additions & 0 deletions library/coretests/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,17 @@ pub mod memchr {
assert_eq!(None, memchr(b'a', b"xyz"));
}

#[test]
fn each_alignment() {
let mut data = [1u8; 64];
let needle = 2;
let pos = 40;
data[pos] = needle;
for start in 0..16 {
assert_eq!(Some(pos - start), memchr(needle, &data[start..]));
}
}

#[test]
fn matches_one_reversed() {
assert_eq!(Some(0), memrchr(b'a', b"a"));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"browser-ui-test": "^0.24.1",
"browser-ui-test": "^0.25.0",
"es-check": "^9.4.4",
"eslint": "^8.57.1",
"typescript": "^5.8.3"
Expand Down
26 changes: 26 additions & 0 deletions tests/codegen-llvm/lib-optimizations/memchr-result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Ensure `memchr` communicates that a returned index is in bounds.
//@ compile-flags: -Copt-level=3 -Zinline-mir=false
//@ only-x86_64

#![crate_type = "lib"]
#![feature(slice_internals)]

extern crate core;

use core::slice::memchr::memrchr;

// CHECK-LABEL: @find_char
#[no_mangle]
pub fn find_char(haystack: &str, needle: char) -> Option<usize> {
// CHECK-NOT: phi { i64, i64 }
// CHECK: ret { i64, i64 }
haystack.find(needle)
}

// CHECK-LABEL: @rfind_byte
#[no_mangle]
pub fn rfind_byte(haystack: &[u8], needle: u8) -> Option<u8> {
// CHECK-NOT: panic_bounds_check
// CHECK: ret { i1, i8 }
memrchr(needle, haystack).map(|index| haystack[index])
}
1 change: 1 addition & 0 deletions tests/rustdoc-gui/code-example-buttons.goml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This test ensures that code blocks buttons are displayed on hover and when you click on them.
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
permissions: ["clipboard-read"]
include: "utils.goml"

// First we check we "hover".
Expand Down
1 change: 1 addition & 0 deletions tests/rustdoc-gui/copy-code.goml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// isn't broken.
include: "utils.goml"
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
permissions: ["clipboard-read"]

define-function: (
"check-copy-button",
Expand Down
1 change: 1 addition & 0 deletions tests/rustdoc-gui/copy-path.goml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Checks that the "copy path" button is not triggering JS error and its display
// isn't broken and the copied path is as expected.
go-to: "file://" + |DOC_PATH| + "/test_docs/foreign_impl_order/trait.Foo.html"
permissions: ["clipboard-read"]

// We ensure that the clipboard is empty.
assert-clipboard: ""
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/proc_macro_bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(DeriveA)]
//~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
//~^ ERROR the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type
pub fn a_derive(input: TokenStream) -> TokenStream {
input
}
6 changes: 3 additions & 3 deletions tests/rustdoc-ui/proc_macro_bug.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
--> $DIR/proc_macro_bug.rs:8:1
error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type
--> $DIR/proc_macro_bug.rs:8:3
|
LL | #[proc_macro_derive(DeriveA)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

4 changes: 2 additions & 2 deletions tests/ui/abi/debug.generic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ error: fn_abi_of(test_generic) = FnAbi {
LL | fn test_generic<T>(_x: *const T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:43:1
|
LL | const C: () = ();
Expand Down Expand Up @@ -845,7 +845,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
= help: the trait `Sized` is not implemented for `str`
= note: only the last element of a tuple may have a dynamically sized type

error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:47:5
|
LL | const C: () = ();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/abi/debug.loongarch64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ error: fn_abi_of(test_generic) = FnAbi {
LL | fn test_generic<T>(_x: *const T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:43:1
|
LL | const C: () = ();
Expand Down Expand Up @@ -845,7 +845,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
= help: the trait `Sized` is not implemented for `str`
= note: only the last element of a tuple may have a dynamically sized type

error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:47:5
|
LL | const C: () = ();
Expand Down
Loading
Loading