Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fdf8b29

Browse files
committedFeb 23, 2024
Auto merge of #121491 - matthiaskrgr:rollup-wkzqawy, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #121434 (Fix #121208 fallout) - #121471 (When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`) - #121476 (remove `llvm.assertions=true` in compiler profile) - #121479 (fix generalizer unsoundness) - #121480 (Fix more #121208 fallout) - #121482 (Allow for a missing `adt_def` in `NamePrivacyVisitor`.) - #121484 (coverage: Use variable name `this` in `CoverageGraph::from_mir`) - #121487 (Explicitly call `emit_stashed_diagnostics`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6dadb6e + 6ee43bc commit fdf8b29

File tree

34 files changed

+377
-133
lines changed

34 files changed

+377
-133
lines changed
 

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16361636
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
16371637
old_def_id
16381638
} else {
1639-
self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1639+
self.dcx()
1640+
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1641+
continue;
16401642
}
16411643
}
16421644

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
123123
// `handle_opaque_type` cannot handle subtyping, so to support subtyping
124124
// we instead eagerly generalize here. This is a bit of a mess but will go
125125
// away once we're using the new solver.
126-
let mut enable_subtyping = |ty, ty_is_expected| {
126+
//
127+
// Given `opaque rel B`, we create a new infer var `ty_vid` constrain it
128+
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
129+
// the opaque.
130+
let mut enable_subtyping = |ty, opaque_is_expected| {
127131
let ty_vid = infcx.next_ty_var_id_in_universe(
128132
TypeVariableOrigin {
129133
kind: TypeVariableOriginKind::MiscVariable,
@@ -132,15 +136,15 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
132136
ty::UniverseIndex::ROOT,
133137
);
134138

135-
let variance = if ty_is_expected {
139+
let variance = if opaque_is_expected {
136140
self.ambient_variance
137141
} else {
138142
self.ambient_variance.xform(ty::Contravariant)
139143
};
140144

141145
self.type_checker.infcx.instantiate_ty_var(
142146
self,
143-
ty_is_expected,
147+
opaque_is_expected,
144148
ty_vid,
145149
variance,
146150
ty,
@@ -149,8 +153,8 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
149153
};
150154

151155
let (a, b) = match (a.kind(), b.kind()) {
152-
(&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, false)?),
153-
(_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, true)?, b),
156+
(&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?),
157+
(_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b),
154158
_ => unreachable!(
155159
"expected at least one opaque type in `relate_opaques`, got {a} and {b}."
156160
),

‎compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
154154
trait_m_sig.inputs_and_output,
155155
));
156156
if !ocx.select_all_or_error().is_empty() {
157-
// This code path is not reached in any tests, but may be reachable. If
158-
// this is triggered, it should be converted to `delayed_bug` and the
159-
// triggering case turned into a test.
160-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
157+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
158+
return;
161159
}
162160
let outlives_env = OutlivesEnvironment::with_bounds(
163161
param_env,
164162
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
165163
);
166164
let errors = infcx.resolve_regions(&outlives_env);
167165
if !errors.is_empty() {
168-
// This code path is not reached in any tests, but may be reachable. If
169-
// this is triggered, it should be converted to `delayed_bug` and the
170-
// triggering case turned into a test.
171-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
166+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
167+
return;
172168
}
173169
// Resolve any lifetime variables that may have been introduced during normalization.
174170
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
315315

316316
if is_host_effect {
317317
if let Some(idx) = host_effect_index {
318-
tcx.dcx().span_bug(
318+
tcx.dcx().span_delayed_bug(
319319
param.span,
320320
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
321321
);

‎compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7777
// coercions from ! to `expected`.
7878
if ty.is_never() {
7979
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
80-
self.dcx()
81-
.span_bug(expr.span, "expression with never type wound up being adjusted");
80+
let reported = self.dcx().span_delayed_bug(
81+
expr.span,
82+
"expression with never type wound up being adjusted",
83+
);
84+
return Ty::new_error(self.tcx(), reported);
8285
}
8386

8487
let adj_ty = self.next_ty_var(TypeVariableOrigin {

‎compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
582582
match ty.kind() {
583583
ty::Tuple(args) => Ok(args.len()),
584584
_ => {
585-
self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple");
585+
self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple");
586+
Err(())
586587
}
587588
}
588589
}

‎compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl<'tcx> InferCtxt<'tcx> {
2626
/// This is *not* expected to be used anywhere except for an implementation of
2727
/// `TypeRelation`. Do not use this, and instead please use `At::eq`, for all
2828
/// other usecases (i.e. setting the value of a type var).
29-
#[instrument(level = "debug", skip(self, relation, target_is_expected))]
29+
#[instrument(level = "debug", skip(self, relation))]
3030
pub fn instantiate_ty_var<R: ObligationEmittingRelation<'tcx>>(
3131
&self,
3232
relation: &mut R,
3333
target_is_expected: bool,
3434
target_vid: ty::TyVid,
35-
ambient_variance: ty::Variance,
35+
instantiation_variance: ty::Variance,
3636
source_ty: Ty<'tcx>,
3737
) -> RelateResult<'tcx, ()> {
3838
debug_assert!(self.inner.borrow_mut().type_variables().probe(target_vid).is_unknown());
@@ -46,7 +46,7 @@ impl<'tcx> InferCtxt<'tcx> {
4646
//
4747
// We then relate `generalized_ty <: source_ty`,adding constraints like `'x: '?2` and `?1 <: ?3`.
4848
let Generalization { value_may_be_infer: generalized_ty, has_unconstrained_ty_var } =
49-
self.generalize(relation.span(), target_vid, ambient_variance, source_ty)?;
49+
self.generalize(relation.span(), target_vid, instantiation_variance, source_ty)?;
5050

5151
// Constrain `b_vid` to the generalized type `generalized_ty`.
5252
if let &ty::Infer(ty::TyVar(generalized_vid)) = generalized_ty.kind() {
@@ -73,7 +73,7 @@ impl<'tcx> InferCtxt<'tcx> {
7373
// the alias can be normalized to something which does not
7474
// mention `?0`.
7575
if self.next_trait_solver() {
76-
let (lhs, rhs, direction) = match ambient_variance {
76+
let (lhs, rhs, direction) = match instantiation_variance {
7777
ty::Variance::Invariant => {
7878
(generalized_ty.into(), source_ty.into(), AliasRelationDirection::Equate)
7979
}
@@ -106,22 +106,28 @@ impl<'tcx> InferCtxt<'tcx> {
106106
}
107107
}
108108
} else {
109-
// HACK: make sure that we `a_is_expected` continues to be
110-
// correct when relating the generalized type with the source.
109+
// NOTE: The `instantiation_variance` is not the same variance as
110+
// used by the relation. When instantiating `b`, `target_is_expected`
111+
// is flipped and the `instantion_variance` is also flipped. To
112+
// constrain the `generalized_ty` while using the original relation,
113+
// we therefore only have to flip the arguments.
114+
//
115+
// ```ignore (not code)
116+
// ?a rel B
117+
// instantiate_ty_var(?a, B) # expected and variance not flipped
118+
// B' rel B
119+
// ```
120+
// or
121+
// ```ignore (not code)
122+
// A rel ?b
123+
// instantiate_ty_var(?b, A) # expected and variance flipped
124+
// A rel A'
125+
// ```
111126
if target_is_expected == relation.a_is_expected() {
112-
relation.relate_with_variance(
113-
ambient_variance,
114-
ty::VarianceDiagInfo::default(),
115-
generalized_ty,
116-
source_ty,
117-
)?;
127+
relation.relate(generalized_ty, source_ty)?;
118128
} else {
119-
relation.relate_with_variance(
120-
ambient_variance.xform(ty::Contravariant),
121-
ty::VarianceDiagInfo::default(),
122-
source_ty,
123-
generalized_ty,
124-
)?;
129+
debug!("flip relation");
130+
relation.relate(source_ty, generalized_ty)?;
125131
}
126132
}
127133

‎compiler/rustc_lint/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ lint_non_upper_case_global = {$sort} `{$name}` should have an upper case name
429429
lint_noop_method_call = call to `.{$method}()` on a reference in this situation does nothing
430430
.suggestion = remove this redundant call
431431
.note = the type `{$orig_ty}` does not implement `{$trait_}`, so calling `{$method}` on `&{$orig_ty}` copies the reference, which does not do anything and can be removed
432+
.derive_suggestion = if you meant to clone `{$orig_ty}`, implement `Clone` for it
432433
433434
lint_only_cast_u8_to_char = only `u8` can be cast into `char`
434435
.suggestion = use a `char` literal instead

‎compiler/rustc_lint/src/lints.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,12 @@ pub struct NoopMethodCallDiag<'a> {
13141314
pub trait_: Symbol,
13151315
#[suggestion(code = "", applicability = "machine-applicable")]
13161316
pub label: Span,
1317+
#[suggestion(
1318+
lint_derive_suggestion,
1319+
code = "#[derive(Clone)]\n",
1320+
applicability = "maybe-incorrect"
1321+
)]
1322+
pub suggest_derive: Option<Span>,
13171323
}
13181324

13191325
#[derive(LintDiagnostic)]

‎compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
121121
let orig_ty = expr_ty.peel_refs();
122122

123123
if receiver_ty == expr_ty {
124+
let suggest_derive = match orig_ty.kind() {
125+
ty::Adt(def, _) => Some(cx.tcx.def_span(def.did()).shrink_to_lo()),
126+
_ => None,
127+
};
124128
cx.emit_span_lint(
125129
NOOP_METHOD_CALL,
126130
span,
127-
NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span },
131+
NoopMethodCallDiag {
132+
method: call.ident.name,
133+
orig_ty,
134+
trait_,
135+
label: span,
136+
suggest_derive,
137+
},
128138
);
129139
} else {
130140
match name {

‎compiler/rustc_mir_transform/src/coverage/graph.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,18 @@ impl CoverageGraph {
5252
}
5353
}
5454

55-
let mut basic_coverage_blocks =
56-
Self { bcbs, bb_to_bcb, successors, predecessors, dominators: None };
57-
let dominators = dominators::dominators(&basic_coverage_blocks);
58-
basic_coverage_blocks.dominators = Some(dominators);
55+
let mut this = Self { bcbs, bb_to_bcb, successors, predecessors, dominators: None };
56+
57+
this.dominators = Some(dominators::dominators(&this));
5958

6059
// The coverage graph's entry-point node (bcb0) always starts with bb0,
6160
// which never has predecessors. Any other blocks merged into bcb0 can't
6261
// have multiple (coverage-relevant) predecessors, so bcb0 always has
6362
// zero in-edges.
64-
assert!(basic_coverage_blocks[START_BCB].leader_bb() == mir::START_BLOCK);
65-
assert!(basic_coverage_blocks.predecessors[START_BCB].is_empty());
63+
assert!(this[START_BCB].leader_bb() == mir::START_BLOCK);
64+
assert!(this.predecessors[START_BCB].is_empty());
6665

67-
basic_coverage_blocks
66+
this
6867
}
6968

7069
fn compute_basic_coverage_blocks(

‎compiler/rustc_privacy/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,10 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
988988
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
989989
if let hir::ExprKind::Struct(qpath, fields, ref base) = expr.kind {
990990
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
991-
let adt = self.typeck_results().expr_ty(expr).ty_adt_def().unwrap();
991+
let Some(adt) = self.typeck_results().expr_ty(expr).ty_adt_def() else {
992+
self.tcx.dcx().span_delayed_bug(expr.span, "no adt_def for expression");
993+
return;
994+
};
992995
let variant = adt.variant_of_res(res);
993996
if let Some(base) = *base {
994997
// If the expression uses FRU we need to make sure all the unmentioned fields

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ fn do_normalize_predicates<'tcx>(
172172
// the normalized predicates.
173173
let errors = infcx.resolve_regions(&outlives_env);
174174
if !errors.is_empty() {
175-
// @lcnr: Let's still ICE here for now. I want a test case
176-
// for that.
177-
tcx.dcx().span_bug(
175+
tcx.dcx().span_delayed_bug(
178176
span,
179177
format!("failed region resolution while normalizing {elaborated_env:?}: {errors:?}"),
180178
);

‎src/bootstrap/defaults/config.compiler.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ lto = "off"
1919
frame-pointers = true
2020

2121
[llvm]
22-
# This enables debug-assertions in LLVM,
23-
# catching logic errors in codegen much earlier in the process.
24-
assertions = true
22+
# Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true`
23+
# because we don't provide ci-llvm on the `rustc-alt-builds` server. Therefore, it is kept off by default.
24+
assertions = false
2525
# Enable warnings during the LLVM compilation (when LLVM is changed, causing a compilation)
2626
enable-warnings = true
2727
# Will download LLVM from CI if available on your platform.

‎src/tools/rustfmt/src/parse/parser.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,21 @@ impl<'a> Parser<'a> {
163163
fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
164164
let mut parser = AssertUnwindSafe(&mut self.parser);
165165

166-
match catch_unwind(move || parser.parse_crate_mod()) {
167-
Ok(Ok(k)) => Ok(k),
168-
Ok(Err(db)) => {
166+
// rustfmt doesn't use `run_compiler` like other tools, so it must emit
167+
// any stashed diagnostics itself, otherwise the `DiagCtxt` will assert
168+
// when dropped. The final result here combines the parsing result and
169+
// the `emit_stashed_diagnostics` result.
170+
let parse_res = catch_unwind(move || parser.parse_crate_mod());
171+
let stashed_res = self.parser.dcx().emit_stashed_diagnostics();
172+
let err = Err(ParserError::ParsePanicError);
173+
match (parse_res, stashed_res) {
174+
(Ok(Ok(k)), None) => Ok(k),
175+
(Ok(Ok(_)), Some(_guar)) => err,
176+
(Ok(Err(db)), _) => {
169177
db.emit();
170-
Err(ParserError::ParseError)
178+
err
171179
}
172-
Err(_) => Err(ParserError::ParsePanicError),
180+
(Err(_), _) => err,
173181
}
174182
}
175183
}

‎src/tools/rustfmt/src/test/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ fn crate_parsing_errors_on_unclosed_delims() {
5555
let filename = "tests/parser/unclosed-delims/issue_4466.rs";
5656
assert_parser_error(filename);
5757
}
58+
59+
#[test]
60+
fn crate_parsing_stashed_diag() {
61+
// See also https://github.com/rust-lang/rust/issues/121450
62+
let filename = "tests/parser/stashed-diag.rs";
63+
assert_parser_error(filename);
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![u={static N;}]
2+
3+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub trait Iterable {
2+
type Item<'a>
3+
where
4+
Self: 'a;
5+
6+
fn iter(&self) -> impl Iterator;
7+
}
8+
9+
impl<'a, I: 'a + Iterable> Iterable for &'a I {
10+
type Item = u32;
11+
//~^ ERROR lifetime parameters or bounds on type `Item` do not match the trait declaration
12+
13+
fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
14+
//~^ ERROR binding for associated type `Item` references lifetime `'missing`
15+
//~| ERROR `()` is not an iterator
16+
}
17+
18+
fn main() {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0582]: binding for associated type `Item` references lifetime `'missing`, which does not appear in the trait input types
2+
--> $DIR/span-bug-issue-121457.rs:13:51
3+
|
4+
LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
8+
--> $DIR/span-bug-issue-121457.rs:10:14
9+
|
10+
LL | type Item<'a>
11+
| ---- lifetimes in impl do not match this type in trait
12+
LL | where
13+
LL | Self: 'a;
14+
| -- this bound might be missing in the impl
15+
...
16+
LL | type Item = u32;
17+
| ^ lifetimes do not match type in trait
18+
19+
error[E0277]: `()` is not an iterator
20+
--> $DIR/span-bug-issue-121457.rs:13:23
21+
|
22+
LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
24+
|
25+
= help: the trait `Iterator` is not implemented for `()`
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0195, E0277, E0582.
30+
For more information about an error, try `rustc --explain E0195`.

‎tests/ui/lint/noop-method-call.fixed

Lines changed: 0 additions & 64 deletions
This file was deleted.

‎tests/ui/lint/noop-method-call.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ check-pass
2-
//@ run-rustfix
32

43
#![feature(rustc_attrs)]
54
#![allow(unused)]

‎tests/ui/lint/noop-method-call.stderr

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: call to `.clone()` on a reference in this situation does nothing
2-
--> $DIR/noop-method-call.rs:16:25
2+
--> $DIR/noop-method-call.rs:15:25
33
|
44
LL | let _ = &mut encoded.clone();
55
| ^^^^^^^^ help: remove this redundant call
@@ -8,52 +8,102 @@ LL | let _ = &mut encoded.clone();
88
= note: `#[warn(noop_method_call)]` on by default
99

1010
warning: call to `.clone()` on a reference in this situation does nothing
11-
--> $DIR/noop-method-call.rs:18:21
11+
--> $DIR/noop-method-call.rs:17:21
1212
|
1313
LL | let _ = &encoded.clone();
1414
| ^^^^^^^^ help: remove this redundant call
1515
|
1616
= note: the type `[u8]` does not implement `Clone`, so calling `clone` on `&[u8]` copies the reference, which does not do anything and can be removed
1717

1818
warning: call to `.clone()` on a reference in this situation does nothing
19-
--> $DIR/noop-method-call.rs:24:71
19+
--> $DIR/noop-method-call.rs:23:71
2020
|
2121
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
22-
| ^^^^^^^^ help: remove this redundant call
22+
| ^^^^^^^^
2323
|
2424
= note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
25+
help: remove this redundant call
26+
|
27+
LL - let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
28+
LL + let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref;
29+
|
30+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
31+
|
32+
LL + #[derive(Clone)]
33+
LL | struct PlainType<T>(T);
34+
|
2535

2636
warning: call to `.deref()` on a reference in this situation does nothing
27-
--> $DIR/noop-method-call.rs:32:63
37+
--> $DIR/noop-method-call.rs:31:63
2838
|
2939
LL | let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
30-
| ^^^^^^^^ help: remove this redundant call
40+
| ^^^^^^^^
3141
|
3242
= note: the type `PlainType<u32>` does not implement `Deref`, so calling `deref` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
43+
help: remove this redundant call
44+
|
45+
LL - let non_deref_type_deref: &PlainType<u32> = non_deref_type.deref();
46+
LL + let non_deref_type_deref: &PlainType<u32> = non_deref_type;
47+
|
48+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
49+
|
50+
LL + #[derive(Clone)]
51+
LL | struct PlainType<T>(T);
52+
|
3353

3454
warning: call to `.borrow()` on a reference in this situation does nothing
35-
--> $DIR/noop-method-call.rs:36:66
55+
--> $DIR/noop-method-call.rs:35:66
3656
|
3757
LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
38-
| ^^^^^^^^^ help: remove this redundant call
58+
| ^^^^^^^^^
3959
|
4060
= note: the type `PlainType<u32>` does not implement `Borrow`, so calling `borrow` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
61+
help: remove this redundant call
62+
|
63+
LL - let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
64+
LL + let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type;
65+
|
66+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
67+
|
68+
LL + #[derive(Clone)]
69+
LL | struct PlainType<T>(T);
70+
|
4171

4272
warning: call to `.clone()` on a reference in this situation does nothing
43-
--> $DIR/noop-method-call.rs:45:19
73+
--> $DIR/noop-method-call.rs:44:19
4474
|
4575
LL | non_clone_type.clone();
46-
| ^^^^^^^^ help: remove this redundant call
76+
| ^^^^^^^^
4777
|
4878
= note: the type `PlainType<T>` does not implement `Clone`, so calling `clone` on `&PlainType<T>` copies the reference, which does not do anything and can be removed
79+
help: remove this redundant call
80+
|
81+
LL - non_clone_type.clone();
82+
LL + non_clone_type;
83+
|
84+
help: if you meant to clone `PlainType<T>`, implement `Clone` for it
85+
|
86+
LL + #[derive(Clone)]
87+
LL | struct PlainType<T>(T);
88+
|
4989

5090
warning: call to `.clone()` on a reference in this situation does nothing
51-
--> $DIR/noop-method-call.rs:50:19
91+
--> $DIR/noop-method-call.rs:49:19
5292
|
5393
LL | non_clone_type.clone();
54-
| ^^^^^^^^ help: remove this redundant call
94+
| ^^^^^^^^
5595
|
5696
= note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
97+
help: remove this redundant call
98+
|
99+
LL - non_clone_type.clone();
100+
LL + non_clone_type;
101+
|
102+
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
103+
|
104+
LL + #[derive(Clone)]
105+
LL | struct PlainType<T>(T);
106+
|
57107

58108
warning: 7 warnings emitted
59109

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn bug<T>() -> impl CallbackMarker< Item = [(); { |_: &mut ()| 3; 4 }] > {}
2+
//~^ ERROR cannot find trait `CallbackMarker` in this scope
3+
4+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0405]: cannot find trait `CallbackMarker` in this scope
2+
--> $DIR/span-bug-issue-121431.rs:1:21
3+
|
4+
LL | fn bug<T>() -> impl CallbackMarker< Item = [(); { |_: &mut ()| 3; 4 }] > {}
5+
| ^^^^^^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0405`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(never_type)]
2+
3+
fn test2() {
4+
let x: !;
5+
let c2 = SingleVariant::Points(0)
6+
| match x { //~ ERROR no implementation for `SingleVariant | ()`
7+
_ => (),
8+
};
9+
}
10+
11+
enum SingleVariant {
12+
Points(u32),
13+
}
14+
15+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0369]: no implementation for `SingleVariant | ()`
2+
--> $DIR/span-bug-issue-121445.rs:6:9
3+
|
4+
LL | let c2 = SingleVariant::Points(0)
5+
| ------------------------ SingleVariant
6+
LL | | match x {
7+
| _________^_-
8+
LL | | _ => (),
9+
LL | | };
10+
| |_________- ()
11+
|
12+
note: an implementation of `BitOr<()>` might be missing for `SingleVariant`
13+
--> $DIR/span-bug-issue-121445.rs:11:1
14+
|
15+
LL | enum SingleVariant {
16+
| ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>`
17+
note: the trait `BitOr` must be implemented
18+
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0369`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn test(s: &Self::Id) {
2+
//~^ ERROR failed to resolve: `Self` is only available in impls, traits, and type definitions
3+
match &s[0..3] {}
4+
}
5+
6+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
2+
--> $DIR/unreachable-issue-121455.rs:1:13
3+
|
4+
LL | fn test(s: &Self::Id) {
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(const_trait_impl)]
2+
#![feature(effects)]
3+
4+
struct S;
5+
trait T {}
6+
7+
impl const dyn T {
8+
//~^ ERROR inherent impls cannot be `const`
9+
//~| ERROR the const parameter `host` is not constrained by the impl trait, self type, or
10+
pub const fn new() -> std::sync::Mutex<dyn T> {}
11+
}
12+
13+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: inherent impls cannot be `const`
2+
--> $DIR/span-bug-issue-121418.rs:7:12
3+
|
4+
LL | impl const dyn T {
5+
| ----- ^^^^^ inherent impl for this type
6+
| |
7+
| `const` because of this
8+
|
9+
= note: only trait implementations may be annotated with `const`
10+
11+
error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates
12+
--> $DIR/span-bug-issue-121418.rs:7:6
13+
|
14+
LL | impl const dyn T {
15+
| ^^^^^ unconstrained const parameter
16+
|
17+
= note: expressions using a const parameter must map each value to a distinct output value
18+
= note: proving the result of expressions other than the parameter are unique is not supported
19+
20+
error: aborting due to 2 previous errors
21+
22+
For more information about this error, try `rustc --explain E0207`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Bar {
2+
type Type;
3+
}
4+
struct Foo<'a>(&'a ());
5+
impl<'a> Bar for Foo<'f> { //~ ERROR undeclared lifetime
6+
type Type = u32;
7+
}
8+
9+
fn test() //~ ERROR implementation of `Bar` is not general enough
10+
where
11+
for<'a> <Foo<'a> as Bar>::Type: Sized,
12+
{
13+
}
14+
15+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0261]: use of undeclared lifetime name `'f`
2+
--> $DIR/span-bug-issue-121414.rs:5:22
3+
|
4+
LL | impl<'a> Bar for Foo<'f> {
5+
| - ^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'f` here: `'f,`
8+
9+
error: implementation of `Bar` is not general enough
10+
--> $DIR/span-bug-issue-121414.rs:9:4
11+
|
12+
LL | fn test()
13+
| ^^^^ implementation of `Bar` is not general enough
14+
|
15+
= note: `Bar` would have to be implemented for the type `Foo<'0>`, for any lifetime `'0`...
16+
= note: ...but `Bar` is actually implemented for the type `Foo<'1>`, for some specific lifetime `'1`
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0261`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fn test_missing_unsafe_warning_on_repr_packed() {
2+
struct Foo {
3+
x: String,
4+
}
5+
6+
let foo = Foo { x: String::new() };
7+
8+
let c = || {
9+
let (_, t2) = foo.x; //~ ERROR mismatched types
10+
};
11+
12+
c();
13+
}
14+
15+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/span-bug-issue-121410.rs:9:13
3+
|
4+
LL | let (_, t2) = foo.x;
5+
| ^^^^^^^ ----- this expression has type `String`
6+
| |
7+
| expected `String`, found `(_, _)`
8+
|
9+
= note: expected struct `String`
10+
found tuple `(_, _)`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
Please sign in to comment.