Skip to content

Commit 9a1d617

Browse files
committed
Auto merge of rust-lang#81832 - jonas-schievink:rollup-3nw53p0, r=jonas-schievink
Rollup of 7 pull requests Successful merges: - rust-lang#81402 (tidy: Run tidy style against markdown files.) - rust-lang#81434 (BTree: fix documentation of unstable public members) - rust-lang#81680 (Refactor `PrimitiveTypeTable` for Clippy) - rust-lang#81737 (typeck: Emit structured suggestions for tuple struct syntax) - rust-lang#81738 (Miscellaneous small diagnostics cleanup) - rust-lang#81766 (Enable 'task list' markdown extension) - rust-lang#81812 (Add a test for escaping LLVMisms in inline asm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 37d067f + 11e7897 commit 9a1d617

File tree

72 files changed

+376
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+376
-270
lines changed

compiler/rustc_hir/src/hir.rs

+49
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,28 @@ pub enum PrimTy {
20582058
}
20592059

20602060
impl PrimTy {
2061+
/// All of the primitive types
2062+
pub const ALL: [Self; 17] = [
2063+
// any changes here should also be reflected in `PrimTy::from_name`
2064+
Self::Int(IntTy::I8),
2065+
Self::Int(IntTy::I16),
2066+
Self::Int(IntTy::I32),
2067+
Self::Int(IntTy::I64),
2068+
Self::Int(IntTy::I128),
2069+
Self::Int(IntTy::Isize),
2070+
Self::Uint(UintTy::U8),
2071+
Self::Uint(UintTy::U16),
2072+
Self::Uint(UintTy::U32),
2073+
Self::Uint(UintTy::U64),
2074+
Self::Uint(UintTy::U128),
2075+
Self::Uint(UintTy::Usize),
2076+
Self::Float(FloatTy::F32),
2077+
Self::Float(FloatTy::F64),
2078+
Self::Bool,
2079+
Self::Char,
2080+
Self::Str,
2081+
];
2082+
20612083
pub fn name_str(self) -> &'static str {
20622084
match self {
20632085
PrimTy::Int(i) => i.name_str(),
@@ -2079,6 +2101,33 @@ impl PrimTy {
20792101
PrimTy::Char => sym::char,
20802102
}
20812103
}
2104+
2105+
/// Returns the matching `PrimTy` for a `Symbol` such as "str" or "i32".
2106+
/// Returns `None` if no matching type is found.
2107+
pub fn from_name(name: Symbol) -> Option<Self> {
2108+
let ty = match name {
2109+
// any changes here should also be reflected in `PrimTy::ALL`
2110+
sym::i8 => Self::Int(IntTy::I8),
2111+
sym::i16 => Self::Int(IntTy::I16),
2112+
sym::i32 => Self::Int(IntTy::I32),
2113+
sym::i64 => Self::Int(IntTy::I64),
2114+
sym::i128 => Self::Int(IntTy::I128),
2115+
sym::isize => Self::Int(IntTy::Isize),
2116+
sym::u8 => Self::Uint(UintTy::U8),
2117+
sym::u16 => Self::Uint(UintTy::U16),
2118+
sym::u32 => Self::Uint(UintTy::U32),
2119+
sym::u64 => Self::Uint(UintTy::U64),
2120+
sym::u128 => Self::Uint(UintTy::U128),
2121+
sym::usize => Self::Uint(UintTy::Usize),
2122+
sym::f32 => Self::Float(FloatTy::F32),
2123+
sym::f64 => Self::Float(FloatTy::F64),
2124+
sym::bool => Self::Bool,
2125+
sym::char => Self::Char,
2126+
sym::str => Self::Str,
2127+
_ => return None,
2128+
};
2129+
Some(ty)
2130+
}
20822131
}
20832132

20842133
#[derive(Debug, HashStable_Generic)]

compiler/rustc_infer/src/infer/lexical_region_resolve/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Lexical Region Resolution was removed in https://github.com/rust-lang/rust/pull/64790.
32

43
Rust now uses Non-lexical lifetimes. For more info, please see the [borrowck

compiler/rustc_resolve/src/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_feature::BUILTIN_ATTRIBUTES;
99
use rustc_hir::def::Namespace::{self, *};
1010
use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind};
1111
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
12+
use rustc_hir::PrimTy;
1213
use rustc_middle::bug;
1314
use rustc_middle::ty::{self, DefIdTree};
1415
use rustc_session::Session;
@@ -718,10 +719,9 @@ impl<'a> Resolver<'a> {
718719
}
719720
}
720721
Scope::BuiltinTypes => {
721-
let primitive_types = &this.primitive_type_table.primitive_types;
722-
suggestions.extend(primitive_types.iter().flat_map(|(name, prim_ty)| {
722+
suggestions.extend(PrimTy::ALL.iter().filter_map(|prim_ty| {
723723
let res = Res::PrimTy(*prim_ty);
724-
filter_fn(res).then_some(TypoSuggestion::from_res(*name, res))
724+
filter_fn(res).then_some(TypoSuggestion::from_res(prim_ty.name(), res))
725725
}))
726726
}
727727
}

compiler/rustc_resolve/src/late.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_errors::DiagnosticId;
2020
use rustc_hir::def::Namespace::{self, *};
2121
use rustc_hir::def::{self, CtorKind, DefKind, PartialRes, PerNS};
2222
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
23-
use rustc_hir::TraitCandidate;
23+
use rustc_hir::{PrimTy, TraitCandidate};
2424
use rustc_middle::{bug, span_bug};
2525
use rustc_session::lint;
2626
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1927,7 +1927,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19271927
self.r.trait_map.insert(id, traits);
19281928
}
19291929

1930-
if self.r.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
1930+
if PrimTy::from_name(path[0].ident.name).is_some() {
19311931
let mut std_path = Vec::with_capacity(1 + path.len());
19321932

19331933
std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
@@ -2121,13 +2121,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
21212121
// The same fallback is used when `a` resolves to nothing.
21222122
PathResult::Module(ModuleOrUniformRoot::Module(_)) | PathResult::Failed { .. }
21232123
if (ns == TypeNS || path.len() > 1)
2124-
&& self
2125-
.r
2126-
.primitive_type_table
2127-
.primitive_types
2128-
.contains_key(&path[0].ident.name) =>
2124+
&& PrimTy::from_name(path[0].ident.name).is_some() =>
21292125
{
2130-
let prim = self.r.primitive_type_table.primitive_types[&path[0].ident.name];
2126+
let prim = PrimTy::from_name(path[0].ident.name).unwrap();
21312127
PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
21322128
}
21332129
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {

compiler/rustc_resolve/src/late/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
12121212
// Add primitive types to the mix
12131213
if filter_fn(Res::PrimTy(PrimTy::Bool)) {
12141214
names.extend(
1215-
self.r.primitive_type_table.primitive_types.iter().map(|(name, prim_ty)| {
1216-
TypoSuggestion::from_res(*name, Res::PrimTy(*prim_ty))
1215+
PrimTy::ALL.iter().map(|prim_ty| {
1216+
TypoSuggestion::from_res(prim_ty.name(), Res::PrimTy(*prim_ty))
12171217
}),
12181218
)
12191219
}

compiler/rustc_resolve/src/lib.rs

+4-43
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_arena::{DroplessArena, TypedArena};
2525
use rustc_ast::node_id::NodeMap;
2626
use rustc_ast::unwrap_or;
2727
use rustc_ast::visit::{self, Visitor};
28-
use rustc_ast::{self as ast, FloatTy, IntTy, NodeId, UintTy};
28+
use rustc_ast::{self as ast, NodeId};
2929
use rustc_ast::{Crate, CRATE_NODE_ID};
3030
use rustc_ast::{ItemKind, Path};
3131
use rustc_ast_lowering::ResolverAstLowering;
@@ -39,8 +39,7 @@ use rustc_hir::def::Namespace::*;
3939
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
4040
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
4141
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
42-
use rustc_hir::PrimTy::{self, Bool, Char, Float, Int, Str, Uint};
43-
use rustc_hir::TraitCandidate;
42+
use rustc_hir::{PrimTy, TraitCandidate};
4443
use rustc_index::vec::IndexVec;
4544
use rustc_metadata::creader::{CStore, CrateLoader};
4645
use rustc_middle::hir::exports::ExportMap;
@@ -834,39 +833,6 @@ impl<'a> NameBinding<'a> {
834833
}
835834
}
836835

837-
/// Interns the names of the primitive types.
838-
///
839-
/// All other types are defined somewhere and possibly imported, but the primitive ones need
840-
/// special handling, since they have no place of origin.
841-
struct PrimitiveTypeTable {
842-
primitive_types: FxHashMap<Symbol, PrimTy>,
843-
}
844-
845-
impl PrimitiveTypeTable {
846-
fn new() -> PrimitiveTypeTable {
847-
let mut table = FxHashMap::default();
848-
849-
table.insert(sym::bool, Bool);
850-
table.insert(sym::char, Char);
851-
table.insert(sym::f32, Float(FloatTy::F32));
852-
table.insert(sym::f64, Float(FloatTy::F64));
853-
table.insert(sym::isize, Int(IntTy::Isize));
854-
table.insert(sym::i8, Int(IntTy::I8));
855-
table.insert(sym::i16, Int(IntTy::I16));
856-
table.insert(sym::i32, Int(IntTy::I32));
857-
table.insert(sym::i64, Int(IntTy::I64));
858-
table.insert(sym::i128, Int(IntTy::I128));
859-
table.insert(sym::str, Str);
860-
table.insert(sym::usize, Uint(UintTy::Usize));
861-
table.insert(sym::u8, Uint(UintTy::U8));
862-
table.insert(sym::u16, Uint(UintTy::U16));
863-
table.insert(sym::u32, Uint(UintTy::U32));
864-
table.insert(sym::u64, Uint(UintTy::U64));
865-
table.insert(sym::u128, Uint(UintTy::U128));
866-
Self { primitive_types: table }
867-
}
868-
}
869-
870836
#[derive(Debug, Default, Clone)]
871837
pub struct ExternPreludeEntry<'a> {
872838
extern_crate_item: Option<&'a NameBinding<'a>>,
@@ -912,9 +878,6 @@ pub struct Resolver<'a> {
912878
/// "self-confirming" import resolutions during import validation.
913879
unusable_binding: Option<&'a NameBinding<'a>>,
914880

915-
/// The idents for the primitive types.
916-
primitive_type_table: PrimitiveTypeTable,
917-
918881
/// Resolutions for nodes that have a single resolution.
919882
partial_res_map: NodeMap<PartialRes>,
920883
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
@@ -1284,8 +1247,6 @@ impl<'a> Resolver<'a> {
12841247
last_import_segment: false,
12851248
unusable_binding: None,
12861249

1287-
primitive_type_table: PrimitiveTypeTable::new(),
1288-
12891250
partial_res_map: Default::default(),
12901251
import_res_map: Default::default(),
12911252
label_res_map: Default::default(),
@@ -1994,9 +1955,9 @@ impl<'a> Resolver<'a> {
19941955
}
19951956

19961957
if ns == TypeNS {
1997-
if let Some(prim_ty) = self.primitive_type_table.primitive_types.get(&ident.name) {
1958+
if let Some(prim_ty) = PrimTy::from_name(ident.name) {
19981959
let binding =
1999-
(Res::PrimTy(*prim_ty), ty::Visibility::Public, DUMMY_SP, ExpnId::root())
1960+
(Res::PrimTy(prim_ty), ty::Visibility::Public, DUMMY_SP, ExpnId::root())
20001961
.to_name_binding(self.arenas);
20011962
return Some(LexicalScopeBinding::Item(binding));
20021963
}

compiler/rustc_resolve/src/macros.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_expand::expand::{AstFragment, Invocation, InvocationKind};
2121
use rustc_feature::is_builtin_attr_name;
2222
use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
2323
use rustc_hir::def_id;
24+
use rustc_hir::PrimTy;
2425
use rustc_middle::middle::stability;
2526
use rustc_middle::ty;
2627
use rustc_session::lint::builtin::{SOFT_UNSTABLE, UNUSED_MACROS};
@@ -796,12 +797,10 @@ impl<'a> Resolver<'a> {
796797
}
797798
result
798799
}
799-
Scope::BuiltinTypes => {
800-
match this.primitive_type_table.primitive_types.get(&ident.name).cloned() {
801-
Some(prim_ty) => ok(Res::PrimTy(prim_ty), DUMMY_SP, this.arenas),
802-
None => Err(Determinacy::Determined),
803-
}
804-
}
800+
Scope::BuiltinTypes => match PrimTy::from_name(ident.name) {
801+
Some(prim_ty) => ok(Res::PrimTy(prim_ty), DUMMY_SP, this.arenas),
802+
None => Err(Determinacy::Determined),
803+
},
805804
};
806805

807806
match result {

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
117117
{
118118
err.span_help(
119119
tcx.def_span(def.did),
120-
&format!("try adding a `where` bound using this expression: where [u8; {}]: Sized", snippet),
120+
&format!("try adding a `where` bound using this expression: `where [u8; {}]: Sized`", snippet),
121121
);
122122
} else {
123123
err.span_help(

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17801780
multispan.push_span_label(
17811781
sp,
17821782
format!(
1783-
"...if indirection was used here: `Box<{}>`",
1783+
"...if indirection were used here: `Box<{}>`",
17841784
param.name.ident(),
17851785
),
17861786
);

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11031103
// This is currently not possible to trigger because E0038 takes precedence, but
11041104
// leave it in for completeness in case anything changes in an earlier stage.
11051105
err.note(&format!(
1106-
"if trait `{}` was object safe, you could return a trait object",
1106+
"if trait `{}` were object-safe, you could return a trait object",
11071107
trait_obj,
11081108
));
11091109
}

compiler/rustc_typeck/src/check/expr.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1460,28 +1460,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14601460
),
14611461
);
14621462
err.span_label(field.ident.span, "field does not exist");
1463-
err.span_label(
1463+
err.span_suggestion(
14641464
ty_span,
1465+
&format!(
1466+
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
1467+
adt = ty,
1468+
variant = variant.ident,
1469+
),
14651470
format!(
1466-
"`{adt}::{variant}` is a tuple {kind_name}, \
1467-
use the appropriate syntax: `{adt}::{variant}(/* fields */)`",
1471+
"{adt}::{variant}(/* fields */)",
14681472
adt = ty,
14691473
variant = variant.ident,
1470-
kind_name = kind_name
14711474
),
1475+
Applicability::HasPlaceholders,
14721476
);
14731477
}
14741478
_ => {
14751479
err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty));
14761480
err.span_label(field.ident.span, "field does not exist");
1477-
err.span_label(
1481+
err.span_suggestion(
14781482
ty_span,
1479-
format!(
1480-
"`{adt}` is a tuple {kind_name}, \
1481-
use the appropriate syntax: `{adt}(/* fields */)`",
1483+
&format!(
1484+
"`{adt}` is a tuple {kind_name}, use the appropriate syntax",
14821485
adt = ty,
1483-
kind_name = kind_name
1486+
kind_name = kind_name,
14841487
),
1488+
format!("{adt}(/* fields */)", adt = ty),
1489+
Applicability::HasPlaceholders,
14851490
);
14861491
}
14871492
},

compiler/rustc_typeck/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn missing_items_err(
838838
// Obtain the level of indentation ending in `sugg_sp`.
839839
let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0);
840840
// Make the whitespace that will make the suggestion have the right indentation.
841-
let padding: String = (0..indentation).map(|_| " ").collect();
841+
let padding: String = std::iter::repeat(" ").take(indentation).collect();
842842

843843
for trait_item in missing_items {
844844
let snippet = suggestion_signature(&trait_item, tcx);

library/alloc/src/collections/btree/map.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -1151,21 +1151,23 @@ impl<K, V> BTreeMap<K, V> {
11511151
right
11521152
}
11531153

1154-
/// Creates an iterator which uses a closure to determine if an element should be removed.
1155-
///
1156-
/// If the closure returns true, the element is removed from the map and yielded.
1157-
/// If the closure returns false, or panics, the element remains in the map and will not be
1158-
/// yielded.
1159-
///
1160-
/// Note that `drain_filter` lets you mutate every value in the filter closure, regardless of
1161-
/// whether you choose to keep or remove it.
1162-
///
1163-
/// If the iterator is only partially consumed or not consumed at all, each of the remaining
1164-
/// elements will still be subjected to the closure and removed and dropped if it returns true.
1165-
///
1166-
/// It is unspecified how many more elements will be subjected to the closure
1167-
/// if a panic occurs in the closure, or a panic occurs while dropping an element,
1168-
/// or if the `DrainFilter` value is leaked.
1154+
/// Creates an iterator that visits all elements (key-value pairs) in
1155+
/// ascending key order and uses a closure to determine if an element should
1156+
/// be removed. If the closure returns `true`, the element is removed from
1157+
/// the map and yielded. If the closure returns `false`, or panics, the
1158+
/// element remains in the map and will not be yielded.
1159+
///
1160+
/// The iterator also lets you mutate the value of each element in the
1161+
/// closure, regardless of whether you choose to keep or remove it.
1162+
///
1163+
/// If the iterator is only partially consumed or not consumed at all, each
1164+
/// of the remaining elements is still subjected to the closure, which may
1165+
/// change its value and, by returning `true`, have the element removed and
1166+
/// dropped.
1167+
///
1168+
/// It is unspecified how many more elements will be subjected to the
1169+
/// closure if a panic occurs in the closure, or a panic occurs while
1170+
/// dropping an element, or if the `DrainFilter` value is leaked.
11691171
///
11701172
/// # Examples
11711173
///

library/alloc/src/collections/btree/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<T> BTreeSet<T> {
679679
/// use std::collections::BTreeSet;
680680
///
681681
/// let mut map = BTreeSet::new();
682-
/// assert_eq!(map.first(), None);
682+
/// assert_eq!(map.last(), None);
683683
/// map.insert(1);
684684
/// assert_eq!(map.last(), Some(&1));
685685
/// map.insert(2);

src/doc/rustc/src/exploit-mitigations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ C library default allocator<sup id="fnref:5" role="doc-noteref"><a
378378
href="#fn:5" class="footnote">5</a></sup> since version 1.32.0
379379
(2019-01-17)[39].
380380

381-
```ignore
381+
```rust,no_run
382382
fn main() {
383383
let mut x = Box::new([0; 1024]);
384384

0 commit comments

Comments
 (0)