Skip to content

Commit 5072826

Browse files
committed
Auto merge of #110170 - JohnTitor:rollup-hdramer, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #109527 (Set up standard library path substitution in rust-gdb and gdbgui) - #109752 (Stall auto trait assembly in new solver for int/float vars) - #109860 (Add support for RISC-V relax target feature) - #109923 (Update `error [E0449]: unnecessary visibility qualifier` to be more clear) - #110070 (The `wrapping_neg` example for unsigned types shouldn't use `i8`) - #110146 (fix(doc): do not parse inline when output is json for external crate) - #110147 (Add regression test for #104916) - #110149 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b80ee39 + 48e14bb commit 5072826

Some content is hidden

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

44 files changed

+381
-174
lines changed

compiler/rustc_ast_passes/messages.ftl

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ ast_passes_keyword_lifetime =
1717
ast_passes_invalid_label =
1818
invalid label name `{$name}`
1919
20-
ast_passes_invalid_visibility =
21-
unnecessary visibility qualifier
22-
.implied = `pub` not permitted here because it's implied
20+
ast_passes_visibility_not_permitted =
21+
visibility qualifiers are not permitted here
22+
.enum_variant = enum variants and their fields always share the visibility of the enum they are in
23+
.trait_impl = trait items always share the visibility of their trait
2324
.individual_impl_items = place qualifiers on individual impl items instead
2425
.individual_foreign_items = place qualifiers on individual foreign items instead
2526

compiler/rustc_ast_passes/src/ast_validation.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,12 @@ impl<'a> AstValidator<'a> {
240240
}
241241
}
242242

243-
fn invalid_visibility(&self, vis: &Visibility, note: Option<errors::InvalidVisibilityNote>) {
243+
fn visibility_not_permitted(&self, vis: &Visibility, note: errors::VisibilityNotPermittedNote) {
244244
if let VisibilityKind::Inherited = vis.kind {
245245
return;
246246
}
247247

248-
self.session.emit_err(errors::InvalidVisibility {
249-
span: vis.span,
250-
implied: vis.kind.is_pub().then_some(vis.span),
251-
note,
252-
});
248+
self.session.emit_err(errors::VisibilityNotPermitted { span: vis.span, note });
253249
}
254250

255251
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
@@ -819,7 +815,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
819815
items,
820816
}) => {
821817
self.with_in_trait_impl(true, Some(*constness), |this| {
822-
this.invalid_visibility(&item.vis, None);
818+
this.visibility_not_permitted(
819+
&item.vis,
820+
errors::VisibilityNotPermittedNote::TraitImpl,
821+
);
823822
if let TyKind::Err = self_ty.kind {
824823
this.err_handler().emit_err(errors::ObsoleteAuto { span: item.span });
825824
}
@@ -866,9 +865,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
866865
only_trait: only_trait.then_some(()),
867866
};
868867

869-
self.invalid_visibility(
868+
self.visibility_not_permitted(
870869
&item.vis,
871-
Some(errors::InvalidVisibilityNote::IndividualImplItems),
870+
errors::VisibilityNotPermittedNote::IndividualImplItems,
872871
);
873872
if let &Unsafe::Yes(span) = unsafety {
874873
self.err_handler().emit_err(errors::InherentImplCannotUnsafe {
@@ -924,9 +923,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
924923
}
925924
ItemKind::ForeignMod(ForeignMod { abi, unsafety, .. }) => {
926925
let old_item = mem::replace(&mut self.extern_mod, Some(item));
927-
self.invalid_visibility(
926+
self.visibility_not_permitted(
928927
&item.vis,
929-
Some(errors::InvalidVisibilityNote::IndividualForeignItems),
928+
errors::VisibilityNotPermittedNote::IndividualForeignItems,
930929
);
931930
if let &Unsafe::Yes(span) = unsafety {
932931
self.err_handler().emit_err(errors::UnsafeItem { span, kind: "extern block" });
@@ -940,9 +939,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
940939
}
941940
ItemKind::Enum(def, _) => {
942941
for variant in &def.variants {
943-
self.invalid_visibility(&variant.vis, None);
942+
self.visibility_not_permitted(
943+
&variant.vis,
944+
errors::VisibilityNotPermittedNote::EnumVariant,
945+
);
944946
for field in variant.data.fields() {
945-
self.invalid_visibility(&field.vis, None);
947+
self.visibility_not_permitted(
948+
&field.vis,
949+
errors::VisibilityNotPermittedNote::EnumVariant,
950+
);
946951
}
947952
}
948953
}
@@ -1301,7 +1306,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13011306
}
13021307

13031308
if ctxt == AssocCtxt::Trait || self.in_trait_impl {
1304-
self.invalid_visibility(&item.vis, None);
1309+
self.visibility_not_permitted(&item.vis, errors::VisibilityNotPermittedNote::TraitImpl);
13051310
if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind {
13061311
self.check_trait_fn_not_const(sig.header.constness);
13071312
}

compiler/rustc_ast_passes/src/errors.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ pub struct InvalidLabel {
4242
}
4343

4444
#[derive(Diagnostic)]
45-
#[diag(ast_passes_invalid_visibility, code = "E0449")]
46-
pub struct InvalidVisibility {
45+
#[diag(ast_passes_visibility_not_permitted, code = "E0449")]
46+
pub struct VisibilityNotPermitted {
4747
#[primary_span]
4848
pub span: Span,
49-
#[label(ast_passes_implied)]
50-
pub implied: Option<Span>,
5149
#[subdiagnostic]
52-
pub note: Option<InvalidVisibilityNote>,
50+
pub note: VisibilityNotPermittedNote,
5351
}
5452

5553
#[derive(Subdiagnostic)]
56-
pub enum InvalidVisibilityNote {
54+
pub enum VisibilityNotPermittedNote {
55+
#[note(ast_passes_enum_variant)]
56+
EnumVariant,
57+
#[note(ast_passes_trait_impl)]
58+
TraitImpl,
5759
#[note(ast_passes_individual_impl_items)]
5860
IndividualImplItems,
5961
#[note(ast_passes_individual_foreign_items)]

compiler/rustc_codegen_ssa/src/target_features.rs

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
251251
("e", Some(sym::riscv_target_feature)),
252252
("f", Some(sym::riscv_target_feature)),
253253
("m", Some(sym::riscv_target_feature)),
254+
("relax", Some(sym::riscv_target_feature)),
254255
("v", Some(sym::riscv_target_feature)),
255256
("zba", Some(sym::riscv_target_feature)),
256257
("zbb", Some(sym::riscv_target_feature)),

compiler/rustc_error_codes/src/error_codes/E0449.md

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
A visibility qualifier was used when it was unnecessary.
1+
A visibility qualifier was used where one is not permitted. Visibility
2+
qualifiers are not permitted on enum variants, trait items, impl blocks, and
3+
extern blocks, as they already share the visibility of the parent item.
24

35
Erroneous code examples:
46

@@ -9,15 +11,18 @@ trait Foo {
911
fn foo();
1012
}
1113
12-
pub impl Bar {} // error: unnecessary visibility qualifier
14+
enum Baz {
15+
pub Qux, // error: visibility qualifiers are not permitted here
16+
}
17+
18+
pub impl Bar {} // error: visibility qualifiers are not permitted here
1319
14-
pub impl Foo for Bar { // error: unnecessary visibility qualifier
15-
pub fn foo() {} // error: unnecessary visibility qualifier
20+
pub impl Foo for Bar { // error: visibility qualifiers are not permitted here
21+
pub fn foo() {} // error: visibility qualifiers are not permitted here
1622
}
1723
```
1824

19-
To fix this error, please remove the visibility qualifier when it is not
20-
required. Example:
25+
To fix this error, simply remove the visibility qualifier. Example:
2126

2227
```
2328
struct Bar;
@@ -26,12 +31,18 @@ trait Foo {
2631
fn foo();
2732
}
2833
34+
enum Baz {
35+
// Enum variants share the visibility of the enum they are in, so
36+
// `pub` is not allowed here
37+
Qux,
38+
}
39+
2940
// Directly implemented methods share the visibility of the type itself,
30-
// so `pub` is unnecessary here
41+
// so `pub` is not allowed here
3142
impl Bar {}
3243
33-
// Trait methods share the visibility of the trait, so `pub` is
34-
// unnecessary in either case
44+
// Trait methods share the visibility of the trait, so `pub` is not
45+
// allowed in either case
3546
impl Foo for Bar {
3647
fn foo() {}
3748
}

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
2424
| ty::FnDef(..)
2525
| ty::FnPtr(_)
2626
| ty::Error(_)
27-
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
2827
| ty::Never
2928
| ty::Char => Ok(vec![]),
3029

31-
// Treat this like `struct str([u8]);`
30+
// Treat `str` like it's defined as `struct str([u8]);`
3231
ty::Str => Ok(vec![tcx.mk_slice(tcx.types.u8)]),
3332

3433
ty::Dynamic(..)
3534
| ty::Param(..)
3635
| ty::Foreign(..)
3736
| ty::Alias(ty::Projection, ..)
38-
| ty::Placeholder(..) => Err(NoSolution),
39-
40-
ty::Bound(..)
41-
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
37+
| ty::Placeholder(..)
38+
| ty::Bound(..)
39+
| ty::Infer(_) => {
4240
bug!("unexpected type `{ty}`")
4341
}
4442

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+60-18
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,66 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
147147
ecx: &mut EvalCtxt<'_, 'tcx>,
148148
goal: Goal<'tcx, Self>,
149149
) -> QueryResult<'tcx> {
150-
// This differs from the current stable behavior and
151-
// fixes #84857. Due to breakage found via crater, we
152-
// currently instead lint patterns which can be used to
153-
// exploit this unsoundness on stable, see #93367 for
154-
// more details.
155-
//
156-
// Using `TreatProjections::NextSolverLookup` is fine here because
157-
// `instantiate_constituent_tys_for_auto_trait` returns nothing for
158-
// projection types anyways. So it doesn't really matter what we do
159-
// here, and this is faster.
160-
if let Some(def_id) = ecx.tcx().find_map_relevant_impl(
161-
goal.predicate.def_id(),
162-
goal.predicate.self_ty(),
163-
TreatProjections::NextSolverLookup,
164-
Some,
165-
) {
166-
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
167-
return Err(NoSolution);
150+
let self_ty = goal.predicate.self_ty();
151+
match *self_ty.kind() {
152+
// Stall int and float vars until they are resolved to a concrete
153+
// numerical type. That's because the check for impls below treats
154+
// int vars as matching any impl. Even if we filtered such impls,
155+
// we probably don't want to treat an `impl !AutoTrait for i32` as
156+
// disqualifying the built-in auto impl for `i64: AutoTrait` either.
157+
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => {
158+
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
159+
}
160+
161+
// These types cannot be structurally decomposed into constitutent
162+
// types, and therefore have no builtin impl.
163+
ty::Dynamic(..)
164+
| ty::Param(..)
165+
| ty::Foreign(..)
166+
| ty::Alias(ty::Projection, ..)
167+
| ty::Placeholder(..) => return Err(NoSolution),
168+
169+
ty::Infer(_) | ty::Bound(_, _) => bug!("unexpected type `{self_ty}`"),
170+
171+
// For rigid types, we only register a builtin auto implementation
172+
// if there is no implementation that could ever apply to the self
173+
// type.
174+
//
175+
// This differs from the current stable behavior and fixes #84857.
176+
// Due to breakage found via crater, we currently instead lint
177+
// patterns which can be used to exploit this unsoundness on stable,
178+
// see #93367 for more details.
179+
ty::Bool
180+
| ty::Char
181+
| ty::Int(_)
182+
| ty::Uint(_)
183+
| ty::Float(_)
184+
| ty::Str
185+
| ty::Array(_, _)
186+
| ty::Slice(_)
187+
| ty::RawPtr(_)
188+
| ty::Ref(_, _, _)
189+
| ty::FnDef(_, _)
190+
| ty::FnPtr(_)
191+
| ty::Closure(_, _)
192+
| ty::Generator(_, _, _)
193+
| ty::GeneratorWitness(_)
194+
| ty::GeneratorWitnessMIR(_, _)
195+
| ty::Never
196+
| ty::Tuple(_)
197+
| ty::Error(_)
198+
| ty::Adt(_, _)
199+
| ty::Alias(ty::Opaque, _) => {
200+
if let Some(def_id) = ecx.tcx().find_map_relevant_impl(
201+
goal.predicate.def_id(),
202+
goal.predicate.self_ty(),
203+
TreatProjections::NextSolverLookup,
204+
Some,
205+
) {
206+
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
207+
return Err(NoSolution);
208+
}
209+
}
168210
}
169211

170212
ecx.probe_and_evaluate_goal_for_constituent_tys(

library/core/src/num/uint_macros.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1363,12 +1363,11 @@ macro_rules! uint_impl {
13631363
///
13641364
/// Basic usage:
13651365
///
1366-
/// Please note that this example is shared between integer types.
1367-
/// Which explains why `i8` is used here.
1368-
///
13691366
/// ```
1370-
/// assert_eq!(100i8.wrapping_neg(), -100);
1371-
/// assert_eq!((-128i8).wrapping_neg(), -128);
1367+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_neg(), 0);")]
1368+
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_neg(), 1);")]
1369+
#[doc = concat!("assert_eq!(13_", stringify!($SelfT), ".wrapping_neg(), (!13) + 1);")]
1370+
#[doc = concat!("assert_eq!(42_", stringify!($SelfT), ".wrapping_neg(), !(42 - 1));")]
13721371
/// ```
13731372
#[stable(feature = "num_wrapping", since = "1.2.0")]
13741373
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]

src/doc/book

src/doc/rust-by-example

src/etc/rust-gdb

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fi
1313
# Find out where the pretty printer Python module is
1414
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
1515
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
16+
# Get the commit hash for path remapping
17+
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"
1618

1719
# Run GDB with the additional arguments that load the pretty printers
1820
# Set the environment variable `RUST_GDB` to overwrite the call to a
@@ -21,4 +23,6 @@ RUST_GDB="${RUST_GDB:-gdb}"
2123
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" exec ${RUST_GDB} \
2224
--directory="$GDB_PYTHON_MODULE_DIRECTORY" \
2325
-iex "add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY" \
26+
-iex "set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust" \
2427
"$@"
28+

src/etc/rust-gdbgui

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fi
4242
# Find out where the pretty printer Python module is
4343
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
4444
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
45+
# Get the commit hash for path remapping
46+
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"
4547

4648
# Set the environment variable `RUST_GDB` to overwrite the call to a
4749
# different/specific command (defaults to `gdb`).
@@ -53,7 +55,9 @@ RUST_GDBGUI="${RUST_GDBGUI:-gdbgui}"
5355

5456
# These arguments get passed through to GDB and make it load the
5557
# Rust pretty printers.
56-
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" -iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\""
58+
GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\"" \
59+
"-iex \"add-auto-load-safe-path $GDB_PYTHON_MODULE_DIRECTORY\"" \
60+
"-iex \"set substitute-path /rustc/$RUSTC_COMMIT_HASH $RUSTC_SYSROOT/lib/rustlib/src/rust\""
5761

5862
# Finally we execute gdbgui.
5963
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \

src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,8 @@ fn clean_extern_crate<'tcx>(
23812381
Some(l) => attr::list_contains_name(&l, sym::inline),
23822382
None => false,
23832383
}
2384-
});
2384+
})
2385+
&& !cx.output_format.is_json();
23852386

23862387
let krate_owner_def_id = krate.owner_id.to_def_id();
23872388
if please_inline {

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ impl Variant {
20192019

20202020
#[derive(Clone, Debug)]
20212021
pub(crate) struct Discriminant {
2022-
// In the case of cross crate re-exports, we don't have the nessesary information
2022+
// In the case of cross crate re-exports, we don't have the necessary information
20232023
// to reconstruct the expression of the discriminant, only the value.
20242024
pub(super) expr: Option<BodyId>,
20252025
pub(super) value: DefId,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub enum O {
2+
L = -1,
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
// aux-build: inner-crate-enum.rs
3+
// compile-flags:-Z unstable-options --output-format json
4+
5+
#[doc(inline)]
6+
pub extern crate inner_crate_enum;
7+
8+
fn main() {}

0 commit comments

Comments
 (0)