Skip to content

Commit

Permalink
Auto merge of rust-lang#110170 - JohnTitor:rollup-hdramer, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - rust-lang#109527 (Set up standard library path substitution in rust-gdb and gdbgui)
 - rust-lang#109752 (Stall auto trait assembly in new solver for int/float vars)
 - rust-lang#109860 (Add support for RISC-V relax target feature)
 - rust-lang#109923 (Update `error [E0449]: unnecessary visibility qualifier` to be more clear)
 - rust-lang#110070 (The `wrapping_neg` example for unsigned types shouldn't use `i8`)
 - rust-lang#110146 (fix(doc): do not parse inline when output is json for external crate)
 - rust-lang#110147 (Add regression test for rust-lang#104916)
 - rust-lang#110149 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 11, 2023
2 parents b80ee39 + 48e14bb commit 5072826
Show file tree
Hide file tree
Showing 44 changed files with 381 additions and 174 deletions.
7 changes: 4 additions & 3 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ ast_passes_keyword_lifetime =
ast_passes_invalid_label =
invalid label name `{$name}`
ast_passes_invalid_visibility =
unnecessary visibility qualifier
.implied = `pub` not permitted here because it's implied
ast_passes_visibility_not_permitted =
visibility qualifiers are not permitted here
.enum_variant = enum variants and their fields always share the visibility of the enum they are in
.trait_impl = trait items always share the visibility of their trait
.individual_impl_items = place qualifiers on individual impl items instead
.individual_foreign_items = place qualifiers on individual foreign items instead
Expand Down
33 changes: 19 additions & 14 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,12 @@ impl<'a> AstValidator<'a> {
}
}

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

self.session.emit_err(errors::InvalidVisibility {
span: vis.span,
implied: vis.kind.is_pub().then_some(vis.span),
note,
});
self.session.emit_err(errors::VisibilityNotPermitted { span: vis.span, note });
}

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

self.invalid_visibility(
self.visibility_not_permitted(
&item.vis,
Some(errors::InvalidVisibilityNote::IndividualImplItems),
errors::VisibilityNotPermittedNote::IndividualImplItems,
);
if let &Unsafe::Yes(span) = unsafety {
self.err_handler().emit_err(errors::InherentImplCannotUnsafe {
Expand Down Expand Up @@ -924,9 +923,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
ItemKind::ForeignMod(ForeignMod { abi, unsafety, .. }) => {
let old_item = mem::replace(&mut self.extern_mod, Some(item));
self.invalid_visibility(
self.visibility_not_permitted(
&item.vis,
Some(errors::InvalidVisibilityNote::IndividualForeignItems),
errors::VisibilityNotPermittedNote::IndividualForeignItems,
);
if let &Unsafe::Yes(span) = unsafety {
self.err_handler().emit_err(errors::UnsafeItem { span, kind: "extern block" });
Expand All @@ -940,9 +939,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
ItemKind::Enum(def, _) => {
for variant in &def.variants {
self.invalid_visibility(&variant.vis, None);
self.visibility_not_permitted(
&variant.vis,
errors::VisibilityNotPermittedNote::EnumVariant,
);
for field in variant.data.fields() {
self.invalid_visibility(&field.vis, None);
self.visibility_not_permitted(
&field.vis,
errors::VisibilityNotPermittedNote::EnumVariant,
);
}
}
}
Expand Down Expand Up @@ -1301,7 +1306,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

if ctxt == AssocCtxt::Trait || self.in_trait_impl {
self.invalid_visibility(&item.vis, None);
self.visibility_not_permitted(&item.vis, errors::VisibilityNotPermittedNote::TraitImpl);
if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind {
self.check_trait_fn_not_const(sig.header.constness);
}
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ pub struct InvalidLabel {
}

#[derive(Diagnostic)]
#[diag(ast_passes_invalid_visibility, code = "E0449")]
pub struct InvalidVisibility {
#[diag(ast_passes_visibility_not_permitted, code = "E0449")]
pub struct VisibilityNotPermitted {
#[primary_span]
pub span: Span,
#[label(ast_passes_implied)]
pub implied: Option<Span>,
#[subdiagnostic]
pub note: Option<InvalidVisibilityNote>,
pub note: VisibilityNotPermittedNote,
}

#[derive(Subdiagnostic)]
pub enum InvalidVisibilityNote {
pub enum VisibilityNotPermittedNote {
#[note(ast_passes_enum_variant)]
EnumVariant,
#[note(ast_passes_trait_impl)]
TraitImpl,
#[note(ast_passes_individual_impl_items)]
IndividualImplItems,
#[note(ast_passes_individual_foreign_items)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("e", Some(sym::riscv_target_feature)),
("f", Some(sym::riscv_target_feature)),
("m", Some(sym::riscv_target_feature)),
("relax", Some(sym::riscv_target_feature)),
("v", Some(sym::riscv_target_feature)),
("zba", Some(sym::riscv_target_feature)),
("zbb", Some(sym::riscv_target_feature)),
Expand Down
29 changes: 20 additions & 9 deletions compiler/rustc_error_codes/src/error_codes/E0449.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
A visibility qualifier was used when it was unnecessary.
A visibility qualifier was used where one is not permitted. Visibility
qualifiers are not permitted on enum variants, trait items, impl blocks, and
extern blocks, as they already share the visibility of the parent item.

Erroneous code examples:

Expand All @@ -9,15 +11,18 @@ trait Foo {
fn foo();
}
pub impl Bar {} // error: unnecessary visibility qualifier
enum Baz {
pub Qux, // error: visibility qualifiers are not permitted here
}
pub impl Bar {} // error: visibility qualifiers are not permitted here
pub impl Foo for Bar { // error: unnecessary visibility qualifier
pub fn foo() {} // error: unnecessary visibility qualifier
pub impl Foo for Bar { // error: visibility qualifiers are not permitted here
pub fn foo() {} // error: visibility qualifiers are not permitted here
}
```

To fix this error, please remove the visibility qualifier when it is not
required. Example:
To fix this error, simply remove the visibility qualifier. Example:

```
struct Bar;
Expand All @@ -26,12 +31,18 @@ trait Foo {
fn foo();
}
enum Baz {
// Enum variants share the visibility of the enum they are in, so
// `pub` is not allowed here
Qux,
}
// Directly implemented methods share the visibility of the type itself,
// so `pub` is unnecessary here
// so `pub` is not allowed here
impl Bar {}
// Trait methods share the visibility of the trait, so `pub` is
// unnecessary in either case
// Trait methods share the visibility of the trait, so `pub` is not
// allowed in either case
impl Foo for Bar {
fn foo() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
| ty::FnDef(..)
| ty::FnPtr(_)
| ty::Error(_)
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
| ty::Never
| ty::Char => Ok(vec![]),

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

ty::Dynamic(..)
| ty::Param(..)
| ty::Foreign(..)
| ty::Alias(ty::Projection, ..)
| ty::Placeholder(..) => Err(NoSolution),

ty::Bound(..)
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
| ty::Placeholder(..)
| ty::Bound(..)
| ty::Infer(_) => {
bug!("unexpected type `{ty}`")
}

Expand Down
78 changes: 60 additions & 18 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,66 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> {
// This differs from the current stable behavior and
// fixes #84857. Due to breakage found via crater, we
// currently instead lint patterns which can be used to
// exploit this unsoundness on stable, see #93367 for
// more details.
//
// Using `TreatProjections::NextSolverLookup` is fine here because
// `instantiate_constituent_tys_for_auto_trait` returns nothing for
// projection types anyways. So it doesn't really matter what we do
// here, and this is faster.
if let Some(def_id) = ecx.tcx().find_map_relevant_impl(
goal.predicate.def_id(),
goal.predicate.self_ty(),
TreatProjections::NextSolverLookup,
Some,
) {
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
return Err(NoSolution);
let self_ty = goal.predicate.self_ty();
match *self_ty.kind() {
// Stall int and float vars until they are resolved to a concrete
// numerical type. That's because the check for impls below treats
// int vars as matching any impl. Even if we filtered such impls,
// we probably don't want to treat an `impl !AutoTrait for i32` as
// disqualifying the built-in auto impl for `i64: AutoTrait` either.
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => {
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
}

// These types cannot be structurally decomposed into constitutent
// types, and therefore have no builtin impl.
ty::Dynamic(..)
| ty::Param(..)
| ty::Foreign(..)
| ty::Alias(ty::Projection, ..)
| ty::Placeholder(..) => return Err(NoSolution),

ty::Infer(_) | ty::Bound(_, _) => bug!("unexpected type `{self_ty}`"),

// For rigid types, we only register a builtin auto implementation
// if there is no implementation that could ever apply to the self
// type.
//
// This differs from the current stable behavior and fixes #84857.
// Due to breakage found via crater, we currently instead lint
// patterns which can be used to exploit this unsoundness on stable,
// see #93367 for more details.
ty::Bool
| ty::Char
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Str
| ty::Array(_, _)
| ty::Slice(_)
| ty::RawPtr(_)
| ty::Ref(_, _, _)
| ty::FnDef(_, _)
| ty::FnPtr(_)
| ty::Closure(_, _)
| ty::Generator(_, _, _)
| ty::GeneratorWitness(_)
| ty::GeneratorWitnessMIR(_, _)
| ty::Never
| ty::Tuple(_)
| ty::Error(_)
| ty::Adt(_, _)
| ty::Alias(ty::Opaque, _) => {
if let Some(def_id) = ecx.tcx().find_map_relevant_impl(
goal.predicate.def_id(),
goal.predicate.self_ty(),
TreatProjections::NextSolverLookup,
Some,
) {
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
return Err(NoSolution);
}
}
}

ecx.probe_and_evaluate_goal_for_constituent_tys(
Expand Down
9 changes: 4 additions & 5 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1363,12 +1363,11 @@ macro_rules! uint_impl {
///
/// Basic usage:
///
/// Please note that this example is shared between integer types.
/// Which explains why `i8` is used here.
///
/// ```
/// assert_eq!(100i8.wrapping_neg(), -100);
/// assert_eq!((-128i8).wrapping_neg(), -128);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_neg(), 0);")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_neg(), 1);")]
#[doc = concat!("assert_eq!(13_", stringify!($SelfT), ".wrapping_neg(), (!13) + 1);")]
#[doc = concat!("assert_eq!(42_", stringify!($SelfT), ".wrapping_neg(), !(42 - 1));")]
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
4 changes: 4 additions & 0 deletions src/etc/rust-gdb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fi
# Find out where the pretty printer Python module is
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
# Get the commit hash for path remapping
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"

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

6 changes: 5 additions & 1 deletion src/etc/rust-gdbgui
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ fi
# Find out where the pretty printer Python module is
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
# Get the commit hash for path remapping
RUSTC_COMMIT_HASH="$("$RUSTC" -vV | sed -n 's/commit-hash: \(\w*\)/\1/p')"

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

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

# Finally we execute gdbgui.
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,8 @@ fn clean_extern_crate<'tcx>(
Some(l) => attr::list_contains_name(&l, sym::inline),
None => false,
}
});
})
&& !cx.output_format.is_json();

let krate_owner_def_id = krate.owner_id.to_def_id();
if please_inline {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ impl Variant {

#[derive(Clone, Debug)]
pub(crate) struct Discriminant {
// In the case of cross crate re-exports, we don't have the nessesary information
// In the case of cross crate re-exports, we don't have the necessary information
// to reconstruct the expression of the discriminant, only the value.
pub(super) expr: Option<BodyId>,
pub(super) value: DefId,
Expand Down
3 changes: 3 additions & 0 deletions tests/rustdoc-ui/intra-doc/auxiliary/inner-crate-enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub enum O {
L = -1,
}
8 changes: 8 additions & 0 deletions tests/rustdoc-ui/intra-doc/inline-external-enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass
// aux-build: inner-crate-enum.rs
// compile-flags:-Z unstable-options --output-format json

#[doc(inline)]
pub extern crate inner_crate_enum;

fn main() {}
Loading

0 comments on commit 5072826

Please sign in to comment.