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 6 pull requests #133189

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5319425
Move diagnostic::on_unimplemented test to the directory with all the …
ehuss Nov 15, 2024
2765432
Improve `{BTreeMap,HashMap}::get_key_value` docs.
nnethercote Nov 8, 2024
8ea0257
Fix typo
GuillaumeGomez Nov 18, 2024
786b747
Fix items with generics not having their jump to def link generated
GuillaumeGomez Nov 18, 2024
8b0f8cb
Add regression test for jump to def links on items with generics
GuillaumeGomez Nov 18, 2024
31f5c3b
const_panic: inline in bootstrap builds to avoid f16/f128 crashes
RalfJung Nov 18, 2024
cc48194
Report `unexpected_cfgs` lint in external macros
Urgau Nov 3, 2024
e8bd643
Update `anstream` to 0.6.18 to fix a check-cfg issue
Urgau Nov 4, 2024
58664de
Bump `stdarch` to the latest master
Urgau Nov 7, 2024
79c8e64
Update `xshell` and `xshell-macros` to v0.2.7
Urgau Nov 16, 2024
1b0e787
Add reference annotations for diagnostic attributes
ehuss Nov 18, 2024
3adbc16
Update books
rustbot Nov 18, 2024
9fb974e
Rollup merge of #132577 - Urgau:check-cfg-report-extern-macro, r=petr…
GuillaumeGomez Nov 18, 2024
538a59d
Rollup merge of #132758 - nnethercote:improve-get_key_value-docs, r=c…
GuillaumeGomez Nov 18, 2024
f20d513
Rollup merge of #133180 - GuillaumeGomez:jump-to-def-links-generics, …
GuillaumeGomez Nov 18, 2024
a2fdcfc
Rollup merge of #133181 - rustbot:docs-update, r=ehuss
GuillaumeGomez Nov 18, 2024
519184f
Rollup merge of #133182 - RalfJung:const-panic-inline, r=tgross35
GuillaumeGomez Nov 18, 2024
87d1684
Rollup merge of #133187 - ehuss:reference-diagnostic, r=jieyouxu
GuillaumeGomez Nov 18, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ dependencies = [

[[package]]
name = "anstream"
version = "0.6.17"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,7 @@ declare_lint! {
pub UNEXPECTED_CFGS,
Warn,
"detects unexpected names and values in `#[cfg]` conditions",
report_in_external_macro
}

declare_lint! {
Expand Down
46 changes: 42 additions & 4 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,20 +677,58 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
}
}

/// Returns the key-value pair corresponding to the supplied key.
/// Returns the key-value pair corresponding to the supplied key. This is
/// potentially useful:
/// - for key types where non-identical keys can be considered equal;
/// - for getting the `&K` stored key value from a borrowed `&Q` lookup key; or
/// - for getting a reference to a key with the same lifetime as the collection.
///
/// The supplied key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
///
/// # Examples
///
/// ```
/// use std::cmp::Ordering;
/// use std::collections::BTreeMap;
///
/// #[derive(Clone, Copy, Debug)]
/// struct S {
/// id: u32,
/// # #[allow(unused)] // prevents a "field `name` is never read" error
/// name: &'static str, // ignored by equality and ordering operations
/// }
///
/// impl PartialEq for S {
/// fn eq(&self, other: &S) -> bool {
/// self.id == other.id
/// }
/// }
///
/// impl Eq for S {}
///
/// impl PartialOrd for S {
/// fn partial_cmp(&self, other: &S) -> Option<Ordering> {
/// self.id.partial_cmp(&other.id)
/// }
/// }
///
/// impl Ord for S {
/// fn cmp(&self, other: &S) -> Ordering {
/// self.id.cmp(&other.id)
/// }
/// }
///
/// let j_a = S { id: 1, name: "Jessica" };
/// let j_b = S { id: 1, name: "Jess" };
/// let p = S { id: 2, name: "Paul" };
/// assert_eq!(j_a, j_b);
///
/// let mut map = BTreeMap::new();
/// map.insert(1, "a");
/// assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
/// assert_eq!(map.get_key_value(&2), None);
/// map.insert(j_a, "Paris");
/// assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
/// assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
/// assert_eq!(map.get_key_value(&p), None);
/// ```
#[stable(feature = "map_get_key_value", since = "1.40.0")]
pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub macro const_panic {
#[noinline]
if const #[track_caller] #[inline] { // Inline this, to prevent codegen
$crate::panic!($const_msg)
} else #[track_caller] { // Do not inline this, it makes perf worse
} else #[track_caller] #[cfg_attr(bootstrap, inline)] { // Do not inline this, it makes perf worse
$crate::panic!($runtime_msg)
}
)
Expand Down
40 changes: 36 additions & 4 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,11 @@ where
self.base.get(k)
}

/// Returns the key-value pair corresponding to the supplied key.
/// Returns the key-value pair corresponding to the supplied key. This is
/// potentially useful:
/// - for key types where non-identical keys can be considered equal;
/// - for getting the `&K` stored key value from a borrowed `&Q` lookup key; or
/// - for getting a reference to a key with the same lifetime as the collection.
///
/// The supplied key may be any borrowed form of the map's key type, but
/// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
Expand All @@ -890,11 +894,39 @@ where
///
/// ```
/// use std::collections::HashMap;
/// use std::hash::{Hash, Hasher};
///
/// #[derive(Clone, Copy, Debug)]
/// struct S {
/// id: u32,
/// # #[allow(unused)] // prevents a "field `name` is never read" error
/// name: &'static str, // ignored by equality and hashing operations
/// }
///
/// impl PartialEq for S {
/// fn eq(&self, other: &S) -> bool {
/// self.id == other.id
/// }
/// }
///
/// impl Eq for S {}
///
/// impl Hash for S {
/// fn hash<H: Hasher>(&self, state: &mut H) {
/// self.id.hash(state);
/// }
/// }
///
/// let j_a = S { id: 1, name: "Jessica" };
/// let j_b = S { id: 1, name: "Jess" };
/// let p = S { id: 2, name: "Paul" };
/// assert_eq!(j_a, j_b);
///
/// let mut map = HashMap::new();
/// map.insert(1, "a");
/// assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
/// assert_eq!(map.get_key_value(&2), None);
/// map.insert(j_a, "Paris");
/// assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
/// assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
/// assert_eq!(map.get_key_value(&p), None);
/// ```
#[inline]
#[stable(feature = "map_get_key_value", since = "1.40.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/nomicon
23 changes: 19 additions & 4 deletions src/librustdoc/html/render/span_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) enum LinkFromSrc {
/// It returns the `krate`, the source code files and the `span` correspondence map.
///
/// Note about the `span` correspondence map: the keys are actually `(lo, hi)` of `span`s. We don't
/// need the `span` context later on, only their position, so instead of keep a whole `Span`, we
/// need the `span` context later on, only their position, so instead of keeping a whole `Span`, we
/// only keep the `lo` and `hi`.
pub(crate) fn collect_spans_and_sources(
tcx: TyCtxt<'_>,
Expand All @@ -45,9 +45,9 @@ pub(crate) fn collect_spans_and_sources(
include_sources: bool,
generate_link_to_definition: bool,
) -> (FxIndexMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };

if include_sources {
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };

if generate_link_to_definition {
tcx.hir().walk_toplevel_module(&mut visitor);
}
Expand Down Expand Up @@ -76,7 +76,22 @@ impl<'tcx> SpanMapVisitor<'tcx> {
} else {
LinkFromSrc::External(def_id)
};
self.matches.insert(path.span, link);
// In case the path ends with generics, we remove them from the span.
let span = path
.segments
.last()
.map(|last| {
// In `use` statements, the included item is not in the path segments.
// However, it doesn't matter because you can't have generics on `use`
// statements.
if path.span.contains(last.ident.span) {
path.span.with_hi(last.ident.span.hi())
} else {
path.span
}
})
.unwrap_or(path.span);
self.matches.insert(span, link);
}
Res::Local(_) => {
if let Some(span) = self.tcx.hir().res_span(path.res) {
Expand Down
10 changes: 5 additions & 5 deletions src/tools/miri/miri-script/Cargo.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4

[[package]]
name = "anyhow"
Expand Down Expand Up @@ -521,15 +521,15 @@ checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"

[[package]]
name = "xshell"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437"
checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d"
dependencies = [
"xshell-macros",
]

[[package]]
name = "xshell-macros"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852"
checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547"
14 changes: 14 additions & 0 deletions tests/rustdoc/link-on-path-with-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This test ensures that paths with generics still get their link to their definition
// correctly generated.

//@ compile-flags: -Zunstable-options --generate-link-to-definition
#![crate_name = "foo"]

//@ has 'src/foo/link-on-path-with-generics.rs.html'

pub struct Soyo<T>(T);
pub struct Saya;

//@ has - '//pre[@class="rust"]//a[@href="#9"]' 'Soyo'
//@ has - '//pre[@class="rust"]//a[@href="#10"]' 'Saya'
pub fn bar<T>(s: Soyo<T>, x: Saya) {}
11 changes: 11 additions & 0 deletions tests/ui/check-cfg/auxiliary/cfg_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Inspired by https://github.com/rust-lang/cargo/issues/14775

pub fn my_lib_func() {}

#[macro_export]
macro_rules! my_lib_macro {
() => {
#[cfg(my_lib_cfg)]
$crate::my_lib_func()
};
}
12 changes: 12 additions & 0 deletions tests/ui/check-cfg/report-in-external-macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This test checks that we emit the `unexpected_cfgs` lint even in code
// coming from an external macro.

//@ check-pass
//@ no-auto-check-cfg
//@ aux-crate: cfg_macro=cfg_macro.rs
//@ compile-flags: --check-cfg=cfg()

fn main() {
cfg_macro::my_lib_macro!();
//~^ WARNING unexpected `cfg` condition name
}
14 changes: 14 additions & 0 deletions tests/ui/check-cfg/report-in-external-macros.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning: unexpected `cfg` condition name: `my_lib_cfg`
--> $DIR/report-in-external-macros.rs:10:5
|
LL | cfg_macro::my_lib_macro!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
= help: to expect this configuration use `--check-cfg=cfg(my_lib_cfg)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
= note: this warning originates in the macro `cfg_macro::my_lib_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/diagnostic_namespace/deny_malformed_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ reference: attributes.diagnostic.namespace.unknown-invalid-syntax

#![deny(unknown_or_malformed_diagnostic_attributes)]

#[diagnostic::unknown_attribute]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/diagnostic_namespace/deny_malformed_attribute.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: unknown diagnostic attribute
--> $DIR/deny_malformed_attribute.rs:3:15
--> $DIR/deny_malformed_attribute.rs:5:15
|
LL | #[diagnostic::unknown_attribute]
| ^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/deny_malformed_attribute.rs:1:9
--> $DIR/deny_malformed_attribute.rs:3:9
|
LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ edition:2021
//@ aux-build:bad_on_unimplemented.rs
//@ reference: attributes.diagnostic.on_unimplemented.syntax

// Do not ICE when encountering a malformed `#[diagnostic::on_unimplemented]` annotation in a
// dependency when incorrectly used (#124651).
Expand Down
Loading
Loading