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 9 pull requests #129595

Merged
merged 19 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a97b41f
Use subtyping for UnsafeFnPointer coercion, too
compiler-errors Aug 20, 2024
147bb17
Rework how we emit errors for unresolved object lifetimes
compiler-errors Aug 24, 2024
6df0ccf
rustdoc: clean up tuple <-> primitive conversion docs
notriddle Aug 24, 2024
e7f11b6
Removes dead code from the compiler
mu001999 Aug 8, 2024
c29e328
gitignore: ignore ICE reports regardless of directory
GrigorenkoPV Aug 24, 2024
ba24121
tweak rustc_allow_const_fn_unstable hint, and add back test for stabl…
RalfJung Aug 25, 2024
8750e24
Fixing span manipulation and indentation of the suggestion introduced…
surechen Aug 22, 2024
48f43fa
Avoid taking reference of &TyKind
compiler-errors Aug 25, 2024
ecd2d11
Remove redundant flags that can be inferred from the HIR
compiler-errors Aug 24, 2024
1c58522
Use FxHasher on new solver unconditionally
compiler-errors Aug 24, 2024
621f272
Rollup merge of #129288 - compiler-errors:unsafe-fn-coercion, r=lcnr
matthiaskrgr Aug 25, 2024
6228bd6
Rollup merge of #129405 - surechen:fix_span_x, r=cjgillot
matthiaskrgr Aug 25, 2024
5a07308
Rollup merge of #129518 - GrigorenkoPV:gitignore-library-ice, r=tgross35
matthiaskrgr Aug 25, 2024
ae21236
Rollup merge of #129519 - compiler-errors:lowering-flags, r=fmease
matthiaskrgr Aug 25, 2024
aa26e1a
Rollup merge of #129525 - notriddle:notriddle/fake-variadic-tuple-arr…
matthiaskrgr Aug 25, 2024
a8a242c
Rollup merge of #129526 - compiler-errors:fx, r=lqd
matthiaskrgr Aug 25, 2024
c6e0068
Rollup merge of #129544 - mu001999-contrib:dead-code/clean, r=compile…
matthiaskrgr Aug 25, 2024
0a8e305
Rollup merge of #129553 - RalfJung:const-stability, r=compiler-errors
matthiaskrgr Aug 25, 2024
d6a3aa4
Rollup merge of #129590 - compiler-errors:ref-tykind, r=fmease
matthiaskrgr Aug 25, 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
Prev Previous commit
Next Next commit
Remove redundant flags that can be inferred from the HIR
  • Loading branch information
compiler-errors committed Aug 25, 2024
commit ecd2d115736581726ee9b77432561ea9480b3241
21 changes: 16 additions & 5 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
///
/// *Bare* trait object types are ones that aren't preceded by the keyword `dyn`.
/// In edition 2021 and onward we emit a hard error for them.
pub(super) fn prohibit_or_lint_bare_trait_object_ty(
&self,
self_ty: &hir::Ty<'_>,
in_path: bool,
) {
pub(super) fn prohibit_or_lint_bare_trait_object_ty(&self, self_ty: &hir::Ty<'_>) {
let tcx = self.tcx();

let hir::TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) =
Expand All @@ -28,6 +24,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
return;
};

let in_path = match tcx.parent_hir_node(self_ty.hir_id) {
hir::Node::Ty(hir::Ty {
kind: hir::TyKind::Path(hir::QPath::TypeRelative(qself, _)),
..
})
| hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Path(hir::QPath::TypeRelative(qself, _)),
..
})
| hir::Node::Pat(hir::Pat {
kind: hir::PatKind::Path(hir::QPath::TypeRelative(qself, _)),
..
}) if qself.hir_id == self_ty.hir_id => true,
_ => false,
};
let needs_bracket = in_path
&& !tcx
.sess
Expand Down
27 changes: 5 additions & 22 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,16 +1998,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}

/// Lower a type from the HIR to our internal notion of a type.
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
self.lower_ty_common(hir_ty, false, false)
}

/// Lower a type inside of a path from the HIR to our internal notion of a type.
pub fn lower_ty_in_path(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
self.lower_ty_common(hir_ty, false, true)
}

fn lower_delegation_ty(&self, idx: hir::InferDelegationKind) -> Ty<'tcx> {
let delegation_sig = self.tcx().inherit_sig_for_delegation_item(self.item_def_id());
match idx {
Expand All @@ -2025,7 +2015,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// 2. `in_path`: Whether the type appears inside of a path.
/// Used to provide correct diagnostics for bare trait object types.
#[instrument(level = "debug", skip(self), ret)]
fn lower_ty_common(&self, hir_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
let tcx = self.tcx();

let result_ty = match &hir_ty.kind {
Expand All @@ -2035,7 +2025,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
hir::TyKind::Ref(region, mt) => {
let r = self.lower_lifetime(region, RegionInferReason::Reference);
debug!(?r);
let t = self.lower_ty_common(mt.ty, true, false);
let t = self.lower_ty(mt.ty);
Ty::new_ref(tcx, r, t, mt.mutbl)
}
hir::TyKind::Never => tcx.types.never,
Expand Down Expand Up @@ -2064,20 +2054,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
)
}
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
self.prohibit_or_lint_bare_trait_object_ty(hir_ty, in_path);
self.prohibit_or_lint_bare_trait_object_ty(hir_ty);

let repr = match repr {
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
TraitObjectSyntax::DynStar => ty::DynStar,
};
self.lower_trait_object_ty(
hir_ty.span,
hir_ty.hir_id,
bounds,
lifetime,
borrowed,
repr,
)
self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id, bounds, lifetime, repr)
}
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
debug!(?maybe_qself, ?path);
Expand Down Expand Up @@ -2105,7 +2088,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
debug!(?qself, ?segment);
let ty = self.lower_ty_common(qself, false, true);
let ty = self.lower_ty(qself);
self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
.map(|(ty, _, _)| ty)
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
hir_id: hir::HirId,
hir_trait_bounds: &[(hir::PolyTraitRef<'tcx>, hir::TraitBoundModifier)],
lifetime: &hir::Lifetime,
_borrowed: bool,
representation: DynKind,
) -> Ty<'tcx> {
let tcx = self.tcx();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// to be object-safe.
// We manually call `register_wf_obligation` in the success path
// below.
let ty = self.lowerer().lower_ty_in_path(qself);
let ty = self.lowerer().lower_ty(qself);
(LoweredTy::from_raw(self, span, ty), qself, segment)
}
QPath::LangItem(..) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/dyn-keyword/suggest-dyn-on-bare-trait-in-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ edition: 2021

trait Trait {}

impl dyn Trait {
const CONST: () = ();
}

fn main() {
match () {
Trait::CONST => {}
//~^ ERROR trait objects must include the `dyn` keyword
}
}
14 changes: 14 additions & 0 deletions tests/ui/dyn-keyword/suggest-dyn-on-bare-trait-in-pat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-dyn-on-bare-trait-in-pat.rs:11:9
|
LL | Trait::CONST => {}
| ^^^^^
|
help: add `dyn` keyword before this trait
|
LL | <dyn Trait>::CONST => {}
| ++++ +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0782`.
Loading