Skip to content

Commit 7b32e93

Browse files
authored
Rollup merge of rust-lang#96812 - cjgillot:no-lint-outllives-macro, r=petrochenkov
Do not lint on explicit outlives requirements from external macros. The current implementation of the list rightfully skipped where predicates from external macros. However, if the where predicate came from the current macro but the bounds were from an external macro, the lint still fired. Closes rust-lang#96640
2 parents c5c273b + 89f15bf commit 7b32e93

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

compiler/rustc_lint/src/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc_hir::def::{DefKind, Res};
3838
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
3939
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
4040
use rustc_index::vec::Idx;
41-
use rustc_middle::lint::LintDiagnosticBuilder;
41+
use rustc_middle::lint::{in_external_macro, LintDiagnosticBuilder};
4242
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
4343
use rustc_middle::ty::print::with_no_trimmed_paths;
4444
use rustc_middle::ty::subst::{GenericArgKind, Subst};
@@ -2115,6 +2115,7 @@ impl ExplicitOutlivesRequirements {
21152115
None
21162116
}
21172117
})
2118+
.filter(|(_, span)| !in_external_macro(tcx.sess, *span))
21182119
.collect()
21192120
}
21202121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn foo() {}
2+
3+
#[macro_export]
4+
macro_rules! gimme_a {
5+
($($mac:tt)*) => { $($mac)* { 'a } }
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// edition:2018
2+
// aux-build:edition-lint-infer-outlives-macro.rs
3+
4+
// Test that the lint does not fire if the where predicate
5+
// is from the local crate, but all the bounds are from an
6+
// external macro.
7+
8+
#![deny(explicit_outlives_requirements)]
9+
10+
#[macro_use]
11+
extern crate edition_lint_infer_outlives_macro;
12+
13+
macro_rules! make_foo {
14+
($a:tt) => {
15+
struct Foo<$a, 'b> where 'b: $a {
16+
foo: &$a &'b (),
17+
}
18+
}
19+
}
20+
21+
gimme_a! {make_foo!}
22+
23+
struct Bar<'a, 'b: 'a> {
24+
//~^ ERROR: outlives requirements can be inferred
25+
bar: &'a &'b (),
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: outlives requirements can be inferred
2+
--> $DIR/edition-lint-infer-outlives-macro.rs:23:18
3+
|
4+
LL | struct Bar<'a, 'b: 'a> {
5+
| ^^^^ help: remove this bound
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/edition-lint-infer-outlives-macro.rs:8:9
9+
|
10+
LL | #![deny(explicit_outlives_requirements)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)